From 4faeeb1041497b3c5c59857f3cfdfdad84f56d0f Mon Sep 17 00:00:00 2001 From: Daniel Veillard Date: Mon, 27 Mar 2006 15:24:36 +0000 Subject: [PATCH] * doc/*: updated module list and rebuilt * include/libvirt.h include/libvirt.h.in: added intialization function * include/virterror.h src/virterror.c: one more error code * src/internal.h: first part of Jim's format checking * src/libvirt.c src/xen_internal.[ch] src/xend_internal.[ch] src/xs_internal.[ch]: initialization and registration of drivers Daniel --- ChangeLog | 9 ++++ docs/APIchunk0.html | 20 +++++--- docs/APIchunk1.html | 50 +++++-------------- docs/APIchunk2.html | 84 +++++++++++++++++--------------- docs/APIfiles.html | 6 ++- docs/APIsymbols.html | 4 ++ docs/apibuild.py | 6 +++ docs/architecture.html | 24 +++++++-- docs/html/book1.html | 2 +- docs/html/index.html | 2 +- docs/html/libvirt-lib.html | 2 +- docs/html/libvirt-libvirt.html | 7 ++- docs/html/libvirt-virterror.html | 25 +++++----- docs/libvir.html | 32 +++++++++++- docs/libvirt-api.xml | 33 ++++++++----- docs/libvirt-refs.xml | 60 ++++++++++++++++++++--- include/libvirt.h | 2 + include/libvirt.h.in | 2 + include/libvirt/libvirt.h | 2 + include/libvirt/libvirt.h.in | 2 + include/libvirt/virterror.h | 1 + include/virterror.h | 1 + src/internal.h | 14 ++++++ src/libvirt.c | 70 ++++++++++++++++++++++++++ src/virterror.c | 6 +++ src/xen_internal.c | 10 ++++ src/xen_internal.h | 1 + src/xend_internal.c | 10 ++++ src/xend_internal.h | 1 + src/xs_internal.c | 10 ++++ src/xs_internal.h | 1 + 31 files changed, 375 insertions(+), 124 deletions(-) diff --git a/ChangeLog b/ChangeLog index 1d2fbf65be..2955e1bcce 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,12 @@ +Mon Mar 27 17:22:16 CEST 2006 Daniel Veillard + + * doc/*: updated module list and rebuilt + * include/libvirt.h include/libvirt.h.in: added intialization function + * include/virterror.h src/virterror.c: one more error code + * src/internal.h: first part of Jim's format checking + * src/libvirt.c src/xen_internal.[ch] src/xend_internal.[ch] + src/xs_internal.[ch]: initialization and registration of drivers + Sat Mar 25 11:45:06 CET 2006 Daniel Veillard * src/Makefile.am: add driver.h to SOURCES as pointed by Jim Meyering diff --git a/docs/APIchunk0.html b/docs/APIchunk0.html index 5c5db71f4b..cd660cc403 100644 --- a/docs/APIchunk0.html +++ b/docs/APIchunk0.html @@ -1,9 +1,9 @@ API Alphabetic Index A-c for libvirt diff --git a/docs/APIchunk1.html b/docs/APIchunk1.html index 7efa812459..bae1da0356 100644 --- a/docs/APIchunk1.html +++ b/docs/APIchunk1.html @@ -1,9 +1,9 @@ -API Alphabetic Index d-n for libvirt

API Alphabetic Index d-n for libvirt

A-c -d-n -o-t -u-z +API Alphabetic Index d-m for libvirt

diff --git a/docs/APIchunk2.html b/docs/APIchunk2.html index bcd69b9960..f231f4a23f 100644 --- a/docs/APIchunk2.html +++ b/docs/APIchunk2.html @@ -1,10 +1,41 @@ -API Alphabetic Index o-t for libvirt

API Alphabetic Index o-t for libvirt

A-c -d-n -o-t -u-z -

Letter o:

object
virDomainCreateLinux
+API Alphabetic Index n-s for libvirt

API Alphabetic Index n-s for libvirt

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

Letter n:

name
virConnectGetType
+virDomainGetName
+virDomainLookupByName
+
need
virConnCopyLastError
+virConnectClose
+virCopyLastError
+virDomainGetName
+
needed
virConnectClose
+
new
virDomainCreateLinux
+virDomainGetOSType
+virDomainLookupByID
+virDomainLookupByName
+virDomainLookupByUUID
+
none
virConnGetLastError
+virGetLastError
+
not
virConnGetLastError
+virConnectClose
+virConnectGetVersion
+virDomainDestroy
+virDomainFree
+virDomainGetName
+virDomainGetXMLDesc
+virDomainSave
+virDomainShutdown
+virGetLastError
+virGetVersion
+
number
_virError
+virConnectListDomains
+virConnectNumOfDomains
+virDomainGetID
+virDomainLookupByID
+

Letter o:

object
virDomainCreateLinux
virDomainDestroy
virDomainFree
virDomainGetID
@@ -79,6 +110,7 @@ virResetError
virSetErrorFunc
pointing
_virDomainKernel
+
potential
virInitialize
printing
virSetErrorFunc
private
_virDomainInfo
priviledged
virConnectGetVersion
@@ -97,7 +129,8 @@
providing
LIBVIR_VERSION_NUMBER
public
virDomainGetName
publicly
_virDomainInfo
-

Letter r:

raised
_virError
+

Letter r:

race
virInitialize
+
raised
_virError
virErrorFunc
virSetErrorFunc
ramdisk
_virDomainKernel
@@ -137,6 +170,7 @@
reused
virDomainGetXMLDesc
root
_virDomainKernel
routine
virDefaultErrorFunc
+virInitialize
running
_virDomainInfo
virConnectClose
virConnectGetVersion
@@ -165,6 +199,7 @@ virDomainGetMaxMemory
virDomainSetMaxMemory
software
virConnectGetType
+
startup
virInitialize
state
_virDomainInfo
virDomainResume
static
virConnectGetType
@@ -195,44 +230,15 @@ virDomainSetMaxMemory
virDomainShutdown
virDomainSuspend
+virInitialize
successful
virDomainSave
suitable
virConnGetLastError
virGetLastError
suspend
virDomainSave
suspended
virDomainResume
system
virDomainGetOSType
-

Letter t:

target
virConnCopyLastError
-virCopyLastError
-
term
_virDomainInfo
-
terminated
virConnectGetType
-virDomainGetXMLDesc
-
that
virConnCopyLastError
-virConnGetLastError
-virConnResetLastError
-virDomainGetInfo
-virDomainGetName
-virDomainShutdown
-
their
virConnectListDomains
-
then
virConnectOpenReadOnly
-virDomainGetMaxMemory
-virDomainSetMaxMemory
-
there
virConnectClose
-virDomainShutdown
-virErrorFunc
-virSetErrorFunc
-
thereafter
virDomainDestroy
-virDomainFree
-
this
_virDomainInfo
-_virError
-virDomainGetMaxMemory
-virDomainSave
-virDomainSetMaxMemory
-
those
virSetErrorFunc
-
two
virGetVersion
-
type
virDomainGetOSType
-virGetVersion

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

diff --git a/docs/APIfiles.html b/docs/APIfiles.html index 034f5bff0f..e2af14b9d4 100644 --- a/docs/APIfiles.html +++ b/docs/APIfiles.html @@ -58,7 +58,9 @@ virDomainState
virDomainSuspend
virGetVersion
-

Module virterror:

VIR_ERR_ERROR
+virInitialize
+

Module virterror:

VIR_ERR_DRIVER_FULL
+VIR_ERR_ERROR
VIR_ERR_GET_FAILED
VIR_ERR_HTTP_ERROR
VIR_ERR_INTERNAL_ERROR
@@ -77,6 +79,7 @@ VIR_ERR_NO_SUPPORT
VIR_ERR_NO_TARGET
VIR_ERR_NO_XEN
+VIR_ERR_NO_XENSTORE
VIR_ERR_OK
VIR_ERR_OPERATION_FAILED
VIR_ERR_OS_TYPE
@@ -90,6 +93,7 @@ VIR_FROM_SEXPR
VIR_FROM_XEN
VIR_FROM_XEND
+VIR_FROM_XENSTORE
VIR_FROM_XML
_virError
virConnCopyLastError
diff --git a/docs/APIsymbols.html b/docs/APIsymbols.html index 62eb789b78..8d6ba646aa 100644 --- a/docs/APIsymbols.html +++ b/docs/APIsymbols.html @@ -17,6 +17,7 @@ VIR_DOMAIN_RUNNING
VIR_DOMAIN_SHUTDOWN
VIR_DOMAIN_SHUTOFF
+VIR_ERR_DRIVER_FULL
VIR_ERR_ERROR
VIR_ERR_GET_FAILED
VIR_ERR_HTTP_ERROR
@@ -36,6 +37,7 @@ VIR_ERR_NO_SUPPORT
VIR_ERR_NO_TARGET
VIR_ERR_NO_XEN
+VIR_ERR_NO_XENSTORE
VIR_ERR_OK
VIR_ERR_OPERATION_FAILED
VIR_ERR_OS_TYPE
@@ -49,6 +51,7 @@ VIR_FROM_SEXPR
VIR_FROM_XEN
VIR_FROM_XEND
+VIR_FROM_XENSTORE
VIR_FROM_XML

Letter _:

_virDomainInfo
_virDomainKernel
@@ -105,6 +108,7 @@ virErrorPtr
virGetLastError
virGetVersion
+virInitialize
virResetError
virResetLastError
virSetErrorFunc
diff --git a/docs/apibuild.py b/docs/apibuild.py index 712d4427aa..6e38f680e7 100755 --- a/docs/apibuild.py +++ b/docs/apibuild.py @@ -25,10 +25,16 @@ ignored_files = { "driver.h": "internal driver interfaces", "xend_internal.h": "internal includes and defines", "xend_internal.c": "internal code", + "xen_internal.h": "internal includes and defines", + "xen_internal.c": "internal code", + "xs_internal.h": "internal includes and defines", + "xs_internal.c": "internal code", "sexpr.h": "internal includes and defines", "sexpr.c": "internal code", "xml.h": "internal includes and defines", "xml.c": "internal code", + "xmlrpc.h": "internal include", + "xmlrpc.c": "internal code", } ignored_words = { diff --git a/docs/architecture.html b/docs/architecture.html index 3fcd25e5a5..5a30549fc3 100644 --- a/docs/architecture.html +++ b/docs/architecture.html @@ -1,7 +1,7 @@ -libvirt architecture

libvirt architecture

This is Xen specific since this is the only hypervisor supported at the -moment

When running in a Xen environment, programs using libvirt have to execute +libvirt architecture

libvirt architecture

This is in a large part Xen specific since this is the only hypervisor +supported at the moment

When running in a Xen environment, programs using libvirt have to execute in "Domain 0", which is the primary Linux OS loaded on the machine. That OS kernel provides most if not all of the actual drivers used by the set of domains. It also runs the Xen Store, a database of informations shared by the @@ -24,4 +24,22 @@ connect to initialize the library. It will try to open the read-only socket /var/run/xenstored/socket_ro to connect to the Xen Store and also try to use the RPC to the Xen daemon. In this case use of hypervisor calls and write to the Xen Store will not be possible, restraining the amount -of APIs available and slowing down information gathering about domains.

+of APIs available and slowing down information gathering about domains.

Internal architecture

As the previous section explains, libvirt can communicate using different +channels with the current hypervisor, and should also be able to use +different kind of hypervisor. To simplify the internal design, code, ease +maintainance and simplify the support of other virtualization engine the +internals have been structured as one core component, the libvirt.c module +acting as a front-end for the library API and a set of hypvisor drivers +defining a common set of routines. That way the Xen Daemon accces, the Xen +Store one, the Hypervisor hypercall are all isolated in separate C modules +implementing at least a subset of the common operations defined by the +drivers present in driver.h:

  • xend_internal: implements the driver functions though the Xen + Daemon
  • +
  • xs_internal: implements the subset of the driver availble though the + Xen Store
  • +
  • xen_internal: provide the implementation of the functions possible via + direct hypervisor access
  • +

Note that a given driver may only implement a subset of those functions, +for example saving a domain state to disk and restoring it is only possible +though the Xen Daemon, on the other hand all interfaces allow to query the +runtime state of a given domain.

diff --git a/docs/html/book1.html b/docs/html/book1.html index df7bf94f2c..276b5a2344 100644 --- a/docs/html/book1.html +++ b/docs/html/book1.html @@ -1,3 +1,3 @@ -Reference Manual for libvirt

Reference Manual for libvirt

Table of Contents

  • libvirt: core interfaces for the libvirt library
  • virterror: error handling interfaces for the libvirt library

+Reference Manual for libvirt

Reference Manual for libvirt

Table of Contents

  • libvirt: core interfaces for the libvirt library
  • virterror: error handling interfaces for the libvirt library

diff --git a/docs/html/index.html b/docs/html/index.html index df7bf94f2c..276b5a2344 100644 --- a/docs/html/index.html +++ b/docs/html/index.html @@ -1,3 +1,3 @@ -Reference Manual for libvirt

Reference Manual for libvirt

Table of Contents

  • libvirt: core interfaces for the libvirt library
  • virterror: error handling interfaces for the libvirt library

+Reference Manual for libvirt

Reference Manual for libvirt

Table of Contents

  • libvirt: core interfaces for the libvirt library
  • virterror: error handling interfaces for the libvirt library

diff --git a/docs/html/libvirt-lib.html b/docs/html/libvirt-lib.html index df7bf94f2c..276b5a2344 100644 --- a/docs/html/libvirt-lib.html +++ b/docs/html/libvirt-lib.html @@ -1,3 +1,3 @@ -Reference Manual for libvirt

Reference Manual for libvirt

Table of Contents

  • libvirt: core interfaces for the libvirt library
  • virterror: error handling interfaces for the libvirt library

+Reference Manual for libvirt

Reference Manual for libvirt

Table of Contents

  • libvirt: core interfaces for the libvirt library
  • virterror: error handling interfaces for the libvirt library

diff --git a/docs/html/libvirt-libvirt.html b/docs/html/libvirt-libvirt.html index 9136aad610..d260f3675f 100644 --- a/docs/html/libvirt-libvirt.html +++ b/docs/html/libvirt-libvirt.html @@ -41,6 +41,7 @@ The content of this structure is not made public by the API.
int	virDomainShutdown		(virDomainPtr domain)
int	virDomainSuspend		(virDomainPtr domain)
int	virGetVersion			(unsigned long * libVer, 
const char * type,
unsigned long * typeVer)
+
int	virInitialize			(void)

Description

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

Structure virConnect
struct _virConnect { @@ -120,7 +121,7 @@ The content of this structure is not made public by the API.

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.

Function: 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

Function: virDomainGetUUID

int	virDomainGetUUID		(virDomainPtr domain, 
unsigned char * uuid)
+
domain:a domain object
Returns:the new string or NULL in case of error, the string must be freed by the caller.

Function: 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

Function: 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().

@@ -144,4 +145,6 @@ The content of this structure is not made public by the API.

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.

Function: virGetVersion

int	virGetVersion			(unsigned long * libVer, 
const char * type,
unsigned long * typeVer)

Provides two information back, @libVer is the version of the library while @typeVer will be the version of the hypervisor type @type against which the library was compiled. If @type is NULL, "Xen" is assumed, if @type is unknown or not availble, an error code will be returned and @typeVer will be 0.

-
libVer:return value for the library version (OUT)
type:hypervisor type
typeVer:return value for the version of the hypervisor (OUT)
Returns:-1 in case of failure, 0 otherwise, and values for @libVer and @typeVer have the format major * 1,000,000 + minor * 1,000 + release.

+
libVer:return value for the library version (OUT)
type:hypervisor type
typeVer:return value for the version of the hypervisor (OUT)
Returns:-1 in case of failure, 0 otherwise, and values for @libVer and @typeVer have the format major * 1,000,000 + minor * 1,000 + release.

Function: virInitialize

int	virInitialize			(void)
+

Initialize the library. It's better to call this routine at startup in multithreaded applications to avoid potential race when initializing the library.

+
Returns:0 in case of success, -1 in case of error

diff --git a/docs/html/libvirt-virterror.html b/docs/html/libvirt-virterror.html index ab5f220954..f039897366 100644 --- a/docs/html/libvirt-virterror.html +++ b/docs/html/libvirt-virterror.html @@ -35,9 +35,10 @@ void virErrorFunc (void * userData,
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_SEXPR = 3 : Error in the S-Epression code - VIR_FROM_XML = 4 : Error in the XML code - VIR_FROM_DOM = 5 : Error when operating on a domain + 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
@@ -62,13 +63,15 @@ void	virErrorFunc			(void * userData, 
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 informations - VIR_ERR_NO_ROOT = 18 : missing root device informations - VIR_ERR_NO_SOURCE = 19 : missing source device informations - VIR_ERR_NO_TARGET = 20 : missing target device informations - VIR_ERR_NO_NAME = 21 : missing domain name informations - VIR_ERR_NO_OS = 22 : missing domain OS informations - VIR_ERR_NO_DEVICE = 23 : missing domain devices informations + 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 }

Function: 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()

@@ -93,4 +96,4 @@ void virErrorFunc (void * userData,
Function: 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

+
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/libvir.html b/docs/libvir.html index 34c767bad6..265848cc71 100644 --- a/docs/libvir.html +++ b/docs/libvir.html @@ -133,8 +133,8 @@ case at the moment, the code currently handle only local node accesses.

libvirt architecture

-

This is Xen specific since this is the only hypervisor supported at the -moment

+

This is in a large part Xen specific since this is the only hypervisor +supported at the moment

When running in a Xen environment, programs using libvirt have to execute in "Domain 0", which is the primary Linux OS loaded on the machine. That OS @@ -170,6 +170,34 @@ also try to use the RPC to the Xen daemon. In this case use of hypervisor calls and write to the Xen Store will not be possible, restraining the amount of APIs available and slowing down information gathering about domains.

+

Internal architecture

+ +

As the previous section explains, libvirt can communicate using different +channels with the current hypervisor, and should also be able to use +different kind of hypervisor. To simplify the internal design, code, ease +maintainance and simplify the support of other virtualization engine the +internals have been structured as one core component, the libvirt.c module +acting as a front-end for the library API and a set of hypvisor drivers +defining a common set of routines. That way the Xen Daemon accces, the Xen +Store one, the Hypervisor hypercall are all isolated in separate C modules +implementing at least a subset of the common operations defined by the +drivers present in driver.h:

+
    +
  • xend_internal: implements the driver functions though the Xen + Daemon
  • +
  • xs_internal: implements the subset of the driver availble though the + Xen Store
  • +
  • xen_internal: provide the implementation of the functions possible via + direct hypervisor access
  • +
+ +

Note that a given driver may only implement a subset of those functions, +for example saving a domain state to disk and restoring it is only possible +though the Xen Daemon, on the other hand all interfaces allow to query the +runtime state of a given domain.

+ +

+

Downloads

The latest versions of libvirt can be found on the + @@ -77,6 +78,7 @@ + @@ -90,12 +92,14 @@ + + @@ -140,6 +144,7 @@ + @@ -149,16 +154,17 @@ - - + + - - - - + + + + - + + @@ -167,12 +173,13 @@ - + - + - + + 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. @@ -338,7 +345,7 @@ Get the type of domain operation system. - + @@ -421,6 +428,10 @@ + + Initialize the library. It's better to call this routine at startup in multithreaded applications to avoid potential race when initializing the library. + + Reset the error being pointed to diff --git a/docs/libvirt-refs.xml b/docs/libvirt-refs.xml index d6a87e2972..32762087ab 100644 --- a/docs/libvirt-refs.xml +++ b/docs/libvirt-refs.xml @@ -18,6 +18,7 @@ + @@ -37,6 +38,7 @@ + @@ -50,6 +52,7 @@ + @@ -106,6 +109,7 @@ + @@ -131,6 +135,7 @@ + @@ -150,6 +155,7 @@ + @@ -163,6 +169,7 @@ + @@ -223,6 +230,7 @@ + @@ -382,8 +390,10 @@ + + @@ -403,6 +413,7 @@ + @@ -416,6 +427,7 @@ + @@ -511,6 +523,9 @@ + + + @@ -725,6 +740,9 @@ + + + @@ -751,6 +769,9 @@ + + + @@ -772,6 +793,9 @@ + + + @@ -791,6 +815,7 @@ + @@ -805,6 +830,7 @@ + @@ -1032,6 +1058,7 @@ + @@ -1131,6 +1158,9 @@ + + + @@ -1198,6 +1228,7 @@ + @@ -1278,11 +1309,15 @@ + + + + @@ -1330,8 +1365,6 @@ - - @@ -1450,6 +1483,9 @@ + + + @@ -1490,6 +1526,9 @@ + + + @@ -1575,6 +1614,7 @@ + @@ -1630,6 +1670,9 @@ + + + @@ -1679,6 +1722,7 @@ + @@ -1697,6 +1741,8 @@ + + @@ -1741,6 +1787,7 @@ + @@ -1753,8 +1800,6 @@ - - @@ -1859,6 +1904,7 @@ + @@ -1923,9 +1969,9 @@ - - - + + + diff --git a/include/libvirt.h b/include/libvirt.h index 2e9f995cf7..507c857e83 100644 --- a/include/libvirt.h +++ b/include/libvirt.h @@ -176,6 +176,8 @@ int virGetVersion (unsigned long *libVer, /* * Connection and disconnections to the Hypervisor */ +int virInitialize (void); + virConnectPtr virConnectOpen (const char *name); virConnectPtr virConnectOpenReadOnly (const char *name); int virConnectClose (virConnectPtr conn); diff --git a/include/libvirt.h.in b/include/libvirt.h.in index 83e8650445..7c4794c29f 100644 --- a/include/libvirt.h.in +++ b/include/libvirt.h.in @@ -176,6 +176,8 @@ int virGetVersion (unsigned long *libVer, /* * Connection and disconnections to the Hypervisor */ +int virInitialize (void); + virConnectPtr virConnectOpen (const char *name); virConnectPtr virConnectOpenReadOnly (const char *name); int virConnectClose (virConnectPtr conn); diff --git a/include/libvirt/libvirt.h b/include/libvirt/libvirt.h index 2e9f995cf7..507c857e83 100644 --- a/include/libvirt/libvirt.h +++ b/include/libvirt/libvirt.h @@ -176,6 +176,8 @@ int virGetVersion (unsigned long *libVer, /* * Connection and disconnections to the Hypervisor */ +int virInitialize (void); + virConnectPtr virConnectOpen (const char *name); virConnectPtr virConnectOpenReadOnly (const char *name); int virConnectClose (virConnectPtr conn); diff --git a/include/libvirt/libvirt.h.in b/include/libvirt/libvirt.h.in index 83e8650445..7c4794c29f 100644 --- a/include/libvirt/libvirt.h.in +++ b/include/libvirt/libvirt.h.in @@ -176,6 +176,8 @@ int virGetVersion (unsigned long *libVer, /* * Connection and disconnections to the Hypervisor */ +int virInitialize (void); + virConnectPtr virConnectOpen (const char *name); virConnectPtr virConnectOpenReadOnly (const char *name); int virConnectClose (virConnectPtr conn); diff --git a/include/libvirt/virterror.h b/include/libvirt/virterror.h index 430f5e88c1..69f8b10b2f 100644 --- a/include/libvirt/virterror.h +++ b/include/libvirt/virterror.h @@ -100,6 +100,7 @@ typedef enum { VIR_ERR_NO_OS, /* missing domain OS information */ 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 */ } virErrorNumber; /** diff --git a/include/virterror.h b/include/virterror.h index 430f5e88c1..69f8b10b2f 100644 --- a/include/virterror.h +++ b/include/virterror.h @@ -100,6 +100,7 @@ typedef enum { VIR_ERR_NO_OS, /* missing domain OS information */ 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 */ } virErrorNumber; /** diff --git a/src/internal.h b/src/internal.h index ce6428033d..e5436d227f 100644 --- a/src/internal.h +++ b/src/internal.h @@ -14,6 +14,7 @@ #include "hash.h" #include "libvirt.h" #include "virterror.h" +#include "driver.h" #ifdef __cplusplus extern "C" { @@ -35,6 +36,19 @@ extern "C" { #define ATTRIBUTE_UNUSED #endif +#ifndef __attribute__ +/* This feature is available in gcc versions 2.5 and later. */ +# if __GNUC__ < 2 || (__GNUC__ == 2 && __GNUC_MINOR__ < 5) +# define __attribute__(Spec) /* empty */ +# endif +/* The __-protected variants of `format' and `printf' attributes + are accepted by gcc versions 2.6.4 (effectively 2.7) and later. */ +# if __GNUC__ < 2 || (__GNUC__ == 2 && __GNUC_MINOR__ < 7) +# define __format__ format +# define __printf__ printf +# endif +#endif + /** * TODO: * diff --git a/src/libvirt.c b/src/libvirt.c index 5364e9304c..eedf52d00d 100644 --- a/src/libvirt.c +++ b/src/libvirt.c @@ -37,6 +37,45 @@ * - memory wrappers for malloc/free ? */ +#define MAX_DRIVERS 5 +static virDriverPtr virDriverTab[MAX_DRIVERS]; +static int initialized = 0; + +/** + * virInitialize: + * + * Initialize the library. It's better to call this routine at startup + * in multithreaded applications to avoid potential race when initializing + * the library. + * + * Returns 0 in case of success, -1 in case of error + */ +int +virInitialize(void) +{ + int i; + + if (initialized) + return(0); + + /* + * should not be needed but... + */ + for (i = 0;i < MAX_DRIVERS;i++) + virDriverTab[i] = NULL; + + /* + * Note that the order is important the first ones have a higher priority + */ + xenHypervisorRegister(); + xenDaemonRegister(); + xenStoreRegister(); + initialized = 1; + return(0); +} + + + /** * virLibConnError: * @conn: the connection if available @@ -84,6 +123,37 @@ virLibDomainError(virDomainPtr domain, virErrorNumber error, errmsg, info, NULL, 0, 0, errmsg, info); } +/** + * virRegisterDriver: + * @driver: pointer to a driver block + * + * Register a virtualization driver + * + * Returns the driver priority or -1 in case of error. + */ +int +virRegisterDriver(virDriverPtr driver) +{ + int i; + + if (driver == NULL) { + virLibConnError(NULL, VIR_ERR_INVALID_ARG, __FUNCTION__); + return(-1); + } + for (i = 0;i < MAX_DRIVERS;i++) { + if (virDriverTab[i] == driver) + return(i); + } + for (i = 0;i < MAX_DRIVERS;i++) { + if (virDriverTab[i] == NULL) { + virDriverTab[i] = driver; + return(i); + } + } + virLibConnError(NULL, VIR_ERR_INVALID_ARG, __FUNCTION__); + return(-1); +} + /** * virGetVersion: * @libVer: return value for the library version (OUT) diff --git a/src/virterror.c b/src/virterror.c index 95f3849940..ba7cd75d8e 100644 --- a/src/virterror.c +++ b/src/virterror.c @@ -491,6 +491,12 @@ __virErrorMsg(virErrorNumber error, const char *info) else errmsg = "missing devices informations for %s"; break; + case VIR_ERR_DRIVER_FULL: + if (info == NULL) + errmsg = "too many drivers registered"; + else + errmsg = "too many drivers registered in %s"; + break; } return (errmsg); } diff --git a/src/xen_internal.c b/src/xen_internal.c index 565d2c7537..abda84f2e7 100644 --- a/src/xen_internal.c +++ b/src/xen_internal.c @@ -69,6 +69,16 @@ static virDriver xenHypervisorDriver = { NULL /* domainRestore */ }; +/** + * xenHypervisorRegister: + * + * Registers the xenHypervisor driver + */ +void xenHypervisorRegister(void) +{ + virRegisterDriver(&xenHypervisorDriver); +} + /** * virXenError: * @conn: the connection if available diff --git a/src/xen_internal.h b/src/xen_internal.h index fa06393f11..e47b8c5ab8 100644 --- a/src/xen_internal.h +++ b/src/xen_internal.h @@ -18,6 +18,7 @@ extern "C" { #endif +void xenHypervisorRegister (void); int xenHypervisorOpen (virConnectPtr conn, const char *name, int flags); diff --git a/src/xend_internal.c b/src/xend_internal.c index e3ddbc0acd..aa2ff6b6bf 100644 --- a/src/xend_internal.c +++ b/src/xend_internal.c @@ -64,6 +64,16 @@ static virDriver xenDaemonDriver = { xenDaemonDomainRestore /* domainRestore */ }; +/** + * xenDaemonRegister: + * + * Registers the xenDaemon driver + */ +void xenDaemonRegister(void) +{ + virRegisterDriver(&xenDaemonDriver); +} + /** * xend_connection_type: * diff --git a/src/xend_internal.h b/src/xend_internal.h index 4c0317eec0..25addb9a8b 100644 --- a/src/xend_internal.h +++ b/src/xend_internal.h @@ -638,6 +638,7 @@ int xenDaemonOpen_unix(virConnectPtr xend, const char *path); int xend_log(virConnectPtr xend, char *buffer, size_t n_buffer); /* refactored ones */ +void xenDaemonRegister(void); int xenDaemonOpen(virConnectPtr conn, const char *name, int flags); int xenDaemonClose(virConnectPtr conn); int xenDaemonDomainSuspend(virDomainPtr domain); diff --git a/src/xs_internal.c b/src/xs_internal.c index 3898e5d166..4bcba392bc 100644 --- a/src/xs_internal.c +++ b/src/xs_internal.c @@ -59,6 +59,16 @@ static virDriver xenStoreDriver = { NULL /* domainRestore */ }; +/** + * xenStoreRegister: + * + * Registers the xenStore driver + */ +void xenStoreRegister(void) +{ + virRegisterDriver(&xenStoreDriver); +} + /** * virXenStoreError: * @conn: the connection if available diff --git a/src/xs_internal.h b/src/xs_internal.h index 2503d451ea..fdecf2bd9d 100644 --- a/src/xs_internal.h +++ b/src/xs_internal.h @@ -15,6 +15,7 @@ extern "C" { #endif +void xenStoreRegister (void); int xenStoreOpen (virConnectPtr conn, const char *name, int flags);