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

#ifndef __VIR_DRIVER_H__
#define __VIR_DRIVER_H__

9 10 11
#include "config.h"
#include <stdbool.h>

12 13
#include <libxml/uri.h>

14
#include "internal.h"
15 16 17 18
/*
 * List of registered drivers numbers
 */
typedef enum {
19 20 21
    VIR_DRV_XEN_UNIFIED = 1,
    VIR_DRV_TEST = 2,
    VIR_DRV_QEMU = 3,
22
    VIR_DRV_REMOTE = 4,
23
    VIR_DRV_OPENVZ = 5,
24 25
    VIR_DRV_LXC = 6,
    VIR_DRV_UML = 7,
26
    VIR_DRV_VBOX = 8,
D
Daniel Veillard 已提交
27
    VIR_DRV_ONE = 9,
28
    VIR_DRV_ESX = 10,
29
    VIR_DRV_PHYP = 11,
30 31 32
} virDrvNo;


33 34 35 36 37 38 39 40 41 42 43 44 45 46
/* 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;

D
Daniel Veillard 已提交
47

48 49 50 51 52 53 54 55 56 57 58 59 60
/* 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)

61
typedef virDrvOpenStatus
62
        (*virDrvOpen)			(virConnectPtr conn,
63 64
                             virConnectAuthPtr auth,
                             int flags);
65
typedef int
66
        (*virDrvClose)			(virConnectPtr conn);
67
typedef int
D
Daniel P. Berrange 已提交
68
    (*virDrvDrvSupportsFeature) (virConnectPtr conn, int feature);
69
typedef const char *
70
        (*virDrvGetType)		(virConnectPtr conn);
71
typedef int
72 73
        (*virDrvGetVersion)		(virConnectPtr conn,
                                         unsigned long *hvVer);
74 75 76
typedef int
        (*virDrvGetLibVersion)      (virConnectPtr conn,
                                     unsigned long *libVer);
77 78 79 80
typedef char *
    (*virDrvGetHostname)    (virConnectPtr conn);
typedef char *
    (*virDrvGetURI)         (virConnectPtr conn);
81
typedef int
82 83
        (*virDrvGetMaxVcpus)		(virConnectPtr conn,
                                         const char *type);
84
typedef int
85 86
        (*virDrvNodeGetInfo)		(virConnectPtr conn,
                                         virNodeInfoPtr info);
87
typedef char *
88
        (*virDrvGetCapabilities) (virConnectPtr conn);
89
typedef int
90 91 92
        (*virDrvListDomains)		(virConnectPtr conn,
                                         int *ids,
                                         int maxids);
93
typedef int
94
        (*virDrvNumOfDomains)		(virConnectPtr conn);
95
typedef virDomainPtr
96
        (*virDrvDomainCreateXML)	(virConnectPtr conn,
97 98
                                         const char *xmlDesc,
                                         unsigned int flags);
99
typedef virDomainPtr
100 101
        (*virDrvDomainLookupByID)	(virConnectPtr conn,
                                         int id);
102
typedef virDomainPtr
103 104
        (*virDrvDomainLookupByUUID)	(virConnectPtr conn,
                                         const unsigned char *uuid);
105
typedef virDomainPtr
106 107
        (*virDrvDomainLookupByName)	(virConnectPtr conn,
                                         const char *name);
108
typedef int
109
        (*virDrvDomainSuspend)		(virDomainPtr domain);
110
typedef int
111
        (*virDrvDomainResume)		(virDomainPtr domain);
112
typedef int
113
        (*virDrvDomainShutdown)		(virDomainPtr domain);
114
typedef int
115 116
        (*virDrvDomainReboot)		(virDomainPtr domain,
                                         unsigned int flags);
117
typedef int
118
        (*virDrvDomainDestroy)		(virDomainPtr domain);
119
typedef char *
120
        (*virDrvDomainGetOSType)	(virDomainPtr domain);
121
typedef unsigned long
122
        (*virDrvDomainGetMaxMemory)	(virDomainPtr domain);
123
typedef int
124 125
        (*virDrvDomainSetMaxMemory)	(virDomainPtr domain,
                                         unsigned long memory);
126
typedef int
127 128
        (*virDrvDomainSetMemory)	(virDomainPtr domain,
                                         unsigned long memory);
129
typedef int
130 131
        (*virDrvDomainGetInfo)		(virDomainPtr domain,
                                         virDomainInfoPtr info);
132
typedef int
133 134
        (*virDrvDomainSave)		(virDomainPtr domain,
                                         const char *to);
135
typedef int
136 137
        (*virDrvDomainRestore)		(virConnectPtr conn,
                                         const char *from);
D
Daniel Veillard 已提交
138
typedef int
139 140 141
        (*virDrvDomainCoreDump)		(virDomainPtr domain,
                                         const char *to,
                                         int flags);
142
typedef char *
143 144
        (*virDrvDomainDumpXML)		(virDomainPtr dom,
                                         int flags);
145 146 147 148 149 150 151 152 153 154
typedef char *
        (*virDrvConnectDomainXMLFromNative) (virConnectPtr conn,
                                             const char *nativeFormat,
                                             const char *nativeConfig,
                                             unsigned int flags);
typedef char *
        (*virDrvConnectDomainXMLToNative) (virConnectPtr conn,
                                           const char *nativeFormat,
                                           const char *domainXml,
                                           unsigned int flags);
155
typedef int
156 157 158
        (*virDrvListDefinedDomains)	(virConnectPtr conn,
                                         char **const names,
                                         int maxnames);
159
typedef int
160
        (*virDrvNumOfDefinedDomains)	(virConnectPtr conn);
161
typedef int
162
        (*virDrvDomainCreate)		(virDomainPtr dom);
163
typedef virDomainPtr
164 165
        (*virDrvDomainDefineXML)	(virConnectPtr conn,
                                         const char *xml);
166
typedef int
167
        (*virDrvDomainUndefine)		(virDomainPtr dom);
168
typedef int
169 170
        (*virDrvDomainSetVcpus)		(virDomainPtr domain,
                                         unsigned int nvcpus);
171
typedef int
172 173 174 175
        (*virDrvDomainPinVcpu)		(virDomainPtr domain,
                                         unsigned int vcpu,
                                         unsigned char *cpumap,
                                         int maplen);
176
typedef int
177 178 179 180 181
        (*virDrvDomainGetVcpus)		(virDomainPtr domain,
                                         virVcpuInfoPtr info,
                                         int maxinfo,
                                         unsigned char *cpumaps,
                                         int maplen);
182
typedef int
183
        (*virDrvDomainGetMaxVcpus)	(virDomainPtr domain);
184 185 186 187 188 189 190

typedef int
        (*virDrvDomainGetSecurityLabel)	(virDomainPtr domain,
                                         virSecurityLabelPtr seclabel);
typedef int
        (*virDrvNodeGetSecurityModel)	(virConnectPtr conn,
                                         virSecurityModelPtr secmodel);
191
typedef int
192 193
        (*virDrvDomainAttachDevice)	(virDomainPtr domain,
                                         const char *xml);
J
Jim Fehlig 已提交
194 195 196 197
typedef int
        (*virDrvDomainAttachDeviceFlags) (virDomainPtr domain,
                                          const char *xml,
                                          unsigned int flags);
198
typedef int
199 200
        (*virDrvDomainDetachDevice)	(virDomainPtr domain,
                                         const char *xml);
J
Jim Fehlig 已提交
201 202 203 204
typedef int
        (*virDrvDomainDetachDeviceFlags) (virDomainPtr domain,
                                          const char *xml,
                                          unsigned int flags);
205
typedef int
206 207
        (*virDrvDomainGetAutostart)	(virDomainPtr domain,
                                         int *autostart);
208
typedef int
209 210
        (*virDrvDomainSetAutostart)	(virDomainPtr domain,
                                         int autostart);
211

212
typedef char *
213 214
        (*virDrvDomainGetSchedulerType)	(virDomainPtr domain,
                                         int *nparams);
215

216
typedef int
217 218 219 220
        (*virDrvDomainGetSchedulerParameters)
                                        (virDomainPtr domain,
                                         virSchedParameterPtr params,
                                         int *nparams);
221 222

typedef int
223 224 225 226
        (*virDrvDomainSetSchedulerParameters)
                                        (virDomainPtr domain,
                                         virSchedParameterPtr params,
                                         int nparams);
227

228 229 230 231 232 233 234 235 236 237 238
typedef int
    (*virDrvDomainBlockStats)
                    (virDomainPtr domain,
                     const char *path,
                     struct _virDomainBlockStats *stats);
typedef int
    (*virDrvDomainInterfaceStats)
                    (virDomainPtr domain,
                     const char *path,
                     struct _virDomainInterfaceStats *stats);

239 240 241 242 243 244
typedef int
    (*virDrvDomainMemoryStats)
                    (virDomainPtr domain,
                     struct _virDomainMemoryStat *stats,
                     unsigned int nr_stats);

R
Richard W.M. Jones 已提交
245 246 247 248 249
typedef int
    (*virDrvDomainBlockPeek)
                    (virDomainPtr domain,
                     const char *path,
                     unsigned long long offset, size_t size,
250 251
                     void *buffer,
                     unsigned int flags);
R
Richard W.M. Jones 已提交
252

R
Richard W.M. Jones 已提交
253 254 255 256 257 258 259
typedef int
    (*virDrvDomainMemoryPeek)
                    (virDomainPtr domain,
                     unsigned long long start, size_t size,
                     void *buffer,
                     unsigned int flags);

260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289
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);

290 291 292
typedef struct _virDriver virDriver;
typedef virDriver *virDriverPtr;

293 294 295 296 297 298 299
typedef int
    (*virDrvNodeGetCellsFreeMemory)
                    (virConnectPtr conn,
                     unsigned long long *freeMems,
                     int startCell,
                     int maxCells);

300 301
typedef unsigned long long
    (*virDrvNodeGetFreeMemory)
302
                    (virConnectPtr conn);
303

304 305 306
typedef int
    (*virDrvDomainEventRegister)
                    (virConnectPtr conn,
307
                     virConnectDomainEventCallback cb,
308 309
                     void *opaque,
                     virFreeCallback freecb);
310 311 312 313

typedef int
    (*virDrvDomainEventDeregister)
                    (virConnectPtr conn,
314
                     virConnectDomainEventCallback cb);
315

D
Daniel Veillard 已提交
316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337
typedef int
    (*virDrvDomainMigratePrepare2)
                    (virConnectPtr dconn,
                     char **cookie,
                     int *cookielen,
                     const char *uri_in,
                     char **uri_out,
                     unsigned long flags,
                     const char *dname,
                     unsigned long resource,
                     const char *dom_xml);

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

338 339 340 341 342 343 344 345 346 347
typedef int
    (*virDrvNodeDeviceDettach)
                    (virNodeDevicePtr dev);
typedef int
    (*virDrvNodeDeviceReAttach)
                    (virNodeDevicePtr dev);
typedef int
    (*virDrvNodeDeviceReset)
                    (virNodeDevicePtr dev);

C
Chris Lalancette 已提交
348 349 350 351 352 353 354 355 356
typedef int
    (*virDrvDomainMigratePrepareTunnel)
                    (virConnectPtr conn,
                     virStreamPtr st,
                     unsigned long flags,
                     const char *dname,
                     unsigned long resource,
                     const char *dom_xml);

357 358 359 360 361 362 363 364 365
typedef int
    (*virDrvConnectIsEncrypted)(virConnectPtr conn);
typedef int
    (*virDrvConnectIsSecure)(virConnectPtr conn);
typedef int
    (*virDrvDomainIsActive)(virDomainPtr dom);
typedef int
    (*virDrvDomainIsPersistent)(virDomainPtr dom);

J
Jiri Denemark 已提交
366 367 368 369
typedef int
    (*virDrvCPUCompare)(virConnectPtr conn,
                        const char *cpu,
                        unsigned int flags);
370 371 372 373 374
typedef char *
    (*virDrvCPUBaseline)(virConnectPtr conn,
                         const char **xmlCPUs,
                         unsigned int ncpus,
                         unsigned int flags);
J
Jiri Denemark 已提交
375

376 377 378 379 380
/**
 * _virDriver:
 *
 * Structure associated to a virtualization driver, defining the various
 * entry points for it.
381 382 383 384 385 386
 *
 * All drivers must support the following fields/methods:
 *  - no
 *  - name
 *  - open
 *  - close
387 388
 */
