Module libvirt-nodedev from libvirt
Provides APIs for the management of nodedevs
Table of Contents
Types
typedef enum virConnectListAllNodeDeviceFlags typedef struct _virNodeDevice virNodeDevice typedef virNodeDevice * virNodeDevicePtr
Functions
int virConnectListAllNodeDevices (virConnectPtr conn,
virNodeDevicePtr ** devices,
unsigned int flags) virNodeDevicePtr virNodeDeviceCreateXML (virConnectPtr conn,
const char * xmlDesc,
unsigned int flags) int virNodeDeviceDestroy (virNodeDevicePtr dev) int virNodeDeviceDetachFlags (virNodeDevicePtr dev,
const char * driverName,
unsigned int flags) int virNodeDeviceDettach (virNodeDevicePtr dev) int virNodeDeviceFree (virNodeDevicePtr dev) const char * virNodeDeviceGetName (virNodeDevicePtr dev) const char * virNodeDeviceGetParent (virNodeDevicePtr dev) char * virNodeDeviceGetXMLDesc (virNodeDevicePtr dev,
unsigned int flags) int virNodeDeviceListCaps (virNodeDevicePtr dev,
char ** const names,
int maxnames) virNodeDevicePtr virNodeDeviceLookupByName (virConnectPtr conn,
const char * name) virNodeDevicePtr virNodeDeviceLookupSCSIHostByWWN (virConnectPtr conn,
const char * wwnn,
const char * wwpn,
unsigned int flags) int virNodeDeviceNumOfCaps (virNodeDevicePtr dev) int virNodeDeviceReAttach (virNodeDevicePtr dev) int virNodeDeviceRef (virNodeDevicePtr dev) int virNodeDeviceReset (virNodeDevicePtr dev) int virNodeListDevices (virConnectPtr conn,
const char * cap,
char ** const names,
int maxnames,
unsigned int flags) int virNodeNumOfDevices (virConnectPtr conn,
const char * cap,
unsigned int flags)
Description
Types¶
virConnectListAllNodeDeviceFlags
¶
enum virConnectListAllNodeDeviceFlags {
VIR_CONNECT_LIST_NODE_DEVICES_CAP_SYSTEM | = | 1 | System capability |
VIR_CONNECT_LIST_NODE_DEVICES_CAP_PCI_DEV | = | 2 | PCI device |
VIR_CONNECT_LIST_NODE_DEVICES_CAP_USB_DEV | = | 4 | USB device |
VIR_CONNECT_LIST_NODE_DEVICES_CAP_USB_INTERFACE | = | 8 | USB interface |
VIR_CONNECT_LIST_NODE_DEVICES_CAP_NET | = | 16 | Network device |
VIR_CONNECT_LIST_NODE_DEVICES_CAP_SCSI_HOST | = | 32 | SCSI Host Bus Adapter |
VIR_CONNECT_LIST_NODE_DEVICES_CAP_SCSI_TARGET | = | 64 | SCSI Target |
VIR_CONNECT_LIST_NODE_DEVICES_CAP_SCSI | = | 128 | SCSI device |
VIR_CONNECT_LIST_NODE_DEVICES_CAP_STORAGE | = | 256 | Storage device |
VIR_CONNECT_LIST_NODE_DEVICES_CAP_FC_HOST | = | 512 | FC Host Bus Adapter |
VIR_CONNECT_LIST_NODE_DEVICES_CAP_VPORTS | = | 1024 | Capable of vport |
VIR_CONNECT_LIST_NODE_DEVICES_CAP_SCSI_GENERIC | = | 2048 | Capable of scsi_generic |
}
virNodeDevice
¶
struct virNodeDevice {
}
Functions¶
virConnectListAllNodeDevices
¶
int virConnectListAllNodeDevices (virConnectPtr conn, virNodeDevicePtr ** devices, unsigned int flags)
Collect the list of node devices, and allocate an array to store those objects.
Normally, all node devices are returned; however, @flags can be used to filter the results for a smaller list of targeted node devices. The valid flags are divided into groups, where each group contains bits that describe mutually exclusive attributes of a node device, and where all bits within a group describe all possible node devices.
Only one group of the @flags is provided to filter the node devices by capability type, flags include: VIR_CONNECT_LIST_NODE_DEVICES_CAP_SYSTEM VIR_CONNECT_LIST_NODE_DEVICES_CAP_PCI_DEV VIR_CONNECT_LIST_NODE_DEVICES_CAP_USB_DEV VIR_CONNECT_LIST_NODE_DEVICES_CAP_USB_INTERFACE VIR_CONNECT_LIST_NODE_DEVICES_CAP_NET VIR_CONNECT_LIST_NODE_DEVICES_CAP_SCSI_HOST VIR_CONNECT_LIST_NODE_DEVICES_CAP_SCSI_TARGET VIR_CONNECT_LIST_NODE_DEVICES_CAP_SCSI VIR_CONNECT_LIST_NODE_DEVICES_CAP_STORAGE VIR_CONNECT_LIST_NODE_DEVICES_CAP_FC_HOST VIR_CONNECT_LIST_NODE_DEVICES_CAP_VPORTS VIR_CONNECT_LIST_NODE_DEVICES_CAP_SCSI_GENERIC
- conn
- Pointer to the hypervisor connection.
- devices
- Pointer to a variable to store the array containing the node device objects or NULL if the list is not required (just returns number of node devices).
- flags
- bitwise-OR of virConnectListAllNodeDevices.
- 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 have an extra allocated element set to NULL but not included in the return count, to make iteration easier. The caller is responsible for calling virNodeDeviceFree() on each array element, then calling free() on @devices.
virNodeDeviceCreateXML
¶
virNodeDevicePtr virNodeDeviceCreateXML (virConnectPtr conn, const char * xmlDesc, unsigned int flags)
Create a new device on the VM host machine, for example, virtual HBAs created using vport_create.
virNodeDeviceFree should be used to free the resources after the node device object is no longer needed.
- conn
- pointer to the hypervisor connection
- xmlDesc
- string containing an XML description of the device to be created
- flags
- extra flags; not used yet, so callers should always pass 0
- Returns
- a node device object if successful, NULL in case of failure
virNodeDeviceDestroy
¶
int virNodeDeviceDestroy (virNodeDevicePtr dev)
Destroy the device object. The virtual device (only works for vHBA currently) is removed from the host operating system. This function may require privileged access.
- dev
- a device object
- Returns
- 0 in case of success and -1 in case of failure.
virNodeDeviceDetachFlags
¶
int virNodeDeviceDetachFlags (virNodeDevicePtr dev, const char * driverName, unsigned int flags)
Detach the node device from the node itself so that it may be assigned to a guest domain.
Depending on the hypervisor, this may involve operations such as unbinding any device drivers from the device, binding the device to a dummy device driver and resetting the device. Different backend drivers expect the device to be bound to different dummy devices. For example, QEMU's "kvm" backend driver (the default) expects the device to be bound to "pci-stub", but its "vfio" backend driver expects the device to be bound to "vfio-pci".
If the device is currently in use by the node, this method may fail.
Once the device is not assigned to any guest, it may be re-attached to the node using the virNodeDeviceReAttach() method.
- dev
- pointer to the node device
- driverName
- name of backend driver that will be used for later device assignment to a domain. NULL means "use the hypervisor default driver"
- flags
- extra flags; not used yet, so callers should always pass 0
- Returns
- 0 in case of success, -1 in case of failure.
virNodeDeviceDettach
¶
int virNodeDeviceDettach (virNodeDevicePtr dev)
Dettach the node device from the node itself so that it may be assigned to a guest domain.
Depending on the hypervisor, this may involve operations such as unbinding any device drivers from the device, binding the device to a dummy device driver and resetting the device.
If the device is currently in use by the node, this method may fail.
Once the device is not assigned to any guest, it may be re-attached to the node using the virNodeDeviceReattach() method.
If the caller needs control over which backend driver will be used during PCI device assignment (to use something other than the default, for example VFIO), the newer virNodeDeviceDetachFlags() API should be used instead.
- dev
- pointer to the node device
- Returns
- 0 in case of success, -1 in case of failure.
virNodeDeviceFree
¶
int virNodeDeviceFree (virNodeDevicePtr dev)
Drops a reference to the node device, freeing it if this was the last reference.
- dev
- pointer to the node device
- Returns
- the 0 for success, -1 for error.
virNodeDeviceGetName
¶
const char * virNodeDeviceGetName (virNodeDevicePtr dev)
Just return the device name
- dev
- the device
- Returns
- the device name or NULL in case of error
virNodeDeviceGetParent
¶
const char * virNodeDeviceGetParent (virNodeDevicePtr dev)
Accessor for the parent of the device
- dev
- the device
- Returns
- the name of the device's parent, or NULL if an error occurred or when the device has no parent.
virNodeDeviceGetXMLDesc
¶
char * virNodeDeviceGetXMLDesc (virNodeDevicePtr dev, unsigned int flags)
Fetch an XML document describing all aspects of the device.
- dev
- pointer to the node device
- flags
- extra flags; not used yet, so callers should always pass 0
- Returns
- the XML document, or NULL on error
virNodeDeviceListCaps
¶
int virNodeDeviceListCaps (virNodeDevicePtr dev, char ** const names, int maxnames)
Lists the names of the capabilities supported by the device.
- dev
- the device
- names
- array to collect the list of capability names
- maxnames
- size of @names
- Returns
- the number of capability names listed in @names or -1 in case of error.
virNodeDeviceLookupByName
¶
virNodeDevicePtr virNodeDeviceLookupByName (virConnectPtr conn, const char * name)
Lookup a node device by its name.
virNodeDeviceFree should be used to free the resources after the node device object is no longer needed.
- conn
- pointer to the hypervisor connection
- name
- unique device name
- Returns
- a virNodeDevicePtr if found, NULL otherwise.
virNodeDeviceLookupSCSIHostByWWN
¶
virNodeDevicePtr virNodeDeviceLookupSCSIHostByWWN (virConnectPtr conn, const char * wwnn, const char * wwpn, unsigned int flags)
Lookup SCSI Host which is capable with 'fc_host' by its WWNN and WWPN.
virNodeDeviceFree should be used to free the resources after the node device object is no longer needed.
- conn
- pointer to the hypervisor connection
- wwnn
- WWNN of the SCSI Host.
- wwpn
- WWPN of the SCSI Host.
- flags
- extra flags; not used yet, so callers should always pass 0
- Returns
- a virNodeDevicePtr if found, NULL otherwise.
virNodeDeviceNumOfCaps
¶
int virNodeDeviceNumOfCaps (virNodeDevicePtr dev)
Accessor for the number of capabilities supported by the device.
- dev
- the device
- Returns
- the number of capabilities supported by the device or -1 in case of error.
virNodeDeviceReAttach
¶
int virNodeDeviceReAttach (virNodeDevicePtr dev)
Re-attach a previously dettached node device to the node so that it may be used by the node again.
Depending on the hypervisor, this may involve operations such as resetting the device, unbinding it from a dummy device driver and binding it to its appropriate driver.
If the device is currently in use by a guest, this method may fail.
- dev
- pointer to the node device
- Returns
- 0 in case of success, -1 in case of failure.
virNodeDeviceRef
¶
int virNodeDeviceRef (virNodeDevicePtr dev)
Increment the reference count on the dev. For each additional call to this method, there shall be a corresponding call to virNodeDeviceFree to release the reference count, once the caller no longer needs the reference to this object.
This method is typically useful for applications where multiple threads are using a connection, and it is required that the connection remain open until all threads have finished using it. ie, each new thread using a dev would increment the reference count.
- dev
- the dev to hold a reference on
- Returns
- 0 in case of success, -1 in case of failure.
virNodeDeviceReset
¶
int virNodeDeviceReset (virNodeDevicePtr dev)
Reset a previously dettached node device to the node before or after assigning it to a guest.
The exact reset semantics depends on the hypervisor and device type but, for example, KVM will attempt to reset PCI devices with a Function Level Reset, Secondary Bus Reset or a Power Management D-State reset.
If the reset will affect other devices which are currently in use, this function may fail.
- dev
- pointer to the node device
- Returns
- 0 in case of success, -1 in case of failure.
virNodeListDevices
¶
int virNodeListDevices (virConnectPtr conn, const char * cap, char ** const names, int maxnames, unsigned int flags)
Collect the list of node devices, and store their names in @names
For more control over the results, see virConnectListAllNodeDevices().
If the optional 'cap' argument is non-NULL, then the count will be restricted to devices with the specified capability
- conn
- pointer to the hypervisor connection
- cap
- capability name
- names
- array to collect the list of node device names
- maxnames
- size of @names
- flags
- extra flags; not used yet, so callers should always pass 0
- Returns
- the number of node devices found or -1 in case of error
virNodeNumOfDevices
¶
int virNodeNumOfDevices (virConnectPtr conn, const char * cap, unsigned int flags)
Provides the number of node devices.
If the optional 'cap' argument is non-NULL, then the count will be restricted to devices with the specified capability
- conn
- pointer to the hypervisor connection
- cap
- capability name
- flags
- extra flags; not used yet, so callers should always pass 0
- Returns
- the number of node devices or -1 in case of error