From bfee5cd2cd6e5a88ea2ff43956af42ad40715d9d Mon Sep 17 00:00:00 2001 From: Daniel Veillard Date: Fri, 28 Apr 2006 18:29:26 +0000 Subject: [PATCH] * src/hash.c src/internal.h src/libvirt.c src/virterror.c src/xml.h include/libvirt.h[.in] include/virterror.h: started adding new APIs, some still TODO, and not tested yet Daniel --- ChangeLog | 6 + docs/APIchunk3.html | 132 +++++++++++ docs/devhelp/general.html | 38 ++++ docs/devhelp/index.html | 43 ++++ docs/devhelp/libvirt-libvirt.html | 326 ++++++++++++++++++++++++++++ docs/devhelp/libvirt-virterror.html | 184 ++++++++++++++++ docs/examples/.cvsignore | 5 + include/libvirt.h | 11 + include/libvirt.h.in | 11 + include/libvirt/libvirt.h | 11 + include/libvirt/libvirt.h.in | 11 + include/libvirt/virterror.h | 4 +- include/virterror.h | 4 +- src/.cvsignore | 1 + src/hash.c | 3 + src/internal.h | 4 +- src/libvirt.c | 161 ++++++++++++++ src/virterror.c | 12 + src/xml.h | 20 +- 19 files changed, 974 insertions(+), 13 deletions(-) create mode 100644 docs/APIchunk3.html create mode 100644 docs/devhelp/general.html create mode 100644 docs/devhelp/index.html create mode 100644 docs/devhelp/libvirt-libvirt.html create mode 100644 docs/devhelp/libvirt-virterror.html create mode 100644 docs/examples/.cvsignore create mode 100644 src/.cvsignore diff --git a/ChangeLog b/ChangeLog index 8a11a6b7bc..5b6fde92b4 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,9 @@ +Fri Apr 28 18:31:49 EDT 2006 Daniel Veillard + + * src/hash.c src/internal.h src/libvirt.c src/virterror.c + src/xml.h include/libvirt.h[.in] include/virterror.h: started + adding new APIs, some still TODO, and not tested yet + Thu Apr 27 14:17:04 EDT 2006 Daniel Veillard * src/xml.c src/xend_internal.c TODO: added uuid to the XML diff --git a/docs/APIchunk3.html b/docs/APIchunk3.html new file mode 100644 index 0000000000..d282e0e721 --- /dev/null +++ b/docs/APIchunk3.html @@ -0,0 +1,132 @@ + + +API Alphabetic Index t-z for libvirt

API Alphabetic Index t-z for libvirt

A-c +d-m +n-s +t-z +

Letter t:

target
virConnCopyLastError
+virCopyLastError
+virDomainSetMemory
+
terminated
virConnectGetType
+virDomainGetXMLDesc
+
that
virConnCopyLastError
+virConnGetLastError
+virConnResetLastError
+virDomainGetInfo
+virDomainGetName
+virDomainReboot
+virDomainShutdown
+
their
virConnectListDomains
+
then
virConnectOpenReadOnly
+virDomainGetMaxMemory
+virDomainSetMaxMemory
+virDomainSetMemory
+
there
virConnectClose
+virDomainReboot
+virDomainShutdown
+virErrorFunc
+virSetErrorFunc
+
thereafter
virDomainDestroy
+virDomainFree
+
this
_virError
+virDomainGetMaxMemory
+virDomainSave
+virDomainSetMaxMemory
+virDomainSetMemory
+virInitialize
+
those
virSetErrorFunc
+
threads
_virNodeInfo
+
time
_virDomainInfo
+
two
virGetVersion
+
type
virDomainGetOSType
+virGetVersion
+

Letter u:

uniform
_virNodeInfo
+
unknown
virGetVersion
+
unsigned
virDomainGetID
+
unused
virConnectOpen
+virConnectOpenReadOnly
+
usable
virConnectOpenReadOnly
+virDomainReboot
+virDomainShutdown
+
use
virConnGetLastError
+virErrorFunc
+virGetLastError
+
used
_virDomainInfo
+virConnectGetType
+virDomainDestroy
+virDomainFree
+virDomainGetInfo
+virDomainGetXMLDesc
+virDomainReboot
+virDomainSuspend
+
user
virConnSetErrorFunc
+virDomainGetInfo
+virErrorFunc
+virNodeGetInfo
+virSetErrorFunc
+

Letter v:

value
virConnectGetVersion
+virDomainGetXMLDesc
+virGetVersion
+
values
virGetVersion
+
version
LIBVIR_VERSION_NUMBER
+virConnectGetVersion
+virGetVersion
+
virConnCopyLastError
virConnGetLastError
+
virCopyLastError
virGetLastError
+
virDomainCreateLinux
virDomainGetXMLDesc
+
virDomainFlags
_virDomainInfo
+virDomainCreateLinux
+
virDomainGetXMLDesc
virDomainCreateLinux
+
virDomainInfo
virDomainGetInfo
+
virDomainRestore
virDomainSave
+
virDomainResume
virDomainSuspend
+
virDomainSave
virDomainRestore
+
virError
virResetError
+
virErrorNumber
_virError
+
virNodeInfo
virNodeGetInfo
+
virResetError
virConnCopyLastError
+virCopyLastError
+
virSuspendDomain
virDomainResume
+
virtual
_virDomainInfo
+

Letter w:

was
virConnCopyLastError
+virCopyLastError
+virDomainResume
+virGetVersion
+
when
virErrorFunc
+virInitialize
+
where
virDomainGetMaxMemory
+virDomainResume
+virDomainSetMaxMemory
+virDomainSetMemory
+
which
virConnGetLastError
+virConnSetErrorFunc
+virConnectClose
+virGetLastError
+virGetVersion
+virSetErrorFunc
+
while
virGetVersion
+
will
virConnCopyLastError
+virConnSetErrorFunc
+virCopyLastError
+virDomainGetName
+virDomainRestore
+virDomainSave
+virDomainSuspend
+virGetVersion
+virSetErrorFunc
+
with
virConnCopyLastError
+virConnectClose
+virConnectGetVersion
+virCopyLastError
+virDomainGetXMLDesc
+
without
virDomainSuspend
+
work
virConnectGetVersion
+

