mirror of
https://gitlab.com/libvirt/libvirt.git
synced 2025-03-07 17:28:15 +00:00
qemuAgentSetVCPUsCommand: Refactor cleanup
Signed-off-by: Peter Krempa <pkrempa@redhat.com> Reviewed-by: Michal Privoznik <mprivozn@redhat.com>
This commit is contained in:
parent
0b236a9260
commit
ad3f3bd048
@ -1483,20 +1483,17 @@ qemuAgentSetVCPUsCommand(qemuAgentPtr agent,
|
|||||||
size_t ninfo,
|
size_t ninfo,
|
||||||
int *nmodified)
|
int *nmodified)
|
||||||
{
|
{
|
||||||
int ret = -1;
|
g_autoptr(virJSONValue) cmd = NULL;
|
||||||
virJSONValuePtr cmd = NULL;
|
g_autoptr(virJSONValue) reply = NULL;
|
||||||
virJSONValuePtr reply = NULL;
|
g_autoptr(virJSONValue) cpus = virJSONValueNewArray();
|
||||||
virJSONValuePtr cpus = NULL;
|
|
||||||
virJSONValuePtr cpu = NULL;
|
|
||||||
size_t i;
|
size_t i;
|
||||||
|
int ret;
|
||||||
|
|
||||||
*nmodified = 0;
|
*nmodified = 0;
|
||||||
|
|
||||||
/* create the key data array */
|
|
||||||
cpus = virJSONValueNewArray();
|
|
||||||
|
|
||||||
for (i = 0; i < ninfo; i++) {
|
for (i = 0; i < ninfo; i++) {
|
||||||
qemuAgentCPUInfoPtr in = &info[i];
|
qemuAgentCPUInfoPtr in = &info[i];
|
||||||
|
g_autoptr(virJSONValue) cpu = virJSONValueNewObject();
|
||||||
|
|
||||||
/* don't set state for cpus that were not touched */
|
/* don't set state for cpus that were not touched */
|
||||||
if (!in->modified)
|
if (!in->modified)
|
||||||
@ -1504,31 +1501,26 @@ qemuAgentSetVCPUsCommand(qemuAgentPtr agent,
|
|||||||
|
|
||||||
(*nmodified)++;
|
(*nmodified)++;
|
||||||
|
|
||||||
/* create single cpu object */
|
|
||||||
cpu = virJSONValueNewObject();
|
|
||||||
|
|
||||||
if (virJSONValueObjectAppendNumberInt(cpu, "logical-id", in->id) < 0)
|
if (virJSONValueObjectAppendNumberInt(cpu, "logical-id", in->id) < 0)
|
||||||
goto cleanup;
|
return -1;
|
||||||
|
|
||||||
if (virJSONValueObjectAppendBoolean(cpu, "online", in->online) < 0)
|
if (virJSONValueObjectAppendBoolean(cpu, "online", in->online) < 0)
|
||||||
goto cleanup;
|
return -1;
|
||||||
|
|
||||||
if (virJSONValueArrayAppend(cpus, &cpu) < 0)
|
if (virJSONValueArrayAppend(cpus, &cpu) < 0)
|
||||||
goto cleanup;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (*nmodified == 0) {
|
if (*nmodified == 0)
|
||||||
ret = 0;
|
return 0;
|
||||||
goto cleanup;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!(cmd = qemuAgentMakeCommand("guest-set-vcpus",
|
if (!(cmd = qemuAgentMakeCommand("guest-set-vcpus",
|
||||||
"a:vcpus", &cpus,
|
"a:vcpus", &cpus,
|
||||||
NULL)))
|
NULL)))
|
||||||
goto cleanup;
|
return -1;
|
||||||
|
|
||||||
if (qemuAgentCommand(agent, cmd, &reply, agent->timeout) < 0)
|
if (qemuAgentCommand(agent, cmd, &reply, agent->timeout) < 0)
|
||||||
goto cleanup;
|
return -1;
|
||||||
|
|
||||||
/* All negative values are invalid. Return of 0 is bogus since we wouldn't
|
/* All negative values are invalid. Return of 0 is bogus since we wouldn't
|
||||||
* call the guest agent so that 0 cpus would be set successfully. Reporting
|
* call the guest agent so that 0 cpus would be set successfully. Reporting
|
||||||
@ -1537,14 +1529,9 @@ qemuAgentSetVCPUsCommand(qemuAgentPtr agent,
|
|||||||
ret <= 0 || ret > *nmodified) {
|
ret <= 0 || ret > *nmodified) {
|
||||||
virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
|
virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
|
||||||
_("guest agent returned malformed or invalid return value"));
|
_("guest agent returned malformed or invalid return value"));
|
||||||
ret = -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
cleanup:
|
|
||||||
virJSONValueFree(cmd);
|
|
||||||
virJSONValueFree(reply);
|
|
||||||
virJSONValueFree(cpu);
|
|
||||||
virJSONValueFree(cpus);
|
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user