Skip to content

Commit

Permalink
conf: Introduce virDomainDefCputuneValidate helper
Browse files Browse the repository at this point in the history
Introduce a simple validation helper to perform the cputune period and
quota checks so that we can get rid of those repetitive chunks. Since
this is a validation helper, this patch also moves the checks from the
'parse' phase into the 'validation' phase.

Signed-off-by: Suyang Chen <dawson0xff@gmail.com>
Reviewed-by: Erik Skultety <eskultet@redhat.com>
  • Loading branch information
he1l0world authored and eskultety committed Mar 14, 2019
1 parent ca14716 commit 265e692
Showing 1 changed file with 45 additions and 69 deletions.
114 changes: 45 additions & 69 deletions src/conf/domain_conf.c
Expand Up @@ -6566,6 +6566,48 @@ virDomainDefLifecycleActionValidate(const virDomainDef *def)
}


#define CPUTUNE_VALIDATE_PERIOD(name) \
do { \
if (def->cputune.name > 0 && \
(def->cputune.name < 1000 || def->cputune.name > 1000000)) { \
virReportError(VIR_ERR_CONFIG_UNSUPPORTED, \
_("Value of cputune '%s' must be in range " \
"[1000, 1000000]"), #name); \
return -1; \
} \
} while (0)

#define CPUTUNE_VALIDATE_QUOTA(name) \
do { \
if (def->cputune.name > 0 && \
(def->cputune.name < 1000 || \
def->cputune.name > 18446744073709551LL)) { \
virReportError(VIR_ERR_CONFIG_UNSUPPORTED, \
_("Value of cputune '%s' must be in range " \
"[1000, 18446744073709551]"), #name); \
return -1; \
} \
} while (0)

static int
virDomainDefCputuneValidate(const virDomainDef *def)
{
CPUTUNE_VALIDATE_PERIOD(period);
CPUTUNE_VALIDATE_PERIOD(global_period);
CPUTUNE_VALIDATE_PERIOD(emulator_period);
CPUTUNE_VALIDATE_PERIOD(iothread_period);

CPUTUNE_VALIDATE_QUOTA(quota);
CPUTUNE_VALIDATE_QUOTA(global_quota);
CPUTUNE_VALIDATE_QUOTA(emulator_quota);
CPUTUNE_VALIDATE_QUOTA(iothread_quota);

return 0;
}
#undef CPUTUNE_VALIDATE_PERIOD
#undef CPUTUNE_VALIDATE_QUOTA


static int
virDomainDefMemtuneValidate(const virDomainDef *def)
{
Expand Down Expand Up @@ -6685,6 +6727,9 @@ virDomainDefValidateInternal(const virDomainDef *def,
if (virDomainDefOSValidate(def, xmlopt) < 0)
return -1;

if (virDomainDefCputuneValidate(def) < 0)
return -1;

return 0;
}

Expand Down Expand Up @@ -19673,92 +19718,41 @@ virDomainDefParseXML(xmlDocPtr xml,
goto error;
}

if (def->cputune.period > 0 &&
(def->cputune.period < 1000 || def->cputune.period > 1000000)) {
virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s",
_("Value of cputune period must be in range "
"[1000, 1000000]"));
goto error;
}

if (virXPathLongLong("string(./cputune/quota[1])", ctxt,
&def->cputune.quota) < -1) {
virReportError(VIR_ERR_XML_ERROR, "%s",
_("can't parse cputune quota value"));
goto error;
}

if (def->cputune.quota > 0 &&
(def->cputune.quota < 1000 ||
def->cputune.quota > 18446744073709551LL)) {
virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s",
_("Value of cputune quota must be in range "
"[1000, 18446744073709551]"));
goto error;
}

if (virXPathULongLong("string(./cputune/global_period[1])", ctxt,
&def->cputune.global_period) < -1) {
virReportError(VIR_ERR_XML_ERROR, "%s",
_("can't parse cputune global period value"));
goto error;
}

if (def->cputune.global_period > 0 &&
(def->cputune.global_period < 1000 || def->cputune.global_period > 1000000)) {
virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s",
_("Value of cputune global period must be in range "
"[1000, 1000000]"));
goto error;
}

if (virXPathLongLong("string(./cputune/global_quota[1])", ctxt,
&def->cputune.global_quota) < -1) {
virReportError(VIR_ERR_XML_ERROR, "%s",
_("can't parse cputune global quota value"));
goto error;
}

if (def->cputune.global_quota > 0 &&
(def->cputune.global_quota < 1000 ||
def->cputune.global_quota > 18446744073709551LL)) {
virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s",
_("Value of cputune global quota must be in range "
"[1000, 18446744073709551]"));
goto error;
}

if (virXPathULongLong("string(./cputune/emulator_period[1])", ctxt,
&def->cputune.emulator_period) < -1) {
virReportError(VIR_ERR_XML_ERROR, "%s",
_("can't parse cputune emulator period value"));
goto error;
}

if (def->cputune.emulator_period > 0 &&
(def->cputune.emulator_period < 1000 ||
def->cputune.emulator_period > 1000000)) {
virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s",
_("Value of cputune emulator_period must be in range "
"[1000, 1000000]"));
goto error;
}

if (virXPathLongLong("string(./cputune/emulator_quota[1])", ctxt,
&def->cputune.emulator_quota) < -1) {
virReportError(VIR_ERR_XML_ERROR, "%s",
_("can't parse cputune emulator quota value"));
goto error;
}

if (def->cputune.emulator_quota > 0 &&
(def->cputune.emulator_quota < 1000 ||
def->cputune.emulator_quota > 18446744073709551LL)) {
virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s",
_("Value of cputune emulator_quota must be in range "
"[1000, 18446744073709551]"));
goto error;
}

if (virXPathULongLong("string(./cputune/iothread_period[1])", ctxt,
&def->cputune.iothread_period) < -1) {
Expand All @@ -19767,31 +19761,13 @@ virDomainDefParseXML(xmlDocPtr xml,
goto error;
}

if (def->cputune.iothread_period > 0 &&
(def->cputune.iothread_period < 1000 ||
def->cputune.iothread_period > 1000000)) {
virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s",
_("Value of cputune iothread_period must be in range "
"[1000, 1000000]"));
goto error;
}

if (virXPathLongLong("string(./cputune/iothread_quota[1])", ctxt,
&def->cputune.iothread_quota) < -1) {
virReportError(VIR_ERR_XML_ERROR, "%s",
_("can't parse cputune iothread quota value"));
goto error;
}

if (def->cputune.iothread_quota > 0 &&
(def->cputune.iothread_quota < 1000 ||
def->cputune.iothread_quota > 18446744073709551LL)) {
virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s",
_("Value of cputune iothread_quota must be in range "
"[1000, 18446744073709551]"));
goto error;
}

if ((n = virXPathNodeSet("./cputune/vcpupin", ctxt, &nodes)) < 0)
goto error;

Expand Down

0 comments on commit 265e692

Please sign in to comment.