Letter x:

xen
virConnectOpen
+

Letter y:

yet
virDomainGetXMLDesc
+virDomainReboot
+

Letter z:

zero
virConnectGetType
+

A-c +d-m +n-s +t-z +

diff --git a/docs/devhelp/general.html b/docs/devhelp/general.html new file mode 100644 index 0000000000..998f2b18a6 --- /dev/null +++ b/docs/devhelp/general.html @@ -0,0 +1,38 @@ + + + + + libvirt: + + + + + + + + + + + + + + + +

+ libvirt API Modules +

+

libvirt - core interfaces for the libvirt library
virterror - error handling interfaces for the libvirt library

+ + diff --git a/docs/devhelp/index.html b/docs/devhelp/index.html new file mode 100644 index 0000000000..df593de2d4 --- /dev/null +++ b/docs/devhelp/index.html @@ -0,0 +1,43 @@ + + + + + libvirt Reference Manual + + + + + + + + + + + +

+ libvirt Reference Manual +

+

Libvir is a C toolkit to interract with the virtualization capabilities of +recent versions of Linux (and other OSes). It is free software available +under the GNU +Lesser General Public License. Virtualization of the Linux Operating +System means the ability to run multiple instances of Operating Systems +concurently on a single hardware system where the basic resources are driven +by a Linux instance. The library aim at providing long term stable C API +initially for the Xen +paravirtualization but should be able to integrate other virtualization +mechanisms if needed.

+

If you get lost searching for some specific API use, try +the online search +engine hosted on libvirt.org +it indexes the project page, the APIs as well as the mailing-list archives.

+ + diff --git a/docs/devhelp/libvirt-libvirt.html b/docs/devhelp/libvirt-libvirt.html new file mode 100644 index 0000000000..1cbede21d7 --- /dev/null +++ b/docs/devhelp/libvirt-libvirt.html @@ -0,0 +1,326 @@ + + + + + libvirt: core interfaces for the libvirt library + + + + + + + + + + + + + + + +

+ libvirt +

+

libvirt - core interfaces for the libvirt library

+

Provides the interfaces of the libvirt library to handle Xen domains from a process running in domain 0

+

Author(s): Daniel Veillard <veillard@redhat.com>

+
+

Synopsis

+
#define LIBVIR_VERSION_NUMBER;
+typedef virNodeInfo * virNodeInfoPtr;
+typedef virDomainInfo * virDomainInfoPtr;
+typedef virDomainKernel * virDomainKernelPtr;
+typedef virConnect * virConnectPtr;
+typedef struct _virDomainKernel virDomainKernel;
+typedef struct _virNodeInfo virNodeInfo;
+typedef enum virDomainState;
+typedef enum virDeviceMode;
+typedef struct _virDomain virDomain;
+typedef virDomain * virDomainPtr;
+typedef enum virDomainRestart;
+typedef struct _virConnect virConnect;
+typedef enum virDomainCreateFlags;
+typedef struct _virDomainInfo virDomainInfo;
+int	virDomainGetInfo		(virDomainPtr domain, 
virDomainInfoPtr info); +int virDomainShutdown (virDomainPtr domain); +int virGetVersion (unsigned long * libVer,
const char * type,
unsigned long * typeVer); +virDomainPtr virDomainLookupByName (virConnectPtr conn,
const char * name); +int virDomainRestore (virConnectPtr conn,
const char * from); +const char * virConnectGetType (virConnectPtr conn); +int virDomainSave (virDomainPtr domain,
const char * to); +int virConnectListDomains (virConnectPtr conn,
int * ids,
int maxids); +virDomainPtr virDomainLookupByUUID (virConnectPtr conn,
const unsigned char * uuid); +virDomainPtr virDomainLookupByID (virConnectPtr conn,
int id); +char * virDomainGetOSType (virDomainPtr domain); +int virNodeGetInfo (virConnectPtr conn,
virNodeInfoPtr info); +int virDomainGetUUID (virDomainPtr domain,
unsigned char * uuid); +int virConnectNumOfDomains (virConnectPtr conn); +int virDomainSetMaxMemory (virDomainPtr domain,
unsigned long memory); +unsigned long virDomainGetMaxMemory (virDomainPtr domain); +int virConnectGetVersion (virConnectPtr conn,
unsigned long * hvVer); +int virDomainFree (virDomainPtr domain); +virConnectPtr virConnectOpen (const char * name); +int virDomainSuspend (virDomainPtr domain); +int virConnectClose (virConnectPtr conn); +int virDomainReboot (virDomainPtr domain,
unsigned int flags); +int virInitialize (void); +unsigned int virDomainGetID (virDomainPtr domain); +int virDomainResume (virDomainPtr domain); +virDomainPtr virDomainCreateLinux (virConnectPtr conn,
const char * xmlDesc,
unsigned int flags); +int virDomainSetMemory (virDomainPtr domain,
unsigned long memory); +int virDomainDestroy (virDomainPtr domain); +char * virDomainGetXMLDesc (virDomainPtr domain,
int flags); +const char * virDomainGetName (virDomainPtr domain); +virConnectPtr virConnectOpenReadOnly (const char * name); +
+
+
+

Description

+
+
+

Details

+
+

Macro LIBVIR_VERSION_NUMBER

#define LIBVIR_VERSION_NUMBER;
+

Macro providing the version of the library as version * 1,000,000 + minor * 1000 + micro

