xen-devel.lists.xenproject.org archive mirror
 help / color / mirror / Atom feed
From: Roger Pau Monne <roger.pau@citrix.com>
To: xen-devel@lists.xen.org
Cc: Roger Pau Monne <roger.pau@citrix.com>
Subject: [PATCH RFC 02/10] libxl: add new hotplug interface support to hotplug script callers
Date: Fri, 21 Dec 2012 18:00:00 +0100	[thread overview]
Message-ID: <1356109208-6830-3-git-send-email-roger.pau@citrix.com> (raw)
In-Reply-To: <1356109208-6830-1-git-send-email-roger.pau@citrix.com>

Add support to call hotplug scripts that use the new hotplug interface
to the low-level functions in charge of calling hotplug scripts. This
new calling convention will be used when the hotplug_version aodev
field is 1.

Signed-off-by: Roger Pau Monné <roger.pau@citrix.com>
---
 tools/libxl/libxl_device.c   |   33 +++++++++++++++++++-
 tools/libxl/libxl_internal.h |   33 ++++++++++++++++++--
 tools/libxl/libxl_linux.c    |   68 ++++++++++++++++++++++++++++++++----------
 tools/libxl/libxl_netbsd.c   |    2 +-
 4 files changed, 115 insertions(+), 21 deletions(-)

diff --git a/tools/libxl/libxl_device.c b/tools/libxl/libxl_device.c
index 58d3f35..85c9953 100644
--- a/tools/libxl/libxl_device.c
+++ b/tools/libxl/libxl_device.c
@@ -83,6 +83,35 @@ out:
     return rc;
 }
 