struct _virDriver {
389 390 391 392
    int	       no;	/* the number virDrvNo */
    const char * name;	/* the name of the driver */
    virDrvOpen			open;
    virDrvClose			close;
D
Daniel P. Berrange 已提交
393
    virDrvDrvSupportsFeature   supports_feature;
394 395
    virDrvGetType			type;
    virDrvGetVersion		version;
396
    virDrvGetLibVersion		libvirtVersion;
397
    virDrvGetHostname       getHostname;
398 399 400 401 402
    virDrvGetMaxVcpus		getMaxVcpus;
    virDrvNodeGetInfo		nodeGetInfo;
    virDrvGetCapabilities		getCapabilities;
    virDrvListDomains		listDomains;
    virDrvNumOfDomains		numOfDomains;
403
    virDrvDomainCreateXML		domainCreateXML;
404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423
    virDrvDomainLookupByID		domainLookupByID;
    virDrvDomainLookupByUUID	domainLookupByUUID;
    virDrvDomainLookupByName	domainLookupByName;
    virDrvDomainSuspend		domainSuspend;
    virDrvDomainResume		domainResume;
    virDrvDomainShutdown		domainShutdown;
    virDrvDomainReboot		domainReboot;
    virDrvDomainDestroy		domainDestroy;
    virDrvDomainGetOSType		domainGetOSType;
    virDrvDomainGetMaxMemory	domainGetMaxMemory;
    virDrvDomainSetMaxMemory	domainSetMaxMemory;
    virDrvDomainSetMemory		domainSetMemory;
    virDrvDomainGetInfo		domainGetInfo;
    virDrvDomainSave		domainSave;
    virDrvDomainRestore		domainRestore;
    virDrvDomainCoreDump		domainCoreDump;
    virDrvDomainSetVcpus		domainSetVcpus;
    virDrvDomainPinVcpu		domainPinVcpu;
    virDrvDomainGetVcpus		domainGetVcpus;
    virDrvDomainGetMaxVcpus		domainGetMaxVcpus;
424 425
    virDrvDomainGetSecurityLabel     domainGetSecurityLabel;
    virDrvNodeGetSecurityModel  nodeGetSecurityModel;
426
    virDrvDomainDumpXML		domainDumpXML;
427 428
    virDrvConnectDomainXMLFromNative domainXMLFromNative;
    virDrvConnectDomainXMLToNative domainXMLToNative;
429 430 431 432 433 434
    virDrvListDefinedDomains	listDefinedDomains;
    virDrvNumOfDefinedDomains	numOfDefinedDomains;
    virDrvDomainCreate		domainCreate;
    virDrvDomainDefineXML           domainDefineXML;
    virDrvDomainUndefine            domainUndefine;
    virDrvDomainAttachDevice	domainAttachDevice;
J
Jim Fehlig 已提交
435
    virDrvDomainAttachDeviceFlags	domainAttachDeviceFlags;
436
    virDrvDomainDetachDevice	domainDetachDevice;
J
Jim Fehlig 已提交
437
    virDrvDomainDetachDeviceFlags	domainDetachDeviceFlags;
438 439 440 441 442
    virDrvDomainGetAutostart	domainGetAutostart;
    virDrvDomainSetAutostart	domainSetAutostart;
    virDrvDomainGetSchedulerType	domainGetSchedulerType;
    virDrvDomainGetSchedulerParameters domainGetSchedulerParameters;
    virDrvDomainSetSchedulerParameters domainSetSchedulerParameters;
443 444 445
    virDrvDomainMigratePrepare	domainMigratePrepare;
    virDrvDomainMigratePerform	domainMigratePerform;
    virDrvDomainMigrateFinish	domainMigrateFinish;
446 447
    virDrvDomainBlockStats      domainBlockStats;
    virDrvDomainInterfaceStats  domainInterfaceStats;
448
    virDrvDomainMemoryStats     domainMemoryStats;
R
Richard W.M. Jones 已提交
449
    virDrvDomainBlockPeek	domainBlockPeek;
R
Richard W.M. Jones 已提交
450
    virDrvDomainMemoryPeek      domainMemoryPeek;
451 452
    virDrvNodeGetCellsFreeMemory	nodeGetCellsFreeMemory;
    virDrvNodeGetFreeMemory		getFreeMemory;
453 454
    virDrvDomainEventRegister         domainEventRegister;
    virDrvDomainEventDeregister       domainEventDeregister;
D
Daniel Veillard 已提交
455 456
    virDrvDomainMigratePrepare2	domainMigratePrepare2;
    virDrvDomainMigrateFinish2	domainMigrateFinish2;
457 458 459
    virDrvNodeDeviceDettach     nodeDeviceDettach;
    virDrvNodeDeviceReAttach    nodeDeviceReAttach;
    virDrvNodeDeviceReset       nodeDeviceReset;
C
Chris Lalancette 已提交
460
    virDrvDomainMigratePrepareTunnel domainMigratePrepareTunnel;
461 462 463 464
    virDrvConnectIsEncrypted   isEncrypted;
    virDrvConnectIsSecure      isSecure;
    virDrvDomainIsActive       domainIsActive;
    virDrvDomainIsPersistent   domainIsPersistent;
J
Jiri Denemark 已提交
465
    virDrvCPUCompare            cpuCompare;
466
    virDrvCPUBaseline           cpuBaseline;
467 468
};

