docs: spec for add-cow file format
PATCH v11 1/6 docs: spec for add-cow file format
Introduce a new file format:add-cow. The usage can be found at this patch.
---
Now add-cow is still using QEMUOptionParameter, not QemuOpts, I will send a seperate patch series to convert.
docs/specs/add-cow.txt | 128 ++++++++++++++++++++++++++++++++++++++++++++++++ 1 files changed, 128 insertions(+), 0 deletions(-) create mode 100644 docs/specs/add-cow.txt
docs/specs/add-cow.txt new file +128 -0
@@ -0,0 +1,128 @@ +== 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 + +test.raw may be larger than ubuntu.img, in that case, the size of test.add-cow +will be calculated by the size of ubuntu.img, test.raw will be used from the +1st byte, the rest part can be used for other purpose. + +=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: +(#define HEADER_SIZE (4096 * header_pages_size)) + 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 file name offset + Offset in the add-cow file at which the backing file + name is stored (NB: The string is not null terminated). + If backing file name does NOT exist, this field will be + 0. Must be between 80 and [HEADER_SIZE - 2](a file name + must be at least 1 byte). + + 16 - 19: backing file name size + Length of the backing file name in bytes. It will be 0 + if the backing file name offset is 0. If backing file + name offset is non-zero, then it must be non-zero. Must + be less than [HEADER_SIZE - 80] to fit in the reserved + part of the header. + + 20 - 23: image file name offset + Offset in the add-cow file at which the image file name + is stored (NB: The string is not null terminated). It + must be between 80 and [HEADER_SIZE - 2]. + + 24 - 27: image file name size + Length of the image file name in bytes. + Must be less than [HEADER_SIZE - 80] to fit in the reserved + part of the header. + + 28 - 35: features + Currently only 3 feature bit is used: + Feature bits: + The image uses a backing file: + * ADD_COW_F_BACKING_FILE = 0x01. + The image uses a image file: + * ADD_COW_F_IMAGE_FILE = 0x02. + All bits in bitmap have been set to 1, add-cow wrapper + can be discarded. + * ADD_COW_F_All_ALLOCATED = 0x04. + + 36 - 43: optional features + Not used now. Researved for future use. + + 44 - 47: header pages size + The header field is variable-sized. This field indicates + how many pages(4k) will be used to store add-cow header. + In add-cow v1, it is fixed to 1, so the header size will + be 4k * 1 = 4096 bytes. + +Image file name and backing file name must NOT be the same, we prevent this +while creating add-cow files. + +Image file and backing file are interpreted relative to the qcow2 file, not +to the current working directory of the process that opened the qcow2 file. + +== Reserved == + + Byte 48 - 63: backing file format + format of backing file. It will be filled with 0 if + backing file name offset is 0. If backing file name + offset is none-zero, it must be non-zero. + + 64 - 79: image file format + format of image file. It must be non-zero. + + 80 - [HEADER_SIZE - 1]: + It is used to make sure COW bitmap field starts at the + HEADER_SIZE 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. the size of bitmap is +calculated according to virtual size of backing 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. + +If raw image is not an even multiple of cluster bytes, bits that correspond to +bytes beyond the raw file size in add-cow will be 0.
Signature · 1 line
1.7.1
PATCH v11 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.
While creating images files, if no size is specified, will use size of backing file. If no backing file is specified, we will use the size of image file.
--- block.c | 37 +++++++++++++++++++++++++++++++++---- block.h | 3 +++ block/qed.c | 29 +---------------------------- 3 files changed, 37 insertions(+), 32 deletions(-)
block.c +33 -4
@@ -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;
@@ -213,6 +213,21 @@ static int path_has_protocol(const char *path)return *p ==':' ; } +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 ; +} +int path_is_absolute (const char *path) {#ifdef _WIN32
@@ -3884,7 +3899,7 @@ int bdrv_img_create(const char *filename, const char *fmt, char *options, uint64_t img_size, int flags) { QEMUOptionParameter *param = NULL, *create_options = NULL; -QEMUOptionParameter *backing_fmt, *backing_file, *size; +QEMUOptionParameter *backing_fmt, *backing_file, *size, *image_file;BlockDriverState *bs =NULL ;BlockDriver *drv, *proto_drv;BlockDriver *backing_drv =NULL ;
@@ -3965,9 +3980,11 @@ int bdrv_img_create(const char *filename, const char *fmt, } } -// The size for the image must always be specified, with one exception: -// If we are using a backing file, we can obtain the size from there +/* The size for the image must always be specified, with one exception: +If we are using a backing file, we can obtain the size from there, +but if not, and we are using an image file, we will obtain the size from it.*/ size =get_option_parameter (param,BLOCK_OPT_SIZE ); + image_file =get_option_parameter (param,BLOCK_OPT_IMAGE_FILE );if (size && size->value.n ==-1 ) {if (backing_file && backing_file->value.s) {uint64_t size;
@@ -3990,6 +4007,18 @@ int bdrv_img_create(const char *filename, const char *fmt,snprintf (buf,sizeof (buf),"%" PRId64, size);set_option_parameter (param,BLOCK_OPT_SIZE , buf); + }else if (image_file && image_file->value.s) { +uint64_t size; +char buf[32 ]; + bs =bdrv_new ("" ); + ret =bdrv_file_open (&bs, image_file->value.s,BDRV_O_RDWR ); +if (ret <0 ) { +error_report ("Could not open '%s'" , image_file->value.s); + goto out; + } + size =bdrv_getlength (bs); +snprintf (buf,sizeof (buf),"%" PRId64, size); +set_option_parameter (param,BLOCK_OPT_SIZE , buf); }else {error_report ("Image creation needs a size parameter" ); ret = -EINVAL ;
block.h +3 -0
@@ -152,6 +152,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,
@@ -306,6 +308,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
Re: [Qemu-devel] [PATCH 2/6 v11 v11] block: make some functions public
Quoted 2 lines · Dong Xu Wang
In add-cow file format, we will use
path_has_protocoland we will read a NUL-terminated string from image ,qed_read_stringhas done the samething,
s/image ,/image,/
s/samething/same thing/
Quoted 12 lines
so make the two functions public, then we will reuse them directly.
While creating images files, if no size is specified, will use size of backing file. If no backing file is specified, we will use the size of image file.
Signed-off-by Dong Xu Wang <[email protected]>--- block.c | 37 +++++++++++++++++++++++++++++++++---- block.h | 3 +++ block/qed.c | 29 +---------------------------- 3 files changed, 37 insertions(+), 32 deletions(-)
block.c int bdrv_img_create(const char *filename, const char *fmt, · line 3985
Quoted 3 lines
block.c +3
-0+/* The size for the image must always be specified, with one exception: +If we are using a backing file, we can obtain the size from there, +but if not, and we are using an image file, we will obtain the size from it.*/
grammar:
The size for the image must be known, either by direct specification, or by reading it from a backing file or image file.
Signature · 2 lines
Eric Blake [email protected] +1-919-301-3266 Libvirt virtualization library http://libvirt.org
Re: [Qemu-devel] [PATCH 2/6 v11 v11] block: make some functions public
Quoted 23 lines · Eric Blake
Quoted 2 lines · Dong Xu Wang
In add-cow file format, we will use
path_has_protocoland we will read a NUL-terminated string from image ,qed_read_stringhas done the samething,s/image ,/image,/
s/samething/same thing/Quoted 12 lines
so make the two functions public, then we will reuse them directly.
While creating images files, if no size is specified, will use size of backing file. If no backing file is specified, we will use the size of image file.
Signed-off-by Dong Xu Wang <[email protected]>--- block.c | 37 +++++++++++++++++++++++++++++++++---- block.h | 3 +++ block/qed.c | 29 +---------------------------- 3 files changed, 37 insertions(+), 32 deletions(-)block.c int bdrv_img_create(const char *filename, const char *fmt, · line 3985
Quoted 3 lines
block.c +3
-0+/* The size for the image must always be specified, with one exception: +If we are using a backing file, we can obtain the size from there, +but if not, and we are using an image file, we will obtain the size from it.*/
Quoted 8 lines
grammar:
The size for the image must be known, either by direct specification, or by reading it from a backing file or image file.--
Eric Blake [email protected] +1-919-301-3266
Libvirt virtualization library http://libvirt.org
Nod, Thank you, Eric
Re: [Qemu-devel] [PATCH 2/6 v11 v11] block: make some functions public
In reply to Dong Xu Wangblock.h int bdrv_pwrite(BlockDriverState *bs, int64_t offset, · line 156
Quoted 10 lines · Dong Xu Wang
block.h +2
-0@@ -152,6 +152,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);
I suggest renaming the "file" argument to "bs" like all the other block.h functions.
block.h int bdrv_pwrite(BlockDriverState *bs, int64_t offset,
Quoted 12 lines
block.h +0
-11/** -* 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. -*/
Please keep the doc comment.
Stefan
Re: [Qemu-devel] [PATCH 2/6 v11 v11] block: make some functions public
Quoted 16 lines · Stefan Hajnoczi
block.h int bdrv_pwrite(BlockDriverState *bs, int64_t offset, · line 156
Quoted 10 lines · Dong Xu Wang
block.h +2
-0@@ -152,6 +152,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);I suggest renaming the "file" argument to "bs" like all the other
block.hfunctions.
Okay.
Quoted 13 lines
block.h int bdrv_pwrite(BlockDriverState *bs, int64_t offset,
Quoted 12 lines
block.h +0
-11/** -* 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. -*/
Quoted 3 lines
Please keep the doc comment.
Stefan
Okay. thank you.
Quoted 1 line
PATCH v11 4/6 add-cow: support snapshot_blkde
In reply to Dong Xu Wangadd-cow will let raw file support snapshot_blkdev indirectly.
--- blockdev.c | 45 +++++++++++++++++++++++++++++++++++++-------- docs/live-block-ops.txt | 11 ++++++++++- 2 files changed, 47 insertions(+), 9 deletions(-)
blockdev.c +37 -8
@@ -19,7 +19,7 @@#include "qmp-commands.h" #include "trace.h" #include "arch_init.h" - +#include "block/add-cow.h" static QTAILQ_HEAD(drivelist, DriveInfo) drives = QTAILQ_HEAD_INITIALIZER(drives);static const char *const if_name[IF_COUNT ] = {
@@ -665,6 +665,8 @@ static void blockdev_do_action(int kind, void *data, Error **errp)void qmp_blockdev_snapshot_sync (const char *device,const char *snapshot_file,bool has_format,const char *format,bool has_mode,enum NewImageMode mode, +bool has_image_file,const char *image_filename, +bool has_image_format,const char *image_format,Error **errp) {BlockdevSnapshot snapshot = {
@@ -674,6 +676,10 @@ void qmp_blockdev_snapshot_sync(const char *device, const char *snapshot_file, .format = (char *) format, .has_mode = has_mode, .mode = mode, + .has_image_file = has_image_file, + .image_file = (char *) image_filename, + .has_image_format = has_image_format, + .image_format = (char *) image_format, };blockdev_do_action (BLOCKDEV_ACTION_KIND_BLOCKDEV_SNAPSHOT_SYNC , &snapshot, errp);
@@ -776,15 +782,30 @@ 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, - 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; +char option[1024 ]; +uint64_t size; + +bdrv_get_geometry (states->old_bs, &size); + size *=BDRV_SECTOR_SIZE ; +if (dev_info->blockdev_snapshot_sync->image_file) { +sprintf (option,"image_file=%s,image_format=%s" , + dev_info->blockdev_snapshot_sync->image_file, + dev_info->blockdev_snapshot_sync->has_image_format ? dev_info->blockdev_snapshot_sync->image_format :"raw" ); + ret =bdrv_img_create (new_image_file, format, + states->old_bs->filename, + states->old_bs->drv->format_name, + option,-1 , flags); + }else { + 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; + }/* We will manually add the backing_hd field to the bs later */ states->new_bs =bdrv_new ("" );
@@ -1083,6 +1104,14 @@ static void block_stream_cb(void *opaque, int ret) }qobject_decref (obj); +if (strcmp (bs->drv->format_name,"add-cow" ) ==0 ) { +BDRVAddCowState *s = bs->opaque; +char *format = s->image_file_format; +BlockDriver *drv =bdrv_find_format (format); +assert (drv); +bdrv_drain_all (); +bdrv_swap (s->image_hd, bs); + }drive_put_ref_bh_schedule (drive_get_by_blockdev (bs)); }
docs/live-block-ops.txt +10 -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,11 @@ 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 source.img raw + +source.img is a raw file, and should be pre-created. disk.img will be created +using soure.img as image file. After block_stream process finished, it will +reassociate the drive with source.img automatically.
Signature · 1 line
1.7.1
Re: [Qemu-devel] [PATCH 4/6 v11] add-cow: support snapshot_blkde
Quoted 7 lines · Dong Xu Wang
add-cow will let raw file support
snapshot_blkdevindirectly.Signed-off-by Dong Xu Wang <[email protected]>--- blockdev.c | 45 +++++++++++++++++++++++++++++++++++++-------- docs/live-block-ops.txt | 11 ++++++++++- 2 files changed, 47 insertions(+), 9 deletions(-)
This patch would need to update qapi-schema.json and qmp-commands.hx to make use of the new arguments.
I don't think QEMU compiles cleanly after this patch. It's important to keep the build clean after every patch so that git-bisect(1) can be used (if you hit a broken build during a bisect it makes things harder).
However, I think the QMP/HMP changes should not be included in this series unless you are sure the interface is stable. When you convert QEMUOptionsParameter will transaction or snapshot-blkdev-sync change? If so, please only send the add-cow image format and leave the QMP/HMP changes until you have the QemuOpts solution.
Stefan
Re: [Qemu-devel] [PATCH 4/6 v11] add-cow: support snapshot_blkde
Quoted 18 lines · Stefan Hajnoczi
Quoted 7 lines · Dong Xu Wang
add-cow will let raw file support
snapshot_blkdevindirectly.Signed-off-by Dong Xu Wang <[email protected]>--- blockdev.c | 45 +++++++++++++++++++++++++++++++++++++-------- docs/live-block-ops.txt | 11 ++++++++++- 2 files changed, 47 insertions(+), 9 deletions(-)This patch would need to update qapi-schema.json and qmp-commands.hx to make use of the new arguments.
I don't think QEMU compiles cleanly after this patch. It's important to keep the build clean after every patch so that git-bisect(1) can be used (if you hit a broken build during a bisect it makes things harder).
Quoted 5 lines
However, I think the QMP/HMP changes should not be included in this series unless you are sure the interface is stable. When you convert QEMUOptionsParameter will transaction or snapshot-blkdev-sync change? If so, please only send the add-cow image format and leave the QMP/HMP changes until you have the QemuOpts solution.
Ah, yes, sorry, the patch must be compiled with 5/6, HMP now works like:
[-n] device [new-image-file] [format] [image-file] [image-format]
snapshot_blockdev /dev/ide-id0 1.add-cow add-cow t.raw raw
Also qmp's args_type:
.args_type = "device:B,snapshot-file:s,format:s?,mode:s?,image-file:s?,image-format:s?",
Before converting QEMUOptionsParameter, can the code be like this?
Thanks.
Quoted 3 lines
Stefan
Re: [Qemu-devel] [PATCH 4/6 v11] add-cow: support snapshot_blkde
Quoted 28 lines · Dong Xu Wang
Quoted 18 lines · Stefan Hajnoczi
Quoted 7 lines · Dong Xu Wang
add-cow will let raw file support
snapshot_blkdevindirectly.Signed-off-by Dong Xu Wang <[email protected]>--- blockdev.c | 45 +++++++++++++++++++++++++++++++++++++-------- docs/live-block-ops.txt | 11 ++++++++++- 2 files changed, 47 insertions(+), 9 deletions(-)This patch would need to update qapi-schema.json and qmp-commands.hx to make use of the new arguments.
I don't think QEMU compiles cleanly after this patch. It's important to keep the build clean after every patch so that git-bisect(1) can be used (if you hit a broken build during a bisect it makes things harder).
Quoted 5 lines
However, I think the QMP/HMP changes should not be included in this series unless you are sure the interface is stable. When you convert QEMUOptionsParameter will transaction or snapshot-blkdev-sync change? If so, please only send the add-cow image format and leave the QMP/HMP changes until you have the QemuOpts solution.
Ah, yes, sorry, the patch must be compiled with 5/6, HMP now works like:
[-n] device [new-image-file] [format] [image-file] [image-format]
Quoted 6 lines
snapshot_blockdev/dev/ide-id01.add-cow add-cow t.raw rawAlso qmp's
args_type:
.args_type = "device:B,snapshot-file:s,format:s?,mode:s?,image-file:s?,image-format:s?",Before converting QEMUOptionsParameter, can the code be like this?
I think it's cleanest to submit just the image format without snapshot_blockdev interface changes. It's definitely not a good idea to temporarily change the QMP/HMP interface if the QEMUOptionsParameter conversion will change it again.
Stefan
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 | 206 +++++++++++++++++ block/add-cow.c | 599 +++++++++++++++++++++++++++++++++++++++++++++++++ block/add-cow.h | 101 +++++++++ block_int.h | 2 + 5 files changed, 909 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 +206 -0
206 lines not on this page · raw message
block/add-cow.c new file +599 -0
599 lines not on this page · raw message
block/add-cow.h new file +101 -0
101 lines not on this page · raw message
block_int.h +2 -0
@@ -51,6 +51,8 @@#define BLOCK_OPT_PREALLOC "preallocation"#define BLOCK_OPT_SUBFMT "subformat"#define BLOCK_OPT_COMPAT_LEVEL "compat" +#define BLOCK_OPT_IMAGE_FILE "image_file" +#define BLOCK_OPT_IMAGE_FORMAT "image_format"typedef struct BdrvTrackedRequest BdrvTrackedRequest ;
Signature · 1 line
1.7.1
Re: [Qemu-devel] [PATCH 3/6] add-cow file format
Quoted 3 lines · Dong Xu Wang
This is the implementation code for add-cow file format. Because
image_filemight be very huge, then we can't read entire bitmap into memory, we must use a cache. Sinceqcow-cache.chas implemted cache code, we can create our cache
s/implemted/implemented/
Quoted 1 line
code based on it.
Just wondering if Paolo's HBitmap code for drive-mirror might be a more efficient way to implement your caching.
Quoted 8 lines
Signed-off-by Dong Xu Wang <[email protected]>--- block/Makefile.objs | 1 + block/add-cow-cache.c | 206 +++++++++++++++++ block/add-cow.c | 599 +++++++++++++++++++++++++++++++++++++++++++++++++ block/add-cow.h | 101 +++++++++ block_int.h | 2 +
Rather than adding a new implementation for code duplication, can you refactor the existing implementation to be reusable, and update qcow-cache.c to call into the common refactored code?
Signature · 2 lines
Eric Blake [email protected] +1-919-301-3266 Libvirt virtualization library http://libvirt.org
Re: [Qemu-devel] [PATCH 3/6] add-cow file format
Quoted 21 lines · Eric Blake
Quoted 3 lines · Dong Xu Wang
This is the implementation code for add-cow file format. Because
image_filemight be very huge, then we can't read entire bitmap into memory, we must use a cache. Sinceqcow-cache.chas implemted cache code, we can create our caches/implemted/implemented/
Quoted 1 line
code based on it.
Just wondering if Paolo's HBitmap code for drive-mirror might be a more efficient way to implement your caching.
Quoted 8 lines
Signed-off-by Dong Xu Wang <[email protected]>--- block/Makefile.objs | 1 + block/add-cow-cache.c | 206 +++++++++++++++++ block/add-cow.c | 599 +++++++++++++++++++++++++++++++++++++++++++++++++ block/add-cow.h | 101 +++++++++ block_int.h | 2 +
Quoted 3 lines
Rather than adding a new implementation for code duplication, can you refactor the existing implementation to be reusable, and update
qcow-cache.cto call into the common refactored code?
I looked at this and block/qcow2-cache.c seems fairly clean and generic. The only things that need to be parameterized are the s->l2_table_cache/s->refcount_block_cache and s->cluster_size.
These can be fixed by adding fields to Qcow2Cache:size_t table_size; /* cached table size in bytes */ BlkDebugEvent flush_event;
BlkDebugEvent load_event;
Or maybe a table type enum (L2/refcount blocks/bitmap blocks).
If Kevin agrees with extracting this from qcow2 (i.e. we can't add more qcow2-specific behavior easily in the future), then this looks doable.
Stefan
Re: [Qemu-devel] [PATCH 3/6] add-cow file format
Am 01.08.2012 16:14, schrieb Stefan Hajnoczi:
Quoted 35 lines · Eric Blake
Quoted 21 lines · Dong Xu Wang
Quoted 3 lines
This is the implementation code for add-cow file format. Because
image_filemight be very huge, then we can't read entire bitmap into memory, we must use a cache. Sinceqcow-cache.chas implemted cache code, we can create our caches/implemted/implemented/
Quoted 1 line
code based on it.
Just wondering if Paolo's HBitmap code for drive-mirror might be a more efficient way to implement your caching.
Quoted 8 lines
Signed-off-by Dong Xu Wang <[email protected]>--- block/Makefile.objs | 1 + block/add-cow-cache.c | 206 +++++++++++++++++ block/add-cow.c | 599 +++++++++++++++++++++++++++++++++++++++++++++++++ block/add-cow.h | 101 +++++++++ block_int.h | 2 +Quoted 3 lines
Rather than adding a new implementation for code duplication, can you refactor the existing implementation to be reusable, and update
qcow-cache.cto call into the common refactored code?I looked at this and
block/qcow2-cache.cseems fairly clean and generic. The only things that need to be parameterized are the s->l2_table_cache/s->refcount_block_cache ands->cluster_size.These can be fixed by adding fields to Qcow2Cache:
size_ttable_size; /* cached table size in bytes */ BlkDebugEventflush_event;
BlkDebugEventload_event;
Quoted 5 lines
Or maybe a table type enum (L2/refcount blocks/bitmap blocks).
If Kevin agrees with extracting this from qcow2 (i.e. we can't add more qcow2-specific behavior easily in the future), then this looks doable.
I don't think we'd want to add qcow2 specific stuff there, and I've been meaning to generalise it for quite a while, so feel free to do it.
One thing to note is that it currently depends on qcow2's s->lock being taken while it's called. Eventually we'll want finer grained locking in the cache itself and I believe this will also require some changes in the interface, but for now add-cow can just do the same qcow2 and take its global CoMutex.
Kevin
Re: [Qemu-devel] [PATCH 3/6] add-cow file format
In reply to Eric BlakeQuoted 7 lines · Eric Blake
Quoted 3 lines · Dong Xu Wang
This is the implementation code for add-cow file format. Because
image_filemight be very huge, then we can't read entire bitmap into memory, we must use a cache. Sinceqcow-cache.chas implemted cache code, we can create our caches/implemted/implemented/
Okay.
Quoted 14 lines
Quoted 1 line
code based on it.
Just wondering if Paolo's HBitmap code for drive-mirror might be a more efficient way to implement your caching.
Quoted 8 lines
Signed-off-by Dong Xu Wang <[email protected]>--- block/Makefile.objs | 1 + block/add-cow-cache.c | 206 +++++++++++++++++ block/add-cow.c | 599 +++++++++++++++++++++++++++++++++++++++++++++++++ block/add-cow.h | 101 +++++++++ block_int.h | 2 +
Quoted 4 lines
Rather than adding a new implementation for code duplication, can you refactor the existing implementation to be reusable, and update
qcow-cache.cto call into the common refactored code?
Okay. thanks.
Quoted 4 lines
--
Eric Blake [email protected] +1-919-301-3266
Libvirt virtualization library http://libvirt.org
Re: [Qemu-devel] [PATCH 3/6] add-cow file format
In reply to Dong Xu Wangblock/add-cow.c line 99
Quoted 3 lines · Dong Xu Wang
block/add-cow.c new file +3
-0+if (backing_filename) { + header.features |=ADD_COW_F_BACKING_FILE ; + header.backing_filename_offset =sizeof (header) +16 *2 ;
It's not obvious what 16 * 2 is.
block/add-cow.c line 175
Quoted 3 lines
block/add-cow.c new file +3
-0+ ret =bdrv_pwrite (bs,sizeof (le_header) +16 , + image_format ? image_format :"raw" , + image_format ?sizeof (image_format) :sizeof ("raw" ));
sizeof(image_format)? I think this should be strlen(image_format).
Stefan
Re: [Qemu-devel] [PATCH 3/6] add-cow file format
Quoted 7 lines · Stefan Hajnoczi
block/add-cow.c line 99
Quoted 3 lines · Dong Xu Wang
block/add-cow.c new file +3
-0+if (backing_filename) { + header.features |=ADD_COW_F_BACKING_FILE ; + header.backing_filename_offset =sizeof (header) +16 *2 ;It's not obvious what 16 * 2 is.
Okay we give meaningful constant later.
Quoted 6 lines
block/add-cow.c line 175
Quoted 4 lines
block/add-cow.c new file +3
-0+ ret =bdrv_pwrite (bs,sizeof (le_header) +16 , + image_format ? image_format :"raw" , + image_format ?sizeof (image_format) :sizeof ("raw" ));
sizeof(image_format)? I think this should bestrlen(image_format).
Okay. thanks.
Quoted 3 lines
Stefan
PATCH v11 5/6 add-cow: hmp and qmp interface
In reply to Dong Xu Wangadd HMP and QMP support for add-cow format. Because add-cow does not work like other image formats, it will use image-file, so we need add add-cow support while doing snapshot.
--- hmp-commands.hx | 8 ++++++-- hmp.c | 5 ++++- qapi-schema.json | 5 +++-- qmp-commands.hx | 2 +- 4 files changed, 14 insertions(+), 6 deletions(-)
hmp-commands.hx +6 -2
@@ -908,14 +908,18 @@ ETEXI { .name = "snapshot_blkdev", - .args_type = "reuse:-n,device:B,snapshot-file:s?,format:s?", - .params = "[-n] device [new-image-file] [format]", + .args_type = "reuse:-n,device:B,snapshot-file:s?,format:s?,image-file:s?,image-format:s?", + .params = "[-n] device [new-image-file] [format] [image-file] [image-format]", .help = "initiates a live snapshot\n\t\t\t" "of device. If a new image file is specified, the\n\t\t\t" "new image file will become the new root image.\n\t\t\t" "If format is specified, the snapshot file will\n\t\t\t" "be created in that format. Otherwise the\n\t\t\t" "snapshot will be internal! (currently unsupported).\n\t\t\t" + "If image file is specified, the snapshot file will\n\t\t\t" + "be created using image_file option.\n\t\t\t" + "If image-format is specified, the image file will\n\t\t\t" + "be created in that format. Otherwise will use raw format.\n\t\t\t" "The default format is qcow2. The -n flag requests QEMU\n\t\t\t" "to reuse the image found in new-image-file, instead of\n\t\t\t" "recreating it from scratch.",
hmp.c +4 -1
@@ -701,6 +701,8 @@ void hmp_snapshot_blkdev(Monitor *mon, const QDict *qdict)const char *filename =qdict_get_try_str (qdict,"snapshot-file" );const char *format =qdict_get_try_str (qdict,"format" );int reuse =qdict_get_try_bool (qdict,"reuse" ,0 ); +const char *image_filename =qdict_get_try_str (qdict,"image-file" ); +const char *image_format =qdict_get_try_str (qdict,"image-format" );enum NewImageMode mode;Error *errp =NULL ;
@@ -714,7 +716,8 @@ void hmp_snapshot_blkdev(Monitor *mon, const QDict *qdict) mode = reuse ?NEW_IMAGE_MODE_EXISTING :NEW_IMAGE_MODE_ABSOLUTE_PATHS ;qmp_blockdev_snapshot_sync (device, filename, !!format, format, - true, mode, &errp); + true, mode, !!image_filename, image_filename, + !!image_format, image_format, &errp);hmp_handle_error (mon, &errp); }
qapi-schema.json +3 -2
@@ -1204,7 +1204,7 @@ ## { 'type': 'BlockdevSnapshot', 'data': { 'device': 'str', 'snapshot-file': 'str', '*format': 'str', - '*mode': 'NewImageMode' } } + '*mode': 'NewImageMode', '*image_file': 'str', '*image_format': 'str' } } ## # @BlockdevAction
@@ -1269,7 +1269,8 @@ ## { 'command': 'blockdev-snapshot-sync', 'data': { 'device': 'str', 'snapshot-file': 'str', '*format': 'str', - '*mode': 'NewImageMode'} } + '*mode': 'NewImageMode', '*image-file': 'str', + '*image-format': 'str'} } ## # @human-monitor-command:
qmp-commands.hx +1 -1
@@ -789,7 +789,7 @@ EQMP { .name = "blockdev-snapshot-sync", - .args_type = "device:B,snapshot-file:s,format:s?,mode:s?", + .args_type = "device:B,snapshot-file:s,format:s?,mode:s?,image-file:s?,image-format:s?", .mhandler.cmd_new = qmp_marshal_input_blockdev_snapshot_sync, },
Signature · 1 line
1.7.1
PATCH v11 6/6 add-cow: support qemu-iotests
In reply to Dong Xu Wangadd qemu-iotests support for add-cow file format.
--- 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
@@ -128,6 +128,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
@@ -163,6 +164,11 @@ testlist options xpand=false ;; + -add-cow) + IMGFMT=add-cow + xpand=false + ;; + -qcow) IMGFMT=qcow xpand=false
tests/qemu-iotests/common.rc +19 -0
@@ -97,6 +97,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
@@ -124,6 +136,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 6 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]>---
Now add-cow is still using QEMUOptionParameter, not QemuOpts, I will send a seperate patch series to convert.
s/seperate/separate/
Quoted 11 lines
docs/specs/add-cow.txt | 128 ++++++++++++++++++++++++++++++++++++++++++++++++ 1 files changed, 128 insertions(+), 0 deletions(-) create mode 100644 docs/specs/add-cow.txtdocs/specs/add-cow.txt new file +0
-0
docs/specs/add-cow.txt line 3
Quoted 3 lines
docs/specs/add-cow.txt new file +3
-0@@ -0,0 +1,128 @@ +== General == + +Raw file format does not support backing file and copy on write feature.
grammar:
The raw file format does not support backing files or the copy-on-write feature.
docs/specs/add-cow.txt line 7
Quoted 4 lines
docs/specs/add-cow.txt new file +4
-0+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.
I'm still not sure how this series fits in with the recent discussions on adding drive-mirror with the capability of creating a raw file mirror of a qcow2 snapshot.
docs/specs/add-cow.txt line 9
Quoted 2 lines
docs/specs/add-cow.txt new file +2
-0+ +While using add-cow, procedures may like this:
grammar:
An example usage of add-cow would look like:
docs/specs/add-cow.txt line 21
Quoted 12 lines
docs/specs/add-cow.txt new file +12
-0+(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 + +test.raw may be larger than ubuntu.img, in that case, the size of test.add-cow +will be calculated by the size of ubuntu.img, test.raw will be used from the +1st byte, the rest part can be used for other purpose.
Grammar was off here, but I'm not sure what you meant to suggest a replacement. Maybe:
the size of test.add-cow will be calculated from the size of ubuntu.img, and extra space at the tail of test.raw can be used for other purposes.
docs/specs/add-cow.txt line 45
Quoted 10 lines
docs/specs/add-cow.txt new file +10
-0+(#define HEADER_SIZE (4096 * header_pages_size)) + 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 file name offset + Offset in the add-cow file at which the backing file + name is stored (NB: The string is not null terminated).
Nit: this should be nul-terminated (NUL is the one-byte all-0 character in single byte encodings that ends a string, and NULL is the four- or eight-byte value, typically all-0, for a pointer to nowhere).
docs/specs/add-cow.txt line 71
Quoted 6 lines
docs/specs/add-cow.txt new file +6
-0+ + 28 - 35: features + Currently only 3 feature bit is used: + Feature bits: + The image uses a backing file: + * ADD_COW_F_BACKING_FILE = 0x01.
Isn't this bit redundant with the earlier field at byte 12 stating whether a backing file is present?
docs/specs/add-cow.txt line 73
Quoted 2 lines
docs/specs/add-cow.txt new file +2
-0+ The image uses a image file: + * ADD_COW_F_IMAGE_FILE = 0x02.
The field at byte 20 implies that an image file name is mandatory, meaning this bit is always 1 and therefore pointless.
docs/specs/add-cow.txt line 79
Quoted 6 lines
docs/specs/add-cow.txt new file +6
-0+ All bits in bitmap have been set to 1, add-cow wrapper + can be discarded. + * ADD_COW_F_All_ALLOCATED = 0x04. + + 36 - 43: optional features + Not used now. Researved for future use.
s/Researved/Reserved/, mention that it must be set to 0
docs/specs/add-cow.txt line 91
Quoted 12 lines
docs/specs/add-cow.txt new file +12
-0+ + 44 - 47: header pages size + The header field is variable-sized. This field indicates + how many pages(4k) will be used to store add-cow header. + In add-cow v1, it is fixed to 1, so the header size will + be 4k * 1 = 4096 bytes. + +Image file name and backing file name must NOT be the same, we prevent this +while creating add-cow files. + +Image file and backing file are interpreted relative to the qcow2 file, not +to the current working directory of the process that opened the qcow2 file.
Either indent this description to match the field it is describing, or sink it down until after you have called out the header layout.
docs/specs/add-cow.txt line 98
Quoted 7 lines
docs/specs/add-cow.txt new file +7
-0+ +== Reserved == + + Byte 48 - 63: backing file format + format of backing file. It will be filled with 0 if + backing file name offset is 0. If backing file name + offset is none-zero, it must be non-zero.
s/none-zero/non-zero/
Why are you defining these byte offsets in the Reserved section? This text should occur earlier in the mandatory header format. Is this field free-form ASCII? Must the field be NUL-terminated? For that matter, I think you can just delete the ==Reserved== header, as you are calling out every possible offset.
docs/specs/add-cow.txt line 101
Quoted 3 lines
docs/specs/add-cow.txt new file +3
-0+ + 64 - 79: image file format + format of image file. It must be non-zero.
Same question about whether this field is ASCII, and must be NUL-terminated.
docs/specs/add-cow.txt line 106
Quoted 5 lines
docs/specs/add-cow.txt new file +5
-0+ + 80 - [HEADER_SIZE - 1]: + It is used to make sure COW bitmap field starts at the + HEADER_SIZE byte, backing file name and image file name + will be stored here.
Is it required that bytes not pointed to by backing file and image names must have any particular value?
docs/specs/add-cow.txt line 117
Quoted 11 lines
docs/specs/add-cow.txt new file +11
-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. the size of bitmap is +calculated according to virtual size of backing file. In each byte, bit 0 to 7 +will track the 1st to 7th cluster in sequence, bit orders in one byte look like:
1st to 7th is only 7 clusters. You mean either '0th to 7th' or '1st to 8th'. Or just simplify to:
Within each byte, the least significant bit covers the first cluster.
docs/specs/add-cow.txt line 128
Quoted 11 lines
docs/specs/add-cow.txt new file +11
-0+ +----+----+----+----+----+----+----+----+ + | 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. + +If raw image is not an even multiple of cluster bytes, bits that correspond to +bytes beyond the raw file size in add-cow will be 0.
Will this affect the use of the ADD_COW_F_ALL_ALLOCATED feature bit in the header?
Signature · 2 lines
Eric Blake [email protected] +1-919-301-3266 Libvirt virtualization library http://libvirt.org
Quoted 10 lines · Eric Blake
Quoted 6 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]>---
Now add-cow is still using QEMUOptionParameter, not QemuOpts, I will send a seperate patch series to convert.s/seperate/separate/
Yep.
Quoted 5 lines
Quoted 5 lines
docs/specs/add-cow.txt | 128 ++++++++++++++++++++++++++++++++++++++++++++++++ 1 files changed, 128 insertions(+), 0 deletions(-) create mode 100644 docs/specs/add-cow.txt
Quoted 13 lines
docs/specs/add-cow.txt line 3
Quoted 9 lines
docs/specs/add-cow.txt new file +3
-0@@ -0,0 +1,128 @@ +== General == + +Raw file format does not support backing file and copy on write feature.grammar:
The raw file format does not support backing files or the copy-on-write feature.
Yep.
Quoted 11 lines
docs/specs/add-cow.txt line 7
Quoted 5 lines
docs/specs/add-cow.txt new file +4
-0+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.I'm still not sure how this series fits in with the recent discussions on adding drive-mirror with the capability of creating a raw file mirror of a qcow2 snapshot.
Quoted 6 lines
docs/specs/add-cow.txt line 9
Quoted 2 lines
docs/specs/add-cow.txt new file +2
-0+ +While using add-cow, procedures may like this:grammar:
An example usage of add-cow would look like:
Yep.
Quoted 16 lines
docs/specs/add-cow.txt line 21
Quoted 12 lines
docs/specs/add-cow.txt new file +12
-0+(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 + +test.raw may be larger than ubuntu.img, in that case, the size of test.add-cow +will be calculated by the size of ubuntu.img, test.raw will be used from the +1st byte, the rest part can be used for other purpose.Grammar was off here, but I'm not sure what you meant to suggest a replacement. Maybe:
Quoted 2 lines
the size of test.add-cow will be calculated from the size of ubuntu.img, and extra space at the tail of test.raw can be used for other purposes.
Yes, this is what I mean.
Quoted 24 lines
docs/specs/add-cow.txt line 45
Quoted 11 lines
docs/specs/add-cow.txt new file +10
-0+(#define HEADER_SIZE (4096 * header_pages_size)) + 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 file name offset + Offset in the add-cow file at which the backing file + name is stored (NB: The string is not null terminated).Nit: this should be nul-terminated (NUL is the one-byte all-0 character in single byte encodings that ends a string, and NULL is the four- or eight-byte value, typically all-0, for a pointer to nowhere).
docs/specs/add-cow.txt line 71
Quoted 6 lines
docs/specs/add-cow.txt new file +6
-0+ + 28 - 35: features + Currently only 3 feature bit is used: + Feature bits: + The image uses a backing file: + * ADD_COW_F_BACKING_FILE = 0x01.
Quoted 3 lines
Isn't this bit redundant with the earlier field at byte 12 stating whether a backing file is present?
Yes, it is redundant. I just want to make if the add-cow image is using backing_file more clear.
Quoted 6 lines
docs/specs/add-cow.txt line 73
Quoted 2 lines
docs/specs/add-cow.txt new file +2
-0+ The image uses a image file: + * ADD_COW_F_IMAGE_FILE = 0x02.The field at byte 20 implies that an image file name is mandatory, meaning this bit is always 1 and therefore pointless.
Quoted 8 lines
docs/specs/add-cow.txt line 79
Quoted 6 lines
docs/specs/add-cow.txt new file +6
-0+ All bits in bitmap have been set to 1, add-cow wrapper + can be discarded. + * ADD_COW_F_All_ALLOCATED = 0x04. + + 36 - 43: optional features + Not used now. Researved for future use.s/Researved/Reserved/, mention that it must be set to 0
Okay.
Quoted 16 lines
docs/specs/add-cow.txt line 91
Quoted 13 lines
docs/specs/add-cow.txt new file +12
-0+ + 44 - 47: header pages size + The header field is variable-sized. This field indicates + how many pages(4k) will be used to store add-cow header. + In add-cow v1, it is fixed to 1, so the header size will + be 4k * 1 = 4096 bytes. + +Image file name and backing file name must NOT be the same, we prevent this +while creating add-cow files. + +Image file and backing file are interpreted relative to the qcow2 file, not +to the current working directory of the process that opened the qcow2 file.Either indent this description to match the field it is describing, or sink it down until after you have called out the header layout.
Okay.
Quoted 10 lines
docs/specs/add-cow.txt line 98
Quoted 8 lines
docs/specs/add-cow.txt new file +7
-0+ +== Reserved == + + Byte 48 - 63: backing file format + format of backing file. It will be filled with 0 if + backing file name offset is 0. If backing file name + offset is none-zero, it must be non-zero.s/none-zero/non-zero/
Okay.
Quoted 7 lines
Why are you defining these byte offsets in the Reserved section? This text should occur earlier in the mandatory header format. Is this field free-form ASCII? Must the field be NUL-terminated? For that matter, I think you can just delete the ==Reserved== header, as you are calling out every possible offset.
Okay. I will describle more clearly in v12.
Quoted 6 lines
docs/specs/add-cow.txt line 101
Quoted 3 lines
docs/specs/add-cow.txt new file +3
-0+ + 64 - 79: image file format + format of image file. It must be non-zero.Same question about whether this field is ASCII, and must be NUL-terminated.
Okay.
Quoted 8 lines
docs/specs/add-cow.txt line 106
Quoted 5 lines
docs/specs/add-cow.txt new file +5
-0+ + 80 - [HEADER_SIZE - 1]: + It is used to make sure COW bitmap field starts at the + HEADER_SIZE byte, backing file name and image file name + will be stored here.Is it required that bytes not pointed to by backing file and image names must have any particular value?
It must be 0, I will correct it later.
Quoted 16 lines
docs/specs/add-cow.txt line 117
Quoted 12 lines
docs/specs/add-cow.txt new file +11
-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. the size of bitmap is +calculated according to virtual size of backing file. In each byte, bit 0 to 7 +will track the 1st to 7th cluster in sequence, bit orders in one byte look like:1st to 7th is only 7 clusters. You mean either '0th to 7th' or '1st to 8th'. Or just simplify to:
Quoted 1 line
Within each byte, the least significant bit covers the first cluster.
Okay.
Quoted 15 lines
docs/specs/add-cow.txt line 128
Quoted 12 lines
docs/specs/add-cow.txt new file +11
-0+ +----+----+----+----+----+----+----+----+ + | 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. + +If raw image is not an even multiple of cluster bytes, bits that correspond to +bytes beyond the raw file size in add-cow will be 0.Will this affect the use of the
ADD_COW_F_ALL_ALLOCATEDfeature bit in the header?
No, beyond the raw file size, the related bits in bitmap will make no sense.
I mean: ADD_COW_F_ALL_ALLOCATED will be set when:
1) If add-cow is created only use image_file option, but no backing_file option.
In this case, bitmap will be useless.
2) when all sectors have been allocated in image_file, we will not use image_file.
but in this case, I think it is hard to determine whether all sectors have been allocated
or not, scanning all bitmap will take some time, maybe we can do this when we call
"qemu-io check"? Or before opening add-cow files, we do a check?
Any comments?
Thank you, Eric,
Quoted 5 lines
--
Eric Blake [email protected] +1-919-301-3266
Libvirt virtualization library http://libvirt.org
Quoted 6 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]>---
Now add-cow is still using QEMUOptionParameter, not QemuOpts, I will send a seperate patch series to convert.
I suggest including a cover letter in future patch series:
git format-patch --cover-letter --numbered -o my-series/ master..
Or to do it in a single command with git-send-email(1) use the --compose option.
The cover letter makes it easy for reviewers to add their Reviewed-by:
to the entire series by replying only once. It's also a good place to include a changelog that tells reviewers what you changed from the last published version.
Quoted 21 lines
docs/specs/add-cow.txt | 128 ++++++++++++++++++++++++++++++++++++++++++++++++ 1 files changed, 128 insertions(+), 0 deletions(-) create mode 100644 docs/specs/add-cow.txtdocs/specs/add-cow.txt new file +11
-0@@ -0,0 +1,128 @@ +== 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
docs/specs/add-cow.txt line 21
Quoted 10 lines
docs/specs/add-cow.txt new file +10
-0+ 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 + +test.raw may be larger than ubuntu.img, in that case, the size of test.add-cow +will be calculated by the size of ubuntu.img, test.raw will be used from the +1st byte, the rest part can be used for other purpose.
This is not how backing files normally work. With qcow2 or qed a smaller backing file just means that the guest reads zeroes from the areas beyond the end of the backing file. Is there a special reason why you want to implement the behavior you described in the spec? Otherwise I suggest implementing the same behavior as qcow2/qed.
Quoted 48 lines
docs/specs/add-cow.txt new file +48
-0+ +=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: +(#define HEADER_SIZE (4096 * header_pages_size)) + 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 file name offset + Offset in the add-cow file at which the backing file + name is stored (NB: The string is not null terminated). + If backing file name does NOT exist, this field will be + 0. Must be between 80 and [HEADER_SIZE - 2](a file name + must be at least 1 byte). + + 16 - 19: backing file name size + Length of the backing file name in bytes. It will be 0 + if the backing file name offset is 0. If backing file + name offset is non-zero, then it must be non-zero. Must + be less than [HEADER_SIZE - 80] to fit in the reserved + part of the header. + + 20 - 23: image file name offset + Offset in the add-cow file at which the image file name + is stored (NB: The string is not null terminated). It + must be between 80 and [HEADER_SIZE - 2]. + + 24 - 27: image file name size + Length of the image file name in bytes. + Must be less than [HEADER_SIZE - 80] to fit in the reserved + part of the header. + + 28 - 35: features + Currently only 3 feature bit is used: + Feature bits:
docs/specs/add-cow.txt line 79
Quoted 10 lines
docs/specs/add-cow.txt new file +10
-0+ The image uses a backing file: + * ADD_COW_F_BACKING_FILE = 0x01. + The image uses a image file: + * ADD_COW_F_IMAGE_FILE = 0x02. + All bits in bitmap have been set to 1, add-cow wrapper + can be discarded. + * ADD_COW_F_All_ALLOCATED = 0x04. + + 36 - 43: optional features + Not used now. Researved for future use.
s/Researved/Reserved/
Quoted 9 lines
docs/specs/add-cow.txt new file +9
-0+ + 44 - 47: header pages size + The header field is variable-sized. This field indicates + how many pages(4k) will be used to store add-cow header. + In add-cow v1, it is fixed to 1, so the header size will + be 4k * 1 = 4096 bytes. + +Image file name and backing file name must NOT be the same, we prevent this +while creating add-cow files.
docs/specs/add-cow.txt line 98
Quoted 10 lines
docs/specs/add-cow.txt new file +10
-0+ +Image file and backing file are interpreted relative to the qcow2 file, not +to the current working directory of the process that opened the qcow2 file. + +== Reserved == + + Byte 48 - 63: backing file format + format of backing file. It will be filled with 0 if + backing file name offset is 0. If backing file name + offset is none-zero, it must be non-zero.
s/none-zero/non-zero/
docs/specs/add-cow.txt line 110
Quoted 12 lines
docs/specs/add-cow.txt new file +12
-0+ + 64 - 79: image file format + format of image file. It must be non-zero. + + 80 - [HEADER_SIZE - 1]: + It is used to make sure COW bitmap field starts at the + HEADER_SIZE 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
I would say it starts at offset HEADER_SIZE. 4096th byte == offset 0x0fff, 4097th byte == offset 0x1000.
Stefan
Quoted 11 lines · Stefan Hajnoczi
Quoted 6 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]>---
Now add-cow is still using QEMUOptionParameter, not QemuOpts, I will send a seperate patch series to convert.I suggest including a cover letter in future patch series:
Quoted 8 lines
git format-patch --cover-letter --numbered -o my-series/ master..
Or to do it in a single command with git-send-email(1) use the --compose option.
The cover letter makes it easy for reviewers to add their Reviewed-by:
to the entire series by replying only once. It's also a good place to include a changelog that tells reviewers what you changed from the last published version.
Okay.
Quoted 30 lines
Quoted 30 lines
docs/specs/add-cow.txt | 128 ++++++++++++++++++++++++++++++++++++++++++++++++ 1 files changed, 128 insertions(+), 0 deletions(-) create mode 100644 docs/specs/add-cow.txtdocs/specs/add-cow.txt new file +19
-0@@ -0,0 +1,128 @@ +== 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 + +test.raw may be larger than ubuntu.img, in that case, the size of test.add-cow
Quoted 8 lines
docs/specs/add-cow.txt line 21
Quoted 2 lines
docs/specs/add-cow.txt new file +2
-0+will be calculated by the size of ubuntu.img, test.raw will be used from the +1st byte, the rest part can be used for other purpose.This is not how backing files normally work. With qcow2 or qed a smaller backing file just means that the guest reads zeroes from the areas beyond the end of the backing file. Is there a special reason why you want to implement the behavior you described in the spec? Otherwise I suggest implementing the same behavior as qcow2/qed.
The size of add-cow will be caclulated by the size of backing_file, if backing_file can be smaller, how can I get the size of add-cow while being created?
Do you mean like following steps?
1) qemu-img create -f qcow2 source.qcow2 *8G*
2) qemu-img create -f t.add-cow -o backing_file=source.qcow2,image_file=t *10G* And then reading un-allocated bytes from add-cow after 8G will be 0?
Quoted 53 lines
Quoted 53 lines
docs/specs/add-cow.txt new file +52
-0+ +=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: +(#define HEADER_SIZE (4096 * header_pages_size)) + 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 file name offset + Offset in the add-cow file at which the backing file + name is stored (NB: The string is not null terminated). + If backing file name does NOT exist, this field will be + 0. Must be between 80 and [HEADER_SIZE - 2](a file name + must be at least 1 byte). + + 16 - 19: backing file name size + Length of the backing file name in bytes. It will be 0 + if the backing file name offset is 0. If backing file + name offset is non-zero, then it must be non-zero. Must + be less than [HEADER_SIZE - 80] to fit in the reserved + part of the header. + + 20 - 23: image file name offset + Offset in the add-cow file at which the image file name + is stored (NB: The string is not null terminated). It + must be between 80 and [HEADER_SIZE - 2]. + + 24 - 27: image file name size + Length of the image file name in bytes. + Must be less than [HEADER_SIZE - 80] to fit in the reserved + part of the header. + + 28 - 35: features + Currently only 3 feature bit is used: + Feature bits: + The image uses a backing file: + * ADD_COW_F_BACKING_FILE = 0x01. + The image uses a image file: + * ADD_COW_F_IMAGE_FILE = 0x02.
Quoted 8 lines
docs/specs/add-cow.txt line 79
Quoted 6 lines
docs/specs/add-cow.txt new file +6
-0+ All bits in bitmap have been set to 1, add-cow wrapper + can be discarded. + * ADD_COW_F_All_ALLOCATED = 0x04. + + 36 - 43: optional features + Not used now. Researved for future use.s/Researved/Reserved/
Okay.
Quoted 14 lines
Quoted 14 lines
docs/specs/add-cow.txt new file +13
-0+ + 44 - 47: header pages size + The header field is variable-sized. This field indicates + how many pages(4k) will be used to store add-cow header. + In add-cow v1, it is fixed to 1, so the header size will + be 4k * 1 = 4096 bytes. + +Image file name and backing file name must NOT be the same, we prevent this +while creating add-cow files. + +Image file and backing file are interpreted relative to the qcow2 file, not +to the current working directory of the process that opened the qcow2 file. +
Quoted 8 lines
docs/specs/add-cow.txt line 98
Quoted 6 lines
docs/specs/add-cow.txt new file +6
-0+== Reserved == + + Byte 48 - 63: backing file format + format of backing file. It will be filled with 0 if + backing file name offset is 0. If backing file name + offset is none-zero, it must be non-zero.s/none-zero/non-zero/
Okay.
Quoted 16 lines
docs/specs/add-cow.txt line 110
Quoted 13 lines
docs/specs/add-cow.txt new file +12
-0+ + 64 - 79: image file format + format of image file. It must be non-zero. + + 80 - [HEADER_SIZE - 1]: + It is used to make sure COW bitmap field starts at the + HEADER_SIZE 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 toI would say it starts at offset
HEADER_SIZE. 4096th byte == offset0x0fff, 4097th byte == offset0x1000.
Okay.
Quoted 3 lines
Stefan
Thank you Stefan.
Quoted 13 lines · Dong Xu Wang
Quoted 11 lines · Stefan Hajnoczi
docs/specs/add-cow.txt line 21
Quoted 3 lines · Dong Xu Wang
docs/specs/add-cow.txt new file +3
-0+test.raw may be larger than ubuntu.img, in that case, the size of test.add-cow +will be calculated by the size of ubuntu.img, test.raw will be used from the +1st byte, the rest part can be used for other purpose.This is not how backing files normally work. With qcow2 or qed a smaller backing file just means that the guest reads zeroes from the areas beyond the end of the backing file. Is there a special reason why you want to implement the behavior you described in the spec? Otherwise I suggest implementing the same behavior as qcow2/qed.
Quoted 8 lines
The size of add-cow will be caclulated by the size of
backing_file, ifbacking_filecan be smaller, how can I get the size of add-cow while being created?Do you mean like following steps?
1) qemu-img create -f qcow2 source.qcow2 *8G*
2) qemu-img create -f t.add-cow -o backing_file=source.qcow2,image_file=t *10G* And then reading un-allocated bytes from add-cow after 8G will be 0?
Yes. You could also get the virtual disk size from the size of the image_file during creation.
Stefan
Quoted 18 lines · Stefan Hajnoczi
Quoted 17 lines · Dong Xu Wang
Quoted 11 lines · Stefan Hajnoczi
docs/specs/add-cow.txt line 21
Quoted 3 lines · Dong Xu Wang
docs/specs/add-cow.txt new file +3
-0+test.raw may be larger than ubuntu.img, in that case, the size of test.add-cow +will be calculated by the size of ubuntu.img, test.raw will be used from the +1st byte, the rest part can be used for other purpose.This is not how backing files normally work. With qcow2 or qed a smaller backing file just means that the guest reads zeroes from the areas beyond the end of the backing file. Is there a special reason why you want to implement the behavior you described in the spec? Otherwise I suggest implementing the same behavior as qcow2/qed.
The size of add-cow will be caclulated by the size of
backing_file, ifbacking_filecan be smaller, how can I get the size of add-cow while being created?
Quoted 7 lines
Quoted 4 lines
Do you mean like following steps?
1) qemu-img create -f qcow2 source.qcow2 *8G*
2) qemu-img create -f t.add-cow -o backing_file=source.qcow2,image_file=t *10G* And then reading un-allocated bytes from add-cow after 8G will be 0?Yes. You could also get the virtual disk size from the size of the
image_fileduring creation.
Eric said I shoud make sure we also support a raw file larger than the backing file. so
add-cow will have the same virtual size with image_file, and their virtual size can be larger
than backing_file's.
Am I right?
Thanks.
Quoted 2 lines
Stefan
Quoted 24 lines · Dong Xu Wang
Quoted 23 lines · Stefan Hajnoczi
Quoted 21 lines · Dong Xu Wang
Quoted 11 lines · Stefan Hajnoczi
docs/specs/add-cow.txt line 21
Quoted 3 lines · Dong Xu Wang
docs/specs/add-cow.txt new file +3
-0+test.raw may be larger than ubuntu.img, in that case, the size of test.add-cow +will be calculated by the size of ubuntu.img, test.raw will be used from the +1st byte, the rest part can be used for other purpose.This is not how backing files normally work. With qcow2 or qed a smaller backing file just means that the guest reads zeroes from the areas beyond the end of the backing file. Is there a special reason why you want to implement the behavior you described in the spec? Otherwise I suggest implementing the same behavior as qcow2/qed.
The size of add-cow will be caclulated by the size of
backing_file, ifbacking_filecan be smaller, how can I get the size of add-cow while being created?Do you mean like following steps?
1) qemu-img create -f qcow2 source.qcow2 *8G*
2) qemu-img create -f t.add-cow -o backing_file=source.qcow2,image_file=t *10G* And then reading un-allocated bytes from add-cow after 8G will be 0?
Quoted 8 lines
Quoted 2 lines
Yes. You could also get the virtual disk size from the size of the
image_fileduring creation.Eric said I shoud make sure we also support a raw file larger than the backing file. so
add-cow will have the same virtual size withimage_file, and their virtual size can be larger
than backing_file's.
Yes. Please update the spec because it says the opposite:
"test.raw may be larger than ubuntu.img, in that case, the size of test.add-cow will be calculated by the size of ubuntu.img"
It should use the size of test.raw.
Stefan
Quoted 34 lines · Stefan Hajnoczi
Quoted 24 lines · Dong Xu Wang
Quoted 23 lines · Stefan Hajnoczi
Quoted 21 lines · Dong Xu Wang
Quoted 11 lines · Stefan Hajnoczi
docs/specs/add-cow.txt line 21
Quoted 3 lines · Dong Xu Wang
docs/specs/add-cow.txt new file +3
-0+test.raw may be larger than ubuntu.img, in that case, the size of test.add-cow +will be calculated by the size of ubuntu.img, test.raw will be used from the +1st byte, the rest part can be used for other purpose.This is not how backing files normally work. With qcow2 or qed a smaller backing file just means that the guest reads zeroes from the areas beyond the end of the backing file. Is there a special reason why you want to implement the behavior you described in the spec? Otherwise I suggest implementing the same behavior as qcow2/qed.
The size of add-cow will be caclulated by the size of
backing_file, ifbacking_filecan be smaller, how can I get the size of add-cow while being created?Do you mean like following steps?
1) qemu-img create -f qcow2 source.qcow2 *8G*
2) qemu-img create -f t.add-cow -o backing_file=source.qcow2,image_file=t *10G* And then reading un-allocated bytes from add-cow after 8G will be 0?Quoted 8 lines
Quoted 2 lines
Yes. You could also get the virtual disk size from the size of the
image_fileduring creation.Eric said I shoud make sure we also support a raw file larger than the backing file. so
add-cow will have the same virtual size withimage_file, and their virtual size can be larger
than backing_file's.
Quoted 4 lines
Yes. Please update the spec because it says the opposite:
"test.raw may be larger than ubuntu.img, in that case, the size of test.add-cow will be calculated by the size of ubuntu.img"
Okay. Thanks.
Quoted 5 lines
It should use the size of test.raw.
Stefan