]> xenbits.xensource.com Git - libvirt.git/commitdiff
conf: disk: Extract verification of disk config
authorPeter Krempa <pkrempa@redhat.com>
Wed, 20 Apr 2016 13:01:44 +0000 (15:01 +0200)
committerPeter Krempa <pkrempa@redhat.com>
Thu, 21 Apr 2016 15:04:06 +0000 (17:04 +0200)
Rather than checking individual fields in dubious places extract them to
a central point.

src/conf/domain_conf.c

index 28248c8873080eb09db880e41072c939cf1ed4a5..3e032e8fa9c5cb88dd8c3f9085af4a1da4e4545e 100644 (file)
@@ -6894,6 +6894,27 @@ virDomainDiskDefGeometryParse(virDomainDiskDefPtr def,
 }
 
 
+static int
+virDomainDiskDefValidate(const virDomainDiskDef *def)
+{
+    if (def->bus != VIR_DOMAIN_DISK_BUS_VIRTIO) {
+        if (def->event_idx != VIR_TRISTATE_SWITCH_ABSENT) {
+            virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s",
+                           _("disk event_idx mode supported only for virtio bus"));
+            return -1;
+        }
+
+        if (def->ioeventfd != VIR_TRISTATE_SWITCH_ABSENT) {
+            virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s",
+                           _("disk ioeventfd mode supported only for virtio bus"));
+            return -1;
+        }
+    }
+
+    return 0;
+}
+
+
 #define VENDOR_LEN  8
 #define PRODUCT_LEN 16
 
@@ -7365,13 +7386,6 @@ virDomainDiskDefParseXML(virDomainXMLOptionPtr xmlopt,
     if (ioeventfd) {
         int val;
 
-        if (def->bus != VIR_DOMAIN_DISK_BUS_VIRTIO) {
-            virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s",
-                           _("disk ioeventfd mode supported "
-                             "only for virtio bus"));
-            goto error;
-        }
-
         if ((val = virTristateSwitchTypeFromString(ioeventfd)) <= 0) {
             virReportError(VIR_ERR_CONFIG_UNSUPPORTED,
                            _("unknown disk ioeventfd mode '%s'"),
@@ -7382,13 +7396,6 @@ virDomainDiskDefParseXML(virDomainXMLOptionPtr xmlopt,
     }
 
     if (event_idx) {
-        if (def->bus != VIR_DOMAIN_DISK_BUS_VIRTIO) {
-            virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s",
-                           _("disk event_idx mode supported "
-                             "only for virtio bus"));
-            goto error;
-        }
-
         int idx;
         if ((idx = virTristateSwitchTypeFromString(event_idx)) <= 0) {
             virReportError(VIR_ERR_CONFIG_UNSUPPORTED,
@@ -7506,6 +7513,9 @@ virDomainDiskDefParseXML(virDomainXMLOptionPtr xmlopt,
             goto error;
     }
 
+    if (virDomainDiskDefValidate(def) < 0)
+        goto error;
+
  cleanup:
     VIR_FREE(bus);
     VIR_FREE(type);