[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Xen-devel] [RFC PATCH 3/6] libxl: implement control feature checking



docs/misc/xenstore-paths documents a set of feature flags that can be used
to determine whether values written to ~/control/shutdown will result in
actions in the guest.

This patch adds empty guest writable values into xenstore for each
documented feature flag (to allow the guest to update them) and also code
to check these flags to determine whether a specific use of
libxl__domain_pvcontrol() will definitely *not* result in action and fail
the call immediately.

Signed-off-by: Paul Durrant <paul.durrant@xxxxxxxxxx>
Cc: Ian Jackson <ian.jackson@xxxxxxxxxxxxx>
Cc: Stefano Stabellini <stefano.stabellini@xxxxxxxxxxxxx>
Cc: Ian Campbell <ian.campbell@xxxxxxxxxx>
Cc: Wei Liu <wei.liu2@xxxxxxxxxx>
---
 tools/libxl/libxl.c             | 51 ++++++++++++++++++++++-------------------
 tools/libxl/libxl_create.c      | 22 ++++++++++++++++++
 tools/libxl/libxl_dom_suspend.c |  6 ++++-
 tools/libxl/libxl_internal.h    |  8 +++----
 4 files changed, 58 insertions(+), 29 deletions(-)

diff --git a/tools/libxl/libxl.c b/tools/libxl/libxl.c
index 0cb4a15..d7dd081 100644
--- a/tools/libxl/libxl.c
+++ b/tools/libxl/libxl.c
@@ -1082,11 +1082,13 @@ int libxl_domain_unpause(libxl_ctx *ctx, uint32_t domid)
     return rc;
 }
 
-int libxl__domain_pvcontrol_available(libxl__gc *gc, uint32_t domid)
+int libxl__domain_pvcontrol_available(libxl__gc *gc, xs_transaction_t t,
+                                      uint32_t domid, const char *cmd)
 {
     libxl_ctx *ctx = libxl__gc_owner(gc);
-
     uint64_t pvdriver = 0;
+    const char *dom_path;
+    char *flag;
     int ret;
 
     libxl_domain_type domtype = libxl__domain_type(gc, domid);
@@ -1101,34 +1103,37 @@ int libxl__domain_pvcontrol_available(libxl__gc *gc, 
uint32_t domid)
         LOGE(ERROR, "getting HVM callback IRQ");
         return ERROR_FAIL;
     }
-    return !!pvdriver;
-}
 
-const char *libxl__domain_pvcontrol_xspath(libxl__gc *gc, uint32_t domid)
-{
-    const char *dom_path;
+    if (!pvdriver)
+        return 0;
 
     dom_path = libxl__xs_get_dompath(gc, domid);
     if (!dom_path)
-        return NULL;
+        return ERROR_FAIL;
 
-    return GCSPRINTF("%s/control/shutdown", dom_path);
+    /* Check to see if the command is explicitly not supported */
+    flag = libxl__xs_read(gc, t,
+                          libxl__sprintf(gc, "%s/control/feature-%s",
+                                         dom_path, cmd));
+    if (flag && !strcmp(flag, "0"))
+        return 0;
+
+    return 1;
 }
 
-char * libxl__domain_pvcontrol_read(libxl__gc *gc, xs_transaction_t t,
-                                    uint32_t domid)
+const char *libxl__domain_pvcontrol_xspath(libxl__gc *gc, uint32_t domid)
 {
-    const char *shutdown_path;
+    const char *dom_path;
 
-    shutdown_path = libxl__domain_pvcontrol_xspath(gc, domid);
-    if (!shutdown_path)
+    dom_path = libxl__xs_get_dompath(gc, domid);
+    if (!dom_path)
         return NULL;
 
-    return libxl__xs_read(gc, t, shutdown_path);
+    return GCSPRINTF("%s/control/shutdown", dom_path);
 }
 
