conf: Split up virDomainVcpuPinDefParseXML

Extract part that parses iothreads into virDomainIothreadPinDefParseXML
This commit is contained in:
Peter Krempa 2015-04-07 17:44:12 +02:00
parent 06c03b48bd
commit 0532ec3faa

View File

@ -13173,30 +13173,19 @@ virDomainIdmapDefParseXML(xmlXPathContextPtr ctxt,
return idmap; return idmap;
} }
/* Parse the XML definition for a vcpupin or emulatorpin. /* Parse the XML definition for a vcpupin
* *
* vcpupin has the form of * vcpupin has the form of
* <vcpupin vcpu='0' cpuset='0'/> * <vcpupin vcpu='0' cpuset='0'/>
*
* and emulatorpin has the form of
* <emulatorpin cpuset='0'/>
*
* and an iothreadspin has the form
* <iothreadpin iothread='1' cpuset='2'/>
*
* A vcpuid of -1 is valid and only valid for emulatorpin. So callers
* have to check the returned cpuid for validity.
*/ */
static virDomainPinDefPtr static virDomainPinDefPtr
virDomainVcpuPinDefParseXML(xmlNodePtr node, virDomainVcpuPinDefParseXML(xmlNodePtr node,
xmlXPathContextPtr ctxt, xmlXPathContextPtr ctxt,
int maxvcpus, int maxvcpus)
bool iothreads)
{ {
virDomainPinDefPtr def; virDomainPinDefPtr def;
xmlNodePtr oldnode = ctxt->node; xmlNodePtr oldnode = ctxt->node;
int vcpuid = -1; int vcpuid = -1;
unsigned int iothreadid;
char *tmp = NULL; char *tmp = NULL;
int ret; int ret;
@ -13205,28 +13194,66 @@ virDomainVcpuPinDefParseXML(xmlNodePtr node,
ctxt->node = node; ctxt->node = node;
if (!iothreads) { ret = virXPathInt("string(./@vcpu)", ctxt, &vcpuid);
ret = virXPathInt("string(./@vcpu)", ctxt, &vcpuid); if ((ret == -2) || (vcpuid < -1)) {
if ((ret == -2) || (vcpuid < -1)) { virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
virReportError(VIR_ERR_INTERNAL_ERROR, "%s", _("vcpu id must be an unsigned integer or -1"));
_("vcpu id must be an unsigned integer or -1")); goto error;
goto error; } else if (vcpuid == -1) {
} else if (vcpuid == -1) { virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
virReportError(VIR_ERR_INTERNAL_ERROR, "%s", _("vcpu id value -1 is not allowed for vcpupin"));
_("vcpu id value -1 is not allowed for vcpupin")); goto error;
goto error;
}
if (vcpuid >= maxvcpus) {
virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
_("vcpu id must be less than maxvcpus"));
goto error;
}
def->id = vcpuid;
} }
if (iothreads && (tmp = virXPathString("string(./@iothread)", ctxt))) { if (vcpuid >= maxvcpus) {
virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
_("vcpu id must be less than maxvcpus"));
goto error;
}
def->id = vcpuid;
if (!(tmp = virXMLPropString(node, "cpuset"))) {
virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
_("missing cpuset for vcpupin"));
goto error;
}
if (virBitmapParse(tmp, 0, &def->cpumask, VIR_DOMAIN_CPUMASK_LEN) < 0)
goto error;
cleanup:
VIR_FREE(tmp);
ctxt->node = oldnode;
return def;
error:
VIR_FREE(def);
goto cleanup;
}
/* Parse the XML definition for a iothreadpin
* and an iothreadspin has the form
* <iothreadpin iothread='1' cpuset='2'/>
*/
static virDomainPinDefPtr
virDomainIOThreadPinDefParseXML(xmlNodePtr node,
xmlXPathContextPtr ctxt,
int iothreads)
{
virDomainPinDefPtr def;
xmlNodePtr oldnode = ctxt->node;
unsigned int iothreadid;
char *tmp = NULL;
if (VIR_ALLOC(def) < 0)
return NULL;
ctxt->node = node;
if ((tmp = virXPathString("string(./@iothread)", ctxt))) {
if (virStrToLong_uip(tmp, NULL, 10, &iothreadid) < 0) { if (virStrToLong_uip(tmp, NULL, 10, &iothreadid) < 0) {
virReportError(VIR_ERR_XML_ERROR, virReportError(VIR_ERR_XML_ERROR,
_("invalid setting for iothread '%s'"), tmp); _("invalid setting for iothread '%s'"), tmp);
@ -13240,11 +13267,9 @@ virDomainVcpuPinDefParseXML(xmlNodePtr node,
goto error; goto error;
} }
/* NB: maxvcpus is actually def->iothreads /* IOThreads are numbered "iothread1...iothread<n>", where
* IOThreads are numbered "iothread1...iothread<n>", where * "n" is the iothreads value */
* "n" is the iothreads value if (iothreadid > iothreads) {
*/
if (iothreadid > maxvcpus) {
virReportError(VIR_ERR_XML_ERROR, "%s", virReportError(VIR_ERR_XML_ERROR, "%s",
_("iothread id must not exceed iothreads")); _("iothread id must not exceed iothreads"));
goto error; goto error;
@ -13254,13 +13279,8 @@ virDomainVcpuPinDefParseXML(xmlNodePtr node,
} }
if (!(tmp = virXMLPropString(node, "cpuset"))) { if (!(tmp = virXMLPropString(node, "cpuset"))) {
if (iothreads) virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
virReportError(VIR_ERR_INTERNAL_ERROR, "%s", _("missing cpuset for iothreadpin"));
_("missing cpuset for iothreadpin"));
else
virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
_("missing cpuset for vcpupin"));
goto error; goto error;
} }
@ -13285,6 +13305,7 @@ virDomainVcpuPinDefParseXML(xmlNodePtr node,
} }
/* Parse the XML definition for emulatorpin. /* Parse the XML definition for emulatorpin.
* emulatorpin has the form of * emulatorpin has the form of
* <emulatorpin cpuset='0'/> * <emulatorpin cpuset='0'/>
@ -14011,7 +14032,7 @@ virDomainDefParseXML(xmlDocPtr xml,
for (i = 0; i < n; i++) { for (i = 0; i < n; i++) {
virDomainPinDefPtr vcpupin = NULL; virDomainPinDefPtr vcpupin = NULL;
vcpupin = virDomainVcpuPinDefParseXML(nodes[i], ctxt, vcpupin = virDomainVcpuPinDefParseXML(nodes[i], ctxt,
def->maxvcpus, false); def->maxvcpus);
if (!vcpupin) if (!vcpupin)
goto error; goto error;
@ -14098,9 +14119,8 @@ virDomainDefParseXML(xmlDocPtr xml,
for (i = 0; i < n; i++) { for (i = 0; i < n; i++) {
virDomainPinDefPtr iothreadpin = NULL; virDomainPinDefPtr iothreadpin = NULL;
iothreadpin = virDomainVcpuPinDefParseXML(nodes[i], ctxt, iothreadpin = virDomainIOThreadPinDefParseXML(nodes[i], ctxt,
def->iothreads, def->iothreads);
true);
if (!iothreadpin) if (!iothreadpin)
goto error; goto error;