[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [Xen-devel] [PATCH 12/13] libxl: call hotplug scripts for disk devices from libxl



Roger Pau Monne writes ("[PATCH 12/13] libxl: call hotplug scripts for disk 
devices from libxl"):
> Since most of the needed work is already done in previous patches,
> this patch only contains the necessary code to call hotplug scripts
> for disk devices, that should be called when the device is added or
> removed from a guest.
> 
> We will chain the launch of the disk hotplug scripts after the
> device_backend_callback callback, or directly from
> libxl__initiate_device_{add,remove} if the device is already in the
> desired state.
> 
> Cc: Ian Jackson <ian.jackson@xxxxxxxxxxxxx>
> Signed-off-by: Roger Pau Monne <roger.pau@xxxxxxxxxx>
> ---
>  tools/hotplug/Linux/xen-backend.rules     |    6 +-
>  tools/hotplug/Linux/xen-hotplug-common.sh |    6 ++
>  tools/libxl/Makefile                      |    3 +-
>  tools/libxl/libxl_device.c                |   23 ++++-
>  tools/libxl/libxl_hotplug.c               |   84 +++++++++++++++++++
>  tools/libxl/libxl_internal.h              |   17 ++++
>  tools/libxl/libxl_linux.c                 |  126 
> +++++++++++++++++++++++++++++
>  7 files changed, 256 insertions(+), 9 deletions(-)
>  create mode 100644 tools/libxl/libxl_hotplug.c
> 
> diff --git a/tools/hotplug/Linux/xen-backend.rules 
> b/tools/hotplug/Linux/xen-backend.rules
> index 405387f..d55ff11 100644
> --- a/tools/hotplug/Linux/xen-backend.rules
> +++ b/tools/hotplug/Linux/xen-backend.rules
> @@ -1,11 +1,11 @@
> -SUBSYSTEM=="xen-backend", KERNEL=="tap*", RUN+="/etc/xen/scripts/blktap 
> $env{ACTION}"
> -SUBSYSTEM=="xen-backend", KERNEL=="vbd*", RUN+="/etc/xen/scripts/block 
> $env{ACTION}"
> +SUBSYSTEM=="xen-backend", KERNEL=="tap*", ENV{UDEV_CALL}="1", 
> RUN+="/etc/xen/scripts/blktap $env{ACTION}"
> +SUBSYSTEM=="xen-backend", KERNEL=="vbd*", ENV{UDEV_CALL}="1", 
> RUN+="/etc/xen/scripts/block $env{ACTION}"
>  SUBSYSTEM=="xen-backend", KERNEL=="vtpm*", RUN+="/etc/xen/scripts/vtpm 
> $env{ACTION}"
>  SUBSYSTEM=="xen-backend", KERNEL=="vif2-*", RUN+="/etc/xen/scripts/vif2 
> $env{ACTION}"
>  SUBSYSTEM=="xen-backend", KERNEL=="vif-*", ACTION=="online", 
> RUN+="/etc/xen/scripts/vif-setup online type_if=vif"
>  SUBSYSTEM=="xen-backend", KERNEL=="vif-*", ACTION=="offline", 
> RUN+="/etc/xen/scripts/vif-setup offline type_if=vif"
>  SUBSYSTEM=="xen-backend", KERNEL=="vscsi*", RUN+="/etc/xen/scripts/vscsi 
> $env{ACTION}"
> -SUBSYSTEM=="xen-backend", ACTION=="remove", 
> RUN+="/etc/xen/scripts/xen-hotplug-cleanup"
> +SUBSYSTEM=="xen-backend", ACTION=="remove", ENV{UDEV_CALL}="1", 
> RUN+="/etc/xen/scripts/xen-hotplug-cleanup"
>  KERNEL=="evtchn", NAME="xen/%k"
>  SUBSYSTEM=="xen", KERNEL=="blktap[0-9]*", NAME="xen/%k", MODE="0600"
>  SUBSYSTEM=="blktap2", KERNEL=="blktap[0-9]*", NAME="xen/blktap-2/%k", 
> MODE="0600"
> diff --git a/tools/hotplug/Linux/xen-hotplug-common.sh 
> b/tools/hotplug/Linux/xen-hotplug-common.sh
> index 8f6557d..4a7bc73 100644
> --- a/tools/hotplug/Linux/xen-hotplug-common.sh
> +++ b/tools/hotplug/Linux/xen-hotplug-common.sh
> @@ -15,6 +15,12 @@
>  # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
>  #
> 
> +# Hack to prevent the execution of hotplug scripts from udev if the domain
> +# has been launched from libxl
> +if [ -n "${UDEV_CALL}" ] && \
> +   xenstore-read "libxl/disable_udev" >/dev/null 2>&1; then
> +    exit 0
> +fi
> 
>  dir=$(dirname "$0")
>  . "$dir/hotplugpath.sh"
> diff --git a/tools/libxl/Makefile b/tools/libxl/Makefile
> index 5d9227e..9abadff 100644
> --- a/tools/libxl/Makefile
> +++ b/tools/libxl/Makefile
> @@ -66,7 +66,8 @@ LIBXL_OBJS = flexarray.o libxl.o libxl_create.o libxl_dm.o 
> libxl_pci.o \
>                         libxl_dom.o libxl_exec.o libxl_xshelp.o 
> libxl_device.o \
>                         libxl_internal.o libxl_utils.o libxl_uuid.o \
>                         libxl_json.o libxl_aoutils.o \
> -                       libxl_qmp.o libxl_event.o libxl_fork.o $(LIBXL_OBJS-y)
> +                       libxl_qmp.o libxl_event.o libxl_fork.o 
> libxl_hotplug.o \
> +                       $(LIBXL_OBJS-y)
>  LIBXL_OBJS += _libxl_types.o libxl_flask.o _libxl_types_internal.o
> 
>  $(LIBXL_OBJS): CFLAGS += $(CFLAGS_libxenctrl) $(CFLAGS_libxenguest) 
> $(CFLAGS_libxenstore) $(CFLAGS_libblktapctl) -include 
> $(XEN_ROOT)/tools/config.h
> diff --git a/tools/libxl/libxl_device.c b/tools/libxl/libxl_device.c
> index 6b0ce95..0b7beb7 100644
> --- a/tools/libxl/libxl_device.c
> +++ b/tools/libxl/libxl_device.c
> @@ -393,6 +398,11 @@ void libxl__device_disk_add(libxl__egc *egc, uint32_t 
> dom> @@ -760,7 +770,7 @@ out_fail:
> 
>  out_ok:
>      assert(!rc);
> -    aorm->callback(egc, aorm);
> +    libxl__device_hotplug(egc, aorm);

Where does the name "aorm" come from here ?  It doesn't seem to
involve removal.

> +int libxl__hotplug_launch(libxl__gc *gc, libxl__ao_device *aorm,

Ie shouldn't that be "aodev" or something ?

> +/* Hotplug scripts helpers */
> +
> +static void cleanup(libxl__gc *gc, libxl__ao_device *aorm)
> +{
> +    if (!aorm) return;
> +    libxl__ev_time_deregister(gc, &aorm->ev);
> +}
> +
> +static void callback(libxl__egc *egc, libxl__ev_child *child,
> +                                    pid_t pid, int status)
> +{
> +    libxl__ao_device *aorm = CONTAINER_OF(child, *aorm, child);
> +    STATE_AO_GC(aorm->ao);
> +
> +    cleanup(gc, aorm);
> +
> +    if (status) {
> +        libxl_report_child_exitstatus(CTX, aorm->rc ? LIBXL__LOG_ERROR
> +                                                    : LIBXL__LOG_WARNING,
> +                                      aorm->what, pid, status);
> +        aorm->rc = ERROR_FAIL;
> +    }
> +    aorm->callback(egc, aorm);
> +}

This structure where half of the event handling is in the common code
and half of it is in libxl_linux.c is not really appropriate.  It
means that the hotplug event machinery is not all in the same place.

Can you make an interface to libxl_linux.c which is fully synchronous,
so that libxl_linux.c simply says whether to run the script or not ?

Eg
   libxl__get_hotplug_script_info(libxl__egc *, libxl__device *dev,
                                    char ***args, char ***env);

Ian.

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


 


Rackspace

Lists.xenproject.org is hosted with RackSpace, monitoring our
servers 24x7x365 and backed by RackSpace's Fanatical Support®.