virsh: domain: refactor cmdSchedinfo()

Signed-off-by: Kristina Hanicova <khanicov@redhat.com>
Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
Reviewed-by: Michal Privoznik <mprivozn@redhat.com>
This commit is contained in:
Kristina Hanicova 2021-09-24 01:25:07 +02:00 committed by Michal Privoznik
parent 55178b5c9e
commit e31502544c

View File

@ -5150,14 +5150,13 @@ cmdSchedInfoUpdate(vshControl *ctl, const vshCmd *cmd,
static bool static bool
cmdSchedinfo(vshControl *ctl, const vshCmd *cmd) cmdSchedinfo(vshControl *ctl, const vshCmd *cmd)
{ {
char *schedulertype; g_autofree char *schedulertype = NULL;
g_autoptr(virshDomain) dom = NULL; g_autoptr(virshDomain) dom = NULL;
virTypedParameterPtr params = NULL; virTypedParameterPtr params = NULL;
virTypedParameterPtr updates = NULL; virTypedParameterPtr updates = NULL;
int nparams = 0; int nparams = 0;
int nupdates = 0; int nupdates = 0;
size_t i; size_t i;
int ret;
bool ret_val = false; bool ret_val = false;
unsigned int flags = VIR_DOMAIN_AFFECT_CURRENT; unsigned int flags = VIR_DOMAIN_AFFECT_CURRENT;
bool current = vshCommandOptBool(cmd, "current"); bool current = vshCommandOptBool(cmd, "current");
@ -5176,73 +5175,67 @@ cmdSchedinfo(vshControl *ctl, const vshCmd *cmd)
return false; return false;
/* Print SchedulerType */ /* Print SchedulerType */
schedulertype = virDomainGetSchedulerType(dom, &nparams); if (!(schedulertype = virDomainGetSchedulerType(dom, &nparams))) {
if (schedulertype != NULL) {
vshPrint(ctl, "%-15s: %s\n", _("Scheduler"), schedulertype);
VIR_FREE(schedulertype);
} else {
vshPrint(ctl, "%-15s: %s\n", _("Scheduler"), _("Unknown")); vshPrint(ctl, "%-15s: %s\n", _("Scheduler"), _("Unknown"));
goto cleanup; goto cleanup;
} }
if (nparams) { vshPrint(ctl, "%-15s: %s\n", _("Scheduler"), schedulertype);
params = g_new0(virTypedParameter, nparams);
memset(params, 0, sizeof(*params) * nparams); if (!nparams)
goto cleanup;
params = g_new0(virTypedParameter, nparams);
memset(params, 0, sizeof(*params) * nparams);
if (flags || current) {
/* We cannot query both live and config at once, so settle
on current in that case. If we are setting, then the
two values should match when we re-query; otherwise, we
report the error later. */
if (virDomainGetSchedulerParametersFlags(dom, params, &nparams,
((live && config) ? 0 : flags)) == -1)
goto cleanup;
} else {
if (virDomainGetSchedulerParameters(dom, params, &nparams) == -1)
goto cleanup;
}
/* See if any params are being set */
if ((nupdates = cmdSchedInfoUpdate(ctl, cmd, params, nparams,
&updates)) < 0)
goto cleanup;
/* Update parameters & refresh data */
if (nupdates > 0) {
if (flags || current) { if (flags || current) {
/* We cannot query both live and config at once, so settle if (virDomainSetSchedulerParametersFlags(dom, updates,
on current in that case. If we are setting, then the nupdates, flags) == -1)
two values should match when we re-query; otherwise, we
report the error later. */
ret = virDomainGetSchedulerParametersFlags(dom, params, &nparams,
((live && config) ? 0
: flags));
} else {
ret = virDomainGetSchedulerParameters(dom, params, &nparams);
}
if (ret == -1)
goto cleanup;
/* See if any params are being set */
if ((nupdates = cmdSchedInfoUpdate(ctl, cmd, params, nparams,
&updates)) < 0)
goto cleanup;
/* Update parameters & refresh data */
if (nupdates > 0) {
if (flags || current)
ret = virDomainSetSchedulerParametersFlags(dom, updates,
nupdates, flags);
else
ret = virDomainSetSchedulerParameters(dom, updates, nupdates);
if (ret == -1)
goto cleanup; goto cleanup;
if (flags || current) if (virDomainGetSchedulerParametersFlags(dom, params, &nparams,
ret = virDomainGetSchedulerParametersFlags(dom, params, ((live && config) ? 0 : flags)) == -1)
&nparams,
((live && config) ? 0
: flags));
else
ret = virDomainGetSchedulerParameters(dom, params, &nparams);
if (ret == -1)
goto cleanup; goto cleanup;
} else { } else {
/* When not doing --set, --live and --config do not mix. */ if (virDomainSetSchedulerParameters(dom, updates, nupdates) == -1)
if (live && config) {
vshError(ctl, "%s",
_("cannot query both live and config at once"));
goto cleanup; goto cleanup;
}
}
ret_val = true; if (virDomainGetSchedulerParameters(dom, params, &nparams) == -1)
for (i = 0; i < nparams; i++) { goto cleanup;
char *str = vshGetTypedParamValue(ctl, &params[i]);
vshPrint(ctl, "%-15s: %s\n", params[i].field, str);
VIR_FREE(str);
} }
} else {
/* When not doing --set, --live and --config do not mix. */
if (live && config) {
vshError(ctl, "%s",
_("cannot query both live and config at once"));
goto cleanup;
}
}
ret_val = true;
for (i = 0; i < nparams; i++) {
g_autofree char *str = vshGetTypedParamValue(ctl, &params[i]);
vshPrint(ctl, "%-15s: %s\n", params[i].field, str);
} }
cleanup: cleanup: