libvirt.h 53.5 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 7001
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 595 596 597 598 599 600 601 602 603

char *                  virConnectDomainXMLFromNative(virConnectPtr conn,
                                                      const char *nativeFormat,
                                                      const char *nativeConfig,
                                                      unsigned int flags);
char *                  virConnectDomainXMLToNative(virConnectPtr conn,
                                                    const char *nativeFormat,
                                                    const char *domainXml,
                                                    unsigned int flags);

604
int                     virDomainBlockStats     (virDomainPtr dom,
605 606 607
                                                 const char *path,
                                                 virDomainBlockStatsPtr stats,
                                                 size_t size);
608
int                     virDomainInterfaceStats (virDomainPtr dom,
609 610 611
                                                 const char *path,
                                                 virDomainInterfaceStatsPtr stats,
                                                 size_t size);
R
Richard W.M. Jones 已提交
612 613 614 615 616 617
int                     virDomainBlockPeek (virDomainPtr dom,
                                            const char *path,
                                            unsigned long long offset,
                                            size_t size,
                                            void *buffer,
                                            unsigned int flags);
618

R
Richard W.M. Jones 已提交
619 620 621
/* Memory peeking flags. */
typedef enum {
  VIR_MEMORY_VIRTUAL              = 1, /* addresses are virtual addresses */
622
  VIR_MEMORY_PHYSICAL             = 2, /* addresses are physical addresses */
R
Richard W.M. Jones 已提交
623 624 625 626 627 628 629 630
} virDomainMemoryFlags;

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

631 632 633
/*
 * defined but not running domains
 */
R
Richard W.M. Jones 已提交
634
virDomainPtr            virDomainDefineXML      (virConnectPtr conn,
635
                                                 const char *xml);
R
Richard W.M. Jones 已提交
636
int                     virDomainUndefine       (virDomainPtr domain);
637
int                     virConnectNumOfDefinedDomains  (virConnectPtr conn);
R
Richard W.M. Jones 已提交
638
int                     virConnectListDefinedDomains (virConnectPtr conn,
639 640
                                                 char **const names,
                                                 int maxnames);
R
Richard W.M. Jones 已提交
641
int                     virDomainCreate         (virDomainPtr domain);
642

R
Richard W.M. Jones 已提交
643
int                     virDomainGetAutostart   (virDomainPtr domain,
644
                                                 int *autostart);
R
Richard W.M. Jones 已提交
645
int                     virDomainSetAutostart   (virDomainPtr domain,
646
                                                 int autostart);
647

648 649 650 651 652
/**
 * virVcpuInfo: structure for information about a virtual CPU in a domain.
 */

typedef enum {
R
Richard W.M. Jones 已提交
653 654 655
    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 */
656 657 658 659
} virVcpuState;

typedef struct _virVcpuInfo virVcpuInfo;
struct _virVcpuInfo {
R
Richard W.M. Jones 已提交
660 661
    unsigned int number;        /* virtual CPU number */
    int state;                  /* value from virVcpuState */
662
    unsigned long long cpuTime; /* CPU time used, in nanoseconds */
R
Richard W.M. Jones 已提交
663
    int cpu;                    /* real CPU number, or -1 if offline */
664 665 666
};
typedef virVcpuInfo *virVcpuInfoPtr;

R
Richard W.M. Jones 已提交
667
int                     virDomainSetVcpus       (virDomainPtr domain,
668
                                                 unsigned int nvcpus);
669

R
Richard W.M. Jones 已提交
670
int                     virDomainPinVcpu        (virDomainPtr domain,
671 672 673
                                                 unsigned int vcpu,
                                                 unsigned char *cpumap,
                                                 int maplen);
674 675 676 677 678 679

/**
 * VIR_USE_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 set the bit (CPU usable) of the related cpu in cpumap.
 */

R
Richard W.M. Jones 已提交
684
#define VIR_USE_CPU(cpumap,cpu) (cpumap[(cpu)/8] |= (1<<((cpu)%8)))
685 686 687 688 689 690

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

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

