Skip to contentSkip to conversation

libxl: new hotplug calling convention

PATCH Applied Roger Pau Monne 4 participants 74 messages Jan 23, 2013 – Apr 19, 2013

lore
Share & tools
lore
#0 lore raw

cover libxl: new hotplug calling convention

This series implements a new hoplug calling convention for libxl.

The aim of this new convention is to reduce the blackout phase of migration when using complex hotplug scripts, like iSCSI or other kind of storage backends that might have a non trivial setup time.

There are some issues that I would like to discuss, the first one is the fact that pdev_path field in libxl_device_disk is no longuer used to store a physical path, since diskspec "target" can now contain "random" information to connect a block device. This is not a blocker for this series to be accepted, but I'm tempted to say that the easier way to solve this is to use a union for target and pdev_path, this way everything will work as expected, and semantics will be right.

The second issue is related to iSCSI and iscsiadm, specifically the way to set authentication parameters, which is done with command line parameters or editing files (which each distro seems to place in different locations). I will look into this to see if we can find a suitable solution.

Thanks for the comments, Roger.

Branch available in the git repository at:
git://xenbits.xen.org/people/royger/xen.git iscsi_v1

*Acked

Roger Pau Monne (12):
*libxl: libxl__prepare_ao_device should reset num_exec
libxl: remove double check in NetBSD hotplug
libxl: move libxl_device_action to idl
libxl: pack hotplug related variables
libxl: add new hotplug interface support to hotplug script callers
libxl: add support for different hotplug interfaces
libxl: add prepare/unprepare operations to the libxl public interface
libxl: add disk specific remove functions
xl: add support for new hotplug interface to block-attach/detach
libxl: add local attach support for new hotplug scripts
hotplug: document new hotplug interface
hotplug/Linux: add iscsi block hotplug script

 docs/misc/libxl-hotplug-interface.txt |  167 +++++++++++++++++
 tools/hotplug/Linux/Makefile          |    1 +
 tools/hotplug/Linux/block-iscsi       |  258 +++++++++++++++++++++++++
 tools/libxl/libxl.c                   |  332 +++++++++++++++++++++++++++++----
 tools/libxl/libxl.h                   |    8 +
 tools/libxl/libxl_bootloader.c        |    1 +
 tools/libxl/libxl_create.c            |   62 ++++++-
 tools/libxl/libxl_device.c            |  153 +++++++++++++---
 tools/libxl/libxl_internal.h          |   87 ++++++++-
 tools/libxl/libxl_linux.c             |   78 ++++++---
 tools/libxl/libxl_netbsd.c            |   10 +-
 tools/libxl/libxl_types.idl           |    1 +
 tools/libxl/libxl_types_internal.idl  |   10 +
 tools/libxl/xl_cmdimpl.c              |    5 +
 14 files changed, 1071 insertions(+), 102 deletions(-)
 create mode 100644 docs/misc/libxl-hotplug-interface.txt
 create mode 100644 tools/hotplug/Linux/block-iscsi
#1 lore raw

PATCH 1/12 libxl: libxl__prepare_ao_device should reset num_exec

num_exec was not cleared when calling libxl__prepare_ao_device.

---
 tools/libxl/libxl_device.c |    1 +
 1 files changed, 1 insertions(+), 0 deletions(-)
tools/libxl/libxl_device.c +1 -0
index 51dd06e..58d3f35 100644
@@ -409,6 +409,7 @@ void libxl__prepare_ao_device(libxl__ao *ao, libxl__ao_device *aodev)
     aodev->ao = ao;
     aodev->rc = 0;
     aodev->dev = NULL;
+    aodev->num_exec = 0;
     /* Initialize timer for QEMU Bodge and hotplug execution */
     libxl__ev_time_init(&aodev->timeout);
     aodev->active = 1;
Signature · 7 lines
1.7.7.5 (Apple Git-26)


_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xen.org/xen-devel
#3 lore raw

PATCH 2/12 libxl: remove double check in NetBSD hotplug

In reply to Roger Pau Monne

Remove a duplicated check performed in libxl__get_hotplug_script_info for NetBSD

---
 tools/libxl/libxl_netbsd.c |    4 ----
 1 files changed, 0 insertions(+), 4 deletions(-)
