block: Block driver callbacks fixes
v4 cover block: Block driver callbacks fixes
This series makes implementing some of the bdrv_* callbacks easier for block filters by passing requests to bs->file if bs->drv doesn't implement it instead of failing, and adding default bdrv_co_get_block_status() implementations.
This is based against Kevin Wolf's block branch, commit da4bd74d2450ab72a7c26bbabb10c6a287dd043e
v4:
forward only for block filters
new patch: remove bdrv_media_changed
dropped commit block: Use defaults of bdrv_* callbacks in raw, since raw is not a filter driver and is incompatible with the changes.
v3:
minor changes by Eric Blake's suggestion new patch: remove bdrv_truncate method from blkdebug
v2:
do not pass to bs->file if bs->drv is NULL
move bs->file check outside of bdrv_inc_in_flight() area in bdrv_co_ioctl() new patch: remove duplicate code from block/raw-format.c
Manos Pitsidianakis (4):
block: pass bdrv_* methods to bs->file by default in block filters
block: remove bdrv_media_changed
block: remove bdrv_truncate callback in blkdebug
block: add default implementations for bdrv_co_get_block_status()
block.c | 35 +++++++++++++++++++---------------- block/blkdebug.c | 19 ++----------------- block/commit.c | 12 +----------- block/io.c | 26 ++++++++++++++++++++++++++ block/mirror.c | 12 +----------- block/raw-format.c | 6 ------ include/block/block.h | 1 - include/block/block_int.h | 25 +++++++++++++++++++++++-- 8 files changed, 72 insertions(+), 64 deletions(-)
Signature · 1 line
2.11.0
PATCH v4 1/4 block: pass bdrv_* methods to bs->file by default in block filters
The following functions fail if bs->drv is a filter and does not implement them:
bdrv_probe_blocksizesbdrv_probe_geometrybdrv_truncatebdrv_has_zero_initbdrv_get_info
Instead, the call should be passed to bs->file if it exists, to allow filter drivers to support those methods without implementing them. This commit makes drv->is_filter = true imply that these callbacks will be forwarded to bs->file by default, so disabling support for these functions must be done explicitly.
--- block.c | 21 +++++++++++++++++++-- include/block/block_int.h | 6 +++++- 2 files changed, 24 insertions(+), 3 deletions(-)
block.c +19 -2
@@ -494,6 +494,8 @@ int bdrv_probe_blocksizes(BlockDriverState *bs, BlockSizes *bsz)if (drv && drv->bdrv_probe_blocksizes) {return drv->bdrv_probe_blocksizes (bs, bsz); + }else if (drv && drv->is_filter && bs->file) { +return bdrv_probe_blocksizes (bs->file->bs, bsz); }return -ENOTSUP ;
@@ -511,6 +513,8 @@ int bdrv_probe_geometry(BlockDriverState *bs, HDGeometry *geo)if (drv && drv->bdrv_probe_geometry) {return drv->bdrv_probe_geometry (bs, geo); + }else if (drv && drv->is_filter && bs->file) { +return bdrv_probe_geometry (bs->file->bs, geo); }return -ENOTSUP ;
@@ -3406,11 +3410,15 @@ int bdrv_truncate(BdrvChild *child, int64_t offset, Error **errp)assert (child->perm &BLK_PERM_RESIZE ); +/* if bs->drv == NULL, bs is closed, so there's nothing to do here */ if (!drv) {error_setg (errp,"No medium inserted" );return -ENOMEDIUM ; }if (!drv->bdrv_truncate) { +if (bs->file && drv->is_filter) { +return bdrv_truncate (bs->file, offset, errp); + }error_setg (errp,"Image format driver does not support resize" );return -ENOTSUP ; }
@@ -3778,6 +3786,9 @@ int bdrv_has_zero_init(BlockDriverState *bs)if (bs->drv->bdrv_has_zero_init) {return bs->drv->bdrv_has_zero_init (bs); } +if (bs->file && bs->drv->is_filter) { +return bdrv_has_zero_init (bs->file->bs); + }/* safe default */ return 0 ;
@@ -3832,10 +3843,16 @@ void bdrv_get_backing_filename(BlockDriverState *bs,int bdrv_get_info (BlockDriverState *bs,BlockDriverInfo *bdi) {BlockDriver *drv = bs->drv; -if (!drv) +/* if bs->drv == NULL, bs is closed, so there's nothing to do here */ +if (!drv) {return -ENOMEDIUM ; -if (!drv->bdrv_get_info) + } +if (!drv->bdrv_get_info) { +if (bs->file && drv->is_filter) { +return bdrv_get_info (bs->file->bs, bdi); + }return -ENOTSUP ; + }memset (bdi,0 ,sizeof (*bdi));return drv->bdrv_get_info (bs, bdi); }
include/block/block_int.h +5 -1
@@ -87,7 +87,11 @@ struct BlockDriver {const char *format_name;int instance_size; -/* set to true if the BlockDriver is a block filter */ +/* set to true if the BlockDriver is a block filter. Block filters pass +* certain callbacks that refer to data (see block.c) to their bs->file if +* the driver doesn't implement them. Drivers that do not wish to forward +* must implement them and return -ENOTSUP. +*/ bool is_filter;/* for snapshots block filter like Quorum can implement the * following recursive callback.
Signature · 1 line
2.11.0
Re: [Qemu-devel] [PATCH v4 1/4] block: pass bdrv_* methods to bs->file by default in block filters
Quoted 21 lines · Manos Pitsidianakis
The following functions fail if
bs->drvis a filter and does not implement them:
bdrv_probe_blocksizesbdrv_probe_geometrybdrv_truncatebdrv_has_zero_initbdrv_get_infoInstead, the call should be passed to
bs->fileif it exists, to allow filter drivers to support those methods without implementing them. This commit makesdrv->is_filter = trueimply that these callbacks will be forwarded tobs->fileby default, so disabling support for these functions must be done explicitly.Signed-off-by Manos Pitsidianakis <[email protected]>--- block.c | 21 +++++++++++++++++++-- include/block/block_int.h | 6 +++++- 2 files changed, 24 insertions(+), 3 deletions(-)
block.c int bdrv_has_zero_init(BlockDriverState *bs) · line 3794
Quoted 9 lines
block.c +3
-0@@ -3778,6 +3786,9 @@ int bdrv_has_zero_init(BlockDriverState *bs)if (bs->drv->bdrv_has_zero_init) {return bs->drv->bdrv_has_zero_init (bs); } +if (bs->file && bs->drv->is_filter) { +return bdrv_has_zero_init (bs->file->bs); + }/* safe default */ return 0 ;
Someday, we should probably clean this function (and all callback implementations) to return bool rather than int. But not this patch.
Certainly more conservative than the earlier versions. I'd still trust Kevin's review over mine, but looks okay to me.
Signature · 3 lines
Eric Blake, Principal Software Engineer Red Hat, Inc. +1-919-301-3266 Virtualization: qemu.org | libvirt.org
Re: [Qemu-devel] [PATCH v4 1/4] block: pass bdrv_* methods to bs->file by default in block filters
In reply to Manos PitsidianakisQuoted 15 lines · Manos Pitsidianakis
The following functions fail if
bs->drvis a filter and does not implement them:
bdrv_probe_blocksizesbdrv_probe_geometrybdrv_truncatebdrv_has_zero_initbdrv_get_infoInstead, the call should be passed to
bs->fileif it exists, to allow filter drivers to support those methods without implementing them. This commit makesdrv->is_filter = trueimply that these callbacks will be forwarded tobs->fileby default, so disabling support for these functions must be done explicitly.
Quoted 5 lines
Signed-off-by Manos Pitsidianakis <[email protected]>--- block.c | 21 +++++++++++++++++++-- include/block/block_int.h | 6 +++++- 2 files changed, 24 insertions(+), 3 deletions(-)
Re: [Qemu-devel] [PATCH v4 1/4] block: pass bdrv_* methods to bs->file by default in block filters
In reply to Manos PitsidianakisQuoted 24 lines · Manos Pitsidianakis
The following functions fail if
bs->drvis a filter and does not implement them:
bdrv_probe_blocksizesbdrv_probe_geometrybdrv_truncatebdrv_has_zero_initbdrv_get_infoInstead, the call should be passed to
bs->fileif it exists, to allow filter drivers to support those methods without implementing them. This commit makesdrv->is_filter = trueimply that these callbacks will be forwarded tobs->fileby default, so disabling support for these functions must be done explicitly.Signed-off-by Manos Pitsidianakis <[email protected]>--- block.c | 21 +++++++++++++++++++-- include/block/block_int.h | 6 +++++- 2 files changed, 24 insertions(+), 3 deletions(-)block.c +0
-0@@ -3406,11 +3410,15 @@ int bdrv_truncate(BdrvChild *child, int64_t offset, Error **errp)assert (child->perm &BLK_PERM_RESIZE );
block.c int bdrv_truncate(BdrvChild *child, int64_t offset, Error **errp) · line 3421
Quoted 10 lines
block.c +4
-0+/* if bs->drv == NULL, bs is closed, so there's nothing to do here */ if (!drv) {error_setg (errp,"No medium inserted" );return -ENOMEDIUM ; }if (!drv->bdrv_truncate) { +if (bs->file && drv->is_filter) { +return bdrv_truncate (bs->file, offset, errp); + }
This has a semantic (but not merge) conflict with Max's preallocation work, and it started to be non-trivial for me to adjust locally in my testing. It may be easiest if you send a v5 on top of 'https://github.com/XanClic/qemu.git block', since Max already has a pending pull request:
https://lists.gnu.org/archive/html/qemu-devel/2017-07/msg02841.html
Signature · 3 lines
Eric Blake, Principal Software Engineer Red Hat, Inc. +1-919-301-3266 Virtualization: qemu.org | libvirt.org
PATCH v4 2/4 block: remove bdrv_media_changed
In reply to Manos PitsidianakisThis function is not used anywhere, so remove it.
--- block.c | 14 -------------- block/raw-format.c | 6 ------ include/block/block.h | 1 - include/block/block_int.h | 1 - 4 files changed, 22 deletions(-)
block.c +0 -14
@@ -4213,20 +4213,6 @@ bool bdrv_is_inserted(BlockDriverState *bs) }/** -* Return whether the media changed since the last call to this -* function, or -ENOTSUP if we don't know. Most drivers don't know. -*/ -int bdrv_media_changed (BlockDriverState *bs) -{ -BlockDriver *drv = bs->drv; - -if (drv && drv->bdrv_media_changed) { -return drv->bdrv_media_changed (bs); - } -return -ENOTSUP ; -} - -/** * If eject_flag is TRUE, eject the media. Otherwise, close the tray */ void bdrv_eject (BlockDriverState *bs,bool eject_flag)
block/raw-format.c +0 -6
@@ -346,11 +346,6 @@ static int raw_truncate(BlockDriverState *bs, int64_t offset, Error **errp)return bdrv_truncate (bs->file, offset, errp); } -static int raw_media_changed (BlockDriverState *bs) -{ -return bdrv_media_changed (bs->file->bs); -} -static void raw_eject (BlockDriverState *bs,bool eject_flag) {bdrv_eject (bs->file->bs, eject_flag);
@@ -483,7 +478,6 @@ BlockDriver bdrv_raw = { .bdrv_refresh_limits = &raw_refresh_limits, .bdrv_probe_blocksizes = &raw_probe_blocksizes, .bdrv_probe_geometry = &raw_probe_geometry, - .bdrv_media_changed = &raw_media_changed, .bdrv_eject = &raw_eject, .bdrv_lock_medium = &raw_lock_medium, .bdrv_co_ioctl = &raw_co_ioctl,
include/block/block.h +0 -1
@@ -438,7 +438,6 @@ int bdrv_can_set_read_only(BlockDriverState *bs, bool read_only, Error **errp);int bdrv_set_read_only (BlockDriverState *bs,bool read_only,Error **errp);bool bdrv_is_sg (BlockDriverState *bs);bool bdrv_is_inserted (BlockDriverState *bs); -int bdrv_media_changed (BlockDriverState *bs);void bdrv_lock_medium (BlockDriverState *bs,bool locked);void bdrv_eject (BlockDriverState *bs,bool eject_flag);const char *bdrv_get_format_name (BlockDriverState *bs);
include/block/block_int.h +0 -1
@@ -246,7 +246,6 @@ struct BlockDriver {/* removable device specific */ bool (*bdrv_is_inserted)(BlockDriverState *bs); -int (*bdrv_media_changed)(BlockDriverState *bs);void (*bdrv_eject)(BlockDriverState *bs,bool eject_flag);void (*bdrv_lock_medium)(BlockDriverState *bs,bool locked);
Signature · 1 line
2.11.0
Re: [Qemu-devel] [PATCH v4 2/4] block: remove bdrv_media_changed
Quoted 2 lines · Manos Pitsidianakis
This function is not used anywhere, so remove it.
Might be interesting to figure out when it WAS last used. If I grepped correctly, it was commit 21fcf360 back in May 2012?
Quoted 7 lines
Signed-off-by Manos Pitsidianakis <[email protected]>--- block.c | 14 -------------- block/raw-format.c | 6 ------ include/block/block.h | 1 - include/block/block_int.h | 1 - 4 files changed, 22 deletions(-)
Signature · 3 lines
Eric Blake, Principal Software Engineer Red Hat, Inc. +1-919-301-3266 Virtualization: qemu.org | libvirt.org
Re: [Qemu-devel] [PATCH v4 2/4] block: remove bdrv_media_changed
Quoted 5 lines · Eric Blake
Quoted 2 lines · Manos Pitsidianakis
This function is not used anywhere, so remove it.
Might be interesting to figure out when it WAS last used.
Yes. When I see "remove X because it's unused" during patch review, I immediately ask "why is it unused now, and what was it used for previously?" Ideally, the commit message answers these questions preemptively.
Quoted 2 lines
If I grepped
correctly, it was commit21fcf360back in May 2012?
Yes. "fdc: simplify media change handling". I suspect that commit broke media change for passed-through host floppy.
Its only implementation went away in commit f709623 "block: Remove host floppy support".
Suggest
block: bdrv_media_changed() is unused, remove
The i82078 floppy device model used to call bdrv_media_changed() to implement its media change bit when backed by a host floppy. This went away in 21fcf36 "fdc: simplify media change handling". Probably broke host floppy media change. Host floppy pass-through was dropped in commit f709623. bdrv_media_changed() has never been used for anything else. Remove it.
Re: [Qemu-devel] [PATCH v4 2/4] block: remove bdrv_media_changed
Am 12.07.2017 um 09:41 hat Markus Armbruster geschrieben:
Quoted 24 lines
Quoted 5 lines · Eric Blake
Quoted 2 lines · Manos Pitsidianakis
This function is not used anywhere, so remove it.
Might be interesting to figure out when it WAS last used.
Yes. When I see "remove X because it's unused" during patch review, I immediately ask "why is it unused now, and what was it used for previously?" Ideally, the commit message answers these questions preemptively.
Quoted 2 lines
If I grepped
correctly, it was commit21fcf360back in May 2012?Yes. "fdc: simplify media change handling". I suspect that commit broke media change for passed-through host floppy.
Its only implementation went away in commit f709623 "block: Remove host floppy support".
Suggest
Quoted 8 lines
block:
bdrv_media_changed()is unused, removeThe i82078 floppy device model used to call
bdrv_media_changed()to implement its media change bit when backed by a host floppy. This went away in 21fcf36 "fdc: simplify media change handling". Probably broke host floppy media change. Host floppy pass-through was dropped in commit f709623.bdrv_media_changed()has never been used for anything else. Remove it.
Manos, if you're happy with this, I can update the commit message while applying the series.
Kevin
Re: [Qemu-devel] [PATCH v4 2/4] block: remove bdrv_media_changed
Quoted 34 lines · Kevin Wolf
Am 12.07.2017 um 09:41 hat Markus Armbruster geschrieben:
Quoted 24 lines
Quoted 5 lines · Eric Blake
Quoted 2 lines · Manos Pitsidianakis
This function is not used anywhere, so remove it.
Might be interesting to figure out when it WAS last used.
Yes. When I see "remove X because it's unused" during patch review, I immediately ask "why is it unused now, and what was it used for previously?" Ideally, the commit message answers these questions preemptively.
Quoted 2 lines
If I grepped
correctly, it was commit21fcf360back in May 2012?Yes. "fdc: simplify media change handling". I suspect that commit broke media change for passed-through host floppy.
Its only implementation went away in commit f709623 "block: Remove host floppy support".
Suggest
Quoted 8 lines
block:
bdrv_media_changed()is unused, removeThe i82078 floppy device model used to call
bdrv_media_changed()to implement its media change bit when backed by a host floppy. This went away in 21fcf36 "fdc: simplify media change handling". Probably broke host floppy media change. Host floppy pass-through was dropped in commit f709623.bdrv_media_changed()has never been used for anything else. Remove it.
Quoted 2 lines
Manos, if you're happy with this, I can update the commit message while applying the series.
Of course, no problem.
Thanks!
Re: [Qemu-devel] [PATCH v4 2/4] block: remove bdrv_media_changed
In reply to Manos PitsidianakisQuoted 9 lines · Manos Pitsidianakis
This function is not used anywhere, so remove it.
Signed-off-by Manos Pitsidianakis <[email protected]>--- block.c | 14 -------------- block/raw-format.c | 6 ------ include/block/block.h | 1 - include/block/block_int.h | 1 - 4 files changed, 22 deletions(-)
Re: [Qemu-devel] [PATCH v4 2/4] block: remove bdrv_media_changed
In reply to Manos PitsidianakisQuoted 13 lines · Manos Pitsidianakis
This function is not used anywhere, so remove it.
Signed-off-by Manos Pitsidianakis <[email protected]>--- block.c | 14 -------------- block/raw-format.c | 6 ------ include/block/block.h | 1 - include/block/block_int.h | 1 - 4 files changed, 22 deletions(-)+++
b/block/raw-format.c
block/raw-format.c static int raw_truncate(BlockDriverState *bs, int64_t offset, Error **errp) · line 353
Quoted 8 lines
block/raw-format.c +0
-5@@ -346,11 +346,6 @@ static int raw_truncate(BlockDriverState *bs, int64_t offset, Error **errp)return bdrv_truncate (bs->file, offset, errp); } -static int raw_media_changed (BlockDriverState *bs) -{ -return bdrv_media_changed (bs->file->bs); -} -
There's a merge conflict here if this lands after Max's pending block pull request, but should be trivial to resolve.
Signature · 3 lines
Eric Blake, Principal Software Engineer Red Hat, Inc. +1-919-301-3266 Virtualization: qemu.org | libvirt.org
PATCH v4 3/4 block: remove bdrv_truncate callback in blkdebug
In reply to Manos PitsidianakisNow that bdrv_truncate is passed to bs->file by default, remove the callback from block/blkdebug.c and set is_filter to true.
--- block/blkdebug.c | 7 +------ 1 file changed, 1 insertion(+), 6 deletions(-)
block/blkdebug.c +1 -6
@@ -821,11 +821,6 @@ static int64_t blkdebug_getlength(BlockDriverState *bs)return bdrv_getlength (bs->file->bs); } -static int blkdebug_truncate (BlockDriverState *bs,int64_t offset,Error **errp) -{ -return bdrv_truncate (bs->file, offset, errp); -} -static void blkdebug_refresh_filename (BlockDriverState *bs,QDict *options) {BDRVBlkdebugState *s = bs->opaque;
@@ -908,6 +903,7 @@ static BlockDriver bdrv_blkdebug = { .format_name = "blkdebug", .protocol_name = "blkdebug", .instance_size = sizeof(BDRVBlkdebugState), + .is_filter = true, .bdrv_parse_filename = blkdebug_parse_filename, .bdrv_file_open = blkdebug_open,
@@ -916,7 +912,6 @@ static BlockDriver bdrv_blkdebug = { .bdrv_child_perm = bdrv_filter_default_perms, .bdrv_getlength = blkdebug_getlength, - .bdrv_truncate = blkdebug_truncate, .bdrv_refresh_filename = blkdebug_refresh_filename, .bdrv_refresh_limits = blkdebug_refresh_limits,
Signature · 1 line
2.11.0
Re: [Qemu-devel] [PATCH v4 3/4] block: remove bdrv_truncate callback in blkdebug
Quoted 2 lines · Manos Pitsidianakis
Now that
bdrv_truncateis passed tobs->fileby default, remove the callback fromblock/blkdebug.cand setis_filterto true.
This also automatically gives blkdebug access to
bdrv_probe_blocksizesbdrv_probe_geometrybdrv_has_zero_initbdrv_get_info
all of which make sense to me.
Quoted 5 lines
Signed-off-by Manos Pitsidianakis <[email protected]>--- block/blkdebug.c | 7 +------ 1 file changed, 1 insertion(+), 6 deletions(-)
Signature · 3 lines
Eric Blake, Principal Software Engineer Red Hat, Inc. +1-919-301-3266 Virtualization: qemu.org | libvirt.org
Re: [Qemu-devel] [PATCH v4 3/4] block: remove bdrv_truncate callback in blkdebug
In reply to Manos PitsidianakisQuoted 7 lines · Manos Pitsidianakis
Now that
bdrv_truncateis passed tobs->fileby default, remove the callback fromblock/blkdebug.cand setis_filterto true.Signed-off-by Manos Pitsidianakis <[email protected]>--- block/blkdebug.c | 7 +------ 1 file changed, 1 insertion(+), 6 deletions(-)
PATCH v4 4/4 block: add default implementations for bdrv_co_get_block_status()
In reply to Manos Pitsidianakisbdrv_co_get_block_status_from_file() and bdrv_co_get_block_status_from_backing() set *file to bs->file and bs->backing respectively, so that bdrv_co_get_block_status() can recurse to them. Future block drivers won't have to duplicate code to implement this.
--- block/blkdebug.c | 12 +----------- block/commit.c | 12 +----------- block/io.c | 26 ++++++++++++++++++++++++++ block/mirror.c | 12 +----------- include/block/block_int.h | 18 ++++++++++++++++++ 5 files changed, 47 insertions(+), 33 deletions(-)
block/blkdebug.c +1 -11
@@ -641,16 +641,6 @@ static int coroutine_fn blkdebug_co_pdiscard(BlockDriverState *bs,return bdrv_co_pdiscard (bs->file->bs, offset, bytes); } -static int64_t coroutine_fn blkdebug_co_get_block_status( -BlockDriverState *bs,int64_t sector_num,int nb_sectors,int *pnum, -BlockDriverState **file) -{ - *pnum = nb_sectors; - *file = bs->file->bs; -return BDRV_BLOCK_RAW |BDRV_BLOCK_OFFSET_VALID | - (sector_num <<BDRV_SECTOR_BITS ); -} -static void blkdebug_close (BlockDriverState *bs) {BDRVBlkdebugState *s = bs->opaque;
@@ -920,7 +910,7 @@ static BlockDriver bdrv_blkdebug = { .bdrv_co_flush_to_disk = blkdebug_co_flush, .bdrv_co_pwrite_zeroes = blkdebug_co_pwrite_zeroes, .bdrv_co_pdiscard = blkdebug_co_pdiscard, - .bdrv_co_get_block_status = blkdebug_co_get_block_status, + .bdrv_co_get_block_status = bdrv_co_get_block_status_from_file, .bdrv_debug_event = blkdebug_debug_event, .bdrv_debug_breakpoint = blkdebug_debug_breakpoint,
block/commit.c +1 -11
@@ -247,16 +247,6 @@ static int coroutine_fn bdrv_commit_top_preadv(BlockDriverState *bs,return bdrv_co_preadv (bs->backing, offset, bytes, qiov, flags); } -static int64_t coroutine_fn bdrv_commit_top_get_block_status( -BlockDriverState *bs,int64_t sector_num,int nb_sectors,int *pnum, -BlockDriverState **file) -{ - *pnum = nb_sectors; - *file = bs->backing->bs; -return BDRV_BLOCK_RAW |BDRV_BLOCK_OFFSET_VALID | - (sector_num <<BDRV_SECTOR_BITS ); -} -static void bdrv_commit_top_refresh_filename (BlockDriverState *bs,QDict *opts) {bdrv_refresh_filename (bs->backing->bs);
@@ -282,7 +272,7 @@ static void bdrv_commit_top_child_perm(BlockDriverState *bs, BdrvChild *c,static BlockDriver bdrv_commit_top = { .format_name ="commit_top" , .bdrv_co_preadv = bdrv_commit_top_preadv, - .bdrv_co_get_block_status = bdrv_commit_top_get_block_status, + .bdrv_co_get_block_status = bdrv_co_get_block_status_from_backing, .bdrv_refresh_filename = bdrv_commit_top_refresh_filename, .bdrv_close = bdrv_commit_top_close, .bdrv_child_perm = bdrv_commit_top_child_perm,
block/io.c +26 -0
@@ -1706,6 +1706,32 @@ typedef struct BdrvCoGetBlockStatusData {bool done; } BdrvCoGetBlockStatusData; +int64_t coroutine_fn bdrv_co_get_block_status_from_file(BlockDriverState *bs, +int64_t sector_num, +int nb_sectors, +int *pnum, +BlockDriverState **file) +{ +assert (bs->file && bs->file->bs); + *pnum = nb_sectors; + *file = bs->file->bs; +return BDRV_BLOCK_RAW |BDRV_BLOCK_OFFSET_VALID | + (sector_num <<BDRV_SECTOR_BITS ); +} + +int64_t coroutine_fn bdrv_co_get_block_status_from_backing(BlockDriverState *bs, +int64_t sector_num, +int nb_sectors, +int *pnum, +BlockDriverState **file) +{ +assert (bs->backing && bs->backing->bs); + *pnum = nb_sectors; + *file = bs->backing->bs; +return BDRV_BLOCK_RAW |BDRV_BLOCK_OFFSET_VALID | + (sector_num <<BDRV_SECTOR_BITS ); +} +/* * Returns the allocation status of the specified sectors. * Drivers not implementing the functionality are assumed to not support
block/mirror.c +1 -11
@@ -1052,16 +1052,6 @@ static int coroutine_fn bdrv_mirror_top_flush(BlockDriverState *bs)return bdrv_co_flush (bs->backing->bs); } -static int64_t coroutine_fn bdrv_mirror_top_get_block_status( -BlockDriverState *bs,int64_t sector_num,int nb_sectors,int *pnum, -BlockDriverState **file) -{ - *pnum = nb_sectors; - *file = bs->backing->bs; -return BDRV_BLOCK_RAW |BDRV_BLOCK_OFFSET_VALID | - (sector_num <<BDRV_SECTOR_BITS ); -} - static int coroutine_fn bdrv_mirror_top_pwrite_zeroes(BlockDriverState *bs,int64_t offset,int bytes,BdrvRequestFlags flags) {
@@ -1108,7 +1098,7 @@ static BlockDriver bdrv_mirror_top = { .bdrv_co_pwrite_zeroes = bdrv_mirror_top_pwrite_zeroes, .bdrv_co_pdiscard = bdrv_mirror_top_pdiscard, .bdrv_co_flush = bdrv_mirror_top_flush, - .bdrv_co_get_block_status = bdrv_mirror_top_get_block_status, + .bdrv_co_get_block_status = bdrv_co_get_block_status_from_backing, .bdrv_refresh_filename = bdrv_mirror_top_refresh_filename, .bdrv_close = bdrv_mirror_top_close, .bdrv_child_perm = bdrv_mirror_top_child_perm,
include/block/block_int.h +18 -0
@@ -948,6 +948,24 @@ void bdrv_format_default_perms(BlockDriverState *bs, BdrvChild *c, uint64_t perm, uint64_t shared, uint64_t *nperm, uint64_t *nshared); +/* +* Default implementation for drivers to pass bdrv_co_get_block_status() to +* their file. +*/ +int64_t coroutine_fn bdrv_co_get_block_status_from_file(BlockDriverState *bs, +int64_t sector_num, +int nb_sectors, +int *pnum, +BlockDriverState **file); +/* +* Default implementation for drivers to pass bdrv_co_get_block_status() to +* their backing file. +*/ +int64_t coroutine_fn bdrv_co_get_block_status_from_backing(BlockDriverState *bs, +int64_t sector_num, +int nb_sectors, +int *pnum, +BlockDriverState **file);const char *bdrv_get_parent_name (const BlockDriverState *bs);void blk_dev_change_media_cb (BlockBackend *blk,bool load,Error **errp);bool blk_dev_has_removable_media (BlockBackend *blk);
Signature · 1 line
2.11.0
Re: [Qemu-devel] [PATCH v4 4/4] block: add default implementations for bdrv_co_get_block_status()
Quoted 11 lines · Manos Pitsidianakis
bdrv_co_get_block_status_from_file()andbdrv_co_get_block_status_from_backing()set *file tobs->fileandbs->backingrespectively, so thatbdrv_co_get_block_status()can recurse to them. Future block drivers won't have to duplicate code to implement this.Reviewed-by Fam Zheng <[email protected]>Reviewed-by Eric Blake <[email protected]>Reviewed-by Stefan Hajnoczi <[email protected]>Reviewed-by Kevin Wolf <[email protected]>Signed-off-by Manos Pitsidianakis <[email protected]>
Quoted 7 lines
--- block/blkdebug.c | 12 +----------- block/commit.c | 12 +----------- block/io.c | 26 ++++++++++++++++++++++++++ block/mirror.c | 12 +----------- include/block/block_int.h | 18 ++++++++++++++++++ 5 files changed, 47 insertions(+), 33 deletions(-)
Quoted 6 lines · Manos Pitsidianakis
This series makes implementing some of the bdrv_* callbacks easier for block filters by passing requests to
bs->fileifbs->drvdoesn't implement it instead of failing, and adding defaultbdrv_co_get_block_status()implementations.This is based against Kevin Wolf's block branch, commit
da4bd74d2450ab72a7c26bbabb10c6a287dd043e
Haven't seen BlockDriver member is_filter before. Interesting. It's documentation
/* set to true if the BlockDriver is a block filter */
bool is_filter;is seriously lacking. What does it *mean* to be a block filter? Which block layer facilities are affected, and how?
Observation: driver "raw" is filter-like in the sense that all it does is pass along method arguments and results. Can't say whether that makes it a filter in the sense of is_filter, because "the sense of is_filter" is nebulous to me :)
Quoted 9 lines · Markus Armbruster
Quoted 6 lines · Manos Pitsidianakis
This series makes implementing some of the bdrv_* callbacks easier for block filters by passing requests to
bs->fileifbs->drvdoesn't implement it instead of failing, and adding defaultbdrv_co_get_block_status()implementations.This is based against Kevin Wolf's block branch, commit
da4bd74d2450ab72a7c26bbabb10c6a287dd043e
Quoted 8 lines
Haven't seen BlockDriver member
is_filterbefore. Interesting. It's documentation/* set to true if the BlockDriver is a block filter */ bool is_filter;is seriously lacking. What does it *mean* to be a block filter? Which block layer facilities are affected, and how?
Currently it is only used in bdrv_recurse_is_first_non_filter.
Quoted 4 lines
Observation: driver "raw" is filter-like in the sense that all it does is pass along method arguments and results. Can't say whether that makes it a filter in the sense of
is_filter, because "the sense ofis_filter" is nebulous to me :)
I'm not very acquainted with raw, so I can't really comment. But the drivers I'm working on, throttle and before write notifier have that exact semantic, ie they do something when IO is intercepted and pass everything to the BDSes below. There was a mini discussion about raw and filters in the previous version's thread.
I might add documentation to block_int.h in the future. When I first read it it felt nebulous to me too.
Am 12.07.2017 um 10:10 hat Manos Pitsidianakis geschrieben:
Quoted 26 lines · Markus Armbruster
Quoted 9 lines
Quoted 6 lines · Manos Pitsidianakis
This series makes implementing some of the bdrv_* callbacks easier for block filters by passing requests to
bs->fileifbs->drvdoesn't implement it instead of failing, and adding defaultbdrv_co_get_block_status()implementations.This is based against Kevin Wolf's block branch, commit
da4bd74d2450ab72a7c26bbabb10c6a287dd043eQuoted 8 lines
Haven't seen BlockDriver member
is_filterbefore. Interesting. It's documentation/* set to true if the BlockDriver is a block filter */ bool
is_filter;is seriously lacking. What does it *mean* to be a block filter? Which block layer facilities are affected, and how?
Currently it is only used in
bdrv_recurse_is_first_non_filter.Quoted 4 lines
Observation: driver "raw" is filter-like in the sense that all it does is pass along method arguments and results. Can't say whether that makes it a filter in the sense of
is_filter, because "the sense ofis_filter" is nebulous to me :)
Quoted 8 lines
I'm not very acquainted with raw, so I can't really comment. But the drivers I'm working on, throttle and before write notifier have that exact semantic, ie they do something when IO is intercepted and pass everything to the BDSes below. There was a mini discussion about raw and filters in the previous version's thread.
I might add documentation to
block_int.hin the future. When I first read it it felt nebulous to me too.
Not something that should stop this series, but while you're adding some implications of being a filter to block_int.h, we still don't have a definition of which block drivers qualify as filters.
"do something when IO is intercepted and pass everything to the BDSes below" is probably not enough, every driver does this unless it is a protocol driver.
We could further qualify it such that reads/writes on filter always result in reads/writes on the same offset in bs->file (this disqualifies the raw format, which you seem to want) and the block status is always taken from bs->file.
We could also add that the data read/written must be the same - it's not quite clear to me yet if we want to require this or can make use of the property.
I'm open for other suggestion of what makes a filter a filter in the sense of this field. Ideally it would contain enough (or maybe better:
the right) conditions that you can use it to justify why for each of the functions that you pass down by default, this is the right behaviour.
For example, passing through bdrv_probe_geometry() makes sense because all I/O is passed through unmodified and the image size is the same, etc.
Kevin