+
+
+

Structure virConnect

struct _virConnect {
+The content of this structure is not made public by the API.
+} virConnect;
+

+

+
+

Typedef virConnectPtr

virConnect * virConnectPtr;
+

a virConnectPtr is pointer to a virConnect private structure, this is the type used to reference a connection to the Xen Hypervisor in the API.

+
+
+

Enum virDeviceMode

enum virDeviceMode {
+    VIR_DEVICE_DEFAULT = 0 /* Default mode */
+    VIR_DEVICE_RO = 1 /* Access read-only */
+    VIR_DEVICE_RW = 2 /* Access read-write */
+    VIR_DEVICE_RW_FORCE = 3 /*  Forced read-write even if already used */
+};
+

+

+
+

Structure virDomain

struct _virDomain {
+The content of this structure is not made public by the API.
+} virDomain;
+

+

+
+

Enum virDomainCreateFlags

enum virDomainCreateFlags {
+    VIR_DOMAIN_NONE = 0
+};
+

+

+
+

Structure virDomainInfo

struct _virDomainInfo {
+    unsigned char	state	: the running state, one of virDomainFlags
+    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
+} virDomainInfo;
+

+

+
+

Typedef virDomainInfoPtr

virDomainInfo * virDomainInfoPtr;
+

a virDomainInfoPtr is a pointer to a virDomainInfo structure.

+
+
+

Structure virDomainKernel

struct _virDomainKernel {
+    const char *	kernel	: filename pointing to the kernel image
+    const char *	ramdisk	: an optional init ramdisk
+    const char *	root	: an optional root block device
+    const char *	extra	: optional kernel command line parameters
+} virDomainKernel;
+

+

+
+

Typedef virDomainKernelPtr

virDomainKernel * virDomainKernelPtr;
+

a virDomainKernelPtr is a pointer to a virDomainKernel structure.

+
+
+

Typedef virDomainPtr

virDomain * virDomainPtr;
+

a virDomainPtr is pointer to a virDomain private structure, this is the type used to reference a Xen domain in the API.

+
+
+

Enum virDomainRestart

enum virDomainRestart {
+    VIR_DOMAIN_DESTROY = 1 /* destroy the domain */
+    VIR_DOMAIN_RESTART = 2 /* restart the domain */
+    VIR_DOMAIN_PRESERVE = 3 /* keep as is, need manual destroy, for debug */
+    VIR_DOMAIN_RENAME_RESTART = 4 /*  restart under an new unique name */
+};
+

+

+
+

Enum virDomainState

enum virDomainState {
+    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 */
+    VIR_DOMAIN_SHUTDOWN = 4 /* the domain is being shut down */
+    VIR_DOMAIN_SHUTOFF = 5 /* the domain is shut off */
+    VIR_DOMAIN_CRASHED = 6 /*  the domain is crashed */
+};
+

+

+
+

Structure virNodeInfo

struct _virNodeInfo {
+    charmodel[32]	model	: string indicating the CPU model
+    unsigned long	memory	: memory size in kilobytes
+    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
+    unsigned int	sockets	: number of CPU socket per node
+    unsigned int	cores	: number of core per socket
+    unsigned int	threads	: number of threads per core
+} virNodeInfo;
+

+

+
+

Typedef virNodeInfoPtr

virNodeInfo * virNodeInfoPtr;
+

a virNodeInfoPtr is a pointer to a virNodeInfo structure.

+
+
+

virConnectClose ()

int	virConnectClose			(virConnectPtr conn)
+

This function closes the connection to the Hypervisor. This should not be called if further interaction with the Hypervisor are needed especially if there is running domain which need further monitoring by the application.

+
conn:pointer to the hypervisor connection
Returns:0 in case of success or -1 in case of error.
+
+

virConnectGetType ()

const char *	virConnectGetType	(virConnectPtr conn)
+

Get the name of the Hypervisor software used.

+
conn:pointer to the hypervisor connection
Returns:NULL in case of error, a static zero terminated string otherwise.
+
+

virConnectGetVersion ()

int	virConnectGetVersion		(virConnectPtr conn, 
unsigned long * hvVer)
+

Get the version level of the Hypervisor running. This may work only with hypervisor call, i.e. with priviledged access to the hypervisor, not with a Read-Only connection.

+
conn:pointer to the hypervisor connection
hvVer:return value for the version of the running hypervisor (OUT)
Returns:-1 in case of error, 0 otherwise. if the version can't be extracted by lack of capacities returns 0 and @hvVer is 0, otherwise @hvVer value is major * 1,000,000 + minor * 1,000 + release
+
+

virConnectListDomains ()

int	virConnectListDomains		(virConnectPtr conn, 
int * ids,
int maxids)
+

Collect the list of active domains, and store their ID in @maxids

+
conn:pointer to the hypervisor connection
ids:array to collect the list of IDs of active domains
maxids:size of @ids
Returns:the number of domain found or -1 in case of error
+
+

virConnectNumOfDomains ()

int	virConnectNumOfDomains		(virConnectPtr conn)
+

Provides the number of active domains.

+
conn:pointer to the hypervisor connection
Returns:the number of domain found or -1 in case of error
+
+

virConnectOpen ()

virConnectPtr	virConnectOpen		(const char * name)
+

This function should be called first to get a connection to the Hypervisor and xen store

+
name:optional argument currently unused, pass NULL
Returns:a pointer to the hypervisor connection or NULL in case of error
+
+

virConnectOpenReadOnly ()

virConnectPtr	virConnectOpenReadOnly	(const char * name)
+

This function should be called first to get a restricted connection to the libbrary functionalities. The set of APIs usable are then restricted on the available methods to control the domains.

+
name:optional argument currently unused, pass NULL
Returns:a pointer to the hypervisor connection or NULL in case of error
+
+

virDomainCreateLinux ()

