aboutsummaryrefslogtreecommitdiff
path: root/blockdev.c
diff options
context:
space:
mode:
authorStefan Hajnoczi <stefanha@redhat.com>2017-12-06 14:45:49 +0000
committerStefan Hajnoczi <stefanha@redhat.com>2017-12-19 10:25:09 +0000
commitca00bbb153d03c5338d8c8136812163f463f841e (patch)
treef19554fdfcb729ab19676835cafea1bb0069ccd5 /blockdev.c
parentfbcc6923b00c2b468a7470fec7863f0403a65736 (diff)
blockdev: add x-blockdev-set-iothread testing command
Currently there is no easy way for iotests to ensure that a BDS is bound to a particular IOThread. Normally the virtio-blk device calls blk_set_aio_context() when dataplane is enabled during guest driver initialization. This never happens in iotests since -machine accel=qtest means there is no guest activity (including device driver initialization). This patch adds a QMP command to explicitly assign IOThreads in test cases. See qapi/block-core.json for a description of the command. Signed-off-by: Stefan Hajnoczi <stefanha@redhat.com> Reviewed-by: Kevin Wolf <kwolf@redhat.com> Reviewed-by: Eric Blake <eblake@redhat.com> Message-id: 20171206144550.22295-9-stefanha@redhat.com Signed-off-by: Stefan Hajnoczi <stefanha@redhat.com>
Diffstat (limited to 'blockdev.c')
-rw-r--r--blockdev.c41
1 files changed, 41 insertions, 0 deletions
diff --git a/blockdev.c b/blockdev.c
index e865ae4873..f75c01f664 100644
--- a/blockdev.c
+++ b/blockdev.c
@@ -45,6 +45,7 @@
#include "qapi/qmp/qerror.h"
#include "qapi/qobject-output-visitor.h"
#include "sysemu/sysemu.h"
+#include "sysemu/iothread.h"
#include "block/block_int.h"
#include "qmp-commands.h"
#include "block/trace.h"
@@ -4129,6 +4130,46 @@ BlockJobInfoList *qmp_query_block_jobs(Error **errp)
return head;
}
+void qmp_x_blockdev_set_iothread(const char *node_name, StrOrNull *iothread,
+ Error **errp)
+{
+ AioContext *old_context;
+ AioContext *new_context;
+ BlockDriverState *bs;
+
+ bs = bdrv_find_node(node_name);
+ if (!bs) {
+ error_setg(errp, "Cannot find node %s", node_name);
+ return;
+ }
+
+ /* If we want to allow more extreme test scenarios this guard could be
+ * removed. For now it protects against accidents. */
+ if (bdrv_has_blk(bs)) {
+ error_setg(errp, "Node %s is in use", node_name);
+ return;
+ }
+
+ if (iothread->type == QTYPE_QSTRING) {
+ IOThread *obj = iothread_by_id(iothread->u.s);
+ if (!obj) {
+ error_setg(errp, "Cannot find iothread %s", iothread->u.s);
+ return;
+ }
+
+ new_context = iothread_get_aio_context(obj);
+ } else {
+ new_context = qemu_get_aio_context();
+ }
+
+ old_context = bdrv_get_aio_context(bs);
+ aio_context_acquire(old_context);
+
+ bdrv_set_aio_context(bs, new_context);
+
+ aio_context_release(old_context);
+}
+
QemuOptsList qemu_common_drive_opts = {
.name = "drive",
.head = QTAILQ_HEAD_INITIALIZER(qemu_common_drive_opts.head),