Add new public api for 'reset'. It can reset domain immediately without any guest shutdown. Signed-off-by: Xu He Jie <xuhj@xxxxxxxxxxxxxxxxxx> --- include/libvirt/libvirt.h.in | 3 ++ src/driver.h | 4 +++ src/libvirt.c | 50 ++++++++++++++++++++++++++++++++++++++++++ src/libvirt_public.syms | 1 + 4 files changed, 58 insertions(+), 0 deletions(-) diff --git a/include/libvirt/libvirt.h.in b/include/libvirt/libvirt.h.in index afeb83f..a3c581d 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 7dcab8f..f85a1b1 100644 --- a/src/driver.h +++ b/src/driver.h @@ -124,6 +124,9 @@ typedef int (*virDrvDomainReboot) (virDomainPtr domain, unsigned int flags); typedef int + (*virDrvDomainReset) (virDomainPtr domain, + unsigned int flags); +typedef int (*virDrvDomainDestroy) (virDomainPtr domain); typedef int (*virDrvDomainDestroyFlags) (virDomainPtr domain, @@ -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 38fcfbc..7fcbda4 100644 --- a/src/libvirt.c +++ b/src/libvirt.c @@ -3017,6 +3017,56 @@ error: } /** + * 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 of a button on a machine, i.e. + * All hardware see the RST line set and reinitialize their internal state. + * + * Note that the 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 cef14f0..9e6f104 100644 --- a/src/libvirt_public.syms +++ b/src/libvirt_public.syms @@ -492,6 +492,7 @@ LIBVIRT_0.9.5 { LIBVIRT_0.9.7 { global: virDomainSnapshotGetParent; + virDomainReset; } LIBVIRT_0.9.5; # .... define new API here using predicted next version number .... -- 1.7.4.1 -- libvir-list mailing list libvir-list@xxxxxxxxxx https://www.redhat.com/mailman/listinfo/libvir-list