[PATCH 18/25] conf: domain: Convert virDomainDiskDef's 'removable' to virTristateSwitch

Peter Krempa pkrempa at redhat.com
Fri Apr 16 15:34:36 UTC 2021


Use the appropriate type for the variable and refactor the XML parser to
parse it correctly using virXMLPropEnum.

Signed-off-by: Peter Krempa <pkrempa at redhat.com>
---
 src/conf/domain_conf.c | 15 +++++----------
 src/conf/domain_conf.h |  2 +-
 2 files changed, 6 insertions(+), 11 deletions(-)

diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c
index ff408188d5..5e27ca6265 100644
--- a/src/conf/domain_conf.c
+++ b/src/conf/domain_conf.c
@@ -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,
diff --git a/src/conf/domain_conf.h b/src/conf/domain_conf.h
index cb5ce68fdb..878ba4c961 100644
--- a/src/conf/domain_conf.h
+++ b/src/conf/domain_conf.h
@@ -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;
-- 
2.30.2




More information about the libvir-list mailing list