qemu: Refactor qemuDomainGetSchedulerParametersFlags

Use virDomainCputune struct to store the data rather than exploding the
fields and use macros to fill the typed params.
This commit is contained in:
Peter Krempa 2016-05-25 12:36:54 +02:00
parent e6e144689d
commit d314410fb8

View File

@ -10325,28 +10325,20 @@ qemuDomainGetSchedulerParametersFlags(virDomainPtr dom,
{ {
virQEMUDriverPtr driver = dom->conn->privateData; virQEMUDriverPtr driver = dom->conn->privateData;
virDomainObjPtr vm = NULL; virDomainObjPtr vm = NULL;
unsigned long long shares; virDomainCputune data;
unsigned long long period;
long long quota;
unsigned long long global_period;
long long global_quota;
unsigned long long emulator_period;
long long emulator_quota;
int ret = -1; int ret = -1;
int rc; bool cpu_bw_status = true;
bool cpu_bw_status = false;
int saved_nparams = 0;
virDomainDefPtr persistentDef; virDomainDefPtr persistentDef;
virDomainDefPtr def; virDomainDefPtr def;
qemuDomainObjPrivatePtr priv; qemuDomainObjPrivatePtr priv;
int maxparams = *nparams;
*nparams = 0;
virCheckFlags(VIR_DOMAIN_AFFECT_LIVE | virCheckFlags(VIR_DOMAIN_AFFECT_LIVE |
VIR_DOMAIN_AFFECT_CONFIG | VIR_DOMAIN_AFFECT_CONFIG |
VIR_TYPED_PARAM_STRING_OKAY, -1); VIR_TYPED_PARAM_STRING_OKAY, -1);
/* We don't return strings, and thus trivially support this flag. */
flags &= ~VIR_TYPED_PARAM_STRING_OKAY;
if (!(vm = qemuDomObjFromDomain(dom))) if (!(vm = qemuDomObjFromDomain(dom)))
goto cleanup; goto cleanup;
@ -10361,113 +10353,62 @@ qemuDomainGetSchedulerParametersFlags(virDomainPtr dom,
goto cleanup; goto cleanup;
} }
if (*nparams > 1)
cpu_bw_status = virCgroupSupportsCpuBW(priv->cgroup);
if (virDomainObjGetDefs(vm, flags, &def, &persistentDef) < 0) if (virDomainObjGetDefs(vm, flags, &def, &persistentDef) < 0)
goto cleanup; goto cleanup;
if (persistentDef) { if (persistentDef) {
shares = persistentDef->cputune.shares; data = persistentDef->cputune;
if (*nparams > 1) { } else if (def) {
period = persistentDef->cputune.period; if (!virCgroupHasController(priv->cgroup, VIR_CGROUP_CONTROLLER_CPU)) {
quota = persistentDef->cputune.quota; virReportError(VIR_ERR_OPERATION_INVALID,
global_period = persistentDef->cputune.global_period; "%s", _("cgroup CPU controller is not mounted"));
global_quota = persistentDef->cputune.global_quota; goto cleanup;
emulator_period = persistentDef->cputune.emulator_period;
emulator_quota = persistentDef->cputune.emulator_quota;
cpu_bw_status = true; /* Allow copy of data to params[] */
} }
goto out;
}
if (!virCgroupHasController(priv->cgroup, VIR_CGROUP_CONTROLLER_CPU)) { if (virCgroupGetCpuShares(priv->cgroup, &data.shares) < 0)
virReportError(VIR_ERR_OPERATION_INVALID,
"%s", _("cgroup CPU controller is not mounted"));
goto cleanup;
}
if (virCgroupGetCpuShares(priv->cgroup, &shares) < 0)
goto cleanup;
if (*nparams > 1 && cpu_bw_status) {
rc = qemuGetVcpusBWLive(vm, &period, &quota);
if (rc != 0)
goto cleanup; goto cleanup;
if (virCgroupSupportsCpuBW(priv->cgroup)) {
if (maxparams > 1 &&
qemuGetVcpusBWLive(vm, &data.period, &data.quota) < 0)
goto cleanup;
if (maxparams > 3 &&
qemuGetEmulatorBandwidthLive(priv->cgroup, &data.emulator_period,
&data.emulator_quota) < 0)
goto cleanup;
if (maxparams > 5 &&
qemuGetGlobalBWLive(priv->cgroup, &data.global_period,
&data.global_quota) < 0)
goto cleanup;
} else {
cpu_bw_status = false;
}
} }
if (*nparams > 3 && cpu_bw_status) { #define QEMU_SCHED_ASSIGN(param, name, type) \
rc = qemuGetEmulatorBandwidthLive(priv->cgroup, &emulator_period, if (*nparams < maxparams && \
&emulator_quota); virTypedParameterAssign(&(params[(*nparams)++]), \
if (rc != 0) VIR_DOMAIN_SCHEDULER_ ## name, \
goto cleanup; VIR_TYPED_PARAM_ ## type, \
} data.param) < 0) \
goto cleanup
if (*nparams > 5 && cpu_bw_status) { QEMU_SCHED_ASSIGN(shares, CPU_SHARES, ULLONG);
rc = qemuGetGlobalBWLive(priv->cgroup, &global_period, &global_quota);
if (rc != 0)
goto cleanup;
}
out:
if (virTypedParameterAssign(&params[0], VIR_DOMAIN_SCHEDULER_CPU_SHARES,
VIR_TYPED_PARAM_ULLONG, shares) < 0)
goto cleanup;
saved_nparams++;
if (cpu_bw_status) { if (cpu_bw_status) {
if (*nparams > saved_nparams) { QEMU_SCHED_ASSIGN(period, VCPU_PERIOD, ULLONG);
if (virTypedParameterAssign(&params[1], QEMU_SCHED_ASSIGN(quota, VCPU_QUOTA, LLONG);
VIR_DOMAIN_SCHEDULER_VCPU_PERIOD,
VIR_TYPED_PARAM_ULLONG, period) < 0)
goto cleanup;
saved_nparams++;
}
if (*nparams > saved_nparams) { QEMU_SCHED_ASSIGN(emulator_period, EMULATOR_PERIOD, ULLONG);
if (virTypedParameterAssign(&params[2], QEMU_SCHED_ASSIGN(emulator_quota, EMULATOR_QUOTA, LLONG);
VIR_DOMAIN_SCHEDULER_VCPU_QUOTA,
VIR_TYPED_PARAM_LLONG, quota) < 0)
goto cleanup;
saved_nparams++;
}
if (*nparams > saved_nparams) { QEMU_SCHED_ASSIGN(global_period, GLOBAL_PERIOD, ULLONG);
if (virTypedParameterAssign(&params[3], QEMU_SCHED_ASSIGN(global_quota, GLOBAL_QUOTA, LLONG);
VIR_DOMAIN_SCHEDULER_EMULATOR_PERIOD,
VIR_TYPED_PARAM_ULLONG,
emulator_period) < 0)
goto cleanup;
saved_nparams++;
}
if (*nparams > saved_nparams) {
if (virTypedParameterAssign(&params[4],
VIR_DOMAIN_SCHEDULER_EMULATOR_QUOTA,
VIR_TYPED_PARAM_LLONG,
emulator_quota) < 0)
goto cleanup;
saved_nparams++;
}
if (*nparams > saved_nparams) {
if (virTypedParameterAssign(&params[5],
VIR_DOMAIN_SCHEDULER_GLOBAL_PERIOD,
VIR_TYPED_PARAM_ULLONG, global_period) < 0)
goto cleanup;
saved_nparams++;
}
if (*nparams > saved_nparams) {
if (virTypedParameterAssign(&params[6],
VIR_DOMAIN_SCHEDULER_GLOBAL_QUOTA,
VIR_TYPED_PARAM_LLONG, global_quota) < 0)
goto cleanup;
saved_nparams++;
}
} }
*nparams = saved_nparams; #undef QEMU_SCHED_ASSIGN
ret = 0; ret = 0;