libvhost-user: Add vu_notify_config_change() to support config change notify
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.
Signed-off-by Xie Yongji <[email protected]>
--- 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
@@ -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
@@ -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
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.
Signed-off-by Xie Yongji <[email protected]>
--- block/export/vhost-user-blk-server.c | 16 ++++++++++++++++ 1 file changed, 16 insertions(+)
block/export/vhost-user-blk-server.c +16 -0
@@ -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