469
typedef int
470
        (*virDrvNumOfNetworks)		(virConnectPtr conn);
471
typedef int
472 473 474
        (*virDrvListNetworks)		(virConnectPtr conn,
                                         char **const names,
                                         int maxnames);
475
typedef int
476
        (*virDrvNumOfDefinedNetworks)	(virConnectPtr conn);
477
typedef int
478 479 480
        (*virDrvListDefinedNetworks)	(virConnectPtr conn,
                                         char **const names,
                                         int maxnames);
481
typedef virNetworkPtr
482 483
        (*virDrvNetworkLookupByUUID)	(virConnectPtr conn,
                                         const unsigned char *uuid);
484
typedef virNetworkPtr
485 486
        (*virDrvNetworkLookupByName)	(virConnectPtr conn,
                                         const char *name);
487
typedef virNetworkPtr
488 489
        (*virDrvNetworkCreateXML)	(virConnectPtr conn,
                                         const char *xmlDesc);
490
typedef virNetworkPtr
491 492
        (*virDrvNetworkDefineXML)	(virConnectPtr conn,
                                         const char *xml);
493
typedef int
494
        (*virDrvNetworkUndefine)	(virNetworkPtr network);
495
typedef int
496
        (*virDrvNetworkCreate)		(virNetworkPtr network);
