mirror of
https://gitlab.com/libvirt/libvirt.git
synced 2025-03-20 07:59:00 +00:00
qemu_monitor: Introduce qemuMonitorJSONGetPRManagerInfo
This function fetches status of all pr-managers. So far, qemu reports only a single attribute "connected" but that fits our needs. Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
This commit is contained in:
parent
6fbda83330
commit
5f085862e8
@ -4335,3 +4335,28 @@ qemuMonitorGetSEVMeasurement(qemuMonitorPtr mon)
|
||||
|
||||
return qemuMonitorJSONGetSEVMeasurement(mon);
|
||||
}
|
||||
|
||||
|
||||
int
|
||||
qemuMonitorGetPRManagerInfo(qemuMonitorPtr mon,
|
||||
virHashTablePtr *retinfo)
|
||||
{
|
||||
int ret = -1;
|
||||
virHashTablePtr info = NULL;
|
||||
|
||||
*retinfo = NULL;
|
||||
|
||||
QEMU_CHECK_MONITOR(mon);
|
||||
|
||||
if (!(info = virHashCreate(10, virHashValueFree)))
|
||||
goto cleanup;
|
||||
|
||||
if (qemuMonitorJSONGetPRManagerInfo(mon, info) < 0)
|
||||
goto cleanup;
|
||||
|
||||
VIR_STEAL_PTR(*retinfo, info);
|
||||
ret = 0;
|
||||
cleanup:
|
||||
virHashFree(info);
|
||||
return ret;
|
||||
}
|
||||
|
@ -1156,4 +1156,13 @@ int qemuMonitorBlockdevDel(qemuMonitorPtr mon,
|
||||
char *
|
||||
qemuMonitorGetSEVMeasurement(qemuMonitorPtr mon);
|
||||
|
||||
typedef struct _qemuMonitorPRManagerInfo qemuMonitorPRManagerInfo;
|
||||
typedef qemuMonitorPRManagerInfo *qemuMonitorPRManagerInfoPtr;
|
||||
struct _qemuMonitorPRManagerInfo {
|
||||
bool connected;
|
||||
};
|
||||
|
||||
int qemuMonitorGetPRManagerInfo(qemuMonitorPtr mon,
|
||||
virHashTablePtr *retinfo);
|
||||
|
||||
#endif /* QEMU_MONITOR_H */
|
||||
|
@ -8052,3 +8052,82 @@ qemuMonitorJSONGetSEVMeasurement(qemuMonitorPtr mon)
|
||||
virJSONValueFree(reply);
|
||||
return measurement;
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* Example return data
|
||||
*
|
||||
* "return": [
|
||||
* { "connected": true, "id": "pr-helper0" }
|
||||
* ]
|
||||
*/
|
||||
static int
|
||||
qemuMonitorJSONExtractPRManagerInfo(virJSONValuePtr reply,
|
||||
virHashTablePtr info)
|
||||
{
|
||||
qemuMonitorPRManagerInfoPtr entry = NULL;
|
||||
virJSONValuePtr data;
|
||||
int ret = -1;
|
||||
size_t i;
|
||||
|
||||
data = virJSONValueObjectGetArray(reply, "return");
|
||||
|
||||
for (i = 0; i < virJSONValueArraySize(data); i++) {
|
||||
virJSONValuePtr prManager = virJSONValueArrayGet(data, i);
|
||||
const char *alias;
|
||||
|
||||
if (!(alias = virJSONValueObjectGetString(prManager, "id")))
|
||||
goto malformed;
|
||||
|
||||
if (VIR_ALLOC(entry) < 0)
|
||||
goto cleanup;
|
||||
|
||||
if (virJSONValueObjectGetBoolean(prManager,
|
||||
"connected",
|
||||
&entry->connected) < 0) {
|
||||
goto malformed;
|
||||
}
|
||||
|
||||
if (virHashAddEntry(info, alias, entry) < 0)
|
||||
goto cleanup;
|
||||
|
||||
entry = NULL;
|
||||
}
|
||||
|
||||
ret = 0;
|
||||
cleanup:
|
||||
VIR_FREE(entry);
|
||||
return ret;
|
||||
|
||||
malformed:
|
||||
virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
|
||||
_("malformed prManager reply"));
|
||||
goto cleanup;
|
||||
}
|
||||
|
||||
|
||||
int
|
||||
qemuMonitorJSONGetPRManagerInfo(qemuMonitorPtr mon,
|
||||
virHashTablePtr info)
|
||||
{
|
||||
int ret = -1;
|
||||
virJSONValuePtr cmd;
|
||||
virJSONValuePtr reply = NULL;
|
||||
|
||||
if (!(cmd = qemuMonitorJSONMakeCommand("query-pr-managers",
|
||||
NULL)))
|
||||
return -1;
|
||||
|
||||
if (qemuMonitorJSONCommand(mon, cmd, &reply) < 0)
|
||||
goto cleanup;
|
||||
|
||||
if (qemuMonitorJSONCheckReply(cmd, reply, VIR_JSON_TYPE_ARRAY) < 0)
|
||||
goto cleanup;
|
||||
|
||||
ret = qemuMonitorJSONExtractPRManagerInfo(reply, info);
|
||||
cleanup:
|
||||
virJSONValueFree(cmd);
|
||||
virJSONValueFree(reply);
|
||||
return ret;
|
||||
|
||||
}
|
||||
|
@ -550,4 +550,8 @@ int qemuMonitorJSONBlockdevDel(qemuMonitorPtr mon,
|
||||
const char *nodename)
|
||||
ATTRIBUTE_NONNULL(1) ATTRIBUTE_NONNULL(2);
|
||||
|
||||
int qemuMonitorJSONGetPRManagerInfo(qemuMonitorPtr mon,
|
||||
virHashTablePtr info)
|
||||
ATTRIBUTE_NONNULL(1) ATTRIBUTE_NONNULL(2);
|
||||
|
||||
#endif /* QEMU_MONITOR_JSON_H */
|
||||
|
Loading…
x
Reference in New Issue
Block a user