2 # -*- mode: Bash; tab-width: 4; indent-tabs-mode: t; -*-
3 # vim:shiftwidth=4:softtabstop=4:tabstop=4:
5 # test e2fsck and lfsck to detect and fix filesystem corruption
10 LUSTRE=${LUSTRE:-$(cd $(dirname $0)/..; echo $PWD)}
11 . $LUSTRE/tests/test-framework.sh
13 . ${CONFIG:=$LUSTRE/tests/cfg/$NAME.sh}
15 NUMFILES=${NUMFILES:-10}
17 OSTIDX=${OSTIDX:-0} # the OST index in LOV
18 OBJGRP=${OBJGRP:-0} # the OST object group
20 [ -d "$SHARED_DIRECTORY" ] || \
21 { skip "SHARED_DIRECTORY should be specified with a shared directory \
22 which can be accessable on all of the nodes" && exit 0; }
24 which getfattr &>/dev/null || { skip_env "could not find getfattr" && exit 0; }
25 which setfattr &>/dev/null || { skip_env "could not find setfattr" && exit 0; }
27 if [ ! -x `which $LFSCK_BIN` ]; then
29 error "e2fsprogs does not support lfsck"
33 check_and_setup_lustre
37 SAMPLE_FILE=$TMP/$(basename $0 .sh).junk
38 dd if=/dev/urandom of=$SAMPLE_FILE bs=1M count=1
40 # Create some dirs and files on the filesystem.
49 for d in $(seq -f d%g $first_num $last_num); do
50 echo "creating files in $test_dir/$d"
51 for e in $(seq -f d%g $num_dirs); do
52 mkdir -p $test_dir/$d/$e || error "mkdir $test_dir/$d/$e failed"
53 for f in $(seq -f test%g $num_dirs); do
54 cp $file_name $test_dir/$d/$e/$f || \
55 error "cp $file_name $test_dir/$d/$e/$f failed"
67 # create some files on the filesystem
69 local last_num=$num_dirs
70 create_files_sub $test_dir $num_dirs /etc/fstab $first_num $last_num
72 # create files to be modified
73 for f in $(seq -f $test_dir/testfile.%g $((num_files * 3))); do
75 cp $SAMPLE_FILE $f || error "cp $SAMPLE_FILE $f failed"
78 # create some more files
79 first_num=$((num_dirs * 2 + 1))
80 last_num=$((num_dirs * 2 + 3))
81 create_files_sub $test_dir $num_dirs /etc/hosts $first_num $last_num
83 # these should NOT be taken as duplicates
84 for f in $(seq -f $test_dir/d$last_num/linkfile.%g $num_files); do
85 echo "linking files in $test_dir/d$last_num"
86 cp /etc/hosts $f || error "cp /etc/hosts $f failed"
87 ln $f $f.link || error "ln $f $f.link failed"
91 # Get the objids for files on the OST (given the OST index and object group).
99 ost_objids=$($LFS getstripe $ost_files | \
100 awk '{if ($1 == '$obdidx' && $4 == '$group') print $2 }')
104 # Get the OST nodet name (given the OST index).
111 ost_uuid=$(ostuuid_from_index $obdidx)
113 for node in $(osts_nodes); do
114 do_node $node "lctl get_param -n obdfilter.*.uuid" | grep -q $ost_uuid
115 [ ${PIPESTATUS[1]} -eq 0 ] && ost_node=$node && break
117 [ -z "$ost_node" ] && \
118 echo "failed to find the OST with index $obdidx" && return 1
122 # Get the OST target device (given the OST facet name and OST index).
129 ost_name=$(ostname_from_index $obdidx)
130 ost_dev=$(get_obdfilter_param $node $ost_name mntdev)
131 if [ $? -ne 0 ]; then
132 printf "unable to find OST%04x on $facet\n" $obdidx
136 if [[ $ost_dev = *loop* ]]; then
137 ost_dev=$(do_node $node "losetup $ost_dev" | \
138 sed -e "s/.*(//" -e "s/).*//")
144 # Get the file names to be duplicated or removed on the MDS.
154 first=$((num_files + 1))
155 last=$((num_files * 2))
158 first=$((num_files * 2 + 1))
159 last=$((num_files * 3))
161 *) echo "get_files(): invalid flavor" && return 1 ;;
166 for f in $(seq -f testfile.%g $first $last); do
167 test_file=$test_dir/$f
168 files="$files $test_file"
170 files=$(echo $files | sed "s#$DIR/##g")
174 # Remove objects associated with files.
187 echo "removing objects from $ostdev on $facet: $objids"
188 tmp=$(mktemp $SHARED_DIRECTORY/debugfs.XXXXXXXXXX)
190 echo "rm O/$group/d$((i % 32))/$i" >> $tmp
193 do_node $node "$DEBUGFS -w -f $tmp $ostdev"
200 # Remove files from MDS.
202 do_rpc_nodes $(facet_host $1) remove_mdt_files $@
205 # Create EAs on files so objects are referenced from different files.
207 do_rpc_nodes $(facet_host $1) duplicate_mdt_files $@
210 #********************************* Main Flow **********************************#
214 # get the server target devices
217 if is_empty_fs $MOUNT; then
218 # create test directory
219 TESTDIR=$DIR/d0.$TESTSUITE
220 mkdir -p $TESTDIR || error "mkdir $TESTDIR failed"
222 # create some dirs and files on the filesystem
223 create_files $TESTDIR $NUMDIRS $NUMFILES
225 # get the objids for files in group $OBJGRP on the OST with index $OSTIDX
226 OST_REMOVE=$(get_objects $OSTIDX $OBJGRP \
227 $(seq -f $TESTDIR/testfile.%g $NUMFILES))
229 # get the node name and target device for the OST with index $OSTIDX
230 OSTNODE=$(get_ost_node $OSTIDX) || error "get_ost_node by index $OSTIDX failed"
231 OSTDEV=$(get_ost_dev $OSTNODE $OSTIDX) || \
232 error "get_ost_dev $OSTNODE $OSTIDX failed"
234 # get the file names to be duplicated on the MDS
235 MDS_DUPE=$(get_files dup $TESTDIR $NUMFILES) || error "$MDS_DUPE"
236 # get the file names to be removed from the MDS
237 MDS_REMOVE=$(get_files remove $TESTDIR $NUMFILES) || error "$MDS_REMOVE"
239 stopall -f || error "cleanupall failed"
241 # remove objects associated with files in group $OBJGRP
242 # on the OST with index $OSTIDX
243 remove_objects $OSTNODE $OSTDEV $OBJGRP $OST_REMOVE || \
244 error "removing objects failed"
246 # remove files from MDS
247 remove_files $SINGLEMDS $MDTDEV $MDS_REMOVE || error "removing files failed"
249 # create EAs on files so objects are referenced from different files
250 duplicate_files $SINGLEMDS $MDTDEV $MDS_DUPE || \
251 error "duplicating files failed"
252 FSCK_MAX_ERR=1 # file system errors corrected
253 else # is_empty_fs $MOUNT
254 FSCK_MAX_ERR=4 # file system errors left uncorrected
257 # Test 1a - check and repair the filesystem
258 # lfsck will return 1 if the filesystem had errors fixed
259 # run e2fsck to generate databases used for lfsck
264 check_and_setup_lustre
269 if [ $rc -eq 0 ]; then
270 echo "clean after the first check"
272 # run e2fsck again to generate databases used for lfsck
278 if [ $rc -eq 0 ]; then
279 echo "clean after the second check"
281 error "lfsck test 2 - finished with rc=$rc"
285 complete $(basename $0) $SECONDS
286 check_and_cleanup_lustre