driver.h 13.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
#include <libxml/uri.h>

14 15 16 17
#ifdef __cplusplus
extern "C" {
#endif

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


30 31 32 33 34 35 36 37 38 39 40 41 42 43
/* 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;

44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71
/* Feature detection.  This is a libvirt-private interface for determining
 * what features are supported by the driver.
 *
 * The remote driver passes features through to the real driver at the
 * remote end unmodified, except if you query a VIR_DRV_FEATURE_REMOTE*
 * feature.
 */
    /* Driver supports V1-style virDomainMigrate, ie. domainMigratePrepare/
     * domainMigratePerform/domainMigrateFinish.
     */
#define VIR_DRV_FEATURE_MIGRATION_V1 1

    /* Driver is not local. */
#define VIR_DRV_FEATURE_REMOTE 2

/* Internal feature-detection macro.  Don't call drv->supports_feature
 * directly, because it may be NULL, use this macro instead.
 *
 * Note that you must check for errors.
 *
 * Returns:
 *   >= 1  Feature is supported.
 *   0     Feature is not supported.
 *   -1    Error.
 */
#define VIR_DRV_SUPPORTS_FEATURE(drv,conn,feature)                      \
    ((drv)->supports_feature ? (drv)->supports_feature((conn),(feature)) : 0)

72
typedef virDrvOpenStatus
73
	(*virDrvOpen)			(virConnectPtr conn,
74 75 76
                             xmlURIPtr uri,
                             virConnectAuthPtr auth,
                             int flags);
77 78
typedef int
	(*virDrvClose)			(virConnectPtr conn);
79 80
typedef int
    (*virDrvSupportsFeature) (virConnectPtr conn, int feature);
81 82 83
typedef const char *
	(*virDrvGetType)		(virConnectPtr conn);
typedef int
84
	(*virDrvGetVersion)		(virConnectPtr conn,
85
					 unsigned long *hvVer);
86 87 88 89
typedef char *
    (*virDrvGetHostname)    (virConnectPtr conn);
typedef char *
    (*virDrvGetURI)         (virConnectPtr conn);
90
typedef int
91 92
	(*virDrvGetMaxVcpus)		(virConnectPtr conn,
					 const char *type);
93 94 95
typedef int
	(*virDrvNodeGetInfo)		(virConnectPtr conn,
					 virNodeInfoPtr info);
96 97
typedef char *
	(*virDrvGetCapabilities) (virConnectPtr conn);
98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122
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);
123 124 125
typedef int
	(*virDrvDomainReboot)		(virDomainPtr domain,
					 unsigned int flags);
126 127 128 129 130 131 132 133 134
typedef int
	(*virDrvDomainDestroy)		(virDomainPtr domain);
typedef char *
	(*virDrvDomainGetOSType)	(virDomainPtr domain);
typedef unsigned long
	(*virDrvDomainGetMaxMemory)	(virDomainPtr domain);
typedef int
	(*virDrvDomainSetMaxMemory)	(virDomainPtr domain,
					 unsigned long memory);
135 136 137
typedef int
	(*virDrvDomainSetMemory)	(virDomainPtr domain,
					 unsigned long memory);
138 139 140 141 142 143 144 145 146
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 已提交
147 148 149 150
typedef int
	(*virDrvDomainCoreDump)		(virDomainPtr domain,
					 const char *to,
					 int flags);
151 152 153
typedef char *
	(*virDrvDomainDumpXML)		(virDomainPtr dom,
					 int flags);
154 155
typedef int
	(*virDrvListDefinedDomains)	(virConnectPtr conn,
156
					 char **const names,
157 158 159 160
					 int maxnames);
typedef int
	(*virDrvNumOfDefinedDomains)	(virConnectPtr conn);
typedef int
161
	(*virDrvDomainCreate)		(virDomainPtr dom);
162
typedef virDomainPtr
163 164
	(*virDrvDomainDefineXML)	(virConnectPtr conn,
					 const char *xml);
165
typedef int
166
	(*virDrvDomainUndefine)		(virDomainPtr dom);
167 168 169 170 171 172 173 174 175 176 177 178 179 180
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);
181 182
typedef int
	(*virDrvDomainGetMaxVcpus)	(virDomainPtr domain);
183 184
typedef int
	(*virDrvDomainAttachDevice)	(virDomainPtr domain,
185
					 const char *xml);
