[linux-tools] 04/04: hyperv-daemons: Add init scripts

debian-kernel at lists.debian.org debian-kernel at lists.debian.org
Wed Feb 3 03:42:59 UTC 2016


This is an automated email from the git hooks/post-receive script.

benh pushed a commit to branch wheezy-backports
in repository linux-tools.

commit 50747480c882dae7d3c8f7b4d0df5cf3276c4ee5
Author: Ben Hutchings <ben at decadent.org.uk>
Date:   Tue Feb 2 16:54:54 2016 +0000

    hyperv-daemons: Add init scripts
    
    Also add a helper executable that implements the check for Hyper-V
    (like ConditionVirtualization=microsoft in the systemd units).
---
 debian/build/tools/hv/.gitignore           |   1 +
 debian/build/tools/hv/Makefile             |   6 +-
 debian/build/tools/hv/check-hyperv.c       | 103 +++++++++++++++++++++++++++
 debian/changelog                           |   1 +
 debian/copyright                           |  19 +++++
 debian/hyperv-daemons.hv-fcopy-daemon.init | 110 +++++++++++++++++++++++++++++
 debian/hyperv-daemons.hv-kvp-daemon.init   | 109 ++++++++++++++++++++++++++++
 debian/hyperv-daemons.hv-vss-daemon.init   | 109 ++++++++++++++++++++++++++++
 debian/rules.real                          |  10 +++
 debian/templates/control.main.in           |   2 +-
 10 files changed, 467 insertions(+), 3 deletions(-)

diff --git a/debian/build/tools/hv/.gitignore b/debian/build/tools/hv/.gitignore
index b6961eb..5684999 100644
--- a/debian/build/tools/hv/.gitignore
+++ b/debian/build/tools/hv/.gitignore
@@ -1 +1,2 @@
 /hv_*_daemon
+/check-hyperv
diff --git a/debian/build/tools/hv/Makefile b/debian/build/tools/hv/Makefile
index a1fddeb..fb3ff37 100644
--- a/debian/build/tools/hv/Makefile
+++ b/debian/build/tools/hv/Makefile
@@ -1,7 +1,8 @@
 PROGS = \
 	hv_fcopy_daemon \
 	hv_kvp_daemon \
-	hv_vss_daemon
+	hv_vss_daemon \
+	check-hyperv
 
 OUTDIR = tools/hv
 prefix = /usr/sbin
@@ -9,7 +10,8 @@ prefix = /usr/sbin
 include ../../Makefile.inc
 
 install-local-progs: $(PROGS)
-	@for p in $^; do \
+	@for p in $(filter-out check-hyperv,$^); do \
 	  echo " install -m755 '$$p' '$(DESTDIR)/$(prefix)'"; \
 	  install -D -m755 "$$p" "$(DESTDIR)/$(prefix)/$$(basename $$p)"; \
 	done