virDomainPtr	virDomainCreateLinux	(virConnectPtr conn, 
const char * xmlDesc,
unsigned int flags)
+

Launch a new Linux guest domain, based on an XML description similar to the one returned by virDomainGetXMLDesc() This function may requires priviledged access to the hypervisor.

+
conn:pointer to the hypervisor connection
xmlDesc:an XML description of the domain
flags:an optional set of virDomainFlags
Returns:a new domain object or NULL in case of failure
+
+

virDomainDestroy ()

int	virDomainDestroy		(virDomainPtr domain)
+

Destroy the domain object. The running instance is shutdown if not down already and all resources used by it are given back to the hypervisor. The data structure is freed and should not be used thereafter if the call does not return an error. This function may requires priviledged access

+
domain:a domain object
Returns:0 in case of success and -1 in case of failure.
+
+

virDomainFree ()

int	virDomainFree			(virDomainPtr domain)
+

Free the domain object. The running instance is kept alive. The data structure is freed and should not be used thereafter.

+
domain:a domain object
Returns:0 in case of success and -1 in case of failure.
+
+

virDomainGetID ()

unsigned int	virDomainGetID		(virDomainPtr domain)
+

Get the hypervisor ID number for the domain

+
domain:a domain object
Returns:the domain ID number or (unsigned int) -1 in case of error
+
+

virDomainGetInfo ()

int	virDomainGetInfo		(virDomainPtr domain, 
virDomainInfoPtr info)
+

Extract information about a domain. Note that if the connection used to get the domain is limited only a partial set of the informations can be extracted.

+
domain:a domain object
info:pointer to a virDomainInfo structure allocated by the user
Returns:0 in case of success and -1 in case of failure.
+
+

virDomainGetMaxMemory ()

unsigned long	virDomainGetMaxMemory	(virDomainPtr domain)
+

Retrieve the maximum amount of physical memory allocated to a domain. If domain is NULL, then this get the amount of memory reserved to Domain0 i.e. the domain where the application runs.

+
domain:a domain object or NULL
Returns:the memory size in kilobytes or 0 in case of error.
+
+

virDomainGetName ()

const char *	virDomainGetName	(virDomainPtr domain)
+

Get the public name for that domain

+
domain:a domain object
Returns:a pointer to the name or NULL, the string need not be deallocated its lifetime will be the same as the domain object.
+
+

virDomainGetOSType ()

char *	virDomainGetOSType		(virDomainPtr domain)
+

Get the type of domain operation system.

+
domain:a domain object
Returns:the new string or NULL in case of error, the string must be freed by the caller.
+
+

virDomainGetUUID ()

int	virDomainGetUUID		(virDomainPtr domain, 
unsigned char * uuid)
+

Get the UUID for a domain

+
domain:a domain object
uuid:pointer to a 16 bytes array
Returns:-1 in case of error, 0 in case of success
+
+

virDomainGetXMLDesc ()

char *	virDomainGetXMLDesc		(virDomainPtr domain, 
int flags)
+

Provide an XML description of the domain. The description may be reused later to relaunch the domain with virDomainCreateLinux().

+
domain:a domain object
flags:and OR'ed set of extraction flags, not used yet
Returns:a 0 terminated UTF-8 encoded XML instance, or NULL in case of error. the caller must free() the returned value.
+
+

virDomainLookupByID ()

virDomainPtr	virDomainLookupByID	(virConnectPtr conn, 
int id)
+

Try to find a domain based on the hypervisor ID number

+
conn:pointer to the hypervisor connection
id:the domain ID number
Returns:a new domain object or NULL in case of failure
+
+

virDomainLookupByName ()

virDomainPtr	virDomainLookupByName	(virConnectPtr conn, 
const char * name)
+

Try to lookup a domain on the given hypervisor based on its name.

+
conn:pointer to the hypervisor connection
name:name for the domain
Returns:a new domain object or NULL in case of failure
+
+

virDomainLookupByUUID ()

virDomainPtr	virDomainLookupByUUID	(virConnectPtr conn, 
const unsigned char * uuid)
+

Try to lookup a domain on the given hypervisor based on its UUID.

+
conn:pointer to the hypervisor connection
uuid:the UUID string for the domain
Returns:a new domain object or NULL in case of failure
+
+

virDomainReboot ()

int	virDomainReboot			(virDomainPtr domain, 
unsigned int flags)
+

Reboot a domain, the domain object is still usable there after but the domain OS is being stopped for a restart. Note that the guest OS may ignore the request.

+
domain:a domain object
flags:extra flags for the reboot operation, not used yet
Returns:0 in case of success and -1 in case of failure.
+
+

virDomainRestore ()

int	virDomainRestore		(virConnectPtr conn, 
const char * from)
+

This method will restore a domain saved to disk by virDomainSave().

+
conn:pointer to the hypervisor connection
from:path to the
Returns:0 in case of success and -1 in case of failure.
+
+

virDomainResume ()

int	virDomainResume			(virDomainPtr domain)
+

Resume an suspended domain, the process is restarted from the state where it was frozen by calling virSuspendDomain(). This function may requires priviledged access

+
domain:a domain object
Returns:0 in case of success and -1 in case of failure.
+
+

virDomainSave ()

int	virDomainSave			(virDomainPtr domain, 
const char * to)
+

This method will suspend a domain and save its memory contents to a file on disk. After the call, if successful, the domain is not listed as running anymore (this may be a problem). Use virDomainRestore() to restore a domain after saving.

+
domain:a domain object
to:path for the output file
Returns:0 in case of success and -1 in case of failure.
+
+

virDomainSetMaxMemory ()

int	virDomainSetMaxMemory		(virDomainPtr domain, 
unsigned long memory)
+

Dynamically change the maximum amount of physical memory allocated to a domain. If domain is NULL, then this change the amount of memory reserved to Domain0 i.e. the domain where the application runs. This function requires priviledged access to the hypervisor.

