mirror of
https://gitlab.com/libvirt/libvirt.git
synced 2025-01-30 16:35:24 +00:00
nodedev: Add ability to filter by active state
Add two flag values for virConnectListAllNodeDevices() so that we can list only node devices that are active or inactive. Signed-off-by: Jonathon Jongsma <jjongsma@redhat.com> Reviewed-by: Erik Skultety <eskultet@redhat.com>
This commit is contained in:
parent
b7a823177b
commit
b1bfe3e5c4
@ -61,10 +61,9 @@ int virNodeListDevices (virConnectPtr conn,
|
||||
* virConnectListAllNodeDevices:
|
||||
*
|
||||
* Flags used to filter the returned node devices. Flags in each group
|
||||
* are exclusive. Currently only one group to filter the devices by cap
|
||||
* type.
|
||||
*/
|
||||
* are exclusive. */
|
||||
typedef enum {
|
||||
/* filter the devices by cap type */
|
||||
VIR_CONNECT_LIST_NODE_DEVICES_CAP_SYSTEM = 1 << 0, /* System capability */
|
||||
VIR_CONNECT_LIST_NODE_DEVICES_CAP_PCI_DEV = 1 << 1, /* PCI device */
|
||||
VIR_CONNECT_LIST_NODE_DEVICES_CAP_USB_DEV = 1 << 2, /* USB device */
|
||||
@ -86,6 +85,10 @@ typedef enum {
|
||||
VIR_CONNECT_LIST_NODE_DEVICES_CAP_AP_CARD = 1 << 18, /* s390 AP Card device */
|
||||
VIR_CONNECT_LIST_NODE_DEVICES_CAP_AP_QUEUE = 1 << 19, /* s390 AP Queue */
|
||||
VIR_CONNECT_LIST_NODE_DEVICES_CAP_AP_MATRIX = 1 << 20, /* s390 AP Matrix */
|
||||
|
||||
/* filter the devices by active state */
|
||||
VIR_CONNECT_LIST_NODE_DEVICES_INACTIVE = 1 << 30, /* Inactive devices */
|
||||
VIR_CONNECT_LIST_NODE_DEVICES_ACTIVE = 1U << 31, /* Active devices */
|
||||
} virConnectListAllNodeDeviceFlags;
|
||||
|
||||
int virConnectListAllNodeDevices (virConnectPtr conn,
|
||||
|
@ -422,6 +422,14 @@ virNodeDevCapsDefFree(virNodeDevCapsDefPtr caps);
|
||||
VIR_CONNECT_LIST_NODE_DEVICES_CAP_AP_QUEUE | \
|
||||
VIR_CONNECT_LIST_NODE_DEVICES_CAP_AP_MATRIX)
|
||||
|
||||
#define VIR_CONNECT_LIST_NODE_DEVICES_FILTERS_ACTIVE \
|
||||
VIR_CONNECT_LIST_NODE_DEVICES_ACTIVE | \
|
||||
VIR_CONNECT_LIST_NODE_DEVICES_INACTIVE
|
||||
|
||||
#define VIR_CONNECT_LIST_NODE_DEVICES_FILTERS_ALL \
|
||||
VIR_CONNECT_LIST_NODE_DEVICES_FILTERS_CAP | \
|
||||
VIR_CONNECT_LIST_NODE_DEVICES_FILTERS_ACTIVE
|
||||
|
||||
int
|
||||
virNodeDeviceGetSCSIHostCaps(virNodeDevCapSCSIHostPtr scsi_host);
|
||||
|
||||
|
@ -848,8 +848,10 @@ virNodeDeviceObjListGetNames(virNodeDeviceObjListPtr devs,
|
||||
}
|
||||
|
||||
|
||||
#define MATCH(FLAG) ((flags & (VIR_CONNECT_LIST_NODE_DEVICES_CAP_ ## FLAG)) && \
|
||||
virNodeDeviceObjHasCap(obj, VIR_NODE_DEV_CAP_ ## FLAG))
|
||||
#define MATCH_CAP(FLAG) ((flags & (VIR_CONNECT_LIST_NODE_DEVICES_CAP_ ## FLAG)) && \
|
||||
virNodeDeviceObjHasCap(obj, VIR_NODE_DEV_CAP_ ## FLAG))
|
||||
#define MATCH(FLAG) (flags & (FLAG))
|
||||
|
||||
static bool
|
||||
virNodeDeviceObjMatch(virNodeDeviceObjPtr obj,
|
||||
unsigned int flags)
|
||||
@ -861,33 +863,42 @@ virNodeDeviceObjMatch(virNodeDeviceObjPtr obj,
|
||||
|
||||
/* filter by cap type */
|
||||
if (flags & VIR_CONNECT_LIST_NODE_DEVICES_FILTERS_CAP) {
|
||||
if (!(MATCH(SYSTEM) ||
|
||||
MATCH(PCI_DEV) ||
|
||||
MATCH(USB_DEV) ||
|
||||
MATCH(USB_INTERFACE) ||
|
||||
MATCH(NET) ||
|
||||
MATCH(SCSI_HOST) ||
|
||||
MATCH(SCSI_TARGET) ||
|
||||
MATCH(SCSI) ||
|
||||
MATCH(STORAGE) ||
|
||||
MATCH(FC_HOST) ||
|
||||
MATCH(VPORTS) ||
|
||||
MATCH(SCSI_GENERIC) ||
|
||||
MATCH(DRM) ||
|
||||
MATCH(MDEV_TYPES) ||
|
||||
MATCH(MDEV) ||
|
||||
MATCH(CCW_DEV) ||
|
||||
MATCH(CSS_DEV) ||
|
||||
MATCH(VDPA) ||
|
||||
MATCH(AP_CARD) ||
|
||||
MATCH(AP_QUEUE) ||
|
||||
MATCH(AP_MATRIX)))
|
||||
if (!(MATCH_CAP(SYSTEM) ||
|
||||
MATCH_CAP(PCI_DEV) ||
|
||||
MATCH_CAP(USB_DEV) ||
|
||||
MATCH_CAP(USB_INTERFACE) ||
|
||||
MATCH_CAP(NET) ||
|
||||
MATCH_CAP(SCSI_HOST) ||
|
||||
MATCH_CAP(SCSI_TARGET) ||
|
||||
MATCH_CAP(SCSI) ||
|
||||
MATCH_CAP(STORAGE) ||
|
||||
MATCH_CAP(FC_HOST) ||
|
||||
MATCH_CAP(VPORTS) ||
|
||||
MATCH_CAP(SCSI_GENERIC) ||
|
||||
MATCH_CAP(DRM) ||
|
||||
MATCH_CAP(MDEV_TYPES) ||
|
||||
MATCH_CAP(MDEV) ||
|
||||
MATCH_CAP(CCW_DEV) ||
|
||||
MATCH_CAP(CSS_DEV) ||
|
||||
MATCH_CAP(VDPA) ||
|
||||
MATCH_CAP(AP_CARD) ||
|
||||
MATCH_CAP(AP_QUEUE) ||
|
||||
MATCH_CAP(AP_MATRIX)))
|
||||
return false;
|
||||
}
|
||||
|
||||
if (flags & (VIR_CONNECT_LIST_NODE_DEVICES_FILTERS_ACTIVE)) {
|
||||
if (!((MATCH(VIR_CONNECT_LIST_NODE_DEVICES_ACTIVE) &&
|
||||
virNodeDeviceObjIsActive(obj)) ||
|
||||
(MATCH(VIR_CONNECT_LIST_NODE_DEVICES_INACTIVE) &&
|
||||
!virNodeDeviceObjIsActive(obj))))
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
#undef MATCH
|
||||
#undef MATCH_CAP
|
||||
|
||||
|
||||
typedef struct _virNodeDeviceObjListExportData virNodeDeviceObjListExportData;
|
||||
|
@ -105,6 +105,8 @@ virNodeNumOfDevices(virConnectPtr conn, const char *cap, unsigned int flags)
|
||||
* VIR_CONNECT_LIST_NODE_DEVICES_CAP_AP_CARD
|
||||
* VIR_CONNECT_LIST_NODE_DEVICES_CAP_AP_QUEUE
|
||||
* VIR_CONNECT_LIST_NODE_DEVICES_CAP_AP_MATRIX
|
||||
* VIR_CONNECT_LIST_NODE_DEVICES_ACTIVE
|
||||
* VIR_CONNECT_LIST_NODE_DEVICES_INACTIVE
|
||||
*
|
||||
* Returns the number of node devices found or -1 and sets @devices to NULL in
|
||||
* case of error. On success, the array stored into @devices is guaranteed to
|
||||
|
@ -217,7 +217,7 @@ nodeConnectListAllNodeDevices(virConnectPtr conn,
|
||||
virNodeDevicePtr **devices,
|
||||
unsigned int flags)
|
||||
{
|
||||
virCheckFlags(VIR_CONNECT_LIST_NODE_DEVICES_FILTERS_CAP, -1);
|
||||
virCheckFlags(VIR_CONNECT_LIST_NODE_DEVICES_FILTERS_ALL, -1);
|
||||
|
||||
if (virConnectListAllNodeDevicesEnsureACL(conn) < 0)
|
||||
return -1;
|
||||
|
Loading…
x
Reference in New Issue
Block a user