define these flags: VIR_DOMAIN_SUSPEND_SLEEP = 0, /* Suspend to RAM */ VIR_DOMAIN_SUSPEND_HIBERNATE = (1 << 0), /* Suspend to disk */ --- include/libvirt/libvirt.h.in | 8 ++++++ src/driver.h | 4 +++ src/libvirt.c | 55 ++++++++++++++++++++++++++++++++++++++++++ src/libvirt_public.syms | 1 + src/remote/remote_driver.c | 1 + src/remote/remote_protocol.x | 9 ++++++- src/remote_protocol-structs | 5 ++++ 7 files changed, 82 insertions(+), 1 deletions(-) diff --git a/include/libvirt/libvirt.h.in b/include/libvirt/libvirt.h.in index e99cd00..d5ac891 100644 --- a/include/libvirt/libvirt.h.in +++ b/include/libvirt/libvirt.h.in @@ -1233,6 +1233,14 @@ int virDomainFree (virDomainPtr domain); int virDomainSuspend (virDomainPtr domain); int virDomainResume (virDomainPtr domain); +typedef enum { + VIR_DOMAIN_SUSPEND_SLEEP = 0, /* Suspend to RAM */ + VIR_DOMAIN_SUSPEND_HIBERNATE = (1 << 0), /* Suspend to disk */ +} virDomainSuspendFlagValues; + +int virDomainSuspendFlags (virDomainPtr domain, + unsigned int flags); + /* * Domain save/restore */ diff --git a/src/driver.h b/src/driver.h index df2aa60..2b878dd 100644 --- a/src/driver.h +++ b/src/driver.h @@ -118,6 +118,9 @@ typedef virDomainPtr typedef int (*virDrvDomainSuspend) (virDomainPtr domain); typedef int + (*virDrvDomainSuspendFlags) (virDomainPtr domain, + unsigned int flags); +typedef int (*virDrvDomainResume) (virDomainPtr domain); typedef int (*virDrvDomainShutdown) (virDomainPtr domain); @@ -831,6 +834,7 @@ struct _virDriver { virDrvDomainLookupByUUID domainLookupByUUID; virDrvDomainLookupByName domainLookupByName; virDrvDomainSuspend domainSuspend; + virDrvDomainSuspendFlags domainSuspendFlags; virDrvDomainResume domainResume; virDrvDomainShutdown domainShutdown; virDrvDomainShutdownFlags domainShutdownFlags; diff --git a/src/libvirt.c b/src/libvirt.c index 8be4e13..f94a5b9 100644 --- a/src/libvirt.c +++ b/src/libvirt.c @@ -2387,6 +2387,61 @@ error: } /** + * virDomainSuspendFlags: + * @domain: a domain object + * @flags: an OR'ed set of virDomainSuspendFlagValues + * + * Suspends an active domain. Dependent of @flags passed, + * the domain will enter either S3 or S4 state. + * Use VIR_DOMAIN_SUSPEND_SLEEP for S4, and + * VIR_DOMAIN_SUSPEND_HIBERNATE for S4. + * + * This function may require privileged access. + * + * Moreover, on some hypervisors, like QEMU, this may + * requires guest agent to be configured and running + * inside the domain. + * + * Returns 0 in case of success and -1 in case of failure. + */ +int +virDomainSuspendFlags(virDomainPtr domain, + unsigned int flags) +{ + virConnectPtr conn; + + VIR_DOMAIN_DEBUG(domain); + + 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->domainSuspendFlags) { + int ret; + ret = conn->driver->domainSuspendFlags(domain, flags); + if (ret < 0) + goto error; + return ret; + } + + virLibConnError(VIR_ERR_NO_SUPPORT, __FUNCTION__); + +error: + virDispatchError(domain->conn); + return -1; +} + +/** * virDomainResume: * @domain: a domain object * diff --git a/src/libvirt_public.syms b/src/libvirt_public.syms index b7f1944..4289ccf 100644 --- a/src/libvirt_public.syms +++ b/src/libvirt_public.syms @@ -520,6 +520,7 @@ LIBVIRT_0.9.10 { global: virDomainShutdownFlags; virStorageVolWipePattern; + virDomainSuspendFlags; } LIBVIRT_0.9.9; # .... define new API here using predicted next version number .... diff --git a/src/remote/remote_driver.c b/src/remote/remote_driver.c index f79f53e..ed5772f 100644 --- a/src/remote/remote_driver.c +++ b/src/remote/remote_driver.c @@ -4615,6 +4615,7 @@ static virDriver remote_driver = { .domainLookupByUUID = remoteDomainLookupByUUID, /* 0.3.0 */ .domainLookupByName = remoteDomainLookupByName, /* 0.3.0 */ .domainSuspend = remoteDomainSuspend, /* 0.3.0 */ + .domainSuspendFlags = remoteDomainSuspendFlags, /* 0.9.10 */ .domainResume = remoteDomainResume, /* 0.3.0 */ .domainShutdown = remoteDomainShutdown, /* 0.3.0 */ .domainShutdownFlags = remoteDomainShutdownFlags, /* 0.9.10 */ diff --git a/src/remote/remote_protocol.x b/src/remote/remote_protocol.x index 0f354bb..d298a03 100644 --- a/src/remote/remote_protocol.x +++ b/src/remote/remote_protocol.x @@ -732,6 +732,11 @@ struct remote_domain_suspend_args { remote_nonnull_domain dom; }; +struct remote_domain_suspend_flags_args { + remote_nonnull_domain dom; + unsigned int flags; +}; + struct remote_domain_resume_args { remote_nonnull_domain dom; }; @@ -2667,7 +2672,9 @@ enum remote_procedure { REMOTE_PROC_DOMAIN_SET_INTERFACE_PARAMETERS = 256, /* autogen autogen */ REMOTE_PROC_DOMAIN_GET_INTERFACE_PARAMETERS = 257, /* skipgen skipgen */ REMOTE_PROC_DOMAIN_SHUTDOWN_FLAGS = 258, /* autogen autogen */ - REMOTE_PROC_STORAGE_VOL_WIPE_PATTERN = 259 /* autogen autogen */ + REMOTE_PROC_STORAGE_VOL_WIPE_PATTERN = 259, /* autogen autogen */ + + REMOTE_PROC_DOMAIN_SUSPEND_FLAGS = 260 /* autogen autogen */ /* * Notice how the entries are grouped in sets of 10 ? diff --git a/src/remote_protocol-structs b/src/remote_protocol-structs index de85862..dc47038 100644 --- a/src/remote_protocol-structs +++ b/src/remote_protocol-structs @@ -440,6 +440,10 @@ struct remote_domain_lookup_by_name_ret { struct remote_domain_suspend_args { remote_nonnull_domain dom; }; +struct remote_domain_suspend_flags_args { + remote_nonnull_domain dom; + u_int flags; +}; struct remote_domain_resume_args { remote_nonnull_domain dom; }; @@ -2101,4 +2105,5 @@ enum remote_procedure { REMOTE_PROC_DOMAIN_GET_INTERFACE_PARAMETERS = 257, REMOTE_PROC_DOMAIN_SHUTDOWN_FLAGS = 258, REMOTE_PROC_STORAGE_VOL_WIPE_PATTERN = 259, + REMOTE_PROC_DOMAIN_SUSPEND_FLAGS = 260, }; -- 1.7.3.4 -- libvir-list mailing list libvir-list@xxxxxxxxxx https://www.redhat.com/mailman/listinfo/libvir-list