mirror of
https://gitlab.com/libvirt/libvirt.git
synced 2025-03-20 07:59:00 +00:00
conf: cpu: Refactor parsing of vendor_id and fallback attributes
This patch simplifies the code that parses the fallback and vendor_id attributes from the domain xml cpu definition. Changes done: - free temp variables in the cleanup section instead of local use - remove checking for presence of the attribute to directly getting the value (saving call to virXPathBoolean) - replace loop used to check for ',' in the vendor_id string with strchr
This commit is contained in:
parent
fb49ffc3bb
commit
4a9c179325
@ -195,6 +195,8 @@ virCPUDefParseXML(const xmlNodePtr node,
|
|||||||
int n;
|
int n;
|
||||||
unsigned int i;
|
unsigned int i;
|
||||||
char *cpuMode;
|
char *cpuMode;
|
||||||
|
char *fallback = NULL;
|
||||||
|
char *vendor_id = NULL;
|
||||||
|
|
||||||
if (!xmlStrEqual(node->name, BAD_CAST "cpu")) {
|
if (!xmlStrEqual(node->name, BAD_CAST "cpu")) {
|
||||||
virReportError(VIR_ERR_INTERNAL_ERROR,
|
virReportError(VIR_ERR_INTERNAL_ERROR,
|
||||||
@ -288,45 +290,32 @@ virCPUDefParseXML(const xmlNodePtr node,
|
|||||||
if (def->type == VIR_CPU_TYPE_GUEST &&
|
if (def->type == VIR_CPU_TYPE_GUEST &&
|
||||||
def->mode != VIR_CPU_MODE_HOST_PASSTHROUGH) {
|
def->mode != VIR_CPU_MODE_HOST_PASSTHROUGH) {
|
||||||
|
|
||||||
if (virXPathBoolean("boolean(./model[1]/@fallback)", ctxt)) {
|
if ((fallback = virXPathString("string(./model[1]/@fallback)", ctxt))) {
|
||||||
const char *fallback;
|
if ((def->fallback = virCPUFallbackTypeFromString(fallback)) < 0) {
|
||||||
|
virReportError(VIR_ERR_XML_ERROR, "%s",
|
||||||
fallback = virXPathString("string(./model[1]/@fallback)", ctxt);
|
_("Invalid fallback attribute"));
|
||||||
if (fallback) {
|
goto error;
|
||||||
def->fallback = virCPUFallbackTypeFromString(fallback);
|
|
||||||
VIR_FREE(fallback);
|
|
||||||
if (def->fallback < 0) {
|
|
||||||
virReportError(VIR_ERR_XML_ERROR, "%s",
|
|
||||||
_("Invalid fallback attribute"));
|
|
||||||
goto error;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (virXPathBoolean("boolean(./model[1]/@vendor_id)", ctxt)) {
|
if ((vendor_id = virXPathString("string(./model[1]/@vendor_id)",
|
||||||
char *vendor_id;
|
ctxt))) {
|
||||||
|
if (strlen(vendor_id) != VIR_CPU_VENDOR_ID_LENGTH) {
|
||||||
vendor_id = virXPathString("string(./model[1]/@vendor_id)",
|
|
||||||
ctxt);
|
|
||||||
if (!vendor_id ||
|
|
||||||
strlen(vendor_id) != VIR_CPU_VENDOR_ID_LENGTH) {
|
|
||||||
virReportError(VIR_ERR_XML_ERROR,
|
virReportError(VIR_ERR_XML_ERROR,
|
||||||
_("vendor_id must be exactly"
|
_("vendor_id must be exactly %d characters long"),
|
||||||
" %d characters long"),
|
|
||||||
VIR_CPU_VENDOR_ID_LENGTH);
|
VIR_CPU_VENDOR_ID_LENGTH);
|
||||||
VIR_FREE(vendor_id);
|
|
||||||
goto error;
|
goto error;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* ensure that the string can be passed to qemu*/
|
/* ensure that the string can be passed to qemu*/
|
||||||
for (i = 0; i < strlen(vendor_id); i++) {
|
if (strchr(vendor_id, ',')) {
|
||||||
if (vendor_id[i]==',') {
|
|
||||||
virReportError(VIR_ERR_XML_ERROR, "%s",
|
virReportError(VIR_ERR_XML_ERROR, "%s",
|
||||||
_("vendor id is invalid"));
|
_("vendor id is invalid"));
|
||||||
VIR_FREE(vendor_id);
|
|
||||||
goto error;
|
goto error;
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
def->vendor_id = vendor_id;
|
def->vendor_id = vendor_id;
|
||||||
|
vendor_id = NULL;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -490,6 +479,8 @@ virCPUDefParseXML(const xmlNodePtr node,
|
|||||||
}
|
}
|
||||||
|
|
||||||
cleanup:
|
cleanup:
|
||||||
|
VIR_FREE(fallback);
|
||||||
|
VIR_FREE(vendor_id);
|
||||||
VIR_FREE(nodes);
|
VIR_FREE(nodes);
|
||||||
return def;
|
return def;
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user