Skip to contentSkip to conversation

block/vxhs.c: Add support for a new block device type called "vxhs"

PATCH Applied Ashish Mittal 4 participants 12 messages Apr 4, 2017 – Apr 20, 2017 Block layer

lore
Share & tools
lore
#0 lore raw

v11 cover block/vxhs.c: Add support for a new block device type called "vxhs"

- Veritas HyperScale block driver in QEMU is designed to provide an accelerated IO path from KVM virtual machines to Veritas HyperScale storage service.

- A network IO transfer library that translates block IO from HyperScale block driver to a network IO format to send it to Veritas HyperScale storage service. This library (libvxhs) has been open sourced and is available on github here: https://github.com/VeritasHyperScale/libqnio.git

Ashish Mittal (2):
block/vxhs.c: Add support for a new block device type called "vxhs" block/vxhs.c: Add qemu-iotests for new block device type "vxhs"

 block/Makefile.objs              |   2 +
 block/trace-events               |  17 ++
 block/vxhs.c                     | 575 +++++++++++++++++++++++++++++++++++++++
 configure                        |  39 +++
 qapi/block-core.json             |  23 +-
 tests/qemu-iotests/common        |   6 +
 tests/qemu-iotests/common.config |  13 +
 tests/qemu-iotests/common.filter |   1 +
 tests/qemu-iotests/common.rc     |  19 ++
 9 files changed, 693 insertions(+), 2 deletions(-)
 create mode 100644 block/vxhs.c
Signature · 1 line
2.5.5
#1 lore raw

PATCH v11 1/2 block/vxhs.c: Add support for a new block device type called "vxhs"

Source code for the qnio library that this code loads can be downloaded from:
https://github.com/VeritasHyperScale/libqnio.git

Sample command line using JSON syntax:
./x86_64-softmmu/qemu-system-x86_64 -name instance-00000008 -S -vnc 0.0.0.0:0 -k en-us -vga cirrus -device virtio-balloon-pci,id=balloon0,bus=pci.0,addr=0x5 -msg timestamp=on 'json:{"driver":"vxhs","vdisk-id":"c3e9095a-a5ee-4dce-afeb-2a59fb387410", "server":{"host":"172.172.17.4","port":"9999"}}'

Sample command line using URI syntax:
qemu-img convert -f raw -O raw -n /var/lib/nova/instances/_base/0c5eacd5ebea5ed914b6a3e7b18f1ce734c386ad vxhs://192.168.0.1:9999/c6718f6b-0401-441d-a8c3-1f0064d75ee0

Sample command line using TLS credentials (run in secure mode):
./qemu-io --object tls-creds-x509,id=tls0,dir=/etc/pki/qemu/vxhs,endpoint=client -c 'read -v 66000 2.5k' 'json:{"server.host": "127.0.0.1", "server.port": "9999", "vdisk-id": "/test.raw", "driver": "vxhs", "tls-creds":"tls0"}'

---
v11 changelog:
(1) Replaced InetSocketAddress with InetSocketAddressBase.
(2) Removed access to qemu_uuid.
(3) Removed unnecessary g_strdup()/g_free().
(4) Removed unused acb->qiov.
(5) Changed vxhs_init_and_ref() and vxhs_unref() per suggestion.
(6) Removed unnecessary initializations from local variables.

v10 changelog:
(1) Implemented accepting TLS creds per block device via the CLI (see 3rd e.g in commit log). Corresponding changes made to the libqnio library.
(2) iio_open() changed to accept TLS creds and use these internally to set up SSL connections.
(3) Got rid of hard-coded VXHS_UUID_DEF. qemu_uuid is no longer used for authentication in any way.
(4) Removed unnecessary qdict_del(backing_options, str).
(5) Added '*tls-creds' to BlockdevOptionsVxHS.

v9 changelog:
(1) Fixes for all the review comments from v8. I have left the definition of VXHS_UUID_DEF unchanged pending a better suggestion.
(2) qcow2 tests now pass on the vxhs test server.
(3) Packaging changes for libvxhs will be checked in to the git repo soon.
(4) I have not moved extern QemuUUID qemu_uuid to a separate header file.

v8 changelog:
(1) Security implementation for libqnio present in branch 'securify'. Please use 'securify' branch for building libqnio and testing with this patch.
(2) Renamed libqnio to libvxhs.
(3) Pass instance ID to libvxhs for SSL authentication.

v7 changelog:
(1) IO failover code has moved out to the libqnio library.
(2) Fixes for issues reported by Stefan on v6.
(3) Incorporated the QEMUBH patch provided by Stefan. This is a replacement for the pipe mechanism used earlier.
(4) Fixes to the buffer overflows reported in libqnio.
(5) Input validations in vxhs.c to prevent any buffer overflows for arguments passed to libqnio.

v6 changelog:
(1) Added qemu-iotests for VxHS as a new patch in the series.
(2) Replaced release version from 2.8 to 2.9 in block-core.json.

v5 changelog:
(1) Incorporated v4 review comments.

v4 changelog:
(1) Incorporated v3 review comments on QAPI changes.
(2) Added refcounting for device open/close. Free library resources on last device close.

v3 changelog:
(1) Added QAPI schema for the VxHS driver.

v2 changelog:
(1) Changes done in response to v1 comments.

 block/Makefile.objs  |   2 +
 block/trace-events   |  17 ++
 block/vxhs.c         | 575 +++++++++++++++++++++++++++++++++++++++++++++++++++
 configure            |  39 ++++
 qapi/block-core.json |  23 ++-
 5 files changed, 654 insertions(+), 2 deletions(-)
 create mode 100644 block/vxhs.c
block/Makefile.objs +2 -0
index de96f8e..ea95530 100644
@@ -19,6 +19,7 @@ block-obj-$(CONFIG_LIBNFS) += nfs.o
 block-obj-$(CONFIG_CURL) += curl.o
 block-obj-$(CONFIG_RBD) += rbd.o
 block-obj-$(CONFIG_GLUSTERFS) += gluster.o
+block-obj-$(CONFIG_VXHS) += vxhs.o
 block-obj-$(CONFIG_LIBSSH2) += ssh.o
 block-obj-y += accounting.o dirty-bitmap.o
 block-obj-y += write-threshold.o
