提交 5eb45639 编写于 作者: A aliguori

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: NUri Lublin <uril@redhat.com>
Signed-off-by: NAnthony Liguori <aliguori@us.ibm.com>


git-svn-id: svn://svn.savannah.nongnu.org/qemu/trunk@6908 c046a42c-6fe2-441c-8c8c-71466251a162
上级 9b80ddf3
...@@ -181,6 +181,20 @@ BlockDriver *bdrv_find_format(const char *format_name) ...@@ -181,6 +181,20 @@ BlockDriver *bdrv_find_format(const char *format_name)
return NULL; 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, int bdrv_create(BlockDriver *drv,
const char *filename, int64_t size_in_sectors, const char *filename, int64_t size_in_sectors,
const char *backing_file, int flags) const char *backing_file, int flags)
...@@ -357,7 +371,7 @@ int bdrv_open2(BlockDriverState *bs, const char *filename, int flags, ...@@ -357,7 +371,7 @@ int bdrv_open2(BlockDriverState *bs, const char *filename, int flags,
/* if there is a backing file, use it */ /* if there is a backing file, use it */
bs1 = bdrv_new(""); bs1 = bdrv_new("");
ret = bdrv_open(bs1, filename, 0); ret = bdrv_open2(bs1, filename, 0, drv);
if (ret < 0) { if (ret < 0) {
bdrv_delete(bs1); bdrv_delete(bs1);
return ret; return ret;
...@@ -378,12 +392,14 @@ int bdrv_open2(BlockDriverState *bs, const char *filename, int flags, ...@@ -378,12 +392,14 @@ int bdrv_open2(BlockDriverState *bs, const char *filename, int flags,
else else
realpath(filename, backing_filename); realpath(filename, backing_filename);
ret = bdrv_create(&bdrv_qcow2, tmp_filename, ret = bdrv_create2(&bdrv_qcow2, tmp_filename,
total_size, backing_filename, 0); total_size, backing_filename,
(drv ? drv->format_name : NULL), 0);
if (ret < 0) { if (ret < 0) {
return ret; return ret;
} }
filename = tmp_filename; filename = tmp_filename;
drv = &bdrv_qcow2;
bs->is_temporary = 1; bs->is_temporary = 1;
} }
...@@ -429,10 +445,14 @@ int bdrv_open2(BlockDriverState *bs, const char *filename, int flags, ...@@ -429,10 +445,14 @@ int bdrv_open2(BlockDriverState *bs, const char *filename, int flags,
#endif #endif
if (bs->backing_file[0] != '\0') { if (bs->backing_file[0] != '\0') {
/* if there is a backing file, use it */ /* if there is a backing file, use it */
BlockDriver *back_drv = NULL;
bs->backing_hd = bdrv_new(""); bs->backing_hd = bdrv_new("");
path_combine(backing_filename, sizeof(backing_filename), path_combine(backing_filename, sizeof(backing_filename),
filename, bs->backing_file); 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) { if (ret < 0) {
bdrv_close(bs); bdrv_close(bs);
return ret; return ret;
......
...@@ -62,6 +62,10 @@ BlockDriver *bdrv_find_format(const char *format_name); ...@@ -62,6 +62,10 @@ BlockDriver *bdrv_find_format(const char *format_name);
int bdrv_create(BlockDriver *drv, int bdrv_create(BlockDriver *drv,
const char *filename, int64_t size_in_sectors, const char *filename, int64_t size_in_sectors,
const char *backing_file, int flags); const char *backing_file, int flags);
int bdrv_create2(BlockDriver *drv,
const char *filename, int64_t size_in_sectors,
const char *backing_file, const char *backing_format,
int flags);
BlockDriverState *bdrv_new(const char *device_name); BlockDriverState *bdrv_new(const char *device_name);
void bdrv_delete(BlockDriverState *bs); void bdrv_delete(BlockDriverState *bs);
int bdrv_file_open(BlockDriverState **pbs, const char *filename, int flags); int bdrv_file_open(BlockDriverState **pbs, const char *filename, int flags);
......
...@@ -91,6 +91,12 @@ struct BlockDriver { ...@@ -91,6 +91,12 @@ struct BlockDriver {
BlockDriverCompletionFunc *cb, void *opaque); BlockDriverCompletionFunc *cb, void *opaque);
AIOPool aio_pool; AIOPool aio_pool;
/* new create with backing file format */
int (*bdrv_create2)(const char *filename, int64_t total_sectors,
const char *backing_file, const char *backing_format,
int flags);
struct BlockDriver *next; struct BlockDriver *next;
}; };
...@@ -113,6 +119,7 @@ struct BlockDriverState { ...@@ -113,6 +119,7 @@ struct BlockDriverState {
char filename[1024]; char filename[1024];
char backing_file[1024]; /* if non zero, the image is a diff of char backing_file[1024]; /* if non zero, the image is a diff of
this file image */ this file image */
char backing_format[16]; /* if non-zero and backing_file exists */
int is_temporary; int is_temporary;
int media_changed; int media_changed;
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册