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 2>&1 || { skip "could not find getfattr" && exit 0; }
23 which setfattr > /dev/null 2>&1 || { skip "could not find setfattr" && exit 0; }
26 check_and_setup_lustre
30 SAMPLE_FILE=$TMP/$(basename $0 .sh).junk
31 dd if=/dev/urandom of=$SAMPLE_FILE bs=1M count=1
33 # Create some dirs and files on the filesystem.
42 for d in $(seq -f d%g $first_num $last_num); do
43 echo "creating files in $test_dir/$d"
44 for e in $(seq -f d%g $num_dirs); do
45 mkdir -p $test_dir/$d/$e || error "mkdir $test_dir/$d/$e failed"
46 for f in $(seq -f test%g $num_dirs); do
47 cp $file_name $test_dir/$d/$e/$f || \
48 error "cp $file_name $test_dir/$d/$e/$f failed"
60 # create some files on the filesystem
62 local last_num=$num_dirs
63 create_files_sub $test_dir $num_dirs /etc/fstab $first_num $last_num
65 # create files to be modified
66 for f in $(seq -f $test_dir/testfile.%g $((num_files * 3))); do
68 cp $SAMPLE_FILE $f || error "cp $SAMPLE_FILE $f failed"
71 # create some more files
72 first_num=$((num_dirs * 2 + 1))
73 last_num=$((num_dirs * 2 + 3))
74 create_files_sub $test_dir $num_dirs /etc/hosts $first_num $last_num
76 # these should NOT be taken as duplicates
77 for f in $(seq -f $test_dir/d$last_num/linkfile.%g $num_files); do
78 echo "linking files in $test_dir/d$last_num"
79 cp /etc/hosts $f || error "cp /etc/hosts $f failed"
80 ln $f $f.link || error "ln $f $f.link failed"
84 # Get the objids for files on the OST (given the OST index and object group).
92 ost_objids=$($LFS getstripe $ost_files | \
93 awk '{if ($1 == '$obdidx' && $4 == '$group') print $2 }')
97 # Get the OST nodet name (given the OST index).
104 ost_uuid=$($LFS osts | grep "^$obdidx: " | cut -d' ' -f2 | head -n1)
106 for node in $(osts_nodes); do
107 do_node $node "lctl get_param -n obdfilter.*.uuid" | grep -q $ost_uuid
108 [ ${PIPESTATUS[1]} -eq 0 ] && ost_node=$node && break
110 [ -z "$ost_node" ] && \
111 echo "failed to find the OST with index $obdidx" && return 1
115 # Get the OST target device (given the OST facet name and OST index).
122 ost_name=$($LFS osts | grep "^$obdidx: " | cut -d' ' -f2 | \
123 head -n1 | sed -e 's/_UUID$//')
125 ost_dev=$(do_node $node "lctl get_param -n obdfilter.$ost_name.mntdev")
126 [ ${PIPESTATUS[0]} -ne 0 ] && \
127 echo "failed to find the OST device with index $obdidx on $facet" && \
130 if [[ $ost_dev = *loop* ]]; then
131 ost_dev=$(do_node $node "losetup $ost_dev" | \
132 sed -e "s/.*(//" -e "s/).*//")
138 # Get the file names to be duplicated or removed on the MDS.
148 first=$((num_files + 1))
149 last=$((num_files * 2))
152 first=$((num_files * 2 + 1))
153 last=$((num_files * 3))
155 *) echo "get_files(): invalid flavor" && return 1 ;;
160 for f in $(seq -f testfile.%g $first $last); do
161 test_file=$test_dir/$f
162 files="$files $test_file"
164 files=$(echo $files | sed "s#$DIR/##g")
168 # Remove objects associated with files.
181 echo "removing objects from $ostdev on $facet: $objids"
182 tmp=$(mktemp $SHARED_DIRECTORY/debugfs.XXXXXXXXXX)
184 echo "rm O/$group/d$((i % 32))/$i" >> $tmp
187 do_node $node "$DEBUGFS -w -f $tmp $ostdev"
194 # Remove files from MDS.
196 do_rpc_nodes $(facet_host $1) remove_mdt_files $@
199 # Create EAs on files so objects are referenced from different files.
201 do_rpc_nodes $(facet_host $1) duplicate_mdt_files $@
204 #********************************* Main Flow **********************************#
208 # get the server target devices
211 if [ "$SKIP_LFSCK" = "no" ] && is_empty_fs $MOUNT; then
212 # create test directory
213 TESTDIR=$DIR/d0.$TESTSUITE
214 mkdir -p $TESTDIR || error "mkdir $TESTDIR failed"
216 # create some dirs and files on the filesystem
217 create_files $TESTDIR $NUMDIRS $NUMFILES
219 # get the objids for files in group $OBJGRP on the OST with index $OSTIDX
220 OST_REMOVE=$(get_objects $OSTIDX $OBJGRP \
221 $(seq -f $TESTDIR/testfile.%g $NUMFILES))
223 # get the node name and target device for the OST with index $OSTIDX
224 OSTNODE=$(get_ost_node $OSTIDX) || error "get_ost_node by index $OSTIDX failed"
225 OSTDEV=$(get_ost_dev $OSTNODE $OSTIDX) || \
226 error "get_ost_dev $OSTNODE $OSTIDX failed"
228 # get the file names to be duplicated on the MDS
229 MDS_DUPE=$(get_files dup $TESTDIR $NUMFILES) || error "$MDS_DUPE"
230 # get the file names to be removed from the MDS
231 MDS_REMOVE=$(get_files remove $TESTDIR $NUMFILES) || error "$MDS_REMOVE"
233 stopall -f || error "cleanupall failed"
235 # remove objects associated with files in group $OBJGRP
236 # on the OST with index $OSTIDX
237 remove_objects $OSTNODE $OSTDEV $OBJGRP $OST_REMOVE || \
238 error "removing objects failed"
240 # remove files from MDS
241 remove_files $SINGLEMDS $MDTDEV $MDS_REMOVE || error "removing files failed"
243 # create EAs on files so objects are referenced from different files
244 duplicate_files $SINGLEMDS $MDTDEV $MDS_DUPE || \
245 error "duplicating files failed"
246 FSCK_MAX_ERR=1 # file system errors corrected
248 FSCK_MAX_ERR=4 # file system errors left uncorrected
251 # Test 1a - check and repair the filesystem
252 # lfsck will return 1 if the filesystem had errors fixed
253 # run e2fsck to generate databases used for lfsck
255 if [ "$SKIP_LFSCK" != "no" ]; then
260 check_and_setup_lustre
265 if [ $rc -eq 0 ]; then
266 echo "clean after the first check"
268 # run e2fsck again to generate databases used for lfsck
274 if [ $rc -eq 0 ]; then
275 echo "clean after the second check"
277 error "lfsck test 2 - finished with rc=$rc"
284 complete $(basename $0) $SECONDS
285 check_and_cleanup_lustre