Skip to contentSkip to conversation

block/vxhs: Initial commit to add Veritas HyperScale VxHS block device support

RFC PATCH Superseded Ashish Mittal 6 participants 19 messages Aug 14, 2016 – Feb 7, 2017 Block layer

v3 of 7 Superseded Latest is v7 →

lore
Share & tools
lore
#0 lore raw

RFC PATCH v3 1/1 block/vxhs: Initial commit to add Veritas HyperScale VxHS block device support

This patch adds support for a new block device type called "vxhs". Source code for the library that this code loads can be downloaded from:
https://github.com/MittalAshish/libqnio.git

Sample command line with a vxhs block device specification:
./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"},{"host":"172.172.17.2","port":"9999"}]}'

---
v3 changelog:
=============
(1) Implemented QAPI interface for passing VxHS block device parameters.

Sample trace o/p after filtering out libqnio debug messages:

./qemu-system-x86_64 -trace enable=vxhs* -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"},{"host":"172.172.17.2","port":"9999"}]}' [email protected]:vxhs_parse_json vdisk_id from json /{c3e9095a-a5ee-4dce-afeb-2a59fb387410}
[email protected]:vxhs_parse_json_numservers Number of servers passed = 2
[email protected]:vxhs_parse_json_hostinfo Host 1: IP 172.172.17.4, Port 9999
[email protected]:vxhs_parse_json_hostinfo Host 2: IP 172.172.17.2, Port 9999
[email protected]:vxhs_open vxhs_vxhs_open: came in to open file = (null)
[email protected]:vxhs_setup_qnio Context to HyperScale IO manager = 0x7f0996fd3920
[email protected]:vxhs_open_device Adding host 172.172.17.4:9999 to BDRVVXHSState
[email protected]:vxhs_open_device Adding host 172.172.17.2:9999 to BDRVVXHSState
[email protected]:vxhs_get_vdisk_stat vDisk /{c3e9095a-a5ee-4dce-afeb-2a59fb387410} stat ioctl returned size 429
...

TODO: Fixes to issues raised by review comments from Stefan and Kevin.

 block/Makefile.objs  |    2 +
 block/trace-events   |   46 ++
 block/vxhs.c         | 1424 ++++++++++++++++++++++++++++++++++++++++++++++++++
 block/vxhs.h         |  293 +++++++++++
 configure            |   50 ++
 qapi/block-core.json |   22 +-
 6 files changed, 1835 insertions(+), 2 deletions(-)
 create mode 100644 block/vxhs.c
 create mode 100644 block/vxhs.h
block/Makefile.objs +2 -0
index 2593a2f..5f83305 100644
@@ -20,6 +20,7 @@ block-obj-$(CONFIG_RBD) += rbd.o
 block-obj-$(CONFIG_GLUSTERFS) += gluster.o
 block-obj-$(CONFIG_ARCHIPELAGO) += archipelago.o
 block-obj-$(CONFIG_LIBSSH2) += ssh.o
+block-obj-$(CONFIG_VXHS) += vxhs.o
 block-obj-y += accounting.o dirty-bitmap.o
 block-obj-y += write-threshold.o
 
@@ -43,3 +44,4 @@ block-obj-m        += dmg.o
 dmg.o-libs         := $(BZIP2_LIBS)
 qcow.o-libs        := -lz
 linux-aio.o-libs   := -laio
+vxhs.o-libs        := $(VXHS_LIBS)
block/trace-events +46 -0

49 lines not on this page · raw message

block/vxhs.c new file +1424 -0

1,424 lines not on this page · raw message

block/vxhs.h new file +293 -0

293 lines not on this page · raw message

configure +50 -0

80 lines not on this page · raw message

qapi/block-core.json +20 -2
index 5e2d7d7..064d620 100644
@@ -1693,12 +1693,13 @@
 #
 # @host_device, @host_cdrom: Since 2.1
 # @gluster: Since 2.7
+# @vxhs: Since 2.7
 #
 # Since: 2.0
 ##
 { 'enum': 'BlockdevDriver',
   'data': [ 'archipelago', 'blkdebug', 'blkverify', 'bochs', 'cloop',
-            'dmg', 'file', 'ftp', 'ftps', 'gluster', 'host_cdrom',
+            'dmg', 'file', 'ftp', 'ftps', 'gluster', 'host_cdrom', 'vxhs',
             'host_device', 'http', 'https', 'luks', 'null-aio', 'null-co',
             'parallels', 'qcow', 'qcow2', 'qed', 'quorum', 'raw', 'tftp',
             'vdi', 'vhdx', 'vmdk', 'vpc', 'vvfat' ] }
@@ -2150,6 +2151,22 @@
             'server': ['GlusterServer'],
             '*debug-level': 'int' } }
 
+# @BlockdevOptionsVxHS
+#
+# Driver specific block device options for VxHS
+#
+# @vdisk_id:    UUID of VxHS volume
+#
+# @server:      list of vxhs server IP, port
+#
+# Since: 2.7
+##
+{ 'struct': 'BlockdevOptionsVxHS',
+  'data': { 'vdisk_id': 'str',
+            'server': ['InetSocketAddress'] } }
+
+##
+
 ##
 # @BlockdevOptions
 #
@@ -2222,7 +2239,8 @@
       'vhdx':       'BlockdevOptionsGenericFormat',
       'vmdk':       'BlockdevOptionsGenericCOWFormat',
       'vpc':        'BlockdevOptionsGenericFormat',
-      'vvfat':      'BlockdevOptionsVVFAT'
+      'vvfat':      'BlockdevOptionsVVFAT',
+      'vxhs':       'BlockdevOptionsVxHS'
   } }
 
 ##
Signature · 1 line
2.5.5
#1 lore raw
Your series seems to have some coding style problems. See output below for more information:

Hi,

Your series seems to have some coding style problems. See output below for more information:

Message-id: [email protected]
Subject: [Qemu-devel] [PATCH v3 RFC] block/vxhs: Initial commit to add Veritas HyperScale VxHS block device support
Type: series

=== TEST SCRIPT BEGIN ===
#!/bin/bash

BASE=base
n=1
total=$(git log --oneline $BASE.. | wc -l)
failed=0

commits="$(git log --format=%H --reverse $BASE..)" for c in $commits; do

    echo "Checking PATCH $n/$total: $(git show --no-patch --format=%s $c)..."
    if ! git show $c --format=email | ./scripts/checkpatch.pl --mailback -; then
        failed=1
        echo
    fi
    n=$((n+1))

done

exit $failed
=== TEST SCRIPT END ===

Updating 3c8cf5a9c21ff8782164d1def7f44bd888713384
From https://github.com/patchew-project/qemu
* [new tag] patchew/[email protected] -> patchew/[email protected]
Switched to a new branch 'test'
7b11227 block/vxhs: Initial commit to add Veritas HyperScale VxHS block device support

=== OUTPUT BEGIN ===
Checking PATCH 1/1: block/vxhs: Initial commit to add Veritas HyperScale VxHS block device support...
WARNING: line over 80 characters
#305: FILE: block/vxhs.c:212:
+ trace_vxhs_iio_callback_fail(reason, acb, acb->segments, acb->size, error);

WARNING: line over 80 characters
#341: FILE: block/vxhs.c:248:
+ trace_vxhs_iio_callback_ready(((BDRVVXHSState *)ctx)->vdisk_guid, error);

ERROR: spaces required around that '+' (ctx:VxV)
#608: FILE: block/vxhs.c:515:

+            trace_vxhs_parse_json_hostinfo(i+1, vxhsconf->host, vxhsconf->port);
                                             ^

ERROR: spaces required around that '==' (ctx:VxV)
#669: FILE: block/vxhs.c:576:

