thebeanogamer / rpms / qemu-kvm

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