Whamcloud - gitweb
LU-2093 lod: fall back to RR allocation when QoS fails
[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
17 cleanup_loop_dev() {
18     local mnt=$1
19     local dev=$2
20     local file=$3
21
22     # if we only have 1 arg, we will search for dev
23     if [[ $# = 1 ]]; then
24         dev=$(losetup -a | grep "$mnt" | cut -d: -f1)
25         [[ -n $dev ]] && losetup -d $dev
26     else # we need all args
27         [[ -z $mnt ]] || [[ -z $dev ]] || [[ -z $file ]] &&
28             error "Can't cleanup loop device"
29         umount -f $mnt
30         losetup -d $dev && rm -rf $mnt
31         rm -f $file
32     fi
33 }
34
35 setup_loop_dev() {
36     local mnt=$1
37     local dev=$2
38     local file=$3
39     local rc=0
40
41     echo "Make a loop file system with $file on $dev"
42     dd if=/dev/zero of=$file bs=1024k count=500 > /dev/null
43     if ! losetup $dev $file; then
44         rc=$?
45         echo "can't set up $dev for $file"
46         return $rc
47     fi
48     if ! mkfs.ext4 $dev; then
49         rc=$?
50         echo "mkfs.ext4 on $dev failed"
51         return $rc
52     fi
53     mkdir -p ${mnt}
54     if ! mount -t ext4 $dev $mnt; then
55         rc=$?
56         echo "mount ext4 failed"
57         return $rc
58     fi
59     echo
60     return $rc
61 }
62
63 test_1() {
64     local allnodes="$(comma_list $(nodes_list))"
65     local tfile="$TMP/ext4-file"
66     local mntpnt=$POSIX_SRC/ext4
67     local loopbase
68     local loopdev
69     local rc=0
70
71     # We start at loop1 because posix build uses loop0
72     [ -b /dev/loop/1 ] && loopbase=/dev/loop/
73     [ -b /dev/loop1 ] && loopbase=/dev/loop
74     [ -z "$loopbase" ] && error "/dev/loop/1 and /dev/loop1 gone?"
75
76     for i in `seq 1 7`; do
77         losetup $loopbase$i > /dev/null 2>&1 && continue || true
78         loopdev=$loopbase$i
79         break
80     done
81
82     [ -z "$loopdev" ] && error "Can not find loop device"
83
84     if ! setup_loop_dev $mntpnt $loopdev $tfile; then
85         cleanup_loop_dev "$mntpnt" "$loopdev" "$tfile"
86         error "Setup loop device failed"
87     fi
88
89     # copy the source over to ext mount point
90     if ! cp -af ${POSIX_SRC}/*.* $mntpnt; then
91         cleanup_loop_dev "$mntpnt" "$loopdev" "$tfile"
92         error "Copy POSIX test suite failed"
93     fi
94     export POSIX_SRC=$mntpnt
95     . $POSIX_DIR/posix.cfg
96
97     setup_posix_users $allnodes
98     if ! setup_posix; then
99         delete_posix_users $allnodes
100         cleanup_loop_dev "$POSIX_SRC"
101         cleanup_loop_dev "$mntpnt" "$loopdev" "$tfile"
102         error "Setup POSIX test suite failed"
103     fi
104
105     log "Run POSIX test against lustre filesystem"
106     run_posix $MOUNT compare || \
107         error_noexit "Run POSIX testsuite on $MOUNT failed"
108
109     [[ -d "$MOUNT/TESTROOT" ]] && rm -fr $MOUNT/TESTROOT
110     delete_posix_users $allnodes
111     cleanup_loop_dev "$POSIX_SRC"
112     cleanup_loop_dev "$mntpnt" "$loopdev" "$tfile"
113 }
114 run_test 1 "build, install, run posix on ext4 and lustre, then compare"
115
116 complete $(basename $0) $SECONDS
117 check_and_cleanup_lustre
118 exit_status