mirror of
https://gitlab.com/libvirt/libvirt.git
synced 2025-02-08 20:51:26 +00:00
qemuMonitorJSONGetDeviceProps: Separate props processing
The code that processes list of device properties is going to be reused. Therefore put it into a separate function. Signed-off-by: Michal Privoznik <mprivozn@redhat.com> Reviewed-by: Ján Tomko <jtomko@redhat.com>
This commit is contained in:
parent
920a7d3336
commit
036120209b
@ -6051,32 +6051,16 @@ int qemuMonitorJSONSetObjectProperty(qemuMonitorPtr mon,
|
|||||||
#undef MAKE_SET_CMD
|
#undef MAKE_SET_CMD
|
||||||
|
|
||||||
|
|
||||||
int qemuMonitorJSONGetDeviceProps(qemuMonitorPtr mon,
|
static int
|
||||||
const char *device,
|
qemuMonitorJSONParsePropsList(virJSONValuePtr cmd,
|
||||||
char ***props)
|
virJSONValuePtr reply,
|
||||||
|
char ***props)
|
||||||
{
|
{
|
||||||
int ret = -1;
|
|
||||||
virJSONValuePtr cmd;
|
|
||||||
virJSONValuePtr reply = NULL;
|
|
||||||
virJSONValuePtr data;
|
virJSONValuePtr data;
|
||||||
char **proplist = NULL;
|
char **proplist = NULL;
|
||||||
size_t n = 0;
|
size_t n = 0;
|
||||||
size_t i;
|
size_t i;
|
||||||
|
int ret = -1;
|
||||||
*props = NULL;
|
|
||||||
|
|
||||||
if (!(cmd = qemuMonitorJSONMakeCommand("device-list-properties",
|
|
||||||
"s:typename", device,
|
|
||||||
NULL)))
|
|
||||||
return -1;
|
|
||||||
|
|
||||||
if (qemuMonitorJSONCommand(mon, cmd, &reply) < 0)
|
|
||||||
goto cleanup;
|
|
||||||
|
|
||||||
if (qemuMonitorJSONHasError(reply, "DeviceNotFound")) {
|
|
||||||
ret = 0;
|
|
||||||
goto cleanup;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (qemuMonitorJSONCheckReply(cmd, reply, VIR_JSON_TYPE_ARRAY) < 0)
|
if (qemuMonitorJSONCheckReply(cmd, reply, VIR_JSON_TYPE_ARRAY) < 0)
|
||||||
goto cleanup;
|
goto cleanup;
|
||||||
@ -6094,7 +6078,7 @@ int qemuMonitorJSONGetDeviceProps(qemuMonitorPtr mon,
|
|||||||
|
|
||||||
if (!(tmp = virJSONValueObjectGetString(child, "name"))) {
|
if (!(tmp = virJSONValueObjectGetString(child, "name"))) {
|
||||||
virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
|
virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
|
||||||
_("device-list-properties reply data was missing 'name'"));
|
_("reply data was missing 'name'"));
|
||||||
goto cleanup;
|
goto cleanup;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -6108,8 +6092,37 @@ int qemuMonitorJSONGetDeviceProps(qemuMonitorPtr mon,
|
|||||||
|
|
||||||
cleanup:
|
cleanup:
|
||||||
virStringListFree(proplist);
|
virStringListFree(proplist);
|
||||||
virJSONValueFree(cmd);
|
return ret;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
int qemuMonitorJSONGetDeviceProps(qemuMonitorPtr mon,
|
||||||
|
const char *device,
|
||||||
|
char ***props)
|
||||||
|
{
|
||||||
|
int ret = -1;
|
||||||
|
virJSONValuePtr cmd;
|
||||||
|
virJSONValuePtr reply = NULL;
|
||||||
|
|
||||||
|
*props = NULL;
|
||||||
|
|
||||||
|
if (!(cmd = qemuMonitorJSONMakeCommand("device-list-properties",
|
||||||
|
"s:typename", device,
|
||||||
|
NULL)))
|
||||||
|
return -1;
|
||||||
|
|
||||||
|
if (qemuMonitorJSONCommand(mon, cmd, &reply) < 0)
|
||||||
|
goto cleanup;
|
||||||
|
|
||||||
|
if (qemuMonitorJSONHasError(reply, "DeviceNotFound")) {
|
||||||
|
ret = 0;
|
||||||
|
goto cleanup;
|
||||||
|
}
|
||||||
|
|
||||||
|
ret = qemuMonitorJSONParsePropsList(cmd, reply, props);
|
||||||
|
cleanup:
|
||||||
virJSONValueFree(reply);
|
virJSONValueFree(reply);
|
||||||
|
virJSONValueFree(cmd);
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user