提交 173054ce 编写于 作者: P Peter Krempa

conf: Extract code for parsing thread resource scheduler info

As the scheduler info elements are represented orthogonally to how it
makes sense to actually store the information, the extracted code will
be later used when converting between XML and internal definitions.
上级 e992aa21
...@@ -14585,36 +14585,34 @@ virDomainLoaderDefParseXML(xmlNodePtr node, ...@@ -14585,36 +14585,34 @@ virDomainLoaderDefParseXML(xmlNodePtr node,
return ret; return ret;
} }
static int
virDomainThreadSchedParse(xmlNodePtr node, static virBitmapPtr
unsigned int minid, virDomainSchedulerParse(xmlNodePtr node,
unsigned int maxid, const char *name,
const char *name, virProcessSchedPolicy *policy,
virDomainThreadSchedParamPtr sp) int *priority)
{ {
virBitmapPtr ret = NULL;
char *tmp = NULL; char *tmp = NULL;
int pol = 0; int pol = 0;
tmp = virXMLPropString(node, name); if (!(tmp = virXMLPropString(node, name))) {
if (!tmp) {
virReportError(VIR_ERR_XML_ERROR, virReportError(VIR_ERR_XML_ERROR,
_("Missing attribute '%s' in element '%sched'"), _("Missing attribute '%s' in element '%sched'"),
name, name); name, name);
goto error; goto error;
} }
if (virBitmapParse(tmp, 0, &sp->ids, VIR_DOMAIN_CPUMASK_LEN) < 0) if (virBitmapParse(tmp, 0, &ret, VIR_DOMAIN_CPUMASK_LEN) < 0)
goto error; goto error;
if (virBitmapIsAllClear(sp->ids) || if (virBitmapIsAllClear(ret)) {
virBitmapNextSetBit(sp->ids, -1) < minid ||
virBitmapLastSetBit(sp->ids) > maxid) {
virReportError(VIR_ERR_CONFIG_UNSUPPORTED, virReportError(VIR_ERR_CONFIG_UNSUPPORTED,
_("Invalid value of '%s': %s"), _("'%s' scheduler bitmap '%s' is empty"),
name, tmp); name, tmp);
goto error; goto error;
} }
VIR_FREE(tmp); VIR_FREE(tmp);
if (!(tmp = virXMLPropString(node, "scheduler"))) { if (!(tmp = virXMLPropString(node, "scheduler"))) {
...@@ -14625,22 +14623,22 @@ virDomainThreadSchedParse(xmlNodePtr node, ...@@ -14625,22 +14623,22 @@ virDomainThreadSchedParse(xmlNodePtr node,
if ((pol = virProcessSchedPolicyTypeFromString(tmp)) <= 0) { if ((pol = virProcessSchedPolicyTypeFromString(tmp)) <= 0) {
virReportError(VIR_ERR_INTERNAL_ERROR, virReportError(VIR_ERR_INTERNAL_ERROR,
_("Invalid scheduler attribute: '%s'"), _("Invalid scheduler attribute: '%s'"), tmp);
tmp);
goto error; goto error;
} }
sp->policy = pol; *policy = pol;
VIR_FREE(tmp); VIR_FREE(tmp);
if (sp->policy == VIR_PROC_POLICY_FIFO ||
sp->policy == VIR_PROC_POLICY_RR) { if (pol == VIR_PROC_POLICY_FIFO ||
tmp = virXMLPropString(node, "priority"); pol == VIR_PROC_POLICY_RR) {
if (!tmp) { if (!(tmp = virXMLPropString(node, "priority"))) {
virReportError(VIR_ERR_XML_ERROR, "%s", virReportError(VIR_ERR_XML_ERROR, "%s",
_("Missing scheduler priority")); _("Missing scheduler priority"));
goto error; goto error;
} }
if (virStrToLong_i(tmp, NULL, 10, &sp->priority) < 0) {
if (virStrToLong_i(tmp, NULL, 10, priority) < 0) {
virReportError(VIR_ERR_XML_ERROR, "%s", virReportError(VIR_ERR_XML_ERROR, "%s",
_("Invalid value for element priority")); _("Invalid value for element priority"));
goto error; goto error;
...@@ -14648,11 +14646,34 @@ virDomainThreadSchedParse(xmlNodePtr node, ...@@ -14648,11 +14646,34 @@ virDomainThreadSchedParse(xmlNodePtr node,
VIR_FREE(tmp); VIR_FREE(tmp);
} }
return 0; return ret;
error: error:
VIR_FREE(tmp); VIR_FREE(tmp);
return -1; virBitmapFree(ret);
return NULL;
}
static int
virDomainThreadSchedParse(xmlNodePtr node,
unsigned int minid,
unsigned int maxid,
const char *name,
virDomainThreadSchedParamPtr sp)
{
if (!(sp->ids = virDomainSchedulerParse(node, name, &sp->policy,
&sp->priority)))
return -1;
if (virBitmapNextSetBit(sp->ids, -1) < minid ||
virBitmapLastSetBit(sp->ids) > maxid) {
virReportError(VIR_ERR_CONFIG_UNSUPPORTED,
_("%sched bitmap is out of range"), name);
return -1;
}
return 0;
} }
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册