libxl: split libxl_domain_shutdown into libxl_domain_shutdown,..._reboot
authorIan Campbell <ian.campbell@citrix.com>
Wed, 21 Dec 2011 10:47:11 +0000 (10:47 +0000)
committerIan Campbell <ian.campbell@citrix.com>
Wed, 21 Dec 2011 10:47:11 +0000 (10:47 +0000)
The other integer request types which shutdown supported are not
useful. Specifically:

 * "suspend" is not usable via this interface since it requires other
   scaffolding, libxl_domain_suspend provides this already.
 * "halt" is the same as "poweroff".
 * "crash" is unused and at least Linux does not implement it. If a user
   steps forward then libxl_domain_crash is trivial to add.

Signed-off-by: Ian Campbell <ian.campbell@citrix.com>
Committed-by: Ian Jackson <ian.jackson.citrix.com>
Acked-by: Ian Jackson <ian.jackson.citrix.com>
tools/libxl/libxl.c
tools/libxl/libxl.h
tools/libxl/xl_cmdimpl.c
tools/python/xen/lowlevel/xl/xl.c

index bc298eb91f1988fdcaea1d79d0d16cd55c6c6243..1407e98e84f4607d9dfef9077772e7e6462ecb27 100644 (file)
@@ -594,38 +594,38 @@ int libxl__domain_pvcontrol_write(libxl__gc *gc, xs_transaction_t t,
     return libxl__xs_write(gc, t, shutdown_path, "%s", cmd);
 }
 
-static char *req_table[] = {
-    [0] = "poweroff",
-    [1] = "reboot",
-    [2] = "suspend",
-    [3] = "crash",
-    [4] = "halt",
-};
-
-int libxl_domain_shutdown(libxl_ctx *ctx, uint32_t domid, int req)
+static int libxl__domain_pvcontrol(libxl__gc *gc, uint32_t domid,
+                                   const char *cmd)
 {
-    GC_INIT(ctx);
     int ret;
 
-    if (req > ARRAY_SIZE(req_table)) {
-        GC_FREE;
-        return ERROR_INVAL;
-    }
-
     ret = libxl__domain_pvcontrol_available(gc, domid);
     if (ret < 0)
-        goto out;
+        return ret;
 
     if (!ret) {
-        LIBXL__LOG(CTX, LIBXL__LOG_ERROR, "PV shutdown control not available:"
-                   " graceful shutdown not possible, use destroy");
-        ret = ERROR_FAIL;
-        goto out;
+        LIBXL__LOG(CTX, LIBXL__LOG_ERROR,
+                   "PV control interface not available\n");
+        return ERROR_FAIL;
     }
 
-    ret = libxl__domain_pvcontrol_write(gc, XBT_NULL, domid, req_table[req]);
+    return libxl__domain_pvcontrol_write(gc, XBT_NULL, domid, cmd);
+}
+
+int libxl_domain_shutdown(libxl_ctx *ctx, uint32_t domid)
+{
+    GC_INIT(ctx);
+    int ret;
+    ret = libxl__domain_pvcontrol(gc, domid, "poweroff");
+    GC_FREE;
+    return ret;
+}
 
-out:
+int libxl_domain_reboot(libxl_ctx *ctx, uint32_t domid)
+{
+    GC_INIT(ctx);
+    int ret;
+    ret = libxl__domain_pvcontrol(gc, domid, "reboot");
     GC_FREE;
     return ret;
 }
index d15bcc3e984dfaa5c63e40d317322b0509eb7309..5344cd07a1e55883da6b21d1f1a3c48215b22765 100644 (file)
@@ -268,7 +268,8 @@ void libxl_domain_config_dispose(libxl_domain_config *d_config);
 int libxl_domain_suspend(libxl_ctx *ctx, libxl_domain_suspend_info *info,
                           uint32_t domid, int fd);
 int libxl_domain_resume(libxl_ctx *ctx, uint32_t domid);
-int libxl_domain_shutdown(libxl_ctx *ctx, uint32_t domid, int req);
+int libxl_domain_shutdown(libxl_ctx *ctx, uint32_t domid);
+int libxl_domain_reboot(libxl_ctx *ctx, uint32_t domid);
 int libxl_domain_destroy(libxl_ctx *ctx, uint32_t domid);
 int libxl_domain_preserve(libxl_ctx *ctx, uint32_t domid, libxl_domain_create_info *info, const char *name_suffix, libxl_uuid new_uuid);
 
index bcf2b8ddf1d898e31beda13e8008a4fe46d91a60..f81b6bb4ac48be56573fa4d0c7a6d50bd9780558 100644 (file)
@@ -2265,7 +2265,7 @@ static void shutdown_domain(const char *p, int wait)
     int rc;
 
     find_domain(p);
-    rc=libxl_domain_shutdown(ctx, domid, 0);
+    rc=libxl_domain_shutdown(ctx, domid);
     if (rc) { fprintf(stderr,"shutdown failed (rc=%d)\n",rc);exit(-1); }
 
     if (wait) {
@@ -2307,7 +2307,7 @@ static void reboot_domain(const char *p)
 {
     int rc;
     find_domain(p);
-    rc=libxl_domain_shutdown(ctx, domid, 1);
+    rc=libxl_domain_reboot(ctx, domid);
     if (rc) { fprintf(stderr,"reboot failed (rc=%d)\n",rc);exit(-1); }
 }
 
index 041daadc815a18582cf32070a971a83aca8904c5..c916e2f54fed0988e9d5050e15bdf592b7cd4b90 100644 (file)
@@ -424,10 +424,10 @@ static PyObject *pyxl_domid_to_name(XlObject *self, PyObject *args)
 
 static PyObject *pyxl_domain_shutdown(XlObject *self, PyObject *args)
 {
-    int domid, req = 0;
-    if ( !PyArg_ParseTuple(args, "i|i", &domid, &req) )
+    int domid;
+    if ( !PyArg_ParseTuple(args, "i", &domid) )
         return NULL;
-    if ( libxl_domain_shutdown(self->ctx, domid, req) ) {
+    if ( libxl_domain_shutdown(self->ctx, domid) ) {
         PyErr_SetString(xl_error_obj, "cannot shutdown domain");
         return NULL;
     }
@@ -435,6 +435,19 @@ static PyObject *pyxl_domain_shutdown(XlObject *self, PyObject *args)
     return Py_None;
 }
 
+static PyObject *pyxl_domain_reboot(XlObject *self, PyObject *args)
+{
+    int domid;
+    if ( !PyArg_ParseTuple(args, "i", &domid) )
+        return NULL;
+    if ( libxl_domain_reboot(self->ctx, domid) ) {
+        PyErr_SetString(xl_error_obj, "cannot reboot domain");
+        return NULL;
+    }
+    Py_INCREF(Py_None);
+    return Py_None;
+}
+
 static PyObject *pyxl_domain_destroy(XlObject *self, PyObject *args)
 {
     int domid;
@@ -637,6 +650,8 @@ static PyMethodDef pyxl_methods[] = {
          "Retrieve name from domain-id"},
     {"domain_shutdown", (PyCFunction)pyxl_domain_shutdown, METH_VARARGS,
          "Shutdown a domain"},
+    {"domain_reboot", (PyCFunction)pyxl_domain_reboot, METH_VARARGS,
+         "Reboot a domain"},
     {"domain_destroy", (PyCFunction)pyxl_domain_destroy, METH_VARARGS,
          "Destroy a domain"},
     {"domain_pause", (PyCFunction)pyxl_domain_pause, METH_VARARGS,