]> xenbits.xensource.com Git - libvirt.git/commitdiff
qemu: command: Refactor blkiotune checks to tolerate NULL qemuCaps
authorPeter Krempa <pkrempa@redhat.com>
Wed, 1 Nov 2017 10:42:06 +0000 (11:42 +0100)
committerPeter Krempa <pkrempa@redhat.com>
Tue, 7 Nov 2017 13:33:23 +0000 (14:33 +0100)
To allow aggregating the checks, refactor the code to check capabilities
only if they were provided.

src/qemu/qemu_command.c

index 62a5baaf751cc3ad2c7cae36c7878f779a600075..6d27237452fc081fdb2befa956772e2ce94e1aec 100644 (file)
@@ -1125,54 +1125,26 @@ qemuDiskConfigBlkdeviotuneHasMaxLength(virDomainDiskDefPtr disk)
 }
 
 
+/**
+ * qemuCheckDiskConfigBlkdeviotune:
+ * @disk: disk configuration
+ * @qemuCaps: qemu capabilities, NULL if checking cold-configuration
+ *
+ * Checks whether block io tuning settings make sense. Returns -1 on error and
+ * reports a proper libvirt error.
+ */
 static int
 qemuCheckDiskConfigBlkdeviotune(virDomainDiskDefPtr disk,
                                 virQEMUCapsPtr qemuCaps)
 {
-    /* block I/O throttling */
-    if (qemuDiskConfigBlkdeviotuneHasBasic(disk) &&
-        !virQEMUCapsGet(qemuCaps, QEMU_CAPS_DRIVE_IOTUNE)) {
-        virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s",
-                       _("block I/O throttling not supported with this "
-                         "QEMU binary"));
-        return -1;
-    }
-
-    /* block I/O throttling 1.7 */
-    if (qemuDiskConfigBlkdeviotuneHasMax(disk) &&
-        !virQEMUCapsGet(qemuCaps, QEMU_CAPS_DRIVE_IOTUNE_MAX)) {
-        virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s",
-                       _("there are some block I/O throttling parameters "
-                         "that are not supported with this QEMU binary"));
-        return -1;
-    }
-
-    /* block I/O group 2.4 */
-    if (disk->blkdeviotune.group_name) {
-        if (!virQEMUCapsGet(qemuCaps, QEMU_CAPS_DRIVE_IOTUNE_GROUP)) {
-            virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s",
-                           _("the block I/O throttling group parameter is "
-                             "not supported with this QEMU binary"));
-            return -1;
-        }
-
-        /* group_name by itself is ignored by qemu */
-        if (!qemuDiskConfigBlkdeviotuneHasBasic(disk) &&
-            !qemuDiskConfigBlkdeviotuneHasMax(disk) &&
-            !qemuDiskConfigBlkdeviotuneHasMaxLength(disk)) {
-            virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s",
-                           _("group_name can be configured only together with "
-                             "settings"));
-            return -1;
-        }
-    }
-
-    /* block I/O throttling length 2.6 */
-    if (qemuDiskConfigBlkdeviotuneHasMaxLength(disk) &&
-        !virQEMUCapsGet(qemuCaps, QEMU_CAPS_DRIVE_IOTUNE_MAX_LENGTH)) {
+    /* group_name by itself is ignored by qemu */
+    if (disk->blkdeviotune.group_name &&
+        !qemuDiskConfigBlkdeviotuneHasBasic(disk) &&
+        !qemuDiskConfigBlkdeviotuneHasMax(disk) &&
+        !qemuDiskConfigBlkdeviotuneHasMaxLength(disk)) {
         virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s",
-                       _("there are some block I/O throttling length parameters "
-                         "that are not supported with this QEMU binary"));
+                       _("group_name can be configured only together with "
+                         "settings"));
         return -1;
     }
 
@@ -1195,6 +1167,44 @@ qemuCheckDiskConfigBlkdeviotune(virDomainDiskDefPtr disk,
         return -1;
     }
 
+    if (qemuCaps) {
+        /* block I/O throttling */
+        if (qemuDiskConfigBlkdeviotuneHasBasic(disk) &&
+            !virQEMUCapsGet(qemuCaps, QEMU_CAPS_DRIVE_IOTUNE)) {
+            virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s",
+                           _("block I/O throttling not supported with this "
+                             "QEMU binary"));
+            return -1;
+        }
+
+        /* block I/O throttling 1.7 */
+        if (qemuDiskConfigBlkdeviotuneHasMax(disk) &&
+            !virQEMUCapsGet(qemuCaps, QEMU_CAPS_DRIVE_IOTUNE_MAX)) {
+            virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s",
+                           _("there are some block I/O throttling parameters "
+                             "that are not supported with this QEMU binary"));
+            return -1;
+        }
+
+        /* block I/O group 2.4 */
+        if (disk->blkdeviotune.group_name &&
+            !virQEMUCapsGet(qemuCaps, QEMU_CAPS_DRIVE_IOTUNE_GROUP)) {
+            virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s",
+                           _("the block I/O throttling group parameter is "
+                             "not supported with this QEMU binary"));
+            return -1;
+        }
+
+        /* block I/O throttling length 2.6 */
+        if (qemuDiskConfigBlkdeviotuneHasMaxLength(disk) &&
+            !virQEMUCapsGet(qemuCaps, QEMU_CAPS_DRIVE_IOTUNE_MAX_LENGTH)) {
+            virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s",
+                           _("there are some block I/O throttling length parameters "
+                             "that are not supported with this QEMU binary"));
+            return -1;
+        }
+    }
+
     return 0;
 }