Mailing List Archive

[PATCH 1 of 3] libxl: add libxl__domain_pvcontrol_{available, read, write}
# HG changeset patch
# User Ian Campbell <ian.campbell@citrix.com>
# Date 1323793378 0
# Node ID 97677918e3a4c8e724d7c8a6aba9cec570400c99
# Parent f2e14742b2a2c1f40bc36063a1485b4072865fd1
libxl: add libxl__domain_pvcontrol_{available,read,write}

Use instead of open coding.

Signed-off-by: Ian Campbell <ian.campbell@citrix.com>

diff -r f2e14742b2a2 -r 97677918e3a4 tools/libxl/libxl.c
--- a/tools/libxl/libxl.c Tue Dec 13 16:10:20 2011 +0000
+++ b/tools/libxl/libxl.c Tue Dec 13 16:22:58 2011 +0000
@@ -542,6 +542,58 @@ int libxl_domain_unpause(libxl_ctx *ctx,
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 (!ret) {
+ LIBXL__LOG(CTX, LIBXL__LOG_ERROR, "PV shutdown control not available:"
+ " graceful shutdown not possible, use destroy");
+ ret = ERROR_FAIL;
+ 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;
- }
- }
-
- 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 -r f2e14742b2a2 -r 97677918e3a4 tools/libxl/libxl_dom.c
--- a/tools/libxl/libxl_dom.c Tue Dec 13 16:10:20 2011 +0000
+++ b/tools/libxl/libxl_dom.c Tue Dec 13 16:22:58 2011 +0000
@@ -415,7 +415,7 @@ static int libxl__domain_suspend_common_
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_
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_
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 -r f2e14742b2a2 -r 97677918e3a4 tools/libxl/libxl_internal.h
--- a/tools/libxl/libxl_internal.h Tue Dec 13 16:10:20 2011 +0000
+++ b/tools/libxl/libxl_internal.h Tue Dec 13 16:22:58 2011 +0000
@@ -247,6 +247,12 @@ _hidden int libxl__domain_suspend_common
_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);

_______________________________________________
Xen-devel mailing list
Xen-devel@lists.xensource.com
http://lists.xensource.com/xen-devel