3 # test e2fsck and lfsck to detect and fix filesystem corruption
8 LUSTRE=${LUSTRE:-$(cd $(dirname $0)/..; echo $PWD)}
9 . $LUSTRE/tests/test-framework.sh
11 . ${CONFIG:=$LUSTRE/tests/cfg/$NAME.sh}
13 NUMFILES=${NUMFILES:-10}
15 OSTIDX=${OSTIDX:-0} # the OST index in LOV
16 OBJGRP=${OBJGRP:-0} # the OST object group
18 [ -d "$SHARED_DIRECTORY" ] || \
19 { skip "SHARED_DIRECTORY should be specified with a shared directory \
20 which can be accessable on all of the nodes" && exit 0; }
22 which getfattr &>/dev/null || { skip_env "could not find getfattr" && exit 0; }
23 which setfattr &>/dev/null || { skip_env "could not find setfattr" && exit 0; }
25 if [ ! -x `which $LFSCK_BIN` ]; then
27 error "e2fsprogs does not support lfsck"
31 check_and_setup_lustre
35 SAMPLE_FILE=$TMP/$(basename $0 .sh).junk
36 dd if=/dev/urandom of=$SAMPLE_FILE bs=1M count=1
38 # Create some dirs and files on the filesystem.
47 for d in $(seq -f d%g $first_num $last_num); do
48 echo "creating files in $test_dir/$d"
49 for e in $(seq -f d%g $num_dirs); do
50 mkdir -p $test_dir/$d/$e || error "mkdir $test_dir/$d/$e failed"
51 for f in $(seq -f test%g $num_dirs); do
52 cp $file_name $test_dir/$d/$e/$f || \
53 error "cp $file_name $test_dir/$d/$e/$f failed"
65 # create some files on the filesystem
67 local last_num=$num_dirs
68 create_files_sub $test_dir $num_dirs /etc/fstab $first_num $last_num
70 # create files to be modified
71 for f in $(seq -f $test_dir/testfile.%g $((num_files * 3))); do
73 cp $SAMPLE_FILE $f || error "cp $SAMPLE_FILE $f failed"
76 # create some more files
77 first_num=$((num_dirs * 2 + 1))
78 last_num=$((num_dirs * 2 + 3))
79 create_files_sub $test_dir $num_dirs /etc/hosts $first_num $last_num
81 # these should NOT be taken as duplicates
82 for f in $(seq -f $test_dir/d$last_num/linkfile.%g $num_files); do
83 echo "linking files in $test_dir/d$last_num"
84 cp /etc/hosts $f || error "cp /etc/hosts $f failed"
85 ln $f $f.link || error "ln $f $f.link failed"
89 # Get the objids for files on the OST (given the OST index and object group).
97 ost_objids=$($LFS getstripe $ost_files | \
98 awk '{if ($1 == '$obdidx' && $4 == '$group') print $2 }')
102 # Get the OST nodet name (given the OST index).
109 ost_uuid=$($LFS osts | grep "^$obdidx: " | cut -d' ' -f2 | head -n1)
111 for node in $(osts_nodes); do
112 do_node $node "lctl get_param -n obdfilter.*.uuid" | grep -q $ost_uuid
113 [ ${PIPESTATUS[1]} -eq 0 ] && ost_node=$node && break
115 [ -z "$ost_node" ] && \
116 echo "failed to find the OST with index $obdidx" && return 1
120 # Get the OST target device (given the OST facet name and OST index).
127 ost_name=$($LFS osts | grep "^$obdidx: " | cut -d' ' -f2 | \
128 head -n1 | sed -e 's/_UUID$//')
130 ost_dev=$(do_node $node "lctl get_param -n obdfilter.$ost_name.mntdev")
131 [ ${PIPESTATUS[0]} -ne 0 ] && \
132 echo "failed to find the OST device with index $obdidx on $facet" && \
135 if [[ $ost_dev = *loop* ]]; then
136 ost_dev=$(do_node $node "losetup $ost_dev" | \
137 sed -e "s/.*(//" -e "s/).*//")
143 # Get the file names to be duplicated or removed on the MDS.
153 first=$((num_files + 1))
154 last=$((num_files * 2))
157 first=$((num_files * 2 + 1))
158 last=$((num_files * 3))
160 *) echo "get_files(): invalid flavor" && return 1 ;;
165 for f in $(seq -f testfile.%g $first $last); do
166 test_file=$test_dir/$f
167 files="$files $test_file"
169 files=$(echo $files | sed "s#$DIR/##g")
173 # Remove objects associated with files.
186 echo "removing objects from $ostdev on $facet: $objids"
187 tmp=$(mktemp $SHARED_DIRECTORY/debugfs.XXXXXXXXXX)
189 echo "rm O/$group/d$((i % 32))/$i" >> $tmp
192 do_node $node "$DEBUGFS -w -f $tmp $ostdev"
199 # Remove files from MDS.
201 do_rpc_nodes $(facet_host $1) remove_mdt_files $@
204 # Create EAs on files so objects are referenced from different files.
206 do_rpc_nodes $(facet_host $1) duplicate_mdt_files $@
209 #********************************* Main Flow **********************************#
213 # get the server target devices
216 if is_empty_fs $MOUNT; then
217 # create test directory
218 TESTDIR=$DIR/d0.$TESTSUITE
219 mkdir -p $TESTDIR || error "mkdir $TESTDIR failed"
221 # create some dirs and files on the filesystem
222 create_files $TESTDIR $NUMDIRS $NUMFILES
224 # get the objids for files in group $OBJGRP on the OST with index $OSTIDX
225 OST_REMOVE=$(get_objects $OSTIDX $OBJGRP \
226 $(seq -f $TESTDIR/testfile.%g $NUMFILES))
228 # get the node name and target device for the OST with index $OSTIDX
229 OSTNODE=$(get_ost_node $OSTIDX) || error "get_ost_node by index $OSTIDX failed"
230 OSTDEV=$(get_ost_dev $OSTNODE $OSTIDX) || \
231 error "get_ost_dev $OSTNODE $OSTIDX failed"
233 # get the file names to be duplicated on the MDS
234 MDS_DUPE=$(get_files dup $TESTDIR $NUMFILES) || error "$MDS_DUPE"
235 # get the file names to be removed from the MDS
236 MDS_REMOVE=$(get_files remove $TESTDIR $NUMFILES) || error "$MDS_REMOVE"
238 stopall -f || error "cleanupall failed"
240 # remove objects associated with files in group $OBJGRP
241 # on the OST with index $OSTIDX
242 remove_objects $OSTNODE $OSTDEV $OBJGRP $OST_REMOVE || \
243 error "removing objects failed"
245 # remove files from MDS
246 remove_files $SINGLEMDS $MDTDEV $MDS_REMOVE || error "removing files failed"
248 # create EAs on files so objects are referenced from different files
249 duplicate_files $SINGLEMDS $MDTDEV $MDS_DUPE || \
250 error "duplicating files failed"
251 FSCK_MAX_ERR=1 # file system errors corrected
252 else # is_empty_fs $MOUNT
253 FSCK_MAX_ERR=4 # file system errors left uncorrected
256 # Test 1a - check and repair the filesystem
257 # lfsck will return 1 if the filesystem had errors fixed
258 # run e2fsck to generate databases used for lfsck
263 check_and_setup_lustre
268 if [ $rc -eq 0 ]; then
269 echo "clean after the first check"
271 # run e2fsck again to generate databases used for lfsck
277 if [ $rc -eq 0 ]; then
278 echo "clean after the second check"
280 error "lfsck test 2 - finished with rc=$rc"
284 complete $(basename $0) $SECONDS
285 check_and_cleanup_lustre