]> git.ipfire.org Git - thirdparty/libvirt.git/commitdiff
Add a public API to invoke suspend/resume on the host
authorSrivatsa S. Bhat <srivatsa.bhat@linux.vnet.ibm.com>
Tue, 29 Nov 2011 06:37:06 +0000 (14:37 +0800)
committerDaniel Veillard <veillard@redhat.com>
Tue, 29 Nov 2011 09:29:16 +0000 (17:29 +0800)
Implement the public definitions for the new API
virNodeSuspendForDuration() which will be subsequently used to
do a timed suspend on the host.

include/libvirt/libvirt.h.in
src/driver.h
src/libvirt.c
src/libvirt_public.syms

index 0787f18249e3ef37230d13886b0cf3298a0e4260..894db374f45bb03efed68e2452fbbaa76e371dfa 100644 (file)
@@ -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
  */
index 9e78257e362ca492660e2c4433436b2a3e72fb94..efb41d97a660e4a0192f0013a11b04cc339d30d1 100644 (file)
@@ -723,6 +723,11 @@ typedef int
                      unsigned long flags,
                      int cancelled);
 
+typedef int
+    (*virDrvNodeSuspendForDuration)(virConnectPtr conn, unsigned int target,
+                                     unsigned long long duration,
+                                     unsigned int flags);
+
 
 typedef int
     (*virDrvDomainBlockJobAbort)(virDomainPtr dom, const char *path,
@@ -907,6 +912,7 @@ struct _virDriver {
     virDrvDomainBlockPull domainBlockPull;
     virDrvSetKeepAlive setKeepAlive;
     virDrvConnectIsAlive isAlive;
+    virDrvNodeSuspendForDuration nodeSuspendForDuration;
 };
 
 typedef int
index b428fe63ae2814cfea0f1e640170a3eda46f9076..02b8343c5f4adf6989a13e71238c7e218c911c4c 100644 (file)
@@ -6353,6 +6353,67 @@ error:
     return 0;
 }
 
+/**
+ * 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
index 6ba1526b26d929e3d95d6906685ff6b4c555158e..d2f272c555aa84c0653f9fb28d87b6721b130964 100644 (file)
@@ -502,6 +502,7 @@ LIBVIRT_0.9.8 {
     global:
         virConnectIsAlive;
         virConnectSetKeepAlive;
+        virNodeSuspendForDuration;
 } LIBVIRT_0.9.7;
 
 # .... define new API here using predicted next version number ....