@@ -38,6 +39,7 @@ rbd.o-cflags       := $(RBD_CFLAGS)
 rbd.o-libs         := $(RBD_LIBS)
 gluster.o-cflags   := $(GLUSTERFS_CFLAGS)
 gluster.o-libs     := $(GLUSTERFS_LIBS)
+vxhs.o-libs        := $(VXHS_LIBS)
 ssh.o-cflags       := $(LIBSSH2_CFLAGS)
 ssh.o-libs         := $(LIBSSH2_LIBS)
 block-obj-$(if $(CONFIG_BZIP2),m,n) += dmg-bz2.o
block/trace-events +17 -0
index 0bc5c0a..7758ec3 100644
@@ -110,3 +110,20 @@ qed_aio_write_data(void *s, void *acb, int ret, uint64_t offset, size_t len) "s
 qed_aio_write_prefill(void *s, void *acb, uint64_t start, size_t len, uint64_t offset) "s %p acb %p start %"PRIu64" len %zu offset %"PRIu64
 qed_aio_write_postfill(void *s, void *acb, uint64_t start, size_t len, uint64_t offset) "s %p acb %p start %"PRIu64" len %zu offset %"PRIu64
 qed_aio_write_main(void *s, void *acb, int ret, uint64_t offset, size_t len) "s %p acb %p ret %d offset %"PRIu64" len %zu"
+
+# block/vxhs.c
+vxhs_iio_callback(int error) "ctx is NULL: error %d"
+vxhs_iio_callback_chnfail(int err, int error) "QNIO channel failed, no i/o %d, %d"
+vxhs_iio_callback_unknwn(int opcode, int err) "unexpected opcode %d, errno %d"
+vxhs_aio_rw_invalid(int req) "Invalid I/O request iodir %d"
+vxhs_aio_rw_ioerr(char *guid, int iodir, uint64_t size, uint64_t off, void *acb, int ret, int err) "IO ERROR (vDisk %s) FOR : Read/Write = %d size = %lu offset = %lu ACB = %p. Error = %d, errno = %d"
+vxhs_get_vdisk_stat_err(char *guid, int ret, int err) "vDisk (%s) stat ioctl failed, ret = %d, errno = %d"
+vxhs_get_vdisk_stat(char *vdisk_guid, uint64_t vdisk_size) "vDisk %s stat ioctl returned size %lu"
+vxhs_complete_aio(void *acb, uint64_t ret) "aio failed acb %p ret %ld"
+vxhs_parse_uri_filename(const char *filename) "URI passed via bdrv_parse_filename %s"
+vxhs_open_vdiskid(const char *vdisk_id) "Opening vdisk-id %s"
+vxhs_open_hostinfo(char *of_vsa_addr, int port) "Adding host %s:%d to BDRVVXHSState"
+vxhs_open_iio_open(const char *host) "Failed to connect to storage agent on host %s"
+vxhs_parse_uri_hostinfo(char *host, int port) "Host: IP %s, Port %d"
+vxhs_close(char *vdisk_guid) "Closing vdisk %s"
+vxhs_get_creds(const char *cacert, const char *client_key, const char *client_cert) "cacert %s, client_key %s, client_cert %s"
block/vxhs.c new file +575 -0

575 lines not on this page · raw message

configure +39 -0
index 4b3b5cd..94f0818 100755
@@ -320,6 +320,7 @@ numa=""
 tcmalloc="no"
 jemalloc="no"
 replication="yes"
+vxhs=""
 
 supported_cpu="no"
 supported_os="no"
@@ -1183,6 +1184,10 @@ for opt do
   ;;
   --enable-replication) replication="yes"
   ;;
+  --disable-vxhs) vxhs="no"
+  ;;
+  --enable-vxhs) vxhs="yes"
+  ;;
   *)
       echo "ERROR: unknown option $opt"
       echo "Try '$0 --help' for more information"
@@ -1427,6 +1432,7 @@ disabled with --disable-FEATURE, default is enabled if available:
   xfsctl          xfsctl support
   qom-cast-debug  cast debugging support
   tools           build qemu-io, qemu-nbd and qemu-image tools
+  vxhs            Veritas HyperScale vDisk backend support
 
 NOTE: The object files are built at the place where configure is launched
 EOF
@@ -4777,6 +4783,33 @@ if compile_prog "" "" ; then
 fi
 
 ##########################################
+# Veritas HyperScale block driver VxHS
+# Check if libvxhs is installed
+
+if test "$vxhs" != "no" ; then
+  cat > $TMPC <<EOF
+#include <stdint.h>
+#include <qnio/qnio_api.h>
+
+void *vxhs_callback;
+
+int main(void) {
+    iio_init(QNIO_VERSION, vxhs_callback);
+    return 0;
+}
+EOF
+  vxhs_libs="-lvxhs -lssl"
+  if compile_prog "" "$vxhs_libs" ; then
+    vxhs=yes
+  else
+    if test "$vxhs" = "yes" ; then
+      feature_not_found "vxhs block device" "Install libvxhs See github"
+    fi
+    vxhs=no
+  fi
+fi
+
+##########################################
 # End of CC checks
 # After here, no more $cc or $ld runs
 
@@ -5142,6 +5175,7 @@ echo "tcmalloc support  $tcmalloc"
 echo "jemalloc support  $jemalloc"
 echo "avx2 optimization $avx2_opt"
 echo "replication support $replication"
+echo "VxHS block device $vxhs"
 
 if test "$sdl_too_old" = "yes"; then
 echo "-> Your SDL version is too old - please upgrade to have SDL support"
@@ -5781,6 +5815,11 @@ if test "$pthread_setname_np" = "yes" ; then
   echo "CONFIG_PTHREAD_SETNAME_NP=y" >> $config_host_mak
 fi
 
+if test "$vxhs" = "yes" ; then
+  echo "CONFIG_VXHS=y" >> $config_host_mak
+  echo "VXHS_LIBS=$vxhs_libs" >> $config_host_mak
+fi
+
 if test "$tcg_interpreter" = "yes"; then
   QEMU_INCLUDES="-I\$(SRC_PATH)/tcg/tci $QEMU_INCLUDES"
 elif test "$ARCH" = "sparc64" ; then