+
domain:a domain object or NULL
memory:the memory size in kilobytes
Returns:0 in case of success and -1 in case of failure.
+
+

virDomainSetMemory ()

int	virDomainSetMemory		(virDomainPtr domain, 
unsigned long memory)
+

Dynamically change the target amount of physical memory allocated to a domain. If domain is NULL, then this change the amount of memory reserved to Domain0 i.e. the domain where the application runs. This function may requires priviledged access to the hypervisor.

+
domain:a domain object or NULL
memory:the memory size in kilobytes
Returns:0 in case of success and -1 in case of failure.
+
+

virDomainShutdown ()

int	virDomainShutdown		(virDomainPtr domain)
+

Shutdown a domain, the domain object is still usable there after but the domain OS is being stopped. Note that the guest OS may ignore the request. TODO: should we add an option for reboot, knowing it may not be doable in the general case ?

+
domain:a domain object
Returns:0 in case of success and -1 in case of failure.
+
+

virDomainSuspend ()

int	virDomainSuspend		(virDomainPtr domain)
+

Suspends an active domain, the process is frozen without further access to CPU resources and I/O but the memory used by the domain at the hypervisor level will stay allocated. Use virDomainResume() to reactivate the domain. This function may requires priviledged access.

+
domain:a domain object
Returns:0 in case of success and -1 in case of failure.
+
+ +
+
+
+

virNodeGetInfo ()

int	virNodeGetInfo			(virConnectPtr conn, 
virNodeInfoPtr info)
+

Extract hardware information about the node.

+
conn:pointer to the hypervisor connection
info:pointer to a virNodeInfo structure allocated by the user
Returns:0 in case of success and -1 in case of failure.
+
+
+
+ + diff --git a/docs/devhelp/libvirt-virterror.html b/docs/devhelp/libvirt-virterror.html new file mode 100644 index 0000000000..4e069fb920 --- /dev/null +++ b/docs/devhelp/libvirt-virterror.html @@ -0,0 +1,184 @@ + + + + + virterror: error handling interfaces for the libvirt library + + + + + + + + + + + + + + + +

+ virterror +

+

virterror - error handling interfaces for the libvirt library

+

Provides the interfaces of the libvirt library to handle errors raised while using the library.

+

Author(s): Daniel Veillard <veillard@redhat.com>

+
+

Synopsis

+
typedef virError * virErrorPtr;
+typedef enum virErrorLevel;
+typedef enum virErrorDomain;
+typedef enum virErrorNumber;
+typedef struct _virError virError;
+int	virCopyLastError		(virErrorPtr to);
+void	virConnSetErrorFunc		(virConnectPtr conn, 
void * userData,
virErrorFunc handler); +void virResetLastError (void); +typedef void virErrorFunc (void * userData,
virErrorPtr error); +void virResetError (virErrorPtr err); +virErrorPtr virConnGetLastError (virConnectPtr conn); +void virDefaultErrorFunc (virErrorPtr err); +virErrorPtr virGetLastError (void); +void virSetErrorFunc (void * userData,
virErrorFunc handler); +int virConnCopyLastError (virConnectPtr conn,
virErrorPtr to); +void virConnResetLastError (virConnectPtr conn); +
+
+
+

Description

+
+
+

Details

+
+

Structure virError

struct _virError {
+    int	code	: The error code, a virErrorNumber
+    int	domain	: What part of the library raised this error
+    char *	message	: human-readable informative error message
+    virErrorLevel	level	: how consequent is the error
+    virConnectPtr	conn	: the connection if available
+    virDomainPtr	dom	: the domain if available
+    char *	str1	: extra string information
+    char *	str2	: extra string information
+    char *	str3	: extra string information
+    int	int1	: extra number information
+    int	int2	: extra number information
+} virError;
+

+

+
+

Enum virErrorDomain

enum virErrorDomain {
+    VIR_FROM_NONE = 0
+    VIR_FROM_XEN = 1 /* Error at Xen hypervisor layer */
+    VIR_FROM_XEND = 2 /* Error at connection with xend daemon */
+    VIR_FROM_XENSTORE = 3 /* Error at connection with xen store */
+    VIR_FROM_SEXPR = 4 /* Error in the S-Epression code */
+    VIR_FROM_XML = 5 /* Error in the XML code */
+    VIR_FROM_DOM = 6 /*  Error when operating on a domain */
+};
+

+

+
+

Enum virErrorLevel

enum virErrorLevel {
+    VIR_ERR_NONE = 0
+    VIR_ERR_WARNING = 1 /* A simple warning */
+    VIR_ERR_ERROR = 2 /*  An error */
+};
+

+

+
+

Enum virErrorNumber

