resize_test.sh revision 226729
1#! /bin/sh 2# 3# $FreeBSD: head/tools/regression/geom_eli/resize.t 226729 2011-10-25 13:41:12Z pjd $ 4 5echo 1..27 6 7BLK=512 8BLKS_PER_MB=2048 9 10md=$(mdconfig -s40m) || exit 1 11unit=${md#md} 12i=1 13 14setsize() { 15 partszMB=$1 unitszMB=$2 16 17 { 18 echo a: $(($partszMB * $BLKS_PER_MB)) 0 4.2BSD 1024 8192 19 echo c: $(($unitszMB * $BLKS_PER_MB)) 0 unused 0 0 20 } | disklabel -R $md /dev/stdin 21} 22 23# Initialise 24 25kldload geom_eli >/dev/null 2>&1 26 27setsize 10 40 || echo -n "not " 28echo ok $i - "Sized ${md}a to 10m" 29i=$((i + 1)) 30 31echo secret >tmp.key 32geli init -Bnone -PKtmp.key ${md}a || echo -n "not " 33echo ok $i - "Initialised geli on ${md}a" 34i=$((i + 1)) 35geli attach -pk tmp.key ${md}a || echo -n "not " 36echo ok $i - "Attached ${md}a as ${md}a.eli" 37i=$((i + 1)) 38 39newfs -U ${md}a.eli >/dev/null || echo -n "not " 40echo ok $i - "Initialised the filesystem on ${md}a.eli" 41i=$((i + 1)) 42out=$(fsck -tufs -y ${md}a.eli) 43echo "$out" | fgrep -q MODIFIED && echo -n "not " 44echo ok $i - "fsck says ${md}a.eli is clean," $(echo $(echo "$out" | wc -l)) \ 45 "lines of output" 46i=$((i + 1)) 47 48 49# Doing a backup, resize & restore must be forced (with -f) as geli 50# verifies that the provider size in the metadata matches the consumer. 51 52geli backup ${md}a tmp.meta || echo -n "not " 53echo ok $i - "Backed up ${md}a metadata" 54i=$((i + 1)) 55 56geli detach ${md}a.eli || echo -n "not " 57echo ok $i - "Detached ${md}a.eli" 58i=$((i + 1)) 59 60setsize 20 40 || echo -n "not " 61echo ok $i - "Sized ${md}a to 20m" 62i=$((i + 1)) 63geli attach -pktmp.key ${md}a && echo -n "not " 64echo ok $i - "Attaching ${md}a fails after resizing the consumer" 65i=$((i + 1)) 66 67geli restore tmp.meta ${md}a && echo -n "not " 68echo ok $i - "Restoring metadata on ${md}a.eli fails without -f" 69i=$((i + 1)) 70geli restore -f tmp.meta ${md}a || echo -n "not " 71echo ok $i - "Restoring metadata on ${md}a.eli can be forced" 72i=$((i + 1)) 73 74geli attach -pktmp.key ${md}a || echo -n "not " 75echo ok $i - "Attaching ${md}a is now possible" 76i=$((i + 1)) 77 78growfs -y ${md}a.eli >/dev/null || echo -n "not " 79echo ok $i - "Extended the filesystem on ${md}a.eli" 80i=$((i + 1)) 81 82out=$(fsck -tufs -y ${md}a.eli) 83echo "$out" | fgrep -q MODIFIED && echo -n "not " 84echo ok $i - "fsck says ${md}a.eli is clean," $(echo $(echo "$out" | wc -l)) \ 85 "lines of output" 86i=$((i + 1)) 87 88 89# Now do the resize properly 90 91geli detach ${md}a.eli || echo -n "not " 92echo ok $i - "Detached ${md}a.eli" 93i=$((i + 1)) 94 95setsize 30 40 || echo -n "not " 96echo ok $i - "Sized ${md}a to 30m" 97i=$((i + 1)) 98 99geli resize -s20m ${md}a || echo -n "not " 100echo ok $i - "Resizing works ok" 101i=$((i + 1)) 102geli resize -s20m ${md}a && echo -n "not " 103echo ok $i - "Resizing doesn't work a 2nd time (no old metadata)" 104i=$((i + 1)) 105 106geli attach -pktmp.key ${md}a || echo -n "not " 107echo ok $i - "Attaching ${md}a works ok" 108i=$((i + 1)) 109 110growfs -y ${md}a.eli >/dev/null || echo -n "not " 111echo ok $i - "Extended the filesystem on ${md}a.eli" 112i=$((i + 1)) 113 114out=$(fsck -tufs -y ${md}a.eli) 115echo "$out" | fgrep -q MODIFIED && echo -n "not " 116echo ok $i - "fsck says ${md}a.eli is clean," $(echo $(echo "$out" | wc -l)) \ 117 "lines of output" 118i=$((i + 1)) 119 120geli detach ${md}a.eli 121gpart destroy -F $md >/dev/null 122 123 124# Verify that the man page example works, changing ada0 to $md, 125# 1g to 20m, 2g to 30m and keyfile to tmp.key, and adding -B none 126# to geli init. 127 128gpart create -s GPT $md || echo -n "not " 129echo ok $i - "Installed a GPT on ${md}" 130i=$((i + 1)) 131gpart add -s 20m -t freebsd-ufs -i 1 $md || echo -n "not " 132echo ok $i - "Added a 20m partition in slot 1" 133i=$((i + 1)) 134geli init -B none -K tmp.key -P ${md}p1 || echo -n "not " 135echo ok $i - "Initialised geli on ${md}p1" 136i=$((i + 1)) 137gpart resize -s 30m -i 1 $md || echo -n "not " 138echo ok $i - "Resized partition ${md}p1 to 30m" 139i=$((i + 1)) 140geli resize -s 20m ${md}p1 || echo -n "not " 141echo ok $i - "Resized geli on ${md}p1 to 30m" 142i=$((i + 1)) 143geli attach -k tmp.key -p ${md}p1 || echo -n "not " 144echo ok $i - "Attached ${md}p1.eli" 145i=$((i + 1)) 146 147geli detach ${md}p1.eli 148mdconfig -du$unit 149 150rm tmp.* 151