qapi/block-core.json +21 -2
index 033457c..87fb747 100644
@@ -2108,6 +2108,8 @@
 #
 # Drivers that are supported in block device operations.
 #
+# @vxhs: Since 2.10
+#
 # Since: 2.9
 ##
 { 'enum': 'BlockdevDriver',
@@ -2116,7 +2118,7 @@
             'host_device', 'http', 'https', 'iscsi', 'luks', 'nbd', 'nfs',
             'null-aio', 'null-co', 'parallels', 'qcow', 'qcow2', 'qed',
             'quorum', 'raw', 'rbd', 'replication', 'sheepdog', 'ssh',
-            'vdi', 'vhdx', 'vmdk', 'vpc', 'vvfat' ] }
+            'vdi', 'vhdx', 'vmdk', 'vpc', 'vvfat', 'vxhs' ] }
 
 ##
 # @BlockdevOptionsFile:
@@ -2866,6 +2868,22 @@
   'data': { '*offset': 'int', '*size': 'int' } }
 
 ##
+# @BlockdevOptionsVxHS:
+#
+# Driver specific block device options for VxHS
+#
+# @vdisk-id:    UUID of VxHS volume
+# @server:      vxhs server IP, port
+# @tls-creds:   TLS credentials ID
+#
+# Since: 2.10
+##
+{ 'struct': 'BlockdevOptionsVxHS',
+  'data': { 'vdisk-id': 'str',
+            'server': 'InetSocketAddressBase',
+            '*tls-creds': 'str' } }
+
+##
 # @BlockdevOptions:
 #
 # Options for creating a block device.  Many options are available for all
@@ -2927,7 +2945,8 @@
       'vhdx':       'BlockdevOptionsGenericFormat',
       'vmdk':       'BlockdevOptionsGenericCOWFormat',
       'vpc':        'BlockdevOptionsGenericFormat',
-      'vvfat':      'BlockdevOptionsVVFAT'
+      'vvfat':      'BlockdevOptionsVVFAT',
+      'vxhs':       'BlockdevOptionsVxHS'
   } }
 
 ##
Signature · 1 line
2.5.5
Reviewed-by on v11 1/2
#2 lore raw
Quoted 15 lines · Ashish Mittal

Source code for the qnio library that this code loads can be downloaded from:
https://github.com/VeritasHyperScale/libqnio.git

Sample command line using JSON syntax:
./x86_64-softmmu/qemu-system-x86_64 -name instance-00000008 -S -vnc 0.0.0.0:0

(quoted diff) +0 -2
-k en-us -vga cirrus -device virtio-balloon-pci,id=balloon0,bus=pci.0,addr=0x5
-msg timestamp=on

'json:{"driver":"vxhs","vdisk-id":"c3e9095a-a5ee-4dce-afeb-2a59fb387410", "server":{"host":"172.172.17.4","port":"9999"}}'

Sample command line using URI syntax:
qemu-img convert -f raw -O raw -n /var/lib/nova/instances/_base/0c5eacd5ebea5ed914b6a3e7b18f1ce734c386ad vxhs://192.168.0.1:9999/c6718f6b-0401-441d-a8c3-1f0064d75ee0

Quoted 7 lines

Sample command line using TLS credentials (run in secure mode):
./qemu-io --object tls-creds-x509,id=tls0,dir=/etc/pki/qemu/vxhs,endpoint=client -c 'read -v 66000 2.5k' 'json:{"server.host": "127.0.0.1", "server.port": "9999", "vdisk-id": "/test.raw", "driver": "vxhs", "tls-creds":"tls0"}'

I've not reviewed the i/o related stuff, but from the POV of TLS cred handling / QAPI / disk open, this all looks fine to me now.

Regards,
Daniel

Signature · 3 lines
|: http://berrange.com      -o-    http://www.flickr.com/photos/dberrange/ :|
|: http://libvirt.org              -o-             http://virt-manager.org :|
|: http://entangle-photo.org       -o-    http://search.cpan.org/~danberr/ :|
#3 lore raw
In reply to Ashish Mittal
Quoted 15 lines · Ashish Mittal

Source code for the qnio library that this code loads can be downloaded from:
https://github.com/VeritasHyperScale/libqnio.git

Sample command line using JSON syntax:
./x86_64-softmmu/qemu-system-x86_64 -name instance-00000008 -S -vnc 0.0.0.0:0

(quoted diff) +0 -2
-k en-us -vga cirrus -device virtio-balloon-pci,id=balloon0,bus=pci.0,addr=0x5
-msg timestamp=on

'json:{"driver":"vxhs","vdisk-id":"c3e9095a-a5ee-4dce-afeb-2a59fb387410", "server":{"host":"172.172.17.4","port":"9999"}}'

Sample command line using URI syntax:
qemu-img convert -f raw -O raw -n /var/lib/nova/instances/_base/0c5eacd5ebea5ed914b6a3e7b18f1ce734c386ad vxhs://192.168.0.1:9999/c6718f6b-0401-441d-a8c3-1f0064d75ee0

Quoted 7 lines

Sample command line using TLS credentials (run in secure mode):
./qemu-io --object tls-creds-x509,id=tls0,dir=/etc/pki/qemu/vxhs,endpoint=client -c 'read -v 66000 2.5k' 'json:{"server.host": "127.0.0.1", "server.port": "9999", "vdisk-id": "/test.raw", "driver": "vxhs", "tls-creds":"tls0"}'

I was testing this some with blockdev-add and blockdev-del, and this sequence causes a segfault:

1. blockdev-add vxhs image
2. blockdev-del above image
3. blockdev-add vxhs image <--- segfaults

Looking at it in gdb, this is an issue with libqnio. The call to iio_fini() is not sufficiently thorough in cleaning up resources.

In nio_client.c, qnc_ctx is never freed, because there does not seem to be a call such as 'qnc_driver_fini' that cleans up the allocated qnio_client_ctx.

Therefore, on the second call to iio_init, the libqnio internal variable network_driver is NULL, because qnc_driver_init() returns NULL if it is called when qnc_ctx is still initialized:

lib/qnio/nio_client.c:

411 int
412 iio_init(int32_t version, iio_cb_t cb)
413 {

[...]

432     apictx->network_driver = qnc_secure_driver_init(client_callback);
433     nioDbg("Created API context.\n");
434     return 0;

435 }