+        if (i==0 && (strstr(uri->path, "vxhs") == NULL)) {
              ^

ERROR: spaces required around that '+' (ctx:VxV)
#670: FILE: block/vxhs.c:577:

+            conf->vdisk_id = g_new0(char, strlen(uri->path)+3);
                                                            ^

ERROR: spaces required around that '+' (ctx:VxV)
#675: FILE: block/vxhs.c:582:

+        trace_vxhs_parse_uri_hostinfo(i+1, vxhsconf->host, vxhsconf->port);
                                        ^

ERROR: suspect code indent for conditional statements (4, 4) #1265: FILE: block/vxhs.c:1172:
+ if (res != 0) {
+ trace_vxhs_switch_storage_agent_failed(

ERROR: g_free(NULL) is safe this check is probably not required #1379: FILE: block/vxhs.c:1286:
+ if (of_vsa_addr) {
+ g_free(of_vsa_addr);

ERROR: g_free(NULL) is safe this check is probably not required #1382: FILE: block/vxhs.c:1289:
+ if (file_name) {
+ g_free(file_name);

total: 7 errors, 2 warnings, 1902 lines checked

Your patch has style problems, please review. If any of these errors are false positives report them to the maintainer, see CHECKPATCH in MAINTAINERS.

=== OUTPUT END ===

Test command exited with code: 1

---
Email generated automatically by Patchew [http://patchew.org/].
Please send your feedback to [email protected]

#2 lore raw
In reply to Ashish Mittal
Your series failed automatic build test. Please find the testing commands and their output below. If you have docker installed, you can probably reproduce it locally.

Hi,

Your series failed automatic build test. Please find the testing commands and their output below. If you have docker installed, you can probably reproduce it locally.

Message-id: [email protected]
Subject: [Qemu-devel] [PATCH v3 RFC] block/vxhs: Initial commit to add Veritas HyperScale VxHS block device support
Type: series

=== TEST SCRIPT BEGIN ===
#!/bin/bash
set -e
git submodule update --init dtc
make J=8 docker-test-quick@centos6

# we need CURL DPRINTF patch
# http://patchew.org/QEMU/1470027888-24381-1-git-send-email-famz%40redhat.com/
#make J=8 docker-test-mingw@fedora
=== TEST SCRIPT END ===

Updating 3c8cf5a9c21ff8782164d1def7f44bd888713384
Switched to a new branch 'test'
7b11227 block/vxhs: Initial commit to add Veritas HyperScale VxHS block device support

=== OUTPUT BEGIN ===
Submodule 'dtc' (git://git.qemu-project.org/dtc.git) registered for path 'dtc' Cloning into 'dtc'...
Submodule path 'dtc': checked out '65cc4d2748a2c2e6f27f1cf39e07a5dbabd80ebf'
BUILD centos6
ARCHIVE qemu.tgz
ARCHIVE dtc.tgz
COPY RUNNER
RUN test-quick in centos6
No C++ compiler available; disabling C++ specific optional code

ERROR: User requested feature vxhs block device
configure was not able to find it.
Install libqnio. See github

tests/docker/Makefile.include:104: recipe for target 'docker-run-test-quick@centos6' failed
make: *** [docker-run-test-quick@centos6] Error 1
=== OUTPUT END ===

Test command exited with code: 2

---
Email generated automatically by Patchew [http://patchew.org/].
Please send your feedback to [email protected]

#3 lore raw
In reply to Ashish Mittal
Quoted 222 lines · Ashish Mittal

This patch adds support for a new block device type called "vxhs". Source code for the library that this code loads can be downloaded from:
https://github.com/MittalAshish/libqnio.git

Sample command line with a vxhs block device specification:
./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"},{"host":"172.172.17.2","port":"9999"}]}'

---
v3 changelog:
=============
(1) Implemented QAPI interface for passing VxHS block device parameters.

Sample trace o/p after filtering out libqnio debug messages:

./qemu-system-x86_64 -trace enable=vxhs* -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"},{"host":"172.172.17.2","port":"9999"}]}' [email protected]:vxhs_parse_json vdisk_id from json /{c3e9095a-a5ee-4dce-afeb-2a59fb387410}
[email protected]:vxhs_parse_json_numservers Number of servers passed = 2
[email protected]:vxhs_parse_json_hostinfo Host 1: IP 172.172.17.4, Port 9999
[email protected]:vxhs_parse_json_hostinfo Host 2: IP 172.172.17.2, Port 9999
[email protected]:vxhs_open vxhs_vxhs_open: came in to open file = (null)
[email protected]:vxhs_setup_qnio Context to HyperScale IO manager = 0x7f0996fd3920
[email protected]:vxhs_open_device Adding host 172.172.17.4:9999 to BDRVVXHSState
[email protected]:vxhs_open_device Adding host 172.172.17.2:9999 to BDRVVXHSState
[email protected]:vxhs_get_vdisk_stat vDisk /{c3e9095a-a5ee-4dce-afeb-2a59fb387410} stat ioctl returned size 429
...

TODO: Fixes to issues raised by review comments from Stefan and Kevin.

 block/Makefile.objs  |    2 +
 block/trace-events   |   46 ++
 block/vxhs.c         | 1424 ++++++++++++++++++++++++++++++++++++++++++++++++++
 block/vxhs.h         |  293 +++++++++++
 configure            |   50 ++
 qapi/block-core.json |   22 +-
 6 files changed, 1835 insertions(+), 2 deletions(-)
 create mode 100644 block/vxhs.c
 create mode 100644 block/vxhs.h
block/vxhs.c new file +174 -0
new file mode 100644
index 0000000..3960ae5
 
 
+
+static QemuOptsList runtime_opts = {
+    .name = "vxhs",
+    .head = QTAILQ_HEAD_INITIALIZER(runtime_opts.head),
+    .desc = {
+        {
+            .name = VXHS_OPT_FILENAME,
+            .type = QEMU_OPT_STRING,
+            .help = "URI to the Veritas HyperScale image",
+        },
+        { /* end of list */ }
+    },
+};
+
+static QemuOptsList runtime_tcp_opts = {
+    .name = "vxhs_tcp",
+    .head = QTAILQ_HEAD_INITIALIZER(runtime_tcp_opts.head),
+    .desc = {
+        {
+            .name = VXHS_OPT_HOST,
+            .type = QEMU_OPT_STRING,
+            .help = "host address (ipv4 addresses)",
+        },
+        {
+            .name = VXHS_OPT_PORT,
+            .type = QEMU_OPT_NUMBER,
+            .help = "port number on which VxHSD is listening (default 9999)",
+        },
+        {
+            .name = "to",
+            .type = QEMU_OPT_NUMBER,
+            .help = "max port number, not supported by VxHS",
+        },
+        {
+            .name = "ipv4",
+            .type = QEMU_OPT_BOOL,
+            .help = "ipv4 bool value, not supported by VxHS",
+        },
+        {
+            .name = "ipv6",
+            .type = QEMU_OPT_BOOL,
+            .help = "ipv6 bool value, not supported by VxHS",
+        },
+        { /* end of list */ }
+    },
+};
+
+static QemuOptsList runtime_json_opts = {
+    .name = "vxhs_json",
+    .head = QTAILQ_HEAD_INITIALIZER(runtime_json_opts.head),
+    .desc = {
+        {
+            .name = VXHS_OPT_VDISK_ID,
+            .type = QEMU_OPT_STRING,
+            .help = "UUID of the VxHS vdisk",
+        },
+        { /* end of list */ }
+    },
+};
+
+
+/*
+ * Convert the json formatted command line into qapi.
+*/
+
+static int vxhs_parse_json(BlockdevOptionsVxHS *conf,
+                                  QDict *options, Error **errp)
+{
+    QemuOpts *opts;
+    InetSocketAddress *vxhsconf;
+    InetSocketAddressList *curr = NULL;
+    QDict *backing_options = NULL;
+    Error *local_err = NULL;
+    char *str = NULL;
+    const char *ptr = NULL;
+    size_t num_servers;
+    int i;
+
+    /* create opts info from runtime_json_opts list */
+    opts = qemu_opts_create(&runtime_json_opts, NULL, 0, &error_abort);
+    qemu_opts_absorb_qdict(opts, options, &local_err);
+    if (local_err) {
+        goto out;
+    }
+
+    ptr = qemu_opt_get(opts, VXHS_OPT_VDISK_ID);
+    if (!ptr) {
+        error_setg(&local_err, QERR_MISSING_PARAMETER, VXHS_OPT_VDISK_ID);
+        goto out;
+    }
+    conf->vdisk_id = g_strdup(ptr);
+    trace_vxhs_parse_json(ptr);
+
+    num_servers = qdict_array_entries(options, VXHS_OPT_SERVER);
+    if (num_servers < 1) {
+        error_setg(&local_err, QERR_MISSING_PARAMETER, "server");
+        goto out;
+    }
+    trace_vxhs_parse_json_numservers(num_servers);
+    qemu_opts_del(opts);
+
+    for (i = 0; i < num_servers; i++) {
+            str = g_strdup_printf(VXHS_OPT_SERVER_PATTERN"%d.", i);
+            qdict_extract_subqdict(options, &backing_options, str);
+
+            /* create opts info from runtime_tcp_opts list */
+            opts = qemu_opts_create(&runtime_tcp_opts, NULL, 0, &error_abort);
+            qemu_opts_absorb_qdict(opts, backing_options, &local_err);
+            if (local_err) {
+                goto out;
+            }
+
+            vxhsconf = g_new0(InetSocketAddress, 1);
+            ptr = qemu_opt_get(opts, VXHS_OPT_HOST);
+            if (!ptr) {
+                error_setg(&local_err, QERR_MISSING_PARAMETER,
+                           VXHS_OPT_HOST);
+                error_append_hint(&local_err, GERR_INDEX_HINT, i);
+                goto out;
+            }
+            vxhsconf->host = g_strdup(ptr);
+
+            ptr = qemu_opt_get(opts, VXHS_OPT_PORT);
+            if (!ptr) {
+                error_setg(&local_err, QERR_MISSING_PARAMETER,
+                           VXHS_OPT_PORT);
+                error_append_hint(&local_err, GERR_INDEX_HINT, i);
+                goto out;
+            }
+            vxhsconf->port = g_strdup(ptr);
+
+            /* defend for unsupported fields in InetSocketAddress,
+             * i.e. @ipv4, @ipv6  and @to
+             */
+            ptr = qemu_opt_get(opts, VXHS_OPT_TO);
+            if (ptr) {
+                vxhsconf->has_to = true;
+            }
+            ptr = qemu_opt_get(opts, VXHS_OPT_IPV4);
+            if (ptr) {
+                vxhsconf->has_ipv4 = true;
+            }
+            ptr = qemu_opt_get(opts, VXHS_OPT_IPV6);
+            if (ptr) {
+                vxhsconf->has_ipv6 = true;
+            }
+            if (vxhsconf->has_to) {
+                error_setg(&local_err, "Parameter 'to' not supported");
+                goto out;
+            }
+            if (vxhsconf->has_ipv4 || vxhsconf->has_ipv6) {
+                error_setg(&local_err, "Parameters 'ipv4/ipv6' not supported");
+                goto out;
+            }
+            trace_vxhs_parse_json_hostinfo(i+1, vxhsconf->host, vxhsconf->port);
+
+            if (conf->server == NULL) {
+                conf->server = g_new0(InetSocketAddressList, 1);
+                conf->server->value = vxhsconf;
+                curr = conf->server;
+            } else {
+                curr->next = g_new0(InetSocketAddressList, 1);
+                curr->next->value = vxhsconf;
+                curr = curr->next;
+            }
+
+            qdict_del(backing_options, str);
+            qemu_opts_del(opts);
+            g_free(str);
+            str = NULL;
+        }
+
+    return 0;
+

block/vxhs.c line 544

Quoted 10 lines
block/vxhs.c new file +10 -0
+out:
+    error_propagate(errp, local_err);
+    qemu_opts_del(opts);
+    if (str) {
+        qdict_del(backing_options, str);
+        g_free(str);
+    }
+    errno = EINVAL;
+    return -errno;
+}

Ewww this is really horrible code. It is open-coding a special purpose conversion of QemuOpts -> QDict -> QAPI scheme. We should really put my qdict_crumple() API impl as a pre-requisite of this, so you can then use qdict_crumple + qmp_input_visitor to do this conversion in a generic manner removing all this code.

https://lists.gnu.org/archive/html/qemu-devel/2016-07/msg03118.html

block/vxhs.c line 556

Quoted 11 lines
block/vxhs.c new file +11 -0
+/*
+ * vxhs_parse_uri: Parse the incoming URI and populate *conf with the
+ * vdisk_id, and all the host(s) information. Host at index 0 is local storage
+ * agent and the rest, reflection target storage agents. The local storage
+ * agent ip is the efficient internal address in the uri, e.g. 192.168.0.2.
+ * The local storage agent address is stored at index 0. The reflection target
+ * ips, are the E-W data network addresses of the reflection node agents, also
+ * extracted from the uri.
+ */
+static int vxhs_parse_uri(BlockdevOptionsVxHS *conf,
+                               const char *filename)

Delete this method entirely. We should not be adding URI syntax for any new block driver. The QAPI schema syntax is all we need.

Quoted 67 lines
block/vxhs.c new file +67 -0
+
+static void *qemu_vxhs_init(BlockdevOptionsVxHS *conf,
+                            const char *filename,
+                            QDict *options, Error **errp)
+{
+    int ret;
+
+    if (filename) {
+        ret = vxhs_parse_uri(conf, filename);
+        if (ret < 0) {
+            error_setg(errp, "invalid URI");
+            error_append_hint(errp, "Usage: file=vxhs://"
+                                    "[host[:port]]/{VDISK_UUID}\n");
+            errno = -ret;
+            return NULL;
+        }
+    } else {
+        ret = vxhs_parse_json(conf, options, errp);
+        if (ret < 0) {
+            error_append_hint(errp, "Usage: "
+                             "json:{\"driver\":\"vxhs\","
+                             "\"vdisk_id\":\"{VDISK_UUID}\","
+                             "\"server\":[{\"host\":\"1.2.3.4\","
+                             "\"port\":\"9999\"}"
+                             ",{\"host\":\"4.5.6.7\",\"port\":\"9999\"}]}"
+                             "\n");
+            errno = -ret;
+            return NULL;
+        }
+
+    }
+
+            return NULL;
+}
+
+int vxhs_open_device(BlockdevOptionsVxHS *conf, int *cfd, int *rfd,
+                       BDRVVXHSState *s)
+{
+    InetSocketAddressList *curr = NULL;
+    char *file_name;
+    char *of_vsa_addr;
+    int ret = 0;
+    int i = 0;
+
+    pthread_mutex_lock(&of_global_ctx_lock);
+    if (global_qnio_ctx == NULL) {
+        global_qnio_ctx = vxhs_setup_qnio();
+        if (global_qnio_ctx == NULL) {
+            pthread_mutex_unlock(&of_global_ctx_lock);
+            return -1;
+        }
+    }
+    pthread_mutex_unlock(&of_global_ctx_lock);
+
+    curr = conf->server;
+    s->vdisk_guid = g_strdup(conf->vdisk_id);
+
+    for (i = 0; curr != NULL; i++) {
+        s->vdisk_hostinfo[i].hostip = g_strdup(curr->value->host);
+        s->vdisk_hostinfo[i].port = g_ascii_strtoll(curr->value->port, NULL, 0);
+
+        s->vdisk_hostinfo[i].qnio_cfd = -1;
+        s->vdisk_hostinfo[i].vdisk_rfd = -1;
+        trace_vxhs_open_device(curr->value->host, curr->value->port);
+        curr = curr->next;
+    }
+    s->vdisk_nhosts = i;

block/vxhs.c line 674

Quoted 10 lines
block/vxhs.c new file +10 -0
+    s->vdisk_cur_host_idx = 0;
+
+
+    *cfd = -1;
+    of_vsa_addr = g_new0(char, OF_MAX_SERVER_ADDR);
+    file_name = g_new0(char, OF_MAX_FILE_LEN);
+    snprintf(file_name, OF_MAX_FILE_LEN, "%s%s", vdisk_prefix, s->vdisk_guid);
+    snprintf(of_vsa_addr, OF_MAX_SERVER_ADDR, "of://%s:%d",
+             s->vdisk_hostinfo[s->vdisk_cur_host_idx].hostip,
+             s->vdisk_hostinfo[s->vdisk_cur_host_idx].port);

*Never* use g_new + snprintf, particularly not with a fixed length buffer. g_strdup_printf() is the right way.

Quoted 7 lines
block/vxhs.c new file +7 -0
+
+    *cfd = qemu_open_iio_conn(global_qnio_ctx, of_vsa_addr, 0);
+    if (*cfd < 0) {
+        trace_vxhs_open_device_qnio(of_vsa_addr);
+        ret = -EIO;
+        goto out;
+    }

block/vxhs.c line 691

Quoted 10 lines
block/vxhs.c new file +10 -0
+    *rfd = qemu_iio_devopen(global_qnio_ctx, *cfd, file_name, 0);
+    s->aio_context = qemu_get_aio_context();
+
+out:
+    if (file_name != NULL) {
+        g_free(file_name);
+    }
+    if (of_vsa_addr != NULL) {
+        g_free(of_vsa_addr);
+    }

Useless if-before-free - g_free happily accepts NULL so don't check for it yourself.

Quoted 128 lines
block/vxhs.c new file +126 -0
+
+    return ret;
+}
+
+int vxhs_create(const char *filename,
+        QemuOpts *options, Error **errp)
+{
+    int ret = 0;
+    int qemu_cfd = 0;
+    int qemu_rfd = 0;
+    BDRVVXHSState s;
+    BlockdevOptionsVxHS *conf = NULL;
+
+    conf = g_new0(BlockdevOptionsVxHS, 1);
+    trace_vxhs_create(filename);
+    qemu_vxhs_init(conf, filename, NULL, errp);
+    ret = vxhs_open_device(conf, &qemu_cfd, &qemu_rfd, &s);
+
+    qapi_free_BlockdevOptionsVxHS(conf);
+    return ret;
+}
+
+int vxhs_open(BlockDriverState *bs, QDict *options,
+              int bdrv_flags, Error **errp)
+{
+    BDRVVXHSState *s = bs->opaque;
+    int ret = 0;
+    int qemu_qnio_cfd = 0;
+    int qemu_rfd = 0;
+    QemuOpts *opts;
+    Error *local_err = NULL;
+    const char *vxhs_uri;
+    BlockdevOptionsVxHS *conf = NULL;
+
+    opts = qemu_opts_create(&runtime_opts, NULL, 0, &error_abort);
+    qemu_opts_absorb_qdict(opts, options, &local_err);
+    if (local_err) {
+        error_propagate(errp, local_err);
+        ret = -EINVAL;
+        goto out;
+    }
+    vxhs_uri = qemu_opt_get(opts, VXHS_OPT_FILENAME);
+
+    conf = g_new0(BlockdevOptionsVxHS, 1);
+
+    qemu_vxhs_init(conf, vxhs_uri, options, errp);
+    memset(s, 0, sizeof(*s));
+    trace_vxhs_open(vxhs_uri);
+    ret = vxhs_open_device(conf, &qemu_qnio_cfd, &qemu_rfd, s);
+    if (ret != 0) {
+        trace_vxhs_open_fail(ret);
+        return ret;
+    }
+    s->qnio_ctx = global_qnio_ctx;
+    s->vdisk_hostinfo[0].qnio_cfd = qemu_qnio_cfd;
+    s->vdisk_hostinfo[0].vdisk_rfd = qemu_rfd;
+    s->vdisk_size = 0;
+    QSIMPLEQ_INIT(&s->vdisk_aio_retryq);
+
+    ret = qemu_pipe(s->fds);
+    if (ret < 0) {
+        trace_vxhs_open_epipe('.');
+        ret = -errno;
+        goto out;
+    }
+    fcntl(s->fds[VDISK_FD_READ], F_SETFL, O_NONBLOCK);
+
+    aio_set_fd_handler(s->aio_context, s->fds[VDISK_FD_READ],
+                       false, vxhs_aio_event_reader, NULL, s);
+
+    /*
+     * Allocate/Initialize the spin-locks.
+     *
+     * NOTE:
+     *      Since spin lock is being allocated
+     *      dynamically hence moving acb struct
+     *      specific lock to BDRVVXHSState
+     *      struct. The reason being,
+     *      we don't want the overhead of spin
+     *      lock being dynamically allocated and
+     *      freed for every AIO.
+     */
+    s->vdisk_lock = VXHS_SPIN_LOCK_ALLOC;
+    s->vdisk_acb_lock = VXHS_SPIN_LOCK_ALLOC;
+
+    qapi_free_BlockdevOptionsVxHS(conf);
+    return 0;
+
+out:
+    if (s->vdisk_hostinfo[0].vdisk_rfd >= 0) {
+        qemu_iio_devclose(s->qnio_ctx, 0,
+                                 s->vdisk_hostinfo[0].vdisk_rfd);
+    }
+    /* never close qnio_cfd */
+    trace_vxhs_open_fail(ret);
+    qapi_free_BlockdevOptionsVxHS(conf);
+    return ret;
+}
+
 
 
+
+/*
+ * This is called by QEMU when a flush gets triggered from within
+ * a guest at the block layer, either for IDE or SCSI disks.
+ */
+int vxhs_co_flush(BlockDriverState *bs)
+{
+    BDRVVXHSState *s = bs->opaque;
+    uint64_t size = 0;
+    int ret = 0;
+    uint32_t iocount = 0;
+
+    ret = qemu_iio_ioctl(s->qnio_ctx,
+            s->vdisk_hostinfo[s->vdisk_cur_host_idx].vdisk_rfd,
+            VDISK_AIO_FLUSH, &size, NULL, IIO_FLAG_SYNC);
+
+    if (ret < 0) {
+        /*
+         * Currently not handling the flush ioctl
+         * failure because of network connection
+         * disconnect. Since all the writes are
+         * commited into persistent storage hence
+         * this flush call is noop and we can safely
+         * return success status to the caller.
+         *
+         * If any write failure occurs for inflight
+         * write AIO because of network disconnect

block/vxhs.c line 1017

Quoted 10 lines
block/vxhs.c new file +10 -0
+         * then anyway IO failover will be triggered.
+         */
+        trace_vxhs_co_flush(s->vdisk_guid, ret, errno);
+        ret = 0;
+    }
+
+    iocount = vxhs_get_vdisk_iocount(s);
+    if (iocount > 0) {
+        trace_vxhs_co_flush_iocnt(iocount);
+    }

You're not doing anything with the iocount value here. Either delete this, or do something useful with it.

block/vxhs.c line 1026

Quoted 9 lines
block/vxhs.c new file +9 -0
+
+    return ret;
+}
+
+unsigned long vxhs_get_vdisk_stat(BDRVVXHSState *s)
+{
+    void *ctx = NULL;
+    int flags = 0;
+    unsigned long vdisk_size = 0;

Is this meansured in bytes ? If so 'unsigned long' is a rather limited choice for 32-bit builds. long long / int64_t would be better.

block/vxhs.c line 1038

Quoted 12 lines
block/vxhs.c new file +12 -0
+    int ret = 0;
+
+    ret = qemu_iio_ioctl(s->qnio_ctx,
+            s->vdisk_hostinfo[s->vdisk_cur_host_idx].vdisk_rfd,
+            VDISK_STAT, &vdisk_size, ctx, flags);
+
+    if (ret < 0) {
+        trace_vxhs_get_vdisk_stat_err(s->vdisk_guid, ret, errno);
+    }
+
+    trace_vxhs_get_vdisk_stat(s->vdisk_guid, vdisk_size);
+    return vdisk_size;

Presumably vdisk_size is garbage when ret < 0, so you really need to propagate the error better.

Quoted 87 lines
block/vxhs.c new file +85 -0
+}
+
+/*
+ * Returns the size of vDisk in bytes. This is required
+ * by QEMU block upper block layer so that it is visible
+ * to guest.
+ */
+int64_t vxhs_getlength(BlockDriverState *bs)
+{
+    BDRVVXHSState *s = bs->opaque;
+    unsigned long vdisk_size = 0;
+
+    if (s->vdisk_size > 0) {
+        vdisk_size = s->vdisk_size;
+    } else {
+        /*
+         * Fetch the vDisk size using stat ioctl
+         */
+        vdisk_size = vxhs_get_vdisk_stat(s);
+        if (vdisk_size > 0) {
+            s->vdisk_size = vdisk_size;
+        }
+    }
+
+    if (vdisk_size > 0) {
+        return (int64_t)vdisk_size; /* return size in bytes */
+    } else {
+        return -EIO;
+    }
+}
+
+/*
+ * Returns actual blocks allocated for the vDisk.
+ * This is required by qemu-img utility.
+ */
+int64_t vxhs_get_allocated_blocks(BlockDriverState *bs)
+{
+    BDRVVXHSState *s = bs->opaque;
+    unsigned long vdisk_size = 0;
+
+    if (s->vdisk_size > 0) {
+        vdisk_size = s->vdisk_size;
+    } else {
+        /*
+         * TODO:
+         * Once HyperScale storage-virtualizer provides
+         * actual physical allocation of blocks then
+         * fetch that information and return back to the
+         * caller but for now just get the full size.
+         */
+        vdisk_size = vxhs_get_vdisk_stat(s);
+        if (vdisk_size > 0) {
+            s->vdisk_size = vdisk_size;
+        }
+    }
+
+    if (vdisk_size > 0) {
+        return (int64_t)vdisk_size; /* return size in bytes */
+    } else {
+        return -EIO;
+    }
+}
 
 
+/*
+ * Try to reopen the vDisk on one of the available hosts
+ * If vDisk reopen is successful on any of the host then
+ * check if that node is ready to accept I/O.
+ */
+int vxhs_reopen_vdisk(BDRVVXHSState *s, int index)
+{
+    char *of_vsa_addr = NULL;
+    char *file_name = NULL;
+    int  res = 0;
+
+    /*
+     * Don't close the channel if it was opened
+     * before successfully. It will be handled
+     * within iio* api if the same channel open
+     * fd is reused.
+     *
+     * close stale vdisk device remote fd since
+     * it is invalid after channel disconnect.
+     */
+    if (s->vdisk_hostinfo[index].vdisk_rfd >= 0) {
+        qemu_iio_devclose(s->qnio_ctx, 0,
+                                 s->vdisk_hostinfo[index].vdisk_rfd);

block/vxhs.c line 1260

Quoted 10 lines
block/vxhs.c new file +10 -0
+        s->vdisk_hostinfo[index].vdisk_rfd = -1;
+    }
+    /*
+     * build storage agent address and vdisk device name strings
+     */
+    of_vsa_addr = g_new0(char, OF_MAX_SERVER_ADDR);
+    file_name = g_new0(char, OF_MAX_FILE_LEN);
+    snprintf(file_name, OF_MAX_FILE_LEN, "%s%s", vdisk_prefix, s->vdisk_guid);
+    snprintf(of_vsa_addr, OF_MAX_SERVER_ADDR, "of://%s:%d",
+             s->vdisk_hostinfo[index].hostip, s->vdisk_hostinfo[index].port);

Again no snprintf please.

Quoted 20 lines
block/vxhs.c new file +20 -0
+    /*
+     * open qnio channel to storage agent if not opened before.
+     */
+    if (s->vdisk_hostinfo[index].qnio_cfd < 0) {
+        s->vdisk_hostinfo[index].qnio_cfd =
+                qemu_open_iio_conn(global_qnio_ctx, of_vsa_addr, 0);
+        if (s->vdisk_hostinfo[index].qnio_cfd < 0) {
+            trace_vxhs_reopen_vdisk(s->vdisk_hostinfo[index].hostip);
+            res = ENODEV;
+            goto out;
+        }
+    }
+    /*
+     * open vdisk device
+     */
+    s->vdisk_hostinfo[index].vdisk_rfd =
+            qemu_iio_devopen(global_qnio_ctx,
+             s->vdisk_hostinfo[index].qnio_cfd, file_name, 0);
+    if (s->vdisk_hostinfo[index].vdisk_rfd < 0) {
+        trace_vxhs_reopen_vdisk_openfail(file_name);

block/vxhs.c line 1290

Quoted 10 lines
block/vxhs.c new file +10 -0
+        res = EIO;
+        goto out;
+    }
+out:
+    if (of_vsa_addr) {
+        g_free(of_vsa_addr);
+    }
+    if (file_name) {
+        g_free(file_name);
+    }

More useless-if-before-free

Quoted 5 lines
block/vxhs.c new file +2 -0
+    return res;
+}
 
 
 

block/vxhs.c line 1423

Quoted 10 lines
block/vxhs.c new file +10 -0
+void bdrv_vxhs_init(void)
+{
+    trace_vxhs_bdrv_init(vxhs_drv_version);
+    bdrv_register(&bdrv_vxhs);
+}
+
+/*
+ * The line below is how our drivier is initialized.
+ * DO NOT TOUCH IT
+ */

This is a rather pointless comment - the function name itself makes it obvious what this is doing.

Quoted 6 lines
block/vxhs.c new file +1 -0
+block_init(bdrv_vxhs_init);
block/vxhs.h new file +0 -0
new file mode 100644
index 0000000..1b678e5

block/vxhs.h line 30

Quoted 10 lines
block/vxhs.h new file +8 -0
 
 
+#define vxhsErr(fmt, ...) { \
+    time_t t = time(0); \
+    char buf[9] = {0}; \
+    strftime(buf, 9, "%H:%M:%S", localtime(&t)); \
+    fprintf(stderr, "[%s: %lu] %d: %s():\t", buf, pthread_self(), \
+                __LINE__, __func__); \
+    fprintf(stderr, fmt, ## __VA_ARGS__); \
+}

This appears unused now, please delete it.

configure vhdx="" · line 323

Quoted 9 lines
configure +1 -0
index 8d84919..fc09dc6 100755
@@ -320,6 +320,7 @@ vhdx=""
 numa=""
 tcmalloc="no"
 jemalloc="no"
+vxhs="yes"

You should set this to "", to indicate that configure should auto-probe for support. Setting it to 'yes' indicates a mandatory requirement which we don't want for an optional library like yours.

This would fix the automated build failure report this patch got.

Quoted 26 lines
qapi/block-core.json +5 -1
index 5e2d7d7..064d620 100644
@@ -1693,12 +1693,13 @@
 #
 # @host_device, @host_cdrom: Since 2.1
 # @gluster: Since 2.7
+# @vxhs: Since 2.7
 #
 # Since: 2.0
 ##
 { 'enum': 'BlockdevDriver',
   'data': [ 'archipelago', 'blkdebug', 'blkverify', 'bochs', 'cloop',
-            'dmg', 'file', 'ftp', 'ftps', 'gluster', 'host_cdrom',
+            'dmg', 'file', 'ftp', 'ftps', 'gluster', 'host_cdrom', 'vxhs',
             'host_device', 'http', 'https', 'luks', 'null-aio', 'null-co',
             'parallels', 'qcow', 'qcow2', 'qed', 'quorum', 'raw', 'tftp',
             'vdi', 'vhdx', 'vmdk', 'vpc', 'vvfat' ] }
@@ -2150,6 +2151,22 @@
             'server': ['GlusterServer'],
             '*debug-level': 'int' } }
 
+# @BlockdevOptionsVxHS
+#
+# Driver specific block device options for VxHS

qapi/block-core.json line 2166

Quoted 10 lines
qapi/block-core.json +10 -0
+#
+# @vdisk_id:    UUID of VxHS volume
+#
+# @server:      list of vxhs server IP, port
+#
+# Since: 2.7
+##
+{ 'struct': 'BlockdevOptionsVxHS',
+  'data': { 'vdisk_id': 'str',
+            'server': ['InetSocketAddress'] } }

Is there any chance that you are going to want to support UNIX domain socket connections in the future ? If so, perhaps we could use SocketAddress instead of InetSocketAddress to allow more flexibility in future.

Regards,
Daniel

Signature · 4 lines
|: http://berrange.com      -o-    http://www.flickr.com/photos/dberrange/ :|
|: http://libvirt.org              -o-             http://virt-manager.org :|
|: http://autobuild.org       -o-         http://search.cpan.org/~danberr/ :|
|: http://entangle-photo.org       -o-       http://live.gnome.org/gtk-vnc :|
#4 lore raw

Am 15.08.2016 um 12:20 hat Daniel P. Berrange geschrieben:

Quoted 7 lines · Ashish Mittal
Quoted 6 lines

+/*
+ * vxhs_parse_uri: Parse the incoming URI and populate *conf with the
+ * vdisk_id, and all the host(s) information. Host at index 0 is local storage
+ * agent and the rest, reflection target storage agents. The local storage
+ * agent ip is the efficient internal address in the uri, e.g. 192.168.0.2.
+ * The local storage agent address is stored at index 0. The reflection target

Quoted 8 lines

block/vxhs.c line 556

Quoted 5 lines

+ * ips, are the E-W data network addresses of the reflection node agents, also
+ * extracted from the uri.
+ */

block/vxhs.c new file +2 -0
+static int vxhs_parse_uri(BlockdevOptionsVxHS *conf,
+                               const char *filename)

Delete this method entirely. We should not be adding URI syntax for any new block driver. The QAPI schema syntax is all we need.

I disagree. URI syntax is nice for human users.

However, you should use the proper interfaces to implement this, which is .bdrv_parse_filename(). This is a function that gets a string and converts it into a QDict, which is then passed to .bdrv_open(). So it uses exactly the same code path in .bdrv_open() as if used directly with QAPI.

Kevin

#5 lore raw
Quoted 17 lines · Kevin Wolf

Am 15.08.2016 um 12:20 hat Daniel P. Berrange geschrieben:

Quoted 7 lines · Ashish Mittal
Quoted 6 lines

+/*
+ * vxhs_parse_uri: Parse the incoming URI and populate *conf with the
+ * vdisk_id, and all the host(s) information. Host at index 0 is local storage
+ * agent and the rest, reflection target storage agents. The local storage
+ * agent ip is the efficient internal address in the uri, e.g. 192.168.0.2.
+ * The local storage agent address is stored at index 0. The reflection target

Quoted 8 lines

block/vxhs.c line 556

Quoted 5 lines

+ * ips, are the E-W data network addresses of the reflection node agents, also
+ * extracted from the uri.
+ */

block/vxhs.c new file +2 -0
+static int vxhs_parse_uri(BlockdevOptionsVxHS *conf,
+                               const char *filename)

Delete this method entirely. We should not be adding URI syntax for any new block driver. The QAPI schema syntax is all we need.

Quoted 1 line

I disagree. URI syntax is nice for human users.

I think the dot-separated qapi syntax is actually more user friendly as looking at it, it is obvious what each component does. The URI syntax is inherantly limited, so if you start with that syntax and then want to support > 1 server, you have to completely change to the qapi syntax anyway. So from that POV I think it is a disservice to users to provide & encourage them to use a syntax that is known to be insufficiently flexible to work.

Regards,
Daniel

Signature · 4 lines
|: http://berrange.com      -o-    http://www.flickr.com/photos/dberrange/ :|
|: http://libvirt.org              -o-             http://virt-manager.org :|
|: http://autobuild.org       -o-         http://search.cpan.org/~danberr/ :|
|: http://entangle-photo.org       -o-       http://live.gnome.org/gtk-vnc :|
#8 lore raw
In reply to Daniel P. Berrange
Quoted 7 lines
Quoted 7 lines
block/vxhs.c new file +7 -0
+/*
+ * Convert the json formatted command line into qapi.
+*/
+
+static int vxhs_parse_json(BlockdevOptionsVxHS *conf,
+                                  QDict *options, Error **errp)
+{

...

Quoted 4 lines

block/vxhs.c line 544

Quoted 3 lines
block/vxhs.c new file +3 -0
+    errno = EINVAL;
+    return -errno;
+}
Quoted 8 lines

Ewww this is really horrible code. It is open-coding a special purpose conversion of QemuOpts -> QDict -> QAPI scheme. We should really put my qdict_crumple() API impl as a pre-requisite of this, so you can then use qdict_crumple + qmp_input_visitor to do this conversion in a generic manner removing all this code.

https://lists.gnu.org/archive/html/qemu-devel/2016-07/msg03118.html

Thanks for the suggestions. I will try to incorporate them in the next version. Actually, I used block/gluster.c for reference (as advised). This is exactly how it parses json CLI options. It also implements the *parse_uri() in a similar way.

Quoted 6 lines
Quoted 6 lines

+/*
+ * vxhs_parse_uri: Parse the incoming URI and populate *conf with the
+ * vdisk_id, and all the host(s) information. Host at index 0 is local storage
+ * agent and the rest, reflection target storage agents. The local storage
+ * agent ip is the efficient internal address in the uri, e.g. 192.168.0.2.
+ * The local storage agent address is stored at index 0. The reflection target

Quoted 9 lines

block/vxhs.c line 556

Quoted 5 lines

+ * ips, are the E-W data network addresses of the reflection node agents, also
+ * extracted from the uri.
+ */

block/vxhs.c new file +2 -0
+static int vxhs_parse_uri(BlockdevOptionsVxHS *conf,
+                               const char *filename)

Delete this method entirely. We should not be adding URI syntax for any new block driver. The QAPI schema syntax is all we need.

Regards,
Ashish

#6 lore raw
In reply to Daniel P. Berrange
Quoted 4 lines · Daniel P. Berrange

I think the dot-separated qapi syntax is actually more user friendly as looking at it, it is obvious what each component does. The URI syntax is inherantly limited, so if you start with that syntax and then want to support > 1 server, you have to completely change to the qapi syntax anyway.

If I understand correctly, this already supports >1 data server, the URI is to some kind of metadata server that is used only at startup.

Paolo

#9 lore raw
In reply to ashish mittal
Quoted 18 lines · ashish mittal
Quoted 7 lines
Quoted 7 lines
block/vxhs.c new file +7 -0
+/*
+ * Convert the json formatted command line into qapi.
+*/
+
+static int vxhs_parse_json(BlockdevOptionsVxHS *conf,
+                                  QDict *options, Error **errp)
+{

...

Quoted 10 lines

block/vxhs.c line 544

Quoted 3 lines
block/vxhs.c new file +3 -0
+    errno = EINVAL;
+    return -errno;
+}

Ewww this is really horrible code. It is open-coding a special purpose conversion of QemuOpts -> QDict -> QAPI scheme. We should really put my qdict_crumple() API impl as a pre-requisite of this, so you can then use qdict_crumple + qmp_input_visitor to do this conversion in a generic manner removing all this code.

Quoted 7 lines
Quoted 2 lines

https://lists.gnu.org/archive/html/qemu-devel/2016-07/msg03118.html

Thanks for the suggestions. I will try to incorporate them in the next version. Actually, I used block/gluster.c for reference (as advised). This is exactly how it parses json CLI options. It also implements the *parse_uri() in a similar way.

I think I pointed you to block/nbd.c instead, which works as Kevin suggested.

Paolo

#10 lore raw

Thanks Paolo, and everyone else for the corrections :)

I will try to fix it in a patch this week or the next. I referred to gluster.c implementation as it was closer to what we wanted to achieve i.e. passing multiple servers for the block device. I picked up the idea of referring to gluster.c from the following email that I received on libvirt mailing list. I did test my implementation to make sure that it worked fine, but did not realize that it was not clean. I will fix it.

/====================/
Hmm, unless I'm mis-reading this, there is no separator between the two URIs you're providing - is there a missing ',' or something similar.

Slightly off topic for the libvirt list, but I would be pretty surprised if the QEMU developers accepted patches using this URI syntax for providing multiple servers.

A similar approach was originally proposed for the glusterfs driver and the submitter was told to write it a different way, not using the legacy URI syntax at all, but instead a QAPI based syntax:

https://lists.gnu.org/archive/html/qemu-devel/2016-06/msg04126.html

So the sooner you can submit your QEMU patches to the qemu-devel mailing list the better, as we'll need to get clarity on the accepted QEMU syntax in order to proceed further with libvirt patch review.

Broadly speaking I think the patch you've proposed looks pretty much fine now. I'd have a slight preference for it to be done as two patches. One patch adds the XML schema, parser changes, etc. The second patch just does the QEMU driver integration & unit tests.
...
/====================/

Regards,
Ashish

Quoted 33 lines · Paolo Bonzini
Quoted 18 lines · ashish mittal
Quoted 7 lines
Quoted 7 lines
block/vxhs.c new file +7 -0
+/*
+ * Convert the json formatted command line into qapi.
+*/
+
+static int vxhs_parse_json(BlockdevOptionsVxHS *conf,
+                                  QDict *options, Error **errp)
+{

...

Quoted 10 lines

block/vxhs.c line 544

Quoted 3 lines
block/vxhs.c new file +3 -0
+    errno = EINVAL;
+    return -errno;
+}

Ewww this is really horrible code. It is open-coding a special purpose conversion of QemuOpts -> QDict -> QAPI scheme. We should really put my qdict_crumple() API impl as a pre-requisite of this, so you can then use qdict_crumple + qmp_input_visitor to do this conversion in a generic manner removing all this code.

Quoted 7 lines
Quoted 2 lines

https://lists.gnu.org/archive/html/qemu-devel/2016-07/msg03118.html

Thanks for the suggestions. I will try to incorporate them in the next version. Actually, I used block/gluster.c for reference (as advised). This is exactly how it parses json CLI options. It also implements the *parse_uri() in a similar way.

I think I pointed you to block/nbd.c instead, which works as Kevin suggested.

Paolo

#11 lore raw

Need some help!

I'm trying to understand how I can parse a json command line having multiple server list (InetSocketAddressList) without the QemuOpts -> QDict -> QAPI conversion that I am currently doing.

block/nbd.c has been suggested, but it only parses a single host entry, which is pretty straightforward, but not very helpful.

Could somebody please suggest a sample implementation (other than gluster.c) that parses a list of server like options in the json format?

Thanks,
Ashish

Quoted 74 lines · ashish mittal

Thanks Paolo, and everyone else for the corrections :)

I will try to fix it in a patch this week or the next. I referred to gluster.c implementation as it was closer to what we wanted to achieve i.e. passing multiple servers for the block device. I picked up the idea of referring to gluster.c from the following email that I received on libvirt mailing list. I did test my implementation to make sure that it worked fine, but did not realize that it was not clean. I will fix it.

/====================/
Hmm, unless I'm mis-reading this, there is no separator between the two URIs you're providing - is there a missing ',' or something similar.

Slightly off topic for the libvirt list, but I would be pretty surprised if the QEMU developers accepted patches using this URI syntax for providing multiple servers.

A similar approach was originally proposed for the glusterfs driver and the submitter was told to write it a different way, not using the legacy URI syntax at all, but instead a QAPI based syntax:

https://lists.gnu.org/archive/html/qemu-devel/2016-06/msg04126.html

So the sooner you can submit your QEMU patches to the qemu-devel mailing list the better, as we'll need to get clarity on the accepted QEMU syntax in order to proceed further with libvirt patch review.

Broadly speaking I think the patch you've proposed looks pretty much fine now. I'd have a slight preference for it to be done as two patches. One patch adds the XML schema, parser changes, etc. The second patch just does the QEMU driver integration & unit tests.
...
/====================/

Regards,
Ashish

Quoted 33 lines · Paolo Bonzini
Quoted 18 lines · ashish mittal
Quoted 7 lines
Quoted 7 lines
block/vxhs.c new file +7 -0
+/*
+ * Convert the json formatted command line into qapi.
+*/
+
+static int vxhs_parse_json(BlockdevOptionsVxHS *conf,
+                                  QDict *options, Error **errp)
+{

...

Quoted 10 lines

block/vxhs.c line 544

Quoted 3 lines
block/vxhs.c new file +3 -0
+    errno = EINVAL;
+    return -errno;
+}

Ewww this is really horrible code. It is open-coding a special purpose conversion of QemuOpts -> QDict -> QAPI scheme. We should really put my qdict_crumple() API impl as a pre-requisite of this, so you can then use qdict_crumple + qmp_input_visitor to do this conversion in a generic manner removing all this code.

Quoted 7 lines
Quoted 2 lines

https://lists.gnu.org/archive/html/qemu-devel/2016-07/msg03118.html

Thanks for the suggestions. I will try to incorporate them in the next version. Actually, I used block/gluster.c for reference (as advised). This is exactly how it parses json CLI options. It also implements the *parse_uri() in a similar way.

I think I pointed you to block/nbd.c instead, which works as Kevin suggested.

Paolo

#12 lore raw
Quoted 10 lines · ashish mittal

I'm trying to understand how I can parse a json command line having multiple server list (InetSocketAddressList) without the QemuOpts -> QDict -> QAPI conversion that I am currently doing.

block/nbd.c has been suggested, but it only parses a single host entry, which is pretty straightforward, but not very helpful.

Could somebody please suggest a sample implementation (other than gluster.c) that parses a list of server like options in the json format?

Another block driver that takes an array of objects is block/quorum.c. See quorum_open() and how it picks out "children." objects.

I haven't read the full discussion in this thread but maybe that's what you're looking for.

Stefan

#13 lore raw

Thanks Stefan, I will look at block/quorum.c.

I have sent V4 of the patch with a reworked parsing logic for both JSON and URI. Both of them are quite compact now.

URI parsing now follows the suggestion given by Kevin. /================/
However, you should use the proper interfaces to implement this, which is .bdrv_parse_filename(). This is a function that gets a string and converts it into a QDict, which is then passed to .bdrv_open(). So it uses exactly the same code path in .bdrv_open() as if used directly with QAPI.
/================/

Additionally, I have fixed all the issues pointed out by you on V1 of the patch. The only change I haven't done is to replace pipes with QEMUBH. I am hoping this will not hold up the patch from being accepted, and I can make this transition later with proper dev and testing.

Regards,
Ashish

Quoted 19 lines · Stefan Hajnoczi
Quoted 10 lines · ashish mittal

I'm trying to understand how I can parse a json command line having multiple server list (InetSocketAddressList) without the QemuOpts -> QDict -> QAPI conversion that I am currently doing.

block/nbd.c has been suggested, but it only parses a single host entry, which is pretty straightforward, but not very helpful.

Could somebody please suggest a sample implementation (other than gluster.c) that parses a list of server like options in the json format?

Another block driver that takes an array of objects is block/quorum.c. See quorum_open() and how it picks out "children." objects.

I haven't read the full discussion in this thread but maybe that's what you're looking for.

Stefan

#18 lore raw
In reply to Daniel P. Berrange

Hi Daniel,

In V4 of the patch:

Quoted 9 lines · Daniel P. Berrange

block/vxhs.c line 444

Quoted 8 lines

+ * Convert the json formatted command line into qapi.

block/vxhs.c new file +6 -0
+*/
+
+static int vxhs_parse_json(BlockdevOptionsVxHS *conf,
+                                  QDict *options, Error **errp)
+{
 
+}
Quoted 7 lines

Ewww this is really horrible code. It is open-coding a special purpose conversion of QemuOpts -> QDict -> QAPI scheme. We should really put my qdict_crumple() API impl as a pre-requisite of this, so you can then use qdict_crumple + qmp_input_visitor to do this conversion in a generic manner removing all this code.

https://lists.gnu.org/archive/html/qemu-devel/2016-07/msg03118.html

Changed to not do the manual conversion anymore.

Quoted 16 lines

block/vxhs.c line 556

Quoted 12 lines
block/vxhs.c new file +11 -0
+/*
+ * vxhs_parse_uri: Parse the incoming URI and populate *conf with the
+ * vdisk_id, and all the host(s) information. Host at index 0 is local storage
+ * agent and the rest, reflection target storage agents. The local storage
+ * agent ip is the efficient internal address in the uri, e.g. 192.168.0.2.
+ * The local storage agent address is stored at index 0. The reflection target
+ * ips, are the E-W data network addresses of the reflection node agents, also
+ * extracted from the uri.
+ */
+static int vxhs_parse_uri(BlockdevOptionsVxHS *conf,
+                               const char *filename)

Delete this method entirely. We should not be adding URI syntax for any new block driver. The QAPI schema syntax is all we need.

Changed per suggestion from Kevin.

Quoted 10 lines

block/vxhs.c line 674

Quoted 6 lines
block/vxhs.c new file +6 -0
+    of_vsa_addr = g_new0(char, OF_MAX_SERVER_ADDR);
+    file_name = g_new0(char, OF_MAX_FILE_LEN);
+    snprintf(file_name, OF_MAX_FILE_LEN, "%s%s", vdisk_prefix, s->vdisk_guid);
+    snprintf(of_vsa_addr, OF_MAX_SERVER_ADDR, "of://%s:%d",
+             s->vdisk_hostinfo[s->vdisk_cur_host_idx].hostip,
+             s->vdisk_hostinfo[s->vdisk_cur_host_idx].port);

*Never* use g_new + snprintf, particularly not with a fixed length buffer. g_strdup_printf() is the right way.

Fixed all such places.

Quoted 11 lines

block/vxhs.c line 691

Quoted 7 lines
block/vxhs.c new file +7 -0
+out:
+    if (file_name != NULL) {
+        g_free(file_name);
+    }
+    if (of_vsa_addr != NULL) {
+        g_free(of_vsa_addr);
+    }

Useless if-before-free - g_free happily accepts NULL so don't check for it yourself.

Removed all if-before-free - g_free.

Quoted 33 lines
Quoted 33 lines
block/vxhs.c new file +32 -0
+
+/*
+ * This is called by QEMU when a flush gets triggered from within
+ * a guest at the block layer, either for IDE or SCSI disks.
+ */
+int vxhs_co_flush(BlockDriverState *bs)
+{
+    BDRVVXHSState *s = bs->opaque;
+    uint64_t size = 0;
+    int ret = 0;
+    uint32_t iocount = 0;
+
+    ret = qemu_iio_ioctl(s->qnio_ctx,
+            s->vdisk_hostinfo[s->vdisk_cur_host_idx].vdisk_rfd,
+            VDISK_AIO_FLUSH, &size, NULL, IIO_FLAG_SYNC);
+
+    if (ret < 0) {
+        /*
+         * Currently not handling the flush ioctl
+         * failure because of network connection
+         * disconnect. Since all the writes are
+         * commited into persistent storage hence
+         * this flush call is noop and we can safely
+         * return success status to the caller.
+         *
+         * If any write failure occurs for inflight
+         * write AIO because of network disconnect
+         * then anyway IO failover will be triggered.
+         */
+        trace_vxhs_co_flush(s->vdisk_guid, ret, errno);
+        ret = 0;
+    }
Quoted 9 lines

block/vxhs.c line 1017

Quoted 5 lines
block/vxhs.c new file +5 -0
+
+    iocount = vxhs_get_vdisk_iocount(s);
+    if (iocount > 0) {
+        trace_vxhs_co_flush_iocnt(iocount);
+    }

You're not doing anything with the iocount value here. Either delete this, or do something useful with it.

Deleted.

Quoted 10 lines

block/vxhs.c line 1026

Quoted 5 lines
block/vxhs.c new file +5 -0
+unsigned long vxhs_get_vdisk_stat(BDRVVXHSState *s)
+{
+    void *ctx = NULL;
+    int flags = 0;
+    unsigned long vdisk_size = 0;

Is this meansured in bytes ? If so 'unsigned long' is a rather limited choice for 32-bit builds. long long / int64_t would be better.

You are right. This will need change in the qnio library as well. Hope I can fix this later!

Quoted 7 lines
Quoted 7 lines
block/vxhs.c new file +7 -0
+    int ret = 0;
+
+    ret = qemu_iio_ioctl(s->qnio_ctx,
+            s->vdisk_hostinfo[s->vdisk_cur_host_idx].vdisk_rfd,
+            VDISK_STAT, &vdisk_size, ctx, flags);
+
+    if (ret < 0) {
Quoted 9 lines

block/vxhs.c line 1038

Quoted 5 lines
block/vxhs.c new file +5 -0
+        trace_vxhs_get_vdisk_stat_err(s->vdisk_guid, ret, errno);
+    }
+
+    trace_vxhs_get_vdisk_stat(s->vdisk_guid, vdisk_size);
+    return vdisk_size;

Presumably vdisk_size is garbage when ret < 0, so you really need to propagate the error better.

Fixed.

Quoted 10 lines

block/vxhs.c line 1260

Quoted 8 lines
block/vxhs.c new file +8 -0
+    /*
+     * build storage agent address and vdisk device name strings
+     */
+    of_vsa_addr = g_new0(char, OF_MAX_SERVER_ADDR);
+    file_name = g_new0(char, OF_MAX_FILE_LEN);
+    snprintf(file_name, OF_MAX_FILE_LEN, "%s%s", vdisk_prefix, s->vdisk_guid);
+    snprintf(of_vsa_addr, OF_MAX_SERVER_ADDR, "of://%s:%d",
+             s->vdisk_hostinfo[index].hostip, s->vdisk_hostinfo[index].port);

Again no snprintf please.

Fixed.

Quoted 10 lines

block/vxhs.c line 1290

Quoted 7 lines
block/vxhs.c new file +7 -0
+out:
+    if (of_vsa_addr) {
+        g_free(of_vsa_addr);
+    }
+    if (file_name) {
+        g_free(file_name);
+    }

More useless-if-before-free

Fixed.

Quoted 9 lines

block/vxhs.c line 1423

Quoted 5 lines
block/vxhs.c new file +5 -0
+
+/*
+ * The line below is how our drivier is initialized.
+ * DO NOT TOUCH IT
+ */

This is a rather pointless comment - the function name itself makes it obvious what this is doing.

Removed.

Quoted 12 lines

block/vxhs.h line 30

Quoted 9 lines
block/vxhs.h new file +8 -0
+#define vxhsErr(fmt, ...) { \
+    time_t t = time(0); \
+    char buf[9] = {0}; \
+    strftime(buf, 9, "%H:%M:%S", localtime(&t)); \
+    fprintf(stderr, "[%s: %lu] %d: %s():\t", buf, pthread_self(), \
+                __LINE__, __func__); \
+    fprintf(stderr, fmt, ## __VA_ARGS__); \
+}

This appears unused now, please delete it.

Removed.

Quoted 14 lines

configure vhdx="" · line 323

Quoted 9 lines
configure +1 -0
index 8d84919..fc09dc6 100755
@@ -320,6 +320,7 @@ vhdx=""
 numa=""
 tcmalloc="no"
 jemalloc="no"
+vxhs="yes"

You should set this to "", to indicate that configure should auto-probe for support. Setting it to 'yes' indicates a mandatory requirement which we don't want for an optional library like yours.

Quoted 2 lines

This would fix the automated build failure report this patch got.

Fixed.

Quoted 32 lines
Quoted 32 lines
qapi/block-core.json +11 -1
index 5e2d7d7..064d620 100644
@@ -1693,12 +1693,13 @@
 #
 # @host_device, @host_cdrom: Since 2.1
 # @gluster: Since 2.7
+# @vxhs: Since 2.7
 #
 # Since: 2.0
 ##
 { 'enum': 'BlockdevDriver',
   'data': [ 'archipelago', 'blkdebug', 'blkverify', 'bochs', 'cloop',
-            'dmg', 'file', 'ftp', 'ftps', 'gluster', 'host_cdrom',
+            'dmg', 'file', 'ftp', 'ftps', 'gluster', 'host_cdrom', 'vxhs',
             'host_device', 'http', 'https', 'luks', 'null-aio', 'null-co',
             'parallels', 'qcow', 'qcow2', 'qed', 'quorum', 'raw', 'tftp',
             'vdi', 'vhdx', 'vmdk', 'vpc', 'vvfat' ] }
@@ -2150,6 +2151,22 @@
             'server': ['GlusterServer'],
             '*debug-level': 'int' } }
 
+# @BlockdevOptionsVxHS
+#
+# Driver specific block device options for VxHS
+#
+# @vdisk_id:    UUID of VxHS volume
+#
+# @server:      list of vxhs server IP, port
+#
+# Since: 2.7
Quoted 9 lines

qapi/block-core.json line 2166

Quoted 4 lines
qapi/block-core.json +4 -0
+##
+{ 'struct': 'BlockdevOptionsVxHS',
+  'data': { 'vdisk_id': 'str',
+            'server': ['InetSocketAddress'] } }

Is there any chance that you are going to want to support UNIX domain socket connections in the future ? If so, perhaps we could use SocketAddress instead of InetSocketAddress to allow more flexibility in future.

We don't see the need for UNIX sockets at present.

Regards,
Ashish

#7 lore raw
In reply to Kevin Wolf

Hi Kevin,

Changed per your suggestion in V4 patch. Please review when you get some time.

Thanks,
Ashish

Quoted 26 lines · Kevin Wolf

Am 15.08.2016 um 12:20 hat Daniel P. Berrange geschrieben:

Quoted 7 lines · Ashish Mittal
Quoted 6 lines

+/*
+ * vxhs_parse_uri: Parse the incoming URI and populate *conf with the
+ * vdisk_id, and all the host(s) information. Host at index 0 is local storage
+ * agent and the rest, reflection target storage agents. The local storage
+ * agent ip is the efficient internal address in the uri, e.g. 192.168.0.2.
+ * The local storage agent address is stored at index 0. The reflection target

Quoted 8 lines

block/vxhs.c line 556

Quoted 5 lines

+ * ips, are the E-W data network addresses of the reflection node agents, also
+ * extracted from the uri.
+ */

block/vxhs.c new file +2 -0
+static int vxhs_parse_uri(BlockdevOptionsVxHS *conf,
+                               const char *filename)

Delete this method entirely. We should not be adding URI syntax for any new block driver. The QAPI schema syntax is all we need.

I disagree. URI syntax is nice for human users.

However, you should use the proper interfaces to implement this, which is .bdrv_parse_filename(). This is a function that gets a string and converts it into a QDict, which is then passed to .bdrv_open(). So it uses exactly the same code path in .bdrv_open() as if used directly with QAPI.

Kevin

#14 lore raw
In reply to ashish mittal

Hi Stefan,

I had replied to the QEMUBH suggestion in the email below.

Regards,
Ashish

Quoted 44 lines · ashish mittal

Thanks Stefan, I will look at block/quorum.c.

I have sent V4 of the patch with a reworked parsing logic for both JSON and URI. Both of them are quite compact now.

URI parsing now follows the suggestion given by Kevin. /================/
However, you should use the proper interfaces to implement this, which is .bdrv_parse_filename(). This is a function that gets a string and converts it into a QDict, which is then passed to .bdrv_open(). So it uses exactly the same code path in .bdrv_open() as if used directly with QAPI.
/================/

Additionally, I have fixed all the issues pointed out by you on V1 of the patch. The only change I haven't done is to replace pipes with QEMUBH. I am hoping this will not hold up the patch from being accepted, and I can make this transition later with proper dev and testing.

Regards,
Ashish

Quoted 19 lines · Stefan Hajnoczi
Quoted 10 lines · ashish mittal

I'm trying to understand how I can parse a json command line having multiple server list (InetSocketAddressList) without the QemuOpts -> QDict -> QAPI conversion that I am currently doing.

block/nbd.c has been suggested, but it only parses a single host entry, which is pretty straightforward, but not very helpful.

Could somebody please suggest a sample implementation (other than gluster.c) that parses a list of server like options in the json format?

Another block driver that takes an array of objects is block/quorum.c. See quorum_open() and how it picks out "children." objects.

I haven't read the full discussion in this thread but maybe that's what you're looking for.

Stefan

#15 lore raw
Quoted 25 lines · ashish mittal

I had replied to the QEMUBH suggestion in the email below.

Regards,
Ashish

Quoted 19 lines · ashish mittal

Thanks Stefan, I will look at block/quorum.c.

I have sent V4 of the patch with a reworked parsing logic for both JSON and URI. Both of them are quite compact now.

URI parsing now follows the suggestion given by Kevin. /================/
However, you should use the proper interfaces to implement this, which is .bdrv_parse_filename(). This is a function that gets a string and converts it into a QDict, which is then passed to .bdrv_open(). So it uses exactly the same code path in .bdrv_open() as if used directly with QAPI.
/================/

Additionally, I have fixed all the issues pointed out by you on V1 of the patch. The only change I haven't done is to replace pipes with QEMUBH. I am hoping this will not hold up the patch from being accepted, and I can make this transition later with proper dev and testing.

Sorry, I forgot about this email. I still think the QEMUBH approach makes sense. Please try the following patch.

I have compiled but not run it. You are welcome to squash it into your next patch.

The following is Signed-off-by: Stefan Hajnoczi <[email protected]>.

---8<---

block/vxhs.c +25 -107
index 8913e8f..22fd989 100644
@@ -60,9 +60,6 @@ typedef struct VXHSvDiskHostsInfo {
  * Structure per vDisk maintained for state
  */
 typedef struct BDRVVXHSState {
-    int fds[2];
-    int event_reader_pos;
-    VXHSAIOCB *qnio_event_acb;
     VXHSvDiskHostsInfo vdisk_hostinfo; /* Per host info */
     char *vdisk_guid;
 } BDRVVXHSState;
@@ -73,12 +70,33 @@ static QNIOLibState qniolib;
 /* vdisk prefix to pass to qnio */
 static const char vdisk_prefix[] = "/dev/of/vdisk";
 
+static void vxhs_complete_aio_bh(void *opaque)
+{
+    VXHSAIOCB *acb = opaque;
+    BlockCompletionFunc *cb = acb->common.cb;
+    void *cb_opaque = acb->common.opaque;
+    int ret = 0;
+
+    if (acb->err != 0) {
+        trace_vxhs_complete_aio(acb, acb->err);
+        /*
+         * We mask all the IO errors generically as EIO for upper layers
+         * Right now our IO Manager uses non standard error codes. Instead
+         * of confusing upper layers with incorrect interpretation we are
+         * doing this workaround.
+         */
+        ret = (-EIO);
+    }
+
+    qemu_aio_unref(acb);
+    cb(cb_opaque, ret);
+}
+
+/* Called from a libqnio thread */
 static void vxhs_iio_callback(int32_t rfd, uint32_t reason, void *ctx,
                               uint32_t error, uint32_t opcode)
 {
     VXHSAIOCB *acb = NULL;
-    BDRVVXHSState *s = NULL;
-    ssize_t ret;
 
     switch (opcode) {
     case IRP_READ_REQUEST:
@@ -91,7 +109,6 @@ static void vxhs_iio_callback(int32_t rfd, uint32_t reason, void *ctx,
          */
         if (ctx) {
             acb = ctx;
-            s = acb->common.bs->opaque;
         } else {
             trace_vxhs_iio_callback(error, reason);
             goto out;
@@ -104,8 +121,8 @@ static void vxhs_iio_callback(int32_t rfd, uint32_t reason, void *ctx,
             trace_vxhs_iio_callback(error, reason);
         }
 
-        ret = qemu_write_full(s->fds[VDISK_FD_WRITE], &acb, sizeof(acb));
-        g_assert(ret == sizeof(acb));
+        aio_bh_schedule_oneshot(bdrv_get_aio_context(acb->common.bs),
+                                vxhs_complete_aio_bh, acb);
         break;
 
     default:
@@ -223,53 +240,6 @@ static void vxhs_qnio_iio_close(BDRVVXHSState *s)
     vxhs_qnio_close();
 }
 
-static void vxhs_complete_aio(VXHSAIOCB *acb, BDRVVXHSState *s)
-{
-    BlockCompletionFunc *cb = acb->common.cb;
-    void *opaque = acb->common.opaque;
-    int ret = 0;
-
-    if (acb->err != 0) {
-        trace_vxhs_complete_aio(acb, acb->err);
-        /*
-         * We mask all the IO errors generically as EIO for upper layers
-         * Right now our IO Manager uses non standard error codes. Instead
-         * of confusing upper layers with incorrect interpretation we are
-         * doing this workaround.
-         */
-        ret = (-EIO);
-    }
-
-    qemu_aio_unref(acb);
-    cb(opaque, ret);
-}
-
-/*
- * This is the HyperScale event handler registered to QEMU.
- * It is invoked when any IO gets completed and written on pipe
- * by callback called from QNIO thread context. Then it marks
- * the AIO as completed, and releases HyperScale AIO callbacks.
- */
-static void vxhs_aio_event_reader(void *opaque)
-{
-    BDRVVXHSState *s = opaque;
-    char *p;
-    ssize_t ret;
-
-    do {
-        p = (char *)&s->qnio_event_acb;
-        ret = read(s->fds[VDISK_FD_READ], p + s->event_reader_pos,
-                   sizeof(s->qnio_event_acb) - s->event_reader_pos);
-        if (ret > 0) {
-            s->event_reader_pos += ret;
-            if (s->event_reader_pos == sizeof(s->qnio_event_acb)) {
-                s->event_reader_pos = 0;
-                vxhs_complete_aio(s->qnio_event_acb, s);
-            }
-        }
-    } while (ret < 0 && errno == EINTR);
-}
-
 static QemuOptsList runtime_opts = {
     .name = "vxhs",
     .head = QTAILQ_HEAD_INITIALIZER(runtime_opts.head),
@@ -468,7 +438,6 @@ static int vxhs_open(BlockDriverState *bs, QDict *options,
                      int bdrv_flags, Error **errp)
 {
     BDRVVXHSState *s = bs->opaque;
-    AioContext *aio_context;
     int qemu_qnio_cfd = -1;
     int qemu_rfd = -1;
     int ret = 0;
@@ -481,32 +450,7 @@ static int vxhs_open(BlockDriverState *bs, QDict *options,
 
     s->vdisk_hostinfo.qnio_cfd = qemu_qnio_cfd;
     s->vdisk_hostinfo.vdisk_rfd = qemu_rfd;
-
-    /*
-     * Create a pipe for communicating between two threads in different
-     * context. Set handler for read event, which gets triggered when
-     * IO completion is done by non-QEMU context.
-     */
-    ret = qemu_pipe(s->fds);
-    if (ret < 0) {
-        trace_vxhs_open_epipe(ret);
-        ret = -errno;
-        goto errout;
-    }
-    fcntl(s->fds[VDISK_FD_READ], F_SETFL, O_NONBLOCK);
-
-    aio_context = bdrv_get_aio_context(bs);
-    aio_set_fd_handler(aio_context, s->fds[VDISK_FD_READ],
-                       false, vxhs_aio_event_reader, NULL, s);
     return 0;
-
-errout:
-    /*
-     * Close remote vDisk device if it was opened earlier
-     */
-    vxhs_qnio_iio_close(s);
-    trace_vxhs_open_fail(ret);
-    return ret;
 }
 
 static const AIOCBInfo vxhs_aiocb_info = {
@@ -596,14 +540,7 @@ static void vxhs_close(BlockDriverState *bs)
     BDRVVXHSState *s = bs->opaque;
 
     trace_vxhs_close(s->vdisk_guid);
-    close(s->fds[VDISK_FD_READ]);
-    close(s->fds[VDISK_FD_WRITE]);
 
-    /*
-     * Clearing all the event handlers for oflame registered to QEMU
-     */
-    aio_set_fd_handler(bdrv_get_aio_context(bs), s->fds[VDISK_FD_READ],
-                       false, NULL, NULL, NULL);
     g_free(s->vdisk_guid);
     s->vdisk_guid = NULL;
     vxhs_qnio_iio_close(s);
@@ -650,23 +587,6 @@ static int64_t vxhs_getlength(BlockDriverState *bs)
     return vdisk_size;
 }
 
-static void vxhs_detach_aio_context(BlockDriverState *bs)
-{
-    BDRVVXHSState *s = bs->opaque;
-
-    aio_set_fd_handler(bdrv_get_aio_context(bs), s->fds[VDISK_FD_READ],
-                       false, NULL, NULL, NULL);
-}
-
-static void vxhs_attach_aio_context(BlockDriverState *bs,
-                                   AioContext *new_context)
-{
-    BDRVVXHSState *s = bs->opaque;
-
-    aio_set_fd_handler(new_context, s->fds[VDISK_FD_READ],
-                       false, vxhs_aio_event_reader, NULL, s);
-}
-
 static BlockDriver bdrv_vxhs = {
     .format_name                  = "vxhs",
     .protocol_name                = "vxhs",
@@ -677,8 +597,6 @@ static BlockDriver bdrv_vxhs = {
     .bdrv_getlength               = vxhs_getlength,
     .bdrv_aio_readv               = vxhs_aio_readv,
     .bdrv_aio_writev              = vxhs_aio_writev,
-    .bdrv_detach_aio_context      = vxhs_detach_aio_context,
-    .bdrv_attach_aio_context      = vxhs_attach_aio_context,
 };
 
 static void bdrv_vxhs_init(void)
#16 lore raw

Thank you. Will work with this.

Quoted 249 lines · Stefan Hajnoczi
Quoted 25 lines · ashish mittal

I had replied to the QEMUBH suggestion in the email below.

Regards,
Ashish

Quoted 19 lines · ashish mittal

Thanks Stefan, I will look at block/quorum.c.

I have sent V4 of the patch with a reworked parsing logic for both JSON and URI. Both of them are quite compact now.

URI parsing now follows the suggestion given by Kevin. /================/
However, you should use the proper interfaces to implement this, which is .bdrv_parse_filename(). This is a function that gets a string and converts it into a QDict, which is then passed to .bdrv_open(). So it uses exactly the same code path in .bdrv_open() as if used directly with QAPI.
/================/

Additionally, I have fixed all the issues pointed out by you on V1 of the patch. The only change I haven't done is to replace pipes with QEMUBH. I am hoping this will not hold up the patch from being accepted, and I can make this transition later with proper dev and testing.

Sorry, I forgot about this email. I still think the QEMUBH approach makes sense. Please try the following patch.

I have compiled but not run it. You are welcome to squash it into your next patch.

The following is Signed-off-by: Stefan Hajnoczi <[email protected]>.

---8<---

block/vxhs.c +25 -107
index 8913e8f..22fd989 100644
@@ -60,9 +60,6 @@ typedef struct VXHSvDiskHostsInfo {
  * Structure per vDisk maintained for state
  */
 typedef struct BDRVVXHSState {
-    int fds[2];
-    int event_reader_pos;
-    VXHSAIOCB *qnio_event_acb;
     VXHSvDiskHostsInfo vdisk_hostinfo; /* Per host info */
     char *vdisk_guid;
 } BDRVVXHSState;
@@ -73,12 +70,33 @@ static QNIOLibState qniolib;
 /* vdisk prefix to pass to qnio */
 static const char vdisk_prefix[] = "/dev/of/vdisk";
 
+static void vxhs_complete_aio_bh(void *opaque)
+{
+    VXHSAIOCB *acb = opaque;
+    BlockCompletionFunc *cb = acb->common.cb;
+    void *cb_opaque = acb->common.opaque;
+    int ret = 0;
+
+    if (acb->err != 0) {
+        trace_vxhs_complete_aio(acb, acb->err);
+        /*
+         * We mask all the IO errors generically as EIO for upper layers
+         * Right now our IO Manager uses non standard error codes. Instead
+         * of confusing upper layers with incorrect interpretation we are
+         * doing this workaround.
+         */
+        ret = (-EIO);
+    }
+
+    qemu_aio_unref(acb);
+    cb(cb_opaque, ret);
+}
+
+/* Called from a libqnio thread */
 static void vxhs_iio_callback(int32_t rfd, uint32_t reason, void *ctx,
                               uint32_t error, uint32_t opcode)
 {
     VXHSAIOCB *acb = NULL;
-    BDRVVXHSState *s = NULL;
-    ssize_t ret;
 
     switch (opcode) {
     case IRP_READ_REQUEST:
@@ -91,7 +109,6 @@ static void vxhs_iio_callback(int32_t rfd, uint32_t reason, void *ctx,
          */
         if (ctx) {
             acb = ctx;
-            s = acb->common.bs->opaque;
         } else {
             trace_vxhs_iio_callback(error, reason);
             goto out;
@@ -104,8 +121,8 @@ static void vxhs_iio_callback(int32_t rfd, uint32_t reason, void *ctx,
             trace_vxhs_iio_callback(error, reason);
         }
 
-        ret = qemu_write_full(s->fds[VDISK_FD_WRITE], &acb, sizeof(acb));
-        g_assert(ret == sizeof(acb));
+        aio_bh_schedule_oneshot(bdrv_get_aio_context(acb->common.bs),
+                                vxhs_complete_aio_bh, acb);
         break;
 
     default:
@@ -223,53 +240,6 @@ static void vxhs_qnio_iio_close(BDRVVXHSState *s)
     vxhs_qnio_close();
 }
 
-static void vxhs_complete_aio(VXHSAIOCB *acb, BDRVVXHSState *s)
-{
-    BlockCompletionFunc *cb = acb->common.cb;
-    void *opaque = acb->common.opaque;
-    int ret = 0;
-
-    if (acb->err != 0) {
-        trace_vxhs_complete_aio(acb, acb->err);
-        /*
-         * We mask all the IO errors generically as EIO for upper layers
-         * Right now our IO Manager uses non standard error codes. Instead
-         * of confusing upper layers with incorrect interpretation we are
-         * doing this workaround.
-         */
-        ret = (-EIO);
-    }
-
-    qemu_aio_unref(acb);
-    cb(opaque, ret);
-}
-
-/*
- * This is the HyperScale event handler registered to QEMU.
- * It is invoked when any IO gets completed and written on pipe
- * by callback called from QNIO thread context. Then it marks
- * the AIO as completed, and releases HyperScale AIO callbacks.
- */
-static void vxhs_aio_event_reader(void *opaque)
-{
-    BDRVVXHSState *s = opaque;
-    char *p;
-    ssize_t ret;
-
-    do {
-        p = (char *)&s->qnio_event_acb;
-        ret = read(s->fds[VDISK_FD_READ], p + s->event_reader_pos,
-                   sizeof(s->qnio_event_acb) - s->event_reader_pos);
-        if (ret > 0) {
-            s->event_reader_pos += ret;
-            if (s->event_reader_pos == sizeof(s->qnio_event_acb)) {
-                s->event_reader_pos = 0;
-                vxhs_complete_aio(s->qnio_event_acb, s);
-            }
-        }
-    } while (ret < 0 && errno == EINTR);
-}
-
 static QemuOptsList runtime_opts = {
     .name = "vxhs",
     .head = QTAILQ_HEAD_INITIALIZER(runtime_opts.head),
@@ -468,7 +438,6 @@ static int vxhs_open(BlockDriverState *bs, QDict *options,
                      int bdrv_flags, Error **errp)
 {
     BDRVVXHSState *s = bs->opaque;
-    AioContext *aio_context;
     int qemu_qnio_cfd = -1;
     int qemu_rfd = -1;
     int ret = 0;
@@ -481,32 +450,7 @@ static int vxhs_open(BlockDriverState *bs, QDict *options,
 
     s->vdisk_hostinfo.qnio_cfd = qemu_qnio_cfd;
     s->vdisk_hostinfo.vdisk_rfd = qemu_rfd;
-
-    /*
-     * Create a pipe for communicating between two threads in different
-     * context. Set handler for read event, which gets triggered when
-     * IO completion is done by non-QEMU context.
-     */
-    ret = qemu_pipe(s->fds);
-    if (ret < 0) {
-        trace_vxhs_open_epipe(ret);
-        ret = -errno;
-        goto errout;
-    }
-    fcntl(s->fds[VDISK_FD_READ], F_SETFL, O_NONBLOCK);
-
-    aio_context = bdrv_get_aio_context(bs);
-    aio_set_fd_handler(aio_context, s->fds[VDISK_FD_READ],
-                       false, vxhs_aio_event_reader, NULL, s);
     return 0;
-
-errout:
-    /*
-     * Close remote vDisk device if it was opened earlier
-     */
-    vxhs_qnio_iio_close(s);
-    trace_vxhs_open_fail(ret);
-    return ret;
 }
 
 static const AIOCBInfo vxhs_aiocb_info = {
@@ -596,14 +540,7 @@ static void vxhs_close(BlockDriverState *bs)
     BDRVVXHSState *s = bs->opaque;
 
     trace_vxhs_close(s->vdisk_guid);
-    close(s->fds[VDISK_FD_READ]);
-    close(s->fds[VDISK_FD_WRITE]);
 
-    /*
-     * Clearing all the event handlers for oflame registered to QEMU
-     */
-    aio_set_fd_handler(bdrv_get_aio_context(bs), s->fds[VDISK_FD_READ],
-                       false, NULL, NULL, NULL);
     g_free(s->vdisk_guid);
     s->vdisk_guid = NULL;
     vxhs_qnio_iio_close(s);
@@ -650,23 +587,6 @@ static int64_t vxhs_getlength(BlockDriverState *bs)
     return vdisk_size;
 }
 
-static void vxhs_detach_aio_context(BlockDriverState *bs)
-{
-    BDRVVXHSState *s = bs->opaque;
-
-    aio_set_fd_handler(bdrv_get_aio_context(bs), s->fds[VDISK_FD_READ],
-                       false, NULL, NULL, NULL);
-}
-
-static void vxhs_attach_aio_context(BlockDriverState *bs,
-                                   AioContext *new_context)
-{
-    BDRVVXHSState *s = bs->opaque;
-
-    aio_set_fd_handler(new_context, s->fds[VDISK_FD_READ],
-                       false, vxhs_aio_event_reader, NULL, s);
-}
-
 static BlockDriver bdrv_vxhs = {
     .format_name                  = "vxhs",
     .protocol_name                = "vxhs",
@@ -677,8 +597,6 @@ static BlockDriver bdrv_vxhs = {
     .bdrv_getlength               = vxhs_getlength,
     .bdrv_aio_readv               = vxhs_aio_readv,
     .bdrv_aio_writev              = vxhs_aio_writev,
-    .bdrv_detach_aio_context      = vxhs_detach_aio_context,
-    .bdrv_attach_aio_context      = vxhs_attach_aio_context,
 };
 
 static void bdrv_vxhs_init(void)
#17 lore raw

Hi Stefan,

Patch V7, which I plan to submit soon, will have fixes to all the issues you pointed out in reply to -
[PATCH v6 1/2] block/vxhs.c: Add support for a new block device type called "vxhs"

It will also have the QEMUBH patch you provided.

Thanks,
Ashish

Quoted 252 lines · ashish mittal

Thank you. Will work with this.

Quoted 249 lines · Stefan Hajnoczi
Quoted 25 lines · ashish mittal

I had replied to the QEMUBH suggestion in the email below.

Regards,
Ashish

Quoted 19 lines · ashish mittal

Thanks Stefan, I will look at block/quorum.c.

I have sent V4 of the patch with a reworked parsing logic for both JSON and URI. Both of them are quite compact now.

URI parsing now follows the suggestion given by Kevin. /================/
However, you should use the proper interfaces to implement this, which is .bdrv_parse_filename(). This is a function that gets a string and converts it into a QDict, which is then passed to .bdrv_open(). So it uses exactly the same code path in .bdrv_open() as if used directly with QAPI.
/================/

Additionally, I have fixed all the issues pointed out by you on V1 of the patch. The only change I haven't done is to replace pipes with QEMUBH. I am hoping this will not hold up the patch from being accepted, and I can make this transition later with proper dev and testing.

Sorry, I forgot about this email. I still think the QEMUBH approach makes sense. Please try the following patch.

I have compiled but not run it. You are welcome to squash it into your next patch.

The following is Signed-off-by: Stefan Hajnoczi <[email protected]>.

---8<---

block/vxhs.c +25 -107
index 8913e8f..22fd989 100644
@@ -60,9 +60,6 @@ typedef struct VXHSvDiskHostsInfo {
  * Structure per vDisk maintained for state
  */
 typedef struct BDRVVXHSState {
-    int fds[2];
-    int event_reader_pos;
-    VXHSAIOCB *qnio_event_acb;
     VXHSvDiskHostsInfo vdisk_hostinfo; /* Per host info */
     char *vdisk_guid;
 } BDRVVXHSState;
@@ -73,12 +70,33 @@ static QNIOLibState qniolib;
 /* vdisk prefix to pass to qnio */
 static const char vdisk_prefix[] = "/dev/of/vdisk";
 
+static void vxhs_complete_aio_bh(void *opaque)
+{
+    VXHSAIOCB *acb = opaque;
+    BlockCompletionFunc *cb = acb->common.cb;
+    void *cb_opaque = acb->common.opaque;
+    int ret = 0;
+
+    if (acb->err != 0) {
+        trace_vxhs_complete_aio(acb, acb->err);
+        /*
+         * We mask all the IO errors generically as EIO for upper layers
+         * Right now our IO Manager uses non standard error codes. Instead
+         * of confusing upper layers with incorrect interpretation we are
+         * doing this workaround.
+         */
+        ret = (-EIO);
+    }
+
+    qemu_aio_unref(acb);
+    cb(cb_opaque, ret);
+}
+
+/* Called from a libqnio thread */
 static void vxhs_iio_callback(int32_t rfd, uint32_t reason, void *ctx,
                               uint32_t error, uint32_t opcode)
 {
     VXHSAIOCB *acb = NULL;
-    BDRVVXHSState *s = NULL;
-    ssize_t ret;
 
     switch (opcode) {
     case IRP_READ_REQUEST:
@@ -91,7 +109,6 @@ static void vxhs_iio_callback(int32_t rfd, uint32_t reason, void *ctx,
          */
         if (ctx) {
             acb = ctx;
-            s = acb->common.bs->opaque;
         } else {
             trace_vxhs_iio_callback(error, reason);
             goto out;
@@ -104,8 +121,8 @@ static void vxhs_iio_callback(int32_t rfd, uint32_t reason, void *ctx,
             trace_vxhs_iio_callback(error, reason);
         }
 
-        ret = qemu_write_full(s->fds[VDISK_FD_WRITE], &acb, sizeof(acb));
-        g_assert(ret == sizeof(acb));
+        aio_bh_schedule_oneshot(bdrv_get_aio_context(acb->common.bs),
+                                vxhs_complete_aio_bh, acb);
         break;
 
     default:
@@ -223,53 +240,6 @@ static void vxhs_qnio_iio_close(BDRVVXHSState *s)
     vxhs_qnio_close();
 }
 
-static void vxhs_complete_aio(VXHSAIOCB *acb, BDRVVXHSState *s)
-{
-    BlockCompletionFunc *cb = acb->common.cb;
-    void *opaque = acb->common.opaque;
-    int ret = 0;
-
-    if (acb->err != 0) {
-        trace_vxhs_complete_aio(acb, acb->err);
-        /*
-         * We mask all the IO errors generically as EIO for upper layers
-         * Right now our IO Manager uses non standard error codes. Instead
-         * of confusing upper layers with incorrect interpretation we are
-         * doing this workaround.
-         */
-        ret = (-EIO);
-    }
-
-    qemu_aio_unref(acb);
-    cb(opaque, ret);
-}
-
-/*
- * This is the HyperScale event handler registered to QEMU.
- * It is invoked when any IO gets completed and written on pipe
- * by callback called from QNIO thread context. Then it marks
- * the AIO as completed, and releases HyperScale AIO callbacks.
- */
-static void vxhs_aio_event_reader(void *opaque)
-{
-    BDRVVXHSState *s = opaque;
-    char *p;
-    ssize_t ret;
-
-    do {
-        p = (char *)&s->qnio_event_acb;
-        ret = read(s->fds[VDISK_FD_READ], p + s->event_reader_pos,
-                   sizeof(s->qnio_event_acb) - s->event_reader_pos);
-        if (ret > 0) {
-            s->event_reader_pos += ret;
-            if (s->event_reader_pos == sizeof(s->qnio_event_acb)) {
-                s->event_reader_pos = 0;
-                vxhs_complete_aio(s->qnio_event_acb, s);
-            }
-        }
-    } while (ret < 0 && errno == EINTR);
-}
-
 static QemuOptsList runtime_opts = {
     .name = "vxhs",
     .head = QTAILQ_HEAD_INITIALIZER(runtime_opts.head),
@@ -468,7 +438,6 @@ static int vxhs_open(BlockDriverState *bs, QDict *options,
                      int bdrv_flags, Error **errp)
 {
     BDRVVXHSState *s = bs->opaque;
-    AioContext *aio_context;
     int qemu_qnio_cfd = -1;
     int qemu_rfd = -1;
     int ret = 0;
@@ -481,32 +450,7 @@ static int vxhs_open(BlockDriverState *bs, QDict *options,
 
     s->vdisk_hostinfo.qnio_cfd = qemu_qnio_cfd;
     s->vdisk_hostinfo.vdisk_rfd = qemu_rfd;
-
-    /*
-     * Create a pipe for communicating between two threads in different
-     * context. Set handler for read event, which gets triggered when
-     * IO completion is done by non-QEMU context.
-     */
-    ret = qemu_pipe(s->fds);
-    if (ret < 0) {
-        trace_vxhs_open_epipe(ret);
-        ret = -errno;
-        goto errout;
-    }
-    fcntl(s->fds[VDISK_FD_READ], F_SETFL, O_NONBLOCK);
-
-    aio_context = bdrv_get_aio_context(bs);
-    aio_set_fd_handler(aio_context, s->fds[VDISK_FD_READ],
-                       false, vxhs_aio_event_reader, NULL, s);
     return 0;
-
-errout:
-    /*
-     * Close remote vDisk device if it was opened earlier
-     */
-    vxhs_qnio_iio_close(s);
-    trace_vxhs_open_fail(ret);
-    return ret;
 }
 
 static const AIOCBInfo vxhs_aiocb_info = {
@@ -596,14 +540,7 @@ static void vxhs_close(BlockDriverState *bs)
     BDRVVXHSState *s = bs->opaque;
 
     trace_vxhs_close(s->vdisk_guid);
-    close(s->fds[VDISK_FD_READ]);
-    close(s->fds[VDISK_FD_WRITE]);
 
-    /*
-     * Clearing all the event handlers for oflame registered to QEMU
-     */
-    aio_set_fd_handler(bdrv_get_aio_context(bs), s->fds[VDISK_FD_READ],
-                       false, NULL, NULL, NULL);
     g_free(s->vdisk_guid);
     s->vdisk_guid = NULL;
     vxhs_qnio_iio_close(s);
@@ -650,23 +587,6 @@ static int64_t vxhs_getlength(BlockDriverState *bs)
     return vdisk_size;
 }
 
-static void vxhs_detach_aio_context(BlockDriverState *bs)
-{
-    BDRVVXHSState *s = bs->opaque;
-
-    aio_set_fd_handler(bdrv_get_aio_context(bs), s->fds[VDISK_FD_READ],
-                       false, NULL, NULL, NULL);
-}
-
-static void vxhs_attach_aio_context(BlockDriverState *bs,
-                                   AioContext *new_context)
-{
-    BDRVVXHSState *s = bs->opaque;
-
-    aio_set_fd_handler(new_context, s->fds[VDISK_FD_READ],
-                       false, vxhs_aio_event_reader, NULL, s);
-}
-
 static BlockDriver bdrv_vxhs = {
     .format_name                  = "vxhs",
     .protocol_name                = "vxhs",
@@ -677,8 +597,6 @@ static BlockDriver bdrv_vxhs = {
     .bdrv_getlength               = vxhs_getlength,
     .bdrv_aio_readv               = vxhs_aio_readv,
     .bdrv_aio_writev              = vxhs_aio_writev,
-    .bdrv_detach_aio_context      = vxhs_detach_aio_context,
-    .bdrv_attach_aio_context      = vxhs_attach_aio_context,
 };
 
 static void bdrv_vxhs_init(void)