cryptospore / rpms / qemu-kvm

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