All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] add xl init scripts
@ 2010-06-04 11:37 Stefano Stabellini
  2010-06-04 15:14 ` Ian Jackson
  2010-06-04 15:26 ` Ian Campbell
  0 siblings, 2 replies; 6+ messages in thread
From: Stefano Stabellini @ 2010-06-04 11:37 UTC (permalink / raw)
  To: xen-devel

Hi all,
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 <stefano.stabellini@eu.citrix.com>

---

diff -r 4ab68bf4c37e tools/hotplug/Linux/Makefile
--- a/tools/hotplug/Linux/Makefile	Thu Jun 03 07:30:54 2010 +0100
+++ b/tools/hotplug/Linux/Makefile	Fri Jun 04 12:15:36 2010 +0100
@@ -7,10 +7,15 @@
 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_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 -r 4ab68bf4c37e tools/hotplug/Linux/init.d/sysconfig.xen_toolstack
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/tools/hotplug/Linux/init.d/sysconfig.xen_toolstack	Fri Jun 04 12:15:36 2010 +0100
@@ -0,0 +1,1 @@
+xen_toolstack=xend
diff -r 4ab68bf4c37e tools/hotplug/Linux/init.d/sysconfig.xenlightdaemons
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/tools/hotplug/Linux/init.d/sysconfig.xenlightdaemons	Fri Jun 04 12:15:36 2010 +0100
@@ -0,0 +1,15 @@
+# Log xenconsoled messages (cf xl dmesg)
+#XENCONSOLED_TRACE=[none|guest|hv|all]
+
+# Log xenstored messages
+#XENSTORED_TRACE=[yes|on|1]
+
+# Running xenstored on XENSTORED_ROOTDIR
+#XENSTORED_ROOTDIR=/var/lib/xenstored
+
+# xen scripts dir
+XEN_SCRIPTS_DIR="/etc/xen/scripts"
+
+# See xend-config.sxp for a detailed explanation of these scripts
+NETWORK_SCRIPT=network-bridge
+VIF_SCRIPT=vif-bridge
diff -r 4ab68bf4c37e tools/hotplug/Linux/init.d/xend
--- a/tools/hotplug/Linux/init.d/xend	Thu Jun 03 07:30:54 2010 +0100
+++ b/tools/hotplug/Linux/init.d/xend	Fri Jun 04 12:15:36 2010 +0100
@@ -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 -r 4ab68bf4c37e tools/hotplug/Linux/init.d/xendomains
--- a/tools/hotplug/Linux/init.d/xendomains	Thu Jun 03 07:30:54 2010 +0100
+++ b/tools/hotplug/Linux/init.d/xendomains	Fri Jun 04 12:15:36 2010 +0100
@@ -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 -r 4ab68bf4c37e tools/hotplug/Linux/init.d/xenlightdaemons
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/tools/hotplug/Linux/init.d/xenlightdaemons	Fri Jun 04 12:15:36 2010 +0100
@@ -0,0 +1,108 @@
+#!/bin/bash
+#
+# xenlightdaemons    Script to start and stop xenstored and xenconsoled
+#                    FOR USE WITH LIBXL, not xend
+#
+# Author:       Ian Jackson <ian.jackson@eu.citrix.com>
+#
+# chkconfig: 2345
+# description: Starts and stops the Xen control daemon.
+### BEGIN INIT INFO
+# Provides:          xenstored xenconsoled
+# Required-Start:    $syslog $remote_fs
+# Should-Start:
+# Required-Stop:     $syslog $remote_fs
+# Should-Stop:
+# Default-Start:     3 4 5
+# Default-Stop:      1
+# Default-Enabled:   yes
+# Short-Description: Start/stop xenstored and xenconsoled
+# Description:       Starts and stops the daemons neeeded for xl/libxenlight
+### END INIT INFO
+
+test -f /etc/sysconfig/xen_toolstack && . /etc/sysconfig/xen_toolstack
+
+if test "x$xen_toolstack" != "xxl"
+then
+    exit 0
+fi
+
+test -f /etc/sysconfig/xenlightdaemons && . /etc/sysconfig/xenlightdaemons
+
+XENCONSOLED_PIDFILE=/var/run/xenconsoled.pid
+shopt -s extglob
+
+if test "x$1" = xstart && \
+     test -d /proc/xen && \
+   ! test -d /proc/xen/capabilities && \
+     grep '	xenfs$' /proc/filesystems >/dev/null && \
+   ! grep '^xenfs ' /proc/mounts >/dev/null;
+then
+	mount -t xenfs xenfs /proc/xen
+fi
+
+if ! grep -q "control_d" /proc/xen/capabilities ; then
+	exit 0
+fi
+
+do_start () {
+	test -z "$XENSTORED_ROOTDIR" || export XENSTORED_ROOTDIR
+	[[ "$XENSTORED_TRACE" == @(yes|on|1) ]] && export XENSTORED_TRACE
+	xenstore-read -s / >/dev/null 2>&1 || xenstored
+	xenstore-write "/local/domain/0/name" "Domain-0"
+
+	test -z "$XENCONSOLED_TRACE" || export XENCONSOLED_TRACE
+	xenconsoled --pid-file=$XENCONSOLED_PIDFILE $XENCONSOLED_OPTIONS
+
+	if test "$NETWORK_SCRIPT"
+	then
+		if test -f "$NETWORK_SCRIPT"
+		then
+			"$NETWORK_SCRIPT" start
+		else
+			"$XEN_SCRIPTS_DIR"/"$NETWORK_SCRIPT" start
+		fi
+	fi
+}
+do_stop () {
+	if read 2>/dev/null <$XENCONSOLED_PIDFILE pid; then
+		kill $pid
+		while kill -9 $pid >/dev/null 2>&1; do sleep 0.1; done
+		rm -f $XENCONSOLED_PIDFILE
+	fi
+	if test "$NETWORK_SCRIPT"
+	then
+		if test -f "$NETWORK_SCRIPT"
+		then
+			"$NETWORK_SCRIPT" stop
+		else
+			"$XEN_SCRIPTS_DIR"/"$NETWORK_SCRIPT" stop
+		fi
+	fi
+}
+
+case "$1" in
+  start)
+	do_start
+	;;
+  status)
+        xenstore-read -s /
+	;;
+  stop)
+	do_stop
+	;;
+  reload)
+	echo >&2 'Reload not available; use force-reload'; exit 1
+	;;
+  force-reload|restart)
+        do_stop
+	do_start
+	;;
+  *)
+	# do not advertise unreasonable commands that there is no reason
+	# to use with this device
+	echo $"Usage: $0 {start|stop|status|restart|force-reload}"
+	exit 1
+esac
+
+exit $?
diff -r 4ab68bf4c37e tools/hotplug/Linux/xl-vif-script
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/tools/hotplug/Linux/xl-vif-script	Fri Jun 04 12:15:36 2010 +0100
@@ -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 -r 4ab68bf4c37e tools/libxl/libxl.h
--- a/tools/libxl/libxl.h	Thu Jun 03 07:30:54 2010 +0100
+++ b/tools/libxl/libxl.h	Fri Jun 04 12:15:36 2010 +0100
@@ -536,5 +536,17 @@
                    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 -r 4ab68bf4c37e tools/libxl/libxl_internal.h
--- a/tools/libxl/libxl_internal.h	Thu Jun 03 07:30:54 2010 +0100
+++ b/tools/libxl/libxl_internal.h	Fri Jun 04 12:15:36 2010 +0100
@@ -215,17 +215,6 @@
 
 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 -r 4ab68bf4c37e tools/libxl/xl_cmdimpl.c
--- a/tools/libxl/xl_cmdimpl.c	Thu Jun 03 07:30:54 2010 +0100
+++ b/tools/libxl/xl_cmdimpl.c	Fri Jun 04 12:15:36 2010 +0100
@@ -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 */
@@ -237,7 +256,8 @@
     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;
 }
 
@@ -784,24 +804,6 @@
     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);

^ permalink raw reply	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2010-06-05  0:12 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2010-06-04 11:37 [PATCH] add xl init scripts Stefano Stabellini
2010-06-04 15:14 ` Ian Jackson
2010-06-04 15:26 ` Ian Campbell
2010-06-04 16:22   ` Stefano Stabellini
2010-06-04 16:55     ` Stefano Stabellini
2010-06-05  0:12   ` Jeremy Fitzhardinge

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.