[...]

779 struct channel_driver *
780 qnc_driver_init(qnio_notify client_notify)
781 {
782 if (qnc_ctx) {
783 nioDbg("Driver already initialized");
784 return NULL;
785 }
786

So two issues:

A. iio_init() should check the returned pointer, and fail if NULL

B. iio_fini() needs to clean everything up so that a new vxhs connection is
possible. This likely means at least one new function in nio_client.c to clean up qnc_ctx.

-Jeff

#4 lore raw
Quoted 71 lines · Jeff Cody
Quoted 15 lines · Ashish Mittal

Source code for the qnio library that this code loads can be downloaded from:
https://github.com/VeritasHyperScale/libqnio.git

Sample command line using JSON syntax:
./x86_64-softmmu/qemu-system-x86_64 -name instance-00000008 -S -vnc 0.0.0.0:0

(quoted diff) +0 -2
-k en-us -vga cirrus -device virtio-balloon-pci,id=balloon0,bus=pci.0,addr=0x5
-msg timestamp=on

'json:{"driver":"vxhs","vdisk-id":"c3e9095a-a5ee-4dce-afeb-2a59fb387410", "server":{"host":"172.172.17.4","port":"9999"}}'

Sample command line using URI syntax:
qemu-img convert -f raw -O raw -n /var/lib/nova/instances/_base/0c5eacd5ebea5ed914b6a3e7b18f1ce734c386ad vxhs://192.168.0.1:9999/c6718f6b-0401-441d-a8c3-1f0064d75ee0

Quoted 7 lines

Sample command line using TLS credentials (run in secure mode):
./qemu-io --object tls-creds-x509,id=tls0,dir=/etc/pki/qemu/vxhs,endpoint=client -c 'read -v 66000 2.5k' 'json:{"server.host": "127.0.0.1", "server.port": "9999", "vdisk-id": "/test.raw", "driver": "vxhs", "tls-creds":"tls0"}'

I was testing this some with blockdev-add and blockdev-del, and this sequence causes a segfault:

1. blockdev-add vxhs image
2. blockdev-del above image
3. blockdev-add vxhs image <--- segfaults

Looking at it in gdb, this is an issue with libqnio. The call to iio_fini() is not sufficiently thorough in cleaning up resources.

In nio_client.c, qnc_ctx is never freed, because there does not seem to be a call such as 'qnc_driver_fini' that cleans up the allocated qnio_client_ctx.

Therefore, on the second call to iio_init, the libqnio internal variable network_driver is NULL, because qnc_driver_init() returns NULL if it is called when qnc_ctx is still initialized:

lib/qnio/nio_client.c:

411 int
412 iio_init(int32_t version, iio_cb_t cb)
413 {

[...]

432     apictx->network_driver = qnc_secure_driver_init(client_callback);
433     nioDbg("Created API context.\n");
434     return 0;

435 }

[...]

779 struct channel_driver *
780 qnc_driver_init(qnio_notify client_notify)
781 {
782 if (qnc_ctx) {
783 nioDbg("Driver already initialized");
784 return NULL;
785 }
786

So two issues:

Quoted 7 lines

A. iio_init() should check the returned pointer, and fail if NULL

B. iio_fini() needs to clean everything up so that a new vxhs connection is
possible. This likely means at least one new function in nio_client.c to clean up qnc_ctx.

-Jeff

Thanks for reporting the issue and also suggesting the fix. I was able to reproduce the issue and have checked in a fix to libqnio.

This was the stack trace from the core -

Program terminated with signal 11, Segmentation fault.
#0 0x00007f12083a3afa in iio_channel_open (uri=0x7f120c57eb70 "of://127.0.0.1:9999", cacert=0x0, client_key=0x0, client_cert=0x0) at lib/qnio/iioapi.c:105
#1 0x00007f12083a470a in iio_open (uri=0x7f120d121be0 "of://127.0.0.1:9999", devid=0x7f120baa4bb0 "/test.raw", flags=0, cacert=0x0, client_key=0x0, client_cert=0x0) at lib/qnio/iioapi.c:520 #2 0x00007f12091bf7a3 in vxhs_open (bs=<optimized out>, options=<optimized out>, bdrv_flags=<optimized out>, errp=0x7ffdf1cafd70) at block/vxhs.c:388
#3 0x00007f120916cf14 in bdrv_open_driver (bs=bs@entry=0x7f120b1481b0, drv=drv@entry=0x7f1209843580 <bdrv_vxhs>, node_name=<optimized out>, options=options@entry=0x7f120daa6840, open_flags=8194,

    errp=errp@entry=0x7ffdf1cafe28) at block.c:1011

#4 0x00007f120917079f in bdrv_open_common (errp=0x7ffdf1cafe28, options=0x7f120daa6840, file=0x0, bs=0x7f120b1481b0) at block.c:1250 #5 bdrv_open_inherit (filename=<optimized out>, filename@entry=0x0, reference=reference@entry=0x0, options=0x7f120daa6840, options@entry=0x7f120daa4800, flags=40962, parent=parent@entry=0x0,

    child_role=child_role@entry=0x0, errp=errp@entry=0x7ffdf1caff18)

at block.c:2413
#6 0x00007f1209171663 in bdrv_open (filename=filename@entry=0x0, reference=reference@entry=0x0, options=options@entry=0x7f120daa4800, flags=<optimized out>, errp=errp@entry=0x7ffdf1caff18)

    at block.c:2505

#7 0x00007f1208f9f026 in bds_tree_init (bs_opts=bs_opts@entry=0x7f120daa4800, errp=errp@entry=0x7ffdf1caff18) at blockdev.c:656
#8 0x00007f1208fa4e5b in qmp_blockdev_add (options=options@entry=0x7ffdf1caff20, errp=errp@entry=0x7ffdf1caff18) at blockdev.c:3885
...

Please test again with refreshed libqnio and let me know in case of issues.

Thanks,
Ashish

#5 lore raw
Quoted 119 lines · ashish mittal
Quoted 71 lines · Jeff Cody
Quoted 15 lines · Ashish Mittal

Source code for the qnio library that this code loads can be downloaded from:
https://github.com/VeritasHyperScale/libqnio.git

