resize_test.sh revision 293436
1293436Sngie#!/bin/sh 2212934Sbrian# $FreeBSD: head/tools/regression/geom_eli/resize.t 293436 2016-01-08 19:38:59Z ngie $ 3212934Sbrian 4293436Sngie. $(dirname $0)/conf.sh 5293436Sngie 6212934Sbrianecho 1..27 7212934Sbrian 8212934SbrianBLK=512 9212934SbrianBLKS_PER_MB=2048 10212934Sbrian 11212934Sbrianmd=$(mdconfig -s40m) || exit 1 12212934Sbrianunit=${md#md} 13212934Sbriani=1 14212934Sbrian 15212934Sbriansetsize() { 16212934Sbrian partszMB=$1 unitszMB=$2 17212934Sbrian 18212934Sbrian { 19212934Sbrian echo a: $(($partszMB * $BLKS_PER_MB)) 0 4.2BSD 1024 8192 20212934Sbrian echo c: $(($unitszMB * $BLKS_PER_MB)) 0 unused 0 0 21212934Sbrian } | disklabel -R $md /dev/stdin 22212934Sbrian} 23212934Sbrian 24212934Sbrian# Initialise 25212934Sbrian 26212934Sbriansetsize 10 40 || echo -n "not " 27212934Sbrianecho ok $i - "Sized ${md}a to 10m" 28212934Sbriani=$((i + 1)) 29212934Sbrian 30212934Sbrianecho secret >tmp.key 31212934Sbriangeli init -Bnone -PKtmp.key ${md}a || echo -n "not " 32212934Sbrianecho ok $i - "Initialised geli on ${md}a" 33212934Sbriani=$((i + 1)) 34212934Sbriangeli attach -pk tmp.key ${md}a || echo -n "not " 35212934Sbrianecho ok $i - "Attached ${md}a as ${md}a.eli" 36212934Sbriani=$((i + 1)) 37212934Sbrian 38212934Sbriannewfs -U ${md}a.eli >/dev/null || echo -n "not " 39212934Sbrianecho ok $i - "Initialised the filesystem on ${md}a.eli" 40212934Sbriani=$((i + 1)) 41212934Sbrianout=$(fsck -tufs -y ${md}a.eli) 42212934Sbrianecho "$out" | fgrep -q MODIFIED && echo -n "not " 43212934Sbrianecho ok $i - "fsck says ${md}a.eli is clean," $(echo $(echo "$out" | wc -l)) \ 44212934Sbrian "lines of output" 45212934Sbriani=$((i + 1)) 46212934Sbrian 47212934Sbrian 48212934Sbrian# Doing a backup, resize & restore must be forced (with -f) as geli 49212934Sbrian# verifies that the provider size in the metadata matches the consumer. 50212934Sbrian 51212934Sbriangeli backup ${md}a tmp.meta || echo -n "not " 52212934Sbrianecho ok $i - "Backed up ${md}a metadata" 53212934Sbriani=$((i + 1)) 54212934Sbrian 55212934Sbriangeli detach ${md}a.eli || echo -n "not " 56212934Sbrianecho ok $i - "Detached ${md}a.eli" 57212934Sbriani=$((i + 1)) 58212934Sbrian 59212934Sbriansetsize 20 40 || echo -n "not " 60212934Sbrianecho ok $i - "Sized ${md}a to 20m" 61212934Sbriani=$((i + 1)) 62212934Sbriangeli attach -pktmp.key ${md}a && echo -n "not " 63212934Sbrianecho ok $i - "Attaching ${md}a fails after resizing the consumer" 64212934Sbriani=$((i + 1)) 65212934Sbrian 66212934Sbriangeli restore tmp.meta ${md}a && echo -n "not " 67212934Sbrianecho ok $i - "Restoring metadata on ${md}a.eli fails without -f" 68212934Sbriani=$((i + 1)) 69212934Sbriangeli restore -f tmp.meta ${md}a || echo -n "not " 70212934Sbrianecho ok $i - "Restoring metadata on ${md}a.eli can be forced" 71212934Sbriani=$((i + 1)) 72212934Sbrian 73212934Sbriangeli attach -pktmp.key ${md}a || echo -n "not " 74212934Sbrianecho ok $i - "Attaching ${md}a is now possible" 75212934Sbriani=$((i + 1)) 76212934Sbrian 77212934Sbriangrowfs -y ${md}a.eli >/dev/null || echo -n "not " 78212934Sbrianecho ok $i - "Extended the filesystem on ${md}a.eli" 79212934Sbriani=$((i + 1)) 80212934Sbrian 81212934Sbrianout=$(fsck -tufs -y ${md}a.eli) 82212934Sbrianecho "$out" | fgrep -q MODIFIED && echo -n "not " 83212934Sbrianecho ok $i - "fsck says ${md}a.eli is clean," $(echo $(echo "$out" | wc -l)) \ 84212934Sbrian "lines of output" 85212934Sbriani=$((i + 1)) 86212934Sbrian 87212934Sbrian 88212934Sbrian# Now do the resize properly 89212934Sbrian 90212934Sbriangeli detach ${md}a.eli || echo -n "not " 91212934Sbrianecho ok $i - "Detached ${md}a.eli" 92212934Sbriani=$((i + 1)) 93212934Sbrian 94212934Sbriansetsize 30 40 || echo -n "not " 95212934Sbrianecho ok $i - "Sized ${md}a to 30m" 96212934Sbriani=$((i + 1)) 97212934Sbrian 98212934Sbriangeli resize -s20m ${md}a || echo -n "not " 99212934Sbrianecho ok $i - "Resizing works ok" 100212934Sbriani=$((i + 1)) 101212934Sbriangeli resize -s20m ${md}a && echo -n "not " 102212934Sbrianecho ok $i - "Resizing doesn't work a 2nd time (no old metadata)" 103212934Sbriani=$((i + 1)) 104212934Sbrian 105212934Sbriangeli attach -pktmp.key ${md}a || echo -n "not " 106212934Sbrianecho ok $i - "Attaching ${md}a works ok" 107212934Sbriani=$((i + 1)) 108212934Sbrian 109212934Sbriangrowfs -y ${md}a.eli >/dev/null || echo -n "not " 110212934Sbrianecho ok $i - "Extended the filesystem on ${md}a.eli" 111212934Sbriani=$((i + 1)) 112212934Sbrian 113212934Sbrianout=$(fsck -tufs -y ${md}a.eli) 114212934Sbrianecho "$out" | fgrep -q MODIFIED && echo -n "not " 115212934Sbrianecho ok $i - "fsck says ${md}a.eli is clean," $(echo $(echo "$out" | wc -l)) \ 116212934Sbrian "lines of output" 117212934Sbriani=$((i + 1)) 118212934Sbrian 119212934Sbriangeli detach ${md}a.eli 120226729Spjdgpart destroy -F $md >/dev/null 121212934Sbrian 122212934Sbrian 123212934Sbrian# Verify that the man page example works, changing ada0 to $md, 124212934Sbrian# 1g to 20m, 2g to 30m and keyfile to tmp.key, and adding -B none 125212934Sbrian# to geli init. 126212934Sbrian 127213167Spjdgpart create -s GPT $md || echo -n "not " 128213231Spjdecho ok $i - "Installed a GPT on ${md}" 129212934Sbriani=$((i + 1)) 130212934Sbriangpart add -s 20m -t freebsd-ufs -i 1 $md || echo -n "not " 131212934Sbrianecho ok $i - "Added a 20m partition in slot 1" 132212934Sbriani=$((i + 1)) 133212934Sbriangeli init -B none -K tmp.key -P ${md}p1 || echo -n "not " 134212934Sbrianecho ok $i - "Initialised geli on ${md}p1" 135212934Sbriani=$((i + 1)) 136212934Sbriangpart resize -s 30m -i 1 $md || echo -n "not " 137212934Sbrianecho ok $i - "Resized partition ${md}p1 to 30m" 138212934Sbriani=$((i + 1)) 139212934Sbriangeli resize -s 20m ${md}p1 || echo -n "not " 140212934Sbrianecho ok $i - "Resized geli on ${md}p1 to 30m" 141212934Sbriani=$((i + 1)) 142212934Sbriangeli attach -k tmp.key -p ${md}p1 || echo -n "not " 143212934Sbrianecho ok $i - "Attached ${md}p1.eli" 144212934Sbriani=$((i + 1)) 145212934Sbrian 146212934Sbriangeli detach ${md}p1.eli 147212934Sbrian 148212934Sbrianrm tmp.* 149