[libvirt] [PATCH v4 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 12:03:06 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 |   17 +++++++++++-
 src/driver.h                 |    6 ++++
 src/libvirt.c                |   61 ++++++++++++++++++++++++++++++++++++++++++
 src/libvirt_public.syms      |    5 +++
 4 files changed, 88 insertions(+), 1 deletions(-)

diff --git a/include/libvirt/libvirt.h.in b/include/libvirt/libvirt.h.in
index 2ab89f5..ad9e8f1 100644
--- a/include/libvirt/libvirt.h.in
+++ b/include/libvirt/libvirt.h.in
@@ -249,7 +249,17 @@ typedef enum {
     VIR_DOMAIN_START_FORCE_BOOT   = 1 << 3, /* Boot, discarding any managed save */
 } virDomainCreateFlags;
 
-
+/**
+ * virNodeSuspendState:
+ *
+ * Flags to indicate which system-wide sleep state the host must be
+ * transitioned to.
+ */
+typedef enum {
+    VIR_NODE_S3             = (1 << 0),              /* Suspend-to-RAM */
+    VIR_NODE_S4             = (1 << 1),              /* Suspend-to-Disk */
+    VIR_NODE_HYBRID_SUSPEND = (1 << 2),              /* Hybrid-Suspend */
+} virNodeSuspendState;
 
 /**
  * virStream:
@@ -1085,6 +1095,11 @@ unsigned long long      virNodeGetFreeMemory    (virConnectPtr conn);
 int                     virNodeGetSecurityModel (virConnectPtr conn,
                                                  virSecurityModelPtr secmodel);
 
+int                     virNodeSuspendForDuration (virConnectPtr conn,
+                                                   int state,
+                                                   unsigned long long duration,
+                                                   unsigned int flags);
+
 /*
  * Gather list of running domains
  */
diff --git a/src/driver.h b/src/driver.h
index 4c14aaa..60df410 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, int state,
+                                     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..47c49fa 100644
--- a/src/libvirt.c
+++ b/src/libvirt.c
@@ -6359,6 +6359,67 @@ error:
 }
 
 /**
+ * virNodeSuspendForDuration:
+ * @conn: pointer to the hypervisor connection
+ * @state: the state to which the host must be suspended to,
+ *         such as: VIR_NODE_S3 (Suspend-to-RAM)
+ *                  VIR_NODE_S4 (Suspend-to-Disk)
+ *                  VIR_NODE_HYBRID_SUSPEND (Hybrid-Suspend, which is a
+ *                  combination of S3 and S4).
+ * @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,
+                          int state,
+                          unsigned long long duration,
+                          unsigned int flags)
+{
+
+    VIR_DEBUG("conn=%p, state=%d, duration=%lld", conn, state, 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, state,
+                                                   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