Sample command line using JSON syntax:
./x86_64-softmmu/qemu-system-x86_64 -name instance-00000008 -S -vnc 0.0.0.0:0

(quoted diff) +0 -2
-k en-us -vga cirrus -device virtio-balloon-pci,id=balloon0,bus=pci.0,addr=0x5
-msg timestamp=on

'json:{"driver":"vxhs","vdisk-id":"c3e9095a-a5ee-4dce-afeb-2a59fb387410", "server":{"host":"172.172.17.4","port":"9999"}}'

Sample command line using URI syntax:
qemu-img convert -f raw -O raw -n /var/lib/nova/instances/_base/0c5eacd5ebea5ed914b6a3e7b18f1ce734c386ad vxhs://192.168.0.1:9999/c6718f6b-0401-441d-a8c3-1f0064d75ee0

Quoted 7 lines

Sample command line using TLS credentials (run in secure mode):
./qemu-io --object tls-creds-x509,id=tls0,dir=/etc/pki/qemu/vxhs,endpoint=client -c 'read -v 66000 2.5k' 'json:{"server.host": "127.0.0.1", "server.port": "9999", "vdisk-id": "/test.raw", "driver": "vxhs", "tls-creds":"tls0"}'

I was testing this some with blockdev-add and blockdev-del, and this sequence causes a segfault:

1. blockdev-add vxhs image
2. blockdev-del above image
3. blockdev-add vxhs image <--- segfaults

Looking at it in gdb, this is an issue with libqnio. The call to iio_fini() is not sufficiently thorough in cleaning up resources.

In nio_client.c, qnc_ctx is never freed, because there does not seem to be a call such as 'qnc_driver_fini' that cleans up the allocated qnio_client_ctx.

Therefore, on the second call to iio_init, the libqnio internal variable network_driver is NULL, because qnc_driver_init() returns NULL if it is called when qnc_ctx is still initialized:

lib/qnio/nio_client.c:

411 int
412 iio_init(int32_t version, iio_cb_t cb)
413 {

[...]

432     apictx->network_driver = qnc_secure_driver_init(client_callback);
433     nioDbg("Created API context.\n");
434     return 0;

435 }

[...]

779 struct channel_driver *
780 qnc_driver_init(qnio_notify client_notify)
781 {
782 if (qnc_ctx) {
783 nioDbg("Driver already initialized");
784 return NULL;
785 }
786

So two issues:

Quoted 7 lines

A. iio_init() should check the returned pointer, and fail if NULL

B. iio_fini() needs to clean everything up so that a new vxhs connection is
possible. This likely means at least one new function in nio_client.c to clean up qnc_ctx.

-Jeff

Thanks for reporting the issue and also suggesting the fix. I was able to reproduce the issue and have checked in a fix to libqnio.

This was the stack trace from the core -

Program terminated with signal 11, Segmentation fault.
#0 0x00007f12083a3afa in iio_channel_open (uri=0x7f120c57eb70 "of://127.0.0.1:9999", cacert=0x0, client_key=0x0, client_cert=0x0) at lib/qnio/iioapi.c:105
#1 0x00007f12083a470a in iio_open (uri=0x7f120d121be0 "of://127.0.0.1:9999", devid=0x7f120baa4bb0 "/test.raw", flags=0, cacert=0x0, client_key=0x0, client_cert=0x0) at lib/qnio/iioapi.c:520 #2 0x00007f12091bf7a3 in vxhs_open (bs=<optimized out>, options=<optimized out>, bdrv_flags=<optimized out>, errp=0x7ffdf1cafd70) at block/vxhs.c:388
#3 0x00007f120916cf14 in bdrv_open_driver (bs=bs@entry=0x7f120b1481b0, drv=drv@entry=0x7f1209843580 <bdrv_vxhs>, node_name=<optimized out>, options=options@entry=0x7f120daa6840, open_flags=8194,

    errp=errp@entry=0x7ffdf1cafe28) at block.c:1011

#4 0x00007f120917079f in bdrv_open_common (errp=0x7ffdf1cafe28, options=0x7f120daa6840, file=0x0, bs=0x7f120b1481b0) at block.c:1250 #5 bdrv_open_inherit (filename=<optimized out>, filename@entry=0x0, reference=reference@entry=0x0, options=0x7f120daa6840, options@entry=0x7f120daa4800, flags=40962, parent=parent@entry=0x0,

    child_role=child_role@entry=0x0, errp=errp@entry=0x7ffdf1caff18)

at block.c:2413
#6 0x00007f1209171663 in bdrv_open (filename=filename@entry=0x0, reference=reference@entry=0x0, options=options@entry=0x7f120daa4800, flags=<optimized out>, errp=errp@entry=0x7ffdf1caff18)

    at block.c:2505

#7 0x00007f1208f9f026 in bds_tree_init (bs_opts=bs_opts@entry=0x7f120daa4800, errp=errp@entry=0x7ffdf1caff18) at blockdev.c:656
#8 0x00007f1208fa4e5b in qmp_blockdev_add (options=options@entry=0x7ffdf1caff20, errp=errp@entry=0x7ffdf1caff18) at blockdev.c:3885
...

Quoted 2 lines

Please test again with refreshed libqnio and let me know in case of issues.

Hi Ashish,

I updated libqnio to 87b641b, and I can confirm that it fixes the issue I was seeing above.

Thanks,
Jeff

Reviewed-by on v11 1/2
#6 lore raw
In reply to Ashish Mittal
Quoted 22 lines · Ashish Mittal

Source code for the qnio library that this code loads can be downloaded from:
https://github.com/VeritasHyperScale/libqnio.git

Sample command line using JSON syntax:
./x86_64-softmmu/qemu-system-x86_64 -name instance-00000008 -S -vnc 0.0.0.0:0

(quoted diff) +0 -2
-k en-us -vga cirrus -device virtio-balloon-pci,id=balloon0,bus=pci.0,addr=0x5
-msg timestamp=on

'json:{"driver":"vxhs","vdisk-id":"c3e9095a-a5ee-4dce-afeb-2a59fb387410", "server":{"host":"172.172.17.4","port":"9999"}}'

