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

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


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

42 43 44 45 46 47 48 49 50 51 52 53 54 55 56
/* 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

D
Daniel Veillard 已提交
57 58 59 60 61
    /* Driver supports V2-style virDomainMigrate, ie. domainMigratePrepare2/
     * domainMigratePerform/domainMigrateFinish2.
     */
#define VIR_DRV_FEATURE_MIGRATION_V2 3

62 63 64 65 66 67 68 69 70 71 72 73 74
/* 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)

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

typedef int
        (*virDrvDomainGetSecurityLabel)	(virDomainPtr domain,
                                         virSecurityLabelPtr seclabel);
typedef int
        (*virDrvNodeGetSecurityModel)	(virConnectPtr conn,
                                         virSecurityModelPtr secmodel);
202
typedef int
203 204
        (*virDrvDomainAttachDevice)	(virDomainPtr domain,
                                         const char *xml);
205
typedef int
206 207
        (*virDrvDomainDetachDevice)	(virDomainPtr domain,
                                         const char *xml);
208
typedef int
209 210
        (*virDrvDomainGetAutostart)	(virDomainPtr domain,
                                         int *autostart);
211
typedef int
212 213
        (*virDrvDomainSetAutostart)	(virDomainPtr domain,
                                         int autostart);
214

215
typedef char *
216 217
        (*virDrvDomainGetSchedulerType)	(virDomainPtr domain,
                                         int *nparams);
218

219
typedef int
220 221 222 223
        (*virDrvDomainGetSchedulerParameters)
                                        (virDomainPtr domain,
                                         virSchedParameterPtr params,
                                         int *nparams);
224 225

typedef int
226 227 228 229
        (*virDrvDomainSetSchedulerParameters)
                                        (virDomainPtr domain,
                                         virSchedParameterPtr params,
                                         int nparams);
230

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

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

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

257 258 259 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
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);

287 288 289
typedef struct _virDriver virDriver;
typedef virDriver *virDriverPtr;

290 291 292 293 294 295 296
typedef int
    (*virDrvNodeGetCellsFreeMemory)
                    (virConnectPtr conn,
                     unsigned long long *freeMems,
                     int startCell,
                     int maxCells);

297 298
typedef unsigned long long
    (*virDrvNodeGetFreeMemory)
299
                    (virConnectPtr conn);
300

301 302 303
typedef int
    (*virDrvDomainEventRegister)
                    (virConnectPtr conn,
304
                     virConnectDomainEventCallback cb,
305 306
                     void *opaque,
                     virFreeCallback freecb);
307 308 309 310

typedef int
    (*virDrvDomainEventDeregister)
                    (virConnectPtr conn,
311
                     virConnectDomainEventCallback cb);
312

D
Daniel Veillard 已提交
313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334
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);

335 336 337 338 339 340 341 342 343 344
typedef int
    (*virDrvNodeDeviceDettach)
                    (virNodeDevicePtr dev);
typedef int
    (*virDrvNodeDeviceReAttach)
                    (virNodeDevicePtr dev);
typedef int
    (*virDrvNodeDeviceReset)
                    (virNodeDevicePtr dev);

345 346 347 348 349
/**
 * _virDriver:
 *
 * Structure associated to a virtualization driver, defining the various
 * entry points for it.
350 351 352 353 354 355
 *
 * All drivers must support the following fields/methods:
 *  - no
 *  - name
 *  - open
 *  - close
356 357
 */
