diff mbox series

[2/2] block/export: Add vhost-user-blk resize support

Message ID 20220121084644.217-2-xieyongji@bytedance.com
State New
Headers show
Series [1/2] libvhost-user: Add vu_notify_config_change() to support config change notify | expand

Commit Message

Yongji Xie Jan. 21, 2022, 8:46 a.m. UTC
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 <xieyongji@bytedance.com>
---
 block/export/vhost-user-blk-server.c | 16 ++++++++++++++++
 1 file changed, 16 insertions(+)
diff mbox series

Patch

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;
 }