enum virErrorNumber {
+    VIR_ERR_OK = 0
+    VIR_ERR_INTERNAL_ERROR = 1 /* internal error */
+    VIR_ERR_NO_MEMORY = 2 /* memory allocation failure */
+    VIR_ERR_NO_SUPPORT = 3 /* no support for this connection */
+    VIR_ERR_UNKNOWN_HOST = 4 /* could not resolve hostname */
+    VIR_ERR_NO_CONNECT = 5 /* can't connect to hypervisor */
+    VIR_ERR_INVALID_CONN = 6 /* invalid connection object */
+    VIR_ERR_INVALID_DOMAIN = 7 /* invalid domain object */
+    VIR_ERR_INVALID_ARG = 8 /* invalid function argument */
+    VIR_ERR_OPERATION_FAILED = 9 /* a command to hypervisor failed */
+    VIR_ERR_GET_FAILED = 10 /* a HTTP GET command to failed */
+    VIR_ERR_POST_FAILED = 11 /* a HTTP POST command to failed */
+    VIR_ERR_HTTP_ERROR = 12 /* unexpected HTTP error code */
+    VIR_ERR_SEXPR_SERIAL = 13 /* failure to serialize an S-Expr */
+    VIR_ERR_NO_XEN = 14 /* could not open Xen hypervisor control */
+    VIR_ERR_XEN_CALL = 15 /* failure doing an hypervisor call */
+    VIR_ERR_OS_TYPE = 16 /* unknown OS type */
+    VIR_ERR_NO_KERNEL = 17 /* missing kernel information */
+    VIR_ERR_NO_ROOT = 18 /* missing root device information */
+    VIR_ERR_NO_SOURCE = 19 /* missing source device information */
+    VIR_ERR_NO_TARGET = 20 /* missing target device information */
+    VIR_ERR_NO_NAME = 21 /* missing domain name information */
+    VIR_ERR_NO_OS = 22 /* missing domain OS information */
+    VIR_ERR_NO_DEVICE = 23 /* missing domain devices information */
+    VIR_ERR_NO_XENSTORE = 24 /* could not open Xen Store control */
+    VIR_ERR_DRIVER_FULL = 25 /* too many drivers registered */
+    VIR_ERR_CALL_FAILED = 26 /*  not supported by the drivers */
+};
+

+

+
+

Typedef virErrorPtr

virError * virErrorPtr;
+

+

+
+

Function type virErrorFunc

void	virErrorFunc			(void * userData, 
virErrorPtr error)
+

Signature of a function to use when there is an error raised by the library.

+
userData:user provided data for the error callback
error:the error being raised.
+
+

virConnCopyLastError ()

int	virConnCopyLastError		(virConnectPtr conn, 
virErrorPtr to)
+

Copy the content of the last error caught on that connection One will need to free the result with virResetError()

+
conn:pointer to the hypervisor connection
to:target to receive the copy
Returns:0 if no error was found and the error code otherwise and -1 in case of parameter error.
+
+

virConnGetLastError ()

virErrorPtr	virConnGetLastError	(virConnectPtr conn)
+

Provide a pointer to the last error caught on that connection Simpler but may not be suitable for multithreaded accesses, in which case use virConnCopyLastError()

+
conn:pointer to the hypervisor connection
Returns:a pointer to the last error or NULL if none occured.
+
+

virConnResetLastError ()

void	virConnResetLastError		(virConnectPtr conn)
+

Reset the last error caught on that connection

+
conn:pointer to the hypervisor connection
+
+

virConnSetErrorFunc ()

void	virConnSetErrorFunc		(virConnectPtr conn, 
void * userData,
virErrorFunc handler)
+

Set a connection error handling function, if @handler is NULL it will reset to default which is to pass error back to the global library handler.

+
conn:pointer to the hypervisor connection
userData:pointer to the user data provided in the handler callback
handler:the function to get called in case of error or NULL
+
+

virCopyLastError ()

int	virCopyLastError		(virErrorPtr to)
+

Copy the content of the last error caught at the library level One will need to free the result with virResetError()

+
to:target to receive the copy
Returns:0 if no error was found and the error code otherwise and -1 in case of parameter error.
+
+

virDefaultErrorFunc ()

void	virDefaultErrorFunc		(virErrorPtr err)
+

Default routine reporting an error to stderr.

+
err:pointer to the error.
+
+

virGetLastError ()

virErrorPtr	virGetLastError		(void)
+

Provide a pointer to the last error caught at the library level Simpler but may not be suitable for multithreaded accesses, in which case use virCopyLastError()

+
Returns:a pointer to the last error or NULL if none occured.
+
+

virResetError ()

void	virResetError			(virErrorPtr err)
+

Reset the error being pointed to

+
err:pointer to the virError to clean up
+
+ +
+

virSetErrorFunc ()

void	virSetErrorFunc			(void * userData, 
virErrorFunc handler)
+

Set a library global error handling function, if @handler is NULL, it will reset to default printing on stderr. The error raised there are those for which no handler at the connection level could caught.

