libvirt/src/conf/domain_conf.h

872 lines
24 KiB
C
Raw Normal View History

2008-07-11 16:23:36 +00:00
/*
* domain_conf.h: domain XML processing
*
* Copyright (C) 2006-2008 Red Hat, Inc.
* Copyright (C) 2006-2008 Daniel P. Berrange
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*
* Author: Daniel P. Berrange <berrange@redhat.com>
*/
#ifndef __DOMAIN_CONF_H
#define __DOMAIN_CONF_H
#include <libxml/parser.h>
#include <libxml/tree.h>
#include <libxml/xpath.h>
2008-07-11 16:23:36 +00:00
#include "internal.h"
#include "capabilities.h"
#include "storage_encryption_conf.h"
#include "cpu_conf.h"
2008-07-11 16:23:36 +00:00
#include "util.h"
2009-01-15 19:56:05 +00:00
#include "threads.h"
Convert virDomainObjListPtr to use a hash of domain objects The current virDomainObjListPtr object stores domain objects in an array. This means that to find a particular objects requires O(n) time, and more critically acquiring O(n) mutex locks. The new impl replaces the array with a virHashTable, keyed off UUID. Finding a object based on UUID is now O(1) time, and only requires a single mutex lock. Finding by name/id is unchanged in complexity. In changing this, all code which iterates over the array had to be updated to use a hash table iterator function callback. Several of the functions which were identically duplicating across all drivers were pulled into domain_conf.c * src/conf/domain_conf.h, src/conf/domain_conf.c: Change virDomainObjListPtr to use virHashTable. Add a initializer method virDomainObjListInit, and rename virDomainObjListFree to virDomainObjListDeinit, since its not actually freeing the container, only its contents. Also add some convenient methods virDomainObjListGetInactiveNames, virDomainObjListGetActiveIDs and virDomainObjListNumOfDomains which can be used to implement the correspondingly named public API entry points in drivers * src/libvirt_private.syms: Export new methods from domain_conf.h * src/lxc/lxc_driver.c, src/opennebula/one_driver.c, src/openvz/openvz_conf.c, src/openvz/openvz_driver.c, src/qemu/qemu_driver.c, src/test/test_driver.c, src/uml/uml_driver.c, src/vbox/vbox_tmpl.c: Update all code to deal with hash tables instead of arrays for domains
2009-10-09 11:33:51 +00:00
#include "hash.h"
#include "network.h"
2008-07-11 16:23:36 +00:00
/* Private component of virDomainXMLFlags */
typedef enum {
VIR_DOMAIN_XML_INTERNAL_STATUS = (1<<16), /* dump internal domain status information */
} virDomainXMLInternalFlags;
2008-07-11 16:23:36 +00:00
/* Different types of hypervisor */
/* NB: Keep in sync with virDomainVirtTypeToString impl */
enum virDomainVirtType {
VIR_DOMAIN_VIRT_QEMU,
VIR_DOMAIN_VIRT_KQEMU,
VIR_DOMAIN_VIRT_KVM,
VIR_DOMAIN_VIRT_XEN,
VIR_DOMAIN_VIRT_LXC,
VIR_DOMAIN_VIRT_UML,
VIR_DOMAIN_VIRT_OPENVZ,
VIR_DOMAIN_VIRT_VSERVER,
VIR_DOMAIN_VIRT_LDOM,
VIR_DOMAIN_VIRT_TEST,
VIR_DOMAIN_VIRT_VMWARE,
VIR_DOMAIN_VIRT_HYPERV,
VIR_DOMAIN_VIRT_VBOX,
VIR_DOMAIN_VIRT_ONE,
VIR_DOMAIN_VIRT_PHYP,
2008-07-11 16:23:36 +00:00
VIR_DOMAIN_VIRT_LAST,
};
enum virDomainDeviceAddressType {
VIR_DOMAIN_DEVICE_ADDRESS_TYPE_NONE,
VIR_DOMAIN_DEVICE_ADDRESS_TYPE_PCI,
VIR_DOMAIN_DEVICE_ADDRESS_TYPE_DRIVE,
VIR_DOMAIN_DEVICE_ADDRESS_TYPE_LAST
};
typedef struct _virDomainDevicePCIAddress virDomainDevicePCIAddress;
typedef virDomainDevicePCIAddress *virDomainDevicePCIAddressPtr;
struct _virDomainDevicePCIAddress {
unsigned int domain;
unsigned int bus;
unsigned int slot;
unsigned int function;
};
typedef struct _virDomainDeviceDriveAddress virDomainDeviceDriveAddress;
typedef virDomainDeviceDriveAddress *virDomainDeviceDriveAddressPtr;
struct _virDomainDeviceDriveAddress {
unsigned int controller;
unsigned int bus;
unsigned int unit;
};
typedef struct _virDomainDeviceInfo virDomainDeviceInfo;
typedef virDomainDeviceInfo *virDomainDeviceInfoPtr;
struct _virDomainDeviceInfo {
int type;
union {
virDomainDevicePCIAddress pci;
virDomainDeviceDriveAddress drive;
} addr;
};
2008-07-11 16:23:36 +00:00
/* Two types of disk backends */
enum virDomainDiskType {
VIR_DOMAIN_DISK_TYPE_BLOCK,
VIR_DOMAIN_DISK_TYPE_FILE,
VIR_DOMAIN_DISK_TYPE_DIR,
2008-07-11 16:23:36 +00:00
VIR_DOMAIN_DISK_TYPE_LAST
};
/* Three types of disk frontend */
enum virDomainDiskDevice {
VIR_DOMAIN_DISK_DEVICE_DISK,
VIR_DOMAIN_DISK_DEVICE_CDROM,
VIR_DOMAIN_DISK_DEVICE_FLOPPY,
VIR_DOMAIN_DISK_DEVICE_LAST
};
enum virDomainDiskBus {
VIR_DOMAIN_DISK_BUS_IDE,
VIR_DOMAIN_DISK_BUS_FDC,
VIR_DOMAIN_DISK_BUS_SCSI,
VIR_DOMAIN_DISK_BUS_VIRTIO,
VIR_DOMAIN_DISK_BUS_XEN,
VIR_DOMAIN_DISK_BUS_USB,
2008-11-19 16:58:23 +00:00
VIR_DOMAIN_DISK_BUS_UML,
VIR_DOMAIN_DISK_BUS_SATA,
2008-07-11 16:23:36 +00:00
VIR_DOMAIN_DISK_BUS_LAST
};
2009-01-30 17:15:39 +00:00
enum virDomainDiskCache {
VIR_DOMAIN_DISK_CACHE_DEFAULT,
VIR_DOMAIN_DISK_CACHE_DISABLE,
VIR_DOMAIN_DISK_CACHE_WRITETHRU,
VIR_DOMAIN_DISK_CACHE_WRITEBACK,
VIR_DOMAIN_DISK_CACHE_LAST
};
2008-07-11 16:23:36 +00:00
/* Stores the virtual disk configuration */
typedef struct _virDomainDiskDef virDomainDiskDef;
typedef virDomainDiskDef *virDomainDiskDefPtr;
struct _virDomainDiskDef {
int type;
int device;
int bus;
char *src;
char *dst;
char *driverName;
char *driverType;
char *serial;
2009-01-30 17:15:39 +00:00
int cachemode;
2008-07-11 16:23:36 +00:00
unsigned int readonly : 1;
unsigned int shared : 1;
virDomainDeviceInfo info;
virStorageEncryptionPtr encryption;
2008-07-11 16:23:36 +00:00
};
/* Two types of disk backends */
enum virDomainFSType {
VIR_DOMAIN_FS_TYPE_MOUNT, /* Better named 'bind' */
VIR_DOMAIN_FS_TYPE_BLOCK,
VIR_DOMAIN_FS_TYPE_FILE,
VIR_DOMAIN_FS_TYPE_TEMPLATE,
VIR_DOMAIN_FS_TYPE_LAST
};
typedef struct _virDomainFSDef virDomainFSDef;
typedef virDomainFSDef *virDomainFSDefPtr;
struct _virDomainFSDef {
int type;
char *src;
char *dst;
unsigned int readonly : 1;
};
2008-07-11 16:23:36 +00:00
/* 5 different types of networking config */
enum virDomainNetType {
VIR_DOMAIN_NET_TYPE_USER,
VIR_DOMAIN_NET_TYPE_ETHERNET,
VIR_DOMAIN_NET_TYPE_SERVER,
VIR_DOMAIN_NET_TYPE_CLIENT,
VIR_DOMAIN_NET_TYPE_MCAST,
VIR_DOMAIN_NET_TYPE_NETWORK,
VIR_DOMAIN_NET_TYPE_BRIDGE,
VIR_DOMAIN_NET_TYPE_INTERNAL,
2008-07-11 16:23:36 +00:00
VIR_DOMAIN_NET_TYPE_LAST,
};
/* Stores the virtual network interface configuration */
typedef struct _virDomainNetDef virDomainNetDef;
typedef virDomainNetDef *virDomainNetDefPtr;
struct _virDomainNetDef {
int type;
unsigned char mac[VIR_MAC_BUFLEN];
2008-07-11 16:23:36 +00:00
char *model;
union {
struct {
char *dev;
char *script;
char *ipaddr;
} ethernet;
struct {
char *address;
int port;
} socket; /* any of NET_CLIENT or NET_SERVER or NET_MCAST */
struct {
char *name;
} network;
struct {
char *brname;
char *script;
2009-01-23 01:48:47 +00:00
char *ipaddr;
2008-07-11 16:23:36 +00:00
} bridge;
struct {
char *name;
} internal;
2008-07-11 16:23:36 +00:00
} data;
char *ifname;
virDomainDeviceInfo info;
/* XXX figure out how to remove this */
char *nic_name;
/* XXX figure out how to remove this */
char *hostnet_name;
/* XXX figure out how to remove this */
int vlan;
2008-07-11 16:23:36 +00:00
};
enum virDomainChrTargetType {
VIR_DOMAIN_CHR_TARGET_TYPE_NULL = 0,
VIR_DOMAIN_CHR_TARGET_TYPE_MONITOR,
VIR_DOMAIN_CHR_TARGET_TYPE_PARALLEL,
VIR_DOMAIN_CHR_TARGET_TYPE_SERIAL,
VIR_DOMAIN_CHR_TARGET_TYPE_CONSOLE,
VIR_DOMAIN_CHR_TARGET_TYPE_GUESTFWD,
VIR_DOMAIN_CHR_TARGET_TYPE_LAST
};
enum virDomainChrType {
2008-07-11 16:23:36 +00:00
VIR_DOMAIN_CHR_TYPE_NULL,
VIR_DOMAIN_CHR_TYPE_VC,
VIR_DOMAIN_CHR_TYPE_PTY,
VIR_DOMAIN_CHR_TYPE_DEV,
VIR_DOMAIN_CHR_TYPE_FILE,
VIR_DOMAIN_CHR_TYPE_PIPE,
VIR_DOMAIN_CHR_TYPE_STDIO,
VIR_DOMAIN_CHR_TYPE_UDP,
VIR_DOMAIN_CHR_TYPE_TCP,
VIR_DOMAIN_CHR_TYPE_UNIX,
VIR_DOMAIN_CHR_TYPE_LAST,
};
enum virDomainChrTcpProtocol {
VIR_DOMAIN_CHR_TCP_PROTOCOL_RAW,
VIR_DOMAIN_CHR_TCP_PROTOCOL_TELNET,
VIR_DOMAIN_CHR_TCP_PROTOCOL_LAST,
};
typedef struct _virDomainChrDef virDomainChrDef;
typedef virDomainChrDef *virDomainChrDefPtr;
struct _virDomainChrDef {
int targetType;
union {
int port; /* parallel, serial, console */
virSocketAddrPtr addr; /* guestfwd */
} target;
2008-07-11 16:23:36 +00:00
int type;
union {
struct {
char *path;
} file; /* pty, file, pipe, or device */
struct {
char *host;
char *service;
int listen;
int protocol;
} tcp;
struct {
char *bindHost;
char *bindService;
char *connectHost;
char *connectService;
} udp;
struct {
char *path;
int listen;
} nix;
} data;
};
enum virDomainInputType {
VIR_DOMAIN_INPUT_TYPE_MOUSE,
VIR_DOMAIN_INPUT_TYPE_TABLET,
VIR_DOMAIN_INPUT_TYPE_LAST,
};
enum virDomainInputBus {
VIR_DOMAIN_INPUT_BUS_PS2,
VIR_DOMAIN_INPUT_BUS_USB,
VIR_DOMAIN_INPUT_BUS_XEN,
VIR_DOMAIN_INPUT_BUS_LAST
};
typedef struct _virDomainInputDef virDomainInputDef;
typedef virDomainInputDef *virDomainInputDefPtr;
struct _virDomainInputDef {
int type;
int bus;
};
enum virDomainSoundModel {
VIR_DOMAIN_SOUND_MODEL_SB16,
VIR_DOMAIN_SOUND_MODEL_ES1370,
VIR_DOMAIN_SOUND_MODEL_PCSPK,
2009-05-21 14:16:06 +00:00
VIR_DOMAIN_SOUND_MODEL_AC97,
2008-07-11 16:23:36 +00:00
VIR_DOMAIN_SOUND_MODEL_LAST
};
typedef struct _virDomainSoundDef virDomainSoundDef;
typedef virDomainSoundDef *virDomainSoundDefPtr;
struct _virDomainSoundDef {
int model;
};
enum virDomainWatchdogModel {
VIR_DOMAIN_WATCHDOG_MODEL_I6300ESB,
VIR_DOMAIN_WATCHDOG_MODEL_IB700,
VIR_DOMAIN_WATCHDOG_MODEL_LAST
};
enum virDomainWatchdogAction {
VIR_DOMAIN_WATCHDOG_ACTION_RESET,
VIR_DOMAIN_WATCHDOG_ACTION_SHUTDOWN,
VIR_DOMAIN_WATCHDOG_ACTION_POWEROFF,
VIR_DOMAIN_WATCHDOG_ACTION_PAUSE,
VIR_DOMAIN_WATCHDOG_ACTION_NONE,
VIR_DOMAIN_WATCHDOG_ACTION_LAST
};
typedef struct _virDomainWatchdogDef virDomainWatchdogDef;
typedef virDomainWatchdogDef *virDomainWatchdogDefPtr;
struct _virDomainWatchdogDef {
int model;
int action;
};
enum virDomainVideoType {
VIR_DOMAIN_VIDEO_TYPE_VGA,
VIR_DOMAIN_VIDEO_TYPE_CIRRUS,
VIR_DOMAIN_VIDEO_TYPE_VMVGA,
VIR_DOMAIN_VIDEO_TYPE_XEN,
VIR_DOMAIN_VIDEO_TYPE_VBOX,
VIR_DOMAIN_VIDEO_TYPE_LAST
};
typedef struct _virDomainVideoAccelDef virDomainVideoAccelDef;
typedef virDomainVideoAccelDef *virDomainVideoAccelDefPtr;
struct _virDomainVideoAccelDef {
int support3d : 1;
int support2d : 1;
};
typedef struct _virDomainVideoDef virDomainVideoDef;
typedef virDomainVideoDef *virDomainVideoDefPtr;
struct _virDomainVideoDef {
int type;
unsigned int vram;
unsigned int heads;
virDomainVideoAccelDefPtr accel;
};
2008-07-11 16:23:36 +00:00
/* 3 possible graphics console modes */
enum virDomainGraphicsType {
VIR_DOMAIN_GRAPHICS_TYPE_SDL,
VIR_DOMAIN_GRAPHICS_TYPE_VNC,
VIR_DOMAIN_GRAPHICS_TYPE_RDP,
VIR_DOMAIN_GRAPHICS_TYPE_DESKTOP,
2008-07-11 16:23:36 +00:00
VIR_DOMAIN_GRAPHICS_TYPE_LAST,
};
typedef struct _virDomainGraphicsDef virDomainGraphicsDef;
typedef virDomainGraphicsDef *virDomainGraphicsDefPtr;
struct _virDomainGraphicsDef {
int type;
union {
struct {
int port;
int autoport : 1;
char *listenAddr;
char *keymap;
char *passwd;
} vnc;
struct {
char *display;
char *xauth;
int fullscreen;
2008-07-11 16:23:36 +00:00
} sdl;
struct {
int port;
char *listenAddr;
int autoport : 1;
int replaceUser : 1;
int multiUser : 1;
} rdp;
struct {
char *display;
int fullscreen : 1;
} desktop;
2008-07-11 16:23:36 +00:00
} data;
};
enum virDomainHostdevMode {
VIR_DOMAIN_HOSTDEV_MODE_SUBSYS,
VIR_DOMAIN_HOSTDEV_MODE_CAPABILITIES,
2008-07-11 16:23:36 +00:00
VIR_DOMAIN_HOSTDEV_MODE_LAST,
};
enum virDomainHostdevSubsysType {
VIR_DOMAIN_HOSTDEV_SUBSYS_TYPE_USB,
VIR_DOMAIN_HOSTDEV_SUBSYS_TYPE_PCI,
VIR_DOMAIN_HOSTDEV_SUBSYS_TYPE_LAST
};
typedef struct _virDomainHostdevDef virDomainHostdevDef;
typedef virDomainHostdevDef *virDomainHostdevDefPtr;
struct _virDomainHostdevDef {
int mode; /* enum virDomainHostdevMode */
unsigned int managed : 1;
union {
struct {
int type; /* enum virDomainHostdevBusType */
union {
struct {
unsigned bus;
unsigned device;
unsigned vendor;
unsigned product;
} usb;
virDomainDevicePCIAddress pci; /* host address */
} u;
} subsys;
struct {
/* TBD: struct capabilities see:
* https://www.redhat.com/archives/libvir-list/2008-July/msg00429.html
*/
int dummy;
} caps;
} source;
char* target;
virDomainDeviceInfo info; /* Guest address */
};
2008-07-11 16:23:36 +00:00
/* Flags for the 'type' field in next struct */
enum virDomainDeviceType {
VIR_DOMAIN_DEVICE_DISK,
VIR_DOMAIN_DEVICE_FS,
2008-07-11 16:23:36 +00:00
VIR_DOMAIN_DEVICE_NET,
VIR_DOMAIN_DEVICE_INPUT,
VIR_DOMAIN_DEVICE_SOUND,
VIR_DOMAIN_DEVICE_VIDEO,
VIR_DOMAIN_DEVICE_HOSTDEV,
VIR_DOMAIN_DEVICE_WATCHDOG,
VIR_DOMAIN_DEVICE_LAST,
2008-07-11 16:23:36 +00:00
};
typedef struct _virDomainDeviceDef virDomainDeviceDef;
typedef virDomainDeviceDef *virDomainDeviceDefPtr;
struct _virDomainDeviceDef {
int type;
union {
virDomainDiskDefPtr disk;
virDomainFSDefPtr fs;
2008-07-11 16:23:36 +00:00
virDomainNetDefPtr net;
virDomainInputDefPtr input;
virDomainSoundDefPtr sound;
virDomainVideoDefPtr video;
virDomainHostdevDefPtr hostdev;
virDomainWatchdogDefPtr watchdog;
2008-07-11 16:23:36 +00:00
} data;
};
#define VIR_DOMAIN_MAX_BOOT_DEVS 4
/* 3 possible boot devices */
enum virDomainBootOrder {
VIR_DOMAIN_BOOT_FLOPPY,
VIR_DOMAIN_BOOT_CDROM,
VIR_DOMAIN_BOOT_DISK,
VIR_DOMAIN_BOOT_NET,
VIR_DOMAIN_BOOT_LAST,
};
enum virDomainFeature {
VIR_DOMAIN_FEATURE_ACPI,
VIR_DOMAIN_FEATURE_APIC,
VIR_DOMAIN_FEATURE_PAE,
VIR_DOMAIN_FEATURE_LAST
};
enum virDomainLifecycleAction {
VIR_DOMAIN_LIFECYCLE_DESTROY,
VIR_DOMAIN_LIFECYCLE_RESTART,
VIR_DOMAIN_LIFECYCLE_RESTART_RENAME,
VIR_DOMAIN_LIFECYCLE_PRESERVE,
VIR_DOMAIN_LIFECYCLE_LAST
};
/* Operating system configuration data & machine / arch */
typedef struct _virDomainOSDef virDomainOSDef;
typedef virDomainOSDef *virDomainOSDefPtr;
struct _virDomainOSDef {
char *type;
char *arch;
char *machine;
int nBootDevs;
int bootDevs[VIR_DOMAIN_BOOT_LAST];
char *init;
2008-07-11 16:23:36 +00:00
char *kernel;
char *initrd;
char *cmdline;
char *root;
char *loader;
char *bootloader;
char *bootloaderArgs;
};
enum virDomainSeclabelType {
VIR_DOMAIN_SECLABEL_DYNAMIC,
VIR_DOMAIN_SECLABEL_STATIC,
VIR_DOMAIN_SECLABEL_LAST,
};
/* Security configuration for domain */
typedef struct _virSecurityLabelDef virSecurityLabelDef;
typedef virSecurityLabelDef *virSecurityLabelDefPtr;
struct _virSecurityLabelDef {
char *model; /* name of security model */
char *label; /* security label string */
char *imagelabel; /* security image label string */
int type;
};
2008-07-11 16:23:36 +00:00
#define VIR_DOMAIN_CPUMASK_LEN 1024
/* Guest VM main configuration */
typedef struct _virDomainDef virDomainDef;
typedef virDomainDef *virDomainDefPtr;
struct _virDomainDef {
int virtType;
int id;
unsigned char uuid[VIR_UUID_BUFLEN];
char *name;
char *description;
2008-07-11 16:23:36 +00:00
unsigned long memory;
unsigned long maxmem;
unsigned char hugepage_backed;
2008-07-11 16:23:36 +00:00
unsigned long vcpus;
int cpumasklen;
char *cpumask;
/* These 3 are based on virDomainLifeCycleAction enum flags */
int onReboot;
int onPoweroff;
int onCrash;
virDomainOSDef os;
char *emulator;
int features;
int localtime;
int ngraphics;
virDomainGraphicsDefPtr *graphics;
int ndisks;
virDomainDiskDefPtr *disks;
int nfss;
virDomainFSDefPtr *fss;
int nnets;
virDomainNetDefPtr *nets;
int ninputs;
virDomainInputDefPtr *inputs;
int nsounds;
virDomainSoundDefPtr *sounds;
int nvideos;
virDomainVideoDefPtr *videos;
int nhostdevs;
virDomainHostdevDefPtr *hostdevs;
int nserials;
virDomainChrDefPtr *serials;
int nparallels;
virDomainChrDefPtr *parallels;
int nchannels;
virDomainChrDefPtr *channels;
/* Only 1 */
2008-07-11 16:23:36 +00:00
virDomainChrDefPtr console;
virSecurityLabelDef seclabel;
virDomainWatchdogDefPtr watchdog;
virCPUDefPtr cpu;
2008-07-11 16:23:36 +00:00
};
/* Guest VM runtime state */
typedef struct _virDomainObj virDomainObj;
typedef virDomainObj *virDomainObjPtr;
struct _virDomainObj {
2009-01-15 19:56:05 +00:00
virMutex lock;
int refs;
2008-12-04 22:00:14 +00:00
2008-07-11 16:23:36 +00:00
int pid;
int state;
unsigned int autostart : 1;
unsigned int persistent : 1;
virDomainDefPtr def; /* The current definition */
virDomainDefPtr newDef; /* New definition to activate at shutdown */
void *privateData;
void (*privateDataFreeFunc)(void *);
2008-07-11 16:23:36 +00:00
};
typedef struct _virDomainObjList virDomainObjList;
typedef virDomainObjList *virDomainObjListPtr;
struct _virDomainObjList {
Convert virDomainObjListPtr to use a hash of domain objects The current virDomainObjListPtr object stores domain objects in an array. This means that to find a particular objects requires O(n) time, and more critically acquiring O(n) mutex locks. The new impl replaces the array with a virHashTable, keyed off UUID. Finding a object based on UUID is now O(1) time, and only requires a single mutex lock. Finding by name/id is unchanged in complexity. In changing this, all code which iterates over the array had to be updated to use a hash table iterator function callback. Several of the functions which were identically duplicating across all drivers were pulled into domain_conf.c * src/conf/domain_conf.h, src/conf/domain_conf.c: Change virDomainObjListPtr to use virHashTable. Add a initializer method virDomainObjListInit, and rename virDomainObjListFree to virDomainObjListDeinit, since its not actually freeing the container, only its contents. Also add some convenient methods virDomainObjListGetInactiveNames, virDomainObjListGetActiveIDs and virDomainObjListNumOfDomains which can be used to implement the correspondingly named public API entry points in drivers * src/libvirt_private.syms: Export new methods from domain_conf.h * src/lxc/lxc_driver.c, src/opennebula/one_driver.c, src/openvz/openvz_conf.c, src/openvz/openvz_driver.c, src/qemu/qemu_driver.c, src/test/test_driver.c, src/uml/uml_driver.c, src/vbox/vbox_tmpl.c: Update all code to deal with hash tables instead of arrays for domains
2009-10-09 11:33:51 +00:00
/* uuid string -> virDomainObj mapping
* for O(1), lockless lookup-by-uuid */
virHashTable *objs;
};
2008-07-11 16:23:36 +00:00
static inline int
virDomainObjIsActive(virDomainObjPtr dom)
2008-07-11 16:23:36 +00:00
{
return dom->def->id != -1;
}
Convert virDomainObjListPtr to use a hash of domain objects The current virDomainObjListPtr object stores domain objects in an array. This means that to find a particular objects requires O(n) time, and more critically acquiring O(n) mutex locks. The new impl replaces the array with a virHashTable, keyed off UUID. Finding a object based on UUID is now O(1) time, and only requires a single mutex lock. Finding by name/id is unchanged in complexity. In changing this, all code which iterates over the array had to be updated to use a hash table iterator function callback. Several of the functions which were identically duplicating across all drivers were pulled into domain_conf.c * src/conf/domain_conf.h, src/conf/domain_conf.c: Change virDomainObjListPtr to use virHashTable. Add a initializer method virDomainObjListInit, and rename virDomainObjListFree to virDomainObjListDeinit, since its not actually freeing the container, only its contents. Also add some convenient methods virDomainObjListGetInactiveNames, virDomainObjListGetActiveIDs and virDomainObjListNumOfDomains which can be used to implement the correspondingly named public API entry points in drivers * src/libvirt_private.syms: Export new methods from domain_conf.h * src/lxc/lxc_driver.c, src/opennebula/one_driver.c, src/openvz/openvz_conf.c, src/openvz/openvz_driver.c, src/qemu/qemu_driver.c, src/test/test_driver.c, src/uml/uml_driver.c, src/vbox/vbox_tmpl.c: Update all code to deal with hash tables instead of arrays for domains
2009-10-09 11:33:51 +00:00
int virDomainObjListInit(virDomainObjListPtr objs);
void virDomainObjListDeinit(virDomainObjListPtr objs);
2008-07-11 16:23:36 +00:00
virDomainObjPtr virDomainFindByID(const virDomainObjListPtr doms,
2008-07-11 16:23:36 +00:00
int id);
virDomainObjPtr virDomainFindByUUID(const virDomainObjListPtr doms,
2008-07-11 16:23:36 +00:00
const unsigned char *uuid);
virDomainObjPtr virDomainFindByName(const virDomainObjListPtr doms,
2008-07-11 16:23:36 +00:00
const char *name);
void virDomainGraphicsDefFree(virDomainGraphicsDefPtr def);
void virDomainInputDefFree(virDomainInputDefPtr def);
void virDomainDiskDefFree(virDomainDiskDefPtr def);
void virDomainFSDefFree(virDomainFSDefPtr def);
2008-07-11 16:23:36 +00:00
void virDomainNetDefFree(virDomainNetDefPtr def);
void virDomainChrDefFree(virDomainChrDefPtr def);
void virDomainSoundDefFree(virDomainSoundDefPtr def);
void virDomainWatchdogDefFree(virDomainWatchdogDefPtr def);
void virDomainVideoDefFree(virDomainVideoDefPtr def);
void virDomainHostdevDefFree(virDomainHostdevDefPtr def);
2008-07-11 16:23:36 +00:00
void virDomainDeviceDefFree(virDomainDeviceDefPtr def);
int virDomainDevicePCIAddressEqual(virDomainDevicePCIAddressPtr a,
virDomainDevicePCIAddressPtr b);
int virDomainDeviceDriveAddressEqual(virDomainDeviceDriveAddressPtr a,
virDomainDeviceDriveAddressPtr b);
int virDomainDeviceAddressIsValid(virDomainDeviceInfoPtr info,
int type);
int virDomainDevicePCIAddressIsValid(virDomainDevicePCIAddressPtr addr);
int virDomainDeviceDriveAddressIsValid(virDomainDeviceDriveAddressPtr addr);
int virDomainDeviceInfoIsSet(virDomainDeviceInfoPtr info);
void virDomainDeviceInfoClear(virDomainDeviceInfoPtr info);
2008-07-11 16:23:36 +00:00
void virDomainDefFree(virDomainDefPtr vm);
void virDomainObjRef(virDomainObjPtr vm);
/* Returns 1 if the object was freed, 0 if more refs exist */
int virDomainObjUnref(virDomainObjPtr vm);
2008-07-11 16:23:36 +00:00
virDomainObjPtr virDomainAssignDef(virConnectPtr conn,
virCapsPtr caps,
virDomainObjListPtr doms,
2008-07-11 16:23:36 +00:00
const virDomainDefPtr def);
void virDomainRemoveInactive(virDomainObjListPtr doms,
2008-07-11 16:23:36 +00:00
virDomainObjPtr dom);
#ifndef PROXY
2008-07-11 16:23:36 +00:00
virDomainDeviceDefPtr virDomainDeviceDefParse(virConnectPtr conn,
virCapsPtr caps,
2008-07-11 16:23:36 +00:00
const virDomainDefPtr def,
const char *xmlStr,
int flags);
2008-07-11 16:23:36 +00:00
virDomainDefPtr virDomainDefParseString(virConnectPtr conn,
virCapsPtr caps,
const char *xmlStr,
int flags);
2008-07-11 16:23:36 +00:00
virDomainDefPtr virDomainDefParseFile(virConnectPtr conn,
virCapsPtr caps,
const char *filename,
int flags);
2008-07-11 16:23:36 +00:00
virDomainDefPtr virDomainDefParseNode(virConnectPtr conn,
virCapsPtr caps,
xmlDocPtr doc,
xmlNodePtr root,
int flags);
virDomainObjPtr virDomainObjParseFile(virConnectPtr conn,
virCapsPtr caps,
const char *filename);
virDomainObjPtr virDomainObjParseNode(virConnectPtr conn,
virCapsPtr caps,
xmlDocPtr xml,
xmlNodePtr root);
#endif
2008-07-11 16:23:36 +00:00
char *virDomainDefFormat(virConnectPtr conn,
virDomainDefPtr def,
int flags);
char *virDomainObjFormat(virConnectPtr conn,
virCapsPtr caps,
virDomainObjPtr obj,
int flags);
2008-07-11 16:23:36 +00:00
int virDomainCpuSetParse(virConnectPtr conn,
const char **str,
char sep,
char *cpuset,
int maxcpu);
char *virDomainCpuSetFormat(virConnectPtr conn,
char *cpuset,
int maxcpu);
int virDomainDiskInsert(virDomainDefPtr def,
virDomainDiskDefPtr disk);
void virDomainDiskInsertPreAlloced(virDomainDefPtr def,
virDomainDiskDefPtr disk);
2008-07-11 16:23:36 +00:00
int virDomainSaveXML(virConnectPtr conn,
const char *configDir,
virDomainDefPtr def,
const char *xml);
2008-07-11 16:23:36 +00:00
int virDomainSaveConfig(virConnectPtr conn,
const char *configDir,
virDomainDefPtr def);
int virDomainSaveStatus(virConnectPtr conn,
virCapsPtr caps,
const char *statusDir,
virDomainObjPtr obj);
2008-07-11 16:23:36 +00:00
typedef void (*virDomainLoadConfigNotify)(virDomainObjPtr dom,
int newDomain,
void *opaque);
2008-07-11 16:23:36 +00:00
virDomainObjPtr virDomainLoadConfig(virConnectPtr conn,
virCapsPtr caps,
virDomainObjListPtr doms,
2008-07-11 16:23:36 +00:00
const char *configDir,
const char *autostartDir,
const char *name,
virDomainLoadConfigNotify notify,
void *opaque);
2008-07-11 16:23:36 +00:00
int virDomainLoadAllConfigs(virConnectPtr conn,
virCapsPtr caps,
virDomainObjListPtr doms,
2008-07-11 16:23:36 +00:00
const char *configDir,
const char *autostartDir,
int liveStatus,
virDomainLoadConfigNotify notify,
void *opaque);
2008-07-11 16:23:36 +00:00
int virDomainDeleteConfig(virConnectPtr conn,
const char *configDir,
const char *autostartDir,
2008-07-11 16:23:36 +00:00
virDomainObjPtr dom);
char *virDomainConfigFile(virConnectPtr conn,
const char *dir,
const char *name);
int virDiskNameToBusDeviceIndex(virDomainDiskDefPtr disk,
int *busIdx,
int *devIdx);
virDomainFSDefPtr virDomainGetRootFilesystem(virDomainDefPtr def);
int virDomainVideoDefaultType(virDomainDefPtr def);
int virDomainVideoDefaultRAM(virDomainDefPtr def, int type);
int virDomainObjIsDuplicate(virDomainObjListPtr doms,
virDomainDefPtr def,
unsigned int check_active);
2008-12-04 20:53:20 +00:00
void virDomainObjLock(virDomainObjPtr obj);
void virDomainObjUnlock(virDomainObjPtr obj);
Convert virDomainObjListPtr to use a hash of domain objects The current virDomainObjListPtr object stores domain objects in an array. This means that to find a particular objects requires O(n) time, and more critically acquiring O(n) mutex locks. The new impl replaces the array with a virHashTable, keyed off UUID. Finding a object based on UUID is now O(1) time, and only requires a single mutex lock. Finding by name/id is unchanged in complexity. In changing this, all code which iterates over the array had to be updated to use a hash table iterator function callback. Several of the functions which were identically duplicating across all drivers were pulled into domain_conf.c * src/conf/domain_conf.h, src/conf/domain_conf.c: Change virDomainObjListPtr to use virHashTable. Add a initializer method virDomainObjListInit, and rename virDomainObjListFree to virDomainObjListDeinit, since its not actually freeing the container, only its contents. Also add some convenient methods virDomainObjListGetInactiveNames, virDomainObjListGetActiveIDs and virDomainObjListNumOfDomains which can be used to implement the correspondingly named public API entry points in drivers * src/libvirt_private.syms: Export new methods from domain_conf.h * src/lxc/lxc_driver.c, src/opennebula/one_driver.c, src/openvz/openvz_conf.c, src/openvz/openvz_driver.c, src/qemu/qemu_driver.c, src/test/test_driver.c, src/uml/uml_driver.c, src/vbox/vbox_tmpl.c: Update all code to deal with hash tables instead of arrays for domains
2009-10-09 11:33:51 +00:00
int virDomainObjListNumOfDomains(virDomainObjListPtr doms, int active);
int virDomainObjListGetActiveIDs(virDomainObjListPtr doms,
int *ids,
int maxids);
int virDomainObjListGetInactiveNames(virDomainObjListPtr doms,
char **const names,
int maxnames);
2008-07-11 16:23:36 +00:00
VIR_ENUM_DECL(virDomainVirt)
VIR_ENUM_DECL(virDomainBoot)
VIR_ENUM_DECL(virDomainFeature)
VIR_ENUM_DECL(virDomainLifecycle)
VIR_ENUM_DECL(virDomainDevice)
VIR_ENUM_DECL(virDomainDeviceAddress)
VIR_ENUM_DECL(virDomainDeviceAddressMode)
2008-07-11 16:23:36 +00:00
VIR_ENUM_DECL(virDomainDisk)
VIR_ENUM_DECL(virDomainDiskDevice)
VIR_ENUM_DECL(virDomainDiskBus)
2009-01-30 17:15:39 +00:00
VIR_ENUM_DECL(virDomainDiskCache)
VIR_ENUM_DECL(virDomainFS)
2008-07-11 16:23:36 +00:00
VIR_ENUM_DECL(virDomainNet)
VIR_ENUM_DECL(virDomainChrTarget)
2008-07-11 16:23:36 +00:00
VIR_ENUM_DECL(virDomainChr)
VIR_ENUM_DECL(virDomainSoundModel)
VIR_ENUM_DECL(virDomainWatchdogModel)
VIR_ENUM_DECL(virDomainWatchdogAction)
VIR_ENUM_DECL(virDomainVideo)
VIR_ENUM_DECL(virDomainHostdevMode)
VIR_ENUM_DECL(virDomainHostdevSubsys)
2008-07-11 16:23:36 +00:00
VIR_ENUM_DECL(virDomainInput)
VIR_ENUM_DECL(virDomainInputBus)
VIR_ENUM_DECL(virDomainGraphics)
2009-01-19 21:06:26 +00:00
/* from libvirt.h */
VIR_ENUM_DECL(virDomainState)
VIR_ENUM_DECL(virDomainSeclabel)
2008-07-11 16:23:36 +00:00
#endif /* __DOMAIN_CONF_H */