struct _virDriver {
358 359 360 361
    int	       no;	/* the number virDrvNo */
    const char * name;	/* the name of the driver */
    virDrvOpen			open;
    virDrvClose			close;
D
Daniel P. Berrange 已提交
362
    virDrvDrvSupportsFeature   supports_feature;
363 364
    virDrvGetType			type;
    virDrvGetVersion		version;
365
    virDrvGetHostname       getHostname;
366 367 368 369 370
    virDrvGetMaxVcpus		getMaxVcpus;
    virDrvNodeGetInfo		nodeGetInfo;
    virDrvGetCapabilities		getCapabilities;
    virDrvListDomains		listDomains;
    virDrvNumOfDomains		numOfDomains;
371
    virDrvDomainCreateXML		domainCreateXML;
372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391
    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;
392 393
    virDrvDomainGetSecurityLabel     domainGetSecurityLabel;
    virDrvNodeGetSecurityModel  nodeGetSecurityModel;
394
    virDrvDomainDumpXML		domainDumpXML;
395 396
    virDrvConnectDomainXMLFromNative domainXMLFromNative;
    virDrvConnectDomainXMLToNative domainXMLToNative;
397 398 399 400 401 402 403 404 405 406 407 408
    virDrvListDefinedDomains	listDefinedDomains;
    virDrvNumOfDefinedDomains	numOfDefinedDomains;
    virDrvDomainCreate		domainCreate;
    virDrvDomainDefineXML           domainDefineXML;
    virDrvDomainUndefine            domainUndefine;
    virDrvDomainAttachDevice	domainAttachDevice;
    virDrvDomainDetachDevice	domainDetachDevice;
    virDrvDomainGetAutostart	domainGetAutostart;
    virDrvDomainSetAutostart	domainSetAutostart;
    virDrvDomainGetSchedulerType	domainGetSchedulerType;
    virDrvDomainGetSchedulerParameters domainGetSchedulerParameters;
    virDrvDomainSetSchedulerParameters domainSetSchedulerParameters;
409 410 411
    virDrvDomainMigratePrepare	domainMigratePrepare;
    virDrvDomainMigratePerform	domainMigratePerform;
    virDrvDomainMigrateFinish	domainMigrateFinish;
412 413
    virDrvDomainBlockStats      domainBlockStats;
    virDrvDomainInterfaceStats  domainInterfaceStats;
R
Richard W.M. Jones 已提交
414
    virDrvDomainBlockPeek	domainBlockPeek;
R
Richard W.M. Jones 已提交
415
    virDrvDomainMemoryPeek      domainMemoryPeek;
416 417
    virDrvNodeGetCellsFreeMemory	nodeGetCellsFreeMemory;
    virDrvNodeGetFreeMemory		getFreeMemory;
418 419
    virDrvDomainEventRegister         domainEventRegister;
    virDrvDomainEventDeregister       domainEventDeregister;
D
Daniel Veillard 已提交
420 421
    virDrvDomainMigratePrepare2	domainMigratePrepare2;
    virDrvDomainMigrateFinish2	domainMigrateFinish2;
422 423 424
    virDrvNodeDeviceDettach     nodeDeviceDettach;
    virDrvNodeDeviceReAttach    nodeDeviceReAttach;
    virDrvNodeDeviceReset       nodeDeviceReset;
425 426
};

427
typedef int
428
        (*virDrvNumOfNetworks)		(virConnectPtr conn);
429
typedef int
430 431 432
        (*virDrvListNetworks)		(virConnectPtr conn,
                                         char **const names,
                                         int maxnames);
433
typedef int
434
        (*virDrvNumOfDefinedNetworks)	(virConnectPtr conn);
435
typedef int
436 437 438
        (*virDrvListDefinedNetworks)	(virConnectPtr conn,
                                         char **const names,
                                         int maxnames);
439
typedef virNetworkPtr
440 441
        (*virDrvNetworkLookupByUUID)	(virConnectPtr conn,
                                         const unsigned char *uuid);
442
typedef virNetworkPtr
443 444
        (*virDrvNetworkLookupByName)	(virConnectPtr conn,
                                         const char *name);
445
typedef virNetworkPtr
446 447
        (*virDrvNetworkCreateXML)	(virConnectPtr conn,
                                         const char *xmlDesc);
448
typedef virNetworkPtr
449 450
        (*virDrvNetworkDefineXML)	(virConnectPtr conn,
                                         const char *xml);
451
typedef int
452
        (*virDrvNetworkUndefine)	(virNetworkPtr network);
453
typedef int
454
        (*virDrvNetworkCreate)		(virNetworkPtr network);
455
typedef int
456
        (*virDrvNetworkDestroy)		(virNetworkPtr network);
457
typedef char *
458 459
        (*virDrvNetworkDumpXML)		(virNetworkPtr network,
                                         int flags);
460
typedef char *
461
        (*virDrvNetworkGetBridgeName)	(virNetworkPtr network);
462
typedef int
463 464
        (*virDrvNetworkGetAutostart)	(virNetworkPtr network,
                                         int *autostart);
465
typedef int
466 467
        (*virDrvNetworkSetAutostart)	(virNetworkPtr network,
                                         int autostart);
468

469 470 471 472 473 474 475 476 477

typedef struct _virNetworkDriver virNetworkDriver;
typedef virNetworkDriver *virNetworkDriverPtr;

/**
 * _virNetworkDriver:
 *
 * Structure associated to a network virtualization driver, defining the various
 * entry points for it.
478 479 480 481
 *
 * All drivers must support the following fields/methods:
 *  - open
 *  - close
482 483
 */
struct _virNetworkDriver {
484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501
        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;
502 503
};

