qemu-img map: Allow driver to return file of the allocated block
v2 cover qemu-img map: Allow driver to return file of the allocated block
v2: Add Eric's rev-by in patches 2, 4, 5.
01: Refering -> referring in commit message. [Eric]
Recurse to "file" for sensible "zero" flag. [Paolo]
12: New. Make MapEntry a QAPI struct. [Paolo, Markus]
I stumbled upon this when looking at external bitmap formats.
Current "qemu-img map" command only displays filename if the data is allocated in bs (bs->file) itself, or in the backing chain. Otherwise, it displays an unfriendly error message:
$ qemu-img create -f vmdk -o subformat=monolithicFlat /tmp/test.vmdk 1G
$ qemu-img map /tmp/test.vmdk
Offset Length Mapped to File
qemu-img: File contains external, encrypted or compressed clusters.This can be improved. This series extends the .bdrv_co_get_block_status callback, to let block driver return the BDS of file; then updates all driver to implement it; and lastly, it changes qemu-img to use this information in "map" command:
$ qemu-img map /tmp/test.vmdk
Offset Length Mapped to File
0 0x40000000 0 /tmp/test-flat.vmdk $ qemu-img map --output json /tmp/test.vmdk
[{"length": 1073741824, "start": 0, "zero": false, "offset": 0, "depth": 0,
"file": "/tmp/test-flat.vmdk", "data": true}
]Fam Zheng (14):
block: Add "file" output parameter to block status query functions
qcow: Assign bs->file->bs to file in qcow_co_get_block_status
qcow2: Assign bs->file->bs to file in qcow2_co_get_block_status
raw: Assign bs to file in raw_co_get_block_status
iscsi: Assign bs to file in iscsi_co_get_block_status
parallels: Assign bs->file->bs to file in
parallels_co_get_block_status
qed: Assign bs->file->bs to file in bdrv_qed_co_get_block_status
sheepdog: Assign bs to file in sd_co_get_block_status
vdi: Assign bs->file->bs to file in vdi_co_get_block_status
vpc: Assign bs->file->bs to file in vpc_co_get_block_status
vmdk: Return extent's file in bdrv_get_block_status
qemu-img: Make MapEntry a QAPI struct
qemu-img: Use QAPI visitor to generate JSON
iotests: Add "qemu-img map" test for VMDK extentsblock/io.c | 42 +++++++++++++------- block/iscsi.c | 9 ++++- block/mirror.c | 3 +- block/parallels.c | 3 +- block/qcow.c | 3 +- block/qcow2.c | 3 +- block/qed.c | 6 ++- block/raw-posix.c | 4 +- block/raw_bsd.c | 4 +- block/sheepdog.c | 5 ++- block/vdi.c | 3 +- block/vmdk.c | 13 +++---- block/vpc.c | 4 +- block/vvfat.c | 2 +- include/block/block.h | 6 ++- include/block/block_int.h | 3 +- qapi/block-core.json | 28 ++++++++++++++ qemu-img.c | 80 +++++++++++++++++++++----------------- tests/qemu-iotests/059 | 10 +++++ tests/qemu-iotests/059.out | 38 ++++++++++++++++++ tests/qemu-iotests/122.out | 96 ++++++++++++++++++++++++++-------------------- 21 files changed, 251 insertions(+), 114 deletions(-)
Signature · 1 line
2.4.3
PATCH v2 1/14 block: Add "file" output parameter to block status query functions
The added parameter can be used to return the BDS pointer which the valid offset is referring to. It's value should be ignored unless BDRV_BLOCK_OFFSET_VALID in ret is set.
Until block drivers fill in the right value, let's clear it explicitly right before calling .bdrv_get_block_status.
--- block/io.c | 42 ++++++++++++++++++++++++++++-------------- block/iscsi.c | 6 ++++-- block/mirror.c | 3 ++- block/parallels.c | 2 +- block/qcow.c | 2 +- block/qcow2.c | 2 +- block/qed.c | 3 ++- block/raw-posix.c | 3 ++- block/raw_bsd.c | 3 ++- block/sheepdog.c | 2 +- block/vdi.c | 2 +- block/vmdk.c | 2 +- block/vpc.c | 2 +- block/vvfat.c | 2 +- include/block/block.h | 6 ++++-- include/block/block_int.h | 3 ++- qemu-img.c | 7 +++++-- 17 files changed, 59 insertions(+), 33 deletions(-)
block/io.c +28 -14
@@ -656,6 +656,7 @@ int bdrv_write_zeroes(BlockDriverState *bs, int64_t sector_num,int bdrv_make_zero (BlockDriverState *bs,BdrvRequestFlags flags) {int64_t target_sectors, ret, nb_sectors, sector_num =0 ; +BlockDriverState *file;int n; target_sectors =bdrv_nb_sectors (bs);
@@ -668,7 +669,7 @@ int bdrv_make_zero(BlockDriverState *bs, BdrvRequestFlags flags)if (nb_sectors <=0 ) {return 0 ; } - ret =bdrv_get_block_status (bs, sector_num, nb_sectors, &n); + ret =bdrv_get_block_status (bs, sector_num, nb_sectors, &n, &file);if (ret <0 ) {error_report ("error getting block status at sector %" PRId64": %s" , sector_num,strerror (-ret));
@@ -1455,6 +1456,7 @@ int bdrv_flush_all(void) typedef struct BdrvCoGetBlockStatusData { BlockDriverState *bs; BlockDriverState *base; + BlockDriverState **file; int64_t sector_num; int nb_sectors; int *pnum;
@@ -1479,7 +1481,8 @@ typedef struct BdrvCoGetBlockStatusData {*/ static int64_t coroutine_fn bdrv_co_get_block_status(BlockDriverState *bs,int64_t sector_num, -int nb_sectors,int *pnum) +int nb_sectors,int *pnum, +BlockDriverState **file) {int64_t total_sectors;int64_t n;
@@ -1509,16 +1512,19 @@ static int64_t coroutine_fn bdrv_co_get_block_status(BlockDriverState *bs,return ret; } - ret = bs->drv->bdrv_co_get_block_status (bs, sector_num, nb_sectors, pnum); + *file =NULL ; + ret = bs->drv->bdrv_co_get_block_status (bs, sector_num, nb_sectors, pnum, + file);if (ret <0 ) { *pnum =0 ; + *file =NULL ;return ret; }if (ret &BDRV_BLOCK_RAW ) {assert (ret &BDRV_BLOCK_OFFSET_VALID );return bdrv_get_block_status (bs->file->bs, ret >>BDRV_SECTOR_BITS , - *pnum, pnum); + *pnum, pnum, file); }if (ret & (BDRV_BLOCK_DATA |BDRV_BLOCK_ZERO )) {
@@ -1535,13 +1541,14 @@ static int64_t coroutine_fn bdrv_co_get_block_status(BlockDriverState *bs, } } -if (bs->file && +if (*file && *file != bs && (ret &BDRV_BLOCK_DATA ) && !(ret &BDRV_BLOCK_ZERO ) && (ret &BDRV_BLOCK_OFFSET_VALID )) { +BlockDriverState *file2;int file_pnum; - ret2 =bdrv_co_get_block_status (bs->file->bs, ret >>BDRV_SECTOR_BITS , - *pnum, &file_pnum); + ret2 =bdrv_co_get_block_status (*file, ret >>BDRV_SECTOR_BITS , + *pnum, &file_pnum, &file2);if (ret2 >=0 ) {/* Ignore errors. This is just providing extra information, it * is useful but not necessary.
@@ -1566,14 +1573,15 @@ static int64_t coroutine_fn bdrv_co_get_block_status_above(BlockDriverState *bs,BlockDriverState *base, int64_t sector_num, int nb_sectors, - int *pnum) + int *pnum, + BlockDriverState **file) { BlockDriverState *p;int64_t ret =0 ;assert (bs != base);for (p = bs; p != base; p =backing_bs (p)) { - ret =bdrv_co_get_block_status (p, sector_num, nb_sectors, pnum); + ret =bdrv_co_get_block_status (p, sector_num, nb_sectors, pnum, file);if (ret <0 || ret &BDRV_BLOCK_ALLOCATED ) {break ; }
@@ -1592,7 +1600,8 @@ static void coroutine_fn bdrv_get_block_status_above_co_entry(void *opaque) data->ret =bdrv_co_get_block_status_above (data->bs, data->base, data->sector_num, data->nb_sectors, - data->pnum); + data->pnum, + data->file); data->done = true; }
@@ -1604,12 +1613,14 @@ static void coroutine_fn bdrv_get_block_status_above_co_entry(void *opaque)int64_t bdrv_get_block_status_above (BlockDriverState *bs,BlockDriverState *base,int64_t sector_num, -int nb_sectors,int *pnum) +int nb_sectors,int *pnum, +BlockDriverState **file) {Coroutine *co;BdrvCoGetBlockStatusData data = { .bs = bs, .base = base, + .file = file, .sector_num = sector_num, .nb_sectors = nb_sectors, .pnum = pnum,
@@ -1633,16 +1644,19 @@ int64_t bdrv_get_block_status_above(BlockDriverState *bs,int64_t bdrv_get_block_status (BlockDriverState *bs,int64_t sector_num, -int nb_sectors,int *pnum) +int nb_sectors,int *pnum, +BlockDriverState **file) {return bdrv_get_block_status_above (bs,backing_bs (bs), - sector_num, nb_sectors, pnum); + sector_num, nb_sectors, pnum, file); } int coroutine_fn bdrv_is_allocated(BlockDriverState *bs, int64_t sector_num,int nb_sectors,int *pnum) { -int64_t ret =bdrv_get_block_status (bs, sector_num, nb_sectors, pnum); +BlockDriverState *file; +int64_t ret =bdrv_get_block_status (bs, sector_num, nb_sectors, pnum, + &file);if (ret <0 ) {return ret; }
block/iscsi.c +4 -2
@@ -532,7 +532,8 @@ static bool iscsi_allocationmap_is_allocated(IscsiLun *iscsilun, static int64_t coroutine_fn iscsi_co_get_block_status(BlockDriverState *bs,int64_t sector_num, -int nb_sectors,int *pnum) +int nb_sectors,int *pnum, +BlockDriverState **file) {IscsiLun *iscsilun = bs->opaque;struct scsi_get_lba_status *lbas =NULL ;
@@ -650,7 +651,8 @@ static int coroutine_fn iscsi_co_readv(BlockDriverState *bs, !iscsi_allocationmap_is_allocated(iscsilun, sector_num, nb_sectors)) {int64_t ret;int pnum; - ret =iscsi_co_get_block_status (bs, sector_num,INT_MAX , &pnum); +BlockDriverState *file; + ret =iscsi_co_get_block_status (bs, sector_num,INT_MAX , &pnum, &file);if (ret <0 ) {return ret; }
block/mirror.c +2 -1
@@ -166,6 +166,7 @@ static uint64_t coroutine_fn mirror_iteration(MirrorBlockJob *s)MirrorOp *op;int pnum;int64_t ret; +BlockDriverState *file; s->sector_num =hbitmap_iter_next (&s->hbi);if (s->sector_num <0 ) {
@@ -302,7 +303,7 @@ static uint64_t coroutine_fn mirror_iteration(MirrorBlockJob *s)trace_mirror_one_iteration (s, sector_num, nb_sectors); ret =bdrv_get_block_status_above (source,NULL , sector_num, - nb_sectors, &pnum); + nb_sectors, &pnum, &file);if (ret <0 || pnum < nb_sectors || (ret &BDRV_BLOCK_DATA && !(ret &BDRV_BLOCK_ZERO ))) { bdrv_aio_readv(source, sector_num, &op->qiov, nb_sectors,
block/parallels.c +1 -1
@@ -260,7 +260,7 @@ static coroutine_fn int parallels_co_flush_to_os(BlockDriverState *bs) static int64_t coroutine_fn parallels_co_get_block_status(BlockDriverState *bs, -int64_t sector_num,int nb_sectors,int *pnum) +int64_t sector_num,int nb_sectors,int *pnum,BlockDriverState **file) {BDRVParallelsState *s = bs->opaque;int64_t offset;
block/qcow.c +1 -1
@@ -488,7 +488,7 @@ static uint64_t get_cluster_offset(BlockDriverState *bs, } static int64_t coroutine_fn qcow_co_get_block_status(BlockDriverState *bs, -int64_t sector_num,int nb_sectors,int *pnum) +int64_t sector_num,int nb_sectors,int *pnum,BlockDriverState **file) {BDRVQcowState *s = bs->opaque;int index_in_cluster, n;
block/qcow2.c +1 -1
@@ -1283,7 +1283,7 @@ static void qcow2_reopen_abort(BDRVReopenState *state) } static int64_t coroutine_fn qcow2_co_get_block_status(BlockDriverState *bs, -int64_t sector_num,int nb_sectors,int *pnum) +int64_t sector_num,int nb_sectors,int *pnum,BlockDriverState **file) {BDRVQcow2State *s = bs->opaque;uint64_t cluster_offset;
block/qed.c +2 -1
@@ -724,7 +724,8 @@ static void qed_is_allocated_cb(void *opaque, int ret, uint64_t offset, size_t l static int64_t coroutine_fn bdrv_qed_co_get_block_status(BlockDriverState *bs,int64_t sector_num, -int nb_sectors,int *pnum) +int nb_sectors,int *pnum, +BlockDriverState **file) {BDRVQEDState *s = bs->opaque;size_t len = (size_t )nb_sectors *BDRV_SECTOR_SIZE ;
block/raw-posix.c +2 -1
@@ -1830,7 +1830,8 @@ static int find_allocation(BlockDriverState *bs, off_t start,*/ static int64_t coroutine_fn raw_co_get_block_status(BlockDriverState *bs,int64_t sector_num, -int nb_sectors,int *pnum) +int nb_sectors,int *pnum, +BlockDriverState **file) {off_t start, data =0 , hole =0 ;int64_t total_size;
block/raw_bsd.c +2 -1
@@ -114,7 +114,8 @@ fail: static int64_t coroutine_fn raw_co_get_block_status(BlockDriverState *bs,int64_t sector_num, -int nb_sectors,int *pnum) +int nb_sectors,int *pnum, +BlockDriverState **file) { *pnum = nb_sectors; return BDRV_BLOCK_RAW | BDRV_BLOCK_OFFSET_VALID | BDRV_BLOCK_DATA |
block/sheepdog.c +1 -1
@@ -2709,7 +2709,7 @@ retry: static coroutine_fn int64_tsd_co_get_block_status (BlockDriverState *bs,int64_t sector_num,int nb_sectors, -int *pnum) +int *pnum,BlockDriverState **file) {BDRVSheepdogState *s = bs->opaque;SheepdogInode *inode = &s->inode;
block/vdi.c +1 -1
@@ -526,7 +526,7 @@ static int vdi_reopen_prepare(BDRVReopenState *state, } static int64_t coroutine_fn vdi_co_get_block_status(BlockDriverState *bs, -int64_t sector_num,int nb_sectors,int *pnum) +int64_t sector_num,int nb_sectors,int *pnum,BlockDriverState **file) {/* TODO: Check for too large sector_num (in bdrv_is_allocated or here). */ BDRVVdiState *s = (BDRVVdiState *)bs->opaque;
block/vmdk.c +1 -1
@@ -1248,7 +1248,7 @@ static inline uint64_t vmdk_find_index_in_cluster(VmdkExtent *extent, } static int64_t coroutine_fn vmdk_co_get_block_status(BlockDriverState *bs, -int64_t sector_num,int nb_sectors,int *pnum) +int64_t sector_num,int nb_sectors,int *pnum,BlockDriverState **file) {BDRVVmdkState *s = bs->opaque;int64_t index_in_cluster, n, ret;
block/vpc.c +1 -1
@@ -578,7 +578,7 @@ static coroutine_fn int vpc_co_write(BlockDriverState *bs, int64_t sector_num, } static int64_t coroutine_fn vpc_co_get_block_status(BlockDriverState *bs, -int64_t sector_num,int nb_sectors,int *pnum) +int64_t sector_num,int nb_sectors,int *pnum,BlockDriverState **file) {BDRVVPCState *s = bs->opaque;VHDFooter *footer = (VHDFooter *) s->footer_buf;
block/vvfat.c +1 -1
@@ -2884,7 +2884,7 @@ static coroutine_fn int vvfat_co_write(BlockDriverState *bs, int64_t sector_num, } static int64_t coroutine_fn vvfat_co_get_block_status(BlockDriverState *bs, -int64_t sector_num,int nb_sectors,int * n) +int64_t sector_num,int nb_sectors,int *n,BlockDriverState **file) {BDRVVVFATState * s = bs->opaque; *n = s->sector_count - sector_num;
include/block/block.h +4 -2
@@ -383,11 +383,13 @@ int bdrv_has_zero_init(BlockDriverState *bs);bool bdrv_unallocated_blocks_are_zero (BlockDriverState *bs);bool bdrv_can_write_zeroes_with_unmap (BlockDriverState *bs);int64_t bdrv_get_block_status (BlockDriverState *bs,int64_t sector_num, -int nb_sectors,int *pnum); +int nb_sectors,int *pnum, +BlockDriverState **file);int64_t bdrv_get_block_status_above (BlockDriverState *bs,BlockDriverState *base,int64_t sector_num, -int nb_sectors,int *pnum); +int nb_sectors,int *pnum, +BlockDriverState **file);int bdrv_is_allocated (BlockDriverState *bs,int64_t sector_num,int nb_sectors,int *pnum); int bdrv_is_allocated_above(BlockDriverState *top, BlockDriverState *base,
include/block/block_int.h +2 -1
@@ -165,7 +165,8 @@ struct BlockDriver { int coroutine_fn (*bdrv_co_discard)(BlockDriverState *bs,int64_t sector_num,int nb_sectors); int64_t coroutine_fn (*bdrv_co_get_block_status)(BlockDriverState *bs, -int64_t sector_num,int nb_sectors,int *pnum); +int64_t sector_num,int nb_sectors,int *pnum, +BlockDriverState **file);/* * Invalidate any cached meta-data.
qemu-img.c +5 -2
@@ -1259,9 +1259,10 @@ static int convert_iteration_sectors(ImgConvertState *s, int64_t sector_num) n =MIN (s->total_sectors - sector_num,BDRV_REQUEST_MAX_SECTORS );if (s->sector_next_status <= sector_num) { +BlockDriverState *file; ret =bdrv_get_block_status (blk_bs (s->src[s->src_cur]), sector_num - s->src_cur_offset, - n, &n); + n, &n, &file);if (ret <0 ) {return ret; }
@@ -2189,6 +2190,7 @@ static int get_block_status(BlockDriverState *bs, int64_t sector_num, {int64_t ret;int depth; +BlockDriverState *file;/* As an optimization, we could cache the current range of unallocated * clusters in each file of the chain, and avoid querying the same
@@ -2197,7 +2199,8 @@ static int get_block_status(BlockDriverState *bs, int64_t sector_num, depth =0 ;for (;;) { - ret =bdrv_get_block_status (bs, sector_num, nb_sectors, &nb_sectors); + ret =bdrv_get_block_status (bs, sector_num, nb_sectors, &nb_sectors, + &file);if (ret <0 ) {return ret; }
Signature · 1 line
2.4.3
Re: [Qemu-devel] [PATCH v2 01/14] block: Add "file" output parameter to block status query functions
Quoted 2 lines · Fam Zheng
The added parameter can be used to return the BDS pointer which the valid offset is referring to. It's value should be ignored unless
s/It's/Its/ (remember, "It's" is valid only if "It is" also works in the same place)
Quoted 7 lines
BDRV_BLOCK_OFFSET_VALIDin ret is set.Until block drivers fill in the right value, let's clear it explicitly right before calling .bdrv_get_block_status.
Signed-off-by Fam Zheng <[email protected]>---
With that fix,
Signature · 2 lines
Eric Blake eblake redhat com +1-919-301-3266 Libvirt virtualization library http://libvirt.org
Re: [Qemu-devel] [PATCH v2 01/14] block: Add "file" output parameter to block status query functions
Quoted 6 lines · Eric Blake
Quoted 2 lines · Fam Zheng
The added parameter can be used to return the BDS pointer which the valid offset is referring to. It's value should be ignored unless
s/It's/Its/ (remember, "It's" is valid only if "It is" also works in the same place)
Right, it's just easy to typo. Thanks :)
Fam
Quoted 16 lines
Quoted 8 lines
BDRV_BLOCK_OFFSET_VALIDin ret is set.Until block drivers fill in the right value, let's clear it explicitly right before calling .bdrv_get_block_status.
Signed-off-by Fam Zheng <[email protected]>---
With that fix,
Reviewed-by Eric Blake <[email protected]>Signature · 2 lines
Eric Blake eblake redhat com +1-919-301-3266 Libvirt virtualization library http://libvirt.org
PATCH v2 2/14 qcow: Assign bs->file->bs to file in qcow_co_get_block_status
In reply to Fam Zheng--- block/qcow.c | 1 + 1 file changed, 1 insertion(+)
block/qcow.c +1 -0
@@ -509,6 +509,7 @@ static int64_t coroutine_fn qcow_co_get_block_status(BlockDriverState *bs,return BDRV_BLOCK_DATA ; } cluster_offset |= (index_in_cluster <<BDRV_SECTOR_BITS ); + *file = bs->file->bs;return BDRV_BLOCK_DATA |BDRV_BLOCK_OFFSET_VALID | cluster_offset; }
Signature · 1 line
2.4.3
PATCH v2 3/14 qcow2: Assign bs->file->bs to file in qcow2_co_get_block_status
In reply to Fam Zheng--- block/qcow2.c | 1 + 1 file changed, 1 insertion(+)
block/qcow2.c +1 -0
@@ -1302,6 +1302,7 @@ static int64_t coroutine_fn qcow2_co_get_block_status(BlockDriverState *bs, !s->cipher) { index_in_cluster = sector_num & (s->cluster_sectors -1 ); cluster_offset |= (index_in_cluster <<BDRV_SECTOR_BITS ); + *file = bs->file->bs; status |=BDRV_BLOCK_OFFSET_VALID | cluster_offset; }if (ret ==QCOW2_CLUSTER_ZERO ) {
Signature · 1 line
2.4.3
PATCH v2 4/14 raw: Assign bs to file in raw_co_get_block_status
In reply to Fam Zheng--- block/raw-posix.c | 1 + block/raw_bsd.c | 1 + 2 files changed, 2 insertions(+)
block/raw-posix.c +1 -0
@@ -1873,6 +1873,7 @@ static int64_t coroutine_fn raw_co_get_block_status(BlockDriverState *bs, *pnum =MIN (nb_sectors, (data - start) /BDRV_SECTOR_SIZE ); ret =BDRV_BLOCK_ZERO ; } + *file = bs;return ret |BDRV_BLOCK_OFFSET_VALID | start; }
block/raw_bsd.c +1 -0
@@ -118,6 +118,7 @@ static int64_t coroutine_fn raw_co_get_block_status(BlockDriverState *bs, BlockDriverState **file) { *pnum = nb_sectors; + *file = bs;return BDRV_BLOCK_RAW |BDRV_BLOCK_OFFSET_VALID |BDRV_BLOCK_DATA | (sector_num <<BDRV_SECTOR_BITS ); }
Signature · 1 line
2.4.3
PATCH v2 5/14 iscsi: Assign bs to file in iscsi_co_get_block_status
In reply to Fam Zheng--- block/iscsi.c | 3 +++ 1 file changed, 3 insertions(+)
block/iscsi.c +3 -0
@@ -625,6 +625,9 @@ out:if (iTask.task !=NULL ) {scsi_free_scsi_task (iTask.task); } +if (ret >0 && ret &BDRV_BLOCK_OFFSET_VALID ) { + *file = bs; + }return ret; }
Signature · 1 line
2.4.3
PATCH v2 6/14 parallels: Assign bs->file->bs to file in parallels_co_get_block_status
In reply to Fam Zheng--- block/parallels.c | 1 + 1 file changed, 1 insertion(+)
block/parallels.c +1 -0
@@ -273,6 +273,7 @@ static int64_t coroutine_fn parallels_co_get_block_status(BlockDriverState *bs,return 0 ; } + *file = bs->file->bs;return (offset <<BDRV_SECTOR_BITS ) |BDRV_BLOCK_DATA |BDRV_BLOCK_OFFSET_VALID ; }
Signature · 1 line
2.4.3
Re: [Qemu-devel] [PATCH v2 06/14] parallels: Assign bs->file->bs to file in parallels_co_get_block_status
Quoted 4 lines · Fam Zheng
Signed-off-by Fam Zheng <[email protected]>--- block/parallels.c | 1 + 1 file changed, 1 insertion(+)
Quoted 14 lines
block/parallels.c +1
-0@@ -273,6 +273,7 @@ static int64_t coroutine_fn parallels_co_get_block_status(BlockDriverState *bs,return 0 ; } + *file = bs->file->bs;return (offset <<BDRV_SECTOR_BITS ) |BDRV_BLOCK_DATA |BDRV_BLOCK_OFFSET_VALID ; }
Signature · 2 lines
Eric Blake eblake redhat com +1-919-301-3266 Libvirt virtualization library http://libvirt.org
PATCH v2 7/14 qed: Assign bs->file->bs to file in bdrv_qed_co_get_block_status
In reply to Fam Zheng--- block/qed.c | 3 +++ 1 file changed, 3 insertions(+)
block/qed.c +3 -0
@@ -692,6 +692,7 @@ typedef struct {uint64_t pos;int64_t status;int *pnum; +BlockDriverState **file; } QEDIsAllocatedCB;static void qed_is_allocated_cb (void *opaque,int ret,uint64_t offset,size_t len)
@@ -703,6 +704,7 @@ static void qed_is_allocated_cb(void *opaque, int ret, uint64_t offset, size_t lcase QED_CLUSTER_FOUND : offset |=qed_offset_into_cluster (s, cb->pos); cb->status =BDRV_BLOCK_DATA |BDRV_BLOCK_OFFSET_VALID | offset; + *cb->file = cb->bs->file->bs;break ;case QED_CLUSTER_ZERO : cb->status =BDRV_BLOCK_ZERO ;
@@ -734,6 +736,7 @@ static int64_t coroutine_fn bdrv_qed_co_get_block_status(BlockDriverState *bs, .pos = (uint64_t)sector_num * BDRV_SECTOR_SIZE, .status = BDRV_BLOCK_OFFSET_MASK, .pnum = pnum, + .file = file, };QEDRequest request = { .l2_table =NULL };
Signature · 1 line
2.4.3
Re: [Qemu-devel] [PATCH v2 07/14] qed: Assign bs->file->bs to file in bdrv_qed_co_get_block_status
Quoted 5 lines · Fam Zheng
Signed-off-by Fam Zheng <[email protected]>--- block/qed.c | 3 +++ 1 file changed, 3 insertions(+)
Signature · 2 lines
Eric Blake eblake redhat com +1-919-301-3266 Libvirt virtualization library http://libvirt.org
PATCH v2 8/14 sheepdog: Assign bs to file in sd_co_get_block_status
In reply to Fam Zheng--- block/sheepdog.c | 3 +++ 1 file changed, 3 insertions(+)
block/sheepdog.c +3 -0
@@ -2740,6 +2740,9 @@ sd_co_get_block_status(BlockDriverState *bs, int64_t sector_num, int nb_sectors,if (*pnum > nb_sectors) { *pnum = nb_sectors; } +if (ret >0 && ret &BDRV_BLOCK_OFFSET_VALID ) { + *file = bs; + }return ret; }
Signature · 1 line
2.4.3
Re: [Qemu-devel] [PATCH v2 08/14] sheepdog: Assign bs to file in sd_co_get_block_status
Quoted 4 lines · Fam Zheng
Signed-off-by Fam Zheng <[email protected]>--- block/sheepdog.c | 3 +++ 1 file changed, 3 insertions(+)
Quoted 16 lines
block/sheepdog.c +3
-0@@ -2740,6 +2740,9 @@ sd_co_get_block_status(BlockDriverState *bs, int64_t sector_num, int nb_sectors,if (*pnum > nb_sectors) { *pnum = nb_sectors; } +if (ret >0 && ret &BDRV_BLOCK_OFFSET_VALID ) { + *file = bs; + }return ret; }
Signature · 2 lines
Eric Blake eblake redhat com +1-919-301-3266 Libvirt virtualization library http://libvirt.org
PATCH v2 9/14 vdi: Assign bs->file->bs to file in vdi_co_get_block_status
In reply to Fam Zheng--- block/vdi.c | 1 + 1 file changed, 1 insertion(+)
block/vdi.c +1 -0
@@ -550,6 +550,7 @@ static int64_t coroutine_fn vdi_co_get_block_status(BlockDriverState *bs, offset = s->header.offset_data + (uint64_t )bmap_entry * s->block_size + sector_in_block *SECTOR_SIZE ; + *file = bs->file->bs;return BDRV_BLOCK_DATA |BDRV_BLOCK_OFFSET_VALID | offset; }
Signature · 1 line
2.4.3
Re: [Qemu-devel] [PATCH v2 09/14] vdi: Assign bs->file->bs to file in vdi_co_get_block_status
Quoted 4 lines · Fam Zheng
Signed-off-by Fam Zheng <[email protected]>--- block/vdi.c | 1 + 1 file changed, 1 insertion(+)
Quoted 14 lines
block/vdi.c +1
-0@@ -550,6 +550,7 @@ static int64_t coroutine_fn vdi_co_get_block_status(BlockDriverState *bs, offset = s->header.offset_data + (uint64_t )bmap_entry * s->block_size + sector_in_block *SECTOR_SIZE ; + *file = bs->file->bs;return BDRV_BLOCK_DATA |BDRV_BLOCK_OFFSET_VALID | offset; }
Signature · 2 lines
Eric Blake eblake redhat com +1-919-301-3266 Libvirt virtualization library http://libvirt.org
PATCH v2 10/14 vpc: Assign bs->file->bs to file in vpc_co_get_block_status
In reply to Fam Zheng--- block/vpc.c | 2 ++ 1 file changed, 2 insertions(+)
block/vpc.c +2 -0
@@ -588,6 +588,7 @@ static int64_t coroutine_fn vpc_co_get_block_status(BlockDriverState *bs,if (be32_to_cpu (footer->type) ==VHD_FIXED ) { *pnum = nb_sectors; + *file = bs->file->bs;return BDRV_BLOCK_RAW |BDRV_BLOCK_OFFSET_VALID |BDRV_BLOCK_DATA | (sector_num <<BDRV_SECTOR_BITS ); }
@@ -609,6 +610,7 @@ static int64_t coroutine_fn vpc_co_get_block_status(BlockDriverState *bs,/* *pnum can't be greater than one block for allocated * sectors since there is always a bitmap in between. */ if (allocated) { + *file = bs->file->bs;return BDRV_BLOCK_DATA |BDRV_BLOCK_OFFSET_VALID | start; }if (nb_sectors ==0 ) {
Signature · 1 line
2.4.3
Re: [Qemu-devel] [PATCH v2 10/14] vpc: Assign bs->file->bs to file in vpc_co_get_block_status
Quoted 4 lines · Fam Zheng
Signed-off-by Fam Zheng <[email protected]>--- block/vpc.c | 2 ++ 1 file changed, 2 insertions(+)
Quoted 22 lines
block/vpc.c +2
-0@@ -588,6 +588,7 @@ static int64_t coroutine_fn vpc_co_get_block_status(BlockDriverState *bs,if (be32_to_cpu (footer->type) ==VHD_FIXED ) { *pnum = nb_sectors; + *file = bs->file->bs;return BDRV_BLOCK_RAW |BDRV_BLOCK_OFFSET_VALID |BDRV_BLOCK_DATA | (sector_num <<BDRV_SECTOR_BITS ); }@@ -609,6 +610,7 @@ static int64_t coroutine_fn vpc_co_get_block_status(BlockDriverState *bs,/* *pnum can't be greater than one block for allocated * sectors since there is always a bitmap in between. */ if (allocated) { + *file = bs->file->bs;return BDRV_BLOCK_DATA |BDRV_BLOCK_OFFSET_VALID | start; }if (nb_sectors ==0 ) {
Signature · 2 lines
Eric Blake eblake redhat com +1-919-301-3266 Libvirt virtualization library http://libvirt.org
PATCH v2 11/14 vmdk: Return extent's file in bdrv_get_block_status
In reply to Fam Zheng--- block/vmdk.c | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-)
block/vmdk.c +5 -6
@@ -1265,6 +1265,7 @@ static int64_t coroutine_fn vmdk_co_get_block_status(BlockDriverState *bs, 0, 0);qemu_co_mutex_unlock (&s->lock); + index_in_cluster =vmdk_find_index_in_cluster (extent, sector_num);switch (ret) {case VMDK_ERROR : ret = -EIO ;
@@ -1276,15 +1277,13 @@ static int64_t coroutine_fn vmdk_co_get_block_status(BlockDriverState *bs, ret =BDRV_BLOCK_ZERO ;break ;case VMDK_OK : - ret =BDRV_BLOCK_DATA ; -if (extent->file == bs->file && !extent->compressed) { - ret |=BDRV_BLOCK_OFFSET_VALID | offset; - } - + ret =BDRV_BLOCK_DATA |BDRV_BLOCK_OFFSET_VALID ; + ret |= (offset + (index_in_cluster <<BDRV_SECTOR_BITS )) + &BDRV_BLOCK_OFFSET_MASK ; + *file = extent->file->bs;break ; } - index_in_cluster =vmdk_find_index_in_cluster (extent, sector_num); n = extent->cluster_sectors - index_in_cluster;if (n > nb_sectors) { n = nb_sectors;
Signature · 1 line
2.4.3
PATCH v2 12/14 qemu-img: Make MapEntry a QAPI struct
In reply to Fam ZhengThe "flags" bit mask is expanded to two booleans, "data" and "zero"; "bs" is replaced with "filename" string.
--- qapi/block-core.json | 28 ++++++++++++++++++++++++++++ qemu-img.c | 48 ++++++++++++++++++++++-------------------------- 2 files changed, 50 insertions(+), 26 deletions(-)
qapi/block-core.json +28 -0
@@ -186,6 +186,34 @@ '*fragmented-clusters': 'int', '*compressed-clusters': 'int' } } ## +# @MapEntry: +# +# Mapping information from a virtual block range to a host file range +# +# @start: the start byte of the mapped virtual range +# +# @length: the number of bytes of the mapped virtual range +# +# @data: whether the mapped range has data +# +# @zero: whether the virtual blocks are zeroed +# +# @depth: the depth of the mapping +# +# @offset: #optional the offset in file that the virtual sectors are mapped to +# +# @filename: #optional filename that is referred to by @offset +# +# Since: 2.6 +# +## + +{ 'struct': 'MapEntry', + 'data': {'start': 'int', 'length': 'int', 'data': 'bool', + 'zero': 'bool', 'depth': 'int', '*offset': 'int', + '*filename': 'str' } } + +## # @BlockdevCacheInfo # # Cache mode information for a block device
qemu-img.c +22 -26
88 lines not on this page · raw message
Signature · 1 line
2.4.3
Re: [Qemu-devel] [PATCH v2 12/14] qemu-img: Make MapEntry a QAPI struct
qemu-img.c static int img_info(int argc, char **argv) · line 2154
Quoted 7 lines · Fam Zheng
*/qemu-img.c +2
-4-if (next && - (next->flags & (BDRV_BLOCK_DATA |BDRV_BLOCK_ZERO )) !=BDRV_BLOCK_DATA ) { - next->flags &= ~BDRV_BLOCK_DATA ; - next->flags |=BDRV_BLOCK_ZERO ; +if (next && !next->data) { + next->zero = true;
before after
0 ZERO ZERO
DATA DATA DATA
DATA|ZERO ZERO DATA|ZERO
ZERO ZERO ZERO
This would not coalesce 0 with DATA|ZERO.
I think you need to do exactly as in the older code: test (!next->data || next->zero), and clear next->data.
Paolo
Re: [Qemu-devel] [PATCH v2 12/14] qemu-img: Make MapEntry a QAPI struct
In reply to Fam Zhengqapi/block-core.json line 211
Quoted 13 lines · Fam Zheng
The "flags" bit mask is expanded to two booleans, "data" and "zero"; "bs" is replaced with "filename" string.
Signed-off-by Fam Zheng <[email protected]>--- qapi/block-core.json | 28 ++++++++++++++++++++++++++++ qemu-img.c | 48 ++++++++++++++++++++++-------------------------- 2 files changed, 50 insertions(+), 26 deletions(-)qapi/block-core.json +3
-0+## + +{ 'struct': 'MapEntry',
Blank line is not typical here.
qapi/block-core.json line 214
Quoted 3 lines
qapi/block-core.json +3
-0+ 'data': {'start': 'int', 'length': 'int', 'data': 'bool', + 'zero': 'bool', 'depth': 'int', '*offset': 'int', + '*filename': 'str' } }
Struct looks fine.
qemu-img.c static int img_info(int argc, char **argv) · line 2149
Quoted 8 lines
qemu-img.c +3
-2-if ((e->flags & (BDRV_BLOCK_DATA |BDRV_BLOCK_ZERO )) ==BDRV_BLOCK_DATA ) { +if (e->data && !e->zero) {printf ("%#-16" PRIx64"%#-16" PRIx64"%#-16" PRIx64"%s\n" , - e->start, e->length, e->offset, e->bs->filename); + e->start, e->length, e->offset, + e->has_filename ? e->filename :"" ); }
This blindly prints e->offset, even though...[1]
qemu-img.c static int img_info(int argc, char **argv) · line 2159
Quoted 4 lines
case
OFORMAT_JSON:qemu-img.c +2
-1- printf("%s{ \"start\": %"PRId64", \"length\": %"PRId64", \"depth\": %d," +printf ("%s{ \"start\": %" PRId64", \"length\": %" PRId64"," + " \"depth\": %ld,"
%ld is wrong; it needs to be PRId64.
Quoted 1 line
" \"zero\": %s, \"data\": %s",
Worth joining the two short lines into one?
qemu-img.c static int get_block_status(BlockDriverState *bs, int64_t sector_num, · line 2214
Quoted 9 lines
qemu-img.c +3
-1@@ -2219,10 +2208,15 @@ static int get_block_status(BlockDriverState *bs, int64_t sector_num, e->start = sector_num *BDRV_SECTOR_SIZE ; e->length = nb_sectors *BDRV_SECTOR_SIZE ; - e->flags = ret & ~BDRV_BLOCK_OFFSET_MASK ; + e->data = !!(ret &BDRV_BLOCK_DATA ); + e->zero = !!(ret &BDRV_BLOCK_ZERO ); e->offset = ret &BDRV_BLOCK_OFFSET_MASK ; + e->has_offset = !!(ret &BDRV_BLOCK_OFFSET_VALID );
[1]... offset might be garbage if has_offset is false.
qemu-img.c static int get_block_status(BlockDriverState *bs, int64_t sector_num, · line 2221
Quoted 8 lines
qemu-img.c +4
-1e->depth = depth; - e->bs = bs; +if (e->has_offset) { + e->has_filename = true; + e->filename = bs->filename; + }return 0 ; }
Are we guaranteed that bs->filename is non-NULL when offset is set? Or does this need to be if (e->has_offset && bs->filename)?
qemu-img.c static int img_map(int argc, char **argv) · line 2307
Quoted 11 lines
qemu-img.c +3
-2@@ -2307,9 +2301,11 @@ static int img_map(int argc, char **argv) goto out; } - if (curr.length != 0 && curr.flags == next.flags && + if (curr.length != 0 && curr.zero == next.zero && + curr.data == next.data && curr.depth == next.depth && - ((curr.flags & BDRV_BLOCK_OFFSET_VALID) == 0 || + !strcmp(curr.filename, next.filename) &&
Is this strcmp valid even when !has_filename?
Quoted 5 lines
qemu-img.c +1
-0+ (!curr.has_offset || curr.offset + curr.length == next.offset)) { curr.length += next.length;continue ;
Signature · 2 lines
Eric Blake eblake redhat com +1-919-301-3266 Libvirt virtualization library http://libvirt.org
Re: [Qemu-devel] [PATCH v2 12/14] qemu-img: Make MapEntry a QAPI struct
Quoted 11 lines · Eric Blake
Quoted 9 lines · Fam Zheng
The "flags" bit mask is expanded to two booleans, "data" and "zero"; "bs" is replaced with "filename" string.
Signed-off-by Fam Zheng <[email protected]>--- qapi/block-core.json | 28 ++++++++++++++++++++++++++++ qemu-img.c | 48 ++++++++++++++++++++++-------------------------- 2 files changed, 50 insertions(+), 26 deletions(-)
Quoted 5 lines
qapi/block-core.json line 211
Quoted 3 lines
qapi/block-core.json +3
-0+## + +{ 'struct': 'MapEntry',Blank line is not typical here.
This is copied from ImageInfo above. Removing.
Quoted 16 lines
qapi/block-core.json line 214
Quoted 4 lines
qapi/block-core.json +3
-0+ 'data': {'start': 'int', 'length': 'int', 'data': 'bool', + 'zero': 'bool', 'depth': 'int', '*offset': 'int', + '*filename': 'str' } }Struct looks fine.
qemu-img.c static int img_info(int argc, char **argv) · line 2149
Quoted 8 lines
qemu-img.c +3
-2-if ((e->flags & (BDRV_BLOCK_DATA |BDRV_BLOCK_ZERO )) ==BDRV_BLOCK_DATA ) { +if (e->data && !e->zero) {printf ("%#-16" PRIx64"%#-16" PRIx64"%#-16" PRIx64"%s\n" , - e->start, e->length, e->offset, e->bs->filename); + e->start, e->length, e->offset, + e->has_filename ? e->filename :"" ); }
Quoted 1 line
This blindly prints
e->offset, even though...[1]
Will add check.
Quoted 7 lines
qemu-img.c static int img_info(int argc, char **argv) · line 2159
Quoted 5 lines
case
OFORMAT_JSON:qemu-img.c +2
-1- printf("%s{ \"start\": %"PRId64", \"length\": %"PRId64", \"depth\": %d," +printf ("%s{ \"start\": %" PRId64", \"length\": %" PRId64"," + " \"depth\": %ld,"%ld is wrong; it needs to be PRId64.
Yes.
Quoted 4 lines
Quoted 2 lines
" \"zero\": %s, \"data\": %s",Worth joining the two short lines into one?
OK.
Quoted 22 lines
qemu-img.c static int get_block_status(BlockDriverState *bs, int64_t sector_num, · line 2214
Quoted 10 lines
qemu-img.c +3
-1@@ -2219,10 +2208,15 @@ static int get_block_status(BlockDriverState *bs, int64_t sector_num, e->start = sector_num *BDRV_SECTOR_SIZE ; e->length = nb_sectors *BDRV_SECTOR_SIZE ; - e->flags = ret & ~BDRV_BLOCK_OFFSET_MASK ; + e->data = !!(ret &BDRV_BLOCK_DATA ); + e->zero = !!(ret &BDRV_BLOCK_ZERO ); e->offset = ret &BDRV_BLOCK_OFFSET_MASK ; + e->has_offset = !!(ret &BDRV_BLOCK_OFFSET_VALID );[1]... offset might be garbage if
has_offsetis false.qemu-img.c static int get_block_status(BlockDriverState *bs, int64_t sector_num, · line 2221
Quoted 8 lines
qemu-img.c +4
-1e->depth = depth; - e->bs = bs; +if (e->has_offset) { + e->has_filename = true; + e->filename = bs->filename; + }return 0 ; }
Quoted 2 lines
Are we guaranteed that
bs->filenameis non-NULL when offset is set? Or does this need to be if (e->has_offset&&bs->filename)?
It's an array field:
struct BlockDriverState {
...
char filename[PATH_MAX];So I think this is OK.
Quoted 6 lines
Quoted 6 lines
qemu-img.c +0
-0@@ -2307,9 +2301,11 @@ static int img_map(int argc, char **argv) goto out; }
Quoted 8 lines
qemu-img.c static int img_map(int argc, char **argv) · line 2307
Quoted 6 lines
qemu-img.c +3
-2- if (curr.length != 0 && curr.flags == next.flags && + if (curr.length != 0 && curr.zero == next.zero && + curr.data == next.data && curr.depth == next.depth && - ((curr.flags & BDRV_BLOCK_OFFSET_VALID) == 0 || + !strcmp(curr.filename, next.filename) &&Is this strcmp valid even when !has_filename?
No, will check it.
Thanks for reviewing!
Fam
Quoted 11 lines
Quoted 6 lines
qemu-img.c +1
-0+ (!curr.has_offset || curr.offset + curr.length == next.offset)) { curr.length += next.length;continue ;Signature · 2 lines
Eric Blake eblake redhat com +1-919-301-3266 Libvirt virtualization library http://libvirt.org
PATCH v2 13/14 qemu-img: Use QAPI visitor to generate JSON
In reply to Fam ZhengA visible improvement is that "filename" is now included in the output if it's valid.
--- qemu-img.c | 39 ++++++++++++------- tests/qemu-iotests/122.out | 96 ++++++++++++++++++++++++++-------------------- 2 files changed, 79 insertions(+), 56 deletions(-)
qemu-img.c +25 -14
@@ -25,6 +25,8 @@#include "qapi/qmp-output-visitor.h" #include "qapi/qmp/qerror.h" #include "qapi/qmp/qjson.h" +#include "qapi/qmp/qint.h" +#include "qapi/qmp/qbool.h" #include "qemu-common.h" #include "qemu/option.h" #include "qemu/error-report.h"
@@ -2136,10 +2138,14 @@ static int img_info(int argc, char **argv)static void dump_map_entry (OutputFormat output_format,MapEntry *e,MapEntry *next) { +QString *str; +QObject *obj; +QmpOutputVisitor *ov; +switch (output_format) {case OFORMAT_HUMAN :if (e->data && !e->has_offset) { -error_report ("File contains external, encrypted or compressed clusters." ); +error_report ("File contains encrypted or compressed clusters." );exit (1 ); }if (e->data && !e->zero) {
@@ -2155,21 +2161,26 @@ static void dump_map_entry(OutputFormat output_format, MapEntry *e, }break ;case OFORMAT_JSON : -printf ("%s{ \"start\": %" PRId64", \"length\": %" PRId64"," -" \"depth\": %ld," -" \"zero\": %s, \"data\": %s" , - (e->start ==0 ?"[" :",\n" ), - e->start, e->length, e->depth, - e->zero ?"true" :"false" , - e->data ?"true" :"false" ); -if (e->has_offset) { -printf (", \"offset\": %" PRId64"" , e->offset); - } -putchar ('}' ); + ov =qmp_output_visitor_new (); +visit_type_MapEntry (qmp_output_get_visitor (ov), + &e,NULL , &error_abort); + obj =qmp_output_get_qobject (ov); + str =qobject_to_json (obj); +assert (str !=NULL ); +if (e->start ==0 ) { +printf ("[" ); + }else { +printf ("," ); + } +printf ("%s\n" ,qstring_get_str (str));if (!next) {printf ("]\n" ); } + +qobject_decref (obj); +qmp_output_visitor_cleanup (ov); +QDECREF (str);break ; } }
@@ -2213,9 +2224,9 @@ static int get_block_status(BlockDriverState *bs, int64_t sector_num, e->offset = ret &BDRV_BLOCK_OFFSET_MASK ; e->has_offset = !!(ret &BDRV_BLOCK_OFFSET_VALID ); e->depth = depth; -if (e->has_offset) { +if (file && e->has_offset) { e->has_filename = true; - e->filename = bs->filename; + e->filename = file->filename; }return 0 ; }
tests/qemu-iotests/122.out +54 -42
154 lines not on this page · raw message
Signature · 1 line
2.4.3
Re: [Qemu-devel] [PATCH v2 13/14] qemu-img: Use QAPI visitor to generate JSON
Quoted 20 lines · Fam Zheng
A visible improvement is that "filename" is now included in the output if it's valid.
Signed-off-by Fam Zheng <[email protected]>--- qemu-img.c | 39 ++++++++++++------- tests/qemu-iotests/122.out | 96 ++++++++++++++++++++++++++-------------------- 2 files changed, 79 insertions(+), 56 deletions(-)qemu-img.c +0
-6@@ -2155,21 +2161,26 @@ static void dump_map_entry(OutputFormat output_format, MapEntry *e, }break ;case OFORMAT_JSON : - printf("%s{ \"start\": %"PRId64", \"length\": %"PRId64"," - " \"depth\": %ld," - " \"zero\": %s, \"data\": %s", - (e->start == 0 ? "[" : ",\n"), - e->start, e->length, e->depth, - e->zero ? "true" : "false",
qemu-img.c static void dump_map_entry(OutputFormat output_format, MapEntry *e, · line 2168
Quoted 10 lines
qemu-img.c +5
-5- e->data ? "true" : "false"); -if (e->has_offset) { -printf (", \"offset\": %" PRId64"" , e->offset); - } -putchar ('}' ); + ov =qmp_output_visitor_new (); +visit_type_MapEntry (qmp_output_get_visitor (ov), + &e,NULL , &error_abort); + obj =qmp_output_get_qobject (ov); + str =qobject_to_json (obj);
It would be nice to someday add a visitor that goes directly to json, instead of through an intermediate QObject. But that's not for this series; your conversion here is sane.
qemu-img.c static int get_block_status(BlockDriverState *bs, int64_t sector_num, · line 2229
Quoted 9 lines
qemu-img.c +2
-2@@ -2213,9 +2224,9 @@ static int get_block_status(BlockDriverState *bs, int64_t sector_num, e->offset = ret &BDRV_BLOCK_OFFSET_MASK ; e->has_offset = !!(ret &BDRV_BLOCK_OFFSET_VALID ); e->depth = depth; -if (e->has_offset) { +if (file && e->has_offset) { e->has_filename = true; - e->filename = bs->filename; + e->filename = file->filename;
Does this hunk belong in a different patch?
Signature · 2 lines
Eric Blake eblake redhat com +1-919-301-3266 Libvirt virtualization library http://libvirt.org
Re: [Qemu-devel] [PATCH v2 13/14] qemu-img: Use QAPI visitor to generate JSON
Quoted 48 lines · Eric Blake
Quoted 20 lines · Fam Zheng
A visible improvement is that "filename" is now included in the output if it's valid.
Signed-off-by Fam Zheng <[email protected]>--- qemu-img.c | 39 ++++++++++++------- tests/qemu-iotests/122.out | 96 ++++++++++++++++++++++++++-------------------- 2 files changed, 79 insertions(+), 56 deletions(-)qemu-img.c +0
-6@@ -2155,21 +2161,26 @@ static void dump_map_entry(OutputFormat output_format, MapEntry *e, }break ;case OFORMAT_JSON : - printf("%s{ \"start\": %"PRId64", \"length\": %"PRId64"," - " \"depth\": %ld," - " \"zero\": %s, \"data\": %s", - (e->start == 0 ? "[" : ",\n"), - e->start, e->length, e->depth, - e->zero ? "true" : "false",qemu-img.c static void dump_map_entry(OutputFormat output_format, MapEntry *e, · line 2168
Quoted 10 lines
qemu-img.c +5
-5- e->data ? "true" : "false"); -if (e->has_offset) { -printf (", \"offset\": %" PRId64"" , e->offset); - } -putchar ('}' ); + ov =qmp_output_visitor_new (); +visit_type_MapEntry (qmp_output_get_visitor (ov), + &e,NULL , &error_abort); + obj =qmp_output_get_qobject (ov); + str =qobject_to_json (obj);It would be nice to someday add a visitor that goes directly to json, instead of through an intermediate QObject. But that's not for this series; your conversion here is sane.
qemu-img.c static int get_block_status(BlockDriverState *bs, int64_t sector_num, · line 2229
Quoted 9 lines
qemu-img.c +2
-2@@ -2213,9 +2224,9 @@ static int get_block_status(BlockDriverState *bs, int64_t sector_num, e->offset = ret &BDRV_BLOCK_OFFSET_MASK ; e->has_offset = !!(ret &BDRV_BLOCK_OFFSET_VALID ); e->depth = depth; -if (e->has_offset) { +if (file && e->has_offset) { e->has_filename = true; - e->filename = bs->filename; + e->filename = file->filename;Does this hunk belong in a different patch?
Quoted 2 lines
Reviewed-by Eric Blake <[email protected]>
Yes, I can split this into a separate patch.
Fam
PATCH v2 14/14 iotests: Add "qemu-img map" test for VMDK extents
In reply to Fam Zheng--- tests/qemu-iotests/059 | 10 ++++++++++ tests/qemu-iotests/059.out | 38 ++++++++++++++++++++++++++++++++++++++ 2 files changed, 48 insertions(+)
tests/qemu-iotests/059 +10 -0
@@ -133,6 +133,16 @@ $QEMU_IO -c "write -P 0xa 900G 512" "$TEST_IMG" | _filter_qemu_io $QEMU_IO -c "read -v 900G 1024" "$TEST_IMG" | _filter_qemu_io echo +echo "=== Testing qemu-img map on extents ===" +for fmt in twoGbMaxExtentSparse twoGbMaxExtentFlat; do + IMGOPTS="subformat=$fmt" _make_test_img 31G + $QEMU_IO -c "write 65024 1k" "$TEST_IMG" | _filter_qemu_io + $QEMU_IO -c "write 2147483136 1k" "$TEST_IMG" | _filter_qemu_io + $QEMU_IO -c "write 5G 1k" "$TEST_IMG" | _filter_qemu_io + $QEMU_IMG map "$TEST_IMG" | _filter_testdir +done + +echo echo "=== Testing afl image with a very large capacity ===" _use_sample_img afl9.vmdk.bz2 _img_info
tests/qemu-iotests/059.out +38 -0
@@ -2337,6 +2337,44 @@ e1000003f0: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ................ read 1024/1024 bytes at offset 966367641600 1 KiB, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec) +=== Testing qemu-img map on extents === +Formatting 'TEST_DIR/iotest-version3.IMGFMT', fmt=IMGFMT size=33285996544 subformat=twoGbMaxExtentSparse +wrote 1024/1024 bytes at offset 65024 +1 KiB, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec) +wrote 1024/1024 bytes at offset 2147483136 +1 KiB, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec) +wrote 1024/1024 bytes at offset 5368709120 +1 KiB, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec) +Offset Length Mapped to File +0 0x20000 0x50000 TEST_DIR/iotest-version3-s001.vmdk +0x7fff0000 0x10000 0x70000 TEST_DIR/iotest-version3-s001.vmdk +0x80000000 0x10000 0x50000 TEST_DIR/iotest-version3-s002.vmdk +0x140000000 0x10000 0x50000 TEST_DIR/iotest-version3-s003.vmdk +Formatting 'TEST_DIR/iotest-version3.IMGFMT', fmt=IMGFMT size=33285996544 subformat=twoGbMaxExtentFlat +wrote 1024/1024 bytes at offset 65024 +1 KiB, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec) +wrote 1024/1024 bytes at offset 2147483136 +1 KiB, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec) +wrote 1024/1024 bytes at offset 5368709120 +1 KiB, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec) +Offset Length Mapped to File +0 0x80000000 0 TEST_DIR/iotest-version3-f001.vmdk +0x80000000 0x80000000 0 TEST_DIR/iotest-version3-f002.vmdk +0x100000000 0x80000000 0 TEST_DIR/iotest-version3-f003.vmdk +0x180000000 0x80000000 0 TEST_DIR/iotest-version3-f004.vmdk +0x200000000 0x80000000 0 TEST_DIR/iotest-version3-f005.vmdk +0x280000000 0x80000000 0 TEST_DIR/iotest-version3-f006.vmdk +0x300000000 0x80000000 0 TEST_DIR/iotest-version3-f007.vmdk +0x380000000 0x80000000 0 TEST_DIR/iotest-version3-f008.vmdk +0x400000000 0x80000000 0 TEST_DIR/iotest-version3-f009.vmdk +0x480000000 0x80000000 0 TEST_DIR/iotest-version3-f010.vmdk +0x500000000 0x80000000 0 TEST_DIR/iotest-version3-f011.vmdk +0x580000000 0x80000000 0 TEST_DIR/iotest-version3-f012.vmdk +0x600000000 0x80000000 0 TEST_DIR/iotest-version3-f013.vmdk +0x680000000 0x80000000 0 TEST_DIR/iotest-version3-f014.vmdk +0x700000000 0x80000000 0 TEST_DIR/iotest-version3-f015.vmdk +0x780000000 0x40000000 0 TEST_DIR/iotest-version3-f016.vmdk + === Testing afl image with a very large capacity === qemu-img: Can't get size of device 'image': File too large *** done
Signature · 1 line
2.4.3
Re: [Qemu-devel] [PATCH v2 14/14] iotests: Add "qemu-img map" test for VMDK extents
Quoted 5 lines · Fam Zheng
Signed-off-by Fam Zheng <[email protected]>--- tests/qemu-iotests/059 | 10 ++++++++++ tests/qemu-iotests/059.out | 38 ++++++++++++++++++++++++++++++++++++++ 2 files changed, 48 insertions(+)
Signature · 2 lines
Eric Blake eblake redhat com +1-919-301-3266 Libvirt virtualization library http://libvirt.org