]> xenbits.xensource.com Git - people/liuw/libxenctrl-split/xen.git/commitdiff
libxendevicemodel: add lifecycle event callbacks
authorIan Campbell <ian.campbell@citrix.com>
Thu, 28 Jan 2016 11:43:44 +0000 (11:43 +0000)
committerIan Campbell <ian.campbell@citrix.com>
Wed, 10 Feb 2016 12:45:24 +0000 (12:45 +0000)
These supercede xc_domain_shutdown and the only remaining uses of
xc_set_hvm_param in QEMU. Those will be removed in a later patch (so
as to not break bisectability of QEMU against Xen).

Signed-off-by: Ian Campbell <ian.campbell@citrix.com>
tools/libs/devicemodel/core.c
tools/libs/devicemodel/include/xendevicemodel.h
tools/libs/devicemodel/libxendevicemodel.map
tools/libs/devicemodel/private.h

index 057ad219b59cfd9766bb495604c9f8fc28d9caa5..361ea96604cb5e42cac403fcbaf1cb2b805bb0d1 100644 (file)
@@ -85,6 +85,84 @@ int xendevicemodel_close(xendevicemodel_handle *dm)
     return rc;
 }
 
+static int shutdown_remote(xendevicemodel_handle *dm, int reason,
+                           const char *what)
+{
+    int ret = -1;
+    sched_remote_shutdown_t *arg;
+
+    arg = xencall_alloc_buffer(dm->call, sizeof(*arg));
+    if ( arg == NULL )
+    {
+        LOGE(ERROR, "unable to allocate memory for %s hypercall", what);
+        goto err;
+    }
+
+    arg->domain_id = dm->domid;
+    arg->reason = reason;
+    ret = xencall2(dm->call, __HYPERVISOR_sched_op,
+                   SCHEDOP_remote_shutdown,
+                   (uintptr_t)arg);
+
+    if ( ret )
+        LOGE(ERROR, "%s hypercall failed", what);
+
+    xencall_free_buffer(dm->call, arg);
+
+ err:
+    return ret;
+}
+
+int xendevicemodel_shutdown(xendevicemodel_handle *dm)
+{
+    return shutdown_remote(dm, SHUTDOWN_poweroff, "shutdown");
+}
+
+int xendevicemodel_reboot(xendevicemodel_handle *dm)
+{
+    return shutdown_remote(dm, SHUTDOWN_reboot, "reboot");
+}
+
+static int set_s3_state(xendevicemodel_handle *dm, int state,
+                        const char *what)
+{
+    xen_hvm_param_t *arg;
+    int ret = -1;
+
+    arg = xencall_alloc_buffer(dm->call, sizeof(*arg));
+    if ( arg == NULL )
+    {
+        LOGE(ERROR, "unable to allocate memory for %s hypercall", what);
+        goto err;
+    }
+
+    arg->domid = dm->domid;
+    arg->index = HVM_PARAM_ACPI_S_STATE;
+    arg->value = state;
+
+    ret = xencall2(dm->call, __HYPERVISOR_hvm_op,
+                   HVMOP_set_param, (uintptr_t)arg);
+
+    if ( ret )
+        LOGE(ERROR, "%s hypercall failed", what);
+
+    xencall_free_buffer(dm->call, arg);
+
+ err:
+    return ret;
+}
+
+int xendevicemodel_s3_suspend(xendevicemodel_handle *dm)
+{
+    return set_s3_state(dm, 3, "s3 suspend");
+}
+
+int xendevicemodel_s3_awaken(xendevicemodel_handle *dm)
+{
+    return set_s3_state(dm, 0, "s3 awaken");
+}
+
+
 /*
  * Local variables:
  * mode: C
index bcfba4174c642dcabaf88f286221652ec0d5ff8a..331e6e42b8f9f676a344bded0a7f957483b0afd5 100644 (file)
@@ -68,6 +68,21 @@ xendevicemodel_handle *xendevicemodel_open(struct xentoollog_logger *logger,
  */
 int xendevicemodel_close(xendevicemodel_handle *dm);
 
+/*
+ * Indicate domain lifecycle changes to the hypervisor.
+ *
+ * shutdown, reboot and s3_suspend indicate to the hypervisor that
+ * emulation has resulted in the given guest behaviour.
+ *
+ * s3_awaken indicates that some event has woken the guest from S3.
+ *
+ * All functions log on failure.
+ */
+int xendevicemodel_shutdown(xendevicemodel_handle *dm);
+int xendevicemodel_reboot(xendevicemodel_handle *dm);
+int xendevicemodel_s3_suspend(xendevicemodel_handle *dm);
+int xendevicemodel_s3_awaken(xendevicemodel_handle *dm);
+
 #endif
 /*
  * Local variables:
index 980c42942592da26ec483e2bb2e53bdcf5caa7b8..1c3d93a3722d3689e30dcda3e314b96701e740a9 100644 (file)
@@ -2,5 +2,11 @@ VERS_1.0 {
        global:
                xendevicemodel_open;
                xendevicemodel_close;
+
+               xendevicemodel_shutdown;
+               xendevicemodel_reboot;
+               xendevicemodel_s3_suspend;
+               xendevicemodel_s3_awaken;
+
        local: *; /* Do not expose anything by default */
 };
index b1f40c286141f3ca485e474793074b0f946ded19..93cf2ed48d9a84d763e940fa2e87979951e4ac03 100644 (file)
@@ -6,6 +6,9 @@
 #include <xendevicemodel.h>
 #include <xencall.h>
 
+#include <xen/sched.h>
+#include <xen/hvm/params.h>
+
 struct xendevicemodel_handle {
     xentoollog_logger *logger, *logger_tofree;
     unsigned flags;