All of lore.kernel.org
 help / color / mirror / Atom feed
From: Kevin Wolf <kwolf@redhat.com>
To: qemu-block@nongnu.org
Cc: kwolf@redhat.com, qemu-devel@nongnu.org, mreitz@redhat.com
Subject: [Qemu-devel] [PATCH 12/15] virtio-scsi-test: Test attaching new overlay with iothreads
Date: Thu, 23 May 2019 18:01:01 +0200	[thread overview]
Message-ID: <20190523160104.21258-13-kwolf@redhat.com> (raw)
In-Reply-To: <20190523160104.21258-1-kwolf@redhat.com>

This tests that blockdev-add can correctly add a qcow2 overlay to an
image used by a virtio-scsi disk in an iothread. The interesting point
here is whether the newly added node gets correctly moved into the
iothread AioContext.

If it isn't, we get an assertion failure in virtio-scsi while processing
the next request:

    virtio_scsi_ctx_check: Assertion `blk_get_aio_context(d->conf.blk) == s->ctx' failed.

Signed-off-by: Kevin Wolf <kwolf@redhat.com>
---
 tests/libqtest.h         | 11 +++++++
 tests/libqtest.c         | 19 ++++++++++++
 tests/virtio-scsi-test.c | 62 ++++++++++++++++++++++++++++++++++++++++
 3 files changed, 92 insertions(+)

diff --git a/tests/libqtest.h b/tests/libqtest.h
index a98ea15b7d..32d927755d 100644
--- a/tests/libqtest.h
+++ b/tests/libqtest.h
@@ -619,6 +619,17 @@ static inline void qtest_end(void)
 QDict *qmp(const char *fmt, ...) GCC_FMT_ATTR(1, 2);
 
 /**
+ * qmp_assert_success:
+ * @fmt...: QMP message to send to qemu, formatted like
+ * qobject_from_jsonf_nofail().  See parse_escape() for what's
+ * supported after '%'.
+ *
+ * Sends a QMP message to QEMU and asserts that a 'return' key is present in
+ * the response.
+ */
+void qmp_assert_success(const char *fmt, ...) GCC_FMT_ATTR(1, 2);
+
+/*
  * qmp_eventwait:
  * @s: #event event to wait for.
  *
diff --git a/tests/libqtest.c b/tests/libqtest.c
index 8ac0c02af4..546a875913 100644
--- a/tests/libqtest.c
+++ b/tests/libqtest.c
@@ -1038,6 +1038,25 @@ QDict *qmp(const char *fmt, ...)
     return response;
 }
 
+void qmp_assert_success(const char *fmt, ...)
+{
+    va_list ap;
+    QDict *response;
+
+    va_start(ap, fmt);
+    response = qtest_vqmp(global_qtest, fmt, ap);
+    va_end(ap);
+
+    g_assert(response);
+    if (!qdict_haskey(response, "return")) {
+        QString *s = qobject_to_json_pretty(QOBJECT(response));
+        g_test_message("%s", qstring_get_str(s));
+        qobject_unref(s);
+    }
+    g_assert(qdict_haskey(response, "return"));
+    qobject_unref(response);
+}
+
 char *hmp(const char *fmt, ...)
 {
     va_list ap;
diff --git a/tests/virtio-scsi-test.c b/tests/virtio-scsi-test.c
index 162b31c88d..923febc76e 100644
--- a/tests/virtio-scsi-test.c
+++ b/tests/virtio-scsi-test.c
@@ -188,6 +188,52 @@ static void test_unaligned_write_same(void *obj, void *data,
     qvirtio_scsi_pci_free(vs);
 }
 
+static void test_iothread_attach_node(void *obj, void *data,
+                                      QGuestAllocator *t_alloc)
+{
+    QVirtioSCSI *scsi = obj;
+    QVirtioSCSIQueues *vs;
+    char tmp_path[] = "/tmp/qtest.XXXXXX";
+    int fd;
+    int ret;
+
+    uint8_t buf[512] = { 0 };
+    const uint8_t write_cdb[VIRTIO_SCSI_CDB_SIZE] = {
+        /* WRITE(10) to LBA 0, transfer length 1 */
+        0x2a, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x00
+    };
+
+    alloc = t_alloc;
+    vs = qvirtio_scsi_init(scsi->vdev);
+
+    /* Create a temporary qcow2 overlay*/
+    fd = mkstemp(tmp_path);
+    g_assert(fd >= 0);
+    close(fd);
+
+    if (!have_qemu_img()) {
+        g_test_message("QTEST_QEMU_IMG not set or qemu-img missing; "
+                       "skipping snapshot test");
+        goto fail;
+    }
+
+    mkqcow2(tmp_path, 64);
+
+    /* Attach the overlay to the null0 node */
+    qmp_assert_success("{'execute': 'blockdev-add', 'arguments': {"
+                       "   'driver': 'qcow2', 'node-name': 'overlay',"
+                       "   'backing': 'null0', 'file': {"
+                       "     'driver': 'file', 'filename': %s}}}", tmp_path);
+
+    /* Send a request to see if the AioContext is still right */
+    ret = virtio_scsi_do_command(vs, write_cdb, NULL, 0, buf, 512, NULL);
+    g_assert_cmphex(ret, ==, 0);
+
+fail:
+    qvirtio_scsi_pci_free(vs);
+    unlink(tmp_path);
+}
+
 static void *virtio_scsi_hotplug_setup(GString *cmd_line, void *arg)
 {
     g_string_append(cmd_line,
@@ -204,6 +250,15 @@ static void *virtio_scsi_setup(GString *cmd_line, void *arg)
     return arg;
 }
 
+static void *virtio_scsi_setup_iothread(GString *cmd_line, void *arg)
+{
+    g_string_append(cmd_line,
+                    " -object iothread,id=thread0"
+                    " -blockdev driver=null-co,node-name=null0"
+                    " -device scsi-hd,drive=null0");
+    return arg;
+}
+
 static void register_virtio_scsi_test(void)
 {
     QOSGraphTestOptions opts = { };
@@ -214,6 +269,13 @@ static void register_virtio_scsi_test(void)
     opts.before = virtio_scsi_setup;
     qos_add_test("unaligned-write-same", "virtio-scsi",
                  test_unaligned_write_same, &opts);
+
+    opts.before = virtio_scsi_setup_iothread;
+    opts.edge = (QOSGraphEdgeOptions) {
+        .extra_device_opts = "iothread=thread0",
+    };
+    qos_add_test("iothread-attach-node", "virtio-scsi",
+                 test_iothread_attach_node, &opts);
 }
 
 libqos_init(register_virtio_scsi_test);
-- 
2.20.1



  parent reply	other threads:[~2019-05-23 16:14 UTC|newest]

Thread overview: 22+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-05-23 16:00 [Qemu-devel] [PATCH 00/15] block: AioContext management, part 2 Kevin Wolf
2019-05-23 16:00 ` [Qemu-devel] [PATCH 01/15] test-block-iothread: Check filter node in test_propagate_mirror Kevin Wolf
2019-05-24 12:25   ` Eric Blake
2019-05-23 16:00 ` [Qemu-devel] [PATCH 02/15] block: Add Error to blk_set_aio_context() Kevin Wolf
2019-05-23 16:00 ` [Qemu-devel] [PATCH 03/15] block: Add BlockBackend.ctx Kevin Wolf
2019-05-23 16:00 ` [Qemu-devel] [PATCH 04/15] block: Add qdev_prop_drive_iothread property type Kevin Wolf
2019-05-23 16:00 ` [Qemu-devel] [PATCH 05/15] scsi-disk: Use qdev_prop_drive_iothread Kevin Wolf
2019-05-23 16:00 ` [Qemu-devel] [PATCH 06/15] block: Adjust AioContexts when attaching nodes Kevin Wolf
2019-05-23 16:00 ` [Qemu-devel] [PATCH 07/15] test-block-iothread: Test adding parent to iothread node Kevin Wolf
2019-05-24 12:24   ` Eric Blake
2019-05-23 16:00 ` [Qemu-devel] [PATCH 08/15] test-block-iothread: BlockBackend AioContext across root node change Kevin Wolf
2019-05-23 16:00 ` [Qemu-devel] [PATCH 09/15] block: Move node without parents to main AioContext Kevin Wolf
2019-05-23 16:00 ` [Qemu-devel] [PATCH 10/15] blockdev: Use bdrv_try_set_aio_context() for monitor commands Kevin Wolf
2019-05-23 16:01 ` [Qemu-devel] [PATCH 11/15] block: Remove wrong bdrv_set_aio_context() calls Kevin Wolf
2019-05-23 16:01 ` Kevin Wolf [this message]
2019-05-23 16:01 ` [Qemu-devel] [PATCH 13/15] iotests: Attach new devices to node in non-default iothread Kevin Wolf
2019-05-23 16:01 ` [Qemu-devel] [PATCH 14/15] test-bdrv-drain: Use bdrv_try_set_aio_context() Kevin Wolf
2019-05-23 16:01 ` [Qemu-devel] [PATCH 15/15] block: Remove bdrv_set_aio_context() Kevin Wolf
2019-05-23 19:44 ` [Qemu-devel] [PATCH 00/15] block: AioContext management, part 2 no-reply
2019-05-24  8:57 ` [Qemu-devel] [PATCH 1.5/15] nbd-server: Call blk_set_allow_aio_context_change() Kevin Wolf
2019-05-24 12:27   ` Eric Blake
2019-06-03 13:19 ` [Qemu-devel] [PATCH 00/15] block: AioContext management, part 2 Kevin Wolf

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20190523160104.21258-13-kwolf@redhat.com \
    --to=kwolf@redhat.com \
    --cc=mreitz@redhat.com \
    --cc=qemu-block@nongnu.org \
    --cc=qemu-devel@nongnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.