From 9b6fdc5d38f582d649661a476e77fac2ff313205 Mon Sep 17 00:00:00 2001 From: "vhanquez@kneesa.uk.xensource.com" Date: Mon, 24 Oct 2005 12:57:37 +0100 Subject: [PATCH 01/34] compute the correct totalram_pages when the balloon increase or decrease the reservation. memory reports should be more correct now. From: Satoshi Uchida Signed-off-by: Vincent Hanquez --- linux-2.6-xen-sparse/drivers/xen/balloon/balloon.c | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/linux-2.6-xen-sparse/drivers/xen/balloon/balloon.c b/linux-2.6-xen-sparse/drivers/xen/balloon/balloon.c index 14a9718326..f630d4bf71 100644 --- a/linux-2.6-xen-sparse/drivers/xen/balloon/balloon.c +++ b/linux-2.6-xen-sparse/drivers/xen/balloon/balloon.c @@ -70,6 +70,9 @@ spinlock_t balloon_lock = SPIN_LOCK_UNLOCKED; static unsigned long current_pages; static unsigned long target_pages; +/* VM /proc information for memory */ +extern unsigned long totalram_pages; + /* We may hit the hard limit in Xen. If we do then we remember it. */ static unsigned long hard_limit; @@ -223,6 +226,7 @@ static int increase_reservation(unsigned long nr_pages) } current_pages += nr_pages; + totalram_pages = current_pages; out: balloon_unlock(flags); @@ -295,6 +299,7 @@ static int decrease_reservation(unsigned long nr_pages) XENMEM_decrease_reservation, &reservation) != nr_pages); current_pages -= nr_pages; + totalram_pages = current_pages; balloon_unlock(flags); From 9f8f05265092ff564826e27fa79fcbb47168e74d Mon Sep 17 00:00:00 2001 From: "emellor@leeni.uk.xensource.com" Date: Mon, 24 Oct 2005 15:18:31 +0100 Subject: [PATCH 02/34] Removed some unnecessary imports. Signed-off-by: Ewan Mellor --- tools/python/xen/xend/xenstore/xstransact.py | 3 --- 1 file changed, 3 deletions(-) diff --git a/tools/python/xen/xend/xenstore/xstransact.py b/tools/python/xen/xend/xenstore/xstransact.py index ac8269f2ba..8d3adb1771 100644 --- a/tools/python/xen/xend/xenstore/xstransact.py +++ b/tools/python/xen/xend/xenstore/xstransact.py @@ -5,9 +5,6 @@ # Public License. See the file "COPYING" in the main directory of # this archive for more details. -import errno -import threading -from xen.lowlevel import xs from xen.xend.xenstore.xsutil import xshandle From 35b62f26306bc5b8d966f12ee79d443ed361a513 Mon Sep 17 00:00:00 2001 From: "emellor@leeni.uk.xensource.com" Date: Mon, 24 Oct 2005 18:21:38 +0100 Subject: [PATCH 03/34] Remove recently added uses of errno, as these cause trouble on ia64 builds. Signed-off-by: Ewan Mellor --- .../drivers/xen/xenbus/xenbus_xs.c | 15 ++++++--------- 1 file changed, 6 insertions(+), 9 deletions(-) diff --git a/linux-2.6-xen-sparse/drivers/xen/xenbus/xenbus_xs.c b/linux-2.6-xen-sparse/drivers/xen/xenbus/xenbus_xs.c index c8d1204fc2..3daf866f33 100644 --- a/linux-2.6-xen-sparse/drivers/xen/xenbus/xenbus_xs.c +++ b/linux-2.6-xen-sparse/drivers/xen/xenbus/xenbus_xs.c @@ -81,7 +81,7 @@ static struct xs_handle xs_state; static LIST_HEAD(watches); static DEFINE_SPINLOCK(watches_lock); -/* List of pending watch calbback events, and a lock to protect it. */ +/* List of pending watch callback events, and a lock to protect it. */ static LIST_HEAD(watch_events); static DEFINE_SPINLOCK(watch_events_lock); @@ -543,11 +543,8 @@ void xenbus_dev_error(struct xenbus_device *dev, int err, const char *fmt, ...) char *printf_buffer = NULL, *path_buffer = NULL; printf_buffer = kmalloc(PRINTF_BUFFER_SIZE, GFP_KERNEL); - if (printf_buffer == NULL) { - printk("xenbus: failed to write error node for %s (%d): %d\n", - dev->nodename, err, errno); + if (printf_buffer == NULL) goto fail; - } len = sprintf(printf_buffer, "%i ", -err); va_start(ap, fmt); @@ -560,8 +557,8 @@ void xenbus_dev_error(struct xenbus_device *dev, int err, const char *fmt, ...) path_buffer = error_path(dev); if (path_buffer == NULL) { - printk("xenbus: failed to write error node for %s (%s): %d\n", - dev->nodename, printf_buffer, errno); + printk("xenbus: failed to write error node for %s (%s)\n", + dev->nodename, printf_buffer); goto fail; } @@ -586,8 +583,8 @@ void xenbus_dev_ok(struct xenbus_device *dev) char *path_buffer = error_path(dev); if (path_buffer == NULL) { - printk("xenbus: failed to clear error node for %s: " - "%d\n", dev->nodename, errno); + printk("xenbus: failed to clear error node for %s\n", + dev->nodename); return; } From 31ad1c62b70775cc28ad9a8bf9d431270a56366f Mon Sep 17 00:00:00 2001 From: "emellor@leeni.uk.xensource.com" Date: Mon, 24 Oct 2005 18:24:07 +0100 Subject: [PATCH 04/34] Change argument spec for introduce_domain argument parsing, as the MFN is a long. Signed-off-by: Ewan Mellor --- tools/python/xen/lowlevel/xs/xs.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tools/python/xen/lowlevel/xs/xs.c b/tools/python/xen/lowlevel/xs/xs.c index 1f0dd5fac2..03e6f6dcd5 100644 --- a/tools/python/xen/lowlevel/xs/xs.c +++ b/tools/python/xen/lowlevel/xs/xs.c @@ -695,7 +695,7 @@ static PyObject *xspy_introduce_domain(PyObject *self, PyObject *args, PyObject *kwds) { static char *kwd_spec[] = { "dom", "page", "port", NULL }; - static char *arg_spec = "iii"; + static char *arg_spec = "ili"; domid_t dom = 0; unsigned long page = 0; unsigned int port = 0; From be8604faf3df2bc567138a9ef4a1e717852a994d Mon Sep 17 00:00:00 2001 From: "chris@ubuntu.eng.hq.xensource.com" Date: Mon, 24 Oct 2005 19:04:30 -0700 Subject: [PATCH 05/34] Don't run network stop script when doing xend stop. It doesn't make sense to undo the network configuration when stopping xend since that would cut off all VMs from the network. Undoing the network setup should be an option independent of xend stop. Signed-off-by: Christian Limpach --- tools/python/xen/xend/server/SrvDaemon.py | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/tools/python/xen/xend/server/SrvDaemon.py b/tools/python/xen/xend/server/SrvDaemon.py index 80e2d0eb8b..ce8b1a4e60 100644 --- a/tools/python/xen/xend/server/SrvDaemon.py +++ b/tools/python/xen/xend/server/SrvDaemon.py @@ -262,10 +262,7 @@ class Daemon: return 1 def stop(self): - result = self.cleanup_xend(True) - from xen.xend import Vifctl - Vifctl.network("stop") - return result + return self.cleanup_xend(True) def run(self, status): try: From 1033d025c45050c7e6fe77a9c7eb7572d13b270d Mon Sep 17 00:00:00 2001 From: "emellor@leeni.uk.xensource.com" Date: Tue, 25 Oct 2005 11:22:47 +0100 Subject: [PATCH 06/34] Moved SuSE-specific getcfg call into a preiftransfer call. The semantics of this aren't beautiful, but this gets the distro-specific code out of the body of the network-bridge script and into a common place, while still preserving the existing code behaviour. Signed-off-by: Ewan Mellor --- tools/examples/network-bridge | 4 +-- tools/examples/xen-network-common.sh | 38 ++++++++++++++++++++++++++-- 2 files changed, 38 insertions(+), 4 deletions(-) diff --git a/tools/examples/network-bridge b/tools/examples/network-bridge index c9d00b8e81..e9a75ea749 100755 --- a/tools/examples/network-bridge +++ b/tools/examples/network-bridge @@ -208,7 +208,7 @@ op_start () { if ip link show ${vdev} 2>/dev/null >/dev/null; then mac=`ip link show ${netdev} | grep 'link\/ether' | sed -e 's/.*ether \(..:..:..:..:..:..\).*/\1/'` - eval `/sbin/getcfg -d /etc/sysconfig/network/ -f ifcfg- -- ${netdev}` + preiftransfer ${netdev} transfer_addrs ${netdev} ${vdev} if ! ifdown ${netdev}; then # if ifup didn't work, see if we have an ip= on cmd line @@ -231,7 +231,7 @@ op_start () { ip link set ${bridge} up ip link set ${vif0} up ip link set ${pdev} up - if ! ifup ${HWD_CONFIG_0} ${netdev} ; then + if ! ifup ${netdev} ; then if [ ${kip} ] ; then # use the addresses we grocked from /proc/cmdline if [ -z "${kmask}" ]; then diff --git a/tools/examples/xen-network-common.sh b/tools/examples/xen-network-common.sh index d4af3990ca..c2fc311fac 100644 --- a/tools/examples/xen-network-common.sh +++ b/tools/examples/xen-network-common.sh @@ -16,11 +16,40 @@ # -# Gentoo doesn't have ifup/ifdown: define appropriate alternatives -if ! which ifup >&/dev/null +# On SuSE it is necessary to run a command before transfering addresses and +# routes from the physical interface to the virtual. This command creates a +# variable $HWD_CONFIG_0 that specifies the appropriate configuration for +# ifup. + +# Gentoo doesn't have ifup/ifdown, so we define appropriate alternatives. + +# Other platforms just use ifup / ifdown directly. + +## +# preiftransfer +# +# @param $1 The current name for the physical device, which is also the name +# that the virtual device will take once the physical device has +# been renamed. + +if [ -e /etc/SuSE-release ] +then + preiftransfer() + { + eval `/sbin/getcfg -d /etc/sysconfig/network/ -f ifcfg- -- $1` + } + ifup() + { + /sbin/ifup ${HWD_CONFIG_0} $1 + } +elif ! which ifup >&/dev/null then if [ -e /etc/conf.d/net ] then + preiftransfer() + { + true + } ifup() { /etc/init.d/net.$1 start @@ -34,4 +63,9 @@ then "You don't have ifup and don't seem to be running Gentoo either!" exit 1 fi +else + preiftransfer() + { + true + } fi From 617482f0580f5bf9849110e5202dfded596b122b Mon Sep 17 00:00:00 2001 From: "emellor@leeni.uk.xensource.com" Date: Tue, 25 Oct 2005 11:52:56 +0100 Subject: [PATCH 07/34] NBD scripts, courtesy of Kurt Garloff: For domain migration, unless you use a rootless setup, you need to have network storage available. For the poor people like me that have no SAN, one easy possibility to have it is to use nbd. Find attached the block-nbd script (in /etc/xen/scripts/) and an example config file. The block-nbd script is based on the -enbd one. They have been used successfully in the Xen Tutorial at Linux Kongress. Signed-off-by: Kurt Garloff --- tools/examples/block-nbd | 35 +++++++++++++++++++++++++++++++++++ tools/examples/xmexample.nbd | 13 +++++++++++++ 2 files changed, 48 insertions(+) create mode 100644 tools/examples/block-nbd create mode 100644 tools/examples/xmexample.nbd diff --git a/tools/examples/block-nbd b/tools/examples/block-nbd new file mode 100644 index 0000000000..06f9f6875e --- /dev/null +++ b/tools/examples/block-nbd @@ -0,0 +1,35 @@ +#!/bin/sh + +# Usage: block-enbd [bind server ctl_port |unbind node] +# +# The file argument to the bind command is the file we are to bind to a +# loop device. +# +# The node argument to unbind is the name of the device node we are to +# unbind. +# +# This assumes you're running a correctly configured server at the other end! + +set -e + +#echo "block-enbd: $@" | logger -t xen + +case $1 in + bind) + for dev in /dev/nbd*; do + if nbd-client $2 $3 $dev; then + major=$(stat -L -c %t "$dev") + minor=$(stat -L -c %T "$dev") + pdev=$(printf "0x%02x%02x" 0x$major 0x$minor) + xenstore-write "$XENBUS_PATH"/physical-device $pdev \ + "$XENBUS_PATH"/node $dev + exit 0 + fi + done + exit 1 + ;; + unbind) + nbd-client -d $2 + exit 0 + ;; +esac diff --git a/tools/examples/xmexample.nbd b/tools/examples/xmexample.nbd new file mode 100644 index 0000000000..06a5d1feb1 --- /dev/null +++ b/tools/examples/xmexample.nbd @@ -0,0 +1,13 @@ +kernel = "/boot/vmlinuz-2.6.13-15b-xen" +ramdisk = "/boot/initrd-2.6.13-15b-xen" +memory = 128 +name = "nbd4" +nics=1 +# Please change MAC +vif = [ 'mac=aa:cc:10:10:00:a0, bridge=xenbr0' ] +# Please change PORT +disk = [ 'nbd:134.100.233.115 20004,hda1,w' ] +dhcp = "dhcp" +hostname= "nbd4" +root = "/dev/hda1 ro" +extra = "3" From e4ba1fec3e49d71bd6a945a8dfbffa16d76c0353 Mon Sep 17 00:00:00 2001 From: "emellor@leeni.uk.xensource.com" Date: Tue, 25 Oct 2005 16:00:49 +0100 Subject: [PATCH 08/34] Fix format spec for tracing. Signed-off-by: Ewan Mellor --- tools/xenstore/xenstored_core.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tools/xenstore/xenstored_core.c b/tools/xenstore/xenstored_core.c index 00c64719de..4dcdb52ef4 100644 --- a/tools/xenstore/xenstored_core.c +++ b/tools/xenstore/xenstored_core.c @@ -188,7 +188,7 @@ static void trace_io(const struct connection *conn, tm = localtime(&now); write(tracefd, prefix, strlen(prefix)); - sprintf(string, " %p %0d:%0d:%0d ", conn, tm->tm_hour, tm->tm_min, + sprintf(string, " %p %02d:%02d:%02d ", conn, tm->tm_hour, tm->tm_min, tm->tm_sec); write(tracefd, string, strlen(string)); write(tracefd, sockmsg_string(data->hdr.msg.type), From 22d8d7060fa80384f1b5857acd7b372e916503b4 Mon Sep 17 00:00:00 2001 From: "jeroney@localhost.localdomain" Date: Tue, 25 Oct 2005 17:37:00 +0100 Subject: [PATCH 09/34] Remove second decleration of .PHONY & cleanup formating --- tools/Makefile | 3 --- 1 file changed, 3 deletions(-) diff --git a/tools/Makefile b/tools/Makefile index 962f7f8ae2..e12479777e 100644 --- a/tools/Makefile +++ b/tools/Makefile @@ -16,9 +16,6 @@ SUBDIRS += vtpm_manager SUBDIRS += vtpm endif SUBDIRS += xenstat - -.PHONY: all install clean check check_clean ioemu eioemuinstall ioemuclean - # These don't cross-compile ifeq ($(XEN_COMPILE_ARCH),$(XEN_TARGET_ARCH)) SUBDIRS += python From ccbd11acd6843de79d50236ee96446cff59eb3b8 Mon Sep 17 00:00:00 2001 From: "emellor@leeni.uk.xensource.com" Date: Wed, 26 Oct 2005 12:06:58 +0100 Subject: [PATCH 10/34] Added comment. Signed-off-by: Ewan Mellor --- tools/examples/xmexample.nbd | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/tools/examples/xmexample.nbd b/tools/examples/xmexample.nbd index 06a5d1feb1..274be6eb06 100644 --- a/tools/examples/xmexample.nbd +++ b/tools/examples/xmexample.nbd @@ -1,3 +1,13 @@ +# -*- mode: python; -*- +# +# xm create configuration example. +# +# This configuration is appropriate for using Network Block Device (NBD) +# filesystems. +# +# Each of these parameters will need changing to match your setup. +# + kernel = "/boot/vmlinuz-2.6.13-15b-xen" ramdisk = "/boot/initrd-2.6.13-15b-xen" memory = 128 From 5c8eb3b72788f4aa3b26462d224376a0e468f9c6 Mon Sep 17 00:00:00 2001 From: "emellor@leeni.uk.xensource.com" Date: Wed, 26 Oct 2005 13:41:00 +0100 Subject: [PATCH 11/34] Check whether dom is NULL when we handle a watch. This might occur if the domain has recently been removed from our list, but with a watch still in flight. This should fix the intermittent crash in xenconsoled that is plaguing us at the moment. Signed-off-by: Ewan Mellor --- tools/console/daemon/io.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/tools/console/daemon/io.c b/tools/console/daemon/io.c index 0b55607d50..ef3f094d27 100644 --- a/tools/console/daemon/io.c +++ b/tools/console/daemon/io.c @@ -512,7 +512,9 @@ static void handle_xs(int fd) enum_domains(); else if (sscanf(vec[XS_WATCH_TOKEN], "dom%u", &domid) == 1) { dom = lookup_domain(domid); - if (dom->is_dead == false) + /* We may get watches firing for domains that have recently + been removed, so dom may be NULL here. */ + if (dom && dom->is_dead == false) domain_create_ring(dom); } From b043099b440efe40c1de74558156363534b9e40d Mon Sep 17 00:00:00 2001 From: "emellor@leeni.uk.xensource.com" Date: Wed, 26 Oct 2005 14:55:32 +0100 Subject: [PATCH 12/34] New xendomains init script, courtesy of Kurt Garloff: It now allows the user to configure what he wants to be done on xendomains stop: sysrq, migrate, save, or shutdown. For this to be safe, a timeout has been introduced (optional). On start, saved domains may be restored, and not yet started domains from the auto start dir will be started in addition. status reports missing domains, restart and reload work as well. The init script is somewhat SUSE-ish, but it should work on LSB compliant and on RH based distros as well. I would appreciate this to be put into tools/examples/init.d/ Signed-off-by: Kurt Garloff --- tools/examples/Makefile | 3 + tools/examples/init.d/sysconfig.xendomains | 126 ++++++ tools/examples/init.d/xendomains | 456 +++++++++++++++++---- 3 files changed, 505 insertions(+), 80 deletions(-) create mode 100644 tools/examples/init.d/sysconfig.xendomains mode change 100755 => 100644 tools/examples/init.d/xendomains diff --git a/tools/examples/Makefile b/tools/examples/Makefile index f58f75e092..2af687e535 100644 --- a/tools/examples/Makefile +++ b/tools/examples/Makefile @@ -9,6 +9,7 @@ INSTALL_DATA = $(INSTALL) -m0644 # Init scripts. XEND_INITD = init.d/xend XENDOMAINS_INITD = init.d/xendomains +XENDOMAINS_SYSCONFIG = init.d/sysconfig.xendomains # Xen configuration dir and configs to go there. XEN_CONFIG_DIR = /etc/xen @@ -51,8 +52,10 @@ install: all install-initd install-configs install-scripts $(HOTPLUGS) install-initd: [ -d $(DESTDIR)/etc/init.d ] || $(INSTALL_DIR) $(DESTDIR)/etc/init.d + [ -d $(DESTDIR)/etc/sysconfig ] || $(INSTALL_DIR) $(DESTDIR)/etc/sysconfig $(INSTALL_PROG) $(XEND_INITD) $(DESTDIR)/etc/init.d $(INSTALL_PROG) $(XENDOMAINS_INITD) $(DESTDIR)/etc/init.d + $(INSTALL_PROG) $(XENDOMAINS_SYSCONFIG) $(DESTDIR)/etc/sysconfig/xendomains install-configs: $(XEN_CONFIGS) [ -d $(DESTDIR)$(XEN_CONFIG_DIR) ] || \ diff --git a/tools/examples/init.d/sysconfig.xendomains b/tools/examples/init.d/sysconfig.xendomains new file mode 100644 index 0000000000..fa95c145cc --- /dev/null +++ b/tools/examples/init.d/sysconfig.xendomains @@ -0,0 +1,126 @@ +## Path: System/xen +## Description: xen domain start/stop on boot +## Type: string +## Default: +# +# The xendomains script can send SysRq requests to domains on shutdown. +# If you don't want to MIGRATE, SAVE, or SHUTDOWN, this may be a possibility +# to do a quick and dirty shutdown ("s e i u o") or at least sync the disks +# of the domains ("s"). +# +XENDOMAINS_SYSRQ="" + +## Type: integer +## Default: 100000 +# +# If XENDOMAINS_SYSRQ is set, this variable determines how long to wait +# (in microseconds) after each SysRq, so the domain has a chance to react. +# If you want to a quick'n'dirty shutdown via SysRq, you may want to set +# it to a relatively high value (1200000). +# +XENDOMAINS_USLEEP=100000 + +## Type: string +## Default: "" +# +# Set this to a non-empty string if you want to migrate virtual machines +# on shutdown. The string will be passed to the xm migrate DOMID command +# as is: It should contain the target IP address of the physical machine +# to migrate to and optionally parameters like --live. Leave empty if +# you don't want to try virtual machine relocation on shutdown. +# If migration succeeds, neither SAVE nor SHUTDOWN will be executed for +# that domain. +# +XENDOMAINS_MIGRATE="" + +## Type: string +## Default: /var/lib/xen/save +# +# Directory to save running domains to when the system (dom0) is +# shut down. Will also be used to restore domains from if # XENDOMAINS_RESTORE +# is set (see below). Leave empty to disable domain saving on shutdown +# (e.g. because you rather shut domains down). +# If domain saving does succeed, SHUTDOWN will not be executed. +# +XENDOMAINS_SAVE=/var/lib/xen/save + +## Type: string +## Default: "--halt --wait" +# +# If neither MIGRATE nor SAVE were enabled or if they failed, you can +# try to shut down a domain by sending it a shutdown request. To do this, +# set this to "--halt --wait". Omit the "--wait" flag to avoid waiting +# for the domain to be really down. Leave empty to skip domain shutdown. +# +XENDOMAINS_SHUTDOWN="--halt --wait" + +## Type: string +## Default: "--all --halt --wait" +# +# After we have gone over all virtual machines (resp. all automatically +# started ones, see XENDOMAINS_AUTO_ONLY below) in a loop and sent SysRq, +# migrated, saved and/or shutdown according to the settings above, we +# might want to shutdown the virtual machines that are still running +# for some reason or another. To do this, set this variable to +# "--all --halt --wait", it will be passed to xm shutdown. +# Leave it empty not to do anything special here. +# (Note: This will hit all virtual machines, even if XENDOMAINS_AUTO_ONLY +# is set.) +# +XENDOMAINS_SHUTDOWN_ALL="--all --halt --wait" + +## Type: boolean +## Default: true +# +# This variable determines whether saved domains from XENDOMAINS_SAVE +# will be restored on system startup. +# +XENDOMAINS_RESTORE=true + +## Type: string +## Default: /etc/xen/auto +# +# This variable sets the directory where domains configurations +# are stored that should be started on system startup automatically. +# Leave empty if you don't want to start domains automatically +# (or just don't place any xen domain config files in that dir). +# Note that the script tries to be clever if both RESTORE and AUTO are +# set: It will first restore saved domains and then only start domains +# in AUTO which are not running yet. +# Note that the name matching is somewhat fuzzy. +# +XENDOMAINS_AUTO=/etc/xen/auto + +## Type: boolean +## Default: false +# +# If this variable is set to "true", only the domains started via config +# files in XENDOMAINS_AUTO will be treated according to XENDOMAINS_SYSRQ, +# XENDOMAINS_MIGRATE, XENDOMAINS_SAVE, XENDMAINS_SHUTDOWN; otherwise +# all running domains will be. +# Note that the name matching is somewhat fuzzy. +# +XENDOMAINS_AUTO_ONLY=false + +## Type: integer +## Default: 300 +# +# On xendomains stop, a number of xm commands (xm migrate, save, shutdown, +# shutdown --all) may be executed. In the worst case, these commands may +# stall forever, which will prevent a successful shutdown of the machine. +# If this variable is non-zero, the script will set up a watchdog timer +# for every of these xm commands and time it out after the number of seconds +# specified by this variable. +# Note that SHUTDOWN_ALL will not be called if no virtual machines or only +# zombies are still running, so you don't need to enable this timeout just +# for the zombie case. +# The setting should be large enough to make sure that migrate/save/shutdown +# can succeed. If you do live migrations, keep in mind that live migration +# of a 1GB machine over Gigabit ethernet may actually take something like +# 100s (assuming that live migration uses 10% of the network # bandwidth). +# Depending on the virtual machine, a shutdown may also require a significant +# amount of time. So better setup this variable to a huge number and hope the +# watchdog never fires. +# +XENDOMAINS_STOP_MAXWAIT=300 + diff --git a/tools/examples/init.d/xendomains b/tools/examples/init.d/xendomains old mode 100755 new mode 100644 index ac2b273fd7..ce96284937 --- a/tools/examples/init.d/xendomains +++ b/tools/examples/init.d/xendomains @@ -1,4 +1,4 @@ -#!/bin/sh +#!/bin/bash # # /etc/init.d/xendomains # Start / stop domains automatically when domain 0 boots / shuts down. @@ -22,101 +22,388 @@ # Should-Stop: # Default-Start: 3 4 5 # Default-Stop: 0 1 2 6 +# Default-Enabled: yes # Short-Description: Start/stop secondary xen domains # Description: Start / stop domains automatically when domain 0 # boots / shuts down. ### END INIT INFO +# Correct exit code would probably be 5, but it's enough +# if xend complains if we're not running as privileged domain if ! [ -e /proc/xen/privcmd ]; then exit 0 fi -RETVAL=0 - -INITD=/etc/init.d - -AUTODIR=/etc/xen/auto LOCKFILE=/var/lock/subsys/xendomains +XENDOM_CONFIG=/etc/sysconfig/xendomains -if [ -e /lib/lsb ]; then - # assume an LSB-compliant distro (Debian with LSB package, - # recent-enough SuSE, others...) +test -r $XENDOM_CONFIG || { echo "$XENDOM_CONFIG not existing"; + if [ "$1" = "stop" ]; then exit 0; + else exit 6; fi; } - . /lib/lsb/init-functions # source LSB standard functions +. $XENDOM_CONFIG - on_fn_exit() +# Use the SUSE rc_ init script functions; +# emulate them on LSB, RH and other systems +if test -e /etc/rc.status; then + # SUSE rc script library + . /etc/rc.status +else + _cmd=$1 + declare -a _SMSG + if test "${_cmd}" = "status"; then + _SMSG=(running dead dead unused unknown) + _RC_UNUSED=3 + else + _SMSG=(done failed failed missed failed skipped unused failed failed) + _RC_UNUSED=6 + fi + if test -e /lib/lsb/init-functions; then + # LSB + . /lib/lsb/init-functions + echo_rc() + { + if test ${_RC_RV} = 0; then + log_success_msg " [${_SMSG[${_RC_RV}]}] " + else + log_failure_msg " [${_SMSG[${_RC_RV}]}] " + fi + } + elif test -e /etc/init.d/functions; then + # REDHAT + . /etc/init.d/functions + echo_rc() + { + #echo -n " [${_SMSG[${_RC_RV}]}] " + if test ${_RC_RV} = 0; then + success " [${_SMSG[${_RC_RV}]}] " + else + failure " [${_SMSG[${_RC_RV}]}] " + fi + } + else + # emulate it + echo_rc() + { + echo " [${_SMSG[${_RC_RV}]}] " + } + fi + rc_reset() { _RC_RV=0; } + rc_failed() { - if [ $RETVAL -eq 0 ]; then - log_success_msg - else - log_failure_msg - fi + if test -z "$1"; then + _RC_RV=1; + elif test "$1" != "0"; then + _RC_RV=$1; + fi + return ${_RC_RV} } -elif [ -r $INITD/functions ]; then - # assume a Redhat-like distro - . $INITD/functions # source Redhat functions - - on_fn_exit() + rc_check() { - if [ $RETVAL -eq 0 ]; then - success - else - failure - fi - - echo + return rc_failed $? + } + rc_status() + { + rc_failed $? + if test "$1" = "-r"; then _RC_RV=0; shift; fi + if test "$1" = "-s"; then rc_failed 5; echo_rc; rc_failed 3; shift; fi + if test "$1" = "-u"; then rc_failed ${_RC_UNUSED}; echo_rc; rc_failed 3; shift; fi + if test "$1" = "-v"; then echo_rc; shift; fi + if test "$1" = "-r"; then _RC_RV=0; shift; fi + return ${_RC_RV} } -else - # none of the above - LOCKFILE=/var/lock/xendomains - - on_fn_exit() + rc_exit() { exit ${_RC_RV}; } + rc_active() { - echo + if test -z "$RUNLEVEL"; then read RUNLEVEL REST < <(/sbin/runlevel); fi + if test -e /etc/init.d/S[0-9][0-9]${1}; then return 0; fi + return 1 } fi +# Reset status of this service +rc_reset +# read name from xen config file +rdname() +{ + NM=`grep '^name *=' $1 | sed -e 's/^name *= *"\([^"]*\)".*$/\1/' -e 's/%[id]/[0-9]*/g'` +} -start() { - if [ -f $LOCKFILE ]; then return; fi +rdnames() +{ + NAMES= + if test ! -d $XENDOMAINS_AUTO -o `/bin/ls $XENDOMAINS_AUTO | wc -l` -eq 0; then + return + fi + for dom in $XENDOMAINS_AUTO/*; do + rdname $dom + if test -z $NAMES; then + NAMES=$NM; + else + NAMES="$NAMES|$NM" + fi + done +} - echo -n $"Starting auto Xen domains:" +parseln() +{ + name=`echo "$1" | cut -c0-17` + name=${name%% *} + rest=`echo "$1" | cut -c18- ` + read id mem cpu vcpu state tm < <(echo "$rest") +} - # We expect config scripts for auto starting domains to be in - # AUTODIR - they could just be symlinks to files elsewhere - if [ -d $AUTODIR ] && [ $(ls $AUTODIR | wc -l) -gt 0 ]; then - touch $LOCKFILE - - # Create all domains with config files in AUTODIR. - for dom in $AUTODIR/*; do - xm create --quiet --defconfig $dom - if [ $? -ne 0 ]; then - RETVAL=$? - fi - done +is_running() +{ + rdname $1 + RC=1 + while read LN; do + parseln "$LN" + if test $id = 0; then continue; fi + case $name in + ($NM) + RC=0 + ;; + esac + done < <(xm list | grep -v '^Name') + return $RC +} +start() +{ + if [ -f $LOCKFILE ]; then + echo -n "xendomains already running (lockfile exists)" + return; fi - on_fn_exit + if test "$XENDOMAINS_RESTORE" = "true" -a -n "$XENDOMAINS_SAVE" \ + -a -d $XENDOMAINS_SAVE -a `/bin/ls $XENDOMAINS_SAVE | wc -l` -gt 0; then + + touch $LOCKFILE + echo -n "Restoring Xen domains:" + for dom in $XENDOMAINS_SAVE/*; do + echo -n " ${dom##*/}" + xm restore $dom + if [ $? -ne 0 ]; then + rc_failed $? + echo -n '!' + else + # mv $dom ${dom%/*}/.${dom##*/} + rm $dom + fi + done + fi + + if test -n "$XENDOMAINS_AUTO" -a -d $XENDOMAINS_AUTO \ + -a `/bin/ls $XENDOMAINS_AUTO | wc -l` -gt 0; then + + touch $LOCKFILE + echo -n "Starting auto Xen domains:" + # We expect config scripts for auto starting domains to be in + # XENDOMAINS_AUTO - they could just be symlinks to files elsewhere + + # Create all domains with config files in XENDOMAINS_AUTO. + # TODO: We should record which domain name belongs + # so we have the option to selectively shut down / migrate later + for dom in $XENDOMAINS_AUTO/*; do + echo -n " ${dom##*/}" + if is_running $dom; then + echo -n "(skip)" + else + xm create --quiet --defconfig $dom + if [ $? -ne 0 ]; then + rc_failed $? + echo -n '!' + fi + fi + done + fi +} + +all_zombies() +{ + while read LN; do + parseln "$LN" + if test $id = 0; then continue; fi + if test "$state" != "-b---d" -a "$state" != "-----d"; then + return 1; + fi + done < <(xm list | grep -v '^Name') + return 0 +} + +# Wait for max $XENDOMAINS_STOP_MAXWAIT for xm $1 to finish; +# if it has not exited by that time kill it, so the init script will +# succeed within a finite amount of time; if $2 is nonnull, it will +# kill the command as well as soon as no domain (except for zombies) +# are left (used for shutdown --all). +watchdog_xm() +{ + if test -z "$XENDOMAINS_STOP_MAXWAIT" -o "$XENDOMAINS_STOP_MAXWAIT" = "0"; then + exit + fi + usleep 20000 + for no in `seq 0 $XENDOMAINS_STOP_MAXWAIT`; do + # exit if xm save/migrate/shutdown is finished + PSAX=`ps axlw | grep "xm $1" | grep -v grep` + if test -z "$PSAX"; then exit; fi + echo -n "."; sleep 1 + # go to kill immediately if there's only zombies left + if all_zombies && test -n "$2"; then break; fi + done + sleep 1 + read PSF PSUID PSPID PSPPID < <(echo "$PSAX") + # kill xm $1 + kill $PSPID >/dev/null 2>&1 } stop() { + # Collect list of domains to shut down + if test "$XENDOMAINS_AUTO_ONLY" = "true"; then + rdnames + fi + echo -n "Shutting down Xen domains:" + while read LN; do + parseln "$LN" + if test $id = 0; then continue; fi + echo -n " $name" + if test "$XENDOMAINS_AUTO_ONLY" = "true"; then + case $name in + ($NAMES) + # nothing + ;; + (*) + echo -n "(skip)" + continue + ;; + esac + fi + # XENDOMAINS_SYSRQ chould be something like just "s" + # or "s e i u" or even "s e s i u o" + # for the latter, you should set XENDOMAINS_USLEEP to 1200000 or so + if test -n "$XENDOMAINS_SYSRQ"; then + for sysrq in $XENDOMAINS_SYSRQ; do + echo -n "(SR-$sysrq)" + xm sysrq $id $sysrq + if test $? -ne 0; then + rc_failed $? + echo -n '!' + fi + # usleep just ignores empty arg + usleep $XENDOMAINS_USLEEP + done + fi + if test "$state" = "-b---d" -o "$state" = "-----d"; then + echo -n "(zomb)" + continue + fi + if test -n "$XENDOMAINS_MIGRATE"; then + echo -n "(migr)" + watchdog_xm migrate & + WDOG_PID=$! + xm migrate $id $XENDOMAINS_MIGRATE + if test $? -ne 0; then + rc_failed $? + echo -n '!' + kill $WDOG_PID >/dev/null 2>&1 + else + kill $WDOG_PID >/dev/null 2>&1 + continue + fi + fi + if test -n "$XENDOMAINS_SAVE"; then + echo -n "(save)" + watchdog_xm save & + WDOG_PID=$! + xm save $id $XENDOMAINS_SAVE/$name + if test $? -ne 0; then + rc_failed $? + echo -n '!' + kill $WDOG_PIG >/dev/null 2>&1 + else + kill $WDOG_PIG >/dev/null 2>&1 + continue + fi + fi + if test -n "$XENDOMAINS_SHUTDOWN"; then + # XENDOMAINS_SHUTDOWN should be "--halt --wait" + echo -n "(shut)" + watchdog_xm shutdown & + WDOG_PID=$! + xm shutdown $id $XENDOMAINS_SHUTDOWN + if test $? -ne 0; then + rc_failed $? + echo -n '!' + fi + kill $WDOG_PIG >/dev/null 2>&1 + fi + done < <(xm list | grep -v '^Name') + # NB. this shuts down ALL Xen domains (politely), not just the ones in # AUTODIR/* # This is because it's easier to do ;-) but arguably if this script is run # on system shutdown then it's also the right thing to do. - - echo -n $"Shutting down all Xen domains:" + if ! all_zombies && test -n "$XENDOMAINS_SHUTDOWN_ALL"; then + # XENDOMAINS_SHUTDOWN_ALL should be "--all --halt --wait" + echo -n " SHUTDOWN_ALL " + watchdog_xm shutdown 1 & + WDOG_PID=$! + xm shutdown $XENDOMAINS_SHUTDOWN_ALL + if test $? -ne 0; then + rc_failed $? + echo -n '!' + fi + kill $WDOG_PID >/dev/null 2>&1 + fi - xm shutdown --all --wait --halt + # Unconditionally delete lock file + rm -f $LOCKFILE +} - RETVAL=$? +check_domain_up() +{ + while read LN; do + parseln "$LN" + if test $id = 0; then continue; fi + case $name in + ($1) + return 0 + ;; + esac + done < <(xm list | grep -v "^Name") + return 1 +} - [ $RETVAL -eq 0 ] && rm -f $LOCKFILE +check_all_auto_domains_up() +{ + if test -z "$XENDOMAINS_AUTO" -o ! -d "$XENDOMAINS_AUTO" \ + -o `/bin/ls $XENDOMAINS_AUTO | wc -l` -eq 0; then return 0; fi + missing= + for nm in $XENDOMAINS_AUTO/*; do + rdname $nm + found=0 + if check_domain_up "$NM"; then + echo -n " $name" + else + missing="$missing $NM" + fi + done + if test -n "$missing"; then + echo -n " MISS AUTO:$missing" + return 1 + fi + return 0 +} - on_fn_exit +check_all_saved_domains_up() +{ + if test -z "$XENDOMAINS_SAVE" -o ! -d "$XENDOMAINS_SAVE" \ + -o `/bin/ls $XENDOMAINS_SAVE | wc -l` -eq 0; then return 0; fi + missing=`/bin/ls $XENDOMAINS_SAVE` + echo -n " MISS SAVED: " $missing + return 1 } # This does NOT necessarily restart all running domains: instead it @@ -124,47 +411,56 @@ stop() # AUTODIR. If other domains have been started manually then they will # not get restarted. # Commented out to avoid confusion! -# -#restart() -#{ -# stop -# start -#} -# same as restart for now - commented out to avoid confusion -#reload() -#{ -# restart -#} +restart() +{ + stop + start +} + +reload() +{ + restart +} case "$1" in start) start + rc_status + if test -f $LOCKFILE; then rc_status -v; fi ;; stop) stop + rc_status -v ;; -# The following are commented out to disable them by default to avoid confusion -# - see the notes above -# -# restart) -# restart -# ;; -# -# reload) -# reload -# ;; + restart) + restart + ;; + reload) + reload + ;; status) - xm list + echo -n "Checking for xendomains:" + if test ! -f $LOCKFILE; then + rc_failed 3 + else + check_all_auto_domains_up + rc_status + check_all_saved_domains_up + rc_status + fi + rc_status -v ;; *) - echo $"Usage: $0 {start|stop|status}" + echo "Usage: $0 {start|stop|restart|reload|status}" + rc_failed 3 + rc_status -v ;; esac -exit $RETVAL +rc_exit From 902a84f59f09d0f7d918c707787421e789be81eb Mon Sep 17 00:00:00 2001 From: "emellor@leeni.uk.xensource.com" Date: Wed, 26 Oct 2005 14:57:16 +0100 Subject: [PATCH 13/34] Added copyright notice. Signed-off-by: Ewan Mellor --- tools/examples/xen-hotplug-common.sh | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/tools/examples/xen-hotplug-common.sh b/tools/examples/xen-hotplug-common.sh index c25f493551..5beb12d60a 100644 --- a/tools/examples/xen-hotplug-common.sh +++ b/tools/examples/xen-hotplug-common.sh @@ -1,3 +1,21 @@ +# +# Copyright (c) 2005 XenSource Ltd. +# +# This library is free software; you can redistribute it and/or +# modify it under the terms of version 2.1 of the GNU Lesser General Public +# License as published by the Free Software Foundation. +# +# This library 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 library; if not, write to the Free Software +# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +# + + set -e export PATH="/sbin:/bin:/usr/bin:/usr/sbin:$PATH" From a8a1d48e4ccc545e7f50d46beb32acd2833fd474 Mon Sep 17 00:00:00 2001 From: "emellor@leeni.uk.xensource.com" Date: Wed, 26 Oct 2005 14:58:13 +0100 Subject: [PATCH 14/34] Break the write_dev function out from block into new block-common.sh, where it can also be used by block-enbd and block-nbd. Signed-off-by: Ewan Mellor --- tools/examples/Makefile | 3 +- tools/examples/block | 16 ++--------- tools/examples/block-common.sh | 51 ++++++++++++++++++++++++++++++++++ tools/examples/block-enbd | 14 +++------- tools/examples/block-nbd | 18 ++++-------- 5 files changed, 64 insertions(+), 38 deletions(-) create mode 100644 tools/examples/block-common.sh diff --git a/tools/examples/Makefile b/tools/examples/Makefile index 2af687e535..54164235b4 100644 --- a/tools/examples/Makefile +++ b/tools/examples/Makefile @@ -24,8 +24,9 @@ XEN_SCRIPTS = network-bridge vif-bridge XEN_SCRIPTS += network-route vif-route XEN_SCRIPTS += network-nat vif-nat XEN_SCRIPTS += block -XEN_SCRIPTS += block-enbd +XEN_SCRIPTS += block-enbd block-nbd XEN_SCRIPTS += xen-hotplug-common.sh xen-network-common.sh vif-common.sh +XEN_SCRIPTS += block-common.sh XEN_HOTPLUG_DIR = /etc/hotplug XEN_HOTPLUG_SCRIPTS = xen-backend.agent diff --git a/tools/examples/block b/tools/examples/block index 2e383bb3a6..c5b6b6c215 100644 --- a/tools/examples/block +++ b/tools/examples/block @@ -1,7 +1,7 @@ #!/bin/sh dir=$(dirname "$0") -. "$dir/xen-hotplug-common.sh" +. "$dir/block-common.sh" expand_dev() { local dev @@ -16,21 +16,9 @@ expand_dev() { echo -n $dev } -write_dev() { - local major - local minor - local pdev - - major=$(stat -L -c %t "$1") - minor=$(stat -L -c %T "$1") - pdev=$(printf "0x%02x%02x" 0x$major 0x$minor) - xenstore_write "$XENBUS_PATH"/physical-device $pdev \ - "$XENBUS_PATH"/node $1 -} - t=$(xenstore_read "$XENBUS_PATH"/type || true) -case $1 in +case "$command" in bind) p=$(xenstore_read "$XENBUS_PATH"/params) case $t in diff --git a/tools/examples/block-common.sh b/tools/examples/block-common.sh new file mode 100644 index 0000000000..1d20550a9d --- /dev/null +++ b/tools/examples/block-common.sh @@ -0,0 +1,51 @@ +# +# Copyright (c) 2005 XenSource Ltd. +# +# This library is free software; you can redistribute it and/or +# modify it under the terms of version 2.1 of the GNU Lesser General Public +# License as published by the Free Software Foundation. +# +# This library 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 library; if not, write to the Free Software +# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +# + + +dir=$(dirname "$0") +. "$dir/xen-hotplug-common.sh" + +command="$1" + +if [ "$command" != "bind" ] && [ "$command" != "unbind" ] +then + log err "Invalid command: $command" + exit 1 +fi + + +XENBUS_PATH="${XENBUS_PATH:?}" + + +## +# Write physical-device = 0xMMmm and node = device to the store, where MM +# and mm are the major and minor numbers of device. +# +# @param device The device from which major and minor numbers are read, which +# will be written into the store. +# +write_dev() { + local major + local minor + local pdev + + major=$(stat -L -c %t "$1") + minor=$(stat -L -c %T "$1") + pdev=$(printf "0x%02x%02x" "0x$major" "0x$minor") + xenstore_write "$XENBUS_PATH"/physical-device "$pdev" \ + "$XENBUS_PATH"/node "$1" +} diff --git a/tools/examples/block-enbd b/tools/examples/block-enbd index c86068d817..c58adb595d 100755 --- a/tools/examples/block-enbd +++ b/tools/examples/block-enbd @@ -2,25 +2,19 @@ # Usage: block-enbd [bind server ctl_port |unbind node] # -# The file argument to the bind command is the file we are to bind to a -# loop device. -# # The node argument to unbind is the name of the device node we are to # unbind. # # This assumes you're running a correctly configured server at the other end! -set -e +dir=$(dirname "$0") +. "$dir/block-common.sh" -case $1 in +case "$command" in bind) for dev in /dev/nd*; do if nbd-client $2:$3 $dev; then - major=$(stat -L -c %t "$dev") - minor=$(stat -L -c %T "$dev") - pdev=$(printf "0x%02x%02x" 0x$major 0x$minor) - xenstore-write "$XENBUS_PATH"/physical-device $pdev \ - "$XENBUS_PATH"/node $dev + write_dev $dev exit 0 fi done diff --git a/tools/examples/block-nbd b/tools/examples/block-nbd index 06f9f6875e..142a403c0f 100644 --- a/tools/examples/block-nbd +++ b/tools/examples/block-nbd @@ -1,28 +1,20 @@ #!/bin/sh -# Usage: block-enbd [bind server ctl_port |unbind node] -# -# The file argument to the bind command is the file we are to bind to a -# loop device. +# Usage: block-nbd [bind server ctl_port |unbind node] # # The node argument to unbind is the name of the device node we are to # unbind. # # This assumes you're running a correctly configured server at the other end! -set -e +dir=$(dirname "$0") +. "$dir/block-common.sh" -#echo "block-enbd: $@" | logger -t xen - -case $1 in +case "$command" in bind) for dev in /dev/nbd*; do if nbd-client $2 $3 $dev; then - major=$(stat -L -c %t "$dev") - minor=$(stat -L -c %T "$dev") - pdev=$(printf "0x%02x%02x" 0x$major 0x$minor) - xenstore-write "$XENBUS_PATH"/physical-device $pdev \ - "$XENBUS_PATH"/node $dev + write_dev $dev exit 0 fi done From 0edd55be1931088d9f8795ec60b3f27cdc2f3a03 Mon Sep 17 00:00:00 2001 From: "emellor@leeni.uk.xensource.com" Date: Wed, 26 Oct 2005 14:59:29 +0100 Subject: [PATCH 15/34] Move exception handler for sxp.ParseError above that for Exception, as the latter subsumes the former. Minor tidy-ups. Signed-off-by: Ewan Mellor --- tools/python/xen/xend/server/SrvDomainDir.py | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/tools/python/xen/xend/server/SrvDomainDir.py b/tools/python/xen/xend/server/SrvDomainDir.py index b410174fac..d0bf999261 100644 --- a/tools/python/xen/xend/server/SrvDomainDir.py +++ b/tools/python/xen/xend/server/SrvDomainDir.py @@ -25,7 +25,6 @@ from xen.xend import XendDomain from xen.xend.XendDomainInfo import XendDomainInfo from xen.xend.Args import FormFn from xen.xend.XendError import XendError -from xen.xend.XendLogging import log from xen.web.SrvDir import SrvDir from SrvDomain import SrvDomain @@ -52,7 +51,7 @@ class SrvDomainDir(SrvDir): else: return self.domain(x) - def op_create(self, op, req): + def op_create(self, _, req): """Create a domain. Expects the domain config in request parameter 'config' in SXP format. """ @@ -66,12 +65,12 @@ class SrvDomainDir(SrvDir): pin.input_eof() config = pin.get_val() ok = 1 + except sxp.ParseError, ex: + errmsg = 'Invalid configuration ' + str(ex) except Exception, ex: print 'op_create> Exception in config', ex traceback.print_exc() errmsg = 'Configuration error ' + str(ex) - except sxp.ParseError, ex: - errmsg = 'Invalid configuration ' + str(ex) if not ok: raise XendError(errmsg) try: @@ -108,7 +107,7 @@ class SrvDomainDir(SrvDir): """ return req.threadRequest(self.do_restore, op, req) - def do_restore(self, op, req): + def do_restore(self, _, req): fn = FormFn(self.xd.domain_restore, [['file', 'str']]) dominfo = fn(req.args) From 6ee89dae792ca89399753492cac801110352f608 Mon Sep 17 00:00:00 2001 From: "emellor@leeni.uk.xensource.com" Date: Wed, 26 Oct 2005 16:59:13 +0100 Subject: [PATCH 16/34] Fix the check for non-existence of the save/restore directories, by using && rather than -a. The former shortcuts at the script level, whereas the latter does not, which means that the backtick-enclosed arguments are evaluated regardless of the success of preceding tests. Tidy the aforementioned test into a function of its own. Add an implementation of usleep for those systems that only have sleep (Debian, for example). Signed-off-by: Ewan Mellor --- tools/examples/init.d/xendomains | 52 +++++++++++++++++++++++++------- 1 file changed, 41 insertions(+), 11 deletions(-) diff --git a/tools/examples/init.d/xendomains b/tools/examples/init.d/xendomains index ce96284937..4d7db36295 100644 --- a/tools/examples/init.d/xendomains +++ b/tools/examples/init.d/xendomains @@ -121,9 +121,34 @@ else } fi +if ! which usleep >&/dev/null +then + usleep() + { + if [ -n "$1" ] + then + sleep $(( $1 / 1000 )) + fi + } +fi + # Reset status of this service rc_reset +## +# Returns 0 (success) if the given parameter names a directory, and that +# directory is not empty. +# +contains_something() +{ + if [ -d "$1" ] && [ `/bin/ls $1 | wc -l` -gt 0 ] + then + return 0 + else + return 1 + fi +} + # read name from xen config file rdname() { @@ -133,7 +158,8 @@ rdname() rdnames() { NAMES= - if test ! -d $XENDOMAINS_AUTO -o `/bin/ls $XENDOMAINS_AUTO | wc -l` -eq 0; then + if ! contains_something "$XENDOMAINS_AUTO" + then return fi for dom in $XENDOMAINS_AUTO/*; do @@ -177,9 +203,10 @@ start() return; fi - if test "$XENDOMAINS_RESTORE" = "true" -a -n "$XENDOMAINS_SAVE" \ - -a -d $XENDOMAINS_SAVE -a `/bin/ls $XENDOMAINS_SAVE | wc -l` -gt 0; then - + if [ "$XENDOMAINS_RESTORE" = "true" ] && + contains_something "$XENDOMAINS_SAVE" + then + mkdir -p $(dirname "$LOCKFILE") touch $LOCKFILE echo -n "Restoring Xen domains:" for dom in $XENDOMAINS_SAVE/*; do @@ -195,9 +222,8 @@ start() done fi - if test -n "$XENDOMAINS_AUTO" -a -d $XENDOMAINS_AUTO \ - -a `/bin/ls $XENDOMAINS_AUTO | wc -l` -gt 0; then - + if contains_something "$XENDOMAINS_AUTO" + then touch $LOCKFILE echo -n "Starting auto Xen domains:" # We expect config scripts for auto starting domains to be in @@ -378,8 +404,10 @@ check_domain_up() check_all_auto_domains_up() { - if test -z "$XENDOMAINS_AUTO" -o ! -d "$XENDOMAINS_AUTO" \ - -o `/bin/ls $XENDOMAINS_AUTO | wc -l` -eq 0; then return 0; fi + if ! contains_something "$XENDOMAINS_AUTO" + then + return 0 + fi missing= for nm in $XENDOMAINS_AUTO/*; do rdname $nm @@ -399,8 +427,10 @@ check_all_auto_domains_up() check_all_saved_domains_up() { - if test -z "$XENDOMAINS_SAVE" -o ! -d "$XENDOMAINS_SAVE" \ - -o `/bin/ls $XENDOMAINS_SAVE | wc -l` -eq 0; then return 0; fi + if ! contains_something "$XENDOMAINS_SAVE" + then + return 0 + fi missing=`/bin/ls $XENDOMAINS_SAVE` echo -n " MISS SAVED: " $missing return 1 From 740401a4f848c64541f892b224d32aec56ac6946 Mon Sep 17 00:00:00 2001 From: "jeroney@localhost.localdomain" Date: Thu, 27 Oct 2005 10:19:58 +0100 Subject: [PATCH 17/34] * Enable xenstat to use xenstore * Have xentop display names instead of DomIDs as requested in Bugzilla#311 filed by Ian --- tools/xenstat/libxenstat/Makefile | 4 +-- tools/xenstat/libxenstat/src/xenstat.c | 41 ++++++++++++++++++++++++++ tools/xenstat/libxenstat/src/xenstat.h | 3 ++ tools/xenstat/xentop/Makefile | 2 +- tools/xenstat/xentop/xentop.c | 19 +++++++++++- 5 files changed, 65 insertions(+), 4 deletions(-) diff --git a/tools/xenstat/libxenstat/Makefile b/tools/xenstat/libxenstat/Makefile index 750adaaa29..d874ba3af1 100644 --- a/tools/xenstat/libxenstat/Makefile +++ b/tools/xenstat/libxenstat/Makefile @@ -38,13 +38,13 @@ SONAME_FLAGS=-Wl,-soname -Wl,libxenstat.so.$(MAJOR) WARN_FLAGS=-Wall -Werror -CFLAGS+=-Isrc -I$(XEN_LIBXC) +CFLAGS+=-Isrc -I$(XEN_LIBXC) -I$(XEN_XENSTORE) LDFLAGS+=-Lsrc all: $(LIB) $(LIB): $(OBJECTS) - $(AR) rc $@ $^ + $(AR) rc $@ $^ $(XEN_XENSTORE)/libxenstore.so $(RANLIB) $@ $(SHLIB): $(OBJECTS) diff --git a/tools/xenstat/libxenstat/src/xenstat.c b/tools/xenstat/libxenstat/src/xenstat.c index 85da72b168..22a3ec8a97 100644 --- a/tools/xenstat/libxenstat/src/xenstat.c +++ b/tools/xenstat/libxenstat/src/xenstat.c @@ -21,6 +21,7 @@ #include #include #include +#include #include "xenstat.h" /* @@ -31,6 +32,7 @@ struct xenstat_handle { xi_handle *xihandle; + struct xs_handle *xshandle; /* xenstore handle */ int page_size; FILE *procnetdev; char xen_version[VERSION_SIZE]; /* xen version running on this node */ @@ -49,6 +51,7 @@ struct xenstat_node { struct xenstat_domain { unsigned int id; + char *name; unsigned int state; unsigned long long cpu_ns; unsigned int num_vcpus; /* No. vcpus configured for domain */ @@ -110,6 +113,7 @@ static void xenstat_free_xen_version(xenstat_node * node); static void xenstat_uninit_vcpus(xenstat_handle * handle); static void xenstat_uninit_networks(xenstat_handle * handle); static void xenstat_uninit_xen_version(xenstat_handle * handle); +static char *xenstat_get_domain_name(xenstat_handle * handle, unsigned int domain_id); static xenstat_collector collectors[] = { { XENSTAT_VCPU, xenstat_collect_vcpus, @@ -153,6 +157,13 @@ xenstat_handle *xenstat_init() return NULL; } + handle->xshandle = xs_daemon_open_readonly(); /* open handle to xenstore*/ + if (handle->xshandle == NULL) { + perror("unable to open xenstore\n"); + free(handle); + return NULL; + } + return handle; } @@ -163,6 +174,7 @@ void xenstat_uninit(xenstat_handle * handle) for (i = 0; i < NUM_COLLECTORS; i++) collectors[i].uninit(handle); xi_uninit(handle->xihandle); + xs_daemon_close(handle->xshandle); free(handle); } } @@ -228,6 +240,7 @@ xenstat_node *xenstat_get_node(xenstat_handle * handle, unsigned int flags) for (i = 0; i < new_domains; i++) { /* Fill in domain using domaininfo[i] */ domain->id = domaininfo[i].domain; + domain->name = xenstat_get_domain_name(handle, domaininfo[i].domain); domain->state = domaininfo[i].flags; domain->cpu_ns = domaininfo[i].cpu_time; domain->num_vcpus = (domaininfo[i].max_vcpu_id+1); @@ -339,6 +352,12 @@ unsigned xenstat_domain_id(xenstat_domain * domain) return domain->id; } +/* Get the domain name for the domain */ +char *xenstat_domain_name(xenstat_domain * domain) +{ + return domain->name; +} + /* Get information about how much CPU time has been used */ unsigned long long xenstat_domain_cpu_ns(xenstat_domain * domain) { @@ -675,3 +694,25 @@ static void xenstat_free_xen_version(xenstat_node * node) static void xenstat_uninit_xen_version(xenstat_handle * handle) { } + +static char *xenstat_get_domain_name(xenstat_handle *handle, unsigned int domain_id) +{ + char path[80]; + char *name; + unsigned int *len; + struct xs_transaction_handle *xstranshandle; + + snprintf(path, sizeof(path),"/local/domain/%i/name", domain_id); + + xstranshandle = xs_transaction_start(handle->xshandle); + if (xstranshandle == NULL) { + perror("Unable to get transcation handle from xenstore\n"); + exit(1); /* Change this */ + } + + name = (char *) xs_read(handle->xshandle, xstranshandle, path, len); + + xs_transaction_end(handle->xshandle, xstranshandle, false); + + return name; +} diff --git a/tools/xenstat/libxenstat/src/xenstat.h b/tools/xenstat/libxenstat/src/xenstat.h index 286fa035bf..b9ac1d3782 100644 --- a/tools/xenstat/libxenstat/src/xenstat.h +++ b/tools/xenstat/libxenstat/src/xenstat.h @@ -80,6 +80,9 @@ unsigned long long xenstat_node_cpu_hz(xenstat_node * node); /* Get the domain ID for this domain */ unsigned xenstat_domain_id(xenstat_domain * domain); +/* Set the domain name for the domain */ +char *xenstat_domain_name(xenstat_domain * domain); + /* Get information about how much CPU time has been used */ unsigned long long xenstat_domain_cpu_ns(xenstat_domain * domain); diff --git a/tools/xenstat/xentop/Makefile b/tools/xenstat/xentop/Makefile index 633fd57064..2115e6f3cf 100644 --- a/tools/xenstat/xentop/Makefile +++ b/tools/xenstat/xentop/Makefile @@ -26,7 +26,7 @@ mandir=$(prefix)/share/man man1dir=$(mandir)/man1 sbindir=$(prefix)/sbin -CFLAGS += -DGCC_PRINTF -Wall -Werror -I$(XEN_LIBXENSTAT) +CFLAGS += -DGCC_PRINTF -Wall -I$(XEN_LIBXENSTAT) LDFLAGS += -L$(XEN_LIBXENSTAT) LDLIBS += -lxenstat -lncurses diff --git a/tools/xenstat/xentop/xentop.c b/tools/xenstat/xentop/xentop.c index 1cb5e36829..286b037051 100644 --- a/tools/xenstat/xentop/xentop.c +++ b/tools/xenstat/xentop/xentop.c @@ -28,6 +28,7 @@ #include #include +#include #include #define XENTOP_VERSION "1.0" @@ -91,6 +92,8 @@ static int compare_net_rx(xenstat_domain *domain1, xenstat_domain *domain2); static void print_net_rx(xenstat_domain *domain); static int compare_ssid(xenstat_domain *domain1, xenstat_domain *domain2); static void print_ssid(xenstat_domain *domain); +static int compare_name(xenstat_domain *domain1, xenstat_domain *domain2); +static void print_name(xenstat_domain *domain); /* Section printing functions */ static void do_summary(void); @@ -104,6 +107,7 @@ static void top(void); /* Field types */ typedef enum field_id { FIELD_DOMID, + FIELD_NAME, FIELD_STATE, FIELD_CPU, FIELD_CPU_PCT, @@ -127,7 +131,8 @@ typedef struct field { } field; field fields[] = { - { FIELD_DOMID, "DOMID", 5, compare_domid, print_domid }, +// { FIELD_DOMID, "DOMID", 5, compare_domid, print_domid }, + { FIELD_NAME, "NAME", 10, compare_name, print_name }, { FIELD_STATE, "STATE", 6, compare_state, print_state }, { FIELD_CPU, "CPU(sec)", 10, compare_cpu, print_cpu }, { FIELD_CPU_PCT, "CPU(%)", 6, compare_cpu_pct, print_cpu_pct }, @@ -356,6 +361,18 @@ void print_domid(xenstat_domain *domain) print("%5u", xenstat_domain_id(domain)); } +/* Compare domain names, returning -1,0,1 for <,=,> */ +int compare_name(xenstat_domain *domain1, xenstat_domain *domain2) +{ + return strcasecmp(xenstat_domain_name(domain1), xenstat_domain_name(domain2)); +} + +/* Prints domain name */ +void print_name(xenstat_domain *domain) +{ + print("%10s", xenstat_domain_name(domain)); +} + struct { unsigned int (*get)(xenstat_domain *); char ch; From f76bd5cf5e9e56b46c8c5acb595dbec6b842c34d Mon Sep 17 00:00:00 2001 From: "emellor@leeni.uk.xensource.com" Date: Thu, 27 Oct 2005 10:53:02 +0100 Subject: [PATCH 18/34] Fix Jerone Young's xenstat / xenstore patch: Reject the removal of -Werror from the xentop Makefile. Reject the #include of xs.h inside xentop -- there is no need for it. Have XendDomainInfo write domain names into /local/domain (which used to happen, but hasn't for a little while). Remove the dead code from xentop.c. Signed-off-by: Ewan Mellor --- tools/python/xen/xend/XendDomainInfo.py | 1 + tools/xenstat/xentop/Makefile | 2 +- tools/xenstat/xentop/xentop.c | 16 ---------------- 3 files changed, 2 insertions(+), 17 deletions(-) diff --git a/tools/python/xen/xend/XendDomainInfo.py b/tools/python/xen/xend/XendDomainInfo.py index 11256f8916..999716219d 100644 --- a/tools/python/xen/xend/XendDomainInfo.py +++ b/tools/python/xen/xend/XendDomainInfo.py @@ -595,6 +595,7 @@ class XendDomainInfo: to_store = { 'domid': str(self.domid), 'vm': self.vmpath, + 'name': self.info['name'], 'console/limit': str(xroot.get_console_limit() * 1024), 'memory/target': str(self.info['memory_KiB']) } diff --git a/tools/xenstat/xentop/Makefile b/tools/xenstat/xentop/Makefile index 2115e6f3cf..633fd57064 100644 --- a/tools/xenstat/xentop/Makefile +++ b/tools/xenstat/xentop/Makefile @@ -26,7 +26,7 @@ mandir=$(prefix)/share/man man1dir=$(mandir)/man1 sbindir=$(prefix)/sbin -CFLAGS += -DGCC_PRINTF -Wall -I$(XEN_LIBXENSTAT) +CFLAGS += -DGCC_PRINTF -Wall -Werror -I$(XEN_LIBXENSTAT) LDFLAGS += -L$(XEN_LIBXENSTAT) LDLIBS += -lxenstat -lncurses diff --git a/tools/xenstat/xentop/xentop.c b/tools/xenstat/xentop/xentop.c index 286b037051..050f95bfcb 100644 --- a/tools/xenstat/xentop/xentop.c +++ b/tools/xenstat/xentop/xentop.c @@ -28,7 +28,6 @@ #include #include -#include #include #define XENTOP_VERSION "1.0" @@ -68,8 +67,6 @@ static int compare_domains(xenstat_domain **, xenstat_domain **); static unsigned long long tot_net_bytes( xenstat_domain *, int); /* Field functions */ -static int compare_domid(xenstat_domain *domain1, xenstat_domain *domain2); -static void print_domid(xenstat_domain *domain); static int compare_state(xenstat_domain *domain1, xenstat_domain *domain2); static void print_state(xenstat_domain *domain); static int compare_cpu(xenstat_domain *domain1, xenstat_domain *domain2); @@ -131,7 +128,6 @@ typedef struct field { } field; field fields[] = { -// { FIELD_DOMID, "DOMID", 5, compare_domid, print_domid }, { FIELD_NAME, "NAME", 10, compare_name, print_name }, { FIELD_STATE, "STATE", 6, compare_state, print_state }, { FIELD_CPU, "CPU(sec)", 10, compare_cpu, print_cpu }, @@ -349,18 +345,6 @@ static int compare_domains(xenstat_domain **domain1, xenstat_domain **domain2) /* Field functions */ -/* Compares domain ids of two domains, returning -1,0,1 for <,=,> */ -int compare_domid(xenstat_domain *domain1, xenstat_domain *domain2) -{ - return compare(xenstat_domain_id(domain1), xenstat_domain_id(domain2)); -} - -/* Prints domain identification number */ -void print_domid(xenstat_domain *domain) -{ - print("%5u", xenstat_domain_id(domain)); -} - /* Compare domain names, returning -1,0,1 for <,=,> */ int compare_name(xenstat_domain *domain1, xenstat_domain *domain2) { From 650fa32a005d49cdec715a3cdd4d1955d57036a8 Mon Sep 17 00:00:00 2001 From: "kaf24@firebug.cl.cam.ac.uk" Date: Thu, 27 Oct 2005 17:09:01 +0100 Subject: [PATCH 19/34] BUG_ON() is a macro very very similar to assert(), and it's a really bad idea in general to put statements with side-effects inside such a construct (for example the BUG_ON() could be compiled away for non-debug builds). The patch below fixes this for the drivers/xen tree. I chose the general construct to store the respective return values in a local var instead of an if (...) BUG(); because it looks like most of these BUG_ON()'s need to be replaced by real error handling when going towards production releases anyway, and then the local variable is going to be needed anyway. (and besides the if construct tends to get unreable due to the unlikely() etc). Please apply. Greetings, Arjan van de Ven --- .../drivers/xen/balloon/balloon.c | 37 ++++++++++++------- .../drivers/xen/blkback/blkback.c | 15 +++++--- .../drivers/xen/blkback/interface.c | 8 +++- .../drivers/xen/blkfront/blkfront.c | 6 ++- .../drivers/xen/blktap/blktap.c | 13 ++++--- .../drivers/xen/blktap/interface.c | 8 +++- .../drivers/xen/evtchn/evtchn.c | 8 +++- .../drivers/xen/netback/interface.c | 14 +++++-- .../drivers/xen/netback/netback.c | 31 +++++++++++----- .../drivers/xen/tpmback/interface.c | 8 +++- linux-2.6-xen-sparse/drivers/xen/util.c | 4 +- .../drivers/xen/xenbus/xenbus_probe.c | 4 +- 12 files changed, 106 insertions(+), 50 deletions(-) diff --git a/linux-2.6-xen-sparse/drivers/xen/balloon/balloon.c b/linux-2.6-xen-sparse/drivers/xen/balloon/balloon.c index f630d4bf71..fab1ea6bc3 100644 --- a/linux-2.6-xen-sparse/drivers/xen/balloon/balloon.c +++ b/linux-2.6-xen-sparse/drivers/xen/balloon/balloon.c @@ -191,12 +191,13 @@ static int increase_reservation(unsigned long nr_pages) rc = HYPERVISOR_memory_op( XENMEM_increase_reservation, &reservation); if (rc < nr_pages) { + int ret; /* We hit the Xen hard limit: reprobe. */ reservation.extent_start = mfn_list; reservation.nr_extents = rc; - BUG_ON(HYPERVISOR_memory_op( - XENMEM_decrease_reservation, - &reservation) != rc); + ret = HYPERVISOR_memory_op(XENMEM_decrease_reservation, + &reservation); + BUG_ON(ret != rc); hard_limit = current_pages + rc - driver_pages; goto out; } @@ -213,11 +214,14 @@ static int increase_reservation(unsigned long nr_pages) xen_machphys_update(mfn_list[i], pfn); /* Link back into the page tables if not highmem. */ - if (pfn < max_low_pfn) - BUG_ON(HYPERVISOR_update_va_mapping( + if (pfn < max_low_pfn) { + int ret; + ret = HYPERVISOR_update_va_mapping( (unsigned long)__va(pfn << PAGE_SHIFT), pfn_pte_ma(mfn_list[i], PAGE_KERNEL), - 0)); + 0); + BUG_ON(ret); + } /* Relinquish the page back to the allocator. */ ClearPageReserved(page); @@ -242,6 +246,7 @@ static int decrease_reservation(unsigned long nr_pages) struct page *page; void *v; int need_sleep = 0; + int ret; struct xen_memory_reservation reservation = { .address_bits = 0, .extent_order = 0, @@ -268,8 +273,9 @@ static int decrease_reservation(unsigned long nr_pages) if (!PageHighMem(page)) { v = phys_to_virt(pfn << PAGE_SHIFT); scrub_pages(v, 1); - BUG_ON(HYPERVISOR_update_va_mapping( - (unsigned long)v, __pte_ma(0), 0)); + ret = HYPERVISOR_update_va_mapping( + (unsigned long)v, __pte_ma(0), 0); + BUG_ON(ret); } #ifdef CONFIG_XEN_SCRUB_PAGES else { @@ -295,8 +301,8 @@ static int decrease_reservation(unsigned long nr_pages) reservation.extent_start = mfn_list; reservation.nr_extents = nr_pages; - BUG_ON(HYPERVISOR_memory_op( - XENMEM_decrease_reservation, &reservation) != nr_pages); + ret = HYPERVISOR_memory_op(XENMEM_decrease_reservation, &reservation); + BUG_ON(ret != nr_pages); current_pages -= nr_pages; totalram_pages = current_pages; @@ -501,6 +507,7 @@ static int dealloc_pte_fn( pte_t *pte, struct page *pte_page, unsigned long addr, void *data) { unsigned long mfn = pte_mfn(*pte); + int ret; struct xen_memory_reservation reservation = { .extent_start = &mfn, .nr_extents = 1, @@ -510,8 +517,8 @@ static int dealloc_pte_fn( set_pte_at(&init_mm, addr, pte, __pte_ma(0)); phys_to_machine_mapping[__pa(addr) >> PAGE_SHIFT] = INVALID_P2M_ENTRY; - BUG_ON(HYPERVISOR_memory_op( - XENMEM_decrease_reservation, &reservation) != 1); + ret = HYPERVISOR_memory_op(XENMEM_decrease_reservation, &reservation); + BUG_ON(ret != 1); return 0; } @@ -519,6 +526,7 @@ struct page *balloon_alloc_empty_page_range(unsigned long nr_pages) { unsigned long vstart, flags; unsigned int order = get_order(nr_pages * PAGE_SIZE); + int ret; vstart = __get_free_pages(GFP_KERNEL, order); if (vstart == 0) @@ -527,8 +535,9 @@ struct page *balloon_alloc_empty_page_range(unsigned long nr_pages) scrub_pages(vstart, 1 << order); balloon_lock(flags); - BUG_ON(generic_page_range( - &init_mm, vstart, PAGE_SIZE << order, dealloc_pte_fn, NULL)); + ret = generic_page_range( + &init_mm, vstart, PAGE_SIZE << order, dealloc_pte_fn, NULL); + BUG_ON(ret); current_pages -= 1UL << order; balloon_unlock(flags); diff --git a/linux-2.6-xen-sparse/drivers/xen/blkback/blkback.c b/linux-2.6-xen-sparse/drivers/xen/blkback/blkback.c index c9d812695e..3dc929f0a7 100644 --- a/linux-2.6-xen-sparse/drivers/xen/blkback/blkback.c +++ b/linux-2.6-xen-sparse/drivers/xen/blkback/blkback.c @@ -108,6 +108,7 @@ static void fast_flush_area(int idx, int nr_pages) struct gnttab_unmap_grant_ref unmap[BLKIF_MAX_SEGMENTS_PER_REQUEST]; unsigned int i, invcount = 0; u16 handle; + int ret; for (i = 0; i < nr_pages; i++) { handle = pending_handle(idx, i); @@ -120,8 +121,9 @@ static void fast_flush_area(int idx, int nr_pages) invcount++; } - BUG_ON(HYPERVISOR_grant_table_op( - GNTTABOP_unmap_grant_ref, unmap, invcount)); + ret = HYPERVISOR_grant_table_op( + GNTTABOP_unmap_grant_ref, unmap, invcount); + BUG_ON(ret); } @@ -338,6 +340,7 @@ static void dispatch_rw_block_io(blkif_t *blkif, blkif_request_t *req) struct bio *bio = NULL, *biolist[BLKIF_MAX_SEGMENTS_PER_REQUEST]; int nbio = 0; request_queue_t *q; + int ret; /* Check that number of segments is sane. */ nseg = req->nr_segments; @@ -367,8 +370,8 @@ static void dispatch_rw_block_io(blkif_t *blkif, blkif_request_t *req) map[i].flags |= GNTMAP_readonly; } - BUG_ON(HYPERVISOR_grant_table_op( - GNTTABOP_map_grant_ref, map, nseg)); + ret = HYPERVISOR_grant_table_op(GNTTABOP_map_grant_ref, map, nseg); + BUG_ON(ret); for (i = 0; i < nseg; i++) { if (unlikely(map[i].handle < 0)) { @@ -493,6 +496,7 @@ static int __init blkif_init(void) { int i; struct page *page; + int ret; blkif_interface_init(); @@ -509,7 +513,8 @@ static int __init blkif_init(void) spin_lock_init(&blkio_schedule_list_lock); INIT_LIST_HEAD(&blkio_schedule_list); - BUG_ON(kernel_thread(blkio_schedule, 0, CLONE_FS | CLONE_FILES) < 0); + ret = kernel_thread(blkio_schedule, 0, CLONE_FS | CLONE_FILES); + BUG_ON(ret < 0); blkif_xenbus_init(); diff --git a/linux-2.6-xen-sparse/drivers/xen/blkback/interface.c b/linux-2.6-xen-sparse/drivers/xen/blkback/interface.c index ee1889a09a..be6f935191 100644 --- a/linux-2.6-xen-sparse/drivers/xen/blkback/interface.c +++ b/linux-2.6-xen-sparse/drivers/xen/blkback/interface.c @@ -31,6 +31,7 @@ blkif_t *alloc_blkif(domid_t domid) static int map_frontend_page(blkif_t *blkif, unsigned long shared_page) { struct gnttab_map_grant_ref op; + int ret; op.host_addr = (unsigned long)blkif->blk_ring_area->addr; op.flags = GNTMAP_host_map; @@ -38,8 +39,9 @@ static int map_frontend_page(blkif_t *blkif, unsigned long shared_page) op.dom = blkif->domid; lock_vm_area(blkif->blk_ring_area); - BUG_ON(HYPERVISOR_grant_table_op(GNTTABOP_map_grant_ref, &op, 1)); + ret = HYPERVISOR_grant_table_op(GNTTABOP_map_grant_ref, &op, 1); unlock_vm_area(blkif->blk_ring_area); + BUG_ON(ret); if (op.handle < 0) { DPRINTK(" Grant table operation failure !\n"); @@ -55,14 +57,16 @@ static int map_frontend_page(blkif_t *blkif, unsigned long shared_page) static void unmap_frontend_page(blkif_t *blkif) { struct gnttab_unmap_grant_ref op; + int ret; op.host_addr = (unsigned long)blkif->blk_ring_area->addr; op.handle = blkif->shmem_handle; op.dev_bus_addr = 0; lock_vm_area(blkif->blk_ring_area); - BUG_ON(HYPERVISOR_grant_table_op(GNTTABOP_unmap_grant_ref, &op, 1)); + ret = HYPERVISOR_grant_table_op(GNTTABOP_unmap_grant_ref, &op, 1); unlock_vm_area(blkif->blk_ring_area); + BUG_ON(ret); } int blkif_map(blkif_t *blkif, unsigned long shared_page, unsigned int evtchn) diff --git a/linux-2.6-xen-sparse/drivers/xen/blkfront/blkfront.c b/linux-2.6-xen-sparse/drivers/xen/blkfront/blkfront.c index 671f16038c..3485d84424 100644 --- a/linux-2.6-xen-sparse/drivers/xen/blkfront/blkfront.c +++ b/linux-2.6-xen-sparse/drivers/xen/blkfront/blkfront.c @@ -305,6 +305,7 @@ static irqreturn_t blkif_int(int irq, void *dev_id, struct pt_regs *ptregs) for (i = info->ring.rsp_cons; i != rp; i++) { unsigned long id; + int ret; bret = RING_GET_RESPONSE(&info->ring, i); id = bret->id; @@ -321,9 +322,10 @@ static irqreturn_t blkif_int(int irq, void *dev_id, struct pt_regs *ptregs) DPRINTK("Bad return from blkdev data " "request: %x\n", bret->status); - BUG_ON(end_that_request_first( + ret = end_that_request_first( req, (bret->status == BLKIF_RSP_OKAY), - req->hard_nr_sectors)); + req->hard_nr_sectors); + BUG_ON(ret); end_that_request_last(req); break; default: diff --git a/linux-2.6-xen-sparse/drivers/xen/blktap/blktap.c b/linux-2.6-xen-sparse/drivers/xen/blktap/blktap.c index dacedfc227..03a4fcb970 100644 --- a/linux-2.6-xen-sparse/drivers/xen/blktap/blktap.c +++ b/linux-2.6-xen-sparse/drivers/xen/blktap/blktap.c @@ -413,6 +413,7 @@ static void fast_flush_area(int idx, int nr_pages) unsigned int i, op = 0; struct grant_handle_pair *handle; unsigned long ptep; + int ret; for ( i = 0; i < nr_pages; i++) { @@ -440,8 +441,8 @@ static void fast_flush_area(int idx, int nr_pages) BLKTAP_INVALIDATE_HANDLE(handle); } - BUG_ON(HYPERVISOR_grant_table_op( - GNTTABOP_unmap_grant_ref, unmap, op)); + ret = HYPERVISOR_grant_table_op(GNTTABOP_unmap_grant_ref, unmap, op); + BUG_ON(ret); if (blktap_vma != NULL) zap_page_range(blktap_vma, @@ -673,6 +674,7 @@ static void dispatch_rw_block_io(blkif_t *blkif, blkif_request_t *req) struct gnttab_map_grant_ref map[BLKIF_MAX_SEGMENTS_PER_REQUEST*2]; int op, ret; unsigned int nseg; + int retval; /* Check that number of segments is sane. */ nseg = req->nr_segments; @@ -740,8 +742,8 @@ static void dispatch_rw_block_io(blkif_t *blkif, blkif_request_t *req) op++; } - BUG_ON(HYPERVISOR_grant_table_op( - GNTTABOP_map_grant_ref, map, op)); + retval = HYPERVISOR_grant_table_op(GNTTABOP_map_grant_ref, map, op); + BUG_ON(retval); op = 0; for (i = 0; i < (req->nr_segments*2); i += 2) { @@ -877,7 +879,8 @@ static int __init blkif_init(void) spin_lock_init(&blkio_schedule_list_lock); INIT_LIST_HEAD(&blkio_schedule_list); - BUG_ON(kernel_thread(blkio_schedule, 0, CLONE_FS | CLONE_FILES) < 0); + i = kernel_thread(blkio_schedule, 0, CLONE_FS | CLONE_FILES); + BUG_ON(i<0); blkif_xenbus_init(); diff --git a/linux-2.6-xen-sparse/drivers/xen/blktap/interface.c b/linux-2.6-xen-sparse/drivers/xen/blktap/interface.c index 1394922ac7..dcaedf875e 100644 --- a/linux-2.6-xen-sparse/drivers/xen/blktap/interface.c +++ b/linux-2.6-xen-sparse/drivers/xen/blktap/interface.c @@ -31,6 +31,7 @@ blkif_t *alloc_blkif(domid_t domid) static int map_frontend_page(blkif_t *blkif, unsigned long shared_page) { struct gnttab_map_grant_ref op; + int ret; op.host_addr = (unsigned long)blkif->blk_ring_area->addr; op.flags = GNTMAP_host_map; @@ -38,8 +39,9 @@ static int map_frontend_page(blkif_t *blkif, unsigned long shared_page) op.dom = blkif->domid; lock_vm_area(blkif->blk_ring_area); - BUG_ON(HYPERVISOR_grant_table_op(GNTTABOP_map_grant_ref, &op, 1)); + ret = HYPERVISOR_grant_table_op(GNTTABOP_map_grant_ref, &op, 1); unlock_vm_area(blkif->blk_ring_area); + BUG_ON(ret); if (op.handle < 0) { DPRINTK(" Grant table operation failure !\n"); @@ -55,14 +57,16 @@ static int map_frontend_page(blkif_t *blkif, unsigned long shared_page) static void unmap_frontend_page(blkif_t *blkif) { struct gnttab_unmap_grant_ref op; + int ret; op.host_addr = (unsigned long)blkif->blk_ring_area->addr; op.handle = blkif->shmem_handle; op.dev_bus_addr = 0; lock_vm_area(blkif->blk_ring_area); - BUG_ON(HYPERVISOR_grant_table_op(GNTTABOP_unmap_grant_ref, &op, 1)); + ret = HYPERVISOR_grant_table_op(GNTTABOP_unmap_grant_ref, &op, 1); unlock_vm_area(blkif->blk_ring_area); + BUG_ON(ret); } int blkif_map(blkif_t *blkif, unsigned long shared_page, unsigned int evtchn) diff --git a/linux-2.6-xen-sparse/drivers/xen/evtchn/evtchn.c b/linux-2.6-xen-sparse/drivers/xen/evtchn/evtchn.c index d3a805fb72..42f4a8f70a 100644 --- a/linux-2.6-xen-sparse/drivers/xen/evtchn/evtchn.c +++ b/linux-2.6-xen-sparse/drivers/xen/evtchn/evtchn.c @@ -282,6 +282,7 @@ static int evtchn_ioctl(struct inode *inode, struct file *file, case IOCTL_EVTCHN_UNBIND: { struct ioctl_evtchn_unbind unbind; + int ret; rc = -EFAULT; if (copy_from_user(&unbind, (void *)arg, sizeof(unbind))) @@ -306,7 +307,8 @@ static int evtchn_ioctl(struct inode *inode, struct file *file, op.cmd = EVTCHNOP_close; op.u.close.port = unbind.port; - BUG_ON(HYPERVISOR_event_channel_op(&op)); + ret = HYPERVISOR_event_channel_op(&op); + BUG_ON(ret); rc = 0; break; @@ -399,6 +401,7 @@ static int evtchn_release(struct inode *inode, struct file *filp) for (i = 0; i < NR_EVENT_CHANNELS; i++) { + int ret; if (port_user[i] != u) continue; @@ -407,7 +410,8 @@ static int evtchn_release(struct inode *inode, struct file *filp) op.cmd = EVTCHNOP_close; op.u.close.port = i; - BUG_ON(HYPERVISOR_event_channel_op(&op)); + ret = HYPERVISOR_event_channel_op(&op); + BUG_ON(ret); } spin_unlock_irq(&port_user_lock); diff --git a/linux-2.6-xen-sparse/drivers/xen/netback/interface.c b/linux-2.6-xen-sparse/drivers/xen/netback/interface.c index 404eb98831..7cfd3c944c 100644 --- a/linux-2.6-xen-sparse/drivers/xen/netback/interface.c +++ b/linux-2.6-xen-sparse/drivers/xen/netback/interface.c @@ -115,6 +115,7 @@ static int map_frontend_pages( netif_t *netif, grant_ref_t tx_ring_ref, grant_ref_t rx_ring_ref) { struct gnttab_map_grant_ref op; + int ret; op.host_addr = (unsigned long)netif->comms_area->addr; op.flags = GNTMAP_host_map; @@ -122,8 +123,9 @@ static int map_frontend_pages( op.dom = netif->domid; lock_vm_area(netif->comms_area); - BUG_ON(HYPERVISOR_grant_table_op(GNTTABOP_map_grant_ref, &op, 1)); + ret = HYPERVISOR_grant_table_op(GNTTABOP_map_grant_ref, &op, 1); unlock_vm_area(netif->comms_area); + BUG_ON(ret); if (op.handle < 0) { DPRINTK(" Gnttab failure mapping tx_ring_ref!\n"); @@ -139,8 +141,9 @@ static int map_frontend_pages( op.dom = netif->domid; lock_vm_area(netif->comms_area); - BUG_ON(HYPERVISOR_grant_table_op(GNTTABOP_map_grant_ref, &op, 1)); + ret = HYPERVISOR_grant_table_op(GNTTABOP_map_grant_ref, &op, 1); unlock_vm_area(netif->comms_area); + BUG_ON(ret); if (op.handle < 0) { DPRINTK(" Gnttab failure mapping rx_ring_ref!\n"); @@ -156,22 +159,25 @@ static int map_frontend_pages( static void unmap_frontend_pages(netif_t *netif) { struct gnttab_unmap_grant_ref op; + int ret; op.host_addr = (unsigned long)netif->comms_area->addr; op.handle = netif->tx_shmem_handle; op.dev_bus_addr = 0; lock_vm_area(netif->comms_area); - BUG_ON(HYPERVISOR_grant_table_op(GNTTABOP_unmap_grant_ref, &op, 1)); + ret = HYPERVISOR_grant_table_op(GNTTABOP_unmap_grant_ref, &op, 1); unlock_vm_area(netif->comms_area); + BUG_ON(ret); op.host_addr = (unsigned long)netif->comms_area->addr + PAGE_SIZE; op.handle = netif->rx_shmem_handle; op.dev_bus_addr = 0; lock_vm_area(netif->comms_area); - BUG_ON(HYPERVISOR_grant_table_op(GNTTABOP_unmap_grant_ref, &op, 1)); + ret = HYPERVISOR_grant_table_op(GNTTABOP_unmap_grant_ref, &op, 1); unlock_vm_area(netif->comms_area); + BUG_ON(ret); } int netif_map(netif_t *netif, unsigned long tx_ring_ref, diff --git a/linux-2.6-xen-sparse/drivers/xen/netback/netback.c b/linux-2.6-xen-sparse/drivers/xen/netback/netback.c index 656ed94ded..2eee002ec6 100644 --- a/linux-2.6-xen-sparse/drivers/xen/netback/netback.c +++ b/linux-2.6-xen-sparse/drivers/xen/netback/netback.c @@ -112,9 +112,12 @@ static void free_mfn(unsigned long mfn) spin_lock_irqsave(&mfn_lock, flags); if ( alloc_index != MAX_MFN_ALLOC ) mfn_list[alloc_index++] = mfn; - else - BUG_ON(HYPERVISOR_memory_op(XENMEM_decrease_reservation, - &reservation) != 1); + else { + int ret; + ret = HYPERVISOR_memory_op(XENMEM_decrease_reservation, + &reservation); + BUG_ON(ret != 1); + } spin_unlock_irqrestore(&mfn_lock, flags); } #endif @@ -159,13 +162,15 @@ int netif_be_start_xmit(struct sk_buff *skb, struct net_device *dev) */ if (skb_shared(skb) || skb_cloned(skb) || !is_xen_skb(skb)) { int hlen = skb->data - skb->head; + int ret; struct sk_buff *nskb = dev_alloc_skb(hlen + skb->len); if ( unlikely(nskb == NULL) ) goto drop; skb_reserve(nskb, hlen); __skb_put(nskb, skb->len); - BUG_ON(skb_copy_bits(skb, -hlen, nskb->data - hlen, - skb->len + hlen)); + ret = skb_copy_bits(skb, -hlen, nskb->data - hlen, + skb->len + hlen); + BUG_ON(ret); nskb->dev = skb->dev; nskb->proto_csum_valid = skb->proto_csum_valid; dev_kfree_skb(skb); @@ -218,6 +223,7 @@ static void net_rx_action(unsigned long unused) struct sk_buff *skb; u16 notify_list[NETIF_RX_RING_SIZE]; int notify_nr = 0; + int ret; skb_queue_head_init(&rxq); @@ -279,7 +285,8 @@ static void net_rx_action(unsigned long unused) mcl++; mcl[-2].args[MULTI_UVMFLAGS_INDEX] = UVMF_TLB_FLUSH|UVMF_ALL; - BUG_ON(HYPERVISOR_multicall(rx_mcl, mcl - rx_mcl) != 0); + ret = HYPERVISOR_multicall(rx_mcl, mcl - rx_mcl); + BUG_ON(ret != 0); mcl = rx_mcl; if( HYPERVISOR_grant_table_op(GNTTABOP_transfer, grant_rx_op, @@ -421,6 +428,7 @@ inline static void net_tx_action_dealloc(void) u16 pending_idx; PEND_RING_IDX dc, dp; netif_t *netif; + int ret; dc = dealloc_cons; dp = dealloc_prod; @@ -436,8 +444,9 @@ inline static void net_tx_action_dealloc(void) gop->handle = grant_tx_ref[pending_idx]; gop++; } - BUG_ON(HYPERVISOR_grant_table_op( - GNTTABOP_unmap_grant_ref, tx_unmap_ops, gop - tx_unmap_ops)); + ret = HYPERVISOR_grant_table_op( + GNTTABOP_unmap_grant_ref, tx_unmap_ops, gop - tx_unmap_ops); + BUG_ON(ret); while (dealloc_cons != dp) { pending_idx = dealloc_ring[MASK_PEND_IDX(dealloc_cons++)]; @@ -477,6 +486,7 @@ static void net_tx_action(unsigned long unused) NETIF_RING_IDX i; gnttab_map_grant_ref_t *mop; unsigned int data_len; + int ret; if (dealloc_cons != dealloc_prod) net_tx_action_dealloc(); @@ -599,8 +609,9 @@ static void net_tx_action(unsigned long unused) if (mop == tx_map_ops) return; - BUG_ON(HYPERVISOR_grant_table_op( - GNTTABOP_map_grant_ref, tx_map_ops, mop - tx_map_ops)); + ret = HYPERVISOR_grant_table_op( + GNTTABOP_map_grant_ref, tx_map_ops, mop - tx_map_ops); + BUG_ON(ret); mop = tx_map_ops; while ((skb = __skb_dequeue(&tx_queue)) != NULL) { diff --git a/linux-2.6-xen-sparse/drivers/xen/tpmback/interface.c b/linux-2.6-xen-sparse/drivers/xen/tpmback/interface.c index 98db181306..6dc05d217b 100644 --- a/linux-2.6-xen-sparse/drivers/xen/tpmback/interface.c +++ b/linux-2.6-xen-sparse/drivers/xen/tpmback/interface.c @@ -78,6 +78,7 @@ tpmif_find(domid_t domid, long int instance) static int map_frontend_page(tpmif_t *tpmif, unsigned long shared_page) { + int ret; struct gnttab_map_grant_ref op = { .host_addr = (unsigned long)tpmif->tx_area->addr, .flags = GNTMAP_host_map, @@ -86,8 +87,9 @@ map_frontend_page(tpmif_t *tpmif, unsigned long shared_page) }; lock_vm_area(tpmif->tx_area); - BUG_ON(HYPERVISOR_grant_table_op(GNTTABOP_map_grant_ref, &op, 1)); + ret = HYPERVISOR_grant_table_op(GNTTABOP_map_grant_ref, &op, 1); unlock_vm_area(tpmif->tx_area); + BUG_ON(ret); if (op.handle < 0) { DPRINTK(" Grant table operation failure !\n"); @@ -104,14 +106,16 @@ static void unmap_frontend_page(tpmif_t *tpmif) { struct gnttab_unmap_grant_ref op; + int ret; op.host_addr = (unsigned long)tpmif->tx_area->addr; op.handle = tpmif->shmem_handle; op.dev_bus_addr = 0; lock_vm_area(tpmif->tx_area); - BUG_ON(HYPERVISOR_grant_table_op(GNTTABOP_unmap_grant_ref, &op, 1)); + ret = HYPERVISOR_grant_table_op(GNTTABOP_unmap_grant_ref, &op, 1); unlock_vm_area(tpmif->tx_area); + BUG_ON(ret); } int diff --git a/linux-2.6-xen-sparse/drivers/xen/util.c b/linux-2.6-xen-sparse/drivers/xen/util.c index 8df067f29e..be2b155cf1 100644 --- a/linux-2.6-xen-sparse/drivers/xen/util.c +++ b/linux-2.6-xen-sparse/drivers/xen/util.c @@ -34,7 +34,9 @@ struct vm_struct *alloc_vm_area(unsigned long size) void free_vm_area(struct vm_struct *area) { - BUG_ON(remove_vm_area(area->addr) != area); + struct vm_struct *ret; + ret = remove_vm_area(area->addr); + BUG_ON(ret != area); kfree(area); } diff --git a/linux-2.6-xen-sparse/drivers/xen/xenbus/xenbus_probe.c b/linux-2.6-xen-sparse/drivers/xen/xenbus/xenbus_probe.c index e5c9de1139..c3d349b385 100644 --- a/linux-2.6-xen-sparse/drivers/xen/xenbus/xenbus_probe.c +++ b/linux-2.6-xen-sparse/drivers/xen/xenbus/xenbus_probe.c @@ -737,6 +737,7 @@ static int __init xenbus_probe_init(void) unsigned long page; evtchn_op_t op = { 0 }; + int ret; /* Allocate page. */ @@ -757,7 +758,8 @@ static int __init xenbus_probe_init(void) op.u.alloc_unbound.dom = DOMID_SELF; op.u.alloc_unbound.remote_dom = 0; - BUG_ON(HYPERVISOR_event_channel_op(&op)); + ret = HYPERVISOR_event_channel_op(&op); + BUG_ON(ret); xen_start_info->store_evtchn = op.u.alloc_unbound.port; /* And finally publish the above info in /proc/xen */ From 9485da60b740e61f97167db212bf4344cc61a45d Mon Sep 17 00:00:00 2001 From: "kaf24@firebug.cl.cam.ac.uk" Date: Thu, 27 Oct 2005 17:16:12 +0100 Subject: [PATCH 20/34] Use standard int typedefs. Signed-off-by: John Levon --- tools/libxc/xc_elf.h | 22 +++++++++++----------- 1 file changed, 11 insertions(+), 11 deletions(-) diff --git a/tools/libxc/xc_elf.h b/tools/libxc/xc_elf.h index e0d0c26131..da5e7b3bc8 100644 --- a/tools/libxc/xc_elf.h +++ b/tools/libxc/xc_elf.h @@ -24,26 +24,26 @@ * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ -typedef u_int8_t Elf_Byte; +typedef uint8_t Elf_Byte; -typedef u_int32_t Elf32_Addr; /* Unsigned program address */ -typedef u_int32_t Elf32_Off; /* Unsigned file offset */ +typedef uint32_t Elf32_Addr; /* Unsigned program address */ +typedef uint32_t Elf32_Off; /* Unsigned file offset */ typedef int32_t Elf32_Sword; /* Signed large integer */ -typedef u_int32_t Elf32_Word; /* Unsigned large integer */ -typedef u_int16_t Elf32_Half; /* Unsigned medium integer */ +typedef uint32_t Elf32_Word; /* Unsigned large integer */ +typedef uint16_t Elf32_Half; /* Unsigned medium integer */ -typedef u_int64_t Elf64_Addr; -typedef u_int64_t Elf64_Off; +typedef uint64_t Elf64_Addr; +typedef uint64_t Elf64_Off; typedef int32_t Elf64_Shalf; typedef int32_t Elf64_Sword; -typedef u_int32_t Elf64_Word; +typedef uint32_t Elf64_Word; typedef int64_t Elf64_Sxword; -typedef u_int64_t Elf64_Xword; +typedef uint64_t Elf64_Xword; -typedef u_int32_t Elf64_Half; -typedef u_int16_t Elf64_Quarter; +typedef uint32_t Elf64_Half; +typedef uint16_t Elf64_Quarter; /* * e_ident[] identification indexes From ce57ab29ffbb14413dc6add66ef5955ab108532b Mon Sep 17 00:00:00 2001 From: "kaf24@firebug.cl.cam.ac.uk" Date: Thu, 27 Oct 2005 17:16:48 +0100 Subject: [PATCH 21/34] Remove a non-portable and unused error.h, and use signal.h not sys/signal.h (in tools/misc). --- tools/misc/cpuperf/cpuperf.c | 1 - tools/misc/miniterm/miniterm.c | 2 +- 2 files changed, 1 insertion(+), 2 deletions(-) diff --git a/tools/misc/cpuperf/cpuperf.c b/tools/misc/cpuperf/cpuperf.c index 999c04891a..5047780532 100644 --- a/tools/misc/cpuperf/cpuperf.c +++ b/tools/misc/cpuperf/cpuperf.c @@ -16,7 +16,6 @@ #include #include -#include #include #include #include diff --git a/tools/misc/miniterm/miniterm.c b/tools/misc/miniterm/miniterm.c index 0dc4143b4e..92f8462781 100644 --- a/tools/misc/miniterm/miniterm.c +++ b/tools/misc/miniterm/miniterm.c @@ -29,7 +29,7 @@ #include #include #include -#include +#include #include #include From 41ae27972e997eee406be536e15956fe1d9f56b0 Mon Sep 17 00:00:00 2001 From: "kaf24@firebug.cl.cam.ac.uk" Date: Thu, 27 Oct 2005 17:20:33 +0100 Subject: [PATCH 22/34] Remove all binaries on make clean. --- tools/xenstore/Makefile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tools/xenstore/Makefile b/tools/xenstore/Makefile index 32194309d1..6fc3992d21 100644 --- a/tools/xenstore/Makefile +++ b/tools/xenstore/Makefile @@ -77,7 +77,7 @@ libxenstore.so: xs.opic xs_lib.opic clean: testsuite-clean rm -f *.o *.opic *.so rm -f xenstored xs_random xs_stress xs_crashme - rm -f xs_test xenstored_test + rm -f xs_test xenstored_test xs_tdb_dump $(RM) $(PROG_DEP) print-dir: From 2b41ca6037ed6642e61c5d05e94e8646d257289a Mon Sep 17 00:00:00 2001 From: "kaf24@firebug.cl.cam.ac.uk" Date: Thu, 27 Oct 2005 17:24:06 +0100 Subject: [PATCH 23/34] This patch * adapts the Xen access control module to recent changes in the "unbound event channel" interface and its usage * adds checks that became necessary because of domain structures "hanging around" in the domain list after domain destruction This patch is tested on today's xen-unstable with Null, CHWALL, STE, CHWALL_STE policies. Signed-off by: Reiner Sailer --- xen/acm/acm_simple_type_enforcement_hooks.c | 106 ++++++++++++-------- xen/common/acm_ops.c | 13 ++- xen/include/acm/acm_hooks.h | 50 +++++---- 3 files changed, 110 insertions(+), 59 deletions(-) diff --git a/xen/acm/acm_simple_type_enforcement_hooks.c b/xen/acm/acm_simple_type_enforcement_hooks.c index de08f46c2a..41bb1b393c 100644 --- a/xen/acm/acm_simple_type_enforcement_hooks.c +++ b/xen/acm/acm_simple_type_enforcement_hooks.c @@ -392,8 +392,11 @@ check_cache(struct domain *dom, domid_t rdom) { int i; printkd("checking cache: %x --> %x.\n", dom->domain_id, rdom); + + if (dom->ssid == NULL) + return 0; ste_ssid = GET_SSIDP(ACM_SIMPLE_TYPE_ENFORCEMENT_POLICY, - (struct acm_ssid_domain *)(dom)->ssid); + (struct acm_ssid_domain *)(dom->ssid)); for(i=0; i< ACM_TE_CACHE_SIZE; i++) { if ((ste_ssid->ste_cache[i].valid == VALID) && @@ -412,6 +415,8 @@ cache_result(struct domain *subj, struct domain *obj) { struct ste_ssid *ste_ssid; int i; printkd("caching from doms: %x --> %x.\n", subj->domain_id, obj->domain_id); + if (subj->ssid == NULL) + return; ste_ssid = GET_SSIDP(ACM_SIMPLE_TYPE_ENFORCEMENT_POLICY, (struct acm_ssid_domain *)(subj)->ssid); for(i=0; i< ACM_TE_CACHE_SIZE; i++) @@ -431,26 +436,34 @@ clean_id_from_cache(domid_t id) struct ste_ssid *ste_ssid; int i; struct domain **pd; + struct acm_ssid_domain *ssid; printkd("deleting cache for dom %x.\n", id); - read_lock(&domlist_lock); /* look through caches of all domains */ pd = &domain_list; for ( pd = &domain_list; *pd != NULL; pd = &(*pd)->next_in_list ) { - ste_ssid = GET_SSIDP(ACM_SIMPLE_TYPE_ENFORCEMENT_POLICY, - (struct acm_ssid_domain *)(*pd)->ssid); + ssid = (struct acm_ssid_domain *)((*pd)->ssid); + + if (ssid == NULL) + continue; /* hanging domain structure, no ssid any more ... */ + ste_ssid = GET_SSIDP(ACM_SIMPLE_TYPE_ENFORCEMENT_POLICY, ssid); + if (!ste_ssid) { + printk("%s: deleting ID from cache ERROR (no ste_ssid)!\n", + __func__); + goto out; + } for (i=0; iste_cache[i].valid == VALID) && - (ste_ssid->ste_cache[i].id = id)) + (ste_ssid->ste_cache[i].id == id)) ste_ssid->ste_cache[i].valid = FREE; } + out: read_unlock(&domlist_lock); } /*************************** * Authorization functions **************************/ - static int ste_pre_domain_create(void *subject_ssid, ssidref_t ssidref) { @@ -484,44 +497,13 @@ ste_post_domain_destroy(void *subject_ssid, domid_t id) /* -------- EVENTCHANNEL OPERATIONS -----------*/ static int -ste_pre_eventchannel_unbound(domid_t id) { - struct domain *subj, *obj; - int ret; - traceprintk("%s: dom%x-->dom%x.\n", - __func__, current->domain->domain_id, id); - - if (check_cache(current->domain, id)) { - atomic_inc(&ste_bin_pol.ec_cachehit_count); - return ACM_ACCESS_PERMITTED; - } - atomic_inc(&ste_bin_pol.ec_eval_count); - subj = current->domain; - obj = find_domain_by_id(id); - - if (share_common_type(subj, obj)) { - cache_result(subj, obj); - ret = ACM_ACCESS_PERMITTED; - } else { - atomic_inc(&ste_bin_pol.ec_denied_count); - ret = ACM_ACCESS_DENIED; - } - if (obj != NULL) - put_domain(obj); - return ret; -} - -static int -ste_pre_eventchannel_interdomain(domid_t id1, domid_t id2) -{ +ste_pre_eventchannel_unbound(domid_t id1, domid_t id2) { struct domain *subj, *obj; int ret; traceprintk("%s: dom%x-->dom%x.\n", __func__, (id1 == DOMID_SELF) ? current->domain->domain_id : id1, (id2 == DOMID_SELF) ? current->domain->domain_id : id2); - /* following is a bit longer but ensures that we - * "put" only domains that we where "find"-ing - */ if (id1 == DOMID_SELF) id1 = current->domain->domain_id; if (id2 == DOMID_SELF) id2 = current->domain->domain_id; @@ -531,7 +513,7 @@ ste_pre_eventchannel_interdomain(domid_t id1, domid_t id2) ret = ACM_ACCESS_DENIED; goto out; } - /* cache check late, but evtchn is not on performance critical path */ + /* cache check late */ if (check_cache(subj, obj->domain_id)) { atomic_inc(&ste_bin_pol.ec_cachehit_count); ret = ACM_ACCESS_PERMITTED; @@ -546,7 +528,7 @@ ste_pre_eventchannel_interdomain(domid_t id1, domid_t id2) atomic_inc(&ste_bin_pol.ec_denied_count); ret = ACM_ACCESS_DENIED; } - out: + out: if (obj != NULL) put_domain(obj); if (subj != NULL) @@ -554,6 +536,50 @@ ste_pre_eventchannel_interdomain(domid_t id1, domid_t id2) return ret; } +static int +ste_pre_eventchannel_interdomain(domid_t id) +{ + struct domain *subj=NULL, *obj=NULL; + int ret; + + traceprintk("%s: dom%x-->dom%x.\n", __func__, + current->domain->domain_id, + (id == DOMID_SELF) ? current->domain->domain_id : id); + + /* following is a bit longer but ensures that we + * "put" only domains that we where "find"-ing + */ + if (id == DOMID_SELF) id = current->domain->domain_id; + + subj = current->domain; + obj = find_domain_by_id(id); + if (obj == NULL) { + ret = ACM_ACCESS_DENIED; + goto out; + } + + /* cache check late, but evtchn is not on performance critical path */ + if (check_cache(subj, obj->domain_id)) { + atomic_inc(&ste_bin_pol.ec_cachehit_count); + ret = ACM_ACCESS_PERMITTED; + goto out; + } + + atomic_inc(&ste_bin_pol.ec_eval_count); + + if (share_common_type(subj, obj)) { + cache_result(subj, obj); + ret = ACM_ACCESS_PERMITTED; + } else { + atomic_inc(&ste_bin_pol.ec_denied_count); + ret = ACM_ACCESS_DENIED; + } + out: + if (obj != NULL) + put_domain(obj); + return ret; +} + /* -------- SHARED MEMORY OPERATIONS -----------*/ static int diff --git a/xen/common/acm_ops.c b/xen/common/acm_ops.c index 4f0d46c3e5..d290b40de6 100644 --- a/xen/common/acm_ops.c +++ b/xen/common/acm_ops.c @@ -133,7 +133,10 @@ long do_acm_op(struct acm_op * u_acm_op) struct domain *subj = find_domain_by_id(op->u.getssid.id.domainid); if (!subj) return -ESRCH; /* domain not found */ - + if (subj->ssid == NULL) { + put_domain(subj); + return -ESRCH; + } ssidref = ((struct acm_ssid_domain *)(subj->ssid))->ssidref; put_domain(subj); } else @@ -167,6 +170,10 @@ long do_acm_op(struct acm_op * u_acm_op) ret = -ESRCH; /* domain not found */ goto out; } + if (subj->ssid == NULL) { + put_domain(subj); + ret = -ESRCH; + } ssidref1 = ((struct acm_ssid_domain *)(subj->ssid))->ssidref; put_domain(subj); } else { @@ -182,6 +189,10 @@ long do_acm_op(struct acm_op * u_acm_op) ret = -ESRCH; /* domain not found */ goto out; } + if (subj->ssid == NULL) { + put_domain(subj); + return -ESRCH; + } ssidref2 = ((struct acm_ssid_domain *)(subj->ssid))->ssidref; put_domain(subj); } else { diff --git a/xen/include/acm/acm_hooks.h b/xen/include/acm/acm_hooks.h index a79acf2952..011669373d 100644 --- a/xen/include/acm/acm_hooks.h +++ b/xen/include/acm/acm_hooks.h @@ -100,10 +100,10 @@ struct acm_operations { void (*fail_domain_create) (void *subject_ssid, ssidref_t ssidref); void (*post_domain_destroy) (void *object_ssid, domid_t id); /* event channel control hooks (can be NULL) */ - int (*pre_eventchannel_unbound) (domid_t id); - void (*fail_eventchannel_unbound) (domid_t id); - int (*pre_eventchannel_interdomain) (domid_t id1, domid_t id2); - int (*fail_eventchannel_interdomain) (domid_t id1, domid_t id2); + int (*pre_eventchannel_unbound) (domid_t id1, domid_t id2); + void (*fail_eventchannel_unbound) (domid_t id1, domid_t id2); + int (*pre_eventchannel_interdomain) (domid_t id); + void (*fail_eventchannel_interdomain) (domid_t id); /* grant table control hooks (can be NULL) */ int (*pre_grant_map_ref) (domid_t id); void (*fail_grant_map_ref) (domid_t id); @@ -193,31 +193,31 @@ static inline void acm_post_domain_destroy(void *object_ssid, domid_t id) return; } -static inline int acm_pre_eventchannel_unbound(domid_t id) +static inline int acm_pre_eventchannel_unbound(domid_t id1, domid_t id2) { if ((acm_primary_ops->pre_eventchannel_unbound != NULL) && - acm_primary_ops->pre_eventchannel_unbound(id)) + acm_primary_ops->pre_eventchannel_unbound(id1, id2)) return ACM_ACCESS_DENIED; else if ((acm_secondary_ops->pre_eventchannel_unbound != NULL) && - acm_secondary_ops->pre_eventchannel_unbound(id)) { + acm_secondary_ops->pre_eventchannel_unbound(id1, id2)) { /* roll-back primary */ if (acm_primary_ops->fail_eventchannel_unbound != NULL) - acm_primary_ops->fail_eventchannel_unbound(id); + acm_primary_ops->fail_eventchannel_unbound(id1, id2); return ACM_ACCESS_DENIED; } else return ACM_ACCESS_PERMITTED; } -static inline int acm_pre_eventchannel_interdomain(domid_t id1, domid_t id2) +static inline int acm_pre_eventchannel_interdomain(domid_t id) { if ((acm_primary_ops->pre_eventchannel_interdomain != NULL) && - acm_primary_ops->pre_eventchannel_interdomain(id1, id2)) + acm_primary_ops->pre_eventchannel_interdomain(id)) return ACM_ACCESS_DENIED; else if ((acm_secondary_ops->pre_eventchannel_interdomain != NULL) && - acm_secondary_ops->pre_eventchannel_interdomain(id1, id2)) { + acm_secondary_ops->pre_eventchannel_interdomain(id)) { /* roll-back primary */ if (acm_primary_ops->fail_eventchannel_interdomain != NULL) - acm_primary_ops->fail_eventchannel_interdomain(id1, id2); + acm_primary_ops->fail_eventchannel_interdomain(id); return ACM_ACCESS_DENIED; } else return ACM_ACCESS_PERMITTED; @@ -234,10 +234,22 @@ static inline int acm_pre_dom0_op(dom0_op_t *op, void **ssid) current->domain->ssid, op->u.createdomain.ssidref); break; case DOM0_DESTROYDOMAIN: + if (*ssid != NULL) { + printkd("%s: Warning. Overlapping destruction.\n", + __func__); + return -EACCES; + } d = find_domain_by_id(op->u.destroydomain.domain); if (d != NULL) { *ssid = d->ssid; /* save for post destroy when d is gone */ - /* no policy-specific hook */ + if (*ssid == NULL) { + printk("%s: Warning. Destroying domain without ssid pointer.\n", + __func__); + put_domain(d); + return -EACCES; + } + d->ssid = NULL; /* make sure it's not used any more */ + /* no policy-specific hook */ put_domain(d); ret = 0; } @@ -248,7 +260,7 @@ static inline int acm_pre_dom0_op(dom0_op_t *op, void **ssid) return ret; } -static inline void acm_post_dom0_op(dom0_op_t *op, void *ssid) +static inline void acm_post_dom0_op(dom0_op_t *op, void **ssid) { switch(op->cmd) { case DOM0_CREATEDOMAIN: @@ -261,7 +273,8 @@ static inline void acm_post_dom0_op(dom0_op_t *op, void *ssid) case DOM0_DESTROYDOMAIN: acm_post_domain_destroy(ssid, op->u.destroydomain.domain); /* free security ssid for the destroyed domain (also if null policy */ - acm_free_domain_ssid((struct acm_ssid_domain *)ssid); + acm_free_domain_ssid((struct acm_ssid_domain *)(*ssid)); + *ssid = NULL; break; } } @@ -282,12 +295,13 @@ static inline int acm_pre_event_channel(evtchn_op_t *op) switch(op->cmd) { case EVTCHNOP_alloc_unbound: - ret = acm_pre_eventchannel_unbound(op->u.alloc_unbound.dom); + ret = acm_pre_eventchannel_unbound( + op->u.alloc_unbound.dom, + op->u.alloc_unbound.remote_dom); break; case EVTCHNOP_bind_interdomain: ret = acm_pre_eventchannel_interdomain( - current->domain->domain_id, - op->u.bind_interdomain.remote_dom); + op->u.bind_interdomain.remote_dom); break; default: ret = 0; /* ok */ From a7da7a4ecb25ebcf3fe7fdd9fbda4bd6bd8e04d1 Mon Sep 17 00:00:00 2001 From: "kaf24@firebug.cl.cam.ac.uk" Date: Thu, 27 Oct 2005 17:27:04 +0100 Subject: [PATCH 24/34] The attached patch fixes 2 issues with the scripts written for the Xen access control module and makes the tools more self-explanatory. Signed-off-by: Stefan Berger --- tools/security/getlabel.sh | 27 +++++++++++--------- tools/security/setlabel.sh | 40 ++++++++++++++++------------- tools/security/updategrub.sh | 49 ++++++++++++++++++++++++++++-------- 3 files changed, 76 insertions(+), 40 deletions(-) diff --git a/tools/security/getlabel.sh b/tools/security/getlabel.sh index ee1fcba199..40c5c195d5 100644 --- a/tools/security/getlabel.sh +++ b/tools/security/getlabel.sh @@ -36,18 +36,21 @@ source labelfuncs.sh usage () { - echo "Usage: $0 -sid [] or" - echo " $0 -dom [] " - echo "" - echo "policy name : the name of the policy, i.e. 'chwall'" - echo " If the policy name is omitted, the grub.conf" - echo " entry of the running system is tried to be read" - echo " and the policy name determined from there." - echo "ssidref : an ssidref in hex or decimal format, i.e., '0x00010002'" - echo " or '65538'" - echo "domid : id of the domain, i.e., '1'; Use numbers from the 2nd" - echo " column shown when invoking 'xm list'" - echo "" +echo "Use this tool to display the label of a domain or the label that is +corresponding to an ssidref given the name of the running policy. + +Usage: $0 -sid [] or + $0 -dom [] + +policy name : the name of the policy, i.e. 'chwall' + If the policy name is omitted, the grub.conf + entry of the running system is tried to be read + and the policy name determined from there. +ssidref : an ssidref in hex or decimal format, i.e., '0x00010002' + or '65538' +domid : id of the domain, i.e., '1'; Use numbers from the 2nd + column shown when invoking 'xm list' +" } diff --git a/tools/security/setlabel.sh b/tools/security/setlabel.sh index 9e0ec34482..fcc08fc4aa 100644 --- a/tools/security/setlabel.sh +++ b/tools/security/setlabel.sh @@ -39,21 +39,27 @@ source labelfuncs.sh usage () { - echo "Usage: $0 [Option]