697
/**
698
 * VIR_CPU_MAPLEN:
699 700
 * @cpu: number of physical CPUs
 *
701
 * This macro is to be used in conjunction with virDomainPinVcpu() API.
702 703 704 705 706 707 708
 * 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 已提交
709
int                     virDomainGetVcpus       (virDomainPtr domain,
710 711 712 713
                                                 virVcpuInfoPtr info,
                                                 int maxinfo,
                                                 unsigned char *cpumaps,
                                                 int maplen);
714 715 716 717 718 719 720 721

/**
 * 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
 *
722
 * This macro is to be used in conjunction with virDomainGetVcpus() API.
723 724 725 726 727
 * 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) \
728
        (cpumaps[((vcpu)*(maplen))+((cpu)/8)] & (1<<((cpu)%8)))
729 730 731 732 733 734 735

/**
 * 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 已提交
736
 *      This cpumap must be previously allocated by the caller
737 738
 *      (ie: malloc(maplen))
 *
739
 * This macro is to be used in conjunction with virDomainGetVcpus() and
740 741 742 743 744
 * 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) \
745
        memcpy(cpumap, &(cpumaps[(vcpu)*(maplen)]), (maplen))
746 747 748 749 750 751 752 753


/**
 * 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
 *
754
 * This macro is to be used in conjunction with virDomainGetVcpus() and
755 756 757
 * virDomainPinVcpu() APIs. VIR_GET_CPUMAP macro returns a pointer to the
 * cpumap of the specified vcpu from cpumaps array.
 */
R
Richard W.M. Jones 已提交
758
#define VIR_GET_CPUMAP(cpumaps,maplen,vcpu)     &(cpumaps[(vcpu)*(maplen)])
759

760 761
int virDomainAttachDevice(virDomainPtr domain, const char *xml);
int virDomainDetachDevice(virDomainPtr domain, const char *xml);
762

763 764 765 766
/*
 * NUMA support
 */

R
Richard W.M. Jones 已提交
767
int                      virNodeGetCellsFreeMemory(virConnectPtr conn,
768 769 770
                                                   unsigned long long *freeMems,
                                                   int startCell,
                                                   int maxCells);
771

772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790
/*
 * 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;

791 792 793
/*
 * Get connection from network.
 */
R
Richard W.M. Jones 已提交
794
virConnectPtr           virNetworkGetConnect    (virNetworkPtr network);
795

796 797 798
/*
 * List active networks
 */
R
Richard W.M. Jones 已提交
799 800
int                     virConnectNumOfNetworks (virConnectPtr conn);
int                     virConnectListNetworks  (virConnectPtr conn,
801 802
                                                 char **const names,
                                                 int maxnames);
803 804 805 806

/*
 * List inactive networks
 */
R
Richard W.M. Jones 已提交
807 808
int                     virConnectNumOfDefinedNetworks  (virConnectPtr conn);
int                     virConnectListDefinedNetworks   (virConnectPtr conn,
809 810
                                                         char **const names,
                                                         int maxnames);
811 812 813 814

/*
 * Lookup network by name or uuid
 */
R
Richard W.M. Jones 已提交
815
virNetworkPtr           virNetworkLookupByName          (virConnectPtr conn,
816
                                                         const char *name);
R
Richard W.M. Jones 已提交
817
virNetworkPtr           virNetworkLookupByUUID          (virConnectPtr conn,
818
                                                         const unsigned char *uuid);
R
Richard W.M. Jones 已提交
819
virNetworkPtr           virNetworkLookupByUUIDString    (virConnectPtr conn,
820
                                                         const char *uuid);
821 822 823 824

/*
 * Create active transient network
 */
R
Richard W.M. Jones 已提交
825
virNetworkPtr           virNetworkCreateXML     (virConnectPtr conn,
826
                                                 const char *xmlDesc);
827 828 829 830

/*
 * Define inactive persistent network
 */
R
Richard W.M. Jones 已提交
831
virNetworkPtr           virNetworkDefineXML     (virConnectPtr conn,
832
                                                 const char *xmlDesc);
833 834 835 836

/*
 * Delete persistent network
 */
R
Richard W.M. Jones 已提交
837
int                     virNetworkUndefine      (virNetworkPtr network);
838 839 840 841

