thebeanogamer / rpms / qemu-kvm

Forked from rpms/qemu-kvm 5 months ago
Clone
ddf19c
From cebc614e5ddd1f770c4d6dc26c066791f36e56df Mon Sep 17 00:00:00 2001
ddf19c
From: Kevin Wolf <kwolf@redhat.com>
ddf19c
Date: Fri, 7 Feb 2020 11:24:02 +0000
ddf19c
Subject: [PATCH 05/18] hmp: Allow using qdev ID for qemu-io command
ddf19c
ddf19c
RH-Author: Kevin Wolf <kwolf@redhat.com>
ddf19c
Message-id: <20200207112404.25198-5-kwolf@redhat.com>
ddf19c
Patchwork-id: 93750
ddf19c
O-Subject: [RHEL-AV-8.2.0 qemu-kvm PATCH v2 4/6] hmp: Allow using qdev ID for qemu-io command
ddf19c
Bugzilla: 1781637
ddf19c
RH-Acked-by: Sergio Lopez Pascual <slp@redhat.com>
ddf19c
RH-Acked-by: Max Reitz <mreitz@redhat.com>
ddf19c
RH-Acked-by: Stefan Hajnoczi <stefanha@redhat.com>
ddf19c
ddf19c
In order to issue requests on an existing BlockBackend with the
ddf19c
'qemu-io' HMP command, allow specifying the BlockBackend not only with a
ddf19c
BlockBackend name, but also with a qdev ID/QOM path for a device that
ddf19c
owns the (possibly anonymous) BlockBackend.
ddf19c
ddf19c
Because qdev names could be conflicting with BlockBackend and node
ddf19c
names, introduce a -d option to explicitly address a device. If the
ddf19c
option is not given, a BlockBackend or a node is addressed.
ddf19c
ddf19c
Signed-off-by: Kevin Wolf <kwolf@redhat.com>
ddf19c
(cherry picked from commit 89b6fc45614bb45dcd58f1590415afe5c2791abd)
ddf19c
Signed-off-by: Kevin Wolf <kwolf@redhat.com>
ddf19c
Signed-off-by: Danilo C. L. de Paula <ddepaula@redhat.com>
ddf19c
---
ddf19c
 hmp-commands.hx    |  8 +++++---
ddf19c
 monitor/hmp-cmds.c | 28 ++++++++++++++++++----------
ddf19c
 2 files changed, 23 insertions(+), 13 deletions(-)
ddf19c
ddf19c
diff --git a/hmp-commands.hx b/hmp-commands.hx
ddf19c
index cfcc044..dc23185 100644
ddf19c
--- a/hmp-commands.hx
ddf19c
+++ b/hmp-commands.hx
ddf19c
@@ -1875,9 +1875,11 @@ ETEXI
ddf19c
 
ddf19c
     {
ddf19c
         .name       = "qemu-io",
ddf19c
-        .args_type  = "device:B,command:s",
ddf19c
-        .params     = "[device] \"[command]\"",
ddf19c
-        .help       = "run a qemu-io command on a block device",
ddf19c
+        .args_type  = "qdev:-d,device:B,command:s",
ddf19c
+        .params     = "[-d] [device] \"[command]\"",
ddf19c
+        .help       = "run a qemu-io command on a block device\n\t\t\t"
ddf19c
+                      "-d: [device] is a device ID rather than a "
ddf19c
+                      "drive ID or node name",
ddf19c
         .cmd        = hmp_qemu_io,
ddf19c
     },
ddf19c
 
ddf19c
diff --git a/monitor/hmp-cmds.c b/monitor/hmp-cmds.c
ddf19c
index b2551c1..5f8941d 100644
ddf19c
--- a/monitor/hmp-cmds.c
ddf19c
+++ b/monitor/hmp-cmds.c
ddf19c
@@ -2468,23 +2468,31 @@ void hmp_qemu_io(Monitor *mon, const QDict *qdict)
ddf19c
 {
ddf19c
     BlockBackend *blk;
ddf19c
     BlockBackend *local_blk = NULL;
ddf19c
+    bool qdev = qdict_get_try_bool(qdict, "qdev", false);
ddf19c
     const char* device = qdict_get_str(qdict, "device");
ddf19c
     const char* command = qdict_get_str(qdict, "command");
ddf19c
     Error *err = NULL;
ddf19c
     int ret;
ddf19c
 
ddf19c
-    blk = blk_by_name(device);
ddf19c
-    if (!blk) {
ddf19c
-        BlockDriverState *bs = bdrv_lookup_bs(NULL, device, &err;;
ddf19c
-        if (bs) {
ddf19c
-            blk = local_blk = blk_new(bdrv_get_aio_context(bs),
ddf19c
-                                      0, BLK_PERM_ALL);
ddf19c
-            ret = blk_insert_bs(blk, bs, &err;;
ddf19c
-            if (ret < 0) {
ddf19c
+    if (qdev) {
ddf19c
+        blk = blk_by_qdev_id(device, &err;;
ddf19c
+        if (!blk) {
ddf19c
+            goto fail;
ddf19c
+        }
ddf19c
+    } else {
ddf19c
+        blk = blk_by_name(device);
ddf19c
+        if (!blk) {
ddf19c
+            BlockDriverState *bs = bdrv_lookup_bs(NULL, device, &err;;
ddf19c
+            if (bs) {
ddf19c
+                blk = local_blk = blk_new(bdrv_get_aio_context(bs),
ddf19c
+                                          0, BLK_PERM_ALL);
ddf19c
+                ret = blk_insert_bs(blk, bs, &err;;
ddf19c
+                if (ret < 0) {
ddf19c
+                    goto fail;
ddf19c
+                }
ddf19c
+            } else {
ddf19c
                 goto fail;
ddf19c
             }
ddf19c
-        } else {
ddf19c
-            goto fail;
ddf19c
         }
ddf19c
     }
ddf19c
 
ddf19c
-- 
ddf19c
1.8.3.1
ddf19c