"Fossies" - the Fresh Open Source Software Archive

Member "cryptsetup-2.4.3/tests/discards-test" (13 Jan 2022, 2552 Bytes) of package /linux/misc/cryptsetup-2.4.3.tar.xz:


As a special service "Fossies" has tried to format the requested source page into HTML format using (guessed) Bash source code syntax highlighting (style: standard) with prefixed line numbers and code folding option. Alternatively you can here view or download the uninterpreted source code file. See also the last Fossies "Diffs" side-by-side code changes report for "discards-test": 2.3.6_vs_2.4.0.

    1 #!/bin/bash
    2 
    3 [ -z "$CRYPTSETUP_PATH" ] && CRYPTSETUP_PATH=".."
    4 CRYPTSETUP=$CRYPTSETUP_PATH/cryptsetup
    5 DEV_NAME="discard-t3st"
    6 DEV=""
    7 PWD1="93R4P4pIqAH8"
    8 
    9 cleanup() {
   10     [ -b /dev/mapper/$DEV_NAME ] && dmsetup remove --retry $DEV_NAME
   11     udevadm settle >/dev/null 2>&1
   12     rmmod scsi_debug >/dev/null 2>&1
   13     sleep 2
   14 }
   15 
   16 fail()
   17 {
   18     echo "FAILED backtrace:"
   19     while caller $frame; do ((frame++)); done
   20     cleanup
   21     exit 100
   22 }
   23 
   24 add_device() {
   25     rmmod scsi_debug >/dev/null 2>&1
   26     if [ -d /sys/module/scsi_debug ] ; then
   27         echo "Cannot use scsi_debug module (in use or compiled-in), test skipped."
   28         exit 77
   29     fi
   30     modprobe scsi_debug $@ delay=0 >/dev/null 2>&1
   31     if [ $? -ne 0 ] ; then
   32         echo "This kernel seems to not support proper scsi_debug module, test skipped."
   33         exit 77
   34     fi
   35 
   36     sleep 2
   37     DEV=$(grep -l -e scsi_debug /sys/block/*/device/model | cut -f4 -d /)
   38 
   39     DEV="/dev/$DEV"
   40     [ -b $DEV ] || fail "Cannot find $DEV."
   41 }
   42 
   43 function check_version()
   44 {
   45     VER_STR=$(dmsetup targets | grep crypt | cut -f 2 -dv)
   46     [ -z "$VER_STR" ] && fail "Failed to parse dm-crypt version."
   47 
   48     VER_MAJ=$(echo $VER_STR | cut -f 1 -d.)
   49     VER_MIN=$(echo $VER_STR | cut -f 2 -d.)
   50 
   51     # option supported in 1.11
   52     test $VER_MAJ -gt 1 && return 0
   53     test $VER_MIN -ge 11 && return 0
   54     return 1
   55 }
   56 
   57 if [ $(id -u) != 0 ]; then
   58     echo "WARNING: You must be root to run this test, test skipped."
   59     exit 77
   60 fi
   61 
   62 modprobe dm-crypt >/dev/null 2>&1
   63 if ! check_version ; then
   64     echo "Probably old kernel, test skipped."
   65     exit 77
   66 fi
   67 
   68 add_device dev_size_mb=16 sector_size=512 num_tgts=1 lbpu=1
   69 
   70 # FIXME test hash of device (unmap -> zero)
   71 # for now just check that flag is enabled
   72 
   73 echo "[1] Allowing discards for LUKS device"
   74 echo $PWD1 | $CRYPTSETUP luksFormat --type luks1 $DEV -q -i1 || fail
   75 echo $PWD1 | $CRYPTSETUP luksOpen $DEV $DEV_NAME --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 luksClose $DEV_NAME || fail
   81 
   82 echo "[2] Allowing discards for plain device"
   83 echo $PWD1 | $CRYPTSETUP create -q $DEV_NAME $DEV --hash sha1 --allow-discards || fail
   84 $CRYPTSETUP status $DEV_NAME | grep flags | grep discards >/dev/null || fail
   85 $CRYPTSETUP resize $DEV_NAME --size 100 || fail
   86 $CRYPTSETUP status $DEV_NAME | grep flags | grep discards >/dev/null || fail
   87 dmsetup table $DEV_NAME | grep allow_discards >/dev/null || fail
   88 $CRYPTSETUP remove $DEV_NAME || fail
   89 
   90 cleanup