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
13 # make sure we have the module
14 modinfo scsi_debug 2>&1 > /dev/null || _notrun "scsi_debug module not found"
16 lsmod | grep -wq scsi_debug
17 if [[ $? -eq 0 ]]; then
21 if [[ $mod_present -eq 1 ]]; then
22 # We try to remove the module only once if MODPROBE_PATIENT_RM_TIMEOUT_SECONDS
23 # is set to forever because fstests does not leave modules
24 # lingering around. If you do have a module lingering around
25 # and its being used, it wasn't us who started it, so you
26 # likely would not want to wait forever for it really.
27 if [[ "$MODPROBE_PATIENT_RM_TIMEOUT_SECONDS" == "forever" ]]; then
28 rmmod scsi_debug || _notrun "scsi_debug module in use and MODPROBE_PATIENT_RM_TIMEOUT_SECONDS set to forever, removing once failed"
30 _patient_rmmod scsi_debug || _notrun "scsi_debug module in use"
33 # make sure it has the features we need
34 # logical/physical sectors plus unmap support all went in together
35 modinfo scsi_debug | grep -wq sector_size || _notrun "scsi_debug too old"
38 # Args: [physical sector size, [logical sector size, [unaligned(0|1), [size in megs]]]]
41 # Defaults to phys 512, logical 512, aligned
52 while [ $logical -lt $physical ]; do
53 let physical=physical/2
54 let phys_exp=phys_exp+1
56 opts="sector_size=$logical physblk_exp=$phys_exp lowest_aligned=$unaligned dev_size_mb=$size $@"
57 echo "scsi_debug options $opts" >> $seqres.full
58 modprobe scsi_debug $opts
59 [ $? -eq 0 ] || _fail "scsi_debug modprobe failed"
61 device=`grep -wl scsi_debug /sys/block/sd*/device/model | awk -F / '{print $4}'`
67 lsmod | grep -wq scsi_debug || return
69 _patient_rmmod scsi_debug || _fail "Could not remove scsi_debug module"