The NBD protocol would like to advertise the optimal I/O size to the client; but it would be a layering violation to peek into blk_bs(blk)->bl, when we only have a BB.
This copies the existing blk_get_max_transfer() in reading a value from the top BDS; where that value was picked via bdrv_refresh_limits() to reflect the overall constraints of the entire BDS chain. Signed-off-by: Eric Blake <ebl...@redhat.com> --- v4: retitle, as part of rebasing to byte limits v3: new patch --- include/sysemu/block-backend.h | 1 + block/block-backend.c | 12 ++++++++++++ 2 files changed, 13 insertions(+) diff --git a/include/sysemu/block-backend.h b/include/sysemu/block-backend.h index 6444e41..882480a 100644 --- a/include/sysemu/block-backend.h +++ b/include/sysemu/block-backend.h @@ -174,6 +174,7 @@ void blk_lock_medium(BlockBackend *blk, bool locked); void blk_eject(BlockBackend *blk, bool eject_flag); int blk_get_flags(BlockBackend *blk); uint32_t blk_get_max_transfer(BlockBackend *blk); +uint32_t blk_get_opt_transfer(BlockBackend *blk); int blk_get_max_iov(BlockBackend *blk); void blk_set_guest_block_size(BlockBackend *blk, int align); void *blk_try_blockalign(BlockBackend *blk, size_t size); diff --git a/block/block-backend.c b/block/block-backend.c index efbf398..4d91ff8 100644 --- a/block/block-backend.c +++ b/block/block-backend.c @@ -1426,6 +1426,18 @@ uint32_t blk_get_max_transfer(BlockBackend *blk) return MIN_NON_ZERO(max, INT_MAX); } +/* Returns the optimum transfer length, in bytes; may be 0 if no optimum */ +uint32_t blk_get_opt_transfer(BlockBackend *blk) +{ + BlockDriverState *bs = blk_bs(blk); + + if (bs) { + return bs->bl.opt_transfer; + } else { + return 0; + } +} + int blk_get_max_iov(BlockBackend *blk) { return blk->root->bs->bl.max_iov; -- 2.9.3