Whamcloud - gitweb
LU-2459 osd: add LMA incompat flag check
[fs/lustre-release.git] / lustre / tests / posix.sh
1 #!/bin/bash
2 #set -vx
3 set -e
4
5 LUSTRE=${LUSTRE:-$(cd $(dirname $0)/..; echo $PWD)}
6 . $LUSTRE/tests/test-framework.sh
7 init_test_env $@
8 . ${CONFIG:=$LUSTRE/tests/cfg/$NAME.sh}
9 init_logging
10
11 build_test_filter
12 check_and_setup_lustre
13
14 POSIX_DIR=${POSIX_DIR:-"$LUSTRE/tests/posix"}
15 POSIX_SRC=${POSIX_SRC:-"/usr/src/posix"}
16 BASELINE_FS=${BASELINE_FS:-"ext4"}
17
18 # SLES does not support read-write access to an ext4 file system by default
19 [[ -e /etc/SuSE-release ]] && BASELINE_FS=ext3
20
21 cleanup_loop_dev() {
22     local mnt=$1
23     local dev=$2
24     local file=$3
25
26     # if we only have 1 arg, we will search for dev
27     if [[ $# = 1 ]]; then
28         dev=$(losetup -a | grep "$mnt" | cut -d: -f1)
29         [[ -n $dev ]] && losetup -d $dev
30     else # we need all args
31         [[ -z $mnt ]] || [[ -z $dev ]] || [[ -z $file ]] &&
32             error "Can't cleanup loop device"
33         umount -f $mnt
34         losetup -d $dev && rm -rf $mnt
35         rm -f $file
36     fi
37 }
38
39 setup_loop_dev() {
40         local mnt=$1
41         local dev=$2
42         local file=$3
43         local rc=0
44
45         echo "Make a loop file system with $file on $dev"
46         dd if=/dev/zero of=$file bs=1024k count=500 > /dev/null
47         if ! losetup $dev $file; then
48                 rc=$?
49                 echo "can't set up $dev for $file"
50                 return $rc
51         fi
52         if ! eval mkfs.$BASELINE_FS $dev; then
53                 rc=$?
54                 echo "mkfs.$BASELINE_FS on $dev failed"
55                 return $rc
56         fi
57         mkdir -p $mnt
58         if ! mount -t $BASELINE_FS $dev $mnt; then
59                 rc=$?
60                 echo "mount $BASELINE_FS failed"
61                 return $rc
62         fi
63         echo
64         return $rc
65 }
66
67 test_1() {
68         local allnodes="$(comma_list $(nodes_list))"
69         local tfile="$TMP/$BASELINE_FS-file"
70         local mntpnt=$POSIX_SRC/$BASELINE_FS
71         local loopbase
72         local loopdev
73         local rc=0
74
75     # We start at loop1 because posix build uses loop0
76     [ -b /dev/loop/1 ] && loopbase=/dev/loop/
77     [ -b /dev/loop1 ] && loopbase=/dev/loop
78     [ -z "$loopbase" ] && error "/dev/loop/1 and /dev/loop1 gone?"
79
80     for i in `seq 1 7`; do
81         losetup $loopbase$i > /dev/null 2>&1 && continue || true
82         loopdev=$loopbase$i
83         break
84     done
85
86     [ -z "$loopdev" ] && error "Can not find loop device"
87
88     if ! setup_loop_dev $mntpnt $loopdev $tfile; then
89         cleanup_loop_dev "$mntpnt" "$loopdev" "$tfile"
90         error "Setup loop device failed"
91     fi
92
93     # copy the source over to ext mount point
94     if ! cp -af ${POSIX_SRC}/*.* $mntpnt; then
95         cleanup_loop_dev "$mntpnt" "$loopdev" "$tfile"
96         error "Copy POSIX test suite failed"
97     fi
98     export POSIX_SRC=$mntpnt
99     . $POSIX_DIR/posix.cfg
100
101     setup_posix_users $allnodes
102     if ! setup_posix; then
103         delete_posix_users $allnodes
104         cleanup_loop_dev "$POSIX_SRC"
105         cleanup_loop_dev "$mntpnt" "$loopdev" "$tfile"
106         error "Setup POSIX test suite failed"
107     fi
108
109     log "Run POSIX test against lustre filesystem"
110     run_posix $MOUNT compare || \
111         error_noexit "Run POSIX testsuite on $MOUNT failed"
112
113     [[ -d "$MOUNT/TESTROOT" ]] && rm -fr $MOUNT/TESTROOT
114     delete_posix_users $allnodes
115     cleanup_loop_dev "$POSIX_SRC"
116     cleanup_loop_dev "$mntpnt" "$loopdev" "$tfile"
117 }
118 run_test 1 "install, build, run posix on $BASELINE_FS and lustre, then compare"
119
120 complete $SECONDS
121 check_and_cleanup_lustre
122 exit_status