diff --git a/include/libvirt/libvirt.h.in b/include/libvirt/libvirt.h.in index afeb83fe79..a3c581db97 100644 --- a/include/libvirt/libvirt.h.in +++ b/include/libvirt/libvirt.h.in @@ -1031,6 +1031,9 @@ virDomainPtr virDomainLookupByUUIDString (virConnectPtr conn, int virDomainShutdown (virDomainPtr domain); int virDomainReboot (virDomainPtr domain, unsigned int flags); +int virDomainReset (virDomainPtr domain, + unsigned int flags); + int virDomainDestroy (virDomainPtr domain); int virDomainDestroyFlags (virDomainPtr domain, unsigned int flags); diff --git a/src/driver.h b/src/driver.h index 7dcab8f68e..f85a1b1fe3 100644 --- a/src/driver.h +++ b/src/driver.h @@ -123,6 +123,9 @@ typedef int typedef int (*virDrvDomainReboot) (virDomainPtr domain, unsigned int flags); +typedef int + (*virDrvDomainReset) (virDomainPtr domain, + unsigned int flags); typedef int (*virDrvDomainDestroy) (virDomainPtr domain); typedef int @@ -759,6 +762,7 @@ struct _virDriver { virDrvDomainResume domainResume; virDrvDomainShutdown domainShutdown; virDrvDomainReboot domainReboot; + virDrvDomainReset domainReset; virDrvDomainDestroy domainDestroy; virDrvDomainDestroyFlags domainDestroyFlags; virDrvDomainGetOSType domainGetOSType; diff --git a/src/libvirt.c b/src/libvirt.c index 38fcfbc0a8..9080b2f7bf 100644 --- a/src/libvirt.c +++ b/src/libvirt.c @@ -3016,6 +3016,56 @@ error: return -1; } +/** + * virDomainReset: + * @domain: a domain object + * @flags: extra flags for the reboot operation, not used yet + * + * Reset a domain immediately without any guest OS shutdown. + * Reset emulates the power reset button on a machine, where all + * hardware sees the RST line set and reinitializes internal state. + * + * Note that there is a risk of data loss caused by reset without any + * guest OS shutdown. + * + * Returns 0 in case of success and -1 in case of failure. + */ +int +virDomainReset(virDomainPtr domain, unsigned int flags) +{ + virConnectPtr conn; + + VIR_DOMAIN_DEBUG(domain, "flags=%x", flags); + + virResetLastError(); + + if (!VIR_IS_CONNECTED_DOMAIN(domain)) { + virLibDomainError(VIR_ERR_INVALID_DOMAIN, __FUNCTION__); + virDispatchError(NULL); + return -1; + } + if (domain->conn->flags & VIR_CONNECT_RO) { + virLibDomainError(VIR_ERR_OPERATION_DENIED, __FUNCTION__); + goto error; + } + + conn = domain->conn; + + if (conn->driver->domainReset) { + int ret; + ret = conn->driver->domainReset (domain, flags); + if (ret < 0) + goto error; + return ret; + } + + virLibConnError(VIR_ERR_NO_SUPPORT, __FUNCTION__); + +error: + virDispatchError(domain->conn); + return -1; +} + /** * virDomainGetName: * @domain: a domain object diff --git a/src/libvirt_public.syms b/src/libvirt_public.syms index cef14f03e5..afea29ba44 100644 --- a/src/libvirt_public.syms +++ b/src/libvirt_public.syms @@ -491,6 +491,7 @@ LIBVIRT_0.9.5 { LIBVIRT_0.9.7 { global: + virDomainReset; virDomainSnapshotGetParent; } LIBVIRT_0.9.5;