497
typedef int
498
        (*virDrvNetworkDestroy)		(virNetworkPtr network);
499
typedef char *
500 501
        (*virDrvNetworkDumpXML)		(virNetworkPtr network,
                                         int flags);
502
typedef char *
503
        (*virDrvNetworkGetBridgeName)	(virNetworkPtr network);
504
typedef int
505 506
        (*virDrvNetworkGetAutostart)	(virNetworkPtr network,
                                         int *autostart);
507
typedef int
508 509
        (*virDrvNetworkSetAutostart)	(virNetworkPtr network,
                                         int autostart);
510

511 512 513 514 515 516
typedef int
        (*virDrvNetworkIsActive)(virNetworkPtr net);
typedef int
        (*virDrvNetworkIsPersistent)(virNetworkPtr net);


517 518 519 520 521 522 523 524 525

typedef struct _virNetworkDriver virNetworkDriver;
typedef virNetworkDriver *virNetworkDriverPtr;

/**
 * _virNetworkDriver:
 *
 * Structure associated to a network virtualization driver, defining the various
 * entry points for it.
526 527 528 529
 *
 * All drivers must support the following fields/methods:
 *  - open
 *  - close
530 531
 */
struct _virNetworkDriver {
532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549
        const char * name;	/* the name of the driver */
        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;
        virDrvNetworkGetBridgeName	networkGetBridgeName;
        virDrvNetworkGetAutostart	networkGetAutostart;
        virDrvNetworkSetAutostart	networkSetAutostart;
550 551
        virDrvNetworkIsActive           networkIsActive;
        virDrvNetworkIsPersistent       networkIsPersistent;
552 553
};

