Introduce vhost-user-scsi and sample application
v3 cover Introduce vhost-user-scsi and sample application
Based on various discussions on the 2016 KVM Forum, I'm sending over a vhost-user-scsi implementation for your consideration.
This patchset introduces a new vhost-user SCSI device. While heavily based on vhost-scsi, it is implemented using vhost's userspace counterpart. The device has been coded and tested to work with live migration.
As part of this work, a new vhost-scsi-common device was created and the existing vhost-scsi device moved underneath it. The new vhost-user-scsi device is also placed underneath it.
A sample application based on the newly introduced libvhost-user is also included. It makes use of libiscsi for simplicity.
For convenience, I'm maintaining an up-to-date version of these patches (including some necessary fixes for libvhost-user) on:
https://github.com/franciozzy/qemu/tree/vus-upstream-3
See the individual patches for build and use instructions.
v2 -> v3:
- Rebase after vhost notifier fixes by Paolo.
- Exposed F_HOTPLUG and F_CHANGE on vhost-user-scsi.
v1 -> v2:
- Introduce new vhost-scsi-common device type.
- Move vhost-scsi device underneath vhost-scsi-common.
- Move sample application from tests/ to contrib/.
- Make sample application use the glib event loop.
- Minor fixes.
Felipe Franciosi (3):
vhost-scsi: create a vhost-scsi-common abstraction
vus: Introduce vhost-user-scsi host device
vus: Introduce a vhost-user-scsi sample application
Makefile | 3 + Makefile.objs | 4 + configure | 11 + contrib/vhost-user-scsi/Makefile.objs | 1 + contrib/vhost-user-scsi/vhost-user-scsi.c | 886 ++++++++++++++++++++++++++++++ hw/scsi/Makefile.objs | 3 +- hw/scsi/vhost-scsi-common.c | 143 +++++ hw/scsi/vhost-scsi.c | 188 ++----- hw/scsi/vhost-user-scsi.c | 215 ++++++++ hw/virtio/virtio-pci.c | 58 ++ hw/virtio/virtio-pci.h | 15 + include/hw/virtio/vhost-scsi-common.h | 48 ++ include/hw/virtio/vhost-scsi.h | 11 +- include/hw/virtio/vhost-user-scsi.h | 35 ++ include/hw/virtio/virtio-scsi.h | 7 + 15 files changed, 1483 insertions(+), 145 deletions(-) create mode 100644 contrib/vhost-user-scsi/Makefile.objs create mode 100644 contrib/vhost-user-scsi/vhost-user-scsi.c create mode 100644 hw/scsi/vhost-scsi-common.c create mode 100644 hw/scsi/vhost-user-scsi.c create mode 100644 include/hw/virtio/vhost-scsi-common.h create mode 100644 include/hw/virtio/vhost-user-scsi.h
Signature · 1 line
1.9.4
PATCH v3 1/3 vhost-scsi: create a vhost-scsi-common abstraction
In order to introduce a new vhost-user-scsi host device type, it makes sense to abstract part of vhost-scsi into a common parent class. This commit does exactly that.
--- hw/scsi/Makefile.objs | 2 +- hw/scsi/vhost-scsi-common.c | 143 ++++++++++++++++++++++++++ hw/scsi/vhost-scsi.c | 188 ++++++++++------------------------ include/hw/virtio/vhost-scsi-common.h | 48 +++++++++ include/hw/virtio/vhost-scsi.h | 11 +- include/hw/virtio/virtio-scsi.h | 2 + 6 files changed, 249 insertions(+), 145 deletions(-) create mode 100644 hw/scsi/vhost-scsi-common.c create mode 100644 include/hw/virtio/vhost-scsi-common.h
hw/scsi/Makefile.objs +1 -1
@@ -10,5 +10,5 @@ obj-$(CONFIG_PSERIES) += spapr_vscsi.o ifeq ($(CONFIG_VIRTIO),y) obj-y += virtio-scsi.o virtio-scsi-dataplane.o -obj-$(CONFIG_VHOST_SCSI) += vhost-scsi.o +obj-$(CONFIG_VHOST_SCSI) += vhost-scsi-common.o vhost-scsi.o endif
hw/scsi/vhost-scsi-common.c new file +143 -0
143 lines not on this page · raw message
hw/scsi/vhost-scsi.c +53 -135
303 lines not on this page · raw message
include/hw/virtio/vhost-scsi-common.h new file +48 -0
48 lines not on this page · raw message
include/hw/virtio/vhost-scsi.h +2 -9
@@ -18,6 +18,7 @@#include "hw/qdev.h" #include "hw/virtio/virtio-scsi.h" #include "hw/virtio/vhost.h" +#include "hw/virtio/vhost-scsi-common.h" enum vhost_scsi_vq_list {VHOST_SCSI_VQ_CONTROL =0 ,
@@ -30,15 +31,7 @@ enum vhost_scsi_vq_list { OBJECT_CHECK(VHostSCSI, (obj), TYPE_VHOST_SCSI)typedef struct VHostSCSI { -VirtIOSCSICommon parent_obj; - -Error *migration_blocker; - -struct vhost_dev dev; -int32_t bootindex; -int channel; -int target; -int lun; +VHostSCSICommon parent_obj; }VHostSCSI ;#endif
include/hw/virtio/virtio-scsi.h +2 -0
@@ -49,8 +49,10 @@ struct VirtIOSCSIConf {uint32_t num_queues;uint32_t max_sectors;uint32_t cmd_per_lun; +#ifdef CONFIG_VHOST_SCSI char *vhostfd;char *wwpn; +#endif uint32_t boot_tpgt;IOThread *iothread; };
Signature · 1 line
1.9.4
PATCH v3 2/3 vus: Introduce vhost-user-scsi host device
In reply to Felipe FranciosiThis commit introduces a vhost-user device for SCSI. This is based on the existing vhost-scsi implementation, but done over vhost-user instead. It also uses a chardev to connect to the backend. Unlike vhost-scsi (today), VMs using vhost-user-scsi can be live migrated.
To use it, one must configure Qemu with --enable-vhost-user-scsi and start Qemu with a command line equivalent to:
qemu-system-x86_64 \
-chardev socket,id=vus0,path=/tmp/vus.sock \
-device vhost-user-scsi-pci,chardev=vus0,bus=pci.0,addr=...A separate commit presents a sample application linked with libiscsi to provide a backend for vhost-user-scsi.
--- configure | 10 ++ hw/scsi/Makefile.objs | 1 + hw/scsi/vhost-user-scsi.c | 215 ++++++++++++++++++++++++++++++++++++ hw/virtio/virtio-pci.c | 58 ++++++++++ hw/virtio/virtio-pci.h | 15 +++ include/hw/virtio/vhost-user-scsi.h | 35 ++++++ include/hw/virtio/virtio-scsi.h | 5 + 7 files changed, 339 insertions(+) create mode 100644 hw/scsi/vhost-user-scsi.c create mode 100644 include/hw/virtio/vhost-user-scsi.h
configure +10 -0
@@ -228,6 +228,7 @@ xfs="" vhost_net="no" vhost_scsi="no" +vhost_user_scsi="no" vhost_vsock="no" kvm="no" colo="yes"
@@ -680,6 +681,7 @@ Haiku) kvm="yes" vhost_net="yes" vhost_scsi="yes" + vhost_user_scsi="yes" vhost_vsock="yes" QEMU_INCLUDES="-I\$(SRC_PATH)/linux-headers -I$(pwd)/linux-headers $QEMU_INCLUDES" ;;
@@ -1026,6 +1028,10 @@ for opt do ;; --enable-vhost-scsi) vhost_scsi="yes" ;; + --disable-vhost-user-scsi) vhost_user_scsi="no" + ;; + --enable-vhost-user-scsi) vhost_user_scsi="yes" + ;; --disable-vhost-vsock) vhost_vsock="no" ;; --enable-vhost-vsock) vhost_vsock="yes"
@@ -5061,6 +5067,7 @@ echo "posix_madvise $posix_madvise" echo "libcap-ng support $cap_ng" echo "vhost-net support $vhost_net" echo "vhost-scsi support $vhost_scsi" +echo "vhost-user-scsi support $vhost_user_scsi" echo "vhost-vsock support $vhost_vsock" echo "Trace backends $trace_backends" if have_backend "simple"; then
@@ -5446,6 +5453,9 @@ fi if test "$vhost_scsi" = "yes" ; then echo "CONFIG_VHOST_SCSI=y" >> $config_host_mak fi +if test "$vhost_user_scsi" = "yes" ; then + echo "CONFIG_VHOST_USER_SCSI=y" >> $config_host_mak +fi if test "$vhost_net" = "yes" ; then echo "CONFIG_VHOST_NET_USED=y" >> $config_host_mak fi
hw/scsi/Makefile.objs +1 -0
@@ -11,4 +11,5 @@ obj-$(CONFIG_PSERIES) += spapr_vscsi.o ifeq ($(CONFIG_VIRTIO),y) obj-y += virtio-scsi.o virtio-scsi-dataplane.o obj-$(CONFIG_VHOST_SCSI) += vhost-scsi-common.o vhost-scsi.o +obj-$(CONFIG_VHOST_USER_SCSI) += vhost-scsi-common.o vhost-user-scsi.o endif
hw/scsi/vhost-user-scsi.c new file +215 -0
215 lines not on this page · raw message
hw/virtio/virtio-pci.c +58 -0
70 lines not on this page · raw message
hw/virtio/virtio-pci.h +15 -0
@@ -33,6 +33,9 @@#ifdef CONFIG_VHOST_SCSI #include "hw/virtio/vhost-scsi.h" #endif +#ifdef CONFIG_VHOST_USER_SCSI +#include "hw/virtio/vhost-user-scsi.h" +#endif #ifdef CONFIG_VHOST_VSOCK #include "hw/virtio/vhost-vsock.h" #endif
@@ -44,6 +47,7 @@ typedef struct VirtIOBalloonPCI VirtIOBalloonPCI;typedef struct VirtIOSerialPCI VirtIOSerialPCI ;typedef struct VirtIONetPCI VirtIONetPCI ;typedef struct VHostSCSIPCI VHostSCSIPCI ; +typedef struct VHostUserSCSIPCI VHostUserSCSIPCI ;typedef struct VirtIORngPCI VirtIORngPCI ;typedef struct VirtIOInputPCI VirtIOInputPCI ;typedef struct VirtIOInputHIDPCI VirtIOInputHIDPCI ;
@@ -214,6 +218,17 @@ struct VHostSCSIPCI { };#endif +#ifdef CONFIG_VHOST_USER_SCSI +#define TYPE_VHOST_USER_SCSI_PCI "vhost-user-scsi-pci" +#define VHOST_USER_SCSI_PCI (obj) \ + OBJECT_CHECK(VHostUserSCSIPCI, (obj), TYPE_VHOST_USER_SCSI_PCI) + +struct VHostUserSCSIPCI { +VirtIOPCIProxy parent_obj; +VHostUserSCSI vdev; +}; +#endif +/* * virtio-blk-pci: This extends VirtioPCIProxy. */
include/hw/virtio/vhost-user-scsi.h new file +35 -0
@@ -0,0 +1,35 @@ +/* +* vhost-user-scsi host device +* +* Copyright (c) 2016 Nutanix Inc. All rights reserved. +* +* Author: +* Felipe Franciosi <[email protected]> +* +* This file is largely based on "vhost-scsi.h" by: +* Stefan Hajnoczi <[email protected]> +* +* This work is licensed under the terms of the GNU LGPL, version 2 or later. +* See the COPYING.LIB file in the top-level directory. +* +*/ + +#ifndef VHOST_USER_SCSI_H +#define VHOST_USER_SCSI_H + +#include "qemu-common.h" +#include "hw/qdev.h" +#include "hw/virtio/virtio-scsi.h" +#include "hw/virtio/vhost.h" +#include "hw/virtio/vhost-scsi-common.h" + +#define TYPE_VHOST_USER_SCSI "vhost-user-scsi" +#define VHOST_USER_SCSI (obj) \ + OBJECT_CHECK(VHostUserSCSI, (obj), TYPE_VHOST_USER_SCSI) + +typedef struct VHostUserSCSI { +VHostSCSICommon parent_obj; +uint64_t host_features; +}VHostUserSCSI ; + +#endif /* VHOST_USER_SCSI_H */
include/hw/virtio/virtio-scsi.h +5 -0
@@ -21,6 +21,7 @@#include "hw/virtio/virtio.h" #include "hw/pci/pci.h" #include "hw/scsi/scsi.h" +#include "sysemu/char.h" #include "sysemu/iothread.h" #define TYPE_VIRTIO_SCSI_COMMON "virtio-scsi-common"
@@ -53,6 +54,10 @@ struct VirtIOSCSIConf {char *vhostfd;char *wwpn;#endif +#ifdef CONFIG_VHOST_USER_SCSI +CharBackend chardev; +int32_t bootindex; +#endif uint32_t boot_tpgt;IOThread *iothread; };
Signature · 1 line
1.9.4
Re: [Qemu-devel] [PATCH v3 2/3] vus: Introduce vhost-user-scsi host device
Quoted 9 lines · Felipe Franciosi
To use it, one must configure Qemu with --enable-vhost-user-scsi and start Qemu with a command line equivalent to:
qemu-system-x86_64 \ -chardev socket,id=vus0,path=/tmp/vus.sock \ -device vhost-user-scsi-pci,chardev=vus0,bus=pci.0,addr=...A separate commit presents a sample application linked with libiscsi to provide a backend for vhost-user-scsi.
Please place CONFIG_VHOST_USER_SCSI=$(CONFIG_POSIX) symbol in default-configs/ (so that it is enabled by default on non-Windows hosts) instead of having the configure option. Otherwise, the patches look good!
Paolo
Re: [Qemu-devel] [PATCH v3 2/3] vus: Introduce vhost-user-scsi host device
Quoted 13 lines · Paolo Bonzini
Quoted 7 lines · Felipe Franciosi
To use it, one must configure Qemu with --enable-vhost-user-scsi and start Qemu with a command line equivalent to:
qemu-system-x86_64 \ -chardev socket,id=vus0,path=/tmp/vus.sock \ -device vhost-user-scsi-pci,chardev=vus0,bus=pci.0,addr=...
Quoted 6 lines
Quoted 2 lines
A separate commit presents a sample application linked with libiscsi to provide a backend for vhost-user-scsi.
Please place
CONFIG_VHOST_USER_SCSI=$(CONFIG_POSIX)symbol in default-configs/ (so that it is enabled by default on non-Windows hosts) instead of having the configure option. Otherwise, the patches look good!
Thanks, will do that and send a v4.
Do you want any entries on MAINTAINERS for this code or are you happy to take care of it under hw/scsi/* ?
Felipe
Quoted 2 lines
Paolo
Re: [Qemu-devel] [PATCH v3 2/3] vus: Introduce vhost-user-scsi host device
Quoted 16 lines · Felipe Franciosi
Quoted 16 lines · Paolo Bonzini
Quoted 9 lines · Felipe Franciosi
To use it, one must configure Qemu with --enable-vhost-user-scsi and start Qemu with a command line equivalent to:
qemu-system-x86_64 \ -chardev socket,id=vus0,path=/tmp/vus.sock \ -device vhost-user-scsi-pci,chardev=vus0,bus=pci.0,addr=...A separate commit presents a sample application linked with libiscsi to provide a backend for vhost-user-scsi.
Quoted 7 lines
Quoted 3 lines
Please place
CONFIG_VHOST_USER_SCSI=$(CONFIG_POSIX)symbol in default-configs/ (so that it is enabled by default on non-Windows hosts) instead of having the configure option. Otherwise, the patches look good!Thanks, will do that and send a v4.
Do you want any entries on
MAINTAINERSfor this code or are you happy to take care of it under hw/scsi/* ?
It's okay to have it under hw/scsi/*.
Paolo
Re: [Qemu-devel] [PATCH v3 2/3] vus: Introduce vhost-user-scsi host device
In reply to Paolo BonziniHi Paolo,
Thanks again for the review.
Just to clarify:
Quoted 12 lines · Paolo Bonzini
Quoted 7 lines · Felipe Franciosi
To use it, one must configure Qemu with --enable-vhost-user-scsi and start Qemu with a command line equivalent to:
qemu-system-x86_64 \ -chardev socket,id=vus0,path=/tmp/vus.sock \ -device vhost-user-scsi-pci,chardev=vus0,bus=pci.0,addr=...
Quoted 6 lines
Quoted 2 lines
A separate commit presents a sample application linked with libiscsi to provide a backend for vhost-user-scsi.
Please place
CONFIG_VHOST_USER_SCSI=$(CONFIG_POSIX)symbol in default-configs/ (so that it is enabled by default on non-Windows hosts) instead of having the configure option. Otherwise, the patches look good!
Which architectures would you like me to add this to? How about putting it in "pci.mak"?
And when you say "instead", do you mean on top of? I imagine having a --disable switch is at least desirable, so I'd rather not remove the commands from 'configure'.
Cheers,
Felipe
Quoted 2 lines
Paolo
Re: [Qemu-devel] [PATCH v3 2/3] vus: Introduce vhost-user-scsi host device
Quoted 5 lines · Felipe Franciosi
Quoted 3 lines
Please place
CONFIG_VHOST_USER_SCSI=$(CONFIG_POSIX)symbol in default-configs/ (so that it is enabled by default on non-Windows hosts) instead of having the configure option. Otherwise, the patches look good!Which architectures would you like me to add this to? How about putting it in "pci.mak"?
I think it should be in every configuration that includes virtio-scsi.
Quoted 1 line
And when you say "instead", do you mean on top of? I imagine having a --disable switch is at least desirable, so I'd rather not remove the commands from 'configure'.
No, I really meant "instead". Even though the default-configs/ mechanisms is not very user-friendly, having two ways to do configuration is messy. Generally --disable is left for features that require a third-party library.
Paolo
PATCH v3 3/3 vus: Introduce a vhost-user-scsi sample application
In reply to Felipe FranciosiThis commit introduces a vhost-user-scsi backend sample application. It must be linked with libiscsi and libvhost-user.
To use it, compile with:
make vhost-user-scsi
And run as follows:
./vhost-user-scsi -u /tmp/vus.sock -i iscsi://uri_to_target/
The application is currently limited at one LUN only and it processes requests synchronously (therefore only achieving QD1). The purpose of the code is to show how a backend can be implemented and to test the vhost-user-scsi Qemu implementation.
If a different instance of this vhost-user-scsi application is executed at a remote host, a VM can be live migrated to such a host.
--- Makefile | 3 + Makefile.objs | 4 + configure | 1 + contrib/vhost-user-scsi/Makefile.objs | 1 + contrib/vhost-user-scsi/vhost-user-scsi.c | 886 ++++++++++++++++++++++++++++++ 5 files changed, 895 insertions(+) create mode 100644 contrib/vhost-user-scsi/Makefile.objs create mode 100644 contrib/vhost-user-scsi/vhost-user-scsi.c
Makefile +3 -0
@@ -150,6 +150,7 @@ dummy := $(call unnest-vars,, \ ivshmem-client-obj-y \ ivshmem-server-obj-y \ libvhost-user-obj-y \ + vhost-user-scsi-obj-y \ qga-vss-dll-obj-y \ block-obj-y \ block-obj-m \
@@ -348,6 +349,8 @@ ivshmem-client$(EXESUF): $(ivshmem-client-obj-y) libqemuutil.a libqemustub.a $(call LINK, $^) ivshmem-server$(EXESUF): $(ivshmem-server-obj-y) libqemuutil.a libqemustub.a $(call LINK, $^) +vhost-user-scsi$(EXESUF): $(vhost-user-scsi-obj-y) + $(call LINK, $^) module_block.h: $(SRC_PATH)/scripts/modules/module_block.py config-host.mak $(call quiet-command,$(PYTHON) $< $@ \
Makefile.objs +4 -0
@@ -117,6 +117,10 @@ qga-vss-dll-obj-y = qga/ ivshmem-client-obj-y = contrib/ivshmem-client/ ivshmem-server-obj-y = contrib/ivshmem-server/ libvhost-user-obj-y = contrib/libvhost-user/ +vhost-user-scsi.o-cflags := $(LIBISCSI_CFLAGS) +vhost-user-scsi.o-libs := $(LIBISCSI_LIBS) +vhost-user-scsi-obj-y = contrib/vhost-user-scsi/ +vhost-user-scsi-obj-y += contrib/libvhost-user/libvhost-user.o ###################################################################### trace-events-y = trace-events
configure +1 -0
@@ -4804,6 +4804,7 @@ if test "$want_tools" = "yes" ; then if [ "$linux" = "yes" -o "$bsd" = "yes" -o "$solaris" = "yes" ] ; then tools="qemu-nbd\$(EXESUF) $tools" tools="ivshmem-client\$(EXESUF) ivshmem-server\$(EXESUF) $tools" + tools="vhost-user-scsi\$(EXESUF) $tools" fi fi if test "$softmmu" = yes ; then
contrib/vhost-user-scsi/Makefile.objs new file +1 -0
@@ -0,0 +1 @@ +vhost-user-scsi-obj-y = vhost-user-scsi.o
contrib/vhost-user-scsi/vhost-user-scsi.c new file +886 -0
886 lines not on this page · raw message
Signature · 1 line
1.9.4
Quoted 15 lines · Felipe Franciosi
Based on various discussions on the 2016 KVM Forum, I'm sending over a vhost-user-scsi implementation for your consideration.
This patchset introduces a new vhost-user SCSI device. While heavily based on vhost-scsi, it is implemented using vhost's userspace counterpart. The device has been coded and tested to work with live migration.
As part of this work, a new vhost-scsi-common device was created and the existing vhost-scsi device moved underneath it. The new vhost-user-scsi device is also placed underneath it.
Quoted 7 lines
A sample application based on the newly introduced libvhost-user is also included. It makes use of libiscsi for simplicity.
For convenience, I'm maintaining an up-to-date version of these patches (including some necessary fixes for libvhost-user) on:
My apologies. The correct URL is:
https://github.com/franciozzy/qemu/tree/vus-upstream-v3
(note the -v3 instead of -3).
Thanks,
Felipe
Quoted 47 lines
See the individual patches for build and use instructions.
Signed-off-by Felipe Franciosi <[email protected]>v2 -> v3:
- Rebase after vhost notifier fixes by Paolo.
- ExposedF_HOTPLUGandF_CHANGEon vhost-user-scsi.v1 -> v2:
- Introduce new vhost-scsi-common device type.
- Move vhost-scsi device underneath vhost-scsi-common.
- Move sample application from tests/ to contrib/.
- Make sample application use the glib event loop.
- Minor fixes.Felipe Franciosi (3):
vhost-scsi: create a vhost-scsi-common abstraction
vus: Introduce vhost-user-scsi host device
vus: Introduce a vhost-user-scsi sample applicationMakefile | 3 + Makefile.objs | 4 + configure | 11 + contrib/vhost-user-scsi/Makefile.objs | 1 + contrib/vhost-user-scsi/vhost-user-scsi.c | 886 ++++++++++++++++++++++++++++++ hw/scsi/Makefile.objs | 3 +- hw/scsi/vhost-scsi-common.c | 143 +++++ hw/scsi/vhost-scsi.c | 188 ++----- hw/scsi/vhost-user-scsi.c | 215 ++++++++ hw/virtio/virtio-pci.c | 58 ++ hw/virtio/virtio-pci.h | 15 + include/hw/virtio/vhost-scsi-common.h | 48 ++ include/hw/virtio/vhost-scsi.h | 11 +- include/hw/virtio/vhost-user-scsi.h | 35 ++ include/hw/virtio/virtio-scsi.h | 7 + 15 files changed, 1483 insertions(+), 145 deletions(-)create mode 100644 contrib/vhost-user-scsi/Makefile.objs create mode 100644
contrib/vhost-user-scsi/vhost-user-scsi.ccreate mode 100644hw/scsi/vhost-scsi-common.ccreate mode 100644hw/scsi/vhost-user-scsi.ccreate mode 100644include/hw/virtio/vhost-scsi-common.hcreate mode 100644include/hw/virtio/vhost-user-scsi.hSignature · 1 line
1.9.4