docs: spec for add-cow file format
PATCH v10 1/6 docs: spec for add-cow file format
Introduce a new file format:add-cow. The usage can be found at this patch.
--- docs/specs/add-cow.txt | 87 ++++++++++++++++++++++++++++++++++++++++++++++++ 1 files changed, 87 insertions(+), 0 deletions(-) create mode 100644 docs/specs/add-cow.txt
docs/specs/add-cow.txt new file +87 -0
@@ -0,0 +1,87 @@ +== General == + +Raw file format does not support backing_file and copy on write feature. +The add-cow image format makes it possible to use backing files with raw +image by keeping a separate .add-cow metadata file. Once all sectors +have been written into the raw image it is safe to discard the .add-cow +and backing files, then we can use the raw image directly. + +While using add-cow, procedures may like this: +(ubuntu.img is a disk image which has been installed OS.) + 1) Create a raw image with the same size of ubuntu.img + qemu-img create -f raw test.raw 8G + 2) Create an add-cow image which will store dirty bitmap + qemu-img create -f add-cow test.add-cow \ + -o backing_file=ubuntu.img,image_file=test.raw + 3) Run qemu with add-cow image + qemu -drive if=virtio,file=test.add-cow + +=Specification= + +The file format looks like this: + + +---------------+-------------+-----------------+ + | Header | Reserved | COW bitmap | + +---------------+-------------+-----------------+ + +All numbers in add-cow are stored in Little Endian byte order. + +== Header == + +The Header is included in the first bytes: + + Byte 0 - 7: magic + add-cow magic string ("ADD_COW\xff") + + 8 - 11: version + Version number (only valid value is 1 now) + + 12 - 15: backing_filename_offset + Offset in the add-cow file at which the backing file name + is stored (NB: The string is not null terminated). 0 if the + image doesn't have a backing file. + + 16 - 19: backing_filename_size + Length of the backing file name in bytes. Undefined if the + image doesn't have a backing file. + + 20 - 23: image_filename_offset + Offset in the add-cow file at which the image_file name + is stored (NB: The string is not null terminated). + + 24 - 27: image_filename_size + Length of the image_file name in bytes. + + 28 - 35: features + Currently only 2 feature bits are used: + Feature bits: + The image uses a backing file: + * ADD_COW_F_BACKING_FILE = 0x01. + The backing file's format is raw: + * ADD_COW_F_BACKING_FORMAT_NO_PROBE = 0x02. + +== Reserved == + + Byte 36 - 4095: Reserved field: + It is used to make sure COW bitmap field starts at the + 4096th byte, backing_file name and image_file name will + be stored here. + +== COW bitmap == + +The "COW bitmap" field starts at the 4096th byte, stores a bitmap related to +backing_file and image_file. The bitmap will track whether the sector in +backing_file is dirty or not. + +Each bit in the bitmap indicates one cluster's status. One cluster includes 128 +sectors, then each bit indicates 512 * 128 = 64k bytes, So the size of bitmap is +calculated according to virtual size of image_file. In each byte, bit 0 to 7 +will track the 1st to 7th cluster in sequence, bit orders in one byte look like: + +----+----+----+----+----+----+----+----+ + | b7 | b6 | b5 | b4 | b3 | b2 | b1 | b0 | + +----+----+----+----+----+----+----+----+ + +If the bit is 0, indicates the sector has not been allocated in image_file, data +should be loaded from backing_file while reading; if the bit is 1, indicates the +related sector has been dirty, should be loaded from image_file while reading. +Writing to a sector causes the corresponding bit to be set to 1.
Signature · 1 line
1.7.1
PATCH 2/6 block: make some functions public
In add-cow file format, we will use path_has_protocol and we will read a NUL-terminated string from image , qed_read_string has done the samething, so make the two functions public, then we will reuse them directly.
--- block.c | 17 ++++++++++++++++- block.h | 3 +++ block/qed.c | 29 +---------------------------- 3 files changed, 20 insertions(+), 29 deletions(-)
block.c +16 -1
@@ -196,7 +196,7 @@ static void bdrv_io_limits_intercept(BlockDriverState *bs, }/* check if the path starts with "<protocol>:" */ -static int path_has_protocol (const char *path) +int path_has_protocol (const char *path) {const char *p;
@@ -1606,6 +1606,21 @@ int bdrv_read(BlockDriverState *bs, int64_t sector_num,return bdrv_rw_co (bs, sector_num, buf, nb_sectors, false); } +int bdrv_read_string (BlockDriverState *file,uint64_t offset,size_t n, +char *buf,size_t buflen) +{ +int ret; +if (n >= buflen) { +return -EINVAL ; + } + ret =bdrv_pread (file, offset, buf, n); +if (ret <0 ) { +return ret; + } + buf[n] ='\0' ; +return 0 ; +} +#define BITS_PER_LONG (sizeof(unsigned long) * 8) static void set_dirty_bitmap(BlockDriverState *bs, int64_t sector_num,
block.h +3 -0
@@ -149,6 +149,8 @@ int bdrv_pwrite(BlockDriverState *bs, int64_t offset, const void *buf, int count);int bdrv_pwrite_sync (BlockDriverState *bs,int64_t offset,const void *buf,int count); +int bdrv_read_string (BlockDriverState *file,uint64_t offset,size_t n, +char *buf,size_t buflen); int coroutine_fn bdrv_co_readv(BlockDriverState *bs, int64_t sector_num,int nb_sectors,QEMUIOVector *qiov); int coroutine_fn bdrv_co_copy_on_readv(BlockDriverState *bs,
@@ -321,6 +323,7 @@ char *bdrv_snapshot_dump(char *buf, int buf_size, QEMUSnapshotInfo *sn);char *get_human_readable_size (char *buf,int buf_size,int64_t size);int path_is_absolute (const char *path); +int path_has_protocol (const char *path);void path_combine (char *dest,int dest_size,const char *base_path,const char *filename);
block/qed.c +1 -28
@@ -217,33 +217,6 @@ static bool qed_is_image_size_valid(uint64_t image_size, uint32_t cluster_size, }/** -* Read a string of known length from the image file -* -* @file: Image file -* @offset: File offset to start of string, in bytes -* @n: String length in bytes -* @buf: Destination buffer -* @buflen: Destination buffer length in bytes -* @ret: 0 on success, -errno on failure -* -* The string is NUL-terminated. -*/ -static int qed_read_string (BlockDriverState *file,uint64_t offset,size_t n, -char *buf,size_t buflen) -{ -int ret; -if (n >= buflen) { -return -EINVAL ; - } - ret =bdrv_pread (file, offset, buf, n); -if (ret <0 ) { -return ret; - } - buf[n] ='\0' ; -return 0 ; -} - -/** * Allocate new clusters * * @s: QED state
@@ -437,7 +410,7 @@ static int bdrv_qed_open(BlockDriverState *bs, int flags)return -EINVAL ; } - ret =qed_read_string (bs->file, s->header.backing_filename_offset, + ret =bdrv_read_string (bs->file, s->header.backing_filename_offset, s->header.backing_filename_size, bs->backing_file,sizeof (bs->backing_file));if (ret <0 ) {
Signature · 1 line
1.7.1
PATCH 3/6 add-cow file format
In reply to Dong Xu WangThis is the implementation code for add-cow file format. Because image_file might be very huge, then we can't read entire bitmap into memory, we must use a cache. Since qcow-cache.c has implemted cache code, we can create our cache code based on it.
--- block/Makefile.objs | 1 + block/add-cow-cache.c | 218 ++++++++++++++++++++++ block/add-cow.c | 488 +++++++++++++++++++++++++++++++++++++++++++++++++ block/add-cow.h | 95 ++++++++++ block_int.h | 1 + 5 files changed, 803 insertions(+), 0 deletions(-) create mode 100644 block/add-cow-cache.c create mode 100644 block/add-cow.c create mode 100644 block/add-cow.h
block/Makefile.objs +1 -0
@@ -2,6 +2,7 @@ block-obj-y += raw.o cow.o qcow.o vdi.o vmdk.o cloop.o dmg.o bochs.o vpc.o vvfat block-obj-y += qcow2.o qcow2-refcount.o qcow2-cluster.o qcow2-snapshot.o qcow2-cache.o block-obj-y += qed.o qed-gencb.o qed-l2-cache.o qed-table.o qed-cluster.o block-obj-y += qed-check.o +block-obj-y += add-cow.o add-cow-cache.o block-obj-y += parallels.o nbd.o blkdebug.o sheepdog.o blkverify.o block-obj-y += stream.o block-obj-$(CONFIG_WIN32) += raw-win32.o
block/add-cow-cache.c new file +218 -0
218 lines not on this page · raw message
block/add-cow.c new file +488 -0
488 lines not on this page · raw message
block/add-cow.h new file +95 -0
95 lines not on this page · raw message
block_int.h +1 -0
@@ -51,6 +51,7 @@#define BLOCK_OPT_PREALLOC "preallocation"#define BLOCK_OPT_SUBFMT "subformat"#define BLOCK_OPT_COMPAT_LEVEL "compat" +#define BLOCK_OPT_IMAGE_FILE "image_file"typedef struct BdrvTrackedRequest BdrvTrackedRequest ;
Signature · 1 line
1.7.1
Re: [Qemu-devel] [PATCH 3/6] add-cow file format
I just took a quick look at the flush code.
Il 13/06/2012 16:36, Dong Xu Wang ha scritto:
block/add-cow-cache.c line 218
Quoted 13 lines
block/add-cow-cache.c new file +12
-0+bool add_cow_cache_set_writethrough (BlockDriverState *bs,AddCowCache *c, +bool enable) +{ +bool old = c->writethrough; + +if (!old && enable) { +add_cow_cache_flush (bs, c); + } + + c->writethrough = enable; +return old; +}
Writethrough mode should not be needed anymore in 1.2 if the new implementation of writethrough is added.
And anyway...
block/add-cow.c line 405
Quoted 3 lines
block/add-cow.c new file +3
-0+if (changed) { + ret =add_cow_cache_flush (bs, s->bitmap_cache); + }
... here you're treating the cache essentially as writethrough. Is this flush necessary?
Quoted 25 lines
block/add-cow.c new file +25
-0+qemu_co_mutex_unlock (&s->lock); +qemu_iovec_destroy (&hd_qiov); +return ret; +} + +static int bdrv_add_cow_truncate (BlockDriverState *bs,int64_t size) +{ +BDRVAddCowState *s = bs->opaque; +int sector_per_byte =SECTORS_PER_CLUSTER *8 ; +int ret; +int64_t bitmap_size = + (size /BDRV_SECTOR_SIZE + sector_per_byte -1 ) / sector_per_byte; + + ret =bdrv_truncate (bs->file, +ADD_COW_BITMAP_POS + bitmap_size); +if (ret <0 ) { +return ret; + } +bdrv_truncate (s->image_hd, size); +return 0 ; +} + +static coroutine_fn int add_cow_co_flush(BlockDriverState *bs) +{ +BDRVAddCowState *s = bs->opaque;
block/add-cow.c line 440
Quoted 10 lines
block/add-cow.c new file +10
-0+int ret; + +qemu_co_mutex_lock (&s->lock); + ret =add_cow_cache_flush (bs, s->bitmap_cache); +qemu_co_mutex_unlock (&s->lock); +if (ret <0 ) { +return ret; + } + +return bdrv_co_flush (bs->file);
Flushing bs->file here is not needed anymore...
Quoted 30 lines
block/add-cow.c new file +30
-0+} + +static QEMUOptionParameter add_cow_create_options[] = { + { + .name =BLOCK_OPT_SIZE , + .type =OPT_SIZE , + .help ="Virtual disk size" + }, + { + .name =BLOCK_OPT_BACKING_FILE , + .type =OPT_STRING , + .help ="File name of a base image" + }, + { + .name =BLOCK_OPT_IMAGE_FILE , + .type =OPT_STRING , + .help ="File name of a image file" + }, + { + .name =BLOCK_OPT_BACKING_FMT , + .type =OPT_STRING , + .help ="Image format of the base image" + }, + {NULL } +}; + +static BlockDriver bdrv_add_cow = { + .format_name ="add-cow" , + .instance_size =sizeof (BDRVAddCowState), + .bdrv_probe = add_cow_probe,
block/add-cow.c line 480
Quoted 10 lines
block/add-cow.c new file +10
-0+ .bdrv_open = add_cow_open, + .bdrv_close = add_cow_close, + .bdrv_create = add_cow_create, + .bdrv_co_readv = add_cow_co_readv, + .bdrv_co_writev = add_cow_co_writev, + .bdrv_truncate = bdrv_add_cow_truncate, + .bdrv_co_is_allocated = add_cow_is_allocated, + + .create_options = add_cow_create_options, + .bdrv_co_flush_to_disk = add_cow_co_flush,
... and this should be bdrv_co_flush_to_os.
Paolo
Re: [Qemu-devel] [PATCH 3/6] add-cow file format
Quoted 110 lines · Paolo Bonzini
I just took a quick look at the flush code.
Il 13/06/2012 16:36, Dong Xu Wang ha scritto:
block/add-cow-cache.c line 218
Quoted 13 lines
block/add-cow-cache.c new file +12
-0+bool add_cow_cache_set_writethrough (BlockDriverState *bs,AddCowCache *c, + bool enable) +{ + bool old = c->writethrough; + + if (!old && enable) { + add_cow_cache_flush(bs, c); + } + + c->writethrough = enable; + return old; +}Writethrough mode should not be needed anymore in 1.2 if the new implementation of writethrough is added.
And anyway...
Quoted 3 lines
+ if (changed) {
+ ret =add_cow_cache_flush(bs, s->bitmap_cache);
+ }... here you're treating the cache essentially as writethrough. Is this flush necessary?
Quoted 25 lines
+ qemu_co_mutex_unlock(&s->lock);
+ qemu_iovec_destroy(&hd_qiov);
+ return ret;block/add-cow.c new file +22
-0+} + +static int bdrv_add_cow_truncate (BlockDriverState *bs,int64_t size) +{ + BDRVAddCowState *s = bs->opaque; + int sector_per_byte = SECTORS_PER_CLUSTER * 8; + int ret; + int64_t bitmap_size = + (size / BDRV_SECTOR_SIZE + sector_per_byte - 1) / sector_per_byte; + + ret = bdrv_truncate(bs->file, + ADD_COW_BITMAP_POS + bitmap_size); + if (ret < 0) { + return ret; + } + bdrv_truncate(s->image_hd, size); + return 0; +} + +static coroutine_fn int add_cow_co_flush(BlockDriverState *bs) +{ + BDRVAddCowState *s = bs->opaque;block/add-cow.c line 440
Quoted 10 lines
block/add-cow.c new file +10
-0+ int ret; + + qemu_co_mutex_lock(&s->lock); + ret = add_cow_cache_flush(bs, s->bitmap_cache); + qemu_co_mutex_unlock(&s->lock); + if (ret < 0) { + return ret; + } + + return bdrv_co_flush(bs->file);Flushing
bs->filehere is not needed anymore...Quoted 30 lines
block/add-cow.c new file +30
-0+} + +static QEMUOptionParameter add_cow_create_options[] = { + { + .name = BLOCK_OPT_SIZE, + .type = OPT_SIZE, + .help = "Virtual disk size" + }, + { + .name = BLOCK_OPT_BACKING_FILE, + .type = OPT_STRING, + .help = "File name of a base image" + }, + { + .name = BLOCK_OPT_IMAGE_FILE, + .type = OPT_STRING, + .help = "File name of a image file" + }, + { + .name = BLOCK_OPT_BACKING_FMT, + .type = OPT_STRING, + .help = "Image format of the base image" + }, + { NULL } +}; + +static BlockDriver bdrv_add_cow = { + .format_name = "add-cow", + .instance_size = sizeof(BDRVAddCowState), + .bdrv_probe = add_cow_probe,block/add-cow.c line 480
Quoted 10 lines
block/add-cow.c new file +10
-0+ .bdrv_open = add_cow_open, + .bdrv_close = add_cow_close, + .bdrv_create = add_cow_create, + .bdrv_co_readv = add_cow_co_readv, + .bdrv_co_writev = add_cow_co_writev, + .bdrv_truncate = bdrv_add_cow_truncate, + .bdrv_co_is_allocated = add_cow_is_allocated, + + .create_options = add_cow_create_options, + .bdrv_co_flush_to_disk = add_cow_co_flush,... and this should be
bdrv_co_flush_to_os.
Quoted 2 lines
Paolo
Okay, thanks for your review, Paolo. :)
PATCH 4/6 qemu-img: add-cow will not support convert
In reply to Dong Xu Wangadd-cow file can't live alone, must together will image_file and backing_file. If we implement qemu-img convert operation for add-cow file format, we must create image_file and backing_file manually, that will be confused for users, so we just ignore add-cow format while doing converting.
--- qemu-img.c | 6 ++++++ 1 files changed, 6 insertions(+), 0 deletions(-)
qemu-img.c +6 -0
@@ -756,6 +756,12 @@ static int img_convert(int argc, char **argv) } } +if (strcmp (out_fmt,"add-cow" ) ==0 ) { +error_report ("Convert operation does not support %s format." , out_fmt); + ret =-1 ; + goto out; + } +/* Find driver and parse its options */ drv =bdrv_find_format (out_fmt);if (!drv) {
Signature · 1 line
1.7.1
Kevin Wolf
NAKRe: [Qemu-devel] [PATCH 4/6] qemu-img: add-cow will not support convert
Am 13.06.2012 16:36, schrieb Dong Xu Wang:
Quoted 6 lines
add-cow file can't live alone, must together will
image_fileandbacking_file. If we implement qemu-img convert operation for add-cow file format, we must createimage_fileandbacking_filemanually, that will be confused for users, so we just ignore add-cow format while doing converting.Signed-off-by Dong Xu Wang <[email protected]>
NACK.
This stupid "let's drop the feature, it might confuse users" attitude is known from Gnome, but not from qemu.
There's no technical reason to forbid it and anyone who manages to create a valid add-cow image will also be able to specify the very same options to a convert command. Also, having image format specific code in qemu-img is evil.
Kevin
Re: [Qemu-devel] [PATCH 4/6] qemu-img: add-cow will not support convert
Quoted 10 lines · Kevin Wolf
Am 13.06.2012 16:36, schrieb Dong Xu Wang:
Quoted 6 lines
add-cow file can't live alone, must together will
image_fileandbacking_file. If we implement qemu-img convert operation for add-cow file format, we must createimage_fileandbacking_filemanually, that will be confused for users, so we just ignore add-cow format while doing converting.Signed-off-by Dong Xu Wang <[email protected]>NACK.
Quoted 8 lines
This stupid "let's drop the feature, it might confuse users" attitude is known from Gnome, but not from qemu.
There's no technical reason to forbid it and anyone who manages to create a valid add-cow image will also be able to specify the very same options to a convert command. Also, having image format specific code in qemu-img is evil.
If I implement add-cow convert command, I am wondering which method should I use:
1) create add-cow, and its backing_file, and its image_file, then we need 3 files.
2) create add-cow(with all bitmap marked to allocated), and its image_file, then we
need 2 files.
2) will be easier, I should let .add-cow file can live only with image_file, without backing_file.
I think both 1) and 2) need add code to qemu-img.c. Or I will have to create image_file automaticly in add_cow_create function.
Can you give some comments on how to implement convert? Thanks.
Quoted 2 lines
Kevin
Re: [Qemu-devel] [PATCH 4/6] qemu-img: add-cow will not support convert
Am 14.06.2012 16:06, schrieb Dong Xu Wang:
Quoted 28 lines · Kevin Wolf
Quoted 10 lines
Am 13.06.2012 16:36, schrieb Dong Xu Wang:
Quoted 6 lines
add-cow file can't live alone, must together will
image_fileandbacking_file. If we implement qemu-img convert operation for add-cow file format, we must createimage_fileandbacking_filemanually, that will be confused for users, so we just ignore add-cow format while doing converting.Signed-off-by Dong Xu Wang <[email protected]>NACK.
Quoted 8 lines
This stupid "let's drop the feature, it might confuse users" attitude is known from Gnome, but not from qemu.
There's no technical reason to forbid it and anyone who manages to create a valid add-cow image will also be able to specify the very same options to a convert command. Also, having image format specific code in qemu-img is evil.
If I implement add-cow convert command, I am wondering which method should I use:
1) create add-cow, and itsbacking_file, and itsimage_file, then we need 3 files.
2) create add-cow(with all bitmap marked to allocated), and itsimage_file, then we
need 2 files.
Quoted 7 lines
2) will be easier, I should let .add-cow file can live only with
image_file, withoutbacking_file.I think both 1) and 2) need add code to
qemu-img.c. Or I will have to createimage_fileautomaticly inadd_cow_createfunction.Can you give some comments on how to implement convert? Thanks.
Just leave it alone and it will work.
qemu-img convert takes the same options as qemu-img create. So like for any other image you specify the backing file with -b or -o backing_file, and for add-cow images to be successfully created you also need to specify -o image_file.
Kevin
Re: [Qemu-devel] [PATCH 4/6] qemu-img: add-cow will not support convert
Quoted 35 lines · Kevin Wolf
Am 14.06.2012 16:06, schrieb Dong Xu Wang:
Quoted 34 lines · Kevin Wolf
Quoted 10 lines
Am 13.06.2012 16:36, schrieb Dong Xu Wang:
Quoted 6 lines
add-cow file can't live alone, must together will
image_fileandbacking_file. If we implement qemu-img convert operation for add-cow file format, we must createimage_fileandbacking_filemanually, that will be confused for users, so we just ignore add-cow format while doing converting.Signed-off-by Dong Xu Wang <[email protected]>NACK.
Quoted 8 lines
This stupid "let's drop the feature, it might confuse users" attitude is known from Gnome, but not from qemu.
There's no technical reason to forbid it and anyone who manages to create a valid add-cow image will also be able to specify the very same options to a convert command. Also, having image format specific code in qemu-img is evil.
If I implement add-cow convert command, I am wondering which method should I use:
1) create add-cow, and itsbacking_file, and itsimage_file, then we need 3 files.
2) create add-cow(with all bitmap marked to allocated), and itsimage_file, then we
need 2 files.2) will be easier, I should let .add-cow file can live only with
image_file, withoutbacking_file.I think both 1) and 2) need add code to
qemu-img.c. Or I will have to createimage_fileautomaticly inadd_cow_createfunction.
Quoted 9 lines
Quoted 1 line
Can you give some comments on how to implement convert? Thanks.
Just leave it alone and it will work.
qemu-img convert takes the same options as qemu-img create. So like for any other image you specify the backing file with -b or -o
backing_file, and for add-cow images to be successfully created you also need to specify -oimage_file.
"-o image_file", the image_file should be precreated? Or I should created it manually?
Quoted 2 lines
Kevin
Re: [Qemu-devel] [PATCH 4/6] qemu-img: add-cow will not support convert
Am 14.06.2012 16:17, schrieb Dong Xu Wang:
Quoted 40 lines · Kevin Wolf
Quoted 39 lines
Am 14.06.2012 16:06, schrieb Dong Xu Wang:
Quoted 28 lines · Kevin Wolf
Quoted 10 lines
Am 13.06.2012 16:36, schrieb Dong Xu Wang:
Quoted 6 lines
add-cow file can't live alone, must together will
image_fileandbacking_file. If we implement qemu-img convert operation for add-cow file format, we must createimage_fileandbacking_filemanually, that will be confused for users, so we just ignore add-cow format while doing converting.Signed-off-by Dong Xu Wang <[email protected]>NACK.
Quoted 8 lines
This stupid "let's drop the feature, it might confuse users" attitude is known from Gnome, but not from qemu.
There's no technical reason to forbid it and anyone who manages to create a valid add-cow image will also be able to specify the very same options to a convert command. Also, having image format specific code in qemu-img is evil.
If I implement add-cow convert command, I am wondering which method should I use:
1) create add-cow, and itsbacking_file, and itsimage_file, then we need 3 files.
2) create add-cow(with all bitmap marked to allocated), and itsimage_file, then we
need 2 files.Quoted 7 lines
2) will be easier, I should let .add-cow file can live only with
image_file, withoutbacking_file.I think both 1) and 2) need add code to
qemu-img.c. Or I will have to createimage_fileautomaticly inadd_cow_createfunction.Can you give some comments on how to implement convert? Thanks.
Just leave it alone and it will work.
Quoted 7 lines
Quoted 5 lines
qemu-img convert takes the same options as qemu-img create. So like for any other image you specify the backing file with -b or -o
backing_file, and for add-cow images to be successfully created you also need to specify -oimage_file."-o
image_file", theimage_fileshould be precreated? Or I should created it manually?
Yes, it must already exist. Just like with qemu-img create. To convert an existing qcow2 image that has a backing file 'base.img' to an add-cow image, you would use something like:
$ qemu-img create -f raw target.img 4G $ qemu-img convert -O add-cow -o image_file=target.img -B base.img source.qcow2 target.add-cow
Kevin
Re: [Qemu-devel] [PATCH 4/6] qemu-img: add-cow will not support convert
Quoted 53 lines · Kevin Wolf
Am 14.06.2012 16:17, schrieb Dong Xu Wang:
Quoted 40 lines · Kevin Wolf
Quoted 39 lines
Am 14.06.2012 16:06, schrieb Dong Xu Wang:
Quoted 28 lines · Kevin Wolf
Quoted 10 lines
Am 13.06.2012 16:36, schrieb Dong Xu Wang:
Quoted 6 lines
add-cow file can't live alone, must together will
image_fileandbacking_file. If we implement qemu-img convert operation for add-cow file format, we must createimage_fileandbacking_filemanually, that will be confused for users, so we just ignore add-cow format while doing converting.Signed-off-by Dong Xu Wang <[email protected]>NACK.
Quoted 8 lines
This stupid "let's drop the feature, it might confuse users" attitude is known from Gnome, but not from qemu.
There's no technical reason to forbid it and anyone who manages to create a valid add-cow image will also be able to specify the very same options to a convert command. Also, having image format specific code in qemu-img is evil.
If I implement add-cow convert command, I am wondering which method should I use:
1) create add-cow, and itsbacking_file, and itsimage_file, then we need 3 files.
2) create add-cow(with all bitmap marked to allocated), and itsimage_file, then we
need 2 files.Quoted 7 lines
2) will be easier, I should let .add-cow file can live only with
image_file, withoutbacking_file.I think both 1) and 2) need add code to
qemu-img.c. Or I will have to createimage_fileautomaticly inadd_cow_createfunction.Can you give some comments on how to implement convert? Thanks.
Just leave it alone and it will work.
Quoted 7 lines
Quoted 5 lines
qemu-img convert takes the same options as qemu-img create. So like for any other image you specify the backing file with -b or -o
backing_file, and for add-cow images to be successfully created you also need to specify -oimage_file."-o
image_file", theimage_fileshould be precreated? Or I should created it manually?Yes, it must already exist. Just like with qemu-img create. To convert an existing qcow2 image that has a backing file 'base.img' to an add-cow image, you would use something like:
Quoted 6 lines
$ qemu-img create -f raw target.img 4G $ qemu-img convert -O add-cow -o image_file=target.img -B base.img source.qcow2 target.add-cowKevin
Got it, thanks
PATCH 5/6 add-cow: support snapshot_blkdev
In reply to Dong Xu Wangadd-cow will let raw file support snapshot_blkdev indirectly.
--- blockdev.c | 31 +++++++++++++++++++++++++++---- docs/live-block-ops.txt | 10 +++++++++- 2 files changed, 36 insertions(+), 5 deletions(-)
blockdev.c +27 -4
@@ -783,15 +783,38 @@ void qmp_transaction(BlockdevActionList *dev_list, Error **errp)/* create new image w/backing file */ if (mode !=NEW_IMAGE_MODE_EXISTING ) { - ret =bdrv_img_create (new_image_file, format, +if (strcmp (format,"add-cow" )) { + ret =bdrv_img_create (new_image_file, format, states->old_bs->filename, states->old_bs->drv->format_name,NULL ,-1 , flags); -if (ret) { -error_set (errp,QERR_OPEN_FILE_FAILED , new_image_file); - goto delete_and_fail; + }else { +char image_file[1024 ]; +char option[1024 ]; +uint64_t size; + +bdrv_get_geometry (states->old_bs, &size); + size *=BDRV_SECTOR_SIZE ; + +sprintf (image_file,"%s.raw" , new_image_file); + + ret =bdrv_img_create (image_file,"raw" ,NULL , +NULL ,NULL , size, flags); +if (ret) { +error_set (errp,QERR_UNDEFINED_ERROR ); +return ; + } +sprintf (option,"image_file=%s.raw" , new_image_file); + ret =bdrv_img_create (new_image_file, format, + states->old_bs->filename, + states->old_bs->drv->format_name, + option,-1 , flags); } } +if (ret) { +error_set (errp,QERR_OPEN_FILE_FAILED , new_image_file); + goto delete_and_fail; + }/* We will manually add the backing_hd field to the bs later */ states->new_bs =bdrv_new ("" );
docs/live-block-ops.txt +9 -1
@@ -2,7 +2,8 @@ LIVE BLOCK OPERATIONS ===================== High level description of live block operations. Note these are not -supported for use with the raw format at the moment. +supported for use with the raw format at the moment, but we can use +add-cow as metadata to suport raw format. Snapshot live merge ===================
@@ -56,3 +57,10 @@ into that image. Example: (qemu) block_stream ide0-hd0 + +Raw is not supported, but we can use add-cow in the 1st step: + +(qemu) snapshot_blkdev ide0-hd0 /new-path/disk.img add-cow + +It will create a raw file named disk.img.raw, with the same virtual size of +ide0-hd0 first, and then create disk.img.
Signature · 1 line
1.7.1
Re: [Qemu-devel] [PATCH 5/6] add-cow: support snapshot_blkdev
Am 13.06.2012 16:36, schrieb Dong Xu Wang:
Quoted 3 lines
add-cow will let raw file support
snapshot_blkdevindirectly.Signed-off-by Dong Xu Wang <[email protected]>
Paolo, what do you think about this magic?
I think I can see its use especially for HMP because it's quite convenient, but on the other hand it assumes a fixed image path for the new raw image. This isn't going to work for block devices, for example.
If we don't do it this way, we need to allow passing image creation options to the snapshotting command so that you can pass a precreated image file.
Kevin
Quoted 77 lines
--- blockdev.c | 31 +++++++++++++++++++++++++++---- docs/live-block-ops.txt | 10 +++++++++- 2 files changed, 36 insertions(+), 5 deletions(-)blockdev.c +27
-4@@ -783,15 +783,38 @@ void qmp_transaction(BlockdevActionList *dev_list, Error **errp)/* create new image w/backing file */ if (mode !=NEW_IMAGE_MODE_EXISTING ) { - ret =bdrv_img_create (new_image_file, format, +if (strcmp (format,"add-cow" )) { + ret =bdrv_img_create (new_image_file, format, states->old_bs->filename, states->old_bs->drv->format_name,NULL ,-1 , flags); -if (ret) { -error_set (errp,QERR_OPEN_FILE_FAILED , new_image_file); - goto delete_and_fail; + }else { +char image_file[1024 ]; +char option[1024 ]; +uint64_t size; + +bdrv_get_geometry (states->old_bs, &size); + size *=BDRV_SECTOR_SIZE ; + +sprintf (image_file,"%s.raw" , new_image_file); + + ret =bdrv_img_create (image_file,"raw" ,NULL , +NULL ,NULL , size, flags); +if (ret) { +error_set (errp,QERR_UNDEFINED_ERROR ); +return ; + } +sprintf (option,"image_file=%s.raw" , new_image_file); + ret =bdrv_img_create (new_image_file, format, + states->old_bs->filename, + states->old_bs->drv->format_name, + option,-1 , flags); } } +if (ret) { +error_set (errp,QERR_OPEN_FILE_FAILED , new_image_file); + goto delete_and_fail; + }/* We will manually add the backing_hd field to the bs later */ states->new_bs =bdrv_new ("" );docs/live-block-ops.txt +9
-1@@ -2,7 +2,8 @@ LIVE BLOCK OPERATIONS ===================== High level description of live block operations. Note these are not -supported for use with the raw format at the moment. +supported for use with the raw format at the moment, but we can use +add-cow as metadata to suport raw format. Snapshot live merge ===================@@ -56,3 +57,10 @@ into that image. Example: (qemu) block_stream ide0-hd0 + +Raw is not supported, but we can use add-cow in the 1st step: + +(qemu) snapshot_blkdev ide0-hd0 /new-path/disk.img add-cow + +It will create a raw file named disk.img.raw, with the same virtual size of +ide0-hd0 first, and then create disk.img.
Re: [Qemu-devel] [PATCH 5/6] add-cow: support snapshot_blkdev
Il 14/06/2012 12:59, Kevin Wolf ha scritto:
Quoted 6 lines
Am 13.06.2012 16:36, schrieb Dong Xu Wang:
Quoted 3 lines
add-cow will let raw file support
snapshot_blkdevindirectly.Signed-off-by Dong Xu Wang <[email protected]>Paolo, what do you think about this magic?
Besides the obvious layering violation (it would be better to add a new method bdrv_ext_snapshot_create perhaps) I don't see very much a problem in it. Passing image creation options sounds like a good idea that we can add in the future as an extension.
But honestly, I don't really see the point of add-cow in general... The raw image is anyway not usable without a pass through qemu-io convert, and mirroring will also allow collapsing an image to raw (with the persistent dirty bitmap playing the role of the add-cow metadata).
Quoted 3 lines
I think I can see its use especially for HMP because it's quite convenient, but on the other hand it assumes a fixed image path for the new raw image. This isn't going to work for block devices, for example.
True, but then probably you would use mode='existing', because you need to pre-create the logical volume.
Quoted 3 lines
If we don't do it this way, we need to allow passing image creation options to the snapshotting command so that you can pass a precreated image file.
This sounds like a useful extension anyway, except that passing an unstructured string for image creation options is ugly... Perhaps we can base a better implementation of options on Laszlo's QemuOpts visitor.
Paolo
Quoted 83 lines
Kevin
Quoted 77 lines
--- blockdev.c | 31 +++++++++++++++++++++++++++---- docs/live-block-ops.txt | 10 +++++++++- 2 files changed, 36 insertions(+), 5 deletions(-)blockdev.c +27
-4@@ -783,15 +783,38 @@ void qmp_transaction(BlockdevActionList *dev_list, Error **errp)/* create new image w/backing file */ if (mode !=NEW_IMAGE_MODE_EXISTING ) { - ret =bdrv_img_create (new_image_file, format, +if (strcmp (format,"add-cow" )) { + ret =bdrv_img_create (new_image_file, format, states->old_bs->filename, states->old_bs->drv->format_name,NULL ,-1 , flags); -if (ret) { -error_set (errp,QERR_OPEN_FILE_FAILED , new_image_file); - goto delete_and_fail; + }else { +char image_file[1024 ]; +char option[1024 ]; +uint64_t size; + +bdrv_get_geometry (states->old_bs, &size); + size *=BDRV_SECTOR_SIZE ; + +sprintf (image_file,"%s.raw" , new_image_file); + + ret =bdrv_img_create (image_file,"raw" ,NULL , +NULL ,NULL , size, flags); +if (ret) { +error_set (errp,QERR_UNDEFINED_ERROR ); +return ; + } +sprintf (option,"image_file=%s.raw" , new_image_file); + ret =bdrv_img_create (new_image_file, format, + states->old_bs->filename, + states->old_bs->drv->format_name, + option,-1 , flags); } } +if (ret) { +error_set (errp,QERR_OPEN_FILE_FAILED , new_image_file); + goto delete_and_fail; + }/* We will manually add the backing_hd field to the bs later */ states->new_bs =bdrv_new ("" );docs/live-block-ops.txt +9
-1@@ -2,7 +2,8 @@ LIVE BLOCK OPERATIONS ===================== High level description of live block operations. Note these are not -supported for use with the raw format at the moment. +supported for use with the raw format at the moment, but we can use +add-cow as metadata to suport raw format. Snapshot live merge ===================@@ -56,3 +57,10 @@ into that image. Example: (qemu) block_stream ide0-hd0 + +Raw is not supported, but we can use add-cow in the 1st step: + +(qemu) snapshot_blkdev ide0-hd0 /new-path/disk.img add-cow + +It will create a raw file named disk.img.raw, with the same virtual size of +ide0-hd0 first, and then create disk.img.
Re: [Qemu-devel] [PATCH 5/6] add-cow: support snapshot_blkdev
Am 14.06.2012 13:18, schrieb Paolo Bonzini:
Quoted 13 lines
Il 14/06/2012 12:59, Kevin Wolf ha scritto:
Quoted 6 lines
Am 13.06.2012 16:36, schrieb Dong Xu Wang:
Quoted 3 lines
add-cow will let raw file support
snapshot_blkdevindirectly.Signed-off-by Dong Xu Wang <[email protected]>Paolo, what do you think about this magic?
Besides the obvious layering violation (it would be better to add a new method
bdrv_ext_snapshot_createperhaps) I don't see very much a problem in it. Passing image creation options sounds like a good idea that we can add in the future as an extension.
Quoted 4 lines
But honestly, I don't really see the point of add-cow in general... The raw image is anyway not usable without a pass through qemu-io convert, and mirroring will also allow collapsing an image to raw (with the persistent dirty bitmap playing the role of the add-cow metadata).
Well, the idea was that you stream into add-cow and once the streaming has completed, you can just drop the bitmap.
There might be some overlap with mirroring, though when we discussed introducing add-cow, mirrors were not yet on the table. One difference that remains is that with streaming the guest only writes to the target image and can't have any problem with convergence.
Quoted 6 lines
Quoted 3 lines
I think I can see its use especially for HMP because it's quite convenient, but on the other hand it assumes a fixed image path for the new raw image. This isn't going to work for block devices, for example.
True, but then probably you would use mode='existing', because you need to pre-create the logical volume.
I think it might be convenient to have the raw volume precreated (you need to do that anyway), but create the COW bitmap only during the snapshot command. But yeah, not really important.
Quoted 7 lines
Quoted 3 lines
If we don't do it this way, we need to allow passing image creation options to the snapshotting command so that you can pass a precreated image file.
This sounds like a useful extension anyway, except that passing an unstructured string for image creation options is ugly... Perhaps we can base a better implementation of options on Laszlo's QemuOpts visitor.
Yes, I wouldn't want to use a string here, we should use something structured. Image creation still uses the old-style options instead of QemuOpts, but maybe this is the opportunity to convert it.
Kevin
Re: [Qemu-devel] [PATCH 5/6] add-cow: support snapshot_blkdev
Quoted 42 lines · Kevin Wolf
Am 14.06.2012 13:18, schrieb Paolo Bonzini:
Quoted 13 lines
Il 14/06/2012 12:59, Kevin Wolf ha scritto:
Quoted 6 lines
Am 13.06.2012 16:36, schrieb Dong Xu Wang:
Quoted 3 lines
add-cow will let raw file support
snapshot_blkdevindirectly.Signed-off-by Dong Xu Wang <[email protected]>Paolo, what do you think about this magic?
Besides the obvious layering violation (it would be better to add a new method
bdrv_ext_snapshot_createperhaps) I don't see very much a problem in it. Passing image creation options sounds like a good idea that we can add in the future as an extension.Quoted 4 lines
But honestly, I don't really see the point of add-cow in general... The raw image is anyway not usable without a pass through qemu-io convert, and mirroring will also allow collapsing an image to raw (with the persistent dirty bitmap playing the role of the add-cow metadata).
Well, the idea was that you stream into add-cow and once the streaming has completed, you can just drop the bitmap.
There might be some overlap with mirroring, though when we discussed introducing add-cow, mirrors were not yet on the table. One difference that remains is that with streaming the guest only writes to the target image and can't have any problem with convergence.
Quoted 6 lines
Quoted 3 lines
I think I can see its use especially for HMP because it's quite convenient, but on the other hand it assumes a fixed image path for the new raw image. This isn't going to work for block devices, for example.
True, but then probably you would use mode='existing', because you need to pre-create the logical volume.
I think it might be convenient to have the raw volume precreated (you need to do that anyway), but create the COW bitmap only during the snapshot command. But yeah, not really important.
Quoted 4 lines
Quoted 3 lines
If we don't do it this way, we need to allow passing image creation options to the snapshotting command so that you can pass a precreated image file.
Quoted 7 lines
Quoted 3 lines
This sounds like a useful extension anyway, except that passing an unstructured string for image creation options is ugly... Perhaps we can base a better implementation of options on Laszlo's QemuOpts visitor.
Yes, I wouldn't want to use a string here, we should use something structured. Image creation still uses the old-style options instead of QemuOpts, but maybe this is the opportunity to convert it.
Kevin, do you mean I need to replace QEMUOptionParameter with QemuOpts?
If true, other image formats should also be changed, I noticed Stefan has an un-comleted patch:
http://repo.or.cz/w/qemu/stefanha.git/commitdiff/b49babb2c8b476a36357cfd7276ca45a11039ca5
then I can work based on Stefan's patch.
Quoted 3 lines
Kevin
Re: [Qemu-devel] [PATCH 5/6] add-cow: support snapshot_blkdev
Am 19.07.2012 04:20, schrieb Dong Xu Wang:
Quoted 51 lines · Kevin Wolf
Quoted 42 lines
Am 14.06.2012 13:18, schrieb Paolo Bonzini:
Quoted 13 lines
Il 14/06/2012 12:59, Kevin Wolf ha scritto:
Quoted 6 lines
Am 13.06.2012 16:36, schrieb Dong Xu Wang:
Quoted 3 lines
add-cow will let raw file support
snapshot_blkdevindirectly.Signed-off-by Dong Xu Wang <[email protected]>Paolo, what do you think about this magic?
Besides the obvious layering violation (it would be better to add a new method
bdrv_ext_snapshot_createperhaps) I don't see very much a problem in it. Passing image creation options sounds like a good idea that we can add in the future as an extension.Quoted 4 lines
But honestly, I don't really see the point of add-cow in general... The raw image is anyway not usable without a pass through qemu-io convert, and mirroring will also allow collapsing an image to raw (with the persistent dirty bitmap playing the role of the add-cow metadata).
Well, the idea was that you stream into add-cow and once the streaming has completed, you can just drop the bitmap.
There might be some overlap with mirroring, though when we discussed introducing add-cow, mirrors were not yet on the table. One difference that remains is that with streaming the guest only writes to the target image and can't have any problem with convergence.
Quoted 6 lines
Quoted 3 lines
I think I can see its use especially for HMP because it's quite convenient, but on the other hand it assumes a fixed image path for the new raw image. This isn't going to work for block devices, for example.
True, but then probably you would use mode='existing', because you need to pre-create the logical volume.
I think it might be convenient to have the raw volume precreated (you need to do that anyway), but create the COW bitmap only during the snapshot command. But yeah, not really important.
Quoted 4 lines
Quoted 3 lines
If we don't do it this way, we need to allow passing image creation options to the snapshotting command so that you can pass a precreated image file.
Quoted 7 lines
Quoted 3 lines
This sounds like a useful extension anyway, except that passing an unstructured string for image creation options is ugly... Perhaps we can base a better implementation of options on Laszlo's QemuOpts visitor.
Yes, I wouldn't want to use a string here, we should use something structured. Image creation still uses the old-style options instead of QemuOpts, but maybe this is the opportunity to convert it.
Quoted 7 lines
Kevin, do you mean I need to replace QEMUOptionParameter with QemuOpts?
If true, other image formats should also be changed, I noticed Stefan has an un-comleted patch:
http://repo.or.cz/w/qemu/stefanha.git/commitdiff/b49babb2c8b476a36357cfd7276ca45a11039ca5then I can work based on Stefan's patch.
Yes, the direction of this patch from Stefan's repo looks good.
I'm not sure whether it will immediately allow passing structured image creation options in QMP, though. It might work using the old-style monitor commands, just getting a QDict from the options. Not quite sure how this is going to work with QAPI.
Kevin
Re: [Qemu-devel] [PATCH 5/6] add-cow: support snapshot_blkdev
Quoted 58 lines · On Thu, 19 Jul 2012 10:17:10 +0200 Kevin Wolf <[email protected]> wrote:
Am 19.07.2012 04:20, schrieb Dong Xu Wang:
Quoted 57 lines · Kevin Wolf
Quoted 42 lines
Am 14.06.2012 13:18, schrieb Paolo Bonzini:
Quoted 13 lines
Il 14/06/2012 12:59, Kevin Wolf ha scritto:
Quoted 6 lines
Am 13.06.2012 16:36, schrieb Dong Xu Wang:
Quoted 3 lines
add-cow will let raw file support
snapshot_blkdevindirectly.Signed-off-by Dong Xu Wang <[email protected]>Paolo, what do you think about this magic?
Besides the obvious layering violation (it would be better to add a new method
bdrv_ext_snapshot_createperhaps) I don't see very much a problem in it. Passing image creation options sounds like a good idea that we can add in the future as an extension.Quoted 4 lines
But honestly, I don't really see the point of add-cow in general... The raw image is anyway not usable without a pass through qemu-io convert, and mirroring will also allow collapsing an image to raw (with the persistent dirty bitmap playing the role of the add-cow metadata).
Well, the idea was that you stream into add-cow and once the streaming has completed, you can just drop the bitmap.
There might be some overlap with mirroring, though when we discussed introducing add-cow, mirrors were not yet on the table. One difference that remains is that with streaming the guest only writes to the target image and can't have any problem with convergence.
Quoted 6 lines
Quoted 3 lines
I think I can see its use especially for HMP because it's quite convenient, but on the other hand it assumes a fixed image path for the new raw image. This isn't going to work for block devices, for example.
True, but then probably you would use mode='existing', because you need to pre-create the logical volume.
I think it might be convenient to have the raw volume precreated (you need to do that anyway), but create the COW bitmap only during the snapshot command. But yeah, not really important.
Quoted 4 lines
Quoted 3 lines
If we don't do it this way, we need to allow passing image creation options to the snapshotting command so that you can pass a precreated image file.
Quoted 7 lines
Quoted 3 lines
This sounds like a useful extension anyway, except that passing an unstructured string for image creation options is ugly... Perhaps we can base a better implementation of options on Laszlo's QemuOpts visitor.
Yes, I wouldn't want to use a string here, we should use something structured. Image creation still uses the old-style options instead of QemuOpts, but maybe this is the opportunity to convert it.
Kevin, do you mean I need to replace QEMUOptionParameter with QemuOpts?
If true, other image formats should also be changed, I noticed Stefan has an un-comleted patch:
http://repo.or.cz/w/qemu/stefanha.git/commitdiff/b49babb2c8b476a36357cfd7276ca45a11039ca5
Quoted 8 lines
Quoted 1 line
then I can work based on Stefan's patch.
Yes, the direction of this patch from Stefan's repo looks good.
I'm not sure whether it will immediately allow passing structured image creation options in QMP, though. It might work using the old-style monitor commands, just getting a QDict from the options. Not quite sure how this is going to work with QAPI.
We did it for netdev_add and it works as you said above. The schema entry looks like this:
{ 'command': 'netdev_add',
'data': {'type': 'str', 'id': 'str', '*props': '**'}, 'gen': 'no' }
Where 'props' is:
# @props: #optional a list of properties to be passed to the backend in
# the format 'name=value', like 'ifname=tap0,script=no'
Then we have the qmp front-end, using the old style monitor signature:
int qmp_netdev_add(Monitor *mon, const QDict *qdict, QObject **ret);
And we have the HMP front-end (which should be used elsewhere too):
void netdev_add(QemuOpts *opts, Error **errp);
As Paolo said, Laszlo's work will help us to this the right way.
Re: [Qemu-devel] [PATCH 5/6] add-cow: support snapshot_blkdev
In reply to Dong Xu WangQuoted 51 lines · Dong Xu Wang
Quoted 42 lines · Kevin Wolf
Am 14.06.2012 13:18, schrieb Paolo Bonzini:
Quoted 13 lines
Il 14/06/2012 12:59, Kevin Wolf ha scritto:
Quoted 6 lines
Am 13.06.2012 16:36, schrieb Dong Xu Wang:
Quoted 3 lines
add-cow will let raw file support
snapshot_blkdevindirectly.Signed-off-by Dong Xu Wang <[email protected]>Paolo, what do you think about this magic?
Besides the obvious layering violation (it would be better to add a new method
bdrv_ext_snapshot_createperhaps) I don't see very much a problem in it. Passing image creation options sounds like a good idea that we can add in the future as an extension.Quoted 4 lines
But honestly, I don't really see the point of add-cow in general... The raw image is anyway not usable without a pass through qemu-io convert, and mirroring will also allow collapsing an image to raw (with the persistent dirty bitmap playing the role of the add-cow metadata).
Well, the idea was that you stream into add-cow and once the streaming has completed, you can just drop the bitmap.
There might be some overlap with mirroring, though when we discussed introducing add-cow, mirrors were not yet on the table. One difference that remains is that with streaming the guest only writes to the target image and can't have any problem with convergence.
Quoted 6 lines
Quoted 3 lines
I think I can see its use especially for HMP because it's quite convenient, but on the other hand it assumes a fixed image path for the new raw image. This isn't going to work for block devices, for example.
True, but then probably you would use mode='existing', because you need to pre-create the logical volume.
I think it might be convenient to have the raw volume precreated (you need to do that anyway), but create the COW bitmap only during the snapshot command. But yeah, not really important.
Quoted 4 lines
Quoted 3 lines
If we don't do it this way, we need to allow passing image creation options to the snapshotting command so that you can pass a precreated image file.
Quoted 7 lines
Quoted 3 lines
This sounds like a useful extension anyway, except that passing an unstructured string for image creation options is ugly... Perhaps we can base a better implementation of options on Laszlo's QemuOpts visitor.
Yes, I wouldn't want to use a string here, we should use something structured. Image creation still uses the old-style options instead of QemuOpts, but maybe this is the opportunity to convert it.
Quoted 7 lines
Kevin, do you mean I need to replace QEMUOptionParameter with QemuOpts?
If true, other image formats should also be changed, I noticed Stefan has an un-comleted patch:
http://repo.or.cz/w/qemu/stefanha.git/commitdiff/b49babb2c8b476a36357cfd7276ca45a11039ca5then I can work based on Stefan's patch.
It's been a while so I don't remember details, but if you want to discuss more let me know and I'll refresh my memory.
Stefan
PATCH 6/6 add-cow: support qemu-iotests
In reply to Dong Xu Wangadd qemu-iotests support for add-cow file format. add-cow need not support convert operation, so not all tests cases related to backing_file are involved.
--- tests/qemu-iotests/017 | 2 +- tests/qemu-iotests/020 | 2 +- tests/qemu-iotests/check | 4 ++-- tests/qemu-iotests/common | 6 ++++++ tests/qemu-iotests/common.rc | 19 +++++++++++++++++++ 5 files changed, 29 insertions(+), 4 deletions(-)
tests/qemu-iotests/017 +1 -1
@@ -40,7 +40,7 @@ trap "_cleanup; exit \$status" 0 1 2 3 15 . ./common.pattern # Any format supporting backing files -_supported_fmt qcow qcow2 vmdk qed +_supported_fmt qcow qcow2 vmdk qed add-cow _supported_proto generic _supported_os Linux
tests/qemu-iotests/020 +1 -1
@@ -42,7 +42,7 @@ trap "_cleanup; exit \$status" 0 1 2 3 15 . ./common.pattern # Any format supporting backing files -_supported_fmt qcow qcow2 vmdk qed +_supported_fmt qcow qcow2 vmdk qed add-cow _supported_proto generic _supported_os Linux
tests/qemu-iotests/check +2 -2
@@ -243,7 +243,7 @@ do echo " - no qualified output" err=true else - if diff -w $seq.out $tmp.out >/dev/null 2>&1 + if diff -w -I "^Formatting" $seq.out $tmp.out >/dev/null 2>&1 then echo "" if $err
@@ -255,7 +255,7 @@ do else echo " - output mismatch (see $seq.out.bad)" mv $tmp.out $seq.out.bad - $diff -w $seq.out $seq.out.bad + $diff -w -I "^Formatting" $seq.out $seq.out.bad err=true fi fi
tests/qemu-iotests/common +6 -0
@@ -127,6 +127,7 @@ common options check options -raw test raw (default) -cow test cow + -add-cow test add-cow -qcow test qcow -qcow2 test qcow2 -qed test qed
@@ -162,6 +163,11 @@ testlist options xpand=false ;; + -add-cow) + IMGFMT=add-cow + xpand=false + ;; + -qcow) IMGFMT=qcow xpand=false
tests/qemu-iotests/common.rc +19 -0
@@ -87,6 +87,18 @@ _make_test_img() fi if [ \( "$IMGFMT" = "qcow2" -o "$IMGFMT" = "qed" \) -a -n "$CLUSTER_SIZE" ]; then optstr=$(_optstr_add "$optstr" "cluster_size=$CLUSTER_SIZE") + elif [ "$IMGFMT" = "add-cow" ]; then + local BACKING="$TEST_IMG"".qcow2" + local IMG="$TEST_IMG"".raw" + if [ "$1" = "-b" ]; then + IMG="$IMG"".b" + $QEMU_IMG create -f raw $IMG $image_size>/dev/null + extra_img_options="-o image_file=$IMG $extra_img_options" + else + $QEMU_IMG create -f raw $IMG $image_size>/dev/null + $QEMU_IMG create -f qcow2 $BACKING $image_size>/dev/null + extra_img_options="-o backing_file=$BACKING,image_file=$IMG" + fi fi if [ -n "$optstr" ]; then
@@ -114,6 +126,13 @@ _cleanup_test_img() rm -f $TEST_DIR/t.$IMGFMT rm -f $TEST_DIR/t.$IMGFMT.orig rm -f $TEST_DIR/t.$IMGFMT.base + if [ "$IMGFMT" = "add-cow" ]; then + rm -f $TEST_DIR/t.$IMGFMT.qcow2 + rm -f $TEST_DIR/t.$IMGFMT.raw + rm -f $TEST_DIR/t.$IMGFMT.raw.b + rm -f $TEST_DIR/t.$IMGFMT.ct.qcow2 + rm -f $TEST_DIR/t.$IMGFMT.ct.raw + fi ;; rbd)
Signature · 1 line
1.7.1
Quoted 16 lines · Dong Xu Wang
Introduce a new file format:add-cow. The usage can be found at this patch.
Signed-off-by Dong Xu Wang <[email protected]>--- docs/specs/add-cow.txt | 87 ++++++++++++++++++++++++++++++++++++++++++++++++ 1 files changed, 87 insertions(+), 0 deletions(-) create mode 100644 docs/specs/add-cow.txtdocs/specs/add-cow.txt new file +2
-0@@ -0,0 +1,87 @@ +== General == +
docs/specs/add-cow.txt line 12
Quoted 10 lines
docs/specs/add-cow.txt new file +10
-0+Raw file format does not support backing_file and copy on write feature. +The add-cow image format makes it possible to use backing files with raw +image by keeping a separate .add-cow metadata file. Once all sectors +have been written into the raw image it is safe to discard the .add-cow +and backing files, then we can use the raw image directly. + +While using add-cow, procedures may like this: +(ubuntu.img is a disk image which has been installed OS.) + 1) Create a raw image with the same size of ubuntu.img + qemu-img create -f raw test.raw 8G
Make sure we also support a raw file larger than the backing file.
Does it matter whether the raw file starts life sparse?
docs/specs/add-cow.txt line 17
Quoted 5 lines
docs/specs/add-cow.txt new file +5
-0+ 2) Create an add-cow image which will store dirty bitmap + qemu-img create -f add-cow test.add-cow \ + -o backing_file=ubuntu.img,image_file=test.raw + 3) Run qemu with add-cow image + qemu -drive if=virtio,file=test.add-cow
How does this interact with live snapshots/live disk mirroring? Is this something where I have to call 'block-stream' to pull data into the new raw file on-demand? I take it that test.add-cow is required until the block-stream completes? Is there a way, while qemu is still running, but after the block-stream is complete, to reassociate the drive with the actual raw file instead of the add-cow, or does the add-cow have to remain around as long as the qemu process is still running?
docs/specs/add-cow.txt line 27
Quoted 10 lines
docs/specs/add-cow.txt new file +10
-0+ +=Specification= + +The file format looks like this: + + +---------------+-------------+-----------------+ + | Header | Reserved | COW bitmap | + +---------------+-------------+-----------------+ + +All numbers in add-cow are stored in Little Endian byte order.
Okay, but different than network byte order, which means we can't use htonl() and friends to convert host bytes into the proper format. <endian.h> is not (yet) standardized, although there is talk of adding it to the next version of POSIX, in which case htole32() and friends would be guaranteed.
Quoted 5 lines
docs/specs/add-cow.txt new file +5
-0+ +== Header == + +The Header is included in the first bytes: +
docs/specs/add-cow.txt line 42
Quoted 10 lines
docs/specs/add-cow.txt new file +10
-0+ Byte 0 - 7: magic + add-cow magic string ("ADD_COW\xff") + + 8 - 11: version + Version number (only valid value is 1 now) + + 12 - 15: backing_filename_offset + Offset in the add-cow file at which the backing file name + is stored (NB: The string is not null terminated). 0 if the + image doesn't have a backing file.
Mention that if this is not 0, then it must be between 36 and 4094 (a file name must be at least 1 byte). What are the semantics if the filename is relative?
docs/specs/add-cow.txt line 46
Quoted 4 lines
docs/specs/add-cow.txt new file +4
-0+ + 16 - 19: backing_filename_size + Length of the backing file name in bytes. Undefined if the + image doesn't have a backing file.
Better to require 0 if backing_filename_offset is 0, than to leave this field undefined; also if backing_filename_offset is non-zero, then this must be non-zero. Must be less than 4096-36 to fit in the reserved part of the header.
docs/specs/add-cow.txt line 50
Quoted 4 lines
docs/specs/add-cow.txt new file +4
-0+ + 20 - 23: image_filename_offset + Offset in the add-cow file at which the image_file name + is stored (NB: The string is not null terminated).
Mention that this must be between 36 and 4094 (a file name must be at least 1 byte). What are the semantics if the filename is relative?
docs/specs/add-cow.txt line 53
Quoted 3 lines
docs/specs/add-cow.txt new file +3
-0+ + 24 - 27: image_filename_size + Length of the image_file name in bytes.
If backing_filename_offset is non-zero, then this must be non-zero. Must be less than 4096-36 to fit in the reserved part of the header.
May image_filename and backing_filename overlap (possible if one is a suffix of the other)? Are there any constraints to prevent infinite loops, such as forbidding backing_filename and image_filename from resolving either to the same file or to the add-cow file?
docs/specs/add-cow.txt line 61
Quoted 8 lines
docs/specs/add-cow.txt new file +8
-0+ + 28 - 35: features + Currently only 2 feature bits are used: + Feature bits: + The image uses a backing file: + * ADD_COW_F_BACKING_FILE = 0x01. + The backing file's format is raw: + * ADD_COW_F_BACKING_FORMAT_NO_PROBE = 0x02.
Should this follow the qcow2v3 proposal of splitting into mandatory vs. optional feature bits?
I agree that ADD_COW_F_BACKING_FORMAT_NO_PROBE is sufficient to avoid security implications, but do we want the extra flexibility of specifying the backing format file format rather than just requiring probes on all but raw?
docs/specs/add-cow.txt line 68
Quoted 7 lines
docs/specs/add-cow.txt new file +7
-0+ +== Reserved == + + Byte 36 - 4095: Reserved field: + It is used to make sure COW bitmap field starts at the + 4096th byte, backing_file name and image_file name will + be stored here.
Do we want to keep a fixed-size header, or should we be planning on the possibility of future extensions requiring enough other header extensions that a variable-sized header would be wiser? That is, I'm fine with requiring that the header be a multiple of 4k, but maybe it would make sense to have a mandatory header field that states how many header pages are present before the COW bitmap begins. In the first round of implementation, this header field can be required to be 1 (that is, for now, we require exactly 4k header), but having the field would let us change in the future to a design with an 8k header to hold more metadata as needed.
Quoted 9 lines
docs/specs/add-cow.txt new file +9
-0+ +== COW bitmap == + +The "COW bitmap" field starts at the 4096th byte, stores a bitmap related to +backing_file and image_file. The bitmap will track whether the sector in +backing_file is dirty or not. + +Each bit in the bitmap indicates one cluster's status. One cluster includes 128 +sectors, then each bit indicates 512 * 128 = 64k bytes, So the size of bitmap is
docs/specs/add-cow.txt line 87
Quoted 10 lines
docs/specs/add-cow.txt new file +10
-0+calculated according to virtual size of image_file. In each byte, bit 0 to 7 +will track the 1st to 7th cluster in sequence, bit orders in one byte look like: + +----+----+----+----+----+----+----+----+ + | b7 | b6 | b5 | b4 | b3 | b2 | b1 | b0 | + +----+----+----+----+----+----+----+----+ + +If the bit is 0, indicates the sector has not been allocated in image_file, data +should be loaded from backing_file while reading; if the bit is 1, indicates the +related sector has been dirty, should be loaded from image_file while reading. +Writing to a sector causes the corresponding bit to be set to 1.
So basically an add-cow image is thin as long as at least one bit is 0, and the add-cow wrapper can only be discarded when all bits are 1.
How do you handle the case where the raw image is not an even multiple of cluster bytes? That is, do bits that correspond to bytes beyond the raw file size have to be in a certain state?
Signature · 2 lines
Eric Blake [email protected] +1-919-301-3266 Libvirt virtualization library http://libvirt.org
Quoted 21 lines · Eric Blake
Quoted 20 lines · Dong Xu Wang
Introduce a new file format:add-cow. The usage can be found at this patch.
Signed-off-by Dong Xu Wang <[email protected]>---
docs/specs/add-cow.txt | 87 ++++++++++++++++++++++++++++++++++++++++++++++++1 files changed, 87 insertions(+), 0 deletions(-)create mode 100644
docs/specs/add-cow.txtdocs/specs/add-cow.txt new file +6
-0@@ -0,0 +1,87 @@ +== General == + +Raw file format does not support backing_file and copy on write feature. +The add-cow image format makes it possible to use backing files with raw +image by keeping a separate .add-cow metadata file. Once all sectors +have been written into the raw image it is safe to discard the .add-cow
Quoted 9 lines
docs/specs/add-cow.txt line 12
Quoted 6 lines
docs/specs/add-cow.txt new file +6
-0+and backing files, then we can use the raw image directly. + +While using add-cow, procedures may like this: +(ubuntu.img is a disk image which has been installed OS.) + 1) Create a raw image with the same size of ubuntu.img + qemu-img create -f raw test.raw 8GMake sure we also support a raw file larger than the backing file.
Okay, in this version, I just truncate raw file with the same size of backing_file,
I will correct this in v11.
Quoted 1 line
Does it matter whether the raw file starts life sparse?
No, it can work with sparse raw file.
Quoted 7 lines
docs/specs/add-cow.txt line 17
Quoted 6 lines
docs/specs/add-cow.txt new file +5
-0+ 2) Create an add-cow image which will store dirty bitmap + qemu-img create -f add-cow test.add-cow \ + -o backing_file=ubuntu.img,image_file=test.raw + 3) Run qemu with add-cow image + qemu -drive if=virtio,file=test.add-cow
Quoted 8 lines
How does this interact with live snapshots/live disk mirroring? Is this something where I have to call 'block-stream' to pull data into the new raw file on-demand? I take it that test.add-cow is required until the block-stream completes? Is there a way, while qemu is still running, but after the block-stream is complete, to reassociate the drive with the actual raw file instead of the add-cow, or does the add-cow have to remain around as long as the qemu process is still running?
I did not touch snapshots/live disk mirroring code much, so have to call "block_stream".
Now, add-cow has to remain until qemu process is still running, I did not implement a way to use raw file directly after the block-stream is complete.
Quoted 28 lines
docs/specs/add-cow.txt line 27
Quoted 10 lines
docs/specs/add-cow.txt new file +10
-0+ +=Specification= + +The file format looks like this: + + +---------------+-------------+-----------------+ + | Header | Reserved | COW bitmap | + +---------------+-------------+-----------------+ + +All numbers in add-cow are stored in Little Endian byte order.Okay, but different than network byte order, which means we can't use
htonl()and friends to convert host bytes into the proper format. <endian.h> is not (yet) standardized, although there is talk of adding it to the next version of POSIX, in which casehtole32()and friends would be guaranteed.Quoted 11 lines
docs/specs/add-cow.txt new file +11
-0+ +== Header == + +The Header is included in the first bytes: + + Byte 0 - 7: magic + add-cow magic string ("ADD_COW\xff") + + 8 - 11: version + Version number (only valid value is 1 now) +
Quoted 8 lines
docs/specs/add-cow.txt line 42
Quoted 4 lines
docs/specs/add-cow.txt new file +4
-0+ 12 - 15: backing_filename_offset + Offset in the add-cow file at which the backing file name + is stored (NB: The string is not null terminated). 0 if the + image doesn't have a backing file.Mention that if this is not 0, then it must be between 36 and 4094 (a file name must be at least 1 byte). What are the semantics if the filename is relative?
relative filename is ok, I tested it just now.
Quoted 11 lines
docs/specs/add-cow.txt line 46
Quoted 5 lines
docs/specs/add-cow.txt new file +4
-0+ + 16 - 19: backing_filename_size + Length of the backing file name in bytes. Undefined if the + image doesn't have a backing file.Better to require 0 if
backing_filename_offsetis 0, than to leave this field undefined; also ifbacking_filename_offsetis non-zero, then this must be non-zero. Must be less than 4096-36 to fit in the reserved part of the header.
Okay.
Quoted 7 lines
docs/specs/add-cow.txt line 50
Quoted 4 lines
docs/specs/add-cow.txt new file +4
-0+ + 20 - 23: image_filename_offset + Offset in the add-cow file at which the image_file name + is stored (NB: The string is not null terminated).Mention that this must be between 36 and 4094 (a file name must be at least 1 byte). What are the semantics if the filename is relative?
relative filename is ok, I tested it just now.
Quoted 8 lines
docs/specs/add-cow.txt line 53
Quoted 4 lines
docs/specs/add-cow.txt new file +3
-0+ + 24 - 27: image_filename_size + Length of the image_file name in bytes.If
backing_filename_offsetis non-zero, then this must be non-zero. Must be less than 4096-36 to fit in the reserved part of the header.
Yes,
Quoted 5 lines
May
image_filenameandbacking_filenameoverlap (possible if one is a suffix of the other)? Are there any constraints to prevent infinite loops, such as forbiddingbacking_filenameandimage_filenamefrom resolving either to the same file or to the add-cow file?
Sorry, I should add the code that judge if image_file is valid. will fix.
Quoted 9 lines
docs/specs/add-cow.txt line 61
Quoted 8 lines
docs/specs/add-cow.txt new file +8
-0+ + 28 - 35: features + Currently only 2 feature bits are used: + Feature bits: + The image uses a backing file: + * ADD_COW_F_BACKING_FILE = 0x01. + The backing file's format is raw: + * ADD_COW_F_BACKING_FORMAT_NO_PROBE = 0x02.
Quoted 7 lines
Should this follow the qcow2v3 proposal of splitting into mandatory vs. optional feature bits?
I agree that
ADD_COW_F_BACKING_FORMAT_NO_PROBEis sufficient to avoid security implications, but do we want the extra flexibility of specifying the backing format file format rather than just requiring probes on all but raw?
Kevin, or Stefan, can you give some comments for this? thanks.
Quoted 11 lines
docs/specs/add-cow.txt line 68
Quoted 8 lines
docs/specs/add-cow.txt new file +7
-0+ +== Reserved == + + Byte 36 - 4095: Reserved field: + It is used to make sure COW bitmap field starts at the + 4096th byte, backing_file name and image_file name will + be stored here.Do we want to keep a fixed-size header, or should we be planning on the possibility of future extensions requiring enough other header
Quoted 9 lines
extensions that a variable-sized header would be wiser? That is, I'm fine with requiring that the header be a multiple of 4k, but maybe it would make sense to have a mandatory header field that states how many header pages are present before the COW bitmap begins. In the first round of implementation, this header field can be required to be 1 (that is, for now, we require exactly 4k header), but having the field would let us change in the future to a design with an 8k header to hold more metadata as needed.
Okay.
Quoted 23 lines
Quoted 9 lines
docs/specs/add-cow.txt new file +9
-0+ +== COW bitmap == + +The "COW bitmap" field starts at the 4096th byte, stores a bitmap related to +backing_file and image_file. The bitmap will track whether the sector in +backing_file is dirty or not. + +Each bit in the bitmap indicates one cluster's status. One cluster includes 128 +sectors, then each bit indicates 512 * 128 = 64k bytes, So the size of bitmap isdocs/specs/add-cow.txt line 87
Quoted 10 lines
docs/specs/add-cow.txt new file +10
-0+calculated according to virtual size of image_file. In each byte, bit 0 to 7 +will track the 1st to 7th cluster in sequence, bit orders in one byte look like: + +----+----+----+----+----+----+----+----+ + | b7 | b6 | b5 | b4 | b3 | b2 | b1 | b0 | + +----+----+----+----+----+----+----+----+ + +If the bit is 0, indicates the sector has not been allocated in image_file, data +should be loaded from backing_file while reading; if the bit is 1, indicates the +related sector has been dirty, should be loaded from image_file while reading. +Writing to a sector causes the corresponding bit to be set to 1.So basically an add-cow image is thin as long as at least one bit is 0, and the add-cow wrapper can only be discarded when all bits are 1.
Quoted 4 lines
How do you handle the case where the raw image is not an even multiple of cluster bytes? That is, do bits that correspond to bytes beyond the raw file size have to be in a certain state?
Now, bits correspond to bytes beyond the raw file size are set to 0.
Really thanks for your reviewing, Eric.
Quoted 4 lines
--
Eric Blake [email protected] +1-919-301-3266
Libvirt virtualization library http://libvirt.org
Am 14.06.2012 05:06, schrieb Dong Xu Wang:
Quoted 30 lines · Eric Blake
Quoted 20 lines · Dong Xu Wang
Quoted 19 lines
Introduce a new file format:add-cow. The usage can be found at this patch.
Signed-off-by Dong Xu Wang <[email protected]>--- docs/specs/add-cow.txt | 87 ++++++++++++++++++++++++++++++++++++++++++++++++ 1 files changed, 87 insertions(+), 0 deletions(-) create mode 100644 docs/specs/add-cow.txtdocs/specs/add-cow.txt new file +11
-0+ +== Header == + +The Header is included in the first bytes: + + Byte 0 - 7: magic + add-cow magic string ("ADD_COW\xff") + + 8 - 11: version + Version number (only valid value is 1 now) +Quoted 8 lines
docs/specs/add-cow.txt line 42
Quoted 4 lines
docs/specs/add-cow.txt new file +4
-0+ 12 - 15: backing_filename_offset + Offset in the add-cow file at which the backing file name + is stored (NB: The string is not null terminated). 0 if the + image doesn't have a backing file.Mention that if this is not 0, then it must be between 36 and 4094 (a file name must be at least 1 byte). What are the semantics if the filename is relative?
Quoted 1 line
relative filename is ok, I tested it just now.
I believe Eric wanted to know what a relative path means, i.e. that it's relative to the image file rather than relative to the working directory.
Quoted 5 lines
Quoted 5 lines
Quoted 4 lines
docs/specs/add-cow.txt new file +4
-0+ + 16 - 19: backing_filename_size + Length of the backing file name in bytes. Undefined if the + image doesn't have a backing file.
Quoted 7 lines
Quoted 5 lines
Better to require 0 if
backing_filename_offsetis 0, than to leave this field undefined; also ifbacking_filename_offsetis non-zero, then this must be non-zero. Must be less than 4096-36 to fit in the reserved part of the header.Okay.
Does an add-cow image without a backing file even make sense?
Quoted 11 lines
Quoted 11 lines
docs/specs/add-cow.txt line 61
Quoted 7 lines
docs/specs/add-cow.txt new file +7
-0+ 28 - 35: features + Currently only 2 feature bits are used: + Feature bits: + The image uses a backing file: + * ADD_COW_F_BACKING_FILE = 0x01. + The backing file's format is raw: + * ADD_COW_F_BACKING_FORMAT_NO_PROBE = 0x02.Should this follow the qcow2v3 proposal of splitting into mandatory vs. optional feature bits?
Quoted 6 lines
Quoted 4 lines
I agree that
ADD_COW_F_BACKING_FORMAT_NO_PROBEis sufficient to avoid security implications, but do we want the extra flexibility of specifying the backing format file format rather than just requiring probes on all but raw?Kevin, or Stefan, can you give some comments for this? thanks.
I tend to agree that a format name is better than relying on probing.
Also, I think we need the same thing for image_file. add-cow is not only useful for raw images, but also for other image format types for which we don't support backing files.
Quoted 7 lines
Quoted 7 lines
Quoted 6 lines
+== Reserved ==
docs/specs/add-cow.txt new file +5
-0+ + Byte 36 - 4095: Reserved field: + It is used to make sure COW bitmap field starts at the + 4096th byte, backing_file name and image_file name will + be stored here.
Quoted 10 lines
Quoted 10 lines
Do we want to keep a fixed-size header, or should we be planning on the possibility of future extensions requiring enough other header extensions that a variable-sized header would be wiser? That is, I'm fine with requiring that the header be a multiple of 4k, but maybe it would make sense to have a mandatory header field that states how many header pages are present before the COW bitmap begins. In the first round of implementation, this header field can be required to be 1 (that is, for now, we require exactly 4k header), but having the field would let us change in the future to a design with an 8k header to hold more metadata as needed.
I have the impression that this simple add-cow hack is starting to get seriously overengineered... :-)
Kevin
Quoted 31 lines · Kevin Wolf
Am 14.06.2012 05:06, schrieb Dong Xu Wang:
Quoted 30 lines · Eric Blake
Quoted 28 lines · Dong Xu Wang
Quoted 13 lines
Introduce a new file format:add-cow. The usage can be found at this patch.
Signed-off-by Dong Xu Wang <[email protected]>---
docs/specs/add-cow.txt | 87 ++++++++++++++++++++++++++++++++++++++++++++++++1 files changed, 87 insertions(+), 0 deletions(-)create mode 100644
docs/specs/add-cow.txtdocs/specs/add-cow.txt new file +5
-0+ +== Header == + +The Header is included in the first bytes: +docs/specs/add-cow.txt line 42
Quoted 10 lines
docs/specs/add-cow.txt new file +10
-0+ Byte 0 - 7: magic + add-cow magic string ("ADD_COW\xff") + + 8 - 11: version + Version number (only valid value is 1 now) + + 12 - 15: backing_filename_offset + Offset in the add-cow file at which the backing file name + is stored (NB: The string is not null terminated). 0 if the + image doesn't have a backing file.Mention that if this is not 0, then it must be between 36 and 4094 (a file name must be at least 1 byte). What are the semantics if the filename is relative?
Quoted 5 lines
Quoted 1 line
relative filename is ok, I tested it just now.
I believe Eric wanted to know what a relative path means, i.e. that it's relative to the image file rather than relative to the working directory.
Now it is relative to working directory.
Quoted 11 lines
Quoted 11 lines
Quoted 10 lines
Quoted 4 lines
+
+ 16 - 19: backing_filename_size
+ Length of the backing file name in bytes. Undefined if the
+ image doesn't have a backing file.Better to require 0 if
backing_filename_offsetis 0, than to leave this field undefined; also ifbacking_filename_offsetis non-zero, then this must be non-zero. Must be less than 4096-36 to fit in the reserved part of the header.
Quoted 4 lines
Quoted 1 line
Okay.
Does an add-cow image without a backing file even make sense?
Okay, I think so, it will be v11.
Quoted 16 lines
Quoted 16 lines
Quoted 15 lines
Quoted 7 lines
+ 28 - 35: features
+ Currently only 2 feature bits are used:
+ Feature bits:
+ The image uses a backing file:
+ *ADD_COW_F_BACKING_FILE=0x01.
+ The backing file's format is raw:
+ *ADD_COW_F_BACKING_FORMAT_NO_PROBE=0x02.Should this follow the qcow2v3 proposal of splitting into mandatory vs. optional feature bits?
I agree that
ADD_COW_F_BACKING_FORMAT_NO_PROBEis sufficient to avoid security implications, but do we want the extra flexibility of specifying the backing format file format rather than just requiring probes on all but raw?
Quoted 8 lines
Quoted 1 line
Kevin, or Stefan, can you give some comments for this? thanks.
I tend to agree that a format name is better than relying on probing.
Also, I think we need the same thing for
image_file. add-cow is not only useful for raw images, but also for other image format types for which we don't support backing files.
Okay.
Quoted 23 lines
Quoted 7 lines
Quoted 7 lines
Quoted 6 lines
+== Reserved ==
+
+ Byte 36 - 4095: Reserved field:
+ It is used to make sure COW bitmap field starts at the
+ 4096th byte,backing_filename andimage_filename will
+ be stored here.Quoted 10 lines
Quoted 10 lines
Do we want to keep a fixed-size header, or should we be planning on the possibility of future extensions requiring enough other header extensions that a variable-sized header would be wiser? That is, I'm fine with requiring that the header be a multiple of 4k, but maybe it would make sense to have a mandatory header field that states how many header pages are present before the COW bitmap begins. In the first round of implementation, this header field can be required to be 1 (that is, for now, we require exactly 4k header), but having the field would let us change in the future to a design with an 8k header to hold more metadata as needed.
I have the impression that this simple add-cow hack is starting to get seriously overengineered... :-)
Kevin
Quoted 10 lines · Dong Xu Wang
Quoted 9 lines
Quoted 5 lines
Quoted 3 lines
Mention that if this is not 0, then it must be between 36 and 4094 (a file name must be at least 1 byte). What are the semantics if the filename is relative?
relative filename is ok, I tested it just now.
I believe Eric wanted to know what a relative path means, i.e. that it's relative to the image file rather than relative to the working directory.
Now it is relative to working directory.
Yuck. So I have to change directories before opening an add-cow image in order to interpret it the same way as the creator? You really need to fix this to be like qcow2 backing files; relative path names there are interpreted relative to the qcow2 file, not to the current working directory of the process that opened the qcow2 file.
Signature · 2 lines
Eric Blake [email protected] +1-919-301-3266 Libvirt virtualization library http://libvirt.org