Create virDomainDefParseUUID that parses only the UUID from XML
definition. This will be used in future patch(es).
Signed-off-by: Martin Kletzander <mkletzan(a)redhat.com>
---
src/conf/domain_conf.c | 64 +++++++++++++++++++++++++++++++++++---------------
1 file changed, 45 insertions(+), 19 deletions(-)
diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c
index c2aeca2e52a6..230800542f8c 100644
--- a/src/conf/domain_conf.c
+++ b/src/conf/domain_conf.c
@@ -14579,6 +14579,49 @@ virDomainVcpuParse(virDomainDefPtr def,
return ret;
}
+/*
+ * Parse domain's UUID, optionally generating it if missing.
+ */
+static int
+virDomainDefParseUUID(virDomainDefPtr def,
+ xmlXPathContextPtr ctxt,
+ bool required,
+ bool *generated)
+{
+ char *tmp = virXPathString("string(./uuid[1])", ctxt);
+
+ if (generated)
+ *generated = false;
+
+ if (tmp) {
+ if (virUUIDParse(tmp, def->uuid) < 0) {
+ virReportError(VIR_ERR_INTERNAL_ERROR,
+ "%s", _("malformed uuid element"));
+ VIR_FREE(tmp);
+ return -1;
+ }
+ VIR_FREE(tmp);
+ return 0;
+ }
+
+ if (required) {
+ virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
+ _("Missing required UUID"));
+ return -1;
+ }
+
+ if (virUUIDGenerate(def->uuid)) {
+ virReportError(VIR_ERR_INTERNAL_ERROR,
+ "%s", _("Failed to generate UUID"));
+ return -1;
+ }
+
+ if (generated)
+ *generated = true;
+
+ return 0;
+}
+
static int
virDomainDefParseName(virDomainDefPtr def,
xmlXPathContextPtr ctxt)
@@ -14719,25 +14762,8 @@ virDomainDefParseXML(xmlDocPtr xml,
if (virDomainDefParseName(def, ctxt) < 0)
goto error;
- /* Extract domain uuid. If both uuid and sysinfo/system/entry/uuid
- * exist, they must match; and if only the latter exists, it can
- * also serve as the uuid. */
- tmp = virXPathString("string(./uuid[1])", ctxt);
- if (!tmp) {
- if (virUUIDGenerate(def->uuid)) {
- virReportError(VIR_ERR_INTERNAL_ERROR,
- "%s", _("Failed to generate UUID"));
- goto error;
- }
- uuid_generated = true;
- } else {
- if (virUUIDParse(tmp, def->uuid) < 0) {
- virReportError(VIR_ERR_INTERNAL_ERROR,
- "%s", _("malformed uuid element"));
- goto error;
- }
- VIR_FREE(tmp);
- }
+ if (virDomainDefParseUUID(def, ctxt, false, &uuid_generated) < 0)
+ goto error;
/* Extract short description of domain (title) */
def->title = virXPathString("string(./title[1])", ctxt);
--
2.5.3