Patchwork [06/16] petitboot: Add hotplug-device test script

login
register
mail settings
Submitter Geoff Levand
Date Feb. 28, 2009, 12:53 a.m.
Message ID <20090228005350.539224491@am.sony.com>
Download mbox | patch
Permalink /patch/23851/
State Rejected
Headers show

Comments

Geoff Levand - Feb. 28, 2009, 12:53 a.m.
From: Jeremy Kerr <jk@ozlabs.org>

Add a hotplug-device test script to the test directory.

Signed-off-by: Geoff Levand <geoffrey.levand@am.sony.com>
---
 test/hotplug-device.sh |   61 +++++++++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 61 insertions(+)

Patch

--- /dev/null
+++ b/test/hotplug-device.sh
@@ -0,0 +1,61 @@ 
+#!/bin/bash
+
+
+devmapper_name=meep
+file=test.ext2
+
+if [ $# -lt 1 ]
+then
+	cat <<EOF
+usage: $0 [add [path]|remove]
+	if <path> is specified, initialise the contents of the hotplugged
+	device from the directory at <path>
+EOF
+	exit 1
+fi
+
+sudo true
+
+set -ex
+
+case "$1"
+in
+	add)
+		dd if=/dev/zero of=$file bs=1k count=640
+		mkfs.ext2 -F -m0 $file
+
+		loopdev=$(sudo losetup -f --show $loopdev $file)
+		echo loop device is $loopdev
+
+		if [ -d $2 ]
+		then
+			mkdir -p mount.tmp
+			sudo mount $loopdev mount.tmp
+			sudo rsync -av $2 mount.tmp/
+			sudo umount mount.tmp
+		fi
+
+		blocksize=$(sudo blockdev --getsize $loopdev)
+		echo block size = $blocksize
+
+		sudo dmsetup create $devmapper_name \
+			--table "0 $blocksize linear $loopdev 0"
+	;;
+	remove)
+		set +e
+		awk '/^\/dev\/mapper\/'$devmapper_name'/ {print $2}' \
+				/proc/mounts |
+		while read mountpoint
+		do
+			sudo umount $mountpoint
+		done
+		sudo dmsetup remove $devmapper_name
+
+		sudo losetup -j $file | cut -f1 -d: |
+		while read loopdev
+		do
+			sudo losetup -d $loopdev
+		done
+	;;
+
+esac