3 CRYPTSETUP="../src/cryptsetup"
4 DEV_NAME="discard-t3st"
9 [ -b /dev/mapper/$DEV_NAME ] && dmsetup remove $DEV_NAME
10 udevadm settle >/dev/null 2>&1
11 rmmod scsi_debug 2>/dev/null
23 modprobe scsi_debug $@
24 if [ $? -ne 0 ] ; then
25 echo "This kernel seems to not support proper scsi_debug module, test skipped."
30 DEV=$(grep scsi_debug /sys/block/*/device/model | cut -f4 -d /)
33 [ -b $DEV ] || fail "Cannot find $DEV."
36 function check_version()
38 VER_STR=$(dmsetup targets | grep crypt | cut -f 2 -dv)
39 VER_MAJ=$(echo $VER_STR | cut -f 1 -d.)
40 VER_MIN=$(echo $VER_STR | cut -f 2 -d.)
42 # option supported in 1.11
43 test $VER_MAJ -gt 1 && return 0
44 test $VER_MIN -ge 11 && return 0
48 if [ $(id -u) != 0 ]; then
49 echo "WARNING: You must be root to run this test, test skipped."
53 modprobe --dry-run scsi_debug || exit 0
54 modprobe dm-crypt >/dev/null 2>&1
55 if ! check_version ; then
56 echo "Probably old kernel, test skipped."
60 add_device dev_size_mb=16 sector_size=512 num_tgts=1 lbpu=1
62 # FIXME test hash of device (unmap -> zero)
63 # for now just check that flag is enabled
65 echo "[1] Allowing discards for LUKS device"
66 echo $PWD1 | $CRYPTSETUP luksFormat $DEV -q -i1 || fail
67 echo $PWD1 | $CRYPTSETUP luksOpen $DEV $DEV_NAME --allow-discards || fail
68 $CRYPTSETUP status $DEV_NAME | grep flags | grep discards >/dev/null || fail
69 $CRYPTSETUP resize $DEV_NAME --size 100 || fail
70 $CRYPTSETUP status $DEV_NAME | grep flags | grep discards >/dev/null || fail
71 dmsetup table $DEV_NAME | grep allow_discards >/dev/null || fail
72 $CRYPTSETUP luksClose $DEV_NAME || fail
74 echo "[2] Allowing discards for plain device"
75 echo $PWD1 | $CRYPTSETUP create $DEV_NAME $DEV --hash sha1 --allow-discards || fail
76 $CRYPTSETUP status $DEV_NAME | grep flags | grep discards >/dev/null || fail
77 $CRYPTSETUP resize $DEV_NAME --size 100 || fail
78 $CRYPTSETUP status $DEV_NAME | grep flags | grep discards >/dev/null || fail
79 dmsetup table $DEV_NAME | grep allow_discards >/dev/null || fail
80 $CRYPTSETUP remove $DEV_NAME || fail