1 /* 2 * libvirt-nodedev.h 3 * Summary: APIs for management of nodedevs 4 * Description: Provides APIs for the management of nodedevs 5 * 6 * Copyright (C) 2006-2014 Red Hat, Inc. 7 * 8 * This library is free software; you can redistribute it and/or 9 * modify it under the terms of the GNU Lesser General Public 10 * License as published by the Free Software Foundation; either 11 * version 2.1 of the License, or (at your option) any later version. 12 * 13 * This library is distributed in the hope that it will be useful, 14 * but WITHOUT ANY WARRANTY; without even the implied warranty of 15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 16 * Lesser General Public License for more details. 17 * 18 * You should have received a copy of the GNU Lesser General Public 19 * License along with this library. If not, see 20 * <http://www.gnu.org/licenses/>. 21 */ 22 23 #ifndef LIBVIRT_NODEDEV_H 24 # define LIBVIRT_NODEDEV_H 25 26 # ifndef __VIR_LIBVIRT_H_INCLUDES__ 27 # error "Don't include this file directly, only use libvirt/libvirt.h" 28 # endif 29 30 31 /** 32 * virNodeDevice: 33 * 34 * A virNodeDevice contains a node (host) device details. 35 */ 36 37 typedef struct _virNodeDevice virNodeDevice; 38 39 /** 40 * virNodeDevicePtr: 41 * 42 * A virNodeDevicePtr is a pointer to a virNodeDevice structure. Get 43 * one via virNodeDeviceLookupByName, or virNodeDeviceCreate. Be sure 44 * to call virNodeDeviceFree when done using a virNodeDevicePtr obtained 45 * from any of the above functions to avoid leaking memory. 46 */ 47 48 typedef virNodeDevice *virNodeDevicePtr; 49 50 51 int virNodeNumOfDevices (virConnectPtr conn, 52 const char *cap, 53 unsigned int flags); 54 55 int virNodeListDevices (virConnectPtr conn, 56 const char *cap, 57 char **const names, 58 int maxnames, 59 unsigned int flags); 60 /* 61 * virConnectListAllNodeDevices: 62 * 63 * Flags used to filter the returned node devices. */ 64 typedef enum { 65 /* filter the devices by cap type */ 66 VIR_CONNECT_LIST_NODE_DEVICES_CAP_SYSTEM = 1 << 0, /* System capability */ 67 VIR_CONNECT_LIST_NODE_DEVICES_CAP_PCI_DEV = 1 << 1, /* PCI device */ 68 VIR_CONNECT_LIST_NODE_DEVICES_CAP_USB_DEV = 1 << 2, /* USB device */ 69 VIR_CONNECT_LIST_NODE_DEVICES_CAP_USB_INTERFACE = 1 << 3, /* USB interface */ 70 VIR_CONNECT_LIST_NODE_DEVICES_CAP_NET = 1 << 4, /* Network device */ 71 VIR_CONNECT_LIST_NODE_DEVICES_CAP_SCSI_HOST = 1 << 5, /* SCSI Host Bus Adapter */ 72 VIR_CONNECT_LIST_NODE_DEVICES_CAP_SCSI_TARGET = 1 << 6, /* SCSI Target */ 73 VIR_CONNECT_LIST_NODE_DEVICES_CAP_SCSI = 1 << 7, /* SCSI device */ 74 VIR_CONNECT_LIST_NODE_DEVICES_CAP_STORAGE = 1 << 8, /* Storage device */ 75 VIR_CONNECT_LIST_NODE_DEVICES_CAP_FC_HOST = 1 << 9, /* FC Host Bus Adapter */ 76 VIR_CONNECT_LIST_NODE_DEVICES_CAP_VPORTS = 1 << 10, /* Capable of vport */ 77 VIR_CONNECT_LIST_NODE_DEVICES_CAP_SCSI_GENERIC = 1 << 11, /* Capable of scsi_generic */ 78 VIR_CONNECT_LIST_NODE_DEVICES_CAP_DRM = 1 << 12, /* DRM device */ 79 VIR_CONNECT_LIST_NODE_DEVICES_CAP_MDEV_TYPES = 1 << 13, /* Capable of mediated devices */ 80 VIR_CONNECT_LIST_NODE_DEVICES_CAP_MDEV = 1 << 14, /* Mediated device */ 81 VIR_CONNECT_LIST_NODE_DEVICES_CAP_CCW_DEV = 1 << 15, /* CCW device */ 82 VIR_CONNECT_LIST_NODE_DEVICES_CAP_CSS_DEV = 1 << 16, /* CSS device */ 83 VIR_CONNECT_LIST_NODE_DEVICES_CAP_VDPA = 1 << 17, /* vDPA device */ 84 VIR_CONNECT_LIST_NODE_DEVICES_CAP_AP_CARD = 1 << 18, /* s390 AP Card device */ 85 VIR_CONNECT_LIST_NODE_DEVICES_CAP_AP_QUEUE = 1 << 19, /* s390 AP Queue */ 86 VIR_CONNECT_LIST_NODE_DEVICES_CAP_AP_MATRIX = 1 << 20, /* s390 AP Matrix */ 87 VIR_CONNECT_LIST_NODE_DEVICES_CAP_VPD = 1 << 21, /* Device with VPD */ 88 89 /* filter the devices by active state */ 90 VIR_CONNECT_LIST_NODE_DEVICES_INACTIVE = 1 << 30, /* Inactive devices */ 91 VIR_CONNECT_LIST_NODE_DEVICES_ACTIVE = 1U << 31, /* Active devices */ 92 } virConnectListAllNodeDeviceFlags; 93 94 int virConnectListAllNodeDevices (virConnectPtr conn, 95 virNodeDevicePtr **devices, 96 unsigned int flags); 97 98 virNodeDevicePtr virNodeDeviceLookupByName (virConnectPtr conn, 99 const char *name); 100 101 virNodeDevicePtr virNodeDeviceLookupSCSIHostByWWN (virConnectPtr conn, 102 const char *wwnn, 103 const char *wwpn, 104 unsigned int flags); 105 106 const char * virNodeDeviceGetName (virNodeDevicePtr dev); 107 108 const char * virNodeDeviceGetParent (virNodeDevicePtr dev); 109 110 int virNodeDeviceNumOfCaps (virNodeDevicePtr dev); 111 112 int virNodeDeviceListCaps (virNodeDevicePtr dev, 113 char **const names, 114 int maxnames); 115 116 char * virNodeDeviceGetXMLDesc (virNodeDevicePtr dev, 117 unsigned int flags); 118 119 int virNodeDeviceRef (virNodeDevicePtr dev); 120 int virNodeDeviceFree (virNodeDevicePtr dev); 121 122 int virNodeDeviceDettach (virNodeDevicePtr dev); 123 int virNodeDeviceDetachFlags(virNodeDevicePtr dev, 124 const char *driverName, 125 unsigned int flags); 126 int virNodeDeviceReAttach (virNodeDevicePtr dev); 127 int virNodeDeviceReset (virNodeDevicePtr dev); 128 129 virNodeDevicePtr virNodeDeviceCreateXML (virConnectPtr conn, 130 const char *xmlDesc, 131 unsigned int flags); 132 133 int virNodeDeviceDestroy (virNodeDevicePtr dev); 134 135 virNodeDevicePtr virNodeDeviceDefineXML(virConnectPtr conn, 136 const char *xmlDesc, 137 unsigned int flags); 138 139 int virNodeDeviceUndefine(virNodeDevicePtr dev, 140 unsigned int flags); 141 142 int virNodeDeviceCreate(virNodeDevicePtr dev, 143 unsigned int flags); 144 145 int virNodeDeviceSetAutostart(virNodeDevicePtr dev, 146 int autostart); 147 148 int virNodeDeviceGetAutostart(virNodeDevicePtr dev, 149 int *autostart); 150 151 int virNodeDeviceIsPersistent(virNodeDevicePtr dev); 152 153 int virNodeDeviceIsActive(virNodeDevicePtr dev); 154 155 /** 156 * VIR_NODE_DEVICE_EVENT_CALLBACK: 157 * 158 * Used to cast the event specific callback into the generic one 159 * for use for virConnectNodeDeviceEventRegisterAny() 160 */ 161 # define VIR_NODE_DEVICE_EVENT_CALLBACK(cb)((virConnectNodeDeviceEventGenericCallback)(cb)) 162 163 /** 164 * virNodeDeviceEventID: 165 * 166 * An enumeration of supported eventId parameters for 167 * virConnectNodeDeviceEventRegisterAny(). Each event id determines which 168 * signature of callback function will be used. 169 */ 170 typedef enum { 171 VIR_NODE_DEVICE_EVENT_ID_LIFECYCLE = 0, /* virConnectNodeDeviceEventLifecycleCallback */ 172 VIR_NODE_DEVICE_EVENT_ID_UPDATE = 1, /* virConnectNodeDeviceEventGenericCallback */ 173 174 # ifdef VIR_ENUM_SENTINELS 175 VIR_NODE_DEVICE_EVENT_ID_LAST 176 /* 177 * NB: this enum value will increase over time as new events are 178 * added to the libvirt API. It reflects the last event ID supported 179 * by this version of the libvirt API. 180 */ 181 # endif 182 } virNodeDeviceEventID; 183 184 /** 185 * virConnectNodeDeviceEventGenericCallback: 186 * @conn: the connection pointer 187 * @dev: the node device pointer 188 * @opaque: application specified data 189 * 190 * A generic node device event callback handler, for use with 191 * virConnectNodeDeviceEventRegisterAny(). Specific events usually 192 * have a customization with extra parameters, often with @opaque being 193 * passed in a different parameter position; use 194 * VIR_NODE_DEVICE_EVENT_CALLBACK() when registering an appropriate handler. 195 */ 196 typedef void (*virConnectNodeDeviceEventGenericCallback)(virConnectPtr conn, 197 virNodeDevicePtr dev, 198 void *opaque); 199 200 /* Use VIR_NODE_DEVICE_EVENT_CALLBACK() to cast the 'cb' parameter */ 201 int virConnectNodeDeviceEventRegisterAny(virConnectPtr conn, 202 virNodeDevicePtr dev, /* optional, to filter */ 203 int eventID, 204 virConnectNodeDeviceEventGenericCallback cb, 205 void *opaque, 206 virFreeCallback freecb); 207 208 int virConnectNodeDeviceEventDeregisterAny(virConnectPtr conn, 209 int callbackID); 210 211 /** 212 * virNodeDeviceEventLifecycleType: 213 * 214 * a virNodeDeviceEventLifecycleType is emitted during node device 215 * lifecycle events 216 */ 217 typedef enum { 218 VIR_NODE_DEVICE_EVENT_CREATED = 0, 219 VIR_NODE_DEVICE_EVENT_DELETED = 1, 220 VIR_NODE_DEVICE_EVENT_DEFINED = 2, 221 VIR_NODE_DEVICE_EVENT_UNDEFINED = 3, 222 223 # ifdef VIR_ENUM_SENTINELS 224 VIR_NODE_DEVICE_EVENT_LAST 225 # endif 226 } virNodeDeviceEventLifecycleType; 227 228 /** 229 * virConnectNodeDeviceEventLifecycleCallback: 230 * @conn: connection object 231 * @dev: node device on which the event occurred 232 * @event: The specific virNodeDeviceEventLifeCycleType which occurred 233 * @detail: contains some details on the reason of the event. 234 * @opaque: application specified data 235 * 236 * This callback is called when a node device lifecycle action is performed, 237 * like added or removed. 238 * 239 * The callback signature to use when registering for an event of type 240 * VIR_NODE_DEVICE_EVENT_ID_LIFECYCLE with 241 * virConnectNodeDeviceEventRegisterAny() 242 */ 243 typedef void (*virConnectNodeDeviceEventLifecycleCallback)(virConnectPtr conn, 244 virNodeDevicePtr dev, 245 int event, 246 int detail, 247 void *opaque); 248 249 #endif /* LIBVIRT_NODEDEV_H */ 250