]> git.ipfire.org Git - thirdparty/libvirt.git/commitdiff
domain_conf.c: move idmapEntry checks to domain_validate.c
authorDaniel Henrique Barboza <danielhb413@gmail.com>
Mon, 7 Dec 2020 12:48:08 +0000 (09:48 -0300)
committerDaniel Henrique Barboza <danielhb413@gmail.com>
Wed, 9 Dec 2020 12:51:52 +0000 (09:51 -0300)
Create a new function called virDomainDefIdMapValidate() and
use it to move these checks out of virDomainIdmapDefParseXML()
and virDomainDefParseXML().

Reviewed-by: Michal Privoznik <mprivozn@redhat.com>
Signed-off-by: Daniel Henrique Barboza <danielhb413@gmail.com>
src/conf/domain_conf.c
src/conf/domain_validate.c
src/conf/domain_validate.h

index 33020093b8e7d07f7b509de1e275a07f4effa9ae..23415b323ce7b45291f9a02a7b4c4d3d71d75923 100644 (file)
@@ -6949,6 +6949,9 @@ virDomainDefValidateInternal(const virDomainDef *def,
     if (virDomainDefTunablesValidate(def) < 0)
         return -1;
 
+    if (virDomainDefIdMapValidate(def) < 0)
+        return -1;
+
     if (virDomainNumaDefValidate(def->numa) < 0)
         return -1;
 
@@ -18468,15 +18471,6 @@ virDomainIdmapDefParseXML(xmlXPathContextPtr ctxt,
 
     qsort(idmap, num, sizeof(idmap[0]), virDomainIdMapEntrySort);
 
-    if (idmap[0].start != 0) {
-        /* Root user of container hasn't been mapped to any user of host,
-         * return error. */
-        virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s",
-                       _("You must map the root user of container"));
-        VIR_FREE(idmap);
-        return NULL;
-    }
-
     return idmap;
 }
 
@@ -21966,13 +21960,6 @@ virDomainDefParseXML(xmlDocPtr xml,
     }
     VIR_FREE(nodes);
 
-    if ((def->idmap.uidmap && !def->idmap.gidmap) ||
-        (!def->idmap.uidmap && def->idmap.gidmap)) {
-            virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
-                           _("uid and gid should be mapped both"));
-            goto error;
-    }
-
     if ((n = virXPathNodeSet("./sysinfo", ctxt, &nodes)) < 0)
         goto error;
 
index 35deb9f017ba140c8030983ed2283d21d6484602..0eed1ba982fdb84472890574a752618f710c06f1 100644 (file)
@@ -612,3 +612,26 @@ virDomainControllerDefValidate(const virDomainControllerDef *controller)
 
     return 0;
 }
+
+
+int
+virDomainDefIdMapValidate(const virDomainDef *def)
+{
+    if ((def->idmap.uidmap && !def->idmap.gidmap) ||
+        (!def->idmap.uidmap && def->idmap.gidmap)) {
+        virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s",
+                       _("uid and gid should be mapped both"));
+        return -1;
+    }
+
+    if ((def->idmap.uidmap && def->idmap.uidmap[0].start != 0) ||
+        (def->idmap.gidmap && def->idmap.gidmap[0].start != 0)) {
+        /* Root user of container hasn't been mapped to any user of host,
+         * return error. */
+        virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s",
+                       _("You must map the root user of container"));
+        return -1;
+    }
+
+    return 0;
+}
index e8004e358d6d8fe9c931726ebd93addf46929d06..497a02b9b35b2f0fd3f6bee25db50dc6f9b362c6 100644 (file)
@@ -44,3 +44,4 @@ int virDomainSmartcardDefValidate(const virDomainSmartcardDef *smartcard,
                                   const virDomainDef *def);
 int virDomainDefTunablesValidate(const virDomainDef *def);
 int virDomainControllerDefValidate(const virDomainControllerDef *controller);
+int virDomainDefIdMapValidate(const virDomainDef *def);