Subject: vnconfig at boot?
To: None <current-users@netbsd.org>
From: Malcolm Herbert <mjch@mjch.net>
List: current-users
Date: 05/11/2005 11:37:10
--Apple-Mail-3-29277385
Content-Transfer-Encoding: 7bit
Content-Type: text/plain;
	charset=US-ASCII;
	format=flowed

Seeing the current thread on vnd devices and vnconfig, is there any 
standard way to have vnd nodes configured at boot?  I'm in the process 
of testing NetBSD/Xen and have the guest OS running in a vnd image 
rather than a real partition because I don't have any free on this 
system ... hence I'd like to have domain0 make the virtual disk 
automatically available for when the Xen daemon fires up.

I hacked something together to do it based on the code in 
/etc/rc.d/network (from memory) which looks for a /etc/vnconfig.<dev> 
and executes it in the same manner as is done for /etc/ifconfig.<int> - 
each line in the file is used as the arguments for
ifconfig, one after the other.  Doing it this way seemed to be more 
useful than the manner done in /etc/rc.d/raidframe because vnconfig -l 
is able to list how many virtual nodes the kernel can handle which 
depends on compiled-in limits (afaict).

Attached are /etc/rc.d/vnconfig as on my 3.99.3 system and 
/etc/vnconfig.vnd0

Enjoy

PS - not sure how the OSX Mail application deals with attachments yet - 
the following may be a complete garbled mess, for which I apologise ...

-- 
Malcolm Herbert
Computer Support Officer
School of Geosciences
Monash University
ph 9905 4881


--Apple-Mail-3-29277385
Content-Transfer-Encoding: 7bit
Content-Type: application/octet-stream;
	x-unix-mode=0500;
	name="vnconfig"
Content-Disposition: attachment;
	filename=vnconfig

#!/bin/sh
#
# $NetBSD: $
#

# PROVIDE: vnconfig
# REQUIRE: mountall

$_rc_subr_loaded . /etc/rc.subr

name="vnconfig"
start_cmd="vnconfig_start"
stop_cmd="vnconfig_stop"

vnconfig_start()
{
  
	# Configure all of the virtual devices listed in $vnd_devices;
	# In the following, "xxN" stands in for device names, like "vnd0".
	# For any devices that has an $vnconfig_xxN variable associated,
	# we do "vnconfig xxN $vnconfig_xxN".
	# If there is no such variable, we take the contents of the file
	# /etc/vnconfig.xxN, and run "vnconfig xxN" repeatedly, using each
	# line of the file as the arguments for a separate "vnconfig"
	# invocation.
	#
	# In order to configure an device reasonably, you at the very least
	# need to specify the filename to make the virtual device from.
	# See the vnconfig manual page for details.
	#
	# You can put shell script fragment into /etc/vnconfig.xxN by
	# starting a line with "!".
	#
	if [ "$vnd_devices" != NO ]; then
		if checkyesno auto_vnconfig; then
			raw=$(vnconfig -l | sed -e 's/:.*//')
			for dev in $raw; do
				if [ -f /etc/vnconfig.$dev ]; then
					tmp="$tmp $dev"
				fi
			done
		else
			tmp="$vnd_devices"
		fi
		echo -n 'Configuring virtual disks devices:'
		for dev in $tmp; do
			eval args=\$vnconfig_$dev
			if [ -n "$args" ]; then
				echo -n " $dev"
				vnconfig $dev $args
			elif [ -f /etc/vnconfig.$dev ]; then
				echo -n " $dev"
				while read args; do
					[ -z "$args" ] && continue
					case "$args" in
					"#"*)
						;;
					"!"*)
						eval ${args#*!}
						;;
					*)
						vnconfig $dev $args
						;;
					esac
				done < /etc/vnconfig.$dev
			fi
		done
		echo "."
	fi
}

vnconfig_stop()
{
	if [ "$vnd_devices" != NO ]; then
		if checkyesno auto_vnconfig; then
			raw=$(vnconfig -l | sed -e 's/:.*//')
			for dev in $raw; do
				if [ -f /etc/vnconfig.$dev ]; then
					tmp="$tmp $dev"
				fi
			done
		else
			tmp="$vnd_devices"
		fi
		echo -n 'Unconfiguring virtual disks devices:'
		for dev in $tmp; do
			eval args=\$vnconfig_$dev
			echo -n " $dev"
			vnconfig -u $dev
		done
		echo "."
	fi

}

load_rc_config $name
run_rc_command "$1"

--Apple-Mail-3-29277385
Content-Transfer-Encoding: 7bit
Content-Type: text/plain;
	charset=US-ASCII;
	format=flowed



--Apple-Mail-3-29277385
Content-Transfer-Encoding: 7bit
Content-Type: application/octet-stream;
	x-unix-mode=0600;
	name="vnconfig.vnd0"
Content-Disposition: attachment;
	filename=vnconfig.vnd0

/data/xen/netbsd1.wd0

--Apple-Mail-3-29277385--