mirror of
https://gitlab.com/libvirt/libvirt.git
synced 2025-02-27 05:42:21 +00: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:
parent
0b52b023fc
commit
6de5cac7f0
@ -2580,20 +2580,24 @@ virQEMUCapsProbeQMPDeviceProperties(virQEMUCapsPtr qemuCaps,
|
|||||||
|
|
||||||
for (i = 0; i < G_N_ELEMENTS(virQEMUCapsDeviceProps); i++) {
|
for (i = 0; i < G_N_ELEMENTS(virQEMUCapsDeviceProps); i++) {
|
||||||
virQEMUCapsObjectTypeProps *device = virQEMUCapsDeviceProps + i;
|
virQEMUCapsObjectTypeProps *device = virQEMUCapsDeviceProps + i;
|
||||||
VIR_AUTOSTRINGLIST values = NULL;
|
g_autoptr(virHashTable) qemuprops = NULL;
|
||||||
int nvalues;
|
size_t j;
|
||||||
|
|
||||||
if (device->capsCondition >= 0 &&
|
if (device->capsCondition >= 0 &&
|
||||||
!virQEMUCapsGet(qemuCaps, device->capsCondition))
|
!virQEMUCapsGet(qemuCaps, device->capsCondition))
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
if ((nvalues = qemuMonitorGetDeviceProps(mon, device->type, &values)) < 0)
|
if (!(qemuprops = qemuMonitorGetDeviceProps(mon, device->type)))
|
||||||
return -1;
|
return -1;
|
||||||
|
|
||||||
virQEMUCapsProcessStringFlags(qemuCaps,
|
for (j = 0; j < device->nprops; j++) {
|
||||||
device->nprops,
|
virJSONValuePtr entry = virHashLookup(qemuprops, device->props[j].value);
|
||||||
device->props,
|
|
||||||
nvalues, values);
|
if (!entry)
|
||||||
|
continue;
|
||||||
|
|
||||||
|
virQEMUCapsSet(qemuCaps, device->props[j].flag);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
|
@ -3764,16 +3764,15 @@ qemuMonitorGetObjectTypes(qemuMonitorPtr mon,
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
int
|
virHashTablePtr
|
||||||
qemuMonitorGetDeviceProps(qemuMonitorPtr mon,
|
qemuMonitorGetDeviceProps(qemuMonitorPtr mon,
|
||||||
const char *device,
|
const char *device)
|
||||||
char ***props)
|
|
||||||
{
|
{
|
||||||
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);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -1203,9 +1203,8 @@ int qemuMonitorGetKVMState(qemuMonitorPtr mon,
|
|||||||
|
|
||||||
int qemuMonitorGetObjectTypes(qemuMonitorPtr mon,
|
int qemuMonitorGetObjectTypes(qemuMonitorPtr mon,
|
||||||
char ***types);
|
char ***types);
|
||||||
int qemuMonitorGetDeviceProps(qemuMonitorPtr mon,
|
virHashTablePtr qemuMonitorGetDeviceProps(qemuMonitorPtr mon,
|
||||||
const char *device,
|
const char *device);
|
||||||
char ***props);
|
|
||||||
int qemuMonitorGetObjectProps(qemuMonitorPtr mon,
|
int qemuMonitorGetObjectProps(qemuMonitorPtr mon,
|
||||||
const char *object,
|
const char *object,
|
||||||
char ***props);
|
char ***props);
|
||||||
|
@ -6745,28 +6745,56 @@ qemuMonitorJSONParsePropsList(virJSONValuePtr cmd,
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
int
|
static int
|
||||||
qemuMonitorJSONGetDeviceProps(qemuMonitorPtr mon,
|
qemuMonitorJSONGetDevicePropsWorker(size_t pos G_GNUC_UNUSED,
|
||||||
const char *device,
|
virJSONValuePtr item,
|
||||||
char ***props)
|
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) cmd = NULL;
|
||||||
g_autoptr(virJSONValue) reply = NULL;
|
g_autoptr(virJSONValue) reply = NULL;
|
||||||
|
|
||||||
*props = NULL;
|
|
||||||
|
|
||||||
if (!(cmd = qemuMonitorJSONMakeCommand("device-list-properties",
|
if (!(cmd = qemuMonitorJSONMakeCommand("device-list-properties",
|
||||||
"s:typename", device,
|
"s:typename", device,
|
||||||
NULL)))
|
NULL)))
|
||||||
return -1;
|
return NULL;
|
||||||
|
|
||||||
if (qemuMonitorJSONCommand(mon, cmd, &reply) < 0)
|
if (qemuMonitorJSONCommand(mon, cmd, &reply) < 0)
|
||||||
return -1;
|
return NULL;
|
||||||
|
|
||||||
|
/* return empty hash */
|
||||||
if (qemuMonitorJSONHasError(reply, "DeviceNotFound"))
|
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);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -487,10 +487,9 @@ int qemuMonitorJSONSetObjectProperty(qemuMonitorPtr mon,
|
|||||||
qemuMonitorJSONObjectPropertyPtr prop)
|
qemuMonitorJSONObjectPropertyPtr prop)
|
||||||
ATTRIBUTE_NONNULL(2) ATTRIBUTE_NONNULL(3) ATTRIBUTE_NONNULL(4);
|
ATTRIBUTE_NONNULL(2) ATTRIBUTE_NONNULL(3) ATTRIBUTE_NONNULL(4);
|
||||||
|
|
||||||
int qemuMonitorJSONGetDeviceProps(qemuMonitorPtr mon,
|
virHashTablePtr qemuMonitorJSONGetDeviceProps(qemuMonitorPtr mon,
|
||||||
const char *device,
|
const char *device)
|
||||||
char ***props)
|
ATTRIBUTE_NONNULL(2);
|
||||||
ATTRIBUTE_NONNULL(2) ATTRIBUTE_NONNULL(3);
|
|
||||||
int qemuMonitorJSONGetObjectProps(qemuMonitorPtr mon,
|
int qemuMonitorJSONGetObjectProps(qemuMonitorPtr mon,
|
||||||
const char *object,
|
const char *object,
|
||||||
char ***props)
|
char ***props)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user