summaryrefslogtreecommitdiff
path: root/block.c
diff options
context:
space:
mode:
authoraliguori <aliguori@c046a42c-6fe2-441c-8c8c-71466251a162>2009-03-28 17:55:10 +0000
committeraliguori <aliguori@c046a42c-6fe2-441c-8c8c-71466251a162>2009-03-28 17:55:10 +0000
commit5eb456396d20554a6b9637b23519579f083aa992 (patch)
tree594c07299d7177e99d12ba97651b3ffd17631e75 /block.c
parent9b80ddf3460f5513b917720a07a1d32ec4ba1817 (diff)
block: support known backing format for image create and open (Uri Lublin)
Added a backing_format field to BlockDriverState. Added bdrv_create2 and drv->bdrv_create2 to create an image with a known backing file format. Upon bdrv_open2 if backing format is known use it, instead of probing the (backing) image. Signed-off-by: Uri Lublin <uril@redhat.com> Signed-off-by: Anthony Liguori <aliguori@us.ibm.com> git-svn-id: svn://svn.savannah.nongnu.org/qemu/trunk@6908 c046a42c-6fe2-441c-8c8c-71466251a162
Diffstat (limited to 'block.c')
-rw-r--r--block.c28
1 files changed, 24 insertions, 4 deletions
diff --git a/block.c b/block.c
index 7230f04e40..823841df03 100644
--- a/block.c
+++ b/block.c
@@ -181,6 +181,20 @@ BlockDriver *bdrv_find_format(const char *format_name)
return NULL;
}
+int bdrv_create2(BlockDriver *drv,
+ const char *filename, int64_t size_in_sectors,
+ const char *backing_file, const char *backing_format,
+ int flags)
+{
+ if (drv->bdrv_create2)
+ return drv->bdrv_create2(filename, size_in_sectors, backing_file,
+ backing_format, flags);
+ if (drv->bdrv_create)
+ return drv->bdrv_create(filename, size_in_sectors, backing_file,
+ flags);
+ return -ENOTSUP;
+}
+
int bdrv_create(BlockDriver *drv,
const char *filename, int64_t size_in_sectors,
const char *backing_file, int flags)
@@ -357,7 +371,7 @@ int bdrv_open2(BlockDriverState *bs, const char *filename, int flags,
/* if there is a backing file, use it */
bs1 = bdrv_new("");
- ret = bdrv_open(bs1, filename, 0);
+ ret = bdrv_open2(bs1, filename, 0, drv);
if (ret < 0) {
bdrv_delete(bs1);
return ret;
@@ -378,12 +392,14 @@ int bdrv_open2(BlockDriverState *bs, const char *filename, int flags,
else
realpath(filename, backing_filename);
- ret = bdrv_create(&bdrv_qcow2, tmp_filename,
- total_size, backing_filename, 0);
+ ret = bdrv_create2(&bdrv_qcow2, tmp_filename,
+ total_size, backing_filename,
+ (drv ? drv->format_name : NULL), 0);
if (ret < 0) {
return ret;
}
filename = tmp_filename;
+ drv = &bdrv_qcow2;
bs->is_temporary = 1;
}
@@ -429,10 +445,14 @@ int bdrv_open2(BlockDriverState *bs, const char *filename, int flags,
#endif
if (bs->backing_file[0] != '\0') {
/* if there is a backing file, use it */
+ BlockDriver *back_drv = NULL;
bs->backing_hd = bdrv_new("");
path_combine(backing_filename, sizeof(backing_filename),
filename, bs->backing_file);
- ret = bdrv_open(bs->backing_hd, backing_filename, open_flags);
+ if (bs->backing_format[0] != '\0')
+ back_drv = bdrv_find_format(bs->backing_format);
+ ret = bdrv_open2(bs->backing_hd, backing_filename, open_flags,
+ back_drv);
if (ret < 0) {
bdrv_close(bs);
return ret;