Start a contrib/libvhost-user
cover Start a contrib/libvhost-user
From: Marc-André Lureau <[email protected]>
Hi
vhost-user & virtio are not so simple and evolve regularly. There isn't a reference code that would help you get started either. And backends duplicate most of the effort.
Furthermore, due to usage of ancillary data, shared memory, eventfd, atomics, it is not so simple to implement in other languages than C either (even rust still lacks socket ancillary data support). Having a library doing the low-level parts could eventually help to reach other languages (this guided some decisions, such as being able to override message handling)
I found it would help me to experiment with new usages of libvhost-user (with other devices than network for example) if qemu would provide such "reference" library. vhost-user-bridge was the most complete attempt in qemu, but it lacked some abstraction and efficient handling of the virt queues.
I propose to provide such library based on virtio.c implementation and vhost-user-bridge socket handling. My hope is that at some point the library would be complete and stable enough that it could become a standalone project, but for now it makes more sense to propose it in qemu/contrib.
Comments welcome!
Marc-André Lureau (6):
vubr: remove false comment
vubr: remove unnecessary dispatcher_remove
vubr: indicate peer disconnected
vubr: do not accept more than one connection
contrib: add libvhost-user
test/vubr: use contrib/libvhost-user
Makefile.objs | 1 + contrib/libvhost-user/Makefile.objs | 1 + contrib/libvhost-user/libvhost-user.c | 1401 +++++++++++++++++++++++++++++++++ contrib/libvhost-user/libvhost-user.h | 264 +++++++ tests/Makefile | 2 +- tests/vhost-user-bridge.c | 1173 ++++++--------------------- 6 files changed, 1891 insertions(+), 951 deletions(-) create mode 100644 contrib/libvhost-user/Makefile.objs create mode 100644 contrib/libvhost-user/libvhost-user.c create mode 100644 contrib/libvhost-user/libvhost-user.h
Signature · 1 line
2.5.5
RFC 1/6 vubr: remove false comment
From: Marc-André Lureau <[email protected]>
dispatcher_remove() is in use.
--- tests/vhost-user-bridge.c | 2 -- 1 file changed, 2 deletions(-)
tests/vhost-user-bridge.c +0 -2
@@ -104,8 +104,6 @@ dispatcher_add(Dispatcher *dispr, int sock, void *ctx, CallbackFunc cb)return 0 ; } -/* dispatcher_remove() is not currently in use but may be useful -* in the future. */ static int dispatcher_remove (Dispatcher *dispr,int sock) {
Signature · 1 line
2.5.5
RFC 2/6 vubr: remove unnecessary dispatcher_remove
In reply to [email protected]From: Marc-André Lureau <[email protected]>
The call fd is not watched
--- tests/vhost-user-bridge.c | 2 -- 1 file changed, 2 deletions(-)
tests/vhost-user-bridge.c +0 -2
@@ -975,7 +975,6 @@ vubr_get_vring_base_exec(VubrDev *dev, VhostUserMsg *vmsg)if (dev->vq[index].call_fd !=-1 ) {close (dev->vq[index].call_fd); -dispatcher_remove (&dev->dispatcher, dev->vq[index].call_fd); dev->vq[index].call_fd =-1 ; }if (dev->vq[index].kick_fd !=-1 ) {
@@ -1039,7 +1038,6 @@ vubr_set_vring_call_exec(VubrDev *dev, VhostUserMsg *vmsg)if (dev->vq[index].call_fd !=-1 ) {close (dev->vq[index].call_fd); -dispatcher_remove (&dev->dispatcher, dev->vq[index].call_fd); } dev->vq[index].call_fd = vmsg->fds[0 ];DPRINT ("Got call_fd: %d for vq: %d\n" , vmsg->fds[0 ], index);
Signature · 1 line
2.5.5
RFC 3/6 vubr: indicate peer disconnected
In reply to [email protected]From: Marc-André Lureau <[email protected]>
--- tests/vhost-user-bridge.c | 1 - 1 file changed, 1 deletion(-)
tests/vhost-user-bridge.c +0 -1
@@ -388,7 +388,6 @@ vubr_message_read(int conn_fd, VhostUserMsg *vmsg) rc =recvmsg (conn_fd, &msg,0 );if (rc ==0 ) { -vubr_die ("recvmsg" );fprintf (stderr,"Peer disconnected.\n" );exit (1 ); }
Signature · 1 line
2.5.5
RFC 4/6 vubr: do not accept more than one connection
In reply to [email protected]From: Marc-André Lureau <[email protected]>
--- tests/vhost-user-bridge.c | 1 + 1 file changed, 1 insertion(+)
tests/vhost-user-bridge.c +1 -0
@@ -1196,6 +1196,7 @@ vubr_accept_cb(int sock, void *ctx) }DPRINT ("Got connection from remote peer on sock %d\n" , conn_fd);dispatcher_add (&dev->dispatcher, conn_fd, ctx, vubr_receive_cb); +dispatcher_remove (&dev->dispatcher, sock); } static VubrDev *
Signature · 1 line
2.5.5
RFC 5/6 contrib: add libvhost-user
In reply to [email protected]From: Marc-André Lureau <[email protected]>
Add a library to help implementing vhost-user backend (or slave).
Dealing with vhost-user as an application developper isn't so easy: you have all the trouble with any protocol: validation, unix ancillary data, shared memory, eventfd, logging, and on top of that you need to deal with virtio queues, if possible efficiently.
qemu test has a nice vhost-user testing application vhost-user-bridge, which implements most of vhost-user, and virtio.c which implements virtqueues manipulation. Based on these two, I tried to make a simple library, reusable for tests or development of new vhost-user scenarios.
--- Makefile.objs | 1 + contrib/libvhost-user/Makefile.objs | 1 + contrib/libvhost-user/libvhost-user.c | 1401 +++++++++++++++++++++++++++++++++ contrib/libvhost-user/libvhost-user.h | 264 +++++++ 4 files changed, 1667 insertions(+) create mode 100644 contrib/libvhost-user/Makefile.objs create mode 100644 contrib/libvhost-user/libvhost-user.c create mode 100644 contrib/libvhost-user/libvhost-user.h
Makefile.objs +1 -0
@@ -116,3 +116,4 @@ qga-vss-dll-obj-y = qga/ # contrib ivshmem-client-obj-y = contrib/ivshmem-client/ ivshmem-server-obj-y = contrib/ivshmem-server/ +libvhost-user-obj-y = contrib/libvhost-user/
contrib/libvhost-user/Makefile.objs new file +1 -0
@@ -0,0 +1 @@ +ivshmem-server-obj-y = ivshmem-server.o main.o
contrib/libvhost-user/libvhost-user.c new file +1401 -0
1,401 lines not on this page · raw message
contrib/libvhost-user/libvhost-user.h new file +264 -0
264 lines not on this page · raw message
Signature · 1 line
2.5.5
RFC 6/6 test/vubr: use contrib/libvhost-user
In reply to [email protected]From: Marc-André Lureau <[email protected]>
Use the libvhost-user library.
This ended up being a rather large patch that cannot be easily splitted, due to massive code move and API changes.
--- tests/Makefile | 2 +- tests/vhost-user-bridge.c | 1167 +++++++++------------------------------------ 2 files changed, 223 insertions(+), 946 deletions(-)
tests/Makefile +1 -1
@@ -585,7 +585,7 @@ tests/test-netfilter$(EXESUF): tests/test-netfilter.o $(qtest-obj-y) tests/test-filter-mirror$(EXESUF): tests/test-filter-mirror.o $(qtest-obj-y) tests/test-filter-redirector$(EXESUF): tests/test-filter-redirector.o $(qtest-obj-y) tests/ivshmem-test$(EXESUF): tests/ivshmem-test.o contrib/ivshmem-server/ivshmem-server.o $(libqos-pc-obj-y) -tests/vhost-user-bridge$(EXESUF): tests/vhost-user-bridge.o +tests/vhost-user-bridge$(EXESUF): tests/vhost-user-bridge.o contrib/libvhost-user/libvhost-user.o $(test-util-obj-y) ifeq ($(CONFIG_POSIX),y) LIBS += -lutil
tests/vhost-user-bridge.c +222 -945
1,330 lines not on this page · raw message
Signature · 1 line
2.5.5