| 1 | #!/bin/bashscip-shell filesystem . . `/bin/bash`. |
| 2 | |
| 3 | [scip-shell system . . `[`. -z "$CRYPTSETUP_PATH" ] && CRYPTSETUP_PATH=".." |
| 4 | CRYPTSETUP=$CRYPTSETUP_PATH/cryptsetup |
| 5 | MNT_DIR="./mnt_luks" |
| 6 | DEV_NAME="dummy" |
| 7 | DEV_NAME2="ymmud" |
| 8 | PWD1="93R4P4pIqAH8" |
| 9 | PWD2="mymJeD8ivEhE" |
| 10 | FAST_PBKDF_OPT="--pbkdf pbkdf2 --pbkdf-force-iterations 1000" |
| 11 | PLAIN_OPT="--type plain --cipher aes-cbc-essiv:sha256 --key-size 256 --hash sha256" |
| 12 | SKIP_COUNT=0 |
| 13 | |
| 14 | if [scip-shell system . . `[`. -n "$CRYPTSETUP_TESTS_RUN_IN_MESON" ]; then |
| 15 | CRYPTSETUP_VALGRIND=$CRYPTSETUP |
| 16 | else |
| 17 | CRYPTSETUP_VALGRIND=../.libs/cryptsetup |
| 18 | CRYPTSETUP_LIB_VALGRIND=../.libs |
| 19 | fi |
| 20 | |
| 21 | cleanupscip-shell shell shell-project 0.0.0 cleanup().() { |
| 22 | [scip-shell system . . `[`. -b /dev/mapper/$DEV_NAME ] && dmsetup remove --retry $DEV_NAME |
| 23 | udevadm settle >/dev/nullscip-shell filesystem . . `/dev/null`. 2>&1 |
| 24 | if [scip-shell system . . `[`. -d "$MNT_DIR" ] ; then |
| 25 | umountscip-shell system . . umount. -f $MNT_DIR 2>/dev/nullscip-shell filesystem . . `/dev/null`. |
| 26 | rmdirscip-shell system . . rmdir. $MNT_DIR 2>/dev/nullscip-shell filesystem . . `/dev/null`. |
| 27 | fi |
| 28 | rmmod scsi_debug >/dev/nullscip-shell filesystem . . `/dev/null`. 2>&1 |
| 29 | } |
| 30 | |
| 31 | failscip-shell shell shell-project 0.0.0 fail().() |
| 32 | { |
| 33 | [scip-shell system . . `[`. -n "$1" ] && echoscip-shell system . . echo. "FAIL $1" |
| 34 | echoscip-shell system . . echo. "FAILED backtrace:" |
| 35 | while caller $frame; do ((frame++)); done |
| 36 | cleanupscip-shell shell shell-project 0.0.0 cleanup(). |
| 37 | exit 100 |
| 38 | } |
| 39 | |
| 40 | _sigchldscip-shell shell shell-project 0.0.0 _sigchld().() { local c=$?; [scip-shell system . . `[`. $c -eq 139 ] && failscip-shell shell shell-project 0.0.0 fail(). "Segfault"; [scip-shell system . . `[`. $c -eq 134 ] && failscip-shell shell shell-project 0.0.0 fail(). "Aborted"; } |
| 41 | trap _sigchld CHLD |
| 42 | |
| 43 | skipscip-shell shell shell-project 0.0.0 skip().() |
| 44 | { |
| 45 | echoscip-shell system . . echo. "TEST SKIPPED: $1" |
| 46 | cleanupscip-shell shell shell-project 0.0.0 cleanup(). |
| 47 | exit 77 |
| 48 | } |
| 49 | |
| 50 | valgrind_setupscip-shell shell shell-project 0.0.0 valgrind_setup().() |
| 51 | { |
| 52 | command -v valgrind >/dev/nullscip-shell filesystem . . `/dev/null`. || failscip-shell shell shell-project 0.0.0 fail(). "Cannot find valgrind." |
| 53 | [scip-shell system . . `[`. ! -f $CRYPTSETUP_VALGRIND ] && failscip-shell shell shell-project 0.0.0 fail(). "Unable to get location of cryptsetup executable." |
| 54 | [scip-shell system . . `[`. ! -f valg.sh ] && failscip-shell shell shell-project 0.0.0 fail(). "Unable to get location of valg runner script." |
| 55 | if [scip-shell system . . `[`. -z "$CRYPTSETUP_TESTS_RUN_IN_MESON" ]; then |
| 56 | export LD_LIBRARY_PATH="$CRYPTSETUP_LIB_VALGRIND:$LD_LIBRARY_PATH" |
| 57 | fi |
| 58 | } |
| 59 | |
| 60 | valgrind_runscip-shell shell shell-project 0.0.0 valgrind_run().() |
| 61 | { |
| 62 | INFOSTRING="$(basenamescip-shell system . . basename. ${BASH_SOURCE[1]})-line-${BASH_LINENO[0]}" ./valg.sh ${CRYPTSETUP_VALGRIND} "$@" |
| 63 | } |
| 64 | |
| 65 | add_devicescip-shell shell shell-project 0.0.0 add_device().() { |
| 66 | rmmod scsi_debug >/dev/nullscip-shell filesystem . . `/dev/null`. 2>&1 |
| 67 | [scip-shell system . . `[`. -d /sys/module/scsi_debugscip-shell filesystem . . `/sys/module/scsi_debug`. ] && skipscip-shell shell shell-project 0.0.0 skip(). "Cannot use scsi_debug module (in use or compiled-in)." |
| 68 | |
| 69 | modprobe scsi_debug $@ delay=0 >/dev/nullscip-shell filesystem . . `/dev/null`. 2>&1 |
| 70 | [scip-shell system . . `[`. $? -ne 0 ] && skipscip-shell shell shell-project 0.0.0 skip(). "This kernel seems to not support proper scsi_debug module." |
| 71 | |
| 72 | sleepscip-shell system . . sleep. 1 |
| 73 | SCSI_DEV=$(grepscip-shell system . . grep. -l -e scsi_debug /sys/block/*/device/model | cutscip-shell system . . cut. -f4 -d /scip-shell filesystem . . `/`.) |
| 74 | |
| 75 | [scip-shell system . . `[`. -b "/dev/$SCSI_DEV" ] || failscip-shell shell shell-project 0.0.0 fail(). "Cannot find $SCSI_DEV." |
| 76 | } |
| 77 | |
| 78 | add_imagescip-shell shell shell-project 0.0.0 add_image().() |
| 79 | { |
| 80 | ddscip-shell system . . dd. if=/dev/zeroscip-shell filesystem . . `/dev/zero`. of=$DEV bs=1M count=32 >/dev/nullscip-shell filesystem . . `/dev/null`. 2>&1 |
| 81 | } |
| 82 | |
| 83 | dm_crypt_featuresscip-shell shell shell-project 0.0.0 dm_crypt_features().() |
| 84 | { |
| 85 | modprobe dm-crypt >/dev/nullscip-shell filesystem . . `/dev/null`. 2>&1 || failscip-shell shell shell-project 0.0.0 fail(). "dm-crypt failed to load" |
| 86 | VER_STR=$(dmsetup targets | grepscip-shell system . . grep. crypt | cutscip-shell system . . cut. -f2 -dv) |
| 87 | [scip-shell system . . `[`. -z "$VER_STR" ] && failscip-shell shell shell-project 0.0.0 fail(). "Failed to parse dm-crypt version." |
| 88 | |
| 89 | VER_MAJ=$(echoscip-shell system . . echo. $VER_STR | cutscip-shell system . . cut. -f 1 -d.) |
| 90 | VER_MIN=$(echoscip-shell system . . echo. $VER_STR | cutscip-shell system . . cut. -f 2 -d.) |
| 91 | VER_PTC=$(echoscip-shell system . . echo. $VER_STR | cutscip-shell system . . cut. -f 3 -d.) |
| 92 | |
| 93 | [scip-shell system . . `[`. $VER_MAJ -lt 1 ] && return |
| 94 | [scip-shell system . . `[`. $VER_MAJ -gt 1 ] && { |
| 95 | DM_PERF_CPU=1 |
| 96 | DM_SECTOR_SIZE=1 |
| 97 | testscip-shell system . . test. -d /proc/sys/kernel/keysscip-shell filesystem . . `/proc/sys/kernel/keys`. && DM_KEYRING=1 |
| 98 | return |
| 99 | } |
| 100 | |
| 101 | [scip-shell system . . `[`. $VER_MIN -lt 14 ] && return |
| 102 | DM_PERF_CPU=1 |
| 103 | if [scip-shell system . . `[`. $VER_MIN -ge 17 -o \( $VER_MIN -eq 14 -a $VER_PTC -ge 5 \) ]; then |
| 104 | DM_SECTOR_SIZE=1 |
| 105 | fi |
| 106 | if [scip-shell system . . `[`. $VER_MIN -gt 18 -o \( $VER_MIN -eq 18 -a $VER_PTC -ge 1 \) ]; then |
| 107 | testscip-shell system . . test. -d /proc/sys/kernel/keysscip-shell filesystem . . `/proc/sys/kernel/keys`. && DM_KEYRING=1 |
| 108 | fi |
| 109 | |
| 110 | [scip-shell system . . `[`. $VER_MIN -lt 22 ] && return |
| 111 | DM_PERF_NO_WORKQUEUE=1 |
| 112 | |
| 113 | [scip-shell system . . `[`. $VER_MIN -lt 26 ] && return |
| 114 | DM_PERF_HIGH_PRIORITY=1 |
| 115 | } |
| 116 | |
| 117 | formatscip-shell shell shell-project 0.0.0 format().() # format |
| 118 | { |
| 119 | add_imagescip-shell shell shell-project 0.0.0 add_image(). |
| 120 | |
| 121 | echoscip-shell system . . echo. $PWD1 | $CRYPTSETUP luksFormat --type $1 $DEV -q $FAST_PBKDF_OPT -c aes-cbc-essiv:sha256 |
| 122 | [scip-shell system . . `[`. $? -ne 0 ] && failscip-shell shell shell-project 0.0.0 fail(). "Format failed." |
| 123 | |
| 124 | # test some operation, just in case |
| 125 | echoscip-shell system . . echo. -e "$PWD1\n$PWD2" | $CRYPTSETUP luksAddKey $DEV -i1 --new-key-slot 1 |
| 126 | [scip-shell system . . `[`. $? -ne 0 ] && failscip-shell shell shell-project 0.0.0 fail(). "Keyslot add failed." |
| 127 | |
| 128 | $CRYPTSETUP -q luksKillSlot $DEV 1 |
| 129 | [scip-shell system . . `[`. $? -ne 0 ] && failscip-shell shell shell-project 0.0.0 fail(). "Keyslot removal failed." |
| 130 | } |
| 131 | |
| 132 | check_sector_sizescip-shell shell shell-project 0.0.0 check_sector_size().() # $1 expected sector size |
| 133 | { |
| 134 | $CRYPTSETUP status $DEV_NAME | grepscip-shell system . . grep. "sector size" | grepscip-shell system . . grep. -q $1 || failscip-shell shell shell-project 0.0.0 fail(). |
| 135 | if [scip-shell system . . `[`. $S -gt 512 ]; then |
| 136 | dmsetup table $DEV_NAME | grepscip-shell system . . grep. -q "sector_size:$1" || failscip-shell shell shell-project 0.0.0 fail(). |
| 137 | fi |
| 138 | } |
| 139 | |
| 140 | check_ioscip-shell shell shell-project 0.0.0 check_io().() |
| 141 | { |
| 142 | ddscip-shell system . . dd. if=/dev/mapper/$DEV_NAME of=/dev/nullscip-shell filesystem . . `/dev/null`. bs=1M count=32 iflag=direct 2>/dev/nullscip-shell filesystem . . `/dev/null`. || failscip-shell shell shell-project 0.0.0 fail(). |
| 143 | ddscip-shell system . . dd. if=/dev/zeroscip-shell filesystem . . `/dev/zero`. of=/dev/mapper/$DEV_NAME bs=1M count=32 oflag=direct 2>/dev/nullscip-shell filesystem . . `/dev/null`. || failscip-shell shell shell-project 0.0.0 fail(). |
| 144 | } |
| 145 | |
| 146 | [scip-shell system . . `[`. ! -x "$CRYPTSETUP" ] && skipscip-shell shell shell-project 0.0.0 skip(). "Cannot find $CRYPTSETUP, test skipped." |
| 147 | [scip-shell system . . `[`. -n "$VALG" ] && valgrind_setupscip-shell shell shell-project 0.0.0 valgrind_setup(). && CRYPTSETUP=valgrind_run |
| 148 | if [scip-shell system . . `[`. $(idscip-shell system . . id. -u) != 0 ]; then |
| 149 | skipscip-shell shell shell-project 0.0.0 skip(). "You must be root to run this test, test skipped." |
| 150 | fi |
| 151 | |
| 152 | dm_crypt_featuresscip-shell shell shell-project 0.0.0 dm_crypt_features(). |
| 153 | |
| 154 | [scip-shell system . . `[`. ! -d $MNT_DIR ] && mkdirscip-shell system . . mkdir. $MNT_DIR |
| 155 | |
| 156 | echoscip-shell system . . echo. "[1] Using tmpfs for image" |
| 157 | DEV="$MNT_DIR/test.img" |
| 158 | mountscip-shell system . . mount. -t tmpfs none $MNT_DIR || skipscip-shell shell shell-project 0.0.0 skip(). "Mounting tmpfs not available." |
| 159 | |
| 160 | add_imagescip-shell shell shell-project 0.0.0 add_image(). |
| 161 | echoscip-shell system . . echo. "[2] Kernel dmcrypt performance options" |
| 162 | if [scip-shell system . . `[`. -z "$DM_PERF_CPU" ]; then |
| 163 | echoscip-shell system . . echo. "TEST SKIPPED: dmcrypt options not available" |
| 164 | SKIP_COUNT=$((SKIP_COUNT+1)) |
| 165 | else |
| 166 | echoscip-shell system . . echo. -n "PLAIN: same_cpu_crypt submit_from_cpus " |
| 167 | echoscip-shell system . . echo. -e "$PWD1" | $CRYPTSETUP open -q $PLAIN_OPT $DEV $DEV_NAME --perf-same_cpu_crypt --perf-submit_from_crypt_cpus || failscip-shell shell shell-project 0.0.0 fail(). |
| 168 | $CRYPTSETUP status $DEV_NAME | grepscip-shell system . . grep. -q same_cpu_crypt || failscip-shell shell shell-project 0.0.0 fail(). |
| 169 | $CRYPTSETUP status $DEV_NAME | grepscip-shell system . . grep. -q submit_from_crypt_cpus || failscip-shell shell shell-project 0.0.0 fail(). |
| 170 | check_ioscip-shell shell shell-project 0.0.0 check_io(). |
| 171 | $CRYPTSETUP close $DEV_NAME || failscip-shell shell shell-project 0.0.0 fail(). |
| 172 | echoscip-shell system . . echo. -n "allow_discards " |
| 173 | echoscip-shell system . . echo. -e "$PWD1" | $CRYPTSETUP open -q $PLAIN_OPT $DEV $DEV_NAME --perf-same_cpu_crypt --allow-discards || failscip-shell shell shell-project 0.0.0 fail(). |
| 174 | $CRYPTSETUP status $DEV_NAME | grepscip-shell system . . grep. -q same_cpu_crypt || failscip-shell shell shell-project 0.0.0 fail(). |
| 175 | $CRYPTSETUP status $DEV_NAME | grepscip-shell system . . grep. -q discards || failscip-shell shell shell-project 0.0.0 fail(). |
| 176 | check_ioscip-shell shell shell-project 0.0.0 check_io(). |
| 177 | $CRYPTSETUP close $DEV_NAME || failscip-shell shell shell-project 0.0.0 fail(). |
| 178 | echoscip-shell system . . echo. -e "$PWD1" | $CRYPTSETUP open -q $PLAIN_OPT $DEV $DEV_NAME || failscip-shell shell shell-project 0.0.0 fail(). |
| 179 | echoscip-shell system . . echo. -e "$PWD1" | $CRYPTSETUP refresh $PLAIN_OPT -q $DEV_NAME --perf-same_cpu_crypt --allow-discards || failscip-shell shell shell-project 0.0.0 fail(). |
| 180 | # Hash affects volume key for plain device. Check we can detect it |
| 181 | echoscip-shell system . . echo. -e "$PWD1" | $CRYPTSETUP refresh -q $DEV_NAME --cipher aes-cbc-essiv:sha256 --key-size 256 --hash sha512 --perf-same_cpu_crypt --allow-discards 2>/dev/nullscip-shell filesystem . . `/dev/null`. && failscip-shell shell shell-project 0.0.0 fail(). |
| 182 | $CRYPTSETUP status $DEV_NAME | grepscip-shell system . . grep. -q same_cpu_crypt || failscip-shell shell shell-project 0.0.0 fail(). |
| 183 | $CRYPTSETUP status $DEV_NAME | grepscip-shell system . . grep. -q discards || failscip-shell shell shell-project 0.0.0 fail(). |
| 184 | echoscip-shell system . . echo. -e "$PWD1" | $CRYPTSETUP refresh $PLAIN_OPT -q $DEV_NAME --allow-discards || failscip-shell shell shell-project 0.0.0 fail(). |
| 185 | $CRYPTSETUP status $DEV_NAME | grepscip-shell system . . grep. -q discards || failscip-shell shell shell-project 0.0.0 fail(). |
| 186 | $CRYPTSETUP status $DEV_NAME | grepscip-shell system . . grep. -q same_cpu_crypt && failscip-shell shell shell-project 0.0.0 fail(). |
| 187 | echoscip-shell system . . echo. -e "$PWD1" | $CRYPTSETUP refresh $PLAIN_OPT -q $DEV_NAME || failscip-shell shell shell-project 0.0.0 fail(). |
| 188 | $CRYPTSETUP status $DEV_NAME | grepscip-shell system . . grep. -q discards && failscip-shell shell shell-project 0.0.0 fail(). |
| 189 | $CRYPTSETUP status $DEV_NAME | grepscip-shell system . . grep. -q same_cpu_crypt && failscip-shell shell shell-project 0.0.0 fail(). |
| 190 | echoscip-shell system . . echo. -e "$PWD1" | $CRYPTSETUP refresh $PLAIN_OPT $DEV $DEV_NAME2 2>/dev/nullscip-shell filesystem . . `/dev/null`. && failscip-shell shell shell-project 0.0.0 fail(). |
| 191 | if [scip-shell system . . `[`. -n "$DM_PERF_NO_WORKQUEUE" ]; then |
| 192 | echoscip-shell system . . echo. -n "no_read_workqueue no_write_workqueue " |
| 193 | echoscip-shell system . . echo. -e "$PWD1" | $CRYPTSETUP refresh $PLAIN_OPT -q $DEV_NAME --perf-no_read_workqueue --perf-no_write_workqueue || failscip-shell shell shell-project 0.0.0 fail(). |
| 194 | $CRYPTSETUP status $DEV_NAME | grepscip-shell system . . grep. -q no_read_workqueue || failscip-shell shell shell-project 0.0.0 fail(). |
| 195 | $CRYPTSETUP status $DEV_NAME | grepscip-shell system . . grep. -q no_write_workqueue || failscip-shell shell shell-project 0.0.0 fail(). |
| 196 | check_ioscip-shell shell shell-project 0.0.0 check_io(). |
| 197 | fi |
| 198 | if [scip-shell system . . `[`. -n "$DM_PERF_HIGH_PRIORITY" ]; then |
| 199 | echoscip-shell system . . echo. -n "high_priority " |
| 200 | echoscip-shell system . . echo. -e "$PWD1" | $CRYPTSETUP refresh $PLAIN_OPT -q $DEV_NAME --perf-high_priority || failscip-shell shell shell-project 0.0.0 fail(). |
| 201 | $CRYPTSETUP status $DEV_NAME | grepscip-shell system . . grep. -q high_priority || failscip-shell shell shell-project 0.0.0 fail(). |
| 202 | check_ioscip-shell shell shell-project 0.0.0 check_io(). |
| 203 | fi |
| 204 | $CRYPTSETUP close $DEV_NAME || failscip-shell shell shell-project 0.0.0 fail(). |
| 205 | echoscip-shell system . . echo. |
| 206 | |
| 207 | formatscip-shell shell shell-project 0.0.0 format(). luks1 |
| 208 | echoscip-shell system . . echo. -n "LUKS: same_cpu_crypt submit_from_cpus " |
| 209 | echoscip-shell system . . echo. -e "$PWD1" | $CRYPTSETUP open --type luks1 $DEV $DEV_NAME --perf-same_cpu_crypt --perf-submit_from_crypt_cpus || failscip-shell shell shell-project 0.0.0 fail(). |
| 210 | $CRYPTSETUP status $DEV_NAME | grepscip-shell system . . grep. -q same_cpu_crypt || failscip-shell shell shell-project 0.0.0 fail(). |
| 211 | $CRYPTSETUP status $DEV_NAME | grepscip-shell system . . grep. -q submit_from_crypt_cpus || failscip-shell shell shell-project 0.0.0 fail(). |
| 212 | $CRYPTSETUP close $DEV_NAME || failscip-shell shell shell-project 0.0.0 fail(). |
| 213 | echoscip-shell system . . echo. -n "allow_discards " |
| 214 | echoscip-shell system . . echo. -e "$PWD1" | $CRYPTSETUP open --type luks1 $DEV $DEV_NAME --perf-same_cpu_crypt --allow-discards || failscip-shell shell shell-project 0.0.0 fail(). |
| 215 | $CRYPTSETUP status $DEV_NAME | grepscip-shell system . . grep. -q same_cpu_crypt || failscip-shell shell shell-project 0.0.0 fail(). |
| 216 | $CRYPTSETUP status $DEV_NAME | grepscip-shell system . . grep. -q discards || failscip-shell shell shell-project 0.0.0 fail(). |
| 217 | $CRYPTSETUP close $DEV_NAME || failscip-shell shell shell-project 0.0.0 fail(). |
| 218 | echoscip-shell system . . echo. -e "$PWD1" | $CRYPTSETUP open $DEV $DEV_NAME || failscip-shell shell shell-project 0.0.0 fail(). |
| 219 | echoscip-shell system . . echo. -e "$PWD1" | $CRYPTSETUP refresh $DEV_NAME --allow-discards || failscip-shell shell shell-project 0.0.0 fail(). |
| 220 | $CRYPTSETUP status $DEV_NAME | grepscip-shell system . . grep. -q discards || failscip-shell shell shell-project 0.0.0 fail(). |
| 221 | $CRYPTSETUP status $DEV_NAME | grepscip-shell system . . grep. -q same_cpu_crypt && failscip-shell shell shell-project 0.0.0 fail(). |
| 222 | echoscip-shell system . . echo. -e "$PWD1" | $CRYPTSETUP refresh $DEV_NAME --allow-discards --perf-same_cpu_crypt || failscip-shell shell shell-project 0.0.0 fail(). |
| 223 | $CRYPTSETUP status $DEV_NAME | grepscip-shell system . . grep. -q discards || failscip-shell shell shell-project 0.0.0 fail(). |
| 224 | $CRYPTSETUP status $DEV_NAME | grepscip-shell system . . grep. -q same_cpu_crypt || failscip-shell shell shell-project 0.0.0 fail(). |
| 225 | echoscip-shell system . . echo. -e "$PWD1" | $CRYPTSETUP refresh $DEV_NAME || failscip-shell shell shell-project 0.0.0 fail(). |
| 226 | $CRYPTSETUP status $DEV_NAME | grepscip-shell system . . grep. -q discards && failscip-shell shell shell-project 0.0.0 fail(). |
| 227 | $CRYPTSETUP status $DEV_NAME | grepscip-shell system . . grep. -q same_cpu_crypt && failscip-shell shell shell-project 0.0.0 fail(). |
| 228 | echoscip-shell system . . echo. -e "$PWD1" | $CRYPTSETUP refresh $DEV $DEV_NAME2 2>/dev/nullscip-shell filesystem . . `/dev/null`. && failscip-shell shell shell-project 0.0.0 fail(). |
| 229 | if [scip-shell system . . `[`. -n "$DM_PERF_NO_WORKQUEUE" ]; then |
| 230 | echoscip-shell system . . echo. -n "no_read_workqueue no_write_workqueue " |
| 231 | echoscip-shell system . . echo. -e "$PWD1" | $CRYPTSETUP refresh $DEV_NAME --perf-no_read_workqueue --perf-no_write_workqueue || failscip-shell shell shell-project 0.0.0 fail(). |
| 232 | $CRYPTSETUP status $DEV_NAME | grepscip-shell system . . grep. -q no_read_workqueue || failscip-shell shell shell-project 0.0.0 fail(). |
| 233 | $CRYPTSETUP status $DEV_NAME | grepscip-shell system . . grep. -q no_write_workqueue || failscip-shell shell shell-project 0.0.0 fail(). |
| 234 | fi |
| 235 | if [scip-shell system . . `[`. -n "$DM_PERF_HIGH_PRIORITY" ]; then |
| 236 | echoscip-shell system . . echo. -n "high_priority " |
| 237 | echoscip-shell system . . echo. -e "$PWD1" | $CRYPTSETUP refresh $DEV_NAME --perf-high_priority || failscip-shell shell shell-project 0.0.0 fail(). |
| 238 | $CRYPTSETUP status $DEV_NAME | grepscip-shell system . . grep. -q high_priority || failscip-shell shell shell-project 0.0.0 fail(). |
| 239 | fi |
| 240 | $CRYPTSETUP close $DEV_NAME || failscip-shell shell shell-project 0.0.0 fail(). |
| 241 | echoscip-shell system . . echo. |
| 242 | |
| 243 | formatscip-shell shell shell-project 0.0.0 format(). luks2 |
| 244 | echoscip-shell system . . echo. -n "LUKS2: same_cpu_crypt submit_from_cpus " |
| 245 | echoscip-shell system . . echo. -e "$PWD1" | $CRYPTSETUP open $DEV $DEV_NAME --perf-same_cpu_crypt --perf-submit_from_crypt_cpus --persistent || failscip-shell shell shell-project 0.0.0 fail(). |
| 246 | $CRYPTSETUP status $DEV_NAME | grepscip-shell system . . grep. -q same_cpu_crypt || failscip-shell shell shell-project 0.0.0 fail(). |
| 247 | $CRYPTSETUP status $DEV_NAME | grepscip-shell system . . grep. -q submit_from_crypt_cpus || failscip-shell shell shell-project 0.0.0 fail(). |
| 248 | $CRYPTSETUP close $DEV_NAME || failscip-shell shell shell-project 0.0.0 fail(). |
| 249 | # Stored in metadata |
| 250 | echoscip-shell system . . echo. -e "$PWD1" | $CRYPTSETUP open $DEV $DEV_NAME || failscip-shell shell shell-project 0.0.0 fail(). |
| 251 | $CRYPTSETUP status $DEV_NAME | grepscip-shell system . . grep. -q same_cpu_crypt || failscip-shell shell shell-project 0.0.0 fail(). |
| 252 | $CRYPTSETUP status $DEV_NAME | grepscip-shell system . . grep. -q submit_from_crypt_cpus || failscip-shell shell shell-project 0.0.0 fail(). |
| 253 | $CRYPTSETUP close $DEV_NAME || failscip-shell shell shell-project 0.0.0 fail(). |
| 254 | echoscip-shell system . . echo. -n "allow_discards [persistent flags] " |
| 255 | echoscip-shell system . . echo. -e "$PWD1" | $CRYPTSETUP open $DEV $DEV_NAME --perf-same_cpu_crypt --allow-discards --persistent || failscip-shell shell shell-project 0.0.0 fail(). |
| 256 | $CRYPTSETUP status $DEV_NAME | grepscip-shell system . . grep. -q same_cpu_crypt || failscip-shell shell shell-project 0.0.0 fail(). |
| 257 | $CRYPTSETUP status $DEV_NAME | grepscip-shell system . . grep. -q discards || failscip-shell shell shell-project 0.0.0 fail(). |
| 258 | $CRYPTSETUP close $DEV_NAME || failscip-shell shell shell-project 0.0.0 fail(). |
| 259 | echoscip-shell system . . echo. -e "$PWD1" | $CRYPTSETUP open $DEV $DEV_NAME || failscip-shell shell shell-project 0.0.0 fail(). |
| 260 | $CRYPTSETUP status $DEV_NAME | grepscip-shell system . . grep. -q same_cpu_crypt || failscip-shell shell shell-project 0.0.0 fail(). |
| 261 | $CRYPTSETUP status $DEV_NAME | grepscip-shell system . . grep. -q discards || failscip-shell shell shell-project 0.0.0 fail(). |
| 262 | $CRYPTSETUP close $DEV_NAME || failscip-shell shell shell-project 0.0.0 fail(). |
| 263 | |
| 264 | echoscip-shell system . . echo. -e "$PWD1" | $CRYPTSETUP open $DEV $DEV_NAME --persistent || failscip-shell shell shell-project 0.0.0 fail(). |
| 265 | $CRYPTSETUP status $DEV_NAME | grepscip-shell system . . grep. -q same_cpu_crypt && failscip-shell shell shell-project 0.0.0 fail(). |
| 266 | $CRYPTSETUP status $DEV_NAME | grepscip-shell system . . grep. -q discards && failscip-shell shell shell-project 0.0.0 fail(). |
| 267 | echoscip-shell system . . echo. -e "$PWD1" | $CRYPTSETUP refresh $DEV $DEV_NAME --perf-same_cpu_crypt --perf-submit_from_crypt_cpus --persistent || failscip-shell shell shell-project 0.0.0 fail(). |
| 268 | $CRYPTSETUP status $DEV_NAME | grepscip-shell system . . grep. -q same_cpu_crypt || failscip-shell shell shell-project 0.0.0 fail(). |
| 269 | $CRYPTSETUP status $DEV_NAME | grepscip-shell system . . grep. -q submit_from_crypt_cpus || failscip-shell shell shell-project 0.0.0 fail(). |
| 270 | echoscip-shell system . . echo. -e "$PWD1" | $CRYPTSETUP refresh $DEV_NAME || failscip-shell shell shell-project 0.0.0 fail(). |
| 271 | $CRYPTSETUP status $DEV_NAME | grepscip-shell system . . grep. -q same_cpu_crypt || failscip-shell shell shell-project 0.0.0 fail(). |
| 272 | $CRYPTSETUP status $DEV_NAME | grepscip-shell system . . grep. -q submit_from_crypt_cpus || failscip-shell shell shell-project 0.0.0 fail(). |
| 273 | echoscip-shell system . . echo. -e "$PWD1" | $CRYPTSETUP refresh $DEV $DEV_NAME --perf-same_cpu_crypt --allow-discards --persistent || failscip-shell shell shell-project 0.0.0 fail(). |
| 274 | $CRYPTSETUP status $DEV_NAME | grepscip-shell system . . grep. -q same_cpu_crypt || failscip-shell shell shell-project 0.0.0 fail(). |
| 275 | $CRYPTSETUP status $DEV_NAME | grepscip-shell system . . grep. -q discards || failscip-shell shell shell-project 0.0.0 fail(). |
| 276 | echoscip-shell system . . echo. -e "$PWD1" | $CRYPTSETUP refresh $DEV_NAME || failscip-shell shell shell-project 0.0.0 fail(). |
| 277 | $CRYPTSETUP status $DEV_NAME | grepscip-shell system . . grep. -q same_cpu_crypt || failscip-shell shell shell-project 0.0.0 fail(). |
| 278 | $CRYPTSETUP status $DEV_NAME | grepscip-shell system . . grep. -q discards || failscip-shell shell shell-project 0.0.0 fail(). |
| 279 | echoscip-shell system . . echo. -e "$PWD1" | $CRYPTSETUP refresh $DEV $DEV_NAME --perf-submit_from_crypt_cpus || failscip-shell shell shell-project 0.0.0 fail(). |
| 280 | $CRYPTSETUP status $DEV_NAME | grepscip-shell system . . grep. -q same_cpu_crypt || failscip-shell shell shell-project 0.0.0 fail(). |
| 281 | $CRYPTSETUP status $DEV_NAME | grepscip-shell system . . grep. -q discards || failscip-shell shell shell-project 0.0.0 fail(). |
| 282 | $CRYPTSETUP status $DEV_NAME | grepscip-shell system . . grep. -q submit_from_crypt_cpus || failscip-shell shell shell-project 0.0.0 fail(). |
| 283 | echoscip-shell system . . echo. -e "$PWD1" | $CRYPTSETUP refresh $DEV $DEV_NAME || failscip-shell shell shell-project 0.0.0 fail(). |
| 284 | $CRYPTSETUP status $DEV_NAME | grepscip-shell system . . grep. -q submit_from_crypt_cpus && failscip-shell shell shell-project 0.0.0 fail(). |
| 285 | echoscip-shell system . . echo. -e "$PWD1" | $CRYPTSETUP refresh $DEV $DEV_NAME --persistent || failscip-shell shell shell-project 0.0.0 fail(). |
| 286 | $CRYPTSETUP status $DEV_NAME | grepscip-shell system . . grep. -q same_cpu_crypt && failscip-shell shell shell-project 0.0.0 fail(). |
| 287 | $CRYPTSETUP status $DEV_NAME | grepscip-shell system . . grep. -q discards && failscip-shell shell shell-project 0.0.0 fail(). |
| 288 | $CRYPTSETUP status $DEV_NAME | grepscip-shell system . . grep. -q submit_from_crypt_cpus && failscip-shell shell shell-project 0.0.0 fail(). |
| 289 | echoscip-shell system . . echo. -e "$PWD1" | $CRYPTSETUP refresh $DEV $DEV_NAME --disable-keyring || failscip-shell shell shell-project 0.0.0 fail(). |
| 290 | $CRYPTSETUP status $DEV_NAME | grepscip-shell system . . grep. -q keyring && failscip-shell shell shell-project 0.0.0 fail(). |
| 291 | if [scip-shell system . . `[`. -n "$DM_KEYRING" ]; then |
| 292 | $CRYPTSETUP --version | grepscip-shell system . . grep. -q KEYRING |
| 293 | if [scip-shell system . . `[`. $? -eq 0 ]; then |
| 294 | echoscip-shell system . . echo. -n "keyring " |
| 295 | echoscip-shell system . . echo. -e "$PWD1" | $CRYPTSETUP refresh $DEV $DEV_NAME || failscip-shell shell shell-project 0.0.0 fail(). |
| 296 | $CRYPTSETUP status $DEV_NAME | grepscip-shell system . . grep. -q keyring || failscip-shell shell shell-project 0.0.0 fail(). |
| 297 | fi |
| 298 | fi |
| 299 | if [scip-shell system . . `[`. -n "$DM_PERF_NO_WORKQUEUE" ]; then |
| 300 | echoscip-shell system . . echo. -n "no_read_workqueue no_write_workqueue " |
| 301 | echoscip-shell system . . echo. -e "$PWD1" | $CRYPTSETUP refresh $DEV $DEV_NAME --perf-no_read_workqueue --perf-no_write_workqueue --persistent || failscip-shell shell shell-project 0.0.0 fail(). |
| 302 | $CRYPTSETUP status $DEV_NAME | grepscip-shell system . . grep. -q no_read_workqueue || failscip-shell shell shell-project 0.0.0 fail(). |
| 303 | $CRYPTSETUP status $DEV_NAME | grepscip-shell system . . grep. -q no_write_workqueue || failscip-shell shell shell-project 0.0.0 fail(). |
| 304 | $CRYPTSETUP close $DEV_NAME || failscip-shell shell shell-project 0.0.0 fail(). |
| 305 | echoscip-shell system . . echo. -e "$PWD1" | $CRYPTSETUP open $DEV $DEV_NAME || failscip-shell shell shell-project 0.0.0 fail(). |
| 306 | $CRYPTSETUP status $DEV_NAME | grepscip-shell system . . grep. -q no_read_workqueue || failscip-shell shell shell-project 0.0.0 fail(). |
| 307 | $CRYPTSETUP status $DEV_NAME | grepscip-shell system . . grep. -q no_write_workqueue || failscip-shell shell shell-project 0.0.0 fail(). |
| 308 | fi |
| 309 | if [scip-shell system . . `[`. -n "$DM_PERF_HIGH_PRIORITY" ]; then |
| 310 | echoscip-shell system . . echo. -n "high_priority " |
| 311 | echoscip-shell system . . echo. -e "$PWD1" | $CRYPTSETUP refresh $DEV $DEV_NAME --perf-high_priority --persistent || failscip-shell shell shell-project 0.0.0 fail(). |
| 312 | $CRYPTSETUP status $DEV_NAME | grepscip-shell system . . grep. -q high_priority || failscip-shell shell shell-project 0.0.0 fail(). |
| 313 | $CRYPTSETUP close $DEV_NAME || failscip-shell shell shell-project 0.0.0 fail(). |
| 314 | echoscip-shell system . . echo. -e "$PWD1" | $CRYPTSETUP open $DEV $DEV_NAME || failscip-shell shell shell-project 0.0.0 fail(). |
| 315 | $CRYPTSETUP status $DEV_NAME | grepscip-shell system . . grep. -q high_priority || failscip-shell shell shell-project 0.0.0 fail(). |
| 316 | fi |
| 317 | echoscip-shell system . . echo. -e "$PWD1" | $CRYPTSETUP refresh $DEV $DEV_NAME2 2>/dev/nullscip-shell filesystem . . `/dev/null`. && failscip-shell shell shell-project 0.0.0 fail(). |
| 318 | $CRYPTSETUP close $DEV_NAME || failscip-shell shell shell-project 0.0.0 fail(). |
| 319 | echoscip-shell system . . echo. |
| 320 | fi |
| 321 | |
| 322 | echoscip-shell system . . echo. "[3] Kernel dmcrypt sector size options" |
| 323 | echoscip-shell system . . echo. -e "$PWD1" | $CRYPTSETUP open $PLAIN_OPT $DEV $DEV_NAME --sector-size 4096 >/dev/nullscip-shell filesystem . . `/dev/null`. 2>&1 |
| 324 | ret=$? |
| 325 | [scip-shell system . . `[`. -z "$DM_SECTOR_SIZE" -a $ret -eq 0 ] && failscip-shell shell shell-project 0.0.0 fail(). "cryptsetup activated device with --sector-size option on incompatible kernel!" |
| 326 | if [scip-shell system . . `[`. $ret -ne 0 ] ; then |
| 327 | SKIP_COUNT=$((SKIP_COUNT+1)) |
| 328 | if [scip-shell system . . `[`. $SKIP_COUNT -ge 2 ]; then |
| 329 | skipscip-shell shell shell-project 0.0.0 skip(). "dmcrypt sector-size option not available" |
| 330 | fi |
| 331 | echoscip-shell system . . echo. "TEST SKIPPED: dmcrypt sector-size option not available" |
| 332 | else |
| 333 | $CRYPTSETUP close $DEV_NAME || failscip-shell shell shell-project 0.0.0 fail(). |
| 334 | |
| 335 | echoscip-shell system . . echo. -n "PLAIN sector size:" |
| 336 | echoscip-shell system . . echo. -e "$PWD1" | $CRYPTSETUP open $PLAIN_OPT $DEV $DEV_NAME --sector-size 1234 >/dev/nullscip-shell filesystem . . `/dev/null`. 2>&1 && failscip-shell shell shell-project 0.0.0 fail(). |
| 337 | for S in 512 1024 2048 4096; do |
| 338 | echoscip-shell system . . echo. -n "[$S]" |
| 339 | echoscip-shell system . . echo. -e "$PWD1" | $CRYPTSETUP open -q $PLAIN_OPT $DEV $DEV_NAME --sector-size $S || failscip-shell shell shell-project 0.0.0 fail(). |
| 340 | check_sector_sizescip-shell shell shell-project 0.0.0 check_sector_size(). $S |
| 341 | $CRYPTSETUP close $DEV_NAME || failscip-shell shell shell-project 0.0.0 fail(). |
| 342 | done |
| 343 | |
| 344 | echoscip-shell system . . echo. -e "$PWD1" | $CRYPTSETUP open $PLAIN_OPT $DEV $DEV_NAME --iv-large-sectors >/dev/nullscip-shell filesystem . . `/dev/null`. 2>&1 && failscip-shell shell shell-project 0.0.0 fail(). |
| 345 | for S in 1024 2048 4096; do |
| 346 | echoscip-shell system . . echo. -n "[$S/IV]" |
| 347 | echoscip-shell system . . echo. -e "$PWD1" | $CRYPTSETUP open -q $PLAIN_OPT $DEV $DEV_NAME --sector-size $S --iv-large-sectors || failscip-shell shell shell-project 0.0.0 fail(). |
| 348 | check_sector_sizescip-shell shell shell-project 0.0.0 check_sector_size(). $S |
| 349 | dmsetup table $DEV_NAME | grepscip-shell system . . grep. -q "iv_large_sectors" || failscip-shell shell shell-project 0.0.0 fail(). |
| 350 | $CRYPTSETUP close $DEV_NAME || failscip-shell shell shell-project 0.0.0 fail(). |
| 351 | done |
| 352 | echoscip-shell system . . echo. |
| 353 | |
| 354 | echoscip-shell system . . echo. -n "LUKS2 sector size:" |
| 355 | echoscip-shell system . . echo. -e "$PWD1" | $CRYPTSETUP luksFormat --type luks2 -$DEV --sector-size 1234 >/dev/nullscip-shell filesystem . . `/dev/null`. 2>&1 && failscip-shell shell shell-project 0.0.0 fail(). |
| 356 | for S in 512 1024 2048 4096; do |
| 357 | echoscip-shell system . . echo. -n "[$S]" |
| 358 | echoscip-shell system . . echo. -e "$PWD1" | $CRYPTSETUP -q luksFormat --type luks2 --pbkdf pbkdf2 --pbkdf-force-iterations 1000 $DEV --sector-size $S || failscip-shell shell shell-project 0.0.0 fail(). |
| 359 | echoscip-shell system . . echo. -e "$PWD1" | $CRYPTSETUP open $DEV $DEV_NAME || failscip-shell shell shell-project 0.0.0 fail(). |
| 360 | check_sector_sizescip-shell shell shell-project 0.0.0 check_sector_size(). $S |
| 361 | $CRYPTSETUP close $DEV_NAME || failscip-shell shell shell-project 0.0.0 fail(). |
| 362 | done |
| 363 | echoscip-shell system . . echo. |
| 364 | fi |
| 365 | |
| 366 | echoscip-shell system . . echo. "[4] Disappeared device test:" |
| 367 | KEY="00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000001" |
| 368 | for F in LUKS1 LUKS2 BITLK TCRYPT; do |
| 369 | add_devicescip-shell shell shell-project 0.0.0 add_device(). dev_size_mb=1 sector_size=512 num_tgts=1 lbpu=1 |
| 370 | echoscip-shell system . . echo. -n "$F" |
| 371 | # Fake CRYPT UUID to force code to parse type-specific path |
| 372 | dmsetup create $DEV_NAME --uuid CRYPT-$F-$DEV_NAME --table "0 1024 crypt aes-xts-plain64 $KEY 16 /dev/$SCSI_DEV 16" |
| 373 | $CRYPTSETUP status $DEV_NAME >/dev/nullscip-shell filesystem . . `/dev/null`. 2>&1 || failscip-shell shell shell-project 0.0.0 fail(). |
| 374 | echoscip-shell system . . echo. 1 > /sys/block/$SCSI_DEV/device/delete |
| 375 | udevadm settle >/dev/nullscip-shell filesystem . . `/dev/null`. 2>&1 |
| 376 | $CRYPTSETUP status $DEV_NAME >/dev/nullscip-shell filesystem . . `/dev/null`. 2>&1 || failscip-shell shell shell-project 0.0.0 fail(). |
| 377 | dmsetup remove $DEV_NAME --retry || failscip-shell shell shell-project 0.0.0 fail(). |
| 378 | rmmod scsi_debug >/dev/nullscip-shell filesystem . . `/dev/null`. 2>&1 |
| 379 | echoscip-shell system . . echo. -n "[OK] " |
| 380 | done |
| 381 | echoscip-shell system . . echo. |
| 382 | |
| 383 | cleanupscip-shell shell shell-project 0.0.0 cleanup(). |
| 384 | exit 0 |