D
Daniel Veillard 已提交
554 555 556 557 558 559 560
/*-------*/
typedef int
        (*virDrvNumOfInterfaces)        (virConnectPtr conn);
typedef int
        (*virDrvListInterfaces)         (virConnectPtr conn,
                                         char **const names,
                                         int maxnames);
561 562 563 564 565 566
typedef int
        (*virDrvNumOfDefinedInterfaces) (virConnectPtr conn);
typedef int
        (*virDrvListDefinedInterfaces)  (virConnectPtr conn,
                                         char **const names,
                                         int maxnames);
D
Daniel Veillard 已提交
567 568 569 570 571 572 573 574
typedef virInterfacePtr
        (*virDrvInterfaceLookupByName)  (virConnectPtr conn,
                                         const char *name);
typedef virInterfacePtr
        (*virDrvInterfaceLookupByMACString)   (virConnectPtr conn,
                                               const char *mac);

typedef char *
575
        (*virDrvInterfaceGetXMLDesc)    (virInterfacePtr iface,
D
Daniel Veillard 已提交
576 577 578 579 580 581 582
                                         unsigned int flags);

typedef virInterfacePtr
        (*virDrvInterfaceDefineXML)     (virConnectPtr conn,
                                         const char *xmlDesc,
                                         unsigned int flags);
typedef int
583
        (*virDrvInterfaceUndefine)      (virInterfacePtr iface);
D
Daniel Veillard 已提交
584
typedef int
585
        (*virDrvInterfaceCreate)        (virInterfacePtr iface,
D
Daniel Veillard 已提交
586 587
                                         unsigned int flags);
typedef int
588
        (*virDrvInterfaceDestroy)       (virInterfacePtr iface,
D
Daniel Veillard 已提交
589 590
                                         unsigned int flags);

591 592 593 594
typedef int
        (*virDrvInterfaceIsActive)(virInterfacePtr iface);


D
Daniel Veillard 已提交
595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613
typedef struct _virInterfaceDriver virInterfaceDriver;
typedef virInterfaceDriver *virInterfaceDriverPtr;

/**
 * _virInterfaceDriver:
 *
 * Structure associated to a network virtualization driver, defining the various
 * entry points for it.
 *
 * All drivers must support the following fields/methods:
 *  - open
 *  - close
 */
struct _virInterfaceDriver {
    const char                      *name; /* the name of the driver */
    virDrvOpen                       open;
    virDrvClose                      close;
    virDrvNumOfInterfaces            numOfInterfaces;
    virDrvListInterfaces             listInterfaces;
614 615
    virDrvNumOfDefinedInterfaces     numOfDefinedInterfaces;
    virDrvListDefinedInterfaces      listDefinedInterfaces;
D
Daniel Veillard 已提交
616 617 618 619 620 621 622
    virDrvInterfaceLookupByName      interfaceLookupByName;
    virDrvInterfaceLookupByMACString interfaceLookupByMACString;
    virDrvInterfaceGetXMLDesc        interfaceGetXMLDesc;
    virDrvInterfaceDefineXML         interfaceDefineXML;
    virDrvInterfaceUndefine          interfaceUndefine;
    virDrvInterfaceCreate            interfaceCreate;
    virDrvInterfaceDestroy           interfaceDestroy;
623
    virDrvInterfaceIsActive          interfaceIsActive;
D
Daniel Veillard 已提交
624 625
};

626 627 628 629 630 631 632 633 634 635 636 637 638

typedef int
    (*virDrvConnectNumOfStoragePools)        (virConnectPtr conn);
typedef int
    (*virDrvConnectListStoragePools)         (virConnectPtr conn,
                                              char **const names,
                                              int maxnames);
typedef int
    (*virDrvConnectNumOfDefinedStoragePools) (virConnectPtr conn);
