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