#!/bin/bash

set -x

host=esmfgw.nac.uci.edu
case "$1" in
	stop)
		killall -v nbd-client
		killall -v nbd-client
		rmmod nbd
		;;
	start)
		#rhel 3 doesn't need a full path.  FC2 does.  The module had to be
		#compiled for both
		insmod /lib/modules/`uname -r`/kernel/drivers/block/nbd.ko
		# nb is it. nd aint.
		/usr/local/sbin/nbd-client "$host" 1070 /dev/nb0 &
		/usr/local/sbin/nbd-client "$host" 1071 /dev/nb1 &
		/usr/local/sbin/nbd-client "$host" 1072 /dev/nb2 &
		;;
	restart)
		$0 stop
		$0 start
		;;
	init)
		# don't actually run this.  It likes to create new volume groups,
		# even if the old ones are dead.  Maybe someday I'll look into how
		# to remove one.  :)
		#
		# wipe the partition table, create the uuid, 
		for i in `seq 0 2`
		do
			dd if=/dev/zero of=/dev/nb$i bs=1024 count=1
			sleep 1
			pvcreate /dev/nb$i
			sleep 1
		done
		vgcreate test_vg2 /dev/nb0 /dev/nb1 /dev/nb2
		sleep 1
		lvcreate -i 3 -I 8 -L 2.7T test_vg2
		sleep 1
		ls -l /dev/test_vg2/lvol0
		lvdisplay /dev/test_vg2/lvol0
		;;
	test)
		#mount /dev/test_vg2/lvol0 /mnt/big
		set +x
		for i in `seq 1 260`; \
		do echo; echo $i; \
			(cd / && tar cflS - .) | \
			reblock -t 65536 120 | \
			(cd /mnt/big && mkdir $i && cd $i && tar xfp -); \
		done
		;;
esac

