aboutsummaryrefslogtreecommitdiffstats
path: root/tools/libxl
diff options
context:
space:
mode:
authorIan Campbell <ian.campbell@citrix.com>2011-12-16 09:34:46 +0000
committerIan Campbell <ian.campbell@citrix.com>2011-12-16 09:34:46 +0000
commit7b83f96ce7e2560388f0c6e36551b0d748a0542a (patch)
treed9b9c347d56fb6d548e6f079ad8d1ef141eee94d /tools/libxl
parent4df7055e7774b8118a3c97153834dae619e12c13 (diff)
downloadxen-7b83f96ce7e2560388f0c6e36551b0d748a0542a.tar.gz
xen-7b83f96ce7e2560388f0c6e36551b0d748a0542a.tar.bz2
xen-7b83f96ce7e2560388f0c6e36551b0d748a0542a.zip
libxl: add libxl__domain_pvcontrol_{available,read,write}
Use instead of open coding. Signed-off-by: Ian Campbell <ian.campbell@citrix.com> Acked-by: Ian Jackson <ian.jackson.citrix.com> Committed-by: Ian Jackson <ian.jackson.citrix.com>
Diffstat (limited to 'tools/libxl')
-rw-r--r--tools/libxl/libxl.c89
-rw-r--r--tools/libxl/libxl_dom.c11
-rw-r--r--tools/libxl/libxl_internal.h6
3 files changed, 75 insertions, 31 deletions
diff --git a/tools/libxl/libxl.c b/tools/libxl/libxl.c
index 53782966da..bc298eb91f 100644
--- a/tools/libxl/libxl.c
+++ b/tools/libxl/libxl.c
@@ -542,6 +542,58 @@ int libxl_domain_unpause(libxl_ctx *ctx, uint32_t domid)
return rc;
}
+int libxl__domain_pvcontrol_available(libxl__gc *gc, uint32_t domid)
+{
+ libxl_ctx *ctx = libxl__gc_owner(gc);
+
+ unsigned long pvdriver = 0;
+ int ret;
+
+ if (LIBXL__DOMAIN_IS_TYPE(gc, domid, PV))
+ return 1;
+
+ ret = xc_get_hvm_param(ctx->xch, domid, HVM_PARAM_CALLBACK_IRQ, &pvdriver);
+ if (ret<0) {
+ LIBXL__LOG_ERRNO(ctx, LIBXL__LOG_ERROR, "getting HVM callback IRQ");
+ return ERROR_FAIL;
+ }
+ return !!pvdriver;
+}
+
+char * libxl__domain_pvcontrol_read(libxl__gc *gc, xs_transaction_t t,
+ uint32_t domid)
+{
+ const char *shutdown_path;
+ const char *dom_path;
+
+ dom_path = libxl__xs_get_dompath(gc, domid);
+ if (!dom_path)
+ return NULL;
+
+ shutdown_path = libxl__sprintf(gc, "%s/control/shutdown", dom_path);
+ if (!shutdown_path)
+ return NULL;
+
+ return libxl__xs_read(gc, t, shutdown_path);
+}
+
+int libxl__domain_pvcontrol_write(libxl__gc *gc, xs_transaction_t t,
+ uint32_t domid, const char *cmd)
+{
+ const char *shutdown_path;
+ const char *dom_path;
+
+ dom_path = libxl__xs_get_dompath(gc, domid);
+ if (!dom_path)
+ return ERROR_FAIL;
+
+ shutdown_path = libxl__sprintf(gc, "%s/control/shutdown", dom_path);
+ if (!shutdown_path)
+ return ERROR_FAIL;
+
+ return libxl__xs_write(gc, t, shutdown_path, "%s", cmd);
+}
+
static char *req_table[] = {
[0] = "poweroff",
[1] = "reboot",
@@ -553,42 +605,29 @@ static char *req_table[] = {
int libxl_domain_shutdown(libxl_ctx *ctx, uint32_t domid, int req)
{
GC_INIT(ctx);
- char *shutdown_path;
- char *dom_path;
+ int ret;
if (req > ARRAY_SIZE(req_table)) {
GC_FREE;
return ERROR_INVAL;
}
- dom_path = libxl__xs_get_dompath(gc, domid);
- if (!dom_path) {
- GC_FREE;
- return ERROR_FAIL;
- }
+ ret = libxl__domain_pvcontrol_available(gc, domid);
+ if (ret < 0)
+ goto out;
- if (LIBXL__DOMAIN_IS_TYPE(gc, domid, HVM)) {
- unsigned long pvdriver = 0;
- int ret;
- ret = xc_get_hvm_param(ctx->xch, domid, HVM_PARAM_CALLBACK_IRQ, &pvdriver);
- if (ret<0) {
- LIBXL__LOG_ERRNO(ctx, LIBXL__LOG_ERROR, "getting HVM callback IRQ");
- GC_FREE;
- return ERROR_FAIL;
- }
- if (!pvdriver) {
- LIBXL__LOG(ctx, LIBXL__LOG_ERROR, "HVM domain without PV drivers:"
- " graceful shutdown not possible, use destroy");
- GC_FREE;
- return ERROR_FAIL;
- }
+ if (!ret) {
+ LIBXL__LOG(CTX, LIBXL__LOG_ERROR, "PV shutdown control not available:"
+ " graceful shutdown not possible, use destroy");
+ ret = ERROR_FAIL;
+ goto out;
}
- shutdown_path = libxl__sprintf(gc, "%s/control/shutdown", dom_path);
- xs_write(ctx->xsh, XBT_NULL, shutdown_path, req_table[req], strlen(req_table[req]));
+ ret = libxl__domain_pvcontrol_write(gc, XBT_NULL, domid, req_table[req]);
+out:
GC_FREE;
- return 0;
+ return ret;
}
int libxl_get_wait_fd(libxl_ctx *ctx, int *fd)
diff --git a/tools/libxl/libxl_dom.c b/tools/libxl/libxl_dom.c
index a63f8ce289..47e908baad 100644
--- a/tools/libxl/libxl_dom.c
+++ b/tools/libxl/libxl_dom.c
@@ -415,7 +415,7 @@ static int libxl__domain_suspend_common_callback(void *data)
struct suspendinfo *si = data;
unsigned long hvm_s_state = 0, hvm_pvdrv = 0;
int ret;
- char *path, *state = "suspend";
+ char *state = "suspend";
int watchdog;
libxl_ctx *ctx = libxl__gc_owner(si->gc);
xs_transaction_t t;
@@ -451,15 +451,14 @@ static int libxl__domain_suspend_common_callback(void *data)
LIBXL__LOG(ctx, LIBXL__LOG_DEBUG, "issuing %s suspend request via XenBus control node",
si->hvm ? "PVHVM" : "PV");
- path = libxl__sprintf(si->gc, "%s/control/shutdown", libxl__xs_get_dompath(si->gc, si->domid));
- libxl__xs_write(si->gc, XBT_NULL, path, "suspend");
+ libxl__domain_pvcontrol_write(si->gc, XBT_NULL, si->domid, "suspend");
LIBXL__LOG(ctx, LIBXL__LOG_DEBUG, "wait for the guest to acknowledge suspend request");
watchdog = 60;
while (!strcmp(state, "suspend") && watchdog > 0) {
usleep(100000);
- state = libxl__xs_read(si->gc, XBT_NULL, path);
+ state = libxl__domain_pvcontrol_read(si->gc, XBT_NULL, si->domid);
if (!state) state = "";
watchdog--;
@@ -479,11 +478,11 @@ static int libxl__domain_suspend_common_callback(void *data)
retry_transaction:
t = xs_transaction_start(ctx->xsh);
- state = libxl__xs_read(si->gc, t, path);
+ state = libxl__domain_pvcontrol_read(si->gc, t, si->domid);
if (!state) state = "";
if (!strcmp(state, "suspend"))
- libxl__xs_write(si->gc, t, path, "");
+ libxl__domain_pvcontrol_write(si->gc, t, si->domid, "");
if (!xs_transaction_end(ctx->xsh, t, 0))
if (errno == EAGAIN)
diff --git a/tools/libxl/libxl_internal.h b/tools/libxl/libxl_internal.h
index 9667893503..fa7fb16679 100644
--- a/tools/libxl/libxl_internal.h
+++ b/tools/libxl/libxl_internal.h
@@ -250,6 +250,12 @@ _hidden const char *libxl__device_model_savefile(libxl__gc *gc, uint32_t domid);
_hidden int libxl__domain_save_device_model(libxl__gc *gc, uint32_t domid, int fd);
_hidden void libxl__userdata_destroyall(libxl__gc *gc, uint32_t domid);
+_hidden int libxl__domain_pvcontrol_available(libxl__gc *gc, uint32_t domid);
+_hidden char * libxl__domain_pvcontrol_read(libxl__gc *gc,
+ xs_transaction_t t, uint32_t domid);
+_hidden int libxl__domain_pvcontrol_write(libxl__gc *gc, xs_transaction_t t,
+ uint32_t domid, const char *cmd);
+
/* from xl_device */
_hidden char *libxl__device_disk_string_of_backend(libxl_disk_backend backend);
_hidden char *libxl__device_disk_string_of_format(libxl_disk_format format);