* [PATCH 1/2] libvhost-user: Add vu_notify_config_change() to support config change notify
@ 2022-01-21 8:46 Xie Yongji
2022-01-21 8:46 ` [PATCH 2/2] block/export: Add vhost-user-blk resize support Xie Yongji
0 siblings, 1 reply; 2+ messages in thread
From: Xie Yongji @ 2022-01-21 8:46 UTC (permalink / raw)
To: Coiby.Xu, stefanha, marcandre.lureau, kwolf, mreitz
Cc: qemu-devel, qemu-block
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 --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
--
2.20.1
^ permalink raw reply related [flat|nested] 2+ messages in thread
* [PATCH 2/2] block/export: Add vhost-user-blk resize support
2022-01-21 8:46 [PATCH 1/2] libvhost-user: Add vu_notify_config_change() to support config change notify Xie Yongji
@ 2022-01-21 8:46 ` Xie Yongji
0 siblings, 0 replies; 2+ messages in thread
From: Xie Yongji @ 2022-01-21 8:46 UTC (permalink / raw)
To: Coiby.Xu, stefanha, marcandre.lureau, kwolf, mreitz
Cc: qemu-devel, qemu-block
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 --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
^ permalink raw reply related [flat|nested] 2+ messages in thread
end of thread, other threads:[~2022-01-21 10:13 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2022-01-21 8:46 [PATCH 1/2] libvhost-user: Add vu_notify_config_change() to support config change notify Xie Yongji
2022-01-21 8:46 ` [PATCH 2/2] block/export: Add vhost-user-blk resize support Xie Yongji
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).