186 187
typedef int
	(*virDrvDomainDetachDevice)	(virDomainPtr domain,
188
					 const char *xml);
189 190 191 192 193 194
typedef int
	(*virDrvDomainGetAutostart)	(virDomainPtr domain,
					 int *autostart);
typedef int
	(*virDrvDomainSetAutostart)	(virDomainPtr domain,
					 int autostart);
195

196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211
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);

212 213 214 215 216 217 218 219 220 221 222
typedef int
    (*virDrvDomainBlockStats)
                    (virDomainPtr domain,
                     const char *path,
                     struct _virDomainBlockStats *stats);
typedef int
    (*virDrvDomainInterfaceStats)
                    (virDomainPtr domain,
                     const char *path,
                     struct _virDomainInterfaceStats *stats);

223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252
typedef int
    (*virDrvDomainMigratePrepare)
                    (virConnectPtr dconn,
                     char **cookie,
                     int *cookielen,
                     const char *uri_in,
                     char **uri_out,
                     unsigned long flags,
                     const char *dname,
                     unsigned long resource);

typedef int
    (*virDrvDomainMigratePerform)
                    (virDomainPtr domain,
                     const char *cookie,
                     int cookielen,
                     const char *uri,
                     unsigned long flags,
                     const char *dname,
                     unsigned long resource);

typedef virDomainPtr
    (*virDrvDomainMigrateFinish)
                    (virConnectPtr dconn,
                     const char *dname,
                     const char *cookie,
                     int cookielen,
                     const char *uri,
                     unsigned long flags);

253 254 255
typedef struct _virDriver virDriver;
typedef virDriver *virDriverPtr;

256 257 258 259 260 261 262
typedef int
    (*virDrvNodeGetCellsFreeMemory)
                    (virConnectPtr conn,
                     unsigned long long *freeMems,
                     int startCell,
                     int maxCells);

263 264 265 266
typedef unsigned long long
    (*virDrvNodeGetFreeMemory)
		    (virConnectPtr conn);

267 268 269 270 271
/**
 * _virDriver:
 *
 * Structure associated to a virtualization driver, defining the various
 * entry points for it.
272 273 274 275 276 277
 *
 * All drivers must support the following fields/methods:
 *  - no
 *  - name
 *  - open
 *  - close
278 279
 */
struct _virDriver {
280 281 282
	int	       no;	/* the number virDrvNo */
	const char * name;	/* the name of the driver */
	unsigned long ver;	/* the version of the backend */
283 284
	virDrvOpen			open;
	virDrvClose			close;
285
    virDrvSupportsFeature   supports_feature;
286 287
	virDrvGetType			type;
	virDrvGetVersion		version;
288 289
    virDrvGetHostname       getHostname;
    virDrvGetURI            getURI;
290
	virDrvGetMaxVcpus		getMaxVcpus;
291
	virDrvNodeGetInfo		nodeGetInfo;
292
	virDrvGetCapabilities		getCapabilities;
293 294 295 296 297 298 299 300 301
	virDrvListDomains		listDomains;
	virDrvNumOfDomains		numOfDomains;
	virDrvDomainCreateLinux		domainCreateLinux;
	virDrvDomainLookupByID		domainLookupByID;
	virDrvDomainLookupByUUID	domainLookupByUUID;
	virDrvDomainLookupByName	domainLookupByName;
	virDrvDomainSuspend		domainSuspend;
	virDrvDomainResume		domainResume;
	virDrvDomainShutdown		domainShutdown;
302
	virDrvDomainReboot		domainReboot;
303 304 305 306
	virDrvDomainDestroy		domainDestroy;
	virDrvDomainGetOSType		domainGetOSType;
	virDrvDomainGetMaxMemory	domainGetMaxMemory;
	virDrvDomainSetMaxMemory	domainSetMaxMemory;
307
	virDrvDomainSetMemory		domainSetMemory;
308 309 310
	virDrvDomainGetInfo		domainGetInfo;
	virDrvDomainSave		domainSave;
	virDrvDomainRestore		domainRestore;
D
Daniel Veillard 已提交
311
	virDrvDomainCoreDump		domainCoreDump;
312 313 314
	virDrvDomainSetVcpus		domainSetVcpus;
	virDrvDomainPinVcpu		domainPinVcpu;
	virDrvDomainGetVcpus		domainGetVcpus;
315
	virDrvDomainGetMaxVcpus		domainGetMaxVcpus;
316
	virDrvDomainDumpXML		domainDumpXML;
317 318 319 320 321
	virDrvListDefinedDomains	listDefinedDomains;
	virDrvNumOfDefinedDomains	numOfDefinedDomains;
	virDrvDomainCreate		domainCreate;
	virDrvDomainDefineXML           domainDefineXML;
	virDrvDomainUndefine            domainUndefine;
322 323
	virDrvDomainAttachDevice	domainAttachDevice;
	virDrvDomainDetachDevice	domainDetachDevice;
324 325
	virDrvDomainGetAutostart	domainGetAutostart;
	virDrvDomainSetAutostart	domainSetAutostart;
326 327 328
	virDrvDomainGetSchedulerType	domainGetSchedulerType;
	virDrvDomainGetSchedulerParameters domainGetSchedulerParameters;
	virDrvDomainSetSchedulerParameters domainSetSchedulerParameters;
329 330 331
    virDrvDomainMigratePrepare	domainMigratePrepare;
    virDrvDomainMigratePerform	domainMigratePerform;
    virDrvDomainMigrateFinish	domainMigrateFinish;
332 333
    virDrvDomainBlockStats      domainBlockStats;
    virDrvDomainInterfaceStats  domainInterfaceStats;
334
	virDrvNodeGetCellsFreeMemory	nodeGetCellsFreeMemory;
335
	virDrvNodeGetFreeMemory		getFreeMemory;
336 337
};