Sample command line using URI syntax:
qemu-img convert -f raw -O raw -n /var/lib/nova/instances/_base/0c5eacd5ebea5ed914b6a3e7b18f1ce734c386ad vxhs://192.168.0.1:9999/c6718f6b-0401-441d-a8c3-1f0064d75ee0

Sample command line using TLS credentials (run in secure mode):
./qemu-io --object tls-creds-x509,id=tls0,dir=/etc/pki/qemu/vxhs,endpoint=client -c 'read -v 66000 2.5k' 'json:{"server.host": "127.0.0.1", "server.port": "9999", "vdisk-id": "/test.raw", "driver": "vxhs", "tls-creds":"tls0"}'

Quoted 8 lines

---
v11 changelog:
(1) Replaced InetSocketAddress with InetSocketAddressBase.
(2) Removed access to qemu_uuid.
(3) Removed unnecessary g_strdup()/g_free().
(4) Removed unused acb->qiov.
(5) Changed vxhs_init_and_ref() and vxhs_unref() per suggestion.
(6) Removed unnecessary initializations from local variables.

QEMU code:

libvxhs is not robust yet. Here are two examples:

1. If the response from the server has an invalid magic number then the whole VM is aborted:

   QNIO_API_(void) kvset_unmarshal(qnio_byte_t * bs, kvset_t * *p)
   {
       ...
       assert(magic == kvset_magic);

2. There are buffer overflows and other memory corruptions. For example when kv_binary_unpack() gets size=-1 over the wire.

The code needs to be audited line-by-line by someone aware of secure coding practices. Please look into this.

Also, is there a plan for getting libvxhs into Fedora and Debian?

#7 lore raw
Quoted 34 lines · Stefan Hajnoczi
Quoted 22 lines · Ashish Mittal

Source code for the qnio library that this code loads can be downloaded from:
https://github.com/VeritasHyperScale/libqnio.git

Sample command line using JSON syntax:
./x86_64-softmmu/qemu-system-x86_64 -name instance-00000008 -S -vnc 0.0.0.0:0

(quoted diff) +0 -2
-k en-us -vga cirrus -device virtio-balloon-pci,id=balloon0,bus=pci.0,addr=0x5
-msg timestamp=on

'json:{"driver":"vxhs","vdisk-id":"c3e9095a-a5ee-4dce-afeb-2a59fb387410", "server":{"host":"172.172.17.4","port":"9999"}}'

Sample command line using URI syntax:
qemu-img convert -f raw -O raw -n /var/lib/nova/instances/_base/0c5eacd5ebea5ed914b6a3e7b18f1ce734c386ad vxhs://192.168.0.1:9999/c6718f6b-0401-441d-a8c3-1f0064d75ee0

Sample command line using TLS credentials (run in secure mode):
./qemu-io --object tls-creds-x509,id=tls0,dir=/etc/pki/qemu/vxhs,endpoint=client -c 'read -v 66000 2.5k' 'json:{"server.host": "127.0.0.1", "server.port": "9999", "vdisk-id": "/test.raw", "driver": "vxhs", "tls-creds":"tls0"}'

Quoted 8 lines

---
v11 changelog:
(1) Replaced InetSocketAddress with InetSocketAddressBase.
(2) Removed access to qemu_uuid.
(3) Removed unnecessary g_strdup()/g_free().
(4) Removed unused acb->qiov.
(5) Changed vxhs_init_and_ref() and vxhs_unref() per suggestion.
(6) Removed unnecessary initializations from local variables.

QEMU code:

Quoted 2 lines

Thanks!

Quoted 5 lines

libvxhs is not robust yet. Here are two examples:

1. If the response from the server has an invalid magic number then the whole VM is aborted:

Quoted 8 lines
   QNIO_API_(void) kvset_unmarshal(qnio_byte_t * bs, kvset_t * *p)
   {
       ...
       assert(magic == kvset_magic);

2. There are buffer overflows and other memory corruptions. For example when kv_binary_unpack() gets size=-1 over the wire.

We will continue to audit the library code and fix potential security issues with libvxhs.

Quoted 4 lines

The code needs to be audited line-by-line by someone aware of secure coding practices. Please look into this.

Also, is there a plan for getting libvxhs into Fedora and Debian?

At the moment, our requirement is only RHEL. The library should build and work fine with any distro.
We also plan to build source tarballs and checkin to github for every release of libvxhs.

#8 lore raw

PATCH v11 2/2 block/vxhs.c: Add qemu-iotests for new block device type "vxhs"

In reply to Ashish Mittal

These changes use a vxhs test server that is a part of the following repository:
https://github.com/VeritasHyperScale/libqnio.git

---
v11 changelog:
(1) No changes.

v10 changelog:
(1) Redirect o/p of "$QEMU_VXHS -d $TEST_DIR" to /dev/null

v9 changelog:
(1) Dropped second argument to set_prog_path(). We will pick up the test server location from the user's PATH env setting.

v8/v7 changelog:
(1) No changes.

v6 changelog:
(1) Added iotests for VxHS block device.

 tests/qemu-iotests/common        |  6 ++++++
 tests/qemu-iotests/common.config | 13 +++++++++++++
 tests/qemu-iotests/common.filter |  1 +
 tests/qemu-iotests/common.rc     | 19 +++++++++++++++++++
 4 files changed, 39 insertions(+)
tests/qemu-iotests/common +6 -0
index 4d5650d..9c6f972 100644
@@ -157,6 +157,7 @@ check options
     -ssh                test ssh
     -nfs                test nfs
     -luks               test luks
+    -vxhs               test vxhs
     -xdiff              graphical mode diff
     -nocache            use O_DIRECT on backing file
     -misalign           misalign memory allocations
@@ -260,6 +261,11 @@ testlist options
             xpand=false
             ;;
 
+        -vxhs)
+            IMGPROTO=vxhs
+            xpand=false
+            ;;
+
         -ssh)
             IMGPROTO=ssh
             xpand=false
tests/qemu-iotests/common.config +13 -0
index 55527aa..c4b51b3 100644
@@ -105,6 +105,10 @@ if [ -z "$QEMU_NBD_PROG" ]; then
     export QEMU_NBD_PROG="`set_prog_path qemu-nbd`"
 fi
 
