From: Roger Pau Monne <roger.pau@citrix.com>
To: xen-devel@lists.xen.org
Cc: Ian Campbell <ian.campbell@citrix.com>,
Roger Pau Monne <roger.pau@citrix.com>
Subject: [PATCH v1 05/12] libxl: add new hotplug interface support to hotplug script callers
Date: Wed, 23 Jan 2013 18:48:30 +0100 [thread overview]
Message-ID: <1358963317-10221-6-git-send-email-roger.pau@citrix.com> (raw)
In-Reply-To: <1358963317-10221-1-git-send-email-roger.pau@citrix.com>
Add support to call hotplug scripts that use the new hotplug interface
to the low-level functions in charge of calling hotplug scripts.
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.
Signed-off-by: Roger Pau Monné <roger.pau@citrix.com>
Cc: Ian Campbell <ian.campbell@citrix.com>
---
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(-)
diff --git a/tools/libxl/libxl_device.c b/tools/libxl/libxl_device.c
index 044cac5..904853a 100644
--- a/tools/libxl/libxl_device.c
+++ b/tools/libxl/libxl_device.c
@@ -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,
diff --git a/tools/libxl/libxl_internal.h b/tools/libxl/libxl_internal.h
index d69d819..e819bbd 100644
--- a/tools/libxl/libxl_internal.h
+++ b/tools/libxl/libxl_internal.h
@@ -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.
*
diff --git a/tools/libxl/libxl_linux.c b/tools/libxl/libxl_linux.c
index 531bc7e..00ffd6d 100644
--- a/tools/libxl/libxl_linux.c
+++ b/tools/libxl/libxl_linux.c
@@ -191,32 +191,63 @@ out:
static int libxl__hotplug_disk(libxl__gc *gc, libxl__device *dev,
char ***args, char ***env,
- libxl__device_action action)
+ libxl__device_action action,
+ int hotplug_version)
{
char *be_path = libxl__device_backend_path(gc, dev);
+ char *hotplug_path = libxl__device_xs_hotplug_path(gc, dev);
char *script;
int nr = 0, rc = 0;
+ const int env_arraysize = 5;
+ const int arg_arraysize = 3;
- script = libxl__xs_read(gc, XBT_NULL,
- GCSPRINTF("%s/%s", be_path, "script"));
- if (!script) {
- LOGEV(ERROR, errno, "unable to read script from %s", be_path);
- rc = ERROR_FAIL;
- goto error;
- }
-
- *env = get_hotplug_env(gc, script, dev);
- if (!*env) {
+ switch (hotplug_version) {
+ case 1:
+ script = libxl__xs_read(gc, XBT_NULL, GCSPRINTF("%s/script", be_path));
+ if (!script) {
+ LOGEV(ERROR, errno, "unable to read script from %s", be_path);
+ rc = ERROR_FAIL;
+ goto error;
+ }
+ *env = get_hotplug_env(gc, script, dev);
+ if (!*env) {
+ rc = ERROR_FAIL;
+ goto error;
+ }
+ break;
+ case 2:
+ /* The new hotplug calling convention only uses two ENV variables:
+ * BACKEND_PATH: path to xenstore backend of the related device.
+ * HOTPLUG_PATH: path to the xenstore directory that can be used to
+ * pass extra parameters to the script.
+ */
+ script = libxl__xs_read(gc, XBT_NULL,
+ GCSPRINTF("%s/script", hotplug_path));
+ if (!script) {
+ LOGEV(ERROR, errno, "unable to read script from %s", hotplug_path);
+ rc = ERROR_FAIL;
+ goto error;
+ }
+ GCNEW_ARRAY(*env, env_arraysize);
+ (*env)[nr++] = "BACKEND_PATH";
+ (*env)[nr++] = be_path;
+ (*env)[nr++] = "HOTPLUG_PATH";
+ (*env)[nr++] = hotplug_path;
+ (*env)[nr++] = NULL;
+ assert(nr == env_arraysize);
+ nr = 0;
+ break;
+ default:
+ LOG(ERROR, "unknown hotplug script version %d", hotplug_version);
rc = ERROR_FAIL;
goto error;
}
- const int arraysize = 3;
- GCNEW_ARRAY(*args, arraysize);
+ GCNEW_ARRAY(*args, arg_arraysize);
(*args)[nr++] = script;
(*args)[nr++] = (char *) libxl__device_action_to_string(action);
(*args)[nr++] = NULL;
- assert(nr == arraysize);
+ assert(nr == arg_arraysize);
rc = 1;
@@ -244,7 +275,7 @@ int libxl__get_hotplug_script_info(libxl__gc *gc, libxl__device *dev,
rc = 0;
goto out;
}
- rc = libxl__hotplug_disk(gc, dev, args, env, action);
+ rc = libxl__hotplug_disk(gc, dev, args, env, action, hotplug->version);
break;
case LIBXL__DEVICE_KIND_VIF:
/*
diff --git a/tools/libxl/libxl_types_internal.idl b/tools/libxl/libxl_types_internal.idl
index cb9444f..253bb18 100644
--- a/tools/libxl/libxl_types_internal.idl
+++ b/tools/libxl/libxl_types_internal.idl
@@ -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"),
])
--
1.7.7.5 (Apple Git-26)
_______________________________________________
Xen-devel mailing list
Xen-devel@lists.xen.org
http://lists.xen.org/xen-devel
next prev parent reply other threads:[~2013-01-23 17:48 UTC|newest]
Thread overview: 74+ messages / expand[flat|nested] mbox.gz Atom feed top
2013-04-17 15:47 [PATCH v3 0/7] libxl: new hotplug calling convention Roger Pau Monne
2013-04-17 15:47 ` [PATCH v3 1/7] libxl: group hotplug related variables Roger Pau Monne
2013-04-17 15:47 ` [PATCH v3 2/7] libxl: add new hotplug interface support to hotplug script callers Roger Pau Monne
2013-03-18 11:47 ` [PATCH v2] libxl: new hotplug calling convention Roger Pau Monne
2013-03-18 11:47 ` [PATCH v2 1/7] libxl: group hotplug related variables Roger Pau Monne
2013-03-18 11:47 ` [PATCH v2 2/7] libxl: add new hotplug interface support to hotplug script callers Roger Pau Monne
2013-04-11 16:25 ` Ian Jackson
2013-04-16 11:30 ` Roger Pau Monné
2013-04-16 12:06 ` Ian Campbell
2013-04-16 14:42 ` Roger Pau Monné
2013-04-16 15:04 ` Ian Jackson
2013-04-11 16:33 ` Ian Jackson
2013-04-12 13:51 ` Roger Pau Monné
2013-04-18 17:23 ` [PATCH v2 2/7] libxl: add new hotplug interface support to hotplug script callers [and 1 more messages] Ian Jackson
2013-04-18 17:40 ` Roger Pau Monné
2013-04-18 17:52 ` Ian Jackson
2013-04-19 8:10 ` Roger Pau Monné
2013-03-18 11:47 ` [PATCH v2 3/7] libxl: add support for hotplug interface v2 in domain creation/destroy Roger Pau Monne
2013-03-18 11:47 ` [PATCH v2 4/7] libxl: chain prepare and attach in libxl_device_disk_add Roger Pau Monne
2013-03-18 11:47 ` [PATCH v2 5/7] libxl: add disk specific remove functions Roger Pau Monne
2013-01-23 17:48 ` [PATCH v1 0/12] libxl: new hotplug calling convention Roger Pau Monne
2013-01-23 17:48 ` [PATCH v1 01/12] libxl: libxl__prepare_ao_device should reset num_exec Roger Pau Monne
2013-01-25 8:57 ` Ian Campbell
2013-01-23 17:48 ` [PATCH v1 02/12] libxl: remove double check in NetBSD hotplug Roger Pau Monne
2013-03-13 14:45 ` Ian Jackson
2013-01-23 17:48 ` [PATCH v1 03/12] libxl: move libxl_device_action to idl Roger Pau Monne
2013-03-13 14:48 ` Ian Jackson
2013-01-23 17:48 ` [PATCH v1 04/12] libxl: pack hotplug related variables Roger Pau Monne
2013-03-13 14:49 ` Ian Jackson
2013-03-14 16:44 ` Roger Pau Monné
2013-01-23 17:48 ` Roger Pau Monne [this message]
2013-03-13 14:53 ` [PATCH v1 05/12] libxl: add new hotplug interface support to hotplug script callers Ian Jackson
2013-03-13 16:04 ` Roger Pau Monné
2013-03-13 16:10 ` Ian Jackson
2013-03-14 17:03 ` Roger Pau Monné
2013-01-23 17:48 ` [PATCH v1 06/12] libxl: add support for different hotplug interfaces Roger Pau Monne
2013-03-13 16:17 ` Ian Jackson
2013-03-15 11:03 ` Roger Pau Monné
2013-03-15 11:24 ` Ian Jackson
2013-03-15 11:36 ` Roger Pau Monné
2013-01-23 17:48 ` [PATCH v1 07/12] libxl: add prepare/unprepare operations to the libxl public interface Roger Pau Monne
2013-03-13 16:19 ` Ian Jackson
2013-03-15 11:33 ` Roger Pau Monné
2013-03-15 11:42 ` Roger Pau Monné
2013-03-15 12:20 ` Ian Jackson
2013-03-15 12:39 ` Roger Pau Monné
2013-01-23 17:48 ` [PATCH v1 08/12] libxl: add disk specific remove functions Roger Pau Monne
2013-03-13 16:22 ` Ian Jackson
2013-03-15 11:52 ` Roger Pau Monné
2013-04-11 16:17 ` [PATCH v1 08/12] libxl: add disk specific remove functions [and 1 more messages] Ian Jackson
2013-04-15 7:33 ` Roger Pau Monné
2013-01-23 17:48 ` [PATCH v1 09/12] xl: add support for new hotplug interface to block-attach/detach Roger Pau Monne
2013-03-13 16:22 ` Ian Jackson
2013-03-15 11:54 ` Roger Pau Monné
2013-01-23 17:48 ` [PATCH v1 10/12] libxl: add local attach support for new hotplug scripts Roger Pau Monne
2013-03-13 16:25 ` Ian Jackson
2013-03-15 11:59 ` Roger Pau Monné
2013-01-23 17:48 ` [PATCH v1 11/12] hotplug: document new hotplug interface Roger Pau Monne
2013-03-13 16:29 ` Ian Jackson
2013-03-15 12:29 ` Roger Pau Monné
2013-01-23 17:48 ` [PATCH v1 12/12] hotplug/Linux: add iscsi block hotplug script Roger Pau Monne
2013-03-13 16:31 ` Ian Jackson
2013-03-15 12:08 ` Roger Pau Monné
2013-03-15 12:24 ` Ian Jackson
2013-03-04 11:13 ` [PATCH v1 0/12] libxl: new hotplug calling convention Roger Pau Monné
2013-03-18 11:47 ` [PATCH v2 6/7] libxl: add local attach support for new hotplug scripts Roger Pau Monne
2013-03-18 11:47 ` [PATCH v2 7/7] hotplug/Linux: add iscsi block hotplug script Roger Pau Monne
2013-04-17 15:47 ` [PATCH v3 3/7] libxl: add support for hotplug interface v2 in domain creation/destroy Roger Pau Monne
2013-04-18 17:30 ` Ian Jackson
2013-04-17 15:47 ` [PATCH v3 4/7] libxl: chain prepare and attach in libxl_device_disk_add Roger Pau Monne
2013-04-17 15:47 ` [PATCH v3 5/7] libxl: add disk specific remove functions Roger Pau Monne
2013-04-17 15:47 ` [PATCH v3 6/7] libxl: add local attach support for new hotplug scripts Roger Pau Monne
2013-04-17 15:47 ` [PATCH v3 7/7] hotplug/Linux: add iscsi block hotplug script Roger Pau Monne
2013-04-18 16:28 ` [PATCH v3 0/7] libxl: new hotplug calling convention George Dunlap
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1358963317-10221-6-git-send-email-roger.pau@citrix.com \
--to=roger.pau@citrix.com \
--cc=ian.campbell@citrix.com \
--cc=xen-devel@lists.xen.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).