mirror of
https://gitlab.com/libvirt/libvirt.git
synced 2025-03-07 17:28:15 +00:00
qemu: monitor: Reuse qemuMonitorJSONQueryBlock in qemuMonitorJSONBlockIoThrottleInfo
The wrapper executes the command and does error detection so there's no need to open-code all of those things. Signed-off-by: Peter Krempa <pkrempa@redhat.com> Reviewed-by: Ján Tomko <jtomko@redhat.com>
This commit is contained in:
parent
192fdaa614
commit
e7e2bbdc94
@ -4817,21 +4817,14 @@ int qemuMonitorJSONOpenGraphics(qemuMonitorPtr mon,
|
|||||||
goto cleanup; \
|
goto cleanup; \
|
||||||
}
|
}
|
||||||
static int
|
static int
|
||||||
qemuMonitorJSONBlockIoThrottleInfo(virJSONValuePtr result,
|
qemuMonitorJSONBlockIoThrottleInfo(virJSONValuePtr io_throttle,
|
||||||
const char *device,
|
const char *device,
|
||||||
virDomainBlockIoTuneInfoPtr reply)
|
virDomainBlockIoTuneInfoPtr reply)
|
||||||
{
|
{
|
||||||
virJSONValuePtr io_throttle;
|
|
||||||
int ret = -1;
|
int ret = -1;
|
||||||
size_t i;
|
size_t i;
|
||||||
bool found = false;
|
bool found = false;
|
||||||
|
|
||||||
if (!(io_throttle = virJSONValueObjectGetArray(result, "return"))) {
|
|
||||||
virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
|
|
||||||
_(" block_io_throttle reply was missing device list"));
|
|
||||||
goto cleanup;
|
|
||||||
}
|
|
||||||
|
|
||||||
for (i = 0; i < virJSONValueArraySize(io_throttle); i++) {
|
for (i = 0; i < virJSONValueArraySize(io_throttle); i++) {
|
||||||
virJSONValuePtr temp_dev = virJSONValueArrayGet(io_throttle, i);
|
virJSONValuePtr temp_dev = virJSONValueArrayGet(io_throttle, i);
|
||||||
virJSONValuePtr inserted;
|
virJSONValuePtr inserted;
|
||||||
@ -5001,33 +4994,13 @@ int qemuMonitorJSONGetBlockIoThrottle(qemuMonitorPtr mon,
|
|||||||
virDomainBlockIoTuneInfoPtr reply)
|
virDomainBlockIoTuneInfoPtr reply)
|
||||||
{
|
{
|
||||||
int ret = -1;
|
int ret = -1;
|
||||||
virJSONValuePtr cmd = NULL;
|
virJSONValuePtr devices = NULL;
|
||||||
virJSONValuePtr result = NULL;
|
|
||||||
|
|
||||||
cmd = qemuMonitorJSONMakeCommand("query-block", NULL);
|
if (!(devices = qemuMonitorJSONQueryBlock(mon)))
|
||||||
if (!cmd)
|
|
||||||
return -1;
|
return -1;
|
||||||
|
|
||||||
if (qemuMonitorJSONCommand(mon, cmd, &result) < 0)
|
ret = qemuMonitorJSONBlockIoThrottleInfo(devices, device, reply);
|
||||||
goto cleanup;
|
virJSONValueFree(devices);
|
||||||
|
|
||||||
if (virJSONValueObjectHasKey(result, "error")) {
|
|
||||||
if (qemuMonitorJSONHasError(result, "DeviceNotActive"))
|
|
||||||
virReportError(VIR_ERR_OPERATION_INVALID,
|
|
||||||
_("No active operation on device: %s"), device);
|
|
||||||
else if (qemuMonitorJSONHasError(result, "NotSupported"))
|
|
||||||
virReportError(VIR_ERR_OPERATION_INVALID,
|
|
||||||
_("Operation is not supported for device: %s"), device);
|
|
||||||
else
|
|
||||||
virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
|
|
||||||
_("Unexpected error"));
|
|
||||||
goto cleanup;
|
|
||||||
}
|
|
||||||
|
|
||||||
ret = qemuMonitorJSONBlockIoThrottleInfo(result, device, reply);
|
|
||||||
cleanup:
|
|
||||||
virJSONValueFree(cmd);
|
|
||||||
virJSONValueFree(result);
|
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user