+if [ -z "$QEMU_VXHS_PROG" ]; then
+    export QEMU_VXHS_PROG="`set_prog_path qnio_server`"
+fi
+
 _qemu_wrapper()
 {
     (
@@ -156,10 +160,19 @@ _qemu_nbd_wrapper()
     )
 }
 
+_qemu_vxhs_wrapper()
+{
+    (
+        echo $BASHPID > "${TEST_DIR}/qemu-vxhs.pid"
+        exec "$QEMU_VXHS_PROG" $QEMU_VXHS_OPTIONS "$@"
+    )
+}
+
 export QEMU=_qemu_wrapper
 export QEMU_IMG=_qemu_img_wrapper
 export QEMU_IO=_qemu_io_wrapper
 export QEMU_NBD=_qemu_nbd_wrapper
+export QEMU_VXHS=_qemu_vxhs_wrapper
 
 QEMU_IMG_EXTRA_ARGS=
 if [ "$IMGOPTSSYNTAX" = "true" ]; then
tests/qemu-iotests/common.filter +1 -0
index 1040013..c9a2d5c 100644
@@ -122,6 +122,7 @@ _filter_img_info()
         -e "s#$TEST_DIR#TEST_DIR#g" \
         -e "s#$IMGFMT#IMGFMT#g" \
         -e 's#nbd://127.0.0.1:10810$#TEST_DIR/t.IMGFMT#g' \
+        -e 's#json.*vdisk-id.*vxhs"}}#TEST_DIR/t.IMGFMT#' \
         -e "/encrypted: yes/d" \
         -e "/cluster_size: [0-9]\\+/d" \
         -e "/table_size: [0-9]\\+/d" \
tests/qemu-iotests/common.rc +19 -0
index 7d4781d..62529ee 100644
@@ -85,6 +85,9 @@ else
     elif [ "$IMGPROTO" = "nfs" ]; then
         TEST_DIR="nfs://127.0.0.1/$TEST_DIR"
         TEST_IMG=$TEST_DIR/t.$IMGFMT
+    elif [ "$IMGPROTO" = "vxhs" ]; then
+        TEST_IMG_FILE=$TEST_DIR/t.$IMGFMT
+        TEST_IMG="vxhs://127.0.0.1:9999/t.$IMGFMT"
     else
         TEST_IMG=$IMGPROTO:$TEST_DIR/t.$IMGFMT
     fi
@@ -171,6 +174,12 @@ _make_test_img()
         eval "$QEMU_NBD -v -t -b 127.0.0.1 -p 10810 -f $IMGFMT  $TEST_IMG_FILE >/dev/null &"
         sleep 1 # FIXME: qemu-nbd needs to be listening before we continue
     fi
+
+    # Start QNIO server on image directory for vxhs protocol
+    if [ $IMGPROTO = "vxhs" ]; then
+        eval "$QEMU_VXHS -d  $TEST_DIR > /dev/null &"
+        sleep 1 # Wait for server to come up.
+    fi
 }
 
 _rm_test_img()
@@ -197,6 +206,16 @@ _cleanup_test_img()
             fi
             rm -f "$TEST_IMG_FILE"
             ;;
+        vxhs)
+            if [ -f "${TEST_DIR}/qemu-vxhs.pid" ]; then
+                local QEMU_VXHS_PID
+                read QEMU_VXHS_PID < "${TEST_DIR}/qemu-vxhs.pid"
+                kill ${QEMU_VXHS_PID} >/dev/null 2>&1
+                rm -f "${TEST_DIR}/qemu-vxhs.pid"
+            fi
+            rm -f "$TEST_IMG_FILE"
+            ;;
+
         file)
             _rm_test_img "$TEST_DIR/t.$IMGFMT"
             _rm_test_img "$TEST_DIR/t.$IMGFMT.orig"
Signature · 1 line
2.5.5
#9 lore raw
In reply to Ashish Mittal
Quoted 12 lines · Ashish Mittal

- Veritas HyperScale block driver in QEMU is designed to provide an accelerated IO path from KVM virtual machines to Veritas HyperScale storage service.

- A network IO transfer library that translates block IO from HyperScale block driver to a network IO format to send it to Veritas HyperScale storage service. This library (libvxhs) has been open sourced and is available on github here: https://github.com/VeritasHyperScale/libqnio.git

Ashish Mittal (2):
block/vxhs.c: Add support for a new block device type called "vxhs" block/vxhs.c: Add qemu-iotests for new block device type "vxhs"

Quoted 15 lines
 block/Makefile.objs              |   2 +
 block/trace-events               |  17 ++
 block/vxhs.c                     | 575 +++++++++++++++++++++++++++++++++++++++
 configure                        |  39 +++
 qapi/block-core.json             |  23 +-
 tests/qemu-iotests/common        |   6 +
 tests/qemu-iotests/common.config |  13 +
 tests/qemu-iotests/common.filter |   1 +
 tests/qemu-iotests/common.rc     |  19 ++
 9 files changed, 693 insertions(+), 2 deletions(-)
 create mode 100644 block/vxhs.c
Signature · 1 line
2.5.5

With this additional patch (below), this passes all qemu-iotests for qcow2.

Quoted 1 line

From aeea8e23e28de325c572f8f3f67a1651b62887bd Mon Sep 17 00:00:00 2001

Message-Id: <aeea8e23e28de325c572f8f3f67a1651b62887bd.1491328865.git.jcody@redhat.com>
From: Jeff Cody <[email protected]>
Date: Tue, 14 Feb 2017 09:51:42 -0500
Subject: [PATCH v10 3/2 1/1] qemu-iotests: exclude vxhs from image creation
via protocol

The protocol VXHS does not support image creation. Some tests expect to be able to create images through the protocol. Exclude VXHS from these tests.

---
 tests/qemu-iotests/017 | 1 +
 tests/qemu-iotests/020 | 1 +
 tests/qemu-iotests/029 | 1 +
 tests/qemu-iotests/073 | 1 +
 tests/qemu-iotests/114 | 1 +
 tests/qemu-iotests/130 | 1 +
 tests/qemu-iotests/134 | 1 +
 tests/qemu-iotests/156 | 1 +
 tests/qemu-iotests/158 | 1 +
 9 files changed, 9 insertions(+)
