mirror of
https://gitlab.com/libvirt/libvirt.git
synced 2025-01-03 19:45:21 +00:00
qemu_capabilities: Separate out device props fetching
The code is generic enough to be reused. Move 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
c2047c5c9f
commit
fb1fae94a1
@ -1249,14 +1249,19 @@ static struct virQEMUCapsStringFlags virQEMUCapsQMPSchemaQueries[] = {
|
|||||||
{ "blockdev-add/arg-type/+qcow2/encrypt/+luks/key-secret", QEMU_CAPS_QCOW2_LUKS },
|
{ "blockdev-add/arg-type/+qcow2/encrypt/+luks/key-secret", QEMU_CAPS_QCOW2_LUKS },
|
||||||
};
|
};
|
||||||
|
|
||||||
struct virQEMUCapsObjectTypeProps {
|
typedef struct _virQEMUCapsObjectTypeProps virQEMUCapsObjectTypeProps;
|
||||||
|
struct _virQEMUCapsObjectTypeProps {
|
||||||
const char *type;
|
const char *type;
|
||||||
struct virQEMUCapsStringFlags *props;
|
struct virQEMUCapsStringFlags *props;
|
||||||
size_t nprops;
|
size_t nprops;
|
||||||
int capsCondition;
|
int capsCondition;
|
||||||
};
|
};
|
||||||
|
|
||||||
static struct virQEMUCapsObjectTypeProps virQEMUCapsDeviceProps[] = {
|
typedef int (*virQEMUCapsObjectTypePropsCB)(qemuMonitorPtr mon,
|
||||||
|
const char *type,
|
||||||
|
char ***props);
|
||||||
|
|
||||||
|
static virQEMUCapsObjectTypeProps virQEMUCapsDeviceProps[] = {
|
||||||
{ "virtio-blk-pci", virQEMUCapsDevicePropsVirtioBlk,
|
{ "virtio-blk-pci", virQEMUCapsDevicePropsVirtioBlk,
|
||||||
ARRAY_CARDINALITY(virQEMUCapsDevicePropsVirtioBlk),
|
ARRAY_CARDINALITY(virQEMUCapsDevicePropsVirtioBlk),
|
||||||
-1 },
|
-1 },
|
||||||
@ -2066,6 +2071,35 @@ virQEMUCapsProbeQMPEvents(virQEMUCapsPtr qemuCaps,
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static int
|
||||||
|
virQEMUCapsProbeQMPGenericProps(virQEMUCapsPtr qemuCaps,
|
||||||
|
qemuMonitorPtr mon,
|
||||||
|
virQEMUCapsObjectTypeProps *props,
|
||||||
|
size_t nprops,
|
||||||
|
virQEMUCapsObjectTypePropsCB propsGetCB)
|
||||||
|
{
|
||||||
|
int nvalues;
|
||||||
|
char **values;
|
||||||
|
size_t i;
|
||||||
|
|
||||||
|
for (i = 0; i < nprops; i++) {
|
||||||
|
const char *type = props[i].type;
|
||||||
|
int cap = props[i].capsCondition;
|
||||||
|
|
||||||
|
if (cap >= 0 && !virQEMUCapsGet(qemuCaps, cap))
|
||||||
|
continue;
|
||||||
|
|
||||||
|
if ((nvalues = propsGetCB(mon, type, &values)) < 0)
|
||||||
|
return -1;
|
||||||
|
virQEMUCapsProcessStringFlags(qemuCaps,
|
||||||
|
props[i].nprops,
|
||||||
|
props[i].props,
|
||||||
|
nvalues, values);
|
||||||
|
virStringListFreeCount(values, nvalues);
|
||||||
|
}
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
static int
|
static int
|
||||||
virQEMUCapsProbeQMPDevices(virQEMUCapsPtr qemuCaps,
|
virQEMUCapsProbeQMPDevices(virQEMUCapsPtr qemuCaps,
|
||||||
@ -2073,7 +2107,6 @@ virQEMUCapsProbeQMPDevices(virQEMUCapsPtr qemuCaps,
|
|||||||
{
|
{
|
||||||
int nvalues;
|
int nvalues;
|
||||||
char **values;
|
char **values;
|
||||||
size_t i;
|
|
||||||
|
|
||||||
if ((nvalues = qemuMonitorGetObjectTypes(mon, &values)) < 0)
|
if ((nvalues = qemuMonitorGetObjectTypes(mon, &values)) < 0)
|
||||||
return -1;
|
return -1;
|
||||||
@ -2083,23 +2116,12 @@ virQEMUCapsProbeQMPDevices(virQEMUCapsPtr qemuCaps,
|
|||||||
nvalues, values);
|
nvalues, values);
|
||||||
virStringListFreeCount(values, nvalues);
|
virStringListFreeCount(values, nvalues);
|
||||||
|
|
||||||
for (i = 0; i < ARRAY_CARDINALITY(virQEMUCapsDeviceProps); i++) {
|
if (virQEMUCapsProbeQMPGenericProps(qemuCaps,
|
||||||
const char *device = virQEMUCapsDeviceProps[i].type;
|
mon,
|
||||||
int cap = virQEMUCapsDeviceProps[i].capsCondition;
|
virQEMUCapsDeviceProps,
|
||||||
|
ARRAY_CARDINALITY(virQEMUCapsDeviceProps),
|
||||||
if (cap >= 0 && !virQEMUCapsGet(qemuCaps, cap))
|
qemuMonitorGetDeviceProps) < 0)
|
||||||
continue;
|
return -1;
|
||||||
|
|
||||||
if ((nvalues = qemuMonitorGetDeviceProps(mon,
|
|
||||||
device,
|
|
||||||
&values)) < 0)
|
|
||||||
return -1;
|
|
||||||
virQEMUCapsProcessStringFlags(qemuCaps,
|
|
||||||
virQEMUCapsDeviceProps[i].nprops,
|
|
||||||
virQEMUCapsDeviceProps[i].props,
|
|
||||||
nvalues, values);
|
|
||||||
virStringListFreeCount(values, nvalues);
|
|
||||||
}
|
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user