xfstests: Assume yes when test device is not partitioned
[xfstests-dev.git] / common.scsi_debug
1 ##/bin/bash
2 #
3 # Copyright (c) 2012 Red Hat, Inc
4 # All Rights Reserved.
5 #
6 # Written by Eric Sandeen <sandeen@redhat.com>
7 #
8 # This program is free software; you can redistribute it and/or
9 # modify it under the terms of the GNU General Public License as
10 # published by the Free Software Foundation.
11 #
12 # This program is distributed in the hope that it would be useful,
13 # but WITHOUT ANY WARRANTY; without even the implied warranty of
14 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15 # GNU General Public License for more details.
16 #
17 # You should have received a copy of the GNU General Public License
18 # along with this program; if not, write the Free Software Foundation,
19 # Inc.,  51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
20 #
21 #
22 # Functions useful for tests on unique block devices
23 #
24
25 _require_scsi_debug()
26 {
27         # make sure we have the module and it's not already used
28         modinfo scsi_debug 2>&1 > /dev/null || _notrun "scsi_debug module not found"
29         lsmod | grep -wq scsi_debug && (rmmod scsi_debug || _notrun "scsi_debug module in use")
30         # make sure it has the features we need
31         # logical/physical sectors plus unmap support all went in together
32         modinfo scsi_debug | grep -wq sector_size || _notrun "scsi_debug too old"
33 }
34
35 # Args: [physical sector size, [logical sector size, [unaligned(0|1), [size in megs]]]]
36 _get_scsi_debug_dev()
37 {
38         # Defaults to phys 512, logical 512, aligned
39         physical=${1-512}
40         logical=${2-512}
41         unaligned=${3-0}
42         size=${4-128}
43
44         phys_exp=0
45         while [ $logical -lt $physical ]; do
46                 let physical=physical/2
47                 let phys_exp=phys_exp+1
48         done
49         opts="sector_size=$logical physblk_exp=$phys_exp lowest_aligned=$unaligned dev_size_mb=$size"
50         echo "scsi_debug options $opts" >> $seq.full
51         modprobe scsi_debug $opts
52         [ $? -eq 0 ] || _fail "scsi_debug modprobe failed"
53         sleep 1
54         device=`grep -wl scsi_debug /sys/block/sd*/device/model | awk -F / '{print $4}'`
55         echo "/dev/$device"
56 }
57
58 _put_scsi_debug_dev()
59 {
60         sleep 1
61         lsmod | grep -wq scsi_debug || return
62         rmmod scsi_debug || _fail "Could not remove scsi_debug module"
63 }