diff mbox series

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

Message ID 20220121084644.217-1-xieyongji@bytedance.com (mailing list archive)
State New, archived
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
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.

Signed-off-by: Xie Yongji <xieyongji@bytedance.com>
---
 subprojects/libvhost-user/libvhost-user.c | 20 ++++++++++++++++++++
 subprojects/libvhost-user/libvhost-user.h |  8 ++++++++
 2 files changed, 28 insertions(+)
diff mbox series

Patch

diff --git a/subprojects/libvhost-user/libvhost-user.c b/subprojects/libvhost-user/libvhost-user.c
index 787f4d2d4f..ff95ccd6f3 100644
--- a/subprojects/libvhost-user/libvhost-user.c
+++ b/subprojects/libvhost-user/libvhost-user.c
@@ -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)
 {
diff --git a/subprojects/libvhost-user/libvhost-user.h b/subprojects/libvhost-user/libvhost-user.h
index 3d13dfadde..dd14242a7b 100644
--- a/subprojects/libvhost-user/libvhost-user.h
+++ b/subprojects/libvhost-user/libvhost-user.h
@@ -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