]> git.ipfire.org Git - thirdparty/libvirt.git/commitdiff
qemu: monitor: Allow using 'qdev' instead of 'device' for getting disk throttling
authorPeter Krempa <pkrempa@redhat.com>
Wed, 25 Jul 2018 13:14:43 +0000 (15:14 +0200)
committerPeter Krempa <pkrempa@redhat.com>
Tue, 21 Aug 2018 13:46:06 +0000 (15:46 +0200)
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@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
src/qemu/qemu_driver.c
src/qemu/qemu_monitor.c
src/qemu/qemu_monitor.h
src/qemu/qemu_monitor_json.c
src/qemu/qemu_monitor_json.h
tests/qemumonitorjsontest.c

index 743da37b6f4c28981a0e2f8c4735c447fec2348f..469c6539d4f424e042389f6f6d91581e22ae5253 100644 (file)
@@ -18601,7 +18601,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)
index 2902c3b246e46e5a30c0c6785ace6fa085145f0d..758942ffcbeea6ba9025b24886b594ab86b88dd3 100644 (file)
@@ -3465,14 +3465,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);
 }
 
 
index 16fc75819ffdc5fbf47da6bf7b0f7165f83f462f..60418422e970de79a2abeb46e1eb22397d43256e 100644 (file)
@@ -940,7 +940,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);
index 8a70d3816990b98e7bd31be85bad22cc5159a220..bdbe003d32ed8c67b8431bf1193c43692245b388 100644 (file)
@@ -4818,7 +4818,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;
@@ -4828,7 +4829,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",
@@ -4837,14 +4839,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;
@@ -4885,7 +4891,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;
@@ -4996,7 +5002,8 @@ int qemuMonitorJSONSetBlockIoThrottle(qemuMonitorPtr mon,
 }
 
 int qemuMonitorJSONGetBlockIoThrottle(qemuMonitorPtr mon,
-                                      const char *device,
+                                      const char *drivealias,
+                                      const char *qdevid,
                                       virDomainBlockIoTuneInfoPtr reply)
 {
     int ret = -1;
@@ -5005,7 +5012,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;
 }
index 47635f14b173b0417fa5202db6400ef2ee7ca3f8..4d75e0418322117460c13d6b5a4d4b90139287f0 100644 (file)
@@ -335,7 +335,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);
index b39d8cd0b86e27fd8816dd863227714ac2213b3a..35d24cfb2294f17558a62cb8af1be405bc0614b4 100644 (file)
@@ -2139,7 +2139,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)