So far, we have just bare virDomainSuspend() API that suspends a domain.
However, in the future there might occur a case, in which we may want
to modify suspend behavior slightly. In that case, @flags are useful.
Signed-off-by: Michal Privoznik <mprivozn(a)redhat.com>
---
include/libvirt/libvirt.h.in | 2 ++
src/driver.h | 5 +++++
src/libvirt.c | 49 ++++++++++++++++++++++++++++++++++++++++----
src/libvirt_public.syms | 5 +++++
src/remote/remote_driver.c | 1 +
src/remote/remote_protocol.x | 13 +++++++++++-
src/remote_protocol-structs | 5 +++++
7 files changed, 75 insertions(+), 5 deletions(-)
diff --git a/include/libvirt/libvirt.h.in b/include/libvirt/libvirt.h.in
index b3ce000..cc916c7 100644
--- a/include/libvirt/libvirt.h.in
+++ b/include/libvirt/libvirt.h.in
@@ -1661,6 +1661,8 @@ int virDomainFree (virDomainPtr
domain);
* Domain suspend/resume
*/
int virDomainSuspend (virDomainPtr domain);
+int virDomainSuspendFlags (virDomainPtr domain,
+ unsigned int flags);
int virDomainResume (virDomainPtr domain);
int virDomainPMSuspendForDuration (virDomainPtr domain,
unsigned int target,
diff --git a/src/driver.h b/src/driver.h
index 5f4cd8d..d325e18 100644
--- a/src/driver.h
+++ b/src/driver.h
@@ -160,6 +160,10 @@ typedef int
(*virDrvDomainSuspend)(virDomainPtr domain);
typedef int
+(*virDrvDomainSuspendFlags)(virDomainPtr domain,
+ unsigned int flags);
+
+typedef int
(*virDrvDomainResume)(virDomainPtr domain);
typedef int
@@ -1167,6 +1171,7 @@ struct _virDriver {
virDrvDomainLookupByUUID domainLookupByUUID;
virDrvDomainLookupByName domainLookupByName;
virDrvDomainSuspend domainSuspend;
+ virDrvDomainSuspendFlags domainSuspendFlags;
virDrvDomainResume domainResume;
virDrvDomainPMSuspendForDuration domainPMSuspendForDuration;
virDrvDomainPMWakeup domainPMWakeup;
diff --git a/src/libvirt.c b/src/libvirt.c
index 9cc5b1c..e39031a 100644
--- a/src/libvirt.c
+++ b/src/libvirt.c
@@ -2347,13 +2347,54 @@ error:
/**
+ * virDomainSuspendFlags:
+ * @domain: a domain object
+ * @flags: extra flags, not used yet, so callers should always pass 0
+ *
+ * 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 may require privileged access.
+ * Moreover, suspend may not be supported if domain is in some special
+ * state like VIR_DOMAIN_PMSUSPENDED.
+ *
+ * Returns 0 in case of success and -1 in case of failure.
+ */
+int
+virDomainSuspendFlags(virDomainPtr domain,
+ unsigned int flags)
+{
+ VIR_DOMAIN_DEBUG(domain, "flags=%x", flags);
+
+ virResetLastError();
+
+ virCheckDomainReturn(domain, -1);
+ virCheckReadOnlyGoto(domain->conn->flags, error);
+
+ if (domain->conn->driver->domainSuspendFlags) {
+ int ret;
+ ret = domain->conn->driver->domainSuspendFlags(domain, flags);
+ if (ret < 0)
+ goto error;
+ return ret;
+ }
+
+ virReportUnsupportedError();
+
+error:
+ virDispatchError(domain->conn);
+ return -1;
+}
+
+
+/**
* virDomainResume:
* @domain: a domain object
*
- * Resume a suspended domain, the process is restarted from the state where
- * it was frozen by calling virDomainSuspend().
- * This function may require privileged access
- * Moreover, resume may not be supported if domain is in some
+ * Resume a suspended domain, the process is restarted from the state
+ * where it was frozen by calling virDomainSuspend() or
+ * virDomainSuspendFlags(). This function may require privileged
+ * access Moreover, resume may not be supported if domain is in some
* special state like VIR_DOMAIN_PMSUSPENDED.
*
* Returns 0 in case of success and -1 in case of failure.
diff --git a/src/libvirt_public.syms b/src/libvirt_public.syms
index 6ed6ce6..b04587a 100644
--- a/src/libvirt_public.syms
+++ b/src/libvirt_public.syms
@@ -645,5 +645,10 @@ LIBVIRT_1.2.1 {
virConnectNetworkEventDeregisterAny;
} LIBVIRT_1.1.3;
+LIBVIRT_1.2.2 {
+ global:
+ virDomainSuspendFlags;
+} LIBVIRT_1.2.1;
+
# .... define new API here using predicted next version number ....
diff --git a/src/remote/remote_driver.c b/src/remote/remote_driver.c
index ca86e3c..a70cb6d 100644
--- a/src/remote/remote_driver.c
+++ b/src/remote/remote_driver.c
@@ -6977,6 +6977,7 @@ static virDriver remote_driver = {
.domainLookupByUUID = remoteDomainLookupByUUID, /* 0.3.0 */
.domainLookupByName = remoteDomainLookupByName, /* 0.3.0 */
.domainSuspend = remoteDomainSuspend, /* 0.3.0 */
+ .domainSuspendFlags = remoteDomainSuspendFlags, /* 1.2.2 */
.domainResume = remoteDomainResume, /* 0.3.0 */
.domainPMSuspendForDuration = remoteDomainPMSuspendForDuration, /* 0.9.10 */
.domainPMWakeup = remoteDomainPMWakeup, /* 0.9.11 */
diff --git a/src/remote/remote_protocol.x b/src/remote/remote_protocol.x
index 790a020..e25ecf3 100644
--- a/src/remote/remote_protocol.x
+++ b/src/remote/remote_protocol.x
@@ -772,6 +772,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;
};
@@ -5068,5 +5073,11 @@ enum remote_procedure {
* @generate: both
* @acl: none
*/
- REMOTE_PROC_NETWORK_EVENT_LIFECYCLE = 315
+ REMOTE_PROC_NETWORK_EVENT_LIFECYCLE = 315,
+
+ /**
+ * @generate: both
+ * @acl: domain:suspend
+ */
+ REMOTE_PROC_DOMAIN_SUSPEND_FLAGS = 316
};
diff --git a/src/remote_protocol-structs b/src/remote_protocol-structs
index e58482e..4adf93a 100644
--- a/src/remote_protocol-structs
+++ b/src/remote_protocol-structs
@@ -451,6 +451,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;
};
@@ -2660,4 +2664,5 @@ enum remote_procedure {
REMOTE_PROC_CONNECT_NETWORK_EVENT_REGISTER_ANY = 313,
REMOTE_PROC_CONNECT_NETWORK_EVENT_DEREGISTER_ANY = 314,
REMOTE_PROC_NETWORK_EVENT_LIFECYCLE = 315,
+ REMOTE_PROC_DOMAIN_SUSPEND_FLAGS = 316,
};
--
1.8.5.2