Create a new function called virDomainDefIdMapPostParse() and
use it to move these checks out of virDomainIdmapDefParseXML().
Signed-off-by: Daniel Henrique Barboza <danielhb413(a)gmail.com>
---
src/conf/domain_conf.c | 42 ++++++++++++++++++++++++++----------------
1 file changed, 26 insertions(+), 16 deletions(-)
diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c
index c99c1b60d4..fa21d41c4a 100644
--- a/src/conf/domain_conf.c
+++ b/src/conf/domain_conf.c
@@ -6015,6 +6015,29 @@ virDomainDefTunablesPostParse(virDomainDefPtr def)
}
+static int
+virDomainDefIdMapPostParse(virDomainDefPtr 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;
+}
+
+
static int
virDomainDefPostParseVideo(virDomainDefPtr def,
void *opaque)
@@ -6105,6 +6128,9 @@ virDomainDefPostParseCommon(virDomainDefPtr def,
if (virDomainDefTunablesPostParse(def) < 0)
return -1;
+ if (virDomainDefIdMapPostParse(def) < 0)
+ return -1;
+
if (def->os.type == VIR_DOMAIN_OSTYPE_HVM &&
!(data->xmlopt->config.features & VIR_DOMAIN_DEF_FEATURE_NO_BOOT_ORDER)
&&
virDomainDefBootOrderPostParse(def) < 0)
@@ -19098,15 +19124,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;
}
@@ -22595,13 +22612,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;
--
2.26.2