[PATCH 09/12] conf: Convert virDomainFSDefParseXML() to virXMLProp*()

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



After previous cleanups, the virDomainFSDefParseXML() function
uses a mixture of virXMLProp*() and the old virXMLPropString() +
virXXXTypeFromString() patterns. Rework it so that virXMLProp*()
is used.

Signed-off-by: Michal Privoznik <mprivozn@xxxxxxxxxx>
---
 src/bhyve/bhyve_command.c      |   2 +-
 src/conf/domain_conf.c         | 127 +++++++++++++--------------------
 src/conf/domain_conf.h         |  10 +--
 src/lxc/lxc_container.c        |   3 +
 src/qemu/qemu_domain_address.c |   2 +-
 5 files changed, 60 insertions(+), 84 deletions(-)

diff --git a/src/bhyve/bhyve_command.c b/src/bhyve/bhyve_command.c
index 3368d20a04..af8ec30fe7 100644
--- a/src/bhyve/bhyve_command.c
+++ b/src/bhyve/bhyve_command.c
@@ -577,7 +577,7 @@ bhyveBuildFSArgStr(const virDomainDef *def G_GNUC_UNUSED,
 {
     g_auto(virBuffer) params = VIR_BUFFER_INITIALIZER;
 
-    switch ((virDomainFSType) fs->type) {
+    switch (fs->type) {
     case VIR_DOMAIN_FS_TYPE_MOUNT:
         break;
     case VIR_DOMAIN_FS_TYPE_BLOCK:
diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c
index 30f0a13e2a..f4b05b1c21 100644
--- a/src/conf/domain_conf.c
+++ b/src/conf/domain_conf.c
@@ -9759,86 +9759,66 @@ virDomainFSDefParseXML(virDomainXMLOption *xmlopt,
     virDomainFSDef *def;
     xmlNodePtr driver_node = NULL;
     xmlNodePtr source_node = NULL;
-    g_autofree char *type = NULL;
     g_autofree char *source = NULL;
     g_autofree char *target = NULL;
     g_autofree char *format = NULL;
-    g_autofree char *accessmode = NULL;
     g_autofree char *usage = NULL;
     g_autofree char *units = NULL;
-    g_autofree char *model = NULL;
-    g_autofree char *multidevs = NULL;
-    g_autofree char *fmode = NULL;
-    g_autofree char *dmode = NULL;
     g_autofree char *sock = NULL;
+    int rv;
 
     ctxt->node = node;
 
     if (!(def = virDomainFSDefNew(xmlopt)))
         return NULL;
 
-    type = virXMLPropString(node, "type");
-    if (type) {
-        if ((def->type = virDomainFSTypeFromString(type)) < 0) {
-            virReportError(VIR_ERR_CONFIG_UNSUPPORTED,
-                           _("unknown filesystem type '%s'"), type);
-            goto error;
-        }
-    } else {
-        def->type = VIR_DOMAIN_FS_TYPE_MOUNT;
-    }
+    if (virXMLPropEnum(node, "type",
+                       virDomainFSTypeFromString,
+                       VIR_XML_PROP_NONE,
+                       &def->type) < 0)
+        goto error;
 
-    accessmode = virXMLPropString(node, "accessmode");
-    if (accessmode) {
-        if ((def->accessmode = virDomainFSAccessModeTypeFromString(accessmode)) < 0) {
-            virReportError(VIR_ERR_CONFIG_UNSUPPORTED,
-                           _("unknown accessmode '%s'"), accessmode);
-            goto error;
-        }
-    } else {
-        def->accessmode = VIR_DOMAIN_FS_ACCESSMODE_DEFAULT;
-    }
+    if (virXMLPropEnum(node, "accessmode",
+                             virDomainFSAccessModeTypeFromString,
+                             VIR_XML_PROP_NONE,
+                             &def->accessmode) < 0)
+        goto error;
 
-    fmode = virXMLPropString(node, "fmode");
-    if (fmode) {
-        if ((virStrToLong_uip(fmode, NULL, 8, &def->fmode) < 0) ||
-            (def->fmode > 0777)) {
+    if ((rv = virXMLPropUInt(node, "fmode", 8,
+                             VIR_XML_PROP_NONE,
+                             &def->fmode)) < 0) {
+        goto error;
+    } else if (rv > 0) {
+        if (def->fmode > 0777) {
             virReportError(VIR_ERR_XML_ERROR,
-                           _("invalid fmode: '%s'"), fmode);
+                           _("invalid fmode: '0%o'"), def->fmode);
             goto error;
         }
     }
 
-    dmode = virXMLPropString(node, "dmode");
-    if (dmode) {
-        if ((virStrToLong_uip(dmode, NULL, 8, &def->dmode) < 0) ||
-            (def->dmode > 0777)) {
+    if ((rv = virXMLPropUInt(node, "dmode", 8,
+                             VIR_XML_PROP_NONE,
+                             &def->dmode)) < 0) {
+        goto error;
+    } else if (rv > 0) {
+        if (def->dmode > 0777) {
             virReportError(VIR_ERR_XML_ERROR,
-                           _("invalid dmode: '%s'"), dmode);
+                           _("invalid dmode: '0%o'"), def->dmode);
             goto error;
         }
     }
 
-    model = virXMLPropString(node, "model");
-    if (model) {
-        if ((def->model = virDomainFSModelTypeFromString(model)) < 0 ||
-            def->model == VIR_DOMAIN_FS_MODEL_DEFAULT) {
-            virReportError(VIR_ERR_CONFIG_UNSUPPORTED,
-                           _("unknown model '%s'"), model);
-            goto error;
-        }
-    }
+    if (virXMLPropEnum(node, "model",
+                       virDomainFSModelTypeFromString,
+                       VIR_XML_PROP_NONZERO,
+                       &def->model) < 0)
+        goto error;
 
-    multidevs = virXMLPropString(node, "multidevs");
-    if (multidevs) {
-        if ((def->multidevs = virDomainFSMultidevsTypeFromString(multidevs)) < 0) {
-            virReportError(VIR_ERR_CONFIG_UNSUPPORTED,
-                           _("unknown multidevs '%s'"), multidevs);
-            goto error;
-        }
-    } else {
-        def->multidevs = VIR_DOMAIN_FS_MULTIDEVS_DEFAULT;
-    }
+    if (virXMLPropEnum(node, "multidevs",
+                       virDomainFSMultidevsTypeFromString,
+                       VIR_XML_PROP_NONE,
+                       &def->multidevs) < 0)
+        goto error;
 
     if (virParseScaledValue("./space_hard_limit[1]",
                             NULL, ctxt, &def->space_hard_limit,
@@ -9901,11 +9881,10 @@ virDomainFSDefParseXML(virDomainXMLOption *xmlopt,
     if (def->fsdriver == VIR_DOMAIN_FS_DRIVER_TYPE_VIRTIOFS) {
         g_autofree char *queue_size = virXPathString("string(./driver/@queue)", ctxt);
         g_autofree char *binary = virXPathString("string(./binary/@path)", ctxt);
-        g_autofree char *cache = virXPathString("string(./binary/cache/@mode)", ctxt);
-        g_autofree char *sandbox = virXPathString("string(./binary/sandbox/@mode)", ctxt);
         xmlNodePtr binary_node = virXPathNode("./binary", ctxt);
         xmlNodePtr binary_lock_node = virXPathNode("./binary/lock", ctxt);
-        int val;
+        xmlNodePtr binary_cache_node = virXPathNode("./binary/cache", ctxt);
+        xmlNodePtr binary_sandbox_node = virXPathNode("./binary/sandbox", ctxt);
 
         if (queue_size && virStrToLong_ull(queue_size, NULL, 10, &def->queue_size) < 0) {
             virReportError(VIR_ERR_XML_ERROR,
@@ -9932,26 +9911,17 @@ virDomainFSDefParseXML(virDomainXMLOption *xmlopt,
                                      &def->flock) < 0)
             goto error;
 
-        if (cache) {
-            if ((val = virDomainFSCacheModeTypeFromString(cache)) <= 0) {
-                virReportError(VIR_ERR_XML_ERROR,
-                               _("cannot parse cache mode '%s' for virtiofs"),
-                               cache);
-                goto error;
-            }
-            def->cache = val;
-        }
-
-        if (sandbox) {
-            if ((val = virDomainFSSandboxModeTypeFromString(sandbox)) <= 0) {
-                virReportError(VIR_ERR_XML_ERROR,
-                               _("cannot parse sandbox mode '%s' for virtiofs"),
-                               sandbox);
-                goto error;
-            }
-            def->sandbox = val;
-        }
+        if (virXMLPropEnum(binary_cache_node, "mode",
+                           virDomainFSCacheModeTypeFromString,
+                           VIR_XML_PROP_NONZERO,
+                           &def->cache) < 0)
+            goto error;
 
+        if (virXMLPropEnum(binary_sandbox_node, "mode",
+                           virDomainFSSandboxModeTypeFromString,
+                           VIR_XML_PROP_NONZERO,
+                           &def->sandbox) < 0)
+            goto error;
     }
 
     if (source == NULL && def->type != VIR_DOMAIN_FS_TYPE_RAM
@@ -24188,6 +24158,9 @@ virDomainFSDefFormat(virBuffer *buf,
         virBufferEscapeString(buf, " volume='%s'", def->src->srcpool->volume);
         virBufferAddLit(buf, "/>\n");
         break;
+
+    case VIR_DOMAIN_FS_TYPE_LAST:
+        break;
     }
 
     virBufferEscapeString(buf, "<target dir='%s'/>\n",
diff --git a/src/conf/domain_conf.h b/src/conf/domain_conf.h
index 584e15b6c7..bbb2f463e2 100644
--- a/src/conf/domain_conf.h
+++ b/src/conf/domain_conf.h
@@ -787,7 +787,7 @@ struct _virDomainControllerDef {
 
 /* Types of disk backends */
 typedef enum {
-    VIR_DOMAIN_FS_TYPE_MOUNT, /* Mounts (binds) a host dir on a guest dir */
+    VIR_DOMAIN_FS_TYPE_MOUNT = 0, /* Mounts (binds) a host dir on a guest dir */
     VIR_DOMAIN_FS_TYPE_BLOCK, /* Mounts a host block dev on a guest dir */
     VIR_DOMAIN_FS_TYPE_FILE,  /* Loopback mounts a host file on a guest dir */
     VIR_DOMAIN_FS_TYPE_TEMPLATE, /* Expands a OS template to a guest dir */
@@ -867,15 +867,15 @@ typedef enum {
 } virDomainFSSandboxMode;
 
 struct _virDomainFSDef {
-    int type;
+    virDomainFSType type;
     virDomainFSDriverType fsdriver;
-    int accessmode; /* enum virDomainFSAccessMode */
+    virDomainFSAccessMode accessmode;
     int format; /* virStorageFileFormat */
     virDomainFSWrpolicy wrpolicy;
-    int model; /* virDomainFSModel */
+    virDomainFSModel model;
     unsigned int fmode;
     unsigned int dmode;
-    int multidevs; /* virDomainFSMultidevs */
+    virDomainFSMultidevs multidevs;
     unsigned long long usage; /* in bytes */
     virStorageSource *src;
     char *sock;
diff --git a/src/lxc/lxc_container.c b/src/lxc/lxc_container.c
index 3f38c55fc6..d5410e9fa6 100644
--- a/src/lxc/lxc_container.c
+++ b/src/lxc/lxc_container.c
@@ -1447,6 +1447,9 @@ static int lxcContainerMountFS(virDomainFSDef *fs,
                        _("Unexpected filesystem type %s"),
                        virDomainFSTypeToString(fs->type));
         return -1;
+    case VIR_DOMAIN_FS_TYPE_TEMPLATE:
+    case VIR_DOMAIN_FS_TYPE_VOLUME:
+    case VIR_DOMAIN_FS_TYPE_LAST:
     default:
         virReportError(VIR_ERR_CONFIG_UNSUPPORTED,
                        _("Cannot mount filesystem type %s"),
diff --git a/src/qemu/qemu_domain_address.c b/src/qemu/qemu_domain_address.c
index 18fc34d049..3e6eed6ec9 100644
--- a/src/qemu/qemu_domain_address.c
+++ b/src/qemu/qemu_domain_address.c
@@ -705,7 +705,7 @@ qemuDomainDeviceCalculatePCIConnectFlags(virDomainDeviceDef *dev,
         case VIR_DOMAIN_FS_DRIVER_TYPE_PATH:
         case VIR_DOMAIN_FS_DRIVER_TYPE_HANDLE:
             /* these drivers are handled by virtio-9p-pci */
-            switch ((virDomainFSModel) dev->data.fs->model) {
+            switch (dev->data.fs->model) {
             case VIR_DOMAIN_FS_MODEL_VIRTIO_TRANSITIONAL:
                 /* Transitional devices only work in conventional PCI slots */
                 return pciFlags;
-- 
2.34.1




[Index of Archives]     [Virt Tools]     [Libvirt Users]     [Lib OS Info]     [Fedora Users]     [Fedora Desktop]     [Fedora SELinux]     [Big List of Linux Books]     [Yosemite News]     [KDE Users]     [Fedora Tools]

  Powered by Linux