+
userData:pointer to the user data provided in the handler callback
handler:the function to get called in case of error or NULL
+
+
+
+ + diff --git a/docs/examples/.cvsignore b/docs/examples/.cvsignore new file mode 100644 index 0000000000..5f28847a8a --- /dev/null +++ b/docs/examples/.cvsignore @@ -0,0 +1,5 @@ +.memdump +Makefile.in +Makefile +info1 +suspend diff --git a/include/libvirt.h b/include/libvirt.h index f1848d0636..0e2e65eafc 100644 --- a/include/libvirt.h +++ b/include/libvirt.h @@ -274,6 +274,17 @@ int virDomainSetMemory (virDomainPtr domain, char * virDomainGetXMLDesc (virDomainPtr domain, int flags); +/* + * defined but not running domains + */ +virDomainPtr virDomainDefineXML (virConnectPtr conn, + const char *xml); +int virDomainUndefine (virDomainPtr domain); +int virConnectListDefinedDomains(virConnectPtr conn, + const char **names, + int maxnames); +int virDomainCreate (virDomainPtr domain); + #ifdef __cplusplus } #endif diff --git a/include/libvirt.h.in b/include/libvirt.h.in index d4dc2a24bc..1846bdda5d 100644 --- a/include/libvirt.h.in +++ b/include/libvirt.h.in @@ -274,6 +274,17 @@ int virDomainSetMemory (virDomainPtr domain, char * virDomainGetXMLDesc (virDomainPtr domain, int flags); +/* + * defined but not running domains + */ +virDomainPtr virDomainDefineXML (virConnectPtr conn, + const char *xml); +int virDomainUndefine (virDomainPtr domain); +int virConnectListDefinedDomains(virConnectPtr conn, + const char **names, + int maxnames); +int virDomainCreate (virDomainPtr domain); + #ifdef __cplusplus } #endif diff --git a/include/libvirt/libvirt.h b/include/libvirt/libvirt.h index f1848d0636..0e2e65eafc 100644 --- a/include/libvirt/libvirt.h +++ b/include/libvirt/libvirt.h @@ -274,6 +274,17 @@ int virDomainSetMemory (virDomainPtr domain, char * virDomainGetXMLDesc (virDomainPtr domain, int flags); +/* + * defined but not running domains + */ +virDomainPtr virDomainDefineXML (virConnectPtr conn, + const char *xml); +int virDomainUndefine (virDomainPtr domain); +int virConnectListDefinedDomains(virConnectPtr conn, + const char **names, + int maxnames); +int virDomainCreate (virDomainPtr domain); + #ifdef __cplusplus } #endif diff --git a/include/libvirt/libvirt.h.in b/include/libvirt/libvirt.h.in index d4dc2a24bc..1846bdda5d 100644 --- a/include/libvirt/libvirt.h.in +++ b/include/libvirt/libvirt.h.in @@ -274,6 +274,17 @@ int virDomainSetMemory (virDomainPtr domain, char * virDomainGetXMLDesc (virDomainPtr domain, int flags); +/* + * defined but not running domains + */ +virDomainPtr virDomainDefineXML (virConnectPtr conn, + const char *xml); +int virDomainUndefine (virDomainPtr domain); +int virConnectListDefinedDomains(virConnectPtr conn, + const char **names, + int maxnames); +int virDomainCreate (virDomainPtr domain); + #ifdef __cplusplus } #endif diff --git a/include/libvirt/virterror.h b/include/libvirt/virterror.h index 1fda6c9b3d..7ac908845c 100644 --- a/include/libvirt/virterror.h +++ b/include/libvirt/virterror.h @@ -101,7 +101,9 @@ typedef enum { VIR_ERR_NO_DEVICE, /* missing domain devices information */ VIR_ERR_NO_XENSTORE,/* could not open Xen Store control */ VIR_ERR_DRIVER_FULL, /* too many drivers registered */ - VIR_ERR_CALL_FAILED /* not supported by the drivers */ + VIR_ERR_CALL_FAILED, /* not supported by the drivers */ + VIR_ERR_XML_ERROR, /* an XML description is not well formed or broken */ + VIR_ERR_DOM_EXIST /* the domain already exist */ } virErrorNumber; /** diff --git a/include/virterror.h b/include/virterror.h index 1fda6c9b3d..7ac908845c 100644 --- a/include/virterror.h +++ b/include/virterror.h @@ -101,7 +101,9 @@ typedef enum { VIR_ERR_NO_DEVICE, /* missing domain devices information */ VIR_ERR_NO_XENSTORE,/* could not open Xen Store control */ VIR_ERR_DRIVER_FULL, /* too many drivers registered */ - VIR_ERR_CALL_FAILED /* not supported by the drivers */ + VIR_ERR_CALL_FAILED, /* not supported by the drivers */ + VIR_ERR_XML_ERROR, /* an XML description is not well formed or broken */ + VIR_ERR_DOM_EXIST /* the domain already exist */ } virErrorNumber; /** diff --git a/src/.cvsignore b/src/.cvsignore new file mode 100644 index 0000000000..69917212fa --- /dev/null +++ b/src/.cvsignore @@ -0,0 +1 @@ +virsh diff --git a/src/hash.c b/src/hash.c index b231e7c5ed..897c585602 100644 --- a/src/hash.c +++ b/src/hash.c @@ -636,6 +636,7 @@ virGetDomain(virConnectPtr conn, const char *name, const char *uuid) { } ret->magic = VIR_DOMAIN_MAGIC; ret->conn = conn; + ret->handle = -1; if (uuid != NULL) memcpy(&(ret->uuid[0]), uuid, 16); @@ -700,6 +701,8 @@ virFreeDomain(virConnectPtr conn, virDomainPtr domain) { domain->handle = -1; if (domain->path != NULL) free(domain->path); + if (domain->xml) + free(domain->xml); if (domain->name) free(domain->name); free(domain); diff --git a/src/internal.h b/src/internal.h index a3d81e7a22..9ac0d99a3e 100644 --- a/src/internal.h +++ b/src/internal.h @@ -128,7 +128,8 @@ struct _virConnect { */ enum { - DOMAIN_IS_SHUTDOWN = (1 << 0) /* the domain is being shutdown */ + DOMAIN_IS_SHUTDOWN = (1 << 0), /* the domain is being shutdown */ + DOMAIN_IS_DEFINED = (1 << 1) /* the domain is defined not running */ } virDomainFlags; /** @@ -145,6 +146,7 @@ struct _virDomain { int handle; /* internal handle for the domnain ID */ int flags; /* extra flags */ unsigned char uuid[16]; /* the domain unique identifier */ + char *xml; /* the XML description for defined domains */ }; /* diff --git a/src/libvirt.c b/src/libvirt.c index 1b5ee111b9..a153fbae47 100644 --- a/src/libvirt.c +++ b/src/libvirt.c @@ -18,6 +18,9 @@ #include #include +#include +#include + #include #include "internal.h" @@ -1411,3 +1414,161 @@ virNodeGetInfo(virConnectPtr conn, virNodeInfoPtr info) { } return(0); } + +/************************************************************************ + * * + * Handling of defined but not running domains * + * * + ************************************************************************/ + +/** + * virDomainDefineXML: + * @conn: pointer to the hypervisor connection + * @xml: the XML description for the domain, preferably in UTF-8 + * + * define a domain, but does not start it + * + * Returns NULL in case of error, a pointer to the domain otherwise + */ +virDomainPtr +virDomainDefineXML(virConnectPtr conn, const char *xml) { + virDomainPtr ret = NULL; + const char *name = NULL; + xmlDocPtr doc = NULL; + xmlXPathObjectPtr obj = NULL; + xmlXPathContextPtr ctxt = NULL; + + if (!VIR_IS_CONNECT(conn)) { + virLibConnError(conn, VIR_ERR_INVALID_CONN, __FUNCTION__); + return (NULL); + } + if (xml == NULL) { + virLibConnError(conn, VIR_ERR_INVALID_ARG, __FUNCTION__); + return (NULL); + } + + /* + * Check the XML description is at least well formed and extract the + * name. + * TODO: a full validation based on RNG for example should be done there + */ + doc = xmlReadMemory(xml, strlen(xml), "domain_define.xml", NULL, 0); + if (doc == NULL) { + virLibConnError(conn, VIR_ERR_XML_ERROR, __FUNCTION__); + goto done; + } + ctxt = xmlXPathNewContext(doc); + if (ctxt == NULL) { + goto done; + } + obj = xmlXPathEval(BAD_CAST "string(/domain/name[1])", ctxt); + if ((obj == NULL) || (obj->type != XPATH_STRING) || + (obj->stringval == NULL) || (obj->stringval[0] == 0)) { + virLibConnError(conn, VIR_ERR_NO_NAME, xml); + goto done; + } + name = (const char *) obj->stringval; + + /* + * Now look it up in the domain pool and check it's not an already run + * domain. + */ + ret = virGetDomain(conn, name, NULL); + if (ret == NULL) { + goto done; + } + /* + * TODO: the lifecycle of domains, especially predefined ones need to be + * explicitely written down + */ + if (ret->handle != -1) { + virLibConnError(conn, VIR_ERR_DOM_EXIST, name); + virFreeDomain(conn, ret); + ret = NULL; + goto done; + } + if ((ret->uses > 1) && (!(ret->flags & DOMAIN_IS_DEFINED))) { + virLibConnError(conn, VIR_ERR_DOM_EXIST, name); + virFreeDomain(conn, ret); + ret = NULL; + goto done; + } + ret->flags |= DOMAIN_IS_DEFINED; + if (ret->xml != NULL) { + free(ret->xml); + } + ret->xml = strdup(xml); + if (ret->xml == NULL) { + virLibConnError(conn, VIR_ERR_INVALID_CONN, __FUNCTION__); + virFreeDomain(conn, ret); + ret = NULL; + goto done; + } + /* TODO shall we keep a list of defined domains there ? */ + +done: + if (obj != NULL) + xmlXPathFreeObject(obj); + if (ctxt != NULL) + xmlXPathFreeContext(ctxt); + if (doc != NULL) + xmlFreeDoc(doc); + return(ret); +} + +/** + * virDomainUndefine: + * @domain: pointer to a defined domain + * + * undefine a domain but does not stop it if it is running + * + * Returns 0 in case of success, -1 in case of error + */ +int +virDomainUndefine(virDomainPtr domain) { + int ret; + + if (!VIR_IS_CONNECTED_DOMAIN(domain)) { + virLibDomainError(domain, VIR_ERR_INVALID_DOMAIN, __FUNCTION__); + return (-1); + } + /* TODO shall we keep a list of defined domains there ? */ + + ret = virFreeDomain(domain->conn, domain); + if (ret < 0) + return(-1); + return(0); +} + +/** + * virConnectListDefinedDomains: + * @conn: pointer to the hypervisor connection + * @names: pointer to an array to store the names + * @maxnames: size of the array + * + * list the defined domains, stores the pointers to the names in @names + * + * Returns the number of names provided in the array or -1 in case of error + */ +int +virConnectListDefinedDomains(virConnectPtr conn, const char **names, + int maxnames) { + TODO + return(-1); +} + +/** + * virDomainCreate: + * @domain: pointer to a defined domain + * + * launch a defined domain. If the call succeed the domain moves from the + * defined to the running domains pools. + * + * Returns 0 in case of success, -1 in case of error + */ +int +virDomainCreate(virDomainPtr domain) { + + return(-1); +} + diff --git a/src/virterror.c b/src/virterror.c index e34f5591c7..de895988af 100644 --- a/src/virterror.c +++ b/src/virterror.c @@ -503,6 +503,18 @@ __virErrorMsg(virErrorNumber error, const char *info) else errmsg = "library call %s failed, possibly not supported"; break; + case VIR_ERR_XML_ERROR: + if (info == NULL) + errmsg = "XML description not well formed or invalid"; + else + errmsg = "XML description for %s is not well formed or invalid"; + break; + case VIR_ERR_DOM_EXIST: + if (info == NULL) + errmsg = "this domain exists already"; + else + errmsg = "domain %s exists already"; + break; } return (errmsg); } diff --git a/src/xml.h b/src/xml.h index 2d75b007bf..8d63b34029 100644 --- a/src/xml.h +++ b/src/xml.h @@ -16,17 +16,17 @@ extern "C" { * * A buffer structure. */ - typedef struct _virBuffer virBuffer; - typedef virBuffer *virBufferPtr; - struct _virBuffer { - char *content; /* The buffer content UTF8 */ - unsigned int use; /* The buffer size used */ - unsigned int size; /* The buffer size */ - }; +typedef struct _virBuffer virBuffer; +typedef virBuffer *virBufferPtr; +struct _virBuffer { + char *content; /* The buffer content UTF8 */ + unsigned int use; /* The buffer size used */ + unsigned int size; /* The buffer size */ +}; - int virBufferAdd(virBufferPtr buf, const char *str, int len); - int virBufferVSprintf(virBufferPtr buf, const char *format, ...); - char *virDomainParseXMLDesc(const char *xmldesc, char **name); +int virBufferAdd(virBufferPtr buf, const char *str, int len); +int virBufferVSprintf(virBufferPtr buf, const char *format, ...); +char *virDomainParseXMLDesc(const char *xmldesc, char **name); #ifdef __cplusplus }