]> git.ipfire.org Git - thirdparty/libvirt.git/commitdiff
conf: domain: Convert virDomainDiskDef's 'removable' to virTristateSwitch
authorPeter Krempa <pkrempa@redhat.com>
Fri, 16 Apr 2021 08:46:00 +0000 (10:46 +0200)
committerPeter Krempa <pkrempa@redhat.com>
Mon, 19 Apr 2021 12:43:59 +0000 (14:43 +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: Michal Privoznik <mprivozn@redhat.com>
src/conf/domain_conf.c
src/conf/domain_conf.h

index ff408188d52634e66d0c8fabe8333c56a2bec21d..5e27ca6265e3e5ccf05301d53e4ba77025bbd355 100644 (file)
@@ -9319,7 +9319,6 @@ virDomainDiskDefParseXML(virDomainXMLOption *xmlopt,
     g_autofree char *target = NULL;
     g_autofree char *bus = NULL;
     g_autofree char *serial = NULL;
-    g_autofree char *removable = NULL;
     g_autofree char *logical_block_size = NULL;
     g_autofree char *physical_block_size = NULL;
     g_autofree char *wwn = NULL;
@@ -9381,7 +9380,11 @@ virDomainDiskDefParseXML(virDomainXMLOption *xmlopt,
             if (virXMLPropEnum(cur, "tray", virDomainDiskTrayTypeFromString,
                                VIR_XML_PROP_OPTIONAL, &def->tray_status) < 0)
                 return NULL;
-            removable = virXMLPropString(cur, "removable");
+
+            if (virXMLPropTristateSwitch(cur, "removable", VIR_XML_PROP_OPTIONAL,
+                                         &def->removable) < 0)
+                return NULL;
+
             rotation_rate = virXMLPropString(cur, "rotation_rate");
         } else if (!domain_name &&
                    virXMLNodeNameEqual(cur, "backenddomain")) {
@@ -9495,14 +9498,6 @@ virDomainDiskDefParseXML(virDomainXMLOption *xmlopt,
         }
     }
 
-    if (removable) {
-        if ((def->removable = virTristateSwitchTypeFromString(removable)) < 0) {
-            virReportError(VIR_ERR_CONFIG_UNSUPPORTED,
-                           _("unknown disk removable status '%s'"), removable);
-            return NULL;
-        }
-    }
-
     if (rotation_rate &&
         virStrToLong_ui(rotation_rate, NULL, 10, &def->rotation_rate) < 0) {
         virReportError(VIR_ERR_INTERNAL_ERROR,
index cb5ce68fdbad284758e79b06054e496f3a92f43e..878ba4c961e025e74bcc83c08d26a45835100be2 100644 (file)
@@ -539,7 +539,7 @@ struct _virDomainDiskDef {
     int bus; /* enum virDomainDiskBus */
     char *dst;
     virDomainDiskTray tray_status;
-    int removable; /* enum virTristateSwitch */
+    virTristateSwitch removable;
     unsigned int rotation_rate;
 
     virStorageSource *mirror;