qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
From: Markus Armbruster <armbru@redhat.com>
To: qemu-devel@nongnu.org
Cc: peterx@redhat.com, eblake@redhat.com, stefanha@redhat.com,
	dgilbert@redhat.com
Subject: [Qemu-devel] [PATCH 05/32] qmp: Get rid of x-oob-test command
Date: Mon,  2 Jul 2018 18:21:51 +0200	[thread overview]
Message-ID: <20180702162218.13678-6-armbru@redhat.com> (raw)
In-Reply-To: <20180702162218.13678-1-armbru@redhat.com>

tests/qmp-test tests an out-of-band command overtaking a slow in-band
command.  To do that, it needs:

1. An in-band command that *reliably* takes long enough to be
   overtaken.

2. An out-of-band command to do the overtaking.

3. To avoid delays, a way to make the in-band command complete quickly
   after it was overtaken.

To satisfy these needs, commit 469638f9cb3 provides the rather
peculiar oob-capable QMP command x-oob-test:

* With "lock": true, it waits for a global semaphore.

* With "lock": false, it signals the global semaphore.

To satisfy 1., the test runs x-oob-test in-band with "lock": true.
To satisfy 2. and 3., it runs x-oob-test out-of-band with "lock": false.

Note that waiting for a semaphore violates the rules for oob-capable
commands.  Running x-oob-test with "lock": true hangs the monitor
until you run x-oob-test with "lock": false on another monitor (which
you might not have set up).

Having an externally visible QMP command that may hang the monitor is
not nice.  Let's apply a little more ingenuity to the problem.  Idea:
have an existing command block on reading a FIFO special file, unblock
it by opening the FIFO for writing.

For 1., use

    {"execute": "blockdev-add",  "id": ID1,
     "arguments": {
        "driver": "blkdebug", "node-name": ID1, "config": FIFO,
        "image": { "driver": "null-co"}}}

where ID1 is an arbitrary string, and FIFO is the name of the FIFO.

For 2., use

    {"execute": "migrate-pause", "id": ID2, "control": {"run-oob": true}}

where ID2 is a different arbitrary string.  Since there's no migration
to pause, the command will fail, but that's fine.

For 3., open FIFO for writing.

Drop QMP command x-oob-test.

Signed-off-by: Markus Armbruster <armbru@redhat.com>
---
 qapi/misc.json   | 18 ----------
 qmp.c            | 16 ---------
 tests/qmp-test.c | 93 ++++++++++++++++++++++++++++++++----------------
 3 files changed, 63 insertions(+), 64 deletions(-)

diff --git a/qapi/misc.json b/qapi/misc.json
index 74cd97f237..f1860418e8 100644
--- a/qapi/misc.json
+++ b/qapi/misc.json
@@ -3472,24 +3472,6 @@
 { 'event': 'COMMAND_DROPPED' ,
   'data': { 'id': 'any', 'reason': 'CommandDropReason' } }
 
-##
-# @x-oob-test:
-#
-# Test OOB functionality.  When sending this command with lock=true,
-# it'll try to hang the dispatcher.  When sending it with lock=false,
-# it'll try to notify the locked thread to continue.  Note: it should
-# only be used by QMP test program rather than anything else.
-#
-# Since: 2.12
-#
-# Example:
-#
-# { "execute": "x-oob-test",
-#   "arguments": { "lock": true } }
-##
-{ 'command': 'x-oob-test', 'data' : { 'lock': 'bool' },
-  'allow-oob': true }
-
 ##
 # @set-numa-node:
 #
diff --git a/qmp.c b/qmp.c
index 73e46d795f..62325ac6aa 100644
--- a/qmp.c
+++ b/qmp.c
@@ -775,19 +775,3 @@ MemoryInfo *qmp_query_memory_size_summary(Error **errp)
 
     return mem_info;
 }
-
-static QemuSemaphore x_oob_test_sem;
-
-static void __attribute__((constructor)) x_oob_test_init(void)
-{
-    qemu_sem_init(&x_oob_test_sem, 0);
-}
-
-void qmp_x_oob_test(bool lock, Error **errp)
-{
-    if (lock) {
-        qemu_sem_wait(&x_oob_test_sem);
-    } else {
-        qemu_sem_post(&x_oob_test_sem);
-    }
-}
diff --git a/tests/qmp-test.c b/tests/qmp-test.c
index 5206b14ca6..b4e54e8970 100644
--- a/tests/qmp-test.c
+++ b/tests/qmp-test.c
@@ -135,16 +135,64 @@ static void test_qmp_protocol(void)
     qtest_quit(qts);
 }
 
