[libvirt] [PATCH v5 1/4] Add a public API to invoke suspend/resume on the host

Srivatsa S. Bhat srivatsa.bhat at linux.vnet.ibm.com
Mon Nov 28 21:42:18 UTC 2011


Implement the public definitions for the new API
virNodeSuspendForDuration() which will be subsequently used to
do a timed suspend on the host.

Signed-off-by: Srivatsa S. Bhat <srivatsa.bhat at linux.vnet.ibm.com>
---

 include/libvirt/libvirt.h.in |   16 +++++++++++
 src/driver.h                 |    6 ++++
 src/libvirt.c                |   61 ++++++++++++++++++++++++++++++++++++++++++
 src/libvirt_public.syms      |    5 +++
 4 files changed, 88 insertions(+), 0 deletions(-)

diff --git a/include/libvirt/libvirt.h.in b/include/libvirt/libvirt.h.in
index 2ab89f5..c89448b 100644
--- a/include/libvirt/libvirt.h.in
+++ b/include/libvirt/libvirt.h.in
@@ -250,6 +250,17 @@ typedef enum {
 } virDomainCreateFlags;
 
 
+/**
+ * virNodeSuspendTarget:
+ *
+ * Flags to indicate which system-wide sleep state the host must be
+ * transitioned to.
+ */
+typedef enum {
+    VIR_NODE_SUSPEND_TARGET_MEM     = (1 << 0),
+    VIR_NODE_SUSPEND_TARGET_DISK    = (1 << 1),
+    VIR_NODE_SUSPEND_TARGET_HYBRID  = (1 << 2),
+} virNodeSuspendTarget;
 
 /**
  * virStream:
@@ -1085,6 +1096,11 @@ unsigned long long      virNodeGetFreeMemory    (virConnectPtr conn);
 int                     virNodeGetSecurityModel (virConnectPtr conn,
                                                  virSecurityModelPtr secmodel);
 
+int                     virNodeSuspendForDuration (virConnectPtr conn,
+                                                   unsigned int target,
+                                                   unsigned long long duration,
+                                                   unsigned int flags);
+
 /*
  * Gather list of running domains
  */
diff --git a/src/driver.h b/src/driver.h
index 4c14aaa..5f3665d 100644
--- a/src/driver.h
+++ b/src/driver.h
@@ -740,6 +740,11 @@ typedef int
     (*virDrvDomainBlockPull)(virDomainPtr dom, const char *path,
                              unsigned long bandwidth, unsigned int flags);
 
+typedef int
+    (*virDrvNodeSuspendForDuration)(virConnectPtr conn, unsigned int target,
+                                     unsigned long long duration,
+                                     unsigned int flags);
+
 
 /**
  * _virDriver:
@@ -899,6 +904,7 @@ struct _virDriver {
     virDrvDomainGetBlockJobInfo domainGetBlockJobInfo;
     virDrvDomainBlockJobSetSpeed domainBlockJobSetSpeed;
     virDrvDomainBlockPull domainBlockPull;
+    virDrvNodeSuspendForDuration nodeSuspendForDuration;
 };
 
 typedef int
diff --git a/src/libvirt.c b/src/libvirt.c
index 1518ed2..7a13b11 100644
--- a/src/libvirt.c
+++ b/src/libvirt.c
@@ -6359,6 +6359,67 @@ error:
 }
 
 /**
+ * virNodeSuspendForDuration:
+ * @conn: pointer to the hypervisor connection
+ * @target: the state to which the host must be suspended to,
+ *         such as: VIR_NODE_SUSPEND_TARGET_MEM (Suspend-to-RAM)
+ *                  VIR_NODE_SUSPEND_TARGET_DISK (Suspend-to-Disk)
+ *                  VIR_NODE_SUSPEND_TARGET_HYBRID (Hybrid-Suspend,
+ *                  which is a combination of the former modes).
+ * @duration: the time duration in seconds for which the host
+ *            has to be suspended
+ * @flags: any flag values that might need to be passed;
+ *         currently unused (0).
+ *
+ * Attempt to suspend the node (host machine) for the given duration of
+ * time in the specified state (Suspend-to-RAM, Suspend-to-Disk or
+ * Hybrid-Suspend). Schedule the node's Real-Time-Clock interrupt to
+ * resume the node after the duration is complete.
+ *
+ * Returns 0 on success (i.e., the node will be suspended after a short
+ * delay), -1 on failure (the operation is not supported, or an attempted
+ * suspend is already underway).
+ */
+int
+virNodeSuspendForDuration(virConnectPtr conn,
+                          unsigned int target,
+                          unsigned long long duration,
+                          unsigned int flags)
+{
+
+    VIR_DEBUG("conn=%p, target=%d, duration=%lld", conn, target, duration);
+
+    virResetLastError();
+
+    if (!VIR_IS_CONNECT(conn)) {
+        virLibConnError(VIR_ERR_INVALID_CONN, __FUNCTION__);
+        virDispatchError(NULL);
+        return -1;
+    }
+
+    if (conn->flags & VIR_CONNECT_RO) {
+        virLibConnError(VIR_ERR_OPERATION_DENIED, __FUNCTION__);
+        goto error;
+    }
+
+    if (conn->driver->nodeSuspendForDuration) {
+        int ret;
+        ret = conn->driver->nodeSuspendForDuration(conn, target,
+                                                   duration, flags);
+        if (ret < 0)
+            goto error;
+        return ret;
+    }
+
+    virLibConnError(VIR_ERR_NO_SUPPORT, __FUNCTION__);
+
+error:
+    virDispatchError(conn);
+    return -1;
+}
+
+
+/**
  * virDomainGetSchedulerType:
  * @domain: pointer to domain object
  * @nparams: pointer to number of scheduler parameters, can be NULL
diff --git a/src/libvirt_public.syms b/src/libvirt_public.syms
index bcefb10..a1eede6 100644
--- a/src/libvirt_public.syms
+++ b/src/libvirt_public.syms
@@ -498,4 +498,9 @@ LIBVIRT_0.9.7 {
         virDomainSnapshotNumChildren;
 } LIBVIRT_0.9.5;
 
+LIBVIRT_0.9.8 {
+    global:
+        virNodeSuspendForDuration;
+} LIBVIRT_0.9.7;
+
 # .... define new API here using predicted next version number ....




More information about the libvir-list mailing list