Create a new function called virDomainDefIdMapValidate() and
use it to move these checks out of virDomainIdmapDefParseXML()
and virDomainDefParseXML().
Reviewed-by: Michal Privoznik <mprivozn(a)redhat.com>
Signed-off-by: Daniel Henrique Barboza <danielhb413(a)gmail.com>
---
src/conf/domain_conf.c | 19 +++----------------
src/conf/domain_validate.c | 23 +++++++++++++++++++++++
src/conf/domain_validate.h | 1 +
3 files changed, 27 insertions(+), 16 deletions(-)
diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c
index 7a7c9ec85c..44f136f530 100644
--- a/src/conf/domain_conf.c
+++ b/src/conf/domain_conf.c
@@ -6947,6 +6947,9 @@ virDomainDefValidateInternal(const virDomainDef *def,
if (virDomainDefTunablesValidate(def) < 0)
return -1;
+ if (virDomainDefIdMapValidate(def) < 0)
+ return -1;
+
if (virDomainNumaDefValidate(def->numa) < 0)
return -1;
@@ -18463,15 +18466,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;
}
@@ -21961,13 +21955,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;
diff --git a/src/conf/domain_validate.c b/src/conf/domain_validate.c
index 35deb9f017..0eed1ba982 100644
--- a/src/conf/domain_validate.c
+++ b/src/conf/domain_validate.c
@@ -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;
+}
diff --git a/src/conf/domain_validate.h b/src/conf/domain_validate.h
index e8004e358d..497a02b9b3 100644
--- a/src/conf/domain_validate.h
+++ b/src/conf/domain_validate.h
@@ -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);
--
2.26.2