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}
14 NUMFILES=${NUMFILES:-10}
16 OSTIDX=${OSTIDX:-0} # the OST index in LOV
17 OBJGRP=${OBJGRP:-0} # the OST object group
19 [ -d "$SHARED_DIRECTORY" ] || \
20 { skip "SHARED_DIRECTORY should be specified with a shared directory \
21 which can be accessable on all of the nodes" && exit 0; }
23 which getfattr > /dev/null 2>&1 || { skip "could not find getfattr" && exit 0; }
24 which setfattr > /dev/null 2>&1 || { skip "could not find setfattr" && exit 0; }
27 check_and_setup_lustre
31 SAMPLE_FILE=$TMP/$(basename $0 .sh).junk
32 dd if=/dev/urandom of=$SAMPLE_FILE bs=1M count=1
34 # Create some dirs and files on the filesystem.
43 for d in $(seq -f d%g $first_num $last_num); do
44 echo "creating files in $test_dir/$d"
45 for e in $(seq -f d%g $num_dirs); do
46 mkdir -p $test_dir/$d/$e || error "mkdir $test_dir/$d/$e failed"
47 for f in $(seq -f test%g $num_dirs); do
48 cp $file_name $test_dir/$d/$e/$f || \
49 error "cp $file_name $test_dir/$d/$e/$f failed"
61 # create some files on the filesystem
63 local last_num=$num_dirs
64 create_files_sub $test_dir $num_dirs /etc/fstab $first_num $last_num
66 # create files to be modified
67 for f in $(seq -f $test_dir/testfile.%g $((num_files * 3))); do
69 cp $SAMPLE_FILE $f || error "cp $SAMPLE_FILE $f failed"
72 # create some more files
73 first_num=$((num_dirs * 2 + 1))
74 last_num=$((num_dirs * 2 + 3))
75 create_files_sub $test_dir $num_dirs /etc/hosts $first_num $last_num
77 # these should NOT be taken as duplicates
78 for f in $(seq -f $test_dir/d$last_num/linkfile.%g $num_files); do
79 echo "linking files in $test_dir/d$last_num"
80 cp /etc/hosts $f || error "cp /etc/hosts $f failed"
81 ln $f $f.link || error "ln $f $f.link failed"
85 # Get the objids for files on the OST (given the OST index and object group).
93 ost_objids=$($LFS getstripe $ost_files | \
94 awk '{if ($1 == '$obdidx' && $4 == '$group') print $2 }')
98 # Get the OST nodet name (given the OST index).
105 ost_uuid=$($LFS osts | grep "^$obdidx: " | cut -d' ' -f2 | head -n1)
107 for node in $(osts_nodes); do
108 do_node $node "lctl get_param -n obdfilter.*.uuid" | grep -q $ost_uuid
109 [ ${PIPESTATUS[1]} -eq 0 ] && ost_node=$node && break
111 [ -z "$ost_node" ] && \
112 echo "failed to find the OST with index $obdidx" && return 1
116 # Get the OST target device (given the OST facet name and OST index).
123 ost_name=$($LFS osts | grep "^$obdidx: " | cut -d' ' -f2 | \
124 head -n1 | sed -e 's/_UUID$//')
126 ost_dev=$(do_node $node "lctl get_param -n obdfilter.$ost_name.mntdev")
127 [ ${PIPESTATUS[0]} -ne 0 ] && \
128 echo "failed to find the OST device with index $obdidx on $facet" && \
131 if [[ $ost_dev = *loop* ]]; then
132 ost_dev=$(do_node $node "losetup $ost_dev" | \
133 sed -e "s/.*(//" -e "s/).*//")
139 # Get the file names to be duplicated or removed on the MDS.
149 first=$((num_files + 1))
150 last=$((num_files * 2))
153 first=$((num_files * 2 + 1))
154 last=$((num_files * 3))
156 *) echo "get_files(): invalid flavor" && return 1 ;;
161 for f in $(seq -f testfile.%g $first $last); do
162 test_file=$test_dir/$f
163 files="$files $test_file"
165 files=$(echo $files | sed "s#$DIR/##g")
169 # Remove objects associated with files.
182 echo "removing objects from $ostdev on $facet: $objids"
183 tmp=$(mktemp $SHARED_DIRECTORY/debugfs.XXXXXXXXXX)
185 echo "rm O/$group/d$((i % 32))/$i" >> $tmp
188 do_node $node "$DEBUGFS -w -f $tmp $ostdev"
195 # Remove files from MDS.
197 do_rpc_nodes $(facet_host $1) remove_mdt_files $@
200 # Create EAs on files so objects are referenced from different files.
202 do_rpc_nodes $(facet_host $1) duplicate_mdt_files $@
205 #********************************* Main Flow **********************************#
207 # get the server target devices
210 if [ "$SKIP_LFSCK" = "no" ] && is_empty_fs $MOUNT; then
211 # create test directory
212 TESTDIR=$DIR/d0.$TESTSUITE
213 mkdir -p $TESTDIR || error "mkdir $TESTDIR failed"
215 # create some dirs and files on the filesystem
216 create_files $TESTDIR $NUMDIRS $NUMFILES
218 # get the objids for files in group $OBJGRP on the OST with index $OSTIDX
219 OST_REMOVE=$(get_objects $OSTIDX $OBJGRP \
220 $(seq -f $TESTDIR/testfile.%g $NUMFILES))
222 # get the node name and target device for the OST with index $OSTIDX
223 OSTNODE=$(get_ost_node $OSTIDX) || error "get_ost_node by index $OSTIDX failed"
224 OSTDEV=$(get_ost_dev $OSTNODE $OSTIDX) || \
225 error "get_ost_dev $OSTNODE $OSTIDX failed"
227 # get the file names to be duplicated on the MDS
228 MDS_DUPE=$(get_files dup $TESTDIR $NUMFILES) || error "$MDS_DUPE"
229 # get the file names to be removed from the MDS
230 MDS_REMOVE=$(get_files remove $TESTDIR $NUMFILES) || error "$MDS_REMOVE"
232 stopall -f || error "cleanupall failed"
234 # remove objects associated with files in group $OBJGRP
235 # on the OST with index $OSTIDX
236 remove_objects $OSTNODE $OSTDEV $OBJGRP $OST_REMOVE || \
237 error "removing objects failed"
239 # remove files from MDS
240 remove_files mds $MDSDEV $MDS_REMOVE || error "removing files failed"
242 # create EAs on files so objects are referenced from different files
243 duplicate_files mds $MDSDEV $MDS_DUPE || \
244 error "duplicating files failed"
245 FSCK_MAX_ERR=1 # file system errors corrected
246 else # $SKIP_LFSCK = yes || !is_empty_fs $MOUNT
247 FSCK_MAX_ERR=4 # file system errors left uncorrected
250 # Test 1a - check and repair the filesystem
251 # lfsck will return 1 if the filesystem had errors fixed
252 # run e2fsck to generate databases used for lfsck
254 if [ "$SKIP_LFSCK" != "no" ]; then
259 check_and_setup_lustre
264 if [ $rc -eq 0 ]; then
265 echo "clean after the first check"
267 # run e2fsck again to generate databases used for lfsck
273 if [ $rc -eq 0 ]; then
274 echo "clean after the second check"
276 error "lfsck test 2 - finished with rc=$rc"
283 complete $(basename $0) $SECONDS
284 check_and_cleanup_lustre