typedef int
    (*virDrvConnectListDefinedStoragePools)  (virConnectPtr conn,
                                              char **const names,
                                              int maxnames);
639 640 641 642 643
typedef char *
    (*virDrvConnectFindStoragePoolSources)   (virConnectPtr conn,
                                              const char *type,
                                              const char *srcSpec,
                                              unsigned int flags);
644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723
typedef virStoragePoolPtr
    (*virDrvStoragePoolLookupByName)         (virConnectPtr conn,
                                              const char *name);
typedef virStoragePoolPtr
    (*virDrvStoragePoolLookupByUUID)         (virConnectPtr conn,
                                              const unsigned char *uuid);
typedef virStoragePoolPtr
    (*virDrvStoragePoolLookupByVolume)       (virStorageVolPtr vol);
typedef virStoragePoolPtr
    (*virDrvStoragePoolCreateXML)            (virConnectPtr conn,
                                              const char *xmlDesc,
                                              unsigned int flags);
typedef virStoragePoolPtr
    (*virDrvStoragePoolDefineXML)            (virConnectPtr conn,
                                              const char *xmlDesc,
                                              unsigned int flags);
typedef int
    (*virDrvStoragePoolUndefine)             (virStoragePoolPtr pool);
typedef int
    (*virDrvStoragePoolBuild)                (virStoragePoolPtr pool,
                                              unsigned int flags);
typedef int
    (*virDrvStoragePoolCreate)               (virStoragePoolPtr pool,
                                              unsigned int flags);
typedef int
    (*virDrvStoragePoolDestroy)              (virStoragePoolPtr pool);
typedef int
    (*virDrvStoragePoolDelete)               (virStoragePoolPtr pool,
                                              unsigned int flags);
typedef int
    (*virDrvStoragePoolRefresh)              (virStoragePoolPtr pool,
                                              unsigned int flags);
typedef int
    (*virDrvStoragePoolGetInfo)              (virStoragePoolPtr vol,
                                              virStoragePoolInfoPtr info);
typedef char *
    (*virDrvStoragePoolGetXMLDesc)           (virStoragePoolPtr pool,
                                              unsigned int flags);
typedef int
    (*virDrvStoragePoolGetAutostart)         (virStoragePoolPtr pool,
                                              int *autostart);
typedef int
    (*virDrvStoragePoolSetAutostart)         (virStoragePoolPtr pool,
                                              int autostart);
typedef int
    (*virDrvStoragePoolNumOfVolumes)         (virStoragePoolPtr pool);
typedef int
    (*virDrvStoragePoolListVolumes)          (virStoragePoolPtr pool,
                                              char **const names,
                                              int maxnames);


typedef virStorageVolPtr
    (*virDrvStorageVolLookupByName)          (virStoragePoolPtr pool,
                                              const char *name);
typedef virStorageVolPtr
    (*virDrvStorageVolLookupByKey)           (virConnectPtr pool,
                                              const char *key);
typedef virStorageVolPtr
    (*virDrvStorageVolLookupByPath)          (virConnectPtr pool,
                                              const char *path);


typedef virStorageVolPtr
    (*virDrvStorageVolCreateXML)             (virStoragePoolPtr pool,
                                              const char *xmldesc,
                                              unsigned int flags);
typedef int
    (*virDrvStorageVolDelete)               (virStorageVolPtr vol,
                                             unsigned int flags);

typedef int
    (*virDrvStorageVolGetInfo)               (virStorageVolPtr vol,
                                              virStorageVolInfoPtr info);
typedef char *
    (*virDrvStorageVolGetXMLDesc)            (virStorageVolPtr pool,
                                              unsigned int flags);
typedef char *
    (*virDrvStorageVolGetPath)               (virStorageVolPtr vol);

724 725 726 727 728
typedef virStorageVolPtr
    (*virDrvStorageVolCreateXMLFrom)         (virStoragePoolPtr pool,
                                              const char *xmldesc,
                                              virStorageVolPtr clone,
                                              unsigned int flags);
729

730 731 732 733 734 735
typedef int
        (*virDrvStoragePoolIsActive)(virStoragePoolPtr pool);
typedef int
        (*virDrvStoragePoolIsPersistent)(virStoragePoolPtr pool);


736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758

typedef struct _virStorageDriver virStorageDriver;
typedef virStorageDriver *virStorageDriverPtr;

/**
 * _virStorageDriver:
 *
 * Structure associated to a network virtualization driver, defining the various
 * entry points for it.
 *
 * All drivers must support the following fields/methods:
 *  - open
 *  - close
 */
struct _virStorageDriver {
    const char * name;    /* the name of the driver */
    virDrvOpen            open;
    virDrvClose           close;