/*
 * Activate persistent network
 */
R
Richard W.M. Jones 已提交
842
int                     virNetworkCreate        (virNetworkPtr network);
843 844 845 846

/*
 * Network destroy/free
 */
R
Richard W.M. Jones 已提交
847
int                     virNetworkDestroy       (virNetworkPtr network);
848
int                     virNetworkRef           (virNetworkPtr network);
R
Richard W.M. Jones 已提交
849
int                     virNetworkFree          (virNetworkPtr network);
850 851

/*
852
 * Network information
853
 */
R
Richard W.M. Jones 已提交
854 855
const char*             virNetworkGetName       (virNetworkPtr network);
int                     virNetworkGetUUID       (virNetworkPtr network,
856
                                                 unsigned char *uuid);
R
Richard W.M. Jones 已提交
857
int                     virNetworkGetUUIDString (virNetworkPtr network,
858
                                                 char *buf);
R
Richard W.M. Jones 已提交
859
char *                  virNetworkGetXMLDesc    (virNetworkPtr network,
860
                                                 int flags);
R
Richard W.M. Jones 已提交
861
char *                  virNetworkGetBridgeName (virNetworkPtr network);
862

R
Richard W.M. Jones 已提交
863
int                     virNetworkGetAutostart  (virNetworkPtr network,
864
                                                 int *autostart);
R
Richard W.M. Jones 已提交
865
int                     virNetworkSetAutostart  (virNetworkPtr network,
866
                                                 int autostart);
867

D
Daniel Veillard 已提交
868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886
/*
 * Physical host interface configuration API
 */

/**
 * virInterface:
 *
 * a virInterface is a private structure representing a virtual interface.
 */
typedef struct _virInterface virInterface;

/**
 * virInterfacePtr:
 *
 * a virInterfacePtr is pointer to a virInterface private structure, this is the
 * type used to reference a virtual interface in the API.
 */
typedef virInterface *virInterfacePtr;

887
virConnectPtr           virInterfaceGetConnect    (virInterfacePtr iface);
D
Daniel Veillard 已提交
888 889 890 891 892 893

int                     virConnectNumOfInterfaces (virConnectPtr conn);
int                     virConnectListInterfaces  (virConnectPtr conn,
                                                   char **const names,
                                                   int maxnames);

894 895 896 897 898
int                     virConnectNumOfDefinedInterfaces (virConnectPtr conn);
int                     virConnectListDefinedInterfaces  (virConnectPtr conn,
                                                          char **const names,
                                                          int maxnames);

D
Daniel Veillard 已提交
899 900 901 902 903
virInterfacePtr         virInterfaceLookupByName  (virConnectPtr conn,
                                                   const char *name);
virInterfacePtr         virInterfaceLookupByMACString (virConnectPtr conn,
                                                       const char *mac);

904 905
const char*             virInterfaceGetName       (virInterfacePtr iface);
const char*             virInterfaceGetMACString  (virInterfacePtr iface);
D
Daniel Veillard 已提交
906

907
char *                  virInterfaceGetXMLDesc    (virInterfacePtr iface,
D
Daniel Veillard 已提交
908 909 910 911 912
                                                   unsigned int flags);
virInterfacePtr         virInterfaceDefineXML     (virConnectPtr conn,
                                                   const char *xmlDesc,
                                                   unsigned int flags);

913
int                     virInterfaceUndefine      (virInterfacePtr iface);
D
Daniel Veillard 已提交
914

915
int                     virInterfaceCreate        (virInterfacePtr iface,
D
Daniel Veillard 已提交
916 917
                                                   unsigned int flags);

918
int                     virInterfaceDestroy       (virInterfacePtr iface,
D
Daniel Veillard 已提交
919 920
                                                   unsigned int flags);

921 922
int                     virInterfaceRef           (virInterfacePtr iface);
int                     virInterfaceFree          (virInterfacePtr iface);
923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 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 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009

/**
 * 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 已提交
1010
virConnectPtr           virStoragePoolGetConnect        (virStoragePoolPtr pool);
1011 1012 1013 1014

/*
 * List active storage pools
 */
