xfstests: introduce a common directory
[xfstests-dev.git] / tests / xfs / 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
25 seq=`basename $0`
26 seqres=$RESULT_DIR/$seq
27 seqres=$RESULT_DIR/$seq
28 seqres=$RESULT_DIR/$seq
29 echo "QA output created by $seq"
30
31 here=`pwd`
32 tmp=/tmp/$$
33 status=1        # failure is the default!
34 trap "_cleanup; exit \$status" 0 1 2 3 15
35
36 _cleanup()
37 {
38     cd /
39     rm -f $tmp.*
40     _put_scsi_debug_dev
41 }
42
43 # get standard environment, filters and checks
44 . ./common/rc
45 . ./common/filter
46 . ./common/scsi_debug
47
48 # real QA test starts here
49 _supported_fs xfs
50 _supported_os Linux
51
52 _require_scsi_debug
53
54 rm -f $seqres.full
55
56 # Remove xfs signature so -f isn't needed to re-mkfs
57 _wipe_device()
58 {
59         device=$1
60         dd if=/dev/zero of=$device bs=4k count=1 &>/dev/null
61 }
62
63 _check_mkfs()
64 {
65         echo "===================" 
66         echo "mkfs with opts: $@" | sed -e "s,/dev/sd.,DEVICE,"
67         /sbin/mkfs.xfs $@ 2>/dev/null > $tmp.mkfs.full
68         if [ $? -ne 0 ]; then
69                 echo "Failed."
70                 return
71         fi
72         echo "Passed."
73         cat $tmp.mkfs.full | _filter_mkfs >> $seqres.full 2>$tmp.mkfs
74         . $tmp.mkfs
75         echo "Got sector size: $sectsz"
76         device=`echo $@ | awk '{print $NF}'`
77         _wipe_device $device
78 }
79
80 # === 4k physical 512b logical aligned
81 (
82 echo "==================="
83 echo "4k physical 512b logical aligned"
84 SCSI_DEBUG_DEV=`_get_scsi_debug_dev 4096 512 0 128`
85 # sector size should default to 4k
86 _check_mkfs $SCSI_DEBUG_DEV
87 # blocksize smaller than physical sectorsize should revert to logical sectorsize
88 _check_mkfs -b size=2048 -f $SCSI_DEBUG_DEV
89 ) | tee -a $seqres.full
90 _put_scsi_debug_dev
91
92 # === 4k physical 512b logical unaligned
93 (
94 echo "==================="
95 echo "4k physical 512b logical unaligned"
96 SCSI_DEBUG_DEV=`_get_scsi_debug_dev 4096 512 1 128`
97 # should fail on misalignment
98 _check_mkfs $SCSI_DEBUG_DEV
99 # should fall back to logical sector size with force
100 _check_mkfs -f $SCSI_DEBUG_DEV
101 # with 4k sector specified should fail without force
102 _check_mkfs -s size=4096 $SCSI_DEBUG_DEV
103 # with 4k sector specified should fall back to logical sector size with force
104 _check_mkfs -s size=4096 -f $SCSI_DEBUG_DEV
105 ) | tee -a $seqres.full
106 _put_scsi_debug_dev
107
108 # === hard 4k physical / 4k logical
109 (
110 echo "==================="
111 echo "hard 4k physical / 4k logical"
112 SCSI_DEBUG_DEV=`_get_scsi_debug_dev 4096 4096 0 128`
113 # block size smaller than sector size should fail 
114 _check_mkfs -b size=2048 $SCSI_DEBUG_DEV
115 # sector size smaller than physical sector size should fail
116 _check_mkfs -s size=512 $SCSI_DEBUG_DEV
117 ) | tee -a $seqres.full
118 _put_scsi_debug_dev
119
120 status=0
121 exit