    virDrvConnectNumOfStoragePools numOfPools;
    virDrvConnectListStoragePools listPools;
    virDrvConnectNumOfDefinedStoragePools numOfDefinedPools;
    virDrvConnectListDefinedStoragePools listDefinedPools;
759
    virDrvConnectFindStoragePoolSources findPoolSources;
760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781
    virDrvStoragePoolLookupByName poolLookupByName;
    virDrvStoragePoolLookupByUUID poolLookupByUUID;
    virDrvStoragePoolLookupByVolume poolLookupByVolume;
    virDrvStoragePoolCreateXML poolCreateXML;
    virDrvStoragePoolDefineXML poolDefineXML;
    virDrvStoragePoolBuild poolBuild;
    virDrvStoragePoolUndefine poolUndefine;
    virDrvStoragePoolCreate poolCreate;
    virDrvStoragePoolDestroy poolDestroy;
    virDrvStoragePoolDelete poolDelete;
    virDrvStoragePoolRefresh poolRefresh;
    virDrvStoragePoolGetInfo poolGetInfo;
    virDrvStoragePoolGetXMLDesc poolGetXMLDesc;
    virDrvStoragePoolGetAutostart poolGetAutostart;
    virDrvStoragePoolSetAutostart poolSetAutostart;
    virDrvStoragePoolNumOfVolumes poolNumOfVolumes;
    virDrvStoragePoolListVolumes poolListVolumes;

    virDrvStorageVolLookupByName volLookupByName;
    virDrvStorageVolLookupByKey volLookupByKey;
    virDrvStorageVolLookupByPath volLookupByPath;
    virDrvStorageVolCreateXML volCreateXML;
782
    virDrvStorageVolCreateXMLFrom volCreateXMLFrom;
783 784 785 786
    virDrvStorageVolDelete volDelete;
    virDrvStorageVolGetInfo volGetInfo;
    virDrvStorageVolGetXMLDesc volGetXMLDesc;
    virDrvStorageVolGetPath volGetPath;
787 788
    virDrvStoragePoolIsActive   poolIsActive;
    virDrvStoragePoolIsPersistent   poolIsPersistent;
789 790
};

791
#ifdef WITH_LIBVIRTD
792
typedef int (*virDrvStateInitialize) (int privileged);
793 794 795 796 797 798 799 800
typedef int (*virDrvStateCleanup) (void);
typedef int (*virDrvStateReload) (void);
typedef int (*virDrvStateActive) (void);

typedef struct _virStateDriver virStateDriver;
typedef virStateDriver *virStateDriverPtr;

struct _virStateDriver {
801
    const char *name;
802 803 804 805 806
    virDrvStateInitialize  initialize;
    virDrvStateCleanup     cleanup;
    virDrvStateReload      reload;
    virDrvStateActive      active;
};
A
Atsushi SAKAI 已提交
807
#endif
808

809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836

typedef struct _virDeviceMonitor virDeviceMonitor;
typedef virDeviceMonitor *virDeviceMonitorPtr;

typedef int (*virDevMonNumOfDevices)(virConnectPtr conn,
                                     const char *cap,
                                     unsigned int flags);

typedef int (*virDevMonListDevices)(virConnectPtr conn,
                                    const char *cap,
                                    char **const names,
                                    int maxnames,
                                    unsigned int flags);

typedef virNodeDevicePtr (*virDevMonDeviceLookupByName)(virConnectPtr conn,
                                                        const char *name);

typedef char * (*virDevMonDeviceDumpXML)(virNodeDevicePtr dev,
                                         unsigned int flags);

typedef char * (*virDevMonDeviceGetParent)(virNodeDevicePtr dev);

typedef int (*virDevMonDeviceNumOfCaps)(virNodeDevicePtr dev);

typedef int (*virDevMonDeviceListCaps)(virNodeDevicePtr dev,
                                       char **const names,
                                       int maxnames);

837 838 839 840 841
typedef virNodeDevicePtr (*virDrvNodeDeviceCreateXML)(virConnectPtr conn,
                                                      const char *xmlDesc,
                                                      unsigned int flags);
typedef int (*virDrvNodeDeviceDestroy)(virNodeDevicePtr dev);

842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859
/**
 * _virDeviceMonitor:
 *
 * Structure associated with monitoring the devices
 * on a virtualized node.
 *
 */
struct _virDeviceMonitor {
    const char * name;    /* the name of the driver */
    virDrvOpen open;
    virDrvClose close;
    virDevMonNumOfDevices numOfDevices;
    virDevMonListDevices listDevices;
    virDevMonDeviceLookupByName deviceLookupByName;
    virDevMonDeviceDumpXML deviceDumpXML;
    virDevMonDeviceGetParent deviceGetParent;
    virDevMonDeviceNumOfCaps deviceNumOfCaps;
    virDevMonDeviceListCaps deviceListCaps;
860 861
    virDrvNodeDeviceCreateXML deviceCreateXML;
    virDrvNodeDeviceDestroy deviceDestroy;
862 863
};

864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879
/* bits 16 and above of virDomainXMLFlags are for internal use */
#define VIR_DOMAIN_XML_FLAGS_MASK 0xffff

/* Bits 16 and above of virSecretGetValue flags are for internal use */
#define VIR_SECRET_GET_VALUE_FLAGS_MASK 0xffff

