From 0cc54b151a15499cf7d4548a1cc379fe93745d3c Mon Sep 17 00:00:00 2001 From: Keir Fraser Date: Mon, 7 Jun 2010 07:05:54 +0100 Subject: [PATCH] Add xl init scripts this patch adds an init script for xl, so that it can be used without xend installed on the system. In cases in which both toolstacks are present, only one init script will be run, dependening on the value of xen_toolstack in /etc/sysconfig/xen_toolstack. Please note that a correct value of xen_toolstack (either xl or xend), is required now. The network script and the vif script to be used with xl can be specified in /etc/sysconfig/xenlightdaemons. Xl sets the vif script to xl-vif-script by default, that reads /etc/sysconfig/xenlightdaemons and calls the vif script set there. A port to a debian system should be straightforward, just replacing /etc/sysconfig with /etc/default everywhere. Signed-off-by: Stefano Stabellini --- tools/hotplug/Linux/Makefile | 8 ++++++ tools/hotplug/Linux/init.d/xend | 6 ++++ tools/hotplug/Linux/init.d/xendomains | 7 +++++ tools/hotplug/Linux/xl-vif-script | 14 ++++++++++ tools/libxl/libxl.h | 12 ++++++++ tools/libxl/libxl_internal.h | 11 -------- tools/libxl/xl_cmdimpl.c | 40 ++++++++++++++------------- 7 files changed, 68 insertions(+), 30 deletions(-) create mode 100644 tools/hotplug/Linux/xl-vif-script diff --git a/tools/hotplug/Linux/Makefile b/tools/hotplug/Linux/Makefile index fa9e2b5c45..ffb3d74b82 100644 --- a/tools/hotplug/Linux/Makefile +++ b/tools/hotplug/Linux/Makefile @@ -7,10 +7,15 @@ XEND_SYSCONFIG = init.d/sysconfig.xend XENDOMAINS_INITD = init.d/xendomains XENDOMAINS_SYSCONFIG = init.d/sysconfig.xendomains +XLD_INITD = init.d/xenlightdaemons +XLD_SYSCONFIG = init.d/sysconfig.xenlightdaemons +XENTOOLSTACK_SYSCONFIG = init.d/sysconfig.xen_toolstack + # Xen script dir and scripts to go there. XEN_SCRIPTS = network-bridge vif-bridge XEN_SCRIPTS += network-route vif-route XEN_SCRIPTS += network-nat vif-nat +XEN_SCRIPTS += xl-vif-script XEN_SCRIPTS += vif2 XEN_SCRIPTS += block XEN_SCRIPTS += block-enbd block-nbd @@ -67,6 +72,9 @@ install-initd: $(INSTALL_PROG) $(XEND_SYSCONFIG) $(DESTDIR)$(CONFIG_DIR)/sysconfig/xend $(INSTALL_PROG) $(XENDOMAINS_INITD) $(DESTDIR)$(CONFIG_DIR)/init.d $(INSTALL_PROG) $(XENDOMAINS_SYSCONFIG) $(DESTDIR)$(CONFIG_DIR)/sysconfig/xendomains + $(INSTALL_PROG) $(XLD_INITD) $(DESTDIR)$(CONFIG_DIR)/init.d + $(INSTALL_PROG) $(XLD_SYSCONFIG) $(DESTDIR)$(CONFIG_DIR)/sysconfig/xenlightdaemons + $(INSTALL_PROG) $(XENTOOLSTACK_SYSCONFIG) $(DESTDIR)$(CONFIG_DIR)/sysconfig/xen_toolstack .PHONY: install-scripts install-scripts: diff --git a/tools/hotplug/Linux/init.d/xend b/tools/hotplug/Linux/init.d/xend index 4016004790..6273a40832 100755 --- a/tools/hotplug/Linux/init.d/xend +++ b/tools/hotplug/Linux/init.d/xend @@ -21,6 +21,12 @@ shopt -s extglob test -f /etc/sysconfig/xend && . /etc/sysconfig/xend +test -f /etc/sysconfig/xen_toolstack && . /etc/sysconfig/xen_toolstack + +if test "x$xen_toolstack" != "xxend" +then + exit 0 +fi if test "x$1" = xstart && \ test -d /proc/xen && \ diff --git a/tools/hotplug/Linux/init.d/xendomains b/tools/hotplug/Linux/init.d/xendomains index 70b5b8fdcf..84a16dc1e8 100644 --- a/tools/hotplug/Linux/init.d/xendomains +++ b/tools/hotplug/Linux/init.d/xendomains @@ -28,6 +28,13 @@ # boots / shuts down. ### END INIT INFO +test -f /etc/sysconfig/xen_toolstack && . /etc/sysconfig/xen_toolstack + +if test "x$xen_toolstack" != "xxend" +then + exit 0 +fi + # Correct exit code would probably be 5, but it's enough # if xend complains if we're not running as privileged domain if ! [ -e /proc/xen/privcmd ]; then diff --git a/tools/hotplug/Linux/xl-vif-script b/tools/hotplug/Linux/xl-vif-script new file mode 100644 index 0000000000..ec53c55b80 --- /dev/null +++ b/tools/hotplug/Linux/xl-vif-script @@ -0,0 +1,14 @@ +#!/bin/sh + +test -f /etc/sysconfig/xenlightdaemons && . /etc/sysconfig/xenlightdaemons + +if test "$VIF_SCRIPT" +then + if test -f "$VIF_SCRIPT" + then + "$VIF_SCRIPT" $* + else + "$XEN_SCRIPTS_DIR"/"$VIF_SCRIPT" $* + fi +fi + diff --git a/tools/libxl/libxl.h b/tools/libxl/libxl.h index b5d972c529..490b7570f7 100644 --- a/tools/libxl/libxl.h +++ b/tools/libxl/libxl.h @@ -538,5 +538,17 @@ int libxl_tmem_set(struct libxl_ctx *ctx, uint32_t domid, char* name, uint32_t set); int libxl_tmem_shared_auth(struct libxl_ctx *ctx, uint32_t domid, char* uuid, int auth); + +/* common paths */ +const char *libxl_sbindir_path(void); +const char *libxl_bindir_path(void); +const char *libxl_libexec_path(void); +const char *libxl_libdir_path(void); +const char *libxl_sharedir_path(void); +const char *libxl_private_bindir_path(void); +const char *libxl_xenfirmwaredir_path(void); +const char *libxl_xen_config_dir_path(void); +const char *libxl_xen_script_dir_path(void); + #endif /* LIBXL_H */ diff --git a/tools/libxl/libxl_internal.h b/tools/libxl/libxl_internal.h index f45d0d539c..5767ae2cf2 100644 --- a/tools/libxl/libxl_internal.h +++ b/tools/libxl/libxl_internal.h @@ -215,17 +215,6 @@ void libxl_log_child_exitstatus(struct libxl_ctx *ctx, char *libxl_abs_path(struct libxl_ctx *ctx, char *s, const char *path); -/* libxl_paths.c */ -const char *libxl_sbindir_path(void); -const char *libxl_bindir_path(void); -const char *libxl_libexec_path(void); -const char *libxl_libdir_path(void); -const char *libxl_sharedir_path(void); -const char *libxl_private_bindir_path(void); -const char *libxl_xenfirmwaredir_path(void); -const char *libxl_xen_config_dir_path(void); -const char *libxl_xen_script_dir_path(void); - #define XL_LOG_DEBUG XTL_DEBUG #define XL_LOG_INFO XTL_INFO #define XL_LOG_WARNING XTL_WARN diff --git a/tools/libxl/xl_cmdimpl.c b/tools/libxl/xl_cmdimpl.c index dbdfb83c05..2633a64b65 100644 --- a/tools/libxl/xl_cmdimpl.c +++ b/tools/libxl/xl_cmdimpl.c @@ -42,6 +42,25 @@ #define UUID_FMT "%02hhx%02hhx%02hhx%02hhx-%02hhx%02hhx-%02hhx%02hhx-%02hhx%02hhx-%02hhx%02hhx%02hhx%02hhx%02hhx%02hhx" +#define CHK_ERRNO( call ) ({ \ + int chk_errno = (call); \ + if (chk_errno < 0) { \ + fprintf(stderr,"xl: fatal error: %s:%d: %s: %s\n", \ + __FILE__,__LINE__, strerror(chk_errno), #call); \ + exit(-ERROR_FAIL); \ + } \ + }) + +#define MUST( call ) ({ \ + int must_rc = (call); \ + if (must_rc < 0) { \ + fprintf(stderr,"xl: fatal error: %s:%d, rc=%d: %s\n", \ + __FILE__,__LINE__, must_rc, #call); \ + exit(-must_rc); \ + } \ + }) + + int logfile = 2; /* every libxl action in xl uses this same libxl context */ @@ -240,7 +259,8 @@ static void init_nic_info(libxl_device_nic *nic_info, int devnum) nic_info->mac[5] = 1 + (int) (0xff * (rand() / (RAND_MAX + 1.0))); nic_info->ifname = NULL; nic_info->bridge = "xenbr0"; - nic_info->script = "/etc/xen/scripts/vif-bridge"; + CHK_ERRNO( asprintf(&nic_info->script, "%s/xl-vif-script", + libxl_xen_script_dir_path()) ); nic_info->nictype = NICTYPE_IOEMU; } @@ -791,24 +811,6 @@ skip_pci: xlu_cfg_destroy(config); } -#define CHK_ERRNO( call ) ({ \ - int chk_errno = (call); \ - if (chk_errno) { \ - fprintf(stderr,"xl: fatal error: %s:%d: %s: %s\n", \ - __FILE__,__LINE__, strerror(chk_errno), #call); \ - exit(-ERROR_FAIL); \ - } \ - }) - -#define MUST( call ) ({ \ - int must_rc = (call); \ - if (must_rc) { \ - fprintf(stderr,"xl: fatal error: %s:%d, rc=%d: %s\n", \ - __FILE__,__LINE__, must_rc, #call); \ - exit(-must_rc); \ - } \ - }) - static void *xmalloc(size_t sz) { void *r; r = malloc(sz); -- 2.30.2