From ea9c089fa633b9fdca6edaa8f3169ceeedf79704 Mon Sep 17 00:00:00 2001 From: Daniel Veillard Date: Fri, 16 Dec 2005 12:16:41 +0000 Subject: [PATCH] * include/libvir.h include/libvir.h.in src/internal.h src/libvir.c: adding the virDomainShutdown() API * src/virsh.c: adding a shutdown command * docs/*: regenerated Daniel --- ChangeLog | 7 +++ NEWS | 3 ++ docs/APIchunk0.html | 36 ++++++-------- docs/APIchunk1.html | 18 ++++++- docs/APIchunk2.html | 5 +- docs/APIfiles.html | 4 +- docs/APIfunctions.html | 2 + docs/APIsymbols.html | 4 +- docs/html/libvir-libvir.html | 16 +++++-- docs/libvir-api.xml | 48 ++++++++++++------- docs/libvir-refs.xml | 91 ++++++++++++++++++++++++++---------- include/libvir.h | 12 +++-- include/libvir.h.in | 5 +- src/internal.h | 11 +++++ src/libvir.c | 71 ++++++++++++++++++++++++++++ src/virsh.c | 39 ++++++++++++++++ 16 files changed, 292 insertions(+), 80 deletions(-) diff --git a/ChangeLog b/ChangeLog index 61601bc1ba..b7d7e64478 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,10 @@ +Fri Dec 16 13:15:04 CET 2005 Daniel Veillard + + * include/libvir.h include/libvir.h.in src/internal.h src/libvir.c: + adding the virDomainShutdown() API + * src/virsh.c: adding a shutdown command + * docs/*: regenerated + Fri Dec 16 01:43:18 CET 2005 Karel Zak * include/libvir.h.in: add missing declaration of virDomainGetXMLDesc() diff --git a/NEWS b/NEWS index 656ec62c28..625216cf8b 100644 --- a/NEWS +++ b/NEWS @@ -1,2 +1,5 @@ +Thu Dec 15 2005 + - project announced publicly + Wed Nov 2 2005 - the very first work was checked in a CVS on veillard.com diff --git a/docs/APIchunk0.html b/docs/APIchunk0.html index 3eb3fd7af6..be502808db 100644 --- a/docs/APIchunk0.html +++ b/docs/APIchunk0.html @@ -26,6 +26,7 @@ A:link, A:visited, A:active { text-decoration: underline } virConnectGetVersion
virDomainGetID
virDomainGetName
+virDomainGetOSType

Letter H:

Hypervisor
virConnectClose
virConnectGetType
virConnectGetVersion
@@ -43,6 +44,7 @@ A:link, A:visited, A:active { text-decoration: underline } virDomainCreateLinux
virDomainGetMaxMemory
virDomainGetName
+virDomainGetOSType
virDomainGetXMLDesc
virDomainLookupByID
virDomainLookupByName
@@ -57,8 +59,10 @@ A:link, A:visited, A:active { text-decoration: underline }

Letter R:

Read-Only
virConnectGetVersion
Resume
virDomainResume
Retrieve
virDomainGetMaxMemory
-

Letter S:

Suspends
virDomainSuspend
+

Letter S:

Shutdown
virDomainShutdown
+
Suspends
virDomainSuspend

Letter T:

TODO:
_virDomainInfo
+virDomainShutdown
This
virConnectClose
virConnectGetVersion
virConnectOpen
@@ -86,6 +90,8 @@ A:link, A:visited, A:active { text-decoration: underline } virConnectNumOfDomains
virDomainSuspend
add
_virDomainInfo
+virDomainShutdown
+
after
virDomainShutdown
against
virGetVersion
alive
virDomainFree
all
virDomainDestroy
@@ -114,8 +120,10 @@ A:link, A:visited, A:active { text-decoration: underline } virGetVersion
based
virDomainLookupByID
virDomainLookupByName
+
being
virDomainShutdown
below
_virDomainInfo
-
but
virDomainSuspend
+
but
virDomainShutdown
+virDomainSuspend

Letter c:

call
_virDomainInfo
virConnectGetVersion
virDomainDestroy
@@ -128,26 +136,6 @@ A:link, A:visited, A:active { text-decoration: underline } virConnectGetVersion
virDomainGetInfo
capacities
virConnectGetVersion
-
case
virConnectClose
-virConnectGetType
-virConnectGetVersion
-virConnectListDomains
-virConnectNumOfDomains
-virConnectOpen
-virConnectOpenReadOnly
-virDomainCreateLinux
-virDomainDestroy
-virDomainFree
-virDomainGetID
-virDomainGetInfo
-virDomainGetMaxMemory
-virDomainGetXMLDesc
-virDomainLookupByID
-virDomainLookupByName
-virDomainResume
-virDomainSetMaxMemory
-virDomainSuspend
-virGetVersion
change
virDomainSetMaxMemory
changes
virDomainGetXMLDesc
check
_virDomainInfo
@@ -176,6 +164,7 @@ A:link, A:visited, A:active { text-decoration: underline }
deallocated
virDomainGetName
defined
virDomainCreateLinux
description
virDomainGetXMLDesc
+
doable
virDomainShutdown
does
virDomainDestroy
domains
virConnectListDomains
virConnectNumOfDomains
@@ -191,6 +180,7 @@ A:link, A:visited, A:active { text-decoration: underline } virDomainDestroy
virDomainGetID
virDomainGetMaxMemory
+virDomainGetOSType
virDomainGetXMLDesc
virGetVersion
especially
virConnectClose
@@ -206,6 +196,7 @@ A:link, A:visited, A:active { text-decoration: underline } virDomainLookupByName
virDomainResume
virDomainSetMaxMemory
+virDomainShutdown
virDomainSuspend
virGetVersion
file
virDomainCreateLinux
@@ -219,6 +210,7 @@ A:link, A:visited, A:active { text-decoration: underline } virDomainGetID
virDomainGetName
virDomainLookupByName
+virDomainShutdown
virGetVersion
format
virGetVersion
found
virConnectListDomains
diff --git a/docs/APIchunk1.html b/docs/APIchunk1.html index be05b8d9ec..1160e43ac3 100644 --- a/docs/APIchunk1.html +++ b/docs/APIchunk1.html @@ -10,7 +10,8 @@ A:link, A:visited, A:active { text-decoration: underline } API Alphabetic Index g-s for libvir
Red Hat Logo

Libvir the virtualization API

API Alphabetic Index g-s for libvir

Developer Menu
API Indexes
Related links

A-f g-s t-z -

Letter g:

get
virConnectOpen
+

Letter g:

general
virDomainShutdown
+
get
virConnectOpen
virConnectOpenReadOnly
virDomainGetInfo
virDomainGetMaxMemory
@@ -52,6 +53,7 @@ A:link, A:visited, A:active { text-decoration: underline }
kilobytes
virDomainCreateLinux
virDomainGetMaxMemory
virDomainSetMaxMemory
+
knowing
virDomainShutdown

Letter l:

lack
virConnectGetVersion
level
virConnectGetVersion
virDomainSuspend
@@ -70,6 +72,7 @@ A:link, A:visited, A:active { text-decoration: underline } virDomainGetMaxMemory
virDomainSetMaxMemory
may
virConnectGetVersion
+virDomainShutdown
memory
_virDomainInfo
virDomainCreateLinux
virDomainGetMaxMemory
@@ -88,6 +91,7 @@ A:link, A:visited, A:active { text-decoration: underline } virDomainGetName
needed
virConnectClose
new
virDomainCreateLinux
+virDomainGetOSType
virDomainLookupByID
virDomainLookupByName
not
virConnectClose
@@ -96,6 +100,7 @@ A:link, A:visited, A:active { text-decoration: underline } virDomainFree
virDomainGetName
virDomainGetXMLDesc
+virDomainShutdown
virGetVersion
number
virConnectListDomains
virConnectNumOfDomains
@@ -108,16 +113,20 @@ A:link, A:visited, A:active { text-decoration: underline } virDomainGetInfo
virDomainGetMaxMemory
virDomainGetName
+virDomainGetOSType
virDomainGetXMLDesc
virDomainLookupByID
virDomainLookupByName
virDomainResume
virDomainSetMaxMemory
+virDomainShutdown
virDomainSuspend
one
_virDomainInfo
only
_virDomainInfo
virConnectGetVersion
virDomainGetInfo
+
operation
virDomainGetOSType
+
option
virDomainShutdown
optional
virConnectOpen
virConnectOpenReadOnly
virDomainCreateLinux
@@ -159,6 +168,7 @@ A:link, A:visited, A:active { text-decoration: underline }
publicly
_virDomainInfo

Letter r:

reactivate
virDomainSuspend
read-only
virConnectOpenReadOnly
+
reboot
virDomainShutdown
release
virConnectGetVersion
virGetVersion
requires
virDomainCreateLinux
@@ -195,6 +205,7 @@ A:link, A:visited, A:active { text-decoration: underline } virConnectOpenReadOnly
virDomainDestroy
virDomainFree
+virDomainShutdown
shutdown
virDomainDestroy
size
virConnectListDomains
virDomainCreateLinux
@@ -205,11 +216,14 @@ A:link, A:visited, A:active { text-decoration: underline } virDomainResume
static
virConnectGetType
stay
virDomainSuspend
+
still
virDomainShutdown
+
stopped
virDomainShutdown
store
virConnectListDomains
virConnectOpen
virConnectOpenReadOnly
string
virConnectGetType
virDomainGetName
+virDomainGetOSType
structure
_virDomainInfo
virDomainDestroy
virDomainFree
@@ -221,8 +235,10 @@ A:link, A:visited, A:active { text-decoration: underline } virDomainGetInfo
virDomainResume
virDomainSetMaxMemory
+virDomainShutdown
virDomainSuspend
suspended
virDomainResume
+
system
virDomainGetOSType

A-f g-s t-z diff --git a/docs/APIchunk2.html b/docs/APIchunk2.html index 3dd0abe6cd..fdd4f86d15 100644 --- a/docs/APIchunk2.html +++ b/docs/APIchunk2.html @@ -20,6 +20,7 @@ A:link, A:visited, A:active { text-decoration: underline } virDomainGetMaxMemory
virDomainSetMaxMemory

there
virConnectClose
+virDomainShutdown
thereafter
virDomainDestroy
virDomainFree
this
_virDomainInfo
@@ -27,13 +28,15 @@ A:link, A:visited, A:active { text-decoration: underline } virDomainGetXMLDesc
virDomainSetMaxMemory
two
virGetVersion
-
type
virGetVersion
+
type
virDomainGetOSType
+virGetVersion

Letter u:

unimplemented
virDomainCreateLinux
unknown
virGetVersion
unsigned
virDomainGetID
unused
virConnectOpen
virConnectOpenReadOnly
usable
virConnectOpenReadOnly
+virDomainShutdown
used
_virDomainInfo
virConnectGetType
virDomainDestroy
diff --git a/docs/APIfiles.html b/docs/APIfiles.html index a57f7c865d..6167b20711 100644 --- a/docs/APIfiles.html +++ b/docs/APIfiles.html @@ -26,14 +26,15 @@ A:link, A:visited, A:active { text-decoration: underline } virConnectOpenReadOnly
virConnectPtr
virDomain
+virDomainCreateFlags
virDomainCreateLinux
virDomainDestroy
-virDomainFlags
virDomainFree
virDomainGetID
virDomainGetInfo
virDomainGetMaxMemory
virDomainGetName
+virDomainGetOSType
virDomainGetXMLDesc
virDomainInfo
virDomainInfoPtr
@@ -42,6 +43,7 @@ A:link, A:visited, A:active { text-decoration: underline } virDomainPtr
virDomainResume
virDomainSetMaxMemory
+virDomainShutdown
virDomainState
virDomainSuspend
virGetVersion
diff --git a/docs/APIfunctions.html b/docs/APIfunctions.html index 6c9d9f86e4..eac6ba5b71 100644 --- a/docs/APIfunctions.html +++ b/docs/APIfunctions.html @@ -28,8 +28,10 @@ A:link, A:visited, A:active { text-decoration: underline } virDomainGetInfo
virDomainGetMaxMemory
virDomainGetName
+virDomainGetOSType
virDomainGetXMLDesc
virDomainResume
virDomainSetMaxMemory
+virDomainShutdown
virDomainSuspend

Daniel Veillard

diff --git a/docs/APIsymbols.html b/docs/APIsymbols.html index 069896aa05..2ae907445c 100644 --- a/docs/APIsymbols.html +++ b/docs/APIsymbols.html @@ -26,14 +26,15 @@ A:link, A:visited, A:active { text-decoration: underline } virConnectOpenReadOnly
virConnectPtr
virDomain
+virDomainCreateFlags
virDomainCreateLinux
virDomainDestroy
-virDomainFlags
virDomainFree
virDomainGetID
virDomainGetInfo
virDomainGetMaxMemory
virDomainGetName
+virDomainGetOSType
virDomainGetXMLDesc
virDomainInfo
virDomainInfoPtr
@@ -42,6 +43,7 @@ A:link, A:visited, A:active { text-decoration: underline } virDomainPtr
virDomainResume
virDomainSetMaxMemory
+virDomainShutdown
virDomainState
virDomainSuspend
virGetVersion
diff --git a/docs/html/libvir-libvir.html b/docs/html/libvir-libvir.html index 08841a3998..74e64bcb1f 100644 --- a/docs/html/libvir-libvir.html +++ b/docs/html/libvir-libvir.html @@ -15,7 +15,7 @@ The content of this structure is not made public by the API.
Typedef virConnect * virConnectPtr
 
Structure virDomain
struct _virDomain The content of this structure is not made public by the API. -
Enum virDomainFlags
+
Enum virDomainCreateFlags
 
Structure virDomainInfo
struct _virDomainInfo
Typedef virDomainInfo * virDomainInfoPtr
 
Typedef virDomain * virDomainPtr
@@ -34,11 +34,13 @@ The content of this structure is not made public by the API.
 
int	virDomainGetInfo		(virDomainPtr domain, 
virDomainInfoPtr info)
unsigned long	virDomainGetMaxMemory	(virDomainPtr domain)
const char *	virDomainGetName	(virDomainPtr domain)
+
char *	virDomainGetOSType		(virDomainPtr domain)
char *	virDomainGetXMLDesc		(virDomainPtr domain, 
int flags)
virDomainPtr	virDomainLookupByID	(virConnectPtr conn, 
int id)
virDomainPtr	virDomainLookupByName	(virConnectPtr conn, 
const char * name)
int	virDomainResume			(virDomainPtr domain)
int	virDomainSetMaxMemory		(virDomainPtr domain, 
unsigned long memory)
+
int	virDomainShutdown		(virDomainPtr domain)
int	virDomainSuspend		(virDomainPtr domain)
int	virGetVersion			(unsigned long * libVer, 
const char * type,
unsigned long * typeVer)

Description

@@ -49,7 +51,7 @@ The content of this structure is not made public by the API. 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.

Structure virDomain

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

Enum virDomainFlags

Enum virDomainFlags {
+}

Enum virDomainCreateFlags

Enum virDomainCreateFlags {
     VIR_DOMAIN_NONE = 0
 }
 

Structure virDomainInfo

Structure virDomainInfo
struct _virDomainInfo { @@ -86,7 +88,7 @@ The content of this structure is not made public by the API.

This function should be called first to get a read-only connection to the xen store. The set of APIs usable are then restricted.

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

Function: virDomainCreateLinux

virDomainPtr	virDomainCreateLinux	(virConnectPtr conn, 
const char * kernel_path,
const char * initrd_path,
const char * cmdline,
unsigned long memory,
unsigned int flags)

Launch a new Linux guest domain, unimplemented yet, API to be defined. This would function requires priviledged access to the hypervisor.

-
conn:pointer to the hypervisor connection
kernel_path:the file path to the kernel image
initrd_path:an optional file path to an initrd
cmdline:optional command line parameters for the kernel
memory:the memory size in kilobytes
flags:an optional set of virDomainFlags
Returns:a new domain object or NULL in case of failure

Function: virDomainDestroy

int	virDomainDestroy		(virDomainPtr domain)
+
conn:pointer to the hypervisor connection
kernel_path:the file path to the kernel image
initrd_path:an optional file path to an initrd
cmdline:optional command line parameters for the kernel
memory:the memory size in kilobytes
flags:an optional set of virDomainFlags
Returns:a new domain object or NULL in case of failure

Function: 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 requires priviledged access to the hypervisor.

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

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

@@ -98,7 +100,9 @@ The content of this structure is not made public by the API.

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.

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

Function: virDomainGetXMLDesc

char *	virDomainGetXMLDesc		(virDomainPtr domain, 
int flags)
+
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: virDomainGetXMLDesc

char *	virDomainGetXMLDesc		(virDomainPtr domain, 
int flags)

Provide an XML description of the domain. NOTE: this API is subject to changes.

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.

Function: virDomainLookupByID

virDomainPtr	virDomainLookupByID	(virConnectPtr conn, 
int id)

Try to find a domain based on the hypervisor ID number

@@ -108,7 +112,9 @@ The content of this structure is not made public by the API.

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

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

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

Function: virDomainSuspend

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

Function: virDomainShutdown

int	virDomainShutdown		(virDomainPtr domain)
+

Shutdown a domain, the domain object is still usable there after but the domain OS is being stopped. 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.

Function: 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 requires priviledged access to the hypervisor.

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.

diff --git a/docs/libvir-api.xml b/docs/libvir-api.xml index 879cbdd18f..e8503fa91e 100644 --- a/docs/libvir-api.xml +++ b/docs/libvir-api.xml @@ -15,34 +15,36 @@ - + - + - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + @@ -50,7 +52,7 @@ Macro providing the version of the library as version * 1,000,000 + minor * 1000 + micro - + @@ -61,7 +63,7 @@ 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. - + @@ -161,6 +163,11 @@ + + Get the type of domain operation system. + + + Provide an XML description of the domain. NOTE: this API is subject to changes. @@ -190,6 +197,11 @@ + + Shutdown a domain, the domain object is still usable there after but the domain OS is being stopped. TODO: should we add an option for reboot, knowing it may not be doable in the general case ? + + + 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 requires priviledged access to the hypervisor. diff --git a/docs/libvir-refs.xml b/docs/libvir-refs.xml index 57a0213d97..cbc43a9d13 100644 --- a/docs/libvir-refs.xml +++ b/docs/libvir-refs.xml @@ -20,14 +20,15 @@ + - + @@ -36,6 +37,7 @@ + @@ -67,14 +69,15 @@ + - + @@ -83,6 +86,7 @@ + @@ -140,9 +144,11 @@ + + @@ -167,14 +173,15 @@ + - + @@ -183,6 +190,7 @@ + @@ -238,6 +246,7 @@ + @@ -285,6 +294,7 @@ + @@ -322,6 +332,9 @@ + + + @@ -329,6 +342,7 @@ + @@ -382,6 +396,10 @@ + + + + @@ -445,10 +463,14 @@ + + + + @@ -477,28 +499,6 @@ - - - - - - - - - - - - - - - - - - - - - - @@ -559,6 +559,9 @@ + + + @@ -585,6 +588,7 @@ + @@ -610,6 +614,7 @@ + @@ -633,6 +638,7 @@ + @@ -678,6 +684,9 @@ + + + @@ -758,6 +767,9 @@ + + + @@ -803,6 +815,7 @@ + @@ -841,6 +854,7 @@ + @@ -851,6 +865,7 @@ + @@ -869,11 +884,13 @@ + + @@ -884,6 +901,12 @@ + + + + + + @@ -965,6 +988,9 @@ + + + @@ -1030,6 +1056,7 @@ + @@ -1053,6 +1080,12 @@ + + + + + + @@ -1061,6 +1094,7 @@ + @@ -1078,11 +1112,15 @@ + + + + @@ -1108,6 +1146,7 @@ + @@ -1123,6 +1162,7 @@ + @@ -1142,6 +1182,7 @@ + diff --git a/include/libvir.h b/include/libvir.h index c8bbe5df56..ba612e1f7d 100644 --- a/include/libvir.h +++ b/include/libvir.h @@ -100,14 +100,14 @@ struct _virDomainInfo { typedef virDomainInfo *virDomainInfoPtr; /** - * virDomainFlags: + * virDomainCreateFlags: * * Flags OR'ed together to provide specific behaviour when creating a * Domain. */ typedef enum { VIR_DOMAIN_NONE = 0 -} virDomainFlags; +} virDomainCreateFlags; /* library versionning */ @@ -160,6 +160,7 @@ virDomainPtr virDomainLookupByName (virConnectPtr conn, const char *name); virDomainPtr virDomainLookupByID (virConnectPtr conn, int id); +int virDomainShutdown (virDomainPtr domain); int virDomainDestroy (virDomainPtr domain); int virDomainFree (virDomainPtr domain); @@ -174,17 +175,20 @@ int virDomainResume (virDomainPtr domain); */ int virDomainGetInfo (virDomainPtr domain, virDomainInfoPtr info); -char * virDomainGetXMLDesc (virDomainPtr domain, - int flags); /* * Dynamic control of domains */ const char * virDomainGetName (virDomainPtr domain); unsigned int virDomainGetID (virDomainPtr domain); +char * virDomainGetOSType (virDomainPtr domain); unsigned long virDomainGetMaxMemory (virDomainPtr domain); int virDomainSetMaxMemory (virDomainPtr domain, unsigned long memory); +/* + * XML domain description + */ +char * virDomainGetXMLDesc (virDomainPtr domain, int flags); #ifdef __cplusplus } diff --git a/include/libvir.h.in b/include/libvir.h.in index f560e9db35..3dc9e0d2cf 100644 --- a/include/libvir.h.in +++ b/include/libvir.h.in @@ -100,14 +100,14 @@ struct _virDomainInfo { typedef virDomainInfo *virDomainInfoPtr; /** - * virDomainFlags: + * virDomainCreateFlags: * * Flags OR'ed together to provide specific behaviour when creating a * Domain. */ typedef enum { VIR_DOMAIN_NONE = 0 -} virDomainFlags; +} virDomainCreateFlags; /* library versionning */ @@ -160,6 +160,7 @@ virDomainPtr virDomainLookupByName (virConnectPtr conn, const char *name); virDomainPtr virDomainLookupByID (virConnectPtr conn, int id); +int virDomainShutdown (virDomainPtr domain); int virDomainDestroy (virDomainPtr domain); int virDomainFree (virDomainPtr domain); diff --git a/src/internal.h b/src/internal.h index a4c1d14889..873e5db5a2 100644 --- a/src/internal.h +++ b/src/internal.h @@ -71,6 +71,16 @@ struct _virConnect { int flags; /* a set of connection flags */ }; +/** + * virDomainFlags: + * + * a set of special flag values associated to the domain + */ + +enum { + DOMAIN_IS_SHUTDOWN = (1 << 0) /* the domain is being shutdown */ +} virDomainFlags; + /** * _virDomain: * @@ -82,6 +92,7 @@ struct _virDomain { char *name; /* the domain external name */ char *path; /* the domain internal path */ int handle; /* internal handle for the dmonain ID */ + int flags; /* extra flags */ }; /* diff --git a/src/libvir.c b/src/libvir.c index 937468b0da..218cf13d16 100644 --- a/src/libvir.c +++ b/src/libvir.c @@ -467,6 +467,46 @@ done: } +/** + * virDomainDoStoreWrite: + * @domain: a domain object + * @path: the relative path of the data in the store to retrieve + * + * Internal API setting up a string value in the Xenstore + * Requires write access to the XenStore + * + * Returns 0 in case of success, -1 in case of failure + */ +static int +virDomainDoStoreWrite(virDomainPtr domain, const char *path, + const char *value) { + struct xs_transaction_handle* t; + char s[256]; + + int ret = -1; + + if ((domain == NULL) || (domain->magic != VIR_DOMAIN_MAGIC)) + return(-1); + if ((domain->conn == NULL) || (domain->conn->flags & VIR_CONNECT_RO)) + return(-1); + + + snprintf(s, 255, "/local/domain/%d/%s", domain->handle, path); + s[255] = 0; + + t = xs_transaction_start(domain->conn->xshandle); + if (t == NULL) + goto done; + + if (xs_write(domain->conn->xshandle, t, &s[0], value, strlen(value))) + ret = 0; + +done: + if (t != NULL) + xs_transaction_end(domain->conn->xshandle, t, 0); + return(ret); +} + /** * virDomainGetVM: * @domain: a domain object @@ -741,6 +781,37 @@ virDomainResume(virDomainPtr domain) { return(xenHypervisorResumeDomain(domain->conn->handle, domain->handle)); } +/** + * virDomainShutdown: + * @domain: a domain object + * + * Shutdown a domain, the domain object is still usable there after but + * the domain OS is being stopped. + * + * TODO: should we add an option for reboot, knowing it may not be doable + * in the general case ? + * + * Returns 0 in case of success and -1 in case of failure. + */ +int +virDomainShutdown(virDomainPtr domain) { + int ret; + + if ((domain == NULL) || (domain->magic != VIR_DOMAIN_MAGIC)) + return(-1); + if ((domain->conn == NULL) || (domain->conn->magic != VIR_CONNECT_MAGIC)) + return(-1); + /* + * this is very hackish, the domU kernel probes for a special + * node in the xenstore and launch the shutdown command if found. + */ + ret = virDomainDoStoreWrite(domain, "control/shutdown", "halt"); + if (ret == 0) { + domain->flags |= DOMAIN_IS_SHUTDOWN; + } + return(ret); +} + /** * virDomainGetName: * @domain: a domain object diff --git a/src/virsh.c b/src/virsh.c index bc0e038e6c..f74f24753f 100644 --- a/src/virsh.c +++ b/src/virsh.c @@ -424,6 +424,44 @@ cmdResume(vshControl *ctl, vshCmd *cmd) { return ret; } +/* + * "shutdown" command + */ +static vshCmdInfo info_shutdown[] = { + { "syntax", "shutdown " }, + { "help", "gracefully shutdown a domain" }, + { "desc", "Run shutdown in the targetted domain" }, + { NULL, NULL } +}; + +static vshCmdOptDef opts_shutdown[] = { + { "domain", VSH_OT_DATA, 0, "domain name or id" }, + { NULL, 0, 0, NULL } +}; + +static int +cmdShutdown(vshControl *ctl, vshCmd *cmd) { + virDomainPtr dom; + int ret = TRUE; + char *name; + + if (!vshConnectionUsability(ctl, ctl->conn, TRUE)) + return FALSE; + + if (!(dom = vshCommandOptDomain(ctl, cmd, "domain", &name))) + return FALSE; + + if (virDomainShutdown(dom)==0) { + vshPrint(ctl, VSH_MESG, "Domain %s is being shutdown\n", name); + } else { + vshError(ctl, FALSE, "Failed to shutdown domain\n"); + ret = FALSE; + } + + virDomainFree(dom); + return ret; +} + /* * "destroy" command */ @@ -743,6 +781,7 @@ static vshCmdDef commands[] = { { "dstate", cmdDstate, opts_dstate, info_dstate }, { "suspend", cmdSuspend, opts_suspend, info_suspend }, { "resume", cmdResume, opts_resume, info_resume }, + { "shutdown", cmdShutdown, opts_shutdown, info_shutdown }, { "destroy", cmdDestroy, opts_destroy, info_destroy }, { "help", cmdHelp, opts_help, info_help }, { "idof", cmdIdof, opts_idof, info_idof },