-/* Tests for out-of-band support. */
+/* Out-of-band tests */
+
+char tmpdir[] = "/tmp/qmp-test-XXXXXX";
+char *fifo_name;
+
+static void setup_blocking_cmd(void)
+{
+    if (!mkdtemp(tmpdir)) {
+        g_error("mkdtemp: %s", strerror(errno));
+    }
+    fifo_name = g_strdup_printf("%s/fifo", tmpdir);
+    g_assert(!mkfifo(fifo_name, 0666));
+}
+
+static void cleanup_blocking_cmd(void)
+{
+    unlink(fifo_name);
+    rmdir(tmpdir);
+}
+
+static void send_cmd_that_blocks(QTestState *s, const char *id)
+{
+    qtest_async_qmp(s, "{ 'execute': 'blockdev-add',  'id': %s,"
+                    " 'arguments': {"
+                    " 'driver': 'blkdebug', 'node-name': %s,"
+                    " 'config': %s,"
+                    " 'image': { 'driver': 'null-co' } } }",
+                    id, id, fifo_name);
+}
+
+static void unblock_blocked_cmd(void)
+{
+    int fd = open(fifo_name, O_WRONLY);
+    g_assert(fd >= 0);
+    close(fd);
+}
+
+static void send_oob_cmd(QTestState *s, const char *id)
+{
+    qtest_async_qmp(s, "{ 'execute': 'migrate-pause', 'id': %s,"
+                    "  'control': { 'run-oob': true } }", id);
+}
+
+static void recv_cmd_id(QTestState *s, const char *id)
+{
+    QDict *resp = qtest_qmp_receive(s);
+
+    g_assert_cmpstr(qdict_get_try_str(resp, "id"), ==, id);
+    qobject_unref(resp);
+}
+
 static void test_qmp_oob(void)
 {
     QTestState *qts;
     QDict *resp, *q;
-    int acks = 0;
     const QListEntry *entry;
     QList *capabilities;
     QString *qstr;
-    const char *cmd_id;
 
     qts = qtest_init_without_qmp_handshake(true, common_args);
 
@@ -185,37 +233,20 @@ static void test_qmp_oob(void)
     g_assert(qdict_haskey(resp, "error"));
     qobject_unref(resp);
 
-    /*
-     * First send the "x-oob-test" command with lock=true and
-     * oob=false, it should hang the dispatcher and main thread;
-     * later, we send another lock=false with oob=true to continue
-     * that thread processing.  Finally we should receive replies from
-     * both commands.
-     */
-    qtest_async_qmp(qts,
-                    "{ 'execute': 'x-oob-test',"
-                    "  'arguments': { 'lock': true }, "
-                    "  'id': 'lock-cmd'}");
-    qtest_async_qmp(qts,
-                    "{ 'execute': 'x-oob-test', "
-                    "  'arguments': { 'lock': false }, "
-                    "  'control': { 'run-oob': true }, "
-                    "  'id': 'unlock-cmd' }");
-
-    /* Ignore all events.  Wait for 2 acks */
-    while (acks < 2) {
-        resp = qtest_qmp_receive(qts);
-        cmd_id = qdict_get_str(resp, "id");
-        if (!g_strcmp0(cmd_id, "lock-cmd") ||
-            !g_strcmp0(cmd_id, "unlock-cmd")) {
-            acks++;
-        }
-        qobject_unref(resp);
-    }
+    /* OOB command overtakes slow in-band command */
+    setup_blocking_cmd();
+    send_cmd_that_blocks(qts, "ib-blocks-1");
+    send_oob_cmd(qts, "oob-1");
+    recv_cmd_id(qts, "oob-1");
+    unblock_blocked_cmd();
+    recv_cmd_id(qts, "ib-blocks-1");
+    cleanup_blocking_cmd();
 
     qtest_quit(qts);
 }
 
+/* Query smoke tests */
+
 static int query_error_class(const char *cmd)
 {
     static struct {
@@ -392,6 +423,8 @@ static void add_query_tests(QmpSchema *schema)
     }
 }
 
