From 831f910e506d371c11ee7c7071888564b19e64cb Mon Sep 17 00:00:00 2001
From: Daniel Veillard
+virDomainReboot
virDomainShutdown
Letter O:
virGetVersion
@@ -68,6 +69,7 @@
virGetVersion
Letter R:
+
virResetError
virResetLastError
@@ -120,7 +122,8 @@
virConnectNumOfDomains
virDomainSuspend
-
+
+virDomainSave
virDomainShutdown
@@ -159,12 +162,14 @@
virDomainLookupByID
virDomainLookupByName
virDomainLookupByUUID
-
+
+virDomainShutdown
virErrorFunc
virResetError
+virDomainReboot
virDomainShutdown
virDomainSuspend
virGetLastError
diff --git a/docs/APIchunk1.html b/docs/APIchunk1.html
index 8db336fee2..63cc24dba9 100644
--- a/docs/APIchunk1.html
+++ b/docs/APIchunk1.html
@@ -27,6 +27,7 @@
+virDomainReboot
virDomainGetInfo
@@ -37,6 +38,7 @@
virDomainLookupByID
virDomainLookupByName
virDomainLookupByUUID
+virDomainReboot
virDomainRestore
virDomainResume
virDomainSave
@@ -51,6 +53,7 @@
virConnectOpenReadOnly
+virDomainReboot
_virNodeInfo
virConnGetLastError
@@ -60,6 +63,7 @@
virDomainGetUUID
virDomainLookupByName
virDomainLookupByUUID
+virDomainReboot
virDomainSave
virDomainShutdown
virErrorFunc
@@ -108,6 +112,7 @@
virSetErrorFunc
+virDomainReboot
virDomainShutdown
Letter h:
virSetErrorFunc
@@ -117,7 +122,8 @@
-Letter i:
+Letter i:
+virDomainShutdown
@@ -184,6 +190,7 @@
virDomainCreateLinux
virDomainDestroy
virDomainGetXMLDesc
+virDomainReboot
virDomainResume
virDomainSave
virDomainShutdown
diff --git a/docs/APIchunk2.html b/docs/APIchunk2.html
index 1973107b1f..72473307f5 100644
--- a/docs/APIchunk2.html
+++ b/docs/APIchunk2.html
@@ -29,6 +29,7 @@
virDomainFree
virDomainGetName
virDomainGetXMLDesc
+virDomainReboot
virDomainSave
virDomainShutdown
virGetLastError
@@ -53,6 +54,7 @@
virDomainLookupByID
virDomainLookupByName
virDomainLookupByUUID
+virDomainReboot
virDomainResume
virDomainSave
virDomainSetMaxMemory
@@ -65,6 +67,7 @@
virDomainGetInfo
+virDomainReboot
virConnectOpen
@@ -137,14 +140,16 @@
virSetErrorFunc
-
+
+virDomainShutdown
virCopyLastError
virGetVersion
-
+
+virDomainShutdown
virDomainDestroy
virDomainResume
@@ -156,6 +161,7 @@
virSetErrorFunc
virDomainSuspend
+
virDomainSave
@@ -210,8 +216,10 @@
virSetErrorFunc
-
-
+
+virDomainShutdown
+
+virDomainShutdown
virConnectOpen
@@ -229,6 +237,7 @@
virDomainFree
virDomainGetInfo
virDomainGetUUID
+virDomainReboot
virDomainRestore
virDomainResume
virDomainSave
diff --git a/docs/APIfiles.html b/docs/APIfiles.html
index ce70802c0c..dbf3b0e94c 100644
--- a/docs/APIfiles.html
+++ b/docs/APIfiles.html
@@ -50,6 +50,7 @@
virDomainLookupByName
virDomainLookupByUUID
virDomainPtr
+virDomainReboot
virDomainRestart
virDomainRestore
virDomainResume
diff --git a/docs/APIfunctions.html b/docs/APIfunctions.html
index 4f6834dd3f..27170a689e 100644
--- a/docs/APIfunctions.html
+++ b/docs/APIfunctions.html
@@ -4,6 +4,7 @@
virDomainCreateLinux
+virDomainReboot
virConnectGetVersion
virGetVersion
@@ -32,6 +33,7 @@
virDomainGetOSType
virDomainGetUUID
virDomainGetXMLDesc
+virDomainReboot
virDomainResume
virDomainSave
virDomainSetMaxMemory
diff --git a/docs/APIsymbols.html b/docs/APIsymbols.html
index 7c7e8f7bb4..c44eb90909 100644
--- a/docs/APIsymbols.html
+++ b/docs/APIsymbols.html
@@ -94,6 +94,7 @@
virDomainLookupByName
virDomainLookupByUUID
virDomainPtr
+virDomainReboot
virDomainRestart
virDomainRestore
virDomainResume
diff --git a/docs/html/libvirt-libvirt.html b/docs/html/libvirt-libvirt.html
index f2a2977a5b..c06d0ef2cc 100644
--- a/docs/html/libvirt-libvirt.html
+++ b/docs/html/libvirt-libvirt.html
@@ -36,6 +36,7 @@ The content of this structure is not made public by the API.
virDomainPtr virDomainLookupByID (virConnectPtr conn,
int id)
virDomainPtr virDomainLookupByName (virConnectPtr conn,
const char * name)
virDomainPtr virDomainLookupByUUID (virConnectPtr conn,+
const unsigned char * uuid)
int virDomainReboot (virDomainPtr domain,
unsigned int flags)
int virDomainRestore (virConnectPtr conn,
const char * from)
int virDomainResume (virDomainPtr domain)
int virDomainSave (virDomainPtr domain,@@ -145,7 +146,9 @@ The content of this structure is not made public by the API.
const char * to)
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 |
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 |
int virDomainRestore (virConnectPtr conn,
const char * from)
+
conn: pointer to the hypervisor connection uuid: the UUID string for the domain Returns: a new domain object or NULL in case of failure Function: 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. Function: 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. Function: 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
diff --git a/docs/libvirt-api.xml b/docs/libvirt-api.xml index 15186f30e7..67b86867a4 100644 --- a/docs/libvirt-api.xml +++ b/docs/libvirt-api.xml @@ -60,6 +60,7 @@+ @@ -391,6 +392,12 @@ + + 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. ++ + + This method will restore a domain saved to disk by virDomainSave(). diff --git a/docs/libvirt-refs.xml b/docs/libvirt-refs.xml index 61f80078ac..0ccfc12271 100644 --- a/docs/libvirt-refs.xml +++ b/docs/libvirt-refs.xml @@ -95,6 +95,7 @@ + @@ -221,6 +222,7 @@ + @@ -280,6 +282,7 @@ + @@ -318,6 +321,7 @@ + @@ -396,6 +400,7 @@ + @@ -590,6 +595,7 @@ + @@ -618,6 +624,9 @@+ + + @@ -727,6 +736,7 @@ + @@ -808,6 +818,7 @@+ @@ -820,6 +831,7 @@ + @@ -1002,6 +1014,7 @@ + @@ -1020,6 +1033,7 @@ + @@ -1044,6 +1058,7 @@ + @@ -1055,6 +1070,7 @@ + @@ -1135,6 +1151,7 @@ + @@ -1162,6 +1179,7 @@+ @@ -1295,6 +1313,7 @@ + @@ -1392,6 +1411,7 @@ + @@ -1422,6 +1442,7 @@ + @@ -1442,6 +1463,7 @@ + @@ -1574,6 +1596,7 @@ + @@ -1591,6 +1614,7 @@ + @@ -1612,6 +1636,9 @@ ++ + @@ -1725,9 +1752,11 @@ + + @@ -1754,6 +1783,7 @@ + @@ -1797,6 +1827,7 @@ + @@ -1809,6 +1840,7 @@ + @@ -1857,6 +1889,7 @@ + @@ -1871,6 +1904,7 @@ + @@ -2003,6 +2037,7 @@ + diff --git a/include/libvirt.h b/include/libvirt.h index 364a5894cc..02ca8c2197 100644 --- a/include/libvirt.h +++ b/include/libvirt.h @@ -230,6 +230,8 @@ virDomainPtr virDomainLookupByID (virConnectPtr conn, virDomainPtr virDomainLookupByUUID (virConnectPtr conn, const unsigned char *uuid); int virDomainShutdown (virDomainPtr domain); +int virDomainReboot (virDomainPtr domain, + unsigned int flags); int virDomainDestroy (virDomainPtr domain); int virDomainFree (virDomainPtr domain); diff --git a/include/libvirt.h.in b/include/libvirt.h.in index b596712b2b..a73c46ac93 100644 --- a/include/libvirt.h.in +++ b/include/libvirt.h.in @@ -230,6 +230,8 @@ virDomainPtr virDomainLookupByID (virConnectPtr conn, virDomainPtr virDomainLookupByUUID (virConnectPtr conn, const unsigned char *uuid); int virDomainShutdown (virDomainPtr domain); +int virDomainReboot (virDomainPtr domain, + unsigned int flags); int virDomainDestroy (virDomainPtr domain); int virDomainFree (virDomainPtr domain); diff --git a/include/libvirt/libvirt.h b/include/libvirt/libvirt.h index 364a5894cc..02ca8c2197 100644 --- a/include/libvirt/libvirt.h +++ b/include/libvirt/libvirt.h @@ -230,6 +230,8 @@ virDomainPtr virDomainLookupByID (virConnectPtr conn, virDomainPtr virDomainLookupByUUID (virConnectPtr conn, const unsigned char *uuid); int virDomainShutdown (virDomainPtr domain); +int virDomainReboot (virDomainPtr domain, + unsigned int flags); int virDomainDestroy (virDomainPtr domain); int virDomainFree (virDomainPtr domain); diff --git a/include/libvirt/libvirt.h.in b/include/libvirt/libvirt.h.in index b596712b2b..a73c46ac93 100644 --- a/include/libvirt/libvirt.h.in +++ b/include/libvirt/libvirt.h.in @@ -230,6 +230,8 @@ virDomainPtr virDomainLookupByID (virConnectPtr conn, virDomainPtr virDomainLookupByUUID (virConnectPtr conn, const unsigned char *uuid); int virDomainShutdown (virDomainPtr domain); +int virDomainReboot (virDomainPtr domain, + unsigned int flags); int virDomainDestroy (virDomainPtr domain); int virDomainFree (virDomainPtr domain); diff --git a/src/driver.h b/src/driver.h index fd5af748af..5489e7fcba 100644 --- a/src/driver.h +++ b/src/driver.h @@ -59,6 +59,9 @@ typedef int (*virDrvDomainResume) (virDomainPtr domain); typedef int (*virDrvDomainShutdown) (virDomainPtr domain); +typedef int + (*virDrvDomainReboot) (virDomainPtr domain, + unsigned int flags); typedef int (*virDrvDomainDestroy) (virDomainPtr domain); typedef int @@ -113,6 +116,7 @@ struct _virDriver { virDrvDomainSuspend domainSuspend; virDrvDomainResume domainResume; virDrvDomainShutdown domainShutdown; + virDrvDomainReboot domainReboot; virDrvDomainDestroy domainDestroy; virDrvDomainFree domainFree; virDrvDomainGetName domainGetName; diff --git a/src/libvirt.c b/src/libvirt.c index 99ba6e5054..b10c206293 100644 --- a/src/libvirt.c +++ b/src/libvirt.c @@ -664,9 +664,7 @@ virDomainLookupByID(virConnectPtr conn, int id) return (ret); error: if (ret != NULL) - free(path); - if (path != NULL) - free(path); + free(ret); if (path != NULL) free(path); return (NULL); @@ -1042,6 +1040,47 @@ virDomainShutdown(virDomainPtr domain) return (ret); } +/** + * virDomainReboot: + * @domain: a domain object + * @flags: extra flags for the reboot operation, not used yet + * + * 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. + * + * Returns 0 in case of success and -1 in case of failure. + */ +int +virDomainReboot(virDomainPtr domain, unsigned int flags) +{ + int ret; + + if (!VIR_IS_CONNECTED_DOMAIN(domain)) { + virLibDomainError(domain, VIR_ERR_INVALID_DOMAIN, __FUNCTION__); + return (-1); + } + + /* + * try first with the xend daemon + */ + ret = xenDaemonDomainReboot(domain, flags); + if (ret == 0) { + domain->flags |= DOMAIN_IS_SHUTDOWN; + return (0); + } + + /* + * this is very hackish, the domU kernel probes for a special + * node in the xenstore and launch the shutdown command if found. + */ + ret = xenDaemonDomainReboot(domain, flags); + if (ret == 0) { + domain->flags |= DOMAIN_IS_SHUTDOWN; + } + return (ret); +} + /** * virDomainGetName: * @domain: a domain object diff --git a/src/libvirt_sym.version b/src/libvirt_sym.version index 618f42877d..077e5ee6e8 100644 --- a/src/libvirt_sym.version +++ b/src/libvirt_sym.version @@ -26,6 +26,7 @@ virDomainSave; virDomainSetMaxMemory; virDomainShutdown; + virDomainReboot; virDomainSuspend; virGetVersion; virCopyLastError; diff --git a/src/virsh.c b/src/virsh.c index 6c7a001fd0..39c3665bd3 100644 --- a/src/virsh.c +++ b/src/virsh.c @@ -635,6 +635,45 @@ cmdShutdown(vshControl * ctl, vshCmd * cmd) return ret; } +/* + * "reboot" command + */ +static vshCmdInfo info_reboot[] = { + {"syntax", "reboot "}, + {"help", "reboot a domain"}, + {"desc", "Run a reboot command in the targetted domain"}, + {NULL, NULL} +}; + +static vshCmdOptDef opts_reboot[] = { + {"domain", VSH_OT_DATA, VSH_OFLAG_REQ, "domain name or id"}, + {NULL, 0, 0, NULL} +}; + +static int +cmdReboot(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 (virDomainReboot(dom, 0) == 0) { + vshPrint(ctl, VSH_MESG, "Domain %s is being rebooted\n", name); + } else { + vshError(ctl, FALSE, "Failed to reboot domain\n"); + ret = FALSE; + } + + virDomainFree(dom); + return ret; +} + /* * "destroy" command */ @@ -961,6 +1000,7 @@ static vshCmdDef commands[] = { {"save", cmdSave, opts_save, info_save}, {"restore", cmdRestore, opts_restore, info_restore}, {"shutdown", cmdShutdown, opts_shutdown, info_shutdown}, + {"reboot", cmdReboot, opts_reboot, info_reboot}, {"destroy", cmdDestroy, opts_destroy, info_destroy}, {"help", cmdHelp, opts_help, info_help}, {"idof", cmdIdof, opts_idof, info_idof}, diff --git a/src/xen_internal.c b/src/xen_internal.c index ccfc7cfdf8..b579831367 100644 --- a/src/xen_internal.c +++ b/src/xen_internal.c @@ -57,6 +57,7 @@ static virDriver xenHypervisorDriver = { xenHypervisorPauseDomain, /* domainSuspend */ xenHypervisorResumeDomain, /* domainResume */ NULL, /* domainShutdown */ + NULL, /* domainReboot */ xenHypervisorDestroyDomain, /* domainDestroy */ NULL, /* domainFree */ NULL, /* domainGetName */ diff --git a/src/xend_internal.c b/src/xend_internal.c index f1771c9dcc..03ba2a7ccf 100644 --- a/src/xend_internal.c +++ b/src/xend_internal.c @@ -55,6 +55,7 @@ static virDriver xenDaemonDriver = { xenDaemonDomainSuspend, /* domainSuspend */ xenDaemonDomainResume, /* domainResume */ xenDaemonDomainShutdown, /* domainShutdown */ + xenDaemonDomainReboot, /* domainReboot */ xenDaemonDomainDestroy, /* domainDestroy */ NULL, /* domainFree */ NULL, /* domainGetName */ @@ -965,26 +966,6 @@ xend_rename(virConnectPtr xend, const char *old, const char *new) return xend_op(xend, old, "op", "rename", "name", new, NULL); } -/** - * xend_reboot: - * @xend: pointer to the Xem Daemon block - * @name: name for the domain - * - * Reboot the domain, the OS is properly shutdown and restarted - * - * Returns 0 in case of success, -1 (with errno) in case of error. - */ -int -xend_reboot(virConnectPtr xend, const char *name) -{ - if ((xend == NULL) || (name == NULL)) { - /* this should be caught at the interface but ... */ - virXendError(xend, VIR_ERR_INVALID_ARG, __FUNCTION__); - return (-1); - } - return xend_op(xend, name, "op", "shutdown", "reason", "reboot", NULL); -} - /** * xend_sysrq: * @xend: pointer to the Xem Daemon block @@ -1768,6 +1749,28 @@ xenDaemonDomainShutdown(virDomainPtr domain) return xend_op(domain->conn, domain->name, "op", "shutdown", "reason", "halt", NULL); } +/** + * xenDaemonDomainReboot: + * @domain: pointer to the Domain block + * @flags: extra flags for the reboot operation, not used yet + * + * Reboot the domain, the OS is requested to properly shutdown + * and restart but the domain may ignore it. It will return immediately + * after queuing the request. + * + * Returns 0 in case of success, -1 (with errno) in case of error. + */ +int +xenDaemonDomainReboot(virDomainPtr domain, unsigned int flags ATTRIBUTE_UNUSED) +{ + if ((domain == NULL) || (domain->conn == NULL) || (domain->name == NULL)) { + virXendError((domain ? domain->conn : NULL), VIR_ERR_INVALID_ARG, + __FUNCTION__); + return(-1); + } + return xend_op(domain->conn, domain->name, "op", "shutdown", "reason", "reboot", NULL); +} + /** * xenDaemonDomainDestroy: * @domain: pointer to the Domain block diff --git a/src/xend_internal.h b/src/xend_internal.h index 25addb9a8b..1deead8d66 100644 --- a/src/xend_internal.h +++ b/src/xend_internal.h @@ -509,18 +509,6 @@ int xenDaemonOpen_unix(virConnectPtr xend, const char *path); */ int xend_sysrq(virConnectPtr xend, const char *name, const char *key); -/** - * \brief Request a domain to reboot - * \param xend A xend instance - * \param name The domain's name - * \return 0 for success; -1 (with errno) on error - * - * This method *requests* that a domain reboot itself. This is only - * a request and the domain may ignore it. It will return immediately - * after queuing the request. - */ - int xend_reboot(virConnectPtr xend, const char *name); - /** * \brief Obtain a list of currently running domains * \param xend A xend instance @@ -644,6 +632,7 @@ int xenDaemonClose(virConnectPtr conn); int xenDaemonDomainSuspend(virDomainPtr domain); int xenDaemonDomainResume(virDomainPtr domain); int xenDaemonDomainShutdown(virDomainPtr domain); +int xenDaemonDomainReboot(virDomainPtr domain, unsigned int flags); int xenDaemonDomainDestroy(virDomainPtr domain); int xenDaemonDomainSave(virDomainPtr domain, const char *filename); int xenDaemonDomainRestore(virConnectPtr conn, const char *filename); diff --git a/src/xs_internal.c b/src/xs_internal.c index 4a24aa9954..87a96054a6 100644 --- a/src/xs_internal.c +++ b/src/xs_internal.c @@ -46,7 +46,8 @@ static virDriver xenStoreDriver = { NULL, /* domainLookupByName */ NULL, /* domainSuspend */ NULL, /* domainResume */ - NULL, /* domainShutdown */ + xenStoreDomainShutdown, /* domainShutdown */ + xenStoreDomainReboot, /* domainReboot */ NULL, /* domainDestroy */ NULL, /* domainFree */ NULL, /* domainGetName */ @@ -599,3 +600,29 @@ xenStoreDomainShutdown(virDomainPtr domain) return(virDomainDoStoreWrite(domain, "control/shutdown", "halt")); } +/** + * xenStoreDomainReboot: + * @domain: pointer to the Domain block + * @flags: extra flags for the reboot operation, not used yet + * + * Reboot the domain, the OS is requested to properly shutdown + * and reboot but the domain may ignore it. It will return immediately + * after queuing the request. + * + * Returns 0 in case of success, -1 in case of error. + */ +int +xenStoreDomainReboot(virDomainPtr domain, unsigned int flags ATTRIBUTE_UNUSED) +{ + if ((domain == NULL) || (domain->conn == NULL)) { + virXenStoreError((domain ? domain->conn : NULL), VIR_ERR_INVALID_ARG, + __FUNCTION__); + return(-1); + } + /* + * this is very hackish, the domU kernel probes for a special + * node in the xenstore and launch the shutdown command if found. + */ + return(virDomainDoStoreWrite(domain, "control/shutdown", "reboot")); +} + diff --git a/src/xs_internal.h b/src/xs_internal.h index fdecf2bd9d..17c1d1c32e 100644 --- a/src/xs_internal.h +++ b/src/xs_internal.h @@ -15,23 +15,26 @@ extern "C" { #endif -void xenStoreRegister (void); -int xenStoreOpen (virConnectPtr conn, - const char *name, - int flags); -int xenStoreClose (virConnectPtr conn); -int xenStoreGetDomainInfo (virDomainPtr domain, - virDomainInfoPtr info); -int xenStoreNumOfDomains (virConnectPtr conn); -int xenStoreListDomains (virConnectPtr conn, - int *ids, - int maxids); -virDomainPtr xenStoreDomainLookupByName(virConnectPtr conn, const char *name); -unsigned long xenStoreGetMaxMemory(virDomainPtr domain); -int xenStoreDomainSetMaxMemory (virDomainPtr domain, - unsigned long memory); -unsigned long xenStoreDomainGetMaxMemory(virDomainPtr domain); -int xenStoreDomainShutdown(virDomainPtr domain); +void xenStoreRegister (void); +int xenStoreOpen (virConnectPtr conn, + const char *name, + int flags); +int xenStoreClose (virConnectPtr conn); +int xenStoreGetDomainInfo (virDomainPtr domain, + virDomainInfoPtr info); +int xenStoreNumOfDomains (virConnectPtr conn); +int xenStoreListDomains (virConnectPtr conn, + int *ids, + int maxids); +virDomainPtr xenStoreDomainLookupByName(virConnectPtr conn, + const char *name); +unsigned long xenStoreGetMaxMemory (virDomainPtr domain); +int xenStoreDomainSetMaxMemory(virDomainPtr domain, + unsigned long memory); +unsigned long xenStoreDomainGetMaxMemory(virDomainPtr domain); +int xenStoreDomainShutdown (virDomainPtr domain); +int xenStoreDomainReboot (virDomainPtr domain, + unsigned int flags); #ifdef __cplusplus } #endif -- 2.47.2