support add-cow file format
Subsystems (2)
PATCH 1/1 support add-cow file format
As raw file format does not support backing_file and copy on write feature, so I add COW to it to support backing_file option. I store dirty bitmap in an add-cow file. When executed, it looks like this:
qemu-img create -f add-cow -o backing_file=ubuntu.img,image_file=test.img test.add-cow qemu -drive if=virtio,file=test.add-cow -m 1024
(test.img is a raw format file; test.add-cow stores bitmap)
--- Makefile.objs | 1 + block.c | 83 ++++++++++- block.h | 2 + block/add-cow.c | 456 +++++++++++++++++++++++++++++++++++++++++++++++++++++++ block_int.h | 6 + qemu-img.c | 10 ++ 6 files changed, 555 insertions(+), 3 deletions(-) create mode 100644 block/add-cow.c
Makefile.objs +1 -0
@@ -31,6 +31,7 @@ block-obj-$(CONFIG_LINUX_AIO) += linux-aio.o block-nested-y += raw.o cow.o qcow.o vdi.o vmdk.o cloop.o dmg.o bochs.o vpc.o vvfat.o block-nested-y += qcow2.o qcow2-refcount.o qcow2-cluster.o qcow2-snapshot.o qcow2-cache.o +block-nested-y += add-cow.o block-nested-y += qed.o qed-gencb.o qed-l2-cache.o qed-table.o qed-cluster.o block-nested-y += qed-check.o block-nested-y += parallels.o nbd.o blkdebug.o sheepdog.o blkverify.o
block.c +80 -3
157 lines not on this page · raw message
block.h +2 -0
@@ -228,6 +228,8 @@ int bdrv_get_info(BlockDriverState *bs, BlockDriverInfo *bdi);const char *bdrv_get_encrypted_filename (BlockDriverState *bs);void bdrv_get_backing_filename (BlockDriverState *bs,char *filename,int filename_size); +void bdrv_get_image_filename (BlockDriverState *bs, +char *filename,int filename_size);int bdrv_can_snapshot (BlockDriverState *bs);int bdrv_is_snapshot (BlockDriverState *bs);BlockDriverState *bdrv_snapshots (void );
block/add-cow.c new file +456 -0
456 lines not on this page · raw message
block_int.h +6 -0
@@ -42,6 +42,7 @@#define BLOCK_OPT_TABLE_SIZE "table_size"#define BLOCK_OPT_PREALLOC "preallocation"#define BLOCK_OPT_SUBFMT "subformat" +#define BLOCK_OPT_IMAGE_FILE "image_file" typedef struct AIOPool { void (*cancel)(BlockDriverAIOCB *acb);
@@ -208,6 +209,11 @@ struct BlockDriverState {int in_use;/* users other than guest access, eg. block migration */ QTAILQ_ENTRY (BlockDriverState) list;void *private; + +char image_file[1024 ]; +BlockDriverState *image_hd; +uint8_t *bitmap; +uint64_t bitmap_size; };struct BlockDriverAIOCB {
qemu-img.c +10 -0
@@ -1093,6 +1093,8 @@ static int img_info(int argc, char **argv)int64_t allocated_size;char backing_filename[1024 ];char backing_filename2[1024 ]; +char image_filename[1024 ]; +char image_filename2[1024 ];BlockDriverInfo bdi; fmt =NULL ;
@@ -1153,6 +1155,14 @@ static int img_info(int argc, char **argv) backing_filename, backing_filename2); } +bdrv_get_image_filename (bs, image_filename,sizeof (image_filename)); +if (image_filename[0 ] !='\0' ) { +path_combine (image_filename2,sizeof (image_filename2), + filename, image_filename); +printf ("image file: %s (actual path: %s)\n" , + image_filename, + image_filename2); + }dump_snapshots (bs);bdrv_delete (bs);return 0 ;
Signature · 1 line
1.7.4.1
Am 09.09.2011 07:48, schrieb Dong Xu Wang:
Quoted 9 lines
As raw file format does not support
backing_fileand copy on write feature, so I add COW to it to supportbacking_fileoption. I store dirty bitmap in an add-cow file. When executed, it looks like this:
qemu-img create -f add-cow -o backing_file=ubuntu.img,image_file=test.img test.add-cow qemu -drive if=virtio,file=test.add-cow -m 1024(test.img is a raw format file; test.add-cow stores bitmap)
Signed-off-by Dong Xu Wang <[email protected]>
You should not make any changes to generic code, except maybe add something to bdrv_get_info(). In particular you shouldn't need to touch bdrv_open() or bdrv_create() at all.
The one required change in the approach for this to work is that you shouldn't view raw+add_cow as a unit, but add_cow should be treated as something separate that happens to be stacked on a raw file (which is created separately).
Then you can do almost everything in block/add-cow.c.
Quoted 27 lines
--- Makefile.objs | 1 + block.c | 83 ++++++++++- block.h | 2 + block/add-cow.c | 456 +++++++++++++++++++++++++++++++++++++++++++++++++++++++ block_int.h | 6 + qemu-img.c | 10 ++ 6 files changed, 555 insertions(+), 3 deletions(-) create mode 100644 block/add-cow.cMakefile.objs +1
-0@@ -31,6 +31,7 @@ block-obj-$(CONFIG_LINUX_AIO) += linux-aio.o block-nested-y += raw.o cow.o qcow.o vdi.o vmdk.o cloop.o dmg.o bochs.o vpc.o vvfat.o block-nested-y += qcow2.o qcow2-refcount.o qcow2-cluster.o qcow2-snapshot.o qcow2-cache.o +block-nested-y += add-cow.o block-nested-y += qed.o qed-gencb.o qed-l2-cache.o qed-table.o qed-cluster.o block-nested-y += qed-check.o block-nested-y += parallels.o nbd.o blkdebug.o sheepdog.o blkverify.oblock.c +0
-0
block.c static int find_image_format(const char *filename, BlockDriver **pdrv) · line 373
Quoted 6 lines
block.c +1
-1@@ -369,7 +369,7 @@ static int find_image_format(const char *filename, BlockDriver **pdrv) {int ret, score, score_max;BlockDriver *drv1, *drv; -uint8_t buf[2048 ]; +uint8_t buf[4096 ];BlockDriverState *bs;
What's the reason for this change?
Quoted 14 lines
block/add-cow.c new file +8
-0@@ -0,0 +1,456 @@ +#include "qemu-common.h" +#include "block_int.h" +#include "module.h" + +#define ADD_COW_MAGIC (((uint64_t)'A' << 56) | ((uint64_t)'D' << 48) | \ + ((uint64_t)'D' << 40) | ((uint64_t)'_' << 32) | \ + ((uint64_t)'C' << 24) | ((uint64_t)'O' << 16) | \ + ((uint64_t)'W' << 8) | 0xFF)
block/add-cow.c line 18
Quoted 10 lines
block/add-cow.c new file +10
-0+#define ADD_COW_VERSION 1 + +struct add_cow_header { +uint64_t magic; +uint32_t version; +char backing_file[1024 ]; +char image_file[1024 ]; +uint64_t size; +uint32_t sectorsize; +} add_cow_header;
QEMU_PACKED
Quoted 7 lines
block/add-cow.c new file +7
-0+typedef struct BDRVAddCowState { +CoMutex lock; +CoMutex bitmap_lock; +}BDRVAddCowState ; + +typedef struct AddCowAIOCB { + BlockDriverAIOCB common;
block/add-cow.c line 36
Quoted 10 lines
block/add-cow.c new file +10
-0+int64_t sector_num; +QEMUIOVector *qiov; +int remaining_sectors; +int cur_nr_sectors; +uint64_t bytes_done; +bool is_write; +QEMUIOVector hd_qiov; +QEMUBH *bh; + +} AddCowAIOCB;
You shouldn't be using AIOCBs with a coroutine-based block driver. Instead you should just use variables on the stack and function parameters.
block/add-cow.c line 425
Quoted 4 lines
block/add-cow.c new file +4
-0+static int add_cow_flush (BlockDriverState *bs) +{ +return bdrv_flush (bs->file); +}
What about bs->image_hd?
block/add-cow.c struct BlockDriverState { · line 217
Quoted 10 lines
block/add-cow.c new file +5
-0@@ -208,6 +209,11 @@ struct BlockDriverState {int in_use;/* users other than guest access, eg. block migration */ QTAILQ_ENTRY (BlockDriverState) list;void *private; + +char image_file[1024 ]; +BlockDriverState *image_hd; +uint8_t *bitmap; +uint64_t bitmap_size; };
These belong in BDRVAddCowState.
Kevin
于Fri 09 Sep 2011 10:27:26 PM CST,Kevin Wolf写到:
Quoted 47 lines
Am 09.09.2011 07:48, schrieb Dong Xu Wang:
Quoted 7 lines
As raw file format does not support
backing_fileand copy on write feature, so I add COW to it to supportbacking_fileoption. I store dirty bitmap in an add-cow file. When executed, it looks like this:
qemu-img create -f add-cow -o backing_file=ubuntu.img,image_file=test.img test.add-cow
qemu -drive if=virtio,file=test.add-cow -m 1024(test.img is a raw format file; test.add-cow stores bitmap)
Signed-off-by Dong Xu Wang <[email protected]>You should not make any changes to generic code, except maybe add something to
bdrv_get_info(). In particular you shouldn't need to touchbdrv_open()orbdrv_create()at all.The one required change in the approach for this to work is that you shouldn't view raw+add_cow as a unit, but
add_cowshould be treated as something separate that happens to be stacked on a raw file (which is created separately).Then you can do almost everything in
block/add-cow.c.Quoted 27 lines
--- Makefile.objs | 1 + block.c | 83 ++++++++++- block.h | 2 + block/add-cow.c | 456 +++++++++++++++++++++++++++++++++++++++++++++++++++++++ block_int.h | 6 + qemu-img.c | 10 ++ 6 files changed, 555 insertions(+), 3 deletions(-) create mode 100644 block/add-cow.cMakefile.objs +1
-0@@ -31,6 +31,7 @@ block-obj-$(CONFIG_LINUX_AIO) += linux-aio.o block-nested-y += raw.o cow.o qcow.o vdi.o vmdk.o cloop.o dmg.o bochs.o vpc.o vvfat.o block-nested-y += qcow2.o qcow2-refcount.o qcow2-cluster.o qcow2-snapshot.o qcow2-cache.o +block-nested-y += add-cow.o block-nested-y += qed.o qed-gencb.o qed-l2-cache.o qed-table.o qed-cluster.o block-nested-y += qed-check.o block-nested-y += parallels.o nbd.o blkdebug.o sheepdog.o blkverify.oblock.c +0
-0@@ -369,7 +369,7 @@ static int find_image_format(const char *filename, BlockDriver **pdrv)
Quoted 9 lines
block.c static int find_image_format(const char *filename, BlockDriver **pdrv) · line 373
Quoted 6 lines
block.c +1
-1{int ret, score, score_max;BlockDriver *drv1, *drv; -uint8_t buf[2048 ]; +uint8_t buf[4096 ];BlockDriverState *bs;What's the reason for this change?
The size of add_cow_header in my code is larger than 2048.
Quoted 18 lines
Quoted 18 lines
block/add-cow.c new file +12
-0@@ -0,0 +1,456 @@ +#include "qemu-common.h" +#include "block_int.h" +#include "module.h" + +#define ADD_COW_MAGIC (((uint64_t)'A' << 56) | ((uint64_t)'D' << 48) | \ + ((uint64_t)'D' << 40) | ((uint64_t)'_' << 32) | \ + ((uint64_t)'C' << 24) | ((uint64_t)'O' << 16) | \ + ((uint64_t)'W' << 8) | 0xFF) +#define ADD_COW_VERSION 1 + +struct add_cow_header { +uint64_t magic;
Quoted 8 lines
block/add-cow.c line 18
Quoted 6 lines
block/add-cow.c new file +6
-0+uint32_t version; +char backing_file[1024 ]; +char image_file[1024 ]; +uint64_t size; +uint32_t sectorsize; +} add_cow_header;
QEMU_PACKED
Sorry, what does QEMU_PACKED mean?
Quoted 42 lines
Quoted 8 lines
block/add-cow.c new file +7
-0+typedef struct BDRVAddCowState { +CoMutex lock; +CoMutex bitmap_lock; +}BDRVAddCowState ; + +typedef struct AddCowAIOCB { + BlockDriverAIOCB common;block/add-cow.c line 36
Quoted 10 lines
block/add-cow.c new file +10
-0+int64_t sector_num; +QEMUIOVector *qiov; +int remaining_sectors; +int cur_nr_sectors; +uint64_t bytes_done; +bool is_write; +QEMUIOVector hd_qiov; +QEMUBH *bh; + +} AddCowAIOCB;You shouldn't be using AIOCBs with a coroutine-based block driver. Instead you should just use variables on the stack and function parameters.
block/add-cow.c line 425
Quoted 4 lines
block/add-cow.c new file +4
-0+static int add_cow_flush (BlockDriverState *bs) +{ +return bdrv_flush (bs->file); +}What about
bs->image_hd?block/add-cow.c struct BlockDriverState { · line 217
Quoted 10 lines
block/add-cow.c new file +5
-0@@ -208,6 +209,11 @@ struct BlockDriverState {int in_use;/* users other than guest access, eg. block migration */ QTAILQ_ENTRY (BlockDriverState) list;void *private; + +char image_file[1024 ]; +BlockDriverState *image_hd; +uint8_t *bitmap; +uint64_t bitmap_size; };These belong in BDRVAddCowState.
Quoted 3 lines
Kevin
Thanks for your comments Kevin, I will produce a second version soon.
Am 10.09.2011 02:54, schrieb Dong Xu Wang:
Quoted 59 lines
于Fri 09 Sep 2011 10:27:26 PM CST,Kevin Wolf写到:
Quoted 49 lines
Am 09.09.2011 07:48, schrieb Dong Xu Wang:
Quoted 9 lines
As raw file format does not support
backing_fileand copy on write feature, so I add COW to it to supportbacking_fileoption. I store dirty bitmap in an add-cow file. When executed, it looks like this:
qemu-img create -f add-cow -o backing_file=ubuntu.img,image_file=test.img test.add-cow qemu -drive if=virtio,file=test.add-cow -m 1024(test.img is a raw format file; test.add-cow stores bitmap)
Signed-off-by Dong Xu Wang <[email protected]>You should not make any changes to generic code, except maybe add something to
bdrv_get_info(). In particular you shouldn't need to touchbdrv_open()orbdrv_create()at all.The one required change in the approach for this to work is that you shouldn't view raw+add_cow as a unit, but
add_cowshould be treated as something separate that happens to be stacked on a raw file (which is created separately).Then you can do almost everything in
block/add-cow.c.Quoted 27 lines
--- Makefile.objs | 1 + block.c | 83 ++++++++++- block.h | 2 + block/add-cow.c | 456 +++++++++++++++++++++++++++++++++++++++++++++++++++++++ block_int.h | 6 + qemu-img.c | 10 ++ 6 files changed, 555 insertions(+), 3 deletions(-) create mode 100644 block/add-cow.cMakefile.objs +1
-0@@ -31,6 +31,7 @@ block-obj-$(CONFIG_LINUX_AIO) += linux-aio.o block-nested-y += raw.o cow.o qcow.o vdi.o vmdk.o cloop.o dmg.o bochs.o vpc.o vvfat.o block-nested-y += qcow2.o qcow2-refcount.o qcow2-cluster.o qcow2-snapshot.o qcow2-cache.o +block-nested-y += add-cow.o block-nested-y += qed.o qed-gencb.o qed-l2-cache.o qed-table.o qed-cluster.o block-nested-y += qed-check.o block-nested-y += parallels.o nbd.o blkdebug.o sheepdog.o blkverify.oblock.c +0
-0@@ -369,7 +369,7 @@ static int find_image_format(const char *filename, BlockDriver **pdrv)Quoted 9 lines
block.c static int find_image_format(const char *filename, BlockDriver **pdrv) · line 373
Quoted 6 lines
block.c +1
-1{int ret, score, score_max;BlockDriver *drv1, *drv; -uint8_t buf[2048 ]; +uint8_t buf[4096 ];BlockDriverState *bs;What's the reason for this change?
Quoted 1 line
The size of
add_cow_headerin my code is larger than 2048.
Right, but the magic is in the first 8 bytes, so for probing 2048 bytes should be more than enough.
Quoted 26 lines
Quoted 18 lines
Quoted 18 lines
block/add-cow.c new file +12
-0@@ -0,0 +1,456 @@ +#include "qemu-common.h" +#include "block_int.h" +#include "module.h" + +#define ADD_COW_MAGIC (((uint64_t)'A' << 56) | ((uint64_t)'D' << 48) | \ + ((uint64_t)'D' << 40) | ((uint64_t)'_' << 32) | \ + ((uint64_t)'C' << 24) | ((uint64_t)'O' << 16) | \ + ((uint64_t)'W' << 8) | 0xFF) +#define ADD_COW_VERSION 1 + +struct add_cow_header { +uint64_t magic;Quoted 8 lines
block/add-cow.c line 18
Quoted 6 lines
block/add-cow.c new file +6
-0+uint32_t version; +char backing_file[1024 ]; +char image_file[1024 ]; +uint64_t size; +uint32_t sectorsize; +} add_cow_header;
QEMU_PACKED
Quoted 1 line
Sorry, what does
QEMU_PACKEDmean?
This is an on-disk structure, so you need to pack the structure. Otherwise the compiler would be free to add padding between the fields in order to optimise alignment.
struct add_cow_header {
...
} QEMU_PACKED add_cow_header;Hm, actually, do you really want to declare a global variable here? Or is a typedef missing? Also, coding style requires the struct name to be spelled AddCowHeader.
Kevin
于Mon 12 Sep 2011 03:59:07 PM CST,Kevin Wolf写到:
Quoted 99 lines
Am 10.09.2011 02:54, schrieb Dong Xu Wang:
Quoted 57 lines
于Fri 09 Sep 2011 10:27:26 PM CST,Kevin Wolf写到:
Quoted 47 lines
Am 09.09.2011 07:48, schrieb Dong Xu Wang:
Quoted 7 lines
As raw file format does not support
backing_fileand copy on write feature, so I add COW to it to supportbacking_fileoption. I store dirty bitmap in an add-cow file. When executed, it looks like this:
qemu-img create -f add-cow -o backing_file=ubuntu.img,image_file=test.img test.add-cow
qemu -drive if=virtio,file=test.add-cow -m 1024(test.img is a raw format file; test.add-cow stores bitmap)
Signed-off-by Dong Xu Wang <[email protected]>You should not make any changes to generic code, except maybe add something to
bdrv_get_info(). In particular you shouldn't need to touchbdrv_open()orbdrv_create()at all.The one required change in the approach for this to work is that you shouldn't view raw+add_cow as a unit, but
add_cowshould be treated as something separate that happens to be stacked on a raw file (which is created separately).Then you can do almost everything in
block/add-cow.c.Quoted 27 lines
--- Makefile.objs | 1 + block.c | 83 ++++++++++- block.h | 2 + block/add-cow.c | 456 +++++++++++++++++++++++++++++++++++++++++++++++++++++++ block_int.h | 6 + qemu-img.c | 10 ++ 6 files changed, 555 insertions(+), 3 deletions(-) create mode 100644 block/add-cow.cMakefile.objs +1
-0@@ -31,6 +31,7 @@ block-obj-$(CONFIG_LINUX_AIO) += linux-aio.o block-nested-y += raw.o cow.o qcow.o vdi.o vmdk.o cloop.o dmg.o bochs.o vpc.o vvfat.o block-nested-y += qcow2.o qcow2-refcount.o qcow2-cluster.o qcow2-snapshot.o qcow2-cache.o +block-nested-y += add-cow.o block-nested-y += qed.o qed-gencb.o qed-l2-cache.o qed-table.o qed-cluster.o block-nested-y += qed-check.o block-nested-y += parallels.o nbd.o blkdebug.o sheepdog.o blkverify.oblock.c +0
-0@@ -369,7 +369,7 @@ static int find_image_format(const char *filename, BlockDriver **pdrv)Quoted 9 lines
block.c static int find_image_format(const char *filename, BlockDriver **pdrv) · line 373
Quoted 6 lines
block.c +1
-1{int ret, score, score_max;BlockDriver *drv1, *drv; -uint8_t buf[2048 ]; +uint8_t buf[4096 ];BlockDriverState *bs;What's the reason for this change?
Quoted 1 line
The size of
add_cow_headerin my code is larger than 2048.Right, but the magic is in the first 8 bytes, so for probing 2048 bytes should be more than enough.
Quoted 26 lines
Quoted 18 lines
Quoted 18 lines
block/add-cow.c new file +12
-0@@ -0,0 +1,456 @@ +#include "qemu-common.h" +#include "block_int.h" +#include "module.h" + +#define ADD_COW_MAGIC (((uint64_t)'A' << 56) | ((uint64_t)'D' << 48) | \ + ((uint64_t)'D' << 40) | ((uint64_t)'_' << 32) | \ + ((uint64_t)'C' << 24) | ((uint64_t)'O' << 16) | \ + ((uint64_t)'W' << 8) | 0xFF) +#define ADD_COW_VERSION 1 + +struct add_cow_header { +uint64_t magic;Quoted 8 lines
block/add-cow.c line 18
Quoted 6 lines
block/add-cow.c new file +6
-0+uint32_t version; +char backing_file[1024 ]; +char image_file[1024 ]; +uint64_t size; +uint32_t sectorsize; +} add_cow_header;
QEMU_PACKEDQuoted 1 line
Sorry, what does
QEMU_PACKEDmean?This is an on-disk structure, so you need to pack the structure. Otherwise the compiler would be free to add padding between the fields in order to optimise alignment.
struct add_cow_header { ... } QEMU_PACKED add_cow_header;
Quoted 6 lines
Hm, actually, do you really want to declare a global variable here? Or is a typedef missing? Also, coding style requires the struct name to be spelled AddCowHeader.
Kevin
Thank you,Kevin. I will consider these advice in the second version.