Subject: Improved block-file script
To: None <port-xen@NetBSD.org>
From: Johnny C. Lam <jlam@pkgsrc.org>
List: port-xen
Date: 10/13/2005 19:54:16
--XsQoSWH+UP9D9v3l
Content-Type: text/plain; charset=us-ascii
Content-Disposition: inline

I've attached an improved block-file script that is used by xend to
create the virtual disks for file-backed guest domains.  This script
is a little friendlier to your xend log when starting large numbers
of domains, since we don't need to fail binding the first (N-1) vnode
devices before successfully binding the Nth one.

I'm also still testing various network configurations using Xen and
will post improved network-* and vif-* scripts here when I'm finished.

	Cheers,

	-- Johnny Lam <jlam@pkgsrc.org>

--XsQoSWH+UP9D9v3l
Content-Type: text/plain; charset=us-ascii
Content-Disposition: attachment; filename=block-file

#!/bin/sh
#
# $NetBSD$
#
# Usage: block-file bind file
#
#    The file argument is the path to the file to which a vnd(4) device
#    will be bound.
#
# 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''.
	#
	for dev in /dev/vnd[0-9]*d; do
		disk="${dev#/dev/}"
		disk="${disk%d}"
		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

	# 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)
	NODE="$2"
	vnconfig -u $NODE
	exit 0
	;;

*)
	echo "Unknown command: $1"
	echo "Valid commands are: bind, unbind"
	exit 1
	;;
esac

--XsQoSWH+UP9D9v3l--