]> git.ipfire.org Git - thirdparty/libvirt.git/commitdiff
conf: domain: Convert virDomainDiskDef's 'startupPolicy' to virDomainStartupPolicy
authorPeter Krempa <pkrempa@redhat.com>
Fri, 16 Apr 2021 08:46:00 +0000 (10:46 +0200)
committerPeter Krempa <pkrempa@redhat.com>
Fri, 16 Apr 2021 15:28:06 +0000 (17:28 +0200)
Use the appropriate type for the variable and refactor the XML parser to
parse it correctly using virXMLPropEnum.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Tim Wiederhake <twiederh@redhat.com>
src/conf/domain_conf.c
src/conf/domain_conf.h

index 0128c9d480def325e8d39620146433fc5613ed4e..17bbeddec600a72f053af8289ee340df95bcf303 100644 (file)
@@ -9343,7 +9343,6 @@ virDomainDiskDefParseXML(virDomainXMLOption *xmlopt,
     g_autofree char *target = NULL;
     g_autofree char *bus = NULL;
     g_autofree char *serial = NULL;
-    g_autofree char *startupPolicy = NULL;
     g_autofree char *removable = NULL;
     g_autofree char *logical_block_size = NULL;
     g_autofree char *physical_block_size = NULL;
@@ -9401,7 +9400,11 @@ virDomainDiskDefParseXML(virDomainXMLOption *xmlopt,
 
             source = true;
 
-            startupPolicy = virXMLPropString(cur, "startupPolicy");
+            if (virXMLPropEnum(cur, "startupPolicy",
+                               virDomainStartupPolicyTypeFromString,
+                               VIR_XML_PROP_OPTIONAL | VIR_XML_PROP_NONZERO,
+                               &def->startupPolicy) < 0)
+                return NULL;
 
             if (!(flags & VIR_DOMAIN_DEF_PARSE_INACTIVE) &&
                 (tmp = virXMLPropString(cur, "index")) &&
@@ -9655,18 +9658,6 @@ virDomainDiskDefParseXML(virDomainXMLOption *xmlopt,
         return NULL;
     }
 
-    if (startupPolicy) {
-        int val;
-
-        if ((val = virDomainStartupPolicyTypeFromString(startupPolicy)) <= 0) {
-            virReportError(VIR_ERR_CONFIG_UNSUPPORTED,
-                           _("unknown startupPolicy value '%s'"),
-                           startupPolicy);
-            return NULL;
-        }
-        def->startupPolicy = val;
-    }
-
     def->dst = g_steal_pointer(&target);
     if (authdef) {
             /* If we've already parsed <source> and found an <auth> child,
index 2f8ef7402092713fdd9baade7315ef5331d3c51f..99ab2a96d9415d955a22439d3c60a42bf48ba1ba 100644 (file)
@@ -573,7 +573,7 @@ struct _virDomainDiskDef {
     virTristateSwitch event_idx;
     virTristateSwitch copy_on_read;
     int snapshot; /* virDomainSnapshotLocation, snapshot_conf.h */
-    int startupPolicy; /* enum virDomainStartupPolicy */
+    virDomainStartupPolicy startupPolicy;
     bool transient;
     virDomainDeviceInfo info;
     int rawio; /* enum virTristateBool */