D
Daniel Veillard 已提交
504 505 506 507 508 509 510 511 512 513 514 515 516 517 518
/*-------*/
typedef int
        (*virDrvNumOfInterfaces)        (virConnectPtr conn);
typedef int
        (*virDrvListInterfaces)         (virConnectPtr conn,
                                         char **const names,
                                         int maxnames);
typedef virInterfacePtr
        (*virDrvInterfaceLookupByName)  (virConnectPtr conn,
                                         const char *name);
typedef virInterfacePtr
        (*virDrvInterfaceLookupByMACString)   (virConnectPtr conn,
                                               const char *mac);

typedef char *
519
        (*virDrvInterfaceGetXMLDesc)    (virInterfacePtr iface,
D
Daniel Veillard 已提交
520 521 522 523 524 525 526
                                         unsigned int flags);

typedef virInterfacePtr
        (*virDrvInterfaceDefineXML)     (virConnectPtr conn,
                                         const char *xmlDesc,
                                         unsigned int flags);
typedef int
527
        (*virDrvInterfaceUndefine)      (virInterfacePtr iface);
D
Daniel Veillard 已提交
528
typedef int
529
        (*virDrvInterfaceCreate)        (virInterfacePtr iface,
D
Daniel Veillard 已提交
530 531
                                         unsigned int flags);
typedef int
532
        (*virDrvInterfaceDestroy)       (virInterfacePtr iface,
D
Daniel Veillard 已提交
533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562
                                         unsigned int flags);

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;
    virDrvInterfaceLookupByName      interfaceLookupByName;
    virDrvInterfaceLookupByMACString interfaceLookupByMACString;
    virDrvInterfaceGetXMLDesc        interfaceGetXMLDesc;
    virDrvInterfaceDefineXML         interfaceDefineXML;
    virDrvInterfaceUndefine          interfaceUndefine;
    virDrvInterfaceCreate            interfaceCreate;
    virDrvInterfaceDestroy           interfaceDestroy;
};

563 564 565 566 567 568 569 570 571 572 573 574 575

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);
576 577 578 579 580
typedef char *
    (*virDrvConnectFindStoragePoolSources)   (virConnectPtr conn,
                                              const char *type,
                                              const char *srcSpec,
                                              unsigned int flags);
581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660
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);

661 662 663 664 665
typedef virStorageVolPtr
    (*virDrvStorageVolCreateXMLFrom)         (virStoragePoolPtr pool,
                                              const char *xmldesc,
                                              virStorageVolPtr clone,
                                              unsigned int flags);
666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689


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;
690
    virDrvConnectFindStoragePoolSources findPoolSources;
691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712
    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;
713
    virDrvStorageVolCreateXMLFrom volCreateXMLFrom;
714 715 716 717 718 719
    virDrvStorageVolDelete volDelete;
    virDrvStorageVolGetInfo volGetInfo;
    virDrvStorageVolGetXMLDesc volGetXMLDesc;
    virDrvStorageVolGetPath volGetPath;
};

720
#ifdef WITH_LIBVIRTD
721 722 723 724 725 726 727 728 729 730 731 732 733 734
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;
};
A
Atsushi SAKAI 已提交
735
#endif
736

737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764

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);

765 766 767 768 769
typedef virNodeDevicePtr (*virDrvNodeDeviceCreateXML)(virConnectPtr conn,
                                                      const char *xmlDesc,
                                                      unsigned int flags);
typedef int (*virDrvNodeDeviceDestroy)(virNodeDevicePtr dev);

770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787
/**
 * _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;
788 789
    virDrvNodeDeviceCreateXML deviceCreateXML;
    virDrvNodeDeviceDestroy deviceDestroy;
790 791
};

792 793 794 795 796 797
/*
 * Registration
 * TODO: also need ways to (des)activate a given driver
 *       lookup based on the URI given in a virConnectOpen(ReadOnly)
 */
int virRegisterDriver(virDriverPtr);
798
int virRegisterNetworkDriver(virNetworkDriverPtr);
D
Daniel Veillard 已提交
799
int virRegisterInterfaceDriver(virInterfaceDriverPtr);
800
int virRegisterStorageDriver(virStorageDriverPtr);
801
int virRegisterDeviceMonitor(virDeviceMonitorPtr);
A
Atsushi SAKAI 已提交
802
#ifdef WITH_LIBVIRTD
803
int virRegisterStateDriver(virStateDriverPtr);
A
Atsushi SAKAI 已提交
804
#endif
805
void *virDriverLoadModule(const char *name);
806 807

#endif /* __VIR_DRIVER_H__ */