From: Roger Pau Monne <roger.pau@citrix.com>
To: xen-devel@lists.xen.org
Cc: Ian Jackson <ian.jackson@eu.citrix.com>,
Roger Pau Monne <roger.pau@citrix.com>
Subject: [PATCH v6 08/13] libxl: add option to choose who executes hotplug scripts
Date: Thu, 14 Jun 2012 13:21:10 +0100 [thread overview]
Message-ID: <1339676475-33265-9-git-send-email-roger.pau@citrix.com> (raw)
In-Reply-To: <1339676475-33265-1-git-send-email-roger.pau@citrix.com>
Add and option to xl.conf file to decide if hotplug scripts are
executed from the toolstack (xl) or from udev as it used to be in the
past.
This option is only introduced in this patch, but it has no effect
since the code to call hotplug scripts from libxl is introduced in a
latter patch.
This choice will be saved in "libxl/disable_udev", as specified in the
DISABLE_UDEV_PATH constant.
Changes since v2:
* Change atoi(...) to !!atoi(...) to prevent returning negative
values from xenstore (which will be handled as errors).
* Check for errors on the return value of libxl__hotplug_settings.
Changes since v1:
* Used an auxiliary function to check for the current setting.
Cc: Ian Jackson <ian.jackson@eu.citrix.com>
Acked-by: Ian Jackson <ian.jackson@eu.citrix.com>
Signed-off-by: Roger Pau Monne <roger.pau@citrix.com>
---
docs/man/xl.conf.pod.5 | 8 ++++++++
tools/examples/xl.conf | 5 +++++
tools/libxl/libxl_create.c | 36 +++++++++++++++++++++++++++++++++++-
tools/libxl/libxl_internal.c | 19 +++++++++++++++++++
tools/libxl/libxl_internal.h | 3 +++
tools/libxl/libxl_types.idl | 1 +
tools/libxl/xl.c | 4 ++++
tools/libxl/xl.h | 1 +
tools/libxl/xl_cmdimpl.c | 1 +
9 files changed, 77 insertions(+), 1 deletions(-)
diff --git a/docs/man/xl.conf.pod.5 b/docs/man/xl.conf.pod.5
index 149430c..23932be 100644
--- a/docs/man/xl.conf.pod.5
+++ b/docs/man/xl.conf.pod.5
@@ -55,6 +55,14 @@ default.
Default: C<1>
+=item B<run_hotplug_scripts=BOOLEAN>
+
+If disabled hotplug scripts will be called from udev, as it used to
+be in the previous releases. With the default option, hotplug scripts
+will be launched by xl directly.
+
+Default: C<1>
+
=item B<lockfile="PATH">
Sets the path to the lock file used by xl to serialise certain
diff --git a/tools/examples/xl.conf b/tools/examples/xl.conf
index ebf057c..28ab796 100644
--- a/tools/examples/xl.conf
+++ b/tools/examples/xl.conf
@@ -15,3 +15,8 @@
# first block device to be used for temporary VM disk mounts
#blkdev_start="xvda"
+
+# default option to run hotplug scripts from xl
+# if disabled the old behaviour will be used, and hotplug scripts will be
+# launched by udev.
+#run_hotplug_scripts=1
diff --git a/tools/libxl/libxl_create.c b/tools/libxl/libxl_create.c
index 274f5d4..d47d1ea 100644
--- a/tools/libxl/libxl_create.c
+++ b/tools/libxl/libxl_create.c
@@ -404,7 +404,7 @@ int libxl__domain_make(libxl__gc *gc, libxl_domain_create_info *info,
uint32_t *domid)
{
libxl_ctx *ctx = libxl__gc_owner(gc);
- int flags, ret, rc;
+ int flags, ret, rc, nb_vm;
char *uuid_string;
char *dom_path, *vm_path, *libxl_path;
struct xs_permissions roperm[2];
@@ -525,6 +525,40 @@ retry_transaction:
libxl__sprintf(gc, "%s/hvmloader/generation-id-address", dom_path),
rwperm, ARRAY_SIZE(rwperm));
+ if (libxl_list_vm(ctx, &nb_vm) < 0) {
+ LOG(ERROR, "cannot get number of running guests");
+ rc = ERROR_FAIL;
+ goto out;
+ }
+
+ int hotplug_setting = libxl__hotplug_settings(gc, t);
+ if (hotplug_setting < 0) {
+ LOG(ERROR, "unable to get current hotplug scripts execution setting");
+ rc = ERROR_FAIL;
+ goto out;
+ }
+ if (libxl_defbool_val(info->run_hotplug_scripts) != hotplug_setting &&
+ (nb_vm - 1)) {
+ LOG(ERROR, "cannot change hotplug execution option once set, "
+ "please shutdown all guests before changing it");
+ rc = ERROR_FAIL;
+ goto out;
+ }
+
+ if (libxl_defbool_val(info->run_hotplug_scripts)) {
+ rc = libxl__xs_write(gc, t, DISABLE_UDEV_PATH, "1");
+ if (rc) {
+ LOGE(ERROR, "unable to write %s = 1", DISABLE_UDEV_PATH);
+ goto out;
+ }
+ } else {
+ rc = xs_rm(ctx->xsh, t, DISABLE_UDEV_PATH);
+ if (rc) {
+ LOGE(ERROR, "unable to delete %s", DISABLE_UDEV_PATH);
+ goto out;
+ }
+ }
+
xs_write(ctx->xsh, t, libxl__sprintf(gc, "%s/uuid", vm_path), uuid_string, strlen(uuid_string));
xs_write(ctx->xsh, t, libxl__sprintf(gc, "%s/name", vm_path), info->name, strlen(info->name));
diff --git a/tools/libxl/libxl_internal.c b/tools/libxl/libxl_internal.c
index 8139520..bc56f21 100644
--- a/tools/libxl/libxl_internal.c
+++ b/tools/libxl/libxl_internal.c
@@ -346,6 +346,25 @@ libxl_device_model_version libxl__device_model_version_running(libxl__gc *gc,
return value;
}
+int libxl__hotplug_settings(libxl__gc *gc, xs_transaction_t t)
+{
+ int rc = 0;
+ char *val;
+
+ val = libxl__xs_read(gc, t, DISABLE_UDEV_PATH);
+ if (!val && errno != ENOENT) {
+ LOGE(ERROR, "cannot read %s from xenstore", DISABLE_UDEV_PATH);
+ rc = ERROR_FAIL;
+ goto out;
+ }
+ if (!val) val = "0";
+
+ rc = !!atoi(val);
+
+out:
+ return rc;
+}
+
/*
* Local variables:
* mode: C
diff --git a/tools/libxl/libxl_internal.h b/tools/libxl/libxl_internal.h
index 1d4726b..1350ba9 100644
--- a/tools/libxl/libxl_internal.h
+++ b/tools/libxl/libxl_internal.h
@@ -88,6 +88,7 @@
#define STUBDOM_CONSOLE_SERIAL 3
#define STUBDOM_SPECIAL_CONSOLES 3
#define TAP_DEVICE_SUFFIX "-emu"
+#define DISABLE_UDEV_PATH "libxl/disable_udev"
#define ARRAY_SIZE(a) (sizeof(a) / sizeof(a[0]))
@@ -1415,6 +1416,8 @@ _hidden libxl__json_object *libxl__json_parse(libxl__gc *gc, const char *s);
_hidden libxl_device_model_version
libxl__device_model_version_running(libxl__gc *gc, uint32_t domid);
+/* Check how executes hotplug script currently */
+int libxl__hotplug_settings(libxl__gc *gc, xs_transaction_t t);
/*
* Calling context and GC for event-generating functions:
diff --git a/tools/libxl/libxl_types.idl b/tools/libxl/libxl_types.idl
index b727abb..1ede19e 100644
--- a/tools/libxl/libxl_types.idl
+++ b/tools/libxl/libxl_types.idl
@@ -221,6 +221,7 @@ libxl_domain_create_info = Struct("domain_create_info",[
("xsdata", libxl_key_value_list),
("platformdata", libxl_key_value_list),
("poolid", uint32),
+ ("run_hotplug_scripts",libxl_defbool),
], dir=DIR_IN)
MemKB = UInt(64, init_val = "LIBXL_MEMKB_DEFAULT")
diff --git a/tools/libxl/xl.c b/tools/libxl/xl.c
index a5ada03..460a6df 100644
--- a/tools/libxl/xl.c
+++ b/tools/libxl/xl.c
@@ -39,6 +39,7 @@ int dryrun_only;
int force_execution;
int autoballoon = 1;
char *blkdev_start;
+libxl_defbool run_hotplug_scripts;
char *lockfile;
char *default_vifscript = NULL;
char *default_bridge = NULL;
@@ -70,6 +71,9 @@ static void parse_global_config(const char *configfile,
if (!xlu_cfg_get_long (config, "autoballoon", &l, 0))
autoballoon = l;
+ libxl_defbool_setdefault(&run_hotplug_scripts, true);
+ xlu_cfg_get_defbool(config, "run_hotplug_scripts", &run_hotplug_scripts, 0);
+
if (!xlu_cfg_get_string (config, "lockfile", &buf, 0))
lockfile = strdup(buf);
else {
diff --git a/tools/libxl/xl.h b/tools/libxl/xl.h
index 59556b5..fddaecb 100644
--- a/tools/libxl/xl.h
+++ b/tools/libxl/xl.h
@@ -140,6 +140,7 @@ int xl_child_pid(xlchildnum); /* returns 0 if child struct is not in use */
/* global options */
extern int autoballoon;
+extern libxl_defbool run_hotplug_scripts;
extern int dryrun_only;
extern char *lockfile;
extern char *default_vifscript;
diff --git a/tools/libxl/xl_cmdimpl.c b/tools/libxl/xl_cmdimpl.c
index 404c9c2..fd980b1 100644
--- a/tools/libxl/xl_cmdimpl.c
+++ b/tools/libxl/xl_cmdimpl.c
@@ -594,6 +594,7 @@ static void parse_config_data(const char *config_source,
}
}
+ c_info->run_hotplug_scripts = run_hotplug_scripts;
c_info->type = LIBXL_DOMAIN_TYPE_PV;
if (!xlu_cfg_get_string (config, "builder", &buf, 0) &&
!strncmp(buf, "hvm", strlen(buf)))
--
1.7.7.5 (Apple Git-26)
next prev parent reply other threads:[~2012-06-14 12:21 UTC|newest]
Thread overview: 84+ messages / expand[flat|nested] mbox.gz Atom feed top
2012-06-14 12:21 [PATCH v6 00/13] execute hotplug scripts from libxl Roger Pau Monne
2012-06-14 12:21 ` [PATCH v6 01/13] libxl: change ao_device_remove to ao_device Roger Pau Monne
2012-06-15 16:45 ` Ian Jackson
2012-06-18 8:58 ` Roger Pau Monne
2012-06-14 12:21 ` [PATCH v6 02/13] libxl: move device model creation prototypes Roger Pau Monne
2012-06-14 12:21 ` [PATCH v6 03/13] libxl: convert libxl_domain_destroy to an async op Roger Pau Monne
2012-06-21 17:34 ` Ian Jackson
2012-06-14 12:21 ` [PATCH v6 04/13] libxl: move bootloader data strucutres and prototypes Roger Pau Monne
2012-06-21 17:35 ` Ian Jackson
2012-06-14 12:21 ` [PATCH v6 05/13] libxl: convert libxl__device_disk_local_attach to an async op Roger Pau Monne
2012-06-21 17:58 ` Ian Jackson
2012-06-26 10:27 ` Roger Pau Monne
2012-07-03 15:14 ` Ian Campbell
2012-06-14 12:21 ` [PATCH v6 06/13] libxl: convert libxl_device_disk_add " Roger Pau Monne
2012-06-22 11:33 ` Ian Jackson
2012-06-26 15:04 ` Roger Pau Monne
2012-06-26 15:14 ` Roger Pau Monne
2012-06-26 17:19 ` Ian Jackson
2012-06-27 17:35 ` Roger Pau Monne
2012-06-14 12:21 ` [PATCH v6 07/13] libxl: convert libxl_device_nic_add to an async operation Roger Pau Monne
2012-06-22 11:37 ` Ian Jackson
2012-06-22 12:01 ` Ian Campbell
2012-06-26 16:17 ` Roger Pau Monne
2012-06-26 17:22 ` Ian Jackson
2012-06-28 9:53 ` Roger Pau Monne
2012-06-28 9:56 ` Ian Campbell
2012-06-28 13:30 ` Roger Pau Monne
2012-06-14 12:21 ` Roger Pau Monne [this message]
2012-07-03 8:33 ` [PATCH v6 08/13] libxl: add option to choose who executes hotplug scripts Ian Campbell
2012-06-14 12:21 ` [PATCH v6 09/13] libxl: rename _IOEMU nic type to VIF_IOEMU Roger Pau Monne
2012-06-22 11:39 ` Ian Jackson
2012-06-14 12:21 ` [PATCH v6 10/13] libxl: set nic type to VIF by default Roger Pau Monne
2012-06-22 11:40 ` Ian Jackson
2012-06-26 16:20 ` Roger Pau Monne
2012-06-26 16:58 ` Pasi Kärkkäinen
2012-06-27 8:50 ` Ian Campbell
2012-06-28 9:22 ` Roger Pau Monne
2012-06-28 9:26 ` Ian Campbell
2012-06-28 9:41 ` Roger Pau Monne
2012-06-28 9:54 ` Ian Campbell
2012-06-28 10:07 ` Roger Pau Monne
2012-06-28 10:10 ` Ian Campbell
2012-06-28 13:29 ` Roger Pau Monne
2012-06-28 9:28 ` Roger Pau Monne
2012-06-26 17:22 ` Ian Jackson
2012-06-14 12:21 ` [PATCH v6 11/13] libxl: use libxl__xs_path_cleanup on device_destroy Roger Pau Monne
2012-06-14 12:21 ` [PATCH v6 12/13] libxl: call hotplug scripts for disk devices from libxl Roger Pau Monne
2012-06-22 11:43 ` Ian Jackson
2012-06-14 12:21 ` [PATCH v6 13/13] libxl: call hotplug scripts for nic " Roger Pau Monne
2012-05-30 13:07 ` [PATCH v5 01/10] execute hotplug scripts " Roger Pau Monne
2012-05-30 13:07 ` [PATCH v5 01/10] libxl: change libxl__ao_device_remove to libxl__ao_device Roger Pau Monne
2012-06-07 10:53 ` Ian Jackson
2012-06-11 10:09 ` Roger Pau Monne
2012-05-30 13:07 ` [PATCH v5 02/10] libxl: move device model creation prototypes Roger Pau Monne
2012-05-30 13:07 ` [PATCH v5 03/10] libxl: convert libxl_domain_destroy to an async op Roger Pau Monne
2012-05-30 13:07 ` [PATCH v5 04/10] libxl: convert libxl_device_disk_add to an asyn op Roger Pau Monne
2012-06-07 11:38 ` Ian Jackson
2012-06-11 12:33 ` Roger Pau Monne
2012-06-07 14:20 ` Ian Jackson
2012-06-07 16:42 ` Roger Pau Monne
2012-06-07 16:47 ` Ian Jackson
2012-06-07 14:25 ` Ian Jackson
2012-06-07 16:55 ` Roger Pau Monne
2012-06-07 17:05 ` Ian Jackson
2012-06-07 17:07 ` Roger Pau Monne
2012-06-07 17:11 ` Ian Jackson
2012-05-30 13:07 ` [PATCH v5 05/10] libxl: convert libxl_device_nic_add to an async operation Roger Pau Monne
2012-06-07 14:26 ` Ian Jackson
2012-05-30 13:07 ` [PATCH v5 06/10] libxl: add option to choose who executes hotplug scripts Roger Pau Monne
2012-05-30 13:07 ` [PATCH v5 07/10] libxl: set nic type to VIF by default Roger Pau Monne
2012-05-30 13:07 ` [PATCH v5 08/10] libxl: call hotplug scripts for disk devices from libxl Roger Pau Monne
2012-06-07 14:40 ` Ian Jackson
2012-05-30 13:07 ` [PATCH v5 09/10] libxl: call hotplug scripts for nic " Roger Pau Monne
2012-06-07 14:48 ` Ian Jackson
2012-06-11 14:34 ` Roger Pau Monne
2012-06-22 11:47 ` [PATCH v5 09/10] libxl: call hotplug scripts for nic devices from libxl [and 1 more messages] Ian Jackson
2012-06-26 8:57 ` Roger Pau Monne
2012-05-30 13:07 ` [PATCH v5 10/10] libxl: use libxl__xs_path_cleanup on device_destroy Roger Pau Monne
2012-06-07 14:50 ` Ian Jackson
2012-07-03 8:27 ` [PATCH v6 00/13] execute hotplug scripts from libxl Ian Campbell
2012-07-03 9:19 ` Ian Campbell
2012-07-03 9:26 ` Ian Campbell
2012-07-03 12:54 ` Ian Jackson
2012-07-03 13:04 ` Ian Campbell
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=1339676475-33265-9-git-send-email-roger.pau@citrix.com \
--to=roger.pau@citrix.com \
--cc=ian.jackson@eu.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).