Whamcloud - gitweb
LU-5710 all: second batch of corrected typos and grammar errors
[fs/lustre-release.git] / lustre / tests / large-lun.sh
1 #!/bin/bash
2 #
3 # This script is used to test large size LUN support in Lustre.
4 #
5 ################################################################################
6 set -e
7
8 LUSTRE=${LUSTRE:-$(cd $(dirname $0)/..; echo $PWD)}
9 . $LUSTRE/tests/test-framework.sh
10 init_test_env $@
11 . ${CONFIG:=$LUSTRE/tests/cfg/$NAME.sh}
12 init_logging
13
14 # Variable to run mdsrate
15 THREADS_PER_CLIENT=${THREADS_PER_CLIENT:-5}    # thread(s) per client node
16 MACHINEFILE=${MACHINEFILE:-$TMP/$TESTSUITE.machines}
17 NODES_TO_USE=${NODES_TO_USE:-$CLIENTS}
18 NUM_CLIENTS=$(get_node_count ${NODES_TO_USE//,/ })
19
20 # bug number:
21 ALWAYS_EXCEPT="$LARGE_LUN_EXCEPT"
22
23 build_test_filter
24 LARGE_LUN_RESTORE_MOUNT=false
25 if is_mounted $MOUNT || is_mounted $MOUNT2; then
26         LARGE_LUN_RESTORE_MOUNT=true
27 fi
28 # Unmount and cleanup the Lustre filesystem
29 cleanupall
30 load_modules
31
32 FULL_MODE=${FULL_MODE:-false}
33 RUN_FSCK=${RUN_FSCK:-true}
34 # if SLOW=yes, enable the FULL_MODE
35 [[ $SLOW = yes ]] && FULL_MODE=true
36 #########################################################################
37 # Dump the super block information for the filesystem present on device.
38 run_dumpfs() {
39         local facet=$1
40         local dev=$2
41         local cmd
42
43         log "dump the super block information on $facet device $dev"
44         local fstype=$(facet_fstype $facet)
45
46         case $fstype in
47                 ldiskfs )
48                         cmd="$DUMPE2FS -h $dev" ;;
49                 zfs )
50                         cmd="$ZDB -l $(facet_vdevice $facet)" ;;
51                 * )
52                         error "unknown fstype!" ;;
53         esac
54
55         do_facet $facet "$cmd"
56 }
57
58 # Report Lustre filesystem disk space usage and inodes usage of each MDT/OST.
59 client_df() {
60         local mnt_pnt=$1
61         local cmd
62
63         cmd="df -h"
64         echo -e "\n# $cmd"
65         eval $cmd
66
67         cmd="lfs df -h $mnt_pnt"
68         echo -e "\n# $cmd"
69         eval $cmd
70
71         cmd="lfs df -i $mnt_pnt"
72         echo -e "\n# $cmd"
73         eval $cmd
74 }
75
76 # Cleanup the directories and files created by llverfs utility.
77 cleanup_dirs() {
78         local target=$1
79         local mnt=${2:-$MOUNT}
80         local cmd="rm -rf $mnt/{*.filecount,dir*}"
81         do_facet $target "$cmd"
82 }
83
84 # Run mdsrate.
85 run_mdsrate() {
86         generate_machine_file $NODES_TO_USE $MACHINEFILE ||
87                 error "can not generate machinefile"
88
89         # set the default stripe count for files in this test to one
90         local testdir=$MOUNT/mdsrate
91         mkdir -p $testdir
92         chmod 0777 $testdir
93         $LFS setstripe $testdir -i 0 -c 1
94         get_stripe $testdir
95
96         local num_dirs=$THREADS_PER_CLIENT
97         [[ $num_dirs -eq 0 ]] && num_dirs=1
98         local free_inodes=$(lfs df -i $MOUNT | grep "OST:0" | awk '{print $4}')
99         local num_files
100         num_files=$((free_inodes / num_dirs))
101
102         local command="$MDSRATE $MDSRATE_DEBUG --create --verbose \
103                 --ndirs $num_dirs --dirfmt '$testdir/dir%d' \
104                 --nfiles $num_files --filefmt 'file%%d'"
105
106         echo "# $command"
107         mpi_run -machinefile $MACHINEFILE \
108                 -np $((NUM_CLIENTS * THREADS_PER_CLIENT)) $command
109
110         if [ ${PIPESTATUS[0]} != 0 ]; then
111                 error "mdsrate create failed"
112         fi
113 }
114
115 check_fsfacet() {
116         local facet=$1
117         local fstype=$(facet_fstype $facet)
118
119         case $fstype in
120             ldiskfs)
121                 run_e2fsck $(facet_active_host $facet) $(facet_device $facet) \
122                     "-y" || error "run e2fsck error"
123                 ;;
124             zfs)
125                 # Could call fsck.zfs, but currently it does nothing,
126                 # Could also call zpool scrub, but that could take a LONG time
127                 # do_facet $facet "fsck.zfs $(facet_device $facet)"
128                 ;;
129         esac
130 }
131
132 # Run e2fsck on MDS and OST
133 do_fsck() {
134         $RUN_FSCK || return
135
136         check_fsfacet $SINGLEMDS
137
138         for num in $(seq $OSTCOUNT); do
139                 check_fsfacet ost${num}
140         done
141 }
142 ################################## Main Flow ###################################
143 trap cleanupall EXIT
144
145 test_1 () {
146         [ $(facet_fstype $SINGLEMDS) != ldiskfs ] &&
147                 skip "Only applicable to ldiskfs-based nodes" && return
148         local dev
149         for num in $(seq $OSTCOUNT); do
150                 dev=$(ostdevname $num)
151                 log "run llverdev on the OST $dev"
152                 do_rpc_nodes $(facet_host ost${num}) run_llverdev $dev -vpf ||
153                         error "llverdev on $dev failed!"
154         done
155 }
156 run_test 1 "run llverdev on raw LUN"
157
158 test_2 () {
159         local dev
160         local ostmnt
161         local fstype
162
163         for num in $(seq $OSTCOUNT); do
164                 dev=$(ostdevname $num)
165                 ostmnt=$(facet_mntpt ost${num})
166                 fstype=$(facet_fstype ost${num})
167
168                 # Mount the OST as an ldiskfs filesystem.
169                 log "mount the OST $dev as a $fstype filesystem"
170                 add ost${num} $(mkfs_opts ost${num} $dev) $FSTYPE_OPT \
171                         --reformat $(ostdevname $num) \
172                         $(ostvdevname $num) > /dev/null ||
173                         error "format ost${num} error"
174                 if [ $fstype == zfs ]; then
175                         import_zpool ost${num}
176                         do_facet ost${num} "$ZFS set canmount=on $dev; " \
177                             "$ZFS set mountpoint=legacy $dev; $ZFS list $dev"
178                 fi
179                 run_dumpfs ost${num} $dev
180                 do_facet ost${num} mount -t $fstype $dev \
181                         $ostmnt "$OST_MOUNT_OPTS"
182
183                 # Run llverfs on the mounted ldiskfs filesystem in partial mode
184                 # to ensure that the kernel can perform filesystem operations
185                 # on the complete device without any errors.
186                 log "run llverfs in partial mode on the OST $fstype $ostmnt"
187                 do_rpc_nodes $(facet_host ost${num}) run_llverfs $ostmnt -vpl \
188                         "no" || error "run_llverfs error on $fstype"
189
190                 # Unmount the OST.
191                 log "unmount the OST $dev"
192                 stop ost${num}
193
194                 # After llverfs is run on the ldiskfs filesystem in partial
195                 # mode, a full e2fsck should be run to catch any errors early.
196                 $RUN_FSCK && check_fsfacet ost${num}
197
198                 if $FULL_MODE; then
199                         log "full mode, mount the OST $dev as a $fstype again"
200                         if [ $fstype == zfs ]; then
201                                 import_zpool ost${num}
202                         fi
203                         do_facet ost${num} mount -t $(facet_fstype ost${num}) \
204                                 $dev $ostmnt "$OST_MOUNT_OPTS"
205                         cleanup_dirs ost${num} $ostmnt
206                         do_facet ost${num} "sync"
207
208                         run_dumpfs ost${num} $dev
209
210                         # Run llverfs on the mounted ldiskfs filesystem in full
211                         # mode to ensure that the kernel can perform filesystem
212                         # operations on the complete device without any errors.
213                         log "run llverfs in full mode on OST $fstype $ostmnt"
214                         do_rpc_nodes $(facet_host ost${num}) run_llverfs \
215                                 $ostmnt -vl "no" ||
216                                 error "run_llverfs error on $fstype"
217
218                         # Unmount the OST.
219                         log "unmount the OST $dev"
220                         stop ost${num}
221
222                         # After llverfs is run on the ldiskfs filesystem in
223                         # full mode, a full e2fsck should be run to catch any
224                         #  errors early.
225                         $RUN_FSCK && check_fsfacet ost${num}
226                 fi
227         done
228 }
229 run_test 2 "run llverfs on OST ldiskfs/zfs filesystem"
230
231 test_3 () {
232         [ -z "$CLIENTS" ] && skip_env "CLIENTS not defined, skipping" && return
233         [ -z "$MPIRUN" ] && skip_env "MIPRUN not defined, skipping" && return
234         [ -z "$MDSRATE" ] && skip_env "MDSRATE not defined, skipping" && return
235         [ ! -x $MDSRATE ] && skip_env "$MDSRATE not built, skipping" && return
236         # Setup the Lustre filesystem.
237         log "setup the lustre filesystem"
238         REFORMAT="yes" check_and_setup_lustre
239
240         log "run mdsrate to use up the free inodes."
241         # Run the mdsrate test suite.
242         run_mdsrate
243         client_df $MOUNT
244
245         sync; sleep 5; sync
246         stopall
247         do_fsck
248 }
249 run_test 3 "use up free inodes on the OST with mdsrate"
250
251 test_4 () {
252         # Setup the Lustre filesystem.
253         log "setup the lustre filesystem"
254         REFORMAT="yes" check_and_setup_lustre
255         local dev
256
257         for num in $(seq $OSTCOUNT); do
258                 dev=$(ostdevname $num)
259                 run_dumpfs ost${num} $dev
260         done
261
262         # Run llverfs on the mounted Lustre filesystem both in partial and
263         # full mode to to fill the filesystem and verify the file contents.
264         log "run llverfs in partial mode on the Lustre filesystem $MOUNT"
265         run_llverfs $MOUNT -vp "no" || error "run_llverfs error on lustre"
266         client_df $MOUNT
267
268         sync; sleep 5; sync
269         stopall
270         do_fsck
271
272         if $FULL_MODE; then
273                 # Setup the Lustre filesystem again.
274                 log "setup the lustre filesystem again"
275                 setupall
276
277                 cleanup_dirs client $MOUNT
278                 sync
279                 client_df $MOUNT
280
281                 for num in $(seq $OSTCOUNT); do
282                         dev=$(ostdevname $num)
283                         run_dumpfs ost${num} $dev
284                 done
285
286                 log "run llverfs in full mode on the Lustre filesystem $MOUNT"
287                 run_llverfs $MOUNT -vl "no" ||
288                         error "run_llverfs error on lustre"
289                 client_df $MOUNT
290
291                 sync; sleep 5; sync
292                 stopall
293                 do_fsck
294         fi
295 }
296 run_test 4 "run llverfs on lustre filesystem"
297
298 complete $SECONDS
299 $LARGE_LUN_RESTORE_MOUNT && setupall
300 check_and_cleanup_lustre
301 exit_status