mirror of
https://github.com/xen-project/xen.git
synced 2026-10-28 02:01:24 +01:00
tools/hotplug: Add an initscript to start "xl devd" in a driver domain
The removal of the udev rules highlighted that although it has been replaced by "xl devd" there isn't an initscript to replace it. To enable this add a --pidfile option to xl devd. Tested on Linux by running the script in dom0 and checking the daemon was started/stopped, but not in an actual driver domain environment since I don't have one conveniently available. I also checked that running without the --pidfile option still works. Scripts mainly cribbed from the xencommons for each platform. Signed-off-by: Ian Campbell <ian.campbell@citrix.com> Cc: Roger Pau Monné <roger.pau@citrix.com> Cc: Konrad Rzeszutek Wilk <konrad@darnok.org> Cc: George Dunlap <george.dunlap@eu.citrix.com> Acked-by: Ian Jackson <ian.jackson@eu.citrix.com> Acked-by: Wei Liu <wei.liu2@citrix.com>
This commit is contained in:
1 parent
a49077e52b
commit
2909ad4c96
11 files changed
+237
-8
No files matched your search
@@ -133,10 +133,12 @@ tools/flask/utils/flask-set-bool
|
||||
tools/flask/utils/flask-label-pci
|
||||
tools/hotplug/common/hotplugpath.sh
|
||||
tools/hotplug/FreeBSD/rc.d/xencommons
|
||||
tools/hotplug/FreeBSD/rc.d/xendriverdomain
|
||||
tools/hotplug/Linux/init.d/sysconfig.xencommons
|
||||
tools/hotplug/Linux/init.d/xen-watchdog
|
||||
tools/hotplug/Linux/init.d/xencommons
|
||||
tools/hotplug/Linux/init.d/xendomains
|
||||
tools/hotplug/Linux/init.d/xendriverdomain
|
||||
tools/hotplug/Linux/systemd/*.conf
|
||||
tools/hotplug/Linux/systemd/*.mount
|
||||
tools/hotplug/Linux/systemd/*.socket
|
||||
@@ -146,6 +148,7 @@ tools/hotplug/Linux/xen-backend.rules
|
||||
tools/hotplug/Linux/xen-hotplug-common.sh
|
||||
tools/hotplug/Linux/xendomains
|
||||
tools/hotplug/NetBSD/rc.d/xencommons
|
||||
tools/hotplug/NetBSD/rc.d/xendriverdomain
|
||||
tools/include/xen/*
|
||||
tools/include/xen-xsm/*
|
||||
tools/include/xen-foreign/*.(c|h|size)
|
||||
|
||||
Vendored
+4
-1
@@ -2403,7 +2403,7 @@ ac_compiler_gnu=$ac_cv_c_compiler_gnu
|
||||
|
||||
|
||||
|
||||
ac_config_files="$ac_config_files ../config/Tools.mk hotplug/FreeBSD/rc.d/xencommons hotplug/Linux/init.d/sysconfig.xencommons hotplug/Linux/init.d/xen-watchdog hotplug/Linux/init.d/xencommons hotplug/Linux/init.d/xendomains hotplug/Linux/vif-setup hotplug/Linux/xen-hotplug-common.sh hotplug/Linux/xendomains hotplug/NetBSD/rc.d/xencommons libxl/xenlight.pc.in libxl/xlutil.pc.in"
|
||||
ac_config_files="$ac_config_files ../config/Tools.mk hotplug/FreeBSD/rc.d/xencommons hotplug/FreeBSD/rc.d/xendriverdomain hotplug/Linux/init.d/sysconfig.xencommons hotplug/Linux/init.d/xen-watchdog hotplug/Linux/init.d/xencommons hotplug/Linux/init.d/xendomains hotplug/Linux/init.d/xendriverdomain hotplug/Linux/vif-setup hotplug/Linux/xen-hotplug-common.sh hotplug/Linux/xendomains hotplug/NetBSD/rc.d/xencommons hotplug/NetBSD/rc.d/xendriverdomain libxl/xenlight.pc.in libxl/xlutil.pc.in"
|
||||
|
||||
ac_config_headers="$ac_config_headers config.h"
|
||||
|
||||
@@ -10045,14 +10045,17 @@ do
|
||||
case $ac_config_target in
|
||||
"../config/Tools.mk") CONFIG_FILES="$CONFIG_FILES ../config/Tools.mk" ;;
|
||||
"hotplug/FreeBSD/rc.d/xencommons") CONFIG_FILES="$CONFIG_FILES hotplug/FreeBSD/rc.d/xencommons" ;;
|
||||
"hotplug/FreeBSD/rc.d/xendriverdomain") CONFIG_FILES="$CONFIG_FILES hotplug/FreeBSD/rc.d/xendriverdomain" ;;
|
||||
"hotplug/Linux/init.d/sysconfig.xencommons") CONFIG_FILES="$CONFIG_FILES hotplug/Linux/init.d/sysconfig.xencommons" ;;
|
||||
"hotplug/Linux/init.d/xen-watchdog") CONFIG_FILES="$CONFIG_FILES hotplug/Linux/init.d/xen-watchdog" ;;
|
||||
"hotplug/Linux/init.d/xencommons") CONFIG_FILES="$CONFIG_FILES hotplug/Linux/init.d/xencommons" ;;
|
||||
"hotplug/Linux/init.d/xendomains") CONFIG_FILES="$CONFIG_FILES hotplug/Linux/init.d/xendomains" ;;
|
||||
"hotplug/Linux/init.d/xendriverdomain") CONFIG_FILES="$CONFIG_FILES hotplug/Linux/init.d/xendriverdomain" ;;
|
||||
"hotplug/Linux/vif-setup") CONFIG_FILES="$CONFIG_FILES hotplug/Linux/vif-setup" ;;
|
||||
"hotplug/Linux/xen-hotplug-common.sh") CONFIG_FILES="$CONFIG_FILES hotplug/Linux/xen-hotplug-common.sh" ;;
|
||||
"hotplug/Linux/xendomains") CONFIG_FILES="$CONFIG_FILES hotplug/Linux/xendomains" ;;
|
||||
"hotplug/NetBSD/rc.d/xencommons") CONFIG_FILES="$CONFIG_FILES hotplug/NetBSD/rc.d/xencommons" ;;
|
||||
"hotplug/NetBSD/rc.d/xendriverdomain") CONFIG_FILES="$CONFIG_FILES hotplug/NetBSD/rc.d/xendriverdomain" ;;
|
||||
"libxl/xenlight.pc.in") CONFIG_FILES="$CONFIG_FILES libxl/xenlight.pc.in" ;;
|
||||
"libxl/xlutil.pc.in") CONFIG_FILES="$CONFIG_FILES libxl/xlutil.pc.in" ;;
|
||||
"config.h") CONFIG_HEADERS="$CONFIG_HEADERS config.h" ;;
|
||||
|
||||
@@ -8,14 +8,17 @@ AC_CONFIG_SRCDIR([libxl/libxl.c])
|
||||
AC_CONFIG_FILES([
|
||||
../config/Tools.mk
|
||||
hotplug/FreeBSD/rc.d/xencommons
|
||||
hotplug/FreeBSD/rc.d/xendriverdomain
|
||||
hotplug/Linux/init.d/sysconfig.xencommons
|
||||
hotplug/Linux/init.d/xen-watchdog
|
||||
hotplug/Linux/init.d/xencommons
|
||||
hotplug/Linux/init.d/xendomains
|
||||
hotplug/Linux/init.d/xendriverdomain
|
||||
hotplug/Linux/vif-setup
|
||||
hotplug/Linux/xen-hotplug-common.sh
|
||||
hotplug/Linux/xendomains
|
||||
hotplug/NetBSD/rc.d/xencommons
|
||||
hotplug/NetBSD/rc.d/xendriverdomain
|
||||
libxl/xenlight.pc.in
|
||||
libxl/xlutil.pc.in
|
||||
])
|
||||
|
||||
@@ -6,7 +6,7 @@ XEN_SCRIPTS = vif-bridge
|
||||
|
||||
XEN_SCRIPT_DATA =
|
||||
|
||||
XEN_RCD_PROG = rc.d/xencommons
|
||||
XEN_RCD_PROG = rc.d/xencommons rc.d/xendriverdomain
|
||||
|
||||
.PHONY: all
|
||||
all:
|
||||
|
||||
@@ -0,0 +1,48 @@
|
||||
#!/bin/sh
|
||||
#
|
||||
# PROVIDE: xendriverdomain
|
||||
# REQUIRE: DAEMON
|
||||
#
|
||||
# Should be run in a driver domain, but not in domain 0.
|
||||
|
||||
. /etc/rc.subr
|
||||
|
||||
. /etc/xen/scripts/hotplugpath.sh
|
||||
|
||||
LD_LIBRARY_PATH="${libdir}"
|
||||
export LD_LIBRARY_PATH
|
||||
|
||||
name="xendriverdomain"
|
||||
start_precmd="xendriverdomain_precmd"
|
||||
start_cmd="xendriverdomain_startcmd"
|
||||
stop_cmd="xendriverdomain_stop"
|
||||
extra_commands=""
|
||||
|
||||
XLDEVD_PIDFILE="/var/run/xldevd.pid"
|
||||
|
||||
xendriverdomain_precmd()
|
||||
{
|
||||
:
|
||||
}
|
||||
|
||||
xendriverdomain_startcmd()
|
||||
{
|
||||
printf "Starting xenservices: xl devd."
|
||||
|
||||
${sbindir}/xl devd --pidfile=$XLDEVD_PIDFILE ${XLDEVD_ARGS}
|
||||
|
||||
printf "\n"
|
||||
}
|
||||
|
||||
xendriverdomain_stop()
|
||||
{
|
||||
printf "Stopping xl devd.\n"
|
||||
|
||||
rc_pid=$(check_pidfile ${XLDEVD_PIDFILE} ${sbindir}/xl)
|
||||
|
||||
kill -${sig_stop:-TERM} $rc_pids
|
||||
wait_for_pids $rc_pids
|
||||
}
|
||||
|
||||
load_rc_config $name
|
||||
run_rc_command "$1"
|
||||
@@ -9,6 +9,8 @@ XENDOMAINS_SYSCONFIG = init.d/sysconfig.xendomains
|
||||
XENCOMMONS_INITD = init.d/xencommons
|
||||
XENCOMMONS_SYSCONFIG = init.d/sysconfig.xencommons
|
||||
|
||||
XENDRIVERDOMAIN_INITD = init.d/xendriverdomain
|
||||
|
||||
# Xen script dir and scripts to go there.
|
||||
XEN_SCRIPTS = vif-bridge
|
||||
XEN_SCRIPTS += vif-route
|
||||
@@ -53,6 +55,7 @@ install-initd:
|
||||
$(INSTALL_DATA) $(XENDOMAINS_SYSCONFIG) $(DESTDIR)$(SYSCONFIG_DIR)/xendomains
|
||||
$(INSTALL_PROG) $(XENCOMMONS_INITD) $(DESTDIR)$(INITD_DIR)
|
||||
$(INSTALL_DATA) $(XENCOMMONS_SYSCONFIG) $(DESTDIR)$(SYSCONFIG_DIR)/xencommons
|
||||
$(INSTALL_PROG) $(XENDRIVERDOMAIN_INITD) $(DESTDIR)$(INITD_DIR)
|
||||
$(INSTALL_PROG) init.d/xen-watchdog $(DESTDIR)$(INITD_DIR)
|
||||
|
||||
.PHONY: install-scripts
|
||||
|
||||
@@ -0,0 +1,85 @@
|
||||
|
||||
#!/bin/bash
|
||||
#
|
||||
# xendriverdomain Script to start services needed in a Xen driver domain
|
||||
#
|
||||
# NOTE: This initscript is not needed on dom0.
|
||||
|
||||
# chkconfig: 2345 70 10
|
||||
# description: Starts and stops xen driver domain daemon
|
||||
### BEGIN INIT INFO
|
||||
# Provides: xendevd
|
||||
# Required-Start: $syslog $remote_fs
|
||||
# Should-Start:
|
||||
# Required-Stop: $syslog $remote_fs
|
||||
# Should-Stop:
|
||||
# Default-Start: 2 3 5
|
||||
# Default-Stop: 0 1 6
|
||||
# Short-Description: Start/stop xen driver domain daemon
|
||||
# Description: Starts and stops the daemons neeeded for a xen driver domain
|
||||
### END INIT INFO
|
||||
|
||||
. @XEN_SCRIPT_DIR@/hotplugpath.sh
|
||||
|
||||
xendriverdomain_config=@CONFIG_DIR@/@CONFIG_LEAF_DIR@
|
||||
|
||||
test -f $xendriverdomain_config/xendriverdomain && . $xendriverdomain_config/xendriverdomain
|
||||
|
||||
XLDEVD_PIDFILE=/var/run/xldevd.pid
|
||||
|
||||
# not running in Xen dom0 or domU
|
||||
if ! test -d /proc/xen ; then
|
||||
exit 0
|
||||
fi
|
||||
|
||||
# mount xenfs in dom0 or domU with a pv_ops kernel
|
||||
if test "x$1" = xstart && \
|
||||
! test -f /proc/xen/capabilities && \
|
||||
! grep '^xenfs ' /proc/mounts >/dev/null;
|
||||
then
|
||||
mount -t xenfs xenfs /proc/xen
|
||||
fi
|
||||
|
||||
# run this script only in domU:
|
||||
# no capabilities file in xenlinux domU kernel
|
||||
# empty capabilities file in pv_ops domU kernel
|
||||
if ! test -f /proc/xen/capabilities || \
|
||||
grep -q "control_d" /proc/xen/capabilities ; then
|
||||
exit 0
|
||||
fi
|
||||
|
||||
do_start () {
|
||||
echo Starting xl devd...
|
||||
${sbindir}/xl devd --pidfile=$XLDEVD_PIDFILE $XLDEVD_ARGS
|
||||
}
|
||||
do_stop () {
|
||||
echo Stopping xl devd...
|
||||
if read 2>/dev/null <$XLDEVD_PIDFILE pid; then
|
||||
kill $pid
|
||||
while kill -9 $pid >/dev/null 2>&1; do sleep 0.1; done
|
||||
rm -f $XLDEVD_PIDFILE
|
||||
fi
|
||||
}
|
||||
|
||||
case "$1" in
|
||||
start)
|
||||
do_start
|
||||
;;
|
||||
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|restart|force-reload}"
|
||||
exit 1
|
||||
esac
|
||||
|
||||
exit $?
|
||||
@@ -8,7 +8,7 @@ XEN_SCRIPTS += vif-bridge
|
||||
XEN_SCRIPTS += vif-ip
|
||||
|
||||
XEN_SCRIPT_DATA =
|
||||
XEN_RCD_PROG = rc.d/xencommons rc.d/xendomains rc.d/xen-watchdog
|
||||
XEN_RCD_PROG = rc.d/xencommons rc.d/xendomains rc.d/xen-watchdog rc.d/xendriverdomain
|
||||
|
||||
.PHONY: all
|
||||
all:
|
||||
|
||||
@@ -0,0 +1,49 @@
|
||||
#!/bin/sh
|
||||
#
|
||||
# PROVIDE: xendriverdomain
|
||||
# REQUIRE: DAEMON
|
||||
#
|
||||
# Should be run in a driver domain, but not in domain 0.
|
||||
|
||||
. /etc/rc.subr
|
||||
|
||||
DIR=$(dirname "$0")
|
||||
. "${DIR}/xen-hotplugpath.sh"
|
||||
|
||||
LD_LIBRARY_PATH="${libdir}"
|
||||
export LD_LIBRARY_PATH
|
||||
|
||||
name="xendriverdomain"
|
||||
start_precmd="xendriverdomain_precmd"
|
||||
start_cmd="xendriverdomain_startcmd"
|
||||
stop_cmd="xendriverdomain_stop"
|
||||
extra_commands=""
|
||||
|
||||
XLDEVD_PIDFILE="/var/run/xldevd.pid"
|
||||
|
||||
xendriverdomain_precmd()
|
||||
{
|
||||
:
|
||||
}
|
||||
|
||||
xendriverdomain_startcmd()
|
||||
{
|
||||
printf "Starting xenservices: xl devd."
|
||||
|
||||
${sbindir}/xl devd --pidfile=$XLDEVD_PIDFILE ${XLDEVD_ARGS}
|
||||
|
||||
printf "\n"
|
||||
}
|
||||
|
||||
xendriverdomain_stop()
|
||||
{
|
||||
printf "Stopping xl devd.\n"
|
||||
|
||||
rc_pid=$(check_pidfile ${XLDEVD_PIDFILE} ${sbindir}/xl)
|
||||
|
||||
kill -${sig_stop:-TERM} $rc_pids
|
||||
wait_for_pids $rc_pids
|
||||
}
|
||||
|
||||
load_rc_config $name
|
||||
run_rc_command "$1"
|
||||
@@ -473,7 +473,7 @@ out:
|
||||
flush_stream(fh);
|
||||
}
|
||||
|
||||
static int do_daemonize(char *name)
|
||||
static int do_daemonize(char *name, const char *pidfile)
|
||||
{
|
||||
char *fullname;
|
||||
pid_t child1;
|
||||
@@ -505,6 +505,31 @@ static int do_daemonize(char *name)
|
||||
|
||||
CHK_SYSCALL(daemon(0, 1));
|
||||
|
||||
if (pidfile) {
|
||||
int fd = open(pidfile, O_RDWR | O_CREAT, S_IRUSR|S_IWUSR);
|
||||
char *pid = NULL;
|
||||
|
||||
if (fd == -1) {
|
||||
perror("Unable to open pidfile");
|
||||
exit(1);
|
||||
}
|
||||
|
||||
if (asprintf(&pid, "%ld\n", (long)getpid()) == -1) {
|
||||
perror("Formatting pid");
|
||||
exit(1);
|
||||
}
|
||||
|
||||
if (write(fd, pid, strlen(pid)) < 0) {
|
||||
perror("Writing pid");
|
||||
exit(1);
|
||||
}
|
||||
|
||||
if ( close(fd) < 0 ) {
|
||||
perror("Closing pidfile");
|
||||
exit(1);
|
||||
}
|
||||
}
|
||||
|
||||
out:
|
||||
return ret;
|
||||
}
|
||||
@@ -2813,7 +2838,7 @@ start:
|
||||
char *name;
|
||||
|
||||
xasprintf(&name, "xl-%s", d_config.c_info.name);
|
||||
ret = do_daemonize(name);
|
||||
ret = do_daemonize(name, NULL);
|
||||
free(name);
|
||||
if (ret) {
|
||||
ret = (ret == 1) ? domid : ret;
|
||||
@@ -7982,15 +8007,24 @@ int main_remus(int argc, char **argv)
|
||||
int main_devd(int argc, char **argv)
|
||||
{
|
||||
int ret = 0, opt = 0, daemonize = 1;
|
||||
const char *pidfile = NULL;
|
||||
static const struct option opts[] = {
|
||||
{"pidfile", 1, 0, 'p'},
|
||||
COMMON_LONG_OPTS,
|
||||
{0, 0, 0, 0}
|
||||
};
|
||||
|
||||
SWITCH_FOREACH_OPT(opt, "F", NULL, "devd", 0) {
|
||||
SWITCH_FOREACH_OPT(opt, "Fp:", opts, "devd", 0) {
|
||||
case 'F':
|
||||
daemonize = 0;
|
||||
break;
|
||||
case 'p':
|
||||
pidfile = optarg;
|
||||
break;
|
||||
}
|
||||
|
||||
if (daemonize) {
|
||||
ret = do_daemonize("xldevd");
|
||||
ret = do_daemonize("xldevd", pidfile);
|
||||
if (ret) {
|
||||
ret = (ret == 1) ? 0 : ret;
|
||||
goto out;
|
||||
|
||||
@@ -506,7 +506,8 @@ struct cmd_spec cmd_table[] = {
|
||||
&main_devd, 0, 1,
|
||||
"Daemon that listens for devices and launches backends",
|
||||
"[options]",
|
||||
"-F Run in the foreground",
|
||||
"-F Run in the foreground.\n"
|
||||
"-p, --pidfile [FILE] Write PID to pidfile when daemonizing.",
|
||||
},
|
||||
#ifdef LIBXL_HAVE_PSR_CMT
|
||||
{ "psr-hwinfo",
|
||||
|
||||