Whamcloud - gitweb
LU-11085 tests: Add performance test for ldlm_extent code
[fs/lustre-release.git] / lustre / tests / sanity-compr.sh
1 #!/bin/bash
2 #
3 # Run select tests by setting ONLY, or as arguments to the script.
4 # Skip specific tests by setting EXCEPT.
5 #
6
7 set -e
8
9 ONLY=${ONLY:-"$*"}
10
11 LUSTRE=${LUSTRE:-$(dirname $0)/..}
12 . $LUSTRE/tests/test-framework.sh
13 init_test_env "$@"
14 init_logging
15
16 # bug number for skipped test:
17 ALWAYS_EXCEPT="$SANITY_COMPR_EXCEPT"
18
19 build_test_filter
20
21 FAIL_ON_ERROR=false
22
23 check_and_setup_lustre
24
25 # $RUNAS_ID may get set incorrectly somewhere else
26 if [[ $UID -eq 0 && $RUNAS_ID -eq 0 ]]; then
27         skip_env "\$RUNAS_ID set to 0, but \$UID is also 0!" && exit
28 fi
29 check_runas_id $RUNAS_ID $RUNAS_GID $RUNAS
30
31 save_layout_restore_at_exit $MOUNT
32 # Set file system with different layout
33 COMPR_EXTRA_LAYOUT=${COMPR_EXTRA_LAYOUT:-"-E EOF -c 1"}
34 $LFS setstripe $COMPR_EXTRA_LAYOUT $MOUNT
35
36 test_sanity()
37 {
38         always_except LU-16928 56wb
39         local rc=0
40
41         SANITY_EXCEPT=$ALWAYS_EXCEPT bash sanity.sh
42         rc=$?
43         return $rc
44 }
45 run_test sanity "Run sanity with PFL layout"
46
47 test_sanityn()
48 {
49         local rc=0
50
51         bash sanityn.sh
52         rc=$?
53         return $rc
54 }
55 run_test sanityn "Run sanityn with PFL layout"
56
57 test_1000() {
58         local blocks=128
59         local dense=$(do_facet ost1 lctl get_param -n \
60                               osd*.*OST0000*.extents_dense)
61         [[ -n $dense ]] || skip "no dense writes supported"
62
63         local osts=$(comma_list $(osts_nodes))
64         do_nodes $osts $LCTL set_param osd*.*.extents_dense=0 ||
65                 error "cannot enable dense extent allocation"
66         stack_trap "do_nodes $osts $LCTL set_param osd*.*.extents_dense=$dense"
67
68         local tf=$DIR/$tfile
69         stack_trap "rm -f $tf"
70         log "create file with dense=0"
71
72         $LFS setstripe -c 1 -i 0 $tf
73         for ((i=0; i<$blocks; i++)); do
74                 dd if=/dev/zero of=$tf bs=32k seek=$((i*2)) count=1 \
75                         oflag=direct >&/dev/null conv=notrunc ||
76                                 error "can't dd (sparse)"
77         done
78         filefrag -sv $tf
79         local nonr=0
80         while read EX LS LE PS PE LEN DEV FLAGS; do
81                 [[ "$EX" == "ext:" || "$EX" =~ "File" ]] && continue
82                 [[ "$EX" == "0:" ]] && PREV=${PE%:} && ((nonr+=1)) && continue
83                 (( ${PS%%.*} == PREV + 1 )) || ((nonr+=1))
84                 PREV=${PE%:}
85         done < <(filefrag -v $tf)
86         (( nonr > 0 )) || error "no extents?"
87         rm -f $tf
88         wait_delete_completed
89
90         do_nodes $osts $LCTL set_param osd*.*.extents_dense=1 ||
91                 error "cannot enable dense extent allocation"
92         #define OBD_FAIL_OSC_MARK_COMPRESSED    0x419
93         $LCTL set_param fail_loc=0x419
94         log "create file with dense=1"
95
96         $LFS setstripe -c 1 -i 0 $tf
97         for ((i=0; i<$blocks; i++)); do
98                 dd if=/dev/zero of=$tf bs=32k seek=$((i*2)) count=1 \
99                         oflag=direct conv=notrunc >&/dev/null ||
100                                 error "can't dd (dense)"
101         done
102         filefrag -sv $tf
103         local nr=0
104         while read EX LS LE PS PE LEN DEV FLAGS; do
105                 [[ "$EX" == "ext:" || "$EX" =~ "File" ]] && continue
106                 [[ "$EX" == "0:" ]] && PREV=${PE%:} && ((nr+=1)) && continue
107                 (( ${PS%%.*} == PREV + 1 )) || ((nr+=1))
108                 PREV=${PE%:}
109         done < <(filefrag -v $tf)
110         (( nr > 0 )) || error "no extents?"
111
112         echo "dense ($nr) should have fewer extents ($nonr)"
113         (( (nonr / nr) > 3 )) ||
114                 error "dense ($nr) should have less extents ($nonr)"
115         $LCTL set_param fail_loc=0
116
117         local tmpfile=$(mktemp)
118         stack_trap "rm -f $tmpfile"
119         echo "generate temp file $tmpfile"
120         dd if=/dev/urandom of=$tmpfile bs=32k count=$((blocks*2)) iflag=fullblock ||
121                 error "can't generate temporary file"
122         dd if=$tmpfile of=$tf bs=32k conv=notrunc
123         cancel_lru_locks osc
124
125         stop ost1 || error "(2) Fail to stop ost1"
126         run_e2fsck $(facet_host ost1) $(ostdevname 1) "-y" ||
127                 error "(3) Fail to run e2fsck error"
128         start ost1 $(ostdevname 1) $OST_MOUNT_OPTS ||
129                 error "(4) Fail to start ost1"
130
131         cmp $tmpfile $tf || error "data mismatch"
132 }
133 run_test 1000 "compressed vs uncompressed allocation"
134
135 test_fsx() {
136         [[ "$ost1_FSTYPE" == "ldiskfs" ]] || skip "need ldiskfs backend"
137         local osts=$(comma_list $(osts_nodes))
138
139         local dense=$(do_facet ost1 lctl get_param -n \
140                               osd*.*OST0000*.extents_dense)
141         [[ -n $dense ]] || skip "no dense writes supported"
142         do_nodes $osts $LCTL set_param osd*.*.extents_dense=1 ||
143                 error "cannot enable dense extent allocation"
144         stack_trap "do_nodes $osts $LCTL set_param osd*.*.extents_dense=$dense"
145
146 #define OBD_FAIL_OSD_MARK_COMPRESSED            0x2302
147         do_nodes $osts $LCTL set_param fail_loc=0x2302 ||
148                 error "cannot force dense writes"
149         stack_trap "do_nodes $osts $LCTL set_param fail_loc=0"
150
151         fsx_STRIPEPARAMS="-E eof -c -1" ONLY=fsx FSX_COUNT=2500 SLOW=yes bash sanity-benchmark.sh
152
153         $DEBUG_ON
154 }
155 run_test fsx "verify dense writes with fsx on ldiskfs"
156
157 complete_test $SECONDS
158 check_and_cleanup_lustre
159 declare -a logs=($ONLY)
160 logs=("${logs[@]/#/$TMP/}")
161 exit_status "$(echo "${logs[@]/%/.log}")"