tests/qemu-iotests/017 +1 -0
index e3f9e75..4f9302d 100755
@@ -41,6 +41,7 @@ trap "_cleanup; exit \$status" 0 1 2 3 15
 # Any format supporting backing files
 _supported_fmt qcow qcow2 vmdk qed
 _supported_proto generic
+_unsupported_proto vxhs
 _supported_os Linux
 _unsupported_imgopts "subformat=monolithicFlat" "subformat=twoGbMaxExtentFlat"
 
tests/qemu-iotests/020 +1 -0
index 9c4a68c..7a11110 100755
@@ -43,6 +43,7 @@ trap "_cleanup; exit \$status" 0 1 2 3 15
 # Any format supporting backing files
 _supported_fmt qcow qcow2 vmdk qed
 _supported_proto generic
+_unsupported_proto vxhs
 _supported_os Linux
 _unsupported_imgopts "subformat=monolithicFlat" \
                      "subformat=twoGbMaxExtentFlat" \
tests/qemu-iotests/029 +1 -0
index e639ac0..30bab24 100755
@@ -42,6 +42,7 @@ trap "_cleanup; exit \$status" 0 1 2 3 15
 # Any format supporting intenal snapshots
 _supported_fmt qcow2
 _supported_proto generic
+_unsupported_proto vxhs
 _supported_os Linux
 # Internal snapshots are (currently) impossible with refcount_bits=1
 _unsupported_imgopts 'refcount_bits=1[^0-9]'
tests/qemu-iotests/073 +1 -0
index ad37a61..40f85b1 100755
@@ -39,6 +39,7 @@ trap "_cleanup; exit \$status" 0 1 2 3 15
 
 _supported_fmt qcow2
 _supported_proto generic
+_unsupported_proto vxhs
 _supported_os Linux
 
 CLUSTER_SIZE=64k
tests/qemu-iotests/114 +1 -0
index f110d4f..5b7dc54 100755
@@ -39,6 +39,7 @@ trap "_cleanup; exit \$status" 0 1 2 3 15
 
 _supported_fmt qcow2
 _supported_proto generic
+_unsupported_proto vxhs
 _supported_os Linux
 
 
tests/qemu-iotests/130 +1 -0
index ecc8a5b..f941fc9 100755
@@ -42,6 +42,7 @@ trap "_cleanup; exit \$status" 0 1 2 3 15
 
 _supported_fmt qcow2
 _supported_proto generic
+_unsupported_proto vxhs
 _supported_os Linux
 
 qemu_comm_method="monitor"
tests/qemu-iotests/134 +1 -0
index af618b8..acce946 100755
@@ -39,6 +39,7 @@ trap "_cleanup; exit \$status" 0 1 2 3 15
 
 _supported_fmt qcow2
 _supported_proto generic
+_unsupported_proto vxhs
 _supported_os Linux
 
 
tests/qemu-iotests/156 +1 -0
index cc95ff1..78deaff 100755
@@ -48,6 +48,7 @@ trap "_cleanup; exit \$status" 0 1 2 3 15
 
 _supported_fmt qcow2 qed
 _supported_proto generic
+_unsupported_proto vxhs
 _supported_os Linux
 
 # Create source disk
tests/qemu-iotests/158 +1 -0
index a6cdd6d..ef8d70f 100755
@@ -39,6 +39,7 @@ trap "_cleanup; exit \$status" 0 1 2 3 15
 
 _supported_fmt qcow2
 _supported_proto generic
+_unsupported_proto vxhs
 _supported_os Linux
 
 
Signature · 1 line
2.9.3
Applied
#10 lore raw
In reply to Ashish Mittal
Quoted 12 lines · Ashish Mittal

- Veritas HyperScale block driver in QEMU is designed to provide an accelerated IO path from KVM virtual machines to Veritas HyperScale storage service.

- A network IO transfer library that translates block IO from HyperScale block driver to a network IO format to send it to Veritas HyperScale storage service. This library (libvxhs) has been open sourced and is available on github here: https://github.com/VeritasHyperScale/libqnio.git

Ashish Mittal (2):
block/vxhs.c: Add support for a new block device type called "vxhs" block/vxhs.c: Add qemu-iotests for new block device type "vxhs"

Quoted 15 lines
 block/Makefile.objs              |   2 +
 block/trace-events               |  17 ++
 block/vxhs.c                     | 575 +++++++++++++++++++++++++++++++++++++++
 configure                        |  39 +++
 qapi/block-core.json             |  23 +-
 tests/qemu-iotests/common        |   6 +
 tests/qemu-iotests/common.config |  13 +
 tests/qemu-iotests/common.filter |   1 +
 tests/qemu-iotests/common.rc     |  19 ++
 9 files changed, 693 insertions(+), 2 deletions(-)
 create mode 100644 block/vxhs.c
Signature · 1 line
2.5.5

Thanks,

Applied to my block branch:

git://github.com/codyprime/qemu-kvm-jtc block

-Jeff

#11 lore raw

Thanks Jeff!

Quoted 36 lines · Jeff Cody
Quoted 24 lines · Ashish Mittal

- Veritas HyperScale block driver in QEMU is designed to provide an accelerated IO path from KVM virtual machines to Veritas HyperScale storage service.

- A network IO transfer library that translates block IO from HyperScale block driver to a network IO format to send it to Veritas HyperScale storage service. This library (libvxhs) has been open sourced and is available on github here: https://github.com/VeritasHyperScale/libqnio.git

Ashish Mittal (2):
block/vxhs.c: Add support for a new block device type called "vxhs" block/vxhs.c: Add qemu-iotests for new block device type "vxhs"

 block/Makefile.objs              |   2 +
 block/trace-events               |  17 ++
 block/vxhs.c                     | 575 +++++++++++++++++++++++++++++++++++++++
 configure                        |  39 +++
 qapi/block-core.json             |  23 +-
 tests/qemu-iotests/common        |   6 +
 tests/qemu-iotests/common.config |  13 +
 tests/qemu-iotests/common.filter |   1 +
 tests/qemu-iotests/common.rc     |  19 ++
 9 files changed, 693 insertions(+), 2 deletions(-)
 create mode 100644 block/vxhs.c
Quoted 3 lines

--
2.5.5

Thanks,

Applied to my block branch:

git://github.com/codyprime/qemu-kvm-jtc block

-Jeff