+	install -D -m755 check-hyperv '$(DESTDIR)/lib/hyperv-daemons/check-hyperv'
diff --git a/debian/build/tools/hv/check-hyperv.c b/debian/build/tools/hv/check-hyperv.c
new file mode 100644
index 0000000..4d2b6f5
--- /dev/null
+++ b/debian/build/tools/hv/check-hyperv.c
@@ -0,0 +1,103 @@
+/*
+ * This program is derived from systemd.
+ *
+ * Copyright 2011 Lennart Poettering
+ *
+ * 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; either version 2.1 of the License, or
+ * (at your option) any later version.
+ *
+ * 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.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this program; If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#include <stdbool.h>
+#include <stdint.h>
+#include <string.h>
+
+#define streq(a, b) (!strcmp(a, b))
+#define ELEMENTSOF(a) (sizeof(a) / sizeof((a)[0]))
+
+enum {
+	VIRTUALIZATION_NONE,
+	VIRTUALIZATION_VM_OTHER,
+	VIRTUALIZATION_MICROSOFT,
+};
+
+static int detect_vm_cpuid(void) {
+
+        static const struct {
+                const char *cpuid;
+                int id;
+        } cpuid_vendor_table[] = {
+                /* http://msdn.microsoft.com/en-us/library/ff542428.aspx */
+                { "Microsoft Hv", VIRTUALIZATION_MICROSOFT },
+        };
+
+        uint32_t eax, ecx;
+        bool hypervisor;
+
+        /* http://lwn.net/Articles/301888/ */
+
+#if defined (__i386__)
+#define REG_a "eax"
+#define REG_b "ebx"
+#elif defined (__amd64__)
+#define REG_a "rax"
+#define REG_b "rbx"
+#endif
+
+        /* First detect whether there is a hypervisor */
+        eax = 1;
+        __asm__ __volatile__ (
+                /* ebx/rbx is being used for PIC! */
+                "  push %%"REG_b"         \n\t"
+                "  cpuid                  \n\t"
+                "  pop %%"REG_b"          \n\t"
+
+                : "=a" (eax), "=c" (ecx)
+                : "0" (eax)
+        );
+
+        hypervisor = !!(ecx & 0x80000000U);
+
+        if (hypervisor) {
+                union {
+                        uint32_t sig32[3];
+                        char text[13];
+                } sig = {};
+                unsigned j;
+
+                /* There is a hypervisor, see what it is */
+                eax = 0x40000000U;
+                __asm__ __volatile__ (
+                        /* ebx/rbx is being used for PIC! */
+                        "  push %%"REG_b"         \n\t"
+                        "  cpuid                  \n\t"
+                        "  mov %%ebx, %1          \n\t"
+                        "  pop %%"REG_b"          \n\t"
+
+                        : "=a" (eax), "=r" (sig.sig32[0]), "=c" (sig.sig32[1]), "=d" (sig.sig32[2])
+                        : "0" (eax)
+                );
+
+                for (j = 0; j < ELEMENTSOF(cpuid_vendor_table); j ++)
+                        if (streq(sig.text, cpuid_vendor_table[j].cpuid))
+                                return cpuid_vendor_table[j].id;
+
+                return VIRTUALIZATION_VM_OTHER;
+        }
+
+        return VIRTUALIZATION_NONE;
+}
+
+int main(void)
+{
+	return detect_vm_cpuid() != VIRTUALIZATION_MICROSOFT;
+}
diff --git a/debian/changelog b/debian/changelog
index 53c8444..74137a1 100644
--- a/debian/changelog
+++ b/debian/changelog
@@ -5,6 +5,7 @@ linux-tools (3.16.7-ckt20-1~bpo70+1) UNRELEASED; urgency=low
     - perf: Work-around Perl bool definition conflict
     - hyperv-daemons: Add symlinks to ensure new kernel headers are used
     - hyperv-daemons: Remove use of dh-systemd
+    - hyperv-daemons: Add init scripts
 
  -- Ben Hutchings <ben at decadent.org.uk>  Sun, 24 Jan 2016 16:01:28 +0000
 
