[Pkg-xen-devel] [PATCH v2 2/3] xen init script: rewrite xenstored start logic

Hans van Kranenburg hans at knorrie.org
Wed Feb 13 00:24:54 GMT 2019


We're adding oxenstored, and we want use it by default in Xen 4.11.

When doing a Debian upgrade from Stretch to Buster, the xen-utils-common
package will be upgraded to the new version, but it still needs to
support running the Xen 4.8 hypervisor and utils, because the user might
not have rebooted yet, or might boot into the 4.8 hypervisor again
because there were troubles running 4.11.

So, this means that oxenstored might or might not be available, and we
have to deal with that.

See comments in the code for more explanation about the new program
flow.

Also...
* Use if statements rather than constructs using || and && to make the
program flow a bit easier to understand.
* Remove the confuscating madness of having 1 as a success return code.
* Don't print the xenstored progress message if we're not touching it.

Signed-off-by: Hans van Kranenburg <hans at knorrie.org>
---
 debian/xen-utils-common.xen.init | 48 +++++++++++++++++++++++++++-----
 1 file changed, 41 insertions(+), 7 deletions(-)

diff --git a/debian/xen-utils-common.xen.init b/debian/xen-utils-common.xen.init
index 4b793d5ac2..f8e4bffc54 100644
--- a/debian/xen-utils-common.xen.init
+++ b/debian/xen-utils-common.xen.init
@@ -28,7 +28,8 @@ fi
 
 XENCONSOLED="$ROOT"/bin/xenconsoled
 XENCONSOLED_PIDFILE="/var/run/xenconsoled.pid"
-XENSTORED="$ROOT"/bin/xenstored
+CXENSTORED="$ROOT"/bin/xenstored
+OXENSTORED="$ROOT"/bin/oxenstored
 XENSTORED_PIDFILE="/var/run/xenstore.pid"
 QEMU=/usr/bin/qemu-system-i386
 QEMU_PIDFILE="/var/run/qemu-dom0.pid"
@@ -171,15 +172,48 @@ qemu_stop_real()
 
 xenstored_start()
 {
+	# First, we check if any of xenstored or oxenstored is already running. If
+	# so, we abort and leave it alone.
+	for try_xenstored in "$OXENSTORED" "$CXENSTORED"; do
+		if [ -x $try_xenstored ]; then
+			start-stop-daemon --start --quiet --pidfile "$XENSTORED_PIDFILE" \
+				--exec "$try_xenstored" --test > /dev/null
+			# s-s-b code 1 here means: "We found a matching live process!"
+			if [ $? -eq 1 ]; then
+				return 0
+			fi
+		fi
+	done
+	# If none of them are running, then try starting one. If the user made an
+	# explicit choice, then run that. Else try the different xenstored
+	# implementations we know about in order of preference.
 	log_progress_msg "xenstored"
-	start-stop-daemon --start --quiet --pidfile "$XENSTORED_PIDFILE" --exec "$XENSTORED" --test > /dev/null \
-		|| return 1
 	[ -d "$XENSTORED_DIR" ] || mkdir -p "$XENSTORED_DIR"
 	[ -x /sbin/restorecon ] && /sbin/restorecon "$XENSTORED_DIR"
 	export XENSTORED_ROOTDIR="$XENSTORED_DIR"
-	start-stop-daemon --start --quiet --pidfile "$XENSTORED_PIDFILE" --exec "$XENSTORED" -- \
-		$XENSTORED_ARGS --pid-file="$XENSTORED_PIDFILE" \
-		|| return 2
+	# $XENSTORED can be set in /etc/default/xen. If the user made an explicit
+	# choice about what to run, we only consider running exactly that an
+	# option. Otherwise, we run any available known xenstored implementation in
+	# order of preference.
+	case "$XENSTORED" in
+	?*) try_xenstoreds='XENSTORED' ;;
+	'') try_xenstoreds='OXENSTORED CXENSTORED' ;;
+	esac
+	for try_xenstored_var in $try_xenstoreds; do
+		eval "try_xenstored=\$$try_xenstored_var"
+		if [ -x $try_xenstored ]; then
+			if start-stop-daemon --start --quiet \
+				--pidfile "$XENSTORED_PIDFILE" --exec "$try_xenstored" -- \
+				$XENSTORED_ARGS --pid-file="$XENSTORED_PIDFILE"; then
+					started_xenstored=$try_xenstored
+					break
+			fi
+		fi
+	done
+	if [ -z "$started_xenstored" ]; then
+		log_failure_msg "No suitable xenstored binary found to start."
+		return 1
+	fi
 
 	# Wait for xenstored to actually come up, timing out after 30 seconds
 	local time=0
@@ -223,7 +257,7 @@ case "$1" in
 	env_setup
 	xenstored_start
 	case "$?" in
-		0|1) ;;
+		0) ;;
 		*) log_end_msg 1; exit ;;
 	esac
 	xenconsoled_start
-- 
2.20.1




More information about the Pkg-xen-devel mailing list