1 /* 2 * virnodedeviceobj.h: node device object handling for node devices 3 * (derived from node_device_conf.h) 4 * 5 * This library is free software; you can redistribute it and/or 6 * modify it under the terms of the GNU Lesser General Public 7 * License as published by the Free Software Foundation; either 8 * version 2.1 of the License, or (at your option) any later version. 9 * 10 * This library is distributed in the hope that it will be useful, 11 * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 13 * Lesser General Public License for more details. 14 * 15 * You should have received a copy of the GNU Lesser General Public 16 * License along with this library. If not, see 17 * <http://www.gnu.org/licenses/>. 18 */ 19 20 #pragma once 21 22 #include "internal.h" 23 #include "virthread.h" 24 25 #include "node_device_conf.h" 26 #include "object_event.h" 27 28 29 typedef struct _virNodeDeviceObj virNodeDeviceObj; 30 31 typedef struct _virNodeDeviceObjList virNodeDeviceObjList; 32 33 typedef struct _virNodeDeviceDriverState virNodeDeviceDriverState; 34 struct _virNodeDeviceDriverState { 35 virMutex lock; 36 virCond initCond; 37 bool initialized; 38 39 /* pid file FD, ensures two copies of the driver can't use the same root */ 40 int lockFD; 41 42 char *stateDir; 43 44 virNodeDeviceObjList *devs; /* currently-known devices */ 45 void *privateData; /* driver-specific private data */ 46 bool privileged; /* whether we run in privileged mode */ 47 48 /* Immutable pointer, self-locking APIs */ 49 virObjectEventState *nodeDeviceEventState; 50 virNodeDeviceDefParserCallbacks parserCallbacks; 51 }; 52 53 void 54 virNodeDeviceObjEndAPI(virNodeDeviceObj **obj); 55 56 virNodeDeviceDef * 57 virNodeDeviceObjGetDef(virNodeDeviceObj *obj); 58 59 virNodeDeviceObj * 60 virNodeDeviceObjListFindByName(virNodeDeviceObjList *devs, 61 const char *name); 62 63 virNodeDeviceObj * 64 virNodeDeviceObjListFindBySysfsPath(virNodeDeviceObjList *devs, 65 const char *sysfs_path) 66 ATTRIBUTE_NONNULL(2); 67 68 virNodeDeviceObj * 69 virNodeDeviceObjListFindSCSIHostByWWNs(virNodeDeviceObjList *devs, 70 const char *wwnn, 71 const char *wwpn); 72 73 virNodeDeviceObj * 74 virNodeDeviceObjListAssignDef(virNodeDeviceObjList *devs, 75 virNodeDeviceDef *def); 76 77 void 78 virNodeDeviceObjListRemove(virNodeDeviceObjList *devs, 79 virNodeDeviceObj *dev); 80 81 void 82 virNodeDeviceObjListRemoveLocked(virNodeDeviceObjList *devs, 83 virNodeDeviceObj *dev); 84 85 int 86 virNodeDeviceObjListGetParentHost(virNodeDeviceObjList *devs, 87 virNodeDeviceDef *def); 88 89 virNodeDeviceObjList * 90 virNodeDeviceObjListNew(void); 91 92 void 93 virNodeDeviceObjListFree(virNodeDeviceObjList *devs); 94 95 typedef bool 96 (*virNodeDeviceObjListFilter)(virConnectPtr conn, 97 virNodeDeviceDef *def); 98 99 int 100 virNodeDeviceObjListNumOfDevices(virNodeDeviceObjList *devs, 101 virConnectPtr conn, 102 const char *cap, 103 virNodeDeviceObjListFilter filter); 104 105 int 106 virNodeDeviceObjListGetNames(virNodeDeviceObjList *devs, 107 virConnectPtr conn, 108 virNodeDeviceObjListFilter filter, 109 const char *cap, 110 char **const names, 111 int maxnames); 112 113 int 114 virNodeDeviceObjListExport(virConnectPtr conn, 115 virNodeDeviceObjList *devobjs, 116 virNodeDevicePtr **devices, 117 virNodeDeviceObjListFilter filter, 118 unsigned int flags); 119 120 void 121 virNodeDeviceObjSetSkipUpdateCaps(virNodeDeviceObj *obj, 122 bool skipUpdateCaps); 123 virNodeDeviceObj * 124 virNodeDeviceObjListFindMediatedDeviceByUUID(virNodeDeviceObjList *devs, 125 const char *uuid, 126 const char *parent_addr); 127 128 bool 129 virNodeDeviceObjIsActive(virNodeDeviceObj *obj); 130 131 void 132 virNodeDeviceObjSetActive(virNodeDeviceObj *obj, 133 bool active); 134 bool 135 virNodeDeviceObjIsPersistent(virNodeDeviceObj *obj); 136 137 void 138 virNodeDeviceObjSetPersistent(virNodeDeviceObj *obj, 139 bool persistent); 140 bool 141 virNodeDeviceObjIsAutostart(virNodeDeviceObj *obj); 142 143 void 144 virNodeDeviceObjSetAutostart(virNodeDeviceObj *obj, 145 bool autostart); 146 147 typedef bool (*virNodeDeviceObjListPredicate)(virNodeDeviceObj *obj, 148 const void *opaque); 149 150 void virNodeDeviceObjListForEachRemove(virNodeDeviceObjList *devs, 151 virNodeDeviceObjListPredicate callback, 152 void *opaque); 153 154 virNodeDeviceObj * 155 virNodeDeviceObjListFind(virNodeDeviceObjList *devs, 156 virNodeDeviceObjListPredicate callback, 157 void *opaque); 158