Roger Pau Monne
2011-Oct-14 13:35 UTC
[Xen-devel] [PATCH 0 of 9] Call hotplug scripts from libxl for NetBSD
This patch adds support for NetBSD to call hotplug scripts directly from libxl, instead of relying on xenbackendd. Also some patches contain general bug fixes that apply to both NetBSD and Linux. Currently Linux hotplug script call functions are empty, so Linux continues to use udev rules to call hotplug scripts. This patch should be applied after Ian Campbell''s "libxl: rationalise libxl_device_* APIs" series. Please review, Roger. _______________________________________________ Xen-devel mailing list Xen-devel@lists.xensource.com http://lists.xensource.com/xen-devel
Roger Pau Monne
2011-Oct-14 13:35 UTC
[Xen-devel] [PATCH 1 of 9] xenbackendd: pass type of block device to hotplug script
# HG changeset patch # User Roger Pau Monne <roger.pau@entel.upc.edu> # Date 1317386335 -7200 # Node ID deb93254ad05ffa13caa64f0159800f04c82666b # Parent c9c228ec718a4c2d22b58ce306f269868af0d12f xenbackendd: pass type of block device to hotplug script Pass the type of block device to attach to the block script instead of reading it from xenstore, since new Xen versions don''t make a difference between a block device or an image. Signed-off-by: Roger Pau Monne <roger.pau@entel.upc.edu> diff -r c9c228ec718a -r deb93254ad05 tools/hotplug/NetBSD/block --- a/tools/hotplug/NetBSD/block Thu Oct 13 10:52:46 2011 +0100 +++ b/tools/hotplug/NetBSD/block Fri Sep 30 14:38:55 2011 +0200 @@ -19,7 +19,7 @@ error() { xpath=$1 xstatus=$2 -xtype=$(xenstore-read "$xpath/type") +xtype=$3 xparams=$(xenstore-read "$xpath/params") case $xstatus in diff -r c9c228ec718a -r deb93254ad05 tools/xenbackendd/xenbackendd.c --- a/tools/xenbackendd/xenbackendd.c Thu Oct 13 10:52:46 2011 +0100 +++ b/tools/xenbackendd/xenbackendd.c Fri Sep 30 14:38:55 2011 +0200 @@ -89,15 +89,15 @@ dodebug(const char *fmt, ...) } static void -doexec(const char *cmd, const char *arg1, const char *arg2) +doexec(const char *cmd, const char *arg1, const char *arg2, const char *arg3) { - dodebug("exec %s %s %s", cmd, arg1, arg2); + dodebug("exec %s %s %s %s", cmd, arg1, arg2, arg3); switch(vfork()) { case -1: dolog(LOG_ERR, "can''t vfork: %s", strerror(errno)); break; case 0: - execl(cmd, cmd, arg1, arg2, NULL); + execl(cmd, cmd, arg1, arg2, arg3, NULL); dolog(LOG_ERR, "can''t exec %s: %s", cmd, strerror(errno)); exit(EXIT_FAILURE); /* NOTREACHED */ @@ -145,11 +145,14 @@ xen_setup(void) int main(int argc, char * const argv[]) { + struct stat stab; char **vec; unsigned int num; char *s; int state; char *sstate; + char *stype; + char *params; char *p; char buf[80]; int type; @@ -297,11 +300,38 @@ main(int argc, char * const argv[]) strerror(errno)); goto next2; } - doexec(s, vec[XS_WATCH_PATH], sstate); + doexec(s, vec[XS_WATCH_PATH], sstate, NULL); break; case DEVTYPE_VBD: - doexec(vbd_script, vec[XS_WATCH_PATH], sstate); + /* check if given file is a block device or a raw image */ + snprintf(buf, sizeof(buf), "%s/params", vec[XS_WATCH_PATH]); + params = xs_read(xs, XBT_NULL, buf, 0); + if(params == NULL) { + dolog(LOG_ERR, + "Failed to read %s (%s)", buf, strerror(errno)); + goto next2; + } + if (stat(params, &stab) < 0) { + dolog(LOG_ERR, + "Failed to get info about %s (%s)", params, + strerror(errno)); + goto next3; + } + stype = NULL; + if (S_ISBLK(stab.st_mode)) + stype = "phy"; + if (S_ISREG(stab.st_mode)) + stype = "file"; + if (stype == NULL) { + dolog(LOG_ERR, + "Failed to attach %s (not a block device or raw image)", + params, strerror(errno)); + goto next3; + } + doexec(vbd_script, vec[XS_WATCH_PATH], sstate, stype); +next3: + free(params); break; default: _______________________________________________ Xen-devel mailing list Xen-devel@lists.xensource.com http://lists.xensource.com/xen-devel
Roger Pau Monne
2011-Oct-14 13:35 UTC
[Xen-devel] [PATCH 2 of 9] libxl: fix for libxl not waiting for devices to disconnect
# HG changeset patch # User Roger Pau Monne <roger.pau@entel.upc.edu> # Date 1317386335 -7200 # Node ID 873e4a1309ce5da0305611ce2e2b460df052019b # Parent deb93254ad05ffa13caa64f0159800f04c82666b libxl: fix for libxl not waiting for devices to disconnect libxl was ignoring the timeout and the number of devices to wait before destroying them. Signed-off-by: Roger Pau Monne <roger.pau@entel.upc.edu> diff -r deb93254ad05 -r 873e4a1309ce tools/libxl/libxl_device.c --- a/tools/libxl/libxl_device.c Fri Sep 30 14:38:55 2011 +0200 +++ b/tools/libxl/libxl_device.c Fri Sep 30 14:38:55 2011 +0200 @@ -391,6 +391,9 @@ static int wait_for_dev_destroy(libxl__g } free(l1); } + } else { + /* timeout reached */ + rc = 0; } return rc; } @@ -531,7 +534,7 @@ int libxl__devices_destroy(libxl__gc *gc tv.tv_usec = 0; while (n_watches > 0) { if (wait_for_dev_destroy(gc, &tv)) { - break; + continue; } else { n_watches--; } _______________________________________________ Xen-devel mailing list Xen-devel@lists.xensource.com http://lists.xensource.com/xen-devel
Roger Pau Monne
2011-Oct-14 13:35 UTC
[Xen-devel] [PATCH 3 of 9] libxl: add support for image files for NetBSD
# HG changeset patch # User Roger Pau Monne <roger.pau@entel.upc.edu> # Date 1317386335 -7200 # Node ID 0865f90beac01012dd0ff4a86b07d8fb62575163 # Parent 873e4a1309ce5da0305611ce2e2b460df052019b libxl: add support for image files for NetBSD Created a helper function to detect if the OS is capable of using image files as phy backends. Create two OS specific files, and changed the Makefile to choose the correct one at compile time. Signed-off-by: Roger Pau Monne <roger.pau@entel.upc.edu> diff -r 873e4a1309ce -r 0865f90beac0 tools/libxl/Makefile --- a/tools/libxl/Makefile Fri Sep 30 14:38:55 2011 +0200 +++ b/tools/libxl/Makefile Fri Sep 30 14:38:55 2011 +0200 @@ -31,6 +31,8 @@ LIBXL_OBJS-y += libxl_noblktap2.o endif LIBXL_OBJS-$(CONFIG_X86) += libxl_cpuid.o LIBXL_OBJS-$(CONFIG_IA64) += libxl_nocpuid.o +LIBXL_OBJS-$(CONFIG_NetBSD) += libxl_phybackend.o +LIBXL_OBJS-$(CONFIG_Linux) += libxl_nophybackend.o LIBXL_LIBS += -lyajl diff -r 873e4a1309ce -r 0865f90beac0 tools/libxl/libxl_device.c --- a/tools/libxl/libxl_device.c Fri Sep 30 14:38:55 2011 +0200 +++ b/tools/libxl/libxl_device.c Fri Sep 30 14:38:55 2011 +0200 @@ -138,15 +138,14 @@ static int disk_try_backend(disk_try_bac a->disk->format == LIBXL_DISK_FORMAT_EMPTY)) { goto bad_format; } - if (a->disk->format != LIBXL_DISK_FORMAT_EMPTY && - !S_ISBLK(a->stab.st_mode)) { - LIBXL__LOG(ctx, LIBXL__LOG_DEBUG, "Disk vdev=%s, backend phy" - " unsuitable as phys path not a block device", - a->disk->vdev); - return 0; - } - return backend; + if (try_phy_backend(a->stab.st_mode)) + return backend; + + LIBXL__LOG(ctx, LIBXL__LOG_DEBUG, "Disk vdev=%s, backend phy" + " unsuitable as phys path not a block device", + a->disk->vdev); + return 0; case LIBXL_DISK_BACKEND_TAP: if (!libxl__blktap_enabled(a->gc)) { diff -r 873e4a1309ce -r 0865f90beac0 tools/libxl/libxl_internal.h --- a/tools/libxl/libxl_internal.h Fri Sep 30 14:38:55 2011 +0200 +++ b/tools/libxl/libxl_internal.h Fri Sep 30 14:38:55 2011 +0200 @@ -247,6 +247,9 @@ _hidden int libxl__device_destroy(libxl_ _hidden int libxl__devices_destroy(libxl__gc *gc, uint32_t domid, int force); _hidden int libxl__wait_for_backend(libxl__gc *gc, char *be_path, char *state); +/* OS dependant helper function */ +_hidden int try_phy_backend(mode_t st_mode); + /* from libxl_pci */ _hidden int libxl__device_pci_add(libxl__gc *gc, uint32_t domid, libxl_device_pci *pcidev, int starting); diff -r 873e4a1309ce -r 0865f90beac0 tools/libxl/libxl_nophybackend.c --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/tools/libxl/libxl_nophybackend.c Fri Sep 30 14:38:55 2011 +0200 @@ -0,0 +1,27 @@ +/* + * Copyright (C) 2011 + * Author Roger Pau Monne <roger.pau@entel.upc.edu> + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License as published + * by the Free Software Foundation; version 2.1 only. with the special + * exception on linking described in file LICENSE. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License for more details. + */ + +#include <sys/stat.h> + +#include "libxl_internal.h" + +int try_phy_backend(mode_t st_mode) +{ + if (!S_ISBLK(st_mode)) { + return 0; + } + + return 1; +} diff -r 873e4a1309ce -r 0865f90beac0 tools/libxl/libxl_phybackend.c --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/tools/libxl/libxl_phybackend.c Fri Sep 30 14:38:55 2011 +0200 @@ -0,0 +1,26 @@ +/* + * Copyright (C) 2011 + * Author Roger Pau Monne <roger.pau@entel.upc.edu> + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License as published + * by the Free Software Foundation; version 2.1 only. with the special + * exception on linking described in file LICENSE. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License for more details. + */ + +#include <sys/stat.h> + +#include "libxl_internal.h" + +int try_phy_backend(mode_t st_mode) +{ + if (S_ISREG(st_mode) || S_ISBLK(st_mode)) + return 1; + + return 0; +} _______________________________________________ Xen-devel mailing list Xen-devel@lists.xensource.com http://lists.xensource.com/xen-devel
Roger Pau Monne
2011-Oct-14 13:35 UTC
[Xen-devel] [PATCH 4 of 9] libxl: add libxl__forkexec to execute hotplug scripts
# HG changeset patch # User Roger Pau Monne <roger.pau@entel.upc.edu> # Date 1318592310 -7200 # Node ID 0235e192a519e29ac3d77e91fe59b38e6a6f06ef # Parent 0865f90beac01012dd0ff4a86b07d8fb62575163 libxl: add libxl__forkexec to execute hotplug scripts Add a new function to libxl_exec that performs a vfork and executes the passed arguments using libxl__exec. Signed-off-by: Roger Pau Monne <roger.pau@entel.upc.edu> diff -r 0865f90beac0 -r 0235e192a519 tools/libxl/libxl_exec.c --- a/tools/libxl/libxl_exec.c Fri Sep 30 14:38:55 2011 +0200 +++ b/tools/libxl/libxl_exec.c Fri Oct 14 13:38:30 2011 +0200 @@ -308,3 +308,25 @@ int libxl__spawn_check(libxl__gc *gc, vo for_spawn->intermediate = 0; return ERROR_FAIL; } + +int libxl__forkexec(libxl__gc *gc, int stdinfd, int stdoutfd, + int stderrfd, char **args) +{ + libxl_ctx *ctx = libxl__gc_owner(gc); + + switch (vfork()) { + case -1: + LIBXL__LOG_ERRNO(ctx, LIBXL__LOG_ERROR, "failed to vfork\n"); + return -1; + case 0: + libxl__exec(stdinfd, stdoutfd, stderrfd, args[0], args); + LIBXL__LOG_ERRNO(ctx, LIBXL__LOG_ERROR, "failed to execute %s\n", + args[0]); + exit(EXIT_FAILURE); + break; + default: + wait(NULL); + break; + } + return 0; +} diff -r 0865f90beac0 -r 0235e192a519 tools/libxl/libxl_internal.h --- a/tools/libxl/libxl_internal.h Fri Sep 30 14:38:55 2011 +0200 +++ b/tools/libxl/libxl_internal.h Fri Oct 14 13:38:30 2011 +0200 @@ -342,6 +342,8 @@ _hidden int libxl__spawn_check(libxl__gc _hidden void libxl__exec(int stdinfd, int stdoutfd, int stderrfd, const char *arg0, char **args); // logs errors, never returns +_hidden int libxl__forkexec(libxl__gc *gc, int stdinfd, int stdoutfd, + int stderrfd, char **args); _hidden void libxl__log_child_exitstatus(libxl__gc *gc, const char *what, pid_t pid, int status); _______________________________________________ Xen-devel mailing list Xen-devel@lists.xensource.com http://lists.xensource.com/xen-devel
Roger Pau Monne
2011-Oct-14 13:35 UTC
[Xen-devel] [PATCH 5 of 9] libxl: wait for devices to initialize upon addition to the domain
# HG changeset patch # User Roger Pau Monne <roger.pau@entel.upc.edu> # Date 1318592310 -7200 # Node ID d14479efe33c3955dcf41783a1b02c8d2bb572e6 # Parent 0235e192a519e29ac3d77e91fe59b38e6a6f06ef libxl: wait for devices to initialize upon addition to the domain. Block waiting for devices to initialize (switch to state 2). Signed-off-by: Roger Pau Monne <roger.pau@entel.upc.edu> diff -r 0235e192a519 -r d14479efe33c tools/libxl/libxl.c --- a/tools/libxl/libxl.c Fri Oct 14 13:38:30 2011 +0200 +++ b/tools/libxl/libxl.c Fri Oct 14 13:38:30 2011 +0200 @@ -1070,6 +1070,11 @@ int libxl_device_disk_add(libxl_ctx *ctx libxl__xs_kvs_of_flexarray(&gc, back, back->count), libxl__xs_kvs_of_flexarray(&gc, front, front->count)); + if (libxl__wait_for_device_initialization(&gc, &device) < 0) { + rc = -1; + goto out_free; + } + rc = 0; out_free: @@ -1513,7 +1518,11 @@ int libxl_device_nic_add(libxl_ctx *ctx, libxl__xs_kvs_of_flexarray(&gc, back, back->count), libxl__xs_kvs_of_flexarray(&gc, front, front->count)); - /* FIXME: wait for plug */ + if (libxl__wait_for_device_initialization(&gc, &device) < 0) { + rc = -1; + goto out_free; + } + rc = 0; out_free: flexarray_free(back); diff -r 0235e192a519 -r d14479efe33c tools/libxl/libxl_device.c --- a/tools/libxl/libxl_device.c Fri Oct 14 13:38:30 2011 +0200 +++ b/tools/libxl/libxl_device.c Fri Oct 14 13:38:30 2011 +0200 @@ -366,6 +366,38 @@ int libxl__device_disk_dev_number(const return -1; } +int libxl__wait_for_device_initialization(libxl__gc *gc, libxl__device *device) +{ + libxl_ctx *ctx = libxl__gc_owner(gc); + char *be_path = libxl__device_backend_path(gc, device); + char *state_path = libxl__sprintf(gc, "%s/state", be_path); + char *state = libxl__xs_read(gc, XBT_NULL, state_path); + int rc = -1; + char **l1 = NULL; + unsigned int n; + + if (atoi(state) == 2) { + rc = 0; + goto out; + } + + xs_watch(ctx->xsh, state_path, be_path); + while (atoi(state) != 2) { + l1 = xs_read_watch(ctx->xsh, &n); + if (l1 == NULL) { + goto out; + } + state = libxl__xs_read(gc, XBT_NULL, l1[XS_WATCH_PATH]); + if (state == NULL) { + goto out; + } + } + rc = 0; + +out: + return rc; +} + static int wait_for_dev_destroy(libxl__gc *gc, struct timeval *tv) { libxl_ctx *ctx = libxl__gc_owner(gc); diff -r 0235e192a519 -r d14479efe33c tools/libxl/libxl_internal.h --- a/tools/libxl/libxl_internal.h Fri Oct 14 13:38:30 2011 +0200 +++ b/tools/libxl/libxl_internal.h Fri Oct 14 13:38:30 2011 +0200 @@ -231,7 +231,7 @@ _hidden int libxl__device_disk_set_backe _hidden int libxl__device_physdisk_major_minor(const char *physpath, int *major, int *minor); _hidden int libxl__device_disk_dev_number(const char *virtpath, int *pdisk, int *ppartition); - +_hidden int libxl__wait_for_device_initialization(libxl__gc *gc, libxl__device *device); _hidden int libxl__device_console_add(libxl__gc *gc, uint32_t domid, libxl_device_console *console, libxl__domain_build_state *state); _______________________________________________ Xen-devel mailing list Xen-devel@lists.xensource.com http://lists.xensource.com/xen-devel
Roger Pau Monne
2011-Oct-14 13:35 UTC
[Xen-devel] [PATCH 6 of 9] libxl: execute hotplug scripts directly from libxl
# HG changeset patch # User Roger Pau Monne <roger.pau@entel.upc.edu> # Date 1317386335 -7200 # Node ID 8800c37a5acba9e95ac8005ea123d3e9954be001 # Parent d14479efe33c3955dcf41783a1b02c8d2bb572e6 libxl: execute hotplug scripts directly from libxl. Added the necessary handlers to execute hotplug scripts when necessary from libxl. Split NetBSD from Linux hotplug calls into two separate files, because parameters for hotplug scripts are different. Linux has empty functions, since the calling of hotplug scripts is still done using udev. Signed-off-by: Roger Pau Monne <roger.pau@entel.upc.edu> diff -r d14479efe33c -r 8800c37a5acb tools/libxl/Makefile --- a/tools/libxl/Makefile Fri Oct 14 13:38:30 2011 +0200 +++ b/tools/libxl/Makefile Fri Sep 30 14:38:55 2011 +0200 @@ -33,6 +33,8 @@ LIBXL_OBJS-$(CONFIG_X86) += libxl_cpuid. LIBXL_OBJS-$(CONFIG_IA64) += libxl_nocpuid.o LIBXL_OBJS-$(CONFIG_NetBSD) += libxl_phybackend.o LIBXL_OBJS-$(CONFIG_Linux) += libxl_nophybackend.o +LIBXL_OBJS-$(CONFIG_NetBSD) += hotplug_netbsd.o +LIBXL_OBJS-$(CONFIG_Linux) += hotplug_linux.o LIBXL_LIBS += -lyajl diff -r d14479efe33c -r 8800c37a5acb tools/libxl/hotplug_linux.c --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/tools/libxl/hotplug_linux.c Fri Sep 30 14:38:55 2011 +0200 @@ -0,0 +1,26 @@ +/* + * Copyright (C) 2011 + * Author Roger Pau Monne <roger.pau@entel.upc.edu> + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License as published + * by the Free Software Foundation; version 2.1 only. with the special + * exception on linking described in file LICENSE. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License for more details. + */ + +#include "libxl_internal.h" + +int libxl_disk_hotplug(libxl__gc *gc, libxl__device *dev) +{ + return 0; +} + +int libxl_nic_hotplug_connect(libxl__gc *gc, libxl__device *dev) +{ + return 0; +} diff -r d14479efe33c -r 8800c37a5acb tools/libxl/hotplug_netbsd.c --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/tools/libxl/hotplug_netbsd.c Fri Sep 30 14:38:55 2011 +0200 @@ -0,0 +1,129 @@ +/* + * Copyright (C) 2011 + * Author Roger Pau Monne <roger.pau@entel.upc.edu> + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License as published + * by the Free Software Foundation; version 2.1 only. with the special + * exception on linking described in file LICENSE. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License for more details. + */ + +#include <sys/stat.h> + +#include "libxl_internal.h" + +int libxl__disk_hotplug(libxl__gc *gc, libxl__device *dev) +{ + libxl_ctx *ctx = libxl__gc_owner(gc); + char *be_path = libxl__device_backend_path(gc, dev); + struct stat stab; + char *stype, *sstate, *script, *params; + char **args; + int nr = 0; + flexarray_t *f_args; + + script = libxl__xs_read(gc, XBT_NULL, libxl__sprintf(gc, "%s/%s", be_path, "script")); + if (!script) { + LIBXL__LOG(ctx, LIBXL__LOG_ERROR, "Unable to read script from %s", + be_path); + return -1; + } + + params = libxl__xs_read(gc, XBT_NULL, libxl__sprintf(gc, "%s/%s", be_path, "params")); + if (!params) + return -1; + + sstate = libxl__xs_read(gc, XBT_NULL, libxl__sprintf(gc, "%s/%s", be_path, "state")); + if (!sstate) { + LIBXL__LOG(ctx, LIBXL__LOG_ERROR, "Unable to read state from %s", + be_path); + return -1; + } + + if (stat(params, &stab) < 0) { + LIBXL__LOG_ERRNO(ctx, LIBXL__LOG_ERROR, "failed to get stat info\n"); + return -1; + } + if (S_ISBLK(stab.st_mode)) + stype = "phy"; + if (S_ISREG(stab.st_mode)) + stype = "file"; + if (stype == NULL) { + LIBXL__LOG(ctx, LIBXL__LOG_ERROR, "Not block or regular file"); + return -1; + } + + f_args = flexarray_make(5, 1); + if (!f_args) + return -1; + + flexarray_set(f_args, nr++, script); + flexarray_set(f_args, nr++, be_path); + flexarray_set(f_args, nr++, sstate); + flexarray_set(f_args, nr++, stype); + flexarray_set(f_args, nr++, NULL); + + args = (char **) flexarray_contents(f_args); + + LIBXL__LOG(ctx, LIBXL__LOG_DEBUG, "Calling disk hotplug script: %s %s %s %s", + args[0], args[1], args[2], args[3]); + if (libxl__forkexec(gc, -1, -1, -1, args) < 0) { + free(args); + return -1; + } + + free(args); + return 0; +} + +int libxl__nic_hotplug(libxl__gc *gc, libxl__device *dev) +{ + libxl_ctx *ctx = libxl__gc_owner(gc); + char *be_path = libxl__device_backend_path(gc, dev); + char *sstate, *script; + char **args; + int nr = 0; + int rc = -1; + flexarray_t *f_args; + + script = libxl__xs_read(gc, XBT_NULL, libxl__sprintf(gc, "%s/%s", be_path, "script")); + if (!script) { + LIBXL__LOG(ctx, LIBXL__LOG_ERROR, "Unable to read script from %s", + be_path); + return -1; + } + + sstate = libxl__xs_read(gc, XBT_NULL, libxl__sprintf(gc, "%s/%s", be_path, "state")); + if (!sstate) { + LIBXL__LOG(ctx, LIBXL__LOG_ERROR, "Unable to read state from %s", + be_path); + return -1; + } + + f_args = flexarray_make(4, 1); + if (!f_args) + return -1; + + flexarray_set(f_args, nr++, script); + flexarray_set(f_args, nr++, be_path); + flexarray_set(f_args, nr++, sstate); + flexarray_set(f_args, nr++, NULL); + + args = (char **) flexarray_contents(f_args); + + LIBXL__LOG(ctx, LIBXL__LOG_DEBUG, "Calling nic hotplug script: %s %s %s", + args[0], args[1], args[2]); + if (libxl__forkexec(gc, -1, -1, -1, args) < 0) { + goto out; + } + rc = 0; + +out: + free(args); + return rc; +} diff -r d14479efe33c -r 8800c37a5acb tools/libxl/libxl.c --- a/tools/libxl/libxl.c Fri Oct 14 13:38:30 2011 +0200 +++ b/tools/libxl/libxl.c Fri Sep 30 14:38:55 2011 +0200 @@ -1056,6 +1056,10 @@ int libxl_device_disk_add(libxl_ctx *ctx flexarray_append(back, disk->readwrite ? "w" : "r"); flexarray_append(back, "device-type"); flexarray_append(back, disk->is_cdrom ? "cdrom" : "disk"); + flexarray_append(back, "script"); + flexarray_append(back, libxl__sprintf(&gc, "%s/%s", + libxl_xen_script_dir_path(), + "block")); flexarray_append(front, "backend-id"); flexarray_append(front, libxl__sprintf(&gc, "%d", disk->backend_domid)); @@ -1075,6 +1079,14 @@ int libxl_device_disk_add(libxl_ctx *ctx goto out_free; } + /* Call hotplug scripts to attach device */ + if (libxl__device_execute_hotplug(&gc, &device) < 0) { + LIBXL__LOG(ctx, LIBXL__LOG_ERROR, "unable to execute hotplug script for disk: %s\n", + disk->pdev_path); + rc = -1; + goto out_free; + } + rc = 0; out_free: @@ -1523,6 +1535,14 @@ int libxl_device_nic_add(libxl_ctx *ctx, goto out_free; } + /* Call hotplug scripts to attach device */ + if (libxl__device_execute_hotplug(&gc, &device) < 0) { + LIBXL__LOG(ctx, LIBXL__LOG_ERROR, "unable to execute hotplug script for nic: %s\n", + nic->ifname); + rc = -1; + goto out_free; + } + rc = 0; out_free: flexarray_free(back); diff -r d14479efe33c -r 8800c37a5acb tools/libxl/libxl_device.c --- a/tools/libxl/libxl_device.c Fri Oct 14 13:38:30 2011 +0200 +++ b/tools/libxl/libxl_device.c Fri Sep 30 14:38:55 2011 +0200 @@ -68,6 +68,24 @@ int libxl__parse_backend_path(libxl__gc return libxl__device_kind_from_string(strkind, &dev->backend_kind); } +int libxl__device_execute_hotplug(libxl__gc *gc, libxl__device *dev) +{ + int rc = 0; + + switch(dev->kind) { + case LIBXL__DEVICE_KIND_VIF: + rc = libxl__nic_hotplug(gc, dev); + break; + case LIBXL__DEVICE_KIND_VBD: + rc = libxl__disk_hotplug(gc, dev); + break; + default: + break; + } + + return rc; +} + int libxl__device_generic_add(libxl__gc *gc, libxl__device *device, char **bents, char **fents) { @@ -405,6 +423,7 @@ static int wait_for_dev_destroy(libxl__g unsigned int n; fd_set rfds; char **l1 = NULL; + libxl__device dev; rc = 1; nfds = xs_fileno(ctx->xsh) + 1; @@ -416,6 +435,8 @@ static int wait_for_dev_destroy(libxl__g char *state = libxl__xs_read(gc, XBT_NULL, l1[XS_WATCH_PATH]); if (!state || atoi(state) == 6) { xs_unwatch(ctx->xsh, l1[0], l1[1]); + libxl__parse_backend_path(gc, l1[XS_WATCH_PATH], &dev); + libxl__device_execute_hotplug(gc, &dev); xs_rm(ctx->xsh, XBT_NULL, l1[XS_WATCH_TOKEN]); LIBXL__LOG(ctx, LIBXL__LOG_DEBUG, "Destroyed device backend at %s", l1[XS_WATCH_TOKEN]); rc = 0; @@ -442,6 +463,7 @@ int libxl__device_remove(libxl__gc *gc, if (!state) goto out; if (atoi(state) != 4) { + libxl__device_execute_hotplug(gc, dev); libxl__device_destroy_tapdisk(gc, be_path); xs_rm(ctx->xsh, XBT_NULL, be_path); goto out; @@ -462,6 +484,7 @@ retry_transaction: xs_watch(ctx->xsh, state_path, be_path); libxl__device_destroy_tapdisk(gc, be_path); + libxl__device_execute_hotplug(gc, dev); if (wait) { struct timeval tv; @@ -482,6 +505,12 @@ int libxl__device_destroy(libxl__gc *gc, char *be_path = libxl__device_backend_path(gc, dev); char *fe_path = libxl__device_frontend_path(gc, dev); + /* + * Run hotplug scripts, which will probably not be able to + * execute successfully since the device may still be plugged + */ + libxl__device_execute_hotplug(gc, dev); + xs_rm(ctx->xsh, XBT_NULL, be_path); xs_rm(ctx->xsh, XBT_NULL, fe_path); diff -r d14479efe33c -r 8800c37a5acb tools/libxl/libxl_internal.h --- a/tools/libxl/libxl_internal.h Fri Oct 14 13:38:30 2011 +0200 +++ b/tools/libxl/libxl_internal.h Fri Sep 30 14:38:55 2011 +0200 @@ -250,6 +250,11 @@ _hidden int libxl__wait_for_backend(libx /* OS dependant helper function */ _hidden int try_phy_backend(mode_t st_mode); +/* hotplug functions */ +_hidden int libxl__device_execute_hotplug(libxl__gc *gc, libxl__device *dev); +_hidden int libxl__disk_hotplug(libxl__gc *gc, libxl__device *dev); +_hidden int libxl__nic_hotplug(libxl__gc *gc, libxl__device *dev); + /* from libxl_pci */ _hidden int libxl__device_pci_add(libxl__gc *gc, uint32_t domid, libxl_device_pci *pcidev, int starting); _______________________________________________ Xen-devel mailing list Xen-devel@lists.xensource.com http://lists.xensource.com/xen-devel
Roger Pau Monne
2011-Oct-14 13:35 UTC
[Xen-devel] [PATCH 7 of 9] hotplug NetBSD: detach devices when state is 5 or 6
# HG changeset patch # User Roger Pau Monne <roger.pau@entel.upc.edu> # Date 1317386335 -7200 # Node ID 2a7a580b84556a11e26be0f15864704ae5a7f0c0 # Parent 8800c37a5acba9e95ac8005ea123d3e9954be001 hotplug NetBSD: detach devices when state is 5 or 6 With the move of hotplug calls from xenbackendd to libxl, we can detach devices when the state is 5 or 6. Signed-off-by: Roger Pau Monne <roger.pau@entel.upc.edu> diff -r 8800c37a5acb -r 2a7a580b8455 tools/hotplug/NetBSD/block --- a/tools/hotplug/NetBSD/block Fri Sep 30 14:38:55 2011 +0200 +++ b/tools/hotplug/NetBSD/block Fri Sep 30 14:38:55 2011 +0200 @@ -23,7 +23,7 @@ xtype=$3 xparams=$(xenstore-read "$xpath/params") case $xstatus in -6) +5|6) # device removed case $xtype in file) diff -r 8800c37a5acb -r 2a7a580b8455 tools/hotplug/NetBSD/vif-bridge --- a/tools/hotplug/NetBSD/vif-bridge Fri Sep 30 14:38:55 2011 +0200 +++ b/tools/hotplug/NetBSD/vif-bridge Fri Sep 30 14:38:55 2011 +0200 @@ -14,7 +14,7 @@ xpath=$1 xstatus=$2 case $xstatus in -6) +5|6) # device removed xenstore-rm $xpath exit 0 diff -r 8800c37a5acb -r 2a7a580b8455 tools/hotplug/NetBSD/vif-ip --- a/tools/hotplug/NetBSD/vif-ip Fri Sep 30 14:38:55 2011 +0200 +++ b/tools/hotplug/NetBSD/vif-ip Fri Sep 30 14:38:55 2011 +0200 @@ -14,7 +14,7 @@ xpath=$1 xstatus=$2 case $xstatus in -6) +5|6) # device removed xenstore-rm $xpath exit 0 _______________________________________________ Xen-devel mailing list Xen-devel@lists.xensource.com http://lists.xensource.com/xen-devel
Roger Pau Monne
2011-Oct-14 13:35 UTC
[Xen-devel] [PATCH 8 of 9] hotplug: remove debug messages from NetBSD hotplug scripts
# HG changeset patch # User Roger Pau Monne <roger.pau@entel.upc.edu> # Date 1318595892 -7200 # Node ID 07502345baca44478e3086515a071b24c5aa9a33 # Parent 2a7a580b84556a11e26be0f15864704ae5a7f0c0 hotplug: remove debug messages from NetBSD hotplug scripts Remove unecessary debug messages from NetBSD hotplug scripts, left error messages only. Signed-off-by: Roger Pau Monne <roger.pau@entel.upc.edu> diff -r 2a7a580b8455 -r 07502345baca tools/hotplug/NetBSD/block --- a/tools/hotplug/NetBSD/block Fri Sep 30 14:38:55 2011 +0200 +++ b/tools/hotplug/NetBSD/block Fri Oct 14 14:38:12 2011 +0200 @@ -64,14 +64,12 @@ 2) if [ "$status" = "free" ] && \ vnconfig /dev/${disk}d $xparams >/dev/null; then device=/dev/${disk}d - echo vnconfig /dev/${disk}d $xparams break fi done if [ x$device = x ] ; then error "no available vnd device" fi - echo xenstore-write $xpath/vnd $device xenstore-write $xpath/vnd $device ;; phy) @@ -79,9 +77,7 @@ 2) ;; esac physical_device=$(stat -f ''%r'' "$device") - echo xenstore-write $xpath/physical-device $physical_device xenstore-write $xpath/physical-device $physical_device - echo xenstore-write $xpath/hotplug-status connected xenstore-write $xpath/hotplug-status connected exit 0 ;; diff -r 2a7a580b8455 -r 07502345baca tools/hotplug/NetBSD/vif-bridge --- a/tools/hotplug/NetBSD/vif-bridge Fri Sep 30 14:38:55 2011 +0200 +++ b/tools/hotplug/NetBSD/vif-bridge Fri Oct 14 14:38:12 2011 +0200 @@ -24,12 +24,9 @@ 2) xfid=$(xenstore-read "$xpath/frontend-id") xhandle=$(xenstore-read "$xpath/handle") iface=$(xenstore-read "$xpath/vifname") - echo ifconfig $iface up ifconfig $iface up brconfig $xbridge add $iface - echo brconfig $xbridge add $iface xenstore-write $xpath/hotplug-status connected - echo xenstore-write $xpath/hotplug-status connected exit 0 ;; *) diff -r 2a7a580b8455 -r 07502345baca tools/hotplug/NetBSD/vif-ip --- a/tools/hotplug/NetBSD/vif-ip Fri Sep 30 14:38:55 2011 +0200 +++ b/tools/hotplug/NetBSD/vif-ip Fri Oct 14 14:38:12 2011 +0200 @@ -24,10 +24,8 @@ 2) xfid=$(xenstore-read "$xpath/frontend-id") xhandle=$(xenstore-read "$xpath/handle") iface=$(xenstore-read "$xpath/vifname") - echo ifconfig $iface $xip up ifconfig $iface $xip up xenstore-write $xpath/hotplug-status connected - echo xenstore-write $xpath/hotplug-status connected exit 0 ;; *) _______________________________________________ Xen-devel mailing list Xen-devel@lists.xensource.com http://lists.xensource.com/xen-devel
Roger Pau Monne
2011-Oct-14 13:35 UTC
[Xen-devel] [PATCH 9 of 9] rc.d NetBSD: don''t start xenbackendd by default, only when xend needs it
# HG changeset patch # User Roger Pau Monne <roger.pau@entel.upc.edu> # Date 1317386335 -7200 # Node ID 40f928cba711eed3823158bc6aa1c8f5ea54bfb1 # Parent 07502345baca44478e3086515a071b24c5aa9a33 rc.d NetBSD: don''t start xenbackendd by default, only when xend needs it. With the move of hotplug scripts from xenbackendd to libxl xenbackendd is no longer needed by libxl, only start it when xend is started. Signed-off-by: Roger Pau Monne <roger.pau@entel.upc.edu> diff -r 07502345baca -r 40f928cba711 tools/hotplug/NetBSD/rc.d/xenbackendd --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/tools/hotplug/NetBSD/rc.d/xenbackendd Fri Sep 30 14:38:55 2011 +0200 @@ -0,0 +1,27 @@ +#!/bin/sh +# +# PROVIDE: xenbackendd +# REQUIRE: xencommons + +. /etc/rc.subr + +DIR=$(dirname "$0") +. "${DIR}/xen-hotplugpath.sh" + +LD_LIBRARY_PATH="${LIBDIR}" +export LD_LIBRARY_PATH PYTHONPATH +PATH="${PATH}:${SBINDIR}" +export PATH + +name="xenbackendd" +rcvar=$name +command="${SBINDIR}/xenbackendd" +if [ -n "${XENBACKENDD_DEBUG}" ]; then + command_args="${XENBACKENDD_ARGS} -d" +else + command_args="${XENBACKENDD_ARGS}" +fi + +load_rc_config $name +run_rc_command "$1" + diff -r 07502345baca -r 40f928cba711 tools/hotplug/NetBSD/rc.d/xencommons --- a/tools/hotplug/NetBSD/rc.d/xencommons Fri Oct 14 14:38:12 2011 +0200 +++ b/tools/hotplug/NetBSD/rc.d/xencommons Fri Sep 30 14:38:55 2011 +0200 @@ -22,8 +22,6 @@ required_files="/kern/xen/privcmd" XENSTORED_PIDFILE="/var/run/xenstored.pid" XENCONSOLED_PIDFILE="/var/run/xenconsoled.pid" -XENBACKENDD_PIDFILE="/var/run/xenbackendd.pid" -#XENBACKENDD_DEBUG=1 #XENCONSOLED_TRACE="/var/log/xen/xenconsole-trace.log" #XENSTORED_TRACE="/var/log/xen/xenstore-trace.log" @@ -46,7 +44,7 @@ xen_startcmd() XENSTORED_ROOTDIR="/var/lib/xenstored" fi rm -f ${XENSTORED_ROOTDIR}/tdb* >/dev/null 2>&1 - printf "Starting xenservices: xenstored, xenconsoled, xenbackendd." + printf "Starting xenservices: xenstored, xenconsoled." XENSTORED_ARGS=" --pid-file ${XENSTORED_PIDFILE}" if [ -n "${XENSTORED_TRACE}" ]; then XENSTORED_ARGS="${XENSTORED_ARGS} -T /var/log/xen/xenstored-trace.log" @@ -58,7 +56,7 @@ xen_startcmd() sleep 1 done else - printf "Starting xenservices: xenconsoled, xenbackendd." + printf "Starting xenservices: xenconsoled." fi XENCONSOLED_ARGS="" @@ -68,13 +66,6 @@ xen_startcmd() ${SBINDIR}/xenconsoled ${XENCONSOLED_ARGS} - XENBACKENDD_ARGS="" - if [ -n "${XENBACKENDD_DEBUG}" ]; then - XENBACKENDD_ARGS="${XENBACKENDD_ARGS} -d" - fi - - ${SBINDIR}/xenbackendd ${XENBACKENDD_ARGS} - printf "\n" printf "Setting domain 0 name.\n" @@ -87,8 +78,6 @@ xen_stop() printf "Stopping xencommons.\n" printf "WARNING: Not stopping xenstored, as it cannot be restarted.\n" - rc_pid=$(check_pidfile ${XENBACKENDD_PIDFILE} ${SBINDIR}/xenbackendd) - pids="$pids $rc_pid" rc_pid=$(check_pidfile ${XENCONSOLED_PIDFILE} ${SBINDIR}/xenconsoled) pids="$pids $rc_pid" @@ -108,17 +97,12 @@ xen_status() pids="$pids $xenconsoled_pid" fi - xenbackend_pid=$(check_pidfile ${XENBACKENDD_PIDFILE} ${SBINDIR}/xenbackendd) - if test -n ${xenbackend_pid}; then - pids="$pids $xenbackend_pid" - fi - - if test -n "$xenbackend_pid" -a -n "$xenconsoled_pid" -a -n "$xenstored_pid"; + if test -n "$xenconsoled_pid" -a -n "$xenstored_pid"; then echo "xencommons are running as pids $pids." return 0 fi - if test -z "$xenbackend_pid" -a -z "$xenconsoled_pid" -a -z "$xenstored_pid"; + if test -z "$xenconsoled_pid" -a -z "$xenstored_pid"; then echo "xencommons are not running." return 0 @@ -134,11 +118,6 @@ xen_status() else echo "xenconsoled is not running." fi - if test -n $xenbackend_pid; then - echo "xenbackendd is running as pid $xenbackend_pid." - else - echo "xenbackendd is not running." - fi } load_rc_config $name diff -r 07502345baca -r 40f928cba711 tools/hotplug/NetBSD/rc.d/xend --- a/tools/hotplug/NetBSD/rc.d/xend Fri Oct 14 14:38:12 2011 +0200 +++ b/tools/hotplug/NetBSD/rc.d/xend Fri Sep 30 14:38:55 2011 +0200 @@ -1,7 +1,7 @@ #!/bin/sh # # PROVIDE: xend -# REQUIRE: xencommons +# REQUIRE: xencommons xenbackendd . /etc/rc.subr _______________________________________________ Xen-devel mailing list Xen-devel@lists.xensource.com http://lists.xensource.com/xen-devel