mirror of
https://gitlab.com/libvirt/libvirt.git
synced 2024-12-25 01:34:11 +03: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,
|
||||
int *nmodified)
|
||||
{
|
||||
int ret = -1;
|
||||
virJSONValuePtr cmd = NULL;
|
||||
virJSONValuePtr reply = NULL;
|
||||
virJSONValuePtr cpus = NULL;
|
||||
virJSONValuePtr cpu = NULL;
|
||||
g_autoptr(virJSONValue) cmd = NULL;
|
||||
g_autoptr(virJSONValue) reply = NULL;
|
||||
g_autoptr(virJSONValue) cpus = virJSONValueNewArray();
|
||||
size_t i;
|
||||
int ret;
|
||||
|
||||
*nmodified = 0;
|
||||
|
||||
/* create the key data array */
|
||||
cpus = virJSONValueNewArray();
|
||||
|
||||
for (i = 0; i < ninfo; i++) {
|
||||
qemuAgentCPUInfoPtr in = &info[i];
|
||||
g_autoptr(virJSONValue) cpu = virJSONValueNewObject();
|
||||
|
||||
/* don't set state for cpus that were not touched */
|
||||
if (!in->modified)
|
||||
@ -1504,31 +1501,26 @@ qemuAgentSetVCPUsCommand(qemuAgentPtr agent,
|
||||
|
||||
(*nmodified)++;
|
||||
|
||||
/* create single cpu object */
|
||||
cpu = virJSONValueNewObject();
|
||||
|
||||
if (virJSONValueObjectAppendNumberInt(cpu, "logical-id", in->id) < 0)
|
||||
goto cleanup;
|
||||
return -1;
|
||||
|
||||
if (virJSONValueObjectAppendBoolean(cpu, "online", in->online) < 0)
|
||||
goto cleanup;
|
||||
return -1;
|
||||
|
||||
if (virJSONValueArrayAppend(cpus, &cpu) < 0)
|
||||
goto cleanup;
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (*nmodified == 0) {
|
||||
ret = 0;
|
||||
goto cleanup;
|
||||
}
|
||||
if (*nmodified == 0)
|
||||
return 0;
|
||||
|
||||
if (!(cmd = qemuAgentMakeCommand("guest-set-vcpus",
|
||||
"a:vcpus", &cpus,
|
||||
NULL)))
|
||||
goto cleanup;
|
||||
return -1;
|
||||
|
||||
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
|
||||
* call the guest agent so that 0 cpus would be set successfully. Reporting
|
||||
@ -1537,14 +1529,9 @@ qemuAgentSetVCPUsCommand(qemuAgentPtr agent,
|
||||
ret <= 0 || ret > *nmodified) {
|
||||
virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
|
||||
_("guest agent returned malformed or invalid return value"));
|
||||
ret = -1;
|
||||
return -1;
|
||||
}
|
||||
|
||||
cleanup:
|
||||
virJSONValueFree(cmd);
|
||||
virJSONValueFree(reply);
|
||||
virJSONValueFree(cpu);
|
||||
virJSONValueFree(cpus);
|
||||
return ret;
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user