R
Richard W.M. Jones 已提交
1015 1016
int                     virConnectNumOfStoragePools     (virConnectPtr conn);
int                     virConnectListStoragePools      (virConnectPtr conn,
1017 1018
                                                         char **const names,
                                                         int maxnames);
1019 1020 1021 1022

/*
 * List inactive storage pools
 */
R
Richard W.M. Jones 已提交
1023 1024
int                     virConnectNumOfDefinedStoragePools(virConnectPtr conn);
int                     virConnectListDefinedStoragePools(virConnectPtr conn,
1025 1026
                                                          char **const names,
                                                          int maxnames);
1027

1028 1029 1030 1031 1032 1033 1034 1035
/*
 * Query a host for storage pools of a particular type
 */
char *                  virConnectFindStoragePoolSources(virConnectPtr conn,
                                                         const char *type,
                                                         const char *srcSpec,
                                                         unsigned int flags);

1036 1037 1038
/*
 * Lookup pool by name or uuid
 */
R
Richard W.M. Jones 已提交
1039
virStoragePoolPtr       virStoragePoolLookupByName      (virConnectPtr conn,
1040
                                                         const char *name);
R
Richard W.M. Jones 已提交
1041
virStoragePoolPtr       virStoragePoolLookupByUUID      (virConnectPtr conn,
1042
                                                         const unsigned char *uuid);
R
Richard W.M. Jones 已提交
1043
virStoragePoolPtr       virStoragePoolLookupByUUIDString(virConnectPtr conn,
1044
                                                         const char *uuid);
R
Richard W.M. Jones 已提交
1045
virStoragePoolPtr       virStoragePoolLookupByVolume    (virStorageVolPtr vol);
1046 1047 1048 1049

/*
 * Creating/destroying pools
 */
R
Richard W.M. Jones 已提交
1050
virStoragePoolPtr       virStoragePoolCreateXML         (virConnectPtr conn,
1051 1052
                                                         const char *xmlDesc,
                                                         unsigned int flags);
R
Richard W.M. Jones 已提交
1053
virStoragePoolPtr       virStoragePoolDefineXML         (virConnectPtr conn,
1054 1055
                                                         const char *xmlDesc,
                                                         unsigned int flags);
R
Richard W.M. Jones 已提交
1056
int                     virStoragePoolBuild             (virStoragePoolPtr pool,
1057
                                                         unsigned int flags);
R
Richard W.M. Jones 已提交
1058 1059
int                     virStoragePoolUndefine          (virStoragePoolPtr pool);
int                     virStoragePoolCreate            (virStoragePoolPtr pool,
1060
                                                         unsigned int flags);
R
Richard W.M. Jones 已提交
1061 1062
int                     virStoragePoolDestroy           (virStoragePoolPtr pool);
int                     virStoragePoolDelete            (virStoragePoolPtr pool,
1063
                                                         unsigned int flags);
1064
int                     virStoragePoolRef               (virStoragePoolPtr pool);
R
Richard W.M. Jones 已提交
1065 1066
int                     virStoragePoolFree              (virStoragePoolPtr pool);
int                     virStoragePoolRefresh           (virStoragePoolPtr pool,
1067
                                                         unsigned int flags);
1068 1069 1070 1071

/*
 * StoragePool information
 */
R
Richard W.M. Jones 已提交
1072 1073
const char*             virStoragePoolGetName           (virStoragePoolPtr pool);
int                     virStoragePoolGetUUID           (virStoragePoolPtr pool,
1074
                                                         unsigned char *uuid);
R
Richard W.M. Jones 已提交
1075
int                     virStoragePoolGetUUIDString     (virStoragePoolPtr pool,
1076
                                                         char *buf);
1077

R
Richard W.M. Jones 已提交
1078
int                     virStoragePoolGetInfo           (virStoragePoolPtr vol,
1079
                                                         virStoragePoolInfoPtr info);
1080

R
Richard W.M. Jones 已提交
1081
char *                  virStoragePoolGetXMLDesc        (virStoragePoolPtr pool,
1082
                                                         unsigned int flags);
