1
0
mirror of https://gitlab.com/libvirt/libvirt.git synced 2025-03-07 17:28:15 +00:00

qemu: agent: Remove unneeded cleanup sections

Remove the cleanup sections where not needed after we've converted to
automatic freeing of virJSONValue.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
This commit is contained in:
Peter Krempa 2021-12-01 10:44:50 +01:00
parent 2783f39adf
commit b3bff3df78

View File

@ -1205,7 +1205,6 @@ VIR_ENUM_IMPL(qemuAgentShutdownMode,
int qemuAgentShutdown(qemuAgent *agent, int qemuAgentShutdown(qemuAgent *agent,
qemuAgentShutdownMode mode) qemuAgentShutdownMode mode)
{ {
int ret = -1;
g_autoptr(virJSONValue) cmd = NULL; g_autoptr(virJSONValue) cmd = NULL;
g_autoptr(virJSONValue) reply = NULL; g_autoptr(virJSONValue) reply = NULL;
@ -1219,10 +1218,9 @@ int qemuAgentShutdown(qemuAgent *agent,
agent->await_event = QEMU_AGENT_EVENT_RESET; agent->await_event = QEMU_AGENT_EVENT_RESET;
else else
agent->await_event = QEMU_AGENT_EVENT_SHUTDOWN; agent->await_event = QEMU_AGENT_EVENT_SHUTDOWN;
ret = qemuAgentCommand(agent, cmd, &reply,
VIR_DOMAIN_QEMU_AGENT_COMMAND_SHUTDOWN);
return ret; return qemuAgentCommand(agent, cmd, &reply,
VIR_DOMAIN_QEMU_AGENT_COMMAND_SHUTDOWN);
} }
/* /*
@ -1242,7 +1240,7 @@ int qemuAgentShutdown(qemuAgent *agent,
int qemuAgentFSFreeze(qemuAgent *agent, const char **mountpoints, int qemuAgentFSFreeze(qemuAgent *agent, const char **mountpoints,
unsigned int nmountpoints) unsigned int nmountpoints)
{ {
int ret = -1; int nfrozen = 0;
g_autoptr(virJSONValue) cmd = NULL; g_autoptr(virJSONValue) cmd = NULL;
g_autoptr(virJSONValue) reply = NULL; g_autoptr(virJSONValue) reply = NULL;
@ -1258,18 +1256,18 @@ int qemuAgentFSFreeze(qemuAgent *agent, const char **mountpoints,
} }
if (!cmd) if (!cmd)
goto cleanup; return -1;
if (qemuAgentCommand(agent, cmd, &reply, agent->timeout) < 0) if (qemuAgentCommand(agent, cmd, &reply, agent->timeout) < 0)
goto cleanup; return -1;
if (virJSONValueObjectGetNumberInt(reply, "return", &ret) < 0) { if (virJSONValueObjectGetNumberInt(reply, "return", &nfrozen) < 0) {
virReportError(VIR_ERR_INTERNAL_ERROR, "%s", virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
_("malformed return value")); _("malformed return value"));
return -1;
} }
cleanup: return nfrozen;
return ret;
} }
/* /*
@ -1285,7 +1283,7 @@ int qemuAgentFSFreeze(qemuAgent *agent, const char **mountpoints,
*/ */
int qemuAgentFSThaw(qemuAgent *agent) int qemuAgentFSThaw(qemuAgent *agent)
{ {
int ret = -1; int nthawed = 0;
g_autoptr(virJSONValue) cmd = qemuAgentMakeCommand("guest-fsfreeze-thaw", NULL); g_autoptr(virJSONValue) cmd = qemuAgentMakeCommand("guest-fsfreeze-thaw", NULL);
g_autoptr(virJSONValue) reply = NULL; g_autoptr(virJSONValue) reply = NULL;
@ -1293,15 +1291,15 @@ int qemuAgentFSThaw(qemuAgent *agent)
return -1; return -1;
if (qemuAgentCommand(agent, cmd, &reply, agent->timeout) < 0) if (qemuAgentCommand(agent, cmd, &reply, agent->timeout) < 0)
goto cleanup; return -1;
if (virJSONValueObjectGetNumberInt(reply, "return", &ret) < 0) { if (virJSONValueObjectGetNumberInt(reply, "return", &nthawed) < 0) {
virReportError(VIR_ERR_INTERNAL_ERROR, "%s", virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
_("malformed return value")); _("malformed return value"));
return -1;
} }
cleanup: return nthawed;
return ret;
} }
VIR_ENUM_DECL(qemuAgentSuspendMode); VIR_ENUM_DECL(qemuAgentSuspendMode);
@ -1317,7 +1315,6 @@ int
qemuAgentSuspend(qemuAgent *agent, qemuAgentSuspend(qemuAgent *agent,
unsigned int target) unsigned int target)
{ {
int ret = -1;
g_autoptr(virJSONValue) cmd = NULL; g_autoptr(virJSONValue) cmd = NULL;
g_autoptr(virJSONValue) reply = NULL; g_autoptr(virJSONValue) reply = NULL;
@ -1327,9 +1324,8 @@ qemuAgentSuspend(qemuAgent *agent,
return -1; return -1;
agent->await_event = QEMU_AGENT_EVENT_SUSPEND; agent->await_event = QEMU_AGENT_EVENT_SUSPEND;
ret = qemuAgentCommand(agent, cmd, &reply, agent->timeout);
return ret; return qemuAgentCommand(agent, cmd, &reply, agent->timeout);
} }
int int
@ -1338,7 +1334,7 @@ qemuAgentArbitraryCommand(qemuAgent *agent,
char **result, char **result,
int timeout) int timeout)
{ {
int ret = -1; int rc;
g_autoptr(virJSONValue) cmd = NULL; g_autoptr(virJSONValue) cmd = NULL;
g_autoptr(virJSONValue) reply = NULL; g_autoptr(virJSONValue) reply = NULL;
@ -1348,28 +1344,25 @@ qemuAgentArbitraryCommand(qemuAgent *agent,
_("guest agent timeout '%d' is " _("guest agent timeout '%d' is "
"less than the minimum '%d'"), "less than the minimum '%d'"),
timeout, VIR_DOMAIN_QEMU_AGENT_COMMAND_MIN); timeout, VIR_DOMAIN_QEMU_AGENT_COMMAND_MIN);
goto cleanup; return -1;
} }
if (!(cmd = virJSONValueFromString(cmd_str))) if (!(cmd = virJSONValueFromString(cmd_str)))
goto cleanup; return -1;
if ((ret = qemuAgentCommand(agent, cmd, &reply, timeout)) < 0) if ((rc = qemuAgentCommand(agent, cmd, &reply, timeout)) < 0)
goto cleanup; return rc;
if (!(*result = virJSONValueToString(reply, false))) if (!(*result = virJSONValueToString(reply, false)))
ret = -1; return -1;
return rc;
cleanup:
return ret;
} }
int int
qemuAgentFSTrim(qemuAgent *agent, qemuAgentFSTrim(qemuAgent *agent,
unsigned long long minimum) unsigned long long minimum)
{ {
int ret = -1;
g_autoptr(virJSONValue) cmd = NULL; g_autoptr(virJSONValue) cmd = NULL;
g_autoptr(virJSONValue) reply = NULL; g_autoptr(virJSONValue) reply = NULL;
@ -1377,18 +1370,15 @@ qemuAgentFSTrim(qemuAgent *agent,
"U:minimum", minimum, "U:minimum", minimum,
NULL); NULL);
if (!cmd) if (!cmd)
return ret; return -1;
ret = qemuAgentCommand(agent, cmd, &reply, agent->timeout); return qemuAgentCommand(agent, cmd, &reply, agent->timeout);
return ret;
} }
int int
qemuAgentGetVCPUs(qemuAgent *agent, qemuAgentGetVCPUs(qemuAgent *agent,
qemuAgentCPUInfo **info) qemuAgentCPUInfo **info)
{ {
int ret = -1;
size_t i; size_t i;
g_autoptr(virJSONValue) cmd = NULL; g_autoptr(virJSONValue) cmd = NULL;
g_autoptr(virJSONValue) reply = NULL; g_autoptr(virJSONValue) reply = NULL;
@ -1399,12 +1389,12 @@ qemuAgentGetVCPUs(qemuAgent *agent,
return -1; return -1;
if (qemuAgentCommand(agent, cmd, &reply, agent->timeout) < 0) if (qemuAgentCommand(agent, cmd, &reply, agent->timeout) < 0)
goto cleanup; return -1;
if (!(data = virJSONValueObjectGetArray(reply, "return"))) { if (!(data = virJSONValueObjectGetArray(reply, "return"))) {
virReportError(VIR_ERR_INTERNAL_ERROR, "%s", virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
_("guest-get-vcpus reply was missing return data")); _("guest-get-vcpus reply was missing return data"));
goto cleanup; return -1;
} }
ndata = virJSONValueArraySize(data); ndata = virJSONValueArraySize(data);
@ -1419,33 +1409,30 @@ qemuAgentGetVCPUs(qemuAgent *agent,
virReportError(VIR_ERR_INTERNAL_ERROR, "%s", virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
_("array element missing in guest-get-vcpus return " _("array element missing in guest-get-vcpus return "
"value")); "value"));
goto cleanup; return -1;
} }
if (virJSONValueObjectGetNumberUint(entry, "logical-id", &in->id) < 0) { if (virJSONValueObjectGetNumberUint(entry, "logical-id", &in->id) < 0) {
virReportError(VIR_ERR_INTERNAL_ERROR, "%s", virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
_("'logical-id' missing in reply of guest-get-vcpus")); _("'logical-id' missing in reply of guest-get-vcpus"));
goto cleanup; return -1;
} }
if (virJSONValueObjectGetBoolean(entry, "online", &in->online) < 0) { if (virJSONValueObjectGetBoolean(entry, "online", &in->online) < 0) {
virReportError(VIR_ERR_INTERNAL_ERROR, "%s", virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
_("'online' missing in reply of guest-get-vcpus")); _("'online' missing in reply of guest-get-vcpus"));
goto cleanup; return -1;
} }
if (virJSONValueObjectGetBoolean(entry, "can-offline", if (virJSONValueObjectGetBoolean(entry, "can-offline",
&in->offlinable) < 0) { &in->offlinable) < 0) {
virReportError(VIR_ERR_INTERNAL_ERROR, "%s", virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
_("'can-offline' missing in reply of guest-get-vcpus")); _("'can-offline' missing in reply of guest-get-vcpus"));
goto cleanup; return -1;
} }
} }
ret = ndata; return ndata;
cleanup:
return ret;
} }
@ -1676,7 +1663,6 @@ qemuAgentGetTime(qemuAgent *agent,
long long *seconds, long long *seconds,
unsigned int *nseconds) unsigned int *nseconds)
{ {
int ret = -1;
unsigned long long json_time; unsigned long long json_time;
g_autoptr(virJSONValue) cmd = NULL; g_autoptr(virJSONValue) cmd = NULL;
g_autoptr(virJSONValue) reply = NULL; g_autoptr(virJSONValue) reply = NULL;
@ -1684,25 +1670,22 @@ qemuAgentGetTime(qemuAgent *agent,
cmd = qemuAgentMakeCommand("guest-get-time", cmd = qemuAgentMakeCommand("guest-get-time",
NULL); NULL);
if (!cmd) if (!cmd)
return ret; return -1;
if (qemuAgentCommand(agent, cmd, &reply, agent->timeout) < 0) if (qemuAgentCommand(agent, cmd, &reply, agent->timeout) < 0)
goto cleanup; return -1;
if (virJSONValueObjectGetNumberUlong(reply, "return", &json_time) < 0) { if (virJSONValueObjectGetNumberUlong(reply, "return", &json_time) < 0) {
virReportError(VIR_ERR_INTERNAL_ERROR, "%s", virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
_("malformed return value")); _("malformed return value"));
goto cleanup; return -1;
} }
/* guest agent returns time in nanoseconds, /* guest agent returns time in nanoseconds,
* we need it in seconds here */ * we need it in seconds here */
*seconds = json_time / 1000000000LL; *seconds = json_time / 1000000000LL;
*nseconds = json_time % 1000000000LL; *nseconds = json_time % 1000000000LL;
ret = 0; return 0;
cleanup:
return ret;
} }
@ -1717,7 +1700,6 @@ qemuAgentSetTime(qemuAgent *agent,
unsigned int nseconds, unsigned int nseconds,
bool rtcSync) bool rtcSync)
{ {
int ret = -1;
g_autoptr(virJSONValue) cmd = NULL; g_autoptr(virJSONValue) cmd = NULL;
g_autoptr(virJSONValue) reply = NULL; g_autoptr(virJSONValue) reply = NULL;
@ -1736,7 +1718,7 @@ qemuAgentSetTime(qemuAgent *agent,
virReportError(VIR_ERR_INVALID_ARG, virReportError(VIR_ERR_INVALID_ARG,
_("Time '%lld' is too big for guest agent"), _("Time '%lld' is too big for guest agent"),
seconds); seconds);
return ret; return -1;
} }
json_time = seconds * 1000000000LL; json_time = seconds * 1000000000LL;
@ -1747,14 +1729,12 @@ qemuAgentSetTime(qemuAgent *agent,
} }
if (!cmd) if (!cmd)
return ret; return -1;
if (qemuAgentCommand(agent, cmd, &reply, agent->timeout) < 0) if (qemuAgentCommand(agent, cmd, &reply, agent->timeout) < 0)
goto cleanup; return -1;
ret = 0; return 0;
cleanup:
return ret;
} }
void void