[PATCH RFC 03/39] qemu: monitor: Allow using 'qdev' instead of 'device' for getting disk throttling

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



The 'device' field reported by 'query-block' is empty when -blockdev is
used. Add an argument which will allow matching disk by using the qdev
id so we can use this code with -blockdev.

Signed-off-by: Peter Krempa <pkrempa@xxxxxxxxxx>
---
 src/qemu/qemu_driver.c       |  2 +-
 src/qemu/qemu_monitor.c      |  8 +++++---
 src/qemu/qemu_monitor.h      |  3 ++-
 src/qemu/qemu_monitor_json.c | 21 ++++++++++++++-------
 src/qemu/qemu_monitor_json.h |  3 ++-
 tests/qemumonitorjsontest.c  |  2 +-
 6 files changed, 25 insertions(+), 14 deletions(-)

diff --git a/src/qemu/qemu_driver.c b/src/qemu/qemu_driver.c
index ae762a3189..b81ad7cdbc 100644
--- a/src/qemu/qemu_driver.c
+++ b/src/qemu/qemu_driver.c
@@ -18623,7 +18623,7 @@ qemuDomainGetBlockIoTune(virDomainPtr dom,
         if (!(device = qemuAliasDiskDriveFromDisk(disk)))
             goto endjob;
         qemuDomainObjEnterMonitor(driver, vm);
-        ret = qemuMonitorGetBlockIoThrottle(priv->mon, device, &reply);
+        ret = qemuMonitorGetBlockIoThrottle(priv->mon, device, NULL, &reply);
         if (qemuDomainObjExitMonitor(driver, vm) < 0)
             goto endjob;
         if (ret < 0)
diff --git a/src/qemu/qemu_monitor.c b/src/qemu/qemu_monitor.c
index 84310ff8ca..ac9cde4577 100644
--- a/src/qemu/qemu_monitor.c
+++ b/src/qemu/qemu_monitor.c
@@ -3469,14 +3469,16 @@ qemuMonitorSetBlockIoThrottle(qemuMonitorPtr mon,

 int
 qemuMonitorGetBlockIoThrottle(qemuMonitorPtr mon,
-                              const char *device,
+                              const char *drivealias,
+                              const char *qdevid,
                               virDomainBlockIoTuneInfoPtr reply)
 {
-    VIR_DEBUG("device=%p, reply=%p", device, reply);
+    VIR_DEBUG("drivealias=%s, qdevid=%s, reply=%p",
+              NULLSTR(drivealias), NULLSTR(qdevid), reply);

     QEMU_CHECK_MONITOR(mon);

-    return qemuMonitorJSONGetBlockIoThrottle(mon, device, reply);
+    return qemuMonitorJSONGetBlockIoThrottle(mon, drivealias, qdevid, reply);
 }


diff --git a/src/qemu/qemu_monitor.h b/src/qemu/qemu_monitor.h
index 01860f11f4..a25b1f54ea 100644
--- a/src/qemu/qemu_monitor.h
+++ b/src/qemu/qemu_monitor.h
@@ -941,7 +941,8 @@ int qemuMonitorSetBlockIoThrottle(qemuMonitorPtr mon,
                                   bool supportMaxLengthOptions);

 int qemuMonitorGetBlockIoThrottle(qemuMonitorPtr mon,
-                                  const char *device,
+                                  const char *drivealias,
+                                  const char *qdevid,
                                   virDomainBlockIoTuneInfoPtr reply);

 int qemuMonitorSystemWakeup(qemuMonitorPtr mon);
diff --git a/src/qemu/qemu_monitor_json.c b/src/qemu/qemu_monitor_json.c
index fc65198f6f..f33535327c 100644
--- a/src/qemu/qemu_monitor_json.c
+++ b/src/qemu/qemu_monitor_json.c
@@ -4834,7 +4834,8 @@ int qemuMonitorJSONOpenGraphics(qemuMonitorPtr mon,
     }
 static int
 qemuMonitorJSONBlockIoThrottleInfo(virJSONValuePtr io_throttle,
-                                   const char *device,
+                                   const char *drivealias,
+                                   const char *qdevid,
                                    virDomainBlockIoTuneInfoPtr reply)
 {
     int ret = -1;
@@ -4844,7 +4845,8 @@ qemuMonitorJSONBlockIoThrottleInfo(virJSONValuePtr io_throttle,
     for (i = 0; i < virJSONValueArraySize(io_throttle); i++) {
         virJSONValuePtr temp_dev = virJSONValueArrayGet(io_throttle, i);
         virJSONValuePtr inserted;
-        const char *current_dev;
+        const char *current_drive;
+        const char *current_qdev;

         if (!temp_dev || virJSONValueGetType(temp_dev) != VIR_JSON_TYPE_OBJECT) {
             virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
@@ -4853,14 +4855,18 @@ qemuMonitorJSONBlockIoThrottleInfo(virJSONValuePtr io_throttle,
             goto cleanup;
         }

-        if (!(current_dev = virJSONValueObjectGetString(temp_dev, "device"))) {
+        current_qdev = virJSONValueObjectGetString(temp_dev, "qdev");
+        current_drive = virJSONValueObjectGetString(temp_dev, "device");
+
+        if (!current_drive && !current_qdev) {
             virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
                            _("block_io_throttle device entry "
                              "was not in expected format"));
             goto cleanup;
         }

-        if (STRNEQ(current_dev, device))
+        if ((drivealias && STRNEQ(current_drive, drivealias)) ||
+            (qdevid && STRNEQ(current_qdev, qdevid)))
             continue;

         found = true;
@@ -4901,7 +4907,7 @@ qemuMonitorJSONBlockIoThrottleInfo(virJSONValuePtr io_throttle,
     if (!found) {
         virReportError(VIR_ERR_INTERNAL_ERROR,
                        _("cannot find throttling info for device '%s'"),
-                       device);
+                       drivealias ? drivealias : qdevid);
         goto cleanup;
     }
     ret = 0;
@@ -5012,7 +5018,8 @@ int qemuMonitorJSONSetBlockIoThrottle(qemuMonitorPtr mon,
 }

 int qemuMonitorJSONGetBlockIoThrottle(qemuMonitorPtr mon,
-                                      const char *device,
+                                      const char *drivealias,
+                                      const char *qdevid,
                                       virDomainBlockIoTuneInfoPtr reply)
 {
     int ret = -1;
@@ -5021,7 +5028,7 @@ int qemuMonitorJSONGetBlockIoThrottle(qemuMonitorPtr mon,
     if (!(devices = qemuMonitorJSONQueryBlock(mon)))
         return -1;

-    ret = qemuMonitorJSONBlockIoThrottleInfo(devices, device, reply);
+    ret = qemuMonitorJSONBlockIoThrottleInfo(devices, drivealias, qdevid, reply);
     virJSONValueFree(devices);
     return ret;
 }
diff --git a/src/qemu/qemu_monitor_json.h b/src/qemu/qemu_monitor_json.h
index 5b5defc3f5..78bc16582e 100644
--- a/src/qemu/qemu_monitor_json.h
+++ b/src/qemu/qemu_monitor_json.h
@@ -336,7 +336,8 @@ int qemuMonitorJSONSetBlockIoThrottle(qemuMonitorPtr mon,
                                       bool supportMaxLengthOptions);

 int qemuMonitorJSONGetBlockIoThrottle(qemuMonitorPtr mon,
-                                      const char *device,
+                                      const char *drivealias,
+                                      const char *qdevid,
                                       virDomainBlockIoTuneInfoPtr reply);

 int qemuMonitorJSONSystemWakeup(qemuMonitorPtr mon);
diff --git a/tests/qemumonitorjsontest.c b/tests/qemumonitorjsontest.c
index e1f4c27a63..6a3d16db71 100644
--- a/tests/qemumonitorjsontest.c
+++ b/tests/qemumonitorjsontest.c
@@ -2123,7 +2123,7 @@ testQemuMonitorJSONqemuMonitorJSONSetBlockIoThrottle(const void *data)
         goto cleanup;

     if (qemuMonitorJSONGetBlockIoThrottle(qemuMonitorTestGetMonitor(test),
-                                          "drive-virtio-disk0", &info) < 0)
+                                          "drive-virtio-disk0", NULL, &info) < 0)
         goto cleanup;

     if (testValidateGetBlockIoThrottle(&info, &expectedInfo) < 0)
-- 
2.16.2

--
libvir-list mailing list
libvir-list@xxxxxxxxxx
https://www.redhat.com/mailman/listinfo/libvir-list



[Index of Archives]     [Virt Tools]     [Libvirt Users]     [Lib OS Info]     [Fedora Users]     [Fedora Desktop]     [Fedora SELinux]     [Big List of Linux Books]     [Yosemite News]     [KDE Users]     [Fedora Tools]

  Powered by Linux