338 339 340 341
typedef int
	(*virDrvNumOfNetworks)		(virConnectPtr conn);
typedef int
	(*virDrvListNetworks)		(virConnectPtr conn,
342
					 char **const names,
343 344 345 346 347
					 int maxnames);
typedef int
	(*virDrvNumOfDefinedNetworks)	(virConnectPtr conn);
typedef int
	(*virDrvListDefinedNetworks)	(virConnectPtr conn,
348
					 char **const names,
349 350 351 352 353 354 355 356 357 358 359
					 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
360 361
	(*virDrvNetworkDefineXML)	(virConnectPtr conn,
					 const char *xml);
362 363 364 365 366 367 368 369 370
typedef int
	(*virDrvNetworkUndefine)	(virNetworkPtr network);
typedef int
	(*virDrvNetworkCreate)		(virNetworkPtr network);
typedef int
	(*virDrvNetworkDestroy)		(virNetworkPtr network);
typedef char *
	(*virDrvNetworkDumpXML)		(virNetworkPtr network,
					 int flags);
371 372
typedef char *
	(*virDrvNetworkGetBridgeName)	(virNetworkPtr network);
373 374 375 376 377 378 379
typedef int
	(*virDrvNetworkGetAutostart)	(virNetworkPtr network,
					 int *autostart);
typedef int
	(*virDrvNetworkSetAutostart)	(virNetworkPtr network,
					 int autostart);

380 381 382 383 384 385 386 387 388

typedef struct _virNetworkDriver virNetworkDriver;
typedef virNetworkDriver *virNetworkDriverPtr;

/**
 * _virNetworkDriver:
 *
 * Structure associated to a network virtualization driver, defining the various
 * entry points for it.
389 390 391 392
 *
 * All drivers must support the following fields/methods:
 *  - open
 *  - close
393 394
 */
struct _virNetworkDriver {
395
	const char * name;	/* the name of the driver */
396 397 398 399 400 401 402 403 404 405 406 407 408 409
	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;
410
	virDrvNetworkGetBridgeName	networkGetBridgeName;
411 412
	virDrvNetworkGetAutostart	networkGetAutostart;
	virDrvNetworkSetAutostart	networkSetAutostart;
413 414
};

415 416 417 418 419 420 421 422 423 424 425 426 427 428
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;
};
429 430 431 432 433 434 435

/*
 * Registration
 * TODO: also need ways to (des)activate a given driver
 *       lookup based on the URI given in a virConnectOpen(ReadOnly)
 */
int virRegisterDriver(virDriverPtr);
436
int virRegisterNetworkDriver(virNetworkDriverPtr);
437
int virRegisterStateDriver(virStateDriverPtr);
438 439 440 441 442

#ifdef __cplusplus
}
#endif /* __cplusplus */
#endif /* __VIR_DRIVER_H__ */
443 444 445 446 447 448 449 450 451 452 453 454 455 456

/*
 * 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:
 */