diff --git a/debian/copyright b/debian/copyright
index 1e7200f..7ba027e 100644
--- a/debian/copyright
+++ b/debian/copyright
@@ -30,3 +30,22 @@ License: GPL-2
 Files: debian/*
 Copyright: 2006-2012 Debian kernel team
 License: GPL-2
+
+Files: debian/build/tools/hv/check-hyperv.c
+Copyright: 2011 Lennart Poettering
+License: LGPL-2.1
+ 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; either version 2.1 of the License, or
+ (at your option) any later version.
+ .
+ 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.
+ .
+ You should have received a copy of the GNU Lesser General Public License
+ along with this program; If not, see <http://www.gnu.org/licenses/>.
+ .
+ On Debian systems, the complete text of the GNU Lesser General Public
+ License version 2.1 can be found in `/usr/share/common-licenses/LGPL-2.1'.
diff --git a/debian/hyperv-daemons.hv-fcopy-daemon.init b/debian/hyperv-daemons.hv-fcopy-daemon.init
new file mode 100755
index 0000000..24d944d
--- /dev/null
+++ b/debian/hyperv-daemons.hv-fcopy-daemon.init
@@ -0,0 +1,110 @@
+#! /bin/sh
+### BEGIN INIT INFO
+# Provides:          hyperv-daemons.hv-fcopy-daemon
+# Required-Start:    $remote_fs $syslog
+# Required-Stop:     $remote_fs $syslog
+# Default-Start:     2 3 4 5
+# Default-Stop:      0 1 6
+# Short-Description: Hyper-V file copy service (FCOPY) daemon
+### END INIT INFO
+
+PATH=/sbin:/usr/sbin:/bin:/usr/bin
+DESC="Hyper-V file copy service (FCOPY) daemon"
+NAME=hv_fcopy_daemon
+DAEMON=/usr/sbin/$NAME
+PIDFILE=/var/run/$NAME.pid
+SCRIPTNAME=/etc/init.d/hyperv-daemons.hv-fcopy-daemon
+
+# Exit if the package is not installed
+[ -x "$DAEMON" ] || exit 0
+
+# Exit if we are not running under Hyper-V or the kernel device does not exist
+/lib/hyperv-daemons/check-hyperv || exit 0
+[ -e "/dev/vmbus/hv_fcopy" ] || exit 0
+
+# Load the VERBOSE setting and other rcS variables
+. /lib/init/vars.sh
+
+# Define LSB log_* functions.
+. /lib/lsb/init-functions
+
+#
+# Function that starts the daemon/service
+#
+do_start()
+{
+	# Return
+	#   0 if daemon has been started
+	#   1 if daemon was already running
+	#   2 if daemon could not be started
+	start-stop-daemon --start --quiet --pidfile $PIDFILE --exec $DAEMON --test > /dev/null \
+		|| return 1
+	start-stop-daemon --start --quiet --pidfile $PIDFILE --exec $DAEMON --background --make-pidfile -- -n \
+		|| return 2
+}
+
+#
+# Function that stops the daemon/service
+#
+do_stop()
+{
+	# Return
+	#   0 if daemon has been stopped
+	#   1 if daemon was already stopped
+	#   2 if daemon could not be stopped
+	#   other if a failure occurred
+	start-stop-daemon --stop --quiet --retry=TERM/30/KILL/5 --pidfile $PIDFILE --name $NAME
+	[ "$?" = 2 ] && return 2
+	start-stop-daemon --stop --quiet --oknodo --retry=0/30/KILL/5 --exec $DAEMON
+	RETVAL=$?
+	[ "$RETVAL" = 2 ] && return 2
+	# Many daemons don't delete their pidfiles when they exit.
+	rm -f $PIDFILE
+	return "$RETVAL"
+}
+
+case "$1" in
+  start)
+	[ "$VERBOSE" != no ] && log_daemon_msg "Starting $DESC" "$NAME"
+	do_start
+	case "$?" in
+		0|1) [ "$VERBOSE" != no ] && log_end_msg 0 ;;
+		2) [ "$VERBOSE" != no ] && log_end_msg 1 ;;
+	esac
+	;;
+  stop)
+	[ "$VERBOSE" != no ] && log_daemon_msg "Stopping $DESC" "$NAME"
+	do_stop
+	case "$?" in
+		0|1) [ "$VERBOSE" != no ] && log_end_msg 0 ;;
+		2) [ "$VERBOSE" != no ] && log_end_msg 1 ;;
+	esac
+	;;
+  status)
+	status_of_proc "$DAEMON" "$NAME" && exit 0 || exit $?
+	;;
+  restart|force-reload)
+	log_daemon_msg "Restarting $DESC" "$NAME"
+	do_stop
+	case "$?" in
+	  0|1)
+		do_start
+		case "$?" in
+			0) log_end_msg 0 ;;
+			1) log_end_msg 1 ;; # Old process is still running
+			*) log_end_msg 1 ;; # Failed to start
+		esac
+		;;
+	  *)
+		# Failed to stop
+		log_end_msg 1
+		;;
+	esac
+	;;
+  *)
+	echo "Usage: $SCRIPTNAME {start|stop|status|restart|force-reload}" >&2
+	exit 3
+	;;
+esac
+
+:
diff --git a/debian/hyperv-daemons.hv-kvp-daemon.init b/debian/hyperv-daemons.hv-kvp-daemon.init
new file mode 100755
index 0000000..e5908ec
--- /dev/null
+++ b/debian/hyperv-daemons.hv-kvp-daemon.init
@@ -0,0 +1,109 @@
+#! /bin/sh
+### BEGIN INIT INFO
+# Provides:          hyperv-daemons.hv-kvp-daemon
+# Required-Start:    $remote_fs $syslog
+# Required-Stop:     $remote_fs $syslog
+# Default-Start:     2 3 4 5
+# Default-Stop:      0 1 6
+# Short-Description: Hyper-V key-value pair (KVP) daemon
+### END INIT INFO
+
+PATH=/sbin:/usr/sbin:/bin:/usr/bin
+DESC="Hyper-V key-value pair (KVP) daemon"
+NAME=hv_kvp_daemon
+DAEMON=/usr/sbin/$NAME
+PIDFILE=/var/run/$NAME.pid
+SCRIPTNAME=/etc/init.d/hyperv-daemons.hv-kvp-daemon
+
+# Exit if the package is not installed
+[ -x "$DAEMON" ] || exit 0
+
+# Exit if we are not running under Hyper-V
+/lib/hyperv-daemons/check-hyperv || exit 0
+
+# Load the VERBOSE setting and other rcS variables
+. /lib/init/vars.sh
+
+# Define LSB log_* functions.
+. /lib/lsb/init-functions
+
+#
+# Function that starts the daemon/service
+#
+do_start()
+{
+	# Return
+	#   0 if daemon has been started
+	#   1 if daemon was already running
+	#   2 if daemon could not be started
+	start-stop-daemon --start --quiet --pidfile $PIDFILE --exec $DAEMON --test > /dev/null \
+		|| return 1
+	start-stop-daemon --start --quiet --pidfile $PIDFILE --exec $DAEMON --background --make-pidfile -- -n \
+		|| return 2
+}
+
+#
+# Function that stops the daemon/service
+#
+do_stop()
+{
+	# Return
+	#   0 if daemon has been stopped
+	#   1 if daemon was already stopped
+	#   2 if daemon could not be stopped
+	#   other if a failure occurred
+	start-stop-daemon --stop --quiet --retry=TERM/30/KILL/5 --pidfile $PIDFILE --name $NAME
+	[ "$?" = 2 ] && return 2
+	start-stop-daemon --stop --quiet --oknodo --retry=0/30/KILL/5 --exec $DAEMON
+	RETVAL=$?
+	[ "$RETVAL" = 2 ] && return 2
+	# Many daemons don't delete their pidfiles when they exit.
+	rm -f $PIDFILE
+	return "$RETVAL"
+}
+
+case "$1" in
+  start)
+	[ "$VERBOSE" != no ] && log_daemon_msg "Starting $DESC" "$NAME"
+	do_start
+	case "$?" in
+		0|1) [ "$VERBOSE" != no ] && log_end_msg 0 ;;
+		2) [ "$VERBOSE" != no ] && log_end_msg 1 ;;
+	esac
+	;;
+  stop)
+	[ "$VERBOSE" != no ] && log_daemon_msg "Stopping $DESC" "$NAME"
+	do_stop
+	case "$?" in
+		0|1) [ "$VERBOSE" != no ] && log_end_msg 0 ;;
+		2) [ "$VERBOSE" != no ] && log_end_msg 1 ;;
+	esac
+	;;
+  status)
+	status_of_proc "$DAEMON" "$NAME" && exit 0 || exit $?
+	;;
+  restart|force-reload)
+	log_daemon_msg "Restarting $DESC" "$NAME"
+	do_stop
+	case "$?" in
+	  0|1)
+		do_start
+		case "$?" in
+			0) log_end_msg 0 ;;
+			1) log_end_msg 1 ;; # Old process is still running
+			*) log_end_msg 1 ;; # Failed to start
+		esac
+		;;
+	  *)
+		# Failed to stop
+		log_end_msg 1
+		;;
+	esac
+	;;
+  *)
+	echo "Usage: $SCRIPTNAME {start|stop|status|restart|force-reload}" >&2
+	exit 3
+	;;
+esac
+
+:
diff --git a/debian/hyperv-daemons.hv-vss-daemon.init b/debian/hyperv-daemons.hv-vss-daemon.init
new file mode 100755
index 0000000..aff28fc
--- /dev/null
+++ b/debian/hyperv-daemons.hv-vss-daemon.init
@@ -0,0 +1,109 @@
+#! /bin/sh
+### BEGIN INIT INFO
+# Provides:          hyperv-daemons.hv-vss-daemon
+# Required-Start:    $remote_fs $syslog
+# Required-Stop:     $remote_fs $syslog
+# Default-Start:     2 3 4 5
+# Default-Stop:      0 1 6
+# Short-Description: Hyper-V volume shadow copy service (VSS) daemon
+### END INIT INFO
+
+PATH=/sbin:/usr/sbin:/bin:/usr/bin
+DESC="Hyper-V volume shadow copy service (VSS) daemon"
+NAME=hv_vss_daemon
+DAEMON=/usr/sbin/$NAME
+PIDFILE=/var/run/$NAME.pid
+SCRIPTNAME=/etc/init.d/hyperv-daemons.hv-vss-daemon
+
+# Exit if the package is not installed
+[ -x "$DAEMON" ] || exit 0
+
+# Exit if we are not running under Hyper-V
+/lib/hyperv-daemons/check-hyperv || exit 0
+
+# Load the VERBOSE setting and other rcS variables
+. /lib/init/vars.sh
+
+# Define LSB log_* functions.
+. /lib/lsb/init-functions
+
+#
+# Function that starts the daemon/service
+#
+do_start()
+{
+	# Return
+	#   0 if daemon has been started
+	#   1 if daemon was already running
+	#   2 if daemon could not be started
+	start-stop-daemon --start --quiet --pidfile $PIDFILE --exec $DAEMON --test > /dev/null \
+		|| return 1
+	start-stop-daemon --start --quiet --pidfile $PIDFILE --exec $DAEMON --background --make-pidfile -- -n \
+		|| return 2
+}
+
+#
+# Function that stops the daemon/service
+#
+do_stop()
+{
+	# Return
+	#   0 if daemon has been stopped
+	#   1 if daemon was already stopped
+	#   2 if daemon could not be stopped
+	#   other if a failure occurred
+	start-stop-daemon --stop --quiet --retry=TERM/30/KILL/5 --pidfile $PIDFILE --name $NAME
+	[ "$?" = 2 ] && return 2
+	start-stop-daemon --stop --quiet --oknodo --retry=0/30/KILL/5 --exec $DAEMON
+	RETVAL=$?
+	[ "$RETVAL" = 2 ] && return 2
+	# Many daemons don't delete their pidfiles when they exit.
+	rm -f $PIDFILE
+	return "$RETVAL"
+}
+
+case "$1" in
+  start)
+	[ "$VERBOSE" != no ] && log_daemon_msg "Starting $DESC" "$NAME"
+	do_start
+	case "$?" in
+		0|1) [ "$VERBOSE" != no ] && log_end_msg 0 ;;
+		2) [ "$VERBOSE" != no ] && log_end_msg 1 ;;
+	esac
+	;;
+  stop)
+	[ "$VERBOSE" != no ] && log_daemon_msg "Stopping $DESC" "$NAME"
+	do_stop
+	case "$?" in
+		0|1) [ "$VERBOSE" != no ] && log_end_msg 0 ;;
+		2) [ "$VERBOSE" != no ] && log_end_msg 1 ;;
+	esac
+	;;
+  status)
+	status_of_proc "$DAEMON" "$NAME" && exit 0 || exit $?
+	;;
+  restart|force-reload)
+	log_daemon_msg "Restarting $DESC" "$NAME"
+	do_stop
+	case "$?" in
+	  0|1)
+		do_start
+		case "$?" in
+			0) log_end_msg 0 ;;
+			1) log_end_msg 1 ;; # Old process is still running
+			*) log_end_msg 1 ;; # Failed to start
+		esac
+		;;
+	  *)
+		# Failed to stop
+		log_end_msg 1
+		;;
+	esac
+	;;
+  *)
+	echo "Usage: $SCRIPTNAME {start|stop|status|restart|force-reload}" >&2
+	exit 3
+	;;
+esac
+
+:
diff --git a/debian/rules.real b/debian/rules.real
index 8505713..d19d33a 100644
--- a/debian/rules.real
+++ b/debian/rules.real
@@ -95,9 +95,19 @@ install-hyperv-daemons: $(STAMPS_DIR)/build
 	dh_clean -k -d
 	$(MAKE) -C $(BUILD_DIR)/tools/hv install top_srcdir=$(CURDIR) DESTDIR=$(DIR)
 	dh_install
+	for service in fcopy kvp vss; do \
+		install -D -m755 debian/hyperv-daemons.hv-$$service-daemon.init \
+			$(DIR)/etc/init.d/hyperv-daemons.hv-$$service-daemon \
+			|| break; \
+	done
 	dh_installchangelogs
 	dh_installdocs
 #	dh_systemd_enable
+	for service in fcopy kvp vss; do \
+		dh_installinit --name hyperv-daemons.hv-$$service-daemon \
+			--onlyscripts \
+			|| break; \
+	done
 #	dh_systemd_start
 	dh_lintian
 	dh_strip
diff --git a/debian/templates/control.main.in b/debian/templates/control.main.in
index 030dadc..f43e45a 100644
--- a/debian/templates/control.main.in
+++ b/debian/templates/control.main.in
@@ -52,7 +52,7 @@ Description: USB device sharing system over IP network
 
 Package: hyperv-daemons
 Architecture: i386 amd64
-Depends: ${shlibs:Depends}, ${misc:Depends}
+Depends: lsb-base (>= 3.2-14), ${shlibs:Depends}, ${misc:Depends}
 Section: admin
 Description: Support daemons for Linux running on Hyper-V
  Suite of daemons for Linux guests running on Hyper-V, consisting of

-- 
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/kernel/linux-tools.git



More information about the Kernel-svn-changes mailing list