2 # SPDX-License-Identifier: GPL-2.0
3 # Copyright (c) 2012 Red Hat, Inc. All Rights Reserved.
5 # Functions useful for tests on unique block devices
9 # make sure we have the module and it's not already used
10 modinfo scsi_debug 2>&1 > /dev/null || _notrun "scsi_debug module not found"
11 lsmod | grep -wq scsi_debug && (rmmod scsi_debug || _notrun "scsi_debug module in use")
12 # make sure it has the features we need
13 # logical/physical sectors plus unmap support all went in together
14 modinfo scsi_debug | grep -wq sector_size || _notrun "scsi_debug too old"
17 # Args: [physical sector size, [logical sector size, [unaligned(0|1), [size in megs]]]]
20 # Defaults to phys 512, logical 512, aligned
31 while [ $logical -lt $physical ]; do
32 let physical=physical/2
33 let phys_exp=phys_exp+1
35 opts="sector_size=$logical physblk_exp=$phys_exp lowest_aligned=$unaligned dev_size_mb=$size $@"
36 echo "scsi_debug options $opts" >> $seqres.full
37 modprobe scsi_debug $opts
38 [ $? -eq 0 ] || _fail "scsi_debug modprobe failed"
40 device=`grep -wl scsi_debug /sys/block/sd*/device/model | awk -F / '{print $4}'`
46 lsmod | grep -wq scsi_debug || return
49 # use redirection not -q option of modprobe here, because -q of old
50 # modprobe is only quiet when the module is not found, not when the
52 while [ $n -ge 0 ] && ! modprobe -nr scsi_debug >/dev/null 2>&1; do
56 rmmod scsi_debug || _fail "Could not remove scsi_debug module"