-int libxl__domain_pvcontrol_write(libxl__gc *gc, xs_transaction_t t,
-                                  uint32_t domid, const char *cmd)
+static int libxl__domain_pvcontrol_write(libxl__gc *gc, xs_transaction_t t,
+                                         uint32_t domid, const char *cmd)
 {
     const char *shutdown_path;
 
@@ -1139,26 +1144,26 @@ int libxl__domain_pvcontrol_write(libxl__gc *gc, 
xs_transaction_t t,
     return libxl__xs_printf(gc, t, shutdown_path, "%s", cmd);
 }
 
-static int libxl__domain_pvcontrol(libxl__gc *gc, uint32_t domid,
-                                   const char *cmd)
+int libxl__domain_pvcontrol(libxl__gc *gc, xs_transaction_t t,
+                            uint32_t domid, const char *cmd)
 {
     int ret;
 
-    ret = libxl__domain_pvcontrol_available(gc, domid);
+    ret = libxl__domain_pvcontrol_available(gc, t, domid, cmd);
     if (ret < 0)
         return ret;
 
     if (!ret)
         return ERROR_NOPARAVIRT;
 
-    return libxl__domain_pvcontrol_write(gc, XBT_NULL, domid, cmd);
+    return libxl__domain_pvcontrol_write(gc, t, domid, cmd);
 }
 
 int libxl_domain_shutdown(libxl_ctx *ctx, uint32_t domid)
 {
     GC_INIT(ctx);
     int ret;
-    ret = libxl__domain_pvcontrol(gc, domid, "poweroff");
+    ret = libxl__domain_pvcontrol(gc, XBT_NULL, domid, "poweroff");
     GC_FREE;
     return ret;
 }
@@ -1167,7 +1172,7 @@ int libxl_domain_reboot(libxl_ctx *ctx, uint32_t domid)
 {
     GC_INIT(ctx);
     int ret;
-    ret = libxl__domain_pvcontrol(gc, domid, "reboot");
+    ret = libxl__domain_pvcontrol(gc, XBT_NULL, domid, "reboot");
     GC_FREE;
     return ret;
 }
diff --git a/tools/libxl/libxl_create.c b/tools/libxl/libxl_create.c
index 279deda..cc82311 100644
--- a/tools/libxl/libxl_create.c
+++ b/tools/libxl/libxl_create.c
@@ -619,6 +619,28 @@ retry_transaction:
                            libxl__sprintf(gc, "%s/shutdown", control_path),
                            rwperm, ARRAY_SIZE(rwperm),
                            "");
+    libxl__xs_printf_perms(gc, t,
+                           libxl__sprintf(gc, "%s/feature-poweroff", 
control_path),
+                           rwperm, ARRAY_SIZE(rwperm),
+                           "");
+    libxl__xs_printf_perms(gc, t,
+                           libxl__sprintf(gc, "%s/feature-reboot", 
control_path),
+                           rwperm, ARRAY_SIZE(rwperm),
+                           "");
+    libxl__xs_printf_perms(gc, t,
+                           libxl__sprintf(gc, "%s/feature-suspend", 
control_path),
+                           rwperm, ARRAY_SIZE(rwperm),
+                           "");
+    if (info->type == LIBXL_DOMAIN_TYPE_HVM) {
+        libxl__xs_printf_perms(gc, t,
+                               libxl__sprintf(gc, "%s/feature-s3", 
control_path),
+                               rwperm, ARRAY_SIZE(rwperm),
+                               "");
+        libxl__xs_printf_perms(gc, t,
+                               libxl__sprintf(gc, "%s/feature-s4", 
control_path),
+                               rwperm, ARRAY_SIZE(rwperm),
+                               "");
+    }
 
     libxl__xs_mkdir(gc, t,
                     libxl__sprintf(gc, "%s/device/suspend/event-channel", 
dom_path),
diff --git a/tools/libxl/libxl_dom_suspend.c b/tools/libxl/libxl_dom_suspend.c
index 4cc01ad..5edfef2 100644
--- a/tools/libxl/libxl_dom_suspend.c
+++ b/tools/libxl/libxl_dom_suspend.c
@@ -143,7 +143,11 @@ static void domain_suspend_callback_common(libxl__egc *egc,
     LOG(DEBUG, "issuing %s suspend request via XenBus control node",
         dss->hvm ? "PVHVM" : "PV");
 
-    libxl__domain_pvcontrol_write(gc, XBT_NULL, domid, "suspend");
+    rc = libxl__domain_pvcontrol(gc, XBT_NULL, domid, "suspend");
+    if (rc < 0) {
+        LOGE(ERROR, "suspend failed");
+        goto err;
+    }
 
     dss->pvcontrol.path = libxl__domain_pvcontrol_xspath(gc, domid);
     if (!dss->pvcontrol.path) { rc = ERROR_FAIL; goto err; }
diff --git a/tools/libxl/libxl_internal.h b/tools/libxl/libxl_internal.h
index 04d8a29..ab62e6f 100644
--- a/tools/libxl/libxl_internal.h
+++ b/tools/libxl/libxl_internal.h
@@ -1135,13 +1135,11 @@ _hidden int libxl__domain_resume(libxl__gc *gc, 
uint32_t domid,
                                  int suspend_cancel);
 
 /* returns 0 or 1, or a libxl error code */
-_hidden int libxl__domain_pvcontrol_available(libxl__gc *gc, uint32_t domid);
+_hidden int libxl__domain_pvcontrol_available(libxl__gc *gc, xs_transaction_t 
t, uint32_t domid,const char *cmd);
 
 _hidden const char *libxl__domain_pvcontrol_xspath(libxl__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);
+_hidden int libxl__domain_pvcontrol(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);
-- 
2.1.4


_______________________________________________
Xen-devel mailing list
Xen-devel@xxxxxxxxxxxxx
http://lists.xen.org/xen-devel


 


Rackspace

Lists.xenproject.org is hosted with RackSpace, monitoring our
servers 24x7x365 and backed by RackSpace's Fanatical Support®.