diff --git a/ksm.init b/ksm.init new file mode 100644 index 0000000..a4bed2d --- /dev/null +++ b/ksm.init @@ -0,0 +1,104 @@ +#!/bin/bash +# +# ksm Kernel Samepage Merging +# +# Author: Dan Kenigsberg +# +# Copyright 2009 Red Hat, Inc. and/or its affiliates. +# Released under the GPL +# +# chkconfig: 345 84 16 +# description: The KSM init script starts and stops the ksm kernel thread. +# config: /etc/sysconfig/ksm +# +### BEGIN INIT INFO +# Provides: ksm +# Required-Start: +# Required-Stop: +# Should-Start: +# Default-Start: 3 4 5 +# Short-Description: start and stop ksm +# Description: The KSM init script starts and stops the ksm kernel thread. +### END INIT INFO + +. /etc/rc.d/init.d/functions + +if [ -f /etc/sysconfig/ksm ]; then + . /etc/sysconfig/ksm +fi + +prog=ksm +RETVAL=0 + +# unless KSM_MAX_KERNEL_PAGES is set, let ksm munch up to half of total memory. +default_max_kernel_pages () { + local total pagesize + total=`awk '/^MemTotal:/ {print $2}' /proc/meminfo` + pagesize=`getconf PAGESIZE` + echo $[total * 1024 / pagesize / 2] +} + +start() { + echo -n $"Starting $prog: " + if [ -f /sys/kernel/mm/ksm/max_kernel_pages ]; then + KSM_MAX_KERNEL_PAGES=${KSM_MAX_KERNEL_PAGES:-`default_max_kernel_pages`} + echo $KSM_MAX_KERNEL_PAGES > /sys/kernel/mm/ksm/max_kernel_pages + fi + echo 1 > /sys/kernel/mm/ksm/run + RETVAL=$? + [ $RETVAL = 0 ] && success $"$prog startup" || failure $"$prog startup" + echo +} + +stop() { + echo -n $"Stopping $prog: " + echo 0 > /sys/kernel/mm/ksm/run + RETVAL=$? + [ $RETVAL = 0 ] && success $"$prog shutdown" || failure $"$prog shutdown" + echo +} + +status() { + if [ ! -f /sys/kernel/mm/ksm/run ] ; then + echo $"$prog not supported" + RETVAL=1 + else if [ "$(cat /sys/kernel/mm/ksm/run 2>/dev/null)" != "1" ]; then + echo $"$prog is not running" + RETVAL=1 + else + echo $"$prog is running" + RETVAL=0 + fi; fi +} + +restart() { + stop + start +} + +case "$1" in + start) + start + ;; + stop) + stop + ;; + status) + status + ;; + restart) + restart + ;; + condrestart|try-restart) + status >/dev/null 2>&1 || exit 0 + restart + ;; + force-reload) + restart + ;; + *) + echo $"Usage: $prog {start|stop|restart|force-reload|condrestart|try-restart|status|help}" + RETVAL=2 +esac + +exit $RETVAL diff --git a/ksmtuned.init b/ksmtuned.init new file mode 100644 index 0000000..5cd6090 --- /dev/null +++ b/ksmtuned.init @@ -0,0 +1,94 @@ +#!/bin/bash +# +# ksmtuned Kernel Samepage Merging (KSM) Tuning Daemon +# +# Author: Dan Kenigsberg +# +# Copyright 2009 Red Hat, Inc. and/or its affiliates. +# Released under the GPL +# +# chkconfig: 345 85 15 +# description: The KSM tuning daemon controls whether (and with what vigor) \ +# ksm should ksm search duplicated pages. +# processname: ksmtuned +# config: /etc/ksmtuned.conf +# pidfile: /var/run/ksmtuned.pid +# +### BEGIN INIT INFO +# Provides: ksmtuned +# Required-Start: +# Required-Stop: +# Should-Start: +# Default-Start: 3 4 5 +# Short-Description: tune the speed of ksm +# Description: The Kernel Samepage Merging control Daemon is a simple script +# that controls whether (and with what vigor) should ksm search duplicated +# memory pages. +# needs testing and ironing. contact danken@redhat.com if something breaks. +### END INIT INFO + +. /etc/rc.d/init.d/functions + +prog=ksmtuned +ksmtuned=/usr/sbin/ksmtuned +pidfile=${PIDFILE-/var/run/ksmtune.pid} +RETVAL=0 + +start() { + echo -n $"Starting $prog: " + daemon --pidfile=${pidfile} $ksmtuned + RETVAL=$? + echo + [ $RETVAL -eq 0 ] && touch /var/lock/subsys/$prog +} + +stop() { + echo -n $"Stopping $prog: " + killproc -p ${pidfile} + RETVAL=$? + echo + [ $RETVAL -eq 0 ] && rm -f /var/lock/subsys/$prog +} + +restart() { + stop + start +} + +condrestart() { + [ -e /var/lock/subsys/$prog ] && restart || : +} + +case "$1" in + start) + start + ;; + stop) + stop + ;; + status) + status -p ${pidfile} $prog + RETVAL=$? + ;; + restart|force-reload) + restart + ;; + condrestart|try-restart) + condrestart + ;; + retune) + pid=`cat ${pidfile} 2> /dev/null` + RETVAL=$? + if [ -z "$pid" ]; then + echo $"Cannot retune, service is not running." + else + kill -SIGUSR1 $pid + RETVAL=$? + fi + ;; + *) + echo $"Usage: $prog {start|stop|restart|force-reload|condrestart|try-restart|status|retune|help}" + RETVAL=2 +esac + +exit $RETVAL diff --git a/qemu-ga.init b/qemu-ga.init new file mode 100644 index 0000000..8d6a866 --- /dev/null +++ b/qemu-ga.init @@ -0,0 +1,86 @@ +#!/bin/bash +# +# qemu-ga: QEMU Guest Agent init script +# Author: Lubomir Rintel +# +# chkconfig: - 80 30 +# description: QEMU Guest Agents lets a virtualized guest use functionality +# provided by the host hypervisor. +# processname: qemu-ga +# config: /etc/sysconfig/qemu-ga +# pidfile: /var/run/qemu-ga.pid +# +### BEGIN INIT INFO +# Provides: qemu-ga +# Required-Start: +# Required-Stop: +# Should-Start: +# Default-Start: +# Default-Stop: 0 1 2 6 +# Short-Description: QEMU Guest Agent +# Description: QEMU Guest Agents lets a virtualized guest use functionality +# provided by the host hypervisor. +### END INIT INFO + +. /etc/rc.d/init.d/functions + +prog=qemu-ga +qemuga=/usr/bin/qemu-ga +pidfile=${PIDFILE-/var/run/ksmtune.pid} +QEMUGA_DEV=/dev/virtio-ports/org.qemu.guest_agent.0 +RETVAL=0 + +# Source service configuration. +[ -e /etc/sysconfig/$prog ] && . /etc/sysconfig/$prog + +# Do nothing if the channel is not present +[ -e "$QEMUGA_DEV" ] || exit 0 + +start() { + echo -n $"Starting $prog: " + daemon --pidfile=${pidfile} $qemuga --daemonize $QEMUGA_OPTS + RETVAL=$? + echo + [ $RETVAL -eq 0 ] && touch /var/lock/subsys/$prog +} + +stop() { + echo -n $"Stopping $prog: " + killproc -p ${pidfile} + RETVAL=$? + echo + [ $RETVAL -eq 0 ] && rm -f /var/lock/subsys/$prog +} + +restart() { + stop + start +} + +condrestart() { + [ -e /var/lock/subsys/$prog ] && restart || : +} + +case "$1" in + start) + start + ;; + stop) + stop + ;; + status) + status -p ${pidfile} $prog + RETVAL=$? + ;; + restart|force-reload) + restart + ;; + condrestart|try-restart) + condrestart + ;; + *) + echo $"Usage: $prog {start|stop|restart|force-reload|condrestart|try-restart|status|retune|help}" + RETVAL=2 +esac + +exit $RETVAL diff --git a/qemu.init b/qemu.init new file mode 100644 index 0000000..95f19f2 --- /dev/null +++ b/qemu.init @@ -0,0 +1,102 @@ +#!/bin/sh +# +# qemu Allow users to run non-native Linux programs by just clicking on them +# (or typing ./file.exe) +# +# chkconfig: 2345 35 98 +# description: Allow users to run non-native Linux programs by just clicking \ +# on them (or typing ./file.exe) + +. /etc/rc.d/init.d/functions +RETVAL=0 +QEMU=/usr/bin + +start() { + cpu=`uname -m` + case "$cpu" in + i386|i486|i586|i686|i86pc|BePC) + cpu="i386" + ;; + "Power Macintosh"|ppc|ppc64) + cpu="ppc" + ;; + armv4l|armv5l) + cpu="arm" + ;; + sh4) + cpu="sh4" + ;; + esac + + echo -n $"Registering binary handler for qemu applications" + /sbin/modprobe binfmt_misc &>/dev/null + if [ "$cpu" != i386 -a -x $QEMU/qemu-i386 -a -d /usr/qemu-i386 ] ; then + echo ":qemu-i386:M::\x7fELF\x01\x01\x01\x00\x00\x00\x00\x00\x00\x00\x00\x00\x02\x00\x03\x00:\xff\xff\xff\xff\xff\xfe\xfe\xff\xff\xff\xff\xff\xff\xff\xff\xff\xfa\xff\xff\xff:$QEMU/qemu-i386:" > /proc/sys/fs/binfmt_misc/register + echo ":qemu-i486:M::\x7fELF\x01\x01\x01\x00\x00\x00\x00\x00\x00\x00\x00\x00\x02\x00\x06\x00:\xff\xff\xff\xff\xff\xfe\xfe\xff\xff\xff\xff\xff\xff\xff\xff\xff\xfa\xff\xff\xff:$QEMU/qemu-i386:" > /proc/sys/fs/binfmt_misc/register + fi + if [ "$cpu" != arm -a -x $QEMU/qemu-arm -a -d /usr/qemu-arm ] ; then + echo ":qemu-arm:M::\x7fELF\x01\x01\x01\x00\x00\x00\x00\x00\x00\x00\x00\x00\x02\x00\x28\x00:\xff\xff\xff\xff\xff\xff\xff\x00\xff\xff\xff\xff\xff\xff\xff\xff\xfa\xff\xff\xff:$QEMU/qemu-arm:" > /proc/sys/fs/binfmt_misc/register + fi + if [ "$cpu" != ppc -a -x $QEMU/qemu-ppc -a -d /usr/qemu-ppc ] ; then + echo ":ppc:M::\x7fELF\x01\x02\x01\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x02\x00\x14:\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xfa\xff\xff\xff:$QEMU/qemu-ppc:" > /proc/sys/fs/binfmt_misc/register + echo do ppc + fi + if [ "$cpu" != sparc -a -x $QEMU/qemu-sparc -a -d /usr/qemu-sparc ] ; then + echo ":qemu-sparc:M::\x7fELF\x01\x02\x01\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x02\x00\x02:\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xfa\xff\xff\xff:$QEMU/qemu-sparc:" > /proc/sys/fs/binfmt_misc/register + fi + if [ "$cpu" != sh4 -a -x $QEMU/qemu-sh4 -a -d /usr/qemu-sh4 ] ; then + echo ":qemu-sh4:M::\x7fELF\x01\x01\x01\x00\x00\x00\x00\x00\x00\x00\x00\x00\x02\x00\x2a\x00:\xff\xff\xff\xff\xff\xff\xff\x00\xff\xff\xff\xff\xff\xff\xff\xff\xfa\xff\xff\xff:$QEMU/qemu-sh4:" > /proc/sys/fs/binfmt_misc/register + fi + echo +} + +stop() { + echo -n $"Unregistering binary handler for qemu applications" + for a in i386 i486 ppc arm sparc sh4 ] ; do + [ -r /proc/sys/fs/binfmt_misc/qemu-$a ] && echo "-1" >/proc/sys/fs/binfmt_misc/qemu-$a + done + echo +} + +reload() { + stop + start +} + +qemu_status() { + if ls /proc/sys/fs/binfmt_misc/qemu-* &>/dev/null; then + echo $"qemu binary format handlers are registered." + return 0 + else + echo $"qemu binary format handlers are not registered." + return 3 + fi +} + +case "$1" in + start) + start + ;; + stop) + stop + ;; + status) + qemu_status + RETVAL=$? + ;; + restart) + stop + start + ;; + condrestart) + if qemu_status &>/dev/null; then + stop + start + fi + ;; + *) + echo $"Usage: $prog {start|stop|status|restart|condrestart}" + exit 1 +esac +exit $RETVAL + diff --git a/qemu.spec b/qemu.spec index 8773079..7db8f58 100644 --- a/qemu.spec +++ b/qemu.spec @@ -14,6 +14,11 @@ # Enable rbd support. # # Enable by default, except on RHEL. +# +# = systemd = +# Install systemd unit files instead of sysvinit scripts. +# +# Enabled by default. %if 0%{?rhel} # RHEL-specific defaults: @@ -22,6 +27,7 @@ %bcond_with rbd # disabled %bcond_without spice # enabled %bcond_without seccomp # enabled +%bcond_without systemd # enabled %else # General defaults: %bcond_with kvmonly # disabled @@ -29,6 +35,7 @@ %bcond_without rbd # enabled %bcond_without spice # enabled %bcond_without seccomp # enabled +%bcond_without systemd # enabled %endif %global SLOF_gittagdate 20120731 @@ -131,6 +138,7 @@ Source0: qemu-kvm-%{version}.tar.gz #Source0: http://downloads.sourceforge.net/sourceforge/kvm/qemu-kvm-%{version}.tar.gz Source1: qemu.binfmt +Source6661: qemu.init # Loads kvm kernel modules at boot Source2: kvm.modules @@ -140,14 +148,17 @@ Source3: 80-kvm.rules # KSM control scripts Source4: ksm.service +Source6664: ksm.init Source5: ksm.sysconfig Source6: ksmctl.c Source7: ksmtuned.service +Source6667: ksmtuned.init Source8: ksmtuned Source9: ksmtuned.conf Source10: qemu-guest-agent.service Source11: 99-qemu-guest-agent.rules +Source66610: qemu-ga.init # Patches queued for 1.2.1 stable Patch0001: 0001-target-xtensa-convert-host-errno-values-to-guest.patch @@ -632,9 +643,11 @@ Group: Development/Tools Requires(post): /usr/bin/getent Requires(post): /usr/sbin/groupadd Requires(post): /usr/sbin/useradd +%if %{with systemd} Requires(post): systemd-units Requires(preun): systemd-units Requires(postun): systemd-units +%endif %description common QEMU is a generic and open source processor emulator which achieves a good emulation speed by using dynamic translation. @@ -644,9 +657,11 @@ This package provides the common files needed by all QEMU targets %package guest-agent Summary: QEMU guest agent Group: System Environment/Daemons +%if %{with systemd} Requires(post): systemd-units Requires(preun): systemd-units Requires(postun): systemd-units +%endif %description guest-agent QEMU is a generic and open source processor emulator which achieves a good @@ -660,20 +675,34 @@ This package does not need to be installed on the host OS. %post guest-agent if [ $1 -eq 1 ] ; then # Initial installation. +%if %{with systemd} /bin/systemctl daemon-reload >/dev/null 2>&1 || : +%else + /sbin/chkconfig --add qemu-ga +%endif fi %preun guest-agent if [ $1 -eq 0 ] ; then # Package removal, not upgrade. +%if %{with systemd} /bin/systemctl stop qemu-guest-agent.service > /dev/null 2>&1 || : +%else + /sbin/chkconfig --del qemu-ga +%endif fi %postun guest-agent +%if %{with systemd} /bin/systemctl daemon-reload >/dev/null 2>&1 || : +%endif if [ $1 -ge 1 ] ; then # Package upgrade, not uninstall. +%if %{with systemd} /bin/systemctl try-restart qemu-guest-agent.service >/dev/null 2>&1 || : +%else + /sbin/service qemu-ga condrestart &>/dev/null || : +%endif fi @@ -683,8 +712,10 @@ fi Summary: QEMU user mode emulation of qemu targets Group: Development/Tools Requires: %{name}-common = %{epoch}:%{version}-%{release} +%if %{with systemd} Requires(post): systemd-units Requires(postun): systemd-units +%endif %description %{user} QEMU is a generic and open source processor emulator which achieves a good emulation speed by using dynamic translation. @@ -1327,11 +1358,21 @@ gcc %{SOURCE6} -O2 -g -o ksmctl %define _udevdir /lib/udev/rules.d +%if %{with systemd} install -D -p -m 0755 %{SOURCE4} $RPM_BUILD_ROOT/lib/systemd/system/ksm.service +%else +install -D -p -m 0755 %{SOURCE6664} $RPM_BUILD_ROOT%{_initddir}/ksm +%endif install -D -p -m 0644 %{SOURCE5} $RPM_BUILD_ROOT%{_sysconfdir}/sysconfig/ksm +%if %{with systemd} install -D -p -m 0755 ksmctl $RPM_BUILD_ROOT/lib/systemd/ksmctl +%endif +%if %{with systemd} install -D -p -m 0755 %{SOURCE7} $RPM_BUILD_ROOT/lib/systemd/system/ksmtuned.service +%else +install -D -p -m 0755 %{SOURCE6667} $RPM_BUILD_ROOT%{_initddir}/ksmtuned +%endif install -D -p -m 0755 %{SOURCE8} $RPM_BUILD_ROOT%{_sbindir}/ksmtuned install -D -p -m 0644 %{SOURCE9} $RPM_BUILD_ROOT%{_sysconfdir}/ksmtuned.conf @@ -1361,6 +1402,9 @@ rm $RPM_BUILD_ROOT%{_datadir}/systemtap/tapset/qemu-system-%{kvm_target}.stp %endif chmod -x ${RPM_BUILD_ROOT}%{_mandir}/man1/* +%if %{without systemd} +install -D -p -m 0755 %{SOURCE6661} $RPM_BUILD_ROOT%{_initddir}/qemu +%endif install -D -p -m 0644 -t ${RPM_BUILD_ROOT}%{qemudocdir} Changelog README TODO COPYING COPYING.LIB LICENSE install -D -p -m 0644 qemu.sasl $RPM_BUILD_ROOT%{_sysconfdir}/sasl2/qemu.conf @@ -1428,6 +1472,7 @@ rom_link ../seabios/bios.bin bios.bin rom_link ../sgabios/sgabios.bin sgabios.bin %endif +%if %{with systemd} %if 0%{?user:1} mkdir -p $RPM_BUILD_ROOT%{_exec_prefix}/lib/binfmt.d for i in dummy \ @@ -1476,6 +1521,11 @@ mkdir -p $RPM_BUILD_ROOT%{_unitdir} mkdir -p $RPM_BUILD_ROOT%{_udevdir} install -m 0644 %{SOURCE10} $RPM_BUILD_ROOT%{_unitdir} install -m 0644 %{SOURCE11} $RPM_BUILD_ROOT%{_udevdir} +%else +# For the qemu-guest-agent subpackage install the service +mkdir -p $RPM_BUILD_ROOT%{_initddir} +install -D -p -m 0755 %{SOURCE66610} $RPM_BUILD_ROOT%{_initddir}/qemu-ga +%endif %check make check @@ -1491,8 +1541,13 @@ udevadm trigger --sysname-match=kvm || : %post common if [ $1 -eq 1 ] ; then # Initial installation +%if %{with systemd} /bin/systemctl enable ksm.service >/dev/null 2>&1 || : /bin/systemctl enable ksmtuned.service >/dev/null 2>&1 || : +%else + /sbin/chkconfig --add ksm + /sbin/chkconfig --add ksmtuned +%endif fi getent group kvm >/dev/null || groupadd -g 36 -r kvm @@ -1504,27 +1559,59 @@ getent passwd qemu >/dev/null || \ %preun common if [ $1 -eq 0 ] ; then # Package removal, not upgrade +%if %{with systemd} /bin/systemctl --no-reload disable ksmtuned.service > /dev/null 2>&1 || : /bin/systemctl --no-reload disable ksm.service > /dev/null 2>&1 || : /bin/systemctl stop ksmtuned.service > /dev/null 2>&1 || : /bin/systemctl stop ksm.service > /dev/null 2>&1 || : +%else + /sbin/service ksmtuned stop &>/dev/null || : + /sbin/chkconfig --del ksmtuned + /sbin/service ksm stop &>/dev/null || : + /sbin/chkconfig --del ksm +%endif fi %postun common +%if %{with systemd} /bin/systemctl daemon-reload >/dev/null 2>&1 || : +%endif if [ $1 -ge 1 ] ; then # Package upgrade, not uninstall +%if %{with systemd} /bin/systemctl try-restart ksmtuned.service >/dev/null 2>&1 || : /bin/systemctl try-restart ksm.service >/dev/null 2>&1 || : +%else + /sbin/service ksm condrestart &>/dev/null || : + /sbin/service ksmtuned condrestart &>/dev/null || : +%endif fi %if 0%{?user:1} %post %{user} +%if %{with systemd} /bin/systemctl --system try-restart systemd-binfmt.service &>/dev/null || : +%else +/sbin/chkconfig --add qemu +%endif + +%preun user +if [ $1 -eq 0 ]; then +%if %{without systemd} + /sbin/service qemu stop &>/dev/null || : + /sbin/chkconfig --del qemu +%endif +fi %postun %{user} +%if %{with systemd} /bin/systemctl --system try-restart systemd-binfmt.service &>/dev/null || : +%else +if [ $1 -ge 1 ]; then + /sbin/service qemu condrestart &>/dev/null || : +fi +%endif %endif %global kvm_files \ @@ -1566,10 +1653,18 @@ fi %{_bindir}/virtfs-proxy-helper %{_libexecdir}/qemu-bridge-helper %config(noreplace) %{_sysconfdir}/sasl2/qemu.conf +%if %{with systemd} /lib/systemd/system/ksm.service /lib/systemd/ksmctl +%else +%{_initddir}/ksm +%endif %config(noreplace) %{_sysconfdir}/sysconfig/ksm +%if %{with systemd} /lib/systemd/system/ksmtuned.service +%else +%{_initddir}/ksmtuned +%endif %{_sbindir}/ksmtuned %config(noreplace) %{_sysconfdir}/ksmtuned.conf %dir %{_sysconfdir}/qemu @@ -1578,13 +1673,21 @@ fi %defattr(-,root,root,-) %doc COPYING README %{_bindir}/qemu-ga +%if %{with systemd} %{_unitdir}/qemu-guest-agent.service %{_udevdir}/99-qemu-guest-agent.rules +%else +%{_initddir}/qemu-ga +%endif %if 0%{?user:1} %files %{user} %defattr(-,root,root) +%if %{with systemd} %{_exec_prefix}/lib/binfmt.d/qemu-*.conf +%else +%{_initddir}/qemu +%endif %{_bindir}/qemu-i386 %{_bindir}/qemu-x86_64 %{_bindir}/qemu-alpha