tools/libxl/libxl_netbsd.c +0 -4
index 9587833..36662c0 100644
@@ -76,10 +76,6 @@ int libxl__get_hotplug_script_info(libxl__gc *gc, libxl__device *dev,
     switch (dev->backend_kind) {
     case LIBXL__DEVICE_KIND_VBD:
     case LIBXL__DEVICE_KIND_VIF:
-        if (num_exec != 0) {
-            rc = 0;
-            goto out;
-        }
         rc = libxl__hotplug(gc, dev, args, action);
         if (!rc) rc = 1;
         break;
Signature · 7 lines
1.7.7.5 (Apple Git-26)


_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xen.org/xen-devel
Acked-by on v1 2/12
#4 lore raw

Re: [PATCH v1 02/12] libxl: remove double check in NetBSD hotplug

Roger Pau Monne writes ("[Xen-devel] [PATCH v1 02/12] libxl: remove double check in NetBSD hotplug"):

Quoted 5 lines

Remove a duplicated check performed in libxl__get_hotplug_script_info for NetBSD

#5 lore raw

PATCH 3/12 libxl: move libxl_device_action to idl

In reply to Roger Pau Monne

Move to idl for ease of expansion and auto-generated functions.

---
 tools/libxl/libxl.c                  |   18 +++++++++---------
 tools/libxl/libxl_device.c           |   11 ++++++-----
 tools/libxl/libxl_internal.h         |    6 ------
 tools/libxl/libxl_linux.c            |    7 ++++---
 tools/libxl/libxl_netbsd.c           |    2 +-
 tools/libxl/libxl_types_internal.idl |    5 +++++
 6 files changed, 25 insertions(+), 24 deletions(-)
tools/libxl/libxl.c +9 -9
index 73e0dc3..a67c4dc 100644
@@ -1695,12 +1695,12 @@ static void device_addrm_aocomplete(libxl__egc *egc, libxl__ao_device *aodev)
     if (aodev->rc) {
         if (aodev->dev) {
             LOG(ERROR, "unable to %s %s with id %u",
-                        aodev->action == DEVICE_CONNECT ? "add" : "remove",
+                        libxl__device_action_to_string(aodev->action),
                         libxl__device_kind_to_string(aodev->dev->kind),
                         aodev->dev->devid);
         } else {
             LOG(ERROR, "unable to %s device",
-                       aodev->action == DEVICE_CONNECT ? "add" : "remove");
+                       libxl__device_action_to_string(aodev->action));
         }
         goto out;
     }
@@ -1806,7 +1806,7 @@ void libxl__device_vtpm_add(libxl__egc *egc, uint32_t domid,
                              libxl__xs_kvs_of_flexarray(gc, front, front->count));
 
     aodev->dev = device;
-    aodev->action = DEVICE_CONNECT;
+    aodev->action = LIBXL__DEVICE_ACTION_ADD;
     libxl__wait_device_connection(egc, aodev);
 
     rc = 0;
@@ -2163,7 +2163,7 @@ static void device_disk_add(libxl__egc *egc, uint32_t domid,
     }
 
     aodev->dev = device;
-    aodev->action = DEVICE_CONNECT;
+    aodev->action = LIBXL__DEVICE_ACTION_ADD;
     libxl__wait_device_connection(egc, aodev);
 
     rc = 0;
@@ -2628,7 +2628,7 @@ static void local_device_attach_cb(libxl__egc *egc, libxl__ao_device *aodev)
     rc = aodev->rc;
     if (rc) {
         LOGE(ERROR, "unable to %s %s with id %u",
-                    aodev->action == DEVICE_CONNECT ? "add" : "remove",
+                    libxl__device_action_to_string(aodev->action),
                     libxl__device_kind_to_string(aodev->dev->kind),
                     aodev->dev->devid);
         goto out;
@@ -2682,7 +2682,7 @@ void libxl__device_disk_local_initiate_detach(libxl__egc *egc,
                                              disk, device);
                 if (rc != 0) goto out;
 
-                aodev->action = DEVICE_DISCONNECT;
+                aodev->action = LIBXL__DEVICE_ACTION_REMOVE;
                 aodev->dev = device;
                 aodev->callback = local_device_detach_cb;
                 aodev->force = 0;
@@ -2713,7 +2713,7 @@ static void local_device_detach_cb(libxl__egc *egc, libxl__ao_device *aodev)
 
     if (aodev->rc) {
         LOGE(ERROR, "unable to %s %s with id %u",
-                    aodev->action == DEVICE_CONNECT ? "add" : "remove",
+                    libxl__device_action_to_string(aodev->action),
                     libxl__device_kind_to_string(aodev->dev->kind),
                     aodev->dev->devid);
         goto out;
@@ -2892,7 +2892,7 @@ void libxl__device_nic_add(libxl__egc *egc, uint32_t domid,
                              libxl__xs_kvs_of_flexarray(gc, front, front->count));
 
     aodev->dev = device;
-    aodev->action = DEVICE_CONNECT;
+    aodev->action = LIBXL__DEVICE_ACTION_ADD;
     libxl__wait_device_connection(egc, aodev);
 
     rc = 0;
@@ -3370,7 +3370,7 @@ out:
                                                                         \
         GCNEW(aodev);                                                   \
         libxl__prepare_ao_device(ao, aodev);                            \
-        aodev->action = DEVICE_DISCONNECT;                              \
+        aodev->action = LIBXL__DEVICE_ACTION_REMOVE;                    \
         aodev->dev = device;                                            \
         aodev->callback = device_addrm_aocomplete;                      \
         aodev->force = f;                                               \
tools/libxl/libxl_device.c +6 -5
index 58d3f35..eeea9d9 100644
@@ -614,7 +614,7 @@ void libxl__devices_destroy(libxl__egc *egc, libxl__devices_remove_state *drs)
                     continue;
                 }
                 aodev = libxl__multidev_prepare(multidev);
-                aodev->action = DEVICE_DISCONNECT;
+                aodev->action = LIBXL__DEVICE_ACTION_REMOVE;
                 aodev->dev = dev;
                 aodev->force = drs->force;
                 libxl__initiate_device_remove(egc, aodev);
@@ -849,7 +849,8 @@ static void device_backend_callback(libxl__egc *egc, libxl__ev_devstate *ds,
 
     device_backend_cleanup(gc, aodev);
 
-    if (rc == ERROR_TIMEDOUT && aodev->action == DEVICE_DISCONNECT &&
+    if (rc == ERROR_TIMEDOUT &&
+        aodev->action == LIBXL__DEVICE_ACTION_REMOVE &&
         !aodev->force) {
         aodev->force = 1;
         libxl__initiate_device_remove(egc, aodev);
@@ -858,7 +859,7 @@ static void device_backend_callback(libxl__egc *egc, libxl__ev_devstate *ds,
 
     if (rc) {
         LOG(ERROR, "unable to %s device with path %s",
-                   aodev->action == DEVICE_CONNECT ? "connect" : "disconnect",
+                   libxl__device_action_to_string(aodev->action),
                    libxl__device_backend_path(gc, aodev->dev));
         goto out;
     }
@@ -981,7 +982,7 @@ static void device_hotplug_child_death_cb(libxl__egc *egc,
         if (hotplug_error)
             LOG(ERROR, "script: %s", hotplug_error);
         aodev->rc = ERROR_FAIL;
-        if (aodev->action == DEVICE_CONNECT)
+        if (aodev->action == LIBXL__DEVICE_ACTION_ADD)
             /*
              * Only fail on device connection, on disconnection
              * ignore error, and continue with the remove process
@@ -1011,7 +1012,7 @@ static void device_hotplug_done(libxl__egc *egc, libxl__ao_device *aodev)
     device_hotplug_clean(gc, aodev);
 
     /* Clean xenstore if it's a disconnection */
-    if (aodev->action == DEVICE_DISCONNECT) {
+    if (aodev->action == LIBXL__DEVICE_ACTION_REMOVE) {
         rc = libxl__device_destroy(gc, aodev->dev);
         if (!aodev->rc)
             aodev->rc = rc;
tools/libxl/libxl_internal.h +0 -6
index 0b38e3e..f127f8a 100644
@@ -1829,12 +1829,6 @@ _hidden const char *libxl__run_dir_path(void);
 
 /*----- device addition/removal -----*/
 
-/* Action to perform (either connect or disconnect) */
-typedef enum {
-    DEVICE_CONNECT,
-    DEVICE_DISCONNECT
-} libxl__device_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*);
tools/libxl/libxl_linux.c +4 -3
index 1fed3cd..1ef13c0 100644
@@ -173,11 +173,12 @@ static int libxl__hotplug_nic(libxl__gc *gc, libxl__device *dev,
     (*args)[nr++] = script;
 
     if (nictype == LIBXL_NIC_TYPE_VIF_IOEMU && num_exec) {
-        (*args)[nr++] = action == DEVICE_CONNECT ? "add" : "remove";
+        (*args)[nr++] = (char *) libxl__device_action_to_string(action);
         (*args)[nr++] = "type_if=tap";
         (*args)[nr++] = NULL;
     } else {
-        (*args)[nr++] = action == DEVICE_CONNECT ? "online" : "offline";
+        (*args)[nr++] = action == LIBXL__DEVICE_ACTION_ADD ? "online" :
+                                                             "offline";
         (*args)[nr++] = "type_if=vif";
         (*args)[nr++] = NULL;
     }
@@ -213,7 +214,7 @@ static int libxl__hotplug_disk(libxl__gc *gc, libxl__device *dev,
     const int arraysize = 3;
     GCNEW_ARRAY(*args, arraysize);
     (*args)[nr++] = script;
-    (*args)[nr++] = action == DEVICE_CONNECT ? "add" : "remove";
+    (*args)[nr++] = (char *) libxl__device_action_to_string(action);
     (*args)[nr++] = NULL;
     assert(nr == arraysize);
 
tools/libxl/libxl_netbsd.c +1 -1
index 36662c0..0ad69af 100644
@@ -50,7 +50,7 @@ static int libxl__hotplug(libxl__gc *gc, libxl__device *dev, char ***args,
     GCNEW_ARRAY(*args, arraysize);
     (*args)[nr++] = script;
     (*args)[nr++] = be_path;
-    (*args)[nr++] = GCSPRINTF("%d", action == DEVICE_CONNECT ?
+    (*args)[nr++] = GCSPRINTF("%d", action == LIBXL__DEVICE_ACTION_ADD ?
                                     XenbusStateInitWait : XenbusStateClosed);
     (*args)[nr++] = NULL;
     assert(nr == arraysize);
tools/libxl/libxl_types_internal.idl +5 -0
index c40120e..cb9444f 100644
@@ -33,3 +33,8 @@ libxl__device_console = Struct("device_console", [
     ("consback", libxl__console_backend),
     ("output", string),
     ])
+
+libxl__device_action = Enumeration("device_action", [
+    (1, "ADD"),
+    (2, "REMOVE"),
+    ])
Signature · 7 lines
1.7.7.5 (Apple Git-26)


_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xen.org/xen-devel
#7 lore raw

PATCH 4/12 libxl: pack hotplug related variables

In reply to Roger Pau Monne

Create a new struct to hold hotplug related variables that are scattered in libxl__ao_device. We will later expand the number of hotplug related variables, so it's best to have them packed

---
 tools/libxl/libxl_device.c   |    6 +++---
 tools/libxl/libxl_internal.h |   15 ++++++++++-----
 tools/libxl/libxl_linux.c    |   10 +++++-----
 tools/libxl/libxl_netbsd.c   |    4 ++--
 4 files changed, 20 insertions(+), 15 deletions(-)
tools/libxl/libxl_device.c +3 -3
index eeea9d9..044cac5 100644
@@ -409,7 +409,7 @@ void libxl__prepare_ao_device(libxl__ao *ao, libxl__ao_device *aodev)
     aodev->ao = ao;
     aodev->rc = 0;
     aodev->dev = NULL;
-    aodev->num_exec = 0;
+    aodev->hotplug.num_exec = 0;
     /* Initialize timer for QEMU Bodge and hotplug execution */
     libxl__ev_time_init(&aodev->timeout);
     aodev->active = 1;
@@ -892,7 +892,7 @@ 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->hotplug);
     switch (hotplug) {
     case 0:
         /* no hotplug script to execute */
@@ -994,7 +994,7 @@ static void device_hotplug_child_death_cb(libxl__egc *egc,
      * If no more executions are needed, device_hotplug will call
      * device_hotplug_done breaking the loop.
      */
-    aodev->num_exec++;
+    aodev->hotplug.num_exec++;
     device_hotplug(egc, aodev);
 
     return;
tools/libxl/libxl_internal.h +10 -5
index f127f8a..d69d819 100644
@@ -1831,6 +1831,7 @@ _hidden const char *libxl__run_dir_path(void);
 
 typedef struct libxl__ao_device libxl__ao_device;
 typedef struct libxl__multidev libxl__multidev;
+typedef struct libxl__hotplug libxl__hotplug;
 typedef void libxl__device_callback(libxl__egc*, libxl__ao_device*);
 
 /* This functions sets the necessary libxl__ao_device struct values to use
@@ -1849,6 +1850,10 @@ typedef void libxl__device_callback(libxl__egc*, libxl__ao_device*);
  */
 _hidden void libxl__prepare_ao_device(libxl__ao *ao, libxl__ao_device *aodev);
 
+struct libxl__hotplug {
+    int num_exec;
+};
+
 struct libxl__ao_device {
     /* filled in by user */
     libxl__ao *ao;
@@ -1867,7 +1872,7 @@ struct libxl__ao_device {
     libxl__ev_time timeout;
     /* device hotplug execution */
     const char *what;
-    int num_exec;
+    libxl__hotplug hotplug;
     libxl__ev_child child;
 };
 
@@ -2048,18 +2053,18 @@ _hidden void libxl__initiate_device_remove(libxl__egc *egc,
  * 0: No need to execute hotplug script
  * 1: Execute hotplug script
  *
- * The last parameter, "num_exec" refeers to the number of times hotplug
- * scripts have been called for this device.
+ * The last parameter, libxl__hotplug contains information related to hotplug
+ * execution.
  *
  * The main body of libxl will, for each device, keep calling
  * libxl__get_hotplug_script_info, with incrementing values of
- * num_exec, and executing the resulting script accordingly,
+ * hotplug->num_exec, and executing the resulting script accordingly,
  * until libxl__get_hotplug_script_info returns<=0.
  */
 _hidden int libxl__get_hotplug_script_info(libxl__gc *gc, libxl__device *dev,
                                            char ***args, char ***env,
                                            libxl__device_action action,
-                                           int num_exec);
+                                           libxl__hotplug *hotplug);
 
 /*----- local disk attach: attach a disk locally to run the bootloader -----*/
 
tools/libxl/libxl_linux.c +5 -5
index 1ef13c0..531bc7e 100644
@@ -227,7 +227,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)
+                                   libxl__hotplug *hotplug)
 {
     char *disable_udev = libxl__xs_read(gc, XBT_NULL, DISABLE_UDEV_PATH);
     int rc;
@@ -240,7 +240,7 @@ int libxl__get_hotplug_script_info(libxl__gc *gc, libxl__device *dev,
 
     switch (dev->backend_kind) {
     case LIBXL__DEVICE_KIND_VBD:
-        if (num_exec != 0) {
+        if (hotplug->num_exec != 0) {
             rc = 0;
             goto out;
         }
@@ -251,12 +251,12 @@ int libxl__get_hotplug_script_info(libxl__gc *gc, libxl__device *dev,
          * If domain has a stubdom we don't have to execute hotplug scripts
          * for emulated interfaces
          */
-        if ((num_exec > 1) ||
-            (libxl_get_stubdom_id(CTX, dev->domid) && num_exec)) {
+        if ((hotplug->num_exec > 1) ||
+            (libxl_get_stubdom_id(CTX, dev->domid) && hotplug->num_exec)) {
             rc = 0;
             goto out;
         }
-        rc = libxl__hotplug_nic(gc, dev, args, env, action, num_exec);
+        rc = libxl__hotplug_nic(gc, dev, args, env, action, hotplug->num_exec);
         break;
     default:
         /* No need to execute any hotplug scripts */
tools/libxl/libxl_netbsd.c +2 -2
index 0ad69af..fa5e418 100644
@@ -62,13 +62,13 @@ out:
 int libxl__get_hotplug_script_info(libxl__gc *gc, libxl__device *dev,
                                    char ***args, char ***env,
                                    libxl__device_action action,
-                                   int num_exec)
+                                   libxl__hotplug *hotplug)
 {
     char *disable_udev = libxl__xs_read(gc, XBT_NULL, DISABLE_UDEV_PATH);
     int rc;
 
     /* Check if we have to run hotplug scripts */
-    if (!disable_udev || num_exec > 0) {
+    if (!disable_udev || hotplug->num_exec > 0) {
         rc = 0;
         goto out;
     }
Signature · 7 lines
1.7.7.5 (Apple Git-26)


_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xen.org/xen-devel
Acked-by on v1 4/12
#8 lore raw

Re: [PATCH v1 04/12] libxl: pack hotplug related variables

Roger Pau Monne writes ("[Xen-devel] [PATCH v1 04/12] libxl: pack hotplug related variables"):

Quoted 6 lines

Create a new struct to hold hotplug related variables that are scattered in libxl__ao_device. We will later expand the number of hotplug related variables, so it's best to have them packed

I think you should avoid the word "packed" which normally makes people think of removing structure memory layout padding. "grouped" perhaps ?

Apart from that, which I think is just a comment about the commit message:

Thanks,
Ian.

#9 lore raw

Re: [PATCH v1 04/12] libxl: pack hotplug related variables

Quoted 8 lines · Ian Jackson

Roger Pau Monne writes ("[Xen-devel] [PATCH v1 04/12] libxl: pack hotplug related variables"):

Quoted 6 lines

Create a new struct to hold hotplug related variables that are scattered in libxl__ao_device. We will later expand the number of hotplug related variables, so it's best to have them packed

Quoted 8 lines

I think you should avoid the word "packed" which normally makes people think of removing structure memory layout padding. "grouped" perhaps ?

Apart from that, which I think is just a comment about the commit message:

Thanks, I've fixed the commit message and added your Ack.

#10 lore raw

PATCH 5/12 libxl: add new hotplug interface support to hotplug script callers

In reply to Roger Pau Monne

Add support to call hotplug scripts that use the new hotplug interface to the low-level functions in charge of calling hotplug scripts.

libxl__prepare_ao_device sets the hotplug version to 1, in later patches hotplug version will be set to 2 by the caller to use this new hotplug calling convention.

---
 tools/libxl/libxl_device.c           |   14 +++++++-
 tools/libxl/libxl_internal.h         |   22 ++++++++++++
 tools/libxl/libxl_linux.c            |   61 +++++++++++++++++++++++++--------
 tools/libxl/libxl_types_internal.idl |    5 +++
 4 files changed, 86 insertions(+), 16 deletions(-)
tools/libxl/libxl_device.c +13 -1
index 044cac5..904853a 100644
@@ -83,6 +83,12 @@ out:
     return rc;
 }
 
+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 +416,7 @@ void libxl__prepare_ao_device(libxl__ao *ao, libxl__ao_device *aodev)
     aodev->rc = 0;
     aodev->dev = NULL;
     aodev->hotplug.num_exec = 0;
+    aodev->hotplug.version = 1;
     /* Initialize timer for QEMU Bodge and hotplug execution */
     libxl__ev_time_init(&aodev->timeout);
     aodev->active = 1;
@@ -974,7 +981,12 @@ static void device_hotplug_child_death_cb(libxl__egc *egc,
 
     device_hotplug_clean(gc, aodev);
 
-    if (status) {
+    if (status && aodev->action != LIBXL__DEVICE_ACTION_VERSION) {
+        /* If a hotplug script returns an error when called
+         * with the "version" argument it means it is using the old
+         * hotplug calling convention, and we don't have to print
+         * an error message.
+         */
         libxl_report_child_exitstatus(CTX, LIBXL__LOG_ERROR,
                                       aodev->what, pid, status);
         hotplug_error = libxl__xs_read(gc, XBT_NULL,
tools/libxl/libxl_internal.h +22 -0
index d69d819..e819bbd 100644
@@ -1847,11 +1847,20 @@ 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 2, the new hotplug script calling convention
+ * will be used to call the hotplug script. This new convention provides
+ * new actions to hotplug scripts, "prepare", "unprepare", "localattach",
+ * "localdetach" and "version". 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);
 
 struct libxl__hotplug {
     int num_exec;
+    int version;
 };
 
 struct libxl__ao_device {
@@ -1861,6 +1870,8 @@ struct libxl__ao_device {
     libxl__device *dev;
     int force;
     libxl__device_callback *callback;
+    /* used by the VERISON and LOCALATTACH actions, set by caller */
+    libxl_device_disk *disk;
     /* return value, zeroed by user on entry, is valid on callback */
     int rc;
     /* private for multidev */
@@ -2044,6 +2055,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.
  *
tools/libxl/libxl_linux.c +46 -15

85 lines not on this page · raw message

tools/libxl/libxl_types_internal.idl +5 -0
index cb9444f..253bb18 100644
@@ -37,4 +37,9 @@ libxl__device_console = Struct("device_console", [
 libxl__device_action = Enumeration("device_action", [
     (1, "ADD"),
     (2, "REMOVE"),
+    (3, "PREPARE"),
+    (4, "UNPREPARE"),
+    (5, "LOCALATTACH"),
+    (6, "LOCALDETACH"),
+    (7, "VERSION"),
     ])
Signature · 7 lines
1.7.7.5 (Apple Git-26)


_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xen.org/xen-devel
#11 lore raw

Re: [PATCH v1 05/12] libxl: add new hotplug interface support to hotplug script callers

Roger Pau Monne writes ("[Xen-devel] [PATCH v1 05/12] libxl: add new hotplug interface support to hotplug script callers"):

Quoted 6 lines

Add support to call hotplug scripts that use the new hotplug interface to the low-level functions in charge of calling hotplug scripts.

libxl__prepare_ao_device sets the hotplug version to 1, in later patches hotplug version will be set to 2 by the caller to use this new hotplug calling convention.

I think this needs a comprehensive document describing the new calling convention. Since there isn't currently a document describing the old calling convention I think you may need to do some reverse engineering.

And then when you do that, there are things about the old calling convention which are distinctly dodgy and should perhaps be changed.

Is this autoprobing with the "version" argument really the best way to deal with compatibility ? I guess we do know that it's reliable.

Ian.

#12 lore raw

Re: [PATCH v1 05/12] libxl: add new hotplug interface support to hotplug script callers

Quoted 4 lines · Ian Jackson

Roger Pau Monne writes ("[Xen-devel] [PATCH v1 05/12] libxl: add new hotplug interface support to hotplug script callers"):

Quoted 3 lines

Add support to call hotplug scripts that use the new hotplug interface to the low-level functions in charge of calling hotplug scripts.

Quoted 8 lines
Quoted 3 lines

libxl__prepare_ao_device sets the hotplug version to 1, in later patches hotplug version will be set to 2 by the caller to use this new hotplug calling convention.

I think this needs a comprehensive document describing the new calling convention. Since there isn't currently a document describing the old calling convention I think you may need to do some reverse engineering.

Patch 11/12 adds a document describing the new calling convention.

Quoted 3 lines

And then when you do that, there are things about the old calling convention which are distinctly dodgy and should perhaps be changed.

I would prefer to avoid touching anything related to the old calling convention, mainly because I would like to avoid touching the old hotplug scripts in this series, and because there might be out-of-tree hotplug scripts relaying on some of this obscure features.

Quoted 2 lines

Is this autoprobing with the "version" argument really the best way to deal with compatibility ? I guess we do know that it's reliable.

I think it's quite reliable, unless someone has an out-of-tree v1 hotplug script that implements this parameter, but I don't think this is going to be the case.

#13 lore raw

Re: [PATCH v1 05/12] libxl: add new hotplug interface support to hotplug script callers

Roger Pau Monne writes ("Re: [Xen-devel] [PATCH v1 05/12] libxl: add new hotplug interface support to hotplug script callers"):

Quoted 7 lines · Ian Jackson
Quoted 4 lines

I think this needs a comprehensive document describing the new calling convention. Since there isn't currently a document describing the old calling convention I think you may need to do some reverse engineering.

Patch 11/12 adds a document describing the new calling convention.

Surely this should be in the same patch ? In general the document for something should be in the same patch as the code that introduces it.

TBH I'm not sure I understand the division between the various patches.

Quoted 7 lines
Quoted 2 lines

And then when you do that, there are things about the old calling convention which are distinctly dodgy and should perhaps be changed.

I would prefer to avoid touching anything related to the old calling convention, mainly because I would like to avoid touching the old hotplug scripts in this series, and because there might be out-of-tree hotplug scripts relaying on some of this obscure features.

Yes, of course. Sorry, I was unclear. I meant that there were aspects about the old calling convention which you are inheriting into the new one which may want to be revisited.

Quoted 3 lines

I think it's quite reliable, unless someone has an out-of-tree v1 hotplug script that implements this parameter, but I don't think this is going to be the case.

Right.

Ian.

#14 lore raw

Re: [PATCH v1 05/12] libxl: add new hotplug interface support to hotplug script callers

Quoted 7 lines · Ian Jackson

Roger Pau Monne writes ("Re: [Xen-devel] [PATCH v1 05/12] libxl: add new hotplug interface support to hotplug script callers"):

Quoted 6 lines · Ian Jackson
Quoted 4 lines

I think this needs a comprehensive document describing the new calling convention. Since there isn't currently a document describing the old calling convention I think you may need to do some reverse engineering.

Quoted 7 lines
Quoted 1 line

Patch 11/12 adds a document describing the new calling convention.

Surely this should be in the same patch ? In general the document for something should be in the same patch as the code that introduces it.

TBH I'm not sure I understand the division between the various patches.

I've just added it as a separate patch because I wanted to add it once the implementation in libxl was complete, but I don't have any problem squashing the doc into this patch.

Regarding the order of the series, I've basically added the core functionality first in this patch, and then I went adding the missing bits all over the other patches, trying to keep them small and concrete.

Quoted 4 lines
Quoted 4 lines
Quoted 3 lines

And then when you do that, there are things about the old calling convention which are distinctly dodgy and should perhaps be changed.

Quoted 8 lines
Quoted 4 lines

I would prefer to avoid touching anything related to the old calling convention, mainly because I would like to avoid touching the old hotplug scripts in this series, and because there might be out-of-tree hotplug scripts relaying on some of this obscure features.

Yes, of course. Sorry, I was unclear. I meant that there were aspects about the old calling convention which you are inheriting into the new one which may want to be revisited.

I'm not sure I follow you here, there's a switch in libxl__hotplug_disk that passes completely different parameters and env vars depending on the hotplug script version, so there's no inheritance between the old and the new calling convention.

#15 lore raw

PATCH 6/12 libxl: add support for different hotplug interfaces

In reply to Roger Pau Monne

Add a new variable to libxl_device_disk "hotplug_version", that will be automatically set to the detected hotplug script interface version.

This patch adds the basic support to handle this new scripts, by adding the prepare/unprepare private libxl functions, and modifying the current domain creation/destruction to call this functions at the appropriate spots. The hotplug interface detection is done in the _prepare call.

This patch also adds some helpers, that will be used here and in later patches.

---
 tools/libxl/libxl.c          |  171 +++++++++++++++++++++++++++++++++++++++++-
 tools/libxl/libxl_create.c   |   62 +++++++++++++++-
 tools/libxl/libxl_device.c   |  127 ++++++++++++++++++++++++++-----
 tools/libxl/libxl_internal.h |   43 +++++++++++
 tools/libxl/libxl_types.idl  |    1 +
 5 files changed, 381 insertions(+), 23 deletions(-)
tools/libxl/libxl.c +169 -2
index a67c4dc..9061fdf 100644
@@ -2011,6 +2011,146 @@ int libxl__device_from_disk(libxl__gc *gc, uint32_t domid,
     return 0;
 }
 
+/* Callbacks for libxl__device_disk_prepare */
+
+static void device_disk_prepare_cb(libxl__egc *, libxl__ao_device *);
+
+void libxl__device_disk_prepare(libxl__egc *egc, uint32_t domid,
+                                libxl_device_disk *disk,
+                                libxl__ao_device *prepare_aodev)
+{
+    STATE_AO_GC(prepare_aodev->ao);
+    char *hotplug_path;
+    char *script_path;
+    int rc;
+    xs_transaction_t t = XBT_NULL;
+    libxl__disk_prepare *dp;
+    libxl__ao_device *aodev;
+
+    if (!disk->script) {
+        /* If script is not set assume v1 */
+        disk->hotplug_version = 1;
+        prepare_aodev->callback(egc, prepare_aodev);
+        return;
+    }
+
+    GCNEW(dp);
+    dp->disk = disk;
+    /* Save original aodev, since we will call it once hotplug
+     * script detection has finished
+     */
+    dp->aodev = prepare_aodev;
+    aodev = &dp->version_aodev;
+    libxl__prepare_ao_device(ao, aodev);
+
+    GCNEW(aodev->dev);
+    rc = libxl__device_from_disk(gc, domid, disk, aodev->dev);
+    if (rc != 0) {
+        LOG(ERROR, "Invalid or unsupported virtual disk identifier %s",
+                   disk->vdev);
+        goto error;
+    }
+
+    script_path = libxl__abs_path(gc, disk->script,
+                                  libxl__xen_script_dir_path());
+
+    hotplug_path = libxl__device_xs_hotplug_path(gc, aodev->dev);
+    for (;;) {
+        rc = libxl__xs_transaction_start(gc, &t);
+        if (rc) goto error;
+
+        rc = libxl__xs_write_checked(gc, t,
+                                 GCSPRINTF("%s/params", hotplug_path),
+                                 disk->pdev_path);
+        if (rc)
+            goto error;
+
+        rc = libxl__xs_write_checked(gc, t,
+                                 GCSPRINTF("%s/script", hotplug_path),
+                                 script_path);
+        if (rc)
+            goto error;
+
+        rc = libxl__xs_transaction_commit(gc, &t);
+        if (!rc) break;
+        if (rc < 0) goto error;
+    }
+
+    aodev->callback = device_disk_prepare_cb;
+    aodev->action = LIBXL__DEVICE_ACTION_VERSION;
+    aodev->disk = disk;
+    aodev->hotplug.version = 2;
+    libxl__device_hotplug(egc, aodev);
+    return;
+
+error:
+    assert(rc);
+    libxl__xs_transaction_abort(gc, &t);
+    aodev->rc = rc;
+    aodev->callback(egc, aodev);
+    return;
+}
+
+static void device_disk_prepare_cb(libxl__egc *egc,
+                                   libxl__ao_device *version_aodev)
+{
+    STATE_AO_GC(version_aodev->ao);
+    libxl__disk_prepare *dp = CONTAINER_OF(version_aodev, *dp, version_aodev);
+    libxl__ao_device *aodev = dp->aodev;
+
+    if (dp->disk->hotplug_version == 1) {
+        aodev->callback(egc, aodev);
+        return;
+    }
+
+    aodev->action = LIBXL__DEVICE_ACTION_PREPARE;
+    aodev->hotplug.version = dp->disk->hotplug_version;
+    aodev->dev = version_aodev->dev;
+    libxl__device_hotplug(egc, aodev);
+    return;
+}
+
+void libxl__device_disk_unprepare(libxl__egc *egc, uint32_t domid,
+                                  libxl_device_disk *disk,
+                                  libxl__ao_device *aodev)
+{
+    STATE_AO_GC(aodev->ao);
+    char *hotplug_path;
+    int rc;
+
+    if (disk->hotplug_version == 1) {
+        aodev->callback(egc, aodev);
+        return;
+    }
+
+    GCNEW(aodev->dev);
+    rc = libxl__device_from_disk(gc, domid, disk, aodev->dev);
+    if (rc != 0) {
+        LOG(ERROR, "Invalid or unsupported virtual disk identifier %s",
+                   disk->vdev);
+        goto error;
+    }
+
+    hotplug_path = libxl__device_xs_hotplug_path(gc, aodev->dev);
+    if (!libxl__xs_read(gc, XBT_NULL, hotplug_path)) {
+        LOG(DEBUG, "unable to unprepare device because %s doesn't exist",
+                   hotplug_path);
+        aodev->callback(egc, aodev);
+        return;
+    }
+
+    aodev->action = LIBXL__DEVICE_ACTION_UNPREPARE;
+    aodev->hotplug.version = disk->hotplug_version;
+    libxl__device_hotplug(egc, aodev);
+    return;
+
+error:
+    assert(rc);
+    aodev->rc = rc;
+    aodev->callback(egc, aodev);
+    return;
+}
+
 /* Specific function called directly only by local disk attach,
  * all other users should instead use the regular
  * libxl__device_disk_add wrapper
@@ -2070,8 +2210,15 @@ static void device_disk_add(libxl__egc *egc, uint32_t domid,
                 dev = disk->pdev_path;
 
         do_backend_phy:
-                flexarray_append(back, "params");
-                flexarray_append(back, dev);
+                if (disk->hotplug_version == 1) {
+                    /*
+                     * If the new hotplug version is used params is
+                     * stored under a private path, since it can contain
+                     * data that the guest should not see.
+                     */
+                    flexarray_append(back, "params");
+                    flexarray_append(back, dev);
+                }
 
                 script = libxl__abs_path(gc, disk->script?: "block",
                                          libxl__xen_script_dir_path());
@@ -2164,6 +2311,8 @@ static void device_disk_add(libxl__egc *egc, uint32_t domid,
 
     aodev->dev = device;
     aodev->action = LIBXL__DEVICE_ACTION_ADD;
+    aodev->hotplug.version = disk->hotplug_version;
+    aodev->disk = disk;
     libxl__wait_device_connection(egc, aodev);
 
     rc = 0;
@@ -2257,6 +2406,7 @@ int libxl_vdev_to_device_disk(libxl_ctx *ctx, uint32_t domid,
     GC_INIT(ctx);
     char *dompath, *path;
     int devid = libxl__device_disk_dev_number(vdev, NULL, NULL);
+    libxl__device dev;
     int rc = ERROR_FAIL;
 
     if (devid < 0)
@@ -2275,6 +2425,23 @@ int libxl_vdev_to_device_disk(libxl_ctx *ctx, uint32_t domid,
         goto out;
 
     rc = libxl__device_disk_from_xs_be(gc, path, disk);
+    if (rc) {
+        LOG(ERROR, "unable to parse disk device from path %s", path);
+        goto out;
+    }
+
+    /* Check if the device is using the new hotplug interface */
+    rc = libxl__device_from_disk(gc, domid, disk, &dev);
+    if (rc) {
+        LOG(ERROR, "invalid or unsupported virtual disk identifier %s",
+                    disk->vdev);
+        goto out;
+    }
+    disk->hotplug_version = 1;
+    path = libxl__device_xs_hotplug_path(gc, &dev);
+    if (libxl__xs_read(gc, XBT_NULL, path))
+        disk->hotplug_version = 2;
+
 out:
     GC_FREE;
     return rc;
tools/libxl/libxl_create.c +61 -1

97 lines not on this page · raw message

tools/libxl/libxl_device.c +107 -20

229 lines not on this page · raw message

tools/libxl/libxl_internal.h +43 -0

61 lines not on this page · raw message

tools/libxl/libxl_types.idl +1 -0
index acc4bc9..8d8cd6a 100644
@@ -367,6 +367,7 @@ libxl_device_disk = Struct("device_disk", [
     ("removable", integer),
     ("readwrite", integer),
     ("is_cdrom", integer),
+    ("hotplug_version", integer),
     ])
 
 libxl_device_nic = Struct("device_nic", [
Signature · 7 lines
1.7.7.5 (Apple Git-26)


_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xen.org/xen-devel
#16 lore raw

Re: [PATCH v1 06/12] libxl: add support for different hotplug interfaces

Roger Pau Monne writes ("[Xen-devel] [PATCH v1 06/12] libxl: add support for different hotplug interfaces"):

Quoted 2 lines

Add a new variable to libxl_device_disk "hotplug_version", that will be automatically set to the detected hotplug script interface version.

...

tools/libxl/libxl_create.c static void domcreate_destruction_cb(libxl__egc *egc, · line 1226

Quoted 10 lines
tools/libxl/libxl_create.c +10 -0
+    /*
+     * We might have devices that have been prepared, but with no
+     * frontend xenstore entries, so domain destruction fails to
+     * find them, that is why we have to unprepare them manually.
+     */
+    libxl__multidev_begin(ao, &dcs->multidev);
+    dcs->multidev.callback = domcreate_unprepare_cb;
+    libxl__unprepare_disks(egc, ao, domid, d_config, &dcs->multidev);
+    libxl__multidev_prepared(egc, &dcs->multidev, 0);
+    return;

I don't think this is correct. What if the calling application crashes and this code is never executed ? Then libxl_destroy would leak this state.

So I think you need to record the preparedness somewhere where libxl_destroy can find it.

Ian.

#17 lore raw

Re: [PATCH v1 06/12] libxl: add support for different hotplug interfaces

Quoted 15 lines · Ian Jackson

Roger Pau Monne writes ("[Xen-devel] [PATCH v1 06/12] libxl: add support for different hotplug interfaces"):

Quoted 2 lines

Add a new variable to libxl_device_disk "hotplug_version", that will be automatically set to the detected hotplug script interface version.

...

tools/libxl/libxl_create.c static void domcreate_destruction_cb(libxl__egc *egc, · line 1226

Quoted 10 lines
tools/libxl/libxl_create.c +10 -0
+    /*
+     * We might have devices that have been prepared, but with no
+     * frontend xenstore entries, so domain destruction fails to
+     * find them, that is why we have to unprepare them manually.
+     */
+    libxl__multidev_begin(ao, &dcs->multidev);
+    dcs->multidev.callback = domcreate_unprepare_cb;
+    libxl__unprepare_disks(egc, ao, domid, d_config, &dcs->multidev);
+    libxl__multidev_prepared(egc, &dcs->multidev, 0);
+    return;
Quoted 6 lines

I don't think this is correct. What if the calling application crashes and this code is never executed ? Then libxl_destroy would leak this state.

So I think you need to record the preparedness somewhere where libxl_destroy can find it.

Right, I've added a new xenstore path that has the following nomenclature:

/libxl/<domid>/hotplug/status/<devid>

Note that it doesn't contain the backend domid, so it can be parsed inside libxl__devices_destroy in order to find devices using the new hotplug interface (even devices that have been prepared but not attached to the domain).

This path is created after the device has been prepared, and is cleaned after the device has been unprepared. It only contains the necessary information to be able to fill a libxl__device struct.

#18 lore raw

Re: [PATCH v1 06/12] libxl: add support for different hotplug interfaces

Roger Pau Monne writes ("Re: [Xen-devel] [PATCH v1 06/12] libxl: add support for different hotplug interfaces"):

Quoted 3 lines

Right, I've added a new xenstore path that has the following nomenclature:

/libxl/<domid>/hotplug/status/<devid>

That sounds plausible. What's the value ?

Quoted 3 lines

This path is created after the device has been prepared, and is cleaned after the device has been unprepared. It only contains the necessary information to be able to fill a libxl__device struct.

I think it needs to be created before you start preparation, so that preparation attempts which crash halfway through are recorded.

Ian.

#19 lore raw

Re: [PATCH v1 06/12] libxl: add support for different hotplug interfaces

Quoted 6 lines · Ian Jackson

Roger Pau Monne writes ("Re: [Xen-devel] [PATCH v1 06/12] libxl: add support for different hotplug interfaces"):

Quoted 3 lines

Right, I've added a new xenstore path that has the following nomenclature:

/libxl/<domid>/hotplug/status/<devid>

That sounds plausible. What's the value ?

There's only one value:

/libxl/<domid>/hotplug/status/<devid>/backend_domid = <backend_dom>

That's all we need to be able to fill a libxl__device structure. I'm also thinking that it might be prudent to use

/libxl/<domid>/hotplug/status/vbd/<devid>/backend_domid = <backend_dom>

Right now vbds are the only users of the new hotplug interface, but who knows if we might want to use it for nics in the future too.

Quoted 7 lines
Quoted 4 lines

This path is created after the device has been prepared, and is cleaned after the device has been unprepared. It only contains the necessary information to be able to fill a libxl__device struct.

I think it needs to be created before you start preparation, so that preparation attempts which crash halfway through are recorded.

Yes, I was also thinking about it after sending the reply...

#20 lore raw

PATCH 7/12 libxl: add prepare/unprepare operations to the libxl public interface

In reply to Roger Pau Monne

Add public functions for the prepare/unprepare disk operations.

---
 tools/libxl/libxl.c |   22 +++++++++++++---------
 tools/libxl/libxl.h |    8 ++++++++
 2 files changed, 21 insertions(+), 9 deletions(-)
tools/libxl/libxl.c +13 -9
index 9061fdf..7e67e61 100644
@@ -1688,7 +1688,7 @@ int libxl_vncviewer_exec(libxl_ctx *ctx, uint32_t domid, int autopass)
 /******************************************************************************/
 
 /* generic callback for devices that only need to set ao_complete */
-static void device_addrm_aocomplete(libxl__egc *egc, libxl__ao_device *aodev)
+static void device_aocomplete(libxl__egc *egc, libxl__ao_device *aodev)
 {
     STATE_AO_GC(aodev->ao);
 
@@ -3539,7 +3539,7 @@ out:
         libxl__prepare_ao_device(ao, aodev);                            \
         aodev->action = LIBXL__DEVICE_ACTION_REMOVE;                    \
         aodev->dev = device;                                            \
-        aodev->callback = device_addrm_aocomplete;                      \
+        aodev->callback = device_aocomplete;                            \
         aodev->force = f;                                               \
         libxl__initiate_device_remove(egc, aodev);                      \
                                                                         \
@@ -3580,10 +3580,12 @@ DEFINE_DEVICE_REMOVE(vtpm, destroy, 1)
  * libxl_device_disk_add
  * libxl_device_nic_add
  * libxl_device_vtpm_add
+ * libxl_device_disk_prepare
+ * libxl_device_disk_unprepare
  */
 
-#define DEFINE_DEVICE_ADD(type)                                         \
-    int libxl_device_##type##_add(libxl_ctx *ctx,                       \
+#define DEFINE_DEVICE_FUNC(type, op)                                    \
+    int libxl_device_##type##_##op(libxl_ctx *ctx,                      \
         uint32_t domid, libxl_device_##type *type,                      \
         const libxl_asyncop_how *ao_how)                                \
     {                                                                   \
@@ -3592,8 +3594,8 @@ DEFINE_DEVICE_REMOVE(vtpm, destroy, 1)
                                                                         \
         GCNEW(aodev);                                                   \
         libxl__prepare_ao_device(ao, aodev);                            \
-        aodev->callback = device_addrm_aocomplete;                      \
-        libxl__device_##type##_add(egc, domid, type, aodev);            \
+        aodev->callback = device_aocomplete;                            \
+        libxl__device_##type##_##op(egc, domid, type, aodev);           \
                                                                         \
         return AO_INPROGRESS;                                           \
     }
@@ -3601,13 +3603,15 @@ DEFINE_DEVICE_REMOVE(vtpm, destroy, 1)
 /* Define alladd functions and undef the macro */
 
 /* disk */
-DEFINE_DEVICE_ADD(disk)
+DEFINE_DEVICE_FUNC(disk, add)
+DEFINE_DEVICE_FUNC(disk, prepare)
+DEFINE_DEVICE_FUNC(disk, unprepare)
 
 /* nic */
-DEFINE_DEVICE_ADD(nic)
+DEFINE_DEVICE_FUNC(nic, add)
 
 /* vtpm */
-DEFINE_DEVICE_ADD(vtpm)
+DEFINE_DEVICE_FUNC(vtpm, add)
 
 #undef DEFINE_DEVICE_ADD
 
tools/libxl/libxl.h +8 -0
index 72e5efb..eda27e2 100644
@@ -687,6 +687,10 @@ void libxl_vtpminfo_list_free(libxl_vtpminfo *, int nr_vtpms);
  */
 
 /* Disks */
+int libxl_device_disk_prepare(libxl_ctx *ctx, uint32_t domid,
+                              libxl_device_disk *disk,
+                              const libxl_asyncop_how *ao_how)
+                              LIBXL_EXTERNAL_CALLERS_ONLY;
 int libxl_device_disk_add(libxl_ctx *ctx, uint32_t domid,
                           libxl_device_disk *disk,
                           const libxl_asyncop_how *ao_how)
@@ -699,6 +703,10 @@ int libxl_device_disk_destroy(libxl_ctx *ctx, uint32_t domid,
                               libxl_device_disk *disk,
                               const libxl_asyncop_how *ao_how)
                               LIBXL_EXTERNAL_CALLERS_ONLY;
+int libxl_device_disk_unprepare(libxl_ctx *ctx, uint32_t domid,
+                                libxl_device_disk *disk,
+                                const libxl_asyncop_how *ao_how)
+                                LIBXL_EXTERNAL_CALLERS_ONLY;
 
 libxl_device_disk *libxl_device_disk_list(libxl_ctx *ctx, uint32_t domid, int *num);
 int libxl_device_disk_getinfo(libxl_ctx *ctx, uint32_t domid,
Signature · 7 lines
1.7.7.5 (Apple Git-26)


_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xen.org/xen-devel
#21 lore raw

Re: [PATCH v1 07/12] libxl: add prepare/unprepare operations to the libxl public interface

Roger Pau Monne writes ("[Xen-devel] [PATCH v1 07/12] libxl: add prepare/unprepare operations to the libxl public interface"):

Quoted 1 line

Add public functions for the prepare/unprepare disk operations.

I'm not sure I understand how the caller is supposed to use this.

How does the eventual script manage to correlate the preparation with the unpreparation ?

How can the caller see what has been prepared ?

Ian.

#22 lore raw

Re: [PATCH v1 07/12] libxl: add prepare/unprepare operations to the libxl public interface

Quoted 4 lines · Ian Jackson

Roger Pau Monne writes ("[Xen-devel] [PATCH v1 07/12] libxl: add prepare/unprepare operations to the libxl public interface"):

Quoted 1 line

Add public functions for the prepare/unprepare disk operations.

I'm not sure I understand how the caller is supposed to use this.

The caller should execute prepare before adding the disk (hopefully in a not performance sensitive path).

Quoted 2 lines

How does the eventual script manage to correlate the preparation with the unpreparation ?

You call the script with the prepare or unprepare parameters, so the script knows which action it has to execute.

Quoted 1 line

How can the caller see what has been prepared ?

The caller should take care of this states by himself (just as we do with add or remove), so it knows if the device has been prepared or not.

The only downfall of not calling prepare before add is that libxl will thread this device as using the v1 hotplug interface, so old users of libxl will still have the same functionality, but they will not be able to use new hotplug scripts using the v2 interface.

This functions are only used for disk attach/detach (xl block-attach/block-detach), for domain creation the domain builder logic already takes care of preparing the devices before adding them.

#23 lore raw

Re: [PATCH v1 07/12] libxl: add prepare/unprepare operations to the libxl public interface

Quoted 2 lines · Roger Pau Monné

The caller should take care of this states by himself (just as we do with add or remove), so it knows if the device has been prepared or not.

Just as a clarification, the way to know if a device has been prepared but not added is to look for the xenstore entries. If the device only has

/libxl/<domid>/hotplug/status/<devid>/

then it has been prepared but not added, on the other hand, if the device has the above xenstore path, and also

/local/domain/<domid>/device/vbd/<devid>/backend

then it has been prepared and added. But I can't come up with any reason a libxl user should look at this paths by himself.

#24 lore raw

Re: [PATCH v1 07/12] libxl: add prepare/unprepare operations to the libxl public interface

In reply to Roger Pau Monné

Roger Pau Monne writes ("Re: [Xen-devel] [PATCH v1 07/12] libxl: add prepare/unprepare operations to the libxl public interface"):

Quoted 5 lines · Ian Jackson
Quoted 1 line

I'm not sure I understand how the caller is supposed to use this.

The caller should execute prepare before adding the disk (hopefully in a not performance sensitive path).

That's a non-backward-compatible API change, then ? We're trying to avoid those.

Quoted 5 lines
Quoted 2 lines

How does the eventual script manage to correlate the preparation with the unpreparation ?

You call the script with the prepare or unprepare parameters, so the script knows which action it has to execute.

No, I mean, is it just the target string that is relevant for identifying the preparation ? Can the same disk be prepared multiple times (eg for multiple guests) ? How is this synchronised ?

Quoted 4 lines

The only downfall of not calling prepare before add is that libxl will thread this device as using the v1 hotplug interface, so old users of libxl will still have the same functionality, but they will not be able to use new hotplug scripts using the v2 interface.

Perhaps it would be better to hide this from the caller and implement the old API in terms of the new one ?

ian.

#25 lore raw

Re: [PATCH v1 07/12] libxl: add prepare/unprepare operations to the libxl public interface

Quoted 9 lines · Ian Jackson

Roger Pau Monne writes ("Re: [Xen-devel] [PATCH v1 07/12] libxl: add prepare/unprepare operations to the libxl public interface"):

Quoted 5 lines · Ian Jackson
Quoted 1 line

I'm not sure I understand how the caller is supposed to use this.

The caller should execute prepare before adding the disk (hopefully in a not performance sensitive path).

That's a non-backward-compatible API change, then ? We're trying to avoid those.

It is backward compatible if the caller only uses v1 hotplug scripts. If the caller wishes to use v2, then it has to call prepare.

Quoted 10 lines
Quoted 6 lines
Quoted 3 lines

How does the eventual script manage to correlate the preparation with the unpreparation ?

You call the script with the prepare or unprepare parameters, so the script knows which action it has to execute.

No, I mean, is it just the target string that is relevant for identifying the preparation ? Can the same disk be prepared multiple times (eg for multiple guests) ? How is this synchronised ?

Yes, since everything is stored in terms of <domid>/<devid>, the same "params" line can be used in multiple guests.

Quoted 8 lines
Quoted 5 lines

The only downfall of not calling prepare before add is that libxl will thread this device as using the v1 hotplug interface, so old users of libxl will still have the same functionality, but they will not be able to use new hotplug scripts using the v2 interface.

Perhaps it would be better to hide this from the caller and implement the old API in terms of the new one ?

The advantage of this new hotplug calling convention is that you are allowed to call prepare and add at different points, so you can offload work done in the add phase to the prepare call.

That being said, this public prepare function is only used for block-attach, so I'm not sure if we are interested in doing any kind of offloading there (since it's not a critical path), so I might as well remove the public prepare/unprepare functions and do it all inside add.

#26 lore raw

PATCH 8/12 libxl: add disk specific remove functions

In reply to Roger Pau Monne

Add a specific macro to generate libxl_device_disk_{remove/destroy} functions that passes the hotplug_version field down to the aodev struct.

---
 tools/libxl/libxl.c |   35 +++++++++++++++++++++++++++++++++--
 1 files changed, 33 insertions(+), 2 deletions(-)
tools/libxl/libxl.c +33 -2
index 7e67e61..80782cb 100644
@@ -3548,11 +3548,41 @@ out:
         return AO_INPROGRESS;                                           \
     }
 
+/* Specific for disk devices, that have to set aodev->hotplug_version */
+#define DEFINE_DISK_REMOVE(type, removedestroy, f)                      \
+    int libxl_device_##type##_##removedestroy(libxl_ctx *ctx,           \
+        uint32_t domid, libxl_device_##type *type,                      \
+        const libxl_asyncop_how *ao_how)                                \
+    {                                                                   \
+        AO_CREATE(ctx, domid, ao_how);                                  \
+        libxl__device *device;                                          \
+        libxl__ao_device *aodev;                                        \
+        int rc;                                                         \
+                                                                        \
+        GCNEW(device);                                                  \
+        rc = libxl__device_from_##type(gc, domid, type, device);        \
+        if (rc != 0) goto out;                                          \
+                                                                        \
+        GCNEW(aodev);                                                   \
+        libxl__prepare_ao_device(ao, aodev);                            \
+        aodev->action = LIBXL__DEVICE_ACTION_REMOVE;                    \
+        aodev->dev = device;                                            \
+        aodev->callback = device_aocomplete;                            \
+        aodev->force = f;                                               \
+        aodev->hotplug.version = type->hotplug_version;                 \
+        LOG(DEBUG, "hotplug version: %d", aodev->hotplug.version);      \
+        libxl__initiate_device_remove(egc, aodev);                      \
+                                                                        \
+    out:                                                                \
+        if (rc) return AO_ABORT(rc);                                    \
+        return AO_INPROGRESS;                                           \
+    }
+
 /* Define all remove/destroy functions and undef the macro */
 
 /* disk */
-DEFINE_DEVICE_REMOVE(disk, remove, 0)
-DEFINE_DEVICE_REMOVE(disk, destroy, 1)
+DEFINE_DISK_REMOVE(disk, remove, 0)
+DEFINE_DISK_REMOVE(disk, destroy, 1)
 
 /* nic */
 DEFINE_DEVICE_REMOVE(nic, remove, 0)
@@ -3571,6 +3601,7 @@ DEFINE_DEVICE_REMOVE(vfb, destroy, 1)
 DEFINE_DEVICE_REMOVE(vtpm, remove, 0)
 DEFINE_DEVICE_REMOVE(vtpm, destroy, 1)
 
+#undef DEFINE_DISK_REMOVE
 #undef DEFINE_DEVICE_REMOVE
 
 /******************************************************************************/
Signature · 7 lines
1.7.7.5 (Apple Git-26)


_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xen.org/xen-devel
#27 lore raw

Re: [PATCH v1 08/12] libxl: add disk specific remove functions

Roger Pau Monne writes ("[Xen-devel] [PATCH v1 08/12] libxl: add disk specific remove functions"):

tools/libxl/libxl.c out: · line 3553

Quoted 7 lines

Add a specific macro to generate libxl_device_disk_{remove/destroy} functions that passes the hotplug_version field down to the aodev struct.

tools/libxl/libxl.c +3 -0
+/* Specific for disk devices, that have to set aodev->hotplug_version */
+#define DEFINE_DISK_REMOVE(type, removedestroy, f)                      \
+    int libxl_device_##type##_##removedestroy(libxl_ctx *ctx,           \

This macro is very similar to DEFINE_DEVICE_REMOVE. The only difference seems to be these extra lines:

tools/libxl/libxl.c out: · line 3574

Quoted 3 lines
tools/libxl/libxl.c +3 -0
+        aodev->hotplug.version = type->hotplug_version;                 \
+        LOG(DEBUG, "hotplug version: %d", aodev->hotplug.version);      \
+        libxl__initiate_device_remove(egc, aodev);                      \

Perhaps the right answer would be to add a new formal parameter to DEFINE_DEVICE_REMOVE which allows DEFINE_DEVICE_REMOVE's user to specify some extra code here ?

Ian.

#28 lore raw

Re: [PATCH v1 08/12] libxl: add disk specific remove functions

Quoted 12 lines · Ian Jackson

Roger Pau Monne writes ("[Xen-devel] [PATCH v1 08/12] libxl: add disk specific remove functions"):

tools/libxl/libxl.c out: · line 3553

Quoted 7 lines

Add a specific macro to generate libxl_device_disk_{remove/destroy} functions that passes the hotplug_version field down to the aodev struct.

tools/libxl/libxl.c +3 -0
+/* Specific for disk devices, that have to set aodev->hotplug_version */
+#define DEFINE_DISK_REMOVE(type, removedestroy, f)                      \
+    int libxl_device_##type##_##removedestroy(libxl_ctx *ctx,           \

This macro is very similar to DEFINE_DEVICE_REMOVE. The only difference seems to be these extra lines:

Quoted 7 lines

tools/libxl/libxl.c out: · line 3574

Quoted 3 lines
tools/libxl/libxl.c +3 -0
+        aodev->hotplug.version = type->hotplug_version;                 \
+        LOG(DEBUG, "hotplug version: %d", aodev->hotplug.version);      \
+        libxl__initiate_device_remove(egc, aodev);                      \

Perhaps the right answer would be to add a new formal parameter to DEFINE_DEVICE_REMOVE which allows DEFINE_DEVICE_REMOVE's user to specify some extra code here ?

type->hotplug_version is only available in libxl_device_disk, so even if using something like

if (param)

	aodev->hotplug.version = type->hotplug_version;

Would break compilation because other device types don't have the hotplug_version field (and adding a hotplug_version field to all device structures seems overkill).

#29 lore raw

Re: [PATCH v1 08/12] libxl: add disk specific remove functions [and 1 more messages]

Roger Pau Monne writes ("Re: [Xen-devel] [PATCH v1 08/12] libxl: add disk specific remove functions"):

Quoted 12 lines · Ian Jackson
Quoted 10 lines

This macro is very similar to DEFINE_DEVICE_REMOVE. The only difference seems to be these extra lines:

tools/libxl/libxl.c out: · line 3574

Quoted 3 lines
tools/libxl/libxl.c +3 -0
+        aodev->hotplug.version = type->hotplug_version;                 \
+        LOG(DEBUG, "hotplug version: %d", aodev->hotplug.version);      \
+        libxl__initiate_device_remove(egc, aodev);                      \

Perhaps the right answer would be to add a new formal parameter to DEFINE_DEVICE_REMOVE which allows DEFINE_DEVICE_REMOVE's user to specify some extra code here ?

Quoted 5 lines

type->hotplug_version is only available in libxl_device_disk, so even if using something like

if (param)

	aodev->hotplug.version = type->hotplug_version;

I see I didn't reply to this and your v2 has this patch unchanged. I still think we need to find a way not to duplicate this code. What I meant above was something like this:

#define DEFINE_DEVICE_REMOVE(type, removedestroy, f, extra)             \
    int libxl_device_##type##_##removedestroy(libxl_ctx *ctx,           \
        uint32_t domid, libxl_device_##type *type,                      \
        const libxl_asyncop_how *ao_how)                                \
    {                                                                   \
        AO_CREATE(ctx, domid, ao_how);                                  \
        libxl__device *device;                                          \
        libxl__ao_device *aodev;                                        \
        int rc;                                                         \
                                                                        \
        GCNEW(device);                                                  \
        rc = libxl__device_from_##type(gc, domid, type, device);        \
        if (rc != 0) goto out;                                          \
                                                                        \
        GCNEW(aodev);                                                   \
        libxl__prepare_ao_device(ao, aodev);                            \
        aodev->action = LIBXL__DEVICE_ACTION_REMOVE;                    \
        aodev->dev = device;                                            \
        aodev->callback = device_addrm_aocomplete;                      \
        aodev->force = f;                                               \
        extra;                                                          \
        libxl__initiate_device_remove(egc, aodev);                      \
                                                                        \
    out:                                                                \
        if (rc) return AO_ABORT(rc);                                    \
        return AO_INPROGRESS;                                           \
    }

#define DEFINE_DISK_REMOVE(type, removedestroy, f) \

 DEFINE_DEVICE_REMOVE(type, removedestroy, f, {
        aodev->hotplug.version = type->hotplug_version;
        LOG(DEBUG, "hotplug version: %d", aodev->hotplug.version);
    })

Ian.

#30 lore raw

Re: [PATCH v1 08/12] libxl: add disk specific remove functions [and 1 more messages]

Quoted 51 lines · Ian Jackson

Roger Pau Monne writes ("Re: [Xen-devel] [PATCH v1 08/12] libxl: add disk specific remove functions"):

Quoted 12 lines · Ian Jackson
Quoted 10 lines

This macro is very similar to DEFINE_DEVICE_REMOVE. The only difference seems to be these extra lines:

tools/libxl/libxl.c out: · line 3574

Quoted 3 lines
tools/libxl/libxl.c +3 -0
+        aodev->hotplug.version = type->hotplug_version;                 \
+        LOG(DEBUG, "hotplug version: %d", aodev->hotplug.version);      \
+        libxl__initiate_device_remove(egc, aodev);                      \

Perhaps the right answer would be to add a new formal parameter to DEFINE_DEVICE_REMOVE which allows DEFINE_DEVICE_REMOVE's user to specify some extra code here ?

Quoted 5 lines

type->hotplug_version is only available in libxl_device_disk, so even if using something like

if (param)

	aodev->hotplug.version = type->hotplug_version;

I see I didn't reply to this and your v2 has this patch unchanged. I still think we need to find a way not to duplicate this code. What I meant above was something like this:

#define DEFINE_DEVICE_REMOVE(type, removedestroy, f, extra)             \
    int libxl_device_##type##_##removedestroy(libxl_ctx *ctx,           \
        uint32_t domid, libxl_device_##type *type,                      \
        const libxl_asyncop_how *ao_how)                                \
    {                                                                   \
        AO_CREATE(ctx, domid, ao_how);                                  \
        libxl__device *device;                                          \
        libxl__ao_device *aodev;                                        \
        int rc;                                                         \
                                                                        \
        GCNEW(device);                                                  \
        rc = libxl__device_from_##type(gc, domid, type, device);        \
        if (rc != 0) goto out;                                          \
                                                                        \
        GCNEW(aodev);                                                   \
        libxl__prepare_ao_device(ao, aodev);                            \
        aodev->action = LIBXL__DEVICE_ACTION_REMOVE;                    \
        aodev->dev = device;                                            \
        aodev->callback = device_addrm_aocomplete;                      \
        aodev->force = f;                                               \
        extra;                                                          \
        libxl__initiate_device_remove(egc, aodev);                      \
                                                                        \
    out:                                                                \
        if (rc) return AO_ABORT(rc);                                    \
        return AO_INPROGRESS;                                           \
    }
Quoted 5 lines

#define DEFINE_DISK_REMOVE(type, removedestroy, f) \

 DEFINE_DEVICE_REMOVE(type, removedestroy, f, {
        aodev->hotplug.version = type->hotplug_version;
        LOG(DEBUG, "hotplug version: %d", aodev->hotplug.version);
    })

Done, I will wait for comments for v2 before reposting.

#31 lore raw

PATCH 9/12 xl: add support for new hotplug interface to block-attach/detach

In reply to Roger Pau Monne

Call prepare before attaching a block device.

---
 tools/libxl/xl_cmdimpl.c |    5 +++++
 1 files changed, 5 insertions(+), 0 deletions(-)
tools/libxl/xl_cmdimpl.c +5 -0
index e964bf1..c4af90f 100644
@@ -5649,6 +5649,11 @@ int main_blockattach(int argc, char **argv)
         return 0;
     }
 
+    if (libxl_device_disk_prepare(ctx, fe_domid, &disk, 0)) {
+        fprintf(stderr, "libxl_device_disk_prepare failed.\n");
+        return 1;
+    }
+
     if (libxl_device_disk_add(ctx, fe_domid, &disk, 0)) {
         fprintf(stderr, "libxl_device_disk_add failed.\n");
     }
Signature · 7 lines
1.7.7.5 (Apple Git-26)


_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xen.org/xen-devel
#32 lore raw

Re: [PATCH v1 09/12] xl: add support for new hotplug interface to block-attach/detach

Roger Pau Monne writes ("[Xen-devel] [PATCH v1 09/12] xl: add support for new hotplug interface to block-attach/detach"):

Quoted 1 line

Call prepare before attaching a block device.

Why is this helpful in xl ?

Ian.

#33 lore raw

Re: [PATCH v1 09/12] xl: add support for new hotplug interface to block-attach/detach

Quoted 4 lines · Ian Jackson

Roger Pau Monne writes ("[Xen-devel] [PATCH v1 09/12] xl: add support for new hotplug interface to block-attach/detach"):

Quoted 1 line

Call prepare before attaching a block device.

Why is this helpful in xl ?

prepare function gets the hotplug version of the script and also executes the prepare hotplug action if necessary. Failing to call prepare would assume hotplug version is v1, so we won't be able to block-attach devices using the v2 hotplug interface.

#34 lore raw

PATCH 10/12 libxl: add local attach support for new hotplug scripts

In reply to Roger Pau Monne

Adds support for locally attaching disks that use the new hotplug script interface, by calling the localattach/localdetach operations and returning a block device that can be used to execute pygrub.

---
 tools/libxl/libxl.c            |   86 ++++++++++++++++++++++++++++++++++------
 tools/libxl/libxl_bootloader.c |    1 +
 tools/libxl/libxl_internal.h   |    1 +
 3 files changed, 76 insertions(+), 12 deletions(-)
tools/libxl/libxl.c +74 -12
index 80782cb..5a8c2cc 100644
@@ -2709,6 +2709,7 @@ void libxl__device_disk_local_initiate_attach(libxl__egc *egc,
     const libxl_device_disk *in_disk = dls->in_disk;
     libxl_device_disk *disk = &dls->disk;
     const char *blkdev_start = dls->blkdev_start;
+    uint32_t domid = dls->domid;
 
     assert(in_disk->pdev_path);
 
@@ -2725,6 +2726,23 @@ void libxl__device_disk_local_initiate_attach(libxl__egc *egc,
         case LIBXL_DISK_BACKEND_PHY:
             LIBXL__LOG(ctx, LIBXL__LOG_DEBUG, "locally attaching PHY disk %s",
                        disk->pdev_path);
+            if (disk->hotplug_version == 2) {
+                disk->vdev = libxl__strdup(gc, in_disk->vdev);
+                libxl__prepare_ao_device(ao, &dls->aodev);
+                GCNEW(dls->aodev.dev);
+                rc = libxl__device_from_disk(gc, domid, disk,
+                                             dls->aodev.dev);
+                if (rc != 0) {
+                    LOG(ERROR, "Invalid or unsupported virtual disk "
+                               "identifier %s", disk->vdev);
+                    goto out;
+                }
+                dls->aodev.action = LIBXL__DEVICE_ACTION_LOCALATTACH;
+                dls->aodev.hotplug.version = disk->hotplug_version;
+                dls->aodev.callback = local_device_attach_cb;
+                libxl__device_hotplug(egc, &dls->aodev);
+                return;
+            }
             dev = disk->pdev_path;
             break;
         case LIBXL_DISK_BACKEND_TAP:
@@ -2787,7 +2805,8 @@ static void local_device_attach_cb(libxl__egc *egc, libxl__ao_device *aodev)
 {
     STATE_AO_GC(aodev->ao);
     libxl__disk_local_state *dls = CONTAINER_OF(aodev, *dls, aodev);
-    char *dev = NULL, *be_path = NULL;
+    char *dev = NULL, *be_path = NULL, *hotplug_path;
+    const char *pdev = NULL;
     int rc;
     libxl__device device;
     libxl_device_disk *disk = &dls->disk;
@@ -2800,20 +2819,45 @@ static void local_device_attach_cb(libxl__egc *egc, libxl__ao_device *aodev)
                     aodev->dev->devid);
         goto out;
     }
+    switch (disk->backend) {
+    case LIBXL_DISK_BACKEND_PHY:
+        /* Fetch hotplug output to obtain the block device */
+        rc = libxl__device_from_disk(gc, dls->domid, disk, &device);
+        if (rc)
+            goto out;
+        hotplug_path = libxl__device_xs_hotplug_path(gc, &device);
+        rc = libxl__xs_read_checked(gc, XBT_NULL,
+                                    GCSPRINTF("%s/pdev", hotplug_path),
+                                    &pdev);
+        if (rc)
+            goto out;
+        if (!pdev) {
+            rc = ERROR_FAIL;
+            goto out;
+        }
+        LOG(DEBUG, "attached local block device %s", pdev);
+        dls->diskpath = libxl__strdup(gc, pdev);
+        break;
+    case LIBXL_DISK_BACKEND_QDISK:
+        dev = GCSPRINTF("/dev/%s", disk->vdev);
+        LOG(DEBUG, "locally attaching qdisk %s", dev);
 
-    dev = GCSPRINTF("/dev/%s", disk->vdev);
-    LOG(DEBUG, "locally attaching qdisk %s", dev);
+        rc = libxl__device_from_disk(gc, LIBXL_TOOLSTACK_DOMID, disk, &device);
+        if (rc < 0)
+            goto out;
+        be_path = libxl__device_backend_path(gc, &device);
+        rc = libxl__wait_for_backend(gc, be_path, "4");
+        if (rc < 0)
+            goto out;
 
-    rc = libxl__device_from_disk(gc, LIBXL_TOOLSTACK_DOMID, disk, &device);
-    if (rc < 0)
-        goto out;
-    be_path = libxl__device_backend_path(gc, &device);
-    rc = libxl__wait_for_backend(gc, be_path, "4");
-    if (rc < 0)
+        if (dev != NULL)
+            dls->diskpath = libxl__strdup(gc, dev);
+        break;
+    default:
+        LOG(ERROR, "invalid disk backend for local attach callback");
+        rc = ERROR_FAIL;
         goto out;
-
-    if (dev != NULL)
-        dls->diskpath = libxl__strdup(gc, dev);
+    }
 
     dls->callback(egc, dls, 0);
     return;
@@ -2837,11 +2881,29 @@ void libxl__device_disk_local_initiate_detach(libxl__egc *egc,
     libxl_device_disk *disk = &dls->disk;
     libxl__device *device;
     libxl__ao_device *aodev = &dls->aodev;
+    uint32_t domid = dls->domid;
     libxl__prepare_ao_device(ao, aodev);
 
     if (!dls->diskpath) goto out;
 
     switch (disk->backend) {
+        case LIBXL_DISK_BACKEND_PHY:
+            if (disk->hotplug_version == 2) {
+                GCNEW(aodev->dev);
+                rc = libxl__device_from_disk(gc, domid, disk,
+                                             aodev->dev);
+                if (rc != 0) {
+                    LOG(ERROR, "Invalid or unsupported virtual disk "
+                               "identifier %s", disk->vdev);
+                    goto out;
+                }
+                aodev->action = LIBXL__DEVICE_ACTION_LOCALDETACH;
+                aodev->hotplug.version = disk->hotplug_version;
+                aodev->callback = local_device_detach_cb;
+                libxl__device_hotplug(egc, aodev);
+                return;
+            }
+            break;
         case LIBXL_DISK_BACKEND_QDISK:
             if (disk->vdev != NULL) {
                 GCNEW(device);
tools/libxl/libxl_bootloader.c +1 -0
index ed12b2c..5d889fe 100644
@@ -381,6 +381,7 @@ void libxl__bootloader_run(libxl__egc *egc, libxl__bootloader_state *bl)
     bl->dls.ao = ao;
     bl->dls.in_disk = bl->disk;
     bl->dls.blkdev_start = info->blkdev_start;
+    bl->dls.domid = domid;
     bl->dls.callback = bootloader_disk_attached_cb;
     libxl__device_disk_local_initiate_attach(egc, &bl->dls);
     return;
tools/libxl/libxl_internal.h +1 -0
index 67fb95e..293d0eb 100644
@@ -2133,6 +2133,7 @@ struct libxl__disk_local_state {
     libxl_device_disk disk;
     const char *blkdev_start;
     libxl__disk_local_state_callback *callback;
+    uint32_t domid;
     /* filled by libxl__device_disk_local_initiate_attach */
     char *diskpath;
     /* private for implementation of local detach */
Signature · 7 lines
1.7.7.5 (Apple Git-26)


_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xen.org/xen-devel
#35 lore raw

Re: [PATCH v1 10/12] libxl: add local attach support for new hotplug scripts

Roger Pau Monne writes ("[Xen-devel] [PATCH v1 10/12] libxl: add local attach support for new hotplug scripts"):

Quoted 3 lines

Adds support for locally attaching disks that use the new hotplug script interface, by calling the localattach/localdetach operations and returning a block device that can be used to execute pygrub.

This is an optimisation, isn't it ? In the sense that nothing should go wrong if we don't have this code ?

Ian.

#36 lore raw

Re: [PATCH v1 10/12] libxl: add local attach support for new hotplug scripts

Quoted 7 lines · Ian Jackson

Roger Pau Monne writes ("[Xen-devel] [PATCH v1 10/12] libxl: add local attach support for new hotplug scripts"):

Quoted 3 lines

Adds support for locally attaching disks that use the new hotplug script interface, by calling the localattach/localdetach operations and returning a block device that can be used to execute pygrub.

This is an optimisation, isn't it ? In the sense that nothing should go wrong if we don't have this code ?

The status-quo right now is that custom hotplug scripts cannot be used in conjunction with pygrub, because we need to pass pygrub either a block device or a raw file. This patch adds the necessary functionality in order to attach the block device before executing pygrub, so we can use this new hotplug scripts with pygrub, providing extra functionality.

#37 lore raw

PATCH 11/12 hotplug: document new hotplug interface

In reply to Roger Pau Monne

Mention the new diskspec parameter and add a document explaining the new hotplug interface.

---
 docs/misc/libxl-hotplug-interface.txt |  167 +++++++++++++++++++++++++++++++++
 1 files changed, 167 insertions(+), 0 deletions(-)
 create mode 100644 docs/misc/libxl-hotplug-interface.txt
docs/misc/libxl-hotplug-interface.txt new file +167 -0
new file mode 100644
index 0000000..2ee0ebd
@@ -0,0 +1,167 @@
+                     -----------------------
+                     LIBXL HOTPLUG INTERFACE
+                     -----------------------
+
+This document specifies the new libxl hotplug interface. This new
+interface has been designed to operate better with complex hotplug
+scripts, that need to perform several operations and can take a
+considerable time to execute.
+
+Hotplug scripts are expected to take a parameter, passed by the caller
+and provide a block device as output, that will be attached to the guest.
+
+
+
+=====================
+ENVIRONMENT VARIABLES
+=====================
+
+
+The following environment variables will be set before calling
+the hotplug script.
+
+
+HOTPLUG_PATH
+------------
+
+Points to the xenstore directory that holds information relative
+to this hotplug script. At present only one parameter is passed by
+the toolstack, the "params" xenstore entry which contains the "target"
+line specified in the diskspec xl disk configuration (pdev_path in
+libxl_device_disk struct).
+
+This xenstore directory will be used to communicate between the
+hotplug script and the toolstack, and it can also be used by the
+hotplug script to store temporary information. This directory is created
+before calling the "prepare" operation, and the toolstack guarantees
+that it will not be removed before the "unprepare" operation has been
+finished. After that, the toolstack will take the appropriate actions
+to remove it. The toolstack guarantees that HOTPLUG_PATH will always
+point to a valid xenstore path for all operations.
+
+The path of this directory follows the syntax:
+
+/local/domain/<local_domid>/libxl/hotplug/<guest_domid>/<device_id>
+
+(Note that there is no end slash appended to HOTPLUG_PATH)
+
+
+BACKEND_PATH
+------------
+
+Points to the xenstore backend path of the corresponding block device.
+Since hotplug scripts are always executed in the Domain that acts as
+backend for a device, it will always have the following syntax:
+
+/local/domain/<local_domain>/backend/vbd/<guest_domid>/<device_id>
+
+(Note that there is no end slash appended to BACKEND_PATH)
+
+This environment variable is not set for all operations, since some
+hotplug operations are executed before the backend xenstore is set up.
+
+
+
+=======================
+COMMAND LINE PARAMETERS
+=======================
+
+
+Script will be called with only one parameter, that is either prepare,
+add, remove, unprepare, localattach or localdetach.
+
+VERSION
+-------
+
+Operation used to request the version this hotplug script supports. Failure
+to perform this operation will result in hotplug script detected as version 1.
+
+BACKEND_PATH: not valid
+
+Expected output:
+HOTPLGU_PATH/version = version supported by the hotplug script
+
+
+PREPARE
+-------
+
+This is the first operation that the hotplug script will be requested to
+execute. This operation is executed before the disk is connected, to
+give the hotplug script the chance to offload some work from the "add"
+operation, that is performed later.
+
+BACKEND_PATH: not valid
+
+Expected output:
+None
+
+
+ADD
+---
+
+This operation should connect the device to the domain. Will only be called
+after the "prepare" operation has finished successfully.
+
+BACKEND_PATH: valid
+
+Expected output:
+BACKEND_PATH/physical-device = block device major:minor
+BACKEND_PATH/params = block device path
+HOTPLUG_PATH/pdev = block device path
+
+
+REMOVE
+------
+
+
+Disconnects a block device from a domain. Will only be called
+after the "prepare" operation has finished successfully. Implementations
+should take into account that the "remove" operation will also be called if
+the "add" operation has failed.
+
+BACKEND_PATH: valid
+
+Expected output:
+None
+
+
+LOCALATTACH
+-----------
+
+
+Creates a block device in the current domain that points to the guest
+disk device. Will only be called after the "prepare" operation has
+finished successfully.
+
+BACKEND_PATH: not valid
+
+Expected output:
+HOTPLUG_PATH/pdev = block device path
+
+
+LOCALDETACH
+-----------
+
+
+Disconnects a device (previously connected with the localattach
+operation) from the current domain. Will only be called after
+the "prepare" operation has finished successfully. Implementations
+should take into account that the "localdetach" operation will
+also be called if the "localattach" operation has failed.
+
+BACKEND_PATH: not valid
+
+Expected output:
+None
+
+
+UNPREPARE
+---------
+
+
+Performs the necessary actions to unprepare the device.
+
+BACKEND_PATH: not valid
+
+Expected output:
+None
Signature · 7 lines
1.7.7.5 (Apple Git-26)


_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xen.org/xen-devel
#38 lore raw

Re: [PATCH v1 11/12] hotplug: document new hotplug interface

Roger Pau Monne writes ("[Xen-devel] [PATCH v1 11/12] hotplug: document new hotplug interface"):

Quoted 2 lines

Mention the new diskspec parameter and add a document explaining the new hotplug interface.

...

docs/misc/libxl-hotplug-interface.txt

Quoted 12 lines
docs/misc/libxl-hotplug-interface.txt new file +12 -0
+HOTPLUG_PATH
+------------
+
+Points to the xenstore directory that holds information relative
+to this hotplug script. At present only one parameter is passed by
+the toolstack, the "params" xenstore entry which contains the "target"
+line specified in the diskspec xl disk configuration (pdev_path in
+libxl_device_disk struct).
+
+This xenstore directory will be used to communicate between the
+hotplug script and the toolstack, and it can also be used by the
+hotplug script to store temporary information.

Doesn't this leave the possibility that a script might decide to write "sponge"="42" in the xenstore directory, for its own purposes, and that libxl might later decide to try to pass "sponge"="bath" for an enhanced interface ?

I think you need to specify which names each user is entitled to use.

Also, you need to say something about access control.

Quoted 3 lines

+=======================
+COMMAND LINE PARAMETERS
+=======================

...

docs/misc/libxl-hotplug-interface.txt line 71

Quoted 2 lines
docs/misc/libxl-hotplug-interface.txt new file +2 -0
+Script will be called with only one parameter, that is either prepare,
+add, remove, unprepare, localattach or localdetach.

You need to say what scripts should do with unknown parameters.

docs/misc/libxl-hotplug-interface.txt line 82

Quoted 4 lines
docs/misc/libxl-hotplug-interface.txt new file +4 -0
+BACKEND_PATH: not valid
+
+Expected output:
+HOTPLGU_PATH/version = version supported by the hotplug script

The output is written into xenstore ? (Also, typo.)

thanks,
Ian.

#39 lore raw

Re: [PATCH v1 11/12] hotplug: document new hotplug interface

Quoted 13 lines · Ian Jackson

Roger Pau Monne writes ("[Xen-devel] [PATCH v1 11/12] hotplug: document new hotplug interface"):

Quoted 2 lines

Mention the new diskspec parameter and add a document explaining the new hotplug interface.

...

Quoted 9 lines
docs/misc/libxl-hotplug-interface.txt new file +9 -0
+HOTPLUG_PATH
+------------
+
+Points to the xenstore directory that holds information relative
+to this hotplug script. At present only one parameter is passed by
+the toolstack, the "params" xenstore entry which contains the "target"
+line specified in the diskspec xl disk configuration (pdev_path in
+libxl_device_disk struct).
+
Quoted 8 lines

docs/misc/libxl-hotplug-interface.txt

Quoted 3 lines
docs/misc/libxl-hotplug-interface.txt new file +3 -0
+This xenstore directory will be used to communicate between the
+hotplug script and the toolstack, and it can also be used by the
+hotplug script to store temporary information.

Doesn't this leave the possibility that a script might decide to write "sponge"="42" in the xenstore directory, for its own purposes, and that libxl might later decide to try to pass "sponge"="bath" for an enhanced interface ?

This hotplug scripts (v2) should only be called with the parameters and env vars specified in this document, so we should never call this scripts with anything different.

If we ever decide to pass some random env var, we should bump hotplug version to 3 and redo this document, but guessing now which env vars we might need in the future is kind of a shot in the dark.

Quoted 1 line

I think you need to specify which names each user is entitled to use.

Reserved xenstore entries are also listed in the document, the user should not use the following entries randomly:

HOTPLUG_PATH/version
HOTPLUG_PATH/pdev

Quoted 1 line

Also, you need to say something about access control.

The hotplug script will have permissions to read/write on HOTPLUG_PATH and BACKEND_PATH at least, but of course if this runs on the Dom0 it will have access to everything (just as hotplug scripts have right now)

Quoted 20 lines
Quoted 4 lines

+=======================
+COMMAND LINE PARAMETERS
+=======================

...

docs/misc/libxl-hotplug-interface.txt line 71

Quoted 2 lines
docs/misc/libxl-hotplug-interface.txt new file +2 -0
+Script will be called with only one parameter, that is either prepare,
+add, remove, unprepare, localattach or localdetach.

You need to say what scripts should do with unknown parameters.

docs/misc/libxl-hotplug-interface.txt line 82

Quoted 4 lines
docs/misc/libxl-hotplug-interface.txt new file +4 -0
+BACKEND_PATH: not valid
+
+Expected output:
+HOTPLGU_PATH/version = version supported by the hotplug script

The output is written into xenstore ? (Also, typo.)

thanks,
Ian.

#40 lore raw

PATCH 12/12 hotplug/Linux: add iscsi block hotplug script

In reply to Roger Pau Monne

This hotplug script has been tested with IET and NetBSD iSCSI targets, without authentication.

Authentication parameters, including the password are passed as parameters to iscsiadm, which is not recommended because other users of the system can see them. This parameters could also be set by editing a corresponding file directly, but the location of this file seems to be different depending on the distribution used.

---
 tools/hotplug/Linux/Makefile    |    1 +
 tools/hotplug/Linux/block-iscsi |  258 +++++++++++++++++++++++++++++++++++++++
 2 files changed, 259 insertions(+), 0 deletions(-)
 create mode 100644 tools/hotplug/Linux/block-iscsi
tools/hotplug/Linux/Makefile +1 -0
index 0605559..98c7738 100644
@@ -21,6 +21,7 @@ XEN_SCRIPTS += blktap
 XEN_SCRIPTS += xen-hotplug-cleanup
 XEN_SCRIPTS += external-device-migrate
 XEN_SCRIPTS += vscsi
+XEN_SCRIPTS += block-iscsi
 XEN_SCRIPT_DATA = xen-script-common.sh locking.sh logging.sh
 XEN_SCRIPT_DATA += xen-hotplug-common.sh xen-network-common.sh vif-common.sh
 XEN_SCRIPT_DATA += block-common.sh
tools/hotplug/Linux/block-iscsi new file +258 -0

258 lines not on this page · raw message

Signature · 7 lines
1.7.7.5 (Apple Git-26)


_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xen.org/xen-devel
#41 lore raw

Re: [PATCH v1 12/12] hotplug/Linux: add iscsi block hotplug script

Roger Pau Monne writes ("[Xen-devel] [PATCH v1 12/12] hotplug/Linux: add iscsi block hotplug script"):

Quoted 8 lines

This hotplug script has been tested with IET and NetBSD iSCSI targets, without authentication.

Authentication parameters, including the password are passed as parameters to iscsiadm, which is not recommended because other users of the system can see them. This parameters could also be set by editing a corresponding file directly, but the location of this file seems to be different depending on the distribution used.

Would it be possible for the user to specify the file that the password should be read from ?

Did you write this script from scratch ? (TBH I don't intend to review it in detail...)

Why no set -e ?

Ian.

#42 lore raw

Re: [PATCH v1 12/12] hotplug/Linux: add iscsi block hotplug script

Quoted 4 lines · Ian Jackson

Roger Pau Monne writes ("[Xen-devel] [PATCH v1 12/12] hotplug/Linux: add iscsi block hotplug script"):

Quoted 3 lines

This hotplug script has been tested with IET and NetBSD iSCSI targets, without authentication.

Quoted 8 lines
Quoted 5 lines

Authentication parameters, including the password are passed as parameters to iscsiadm, which is not recommended because other users of the system can see them. This parameters could also be set by editing a corresponding file directly, but the location of this file seems to be different depending on the distribution used.

Would it be possible for the user to specify the file that the password should be read from ?

AFAIK no, this is read from a system defined file, that can be different depending on the distro used. Maybe be could expand this script latter if needed, in order to be able to detect where this file resides and use that instead of passing the user/password in the command line.

Quoted 3 lines

Did you write this script from scratch ? (TBH I don't intend to review it in detail...)

I've found a previous version of iSCSI and Xen here:

http://backdrift.org/xen-block-iscsi-script-with-multipath-support

but I didn't use it, so yes.

Quoted 1 line

Why no set -e ?

Because some of the executed commands might fail, but that's expected (and shouldn't abort the execution) and we manually check for the return value of executed commands.

Quoted 2 lines

Ian.

#43 lore raw

Re: [PATCH v1 12/12] hotplug/Linux: add iscsi block hotplug script

Roger Pau Monne writes ("Re: [Xen-devel] [PATCH v1 12/12] hotplug/Linux: add iscsi block hotplug script"):

Quoted 8 lines · Ian Jackson
Quoted 2 lines

Would it be possible for the user to specify the file that the password should be read from ?

AFAIK no, this is read from a system defined file, that can be different depending on the distro used. Maybe be could expand this script latter if needed, in order to be able to detect where this file resides and use that instead of passing the user/password in the command line.

Right, fair enough.

Quoted 8 lines
Quoted 2 lines

Did you write this script from scratch ? (TBH I don't intend to review it in detail...)

I've found a previous version of iSCSI and Xen here:

http://backdrift.org/xen-block-iscsi-script-with-multipath-support

but I didn't use it, so yes.

Right.

Quoted 5 lines
Quoted 1 line

Why no set -e ?

Because some of the executed commands might fail, but that's expected (and shouldn't abort the execution) and we manually check for the return value of executed commands.

I would normally turn on set -e, and then deal explicitly with the commands that are expected to fail, with patterns like
set +e
command that might fail
rc=$?
set -e
or
command we don't care about ||:
or
if command
then ...

That avoids accidentally missing out error checking.

Ian.

#44 lore raw
In reply to Roger Pau Monne
Quoted 50 lines · Roger Pau Monne

This series implements a new hoplug calling convention for libxl.

The aim of this new convention is to reduce the blackout phase of migration when using complex hotplug scripts, like iSCSI or other kind of storage backends that might have a non trivial setup time.

There are some issues that I would like to discuss, the first one is the fact that pdev_path field in libxl_device_disk is no longuer used to store a physical path, since diskspec "target" can now contain "random" information to connect a block device. This is not a blocker for this series to be accepted, but I'm tempted to say that the easier way to solve this is to use a union for target and pdev_path, this way everything will work as expected, and semantics will be right.

The second issue is related to iSCSI and iscsiadm, specifically the way to set authentication parameters, which is done with command line parameters or editing files (which each distro seems to place in different locations). I will look into this to see if we can find a suitable solution.

Thanks for the comments, Roger.

Branch available in the git repository at:
git://xenbits.xen.org/people/royger/xen.git iscsi_v1

*Acked

Roger Pau Monne (12):
*libxl: libxl__prepare_ao_device should reset num_exec
libxl: remove double check in NetBSD hotplug
libxl: move libxl_device_action to idl
libxl: pack hotplug related variables
libxl: add new hotplug interface support to hotplug script callers
libxl: add support for different hotplug interfaces
libxl: add prepare/unprepare operations to the libxl public interface
libxl: add disk specific remove functions
xl: add support for new hotplug interface to block-attach/detach
libxl: add local attach support for new hotplug scripts
hotplug: document new hotplug interface
hotplug/Linux: add iscsi block hotplug script

 docs/misc/libxl-hotplug-interface.txt |  167 +++++++++++++++++
 tools/hotplug/Linux/Makefile          |    1 +
 tools/hotplug/Linux/block-iscsi       |  258 +++++++++++++++++++++++++
 tools/libxl/libxl.c                   |  332 +++++++++++++++++++++++++++++----
 tools/libxl/libxl.h                   |    8 +
 tools/libxl/libxl_bootloader.c        |    1 +
 tools/libxl/libxl_create.c            |   62 ++++++-
 tools/libxl/libxl_device.c            |  153 +++++++++++++---
 tools/libxl/libxl_internal.h          |   87 ++++++++-
Quoted 8 lines
 tools/libxl/libxl_linux.c             |   78 ++++++---
 tools/libxl/libxl_netbsd.c            |   10 +-
 tools/libxl/libxl_types.idl           |    1 +
 tools/libxl/libxl_types_internal.idl  |   10 +
 tools/libxl/xl_cmdimpl.c              |    5 +
 14 files changed, 1071 insertions(+), 102 deletions(-)
 create mode 100644 docs/misc/libxl-hotplug-interface.txt
 create mode 100644 tools/hotplug/Linux/block-iscsi

It has been some time since I've posted the series, should I rebase and resend them?

#45 lore raw

PATCH v2 1/1 libxl: new hotplug calling convention

This series implements a new hoplug calling convention for libxl.

The aim of this new convention is to reduce the blackout phase of migration when using complex hotplug scripts, like iSCSI or other kind of storage backends that might have a non trivial setup time.

Thanks for the comments, Roger.

Branch available in the git repository at:
git://xenbits.xen.org/people/royger/xen.git iscsi_v2

* Acked

Roger Pau Monne (7):
*libxl: group hotplug related variables
libxl: add new hotplug interface support to hotplug script callers
libxl: add support for hotplug interface v2 in domain creation/destroy
libxl: chain prepare and attach in libxl_device_disk_add
libxl: add disk specific remove functions
libxl: add local attach support for new hotplug scripts hotplug/Linux: add iscsi block hotplug script

 docs/misc/libxl-hotplug-interface.txt |  179 +++++++++++++++++++
 tools/hotplug/Linux/Makefile          |    1 +
 tools/hotplug/Linux/block-iscsi       |  278 ++++++++++++++++++++++++++++++
 tools/libxl/libxl.c                   |  302 ++++++++++++++++++++++++++++++---
 tools/libxl/libxl_bootloader.c        |    1 +
 tools/libxl/libxl_create.c            |   32 ++++-
 tools/libxl/libxl_device.c            |  221 +++++++++++++++++++++---
 tools/libxl/libxl_internal.h          |   83 +++++++++-
 tools/libxl/libxl_linux.c             |   71 ++++++---
 tools/libxl/libxl_netbsd.c            |    4 +-
 tools/libxl/libxl_types.idl           |    1 +
 tools/libxl/libxl_types_internal.idl  |    5 +
 12 files changed, 1106 insertions(+), 72 deletions(-)
 create mode 100644 docs/misc/libxl-hotplug-interface.txt
 create mode 100644 tools/hotplug/Linux/block-iscsi
#46 lore raw

PATCH v2 1/7 libxl: group hotplug related variables

Create a new struct to hold hotplug related variables that are scattered in libxl__ao_device. We will later expand the number of hotplug related variables, so it's best to have them grouped.

---
Changes since v1:
* s/packed/grouped in commit message

---
 tools/libxl/libxl_device.c   |    6 +++---
 tools/libxl/libxl_internal.h |   15 ++++++++++-----
 tools/libxl/libxl_linux.c    |   10 +++++-----
 tools/libxl/libxl_netbsd.c   |    4 ++--
 4 files changed, 20 insertions(+), 15 deletions(-)
tools/libxl/libxl_device.c +3 -3
index eeea9d9..044cac5 100644
@@ -409,7 +409,7 @@ void libxl__prepare_ao_device(libxl__ao *ao, libxl__ao_device *aodev)
     aodev->ao = ao;
     aodev->rc = 0;
     aodev->dev = NULL;
-    aodev->num_exec = 0;
+    aodev->hotplug.num_exec = 0;
     /* Initialize timer for QEMU Bodge and hotplug execution */
     libxl__ev_time_init(&aodev->timeout);
     aodev->active = 1;
@@ -892,7 +892,7 @@ 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->hotplug);
     switch (hotplug) {
     case 0:
         /* no hotplug script to execute */
@@ -994,7 +994,7 @@ static void device_hotplug_child_death_cb(libxl__egc *egc,
      * If no more executions are needed, device_hotplug will call
      * device_hotplug_done breaking the loop.
      */
-    aodev->num_exec++;
+    aodev->hotplug.num_exec++;
     device_hotplug(egc, aodev);
 
     return;
tools/libxl/libxl_internal.h +10 -5
index 8be086d..bc468a6 100644
@@ -1837,6 +1837,7 @@ _hidden const char *libxl__run_dir_path(void);
 
 typedef struct libxl__ao_device libxl__ao_device;
 typedef struct libxl__multidev libxl__multidev;
+typedef struct libxl__hotplug libxl__hotplug;
 typedef void libxl__device_callback(libxl__egc*, libxl__ao_device*);
 
 /* This functions sets the necessary libxl__ao_device struct values to use
@@ -1855,6 +1856,10 @@ typedef void libxl__device_callback(libxl__egc*, libxl__ao_device*);
  */
 _hidden void libxl__prepare_ao_device(libxl__ao *ao, libxl__ao_device *aodev);
 
+struct libxl__hotplug {
+    int num_exec;
+};
+
 struct libxl__ao_device {
     /* filled in by user */
     libxl__ao *ao;
@@ -1873,7 +1878,7 @@ struct libxl__ao_device {
     libxl__ev_time timeout;
     /* device hotplug execution */
     const char *what;
-    int num_exec;
+    libxl__hotplug hotplug;
     libxl__ev_child child;
 };
 
@@ -2054,18 +2059,18 @@ _hidden void libxl__initiate_device_remove(libxl__egc *egc,
  * 0: No need to execute hotplug script
  * 1: Execute hotplug script
  *
- * The last parameter, "num_exec" refeers to the number of times hotplug
- * scripts have been called for this device.
+ * The last parameter, libxl__hotplug contains information related to hotplug
+ * execution.
  *
  * The main body of libxl will, for each device, keep calling
  * libxl__get_hotplug_script_info, with incrementing values of
- * num_exec, and executing the resulting script accordingly,
+ * hotplug->num_exec, and executing the resulting script accordingly,
  * until libxl__get_hotplug_script_info returns<=0.
  */
 _hidden int libxl__get_hotplug_script_info(libxl__gc *gc, libxl__device *dev,
                                            char ***args, char ***env,
                                            libxl__device_action action,
-                                           int num_exec);
+                                           libxl__hotplug *hotplug);
 
 /*----- local disk attach: attach a disk locally to run the bootloader -----*/
 
tools/libxl/libxl_linux.c +5 -5
index d34fbb3..d4ee58a 100644
@@ -227,7 +227,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)
+                                   libxl__hotplug *hotplug)
 {
     char *disable_udev = libxl__xs_read(gc, XBT_NULL, DISABLE_UDEV_PATH);
     int rc;
@@ -240,7 +240,7 @@ int libxl__get_hotplug_script_info(libxl__gc *gc, libxl__device *dev,
 
     switch (dev->backend_kind) {
     case LIBXL__DEVICE_KIND_VBD:
-        if (num_exec != 0) {
+        if (hotplug->num_exec != 0) {
             rc = 0;
             goto out;
         }
@@ -251,12 +251,12 @@ int libxl__get_hotplug_script_info(libxl__gc *gc, libxl__device *dev,
          * If domain has a stubdom we don't have to execute hotplug scripts
          * for emulated interfaces
          */
-        if ((num_exec > 1) ||
-            (libxl_get_stubdom_id(CTX, dev->domid) && num_exec)) {
+        if ((hotplug->num_exec > 1) ||
+            (libxl_get_stubdom_id(CTX, dev->domid) && hotplug->num_exec)) {
             rc = 0;
             goto out;
         }
-        rc = libxl__hotplug_nic(gc, dev, args, env, action, num_exec);
+        rc = libxl__hotplug_nic(gc, dev, args, env, action, hotplug->num_exec);
         break;
     default:
         /* No need to execute any hotplug scripts */
tools/libxl/libxl_netbsd.c +2 -2
index 898e160..48c87eb 100644
@@ -62,13 +62,13 @@ out:
 int libxl__get_hotplug_script_info(libxl__gc *gc, libxl__device *dev,
                                    char ***args, char ***env,
                                    libxl__device_action action,
-                                   int num_exec)
+                                   libxl__hotplug *hotplug)
 {
     char *disable_udev = libxl__xs_read(gc, XBT_NULL, DISABLE_UDEV_PATH);
     int rc;
 
     /* Check if we have to run hotplug scripts */
-    if (!disable_udev || num_exec > 0) {
+    if (!disable_udev || hotplug->num_exec > 0) {
         rc = 0;
         goto out;
     }
Signature · 7 lines
1.7.7.5 (Apple Git-26)


_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xen.org/xen-devel
#47 lore raw

PATCH v2 2/7 libxl: add new hotplug interface support to hotplug script callers

In reply to Roger Pau Monne

Add support to call hotplug scripts that use the new hotplug interface to the low-level functions in charge of calling hotplug scripts.

libxl__prepare_ao_device sets the hotplug version to 1, in later patches hotplug version will be set to 2 by the caller to use this new hotplug calling convention.

Also add a document describing the new interface.

Cc Ian Campbell <[email protected]>
Cc Ian Jackson <[email protected]>
---
 docs/misc/libxl-hotplug-interface.txt |  179 +++++++++++++++++++++++++++++++++
 tools/libxl/libxl_device.c            |   16 +++-
 tools/libxl/libxl_internal.h          |   20 ++++
 tools/libxl/libxl_linux.c             |   61 +++++++++---
 tools/libxl/libxl_types_internal.idl  |    5 +
 5 files changed, 265 insertions(+), 16 deletions(-)
 create mode 100644 docs/misc/libxl-hotplug-interface.txt
docs/misc/libxl-hotplug-interface.txt new file +179 -0
new file mode 100644
index 0000000..357f42d
@@ -0,0 +1,179 @@
+                     -----------------------
+                     LIBXL HOTPLUG INTERFACE
+                     -----------------------
+
+This document specifies the new libxl hotplug interface. This new
+interface has been designed to operate better with complex hotplug
+scripts, that need to perform several operations and can take a
+considerable time to execute.
+
+Hotplug scripts are expected to take a parameter, passed by the caller
+and provide a block device as output, that will be attached to the guest.
+
+
+
+=====================
+ENVIRONMENT VARIABLES
+=====================
+
+
+The following environment variables will be set before calling
+the hotplug script.
+
+The hotplug script will have write permissions on this xenstore paths.
+
+
+HOTPLUG_PATH
+------------
+
+Points to the xenstore directory that holds information relative
+to this hotplug script. At present only one parameter is passed by
+the toolstack, the "params" xenstore entry which contains the "target"
+line specified in the diskspec xl disk configuration (pdev_path in
+libxl_device_disk struct).
+
+This xenstore directory will be used to communicate between the
+hotplug script and the toolstack, and it can also be used by the
+hotplug script to store temporary information. This directory is created
+before calling the "prepare" operation, and the toolstack guarantees
+that it will not be removed before the "unprepare" operation has been
+finished. After that, the toolstack will take the appropriate actions
+to remove it. The toolstack guarantees that HOTPLUG_PATH will always
+point to a valid xenstore path for all operations.
+
+The path of this directory follows the syntax:
+
+/local/domain/<local_domid>/libxl/hotplug/vbd/<guest_domid>/<device_id>
+
+(Note that there is no end slash appended to HOTPLUG_PATH)
+
+The hotplug script should take special care in not storing arbitrary
+values in the following entries:
+
+HOTPLUG_PATH/version
+HOTPLUG_PATH/pdev
+
+This are used for communication between the hotplug script and the
+toolstack, and should only be written to when the parameter passed
+to the hotplug script requires it.
+
+
+BACKEND_PATH
+------------
+
+Points to the xenstore backend path of the corresponding block device.
+Since hotplug scripts are always executed in the Domain that acts as
+backend for a device, it will always have the following syntax:
+
+/local/domain/<local_domain>/backend/vbd/<guest_domid>/<device_id>
+
+(Note that there is no end slash appended to BACKEND_PATH)
+
+This environment variable is not set for all operations, since some
+hotplug operations are executed before the backend xenstore is set up.
+
+
+
+=======================
+COMMAND LINE PARAMETERS
+=======================
+
+
+Script will be called with only one parameter, that is either prepare,
+add, remove, unprepare, localattach or localdetach.
+
+VERSION
+-------
+
+Operation used to request the version this hotplug script supports. Failure
+to perform this operation will result in hotplug script detected as version 1.
+
+BACKEND_PATH: not valid
+
+Expected output:
+HOTPLGU_PATH/version = version supported by the hotplug script
+
+
+PREPARE
+-------
+
+This is the first operation that the hotplug script will be requested to
+execute. This operation is executed before the disk is connected, to
+give the hotplug script the chance to offload some work from the "add"
+operation, that is performed later.
+
+BACKEND_PATH: not valid
+
+Expected output:
+None
+
+
+ADD
+---
+
+This operation should connect the device to the domain. Will only be called
+after the "prepare" operation has finished successfully.
+
+BACKEND_PATH: valid
+
+Expected output:
+BACKEND_PATH/physical-device = block device major:minor
+BACKEND_PATH/params = block device path
+HOTPLUG_PATH/pdev = block device path
+
+
+REMOVE
+------
+
+
+Disconnects a block device from a domain. Will only be called
+after the "prepare" operation has finished successfully. Implementations
+should take into account that the "remove" operation will also be called if
+the "add" operation has failed.
+
+BACKEND_PATH: valid
+
+Expected output:
+None
+
+
+LOCALATTACH
+-----------
+
+
+Creates a block device in the current domain that points to the guest
+disk device. Will only be called after the "prepare" operation has
+finished successfully.
+
+BACKEND_PATH: not valid
+
+Expected output:
+HOTPLUG_PATH/pdev = block device path
+
+
+LOCALDETACH
+-----------
+
+
+Disconnects a device (previously connected with the localattach
+operation) from the current domain. Will only be called after
+the "prepare" operation has finished successfully. Implementations
+should take into account that the "localdetach" operation will
+also be called if the "localattach" operation has failed.
+
+BACKEND_PATH: not valid
+
+Expected output:
+None
+
+
+UNPREPARE
+---------
+
+
+Performs the necessary actions to unprepare the device.
+
+BACKEND_PATH: not valid
+
+Expected output:
+None
tools/libxl/libxl_device.c +15 -1
index 044cac5..024bc1f 100644
@@ -83,6 +83,14 @@ out:
     return rc;
 }
 
+char *libxl__device_xs_hotplug_path(libxl__gc *gc, libxl__device *dev)
+{
+    return GCSPRINTF("/local/domain/%u/libxl/hotplug/%u/%s/%u",
+                     dev->backend_domid, dev->domid,
+                     libxl__device_kind_to_string(dev->backend_kind),
+                     dev->devid);
+}
+
 int libxl__device_generic_add(libxl__gc *gc, xs_transaction_t t,
         libxl__device *device, char **bents, char **fents)
 {
@@ -410,6 +418,7 @@ void libxl__prepare_ao_device(libxl__ao *ao, libxl__ao_device *aodev)
     aodev->rc = 0;
     aodev->dev = NULL;
     aodev->hotplug.num_exec = 0;
+    aodev->hotplug.version = 1;
     /* Initialize timer for QEMU Bodge and hotplug execution */
     libxl__ev_time_init(&aodev->timeout);
     aodev->active = 1;
@@ -974,7 +983,12 @@ static void device_hotplug_child_death_cb(libxl__egc *egc,
 
     device_hotplug_clean(gc, aodev);
 
-    if (status) {
+    if (status && aodev->action != LIBXL__DEVICE_ACTION_VERSION) {
+        /* If a hotplug script returns an error when called
+         * with the "version" argument it means it is using the old
+         * hotplug calling convention, and we don't have to print
+         * an error message.
+         */
         libxl_report_child_exitstatus(CTX, LIBXL__LOG_ERROR,
                                       aodev->what, pid, status);
         hotplug_error = libxl__xs_read(gc, XBT_NULL,
tools/libxl/libxl_internal.h +20 -0
index bc468a6..fe0b20d 100644
@@ -1853,11 +1853,20 @@ 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 2, the new hotplug script calling convention
+ * will be used to call the hotplug script. This new convention provides
+ * new actions to hotplug scripts, "prepare", "unprepare", "localattach",
+ * "localdetach" and "version". 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);
 
 struct libxl__hotplug {
     int num_exec;
+    int version;
 };
 
 struct libxl__ao_device {
@@ -1867,6 +1876,8 @@ struct libxl__ao_device {
     libxl__device *dev;
     int force;
     libxl__device_callback *callback;
+    /* used by the VERISON and LOCALATTACH actions, set by caller */
+    libxl_device_disk *disk;
     /* return value, zeroed by user on entry, is valid on callback */
     int rc;
     /* private for multidev */
@@ -2050,6 +2061,15 @@ _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 hotplug scripts v2.
+ */
+_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.
  *
tools/libxl/libxl_linux.c +46 -15

85 lines not on this page · raw message

tools/libxl/libxl_types_internal.idl +5 -0
index cb9444f..253bb18 100644
@@ -37,4 +37,9 @@ libxl__device_console = Struct("device_console", [
 libxl__device_action = Enumeration("device_action", [
     (1, "ADD"),
     (2, "REMOVE"),
+    (3, "PREPARE"),
+    (4, "UNPREPARE"),
+    (5, "LOCALATTACH"),
+    (6, "LOCALDETACH"),
+    (7, "VERSION"),
     ])
Signature · 7 lines
1.7.7.5 (Apple Git-26)


_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xen.org/xen-devel
#48 lore raw

Re: [PATCH v2 2/7] libxl: add new hotplug interface support to hotplug script callers

Roger Pau Monne writes ("[Xen-devel] [PATCH v2 2/7] libxl: add new hotplug interface support to hotplug script callers"):

docs/misc/libxl-hotplug-interface.txt line 54

Quoted 5 lines
docs/misc/libxl-hotplug-interface.txt new file +5 -0
+The hotplug script should take special care in not storing arbitrary
+values in the following entries:
+
+HOTPLUG_PATH/version
+HOTPLUG_PATH/pdev

Do we want to allow any scope for introducing new toolstack-reserved entries later ?

"... take special care not to store ..." would be correct grammar.

Thanks,
Ian.

#49 lore raw

Re: [PATCH v2 2/7] libxl: add new hotplug interface support to hotplug script callers

Quoted 9 lines · Ian Jackson

Roger Pau Monne writes ("[Xen-devel] [PATCH v2 2/7] libxl: add new hotplug interface support to hotplug script callers"):

docs/misc/libxl-hotplug-interface.txt line 54

Quoted 5 lines
docs/misc/libxl-hotplug-interface.txt new file +5 -0
+The hotplug script should take special care in not storing arbitrary
+values in the following entries:
+
+HOTPLUG_PATH/version
+HOTPLUG_PATH/pdev

Do we want to allow any scope for introducing new toolstack-reserved entries later ?

Would you agree to say that the script is not able to use entries beginning with libxl_*, so we can reserve that for later use?

Also, if you could take a look at the rest of the series, I would like to try to respin the series before the end of the week.

Quoted 5 lines

"... take special care not to store ..." would be correct grammar.

Thanks,
Ian.

#50 lore raw

Re: [PATCH v2 2/7] libxl: add new hotplug interface support to hotplug script callers

Quoted 11 lines · Roger Pau Monne
Quoted 9 lines · Ian Jackson

Roger Pau Monne writes ("[Xen-devel] [PATCH v2 2/7] libxl: add new hotplug interface support to hotplug script callers"):

docs/misc/libxl-hotplug-interface.txt line 54

Quoted 5 lines
docs/misc/libxl-hotplug-interface.txt new file +5 -0
+The hotplug script should take special care in not storing arbitrary
+values in the following entries:
+
+HOTPLUG_PATH/version
+HOTPLUG_PATH/pdev

Do we want to allow any scope for introducing new toolstack-reserved entries later ?

Quoted 2 lines

Would you agree to say that the script is not able to use entries beginning with libxl_*, so we can reserve that for later use?

Doesn't the toolstack have its own prefix, under which it could duplicate HOTPLUG_PATH if it wanted?

Or maybe there is more benefit to having all the hotplug info about a device in the same place to having things be nicely separated?

Quoted 10 lines

Also, if you could take a look at the rest of the series, I would like to try to respin the series before the end of the week.

Quoted 5 lines

"... take special care not to store ..." would be correct grammar.

Thanks,
Ian.

#51 lore raw

Re: [PATCH v2 2/7] libxl: add new hotplug interface support to hotplug script callers

Quoted 12 lines · Ian Campbell
Quoted 11 lines · Roger Pau Monne
Quoted 9 lines · Ian Jackson

Roger Pau Monne writes ("[Xen-devel] [PATCH v2 2/7] libxl: add new hotplug interface support to hotplug script callers"):

docs/misc/libxl-hotplug-interface.txt line 54

Quoted 5 lines
docs/misc/libxl-hotplug-interface.txt new file +5 -0
+The hotplug script should take special care in not storing arbitrary
+values in the following entries:
+
+HOTPLUG_PATH/version
+HOTPLUG_PATH/pdev

Do we want to allow any scope for introducing new toolstack-reserved entries later ?

Quoted 8 lines
Quoted 2 lines

Would you agree to say that the script is not able to use entries beginning with libxl_*, so we can reserve that for later use?

Doesn't the toolstack have its own prefix, under which it could duplicate HOTPLUG_PATH if it wanted?

Or maybe there is more benefit to having all the hotplug info about a device in the same place to having things be nicely separated?

One solution would be to say that the hotplug script can only write to the following entries:

HOTPLUG_PATH/version
HOTPLUG_PATH/pdev

And then provide the script with another path that could be used to store whatever private entries the hotplug script needs:

PRIVATE_PATH

This would solve the problem of adding new toolstack-reserved entries later in HOTPLUG_PATH.

The private path could for example be:

/local/domain/<local_domid>/libxl/private/vbd/<guest_domid>/<device_id>

Which is basically the same as HOTPLUG_PATH replacing "hotplug" with "private".

Quoted 12 lines
Quoted 10 lines

Also, if you could take a look at the rest of the series, I would like to try to respin the series before the end of the week.

Quoted 5 lines

"... take special care not to store ..." would be correct grammar.

Thanks,
Ian.

#52 lore raw

Re: [PATCH v2 2/7] libxl: add new hotplug interface support to hotplug script callers

In reply to Roger Pau Monné

Roger Pau Monne writes ("Re: [Xen-devel] [PATCH v2 2/7] libxl: add new hotplug interface support to hotplug script callers"):

Quoted 6 lines · Ian Jackson
Quoted 2 lines

Do we want to allow any scope for introducing new toolstack-reserved entries later ?

Would you agree to say that the script is not able to use entries beginning with libxl_*, so we can reserve that for later use?

Yes.

Quoted 2 lines

Also, if you could take a look at the rest of the series, I would like to try to respin the series before the end of the week.

OK.

Ian.

#53 lore raw

Re: [PATCH v2 2/7] libxl: add new hotplug interface support to hotplug script callers

In reply to Roger Pau Monne

Roger Pau Monne writes ("[Xen-devel] [PATCH v2 2/7] libxl: add new hotplug interface support to hotplug script callers"):

Quoted 5 lines
docs/misc/libxl-hotplug-interface.txt new file +5 -0
+This document specifies the new libxl hotplug interface. This new
+interface has been designed to operate better with complex hotplug
+scripts, that need to perform several operations and can take a
+considerable time to execute.
+

docs/misc/libxl-hotplug-interface.txt

Quoted 10 lines
docs/misc/libxl-hotplug-interface.txt new file +9 -0
+Hotplug scripts are expected to take a parameter, passed by the caller
+and provide a block device as output, that will be attached to the guest.
 
+PREPARE
+-------
+
+This is the first operation that the hotplug script will be requested to
+execute. This operation is executed before the disk is connected, to
+give the hotplug script the chance to offload some work from the "add"
+operation, that is performed later.

But in fact in your implementation this is only called right before add, isn't it ?

Also, IIRC part of the point of this new interface is that for target devices which can't be accessed simultaneously from different hosts, during migration you'd be able to do costly setup during the initial part of the migration and merely "activate" the devices later.

Am I missing something ?

Thanks,
Ian.

#54 lore raw

Re: [PATCH v2 2/7] libxl: add new hotplug interface support to hotplug script callers

Quoted 9 lines · Ian Jackson

Roger Pau Monne writes ("[Xen-devel] [PATCH v2 2/7] libxl: add new hotplug interface support to hotplug script callers"):

Quoted 7 lines
docs/misc/libxl-hotplug-interface.txt new file +7 -0
+This document specifies the new libxl hotplug interface. This new
+interface has been designed to operate better with complex hotplug
+scripts, that need to perform several operations and can take a
+considerable time to execute.
+
+Hotplug scripts are expected to take a parameter, passed by the caller
+and provide a block device as output, that will be attached to the guest.
Quoted 10 lines

docs/misc/libxl-hotplug-interface.txt line 103

Quoted 7 lines
docs/misc/libxl-hotplug-interface.txt new file +7 -0
+PREPARE
+-------
+
+This is the first operation that the hotplug script will be requested to
+execute. This operation is executed before the disk is connected, to
+give the hotplug script the chance to offload some work from the "add"
+operation, that is performed later.

But in fact in your implementation this is only called right before add, isn't it ?

It depends on the caller, for example if using libxl_device_disk_add, libxl will take care of calling prepare before add (so external API is not changed), on the other hand, when creating a new domain, the prepare functions will be called much before calling add, so we can prepare the device before the domain is paused when doing migration. If you take a look at patch 3/7, you will see that on domain create disks are prepared at initiate_domain_create.

Quoted 5 lines

Also, IIRC part of the point of this new interface is that for target devices which can't be accessed simultaneously from different hosts, during migration you'd be able to do costly setup during the initial part of the migration and merely "activate" the devices later.

Yes, that's right, prepare will be called while the domain is still running on the sender side, so we can offload as much work as possible to this phase.

Quoted 5 lines

Am I missing something ?

Thanks,
Ian.

#55 lore raw

Re: [PATCH v2 2/7] libxl: add new hotplug interface support to hotplug script callers [and 1 more messages]

In reply to Ian Jackson

Ian Jackson writes ("Re: [Xen-devel] [PATCH v2 2/7] libxl: add new hotplug interface support to hotplug script callers"):

Quoted 1 line

Roger Pau Monne writes ("[Xen-devel] [PATCH v2 2/7] libxl: add new hotplug interface support to hotplug script callers"):

...

Quoted 11 lines

docs/misc/libxl-hotplug-interface.txt line 103

Quoted 7 lines
docs/misc/libxl-hotplug-interface.txt new file +7 -0
+PREPARE
+-------
+
+This is the first operation that the hotplug script will be requested to
+execute. This operation is executed before the disk is connected, to
+give the hotplug script the chance to offload some work from the "add"
+operation, that is performed later.

But in fact in your implementation this is only called right before add, isn't it ?

Quoted 6 lines

Also, IIRC part of the point of this new interface is that for target devices which can't be accessed simultaneously from different hosts, during migration you'd be able to do costly setup during the initial part of the migration and merely "activate" the devices later.

Am I missing something ?

This question needs to be answered by the documentation, I think.

What are the guarantees that the hotplug scripts rely on ?

AFAICT what happens after your series is applied is that we always call prepare just before add, and unprepare just after remove (if I may neglect local attach for now). So I don't see why these new functions are necessary to your new scripts.

Ian.

#56 lore raw

Re: [PATCH v2 2/7] libxl: add new hotplug interface support to hotplug script callers [and 1 more messages]

Quoted 21 lines · Ian Jackson

Ian Jackson writes ("Re: [Xen-devel] [PATCH v2 2/7] libxl: add new hotplug interface support to hotplug script callers"):

Quoted 1 line

Roger Pau Monne writes ("[Xen-devel] [PATCH v2 2/7] libxl: add new hotplug interface support to hotplug script callers"):

...

Quoted 11 lines

docs/misc/libxl-hotplug-interface.txt line 103

Quoted 7 lines
docs/misc/libxl-hotplug-interface.txt new file +7 -0
+PREPARE
+-------
+
+This is the first operation that the hotplug script will be requested to
+execute. This operation is executed before the disk is connected, to
+give the hotplug script the chance to offload some work from the "add"
+operation, that is performed later.

But in fact in your implementation this is only called right before add, isn't it ?

Quoted 6 lines

Also, IIRC part of the point of this new interface is that for target devices which can't be accessed simultaneously from different hosts, during migration you'd be able to do costly setup during the initial part of the migration and merely "activate" the devices later.

Am I missing something ?

Quoted 8 lines

This question needs to be answered by the documentation, I think.

What are the guarantees that the hotplug scripts rely on ?

AFAICT what happens after your series is applied is that we always call prepare just before add, and unprepare just after remove (if I may neglect local attach for now). So I don't see why these new functions are necessary to your new scripts.

Do you mean that both prepare and add are called after the domain on the sender side is paused?

Disks are prepared on "initiate_domain_create", which is the first function that gets called on domain creation, on the other hand they are added much later.

#57 lore raw

Re: [PATCH v2 2/7] libxl: add new hotplug interface support to hotplug script callers [and 1 more messages]

Roger Pau Monné writes ("Re: [Xen-devel] [PATCH v2 2/7] libxl: add new hotplug interface support to hotplug script callers [and 1 more messages]"):

Quoted 8 lines · Ian Jackson
Quoted 4 lines

AFAICT what happens after your series is applied is that we always call prepare just before add, and unprepare just after remove (if I may neglect local attach for now). So I don't see why these new functions are necessary to your new scripts.

Do you mean that both prepare and add are called after the domain on the sender side is paused?

I don't know exactly what I mean :-).

Quoted 3 lines

Disks are prepared on "initiate_domain_create", which is the first function that gets called on domain creation, on the other hand they are added much later.

You can't write that in the documentation because it's in terms of the internal workings of libxl.

What is the purpose of the distinction between prepare and add ?

Ian.

#58 lore raw

Re: [PATCH v2 2/7] libxl: add new hotplug interface support to hotplug script callers [and 1 more messages]

Quoted 12 lines · Ian Jackson

Roger Pau Monné writes ("Re: [Xen-devel] [PATCH v2 2/7] libxl: add new hotplug interface support to hotplug script callers [and 1 more messages]"):

Quoted 8 lines · Ian Jackson
Quoted 4 lines

AFAICT what happens after your series is applied is that we always call prepare just before add, and unprepare just after remove (if I may neglect local attach for now). So I don't see why these new functions are necessary to your new scripts.

Do you mean that both prepare and add are called after the domain on the sender side is paused?

I don't know exactly what I mean :-).

Quoted 8 lines
Quoted 3 lines

Disks are prepared on "initiate_domain_create", which is the first function that gets called on domain creation, on the other hand they are added much later.

You can't write that in the documentation because it's in terms of the internal workings of libxl.

What is the purpose of the distinction between prepare and add ?

The main purpose of this distinction is that during migration the "prepare" action is called before the guest on the sender side is paused, so it allows to offload work from the "add" action, thus reducing the blackout phase during migration.

I guess you want me to add this to the Documentation?

Thanks, Roger.

#59 lore raw

PATCH v2 3/7 libxl: add support for hotplug interface v2 in domain creation/destroy

In reply to Roger Pau Monne

Add a new variable to libxl_device_disk "hotplug_version", that will be automatically set to the detected hotplug script interface version.

This patch adds the basic support to handle this new scripts, by adding the prepare private libxl function, and modifying the current domain creation/destruction to call this functions at the appropriate spots. The hotplug interface detection is done in the _prepare call.

This patch also adds some helpers, that will be used here and in later patches.

Cc Ian Campbell <[email protected]>
Cc Ian Jackson <[email protected]>

---
Changes since v1:
* Keep track of hotplug status in xenstore

---
 tools/libxl/libxl.c          |  144 ++++++++++++++++++++++++++++++-
 tools/libxl/libxl_create.c   |   32 +++++++-
 tools/libxl/libxl_device.c   |  199 +++++++++++++++++++++++++++++++++++++----
 tools/libxl/libxl_internal.h |   47 ++++++++++
 tools/libxl/libxl_types.idl  |    1 +
 5 files changed, 400 insertions(+), 23 deletions(-)
tools/libxl/libxl.c +142 -2
index a09c0fa..e6d4a98 100644
@@ -2011,6 +2011,119 @@ int libxl__device_from_disk(libxl__gc *gc, uint32_t domid,
     return 0;
 }
 
+/* Callbacks for libxl__device_disk_prepare */
+
+static void device_disk_prepare_cb(libxl__egc *, libxl__ao_device *);
+
+void libxl__device_disk_prepare(libxl__egc *egc, uint32_t domid,
+                                libxl_device_disk *disk,
+                                libxl__ao_device *prepare_aodev)
+{
+    STATE_AO_GC(prepare_aodev->ao);
+    char *hotplug_path;
+    char *script_path;
+    int rc;
+    xs_transaction_t t = XBT_NULL;
+    libxl__disk_prepare *dp;
+    libxl__ao_device *aodev;
+
+    if (!disk->script) {
+        /* If script is not set assume v1 */
+        disk->hotplug_version = 1;
+        prepare_aodev->callback(egc, prepare_aodev);
+        return;
+    }
+
+    GCNEW(dp);
+    dp->disk = disk;
+    /* Save original aodev, since we will call it once hotplug
+     * script detection has finished
+     */
+    dp->aodev = prepare_aodev;
+    aodev = &dp->version_aodev;
+    libxl__prepare_ao_device(ao, aodev);
+
+    GCNEW(aodev->dev);
+    rc = libxl__device_from_disk(gc, domid, disk, aodev->dev);
+    if (rc != 0) {
+        LOG(ERROR, "Invalid or unsupported virtual disk identifier %s",
+                   disk->vdev);
+        goto error;
+    }
+
+    script_path = libxl__abs_path(gc, disk->script,
+                                  libxl__xen_script_dir_path());
+
+    hotplug_path = libxl__device_xs_hotplug_path(gc, aodev->dev);
+    for (;;) {
+        rc = libxl__xs_transaction_start(gc, &t);
+        if (rc) goto error;
+
+        rc = libxl__xs_write_checked(gc, t,
+                                 GCSPRINTF("%s/params", hotplug_path),
+                                 disk->pdev_path);
+        if (rc)
+            goto error;
+
+        rc = libxl__xs_write_checked(gc, t,
+                                 GCSPRINTF("%s/script", hotplug_path),
+                                 script_path);
+        if (rc)
+            goto error;
+
+        rc = libxl__xs_transaction_commit(gc, &t);
+        if (!rc) break;
+        if (rc < 0) goto error;
+    }
+
+    aodev->callback = device_disk_prepare_cb;
+    aodev->action = LIBXL__DEVICE_ACTION_VERSION;
+    aodev->disk = disk;
+    aodev->hotplug.version = 2;
+    libxl__device_hotplug(egc, aodev);
+    return;
+
+error:
+    assert(rc);
+    libxl__xs_transaction_abort(gc, &t);
+    prepare_aodev->rc = rc;
+    prepare_aodev->callback(egc, prepare_aodev);
+    return;
+}
+
+static void device_disk_prepare_cb(libxl__egc *egc,
+                                   libxl__ao_device *version_aodev)
+{
+    STATE_AO_GC(version_aodev->ao);
+    libxl__disk_prepare *dp = CONTAINER_OF(version_aodev, *dp, version_aodev);
+    libxl__ao_device *aodev = dp->aodev;
+
+    if (dp->disk->hotplug_version == 1) {
+        aodev->callback(egc, aodev);
+        return;
+    }
+
+    aodev->action = LIBXL__DEVICE_ACTION_PREPARE;
+    aodev->hotplug.version = dp->disk->hotplug_version;
+    aodev->dev = version_aodev->dev;
+
+    /*
+     * Write status information to xenstore, so we know this device
+     * has been prepared
+     */
+    aodev->rc = libxl__xs_write_checked(gc, XBT_NULL,
+                    GCSPRINTF("%s/backend_domid",
+                        libxl__device_xs_hotplug_status_path(gc, aodev->dev)),
+                    GCSPRINTF("%u", aodev->dev->backend_domid));
+    if (aodev->rc) {
+        aodev->callback(egc, aodev);
+        return;
+    }
+
+    libxl__device_hotplug(egc, aodev);
+    return;
+}
+
 /* Specific function called directly only by local disk attach,
  * all other users should instead use the regular
  * libxl__device_disk_add wrapper
@@ -2070,8 +2183,15 @@ static void device_disk_add(libxl__egc *egc, uint32_t domid,
                 dev = disk->pdev_path;
 
         do_backend_phy:
-                flexarray_append(back, "params");
-                flexarray_append(back, dev);
+                if (disk->hotplug_version == 1) {
+                    /*
+                     * If the new hotplug version is used params is
+                     * stored under a private path, since it can contain
+                     * data that the guest should not see.
+                     */
+                    flexarray_append(back, "params");
+                    flexarray_append(back, dev);
+                }
 
                 script = libxl__abs_path(gc, disk->script?: "block",
                                          libxl__xen_script_dir_path());
@@ -2167,6 +2287,8 @@ static void device_disk_add(libxl__egc *egc, uint32_t domid,
 
     aodev->dev = device;
     aodev->action = LIBXL__DEVICE_ACTION_ADD;
+    aodev->hotplug.version = disk->hotplug_version;
+    aodev->disk = disk;
     libxl__wait_device_connection(egc, aodev);
 
     rc = 0;
@@ -2260,6 +2382,7 @@ int libxl_vdev_to_device_disk(libxl_ctx *ctx, uint32_t domid,
     GC_INIT(ctx);
     char *dompath, *path;
     int devid = libxl__device_disk_dev_number(vdev, NULL, NULL);
+    libxl__device dev;
     int rc = ERROR_FAIL;
 
     if (devid < 0)
@@ -2278,6 +2401,23 @@ int libxl_vdev_to_device_disk(libxl_ctx *ctx, uint32_t domid,
         goto out;
 
     rc = libxl__device_disk_from_xs_be(gc, path, disk);
+    if (rc) {
+        LOG(ERROR, "unable to parse disk device from path %s", path);
+        goto out;
+    }
+
+    /* Check if the device is using the new hotplug interface */
+    rc = libxl__device_from_disk(gc, domid, disk, &dev);
+    if (rc) {
+        LOG(ERROR, "invalid or unsupported virtual disk identifier %s",
+                    disk->vdev);
+        goto out;
+    }
+    disk->hotplug_version = 1;
+    path = libxl__device_xs_hotplug_path(gc, &dev);
+    if (libxl__xs_read(gc, XBT_NULL, path))
+        disk->hotplug_version = 2;
+
 out:
     GC_FREE;
     return rc;
tools/libxl/libxl_create.c +31 -1
index 2ea628a..ad5f8c4 100644
@@ -592,6 +592,10 @@ static int store_libxl_entry(libxl__gc *gc, uint32_t domid,
  */
 
 /* Event callbacks, in this order: */
+
+static void domcreate_launch_bootloader(libxl__egc *egc,
+                                        libxl__multidev *multidev,
+                                        int ret);
 static void domcreate_devmodel_started(libxl__egc *egc,
                                        libxl__dm_spawn_state *dmss,
                                        int rc);
@@ -638,7 +642,6 @@ static void initiate_domain_create(libxl__egc *egc,
 
     /* convenience aliases */
     libxl_domain_config *const d_config = dcs->guest_config;
-    const int restore_fd = dcs->restore_fd;
     memset(&dcs->build_state, 0, sizeof(dcs->build_state));
 
     domid = 0;
@@ -671,6 +674,33 @@ static void initiate_domain_create(libxl__egc *egc,
         if (ret) goto error_out;
     }
 
+    libxl__multidev_begin(ao, &dcs->multidev);
+    dcs->multidev.callback = domcreate_launch_bootloader;
+    libxl__prepare_disks(egc, ao, domid, d_config, &dcs->multidev);
+    libxl__multidev_prepared(egc, &dcs->multidev, 0);
+    return;
+
+error_out:
+    assert(ret);
+    domcreate_complete(egc, dcs, ret);
+}
+
+static void domcreate_launch_bootloader(libxl__egc *egc,
+                                        libxl__multidev *multidev,
+                                        int ret)
+{
+    libxl__domain_create_state *dcs = CONTAINER_OF(multidev, *dcs, multidev);
+    STATE_AO_GC(dcs->ao);
+
+    /* convenience aliases */
+    const int restore_fd = dcs->restore_fd;
+    libxl_domain_config *const d_config = dcs->guest_config;
+
+    if (ret) {
+        LOG(ERROR, "unable to prepare devices");
+        goto error_out;
+    }
+
     dcs->bl.ao = ao;
     libxl_device_disk *bootdisk =
         d_config->num_disks > 0 ? &d_config->disks[0] : NULL;
tools/libxl/libxl_device.c +179 -20

326 lines not on this page · raw message

tools/libxl/libxl_internal.h +47 -0

71 lines not on this page · raw message

tools/libxl/libxl_types.idl +1 -0
index 5b080ed..ac8361b 100644
@@ -370,6 +370,7 @@ libxl_device_disk = Struct("device_disk", [
     ("removable", integer),
     ("readwrite", integer),
     ("is_cdrom", integer),
+    ("hotplug_version", integer),
     ])
 
 libxl_device_nic = Struct("device_nic", [
Signature · 7 lines
1.7.7.5 (Apple Git-26)


_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xen.org/xen-devel
#60 lore raw

PATCH v2 4/7 libxl: chain prepare and attach in libxl_device_disk_add

In reply to Roger Pau Monne

Chaining the prepare and attach functions in the public libxl_device_disk_add allows libxl to keep the same public API while allowing hotplug scripts v2 to be used.

libxl takes care of detecting the hotplug version of the script and executing the necessary actions.

Cc Ian Campbell <[email protected]>
Cc Ian Jackson <[email protected]>

---
Changes since v1:
* Remove public _prepare/_unprepare functions and do all the logic inside libxl_device_disk_add, this prevents an API change.

---
 tools/libxl/libxl.c |   37 +++++++++++++++++++++++++++++++++----
 1 files changed, 33 insertions(+), 4 deletions(-)
tools/libxl/libxl.c +33 -4
index e6d4a98..b15cb96 100644
@@ -2306,6 +2306,39 @@ void libxl__device_disk_add(libxl__egc *egc, uint32_t domid,
     device_disk_add(egc, domid, disk, aodev, NULL, NULL);
 }
 
+/* Callbacks for device_disk_add */
+
+static void device_disk_add_prepared(libxl__egc *, libxl__ao_device *);
+
+int libxl_device_disk_add(libxl_ctx *ctx, uint32_t domid,
+                          libxl_device_disk *disk,
+                          const libxl_asyncop_how *ao_how)
+{
+    AO_CREATE(ctx, domid, ao_how);
+    libxl__ao_device *aodev;
+
+    GCNEW(aodev);
+    libxl__prepare_ao_device(ao, aodev);
+    aodev->callback = device_disk_add_prepared;
+    aodev->disk = disk;
+    libxl__device_disk_prepare(egc, domid, disk, aodev);
+
+    return AO_INPROGRESS;
+}
+
+static void device_disk_add_prepared(libxl__egc *egc, libxl__ao_device *aodev)
+{
+    if (aodev->rc) {
+        device_addrm_aocomplete(egc, aodev);
+        return;
+    }
+
+    aodev->hotplug.num_exec = 0;
+    aodev->callback = device_addrm_aocomplete;
+    libxl__device_disk_add(egc, aodev->dev->domid, aodev->disk, aodev);
+    return;
+}
+
 static int libxl__device_disk_from_xs_be(libxl__gc *gc,
                                          const char *be_path,
                                          libxl_device_disk *disk)
@@ -3553,7 +3586,6 @@ DEFINE_DEVICE_REMOVE(vtpm, destroy, 1)
 
 /* Macro for defining device addition functions in a compact way */
 /* The following functions are defined:
- * libxl_device_disk_add
  * libxl_device_nic_add
  * libxl_device_vtpm_add
  */
@@ -3576,9 +3608,6 @@ DEFINE_DEVICE_REMOVE(vtpm, destroy, 1)
 
 /* Define alladd functions and undef the macro */
 
-/* disk */
-DEFINE_DEVICE_ADD(disk)
-
 /* nic */
 DEFINE_DEVICE_ADD(nic)
 
Signature · 7 lines
1.7.7.5 (Apple Git-26)


_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xen.org/xen-devel
#61 lore raw

PATCH v2 5/7 libxl: add disk specific remove functions

In reply to Roger Pau Monne

Add a specific macro to generate libxl_device_disk_{remove/destroy} functions that passes the hotplug_version field down to the aodev struct.

Cc Ian Campbell <[email protected]>
Cc Ian Jackson <[email protected]>
---
 tools/libxl/libxl.c |   35 +++++++++++++++++++++++++++++++++--
 1 files changed, 33 insertions(+), 2 deletions(-)
tools/libxl/libxl.c +33 -2
index b15cb96..987723b 100644
@@ -3557,11 +3557,41 @@ out:
         return AO_INPROGRESS;                                           \
     }
 
+/* Specific for disk devices, that have to set aodev->hotplug_version */
+#define DEFINE_DISK_REMOVE(type, removedestroy, f)                      \
+    int libxl_device_##type##_##removedestroy(libxl_ctx *ctx,           \
+        uint32_t domid, libxl_device_##type *type,                      \
+        const libxl_asyncop_how *ao_how)                                \
+    {                                                                   \
+        AO_CREATE(ctx, domid, ao_how);                                  \
+        libxl__device *device;                                          \
+        libxl__ao_device *aodev;                                        \
+        int rc;                                                         \
+                                                                        \
+        GCNEW(device);                                                  \
+        rc = libxl__device_from_##type(gc, domid, type, device);        \
+        if (rc != 0) goto out;                                          \
+                                                                        \
+        GCNEW(aodev);                                                   \
+        libxl__prepare_ao_device(ao, aodev);                            \
+        aodev->action = LIBXL__DEVICE_ACTION_REMOVE;                    \
+        aodev->dev = device;                                            \
+        aodev->callback = device_addrm_aocomplete;                      \
+        aodev->force = f;                                               \
+        aodev->hotplug.version = type->hotplug_version;                 \
+        LOG(DEBUG, "hotplug version: %d", aodev->hotplug.version);      \
+        libxl__initiate_device_remove(egc, aodev);                      \
+                                                                        \
+    out:                                                                \
+        if (rc) return AO_ABORT(rc);                                    \
+        return AO_INPROGRESS;                                           \
+    }
+
 /* Define all remove/destroy functions and undef the macro */
 
 /* disk */
-DEFINE_DEVICE_REMOVE(disk, remove, 0)
-DEFINE_DEVICE_REMOVE(disk, destroy, 1)
+DEFINE_DISK_REMOVE(disk, remove, 0)
+DEFINE_DISK_REMOVE(disk, destroy, 1)
 
 /* nic */
 DEFINE_DEVICE_REMOVE(nic, remove, 0)
@@ -3580,6 +3610,7 @@ DEFINE_DEVICE_REMOVE(vfb, destroy, 1)
 DEFINE_DEVICE_REMOVE(vtpm, remove, 0)
 DEFINE_DEVICE_REMOVE(vtpm, destroy, 1)
 
+#undef DEFINE_DISK_REMOVE
 #undef DEFINE_DEVICE_REMOVE
 
 /******************************************************************************/
Signature · 7 lines
1.7.7.5 (Apple Git-26)


_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xen.org/xen-devel
#62 lore raw

PATCH v2 6/7 libxl: add local attach support for new hotplug scripts

In reply to Roger Pau Monne

Adds support for locally attaching disks that use the new hotplug script interface, by calling the localattach/localdetach operations and returning a block device that can be used to execute pygrub.

Cc Ian Campbell <[email protected]>
Cc Ian Jackson <[email protected]>
---
 tools/libxl/libxl.c            |   86 ++++++++++++++++++++++++++++++++++------
 tools/libxl/libxl_bootloader.c |    1 +
 tools/libxl/libxl_internal.h   |    1 +
 3 files changed, 76 insertions(+), 12 deletions(-)
tools/libxl/libxl.c +74 -12
index 987723b..9d0d15a 100644
@@ -2718,6 +2718,7 @@ void libxl__device_disk_local_initiate_attach(libxl__egc *egc,
     const libxl_device_disk *in_disk = dls->in_disk;
     libxl_device_disk *disk = &dls->disk;
     const char *blkdev_start = dls->blkdev_start;
+    uint32_t domid = dls->domid;
 
     assert(in_disk->pdev_path);
 
@@ -2734,6 +2735,23 @@ void libxl__device_disk_local_initiate_attach(libxl__egc *egc,
         case LIBXL_DISK_BACKEND_PHY:
             LIBXL__LOG(ctx, LIBXL__LOG_DEBUG, "locally attaching PHY disk %s",
                        disk->pdev_path);
+            if (disk->hotplug_version == 2) {
+                disk->vdev = libxl__strdup(gc, in_disk->vdev);
+                libxl__prepare_ao_device(ao, &dls->aodev);
+                GCNEW(dls->aodev.dev);
+                rc = libxl__device_from_disk(gc, domid, disk,
+                                             dls->aodev.dev);
+                if (rc != 0) {
+                    LOG(ERROR, "Invalid or unsupported virtual disk "
+                               "identifier %s", disk->vdev);
+                    goto out;
+                }
+                dls->aodev.action = LIBXL__DEVICE_ACTION_LOCALATTACH;
+                dls->aodev.hotplug.version = disk->hotplug_version;
+                dls->aodev.callback = local_device_attach_cb;
+                libxl__device_hotplug(egc, &dls->aodev);
+                return;
+            }
             dev = disk->pdev_path;
             break;
         case LIBXL_DISK_BACKEND_TAP:
@@ -2796,7 +2814,8 @@ static void local_device_attach_cb(libxl__egc *egc, libxl__ao_device *aodev)
 {
     STATE_AO_GC(aodev->ao);
     libxl__disk_local_state *dls = CONTAINER_OF(aodev, *dls, aodev);
-    char *dev = NULL, *be_path = NULL;
+    char *dev = NULL, *be_path = NULL, *hotplug_path;
+    const char *pdev = NULL;
     int rc;
     libxl__device device;
     libxl_device_disk *disk = &dls->disk;
@@ -2809,20 +2828,45 @@ static void local_device_attach_cb(libxl__egc *egc, libxl__ao_device *aodev)
                     aodev->dev->devid);
         goto out;
     }
+    switch (disk->backend) {
+    case LIBXL_DISK_BACKEND_PHY:
+        /* Fetch hotplug output to obtain the block device */
+        rc = libxl__device_from_disk(gc, dls->domid, disk, &device);
+        if (rc)
+            goto out;
+        hotplug_path = libxl__device_xs_hotplug_path(gc, &device);
+        rc = libxl__xs_read_checked(gc, XBT_NULL,
+                                    GCSPRINTF("%s/pdev", hotplug_path),
+                                    &pdev);
+        if (rc)
+            goto out;
+        if (!pdev) {
+            rc = ERROR_FAIL;
+            goto out;
+        }
+        LOG(DEBUG, "attached local block device %s", pdev);
+        dls->diskpath = libxl__strdup(gc, pdev);
+        break;
+    case LIBXL_DISK_BACKEND_QDISK:
+        dev = GCSPRINTF("/dev/%s", disk->vdev);
+        LOG(DEBUG, "locally attaching qdisk %s", dev);
 
-    dev = GCSPRINTF("/dev/%s", disk->vdev);
-    LOG(DEBUG, "locally attaching qdisk %s", dev);
+        rc = libxl__device_from_disk(gc, LIBXL_TOOLSTACK_DOMID, disk, &device);
+        if (rc < 0)
+            goto out;
+        be_path = libxl__device_backend_path(gc, &device);
+        rc = libxl__wait_for_backend(gc, be_path, "4");
+        if (rc < 0)
+            goto out;
 
-    rc = libxl__device_from_disk(gc, LIBXL_TOOLSTACK_DOMID, disk, &device);
-    if (rc < 0)
-        goto out;
-    be_path = libxl__device_backend_path(gc, &device);
-    rc = libxl__wait_for_backend(gc, be_path, "4");
-    if (rc < 0)
+        if (dev != NULL)
+            dls->diskpath = libxl__strdup(gc, dev);
+        break;
+    default:
+        LOG(ERROR, "invalid disk backend for local attach callback");
+        rc = ERROR_FAIL;
         goto out;
-
-    if (dev != NULL)
-        dls->diskpath = libxl__strdup(gc, dev);
+    }
 
     dls->callback(egc, dls, 0);
     return;
@@ -2846,11 +2890,29 @@ void libxl__device_disk_local_initiate_detach(libxl__egc *egc,
     libxl_device_disk *disk = &dls->disk;
     libxl__device *device;
     libxl__ao_device *aodev = &dls->aodev;
+    uint32_t domid = dls->domid;
     libxl__prepare_ao_device(ao, aodev);
 
     if (!dls->diskpath) goto out;
 
     switch (disk->backend) {
+        case LIBXL_DISK_BACKEND_PHY:
+            if (disk->hotplug_version == 2) {
+                GCNEW(aodev->dev);
+                rc = libxl__device_from_disk(gc, domid, disk,
+                                             aodev->dev);
+                if (rc != 0) {
+                    LOG(ERROR, "Invalid or unsupported virtual disk "
+                               "identifier %s", disk->vdev);
+                    goto out;
+                }
+                aodev->action = LIBXL__DEVICE_ACTION_LOCALDETACH;
+                aodev->hotplug.version = disk->hotplug_version;
+                aodev->callback = local_device_detach_cb;
+                libxl__device_hotplug(egc, aodev);
+                return;
+            }
+            break;
         case LIBXL_DISK_BACKEND_QDISK:
             if (disk->vdev != NULL) {
                 GCNEW(device);
tools/libxl/libxl_bootloader.c +1 -0
index ed12b2c..5d889fe 100644
@@ -381,6 +381,7 @@ void libxl__bootloader_run(libxl__egc *egc, libxl__bootloader_state *bl)
     bl->dls.ao = ao;
     bl->dls.in_disk = bl->disk;
     bl->dls.blkdev_start = info->blkdev_start;
+    bl->dls.domid = domid;
     bl->dls.callback = bootloader_disk_attached_cb;
     libxl__device_disk_local_initiate_attach(egc, &bl->dls);
     return;
tools/libxl/libxl_internal.h +1 -0
index d957ed2..3228ab2 100644
@@ -2151,6 +2151,7 @@ struct libxl__disk_local_state {
     libxl_device_disk disk;
     const char *blkdev_start;
     libxl__disk_local_state_callback *callback;
+    uint32_t domid;
     /* filled by libxl__device_disk_local_initiate_attach */
     char *diskpath;
     /* private for implementation of local detach */
Signature · 7 lines
1.7.7.5 (Apple Git-26)


_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xen.org/xen-devel
#63 lore raw

PATCH v2 7/7 hotplug/Linux: add iscsi block hotplug script

In reply to Roger Pau Monne

This hotplug script has been tested with IET and NetBSD iSCSI targets, without authentication.

Authentication parameters, including the password are passed as parameters to iscsiadm, which is not recommended because other users of the system can see them. This parameters could also be set by editing a corresponding file directly, but the location of this file seems to be different depending on the distribution used.

Cc Ian Campbell <[email protected]>
Cc Ian Jackson <[email protected]>

---
Changes since v1:
* Add -e to script shebang, and use 'set +e' if we know hotplug execution might fail.

---
 tools/hotplug/Linux/Makefile    |    1 +
 tools/hotplug/Linux/block-iscsi |  278 +++++++++++++++++++++++++++++++++++++++
 2 files changed, 279 insertions(+), 0 deletions(-)
 create mode 100644 tools/hotplug/Linux/block-iscsi
tools/hotplug/Linux/Makefile +1 -0
index 0605559..98c7738 100644
@@ -21,6 +21,7 @@ XEN_SCRIPTS += blktap
 XEN_SCRIPTS += xen-hotplug-cleanup
 XEN_SCRIPTS += external-device-migrate
 XEN_SCRIPTS += vscsi
+XEN_SCRIPTS += block-iscsi
 XEN_SCRIPT_DATA = xen-script-common.sh locking.sh logging.sh
 XEN_SCRIPT_DATA += xen-hotplug-common.sh xen-network-common.sh vif-common.sh
 XEN_SCRIPT_DATA += block-common.sh
tools/hotplug/Linux/block-iscsi new file +278 -0

278 lines not on this page · raw message

Signature · 7 lines
1.7.7.5 (Apple Git-26)


_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xen.org/xen-devel
#64 lore raw

v3 cover libxl: new hotplug calling convention

This series implements a new hoplug calling convention for libxl.

The aim of this new convention is to reduce the blackout phase of migration when using complex hotplug scripts, like iSCSI or other kind of storage backends that might have a non trivial setup time.

Major changes from v2 are the addition of HOTPLUG_PATH/libxl_* to the list of reserved entries, and the rebase of the whole series on top of current xen-unstable commit.

Thanks for the comments, Roger.

Branch available in the git repository at:
git://xenbits.xen.org/people/royger/xen.git iscsi_v3

* Acked

Roger Pau Monne (7):
*libxl: group hotplug related variables
libxl: add new hotplug interface support to hotplug script callers
libxl: add support for hotplug interface v2 in domain creation/destroy
libxl: chain prepare and attach in libxl_device_disk_add
libxl: add disk specific remove functions
libxl: add local attach support for new hotplug scripts hotplug/Linux: add iscsi block hotplug script

 docs/misc/libxl-hotplug-interface.txt |  184 +++++++++++++++++++++
 tools/hotplug/Linux/Makefile          |    1 +
 tools/hotplug/Linux/block-iscsi       |  278 ++++++++++++++++++++++++++++++++
 tools/libxl/libxl.c                   |  286 ++++++++++++++++++++++++++++++---
 tools/libxl/libxl_bootloader.c        |    1 +
 tools/libxl/libxl_create.c            |   32 ++++-
 tools/libxl/libxl_device.c            |  221 +++++++++++++++++++++++---
 tools/libxl/libxl_internal.h          |   83 +++++++++-
 tools/libxl/libxl_linux.c             |   73 ++++++---
 tools/libxl/libxl_netbsd.c            |    4 +-
 tools/libxl/libxl_types.idl           |    1 +
 tools/libxl/libxl_types_internal.idl  |    5 +
 12 files changed, 1095 insertions(+), 74 deletions(-)
 create mode 100644 docs/misc/libxl-hotplug-interface.txt
 create mode 100644 tools/hotplug/Linux/block-iscsi
#65 lore raw

PATCH v3 1/7 libxl: group hotplug related variables

Create a new struct to hold hotplug related variables that are scattered in libxl__ao_device. We will later expand the number of hotplug related variables, so it's best to have them grouped.

---
Changes since v1:
* s/packed/grouped in commit message

---
 tools/libxl/libxl_device.c   |    6 +++---
 tools/libxl/libxl_internal.h |   15 ++++++++++-----
 tools/libxl/libxl_linux.c    |   10 +++++-----
 tools/libxl/libxl_netbsd.c   |    4 ++--
 4 files changed, 20 insertions(+), 15 deletions(-)
tools/libxl/libxl_device.c +3 -3
index eeea9d9..044cac5 100644
@@ -409,7 +409,7 @@ void libxl__prepare_ao_device(libxl__ao *ao, libxl__ao_device *aodev)
     aodev->ao = ao;
     aodev->rc = 0;
     aodev->dev = NULL;
-    aodev->num_exec = 0;
+    aodev->hotplug.num_exec = 0;
     /* Initialize timer for QEMU Bodge and hotplug execution */
     libxl__ev_time_init(&aodev->timeout);
     aodev->active = 1;
@@ -892,7 +892,7 @@ 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->hotplug);
     switch (hotplug) {
     case 0:
         /* no hotplug script to execute */
@@ -994,7 +994,7 @@ static void device_hotplug_child_death_cb(libxl__egc *egc,
      * If no more executions are needed, device_hotplug will call
      * device_hotplug_done breaking the loop.
      */
-    aodev->num_exec++;
+    aodev->hotplug.num_exec++;
     device_hotplug(egc, aodev);
 
     return;
tools/libxl/libxl_internal.h +10 -5
index 3ba3a21..8507ac3 100644
@@ -1838,6 +1838,7 @@ _hidden const char *libxl__run_dir_path(void);
 
 typedef struct libxl__ao_device libxl__ao_device;
 typedef struct libxl__multidev libxl__multidev;
+typedef struct libxl__hotplug libxl__hotplug;
 typedef void libxl__device_callback(libxl__egc*, libxl__ao_device*);
 
 /* This functions sets the necessary libxl__ao_device struct values to use
@@ -1856,6 +1857,10 @@ typedef void libxl__device_callback(libxl__egc*, libxl__ao_device*);
  */
 _hidden void libxl__prepare_ao_device(libxl__ao *ao, libxl__ao_device *aodev);
 
+struct libxl__hotplug {
+    int num_exec;
+};
+
 struct libxl__ao_device {
     /* filled in by user */
     libxl__ao *ao;
@@ -1874,7 +1879,7 @@ struct libxl__ao_device {
     libxl__ev_time timeout;
     /* device hotplug execution */
     const char *what;
-    int num_exec;
+    libxl__hotplug hotplug;
     libxl__ev_child child;
 };
 
@@ -2055,18 +2060,18 @@ _hidden void libxl__initiate_device_remove(libxl__egc *egc,
  * 0: No need to execute hotplug script
  * 1: Execute hotplug script
  *
- * The last parameter, "num_exec" refeers to the number of times hotplug
- * scripts have been called for this device.
+ * The last parameter, libxl__hotplug contains information related to hotplug
+ * execution.
  *
  * The main body of libxl will, for each device, keep calling
  * libxl__get_hotplug_script_info, with incrementing values of
- * num_exec, and executing the resulting script accordingly,
+ * hotplug->num_exec, and executing the resulting script accordingly,
  * until libxl__get_hotplug_script_info returns<=0.
  */
 _hidden int libxl__get_hotplug_script_info(libxl__gc *gc, libxl__device *dev,
                                            char ***args, char ***env,
                                            libxl__device_action action,
-                                           int num_exec);
+                                           libxl__hotplug *hotplug);
 
 /*----- local disk attach: attach a disk locally to run the bootloader -----*/
 
tools/libxl/libxl_linux.c +5 -5
index 37815eb..be76045 100644
@@ -234,7 +234,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)
+                                   libxl__hotplug *hotplug)
 {
     char *disable_udev = libxl__xs_read(gc, XBT_NULL, DISABLE_UDEV_PATH);
     int rc;
@@ -247,7 +247,7 @@ int libxl__get_hotplug_script_info(libxl__gc *gc, libxl__device *dev,
 
     switch (dev->backend_kind) {
     case LIBXL__DEVICE_KIND_VBD:
-        if (num_exec != 0) {
+        if (hotplug->num_exec != 0) {
             rc = 0;
             goto out;
         }
@@ -258,12 +258,12 @@ int libxl__get_hotplug_script_info(libxl__gc *gc, libxl__device *dev,
          * If domain has a stubdom we don't have to execute hotplug scripts
          * for emulated interfaces
          */
-        if ((num_exec > 1) ||
-            (libxl_get_stubdom_id(CTX, dev->domid) && num_exec)) {
+        if ((hotplug->num_exec > 1) ||
+            (libxl_get_stubdom_id(CTX, dev->domid) && hotplug->num_exec)) {
             rc = 0;
             goto out;
         }
-        rc = libxl__hotplug_nic(gc, dev, args, env, action, num_exec);
+        rc = libxl__hotplug_nic(gc, dev, args, env, action, hotplug->num_exec);
         break;
     default:
         /* No need to execute any hotplug scripts */
tools/libxl/libxl_netbsd.c +2 -2
index 898e160..48c87eb 100644
@@ -62,13 +62,13 @@ out:
 int libxl__get_hotplug_script_info(libxl__gc *gc, libxl__device *dev,
                                    char ***args, char ***env,
                                    libxl__device_action action,
-                                   int num_exec)
+                                   libxl__hotplug *hotplug)
 {
     char *disable_udev = libxl__xs_read(gc, XBT_NULL, DISABLE_UDEV_PATH);
     int rc;
 
     /* Check if we have to run hotplug scripts */
-    if (!disable_udev || num_exec > 0) {
+    if (!disable_udev || hotplug->num_exec > 0) {
         rc = 0;
         goto out;
     }
Signature · 7 lines
1.7.7.5 (Apple Git-26)


_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xen.org/xen-devel
#66 lore raw

PATCH v3 2/7 libxl: add new hotplug interface support to hotplug script callers

In reply to Roger Pau Monne

Add support to call hotplug scripts that use the new hotplug interface to the low-level functions in charge of calling hotplug scripts.

libxl__prepare_ao_device sets the hotplug version to 1, in later patches hotplug version will be set to 2 by the caller to use this new hotplug calling convention.

Also add a document describing the new interface.

Cc Ian Campbell <[email protected]>
Cc Ian Jackson <[email protected]>

---
Changes since v2:
* Reserve HOTPLUG_PATH/libxl_* for future toolstack entries.
* Fix grammar fault in documentation.

---
 docs/misc/libxl-hotplug-interface.txt |  184 +++++++++++++++++++++++++++++++++
 tools/libxl/libxl_device.c            |   16 +++-
 tools/libxl/libxl_internal.h          |   20 ++++
 tools/libxl/libxl_linux.c             |   63 +++++++++---
 tools/libxl/libxl_types_internal.idl  |    5 +
 5 files changed, 271 insertions(+), 17 deletions(-)
 create mode 100644 docs/misc/libxl-hotplug-interface.txt
docs/misc/libxl-hotplug-interface.txt new file +184 -0
new file mode 100644
index 0000000..6d67025
@@ -0,0 +1,184 @@
+                     -----------------------
+                     LIBXL HOTPLUG INTERFACE
+                     -----------------------
+
+This document specifies the new libxl hotplug interface. This new
+interface has been designed to operate better with complex hotplug
+scripts, that need to perform several operations and can take a
+considerable time to execute.
+
+Hotplug scripts are expected to take a parameter, passed by the caller
+and provide a block device as output, that will be attached to the guest.
+
+
+
+=====================
+ENVIRONMENT VARIABLES
+=====================
+
+
+The following environment variables will be set before calling
+the hotplug script.
+
+The hotplug script will have write permissions on this xenstore paths.
+
+
+HOTPLUG_PATH
+------------
+
+Points to the xenstore directory that holds information relative
+to this hotplug script. At present only one parameter is passed by
+the toolstack, the "params" xenstore entry which contains the "target"
+line specified in the diskspec xl disk configuration (pdev_path in
+libxl_device_disk struct).
+
+This xenstore directory will be used to communicate between the
+hotplug script and the toolstack, and it can also be used by the
+hotplug script to store temporary information. This directory is created
+before calling the "prepare" operation, and the toolstack guarantees
+that it will not be removed before the "unprepare" operation has been
+finished. After that, the toolstack will take the appropriate actions
+to remove it. The toolstack guarantees that HOTPLUG_PATH will always
+point to a valid xenstore path for all operations.
+
+The path of this directory follows the syntax:
+
+/local/domain/<local_domid>/libxl/hotplug/vbd/<guest_domid>/<device_id>
+
+(Note that there is no end slash appended to HOTPLUG_PATH)
+
+The hotplug script should take special care not to store arbitrary
+values in the following entries:
+
+HOTPLUG_PATH/version
+HOTPLUG_PATH/pdev
+
+This are used for communication between the hotplug script and the
+toolstack, and should only be written to when the parameter passed
+to the hotplug script requires it.
+
+Also, the toolstack reserves the right to use any of the following entries,
+that should not be used to store arbitrary data from the hotplug script:
+
+HOTPLUG_PATH/libxl_*
+
+
+BACKEND_PATH
+------------
+
+Points to the xenstore backend path of the corresponding block device.
+Since hotplug scripts are always executed in the Domain that acts as
+backend for a device, it will always have the following syntax:
+
+/local/domain/<local_domain>/backend/vbd/<guest_domid>/<device_id>
+
+(Note that there is no end slash appended to BACKEND_PATH)
+
+This environment variable is not set for all operations, since some
+hotplug operations are executed before the backend xenstore is set up.
+
+
+
+=======================
+COMMAND LINE PARAMETERS
+=======================
+
+
+Script will be called with only one parameter, that is either prepare,
+add, remove, unprepare, localattach or localdetach.
+
+VERSION
+-------
+
+Operation used to request the version this hotplug script supports. Failure
+to perform this operation will result in hotplug script detected as version 1.
+
+BACKEND_PATH: not valid
+
+Expected output:
+HOTPLGU_PATH/version = version supported by the hotplug script
+
+
+PREPARE
+-------
+
+This is the first operation that the hotplug script will be requested to
+execute. This operation is executed before the disk is connected, to
+give the hotplug script the chance to offload some work from the "add"
+operation, that is performed later.
+
+BACKEND_PATH: not valid
+
+Expected output:
+None
+
+
+ADD
+---
+
+This operation should connect the device to the domain. Will only be called
+after the "prepare" operation has finished successfully.
+
+BACKEND_PATH: valid
+
+Expected output:
+BACKEND_PATH/physical-device = block device major:minor
+BACKEND_PATH/params = block device path
+HOTPLUG_PATH/pdev = block device path
+
+
+REMOVE
+------
+
+
+Disconnects a block device from a domain. Will only be called
+after the "prepare" operation has finished successfully. Implementations
+should take into account that the "remove" operation will also be called if
+the "add" operation has failed.
+
+BACKEND_PATH: valid
+
+Expected output:
+None
+
+
+LOCALATTACH
+-----------
+
+
+Creates a block device in the current domain that points to the guest
+disk device. Will only be called after the "prepare" operation has
+finished successfully.
+
+BACKEND_PATH: not valid
+
+Expected output:
+HOTPLUG_PATH/pdev = block device path
+
+
+LOCALDETACH
+-----------
+
+
+Disconnects a device (previously connected with the localattach
+operation) from the current domain. Will only be called after
+the "prepare" operation has finished successfully. Implementations
+should take into account that the "localdetach" operation will
+also be called if the "localattach" operation has failed.
+
+BACKEND_PATH: not valid
+
+Expected output:
+None
+
+
+UNPREPARE
+---------
+
+
+Performs the necessary actions to unprepare the device.
+
+BACKEND_PATH: not valid
+
+Expected output:
+None
tools/libxl/libxl_device.c +15 -1
index 044cac5..024bc1f 100644
@@ -83,6 +83,14 @@ out:
     return rc;
 }
 
+char *libxl__device_xs_hotplug_path(libxl__gc *gc, libxl__device *dev)
+{
+    return GCSPRINTF("/local/domain/%u/libxl/hotplug/%u/%s/%u",
+                     dev->backend_domid, dev->domid,
+                     libxl__device_kind_to_string(dev->backend_kind),
+                     dev->devid);
+}
+
 int libxl__device_generic_add(libxl__gc *gc, xs_transaction_t t,
         libxl__device *device, char **bents, char **fents)
 {
@@ -410,6 +418,7 @@ void libxl__prepare_ao_device(libxl__ao *ao, libxl__ao_device *aodev)
     aodev->rc = 0;
     aodev->dev = NULL;
     aodev->hotplug.num_exec = 0;
+    aodev->hotplug.version = 1;
     /* Initialize timer for QEMU Bodge and hotplug execution */
     libxl__ev_time_init(&aodev->timeout);
     aodev->active = 1;
@@ -974,7 +983,12 @@ static void device_hotplug_child_death_cb(libxl__egc *egc,
 
     device_hotplug_clean(gc, aodev);
 
-    if (status) {
+    if (status && aodev->action != LIBXL__DEVICE_ACTION_VERSION) {
+        /* If a hotplug script returns an error when called
+         * with the "version" argument it means it is using the old
+         * hotplug calling convention, and we don't have to print
+         * an error message.
+         */
         libxl_report_child_exitstatus(CTX, LIBXL__LOG_ERROR,
                                       aodev->what, pid, status);
         hotplug_error = libxl__xs_read(gc, XBT_NULL,
tools/libxl/libxl_internal.h +20 -0
index 8507ac3..aa0102c 100644
@@ -1854,11 +1854,20 @@ 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 2, the new hotplug script calling convention
+ * will be used to call the hotplug script. This new convention provides
+ * new actions to hotplug scripts, "prepare", "unprepare", "localattach",
+ * "localdetach" and "version". 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);
 
 struct libxl__hotplug {
     int num_exec;
+    int version;
 };
 
 struct libxl__ao_device {
@@ -1868,6 +1877,8 @@ struct libxl__ao_device {
     libxl__device *dev;
     int force;
     libxl__device_callback *callback;
+    /* used by the VERISON and LOCALATTACH actions, set by caller */
+    libxl_device_disk *disk;
     /* return value, zeroed by user on entry, is valid on callback */
     int rc;
     /* private for multidev */
@@ -2051,6 +2062,15 @@ _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 hotplug scripts v2.
+ */
+_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.
  *
tools/libxl/libxl_linux.c +47 -16

86 lines not on this page · raw message

tools/libxl/libxl_types_internal.idl +5 -0
index cb9444f..253bb18 100644
@@ -37,4 +37,9 @@ libxl__device_console = Struct("device_console", [
 libxl__device_action = Enumeration("device_action", [
     (1, "ADD"),
     (2, "REMOVE"),
+    (3, "PREPARE"),
+    (4, "UNPREPARE"),
+    (5, "LOCALATTACH"),
+    (6, "LOCALDETACH"),
+    (7, "VERSION"),
     ])
Signature · 7 lines
1.7.7.5 (Apple Git-26)


_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xen.org/xen-devel
#67 lore raw

PATCH v3 3/7 libxl: add support for hotplug interface v2 in domain creation/destroy

In reply to Roger Pau Monne

Add a new variable to libxl_device_disk "hotplug_version", that will be automatically set to the detected hotplug script interface version.

This patch adds the basic support to handle this new scripts, by adding the prepare private libxl function, and modifying the current domain creation/destruction to call this functions at the appropriate spots. The hotplug interface detection is done in the _prepare call.

This patch also adds some helpers, that will be used here and in later patches.

Cc Ian Campbell <[email protected]>
Cc Ian Jackson <[email protected]>

---
Changes since v1:
* Keep track of hotplug status in xenstore

---
 tools/libxl/libxl.c          |  144 ++++++++++++++++++++++++++++++-
 tools/libxl/libxl_create.c   |   32 +++++++-
 tools/libxl/libxl_device.c   |  199 +++++++++++++++++++++++++++++++++++++----
 tools/libxl/libxl_internal.h |   47 ++++++++++
 tools/libxl/libxl_types.idl  |    1 +
 5 files changed, 400 insertions(+), 23 deletions(-)
tools/libxl/libxl.c +142 -2
index 03a9782..444e039 100644
@@ -2012,6 +2012,119 @@ int libxl__device_from_disk(libxl__gc *gc, uint32_t domid,
     return 0;
 }
 
+/* Callbacks for libxl__device_disk_prepare */
+
+static void device_disk_prepare_cb(libxl__egc *, libxl__ao_device *);
+
+void libxl__device_disk_prepare(libxl__egc *egc, uint32_t domid,
+                                libxl_device_disk *disk,
+                                libxl__ao_device *prepare_aodev)
+{
+    STATE_AO_GC(prepare_aodev->ao);
+    char *hotplug_path;
+    char *script_path;
+    int rc;
+    xs_transaction_t t = XBT_NULL;
+    libxl__disk_prepare *dp;
+    libxl__ao_device *aodev;
+
+    if (!disk->script) {
+        /* If script is not set assume v1 */
+        disk->hotplug_version = 1;
+        prepare_aodev->callback(egc, prepare_aodev);
+        return;
+    }
+
+    GCNEW(dp);
+    dp->disk = disk;
+    /* Save original aodev, since we will call it once hotplug
+     * script detection has finished
+     */
+    dp->aodev = prepare_aodev;
+    aodev = &dp->version_aodev;
+    libxl__prepare_ao_device(ao, aodev);
+
+    GCNEW(aodev->dev);
+    rc = libxl__device_from_disk(gc, domid, disk, aodev->dev);
+    if (rc != 0) {
+        LOG(ERROR, "Invalid or unsupported virtual disk identifier %s",
+                   disk->vdev);
+        goto error;
+    }
+
+    script_path = libxl__abs_path(gc, disk->script,
+                                  libxl__xen_script_dir_path());
+
+    hotplug_path = libxl__device_xs_hotplug_path(gc, aodev->dev);
+    for (;;) {
+        rc = libxl__xs_transaction_start(gc, &t);
+        if (rc) goto error;
+
+        rc = libxl__xs_write_checked(gc, t,
+                                 GCSPRINTF("%s/params", hotplug_path),
+                                 disk->pdev_path);
+        if (rc)
+            goto error;
+
+        rc = libxl__xs_write_checked(gc, t,
+                                 GCSPRINTF("%s/script", hotplug_path),
+                                 script_path);
+        if (rc)
+            goto error;
+
+        rc = libxl__xs_transaction_commit(gc, &t);
+        if (!rc) break;
+        if (rc < 0) goto error;
+    }
+
+    aodev->callback = device_disk_prepare_cb;
+    aodev->action = LIBXL__DEVICE_ACTION_VERSION;
+    aodev->disk = disk;
+    aodev->hotplug.version = 2;
+    libxl__device_hotplug(egc, aodev);
+    return;
+
+error:
+    assert(rc);
+    libxl__xs_transaction_abort(gc, &t);
+    prepare_aodev->rc = rc;
+    prepare_aodev->callback(egc, prepare_aodev);
+    return;
+}
+
+static void device_disk_prepare_cb(libxl__egc *egc,
+                                   libxl__ao_device *version_aodev)
+{
+    STATE_AO_GC(version_aodev->ao);
+    libxl__disk_prepare *dp = CONTAINER_OF(version_aodev, *dp, version_aodev);
+    libxl__ao_device *aodev = dp->aodev;
+
+    if (dp->disk->hotplug_version == 1) {
+        aodev->callback(egc, aodev);
+        return;
+    }
+
+    aodev->action = LIBXL__DEVICE_ACTION_PREPARE;
+    aodev->hotplug.version = dp->disk->hotplug_version;
+    aodev->dev = version_aodev->dev;
+
+    /*
+     * Write status information to xenstore, so we know this device
+     * has been prepared
+     */
+    aodev->rc = libxl__xs_write_checked(gc, XBT_NULL,
+                    GCSPRINTF("%s/backend_domid",
+                        libxl__device_xs_hotplug_status_path(gc, aodev->dev)),
+                    GCSPRINTF("%u", aodev->dev->backend_domid));
+    if (aodev->rc) {
+        aodev->callback(egc, aodev);
+        return;
+    }
+
+    libxl__device_hotplug(egc, aodev);
+    return;
+}
+
 /* Specific function called directly only by local disk attach,
  * all other users should instead use the regular
  * libxl__device_disk_add wrapper
@@ -2071,8 +2184,15 @@ static void device_disk_add(libxl__egc *egc, uint32_t domid,
                 dev = disk->pdev_path;
 
         do_backend_phy:
-                flexarray_append(back, "params");
-                flexarray_append(back, dev);
+                if (disk->hotplug_version == 1) {
+                    /*
+                     * If the new hotplug version is used params is
+                     * stored under a private path, since it can contain
+                     * data that the guest should not see.
+                     */
+                    flexarray_append(back, "params");
+                    flexarray_append(back, dev);
+                }
 
                 script = libxl__abs_path(gc, disk->script?: "block",
                                          libxl__xen_script_dir_path());
@@ -2168,6 +2288,8 @@ static void device_disk_add(libxl__egc *egc, uint32_t domid,
 
     aodev->dev = device;
     aodev->action = LIBXL__DEVICE_ACTION_ADD;
+    aodev->hotplug.version = disk->hotplug_version;
+    aodev->disk = disk;
     libxl__wait_device_connection(egc, aodev);
 
     rc = 0;
@@ -2261,6 +2383,7 @@ int libxl_vdev_to_device_disk(libxl_ctx *ctx, uint32_t domid,
     GC_INIT(ctx);
     char *dompath, *path;
     int devid = libxl__device_disk_dev_number(vdev, NULL, NULL);
+    libxl__device dev;
     int rc = ERROR_FAIL;
 
     if (devid < 0)
@@ -2279,6 +2402,23 @@ int libxl_vdev_to_device_disk(libxl_ctx *ctx, uint32_t domid,
         goto out;
 
     rc = libxl__device_disk_from_xs_be(gc, path, disk);
+    if (rc) {
+        LOG(ERROR, "unable to parse disk device from path %s", path);
+        goto out;
+    }
+
+    /* Check if the device is using the new hotplug interface */
+    rc = libxl__device_from_disk(gc, domid, disk, &dev);
+    if (rc) {
+        LOG(ERROR, "invalid or unsupported virtual disk identifier %s",
+                    disk->vdev);
+        goto out;
+    }
+    disk->hotplug_version = 1;
+    path = libxl__device_xs_hotplug_path(gc, &dev);
+    if (libxl__xs_read(gc, XBT_NULL, path))
+        disk->hotplug_version = 2;
+
 out:
     GC_FREE;
     return rc;
tools/libxl/libxl_create.c +31 -1
index ae72f21..708e14e 100644
@@ -595,6 +595,10 @@ static int store_libxl_entry(libxl__gc *gc, uint32_t domid,
  */
 
 /* Event callbacks, in this order: */
+
+static void domcreate_launch_bootloader(libxl__egc *egc,
+                                        libxl__multidev *multidev,
+                                        int ret);
 static void domcreate_devmodel_started(libxl__egc *egc,
                                        libxl__dm_spawn_state *dmss,
                                        int rc);
@@ -641,7 +645,6 @@ static void initiate_domain_create(libxl__egc *egc,
 
     /* convenience aliases */
     libxl_domain_config *const d_config = dcs->guest_config;
-    const int restore_fd = dcs->restore_fd;
     memset(&dcs->build_state, 0, sizeof(dcs->build_state));
 
     domid = 0;
@@ -674,6 +677,33 @@ static void initiate_domain_create(libxl__egc *egc,
         if (ret) goto error_out;
     }
 
+    libxl__multidev_begin(ao, &dcs->multidev);
+    dcs->multidev.callback = domcreate_launch_bootloader;
+    libxl__prepare_disks(egc, ao, domid, d_config, &dcs->multidev);
+    libxl__multidev_prepared(egc, &dcs->multidev, 0);
+    return;
+
+error_out:
+    assert(ret);
+    domcreate_complete(egc, dcs, ret);
+}
+
+static void domcreate_launch_bootloader(libxl__egc *egc,
+                                        libxl__multidev *multidev,
+                                        int ret)
+{
+    libxl__domain_create_state *dcs = CONTAINER_OF(multidev, *dcs, multidev);
+    STATE_AO_GC(dcs->ao);
+
+    /* convenience aliases */
+    const int restore_fd = dcs->restore_fd;
+    libxl_domain_config *const d_config = dcs->guest_config;
+
+    if (ret) {
+        LOG(ERROR, "unable to prepare devices");
+        goto error_out;
+    }
+
     dcs->bl.ao = ao;
     libxl_device_disk *bootdisk =
         d_config->num_disks > 0 ? &d_config->disks[0] : NULL;
tools/libxl/libxl_device.c +179 -20

326 lines not on this page · raw message

tools/libxl/libxl_internal.h +47 -0

71 lines not on this page · raw message

tools/libxl/libxl_types.idl +1 -0
index fcb1ecd..a5470f0 100644
@@ -372,6 +372,7 @@ libxl_device_disk = Struct("device_disk", [
     ("removable", integer),
     ("readwrite", integer),
     ("is_cdrom", integer),
+    ("hotplug_version", integer),
     ])
 
 libxl_device_nic = Struct("device_nic", [
Signature · 7 lines
1.7.7.5 (Apple Git-26)


_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xen.org/xen-devel
#68 lore raw

Re: [PATCH v3 3/7] libxl: add support for hotplug interface v2 in domain creation/destroy

Roger Pau Monne writes ("[PATCH v3 3/7] libxl: add support for hotplug interface v2 in domain creation/destroy"):

Quoted 2 lines

Add a new variable to libxl_device_disk "hotplug_version", that will be automatically set to the detected hotplug script interface version.

Why does this need to be in the public interface ? Is it just there for reporting ?

The rest of this looks OK assuming that this is roughly the right approach, but see my previous mail.

Ian.

#69 lore raw

PATCH v3 4/7 libxl: chain prepare and attach in libxl_device_disk_add

In reply to Roger Pau Monne

Chaining the prepare and attach functions in the public libxl_device_disk_add allows libxl to keep the same public API while allowing hotplug scripts v2 to be used.

libxl takes care of detecting the hotplug version of the script and executing the necessary actions.

Cc Ian Campbell <[email protected]>
Cc Ian Jackson <[email protected]>

---
Changes since v1:
* Remove public _prepare/_unprepare functions and do all the logic inside libxl_device_disk_add, this prevents an API change.

---
 tools/libxl/libxl.c |   37 +++++++++++++++++++++++++++++++++----
 1 files changed, 33 insertions(+), 4 deletions(-)
tools/libxl/libxl.c +33 -4
index 444e039..32e2696 100644
@@ -2307,6 +2307,39 @@ void libxl__device_disk_add(libxl__egc *egc, uint32_t domid,
     device_disk_add(egc, domid, disk, aodev, NULL, NULL);
 }
 
+/* Callbacks for device_disk_add */
+
+static void device_disk_add_prepared(libxl__egc *, libxl__ao_device *);
+
+int libxl_device_disk_add(libxl_ctx *ctx, uint32_t domid,
+                          libxl_device_disk *disk,
+                          const libxl_asyncop_how *ao_how)
+{
+    AO_CREATE(ctx, domid, ao_how);
+    libxl__ao_device *aodev;
+
+    GCNEW(aodev);
+    libxl__prepare_ao_device(ao, aodev);
+    aodev->callback = device_disk_add_prepared;
+    aodev->disk = disk;
+    libxl__device_disk_prepare(egc, domid, disk, aodev);
+
+    return AO_INPROGRESS;
+}
+
+static void device_disk_add_prepared(libxl__egc *egc, libxl__ao_device *aodev)
+{
+    if (aodev->rc) {
+        device_addrm_aocomplete(egc, aodev);
+        return;
+    }
+
+    aodev->hotplug.num_exec = 0;
+    aodev->callback = device_addrm_aocomplete;
+    libxl__device_disk_add(egc, aodev->dev->domid, aodev->disk, aodev);
+    return;
+}
+
 static int libxl__device_disk_from_xs_be(libxl__gc *gc,
                                          const char *be_path,
                                          libxl_device_disk *disk)
@@ -3558,7 +3591,6 @@ DEFINE_DEVICE_REMOVE(vtpm, destroy, 1)
 
 /* Macro for defining device addition functions in a compact way */
 /* The following functions are defined:
- * libxl_device_disk_add
  * libxl_device_nic_add
  * libxl_device_vtpm_add
  */
@@ -3581,9 +3613,6 @@ DEFINE_DEVICE_REMOVE(vtpm, destroy, 1)
 
 /* Define alladd functions and undef the macro */
 
-/* disk */
-DEFINE_DEVICE_ADD(disk)
-
 /* nic */
 DEFINE_DEVICE_ADD(nic)
 
Signature · 7 lines
1.7.7.5 (Apple Git-26)


_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xen.org/xen-devel
#70 lore raw

PATCH v3 5/7 libxl: add disk specific remove functions

In reply to Roger Pau Monne

Add a specific macro to generate libxl_device_disk_{remove/destroy} functions that passes the hotplug_version field down to the aodev struct.

Cc Ian Campbell <[email protected]>
Cc Ian Jackson <[email protected]>
---
 tools/libxl/libxl.c |   19 ++++++++++++++++---
 1 files changed, 16 insertions(+), 3 deletions(-)
tools/libxl/libxl.c +16 -3
index 32e2696..f9502a8 100644
@@ -3535,7 +3535,7 @@ out:
  * libxl_device_vfb_remove
  * libxl_device_vfb_destroy
  */
-#define DEFINE_DEVICE_REMOVE(type, removedestroy, f)                    \
+#define DEFINE_GENERIC_REMOVE(type, removedestroy, f, extra)            \
     int libxl_device_##type##_##removedestroy(libxl_ctx *ctx,           \
         uint32_t domid, libxl_device_##type *type,                      \
         const libxl_asyncop_how *ao_how)                                \
@@ -3555,6 +3555,7 @@ out:
         aodev->dev = device;                                            \
         aodev->callback = device_addrm_aocomplete;                      \
         aodev->force = f;                                               \
+        extra;                                                          \
         libxl__initiate_device_remove(egc, aodev);                      \
                                                                         \
     out:                                                                \
@@ -3562,11 +3563,21 @@ out:
         return AO_INPROGRESS;                                           \
     }
 
+/* Specific for disk devices, that have to set aodev->hotplug_version */
+#define DEFINE_DISK_REMOVE(type, removedestroy, f)                      \
+    DEFINE_GENERIC_REMOVE(type, removedestroy, f, {                     \
+        aodev->hotplug.version = type->hotplug_version;                 \
+        LOG(DEBUG, "hotplug version: %d", aodev->hotplug.version);      \
+    })
+
+#define DEFINE_DEVICE_REMOVE(type, removedestroy, f)                    \
+    DEFINE_GENERIC_REMOVE(type, removedestroy, f, )
+
 /* Define all remove/destroy functions and undef the macro */
 
 /* disk */
-DEFINE_DEVICE_REMOVE(disk, remove, 0)
-DEFINE_DEVICE_REMOVE(disk, destroy, 1)
+DEFINE_DISK_REMOVE(disk, remove, 0)
+DEFINE_DISK_REMOVE(disk, destroy, 1)
 
 /* nic */
 DEFINE_DEVICE_REMOVE(nic, remove, 0)
@@ -3585,7 +3596,9 @@ DEFINE_DEVICE_REMOVE(vfb, destroy, 1)
 DEFINE_DEVICE_REMOVE(vtpm, remove, 0)
 DEFINE_DEVICE_REMOVE(vtpm, destroy, 1)
 
+#undef DEFINE_DISK_REMOVE
 #undef DEFINE_DEVICE_REMOVE
+#undef DEFINE_GENERIC_REMOVE
 
 /******************************************************************************/
 
Signature · 7 lines
1.7.7.5 (Apple Git-26)


_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xen.org/xen-devel
#71 lore raw

PATCH v3 6/7 libxl: add local attach support for new hotplug scripts

In reply to Roger Pau Monne

Adds support for locally attaching disks that use the new hotplug script interface, by calling the localattach/localdetach operations and returning a block device that can be used to execute pygrub.

Cc Ian Campbell <[email protected]>
Cc Ian Jackson <[email protected]>
---
 tools/libxl/libxl.c            |   86 ++++++++++++++++++++++++++++++++++------
 tools/libxl/libxl_bootloader.c |    1 +
 tools/libxl/libxl_internal.h   |    1 +
 3 files changed, 76 insertions(+), 12 deletions(-)
tools/libxl/libxl.c +74 -12
index f9502a8..fdf9e16 100644
@@ -2719,6 +2719,7 @@ void libxl__device_disk_local_initiate_attach(libxl__egc *egc,
     const libxl_device_disk *in_disk = dls->in_disk;
     libxl_device_disk *disk = &dls->disk;
     const char *blkdev_start = dls->blkdev_start;
+    uint32_t domid = dls->domid;
 
     assert(in_disk->pdev_path);
 
@@ -2735,6 +2736,23 @@ void libxl__device_disk_local_initiate_attach(libxl__egc *egc,
         case LIBXL_DISK_BACKEND_PHY:
             LIBXL__LOG(ctx, LIBXL__LOG_DEBUG, "locally attaching PHY disk %s",
                        disk->pdev_path);
+            if (disk->hotplug_version == 2) {
+                disk->vdev = libxl__strdup(gc, in_disk->vdev);
+                libxl__prepare_ao_device(ao, &dls->aodev);
+                GCNEW(dls->aodev.dev);
+                rc = libxl__device_from_disk(gc, domid, disk,
+                                             dls->aodev.dev);
+                if (rc != 0) {
+                    LOG(ERROR, "Invalid or unsupported virtual disk "
+                               "identifier %s", disk->vdev);
+                    goto out;
+                }
+                dls->aodev.action = LIBXL__DEVICE_ACTION_LOCALATTACH;
+                dls->aodev.hotplug.version = disk->hotplug_version;
+                dls->aodev.callback = local_device_attach_cb;
+                libxl__device_hotplug(egc, &dls->aodev);
+                return;
+            }
             dev = disk->pdev_path;
             break;
         case LIBXL_DISK_BACKEND_TAP:
@@ -2797,7 +2815,8 @@ static void local_device_attach_cb(libxl__egc *egc, libxl__ao_device *aodev)
 {
     STATE_AO_GC(aodev->ao);
     libxl__disk_local_state *dls = CONTAINER_OF(aodev, *dls, aodev);
-    char *dev = NULL, *be_path = NULL;
+    char *dev = NULL, *be_path = NULL, *hotplug_path;
+    const char *pdev = NULL;
     int rc;
     libxl__device device;
     libxl_device_disk *disk = &dls->disk;
@@ -2810,20 +2829,45 @@ static void local_device_attach_cb(libxl__egc *egc, libxl__ao_device *aodev)
                     aodev->dev->devid);
         goto out;
     }
+    switch (disk->backend) {
+    case LIBXL_DISK_BACKEND_PHY:
+        /* Fetch hotplug output to obtain the block device */
+        rc = libxl__device_from_disk(gc, dls->domid, disk, &device);
+        if (rc)
+            goto out;
+        hotplug_path = libxl__device_xs_hotplug_path(gc, &device);
+        rc = libxl__xs_read_checked(gc, XBT_NULL,
+                                    GCSPRINTF("%s/pdev", hotplug_path),
+                                    &pdev);
+        if (rc)
+            goto out;
+        if (!pdev) {
+            rc = ERROR_FAIL;
+            goto out;
+        }
+        LOG(DEBUG, "attached local block device %s", pdev);
+        dls->diskpath = libxl__strdup(gc, pdev);
+        break;
+    case LIBXL_DISK_BACKEND_QDISK:
+        dev = GCSPRINTF("/dev/%s", disk->vdev);
+        LOG(DEBUG, "locally attaching qdisk %s", dev);
 
-    dev = GCSPRINTF("/dev/%s", disk->vdev);
-    LOG(DEBUG, "locally attaching qdisk %s", dev);
+        rc = libxl__device_from_disk(gc, LIBXL_TOOLSTACK_DOMID, disk, &device);
+        if (rc < 0)
+            goto out;
+        be_path = libxl__device_backend_path(gc, &device);
+        rc = libxl__wait_for_backend(gc, be_path, "4");
+        if (rc < 0)
+            goto out;
 
-    rc = libxl__device_from_disk(gc, LIBXL_TOOLSTACK_DOMID, disk, &device);
-    if (rc < 0)
-        goto out;
-    be_path = libxl__device_backend_path(gc, &device);
-    rc = libxl__wait_for_backend(gc, be_path, "4");
-    if (rc < 0)
+        if (dev != NULL)
+            dls->diskpath = libxl__strdup(gc, dev);
+        break;
+    default:
+        LOG(ERROR, "invalid disk backend for local attach callback");
+        rc = ERROR_FAIL;
         goto out;
-
-    if (dev != NULL)
-        dls->diskpath = libxl__strdup(gc, dev);
+    }
 
     dls->callback(egc, dls, 0);
     return;
@@ -2847,11 +2891,29 @@ void libxl__device_disk_local_initiate_detach(libxl__egc *egc,
     libxl_device_disk *disk = &dls->disk;
     libxl__device *device;
     libxl__ao_device *aodev = &dls->aodev;
+    uint32_t domid = dls->domid;
     libxl__prepare_ao_device(ao, aodev);
 
     if (!dls->diskpath) goto out;
 
     switch (disk->backend) {
+        case LIBXL_DISK_BACKEND_PHY:
+            if (disk->hotplug_version == 2) {
+                GCNEW(aodev->dev);
+                rc = libxl__device_from_disk(gc, domid, disk,
+                                             aodev->dev);
+                if (rc != 0) {
+                    LOG(ERROR, "Invalid or unsupported virtual disk "
+                               "identifier %s", disk->vdev);
+                    goto out;
+                }
+                aodev->action = LIBXL__DEVICE_ACTION_LOCALDETACH;
+                aodev->hotplug.version = disk->hotplug_version;
+                aodev->callback = local_device_detach_cb;
+                libxl__device_hotplug(egc, aodev);
+                return;
+            }
+            break;
         case LIBXL_DISK_BACKEND_QDISK:
             if (disk->vdev != NULL) {
                 GCNEW(device);
tools/libxl/libxl_bootloader.c +1 -0
index ed12b2c..5d889fe 100644
@@ -381,6 +381,7 @@ void libxl__bootloader_run(libxl__egc *egc, libxl__bootloader_state *bl)
     bl->dls.ao = ao;
     bl->dls.in_disk = bl->disk;
     bl->dls.blkdev_start = info->blkdev_start;
+    bl->dls.domid = domid;
     bl->dls.callback = bootloader_disk_attached_cb;
     libxl__device_disk_local_initiate_attach(egc, &bl->dls);
     return;
tools/libxl/libxl_internal.h +1 -0
index 00d9232..333a797 100644
@@ -2152,6 +2152,7 @@ struct libxl__disk_local_state {
     libxl_device_disk disk;
     const char *blkdev_start;
     libxl__disk_local_state_callback *callback;
+    uint32_t domid;
     /* filled by libxl__device_disk_local_initiate_attach */
     char *diskpath;
     /* private for implementation of local detach */
Signature · 7 lines
1.7.7.5 (Apple Git-26)


_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xen.org/xen-devel
#72 lore raw

PATCH v3 7/7 hotplug/Linux: add iscsi block hotplug script

In reply to Roger Pau Monne

This hotplug script has been tested with IET and NetBSD iSCSI targets, without authentication.

Authentication parameters, including the password are passed as parameters to iscsiadm, which is not recommended because other users of the system can see them. This parameters could also be set by editing a corresponding file directly, but the location of this file seems to be different depending on the distribution used.

Cc Ian Campbell <[email protected]>
Cc Ian Jackson <[email protected]>

---
Changes since v1:
* Add -e to script shebang, and use 'set +e' if we know hotplug execution might fail.

---
 tools/hotplug/Linux/Makefile    |    1 +
 tools/hotplug/Linux/block-iscsi |  278 +++++++++++++++++++++++++++++++++++++++
 2 files changed, 279 insertions(+), 0 deletions(-)
 create mode 100644 tools/hotplug/Linux/block-iscsi
tools/hotplug/Linux/Makefile +1 -0
index 0605559..98c7738 100644
@@ -21,6 +21,7 @@ XEN_SCRIPTS += blktap
 XEN_SCRIPTS += xen-hotplug-cleanup
 XEN_SCRIPTS += external-device-migrate
 XEN_SCRIPTS += vscsi
+XEN_SCRIPTS += block-iscsi
 XEN_SCRIPT_DATA = xen-script-common.sh locking.sh logging.sh
 XEN_SCRIPT_DATA += xen-hotplug-common.sh xen-network-common.sh vif-common.sh
 XEN_SCRIPT_DATA += block-common.sh
tools/hotplug/Linux/block-iscsi new file +278 -0

278 lines not on this page · raw message

Signature · 7 lines
1.7.7.5 (Apple Git-26)


_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xen.org/xen-devel
Acked-by on the v3 series
#73 lore raw
In reply to Roger Pau Monne
Quoted 11 lines · Roger Pau Monne

This series implements a new hoplug calling convention for libxl.

The aim of this new convention is to reduce the blackout phase of migration when using complex hotplug scripts, like iSCSI or other kind of storage backends that might have a non trivial setup time.

Major changes from v2 are the addition of HOTPLUG_PATH/libxl_* to the list of reserved entries, and the rebase of the whole series on top of current xen-unstable commit.

Thanks for the comments, Roger.

Based on the argument that this will be heavily tested (on every domain creation), and will be fairly easy to revert if it looks like it's causing trouble, then from a release perspective:

Quoted 35 lines

Branch available in the git repository at:
git://xenbits.xen.org/people/royger/xen.git iscsi_v3

* Acked

Roger Pau Monne (7):
*libxl: group hotplug related variables
libxl: add new hotplug interface support to hotplug script callers
libxl: add support for hotplug interface v2 in domain creation/destroy
libxl: chain prepare and attach in libxl_device_disk_add
libxl: add disk specific remove functions
libxl: add local attach support for new hotplug scripts hotplug/Linux: add iscsi block hotplug script

 docs/misc/libxl-hotplug-interface.txt |  184 +++++++++++++++++++++
 tools/hotplug/Linux/Makefile          |    1 +
 tools/hotplug/Linux/block-iscsi       |  278 ++++++++++++++++++++++++++++++++
 tools/libxl/libxl.c                   |  286 ++++++++++++++++++++++++++++++---
 tools/libxl/libxl_bootloader.c        |    1 +
 tools/libxl/libxl_create.c            |   32 ++++-
 tools/libxl/libxl_device.c            |  221 +++++++++++++++++++++++---
 tools/libxl/libxl_internal.h          |   83 +++++++++-
 tools/libxl/libxl_linux.c             |   73 ++++++---
 tools/libxl/libxl_netbsd.c            |    4 +-
 tools/libxl/libxl_types.idl           |    1 +
 tools/libxl/libxl_types_internal.idl  |    5 +
 12 files changed, 1095 insertions(+), 74 deletions(-)
 create mode 100644 docs/misc/libxl-hotplug-interface.txt
 create mode 100644 tools/hotplug/Linux/block-iscsi

_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xen.org/xen-devel