From: Ian Campbell Date: Thu, 28 Jan 2016 11:43:44 +0000 (+0000) Subject: libxendevicemodel: add lifecycle event callbacks X-Git-Url: http://xenbits.xensource.com/gitweb?a=commitdiff_plain;h=4deb9a90907151d3e5c552fde93d35882804fb4f;p=people%2Fliuw%2Flibxenctrl-split%2Fxen.git libxendevicemodel: add lifecycle event callbacks 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 --- diff --git a/tools/libs/devicemodel/core.c b/tools/libs/devicemodel/core.c index 057ad219b5..361ea96604 100644 --- a/tools/libs/devicemodel/core.c +++ b/tools/libs/devicemodel/core.c @@ -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 diff --git a/tools/libs/devicemodel/include/xendevicemodel.h b/tools/libs/devicemodel/include/xendevicemodel.h index bcfba4174c..331e6e42b8 100644 --- a/tools/libs/devicemodel/include/xendevicemodel.h +++ b/tools/libs/devicemodel/include/xendevicemodel.h @@ -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: diff --git a/tools/libs/devicemodel/libxendevicemodel.map b/tools/libs/devicemodel/libxendevicemodel.map index 980c429425..1c3d93a372 100644 --- a/tools/libs/devicemodel/libxendevicemodel.map +++ b/tools/libs/devicemodel/libxendevicemodel.map @@ -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 */ }; diff --git a/tools/libs/devicemodel/private.h b/tools/libs/devicemodel/private.h index b1f40c2861..93cf2ed48d 100644 --- a/tools/libs/devicemodel/private.h +++ b/tools/libs/devicemodel/private.h @@ -6,6 +6,9 @@ #include #include +#include +#include + struct xendevicemodel_handle { xentoollog_logger *logger, *logger_tofree; unsigned flags;