To support block resize, this updates the capacity field in configuration space and use vu_notify_config_change() to notify the vhost-user master on the block resize callback.
Signed-off-by: Xie Yongji <xieyon...@bytedance.com> --- block/export/vhost-user-blk-server.c | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/block/export/vhost-user-blk-server.c b/block/export/vhost-user-blk-server.c index 1862563336..929a0bd007 100644 --- a/block/export/vhost-user-blk-server.c +++ b/block/export/vhost-user-blk-server.c @@ -435,6 +435,20 @@ static void blk_aio_detach(void *opaque) vexp->export.ctx = NULL; } +static void vu_blk_resize(void *opaque) +{ + BlockExport *exp = opaque; + VuBlkExport *vexp = container_of(exp, VuBlkExport, export); + + vexp->blkcfg.capacity = + cpu_to_le64(blk_getlength(exp->blk) >> VIRTIO_BLK_SECTOR_BITS); + vu_notify_config_change(&vexp->vu_server.vu_dev); +} + +static const BlockDevOps vu_block_ops = { + .resize_cb = vu_blk_resize, +}; + static void vu_blk_initialize_config(BlockDriverState *bs, struct virtio_blk_config *config, @@ -513,6 +527,8 @@ static int vu_blk_exp_create(BlockExport *exp, BlockExportOptions *opts, return -EADDRNOTAVAIL; } + blk_set_dev_ops(exp->blk, &vu_block_ops, exp); + return 0; } -- 2.20.1