Skip to contentSkip to conversation

libvhost-user: Add vu_notify_config_change() to support config change notify

PATCH New Xie Yongji 1 participant 2 messages Jan 21, 2022 Block layer

lore
Share & tools
lore

Xie Yongji

author
#0 lore raw

PATCH 1/2 libvhost-user: Add vu_notify_config_change() to support config change notify

This adds a new API vu_notify_config_change() to support sending VHOST_USER_SLAVE_CONFIG_CHANGE_MSG message to notify that the configuration space has changed.

---
 subprojects/libvhost-user/libvhost-user.c | 20 ++++++++++++++++++++
 subprojects/libvhost-user/libvhost-user.h |  8 ++++++++
 2 files changed, 28 insertions(+)
subprojects/libvhost-user/libvhost-user.c +20 -0
index 787f4d2d4f..ff95ccd6f3 100644
@@ -1545,6 +1545,26 @@ vu_set_config(VuDev *dev, VhostUserMsg *vmsg)
     return false;
 }
 
+bool vu_notify_config_change(VuDev *dev)
+{
+    bool ret;
+    VhostUserMsg vmsg = {
+        .request = VHOST_USER_SLAVE_CONFIG_CHANGE_MSG,
+        .flags = VHOST_USER_VERSION,
+        .size = 0,
+    };
+
+    if (!vu_has_protocol_feature(dev, VHOST_USER_PROTOCOL_F_CONFIG)) {
+        return false;
+    }
+
+    pthread_mutex_lock(&dev->slave_mutex);
+    ret = !vu_message_write(dev, dev->slave_fd, &vmsg);
+    pthread_mutex_unlock(&dev->slave_mutex);
+
+    return ret;
+}
+
 static bool
 vu_set_postcopy_advise(VuDev *dev, VhostUserMsg *vmsg)
 {
subprojects/libvhost-user/libvhost-user.h +8 -0
index 3d13dfadde..dd14242a7b 100644
@@ -491,6 +491,14 @@ bool vu_dispatch(VuDev *dev);
  */
 void *vu_gpa_to_va(VuDev *dev, uint64_t *plen, uint64_t guest_addr);
 
+/**
+ * vu_notify_config_change:
+ * @dev: a VuDev context
+ *
+ * Notify that the configuration space has changed. Returns FALSE on failure.
+ */
+bool vu_notify_config_change(VuDev *dev);
+
 /**
  * vu_get_queue:
  * @dev: a VuDev context
Signature · 1 line
2.20.1
author
#1 lore raw

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

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.

---
 block/export/vhost-user-blk-server.c | 16 ++++++++++++++++
 1 file changed, 16 insertions(+)
block/export/vhost-user-blk-server.c +16 -0
index 1862563336..929a0bd007 100644
@@ -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;
 }
 
Signature · 1 line
2.20.1