block/export: convert vhost-user-blk-server to block exports API
Subsystems (2)
v2 cover block/export: convert vhost-user-blk-server to block exports API
v2:
* Replace unix-socket=str with addr=SocketAddress for consistency with NBD and fd passing support. The new syntax is:
--export vhost-user-blk,addr.type=unix,addr.path=/tmp/vhost-user-blk.sock,...
* Make addr=SocketAddress mandatory instead of optional [Markus]
* Update test-vhost-user-blk.c to use new syntax
* Add patch moving vhost-user-server.h to include/
* Add patch to use libvhost-user.a instead of compiling it multiple times
This patch series converts Coiby Xu's vhost-user-blk-server from a QOM object to the block exports API. The block exports API provides a standard QMP and command-line interface for managing block exports (NBD, FUSE, vhost-user-blk, etc). A fair amount of init/shutdown code is removed because the block exports API already takes care of that functionality.
Most of the patches are vhost-user-blk-server cleanups.
The syntax for launching qemu-storage-daemon is:
$ qemu-storage-daemon \
--blockdev file,node-name=drive0,filename=test.img \
--export vhost-user-blk,node-name=drive0,id=export0,writable=on,addr.type=unix,addr.path=/tmp/vhost-user-blk.sockQEMU can connect to the vhost-user-blk export like this:
$ qemu-system-x86_64 \
-M accel=kvm,memory-backend=mem \
-m 1G \
-object memory-backend-memfd,size=1G,id=mem \
-cpu host \
-chardev socket,path=/tmp/vhost-user-blk.sock,id=char0 \
-device vhost-user-blk-pci,chardev=char0Based-on: [email protected] ("[PATCH v10 0/7] vhost-user block device backend implementation")
Based-on: [email protected] ("[PATCH 00/29] block/export: Add infrastructure and QAPI for block exports")
Stefan Hajnoczi (13):
block/export: shorten serial string to fit util/vhost-user-server: s/fileds/fields/ typo fix util/vhost-user-server: drop unnecessary QOM cast util/vhost-user-server: drop unnecessary watch deletion block/export: consolidate request structs into VuBlockReq util/vhost-user-server: drop unused DevicePanicNotifier util/vhost-user-server: fix memory leak in vu_message_read() util/vhost-user-server: check EOF when reading payload util/vhost-user-server: rework vu_client_trip() coroutine lifecycle block/export: report flush errors
block/export: convert vhost-user-blk server to block export API util/vhost-user-server: move header to include/ util/vhost-user-server: use static library in meson.build
MAINTAINERS | 4 +-
qapi/block-export.json | 21 +-
block/export/vhost-user-blk-server.h | 23 +-
{util => include/qemu}/vhost-user-server.h | 32 +-
block/export/export.c | 8 +-
block/export/vhost-user-blk-server.c | 525 ++++++---------------
tests/qtest/vhost-user-blk-test.c | 2 +-
util/vhost-user-server.c | 334 ++++++-------
block/export/meson.build | 1 +
block/meson.build | 1 -
contrib/libvhost-user/meson.build | 1 +
meson.build | 6 +-
tests/qtest/meson.build | 2 +-
util/meson.build | 4 +-
14 files changed, 376 insertions(+), 588 deletions(-)
rename {util => include/qemu}/vhost-user-server.h (72%)Signature · 1 line
2.26.2
PATCH v2 1/13 block/export: shorten serial string to fit
The serial field is only 20 bytes long. Shorten the string so it fits.
This fixes the following compiler warning:
../block/export/vhost-user-blk-server.c:178:50: error: ‘%s’ directive output truncated writing 21 bytes into a region of size 20 [-Werror=format-truncation=]
178 | snprintf(elem->in_sg[0].iov_base, size, "%s", "vhost_user_blk_server");
| ^~ ~~~~~~~~~~~~~~~~~~~~~~~--- block/export/vhost-user-blk-server.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
block/export/vhost-user-blk-server.c +1 -1
@@ -175,7 +175,7 @@ static void coroutine_fn vu_block_virtio_process_req(void *opaque)case VIRTIO_BLK_T_GET_ID : {size_t size =MIN (iov_size (&elem->in_sg[0 ], in_num),VIRTIO_BLK_ID_BYTES ); -snprintf (elem->in_sg[0 ].iov_base, size,"%s" ,"vhost_user_blk_server" ); +snprintf (elem->in_sg[0 ].iov_base, size,"%s" ,"vhost_user_blk" ); req->in->status =VIRTIO_BLK_S_OK ; req->size = elem->in_sg[0 ].iov_len;break ;
Signature · 1 line
2.26.2
PATCH v2 2/13 util/vhost-user-server: s/fileds/fields/ typo fix
In reply to Stefan Hajnoczi--- util/vhost-user-server.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
util/vhost-user-server.c +1 -1
@@ -407,7 +407,7 @@ bool vhost_user_server_start(VuServer *server,return false; } -/* zero out unspecified fileds */ +/* zero out unspecified fields */ *server = (VuServer ) { .listener = listener, .vu_iface = vu_iface,
Signature · 1 line
2.26.2
PATCH v2 3/13 util/vhost-user-server: drop unnecessary QOM cast
In reply to Stefan HajnocziWe already have access to the value with the correct type (ioc and sioc are the same QIOChannel).
--- util/vhost-user-server.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
util/vhost-user-server.c +1 -1
@@ -337,7 +337,7 @@ static void vu_accept(QIONetListener *listener, QIOChannelSocket *sioc, server->ioc =QIO_CHANNEL (sioc);object_ref (OBJECT (server->ioc));qio_channel_attach_aio_context (server->ioc, server->ctx); -qio_channel_set_blocking (QIO_CHANNEL (server->sioc), false,NULL ); +qio_channel_set_blocking (server->ioc, false,NULL );vu_client_start (server); }
Signature · 1 line
2.26.2
PATCH v2 4/13 util/vhost-user-server: drop unnecessary watch deletion
In reply to Stefan HajnocziExplicitly deleting watches is not necessary since libvhost-user calls remove_watch() during vu_deinit(). Add an assertion to check this though.
--- util/vhost-user-server.c | 19 ++++--------------- 1 file changed, 4 insertions(+), 15 deletions(-)
util/vhost-user-server.c +4 -15
@@ -48,21 +48,6 @@ static void close_client(VuServer *server)/* When this is set vu_client_trip will stop new processing vhost-user message */ server->sioc =NULL ; -VuFdWatch *vu_fd_watch, *next; - QTAILQ_FOREACH_SAFE(vu_fd_watch, &server->vu_fd_watches, next, next) { -aio_set_fd_handler (server->ioc->ctx, vu_fd_watch->fd, true,NULL , -NULL ,NULL ,NULL ); - } - -while (!QTAILQ_EMPTY (&server->vu_fd_watches)) { - QTAILQ_FOREACH_SAFE(vu_fd_watch, &server->vu_fd_watches, next, next) { -if (!vu_fd_watch->processing) { -QTAILQ_REMOVE (&server->vu_fd_watches, vu_fd_watch, next); -g_free (vu_fd_watch); - } - } - } -while (server->processing_msg) {if (server->ioc->read_coroutine) { server->ioc->read_coroutine =NULL ;
@@ -73,6 +58,10 @@ static void close_client(VuServer *server) }vu_deinit (&server->vu_dev); + +/* vu_deinit() should have called remove_watch() */ +assert (QTAILQ_EMPTY (&server->vu_fd_watches)); +object_unref (OBJECT (sioc));object_unref (OBJECT (server->ioc)); }
Signature · 1 line
2.26.2
PATCH v2 5/13 block/export: consolidate request structs into VuBlockReq
In reply to Stefan HajnocziOnly one struct is needed per request. Drop req_data and the separate VuBlockReq instance. Instead let vu_queue_pop() allocate everything at once.
This fixes the req_data memory leak in vu_block_virtio_process_req().
--- block/export/vhost-user-blk-server.c | 68 +++++++++------------------- 1 file changed, 21 insertions(+), 47 deletions(-)
block/export/vhost-user-blk-server.c +21 -47
@@ -25,7 +25,7 @@ struct virtio_blk_inhdr { }; typedef struct VuBlockReq { - VuVirtqElement *elem; + VuVirtqElement elem; int64_t sector_num; size_t size; struct virtio_blk_inhdr *in;
@@ -39,14 +39,10 @@ static void vu_block_req_complete(VuBlockReq *req)VuDev *vu_dev = &req->server->vu_dev;/* IO size with 1 extra status byte */ -vu_queue_push (vu_dev, req->vq, req->elem, req->size +1 ); +vu_queue_push (vu_dev, req->vq, &req->elem, req->size +1 );vu_queue_notify (vu_dev, req->vq); -if (req->elem) { -free (req->elem); - } - -g_free (req); +free (req); }static VuBlockDev *get_vu_block_device_by_server (VuServer *server)
@@ -89,20 +85,12 @@ static void coroutine_fn vu_block_flush(VuBlockReq *req)blk_co_flush (backend); } -struct req_data { -VuServer *server; -VuVirtq *vq; -VuVirtqElement *elem; -}; - static void coroutine_fn vu_block_virtio_process_req(void *opaque) { -struct req_data *data = opaque; -VuServer *server = data->server; -VuVirtq *vq = data->vq; -VuVirtqElement *elem = data->elem; +VuBlockReq *req = opaque; +VuServer *server = req->server; +VuVirtqElement *elem = &req->elem;uint32_t type; -VuBlockReq *req;VuBlockDev *vdev_blk =get_vu_block_device_by_server (server);BlockBackend *backend = vdev_blk->backend;
@@ -111,18 +99,13 @@ static void coroutine_fn vu_block_virtio_process_req(void *opaque)struct iovec *out_iov = elem->out_sg;unsigned in_num = elem->in_num;unsigned out_num = elem->out_num; +/* refer to hw/block/virtio_blk.c */ if (elem->out_num <1 || elem->in_num <1 ) {error_report ("virtio-blk request missing headers" ); -free (elem); -return ; + goto err; } - req =g_new0 (VuBlockReq,1 ); - req->server = server; - req->vq = vq; - req->elem = elem; -if (unlikely (iov_to_buf (out_iov, out_num,0 , &req->out,sizeof (req->out)) !=sizeof (req->out))) {error_report ("virtio-blk request outhdr too short" );
@@ -202,36 +185,27 @@ static void coroutine_fn vu_block_virtio_process_req(void *opaque) err:free (elem); -g_free (req); -return ; }static void vu_block_process_vq (VuDev *vu_dev,int idx) { -VuServer *server; -VuVirtq *vq; -struct req_data *req_data; +VuServer *server =container_of (vu_dev, VuServer, vu_dev); +VuVirtq *vq =vu_get_queue (vu_dev, idx); - server =container_of (vu_dev, VuServer, vu_dev); -assert (server); - - vq =vu_get_queue (vu_dev, idx); -assert (vq); -VuVirtqElement *elem;while (1 ) { - elem =vu_queue_pop (vu_dev, vq,sizeof (VuVirtqElement) + -sizeof (VuBlockReq)); -if (elem) { - req_data = g_new0(struct req_data, 1); - req_data->server = server; - req_data->vq = vq; - req_data->elem = elem; -Coroutine *co =qemu_coroutine_create (vu_block_virtio_process_req, - req_data); -aio_co_enter (server->ioc->ctx, co); - }else { +VuBlockReq *req; + + req =vu_queue_pop (vu_dev, vq,sizeof (VuBlockReq)); +if (!req) {break ; } + + req->server = server; + req->vq = vq; + +Coroutine *co = +qemu_coroutine_create (vu_block_virtio_process_req, req); +qemu_coroutine_enter (co); } }
Signature · 1 line
2.26.2
PATCH v2 6/13 util/vhost-user-server: drop unused DevicePanicNotifier
In reply to Stefan HajnocziThe device panic notifier callback is not used. Drop it.
--- util/vhost-user-server.h | 3 --- block/export/vhost-user-blk-server.c | 3 +-- util/vhost-user-server.c | 6 ------ 3 files changed, 1 insertion(+), 11 deletions(-)
util/vhost-user-server.h +0 -3
@@ -29,12 +29,10 @@ typedef struct VuFdWatch { } VuFdWatch;typedef struct VuServer VuServer ; -typedef void DevicePanicNotifierFn (VuServer *server);struct VuServer {QIONetListener *listener;AioContext *ctx; -DevicePanicNotifierFn *device_panic_notifier;int max_queues;const VuDevIface *vu_iface;VuDev vu_dev;
@@ -54,7 +52,6 @@ bool vhost_user_server_start(VuServer *server, SocketAddress *unix_socket, AioContext *ctx, uint16_t max_queues, - DevicePanicNotifierFn *device_panic_notifier, const VuDevIface *vu_iface, Error **errp);
block/export/vhost-user-blk-server.c +1 -2
@@ -439,8 +439,7 @@ static void vhost_user_blk_server_start(VuBlockDev *vu_block_device, ctx =bdrv_get_aio_context (blk_bs (vu_block_device->backend));if (!vhost_user_server_start (&vu_block_device->vu_server, addr, ctx, -VHOST_USER_BLK_MAX_QUEUES , -NULL , &vu_block_iface, +VHOST_USER_BLK_MAX_QUEUES , &vu_block_iface, errp)) { goto error; }
util/vhost-user-server.c +0 -6
@@ -81,10 +81,6 @@ static void panic_cb(VuDev *vu_dev, const char *buf)close_client (server); } -if (server->device_panic_notifier) { - server->device_panic_notifier (server); - } -/* * Set the callback function for network listener so another * vhost-user client can connect to this server
@@ -385,7 +381,6 @@ bool vhost_user_server_start(VuServer *server, SocketAddress *socket_addr, AioContext *ctx, uint16_t max_queues, - DevicePanicNotifierFn *device_panic_notifier, const VuDevIface *vu_iface, Error **errp) {
@@ -402,7 +397,6 @@ bool vhost_user_server_start(VuServer *server, .vu_iface = vu_iface, .max_queues = max_queues, .ctx = ctx, - .device_panic_notifier = device_panic_notifier, };qio_net_listener_set_name (server->listener,"vhost-user-backend-listener" );
Signature · 1 line
2.26.2
PATCH v2 7/13 util/vhost-user-server: fix memory leak in vu_message_read()
In reply to Stefan Hajnoczifds[] is leaked when qio_channel_readv_full() fails.
Use vmsg->fds[] instead of keeping a local fds[] array. Then we can reuse goto fail to clean up fds. vmsg->fd_num must be zeroed before the loop to make this safe.
--- util/vhost-user-server.c | 50 ++++++++++++++++++---------------------- 1 file changed, 23 insertions(+), 27 deletions(-)
util/vhost-user-server.c +23 -27
@@ -100,21 +100,11 @@ vu_message_read(VuDev *vu_dev, int conn_fd, VhostUserMsg *vmsg) };int rc, read_bytes =0 ;Error *local_err =NULL ; -/* -* Store fds/nfds returned from qio_channel_readv_full into -* temporary variables. -* -* VhostUserMsg is a packed structure, gcc will complain about passing -* pointer to a packed structure member if we pass &VhostUserMsg.fd_num -* and &VhostUserMsg.fds directly when calling qio_channel_readv_full, -* thus two temporary variables nfds and fds are used here. -*/ -size_t nfds =0 , nfds_t =0 ;const size_t max_fds =G_N_ELEMENTS (vmsg->fds); -int *fds_t =NULL ;VuServer *server =container_of (vu_dev, VuServer, vu_dev);QIOChannel *ioc = server->ioc; + vmsg->fd_num =0 ;if (!ioc) {error_report_err (local_err); goto fail;
@@ -122,41 +112,47 @@ vu_message_read(VuDev *vu_dev, int conn_fd, VhostUserMsg *vmsg)assert (qemu_in_coroutine ());do { +size_t nfds =0 ; +int *fds =NULL ; +/* * qio_channel_readv_full may have short reads, keeping calling it * until getting VHOST_USER_HDR_SIZE or 0 bytes in total */ - rc =qio_channel_readv_full (ioc, &iov,1 , &fds_t, &nfds_t, &local_err); + rc =qio_channel_readv_full (ioc, &iov,1 , &fds, &nfds, &local_err);if (rc <0 ) {if (rc ==QIO_CHANNEL_ERR_BLOCK ) { +assert (local_err ==NULL );qio_channel_yield (ioc,G_IO_IN );continue ; }else {error_report_err (local_err); -return false; + goto fail; } } - read_bytes += rc; -if (nfds_t >0 ) { -if (nfds + nfds_t > max_fds) { + +if (nfds >0 ) { +if (vmsg->fd_num + nfds > max_fds) {error_report ("A maximum of %zu fds are allowed, " "however got %lu fds now" , - max_fds, nfds + nfds_t); + max_fds, vmsg->fd_num + nfds); +g_free (fds); goto fail; } -memcpy (vmsg->fds + nfds, fds_t, - nfds_t *sizeof (vmsg->fds[0 ])); - nfds += nfds_t; -g_free (fds_t); +memcpy (vmsg->fds + vmsg->fd_num, fds, nfds *sizeof (vmsg->fds[0 ])); + vmsg->fd_num += nfds; +g_free (fds); } -if (read_bytes ==VHOST_USER_HDR_SIZE || rc ==0 ) { -break ; + +if (rc ==0 ) {/* socket closed */ + goto fail; } - iov.iov_base = (char *)vmsg + read_bytes; - iov.iov_len =VHOST_USER_HDR_SIZE - read_bytes; - }while (true); - vmsg->fd_num = nfds; + iov.iov_base += rc; + iov.iov_len -= rc; + read_bytes += rc; + }while (read_bytes !=VHOST_USER_HDR_SIZE ); +/* qio_channel_readv_full will make socket fds blocking, unblock them */ vmsg_unblock_fds (vmsg);if (vmsg->size >sizeof (vmsg->payload)) {
Signature · 1 line
2.26.2
PATCH v2 8/13 util/vhost-user-server: check EOF when reading payload
In reply to Stefan HajnocziUnexpected EOF is an error that must be reported.
--- util/vhost-user-server.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-)
util/vhost-user-server.c +4 -2
@@ -169,8 +169,10 @@ vu_message_read(VuDev *vu_dev, int conn_fd, VhostUserMsg *vmsg) };if (vmsg->size) { rc =qio_channel_readv_all_eof (ioc, &iov_payload,1 , &local_err); -if (rc ==-1 ) { -error_report_err (local_err); +if (rc !=1 ) { +if (local_err) { +error_report_err (local_err); + } goto fail; } }
Signature · 1 line
2.26.2
PATCH v2 9/13 util/vhost-user-server: rework vu_client_trip() coroutine lifecycle
In reply to Stefan HajnocziThe vu_client_trip() coroutine is leaked during AioContext switching. It is also unsafe to destroy the vu_dev in panic_cb() since its callers still access it in some cases.
Rework the lifecycle to solve these safety issues.
--- util/vhost-user-server.h | 29 ++-- block/export/vhost-user-blk-server.c | 9 +- util/vhost-user-server.c | 245 +++++++++++++++------------ 3 files changed, 155 insertions(+), 128 deletions(-)
util/vhost-user-server.h +16 -13
@@ -19,34 +19,36 @@#include "qapi/error.h" #include "standard-headers/linux/virtio_blk.h" +/* A kick fd that we monitor on behalf of libvhost-user */ typedef struct VuFdWatch {VuDev *vu_dev;int fd;/*kick fd*/ void *pvt;vu_watch_cb cb; -bool processing;QTAILQ_ENTRY (VuFdWatch) next; }VuFdWatch ; -typedef struct VuServer VuServer ; - -struct VuServer { +/** +* VuServer: +* A vhost-user server instance with user-defined VuDevIface callbacks. +* Vhost-user device backends can be implemented using VuServer. VuDevIface +* callbacks and virtqueue kicks run in the given AioContext. +*/ +typedef struct {QIONetListener *listener; +QEMUBH *restart_listener_bh;AioContext *ctx;int max_queues;const VuDevIface *vu_iface; + +/* Protected by ctx lock */ VuDev vu_dev;QIOChannel *ioc;/* The I/O channel with the client */ QIOChannelSocket *sioc;/* The underlying data channel with the client */ -/* IOChannel for fd provided via VHOST_USER_SET_SLAVE_REQ_FD */ -QIOChannel *ioc_slave; -QIOChannelSocket *sioc_slave; -Coroutine *co_trip;/* coroutine for processing VhostUserMsg */ QTAILQ_HEAD(, VuFdWatch) vu_fd_watches; -/* restart coroutine co_trip if AIOContext is changed */ -bool aio_context_changed; -bool processing_msg; -}; + +Coroutine *co_trip;/* coroutine for processing VhostUserMsg */ +}VuServer ; bool vhost_user_server_start(VuServer *server, SocketAddress *unix_socket,
@@ -57,6 +59,7 @@ bool vhost_user_server_start(VuServer *server,void vhost_user_server_stop (VuServer *server); -void vhost_user_server_set_aio_context (VuServer *server,AioContext *ctx); +void vhost_user_server_attach_aio_context (VuServer *server,AioContext *ctx); +void vhost_user_server_detach_aio_context (VuServer *server);#endif /* VHOST_USER_SERVER_H */
block/export/vhost-user-blk-server.c +2 -7
@@ -313,18 +313,13 @@ static const VuDevIface vu_block_iface = {static void blk_aio_attached (AioContext *ctx,void *opaque) {VuBlockDev *vub_dev = opaque; -aio_context_acquire (ctx); -vhost_user_server_set_aio_context (&vub_dev->vu_server, ctx); -aio_context_release (ctx); +vhost_user_server_attach_aio_context (&vub_dev->vu_server, ctx); }static void blk_aio_detach (void *opaque) {VuBlockDev *vub_dev = opaque; -AioContext *ctx = vub_dev->vu_server.ctx; -aio_context_acquire (ctx); -vhost_user_server_set_aio_context (&vub_dev->vu_server,NULL ); -aio_context_release (ctx); +vhost_user_server_detach_aio_context (&vub_dev->vu_server); } static void
util/vhost-user-server.c +137 -108
330 lines not on this page · raw message
Signature · 1 line
2.26.2
PATCH v2 10/13 block/export: report flush errors
In reply to Stefan HajnocziPropagate the flush return value since errors are possible.
--- block/export/vhost-user-blk-server.c | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-)
block/export/vhost-user-blk-server.c +7 -4
@@ -78,11 +78,11 @@ vu_block_discard_write_zeroes(VuBlockReq *req, struct iovec *iov,return -EINVAL ; } -static void coroutine_fn vu_block_flush(VuBlockReq *req) +static int coroutine_fn vu_block_flush(VuBlockReq *req) {VuBlockDev *vdev_blk =get_vu_block_device_by_server (req->server);BlockBackend *backend = vdev_blk->backend; -blk_co_flush (backend); +return blk_co_flush (backend); } static void coroutine_fn vu_block_virtio_process_req(void *opaque)
@@ -152,8 +152,11 @@ static void coroutine_fn vu_block_virtio_process_req(void *opaque)break ; }case VIRTIO_BLK_T_FLUSH : -vu_block_flush (req); - req->in->status =VIRTIO_BLK_S_OK ; +if (vu_block_flush (req) ==0 ) { + req->in->status =VIRTIO_BLK_S_OK ; + }else { + req->in->status =VIRTIO_BLK_S_IOERR ; + }break ;case VIRTIO_BLK_T_GET_ID : { size_t size = MIN(iov_size(&elem->in_sg[0], in_num),
Signature · 1 line
2.26.2
PATCH v2 11/13 block/export: convert vhost-user-blk server to block export API
In reply to Stefan HajnocziUse the new QAPI block exports API instead of defining our own QOM objects.
This is a large change because the lifecycle of VuBlockDev needs to follow BlockExportDriver. QOM properties are replaced by QAPI options objects.
VuBlockDev is renamed VuBlkExport and contains a BlockExport field. Several fields can be dropped since BlockExport already has equivalents.
The file names and meson build integration will be adjusted in a future patch. libvhost-user should probably be built as a static library that is linked into QEMU instead of as a .c file that results in duplicate compilation.
The new command-line syntax is:
$ qemu-storage-daemon \
--blockdev file,node-name=drive0,filename=test.img \
--export vhost-user-blk,node-name=drive0,id=export0,unix-socket=/tmp/vhost-user-blk.sockNote that unix-socket is optional because we may wish to accept chardevs too in the future.
---
v2:
* Replace str unix-socket with SocketAddress addr to match NBD and support file descriptor passing
* Make addr mandatory [Markus]
* Update vhost-user-blk-test.c to use --export syntax
--- qapi/block-export.json | 21 +- block/export/vhost-user-blk-server.h | 23 +- block/export/export.c | 8 +- block/export/vhost-user-blk-server.c | 452 +++++++-------------------- tests/qtest/vhost-user-blk-test.c | 2 +- util/vhost-user-server.c | 10 +- block/export/meson.build | 1 + block/meson.build | 1 - 8 files changed, 158 insertions(+), 360 deletions(-)
qapi/block-export.json +19 -2
@@ -84,6 +84,21 @@ 'data': { '*name': 'str', '*description': 'str', '*bitmap': 'str' } } +## +# @BlockExportOptionsVhostUserBlk: +# +# A vhost-user-blk block export. +# +# @addr: The vhost-user socket on which to listen. Both 'unix' and 'fd' +# SocketAddress types are supported. Passed fds must be UNIX domain +# sockets. +# @logical-block-size: Logical block size in bytes. Defaults to 512 bytes. +# +# Since: 5.2 +## +{ 'struct': 'BlockExportOptionsVhostUserBlk', + 'data': { 'addr': 'SocketAddress', '*logical-block-size': 'size' } } + ## # @NbdServerAddOptions: #
@@ -180,11 +195,12 @@ # An enumeration of block export types # # @nbd: NBD export +# @vhost-user-blk: vhost-user-blk export (since 5.2) # # Since: 4.2 ## { 'enum': 'BlockExportType', - 'data': [ 'nbd' ] } + 'data': [ 'nbd', 'vhost-user-blk' ] } ## # @BlockExportOptions:
@@ -213,7 +229,8 @@ '*writethrough': 'bool' }, 'discriminator': 'type', 'data': { - 'nbd': 'BlockExportOptionsNbd' + 'nbd': 'BlockExportOptionsNbd', + 'vhost-user-blk': 'BlockExportOptionsVhostUserBlk' } } ##
block/export/vhost-user-blk-server.h +3 -20
@@ -10,27 +10,10 @@#ifndef VHOST_USER_BLK_SERVER_H #define VHOST_USER_BLK_SERVER_H -#include "util/vhost-user-server.h" -typedef struct VuBlockDev VuBlockDev ; -#define TYPE_VHOST_USER_BLK_SERVER "vhost-user-blk-server" -#define VHOST_USER_BLK_SERVER (obj) \ - OBJECT_CHECK(VuBlockDev, obj, TYPE_VHOST_USER_BLK_SERVER) +#include "block/export.h" -/* vhost user block device */ -struct VuBlockDev { -Object parent_obj; -char *node_name; -SocketAddress *addr; -AioContext *ctx; -VuServer vu_server; -bool running; -uint32_t blk_size; -BlockBackend *backend; -QIOChannelSocket *sioc; -QTAILQ_ENTRY (VuBlockDev) next; -struct virtio_blk_config blkcfg; -bool writable; -}; +/* For block/export/export.c */ +extern const BlockExportDriver blk_exp_vhost_user_blk;#endif /* VHOST_USER_BLK_SERVER_H */
block/export/export.c +7 -1
@@ -17,6 +17,9 @@#include "sysemu/block-backend.h" #include "block/export.h" #include "block/nbd.h" +#if CONFIG_LINUX +#include "block/export/vhost-user-blk-server.h" +#endif #include "qapi/error.h" #include "qapi/qapi-commands-block-export.h" #include "qapi/qapi-events-block-export.h"
@@ -24,6 +27,9 @@static const BlockExportDriver *blk_exp_drivers[] = { &blk_exp_nbd, +#if CONFIG_LINUX + &blk_exp_vhost_user_blk, +#endif };/* Only accessed from the main thread */
@@ -123,7 +129,7 @@ BlockExport *blk_exp_add(BlockExportOptions *export, Error **errp)assert (drv->instance_size >=sizeof (BlockExport)); exp =g_malloc0 (drv->instance_size); *exp = (BlockExport ) { - .drv = &blk_exp_nbd, + .drv = drv, .refcount =1 , .user_owned = true, .id =g_strdup (export->id),
block/export/vhost-user-blk-server.c +118 -334
640 lines not on this page · raw message
tests/qtest/vhost-user-blk-test.c +1 -1
@@ -674,7 +674,7 @@ static char *start_vhost_user_blk(GString *cmd_line, int vus_instances) img_path =drive_create ();g_string_append_printf (storage_daemon_command,"--blockdev driver=file,node-name=disk%d,filename=%s " -"--object vhost-user-blk-server,id=disk%d,unix-socket=%s," +"--export type=vhost-user-blk,id=disk%d,addr.type=unix,addr.path=%s," "node-name=disk%i,writable=on " , i, img_path, i, sock_path, i);
util/vhost-user-server.c +9 -1
@@ -408,7 +408,15 @@ bool vhost_user_server_start(VuServer *server, Error **errp) {QEMUBH *bh; -QIONetListener *listener =qio_net_listener_new (); +QIONetListener *listener; + +if (socket_addr->type !=SOCKET_ADDRESS_TYPE_UNIX && + socket_addr->type !=SOCKET_ADDRESS_TYPE_FD ) { +error_setg (errp,"Only socket address types 'unix' and 'fd' are supported" ); +return false; + } + + listener =qio_net_listener_new ();if (qio_net_listener_open_sync (listener, socket_addr,1 , errp) <0 ) {object_unref (OBJECT (listener));
block/export/meson.build +1 -0
@@ -1 +1,2 @@ block_ss.add(files('export.c')) +block_ss.add(when: 'CONFIG_LINUX', if_true: files('vhost-user-blk-server.c', '../../contrib/libvhost-user/libvhost-user.c'))
block/meson.build +0 -1
@@ -60,7 +60,6 @@ block_ss.add(when: 'CONFIG_WIN32', if_true: files('file-win32.c', 'win32-aio.c') block_ss.add(when: 'CONFIG_POSIX', if_true: [files('file-posix.c'), coref, iokit]) block_ss.add(when: 'CONFIG_LIBISCSI', if_true: files('iscsi-opts.c')) block_ss.add(when: 'CONFIG_LINUX', if_true: files('nvme.c')) -block_ss.add(when: 'CONFIG_LINUX', if_true: files('export/vhost-user-blk-server.c', '../contrib/libvhost-user/libvhost-user.c')) block_ss.add(when: 'CONFIG_REPLICATION', if_true: files('replication.c')) block_ss.add(when: 'CONFIG_SHEEPDOG', if_true: files('sheepdog.c')) block_ss.add(when: ['CONFIG_LINUX_AIO', libaio], if_true: files('linux-aio.c'))
Signature · 1 line
2.26.2
Re: [PATCH v2 11/13] block/export: convert vhost-user-blk server to block export API
Quoted 48 lines · Stefan Hajnoczi
Use the new QAPI block exports API instead of defining our own QOM objects.
This is a large change because the lifecycle of VuBlockDev needs to follow BlockExportDriver. QOM properties are replaced by QAPI options objects.
VuBlockDev is renamed VuBlkExport and contains a BlockExport field. Several fields can be dropped since BlockExport already has equivalents.
The file names and meson build integration will be adjusted in a future patch. libvhost-user should probably be built as a static library that is linked into QEMU instead of as a .c file that results in duplicate compilation.
The new command-line syntax is:
$ qemu-storage-daemon \ --blockdev file,node-name=drive0,filename=test.img \ --export vhost-user-blk,node-name=drive0,id=export0,unix-socket=/tmp/vhost-user-blk.sockNote that unix-socket is optional because we may wish to accept chardevs too in the future.
Signed-off-by Stefan Hajnoczi <[email protected]>---
v2:
* Replace str unix-socket with SocketAddress addr to match NBD and support file descriptor passing
* Make addr mandatory [Markus]
* Updatevhost-user-blk-test.cto use --export syntax--- qapi/block-export.json | 21 +- block/export/vhost-user-blk-server.h | 23 +- block/export/export.c | 8 +- block/export/vhost-user-blk-server.c | 452 +++++++-------------------- tests/qtest/vhost-user-blk-test.c | 2 +- util/vhost-user-server.c | 10 +- block/export/meson.build | 1 + block/meson.build | 1 - 8 files changed, 158 insertions(+), 360 deletions(-)qapi/block-export.json +0
-0@@ -84,6 +84,21 @@ 'data': { '*name': 'str', '*description': 'str',
qapi/block-export.json line 94
Quoted 10 lines
qapi/block-export.json +8
-0'*bitmap': 'str' } } +## +# @BlockExportOptionsVhostUserBlk: +# +# A vhost-user-blk block export. +# +# @addr: The vhost-user socket on which to listen. Both 'unix' and 'fd' +# SocketAddress types are supported. Passed fds must be UNIX domain +# sockets.
"addr.type must be 'unix' or 'fd'" is not visible in introspection. Awkward. Practical problem only if other addresses ever become available here. Is that possible?
Quoted 34 lines
qapi/block-export.json +11
-2+# @logical-block-size: Logical block size in bytes. Defaults to 512 bytes. +# +# Since: 5.2 +## +{ 'struct': 'BlockExportOptionsVhostUserBlk', + 'data': { 'addr': 'SocketAddress', '*logical-block-size': 'size' } } + ## # @NbdServerAddOptions: #@@ -180,11 +195,12 @@ # An enumeration of block export types # # @nbd: NBD export +# @vhost-user-blk: vhost-user-blk export (since 5.2) # # Since: 4.2 ## { 'enum': 'BlockExportType', - 'data': [ 'nbd' ] } + 'data': [ 'nbd', 'vhost-user-blk' ] } ## # @BlockExportOptions:@@ -213,7 +229,8 @@ '*writethrough': 'bool' }, 'discriminator': 'type', 'data': { - 'nbd': 'BlockExportOptionsNbd' + 'nbd': 'BlockExportOptionsNbd', + 'vhost-user-blk': 'BlockExportOptionsVhostUserBlk' } } ##
[...]
Re: [PATCH v2 11/13] block/export: convert vhost-user-blk server to block export API
Quoted 52 lines · Markus Armbruster
Quoted 50 lines · Stefan Hajnoczi
Use the new QAPI block exports API instead of defining our own QOM objects.
This is a large change because the lifecycle of VuBlockDev needs to follow BlockExportDriver. QOM properties are replaced by QAPI options objects.
VuBlockDev is renamed VuBlkExport and contains a BlockExport field. Several fields can be dropped since BlockExport already has equivalents.
The file names and meson build integration will be adjusted in a future patch. libvhost-user should probably be built as a static library that is linked into QEMU instead of as a .c file that results in duplicate compilation.
The new command-line syntax is:
$ qemu-storage-daemon \ --blockdev file,node-name=drive0,filename=test.img \ --export vhost-user-blk,node-name=drive0,id=export0,unix-socket=/tmp/vhost-user-blk.sockNote that unix-socket is optional because we may wish to accept chardevs too in the future.
Signed-off-by Stefan Hajnoczi <[email protected]>---
v2:
* Replace str unix-socket with SocketAddress addr to match NBD and support file descriptor passing
* Make addr mandatory [Markus]
* Updatevhost-user-blk-test.cto use --export syntax--- qapi/block-export.json | 21 +- block/export/vhost-user-blk-server.h | 23 +- block/export/export.c | 8 +- block/export/vhost-user-blk-server.c | 452 +++++++-------------------- tests/qtest/vhost-user-blk-test.c | 2 +- util/vhost-user-server.c | 10 +- block/export/meson.build | 1 + block/meson.build | 1 - 8 files changed, 158 insertions(+), 360 deletions(-)qapi/block-export.json +0
-0@@ -84,6 +84,21 @@ 'data': { '*name': 'str', '*description': 'str', '*bitmap': 'str' } }
Quoted 12 lines
qapi/block-export.json line 94
Quoted 8 lines
qapi/block-export.json +8
-0+## +# @BlockExportOptionsVhostUserBlk: +# +# A vhost-user-blk block export. +# +# @addr: The vhost-user socket on which to listen. Both 'unix' and 'fd' +# SocketAddress types are supported. Passed fds must be UNIX domain +# sockets."addr.type must be 'unix' or 'fd'" is not visible in introspection. Awkward. Practical problem only if other addresses ever become available here. Is that possible?
addr.type=fd itself has the same problem, because it is a file descriptor without type information. Therefore the QMP client cannot introspect which types of file descriptors can be passed.
Two ideas:
1. Introduce per-address family fd types (SocketAddrFdTcpInet, SocketAddrFdTcpInet6, SocketAddrFdUnix, etc) to express specific address families in the QAPI schema.
Then use per-command unions to express the address families supported by specific commands. For example, BlockExportOptionsVhostUserBlkSocketAddr would only allow SocketAddrUnix and SocketAddrFdUnix. That way new address families can be supported in the future and introspection reports.
2. Use a side-channel (query-features, I think we discussed something like this a while back) to report features that cannot be introspected.
I think the added complexity for achieving full introspection is not worth it. It becomes harder to define new QAPI commands, increases the chance of errors, and is more tedious to program for clients/servers.
Accepting any SocketAddr seems reasonable to me since vhost-user requires an address family that has file descriptor passing. Very few address families support this feature and we don't expect to add new ones often.
Stefan
Re: [PATCH v2 11/13] block/export: convert vhost-user-blk server to block export API
Quoted 66 lines · Stefan Hajnoczi
Quoted 52 lines · Markus Armbruster
Quoted 50 lines · Stefan Hajnoczi
Use the new QAPI block exports API instead of defining our own QOM objects.
This is a large change because the lifecycle of VuBlockDev needs to follow BlockExportDriver. QOM properties are replaced by QAPI options objects.
VuBlockDev is renamed VuBlkExport and contains a BlockExport field. Several fields can be dropped since BlockExport already has equivalents.
The file names and meson build integration will be adjusted in a future patch. libvhost-user should probably be built as a static library that is linked into QEMU instead of as a .c file that results in duplicate compilation.
The new command-line syntax is:
$ qemu-storage-daemon \ --blockdev file,node-name=drive0,filename=test.img \ --export vhost-user-blk,node-name=drive0,id=export0,unix-socket=/tmp/vhost-user-blk.sockNote that unix-socket is optional because we may wish to accept chardevs too in the future.
Signed-off-by Stefan Hajnoczi <[email protected]>---
v2:
* Replace str unix-socket with SocketAddress addr to match NBD and support file descriptor passing
* Make addr mandatory [Markus]
* Updatevhost-user-blk-test.cto use --export syntax--- qapi/block-export.json | 21 +- block/export/vhost-user-blk-server.h | 23 +- block/export/export.c | 8 +- block/export/vhost-user-blk-server.c | 452 +++++++-------------------- tests/qtest/vhost-user-blk-test.c | 2 +- util/vhost-user-server.c | 10 +- block/export/meson.build | 1 + block/meson.build | 1 - 8 files changed, 158 insertions(+), 360 deletions(-)qapi/block-export.json +0
-0@@ -84,6 +84,21 @@ 'data': { '*name': 'str', '*description': 'str', '*bitmap': 'str' } }Quoted 12 lines
qapi/block-export.json line 94
Quoted 8 lines
qapi/block-export.json +8
-0+## +# @BlockExportOptionsVhostUserBlk: +# +# A vhost-user-blk block export. +# +# @addr: The vhost-user socket on which to listen. Both 'unix' and 'fd' +# SocketAddress types are supported. Passed fds must be UNIX domain +# sockets."addr.type must be 'unix' or 'fd'" is not visible in introspection. Awkward. Practical problem only if other addresses ever become available here. Is that possible?
Quoted 3 lines
addr.type=fd itself has the same problem, because it is a file descriptor without type information. Therefore the QMP client cannot introspect which types of file descriptors can be passed.
Yes, but if introspection could tell us which which values of addr.type are valid, then a client should figure out the address families, as follows. Any valid value other than 'fd' corresponds to an address family. The set of values valid for addr.type therefore corresponds to a set of address families. The address families in that set are all valid with 'fd', aren't they?
Quoted 11 lines
Two ideas:
1. Introduce per-address family fd types (SocketAddrFdTcpInet, SocketAddrFdTcpInet6, SocketAddrFdUnix, etc) to express specific address families in the QAPI schema.
Then use per-command unions to express the address families supported by specific commands. For example, BlockExportOptionsVhostUserBlkSocketAddr would only allow SocketAddrUnix and SocketAddrFdUnix. That way new address families can be supported in the future and introspection reports.
Awkward. These types would have to differ structurally, or else they are indistinguishable in introspection.
Quoted 3 lines
2. Use a side-channel (query-features, I think we discussed something like this a while back) to report features that cannot be introspected.
We implemented this in the form of QAPI feature flags, visible in introspection. You could do something like
'addr': { 'type': 'SocketAddress',
'features': [ 'unix' ] }
Quoted 3 lines
I think the added complexity for achieving full introspection is not worth it. It becomes harder to define new QAPI commands, increases the chance of errors, and is more tedious to program for clients/servers.
Hence my question: is it possible that address families other than unix become available here?
When that happens, we have an introspection problem of the sort we common solve with a feature flag.
Quoted 4 lines
Accepting any SocketAddr seems reasonable to me since vhost-user requires an address family that has file descriptor passing. Very few address families support this feature and we don't expect to add new ones often.
Your answer appears to be "yes in theory, quite unlikely in practice". Correct?
Re: [PATCH v2 11/13] block/export: convert vhost-user-blk server to block export API
Quoted 72 lines · Markus Armbruster
Quoted 66 lines · Stefan Hajnoczi
Quoted 52 lines · Markus Armbruster
Quoted 50 lines · Stefan Hajnoczi
Use the new QAPI block exports API instead of defining our own QOM objects.
This is a large change because the lifecycle of VuBlockDev needs to follow BlockExportDriver. QOM properties are replaced by QAPI options objects.
VuBlockDev is renamed VuBlkExport and contains a BlockExport field. Several fields can be dropped since BlockExport already has equivalents.
The file names and meson build integration will be adjusted in a future patch. libvhost-user should probably be built as a static library that is linked into QEMU instead of as a .c file that results in duplicate compilation.
The new command-line syntax is:
$ qemu-storage-daemon \ --blockdev file,node-name=drive0,filename=test.img \ --export vhost-user-blk,node-name=drive0,id=export0,unix-socket=/tmp/vhost-user-blk.sockNote that unix-socket is optional because we may wish to accept chardevs too in the future.
Signed-off-by Stefan Hajnoczi <[email protected]>---
v2:
* Replace str unix-socket with SocketAddress addr to match NBD and support file descriptor passing
* Make addr mandatory [Markus]
* Updatevhost-user-blk-test.cto use --export syntax--- qapi/block-export.json | 21 +- block/export/vhost-user-blk-server.h | 23 +- block/export/export.c | 8 +- block/export/vhost-user-blk-server.c | 452 +++++++-------------------- tests/qtest/vhost-user-blk-test.c | 2 +- util/vhost-user-server.c | 10 +- block/export/meson.build | 1 + block/meson.build | 1 - 8 files changed, 158 insertions(+), 360 deletions(-)qapi/block-export.json +0
-0@@ -84,6 +84,21 @@ 'data': { '*name': 'str', '*description': 'str', '*bitmap': 'str' } }Quoted 12 lines
qapi/block-export.json line 94
Quoted 8 lines
qapi/block-export.json +8
-0+## +# @BlockExportOptionsVhostUserBlk: +# +# A vhost-user-blk block export. +# +# @addr: The vhost-user socket on which to listen. Both 'unix' and 'fd' +# SocketAddress types are supported. Passed fds must be UNIX domain +# sockets."addr.type must be 'unix' or 'fd'" is not visible in introspection. Awkward. Practical problem only if other addresses ever become available here. Is that possible?
Quoted 3 lines
addr.type=fd itself has the same problem, because it is a file descriptor without type information. Therefore the QMP client cannot introspect which types of file descriptors can be passed.
Quoted 6 lines
Yes, but if introspection could tell us which which values of addr.type are valid, then a client should figure out the address families, as follows. Any valid value other than 'fd' corresponds to an address family. The set of values valid for addr.type therefore corresponds to a set of address families. The address families in that set are all valid with 'fd', aren't they?
Yes, in this case the address families in addr.type are the ones also supported by addr.type=fd.
Quoted 19 lines
Quoted 11 lines
Two ideas:
1. Introduce per-address family fd types (SocketAddrFdTcpInet, SocketAddrFdTcpInet6, SocketAddrFdUnix, etc) to express specific address families in the QAPI schema.
Then use per-command unions to express the address families supported by specific commands. For example, BlockExportOptionsVhostUserBlkSocketAddr would only allow SocketAddrUnix and SocketAddrFdUnix. That way new address families can be supported in the future and introspection reports.
Awkward. These types would have to differ structurally, or else they are indistinguishable in introspection.
Quoted 3 lines
2. Use a side-channel (query-features, I think we discussed something like this a while back) to report features that cannot be introspected.
Quoted 5 lines
We implemented this in the form of QAPI feature flags, visible in introspection. You could do something like
'addr': { 'type': 'SocketAddress',
'features': [ 'unix' ] }
That is nice.
Quoted 11 lines
Quoted 4 lines
I think the added complexity for achieving full introspection is not worth it. It becomes harder to define new QAPI commands, increases the chance of errors, and is more tedious to program for clients/servers.
Hence my question: is it possible that address families other than unix become available here?
When that happens, we have an introspection problem of the sort we common solve with a feature flag.
Quoted 7 lines
Quoted 4 lines
Accepting any SocketAddr seems reasonable to me since vhost-user requires an address family that has file descriptor passing. Very few address families support this feature and we don't expect to add new ones often.
Your answer appears to be "yes in theory, quite unlikely in practice". Correct?
Yes.
Stefan
Markus Armbruster
Acked-byRe: [PATCH v2 11/13] block/export: convert vhost-user-blk server to block export API
Quoted 102 lines · Stefan Hajnoczi
Quoted 72 lines · Markus Armbruster
Quoted 66 lines · Stefan Hajnoczi
Quoted 52 lines · Markus Armbruster
Quoted 50 lines · Stefan Hajnoczi
Use the new QAPI block exports API instead of defining our own QOM objects.
This is a large change because the lifecycle of VuBlockDev needs to follow BlockExportDriver. QOM properties are replaced by QAPI options objects.
VuBlockDev is renamed VuBlkExport and contains a BlockExport field. Several fields can be dropped since BlockExport already has equivalents.
The file names and meson build integration will be adjusted in a future patch. libvhost-user should probably be built as a static library that is linked into QEMU instead of as a .c file that results in duplicate compilation.
The new command-line syntax is:
$ qemu-storage-daemon \ --blockdev file,node-name=drive0,filename=test.img \ --export vhost-user-blk,node-name=drive0,id=export0,unix-socket=/tmp/vhost-user-blk.sockNote that unix-socket is optional because we may wish to accept chardevs too in the future.
Signed-off-by Stefan Hajnoczi <[email protected]>---
v2:
* Replace str unix-socket with SocketAddress addr to match NBD and support file descriptor passing
* Make addr mandatory [Markus]
* Updatevhost-user-blk-test.cto use --export syntax--- qapi/block-export.json | 21 +- block/export/vhost-user-blk-server.h | 23 +- block/export/export.c | 8 +- block/export/vhost-user-blk-server.c | 452 +++++++-------------------- tests/qtest/vhost-user-blk-test.c | 2 +- util/vhost-user-server.c | 10 +- block/export/meson.build | 1 + block/meson.build | 1 - 8 files changed, 158 insertions(+), 360 deletions(-)qapi/block-export.json +0
-0@@ -84,6 +84,21 @@ 'data': { '*name': 'str', '*description': 'str', '*bitmap': 'str' } }Quoted 12 lines
qapi/block-export.json line 94
Quoted 8 lines
qapi/block-export.json +8
-0+## +# @BlockExportOptionsVhostUserBlk: +# +# A vhost-user-blk block export. +# +# @addr: The vhost-user socket on which to listen. Both 'unix' and 'fd' +# SocketAddress types are supported. Passed fds must be UNIX domain +# sockets."addr.type must be 'unix' or 'fd'" is not visible in introspection. Awkward. Practical problem only if other addresses ever become available here. Is that possible?
Quoted 3 lines
addr.type=fd itself has the same problem, because it is a file descriptor without type information. Therefore the QMP client cannot introspect which types of file descriptors can be passed.
Quoted 6 lines
Yes, but if introspection could tell us which which values of addr.type are valid, then a client should figure out the address families, as follows. Any valid value other than 'fd' corresponds to an address family. The set of values valid for addr.type therefore corresponds to a set of address families. The address families in that set are all valid with 'fd', aren't they?
Yes, in this case the address families in addr.type are the ones also supported by addr.type=fd.
Quoted 19 lines
Quoted 11 lines
Two ideas:
1. Introduce per-address family fd types (SocketAddrFdTcpInet, SocketAddrFdTcpInet6, SocketAddrFdUnix, etc) to express specific address families in the QAPI schema.
Then use per-command unions to express the address families supported by specific commands. For example, BlockExportOptionsVhostUserBlkSocketAddr would only allow SocketAddrUnix and SocketAddrFdUnix. That way new address families can be supported in the future and introspection reports.
Awkward. These types would have to differ structurally, or else they are indistinguishable in introspection.
Quoted 3 lines
2. Use a side-channel (query-features, I think we discussed something like this a while back) to report features that cannot be introspected.
Quoted 26 lines
Quoted 5 lines
We implemented this in the form of QAPI feature flags, visible in introspection. You could do something like
'addr': { 'type': 'SocketAddress',
'features': [ 'unix' ] }That is nice.
Quoted 18 lines
Quoted 4 lines
I think the added complexity for achieving full introspection is not worth it. It becomes harder to define new QAPI commands, increases the chance of errors, and is more tedious to program for clients/servers.
Hence my question: is it possible that address families other than unix become available here?
When that happens, we have an introspection problem of the sort we common solve with a feature flag.
Quoted 4 lines
Accepting any SocketAddr seems reasonable to me since vhost-user requires an address family that has file descriptor passing. Very few address families support this feature and we don't expect to add new ones often.
Your answer appears to be "yes in theory, quite unlikely in practice". Correct?
Keeping introspection "tight" would be nice, but since a real need for "tight" here seems quite unlikely, it doesn't seem to be worth the trouble.
Perhaps this argument could be worked into the commit message. Up to you.
Re: [PATCH v2 11/13] block/export: convert vhost-user-blk server to block export API
Quoted 19 lines · Markus Armbruster
Quoted 10 lines · Stefan Hajnoczi
Quoted 9 lines · Markus Armbruster
Quoted 2 lines · Stefan Hajnoczi
Quoted 1 line · Markus Armbruster
Stefan Hajnoczi <[email protected]> writes:
Hence my question: is it possible that address families other than unix become available here?
When that happens, we have an introspection problem of the sort we common solve with a feature flag.
Quoted 7 lines
Quoted 7 lines
Quoted 4 lines
Accepting any SocketAddr seems reasonable to me since vhost-user requires an address family that has file descriptor passing. Very few address families support this feature and we don't expect to add new ones often.
Your answer appears to be "yes in theory, quite unlikely in practice". Correct?
Quoted 8 lines
Keeping introspection "tight" would be nice, but since a real need for "tight" here seems quite unlikely, it doesn't seem to be worth the trouble.
Perhaps this argument could be worked into the commit message. Up to you.
Thanks, I will update the commit message when merging.
PATCH v2 12/13 util/vhost-user-server: move header to include/
In reply to Stefan HajnocziHeaders used by other subsystems are located in include/. Also add the vhost-user-server and vhost-user-blk-server headers to MAINTAINERS.
---
MAINTAINERS | 4 +++-
{util => include/qemu}/vhost-user-server.h | 0
block/export/vhost-user-blk-server.c | 2 +-
util/vhost-user-server.c | 2 +-
4 files changed, 5 insertions(+), 3 deletions(-)
rename {util => include/qemu}/vhost-user-server.h (100%)MAINTAINERS +3 -1
@@ -3043,9 +3043,11 @@ Vhost-user block device backend server M: Coiby Xu <[email protected]> S: Maintained F: block/export/vhost-user-blk-server.c -F: util/vhost-user-server.c +F: block/export/vhost-user-blk-server.h +F: include/qemu/vhost-user-server.h F: tests/qtest/vhost-user-blk-test.c F: tests/qtest/libqos/vhost-user-blk.c +F: util/vhost-user-server.c Replication M: Wen Congyang <[email protected]>
include/qemu/vhost-user-server.h renamed from util/vhost-user-server.h +0 -0
block/export/vhost-user-blk-server.c +1 -1
@@ -13,7 +13,7 @@#include "block/block.h" #include "contrib/libvhost-user/libvhost-user.h" #include "standard-headers/linux/virtio_blk.h" -#include "util/vhost-user-server.h" +#include "qemu/vhost-user-server.h" #include "vhost-user-blk-server.h" #include "qapi/error.h" #include "qom/object_interfaces.h"
util/vhost-user-server.c +1 -1
@@ -9,8 +9,8 @@*/ #include "qemu/osdep.h" #include "qemu/main-loop.h" +#include "qemu/vhost-user-server.h" #include "block/aio-wait.h" -#include "vhost-user-server.h" /* * Theory of operation:
Signature · 1 line
2.26.2
PATCH v2 13/13 util/vhost-user-server: use static library in meson.build
In reply to Stefan HajnocziDon't compile contrib/libvhost-user/libvhost-user.c again. Instead build the static library once and then reuse it throughout QEMU.
Also switch from CONFIG_LINUX to CONFIG_VHOST_USER, which is what the vhost-user tools (vhost-user-gpu, etc) do.
--- block/export/export.c | 8 ++++---- block/export/meson.build | 2 +- contrib/libvhost-user/meson.build | 1 + meson.build | 6 +++++- tests/qtest/meson.build | 2 +- util/meson.build | 4 +++- 6 files changed, 15 insertions(+), 8 deletions(-)
block/export/export.c +4 -4
@@ -17,17 +17,17 @@#include "sysemu/block-backend.h" #include "block/export.h" #include "block/nbd.h" -#if CONFIG_LINUX -#include "block/export/vhost-user-blk-server.h" -#endif #include "qapi/error.h" #include "qapi/qapi-commands-block-export.h" #include "qapi/qapi-events-block-export.h" #include "qemu/id.h" +#ifdef CONFIG_VHOST_USER +#include "vhost-user-blk-server.h" +#endif static const BlockExportDriver *blk_exp_drivers[] = { &blk_exp_nbd, -#if CONFIG_LINUX +#ifdef CONFIG_VHOST_USER &blk_exp_vhost_user_blk, #endif };
block/export/meson.build +1 -1
@@ -1,2 +1,2 @@ block_ss.add(files('export.c')) -block_ss.add(when: 'CONFIG_LINUX', if_true: files('vhost-user-blk-server.c', '../../contrib/libvhost-user/libvhost-user.c')) +block_ss.add(when: 'CONFIG_VHOST_USER', if_true: files('vhost-user-blk-server.c'))
contrib/libvhost-user/meson.build +1 -0
@@ -1,3 +1,4 @@ libvhost_user = static_library('vhost-user', files('libvhost-user.c', 'libvhost-user-glib.c'), build_by_default: false) +vhost_user = declare_dependency(link_with: libvhost_user)
meson.build +5 -1
@@ -788,6 +788,11 @@ trace_events_subdirs += [ 'util', ] +vhost_user = not_found +if 'CONFIG_VHOST_USER' in config_host + subdir('contrib/libvhost-user') +endif + subdir('qapi') subdir('qobject') subdir('stubs')
@@ -1169,7 +1174,6 @@ if have_tools install: true) if 'CONFIG_VHOST_USER' in config_host - subdir('contrib/libvhost-user') subdir('contrib/vhost-user-blk') subdir('contrib/vhost-user-gpu') subdir('contrib/vhost-user-input')
tests/qtest/meson.build +1 -1
@@ -191,7 +191,7 @@ qos_test_ss.add( ) qos_test_ss.add(when: 'CONFIG_VIRTFS', if_true: files('virtio-9p-test.c')) qos_test_ss.add(when: 'CONFIG_VHOST_USER', if_true: files('vhost-user-test.c')) -qos_test_ss.add(when: 'CONFIG_LINUX', if_true: files('vhost-user-blk-test.c')) +qos_test_ss.add(when: 'CONFIG_VHOST_USER', if_true: files('vhost-user-blk-test.c')) extra_qtest_deps = { 'bios-tables-test': [io],
util/meson.build +3 -1
@@ -66,7 +66,9 @@ if have_block util_ss.add(files('main-loop.c')) util_ss.add(files('nvdimm-utils.c')) util_ss.add(files('qemu-coroutine.c', 'qemu-coroutine-lock.c', 'qemu-coroutine-io.c')) - util_ss.add(when: 'CONFIG_LINUX', if_true: files('vhost-user-server.c')) + util_ss.add(when: 'CONFIG_VHOST_USER', if_true: [ + files('vhost-user-server.c'), vhost_user + ]) util_ss.add(files('block-helpers.c')) util_ss.add(files('qemu-coroutine-sleep.c')) util_ss.add(files('qemu-co-shared-resource.c'))
Signature · 1 line
2.26.2
Stefan Hajnoczi
AppliedQuoted 51 lines · Stefan Hajnoczi
v2:
* Replace unix-socket=str with addr=SocketAddress for consistency with NBD and fd passing support. The new syntax is:
--export vhost-user-blk,addr.type=unix,addr.path=/tmp/vhost-user-blk.sock,...
* Make addr=SocketAddress mandatory instead of optional [Markus]
* Updatetest-vhost-user-blk.cto use new syntax
* Add patch movingvhost-user-server.htoinclude/
* Add patch to use libvhost-user.a instead of compiling it multiple timesThis patch series converts Coiby Xu's vhost-user-blk-server from a QOM object to the block exports API. The block exports API provides a standard QMP and command-line interface for managing block exports (NBD, FUSE, vhost-user-blk, etc). A fair amount of init/shutdown code is removed because the block exports API already takes care of that functionality.
Most of the patches are vhost-user-blk-server cleanups.
The syntax for launching qemu-storage-daemon is:
$ qemu-storage-daemon \ --blockdev file,node-name=drive0,filename=test.img \ --export vhost-user-blk,node-name=drive0,id=export0,writable=on,addr.type=unix,addr.path=/tmp/vhost-user-blk.sockQEMU can connect to the vhost-user-blk export like this:
$ qemu-system-x86_64 \ -M accel=kvm,memory-backend=mem \ -m 1G \ -object memory-backend-memfd,size=1G,id=mem \ -cpu host \ -chardev socket,path=/tmp/vhost-user-blk.sock,id=char0 \ -device vhost-user-blk-pci,chardev=char0Based-on: [email protected] ("[PATCH v10 0/7] vhost-user block device backend implementation")
Based-on: [email protected] ("[PATCH 00/29] block/export: Add infrastructure and QAPI for block exports")Stefan Hajnoczi (13):
block/export: shorten serial string to fit util/vhost-user-server: s/fileds/fields/ typo fix util/vhost-user-server: drop unnecessary QOM cast util/vhost-user-server: drop unnecessary watch deletion block/export: consolidate request structs into VuBlockReq util/vhost-user-server: drop unused DevicePanicNotifier util/vhost-user-server: fix memory leak invu_message_read()util/vhost-user-server: check EOF when reading payload util/vhost-user-server: reworkvu_client_trip()coroutine lifecycle block/export: report flush errors
block/export: convert vhost-user-blk server to block export API util/vhost-user-server: move header toinclude/util/vhost-user-server: use static library in meson.build
Quoted 20 lines
MAINTAINERS | 4 +- qapi/block-export.json | 21 +- block/export/vhost-user-blk-server.h | 23 +- {util => include/qemu}/vhost-user-server.h | 32 +- block/export/export.c | 8 +- block/export/vhost-user-blk-server.c | 525 ++++++--------------- tests/qtest/vhost-user-blk-test.c | 2 +- util/vhost-user-server.c | 334 ++++++------- block/export/meson.build | 1 + block/meson.build | 1 - contrib/libvhost-user/meson.build | 1 + meson.build | 6 +- tests/qtest/meson.build | 2 +- util/meson.build | 4 +- 14 files changed, 376 insertions(+), 588 deletions(-) rename {util => include/qemu}/vhost-user-server.h (72%)Signature · 1 line
2.26.2
Thanks, applied to my block tree with a mention of the QAPI schema situation regarding address families as suggested by Markus:
https://github.com/stefanha/qemu/commits/block
Stefan