+/* Preconfig tests */
+
 static void test_qmp_preconfig(void)
 {
     QDict *rsp, *ret;
-- 
2.17.1

  parent reply	other threads:[~2018-07-02 16:22 UTC|newest]

Thread overview: 85+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-07-02 16:21 [Qemu-devel] [PATCH 00/32] qmp: Fixes and cleanups around OOB commands Markus Armbruster
2018-07-02 16:21 ` [Qemu-devel] [PATCH 01/32] qmp: Say "out-of-band" instead of "Out-Of-Band" Markus Armbruster
2018-07-02 20:46   ` Eric Blake
2018-07-02 16:21 ` [Qemu-devel] [PATCH 02/32] monitor: Spell "I/O thread" consistently in comments Markus Armbruster
2018-07-02 20:48   ` Eric Blake
2018-07-02 16:21 ` [Qemu-devel] [PATCH 03/32] docs/interop/qmp: Improve OOB documentation Markus Armbruster
2018-07-02 20:54   ` Eric Blake
2018-07-03  6:01     ` Markus Armbruster
2018-07-02 16:21 ` [Qemu-devel] [PATCH 04/32] qmp: Document COMMAND_DROPPED design flaw Markus Armbruster
2018-07-02 20:58   ` Eric Blake
2018-07-02 16:21 ` Markus Armbruster [this message]
2018-07-02 21:08   ` [Qemu-devel] [PATCH 05/32] qmp: Get rid of x-oob-test command Eric Blake
2018-07-03  6:05     ` Markus Armbruster
2018-07-02 16:21 ` [Qemu-devel] [PATCH 06/32] tests/qmp-test: Test in-band command doesn't overtake Markus Armbruster
2018-07-02 21:09   ` Eric Blake
2018-07-02 16:21 ` [Qemu-devel] [PATCH 07/32] qmp: Make "id" optional again even in "oob" monitors Markus Armbruster
2018-07-02 21:13   ` Eric Blake
2018-07-03  6:06     ` Markus Armbruster
2018-07-03  3:36   ` Peter Xu
2018-07-03  6:14     ` Markus Armbruster
2018-07-03  6:24       ` Peter Xu
2018-07-03  9:08       ` Daniel P. Berrangé
2018-07-02 16:21 ` [Qemu-devel] [PATCH 08/32] tests/test-qga: Demonstrate the guest-agent ignores "id" Markus Armbruster
2018-07-02 21:15   ` Eric Blake
2018-07-03  6:27     ` Markus Armbruster
2018-07-02 16:21 ` [Qemu-devel] [PATCH 09/32] qmp qemu-ga: Revert change that accidentally made qemu-ga accept "id" Markus Armbruster
2018-07-02 21:44   ` Eric Blake
2018-07-02 16:21 ` [Qemu-devel] [PATCH 10/32] tests/test-qga: Demonstrate the guest-agent ignores "control" Markus Armbruster
2018-07-03  1:47   ` Eric Blake
2018-07-03  6:29     ` Markus Armbruster
2018-07-02 16:21 ` [Qemu-devel] [PATCH 11/32] qmp qemu-ga: Fix qemu-ga not to accept "control" Markus Armbruster
2018-07-03  1:49   ` Eric Blake
2018-07-02 16:21 ` [Qemu-devel] [PATCH 12/32] qmp: Redo how the client requests out-of-band execution Markus Armbruster
2018-07-03  1:57   ` Eric Blake
2018-07-02 16:21 ` [Qemu-devel] [PATCH 13/32] qmp: Revert change to handle_qmp_command tracepoint Markus Armbruster
2018-07-03  1:58   ` Eric Blake
2018-07-02 16:22 ` [Qemu-devel] [PATCH 14/32] qmp: Always free QMPRequest with qmp_request_free() Markus Armbruster
2018-07-03  2:01   ` Eric Blake
2018-07-03  6:38     ` Markus Armbruster
2018-07-02 16:22 ` [Qemu-devel] [PATCH 15/32] qmp: Simplify code around monitor_qmp_dispatch_one() Markus Armbruster
2018-07-03  2:04   ` Eric Blake
2018-07-02 16:22 ` [Qemu-devel] [PATCH 16/32] tests/qmp-test: Demonstrate QMP errors jumping the queue Markus Armbruster
2018-07-03  2:07   ` Eric Blake
2018-07-03  6:20   ` Peter Xu
2018-07-03  6:54     ` Markus Armbruster
2018-07-02 16:22 ` [Qemu-devel] [PATCH 17/32] qmp: Don't let malformed in-band commands jump " Markus Armbruster
2018-07-03  2:11   ` Eric Blake
2018-07-03  6:46     ` Markus Armbruster
2018-07-02 16:22 ` [Qemu-devel] [PATCH 18/32] qmp: Don't let JSON errors " Markus Armbruster
2018-07-03  2:13   ` Eric Blake
2018-07-02 16:22 ` [Qemu-devel] [PATCH 19/32] monitor: Rename use_io_thr to use_io_thread Markus Armbruster
2018-07-03  2:13   ` Eric Blake
2018-07-02 16:22 ` [Qemu-devel] [PATCH 20/32] monitor: Peel off @mon_global wrapper Markus Armbruster
2018-07-03  2:15   ` Eric Blake
2018-07-02 16:22 ` [Qemu-devel] [PATCH 21/32] qobject: New qdict_from_jsonf_nofail() Markus Armbruster
2018-07-03  2:16   ` Eric Blake
2018-07-02 16:22 ` [Qemu-devel] [PATCH 22/32] qmp: De-duplicate error response building Markus Armbruster
2018-07-03  2:18   ` Eric Blake
2018-07-02 16:22 ` [Qemu-devel] [PATCH 23/32] qmp: Use QDict * instead of QObject * for response objects Markus Armbruster
2018-07-03  2:21   ` Eric Blake
2018-07-02 16:22 ` [Qemu-devel] [PATCH 24/32] qmp: Replace monitor_json_emitter{, raw}() by qmp_{queue, send}_response() Markus Armbruster
2018-07-03  2:25   ` Eric Blake
2018-07-02 16:22 ` [Qemu-devel] [PATCH 25/32] qmp: Replace get_qmp_greeting() by qmp_greeting() Markus Armbruster
2018-07-03  2:26   ` Eric Blake
2018-07-02 16:22 ` [Qemu-devel] [PATCH 26/32] qmp: Simplify monitor_qmp_respond() Markus Armbruster
2018-07-03  2:28   ` Eric Blake
2018-07-02 16:22 ` [Qemu-devel] [PATCH 27/32] qmp: Add some comments around null responses Markus Armbruster
2018-07-03  2:28   ` Eric Blake
2018-07-02 16:22 ` [Qemu-devel] [PATCH 28/32] qmp: Switch timestamp_put() to qdict_from_jsonf_nofail() Markus Armbruster
2018-07-03  2:29   ` Eric Blake
2018-07-02 16:22 ` [Qemu-devel] [PATCH 29/32] qobject: Let qobject_from_jsonf() fail instead of abort Markus Armbruster
2018-07-03  2:30   ` Eric Blake
2018-07-02 16:22 ` [Qemu-devel] [PATCH 30/32] qmp: Clean up capability negotiation after commit 02130314d8c Markus Armbruster
2018-07-03  2:33   ` Eric Blake
2018-07-03  6:50     ` Markus Armbruster
2018-07-02 16:22 ` [Qemu-devel] [PATCH 31/32] monitor: Improve some comments Markus Armbruster
2018-07-03  2:36   ` Eric Blake
2018-07-02 16:22 ` [Qemu-devel] [PATCH 32/32] qapi: Polish command flags documentation in qapi-code-gen.txt Markus Armbruster
2018-07-03  2:38   ` Eric Blake
2018-07-03  5:35 ` [Qemu-devel] [PATCH 00/32] qmp: Fixes and cleanups around OOB commands Markus Armbruster
2018-07-03  6:36 ` Peter Xu
2018-07-03  6:57   ` Markus Armbruster
2018-07-03  7:05 ` Marc-André Lureau
2018-07-03  8:36   ` Markus Armbruster
2018-07-03  9:08     ` Markus Armbruster

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=20180702162218.13678-6-armbru@redhat.com \
    --to=armbru@redhat.com \
    --cc=dgilbert@redhat.com \
    --cc=eblake@redhat.com \
    --cc=peterx@redhat.com \
    --cc=qemu-devel@nongnu.org \
    --cc=stefanha@redhat.com \
    /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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).