1083

R
Richard W.M. Jones 已提交
1084
int                     virStoragePoolGetAutostart      (virStoragePoolPtr pool,
1085
                                                         int *autostart);
R
Richard W.M. Jones 已提交
1086
int                     virStoragePoolSetAutostart      (virStoragePoolPtr pool,
1087
                                                         int autostart);
1088 1089 1090 1091

/*
 * List/lookup storage volumes within a pool
 */
R
Richard W.M. Jones 已提交
1092 1093
int                     virStoragePoolNumOfVolumes      (virStoragePoolPtr pool);
int                     virStoragePoolListVolumes       (virStoragePoolPtr pool,
1094 1095
                                                         char **const names,
                                                         int maxnames);
1096

R
Richard W.M. Jones 已提交
1097
virConnectPtr           virStorageVolGetConnect         (virStorageVolPtr vol);
1098 1099 1100 1101

/*
 * Lookup volumes based on various attributes
 */
R
Richard W.M. Jones 已提交
1102
virStorageVolPtr        virStorageVolLookupByName       (virStoragePoolPtr pool,
1103
                                                         const char *name);
R
Richard W.M. Jones 已提交
1104
virStorageVolPtr        virStorageVolLookupByKey        (virConnectPtr conn,
1105
                                                         const char *key);
R
Richard W.M. Jones 已提交
1106
virStorageVolPtr        virStorageVolLookupByPath       (virConnectPtr conn,
1107
                                                         const char *path);
1108 1109


R
Richard W.M. Jones 已提交
1110 1111
const char*             virStorageVolGetName            (virStorageVolPtr vol);
const char*             virStorageVolGetKey             (virStorageVolPtr vol);
1112

R
Richard W.M. Jones 已提交
1113
virStorageVolPtr        virStorageVolCreateXML          (virStoragePoolPtr pool,
1114 1115
                                                         const char *xmldesc,
                                                         unsigned int flags);
1116 1117 1118 1119
virStorageVolPtr        virStorageVolCreateXMLFrom      (virStoragePoolPtr pool,
                                                         const char *xmldesc,
                                                         virStorageVolPtr clonevol,
                                                         unsigned int flags);
R
Richard W.M. Jones 已提交
1120
int                     virStorageVolDelete             (virStorageVolPtr vol,
1121
                                                         unsigned int flags);
1122
int                     virStorageVolRef                (virStorageVolPtr vol);
R
Richard W.M. Jones 已提交
1123
int                     virStorageVolFree               (virStorageVolPtr vol);
1124

R
Richard W.M. Jones 已提交
1125
int                     virStorageVolGetInfo            (virStorageVolPtr vol,
1126
                                                         virStorageVolInfoPtr info);
R
Richard W.M. Jones 已提交
1127
char *                  virStorageVolGetXMLDesc         (virStorageVolPtr pool,
1128
                                                         unsigned int flags);
1129

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

1132 1133 1134 1135 1136 1137
/*
 * Deprecated calls
 */
virDomainPtr            virDomainCreateLinux    (virConnectPtr conn,
                                                 const char *xmlDesc,
                                                 unsigned int flags);
1138

1139 1140 1141 1142 1143 1144 1145 1146 1147 1148 1149 1150 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
/*
 * 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);

1190
int                     virNodeDeviceRef        (virNodeDevicePtr dev);
1191 1192
int                     virNodeDeviceFree       (virNodeDevicePtr dev);

1193 1194 1195 1196
int                     virNodeDeviceDettach    (virNodeDevicePtr dev);
int                     virNodeDeviceReAttach   (virNodeDevicePtr dev);
int                     virNodeDeviceReset      (virNodeDevicePtr dev);

1197 1198 1199 1200 1201 1202
virNodeDevicePtr        virNodeDeviceCreateXML  (virConnectPtr conn,
                                                 const char *xmlDesc,
                                                 unsigned int flags);

int                     virNodeDeviceDestroy    (virNodeDevicePtr dev);

1203 1204 1205 1206 1207 1208 1209 1210 1211 1212
/*
 * Domain Event Notification
 */

