1
0
mirror of https://gitlab.com/libvirt/libvirt.git synced 2024-12-26 03:21:44 +03:00

qemuMonitorGetDeviceProps: Return data in a hash table

Create a hash table of device property names which also stores the
corresponding JSON object so that the detection code can look at the
recently added 'default-value' field and possibly others.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Michal Privoznik <mprivozn@redhat.com>
This commit is contained in:
Peter Krempa 2020-05-06 19:53:43 +02:00
parent 0b52b023fc
commit 6de5cac7f0
5 changed files with 59 additions and 30 deletions

View File

@ -2580,20 +2580,24 @@ virQEMUCapsProbeQMPDeviceProperties(virQEMUCapsPtr qemuCaps,
for (i = 0; i < G_N_ELEMENTS(virQEMUCapsDeviceProps); i++) {
virQEMUCapsObjectTypeProps *device = virQEMUCapsDeviceProps + i;
VIR_AUTOSTRINGLIST values = NULL;
int nvalues;
g_autoptr(virHashTable) qemuprops = NULL;
size_t j;
if (device->capsCondition >= 0 &&
!virQEMUCapsGet(qemuCaps, device->capsCondition))
continue;
if ((nvalues = qemuMonitorGetDeviceProps(mon, device->type, &values)) < 0)
if (!(qemuprops = qemuMonitorGetDeviceProps(mon, device->type)))
return -1;
virQEMUCapsProcessStringFlags(qemuCaps,
device->nprops,
device->props,
nvalues, values);
for (j = 0; j < device->nprops; j++) {
virJSONValuePtr entry = virHashLookup(qemuprops, device->props[j].value);
if (!entry)
continue;
virQEMUCapsSet(qemuCaps, device->props[j].flag);
}
}
return 0;

View File

@ -3764,16 +3764,15 @@ qemuMonitorGetObjectTypes(qemuMonitorPtr mon,
}
int
virHashTablePtr
qemuMonitorGetDeviceProps(qemuMonitorPtr mon,
const char *device,
char ***props)
const char *device)
{
VIR_DEBUG("device=%s props=%p", device, props);
VIR_DEBUG("device=%s", device);
QEMU_CHECK_MONITOR(mon);
QEMU_CHECK_MONITOR_NULL(mon);
return qemuMonitorJSONGetDeviceProps(mon, device, props);
return qemuMonitorJSONGetDeviceProps(mon, device);
}

View File

@ -1203,9 +1203,8 @@ int qemuMonitorGetKVMState(qemuMonitorPtr mon,
int qemuMonitorGetObjectTypes(qemuMonitorPtr mon,
char ***types);
int qemuMonitorGetDeviceProps(qemuMonitorPtr mon,
const char *device,
char ***props);
virHashTablePtr qemuMonitorGetDeviceProps(qemuMonitorPtr mon,
const char *device);
int qemuMonitorGetObjectProps(qemuMonitorPtr mon,
const char *object,
char ***props);

View File

@ -6745,28 +6745,56 @@ qemuMonitorJSONParsePropsList(virJSONValuePtr cmd,
}
int
qemuMonitorJSONGetDeviceProps(qemuMonitorPtr mon,
const char *device,
char ***props)
static int
qemuMonitorJSONGetDevicePropsWorker(size_t pos G_GNUC_UNUSED,
virJSONValuePtr item,
void *opaque)
{
const char *name = virJSONValueObjectGetString(item, "name");
virHashTablePtr devices = opaque;
if (!name) {
virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
_("reply data was missing 'name'"));
return -1;
}
if (virHashAddEntry(devices, name, item) < 0)
return -1;
return 0;
}
virHashTablePtr
qemuMonitorJSONGetDeviceProps(qemuMonitorPtr mon,
const char *device)
{
g_autoptr(virHashTable) props = virHashNew(virJSONValueHashFree);
g_autoptr(virJSONValue) cmd = NULL;
g_autoptr(virJSONValue) reply = NULL;
*props = NULL;
if (!(cmd = qemuMonitorJSONMakeCommand("device-list-properties",
"s:typename", device,
NULL)))
return -1;
return NULL;
if (qemuMonitorJSONCommand(mon, cmd, &reply) < 0)
return -1;
return NULL;
/* return empty hash */
if (qemuMonitorJSONHasError(reply, "DeviceNotFound"))
return 0;
return g_steal_pointer(&props);
return qemuMonitorJSONParsePropsList(cmd, reply, NULL, props);
if (qemuMonitorJSONCheckReply(cmd, reply, VIR_JSON_TYPE_ARRAY) < 0)
return NULL;
if (virJSONValueArrayForeachSteal(virJSONValueObjectGetArray(reply, "return"),
qemuMonitorJSONGetDevicePropsWorker,
props) < 0)
return NULL;
return g_steal_pointer(&props);
}

View File

@ -487,10 +487,9 @@ int qemuMonitorJSONSetObjectProperty(qemuMonitorPtr mon,
qemuMonitorJSONObjectPropertyPtr prop)
ATTRIBUTE_NONNULL(2) ATTRIBUTE_NONNULL(3) ATTRIBUTE_NONNULL(4);
int qemuMonitorJSONGetDeviceProps(qemuMonitorPtr mon,
const char *device,
char ***props)
ATTRIBUTE_NONNULL(2) ATTRIBUTE_NONNULL(3);
virHashTablePtr qemuMonitorJSONGetDeviceProps(qemuMonitorPtr mon,
const char *device)
ATTRIBUTE_NONNULL(2);
int qemuMonitorJSONGetObjectProps(qemuMonitorPtr mon,
const char *object,
char ***props)