[libvirt] [PATCH] Move libvirt-guests init script and config to tools
by Jiri Denemark
Since libvirt-guests init script and its configuration do not require
libvirtd to be running/installed, it was a bad idea to put them into
daemon directory. libvirt.spec even includes these files in
libvirt-client subpackage, which may result in build failure for
client-only builds when the whole daemon directory is just skipped.
---
daemon/Makefile.am | 16 +--
daemon/libvirt-guests.init.in | 341 -----------------------------------------
daemon/libvirt-guests.sysconf | 24 ---
tools/Makefile.am | 41 +++++-
tools/libvirt-guests.init.in | 341 +++++++++++++++++++++++++++++++++++++++++
tools/libvirt-guests.sysconf | 24 +++
6 files changed, 409 insertions(+), 378 deletions(-)
delete mode 100644 daemon/libvirt-guests.init.in
delete mode 100644 daemon/libvirt-guests.sysconf
create mode 100644 tools/libvirt-guests.init.in
create mode 100644 tools/libvirt-guests.sysconf
diff --git a/daemon/Makefile.am b/daemon/Makefile.am
index dbf0ac3..53133d2 100644
--- a/daemon/Makefile.am
+++ b/daemon/Makefile.am
@@ -35,8 +35,6 @@ EXTRA_DIST = \
libvirtd.uml.logrotate.in \
test_libvirtd.aug \
THREADING.txt \
- libvirt-guests.init.in \
- libvirt-guests.sysconf \
libvirtd.pod.in \
$(AVAHI_SOURCES) \
$(DAEMON_SOURCES)
@@ -258,27 +256,21 @@ install-logrotate: $(LOGROTATE_CONFS)
$(INSTALL_DATA) libvirtd.uml.logrotate $(DESTDIR)$(sysconfdir)/logrotate.d/libvirtd.uml
if LIBVIRT_INIT_SCRIPT_RED_HAT
-install-init: libvirtd.init libvirt-guests.init
+install-init: libvirtd.init
mkdir -p $(DESTDIR)$(sysconfdir)/rc.d/init.d
$(INSTALL_SCRIPT) libvirtd.init \
$(DESTDIR)$(sysconfdir)/rc.d/init.d/libvirtd
- $(INSTALL_SCRIPT) libvirt-guests.init \
- $(DESTDIR)$(sysconfdir)/rc.d/init.d/libvirt-guests
mkdir -p $(DESTDIR)$(sysconfdir)/sysconfig
$(INSTALL_SCRIPT) $(srcdir)/libvirtd.sysconf \
$(DESTDIR)$(sysconfdir)/sysconfig/libvirtd
- $(INSTALL_SCRIPT) $(srcdir)/libvirt-guests.sysconf \
- $(DESTDIR)$(sysconfdir)/sysconfig/libvirt-guests
uninstall-init:
rm -f $(DESTDIR)$(sysconfdir)/rc.d/init.d/libvirtd \
- $(DESTDIR)$(sysconfdir)/sysconfig/libvirtd \
- $(DESTDIR)$(sysconfdir)/rc.d/init.d/libvirt-guests \
- $(DESTDIR)$(sysconfdir)/sysconfig/libvirt-guests
+ $(DESTDIR)$(sysconfdir)/sysconfig/libvirtd
-BUILT_SOURCES += libvirtd.init libvirt-guests.init
+BUILT_SOURCES += libvirtd.init
-%.init: %.init.in $(top_builddir)/config.status
+libvirtd.init: libvirtd.init.in $(top_builddir)/config.status
$(AM_V_GEN)sed \
-e s!\@localstatedir\@!@localstatedir@!g \
-e s!\@sbindir\@!@sbindir@!g \
diff --git a/daemon/libvirt-guests.init.in b/daemon/libvirt-guests.init.in
deleted file mode 100644
index 993c12d..0000000
--- a/daemon/libvirt-guests.init.in
+++ /dev/null
@@ -1,341 +0,0 @@
-#!/bin/sh
-
-# the following is the LSB init header
-#
-### BEGIN INIT INFO
-# Provides: libvirt-guests
-# Required-Start: libvirtd
-# Required-Stop: libvirtd
-# Default-Start: 3 4 5
-# Short-Description: suspend/resume libvirt guests on shutdown/boot
-# Description: This is a script for suspending active libvirt guests
-# on shutdown and resuming them on next boot
-# See http://libvirt.org
-### END INIT INFO
-
-# the following is chkconfig init header
-#
-# libvirt-guests: suspend/resume libvirt guests on shutdown/boot
-#
-# chkconfig: 345 98 02
-# description: This is a script for suspending active libvirt guests \
-# on shutdown and resuming them on next boot \
-# See http://libvirt.org
-#
-
-sysconfdir=@sysconfdir@
-localstatedir=@localstatedir@
-libvirtd=@sbindir@/libvirtd
-
-# Source function library.
-. "$sysconfdir"/rc.d/init.d/functions
-
-URIS=default
-ON_BOOT=start
-ON_SHUTDOWN=suspend
-SHUTDOWN_TIMEOUT=0
-
-test -f "$sysconfdir"/sysconfig/libvirt-guests && . "$sysconfdir"/sysconfig/libvirt-guests
-
-LISTFILE="$localstatedir"/lib/libvirt/libvirt-guests
-VAR_SUBSYS_LIBVIRT_GUESTS="$localstatedir"/lock/subsys/libvirt-guests
-
-RETVAL=0
-
-retval() {
- "$@"
- if [ $? -ne 0 ]; then
- RETVAL=1
- return 1
- else
- return 0
- fi
-}
-
-run_virsh() {
- uri=$1
- shift
-
- if [ "x$uri" = xdefault ]; then
- conn=
- else
- conn="-c $uri"
- fi
-
- virsh $conn "$@" </dev/null
-}
-
-run_virsh_c() {
- ( export LC_ALL=C; run_virsh "$@" )
-}
-
-list_guests() {
- uri=$1
-
- list=$(run_virsh_c $uri list)
- if [ $? -ne 0 ]; then
- RETVAL=1
- return 1
- fi
-
- uuids=
- for id in $(echo "$list" | awk 'NR > 2 {print $1}'); do
- uuid=$(run_virsh_c $uri dominfo $id | awk '/^UUID:/{print $2}')
- if [ -z "$uuid" ]; then
- RETVAL=1
- return 1
- fi
- uuids="$uuids $uuid"
- done
-
- echo $uuids
-}
-
-guest_name() {
- uri=$1
- uuid=$2
-
- name=$(run_virsh_c $uri dominfo $uuid 2>/dev/null | \
- awk '/^Name:/{print $2}')
- [ -n "$name" ] || name=$uuid
-
- echo "$name"
-}
-
-guest_is_on() {
- uri=$1
- uuid=$2
-
- guest_running=false
- info=$(run_virsh_c $uri dominfo $uuid)
- if [ $? -ne 0 ]; then
- RETVAL=1
- return 1
- fi
-
- id=$(echo "$info" | awk '/^Id:/{print $2}')
-
- [ -n "$id" ] && [ "x$id" != x- ] && guest_running=true
- return 0
-}
-
-started() {
- touch "$VAR_SUBSYS_LIBVIRT_GUESTS"
-}
-
-start() {
- [ -f "$LISTFILE" ] || { started; return 0; }
-
- if [ "x$ON_BOOT" != xstart ]; then
- echo $"libvirt-guests is configured not to start any guests on boot"
- rm -f "$LISTFILE"
- started
- return 0
- fi
-
- while read uri list; do
- configured=false
- for confuri in $URIS; do
- if [ $confuri = $uri ]; then
- configured=true
- break
- fi
- done
- if ! $configured; then
- echo $"Ignoring guests on $uri URI"
- continue
- fi
-
- echo $"Resuming guests on $uri URI..."
- for guest in $list; do
- name=$(guest_name $uri $guest)
- echo -n $"Resuming guest $name: "
- if guest_is_on $uri $guest; then
- if $guest_running; then
- echo $"already active"
- else
- retval run_virsh $uri start "$name" >/dev/null && \
- echo $"done"
- fi
- fi
- done
- done <"$LISTFILE"
-
- rm -f "$LISTFILE"
- started
-}
-
-suspend_guest()
-{
- uri=$1
- guest=$2
-
- name=$(guest_name $uri $guest)
- label=$"Suspending $name: "
- echo -n "$label"
- run_virsh $uri managedsave $guest >/dev/null &
- virsh_pid=$!
- while true; do
- sleep 1
- kill -0 $virsh_pid >&/dev/null || break
- progress=$(run_virsh_c $uri domjobinfo $guest 2>/dev/null | \
- awk '/^Data processed:/{print $3, $4}')
- if [ -n "$progress" ]; then
- printf '\r%s%12s ' "$label" "$progress"
- else
- printf '\r%s%-12s ' "$label" "..."
- fi
- done
- retval wait $virsh_pid && printf '\r%s%-12s\n' "$label" $"done"
-}
-
-shutdown_guest()
-{
- uri=$1
- guest=$2
-
- name=$(guest_name $uri $guest)
- label=$"Shutting down $name: "
- echo -n "$label"
- retval run_virsh $uri shutdown $guest >/dev/null || return
- timeout=$SHUTDOWN_TIMEOUT
- while [ $timeout -gt 0 ]; do
- sleep 1
- timeout=$[timeout - 1]
- guest_is_on $uri $guest || return
- $guest_running || break
- printf '\r%s%-12d ' "$label" $timeout
- done
-
- if guest_is_on $uri $guest; then
- if $guest_running; then
- printf '\r%s%-12s\n' "$label" $"failed to shutdown in time"
- else
- printf '\r%s%-12s\n' "$label" $"done"
- fi
- fi
-}
-
-stop() {
- # last stop was not followed by start
- [ -f "$LISTFILE" ] && return 0
-
- suspending=true
- if [ "x$ON_SHUTDOWN" = xshutdown ]; then
- suspending=false
- if [ $SHUTDOWN_TIMEOUT -le 0 ]; then
- echo $"Shutdown action requested but SHUTDOWN_TIMEOUT was not set"
- RETVAL=6
- return
- fi
- fi
-
- : >"$LISTFILE"
- for uri in $URIS; do
- echo -n $"Running guests on $uri URI: "
-
- if [ "x$uri" = xdefault ] && [ ! -x "$libvirtd" ]; then
- echo $"libvirtd not installed; skipping this URI."
- continue
- fi
-
- list=$(list_guests $uri)
- if [ $? -eq 0 ]; then
- empty=true
- for uuid in $list; do
- $empty || printf ", "
- echo -n $(guest_name $uri $uuid)
- empty=false
- done
- if $empty; then
- echo $"no running guests."
- else
- echo
- echo $uri $list >>"$LISTFILE"
- fi
- fi
- done
-
- while read uri list; do
- if $suspending; then
- echo $"Suspending guests on $uri URI..."
- else
- echo $"Shutting down guests on $uri URI..."
- fi
-
- for guest in $list; do
- if $suspending; then
- suspend_guest $uri $guest
- else
- shutdown_guest $uri $guest
- fi
- done
- done <"$LISTFILE"
-
- rm -f "$VAR_SUBSYS_LIBVIRT_GUESTS"
-}
-
-gueststatus() {
- for uri in $URIS; do
- echo "* $uri URI:"
- retval run_virsh $uri list || echo
- done
-}
-
-# rh_status
-# Display current status: whether saved state exists, and whether start
-# has been executed. We cannot use status() from the functions library,
-# since there is no external daemon process matching this init script.
-rh_status() {
- if [ -f "$LISTFILE" ]; then
- echo $"stopped, with saved guests"
- RETVAL=3
- else
- if [ -f "$VAR_SUBSYS_LIBVIRT_GUESTS" ]; then
- echo $"started"
- else
- echo $"stopped, with no saved guests"
- fi
- RETVAL=0
- fi
-}
-
-# usage [val]
-# Display usage string, then exit with VAL (defaults to 2).
-usage() {
- echo $"Usage: $0 {start|stop|status|restart|condrestart|try-restart|reload|force-reload|gueststatus|shutdown}"
- exit ${1-2}
-}
-
-# See how we were called.
-if test $# != 1; then
- usage
-fi
-case "$1" in
- --help)
- usage 0
- ;;
- start|stop|gueststatus)
- $1
- ;;
- restart)
- stop && start
- ;;
- condrestart|try-restart)
- [ -f "$VAR_SUBSYS_LIBVIRT_GUESTS" ] && stop && start
- ;;
- reload|force-reload)
- # Nothing to do; we reread configuration on each invocation
- ;;
- status)
- rh_status
- ;;
- shutdown)
- ON_SHUTDOWN=shutdown
- stop
- ;;
- *)
- usage
- ;;
-esac
-exit $RETVAL
diff --git a/daemon/libvirt-guests.sysconf b/daemon/libvirt-guests.sysconf
deleted file mode 100644
index cd58728..0000000
--- a/daemon/libvirt-guests.sysconf
+++ /dev/null
@@ -1,24 +0,0 @@
-# URIs to check for running guests
-# example: URIS='default xen:/// vbox+tcp://host/system lxc:///'
-#URIS=default
-
-# action taken on host boot
-# - start all guests which were running on shutdown are started on boot
-# regardless on their autostart settings
-# - ignore libvirt-guests init script won't start any guest on boot, however,
-# guests marked as autostart will still be automatically started by
-# libvirtd
-#ON_BOOT=start
-
-# action taken on host shutdown
-# - suspend all running guests are suspended using virsh managedsave
-# - shutdown all running guests are asked to shutdown. Please be careful with
-# this settings since there is no way to distinguish between a
-# guest which is stuck or ignores shutdown requests and a guest
-# which just needs a long time to shutdown. When setting
-# ON_SHUTDOWN=shutdown, you must also set SHUTDOWN_TIMEOUT to a
-# value suitable for your guests.
-#ON_SHUTDOWN=suspend
-
-# number of seconds we're willing to wait for a guest to shut down
-#SHUTDOWN_TIMEOUT=0
diff --git a/tools/Makefile.am b/tools/Makefile.am
index fd05e8b..ac26cae 100644
--- a/tools/Makefile.am
+++ b/tools/Makefile.am
@@ -8,7 +8,13 @@ ICON_FILES = \
libvirt_win_icon_64x64.ico \
virsh_win_icon.rc
-EXTRA_DIST = $(ICON_FILES) virt-xml-validate.in virt-pki-validate.in virsh.pod
+EXTRA_DIST = \
+ $(ICON_FILES) \
+ virt-xml-validate.in \
+ virt-pki-validate.in \
+ virsh.pod \
+ libvirt-guests.init.in \
+ libvirt-guests.sysconf
bin_SCRIPTS = virt-xml-validate virt-pki-validate
bin_PROGRAMS = virsh
@@ -118,6 +124,39 @@ endif
virsh.1: virsh.pod
$(AM_V_GEN)$(POD2MAN) $< $@
+install-data-local: install-init
+
+uninstall-local: uninstall-init
+
+if LIBVIRT_INIT_SCRIPT_RED_HAT
+install-init: libvirt-guests.init
+ mkdir -p $(DESTDIR)$(sysconfdir)/rc.d/init.d
+ $(INSTALL_SCRIPT) libvirt-guests.init \
+ $(DESTDIR)$(sysconfdir)/rc.d/init.d/libvirt-guests
+ mkdir -p $(DESTDIR)$(sysconfdir)/sysconfig
+ $(INSTALL_SCRIPT) $(srcdir)/libvirt-guests.sysconf \
+ $(DESTDIR)$(sysconfdir)/sysconfig/libvirt-guests
+
+uninstall-init:
+ rm -f $(DESTDIR)$(sysconfdir)/rc.d/init.d/libvirt-guests \
+ $(DESTDIR)$(sysconfdir)/sysconfig/libvirt-guests
+
+BUILT_SOURCES += libvirt-guests.init
+
+libvirt-guests.init: libvirt-guests.init.in $(top_builddir)/config.status
+ $(AM_V_GEN)sed \
+ -e s!\@localstatedir\@!@localstatedir@!g \
+ -e s!\@sbindir\@!@sbindir@!g \
+ -e s!\@sysconfdir\@!@sysconfdir@!g \
+ < $< > $@-t && \
+ chmod a+x $@-t && \
+ mv $@-t $@
+else
+install-init:
+uninstall-init:
+libvirt-guests.init:
+endif # LIBVIRT_INIT_SCRIPT_RED_HAT
+
CLEANFILES = $(bin_SCRIPTS) $(man1_MANS)
diff --git a/tools/libvirt-guests.init.in b/tools/libvirt-guests.init.in
new file mode 100644
index 0000000..993c12d
--- /dev/null
+++ b/tools/libvirt-guests.init.in
@@ -0,0 +1,341 @@
+#!/bin/sh
+
+# the following is the LSB init header
+#
+### BEGIN INIT INFO
+# Provides: libvirt-guests
+# Required-Start: libvirtd
+# Required-Stop: libvirtd
+# Default-Start: 3 4 5
+# Short-Description: suspend/resume libvirt guests on shutdown/boot
+# Description: This is a script for suspending active libvirt guests
+# on shutdown and resuming them on next boot
+# See http://libvirt.org
+### END INIT INFO
+
+# the following is chkconfig init header
+#
+# libvirt-guests: suspend/resume libvirt guests on shutdown/boot
+#
+# chkconfig: 345 98 02
+# description: This is a script for suspending active libvirt guests \
+# on shutdown and resuming them on next boot \
+# See http://libvirt.org
+#
+
+sysconfdir=@sysconfdir@
+localstatedir=@localstatedir@
+libvirtd=@sbindir@/libvirtd
+
+# Source function library.
+. "$sysconfdir"/rc.d/init.d/functions
+
+URIS=default
+ON_BOOT=start
+ON_SHUTDOWN=suspend
+SHUTDOWN_TIMEOUT=0
+
+test -f "$sysconfdir"/sysconfig/libvirt-guests && . "$sysconfdir"/sysconfig/libvirt-guests
+
+LISTFILE="$localstatedir"/lib/libvirt/libvirt-guests
+VAR_SUBSYS_LIBVIRT_GUESTS="$localstatedir"/lock/subsys/libvirt-guests
+
+RETVAL=0
+
+retval() {
+ "$@"
+ if [ $? -ne 0 ]; then
+ RETVAL=1
+ return 1
+ else
+ return 0
+ fi
+}
+
+run_virsh() {
+ uri=$1
+ shift
+
+ if [ "x$uri" = xdefault ]; then
+ conn=
+ else
+ conn="-c $uri"
+ fi
+
+ virsh $conn "$@" </dev/null
+}
+
+run_virsh_c() {
+ ( export LC_ALL=C; run_virsh "$@" )
+}
+
+list_guests() {
+ uri=$1
+
+ list=$(run_virsh_c $uri list)
+ if [ $? -ne 0 ]; then
+ RETVAL=1
+ return 1
+ fi
+
+ uuids=
+ for id in $(echo "$list" | awk 'NR > 2 {print $1}'); do
+ uuid=$(run_virsh_c $uri dominfo $id | awk '/^UUID:/{print $2}')
+ if [ -z "$uuid" ]; then
+ RETVAL=1
+ return 1
+ fi
+ uuids="$uuids $uuid"
+ done
+
+ echo $uuids
+}
+
+guest_name() {
+ uri=$1
+ uuid=$2
+
+ name=$(run_virsh_c $uri dominfo $uuid 2>/dev/null | \
+ awk '/^Name:/{print $2}')
+ [ -n "$name" ] || name=$uuid
+
+ echo "$name"
+}
+
+guest_is_on() {
+ uri=$1
+ uuid=$2
+
+ guest_running=false
+ info=$(run_virsh_c $uri dominfo $uuid)
+ if [ $? -ne 0 ]; then
+ RETVAL=1
+ return 1
+ fi
+
+ id=$(echo "$info" | awk '/^Id:/{print $2}')
+
+ [ -n "$id" ] && [ "x$id" != x- ] && guest_running=true
+ return 0
+}
+
+started() {
+ touch "$VAR_SUBSYS_LIBVIRT_GUESTS"
+}
+
+start() {
+ [ -f "$LISTFILE" ] || { started; return 0; }
+
+ if [ "x$ON_BOOT" != xstart ]; then
+ echo $"libvirt-guests is configured not to start any guests on boot"
+ rm -f "$LISTFILE"
+ started
+ return 0
+ fi
+
+ while read uri list; do
+ configured=false
+ for confuri in $URIS; do
+ if [ $confuri = $uri ]; then
+ configured=true
+ break
+ fi
+ done
+ if ! $configured; then
+ echo $"Ignoring guests on $uri URI"
+ continue
+ fi
+
+ echo $"Resuming guests on $uri URI..."
+ for guest in $list; do
+ name=$(guest_name $uri $guest)
+ echo -n $"Resuming guest $name: "
+ if guest_is_on $uri $guest; then
+ if $guest_running; then
+ echo $"already active"
+ else
+ retval run_virsh $uri start "$name" >/dev/null && \
+ echo $"done"
+ fi
+ fi
+ done
+ done <"$LISTFILE"
+
+ rm -f "$LISTFILE"
+ started
+}
+
+suspend_guest()
+{
+ uri=$1
+ guest=$2
+
+ name=$(guest_name $uri $guest)
+ label=$"Suspending $name: "
+ echo -n "$label"
+ run_virsh $uri managedsave $guest >/dev/null &
+ virsh_pid=$!
+ while true; do
+ sleep 1
+ kill -0 $virsh_pid >&/dev/null || break
+ progress=$(run_virsh_c $uri domjobinfo $guest 2>/dev/null | \
+ awk '/^Data processed:/{print $3, $4}')
+ if [ -n "$progress" ]; then
+ printf '\r%s%12s ' "$label" "$progress"
+ else
+ printf '\r%s%-12s ' "$label" "..."
+ fi
+ done
+ retval wait $virsh_pid && printf '\r%s%-12s\n' "$label" $"done"
+}
+
+shutdown_guest()
+{
+ uri=$1
+ guest=$2
+
+ name=$(guest_name $uri $guest)
+ label=$"Shutting down $name: "
+ echo -n "$label"
+ retval run_virsh $uri shutdown $guest >/dev/null || return
+ timeout=$SHUTDOWN_TIMEOUT
+ while [ $timeout -gt 0 ]; do
+ sleep 1
+ timeout=$[timeout - 1]
+ guest_is_on $uri $guest || return
+ $guest_running || break
+ printf '\r%s%-12d ' "$label" $timeout
+ done
+
+ if guest_is_on $uri $guest; then
+ if $guest_running; then
+ printf '\r%s%-12s\n' "$label" $"failed to shutdown in time"
+ else
+ printf '\r%s%-12s\n' "$label" $"done"
+ fi
+ fi
+}
+
+stop() {
+ # last stop was not followed by start
+ [ -f "$LISTFILE" ] && return 0
+
+ suspending=true
+ if [ "x$ON_SHUTDOWN" = xshutdown ]; then
+ suspending=false
+ if [ $SHUTDOWN_TIMEOUT -le 0 ]; then
+ echo $"Shutdown action requested but SHUTDOWN_TIMEOUT was not set"
+ RETVAL=6
+ return
+ fi
+ fi
+
+ : >"$LISTFILE"
+ for uri in $URIS; do
+ echo -n $"Running guests on $uri URI: "
+
+ if [ "x$uri" = xdefault ] && [ ! -x "$libvirtd" ]; then
+ echo $"libvirtd not installed; skipping this URI."
+ continue
+ fi
+
+ list=$(list_guests $uri)
+ if [ $? -eq 0 ]; then
+ empty=true
+ for uuid in $list; do
+ $empty || printf ", "
+ echo -n $(guest_name $uri $uuid)
+ empty=false
+ done
+ if $empty; then
+ echo $"no running guests."
+ else
+ echo
+ echo $uri $list >>"$LISTFILE"
+ fi
+ fi
+ done
+
+ while read uri list; do
+ if $suspending; then
+ echo $"Suspending guests on $uri URI..."
+ else
+ echo $"Shutting down guests on $uri URI..."
+ fi
+
+ for guest in $list; do
+ if $suspending; then
+ suspend_guest $uri $guest
+ else
+ shutdown_guest $uri $guest
+ fi
+ done
+ done <"$LISTFILE"
+
+ rm -f "$VAR_SUBSYS_LIBVIRT_GUESTS"
+}
+
+gueststatus() {
+ for uri in $URIS; do
+ echo "* $uri URI:"
+ retval run_virsh $uri list || echo
+ done
+}
+
+# rh_status
+# Display current status: whether saved state exists, and whether start
+# has been executed. We cannot use status() from the functions library,
+# since there is no external daemon process matching this init script.
+rh_status() {
+ if [ -f "$LISTFILE" ]; then
+ echo $"stopped, with saved guests"
+ RETVAL=3
+ else
+ if [ -f "$VAR_SUBSYS_LIBVIRT_GUESTS" ]; then
+ echo $"started"
+ else
+ echo $"stopped, with no saved guests"
+ fi
+ RETVAL=0
+ fi
+}
+
+# usage [val]
+# Display usage string, then exit with VAL (defaults to 2).
+usage() {
+ echo $"Usage: $0 {start|stop|status|restart|condrestart|try-restart|reload|force-reload|gueststatus|shutdown}"
+ exit ${1-2}
+}
+
+# See how we were called.
+if test $# != 1; then
+ usage
+fi
+case "$1" in
+ --help)
+ usage 0
+ ;;
+ start|stop|gueststatus)
+ $1
+ ;;
+ restart)
+ stop && start
+ ;;
+ condrestart|try-restart)
+ [ -f "$VAR_SUBSYS_LIBVIRT_GUESTS" ] && stop && start
+ ;;
+ reload|force-reload)
+ # Nothing to do; we reread configuration on each invocation
+ ;;
+ status)
+ rh_status
+ ;;
+ shutdown)
+ ON_SHUTDOWN=shutdown
+ stop
+ ;;
+ *)
+ usage
+ ;;
+esac
+exit $RETVAL
diff --git a/tools/libvirt-guests.sysconf b/tools/libvirt-guests.sysconf
new file mode 100644
index 0000000..cd58728
--- /dev/null
+++ b/tools/libvirt-guests.sysconf
@@ -0,0 +1,24 @@
+# URIs to check for running guests
+# example: URIS='default xen:/// vbox+tcp://host/system lxc:///'
+#URIS=default
+
+# action taken on host boot
+# - start all guests which were running on shutdown are started on boot
+# regardless on their autostart settings
+# - ignore libvirt-guests init script won't start any guest on boot, however,
+# guests marked as autostart will still be automatically started by
+# libvirtd
+#ON_BOOT=start
+
+# action taken on host shutdown
+# - suspend all running guests are suspended using virsh managedsave
+# - shutdown all running guests are asked to shutdown. Please be careful with
+# this settings since there is no way to distinguish between a
+# guest which is stuck or ignores shutdown requests and a guest
+# which just needs a long time to shutdown. When setting
+# ON_SHUTDOWN=shutdown, you must also set SHUTDOWN_TIMEOUT to a
+# value suitable for your guests.
+#ON_SHUTDOWN=suspend
+
+# number of seconds we're willing to wait for a guest to shut down
+#SHUTDOWN_TIMEOUT=0
--
1.7.2.2
14 years, 7 months
[libvirt] [PATCH] spec: Fix undefined with_libnl
by Jiri Denemark
When building libvirt RPM without macvtap, with_libnl would be
undefined.
---
libvirt.spec.in | 1 +
1 files changed, 1 insertions(+), 0 deletions(-)
diff --git a/libvirt.spec.in b/libvirt.spec.in
index cc3e8e2..e530b1a 100644
--- a/libvirt.spec.in
+++ b/libvirt.spec.in
@@ -64,6 +64,7 @@
%define with_nwfilter 0%{!?_without_nwfilter:0}
%define with_libpcap 0%{!?_without_libpcap:0}
%define with_macvtap 0%{!?_without_macvtap:0}
+%define with_libnl 0%{!?_without_libnl:0}
# Non-server/HV driver defaults which are always enabled
%define with_python 0%{!?_without_python:1}
--
1.7.2.2
14 years, 7 months
Re: [libvirt] KVM doesn't send an arp announce after live migrating a domain
by Avi Kivity
On 08/25/2010 12:21 PM, Nils Cant wrote:
> On 08/25/2010 10:38 AM, Gleb Natapov wrote:
>> qemu sends gratuitous ARP after migration. Check forward delay
>> setting on your
>> bridge interface. It should be set to zero.
>>
>
> Aha! That fixed it. Turns out that debian bridge-utils sets the
> default to 15 for bridges.
> Manually setting it to 0 with 'brctl setfd br0 0' or setting the
> 'bridge_fd' parameter to 0 in /etc/network/interfaces solves the issue.
>
I think libvirt is doing something about this, copying list for further
info.
--
I have a truly marvellous patch that fixes the bug which this
signature is too narrow to contain.
14 years, 7 months
[libvirt] Add new API for accessing remote guest text console
by Daniel P. Berrange
The 'virsh console' command has been an oddity that only works
when run locally, as the same UID as the QEMU instance. This
is because it directly opens /dev/pty/XXX. This introduces a
formal API for accessing consoles that uses the virStreamPtr
APIs. Now any app can open consoles anywhere it can connect
to libvirt
14 years, 7 months
[libvirt] [PATCH 1/2] Rename qemudShrinkDisks to virDomainDiskRemove and move to domain_conf.c
by soren@linux2go.dk
From: Soren Hansen <soren(a)linux2go.dk>
Other drivers will need this same functionality, so move it to up to
conf/domain_conf.c and give it a more general name.
Signed-off-by: Soren Hansen <soren(a)linux2go.dk>
---
src/conf/domain_conf.c | 18 ++++++++++++++++++
src/conf/domain_conf.h | 2 ++
src/libvirt_private.syms | 1 +
src/qemu/qemu_driver.c | 20 ++------------------
4 files changed, 23 insertions(+), 18 deletions(-)
diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c
index ee99cd1..e05d5d7 100644
--- a/src/conf/domain_conf.c
+++ b/src/conf/domain_conf.c
@@ -4064,6 +4064,24 @@ void virDomainDiskInsertPreAlloced(virDomainDefPtr def,
}
+void virDomainDiskRemove(virDomainDefPtr def, size_t i)
+{
+ if (def->ndisks > 1) {
+ memmove(def->disks + i,
+ def->disks + i + 1,
+ sizeof(*def->disks) *
+ (def->ndisks - (i + 1)));
+ def->ndisks--;
+ if (VIR_REALLOC_N(def->disks, def->ndisks) < 0) {
+ /* ignore, harmless */
+ }
+ } else {
+ VIR_FREE(def->disks);
+ def->ndisks = 0;
+ }
+}
+
+
int virDomainControllerInsert(virDomainDefPtr def,
virDomainControllerDefPtr controller)
{
diff --git a/src/conf/domain_conf.h b/src/conf/domain_conf.h
index 92f98bc..7195c04 100644
--- a/src/conf/domain_conf.h
+++ b/src/conf/domain_conf.h
@@ -1067,6 +1067,8 @@ void virDomainDiskInsertPreAlloced(virDomainDefPtr def,
virDomainDiskDefPtr disk);
int virDomainDiskDefAssignAddress(virCapsPtr caps, virDomainDiskDefPtr def);
+void virDomainDiskRemove(virDomainDefPtr def, size_t i);
+
int virDomainControllerInsert(virDomainDefPtr def,
virDomainControllerDefPtr controller);
void virDomainControllerInsertPreAlloced(virDomainDefPtr def,
diff --git a/src/libvirt_private.syms b/src/libvirt_private.syms
index d5a7a73..c2905ba 100644
--- a/src/libvirt_private.syms
+++ b/src/libvirt_private.syms
@@ -144,6 +144,7 @@ virDomainDiskDefFree;
virDomainDiskDeviceTypeToString;
virDomainDiskInsert;
virDomainDiskInsertPreAlloced;
+virDomainDiskRemove;
virDomainDiskDefAssignAddress;
virDomainControllerInsert;
virDomainControllerInsertPreAlloced;
diff --git a/src/qemu/qemu_driver.c b/src/qemu/qemu_driver.c
index 656a1e4..25695df 100644
--- a/src/qemu/qemu_driver.c
+++ b/src/qemu/qemu_driver.c
@@ -8583,22 +8583,6 @@ static inline int qemudFindDisk(virDomainDefPtr def, const char *dst)
return -1;
}
-static inline void qemudShrinkDisks(virDomainDefPtr def, size_t i)
-{
- if (def->ndisks > 1) {
- memmove(def->disks + i,
- def->disks + i + 1,
- sizeof(*def->disks) *
- (def->ndisks - (i + 1)));
- def->ndisks--;
- if (VIR_REALLOC_N(def->disks, def->ndisks) < 0) {
- /* ignore, harmless */
- }
- } else {
- VIR_FREE(def->disks);
- def->ndisks = 0;
- }
-}
static int qemudDomainDetachPciDiskDevice(struct qemud_driver *driver,
virDomainObjPtr vm,
@@ -8655,7 +8639,7 @@ static int qemudDomainDetachPciDiskDevice(struct qemud_driver *driver,
qemuDomainPCIAddressReleaseAddr(priv->pciaddrs, &detach->info) < 0)
VIR_WARN("Unable to release PCI address on %s", dev->data.disk->src);
- qemudShrinkDisks(vm->def, i);
+ virDomainDiskRemove(vm->def, i);
virDomainDiskDefFree(detach);
@@ -8719,7 +8703,7 @@ static int qemudDomainDetachSCSIDiskDevice(struct qemud_driver *driver,
}
qemuDomainObjExitMonitorWithDriver(driver, vm);
- qemudShrinkDisks(vm->def, i);
+ virDomainDiskRemove(vm->def, i);
virDomainDiskDefFree(detach);
--
1.7.0.4
14 years, 7 months
[libvirt] [PATCH] Fix dependancies for remote generated files
by Daniel P. Berrange
Very occasionally during a parallel make, dispatch.c would
be compiled before the generated remote headers had been
fully written. This would cause it to compile an empty
union, and result in really wierd runtime bugs that are
near impossible to diagnose.
* daemon/Makefile.am: Fix remote build deps
---
daemon/Makefile.am | 19 +++++++++++--------
1 files changed, 11 insertions(+), 8 deletions(-)
diff --git a/daemon/Makefile.am b/daemon/Makefile.am
index dbf0ac3..035c149 100644
--- a/daemon/Makefile.am
+++ b/daemon/Makefile.am
@@ -189,14 +189,17 @@ uninstall-data-polkit::
endif
-remote.c: remote_dispatch_prototypes.h \
- remote_dispatch_table.h \
- remote_dispatch_args.h \
- remote_dispatch_ret.h \
- qemu_dispatch_prototypes.h \
- qemu_dispatch_table.h \
- qemu_dispatch_args.h \
- qemu_dispatch_ret.h
+remote.c: \
+ remote_dispatch_prototypes.h \
+ remote_dispatch_table.h \
+ qemu_dispatch_prototypes.h \
+ qemu_dispatch_table.h
+
+remote.h: \
+ remote_dispatch_args.h \
+ remote_dispatch_ret.h \
+ qemu_dispatch_args.h \
+ qemu_dispatch_ret.h
REMOTE_PROTOCOL = $(top_srcdir)/src/remote/remote_protocol.x
QEMU_PROTOCOL = $(top_srcdir)/src/remote/qemu_protocol.x
--
1.7.2.1
14 years, 8 months
[libvirt] [BUG] Xen x86_64 needs PAE?
by Philipp Hahn
Hello,
I tried to install "Microsoft Windows 2008 Server R2" on an Amd64 host using
Xen-3.4.3. The installation aborted with the following error message:
> Windows Boot Mager
...
> File: \windows\system32\boot\winload.exe
> Status: 0xc000035a
> Info: Attempting to load a 64-bit application, however this CPU is not
compatible with 64-bit mode.
For testing I converted the libvirt-XML file to an Xen-Xm file using "virsh
domxml-to-native" and started that file with "xm create", which worked.
Comparing the output of "xm list -a" of the broken libvirt- and the working
xm-configuration I found several differences, especially with "pae":
Using "xm create" pae is set to 1, while with libvirt pae is set to 0. After
adding the /domain/featues/pae node to libvirts XML domain file, Windows
installed fine.
Looking at "virsh capabilities" I get the following (abbreviated) output:
> <capabilities>
> <guest>
> <os_type>hvm</os_type>
> <arch name='i686'>
> <wordsize>32</wordsize>
...
> </arch>
> <features>
> <pae/>
> <nonpae/>
> <acpi default='on' toggle='yes'/>
> <apic default='on' toggle='yes'/>
> </features>
> </guest>
> <guest>
> <os_type>hvm</os_type>
> <arch name='x86_64'>
> <wordsize>64</wordsize>
...
> </arch>
> <features>
> <acpi default='on' toggle='yes'/>
> <apic default='on' toggle='yes'/>
> </features>
> </guest>
> </capabilities>
As you can see, neither "<pae/>" nor "<nopae/>" is listed for for the 64 bit
Xen-Fv domain type, which makes it hard to automatically create a correct
_and_ _working_ XML file for Xen-Fv-64 bit domains
Looking at "/sys/hypervisor/properties/capabilities" I find the following
capabilities reported by Xen
> xen-3.0-x86_64
> xen-3.0-x86_32p
> hvm-3.0-x86_32
> hvm-3.0-x86_32p
> hvm-3.0-x86_64
There's also no "hvm-3.0-x86_64p" which makes me wonder, if "<pae/>" is the
default for Xen-64 bit domains.
If that is true, should libvirt add "<pae/"> by default to the capabilities
report, or should libvirt silently pass "(pae 1)" when pushing the XML domain
description to Xend? Lookign at
<file:xen-3.4.3/tools/python/xen/xm/create.py>:210 I see that "pae" is
enabled by default there, and thus gets enabled for each domain using "xm
create":
> gopts.var('pae', val='PAE',
> fn=set_int, default=1,
> use="Disable or enable PAE of HVM domain.")
Any feedback is appreciated.
BYtE
Philipp
--
Philipp Hahn Open Source Software Engineer hahn(a)univention.de
Univention GmbH Linux for Your Business fon: +49 421 22 232- 0
Mary-Somerville-Str.1 28359 Bremen fax: +49 421 22 232-99
http://www.univention.de
14 years, 8 months
[libvirt] [PATCH] Ensure remote daemon unions are always non-zero length
by Daniel P. Berrange
If the remote daemon args/ret unions ever become zero length
(due to a build / Makefile bug) then bad stuff happens at
runtime. Add a compile time assertion to check for this kind
of problem
* daemon/remote.h: Ensure non-zero length unions
---
daemon/remote.h | 4 ++++
1 files changed, 4 insertions(+), 0 deletions(-)
diff --git a/daemon/remote.h b/daemon/remote.h
index fd8d381..1eb8386 100644
--- a/daemon/remote.h
+++ b/daemon/remote.h
@@ -30,18 +30,22 @@
typedef union {
# include "remote_dispatch_args.h"
} dispatch_args;
+verify(sizeof(dispatch_args) > 0);
typedef union {
# include "remote_dispatch_ret.h"
} dispatch_ret;
+verify(sizeof(dispatch_ret) > 0);
typedef union {
# include "qemu_dispatch_args.h"
} qemu_dispatch_args;
+verify(sizeof(qemu_dispatch_args) > 0);
typedef union {
# include "qemu_dispatch_ret.h"
} qemu_dispatch_ret;
+verify(sizeof(qemu_dispatch_ret) > 0);
--
1.7.2.1
14 years, 8 months
[libvirt] [PATCH] Fix off-by-1 in QEMU boot arg array handling
by Daniel P. Berrange
A QEMU guest can have upto VIR_DOMAIN_BOOT_LAST boot entries
defined. When building the QEMU arg, each entry takes a
single byte. This means the array must be declared to be
VIR_DOMAIN_BOOT_LAST+1 bytes in length to allow for the
trailing null
* src/qemu/qemu_conf.c: Fix off-by-1 boot arg array size
---
src/qemu/qemu_conf.c | 2 +-
1 files changed, 1 insertions(+), 1 deletions(-)
diff --git a/src/qemu/qemu_conf.c b/src/qemu/qemu_conf.c
index aa34d63..7a37c70 100644
--- a/src/qemu/qemu_conf.c
+++ b/src/qemu/qemu_conf.c
@@ -3662,7 +3662,7 @@ int qemudBuildCommandLine(virConnectPtr conn,
{
int i;
char memory[50];
- char boot[VIR_DOMAIN_BOOT_LAST];
+ char boot[VIR_DOMAIN_BOOT_LAST+1];
struct utsname ut;
int disableKQEMU = 0;
int enableKQEMU = 0;
--
1.7.2.1
14 years, 8 months