/**
 * virDomainEventType:
 *
 * a virDomainEventType is emitted during domain lifecycle events
 */
typedef enum {
1213 1214
      VIR_DOMAIN_EVENT_DEFINED = 0,
      VIR_DOMAIN_EVENT_UNDEFINED = 1,
1215 1216 1217 1218
      VIR_DOMAIN_EVENT_STARTED = 2,
      VIR_DOMAIN_EVENT_SUSPENDED = 3,
      VIR_DOMAIN_EVENT_RESUMED = 4,
      VIR_DOMAIN_EVENT_STOPPED = 5,
1219 1220
} virDomainEventType;

1221 1222 1223 1224 1225 1226 1227 1228 1229 1230 1231 1232 1233 1234 1235 1236 1237 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 1263 1264 1265 1266 1267 1268 1269 1270 1271 1272 1273 1274 1275 1276 1277 1278 1279 1280 1281 1282 1283 1284 1285
/**
 * 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;


1286 1287 1288 1289 1290
/**
 * virConnectDomainEventCallback:
 * @conn: virConnect connection
 * @dom: The domain on which the event occured
 * @event: The specfic virDomainEventType which occured
1291
 * @detail: event specific detail information
1292 1293
 * @opaque: opaque user data
 *
D
Daniel P. Berrange 已提交
1294
 * A callback function to be registered, and called when a domain event occurs
1295 1296 1297 1298
 */
typedef int (*virConnectDomainEventCallback)(virConnectPtr conn,
                                             virDomainPtr dom,
                                             int event,
1299
                                             int detail,
1300 1301
                                             void *opaque);

1302 1303
typedef void (*virFreeCallback)(void *opaque);

1304 1305
int virConnectDomainEventRegister(virConnectPtr conn,
                                  virConnectDomainEventCallback cb,
1306 1307
                                  void *opaque,
                                  virFreeCallback freecb);
1308 1309 1310 1311 1312 1313 1314 1315 1316 1317 1318 1319 1320 1321 1322 1323 1324 1325 1326 1327 1328 1329 1330 1331 1332

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:
 *
1333
 * @watch: watch on which the event occurred
1334 1335 1336 1337
 * @fd: file handle on which the event occurred
 * @events: bitset of events from virEventHandleType constants
 * @opaque: user data registered with handle
 *
1338 1339
 * Callback for receiving file handle events. The callback will
 * be invoked once for each event which is pending.
1340
 */
1341
typedef void (*virEventHandleCallback)(int watch, int fd, int events, void *opaque);
1342 1343 1344 1345 1346

/**
 * virEventAddHandleFunc:
 * @fd: file descriptor to listen on
 * @event: bitset of events on which to fire the callback
1347
 * @cb: the callback to be called when an event occurrs
1348
 * @opaque: user data to pass to the callback
1349
 * @ff: the callback invoked to free opaque data blob
1350 1351
 *
 * Part of the EventImpl, this callback Adds a file handle callback to
1352 1353 1354
 * listen for specific events. The same file handle can be registered
 * multiple times provided the requested event sets are non-overlapping
 *
1355 1356 1357 1358
 * If the opaque user data requires free'ing when the handle
 * is unregistered, then a 2nd callback can be supplied for
 * this purpose.
 *
1359 1360
 * Returns a handle watch number to be used for updating
 * and unregistering for events
1361 1362
 */
typedef int (*virEventAddHandleFunc)(int fd, int event,
1363 1364 1365
                                     virEventHandleCallback cb,
                                     void *opaque,
                                     virFreeCallback ff);
1366 1367 1368

/**
 * virEventUpdateHandleFunc:
1369
 * @watch: file descriptor watch to modify
1370 1371 1372 1373 1374
 * @event: new events to listen on
 *
 * Part of the EventImpl, this user-provided callback is notified when
 * events to listen on change
 */
1375
typedef void (*virEventUpdateHandleFunc)(int watch, int event);
1376 1377 1378

/**
 * virEventRemoveHandleFunc:
1379
 * @watch: file descriptor watch to stop listening on
1380 1381
 *
 * Part of the EventImpl, this user-provided callback is notified when
1382 1383 1384 1385 1386
 * 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.
1387
 */
