diff options
author | jlam <jlam> | 2005-11-08 00:47:35 +0000 |
---|---|---|
committer | jlam <jlam> | 2005-11-08 00:47:35 +0000 |
commit | 045e8804080ffacddc7a6ed0fe6dff4bdb9d0bcd (patch) | |
tree | e6e04de367794877e2fbe49f8f43f179c18ff6e1 /sysutils/xentools20 | |
parent | 37408d776ebc1ecf1ae5599023b3c01cf0929131 (diff) | |
download | pkgsrc-045e8804080ffacddc7a6ed0fe6dff4bdb9d0bcd.tar.gz |
* Add a MESSAGE file with helpful information for NetBSD domain0
installations.
* Modify the package to not install all of the configuration files with
the execute bit set -- only install the helper scripts that way.
* Update the block-file-nbsd script to not blindly try to configure (and
often fail to configure) every vnd(4) device until it finds one that
works. We now just determine what the next free vnd(4) device is and
configure it directly.
* Add a netbsd-nbsd script that avoids trying to do all the Linux-specific
that just filled the log files with garbage on NetBSD.
* Update the vif-bridge-nbsd script to check that the bridge device is
configured before using it.
* Add clear comments at the top of scripts that can be customized so that
the user has enough information to know how to do the customization.
* Add a xendomains rc.d script that can be used to start and stop guest
domains at system boot- or shutdown-time.
Bump the PKGREVISION to 5.
Diffstat (limited to 'sysutils/xentools20')
-rw-r--r-- | sysutils/xentools20/MESSAGE.NetBSD | 17 | ||||
-rw-r--r-- | sysutils/xentools20/Makefile | 49 | ||||
-rw-r--r-- | sysutils/xentools20/PLIST | 3 | ||||
-rw-r--r-- | sysutils/xentools20/files/block-file-nbsd | 69 | ||||
-rw-r--r-- | sysutils/xentools20/files/network-nbsd | 55 | ||||
-rw-r--r-- | sysutils/xentools20/files/vif-bridge-nbsd | 78 | ||||
-rw-r--r-- | sysutils/xentools20/files/xend.sh | 6 | ||||
-rw-r--r-- | sysutils/xentools20/files/xendomains.sh | 128 |
8 files changed, 311 insertions, 94 deletions
diff --git a/sysutils/xentools20/MESSAGE.NetBSD b/sysutils/xentools20/MESSAGE.NetBSD new file mode 100644 index 00000000000..c8a4bc4366a --- /dev/null +++ b/sysutils/xentools20/MESSAGE.NetBSD @@ -0,0 +1,17 @@ +=========================================================================== +$NetBSD: MESSAGE.NetBSD,v 1.1 2005/11/08 00:47:35 jlam Exp $ + +Please ensure that the Xen-specific devices needed by xend(8) exist: + + cd /dev && sh MAKEDEV xen + +There are example configuration files for setting up a guest domain in: + + ${EGDIR}/xmexample[0-9]* + +Please also refer to the the "NetBSD/xen How-To" for more information on +creating a Xen setup: + + http://www.netbsd.org/Ports/xen/howto.html + +=========================================================================== diff --git a/sysutils/xentools20/Makefile b/sysutils/xentools20/Makefile index f6298c0ea4f..d86162e7654 100644 --- a/sysutils/xentools20/Makefile +++ b/sysutils/xentools20/Makefile @@ -1,9 +1,9 @@ -# $NetBSD: Makefile,v 1.21 2005/10/01 02:10:10 xtraeme Exp $ +# $NetBSD: Makefile,v 1.22 2005/11/08 00:47:35 jlam Exp $ # DISTNAME= xen-2.0.7-src PKGNAME= xentools20-2.0.7 -PKGREVISION= 4 +PKGREVISION= 5 CATEGORIES= sysutils MASTER_SITES= http://www.cl.cam.ac.uk/Research/SRG/netos/xen/downloads/ EXTRACT_SUFX= .tgz @@ -24,6 +24,7 @@ CONFLICTS+= libxen-[0-9]* WRKSRC= ${WRKDIR}/xen-2.0/tools EGDIR= ${PREFIX}/share/examples/xen +MESSAGE_SUBST= EGDIR=${EGDIR} USE_TOOLS+= gmake MAKE_ENV+= EGDIR="${EGDIR}" @@ -73,45 +74,41 @@ PROCPATH= /kern PROCPATH= /proc .endif -RCD_SCRIPTS= xend +RCD_SCRIPTS= xend xendomains FILES_SUBST+= RCD_INTERPRETER=${PYTHONBIN} FILES_SUBST+= PROCPATH=${PROCPATH} FILES_SUBST+= PKG_SYSCONFDIR=${PKG_SYSCONFDIR} -INSTALLATION_DIRS= share/examples/xen - -XEND_SCRIPTS= network block-enbd vif-bridge block-file \ - xmexample1 xmexample2 xmexample3 +XEND_SCRIPTS= network block-enbd vif-bridge block-file CONF_FILES= ${EGDIR}/xend-config.sxp \ ${PKG_SYSCONFDIR}/xend-config.sxp -.for f in ${XEND_SCRIPTS} -CONF_FILES+= ${EGDIR}/${f} ${PKG_SYSCONFDIR}/${f} +.for s in ${XEND_SCRIPTS} +CONF_FILES_PERMS+= ${EGDIR}/${s} ${PKG_SYSCONFDIR}/${s} \ + ${ROOT_USER} ${ROOT_GROUP} 0755 .endfor -CONF_FILES_MODE= 0755 - pre-build: ${MKDIR} ${WRKSRC}/libxc/xen/NetBSD ${CP} ${FILESDIR}/xenio.h ${WRKSRC}/libxc/xen/NetBSD +.if ${OPSYS} == "NetBSD" +post-build: + cd ${FILESDIR}; for src in *-nbsd; do \ + dst="$${src%-nbsd}"; \ + ${SED} -e "s|@PKG_SYSCONFDIR@|${PKG_SYSCONFDIR}|g" \ + $$src > ${WRKSRC}/examples/$$dst; \ + done +.endif + post-install: - ${INSTALL_DATA} ${WRKSRC}/examples/xend-config.sxp \ - ${EGDIR}/xend-config.sxp -.if ${OPSYS} == "Linux" -. for s in ${XEND_SCRIPTS} + ${INSTALL_DATA_DIR} ${EGDIR} + for f in xend-config.sxp xmexample1 xmexample2 xmexample3; do \ + ${INSTALL_DATA} ${WRKSRC}/examples/$$f ${EGDIR}/$$f; \ + done +.for s in ${XEND_SCRIPTS} ${INSTALL_SCRIPT} ${WRKSRC}/examples/${s} ${EGDIR}/${s} -. endfor -.else -. for f in vif-bridge block-file - ${SED} -e "s|@PKG_SYSCONFDIR@|${PKG_SYSCONFDIR}|g" \ - ${FILESDIR}/${f}-nbsd > ${WRKSRC}/${f}-nbsd - ${INSTALL_SCRIPT} ${WRKSRC}/${f}-nbsd ${EGDIR}/${f} -. endfor -. for f in ${XEND_SCRIPTS:S/vif-bridge//:S/block-file//} - ${INSTALL_SCRIPT} ${WRKSRC}/examples/${f} ${EGDIR}/${f} -. endfor -.endif +.endfor .include "../../lang/python/application.mk" .include "../../lang/python/extension.mk" diff --git a/sysutils/xentools20/PLIST b/sysutils/xentools20/PLIST index 849b4308499..e3a010b977f 100644 --- a/sysutils/xentools20/PLIST +++ b/sysutils/xentools20/PLIST @@ -1,4 +1,4 @@ -@comment $NetBSD: PLIST,v 1.7 2005/08/06 17:43:14 bouyer Exp $ +@comment $NetBSD: PLIST,v 1.8 2005/11/08 00:47:35 jlam Exp $ bin/xencons bin/xenperf include/xc.h @@ -179,6 +179,7 @@ sbin/xensv sbin/xfrd sbin/xm share/examples/rc.d/xend +share/examples/rc.d/xendomains share/examples/xen/block-enbd share/examples/xen/block-file share/examples/xen/network diff --git a/sysutils/xentools20/files/block-file-nbsd b/sysutils/xentools20/files/block-file-nbsd index 65eb5630fe1..06c9fcbe067 100644 --- a/sysutils/xentools20/files/block-file-nbsd +++ b/sysutils/xentools20/files/block-file-nbsd @@ -1,34 +1,59 @@ #!/bin/sh # -# $NetBSD: block-file-nbsd,v 1.1 2005/10/01 02:10:10 xtraeme Exp $ +# $NetBSD: block-file-nbsd,v 1.2 2005/11/08 00:47:35 jlam Exp $ # -# Usage: block_file [bind file|unbind node] +# Usage: block-file bind file # -# The file argument to the bind command is the file we are to bind to a -# vnd device. We print the path to the vnd device node to stdout. +# The file argument is the path to the file to which a vnd(4) device +# will be bound. # -# The node argument to unbind is the name of the device node we are to -# unbind. +# Usage: block-file unbind node +# +# The node argument is the name of the device node to unbind. +# + +case "$1" in +bind) + FILE="$2" + + # Store the list of available vnd(4) devices in ``available_disks'', + # and mark them as ``free''. + # + list=`/bin/ls -1 /dev/vnd[0-9]*d | sed "s,/dev/vnd,,;s,d,," | sort -n` + for i in $list; do + disk="vnd$i" + available_disks="$available_disks $disk" + eval $disk=free + done + + # Mark the used vnd(4) devices as ``used''. + for disk in `sysctl hw.disknames`; do + case $disk in + vnd[0-9]*) eval $disk=used ;; + esac + done -case $1 in - bind) - for dev in /dev/vnd?d; do - if /usr/sbin/vnconfig $dev $2; then - echo $dev - exit 0 - fi - done - exit 1 + # Configure the first free vnd(4) device. + for disk in $available_disks; do + eval status=\$$disk + if [ "$status" = "free" ] && \ + vnconfig /dev/${disk}d $FILE >/dev/null; then + echo /dev/${disk}d + exit 0 + fi + done + exit 1 ;; - unbind) - /usr/sbin/vnconfig -u $2 - exit 0 +unbind) + NODE="$2" + vnconfig -u $NODE + exit 0 ;; - *) - echo 'Unknown command: ' $1 - echo 'Valid commands are: bind, unbind' - exit 1 +*) + echo "Unknown command: $1" + echo "Valid commands are: bind, unbind" + exit 1 ;; esac diff --git a/sysutils/xentools20/files/network-nbsd b/sysutils/xentools20/files/network-nbsd new file mode 100644 index 00000000000..f0197ee56b6 --- /dev/null +++ b/sysutils/xentools20/files/network-nbsd @@ -0,0 +1,55 @@ +#!/bin/sh +#============================================================================ +# $NetBSD: network-nbsd,v 1.1 2005/11/08 00:47:35 jlam Exp $ +# +# @PKG_SYSCONFDIR@/network +# +# Script for starting and stopping the network configuration for the Xen +# domains. The xend(8) daemon calls a network script when it starts, +# before any guest domains are started. The xend(8) daemon also calls +# a network script when it stops. The script name to use is defined in +# @PKG_SYSCONFDIR@/xend-config.sxp in the ``network-script'' field. +# +# Usage: network start|stop|status [var=value ...] +# +# Actions: +# start Create the network configuration for the Xen domains. +# stop Destroy the network configuration for the Xen domains. +# status Print some network-related information, e.g. ifconfig +# and routes. +# +# This script may be customized so that the "start" action creates the +# bridge device(s) to which the guest domains' vifs should connect. +# However, it is simpler to create any network devices at system startup +# via /etc/ifconfig.* scripts, e.g. if dom0 has a bge0 device and we wish +# to create a bridge0 device: +# +# /etc/ifconfig.bridge0 +# ------8<------8<------8<------8<------ +# create +# !brconfig $int add bge0 stp bge0 up +# ------>8------>8------>8------>8------ +# +#============================================================================ + +# Exit if anything goes wrong. +set -e + +# First arg is the operation. +OP=$1; shift + +# Pull variables in args into environment +for arg ; do export "${arg}" ; done + +case $OP in +start|stop|status) + # Do nothing + ;; +*) + echo 'Invalid command: ' $OP + echo 'Valid commands are: start, stop, status' + exit 1 + ;; +esac + +exit 0 diff --git a/sysutils/xentools20/files/vif-bridge-nbsd b/sysutils/xentools20/files/vif-bridge-nbsd index 4f400cbeb02..22f52f61201 100644 --- a/sysutils/xentools20/files/vif-bridge-nbsd +++ b/sysutils/xentools20/files/vif-bridge-nbsd @@ -1,47 +1,39 @@ #!/bin/sh -# -# $NetBSD: vif-bridge-nbsd,v 1.2 2005/10/01 02:38:51 xtraeme Exp $ -# #============================================================================ -# @PKG_SYSCONFDIR@/vif-bridge +# $NetBSD: vif-bridge-nbsd,v 1.3 2005/11/08 00:47:35 jlam Exp $ # -# Script for configuring a vif in bridged mode. -# Xend calls a vif script when bringing a vif up or down. -# This script is the default - but it can be configured for each vif. -# -# Example invocation: +# @PKG_SYSCONFDIR@/vif-bridge # -# vif-bridge up domain=VM1 vif=xvif1.0 bridge=bridge0 ip="128.232.38.45/28 10.10.10.55/24" +# Script for configuring a vif in bridged mode with a dom0 interface. +# The xend(8) daemon calls a vif script when bringing a vif up or down. +# The script name to use is defined in @PKG_SYSCONFDIR@/xend-config.sxp +# in the ``vif-script'' field. # +# Usage: vif-bridge up|down [var=value ...] # -# Usage: -# vif-bridge (up|down) {VAR=VAL}* +# Actions: +# up Adds the vif interface to the bridge. +# down Removes the vif interface from the bridge. # -# Vars: +# Variables: +# domain name of the domain the interface is on (required). +# vifq vif interface name (required). +# mac vif MAC address (required). +# bridge bridge to add the vif to (required). # -# domain name of the domain the interface is on (required). -# vif vif interface name (required). -# mac vif MAC address (required). -# bridge bridge to add the vif to (required). -# ip list of IP networks for the vif, space-separated (optional). +# Example invocation: # -# up: -# Enslaves the vif interface to the bridge and adds iptables rules -# for its ip addresses (if any). +# vif-bridge up domain=VM1 vif=xvif1.0 mac="ee:14:01:d0:ec:af" bridge=bridge0 # -# down: -# Removes the vif interface from the bridge and removes the iptables -# rules for its ip addresses (if any). #============================================================================ # Exit if anything goes wrong -set -e +set -e echo "vif-bridge $*" # Operation name. -OP=$1 -shift +OP=$1; shift # Pull variables in args into environment for arg ; do export "${arg}" ; done @@ -52,26 +44,30 @@ vif=${vif:?} mac=${mac:?} bridge=${bridge:?} +# Optional parameters. Set defaults. +ip=${ip:-''} # default to null (do nothing) + # Are we going up or down? case $OP in - up) - brcmd='add' - ;; - down) - brcmd='delete' - ;; - *) - echo 'Invalid command: ' $OP - echo 'Valid commands are: up, down' - exit 1 - ;; +up) brcmd='add' ;; +down) brcmd='delete' ;; +*) + echo 'Invalid command: ' $OP + echo 'Valid commands are: up, down' + exit 1 + ;; esac # Don't do anything if the bridge is "null". if [ "${bridge}" = "null" ] ; then - exit + exit +fi + +# Don't do anything if the bridge doesn't exist. +if ! ifconfig -l | grep "${bridge}" >/dev/null; then + exit fi # Add/remove vif to/from bridge. -/sbin/brconfig ${bridge} ${brcmd} x${vif} -/sbin/ifconfig x${vif} $OP +ifconfig x${vif} $OP +brconfig ${bridge} ${brcmd} x${vif} diff --git a/sysutils/xentools20/files/xend.sh b/sysutils/xentools20/files/xend.sh index 0d4b6e3619d..a2e799416bb 100644 --- a/sysutils/xentools20/files/xend.sh +++ b/sysutils/xentools20/files/xend.sh @@ -1,13 +1,11 @@ #!@RCD_SCRIPTS_SHELL@ # -# $NetBSD: xend.sh,v 1.4 2005/07/13 02:12:59 grant Exp $ +# $NetBSD: xend.sh,v 1.5 2005/11/08 00:47:35 jlam Exp $ # # PROVIDE: xend # REQUIRE: disks network -if [ -f /etc/rc.subr ]; then - . /etc/rc.subr -fi +. /etc/rc.subr name="xend" rcvar=$name diff --git a/sysutils/xentools20/files/xendomains.sh b/sysutils/xentools20/files/xendomains.sh new file mode 100644 index 00000000000..d395c4e841b --- /dev/null +++ b/sysutils/xentools20/files/xendomains.sh @@ -0,0 +1,128 @@ +#!@RCD_SCRIPTS_SHELL@ +# +# $NetBSD: xendomains.sh,v 1.1 2005/11/08 00:47:35 jlam Exp $ +# +# PROVIDE: xendomains +# REQUIRE: xend +# KEYWORD: shutdown +# +# xendomains This required variable is a whitespace-separated +# list of domains, e.g., xendomains="dom1 dom2 dom3". +# +# xendomains_config This optional variable is a format string that +# represents the path to the configuration file for +# each domain. "%s" is substituted with the name of +# the domain. The default is "@PKG_SYSCONFDIR@/%s". +# +# xendomains_prehook This optional variable is a format string that +# represents the command to run, if it exists, before +# starting each domain. "%s" is substituted with the +# name of the domain. The default is +# "@PKG_SYSCONFDIR@/%s-pre". +# +# xendomains_posthook This optional variable is a format string that +# represents the command to run, if it exists, after +# stopping each domain. "%s" is substituted with the +# name of the domain. The default is +# "@PKG_SYSCONFDIR@/%s-post". +# + +. /etc/rc.subr + +name="xendomains" +ctl_command="@PREFIX@/sbin/xm" +start_cmd="xendomains_start" +stop_cmd="xendomains_stop" +list_cmd="xendomains_list" +extra_commands="list" + +xendomains_start() +{ + [ -n "$xendomains" ] || return + + echo "Starting xen domains." + for domain in $xendomains; do + case "$domain" in + "") continue ;; + esac + + # Start off by running the pre-hook script if it's present. + if [ -n "${xendomains_prehook}" ]; then + cmdline=`printf "${xendomains_prehook}" $domain` + cmd="${cmdline%% *}" + if [ -x "$cmd" ]; then + $cmdline || echo "Pre-hook \`\`$cmdline'' failed... skipping $domain." + continue + fi + fi + + # Ask xend to create the domain. + if [ -n "${xendomains_config}" ]; then + file=`printf "${xendomains_config}" $domain` + if [ -f "$file" ]; then + ${ctl_command} create "$file" + fi + fi + done +} + +xendomains_list() { + # Output a whitespace-separated list of live guest domains. + ${ctl_command} list | awk ' + (FNR <= 2) { next } + ($5 !~ /s/) { s = s " " $1 } + END { sub(" *", "", s); print s }' +} + +xendomains_stop() +{ + # Determine an appropriate timeout waiting for all domains to + # stop -- always wait at least 60s, and add 5s per active domain. + # + numdomains=$(xendomains_list | awk '{ print NF }') + [ $numdomains -gt 0 ] || return + timeout=$((60 + numdomains * 5)) + + # Ask xend to stop every domain, and poll xend every 10s up to the + # timeout period to check if all the domains are stopped. We + # consider a domain in the "s" (shutdown) state to be stopped. + # + echo "Stopping xen domains." + for domain in $(xendomains_list); do + ${ctl_command} shutdown --halt $domain + done + while [ $timeout -gt 0 ]; do + livedomains=$(xendomains_list) + [ -n "$livedomains" ] || break + timeout=$((timeout - 10)) + sleep 10 + done + livedomains=$(xendomains_list) + if [ -n "$livedomains" ]; then + echo "Failed to stop: $livedomains" + else + echo "All domains stopped." + fi + + # Finish off by running the post-hook script if it's present. + for domain in $xendomains; do + case "$domain" in + "") continue ;; + esac + if [ -n "${xendomains_posthook}" ]; then + cmdline=`printf "${xendomains_posthook}" $domain` + cmd="${cmdline%% *}" + if [ -x "$cmd" ]; then + $cmdline || echo "Post-hook \`\`$cmdline'' failed." + fi + fi + done +} + +load_rc_config $name + +: ${xendomains_config="@PKG_SYSCONFDIR@/%s"} +: ${xendomains_prehook="@PKG_SYSCONFDIR@/%s-pre"} +: ${xendomains_posthook="@PKG_SYSCONFDIR@/%s-post"} + +run_rc_command "$1" |