Merge branch 'master' of git://git.kernel.org/pub/scm/fs/xfs/xfstests-dev
[xfstests-dev.git] / 279
1 #! /bin/bash
2 # FS QA Test No. 279
3 #
4 # Test mkfs.xfs against various types of devices with varying
5 # logical & physical sector sizes and offsets.
6 #
7 #-----------------------------------------------------------------------
8 # Copyright (c) 2012 Red Hat, Inc.  All Rights Reserved.
9 #
10 # This program is free software; you can redistribute it and/or
11 # modify it under the terms of the GNU General Public License as
12 # published by the Free Software Foundation.
13 #
14 # This program is distributed in the hope that it would be useful,
15 # but WITHOUT ANY WARRANTY; without even the implied warranty of
16 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
17 # GNU General Public License for more details.
18 #
19 # You should have received a copy of the GNU General Public License
20 # along with this program; if not, write the Free Software Foundation,
21 # Inc.,  51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
22 #-----------------------------------------------------------------------
23 #
24 # creator
25 owner=sandeen@redhat.com
26
27 seq=`basename $0`
28 echo "QA output created by $seq"
29
30 here=`pwd`
31 tmp=/tmp/$$
32 status=1        # failure is the default!
33 trap "_cleanup; exit \$status" 0 1 2 3 15
34
35 _cleanup()
36 {
37     cd /
38     rm -f $tmp.*
39     _put_scsi_debug_dev
40 }
41
42 # get standard environment, filters and checks
43 . ./common.rc
44 . ./common.filter
45 . ./common.scsi_debug
46
47 # real QA test starts here
48 _supported_fs xfs
49 _supported_os Linux
50
51 _require_scsi_debug
52
53 rm -f $seq.full
54
55 # Remove xfs signature so -f isn't needed to re-mkfs
56 _wipe_device()
57 {
58         device=$1
59         dd if=/dev/zero of=$device bs=4k count=1 &>/dev/null
60 }
61
62 _check_mkfs()
63 {
64         echo "===================" 
65         echo "mkfs with opts: $@" | sed -e "s,/dev/sd.,DEVICE,"
66         /sbin/mkfs.xfs $@ 2>/dev/null > $tmp.mkfs.full
67         if [ $? -ne 0 ]; then
68                 echo "Failed."
69                 return
70         fi
71         echo "Passed."
72         cat $tmp.mkfs.full | _filter_mkfs >> $seq.full 2>$tmp.mkfs
73         . $tmp.mkfs
74         echo "Got sector size: $sectsz"
75         device=`echo $@ | awk '{print $NF}'`
76         _wipe_device $device
77 }
78
79 # === 4k physical 512b logical aligned
80 (
81 echo "==================="
82 echo "4k physical 512b logical aligned"
83 SCSI_DEBUG_DEV=`_get_scsi_debug_dev 4096 512 0 128`
84 # sector size should default to 4k
85 _check_mkfs $SCSI_DEBUG_DEV
86 # blocksize smaller than physical sectorsize should revert to logical sectorsize
87 _check_mkfs -b size=2048 -f $SCSI_DEBUG_DEV
88 ) | tee -a $seq.full
89 _put_scsi_debug_dev
90
91 # === 4k physical 512b logical unaligned
92 (
93 echo "==================="
94 echo "4k physical 512b logical unaligned"
95 SCSI_DEBUG_DEV=`_get_scsi_debug_dev 4096 512 1 128`
96 # should fail on misalignment
97 _check_mkfs $SCSI_DEBUG_DEV
98 # should fall back to logical sector size with force
99 _check_mkfs -f $SCSI_DEBUG_DEV
100 # with 4k sector specified should fail without force
101 _check_mkfs -s size=4096 $SCSI_DEBUG_DEV
102 # with 4k sector specified should fall back to logical sector size with force
103 _check_mkfs -s size=4096 -f $SCSI_DEBUG_DEV
104 ) | tee -a $seq.full
105 _put_scsi_debug_dev
106
107 # === hard 4k physical / 4k logical
108 (
109 echo "==================="
110 echo "hard 4k physical / 4k logical"
111 SCSI_DEBUG_DEV=`_get_scsi_debug_dev 4096 4096 0 128`
112 # block size smaller than sector size should fail 
113 _check_mkfs -b size=2048 $SCSI_DEBUG_DEV
114 # sector size smaller than physical sector size should fail
115 _check_mkfs -s size=512 $SCSI_DEBUG_DEV
116 ) | tee -a $seq.full
117 _put_scsi_debug_dev
118
119 status=0
120 exit