3 [ -z "$CRYPTSETUP_PATH" ] && CRYPTSETUP_PATH=".."
4 CRYPTSETUP=$CRYPTSETUP_PATH/cryptsetup
5 DEV_NAME="discard-t3st"
10 [ -b /dev/mapper/$DEV_NAME ] && dmsetup remove --retry $DEV_NAME
11 udevadm settle >/dev/null 2>&1
12 rmmod scsi_debug 2>/dev/null
18 echo "FAILED backtrace:"
19 while caller $frame; do ((frame++)); done
25 modprobe scsi_debug $@ delay=0
26 if [ $? -ne 0 ] ; then
27 echo "This kernel seems to not support proper scsi_debug module, test skipped."
32 DEV=$(grep -l -e scsi_debug /sys/block/*/device/model | cut -f4 -d /)
35 [ -b $DEV ] || fail "Cannot find $DEV."
38 function check_version()
40 VER_STR=$(dmsetup targets | grep crypt | cut -f 2 -dv)
41 [ -z "$VER_STR" ] && fail "Failed to parse dm-crypt version."
43 VER_MAJ=$(echo $VER_STR | cut -f 1 -d.)
44 VER_MIN=$(echo $VER_STR | cut -f 2 -d.)
46 # option supported in 1.11
47 test $VER_MAJ -gt 1 && return 0
48 test $VER_MIN -ge 11 && return 0
52 if [ $(id -u) != 0 ]; then
53 echo "WARNING: You must be root to run this test, test skipped."
57 modprobe --dry-run scsi_debug || exit 77
58 modprobe dm-crypt >/dev/null 2>&1
59 if ! check_version ; then
60 echo "Probably old kernel, test skipped."
64 add_device dev_size_mb=16 sector_size=512 num_tgts=1 lbpu=1
66 # FIXME test hash of device (unmap -> zero)
67 # for now just check that flag is enabled
69 echo "[1] Allowing discards for LUKS device"
70 echo $PWD1 | $CRYPTSETUP luksFormat --type luks1 $DEV -q -i1 || fail
71 echo $PWD1 | $CRYPTSETUP luksOpen $DEV $DEV_NAME --allow-discards || fail
72 $CRYPTSETUP status $DEV_NAME | grep flags | grep discards >/dev/null || fail
73 $CRYPTSETUP resize $DEV_NAME --size 100 || fail
74 $CRYPTSETUP status $DEV_NAME | grep flags | grep discards >/dev/null || fail
75 dmsetup table $DEV_NAME | grep allow_discards >/dev/null || fail
76 $CRYPTSETUP luksClose $DEV_NAME || fail
78 echo "[2] Allowing discards for plain device"
79 echo $PWD1 | $CRYPTSETUP create -q $DEV_NAME $DEV --hash sha1 --allow-discards || fail
80 $CRYPTSETUP status $DEV_NAME | grep flags | grep discards >/dev/null || fail
81 $CRYPTSETUP resize $DEV_NAME --size 100 || fail
82 $CRYPTSETUP status $DEV_NAME | grep flags | grep discards >/dev/null || fail
83 dmsetup table $DEV_NAME | grep allow_discards >/dev/null || fail
84 $CRYPTSETUP remove $DEV_NAME || fail