enum {
    /* This getValue call is inside libvirt, override the "private" flag.
       This flag can not be set by outside callers. */
    VIR_SECRET_GET_VALUE_INTERNAL_CALL = 1 << 16
};

/* Make sure ... INTERNAL_CALL can not be set by the caller */
verify((VIR_SECRET_GET_VALUE_INTERNAL_CALL &
        VIR_SECRET_GET_VALUE_FLAGS_MASK) == 0);

880
typedef virSecretPtr
881 882
    (*virDrvSecretLookupByUUID)        (virConnectPtr conn,
                                        const unsigned char *uuid);
883 884 885 886
typedef virSecretPtr
    (*virDrvSecretLookupByUsage)       (virConnectPtr conn,
                                        int usageType,
                                        const char *usageID);
887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931
typedef virSecretPtr
    (*virDrvSecretDefineXML)                 (virConnectPtr conn,
                                              const char *xml,
                                              unsigned int flags);
typedef char *
    (*virDrvSecretGetXMLDesc)                (virSecretPtr secret,
                                              unsigned int flags);
typedef int
    (*virDrvSecretSetValue)                  (virSecretPtr secret,
                                              const unsigned char *value,
                                              size_t value_size,
                                              unsigned int flags);
typedef unsigned char *
    (*virDrvSecretGetValue)                  (virSecretPtr secret,
                                              size_t *value_size,
                                              unsigned int flags);
typedef int
    (*virDrvSecretUndefine)                  (virSecretPtr secret);
typedef int
    (*virDrvSecretNumOfSecrets)              (virConnectPtr conn);
typedef int
    (*virDrvSecretListSecrets)               (virConnectPtr conn,
                                              char **uuids,
                                              int maxuuids);

typedef struct _virSecretDriver virSecretDriver;
typedef virSecretDriver *virSecretDriverPtr;

/**
 * _virSecretDriver:
 *
 * Structure associated to a driver for storing secrets, defining the various
 * entry points for it.
 *
 * All drivers must support the following fields/methods:
 *  - open
 *  - close
 */
struct _virSecretDriver {
    const char *name;
    virDrvOpen open;
    virDrvClose close;

    virDrvSecretNumOfSecrets numOfSecrets;
    virDrvSecretListSecrets listSecrets;
932
    virDrvSecretLookupByUUID lookupByUUID;
933
    virDrvSecretLookupByUsage lookupByUsage;
934 935 936 937 938 939 940
    virDrvSecretDefineXML defineXML;
    virDrvSecretGetXMLDesc getXMLDesc;
    virDrvSecretSetValue setValue;
    virDrvSecretGetValue getValue;
    virDrvSecretUndefine undefine;
};

941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975

typedef struct _virStreamDriver virStreamDriver;
typedef virStreamDriver *virStreamDriverPtr;

typedef int (*virDrvStreamSend)(virStreamPtr st,
                                const char *data,
                                size_t nbytes);
typedef int (*virDrvStreamRecv)(virStreamPtr st,
                                char *data,
                                size_t nbytes);

typedef int (*virDrvStreamEventAddCallback)(virStreamPtr stream,
                                            int events,
                                            virStreamEventCallback cb,
                                            void *opaque,
                                            virFreeCallback ff);

typedef int (*virDrvStreamEventUpdateCallback)(virStreamPtr stream,
                                               int events);
typedef int (*virDrvStreamEventRemoveCallback)(virStreamPtr stream);
typedef int (*virDrvStreamFinish)(virStreamPtr st);
typedef int (*virDrvStreamAbort)(virStreamPtr st);


struct _virStreamDriver {
    virDrvStreamSend streamSend;
    virDrvStreamRecv streamRecv;
    virDrvStreamEventAddCallback streamAddCallback;
    virDrvStreamEventUpdateCallback streamUpdateCallback;
    virDrvStreamEventRemoveCallback streamRemoveCallback;
    virDrvStreamFinish streamFinish;
    virDrvStreamAbort streamAbort;
};


976 977 978 979 980 981
/*
 * Registration
 * TODO: also need ways to (des)activate a given driver
 *       lookup based on the URI given in a virConnectOpen(ReadOnly)
 */
int virRegisterDriver(virDriverPtr);
982
int virRegisterNetworkDriver(virNetworkDriverPtr);
D
Daniel Veillard 已提交
983
int virRegisterInterfaceDriver(virInterfaceDriverPtr);
984
int virRegisterStorageDriver(virStorageDriverPtr);
985
int virRegisterDeviceMonitor(virDeviceMonitorPtr);
986
int virRegisterSecretDriver(virSecretDriverPtr);
A
Atsushi SAKAI 已提交
987
#ifdef WITH_LIBVIRTD
988
int virRegisterStateDriver(virStateDriverPtr);
A
Atsushi SAKAI 已提交
989
#endif
990
void *virDriverLoadModule(const char *name);
991 992

#endif /* __VIR_DRIVER_H__ */