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

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