1388
typedef int (*virEventRemoveHandleFunc)(int watch);
1389 1390 1391 1392 1393 1394 1395 1396 1397 1398 1399 1400 1401 1402 1403 1404

/**
 * 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
1405
 * @ff: the callback invoked to free opaque data blob
1406 1407 1408 1409
 *
 * Part of the EventImpl, this user-defined callback handles adding an
 * event timeout.
 *
1410 1411 1412 1413
 * If the opaque user data requires free'ing when the handle
 * is unregistered, then a 2nd callback can be supplied for
 * this purpose.
 *
1414 1415
 * Returns a timer value
 */
1416 1417 1418 1419
typedef int (*virEventAddTimeoutFunc)(int timeout,
                                      virEventTimeoutCallback cb,
                                      void *opaque,
                                      virFreeCallback ff);
1420 1421 1422 1423 1424 1425 1426 1427 1428 1429 1430 1431 1432 1433 1434 1435 1436

/**
 * 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
 *
1437 1438 1439 1440
 * 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.
 *
1441 1442 1443 1444 1445 1446 1447 1448 1449 1450
 * 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);
M
Miloslav Trmač 已提交
1451 1452 1453 1454 1455 1456 1457 1458 1459 1460 1461 1462 1463 1464

/*
 * Secret manipulation API
 */

/**
 * virSecret:
 *
 * A virSecret stores a secret value (e.g. a passphrase or encryption key)
 * and associated metadata.
 */
typedef struct _virSecret virSecret;
typedef virSecret *virSecretPtr;

1465 1466 1467 1468 1469 1470
typedef enum {
    VIR_SECRET_USAGE_TYPE_NONE = 0,
    VIR_SECRET_USAGE_TYPE_VOLUME = 1,
    /* Expect more owner types later... */
} virSecretUsageType;

M
Miloslav Trmač 已提交
1471 1472 1473 1474 1475
virConnectPtr           virSecretGetConnect     (virSecretPtr secret);
int                     virConnectNumOfSecrets  (virConnectPtr conn);
int                     virConnectListSecrets   (virConnectPtr conn,
                                                 char **uuids,
                                                 int maxuuids);
1476 1477
virSecretPtr            virSecretLookupByUUID(virConnectPtr conn,
                                              const unsigned char *uuid);
M
Miloslav Trmač 已提交
1478 1479
virSecretPtr            virSecretLookupByUUIDString(virConnectPtr conn,
                                                    const char *uuid);
1480 1481 1482
virSecretPtr            virSecretLookupByUsage(virConnectPtr conn,
                                               int usageType,
                                               const char *usageID);
M
Miloslav Trmač 已提交
1483 1484 1485
virSecretPtr            virSecretDefineXML      (virConnectPtr conn,
                                                 const char *xml,
                                                 unsigned int flags);
1486 1487 1488 1489
int                     virSecretGetUUID        (virSecretPtr secret,
                                                 unsigned char *buf);
int                     virSecretGetUUIDString  (virSecretPtr secret,
                                                 char *buf);
1490 1491
int                     virSecretGetUsageType   (virSecretPtr secret);
const char *            virSecretGetUsageID     (virSecretPtr secret);
M
Miloslav Trmač 已提交
1492 1493 1494 1495 1496 1497 1498 1499 1500 1501 1502 1503 1504
char *                  virSecretGetXMLDesc     (virSecretPtr secret,
                                                 unsigned int flags);
int                     virSecretSetValue       (virSecretPtr secret,
                                                 const unsigned char *value,
                                                 size_t value_size,
                                                 unsigned int flags);
unsigned char *         virSecretGetValue       (virSecretPtr secret,
                                                 size_t *value_size,
                                                 unsigned int flags);
int                     virSecretUndefine       (virSecretPtr secret);
int                     virSecretRef            (virSecretPtr secret);
int                     virSecretFree           (virSecretPtr secret);

1505 1506 1507 1508 1509
#ifdef __cplusplus
}
#endif

#endif /* __VIR_VIRLIB_H__ */