1 /*
2  * node_device_driver.h: node device enumeration
3  *
4  * Copyright (C) 2008 Virtual Iron Software, Inc.
5  * Copyright (C) 2008 David F. Lively
6  *
7  * This library is free software; you can redistribute it and/or
8  * modify it under the terms of the GNU Lesser General Public
9  * License as published by the Free Software Foundation; either
10  * version 2.1 of the License, or (at your option) any later version.
11  *
12  * This library is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
15  * Lesser General Public License for more details.
16  *
17  * You should have received a copy of the GNU Lesser General Public
18  * License along with this library.  If not, see
19  * <http://www.gnu.org/licenses/>.
20  */
21 
22 #pragma once
23 
24 #include "internal.h"
25 #include "driver.h"
26 #include "virnodedeviceobj.h"
27 #include "vircommand.h"
28 
29 #define LINUX_NEW_DEVICE_WAIT_TIME 60
30 
31 #ifdef WITH_UDEV
32 int
33 udevNodeRegister(void);
34 #endif
35 
36 
37 typedef enum {
38     MDEVCTL_CMD_START,
39     MDEVCTL_CMD_STOP,
40     MDEVCTL_CMD_DEFINE,
41     MDEVCTL_CMD_UNDEFINE,
42 
43     /* mdevctl actually doesn't have a 'create' command, it will be replaced
44      * with 'start' eventually in nodeDeviceGetMdevctlCommand, but this clear
45      * separation makes our code more readable in terms of knowing when we're
46      * starting a defined device and when we're creating a transient one */
47     MDEVCTL_CMD_CREATE,
48 
49     MDEVCTL_CMD_LAST,
50 } virMdevctlCommand;
51 
52 VIR_ENUM_DECL(virMdevctlCommand);
53 
54 
55 void
56 nodeDeviceLock(void);
57 
58 void
59 nodeDeviceUnlock(void);
60 
61 extern virNodeDeviceDriverState *driver;
62 
63 int
64 nodedevRegister(void);
65 
66 virDrvOpenStatus nodeConnectOpen(virConnectPtr conn,
67                                  virConnectAuthPtr auth,
68                                  virConf *conf,
69                                  unsigned int flags);
70 int nodeConnectClose(virConnectPtr conn);
71 int nodeConnectIsSecure(virConnectPtr conn);
72 int nodeConnectIsEncrypted(virConnectPtr conn);
73 int nodeConnectIsAlive(virConnectPtr conn);
74 
75 int
76 nodeNumOfDevices(virConnectPtr conn,
77                  const char *cap,
78                  unsigned int flags);
79 
80 int nodeListDevices(virConnectPtr conn,
81                     const char *cap,
82                     char **const names,
83                     int maxnames,
84                     unsigned int flags);
85 
86 int
87 nodeConnectListAllNodeDevices(virConnectPtr conn,
88                               virNodeDevicePtr **devices,
89                               unsigned int flags);
90 
91 virNodeDevicePtr
92 nodeDeviceLookupByName(virConnectPtr conn,
93                        const char *name);
94 
95 virNodeDevicePtr
96 nodeDeviceLookupSCSIHostByWWN(virConnectPtr conn,
97                               const char *wwnn,
98                               const char *wwpn,
99                               unsigned int flags);
100 
101 char *
102 nodeDeviceGetXMLDesc(virNodeDevicePtr dev,
103                      unsigned int flags);
104 
105 char *
106 nodeDeviceGetParent(virNodeDevicePtr dev);
107 
108 int
109 nodeDeviceNumOfCaps(virNodeDevicePtr dev);
110 
111 int
112 nodeDeviceListCaps(virNodeDevicePtr dev,
113                    char **const names,
114                    int maxnames);
115 
116 virNodeDevicePtr
117 nodeDeviceCreateXML(virConnectPtr conn,
118                     const char *xmlDesc,
119                     unsigned int flags);
120 
121 int
122 nodeDeviceDestroy(virNodeDevicePtr dev);
123 
124 virNodeDevice*
125 nodeDeviceDefineXML(virConnect *conn,
126                     const char *xmlDesc,
127                     unsigned int flags);
128 
129 int
130 nodeDeviceUndefine(virNodeDevice *dev,
131                    unsigned int flags);
132 
133 int
134 nodeConnectNodeDeviceEventRegisterAny(virConnectPtr conn,
135                                       virNodeDevicePtr dev,
136                                       int eventID,
137                                       virConnectNodeDeviceEventGenericCallback callback,
138                                       void *opaque,
139                                       virFreeCallback freecb);
140 int
141 nodeConnectNodeDeviceEventDeregisterAny(virConnectPtr conn,
142                                         int callbackID);
143 
144 virCommand *
145 nodeDeviceGetMdevctlCommand(virNodeDeviceDef *def,
146                             virMdevctlCommand cmd_type,
147                             char **outbuf,
148                             char **errbuf);
149 
150 virCommand *
151 nodeDeviceGetMdevctlListCommand(bool defined,
152                                 char **output,
153                                 char **errmsg);
154 
155 int
156 nodeDeviceParseMdevctlJSON(const char *jsonstring,
157                            virNodeDeviceDef ***devs);
158 
159 int
160 nodeDeviceUpdateMediatedDevices(void);
161 
162 void
163 nodeDeviceGenerateName(virNodeDeviceDef *def,
164                        const char *subsystem,
165                        const char *sysname,
166                        const char *s);
167 
168 bool nodeDeviceDefCopyFromMdevctl(virNodeDeviceDef *dst,
169                                   virNodeDeviceDef *src);
170 
171 int
172 nodeDeviceCreate(virNodeDevice *dev,
173                  unsigned int flags);
174 
175 int nodeDeviceDefPostParse(virNodeDeviceDef *def,
176                            void *opaque);
177 
178 int nodeDeviceDefValidate(virNodeDeviceDef *def,
179                           void *opaque);
180 
181 int
182 nodeDeviceSetAutostart(virNodeDevice *dev,
183                        int autostart);
184 
185 int
186 nodeDeviceGetAutostart(virNodeDevice *dev,
187                        int *autostart);
188 
189 int
190 nodeDeviceIsPersistent(virNodeDevice *dev);
191 
192 int
193 nodeDeviceIsActive(virNodeDevice *dev);
194 
195 virCommand*
196 nodeDeviceGetMdevctlSetAutostartCommand(virNodeDeviceDef *def,
197                                         bool autostart,
198                                         char **errmsg);
199