+char *libxl__device_hotplug_action(libxl__gc *gc,
+                                   libxl__device_action action)
+{
+    switch (action) {
+    case DEVICE_CONNECT:
+        return "add";
+    case DEVICE_DISCONNECT:
+        return "remove";
+    case DEVICE_PREPARE:
+        return "prepare";
+    case DEVICE_UNPREPARE:
+        return "unprepare";
+    case DEVICE_LOCALATTACH:
+        return "localattach";
+    case DEVICE_LOCALDETACH:
+        return "localdetach";
+    default:
+        LOG(ERROR, "invalid action (%d) for device", action);
+        break;
+    }
+    return NULL;
+}
+
+char *libxl__device_xs_hotplug_path(libxl__gc *gc, libxl__device *dev)
+{
+    return GCSPRINTF("/local/domain/%u/libxl/hotplug/%u/%u",
+                     dev->backend_domid, dev->domid, dev->devid);
+}
+
 int libxl__device_generic_add(libxl__gc *gc, xs_transaction_t t,
         libxl__device *device, char **bents, char **fents)
 {
@@ -410,6 +439,7 @@ void libxl__prepare_ao_device(libxl__ao *ao, libxl__ao_device *aodev)
     aodev->rc = 0;
     aodev->dev = NULL;
     aodev->num_exec = 0;
+    aodev->hotplug_version = 0;
     /* Initialize timer for QEMU Bodge and hotplug execution */
     libxl__ev_time_init(&aodev->timeout);
     aodev->active = 1;
@@ -891,7 +921,8 @@ static void device_hotplug(libxl__egc *egc, libxl__ao_device *aodev)
      * and return the necessary args/env vars for execution */
     hotplug = libxl__get_hotplug_script_info(gc, aodev->dev, &args, &env,
                                              aodev->action,
-                                             aodev->num_exec);
+                                             aodev->num_exec,
+                                             aodev->hotplug_version);
     switch (hotplug) {
     case 0:
         /* no hotplug script to execute */
diff --git a/tools/libxl/libxl_internal.h b/tools/libxl/libxl_internal.h
index 0b38e3e..c41e608 100644
--- a/tools/libxl/libxl_internal.h
+++ b/tools/libxl/libxl_internal.h
@@ -1829,12 +1829,19 @@ _hidden const char *libxl__run_dir_path(void);
 
 /*----- device addition/removal -----*/
 
-/* Action to perform (either connect or disconnect) */
+/* Action to perform */
 typedef enum {
     DEVICE_CONNECT,
-    DEVICE_DISCONNECT
+    DEVICE_DISCONNECT,
+    DEVICE_PREPARE,
+    DEVICE_UNPREPARE,
+    DEVICE_LOCALATTACH,
+    DEVICE_LOCALDETACH
 } libxl__device_action;
 
+_hidden char *libxl__device_hotplug_action(libxl__gc *gc,
+                                           libxl__device_action action);
+
 typedef struct libxl__ao_device libxl__ao_device;
 typedef struct libxl__multidev libxl__multidev;
 typedef void libxl__device_callback(libxl__egc*, libxl__ao_device*);
@@ -1852,6 +1859,14 @@ typedef void libxl__device_callback(libxl__egc*, libxl__ao_device*);
  * Once _prepare has been called on a libxl__ao_device, it is safe to just
  * discard this struct, there's no need to call any destroy function.
  * _prepare can also be called multiple times with the same libxl__ao_device.
+ *
+ * If hotplug_version field is 1, the new hotplug script calling convention
+ * will be used to call the hotplug script. This new convention provides
+ * two new actions to hotplug scripts, "prepare", "unprepare", "localattach"
+ * and "localdetach". This new actions have been added to offload work done
+ * by hotplug scripts during the blackout phase of migration. "prepare" is
+ * called before the remote domain is paused, so as much operations as
+ * possible should be done in this phase.
  */
 _hidden void libxl__prepare_ao_device(libxl__ao *ao, libxl__ao_device *aodev);
 
@@ -1862,6 +1877,7 @@ struct libxl__ao_device {
     libxl__device *dev;
     int force;
     libxl__device_callback *callback;
+    int hotplug_version;
     /* return value, zeroed by user on entry, is valid on callback */
     int rc;
     /* private for multidev */
@@ -2045,6 +2061,17 @@ _hidden void libxl__initiate_device_remove(libxl__egc *egc,
                                            libxl__ao_device *aodev);
 
 /*
+ * libxl__device_xs_hotplug_path returns the xenstore hotplug
+ * path that is used to share information with the hotplug
+ * script.
+ *
+ * This path is only used by new hotplug scripts, that are
+ * specified using "method" instead of "script" in the disk
+ * parameters.
+ */
+_hidden char *libxl__device_xs_hotplug_path(libxl__gc *gc, libxl__device *dev);
+
+/*
  * libxl__get_hotplug_script_info returns the args and env that should
  * be passed to the hotplug script for the requested device.
  *
@@ -2065,7 +2092,7 @@ _hidden void libxl__initiate_device_remove(libxl__egc *egc,
 _hidden int libxl__get_hotplug_script_info(libxl__gc *gc, libxl__device *dev,
                                            char ***args, char ***env,
                                            libxl__device_action action,
-                                           int num_exec);
+                                           int num_exec, int hotplug_version);
 
 /*----- local disk attach: attach a disk locally to run the bootloader -----*/
 
diff --git a/tools/libxl/libxl_linux.c b/tools/libxl/libxl_linux.c
index 1fed3cd..43f23dd 100644
--- a/tools/libxl/libxl_linux.c
+++ b/tools/libxl/libxl_linux.c
@@ -190,32 +190,68 @@ out:
 
 static int libxl__hotplug_disk(libxl__gc *gc, libxl__device *dev,
                                char ***args, char ***env,
-                               libxl__device_action action)
+                               libxl__device_action action,
+                               int hotplug_version)
 {
     char *be_path = libxl__device_backend_path(gc, dev);
-    char *script;
+    char *hotplug_path = libxl__device_xs_hotplug_path(gc, dev);
+    char *script, *saction;
     int nr = 0, rc = 0;
+    const int env_arraysize = 5;
+    const int arg_arraysize = 3;
 
-    script = libxl__xs_read(gc, XBT_NULL,
-                            GCSPRINTF("%s/%s", be_path, "script"));
-    if (!script) {
-        LOGEV(ERROR, errno, "unable to read script from %s", be_path);
+    switch (hotplug_version) {
+    case 0:
+        script = libxl__xs_read(gc, XBT_NULL, GCSPRINTF("%s/script", be_path));
+        if (!script) {
+            LOGEV(ERROR, errno, "unable to read script from %s", be_path);
+            rc = ERROR_FAIL;
+            goto error;
+        }
+        *env = get_hotplug_env(gc, script, dev);
+        if (!*env) {
+            rc = ERROR_FAIL;
+            goto error;
+        }
+        break;
+    case 1:
+        /* The new hotplug calling convention only uses two ENV variables:
+         * BACKEND_PATH: path to xenstore backend of the related device.
+         * HOTPLUG_PATH: path to the xenstore directory that can be used to
+         * pass extra parameters to the script.
+         */
+        script = libxl__xs_read(gc, XBT_NULL,
+                                GCSPRINTF("%s/script", hotplug_path));
+        if (!script) {
+            LOGEV(ERROR, errno, "unable to read script from %s", hotplug_path);
+            rc = ERROR_FAIL;
+            goto error;
+        }
+        GCNEW_ARRAY(*env, env_arraysize);
+        (*env)[nr++] = "BACKEND_PATH";
+        (*env)[nr++] = be_path;
+        (*env)[nr++] = "HOTPLUG_PATH";
+        (*env)[nr++] = hotplug_path;
+        (*env)[nr++] = NULL;
+        assert(nr == env_arraysize);
+        nr = 0;
+        break;
+    default:
+        LOG(ERROR, "unknown hotplug script version %d", hotplug_version);
         rc = ERROR_FAIL;
         goto error;
     }
 
-    *env = get_hotplug_env(gc, script, dev);
-    if (!*env) {
+    GCNEW_ARRAY(*args, arg_arraysize);
+    (*args)[nr++] = script;
+    saction = libxl__device_hotplug_action(gc, action);
+    if (!saction) {
         rc = ERROR_FAIL;
         goto error;
     }
-
-    const int arraysize = 3;
-    GCNEW_ARRAY(*args, arraysize);
-    (*args)[nr++] = script;
-    (*args)[nr++] = action == DEVICE_CONNECT ? "add" : "remove";
+    (*args)[nr++] = saction;
     (*args)[nr++] = NULL;
-    assert(nr == arraysize);
+    assert(nr == arg_arraysize);
 
     rc = 1;
 
@@ -226,7 +262,7 @@ error:
 int libxl__get_hotplug_script_info(libxl__gc *gc, libxl__device *dev,
                                    char ***args, char ***env,
                                    libxl__device_action action,
-                                   int num_exec)
+                                   int num_exec, int hotplug_version)
 {
     char *disable_udev = libxl__xs_read(gc, XBT_NULL, DISABLE_UDEV_PATH);
     int rc;
@@ -243,7 +279,7 @@ int libxl__get_hotplug_script_info(libxl__gc *gc, libxl__device *dev,
             rc = 0;
             goto out;
         }
-        rc = libxl__hotplug_disk(gc, dev, args, env, action);
+        rc = libxl__hotplug_disk(gc, dev, args, env, action, hotplug_version);
         break;
     case LIBXL__DEVICE_KIND_VIF:
         /*
diff --git a/tools/libxl/libxl_netbsd.c b/tools/libxl/libxl_netbsd.c
index 9587833..8061e7a 100644
--- a/tools/libxl/libxl_netbsd.c
+++ b/tools/libxl/libxl_netbsd.c
@@ -62,7 +62,7 @@ out:
 int libxl__get_hotplug_script_info(libxl__gc *gc, libxl__device *dev,
                                    char ***args, char ***env,
                                    libxl__device_action action,
-                                   int num_exec)
+                                   int num_exec, int hotplug_version)
 {
     char *disable_udev = libxl__xs_read(gc, XBT_NULL, DISABLE_UDEV_PATH);
     int rc;
-- 
1.7.7.5 (Apple Git-26)


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

  parent reply	other threads:[~2012-12-21 17:00 UTC|newest]

Thread overview: 28+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2012-12-21 16:59 [PATCH RFC 00/10] libxl: new hotplug calling convention Roger Pau Monne
2012-12-21 16:59 ` [PATCH RFC 01/10] libxl: libxl__prepare_ao_device should reset num_exec Roger Pau Monne
2013-01-17 13:57   ` Ian Campbell
2012-12-21 17:00 ` Roger Pau Monne [this message]
2013-01-18 13:29   ` [PATCH RFC 02/10] libxl: add new hotplug interface support to hotplug script callers Ian Campbell
2013-01-18 16:24     ` Roger Pau Monné
2013-01-21 10:07       ` Ian Campbell
2013-01-21 12:11         ` Roger Pau Monné
2013-01-21 12:18           ` Ian Campbell
2013-01-22  9:30     ` Roger Pau Monné
2012-12-21 17:00 ` [PATCH RFC 03/10] libxl: add new "method" parameter to xl disk config Roger Pau Monne
2013-01-17 15:49   ` Ian Campbell
2012-12-21 17:00 ` [PATCH RFC 04/10] libxl: add prepare/unprepare operations to the libxl public interface Roger Pau Monne
2012-12-21 17:00 ` [PATCH RFC 05/10] libxl: add disk specific remove functions Roger Pau Monne
2012-12-21 17:00 ` [PATCH RFC 06/10] xl: add support for new hotplug interface to block-attach/detach Roger Pau Monne
2012-12-21 17:00 ` [PATCH RFC 07/10] libxl: add local attach support for new hotplug scripts Roger Pau Monne
2012-12-21 17:00 ` [PATCH RFC 08/10] libxl: add new hotplug interface support for HVM guests Roger Pau Monne
2012-12-21 17:00 ` [PATCH RFC 09/10] hotplug: document new hotplug interface Roger Pau Monne
2012-12-21 17:00 ` [PATCH RFC 10/10] hotplug/Linux: add iscsi block hotplug script Roger Pau Monne
2013-01-15 16:56 ` [PATCH RFC 00/10] libxl: new hotplug calling convention Roger Pau Monné
2013-01-17 13:56 ` Ian Campbell
2013-01-17 15:30   ` Roger Pau Monné
2013-01-17 15:40     ` Ian Campbell
2013-01-17 15:47       ` Roger Pau Monné
2013-01-17 15:57         ` Ian Campbell
2013-01-17 16:10           ` Roger Pau Monné
2013-01-17 16:15             ` Ian Campbell
2013-01-17 16:45               ` Roger Pau Monné

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1356109208-6830-3-git-send-email-roger.pau@citrix.com \
    --to=roger.pau@citrix.com \
    --cc=xen-devel@lists.xen.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).