Blame SOURCES/kvm-blockdev-add-x-blockdev-set-iothread-testing-command.patch

9bac43
From 0ee9b6146fd9b451c21f3428fb363d5e659693b7 Mon Sep 17 00:00:00 2001
9bac43
From: Stefan Hajnoczi <stefanha@redhat.com>
9bac43
Date: Fri, 22 Dec 2017 11:08:55 +0100
9bac43
Subject: [PATCH 37/42] blockdev: add x-blockdev-set-iothread testing command
9bac43
9bac43
RH-Author: Stefan Hajnoczi <stefanha@redhat.com>
9bac43
Message-id: <20171222110900.24813-16-stefanha@redhat.com>
9bac43
Patchwork-id: 78494
9bac43
O-Subject: [RHV7.5 qemu-kvm-rhev PATCH 15/20] blockdev: add x-blockdev-set-iothread testing command
9bac43
Bugzilla: 1519721
9bac43
RH-Acked-by: Paolo Bonzini <pbonzini@redhat.com>
9bac43
RH-Acked-by: Jeffrey Cody <jcody@redhat.com>
9bac43
RH-Acked-by: Miroslav Rezanina <mrezanin@redhat.com>
9bac43
9bac43
Currently there is no easy way for iotests to ensure that a BDS is bound
9bac43
to a particular IOThread.  Normally the virtio-blk device calls
9bac43
blk_set_aio_context() when dataplane is enabled during guest driver
9bac43
initialization.  This never happens in iotests since -machine
9bac43
accel=qtest means there is no guest activity (including device driver
9bac43
initialization).
9bac43
9bac43
This patch adds a QMP command to explicitly assign IOThreads in test
9bac43
cases.  See qapi/block-core.json for a description of the command.
9bac43
9bac43
Signed-off-by: Stefan Hajnoczi <stefanha@redhat.com>
9bac43
Reviewed-by: Kevin Wolf <kwolf@redhat.com>
9bac43
Reviewed-by: Eric Blake <eblake@redhat.com>
9bac43
Message-id: 20171206144550.22295-9-stefanha@redhat.com
9bac43
Signed-off-by: Stefan Hajnoczi <stefanha@redhat.com>
9bac43
(cherry picked from commit ca00bbb153d03c5338d8c8136812163f463f841e)
9bac43
Signed-off-by: Stefan Hajnoczi <stefanha@redhat.com>
9bac43
Signed-off-by: Miroslav Rezanina <mrezanin@redhat.com>
9bac43
---
9bac43
 blockdev.c           | 41 +++++++++++++++++++++++++++++++++++++++++
9bac43
 qapi/block-core.json | 36 ++++++++++++++++++++++++++++++++++++
9bac43
 2 files changed, 77 insertions(+)
9bac43
9bac43
diff --git a/blockdev.c b/blockdev.c
9bac43
index f118444..6cbe627 100644
9bac43
--- a/blockdev.c
9bac43
+++ b/blockdev.c
9bac43
@@ -46,6 +46,7 @@
9bac43
 #include "qapi/qobject-output-visitor.h"
9bac43
 #include "qapi/util.h"
9bac43
 #include "sysemu/sysemu.h"
9bac43
+#include "sysemu/iothread.h"
9bac43
 #include "block/block_int.h"
9bac43
 #include "qmp-commands.h"
9bac43
 #include "block/trace.h"
9bac43
@@ -4190,6 +4191,46 @@ BlockJobInfoList *qmp_query_block_jobs(Error **errp)
9bac43
     return head;
9bac43
 }
9bac43
 
9bac43
+void qmp_x_blockdev_set_iothread(const char *node_name, StrOrNull *iothread,
9bac43
+                                 Error **errp)
9bac43
+{
9bac43
+    AioContext *old_context;
9bac43
+    AioContext *new_context;
9bac43
+    BlockDriverState *bs;
9bac43
+
9bac43
+    bs = bdrv_find_node(node_name);
9bac43
+    if (!bs) {
9bac43
+        error_setg(errp, "Cannot find node %s", node_name);
9bac43
+        return;
9bac43
+    }
9bac43
+
9bac43
+    /* If we want to allow more extreme test scenarios this guard could be
9bac43
+     * removed.  For now it protects against accidents. */
9bac43
+    if (bdrv_has_blk(bs)) {
9bac43
+        error_setg(errp, "Node %s is in use", node_name);
9bac43
+        return;
9bac43
+    }
9bac43
+
9bac43
+    if (iothread->type == QTYPE_QSTRING) {
9bac43
+        IOThread *obj = iothread_by_id(iothread->u.s);
9bac43
+        if (!obj) {
9bac43
+            error_setg(errp, "Cannot find iothread %s", iothread->u.s);
9bac43
+            return;
9bac43
+        }
9bac43
+
9bac43
+        new_context = iothread_get_aio_context(obj);
9bac43
+    } else {
9bac43
+        new_context = qemu_get_aio_context();
9bac43
+    }
9bac43
+
9bac43
+    old_context = bdrv_get_aio_context(bs);
9bac43
+    aio_context_acquire(old_context);
9bac43
+
9bac43
+    bdrv_set_aio_context(bs, new_context);
9bac43
+
9bac43
+    aio_context_release(old_context);
9bac43
+}
9bac43
+
9bac43
 QemuOptsList qemu_common_drive_opts = {
9bac43
     .name = "drive",
9bac43
     .head = QTAILQ_HEAD_INITIALIZER(qemu_common_drive_opts.head),
9bac43
diff --git a/qapi/block-core.json b/qapi/block-core.json
9bac43
index 15fc08f..d579c99 100644
9bac43
--- a/qapi/block-core.json
9bac43
+++ b/qapi/block-core.json
9bac43
@@ -3882,3 +3882,39 @@
9bac43
   'data' : { 'parent': 'str',
9bac43
              '*child': 'str',
9bac43
              '*node': 'str' } }
9bac43
+
9bac43
+##
9bac43
+# @x-blockdev-set-iothread:
9bac43
+#
9bac43
+# Move @node and its children into the @iothread.  If @iothread is null then
9bac43
+# move @node and its children into the main loop.
9bac43
+#
9bac43
+# The node must not be attached to a BlockBackend.
9bac43
+#
9bac43
+# @node-name: the name of the block driver node
9bac43
+#
9bac43
+# @iothread: the name of the IOThread object or null for the main loop
9bac43
+#
9bac43
+# Note: this command is experimental and intended for test cases that need
9bac43
+# control over IOThreads only.
9bac43
+#
9bac43
+# Since: 2.12
9bac43
+#
9bac43
+# Example:
9bac43
+#
9bac43
+# 1. Move a node into an IOThread
9bac43
+# -> { "execute": "x-blockdev-set-iothread",
9bac43
+#      "arguments": { "node-name": "disk1",
9bac43
+#                     "iothread": "iothread0" } }
9bac43
+# <- { "return": {} }
9bac43
+#
9bac43
+# 2. Move a node into the main loop
9bac43
+# -> { "execute": "x-blockdev-set-iothread",
9bac43
+#      "arguments": { "node-name": "disk1",
9bac43
+#                     "iothread": null } }
9bac43
+# <- { "return": {} }
9bac43
+#
9bac43
+##
9bac43
+{ 'command': 'x-blockdev-set-iothread',
9bac43
+  'data' : { 'node-name': 'str',
9bac43
+             'iothread': 'StrOrNull' } }
9bac43
-- 
9bac43
1.8.3.1
9bac43