driver.h 10.2 KB
Newer Older
1 2 3 4 5 6 7 8
/*
 * driver.h: description of the set of interfaces provided by a 
 *           entry point to the virtualization engine
 */

#ifndef __VIR_DRIVER_H__
#define __VIR_DRIVER_H__

9 10
#include "libvirt/libvirt.h"
#include "libvirt/virterror.h"
11 12 13 14 15

#ifdef __cplusplus
extern "C" {
#endif

16 17 18 19
/*
 * List of registered drivers numbers
 */
typedef enum {
20 21 22
    VIR_DRV_XEN_UNIFIED = 1,
    VIR_DRV_TEST = 2,
    VIR_DRV_QEMU = 3,
23
    VIR_DRV_REMOTE = 4,
24
    VIR_DRV_OPENVZ = 5,
25 26 27
} virDrvNo;


28
typedef enum {
29
    /* VIR_DRV_OPEN_QUIET = 1 - removed by RWMJ */
30 31 32
    VIR_DRV_OPEN_RO = 2
} virDrvOpenFlag;

33 34 35 36 37 38 39 40 41 42 43 44 45 46 47
/* Status codes returned from driver open call. */
typedef enum {
    /* Opened successfully. */
    VIR_DRV_OPEN_SUCCESS = 0,

    /* 'name' is not for us. */
    VIR_DRV_OPEN_DECLINED = -1,

    /* 'name' is for us, but there was some error.  virConnectOpen will
     * return an error rather than continue probing the other drivers.
     */
    VIR_DRV_OPEN_ERROR = -2,
} virDrvOpenStatus;

typedef virDrvOpenStatus
48 49 50
	(*virDrvOpen)			(virConnectPtr conn,
					 const char *name,
					 int flags);
51 52 53 54 55
typedef int
	(*virDrvClose)			(virConnectPtr conn);
typedef const char *
	(*virDrvGetType)		(virConnectPtr conn);
typedef int
56
	(*virDrvGetVersion)		(virConnectPtr conn,
57
					 unsigned long *hvVer);
58 59 60 61
typedef char *
    (*virDrvGetHostname)    (virConnectPtr conn);
typedef char *
    (*virDrvGetURI)         (virConnectPtr conn);
62
typedef int
63 64
	(*virDrvGetMaxVcpus)		(virConnectPtr conn,
					 const char *type);
65 66 67
typedef int
	(*virDrvNodeGetInfo)		(virConnectPtr conn,
					 virNodeInfoPtr info);
68 69
typedef char *
	(*virDrvGetCapabilities) (virConnectPtr conn);
70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94
typedef int
	(*virDrvListDomains)		(virConnectPtr conn,
					 int *ids,
					 int maxids);
typedef int
	(*virDrvNumOfDomains)		(virConnectPtr conn);
typedef virDomainPtr
	(*virDrvDomainCreateLinux)	(virConnectPtr conn,
					 const char *xmlDesc,
					 unsigned int flags);
typedef virDomainPtr
	(*virDrvDomainLookupByID)	(virConnectPtr conn,
					 int id);
typedef virDomainPtr
	(*virDrvDomainLookupByUUID)	(virConnectPtr conn,
					 const unsigned char *uuid);
typedef virDomainPtr
	(*virDrvDomainLookupByName)	(virConnectPtr conn,
					 const char *name);
typedef int
	(*virDrvDomainSuspend)		(virDomainPtr domain);
typedef int
	(*virDrvDomainResume)		(virDomainPtr domain);
typedef int
	(*virDrvDomainShutdown)		(virDomainPtr domain);
95 96 97
typedef int
	(*virDrvDomainReboot)		(virDomainPtr domain,
					 unsigned int flags);
98 99 100 101 102 103 104 105 106
typedef int
	(*virDrvDomainDestroy)		(virDomainPtr domain);
typedef char *
	(*virDrvDomainGetOSType)	(virDomainPtr domain);
typedef unsigned long
	(*virDrvDomainGetMaxMemory)	(virDomainPtr domain);
typedef int
	(*virDrvDomainSetMaxMemory)	(virDomainPtr domain,
					 unsigned long memory);
107 108 109
typedef int
	(*virDrvDomainSetMemory)	(virDomainPtr domain,
					 unsigned long memory);
110 111 112 113 114 115 116 117 118
typedef int
	(*virDrvDomainGetInfo)		(virDomainPtr domain,
					 virDomainInfoPtr info);
typedef int
	(*virDrvDomainSave)		(virDomainPtr domain,
					 const char *to);
typedef int
	(*virDrvDomainRestore)		(virConnectPtr conn,
					 const char *from);
D
Daniel Veillard 已提交
119 120 121 122
typedef int
	(*virDrvDomainCoreDump)		(virDomainPtr domain,
					 const char *to,
					 int flags);
123 124 125
typedef char *
	(*virDrvDomainDumpXML)		(virDomainPtr dom,
					 int flags);
126 127
typedef int
	(*virDrvListDefinedDomains)	(virConnectPtr conn,
128
					 char **const names,
129 130 131 132
					 int maxnames);
typedef int
	(*virDrvNumOfDefinedDomains)	(virConnectPtr conn);
typedef int
133
	(*virDrvDomainCreate)		(virDomainPtr dom);
134
typedef virDomainPtr
135 136
	(*virDrvDomainDefineXML)	(virConnectPtr conn,
					 const char *xml);
137
typedef int
138
	(*virDrvDomainUndefine)		(virDomainPtr dom);
139 140 141 142 143 144 145 146 147 148 149 150 151 152
typedef int
	(*virDrvDomainSetVcpus)		(virDomainPtr domain,
					 unsigned int nvcpus);
typedef int
	(*virDrvDomainPinVcpu)		(virDomainPtr domain,
					 unsigned int vcpu,
					 unsigned char *cpumap,
					 int maplen);
typedef int
	(*virDrvDomainGetVcpus)		(virDomainPtr domain,
					 virVcpuInfoPtr info,
					 int maxinfo,
					 unsigned char *cpumaps,
					 int maplen);
153 154
typedef int
	(*virDrvDomainGetMaxVcpus)	(virDomainPtr domain);
155 156 157 158 159 160
typedef int
	(*virDrvDomainAttachDevice)	(virDomainPtr domain,
					 char *xml);
typedef int
	(*virDrvDomainDetachDevice)	(virDomainPtr domain,
					 char *xml);
161 162 163 164 165 166
typedef int
	(*virDrvDomainGetAutostart)	(virDomainPtr domain,
					 int *autostart);
typedef int
	(*virDrvDomainSetAutostart)	(virDomainPtr domain,
					 int autostart);
167

168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183
typedef char *
	(*virDrvDomainGetSchedulerType)	(virDomainPtr domain,
					 int *nparams);

typedef int 
	(*virDrvDomainGetSchedulerParameters)
					(virDomainPtr domain,
					 virSchedParameterPtr params,
					 int *nparams);

typedef int
	(*virDrvDomainSetSchedulerParameters)
					(virDomainPtr domain,
					 virSchedParameterPtr params,
					 int nparams);

184 185 186 187 188 189 190 191
typedef struct _virDriver virDriver;
typedef virDriver *virDriverPtr;

/**
 * _virDriver:
 *
 * Structure associated to a virtualization driver, defining the various
 * entry points for it.
192 193 194 195 196 197
 *
 * All drivers must support the following fields/methods:
 *  - no
 *  - name
 *  - open
 *  - close
198 199
 */
struct _virDriver {
200 201 202
	int	       no;	/* the number virDrvNo */
	const char * name;	/* the name of the driver */
	unsigned long ver;	/* the version of the backend */
203 204 205 206
	virDrvOpen			open;
	virDrvClose			close;
	virDrvGetType			type;
	virDrvGetVersion		version;
207 208
    virDrvGetHostname       getHostname;
    virDrvGetURI            getURI;
209
	virDrvGetMaxVcpus		getMaxVcpus;
210
	virDrvNodeGetInfo		nodeGetInfo;
211
	virDrvGetCapabilities		getCapabilities;
212 213 214 215 216 217 218 219 220
	virDrvListDomains		listDomains;
	virDrvNumOfDomains		numOfDomains;
	virDrvDomainCreateLinux		domainCreateLinux;
	virDrvDomainLookupByID		domainLookupByID;
	virDrvDomainLookupByUUID	domainLookupByUUID;
	virDrvDomainLookupByName	domainLookupByName;
	virDrvDomainSuspend		domainSuspend;
	virDrvDomainResume		domainResume;
	virDrvDomainShutdown		domainShutdown;
221
	virDrvDomainReboot		domainReboot;
222 223 224 225
	virDrvDomainDestroy		domainDestroy;
	virDrvDomainGetOSType		domainGetOSType;
	virDrvDomainGetMaxMemory	domainGetMaxMemory;
	virDrvDomainSetMaxMemory	domainSetMaxMemory;
226
	virDrvDomainSetMemory		domainSetMemory;
227 228 229
	virDrvDomainGetInfo		domainGetInfo;
	virDrvDomainSave		domainSave;
	virDrvDomainRestore		domainRestore;
D
Daniel Veillard 已提交
230
	virDrvDomainCoreDump		domainCoreDump;
231 232 233
	virDrvDomainSetVcpus		domainSetVcpus;
	virDrvDomainPinVcpu		domainPinVcpu;
	virDrvDomainGetVcpus		domainGetVcpus;
234
	virDrvDomainGetMaxVcpus		domainGetMaxVcpus;
235
	virDrvDomainDumpXML		domainDumpXML;
236 237 238 239 240
	virDrvListDefinedDomains	listDefinedDomains;
	virDrvNumOfDefinedDomains	numOfDefinedDomains;
	virDrvDomainCreate		domainCreate;
	virDrvDomainDefineXML           domainDefineXML;
	virDrvDomainUndefine            domainUndefine;
241 242
	virDrvDomainAttachDevice	domainAttachDevice;
	virDrvDomainDetachDevice	domainDetachDevice;
243 244
	virDrvDomainGetAutostart	domainGetAutostart;
	virDrvDomainSetAutostart	domainSetAutostart;
245 246 247
	virDrvDomainGetSchedulerType	domainGetSchedulerType;
	virDrvDomainGetSchedulerParameters domainGetSchedulerParameters;
	virDrvDomainSetSchedulerParameters domainSetSchedulerParameters;
248 249
};

250 251 252 253
typedef int
	(*virDrvNumOfNetworks)		(virConnectPtr conn);
typedef int
	(*virDrvListNetworks)		(virConnectPtr conn,
254
					 char **const names,
255 256 257 258 259
					 int maxnames);
typedef int
	(*virDrvNumOfDefinedNetworks)	(virConnectPtr conn);
typedef int
	(*virDrvListDefinedNetworks)	(virConnectPtr conn,
260
					 char **const names,
261 262 263 264 265 266 267 268 269 270 271
					 int maxnames);
typedef virNetworkPtr
	(*virDrvNetworkLookupByUUID)	(virConnectPtr conn,
					 const unsigned char *uuid);
typedef virNetworkPtr
	(*virDrvNetworkLookupByName)	(virConnectPtr conn,
					 const char *name);
typedef virNetworkPtr
	(*virDrvNetworkCreateXML)	(virConnectPtr conn,
					 const char *xmlDesc);
typedef virNetworkPtr
272 273
	(*virDrvNetworkDefineXML)	(virConnectPtr conn,
					 const char *xml);
274 275 276 277 278 279 280 281 282
typedef int
	(*virDrvNetworkUndefine)	(virNetworkPtr network);
typedef int
	(*virDrvNetworkCreate)		(virNetworkPtr network);
typedef int
	(*virDrvNetworkDestroy)		(virNetworkPtr network);
typedef char *
	(*virDrvNetworkDumpXML)		(virNetworkPtr network,
					 int flags);
283 284
typedef char *
	(*virDrvNetworkGetBridgeName)	(virNetworkPtr network);
285 286 287 288 289 290 291
typedef int
	(*virDrvNetworkGetAutostart)	(virNetworkPtr network,
					 int *autostart);
typedef int
	(*virDrvNetworkSetAutostart)	(virNetworkPtr network,
					 int autostart);

292 293 294 295 296 297 298 299 300

typedef struct _virNetworkDriver virNetworkDriver;
typedef virNetworkDriver *virNetworkDriverPtr;

/**
 * _virNetworkDriver:
 *
 * Structure associated to a network virtualization driver, defining the various
 * entry points for it.
301 302 303 304
 *
 * All drivers must support the following fields/methods:
 *  - open
 *  - close
305 306
 */
struct _virNetworkDriver {
307
	const char * name;	/* the name of the driver */
308 309 310 311 312 313 314 315 316 317 318 319 320 321
	virDrvOpen			open;
	virDrvClose			close;
	virDrvNumOfNetworks		numOfNetworks;
	virDrvListNetworks		listNetworks;
	virDrvNumOfDefinedNetworks	numOfDefinedNetworks;
	virDrvListDefinedNetworks	listDefinedNetworks;
	virDrvNetworkLookupByUUID	networkLookupByUUID;
	virDrvNetworkLookupByName	networkLookupByName;
	virDrvNetworkCreateXML		networkCreateXML;
	virDrvNetworkDefineXML		networkDefineXML;
	virDrvNetworkUndefine		networkUndefine;
	virDrvNetworkCreate		networkCreate;
	virDrvNetworkDestroy		networkDestroy;
	virDrvNetworkDumpXML		networkDumpXML;
322
	virDrvNetworkGetBridgeName	networkGetBridgeName;
323 324
	virDrvNetworkGetAutostart	networkGetAutostart;
	virDrvNetworkSetAutostart	networkSetAutostart;
325 326
};

327 328 329 330 331 332 333 334 335 336 337 338 339 340
typedef int (*virDrvStateInitialize) (void);
typedef int (*virDrvStateCleanup) (void);
typedef int (*virDrvStateReload) (void);
typedef int (*virDrvStateActive) (void);

typedef struct _virStateDriver virStateDriver;
typedef virStateDriver *virStateDriverPtr;

struct _virStateDriver {
    virDrvStateInitialize  initialize;
    virDrvStateCleanup     cleanup;
    virDrvStateReload      reload;
    virDrvStateActive      active;
};
341 342 343 344 345 346 347

/*
 * Registration
 * TODO: also need ways to (des)activate a given driver
 *       lookup based on the URI given in a virConnectOpen(ReadOnly)
 */
int virRegisterDriver(virDriverPtr);
348
int virRegisterNetworkDriver(virNetworkDriverPtr);
349
int virRegisterStateDriver(virStateDriverPtr);
350 351 352 353 354

#ifdef __cplusplus
}
#endif /* __cplusplus */
#endif /* __VIR_DRIVER_H__ */
355 356 357 358 359 360 361 362 363 364 365 366 367 368

/*
 * vim: set tabstop=4:
 * vim: set shiftwidth=4:
 * vim: set expandtab:
 */
/*
 * Local variables:
 *  indent-tabs-mode: nil
 *  c-indent-level: 4
 *  c-basic-offset: 4
 *  tab-width: 4
 * End:
 */