mirror of
https://gitlab.com/libvirt/libvirt.git
synced 2025-02-22 11:22:23 +00:00
qemu: migration_cookie: Extract parsing/validation of mandatory features
Move the code into 'qemuMigrationCookieXMLParseMandatoryFeatures' to simplify 'qemuMigrationCookieXMLParse'. Signed-off-by: Peter Krempa <pkrempa@redhat.com> Reviewed-by: Michal Privoznik <mprivozn@redhat.com>
This commit is contained in:
parent
28027f1fb1
commit
dd6f669d2c
@ -1156,6 +1156,49 @@ qemuMigrationCookieCapsXMLParse(xmlXPathContextPtr ctxt)
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* qemuMigrationCookieXMLParseMandatoryFeatures:
|
||||||
|
*
|
||||||
|
* Check to ensure all mandatory features from XML are also present in 'flags'.
|
||||||
|
*/
|
||||||
|
static int
|
||||||
|
qemuMigrationCookieXMLParseMandatoryFeatures(xmlXPathContextPtr ctxt,
|
||||||
|
unsigned int flags)
|
||||||
|
{
|
||||||
|
g_autofree xmlNodePtr *nodes = NULL;
|
||||||
|
size_t i;
|
||||||
|
ssize_t n;
|
||||||
|
|
||||||
|
if ((n = virXPathNodeSet("./feature", ctxt, &nodes)) < 0)
|
||||||
|
return -1;
|
||||||
|
|
||||||
|
for (i = 0; i < n; i++) {
|
||||||
|
int val;
|
||||||
|
g_autofree char *str = virXMLPropString(nodes[i], "name");
|
||||||
|
|
||||||
|
if (!str) {
|
||||||
|
virReportError(VIR_ERR_INTERNAL_ERROR,
|
||||||
|
"%s", _("missing feature name"));
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
if ((val = qemuMigrationCookieFlagTypeFromString(str)) < 0) {
|
||||||
|
virReportError(VIR_ERR_INTERNAL_ERROR,
|
||||||
|
_("Unknown migration cookie feature %s"), str);
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
if ((flags & (1 << val)) == 0) {
|
||||||
|
virReportError(VIR_ERR_INTERNAL_ERROR,
|
||||||
|
_("Unsupported migration cookie feature %s"), str);
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
static int
|
static int
|
||||||
qemuMigrationCookieXMLParse(qemuMigrationCookiePtr mig,
|
qemuMigrationCookieXMLParse(qemuMigrationCookiePtr mig,
|
||||||
virQEMUDriverPtr driver,
|
virQEMUDriverPtr driver,
|
||||||
@ -1167,7 +1210,6 @@ qemuMigrationCookieXMLParse(qemuMigrationCookiePtr mig,
|
|||||||
char uuidstr[VIR_UUID_STRING_BUFLEN];
|
char uuidstr[VIR_UUID_STRING_BUFLEN];
|
||||||
char *tmp = NULL;
|
char *tmp = NULL;
|
||||||
xmlNodePtr *nodes = NULL;
|
xmlNodePtr *nodes = NULL;
|
||||||
size_t i;
|
|
||||||
int n;
|
int n;
|
||||||
|
|
||||||
/* We don't store the uuid, name, hostname, or hostuuid
|
/* We don't store the uuid, name, hostname, or hostuuid
|
||||||
@ -1234,38 +1276,9 @@ qemuMigrationCookieXMLParse(qemuMigrationCookiePtr mig,
|
|||||||
}
|
}
|
||||||
VIR_FREE(tmp);
|
VIR_FREE(tmp);
|
||||||
|
|
||||||
/* Check to ensure all mandatory features from XML are also
|
|
||||||
* present in 'flags' */
|
|
||||||
if ((n = virXPathNodeSet("./feature", ctxt, &nodes)) < 0)
|
|
||||||
goto error;
|
|
||||||
|
|
||||||
for (i = 0; i < n; i++) {
|
if (qemuMigrationCookieXMLParseMandatoryFeatures(ctxt, flags) < 0)
|
||||||
int val;
|
return -1;
|
||||||
char *str = virXMLPropString(nodes[i], "name");
|
|
||||||
if (!str) {
|
|
||||||
virReportError(VIR_ERR_INTERNAL_ERROR,
|
|
||||||
"%s", _("missing feature name"));
|
|
||||||
goto error;
|
|
||||||
}
|
|
||||||
|
|
||||||
if ((val = qemuMigrationCookieFlagTypeFromString(str)) < 0) {
|
|
||||||
virReportError(VIR_ERR_INTERNAL_ERROR,
|
|
||||||
_("Unknown migration cookie feature %s"),
|
|
||||||
str);
|
|
||||||
VIR_FREE(str);
|
|
||||||
goto error;
|
|
||||||
}
|
|
||||||
|
|
||||||
if ((flags & (1 << val)) == 0) {
|
|
||||||
virReportError(VIR_ERR_INTERNAL_ERROR,
|
|
||||||
_("Unsupported migration cookie feature %s"),
|
|
||||||
str);
|
|
||||||
VIR_FREE(str);
|
|
||||||
goto error;
|
|
||||||
}
|
|
||||||
VIR_FREE(str);
|
|
||||||
}
|
|
||||||
VIR_FREE(nodes);
|
|
||||||
|
|
||||||
if ((flags & QEMU_MIGRATION_COOKIE_GRAPHICS) &&
|
if ((flags & QEMU_MIGRATION_COOKIE_GRAPHICS) &&
|
||||||
virXPathBoolean("count(./graphics) > 0", ctxt) &&
|
virXPathBoolean("count(./graphics) > 0", ctxt) &&
|
||||||
|
Loading…
x
Reference in New Issue
Block a user