libvirt.h 47.6 KB
Newer Older
1
/* -*- c -*-
2 3 4
 * libvirt.h:
 * Summary: core interfaces for the libvirt library
 * Description: Provides the interfaces of the libvirt library to handle
5
 *              virtualized domains
6
 *
7
 * Copy:  Copyright (C) 2005,2006 Red Hat, Inc.
8 9 10
 *
 * See COPYING.LIB for the License of this software
 *
11
 * Author: Daniel Veillard <veillard@redhat.com>
12 13 14 15 16
 */

#ifndef __VIR_VIRLIB_H__
#define __VIR_VIRLIB_H__

17 18
#include <sys/types.h>

19 20 21 22
#ifdef __cplusplus
extern "C" {
#endif

23 24 25 26 27 28 29 30 31
#ifndef VIR_DEPRECATED
  /* The feature is present in gcc-3.1 and newer.  */
# if __GNUC__ > 3 || (__GNUC__ == 3 && __GNUC_MINOR__ >= 1)
#  define VIR_DEPRECATED __attribute__((__deprecated__))
# else
#  define VIR_DEPRECATED /* nothing */
# endif
#endif /* VIR_DEPRECATED */

32 33 34 35
/**
 * virConnect:
 *
 * a virConnect is a private structure representing a connection to
36
 * the Hypervisor.
37 38 39 40 41 42 43
 */
typedef struct _virConnect virConnect;

/**
 * virConnectPtr:
 *
 * a virConnectPtr is pointer to a virConnect private structure, this is the
44
 * type used to reference a connection to the Hypervisor in the API.
45 46 47 48 49 50
 */
typedef virConnect *virConnectPtr;

/**
 * virDomain:
 *
51
 * a virDomain is a private structure representing a domain.
52 53 54 55 56 57 58
 */
typedef struct _virDomain virDomain;

/**
 * virDomainPtr:
 *
 * a virDomainPtr is pointer to a virDomain private structure, this is the
59
 * type used to reference a domain in the API.
60 61 62
 */
typedef virDomain *virDomainPtr;

63 64 65 66 67 68
/**
 * virDomainState:
 *
 * A domain may be in different states at a given point in time
 */
typedef enum {
R
Richard W.M. Jones 已提交
69 70 71 72
     VIR_DOMAIN_NOSTATE = 0, /* no state */
     VIR_DOMAIN_RUNNING = 1, /* the domain is running */
     VIR_DOMAIN_BLOCKED = 2, /* the domain is blocked on resource */
     VIR_DOMAIN_PAUSED  = 3, /* the domain is paused by user */
73
     VIR_DOMAIN_SHUTDOWN= 4, /* the domain is being shut down */
R
Richard W.M. Jones 已提交
74
     VIR_DOMAIN_SHUTOFF = 5, /* the domain is shut off */
75
     VIR_DOMAIN_CRASHED = 6  /* the domain is crashed */
76 77 78 79 80
} virDomainState;

/**
 * virDomainInfoPtr:
 *
81
 * a virDomainInfo is a structure filled by virDomainGetInfo() and extracting
82
 * runtime information for a given active Domain
83 84 85 86 87
 */

typedef struct _virDomainInfo virDomainInfo;

struct _virDomainInfo {
88
    unsigned char state;        /* the running state, one of virDomainState */
R
Richard W.M. Jones 已提交
89 90 91 92
    unsigned long maxMem;       /* the maximum memory in KBytes allowed */
    unsigned long memory;       /* the memory in KBytes used by the domain */
    unsigned short nrVirtCpu;   /* the number of virtual CPUs for the domain */
    unsigned long long cpuTime; /* the CPU time used in nanoseconds */
93 94 95 96 97 98 99 100 101 102
};

/**
 * virDomainInfoPtr:
 *
 * a virDomainInfoPtr is a pointer to a virDomainInfo structure.
 */

typedef virDomainInfo *virDomainInfoPtr;

103
/**
104
 * virDomainCreateFlags:
105 106 107 108 109 110
 *
 * Flags OR'ed together to provide specific behaviour when creating a
 * Domain.
 */
typedef enum {
     VIR_DOMAIN_NONE = 0
111
} virDomainCreateFlags;
112

113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174
/**
 * VIR_SECURITY_LABEL_BUFLEN:
 *
 * Macro providing the maximum length of the virSecurityLabel label string.
 * Note that this value is based on that used by Labeled NFS.
 */
#define VIR_SECURITY_LABEL_BUFLEN (4096 + 1)

/**
 * virSecurityLabel:
 *
 * a virSecurityLabel is a structure filled by virDomainGetSecurityLabel(),
 * providing the security label and associated attributes for the specified
 * domain.
 *
 */
typedef struct _virSecurityLabel {
    char label[VIR_SECURITY_LABEL_BUFLEN];    /* security label string */
    int enforcing;                            /* 1 if security policy is being enforced for domain */
} virSecurityLabel;

/**
 * virSecurityLabelPtr:
 *
 * a virSecurityLabelPtr is a pointer to a virSecurityLabel.
 */
typedef virSecurityLabel *virSecurityLabelPtr;

/**
 * VIR_SECURITY_MODEL_BUFLEN:
 *
 * Macro providing the maximum length of the virSecurityModel model string.
 */
#define VIR_SECURITY_MODEL_BUFLEN (256 + 1)

/**
 * VIR_SECURITY_DOI_BUFLEN:
 *
 * Macro providing the maximum length of the virSecurityModel doi string.
 */
#define VIR_SECURITY_DOI_BUFLEN (256 + 1)

/**
 * virSecurityModel:
 *
 * a virSecurityModel is a structure filled by virNodeGetSecurityModel(),
 * providing the per-hypervisor security model and DOI attributes for the
 * specified domain.
 *
 */
typedef struct _virSecurityModel {
    char model[VIR_SECURITY_MODEL_BUFLEN];      /* security model string */
    char doi[VIR_SECURITY_DOI_BUFLEN];          /* domain of interpetation */
} virSecurityModel;

/**
 * virSecurityModelPtr:
 *
 * a virSecurityModelPtr is a pointer to a virSecurityModel.
 */
typedef virSecurityModel *virSecurityModelPtr;

175 176 177 178
/**
 * virNodeInfoPtr:
 *
 * a virNodeInfo is a structure filled by virNodeGetInfo() and providing
179
 * the information for the Node.
180 181 182 183 184
 */

typedef struct _virNodeInfo virNodeInfo;

struct _virNodeInfo {
R
Richard W.M. Jones 已提交
185
    char model[32];     /* string indicating the CPU model */
186
    unsigned long memory;/* memory size in kilobytes */
R
Richard W.M. Jones 已提交
187 188 189
    unsigned int cpus;  /* the number of active CPUs */
    unsigned int mhz;   /* expected CPU frequency */
    unsigned int nodes; /* the number of NUMA cell, 1 for uniform mem access */
190
    unsigned int sockets;/* number of CPU socket per node */
R
Richard W.M. Jones 已提交
191
    unsigned int cores; /* number of core per socket */
192 193 194
    unsigned int threads;/* number of threads per core */
};

195

196 197 198 199 200 201
/**
 * virDomainSchedParameterType:
 *
 * A scheduler parameter field type
 */
typedef enum {
R
Richard W.M. Jones 已提交
202 203 204 205 206 207
    VIR_DOMAIN_SCHED_FIELD_INT     = 1, /* integer case */
    VIR_DOMAIN_SCHED_FIELD_UINT    = 2, /* unsigned integer case */
    VIR_DOMAIN_SCHED_FIELD_LLONG   = 3, /* long long case */
    VIR_DOMAIN_SCHED_FIELD_ULLONG  = 4, /* unsigned long long case */
    VIR_DOMAIN_SCHED_FIELD_DOUBLE  = 5, /* double case */
    VIR_DOMAIN_SCHED_FIELD_BOOLEAN = 6  /* boolean(character) case */
208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226
} virSchedParameterType;

/**
 * VIR_DOMAIN_SCHED_FIELD_LENGTH:
 *
 * Macro providing the field length of virSchedParameter
 */

#define VIR_DOMAIN_SCHED_FIELD_LENGTH 80

/**
 * virDomainSchedParameter:
 *
 * a virDomainSchedParameter is the set of scheduler parameters
 */

typedef struct _virSchedParameter virSchedParameter;

struct _virSchedParameter {
R
Richard W.M. Jones 已提交
227 228
    char field[VIR_DOMAIN_SCHED_FIELD_LENGTH];  /* parameter name */
    int type;   /* parameter type */
229
    union {
R
Richard W.M. Jones 已提交
230 231 232 233 234 235
        int i;                          /* data for integer case */
        unsigned int ui;        /* data for unsigned integer case */
        long long int l;        /* data for long long integer case */
        unsigned long long int ul;      /* data for unsigned long long integer case */
        double d;       /* data for double case */
        char b;         /* data for char case */
236 237 238 239 240 241 242 243 244 245 246 247 248 249
    } value; /* parameter value */
};

/**
 * virSchedParameterPtr:
 *
 * a virSchedParameterPtr is a pointer to a virSchedParameter structure.
 */

typedef virSchedParameter *virSchedParameterPtr;

/*
 * Fetch scheduler parameters, caller allocates 'params' field of size 'nparams'
 */
R
Richard W.M. Jones 已提交
250
int     virDomainGetSchedulerParameters (virDomainPtr domain,
251 252
                                         virSchedParameterPtr params,
                                         int *nparams);
253 254 255 256

/*
 * Change scheduler parameters
 */
R
Richard W.M. Jones 已提交
257
int     virDomainSetSchedulerParameters (virDomainPtr domain,
258 259
                                         virSchedParameterPtr params,
                                         int nparams);
260

261 262 263 264
/**
 * virDomainBlockStats:
 *
 * Block device stats for virDomainBlockStats.
265 266 267 268 269 270
 *
 * Hypervisors may return a field set to ((long long)-1) which indicates
 * that the hypervisor does not support that statistic.
 *
 * NB. Here 'long long' means 64 bit integer.
 */
271 272
typedef struct _virDomainBlockStats virDomainBlockStatsStruct;

273
struct _virDomainBlockStats {
274 275 276
  long long rd_req; /* number of read requests */
  long long rd_bytes; /* number of read bytes */
  long long wr_req; /* number of write requests */
277
  long long wr_bytes; /* number of written bytes */
278
  long long errs;   /* In Xen this returns the mysterious 'oo_req'. */
279 280
};

281 282 283 284 285 286 287 288 289 290 291
/**
 * virDomainBlockStatsPtr:
 *
 * A pointer to a virDomainBlockStats structure
 */
typedef virDomainBlockStatsStruct *virDomainBlockStatsPtr;

/**
 * virDomainInterfaceStats:
 *
 * Network interface stats for virDomainInterfaceStats.
292 293 294 295 296 297
 *
 * Hypervisors may return a field set to ((long long)-1) which indicates
 * that the hypervisor does not support that statistic.
 *
 * NB. Here 'long long' means 64 bit integer.
 */
298 299
typedef struct _virDomainInterfaceStats virDomainInterfaceStatsStruct;

300 301 302 303 304 305 306 307 308 309
struct _virDomainInterfaceStats {
  long long rx_bytes;
  long long rx_packets;
  long long rx_errs;
  long long rx_drop;
  long long tx_bytes;
  long long tx_packets;
  long long tx_errs;
  long long tx_drop;
};
310 311 312 313

/**
 * virDomainInterfaceStatsPtr:
 *
314
 * A pointer to a virDomainInterfaceStats structure
315 316 317
 */
typedef virDomainInterfaceStatsStruct *virDomainInterfaceStatsPtr;

318

319 320 321 322 323 324 325
/* Domain migration flags. */
typedef enum {
  VIR_MIGRATE_LIVE              = 1, /* live migration */
} virDomainMigrateFlags;

/* Domain migration. */
virDomainPtr virDomainMigrate (virDomainPtr domain, virConnectPtr dconn,
326 327
                               unsigned long flags, const char *dname,
                               const char *uri, unsigned long bandwidth);
328

329 330 331 332 333
/**
 * VIR_NODEINFO_MAXCPUS:
 * @nodeinfo: virNodeInfo instance
 *
 * This macro is to calculate the total number of CPUs supported
334
 * but not necessary active in the host.
335 336 337 338 339
 */


#define VIR_NODEINFO_MAXCPUS(nodeinfo) ((nodeinfo).nodes*(nodeinfo).sockets*(nodeinfo).cores*(nodeinfo).threads)

340 341 342 343 344 345 346 347
/**
 * virNodeInfoPtr:
 *
 * a virNodeInfoPtr is a pointer to a virNodeInfo structure.
 */

typedef virNodeInfo *virNodeInfoPtr;

348 349 350
/**
 * virConnectFlags
 *
351
 * Flags when opening a connection to a hypervisor
352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391
 */
typedef enum {
    VIR_CONNECT_RO = 1,    /* A readonly connection */
} virConnectFlags;


typedef enum {
    VIR_CRED_USERNAME = 1,     /* Identity to act as */
    VIR_CRED_AUTHNAME = 2,     /* Identify to authorize as */
    VIR_CRED_LANGUAGE = 3,     /* RFC 1766 languages, comma separated */
    VIR_CRED_CNONCE = 4,       /* client supplies a nonce */
    VIR_CRED_PASSPHRASE = 5,   /* Passphrase secret */
    VIR_CRED_ECHOPROMPT = 6,   /* Challenge response */
    VIR_CRED_NOECHOPROMPT = 7, /* Challenge response */
    VIR_CRED_REALM = 8,        /* Authentication realm */
    VIR_CRED_EXTERNAL = 9,     /* Externally managed credential */

    /* More may be added - expect the unexpected */
} virConnectCredentialType;

struct _virConnectCredential {
    int type; /* One of virConnectCredentialType constants */
    const char *prompt; /* Prompt to show to user */
    const char *challenge; /* Additional challenge to show */
    const char *defresult; /* Optional default result */
    char *result; /* Result to be filled with user response (or defresult) */
    unsigned int resultlen; /* Length of the result */
};

typedef struct _virConnectCredential virConnectCredential;
typedef virConnectCredential *virConnectCredentialPtr;


/**
 * virConnectCredCallbackPtr
 *
 * @param authtype type of authentication being performed
 * @param cred list of virConnectCredential object to fetch from user
 * @param ncred size of cred list
 * @param cbdata opaque data passed to virConnectOpenAuth
392
 *
393 394 395 396 397 398 399 400
 * When authentication requires one or more interactions, this callback
 * is invoked. For each interaction supplied, data must be gathered
 * from the user and filled in to the 'result' and 'resultlen' fields.
 * If an interaction can not be filled, fill in NULL and 0.
 *
 * Return 0 if all interactions were filled, or -1 upon error
 */
typedef int (*virConnectAuthCallbackPtr)(virConnectCredentialPtr cred,
401 402
                                         unsigned int ncred,
                                         void *cbdata);
403 404 405 406 407 408 409 410 411 412 413 414 415

struct _virConnectAuth {
    int *credtype; /* List of supported virConnectCredentialType values */
    unsigned int ncredtype;

    virConnectAuthCallbackPtr cb; /* Callback used to collect credentials */
    void *cbdata;
};


typedef struct _virConnectAuth virConnectAuth;
typedef virConnectAuth *virConnectAuthPtr;

416 417
extern virConnectAuthPtr virConnectAuthPtrDefault;

418
/**
419
 * VIR_UUID_BUFLEN:
420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435
 *
 * This macro provides the length of the buffer required
 * for virDomainGetUUID()
 */

#define VIR_UUID_BUFLEN (16)

/**
 * VIR_UUID_STRING_BUFLEN:
 *
 * This macro provides the length of the buffer required
 * for virDomainGetUUIDString()
 */

#define VIR_UUID_STRING_BUFLEN (36+1)

436
/* library versioning */
437 438 439 440

/**
 * LIBVIR_VERSION_NUMBER:
 *
441
 * Macro providing the version of the library as
442 443 444
 * version * 1,000,000 + minor * 1000 + micro
 */

D
Daniel Veillard 已提交
445
#define LIBVIR_VERSION_NUMBER 6003
446

R
Richard W.M. Jones 已提交
447
int                     virGetVersion           (unsigned long *libVer,
448 449
                                                 const char *type,
                                                 unsigned long *typeVer);
450

451 452 453
/*
 * Connection and disconnections to the Hypervisor
 */
R
Richard W.M. Jones 已提交
454
int                     virInitialize           (void);
455

R
Richard W.M. Jones 已提交
456 457
virConnectPtr           virConnectOpen          (const char *name);
virConnectPtr           virConnectOpenReadOnly  (const char *name);
458
virConnectPtr           virConnectOpenAuth      (const char *name,
459 460
                                                 virConnectAuthPtr auth,
                                                 int flags);
461
int                     virConnectRef           (virConnectPtr conn);
R
Richard W.M. Jones 已提交
462 463 464
int                     virConnectClose         (virConnectPtr conn);
const char *            virConnectGetType       (virConnectPtr conn);
int                     virConnectGetVersion    (virConnectPtr conn,
465
                                                 unsigned long *hvVer);
466 467 468 469
char *                  virConnectGetHostname   (virConnectPtr conn);
char *                  virConnectGetURI        (virConnectPtr conn);


470 471 472 473 474
/*
 * Capabilities of the connection / driver.
 */

int                     virConnectGetMaxVcpus   (virConnectPtr conn,
475
                                                 const char *type);
R
Richard W.M. Jones 已提交
476
int                     virNodeGetInfo          (virConnectPtr conn,
477
                                                 virNodeInfoPtr info);
478
char *                  virConnectGetCapabilities (virConnectPtr conn);
479

R
Richard W.M. Jones 已提交
480
unsigned long long      virNodeGetFreeMemory    (virConnectPtr conn);
481

482 483 484
int                     virNodeGetSecurityModel (virConnectPtr conn,
                                                 virSecurityModelPtr secmodel);

485 486 487
/*
 * Gather list of running domains
 */
R
Richard W.M. Jones 已提交
488
int                     virConnectListDomains   (virConnectPtr conn,
489 490
                                                 int *ids,
                                                 int maxids);
491

K
 
Karel Zak 已提交
492 493 494
/*
 * Number of domains
 */
R
Richard W.M. Jones 已提交
495
int                     virConnectNumOfDomains  (virConnectPtr conn);
K
 
Karel Zak 已提交
496 497


498 499 500
/*
 * Get connection from domain.
 */
R
Richard W.M. Jones 已提交
501
virConnectPtr           virDomainGetConnect     (virDomainPtr domain);
502

503 504 505
/*
 * Domain creation and destruction
 */
506
virDomainPtr            virDomainCreateXML      (virConnectPtr conn,
507 508
                                                 const char *xmlDesc,
                                                 unsigned int flags);
R
Richard W.M. Jones 已提交
509
virDomainPtr            virDomainLookupByName   (virConnectPtr conn,
510
                                                 const char *name);
R
Richard W.M. Jones 已提交
511
virDomainPtr            virDomainLookupByID     (virConnectPtr conn,
512
                                                 int id);
R
Richard W.M. Jones 已提交
513
virDomainPtr            virDomainLookupByUUID   (virConnectPtr conn,
514
                                                 const unsigned char *uuid);
R
Richard W.M. Jones 已提交
515
virDomainPtr            virDomainLookupByUUIDString     (virConnectPtr conn,
516
                                                        const char *uuid);
K
Karel Zak 已提交
517

R
Richard W.M. Jones 已提交
518 519
int                     virDomainShutdown       (virDomainPtr domain);
int                     virDomainReboot         (virDomainPtr domain,
520
                                                 unsigned int flags);
R
Richard W.M. Jones 已提交
521
int                     virDomainDestroy        (virDomainPtr domain);
522
int                     virDomainRef            (virDomainPtr domain);
R
Richard W.M. Jones 已提交
523
int                     virDomainFree           (virDomainPtr domain);
524 525 526 527

/*
 * Domain suspend/resume
 */
R
Richard W.M. Jones 已提交
528 529
int                     virDomainSuspend        (virDomainPtr domain);
int                     virDomainResume         (virDomainPtr domain);
530

531 532 533
/*
 * Domain save/restore
 */
R
Richard W.M. Jones 已提交
534
int                     virDomainSave           (virDomainPtr domain,
535
                                                 const char *to);
R
Richard W.M. Jones 已提交
536
int                     virDomainRestore        (virConnectPtr conn,
537
                                                 const char *from);
538

D
Daniel Veillard 已提交
539 540 541
/*
 * Domain core dump
 */
R
Richard W.M. Jones 已提交
542
int                     virDomainCoreDump       (virDomainPtr domain,
543 544
                                                 const char *to,
                                                 int flags);
D
Daniel Veillard 已提交
545

546
/*
547
 * Domain runtime information
548
 */
R
Richard W.M. Jones 已提交
549
int                     virDomainGetInfo        (virDomainPtr domain,
550
                                                 virDomainInfoPtr info);
551

552 553 554
/*
 * Return scheduler type in effect 'sedf', 'credit', 'linux'
 */
R
Richard W.M. Jones 已提交
555
char *                  virDomainGetSchedulerType(virDomainPtr domain,
556
                                                 int *nparams);
557

558 559 560
/*
 * Dynamic control of domains
 */
R
Richard W.M. Jones 已提交
561 562 563
const char *            virDomainGetName        (virDomainPtr domain);
unsigned int            virDomainGetID          (virDomainPtr domain);
int                     virDomainGetUUID        (virDomainPtr domain,
564
                                                 unsigned char *uuid);
R
Richard W.M. Jones 已提交
565
int                     virDomainGetUUIDString  (virDomainPtr domain,
566
                                                char *buf);
R
Richard W.M. Jones 已提交
567 568 569
char *                  virDomainGetOSType      (virDomainPtr domain);
unsigned long           virDomainGetMaxMemory   (virDomainPtr domain);
int                     virDomainSetMaxMemory   (virDomainPtr domain,
570
                                                 unsigned long memory);
R
Richard W.M. Jones 已提交
571
int                     virDomainSetMemory      (virDomainPtr domain,
572
                                                 unsigned long memory);
R
Richard W.M. Jones 已提交
573
int                     virDomainGetMaxVcpus    (virDomainPtr domain);
574 575
int                     virDomainGetSecurityLabel (virDomainPtr domain,
                                                   virSecurityLabelPtr seclabel);
576

577 578 579
/*
 * XML domain description
 */
580 581 582 583 584 585 586
/**
 * virDomainXMLFlags:
 *
 * Flags available for virDomainGetXMLDesc
 */

typedef enum {
587 588
    VIR_DOMAIN_XML_SECURE = 1, /* dump security sensitive information too */
    VIR_DOMAIN_XML_INACTIVE = 2/* dump inactive domain information */
589 590
} virDomainXMLFlags;

R
Richard W.M. Jones 已提交
591
char *                  virDomainGetXMLDesc     (virDomainPtr domain,
592
                                                 int flags);
593

594
int                     virDomainBlockStats     (virDomainPtr dom,
595 596 597
                                                 const char *path,
                                                 virDomainBlockStatsPtr stats,
                                                 size_t size);
598
int                     virDomainInterfaceStats (virDomainPtr dom,
599 600 601
                                                 const char *path,
                                                 virDomainInterfaceStatsPtr stats,
                                                 size_t size);
R
Richard W.M. Jones 已提交
602 603 604 605 606 607
int                     virDomainBlockPeek (virDomainPtr dom,
                                            const char *path,
                                            unsigned long long offset,
                                            size_t size,
                                            void *buffer,
                                            unsigned int flags);
608

R
Richard W.M. Jones 已提交
609 610 611 612 613 614 615 616 617 618 619
/* Memory peeking flags. */
typedef enum {
  VIR_MEMORY_VIRTUAL              = 1, /* addresses are virtual addresses */
} virDomainMemoryFlags;

int                     virDomainMemoryPeek (virDomainPtr dom,
                                             unsigned long long start,
                                             size_t size,
                                             void *buffer,
                                             unsigned int flags);

620 621 622
/*
 * defined but not running domains
 */
R
Richard W.M. Jones 已提交
623
virDomainPtr            virDomainDefineXML      (virConnectPtr conn,
624
                                                 const char *xml);
R
Richard W.M. Jones 已提交
625
int                     virDomainUndefine       (virDomainPtr domain);
626
int                     virConnectNumOfDefinedDomains  (virConnectPtr conn);
R
Richard W.M. Jones 已提交
627
int                     virConnectListDefinedDomains (virConnectPtr conn,
628 629
                                                 char **const names,
                                                 int maxnames);
R
Richard W.M. Jones 已提交
630
int                     virDomainCreate         (virDomainPtr domain);
631

R
Richard W.M. Jones 已提交
632
int                     virDomainGetAutostart   (virDomainPtr domain,
633
                                                 int *autostart);
R
Richard W.M. Jones 已提交
634
int                     virDomainSetAutostart   (virDomainPtr domain,
635
                                                 int autostart);
636

637 638 639 640 641
/**
 * virVcpuInfo: structure for information about a virtual CPU in a domain.
 */

typedef enum {
R
Richard W.M. Jones 已提交
642 643 644
    VIR_VCPU_OFFLINE    = 0,    /* the virtual CPU is offline */
    VIR_VCPU_RUNNING    = 1,    /* the virtual CPU is running */
    VIR_VCPU_BLOCKED    = 2,    /* the virtual CPU is blocked on resource */
645 646 647 648
} virVcpuState;

typedef struct _virVcpuInfo virVcpuInfo;
struct _virVcpuInfo {
R
Richard W.M. Jones 已提交
649 650
    unsigned int number;        /* virtual CPU number */
    int state;                  /* value from virVcpuState */
651
    unsigned long long cpuTime; /* CPU time used, in nanoseconds */
R
Richard W.M. Jones 已提交
652
    int cpu;                    /* real CPU number, or -1 if offline */
653 654 655
};
typedef virVcpuInfo *virVcpuInfoPtr;

R
Richard W.M. Jones 已提交
656
int                     virDomainSetVcpus       (virDomainPtr domain,
657
                                                 unsigned int nvcpus);
658

R
Richard W.M. Jones 已提交
659
int                     virDomainPinVcpu        (virDomainPtr domain,
660 661 662
                                                 unsigned int vcpu,
                                                 unsigned char *cpumap,
                                                 int maplen);
663 664 665 666 667 668

/**
 * VIR_USE_CPU:
 * @cpumap: pointer to a bit map of real CPUs (in 8-bit bytes) (IN/OUT)
 * @cpu: the physical CPU number
 *
669
 * This macro is to be used in conjunction with virDomainPinVcpu() API.
670 671 672
 * USE_CPU macro set the bit (CPU usable) of the related cpu in cpumap.
 */

R
Richard W.M. Jones 已提交
673
#define VIR_USE_CPU(cpumap,cpu) (cpumap[(cpu)/8] |= (1<<((cpu)%8)))
674 675 676 677 678 679

/**
 * VIR_UNUSE_CPU:
 * @cpumap: pointer to a bit map of real CPUs (in 8-bit bytes) (IN/OUT)
 * @cpu: the physical CPU number
 *
680
 * This macro is to be used in conjunction with virDomainPinVcpu() API.
681 682 683
 * USE_CPU macro reset the bit (CPU not usable) of the related cpu in cpumap.
 */

R
Richard W.M. Jones 已提交
684
#define VIR_UNUSE_CPU(cpumap,cpu)       (cpumap[(cpu)/8] &= ~(1<<((cpu)%8)))
685

686
/**
687
 * VIR_CPU_MAPLEN:
688 689
 * @cpu: number of physical CPUs
 *
690
 * This macro is to be used in conjunction with virDomainPinVcpu() API.
691 692 693 694 695 696 697
 * It returns the length (in bytes) required to store the complete
 * CPU map between a single virtual & all physical CPUs of a domain.
 */

#define VIR_CPU_MAPLEN(cpu)      (((cpu)+7)/8)


R
Richard W.M. Jones 已提交
698
int                     virDomainGetVcpus       (virDomainPtr domain,
699 700 701 702
                                                 virVcpuInfoPtr info,
                                                 int maxinfo,
                                                 unsigned char *cpumaps,
                                                 int maplen);
703 704 705 706 707 708 709 710

/**
 * VIR_CPU_USABLE:
 * @cpumaps: pointer to an array of cpumap (in 8-bit bytes) (IN)
 * @maplen: the length (in bytes) of one cpumap
 * @vcpu: the virtual CPU number
 * @cpu: the physical CPU number
 *
711
 * This macro is to be used in conjunction with virDomainGetVcpus() API.
712 713 714 715 716
 * VIR_CPU_USABLE macro returns a non zero value (true) if the cpu
 * is usable by the vcpu, and 0 otherwise.
 */

#define VIR_CPU_USABLE(cpumaps,maplen,vcpu,cpu) \
717
        (cpumaps[((vcpu)*(maplen))+((cpu)/8)] & (1<<((cpu)%8)))
718 719 720 721 722 723 724

/**
 * VIR_COPY_CPUMAP:
 * @cpumaps: pointer to an array of cpumap (in 8-bit bytes) (IN)
 * @maplen: the length (in bytes) of one cpumap
 * @vcpu: the virtual CPU number
 * @cpumap: pointer to a cpumap (in 8-bit bytes) (OUT)
R
Richard W.M. Jones 已提交
725
 *      This cpumap must be previously allocated by the caller
726 727
 *      (ie: malloc(maplen))
 *
728
 * This macro is to be used in conjunction with virDomainGetVcpus() and
729 730 731 732 733
 * virDomainPinVcpu() APIs. VIR_COPY_CPUMAP macro extract the cpumap of
 * the specified vcpu from cpumaps array and copy it into cpumap to be used
 * later by virDomainPinVcpu() API.
 */
#define VIR_COPY_CPUMAP(cpumaps,maplen,vcpu,cpumap) \
734
        memcpy(cpumap, &(cpumaps[(vcpu)*(maplen)]), (maplen))
735 736 737 738 739 740 741 742


/**
 * VIR_GET_CPUMAP:
 * @cpumaps: pointer to an array of cpumap (in 8-bit bytes) (IN)
 * @maplen: the length (in bytes) of one cpumap
 * @vcpu: the virtual CPU number
 *
743
 * This macro is to be used in conjunction with virDomainGetVcpus() and
744 745 746
 * virDomainPinVcpu() APIs. VIR_GET_CPUMAP macro returns a pointer to the
 * cpumap of the specified vcpu from cpumaps array.
 */
R
Richard W.M. Jones 已提交
747
#define VIR_GET_CPUMAP(cpumaps,maplen,vcpu)     &(cpumaps[(vcpu)*(maplen)])
748

749 750
int virDomainAttachDevice(virDomainPtr domain, const char *xml);
int virDomainDetachDevice(virDomainPtr domain, const char *xml);
751

752 753 754 755
/*
 * NUMA support
 */

R
Richard W.M. Jones 已提交
756
int                      virNodeGetCellsFreeMemory(virConnectPtr conn,
757 758 759
                                                   unsigned long long *freeMems,
                                                   int startCell,
                                                   int maxCells);
760

761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779
/*
 * Virtual Networks API
 */

/**
 * virNetwork:
 *
 * a virNetwork is a private structure representing a virtual network.
 */
typedef struct _virNetwork virNetwork;

/**
 * virNetworkPtr:
 *
 * a virNetworkPtr is pointer to a virNetwork private structure, this is the
 * type used to reference a virtual network in the API.
 */
typedef virNetwork *virNetworkPtr;

780 781 782
/*
 * Get connection from network.
 */
R
Richard W.M. Jones 已提交
783
virConnectPtr           virNetworkGetConnect    (virNetworkPtr network);
784

785 786 787
/*
 * List active networks
 */
R
Richard W.M. Jones 已提交
788 789
int                     virConnectNumOfNetworks (virConnectPtr conn);
int                     virConnectListNetworks  (virConnectPtr conn,
790 791
                                                 char **const names,
                                                 int maxnames);
792 793 794 795

/*
 * List inactive networks
 */
R
Richard W.M. Jones 已提交
796 797
int                     virConnectNumOfDefinedNetworks  (virConnectPtr conn);
int                     virConnectListDefinedNetworks   (virConnectPtr conn,
798 799
                                                         char **const names,
                                                         int maxnames);
800 801 802 803

/*
 * Lookup network by name or uuid
 */
R
Richard W.M. Jones 已提交
804
virNetworkPtr           virNetworkLookupByName          (virConnectPtr conn,
805
                                                         const char *name);
R
Richard W.M. Jones 已提交
806
virNetworkPtr           virNetworkLookupByUUID          (virConnectPtr conn,
807
                                                         const unsigned char *uuid);
R
Richard W.M. Jones 已提交
808
virNetworkPtr           virNetworkLookupByUUIDString    (virConnectPtr conn,
809
                                                         const char *uuid);
810 811 812 813

/*
 * Create active transient network
 */
R
Richard W.M. Jones 已提交
814
virNetworkPtr           virNetworkCreateXML     (virConnectPtr conn,
815
                                                 const char *xmlDesc);
816 817 818 819

/*
 * Define inactive persistent network
 */
R
Richard W.M. Jones 已提交
820
virNetworkPtr           virNetworkDefineXML     (virConnectPtr conn,
821
                                                 const char *xmlDesc);
822 823 824 825

/*
 * Delete persistent network
 */
R
Richard W.M. Jones 已提交
826
int                     virNetworkUndefine      (virNetworkPtr network);
827 828 829 830

/*
 * Activate persistent network
 */
R
Richard W.M. Jones 已提交
831
int                     virNetworkCreate        (virNetworkPtr network);
832 833 834 835

/*
 * Network destroy/free
 */
R
Richard W.M. Jones 已提交
836
int                     virNetworkDestroy       (virNetworkPtr network);
837
int                     virNetworkRef           (virNetworkPtr network);
R
Richard W.M. Jones 已提交
838
int                     virNetworkFree          (virNetworkPtr network);
839 840

/*
841
 * Network information
842
 */
R
Richard W.M. Jones 已提交
843 844
const char*             virNetworkGetName       (virNetworkPtr network);
int                     virNetworkGetUUID       (virNetworkPtr network,
845
                                                 unsigned char *uuid);
R
Richard W.M. Jones 已提交
846
int                     virNetworkGetUUIDString (virNetworkPtr network,
847
                                                 char *buf);
R
Richard W.M. Jones 已提交
848
char *                  virNetworkGetXMLDesc    (virNetworkPtr network,
849
                                                 int flags);
R
Richard W.M. Jones 已提交
850
char *                  virNetworkGetBridgeName (virNetworkPtr network);
851

R
Richard W.M. Jones 已提交
852
int                     virNetworkGetAutostart  (virNetworkPtr network,
853
                                                 int *autostart);
R
Richard W.M. Jones 已提交
854
int                     virNetworkSetAutostart  (virNetworkPtr network,
855
                                                 int autostart);
856

857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 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 932 933 934 935 936 937 938 939 940 941 942 943

/**
 * virStoragePool:
 *
 * a virStoragePool is a private structure representing a storage pool
 */
typedef struct _virStoragePool virStoragePool;

/**
 * virStoragePoolPtr:
 *
 * a virStoragePoolPtr is pointer to a virStoragePool private structure, this is the
 * type used to reference a storage pool in the API.
 */
typedef virStoragePool *virStoragePoolPtr;


typedef enum {
  VIR_STORAGE_POOL_INACTIVE = 0, /* Not running */
  VIR_STORAGE_POOL_BUILDING = 1, /* Initializing pool, not available */
  VIR_STORAGE_POOL_RUNNING = 2,  /* Running normally */
  VIR_STORAGE_POOL_DEGRADED = 3, /* Running degraded */
} virStoragePoolState;


typedef enum {
  VIR_STORAGE_POOL_BUILD_NEW  = 0,   /* Regular build from scratch */
  VIR_STORAGE_POOL_BUILD_REPAIR = 1, /* Repair / reinitialize */
  VIR_STORAGE_POOL_BUILD_RESIZE = 2  /* Extend existing pool */
} virStoragePoolBuildFlags;

typedef enum {
  VIR_STORAGE_POOL_DELETE_NORMAL = 0, /* Delete metadata only    (fast) */
  VIR_STORAGE_POOL_DELETE_ZEROED = 1,  /* Clear all data to zeros (slow) */
} virStoragePoolDeleteFlags;

typedef struct _virStoragePoolInfo virStoragePoolInfo;

struct _virStoragePoolInfo {
  int state;                     /* virStoragePoolState flags */
  unsigned long long capacity;   /* Logical size bytes */
  unsigned long long allocation; /* Current allocation bytes */
  unsigned long long available;  /* Remaining free space bytes */
};

typedef virStoragePoolInfo *virStoragePoolInfoPtr;


/**
 * virStorageVol:
 *
 * a virStorageVol is a private structure representing a storage volume
 */
typedef struct _virStorageVol virStorageVol;

/**
 * virStorageVolPtr:
 *
 * a virStorageVolPtr is pointer to a virStorageVol private structure, this is the
 * type used to reference a storage volume in the API.
 */
typedef virStorageVol *virStorageVolPtr;


typedef enum {
  VIR_STORAGE_VOL_FILE = 0,     /* Regular file based volumes */
  VIR_STORAGE_VOL_BLOCK = 1,    /* Block based volumes */
} virStorageVolType;

typedef enum {
  VIR_STORAGE_VOL_DELETE_NORMAL = 0, /* Delete metadata only    (fast) */
  VIR_STORAGE_VOL_DELETE_ZEROED = 1,  /* Clear all data to zeros (slow) */
} virStorageVolDeleteFlags;

typedef struct _virStorageVolInfo virStorageVolInfo;

struct _virStorageVolInfo {
  int type;                      /* virStorageVolType flags */
  unsigned long long capacity;   /* Logical size bytes */
  unsigned long long allocation; /* Current allocation bytes */
};

typedef virStorageVolInfo *virStorageVolInfoPtr;

/*
 * Get connection from pool.
 */
R
Richard W.M. Jones 已提交
944
virConnectPtr           virStoragePoolGetConnect        (virStoragePoolPtr pool);
945 946 947 948

/*
 * List active storage pools
 */
R
Richard W.M. Jones 已提交
949 950
int                     virConnectNumOfStoragePools     (virConnectPtr conn);
int                     virConnectListStoragePools      (virConnectPtr conn,
951 952
                                                         char **const names,
                                                         int maxnames);
953 954 955 956

/*
 * List inactive storage pools
 */
R
Richard W.M. Jones 已提交
957 958
int                     virConnectNumOfDefinedStoragePools(virConnectPtr conn);
int                     virConnectListDefinedStoragePools(virConnectPtr conn,
959 960
                                                          char **const names,
                                                          int maxnames);
961

962 963 964 965 966 967 968 969
/*
 * Query a host for storage pools of a particular type
 */
char *                  virConnectFindStoragePoolSources(virConnectPtr conn,
                                                         const char *type,
                                                         const char *srcSpec,
                                                         unsigned int flags);

970 971 972
/*
 * Lookup pool by name or uuid
 */
R
Richard W.M. Jones 已提交
973
virStoragePoolPtr       virStoragePoolLookupByName      (virConnectPtr conn,
974
                                                         const char *name);
R
Richard W.M. Jones 已提交
975
virStoragePoolPtr       virStoragePoolLookupByUUID      (virConnectPtr conn,
976
                                                         const unsigned char *uuid);
R
Richard W.M. Jones 已提交
977
virStoragePoolPtr       virStoragePoolLookupByUUIDString(virConnectPtr conn,
978
                                                         const char *uuid);
R
Richard W.M. Jones 已提交
979
virStoragePoolPtr       virStoragePoolLookupByVolume    (virStorageVolPtr vol);
980 981 982 983

/*
 * Creating/destroying pools
 */
R
Richard W.M. Jones 已提交
984
virStoragePoolPtr       virStoragePoolCreateXML         (virConnectPtr conn,
985 986
                                                         const char *xmlDesc,
                                                         unsigned int flags);
R
Richard W.M. Jones 已提交
987
virStoragePoolPtr       virStoragePoolDefineXML         (virConnectPtr conn,
988 989
                                                         const char *xmlDesc,
                                                         unsigned int flags);
R
Richard W.M. Jones 已提交
990
int                     virStoragePoolBuild             (virStoragePoolPtr pool,
991
                                                         unsigned int flags);
R
Richard W.M. Jones 已提交
992 993
int                     virStoragePoolUndefine          (virStoragePoolPtr pool);
int                     virStoragePoolCreate            (virStoragePoolPtr pool,
994
                                                         unsigned int flags);
R
Richard W.M. Jones 已提交
995 996
int                     virStoragePoolDestroy           (virStoragePoolPtr pool);
int                     virStoragePoolDelete            (virStoragePoolPtr pool,
997
                                                         unsigned int flags);
998
int                     virStoragePoolRef               (virStoragePoolPtr pool);
R
Richard W.M. Jones 已提交
999 1000
int                     virStoragePoolFree              (virStoragePoolPtr pool);
int                     virStoragePoolRefresh           (virStoragePoolPtr pool,
1001
                                                         unsigned int flags);
1002 1003 1004 1005

/*
 * StoragePool information
 */
R
Richard W.M. Jones 已提交
1006 1007
const char*             virStoragePoolGetName           (virStoragePoolPtr pool);
int                     virStoragePoolGetUUID           (virStoragePoolPtr pool,
1008
                                                         unsigned char *uuid);
R
Richard W.M. Jones 已提交
1009
int                     virStoragePoolGetUUIDString     (virStoragePoolPtr pool,
1010
                                                         char *buf);
1011

R
Richard W.M. Jones 已提交
1012
int                     virStoragePoolGetInfo           (virStoragePoolPtr vol,
1013
                                                         virStoragePoolInfoPtr info);
1014

R
Richard W.M. Jones 已提交
1015
char *                  virStoragePoolGetXMLDesc        (virStoragePoolPtr pool,
1016
                                                         unsigned int flags);
1017

R
Richard W.M. Jones 已提交
1018
int                     virStoragePoolGetAutostart      (virStoragePoolPtr pool,
1019
                                                         int *autostart);
R
Richard W.M. Jones 已提交
1020
int                     virStoragePoolSetAutostart      (virStoragePoolPtr pool,
1021
                                                         int autostart);
1022 1023 1024 1025

/*
 * List/lookup storage volumes within a pool
 */
R
Richard W.M. Jones 已提交
1026 1027
int                     virStoragePoolNumOfVolumes      (virStoragePoolPtr pool);
int                     virStoragePoolListVolumes       (virStoragePoolPtr pool,
1028 1029
                                                         char **const names,
                                                         int maxnames);
1030

R
Richard W.M. Jones 已提交
1031
virConnectPtr           virStorageVolGetConnect         (virStorageVolPtr vol);
1032 1033 1034 1035

/*
 * Lookup volumes based on various attributes
 */
R
Richard W.M. Jones 已提交
1036
virStorageVolPtr        virStorageVolLookupByName       (virStoragePoolPtr pool,
1037
                                                         const char *name);
R
Richard W.M. Jones 已提交
1038
virStorageVolPtr        virStorageVolLookupByKey        (virConnectPtr conn,
1039
                                                         const char *key);
R
Richard W.M. Jones 已提交
1040
virStorageVolPtr        virStorageVolLookupByPath       (virConnectPtr conn,
1041
                                                         const char *path);
1042 1043


R
Richard W.M. Jones 已提交
1044 1045
const char*             virStorageVolGetName            (virStorageVolPtr vol);
const char*             virStorageVolGetKey             (virStorageVolPtr vol);
1046

R
Richard W.M. Jones 已提交
1047
virStorageVolPtr        virStorageVolCreateXML          (virStoragePoolPtr pool,
1048 1049
                                                         const char *xmldesc,
                                                         unsigned int flags);
R
Richard W.M. Jones 已提交
1050
int                     virStorageVolDelete             (virStorageVolPtr vol,
1051
                                                         unsigned int flags);
1052
int                     virStorageVolRef                (virStorageVolPtr vol);
R
Richard W.M. Jones 已提交
1053
int                     virStorageVolFree               (virStorageVolPtr vol);
1054

R
Richard W.M. Jones 已提交
1055
int                     virStorageVolGetInfo            (virStorageVolPtr vol,
1056
                                                         virStorageVolInfoPtr info);
R
Richard W.M. Jones 已提交
1057
char *                  virStorageVolGetXMLDesc         (virStorageVolPtr pool,
1058
                                                         unsigned int flags);
1059

R
Richard W.M. Jones 已提交
1060
char *                  virStorageVolGetPath            (virStorageVolPtr vol);
1061

1062 1063 1064 1065 1066 1067
/*
 * Deprecated calls
 */
virDomainPtr            virDomainCreateLinux    (virConnectPtr conn,
                                                 const char *xmlDesc,
                                                 unsigned int flags);
1068

1069 1070 1071 1072 1073 1074 1075 1076 1077 1078 1079 1080 1081 1082 1083 1084 1085 1086 1087 1088 1089 1090 1091 1092 1093 1094 1095 1096 1097 1098 1099 1100 1101 1102 1103 1104 1105 1106 1107 1108 1109 1110 1111 1112 1113 1114 1115 1116 1117 1118 1119
/*
 * Host device enumeration
 */

/**
 * virNodeDevice:
 *
 * A virNodeDevice contains a node (host) device details.
 */

typedef struct _virNodeDevice virNodeDevice;

/**
 * virNodeDevicePtr:
 *
 * A virNodeDevicePtr is a pointer to a virNodeDevice structure.  Get
 * one via virNodeDeviceLookupByKey, virNodeDeviceLookupByName, or
 * virNodeDeviceCreate.  Be sure to Call virNodeDeviceFree when done
 * using a virNodeDevicePtr obtained from any of the above functions to
 * avoid leaking memory.
 */

typedef virNodeDevice *virNodeDevicePtr;


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

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

virNodeDevicePtr        virNodeDeviceLookupByName (virConnectPtr conn,
                                                   const char *name);

const char *            virNodeDeviceGetName     (virNodeDevicePtr dev);

const char *            virNodeDeviceGetParent   (virNodeDevicePtr dev);

int                     virNodeDeviceNumOfCaps   (virNodeDevicePtr dev);

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

char *                  virNodeDeviceGetXMLDesc (virNodeDevicePtr dev,
                                                 unsigned int flags);

1120
int                     virNodeDeviceRef        (virNodeDevicePtr dev);
1121 1122
int                     virNodeDeviceFree       (virNodeDevicePtr dev);

1123 1124 1125 1126
int                     virNodeDeviceDettach    (virNodeDevicePtr dev);
int                     virNodeDeviceReAttach   (virNodeDevicePtr dev);
int                     virNodeDeviceReset      (virNodeDevicePtr dev);

1127 1128 1129 1130 1131 1132
virNodeDevicePtr        virNodeDeviceCreateXML  (virConnectPtr conn,
                                                 const char *xmlDesc,
                                                 unsigned int flags);

int                     virNodeDeviceDestroy    (virNodeDevicePtr dev);

1133 1134 1135 1136 1137 1138 1139 1140 1141 1142
/*
 * Domain Event Notification
 */

/**
 * virDomainEventType:
 *
 * a virDomainEventType is emitted during domain lifecycle events
 */
typedef enum {
1143 1144
      VIR_DOMAIN_EVENT_DEFINED = 0,
      VIR_DOMAIN_EVENT_UNDEFINED = 1,
1145 1146 1147 1148
      VIR_DOMAIN_EVENT_STARTED = 2,
      VIR_DOMAIN_EVENT_SUSPENDED = 3,
      VIR_DOMAIN_EVENT_RESUMED = 4,
      VIR_DOMAIN_EVENT_STOPPED = 5,
1149 1150
} virDomainEventType;

1151 1152 1153 1154 1155 1156 1157 1158 1159 1160 1161 1162 1163 1164 1165 1166 1167 1168 1169 1170 1171 1172 1173 1174 1175 1176 1177 1178 1179 1180 1181 1182 1183 1184 1185 1186 1187 1188 1189 1190 1191 1192 1193 1194 1195 1196 1197 1198 1199 1200 1201 1202 1203 1204 1205 1206 1207 1208 1209 1210 1211 1212 1213 1214 1215
/**
 * virDomainEventDefinedDetailType:
 *
 * Details on the caused of the 'defined' lifecycle event
 */
typedef enum {
    VIR_DOMAIN_EVENT_DEFINED_ADDED = 0,     /* Newly created config file */
    VIR_DOMAIN_EVENT_DEFINED_UPDATED = 1,   /* Changed config file */
} virDomainEventDefinedDetailType;

/**
 * virDomainEventUndefinedDetailType:
 *
 * Details on the caused of the 'undefined' lifecycle event
 */
typedef enum {
    VIR_DOMAIN_EVENT_UNDEFINED_REMOVED = 0, /* Deleted the config file */
} virDomainEventUndefinedDetailType;

/**
 * virDomainEventStartedDetailType:
 *
 * Details on the caused of the 'started' lifecycle event
 */
typedef enum {
    VIR_DOMAIN_EVENT_STARTED_BOOTED = 0,   /* Normal startup from boot */
    VIR_DOMAIN_EVENT_STARTED_MIGRATED = 1, /* Incoming migration from another host */
    VIR_DOMAIN_EVENT_STARTED_RESTORED = 2, /* Restored from a state file */
} virDomainEventStartedDetailType;

/**
 * virDomainEventSuspendedDetailType:
 *
 * Details on the caused of the 'suspended' lifecycle event
 */
typedef enum {
    VIR_DOMAIN_EVENT_SUSPENDED_PAUSED = 0,   /* Normal suspend due to admin pause */
    VIR_DOMAIN_EVENT_SUSPENDED_MIGRATED = 1, /* Suspended for offline migration */
} virDomainEventSuspendedDetailType;

/**
 * virDomainEventResumedDetailType:
 *
 * Details on the caused of the 'resumed' lifecycle event
 */
typedef enum {
    VIR_DOMAIN_EVENT_RESUMED_UNPAUSED = 0,   /* Normal resume due to admin unpause */
    VIR_DOMAIN_EVENT_RESUMED_MIGRATED = 1,   /* Resumed for completion of migration */
} virDomainEventResumedDetailType;

/**
 * virDomainEventStoppedDetailType:
 *
 * Details on the caused of the 'stopped' lifecycle event
 */
typedef enum {
    VIR_DOMAIN_EVENT_STOPPED_SHUTDOWN = 0,  /* Normal shutdown */
    VIR_DOMAIN_EVENT_STOPPED_DESTROYED = 1, /* Forced poweroff from host */
    VIR_DOMAIN_EVENT_STOPPED_CRASHED = 2,   /* Guest crashed */
    VIR_DOMAIN_EVENT_STOPPED_MIGRATED = 3,  /* Migrated off to another host */
    VIR_DOMAIN_EVENT_STOPPED_SAVED = 4,     /* Saved to a state file */
    VIR_DOMAIN_EVENT_STOPPED_FAILED = 5,    /* Host emulator/mgmt failed */
} virDomainEventStoppedDetailType;


1216 1217 1218 1219 1220
/**
 * virConnectDomainEventCallback:
 * @conn: virConnect connection
 * @dom: The domain on which the event occured
 * @event: The specfic virDomainEventType which occured
1221
 * @detail: event specific detail information
1222 1223
 * @opaque: opaque user data
 *
D
Daniel P. Berrange 已提交
1224
 * A callback function to be registered, and called when a domain event occurs
1225 1226 1227 1228
 */
typedef int (*virConnectDomainEventCallback)(virConnectPtr conn,
                                             virDomainPtr dom,
                                             int event,
1229
                                             int detail,
1230 1231
                                             void *opaque);

1232 1233
typedef void (*virFreeCallback)(void *opaque);

1234 1235
int virConnectDomainEventRegister(virConnectPtr conn,
                                  virConnectDomainEventCallback cb,
1236 1237
                                  void *opaque,
                                  virFreeCallback freecb);
1238 1239 1240 1241 1242 1243 1244 1245 1246 1247 1248 1249 1250 1251 1252 1253 1254 1255 1256 1257 1258 1259 1260 1261 1262

int virConnectDomainEventDeregister(virConnectPtr conn,
                                    virConnectDomainEventCallback cb);

/*
 * Events Implementation
 */

/**
 * virEventHandleType:
 *
 * a virEventHandleType is used similar to POLLxxx FD events, but is specific
 * to libvirt. A client app must translate to, and from POLL events when using
 * this construct.
 */
typedef enum {
    VIR_EVENT_HANDLE_READABLE  = (1 << 0),
    VIR_EVENT_HANDLE_WRITABLE  = (1 << 1),
    VIR_EVENT_HANDLE_ERROR     = (1 << 2),
    VIR_EVENT_HANDLE_HANGUP    = (1 << 3),
} virEventHandleType;

/**
 * virEventHandleCallback:
 *
1263
 * @watch: watch on which the event occurred
1264 1265 1266 1267
 * @fd: file handle on which the event occurred
 * @events: bitset of events from virEventHandleType constants
 * @opaque: user data registered with handle
 *
1268 1269
 * Callback for receiving file handle events. The callback will
 * be invoked once for each event which is pending.
1270
 */
1271
typedef void (*virEventHandleCallback)(int watch, int fd, int events, void *opaque);
1272 1273 1274 1275 1276

/**
 * virEventAddHandleFunc:
 * @fd: file descriptor to listen on
 * @event: bitset of events on which to fire the callback
1277
 * @cb: the callback to be called when an event occurrs
1278
 * @opaque: user data to pass to the callback
1279
 * @ff: the callback invoked to free opaque data blob
1280 1281
 *
 * Part of the EventImpl, this callback Adds a file handle callback to
1282 1283 1284
 * listen for specific events. The same file handle can be registered
 * multiple times provided the requested event sets are non-overlapping
 *
1285 1286 1287 1288
 * If the opaque user data requires free'ing when the handle
 * is unregistered, then a 2nd callback can be supplied for
 * this purpose.
 *
1289 1290
 * Returns a handle watch number to be used for updating
 * and unregistering for events
1291 1292
 */
typedef int (*virEventAddHandleFunc)(int fd, int event,
1293 1294 1295
                                     virEventHandleCallback cb,
                                     void *opaque,
                                     virFreeCallback ff);
1296 1297 1298

/**
 * virEventUpdateHandleFunc:
1299
 * @watch: file descriptor watch to modify
1300 1301 1302 1303 1304
 * @event: new events to listen on
 *
 * Part of the EventImpl, this user-provided callback is notified when
 * events to listen on change
 */
1305
typedef void (*virEventUpdateHandleFunc)(int watch, int event);
1306 1307 1308

/**
 * virEventRemoveHandleFunc:
1309
 * @watch: file descriptor watch to stop listening on
1310 1311
 *
 * Part of the EventImpl, this user-provided callback is notified when
1312 1313 1314 1315 1316
 * an fd is no longer being listened on.
 *
 * If a virEventHandleFreeFunc was supplied when the handle was
 * registered, it will be invoked some time during, or after this
 * function call, when it is safe to release the user data.
1317
 */
1318
typedef int (*virEventRemoveHandleFunc)(int watch);
1319 1320 1321 1322 1323 1324 1325 1326 1327 1328 1329 1330 1331 1332 1333 1334

/**
 * virEventTimeoutCallback:
 *
 * @timer: timer id emitting the event
 * @opaque: user data registered with handle
 *
 * callback for receiving timer events
 */
typedef void (*virEventTimeoutCallback)(int timer, void *opaque);

/**
 * virEventAddTimeoutFunc:
 * @timeout: The timeout to monitor
 * @cb: the callback to call when timeout has expired
 * @opaque: user data to pass to the callback
1335
 * @ff: the callback invoked to free opaque data blob
1336 1337 1338 1339
 *
 * Part of the EventImpl, this user-defined callback handles adding an
 * event timeout.
 *
1340 1341 1342 1343
 * If the opaque user data requires free'ing when the handle
 * is unregistered, then a 2nd callback can be supplied for
 * this purpose.
 *
1344 1345
 * Returns a timer value
 */
1346 1347 1348 1349
typedef int (*virEventAddTimeoutFunc)(int timeout,
                                      virEventTimeoutCallback cb,
                                      void *opaque,
                                      virFreeCallback ff);
1350 1351 1352 1353 1354 1355 1356 1357 1358 1359 1360 1361 1362 1363 1364 1365 1366

/**
 * virEventUpdateTimeoutFunc:
 * @timer: the timer to modify
 * @timeout: the new timeout value
 *
 * Part of the EventImpl, this user-defined callback updates an
 * event timeout.
 */
typedef void (*virEventUpdateTimeoutFunc)(int timer, int timeout);

/**
 * virEventRemoveTimeoutFunc:
 * @timer: the timer to remove
 *
 * Part of the EventImpl, this user-defined callback removes a timer
 *
1367 1368 1369 1370
 * If a virEventTimeoutFreeFunc was supplied when the handle was
 * registered, it will be invoked some time during, or after this
 * function call, when it is safe to release the user data.
 *
1371 1372 1373 1374 1375 1376 1377 1378 1379 1380
 * Returns 0 on success, -1 on failure
 */
typedef int (*virEventRemoveTimeoutFunc)(int timer);

void virEventRegisterImpl(virEventAddHandleFunc addHandle,
                          virEventUpdateHandleFunc updateHandle,
                          virEventRemoveHandleFunc removeHandle,
                          virEventAddTimeoutFunc addTimeout,
                          virEventUpdateTimeoutFunc updateTimeout,
                          virEventRemoveTimeoutFunc removeTimeout);
1381 1382 1383 1384 1385
#ifdef __cplusplus
}
#endif

#endif /* __VIR_VIRLIB_H__ */