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=$(ostuuid_from_index $obdidx)
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=$(ostname_from_index $obdidx)
128 ost_dev=$(do_node $node "lctl get_param -n obdfilter.${ost_name}.mntdev")
129 [ ${PIPESTATUS[0]} -ne 0 ] && \
130 echo "failed to find the OST device with index $obdidx on $facet" && \
133 if [[ $ost_dev = *loop* ]]; then
134 ost_dev=$(do_node $node "losetup $ost_dev" | \
135 sed -e "s/.*(//" -e "s/).*//")
141 # Get the file names to be duplicated or removed on the MDS.
151 first=$((num_files + 1))
152 last=$((num_files * 2))
155 first=$((num_files * 2 + 1))
156 last=$((num_files * 3))
158 *) echo "get_files(): invalid flavor" && return 1 ;;
163 for f in $(seq -f testfile.%g $first $last); do
164 test_file=$test_dir/$f
165 files="$files $test_file"
167 files=$(echo $files | sed "s#$DIR/##g")
171 # Remove objects associated with files.
184 echo "removing objects from $ostdev on $facet: $objids"
185 tmp=$(mktemp $SHARED_DIRECTORY/debugfs.XXXXXXXXXX)
187 echo "rm O/$group/d$((i % 32))/$i" >> $tmp
190 do_node $node "$DEBUGFS -w -f $tmp $ostdev"
197 # Remove files from MDS.
199 do_rpc_nodes $(facet_host $1) remove_mdt_files $@
202 # Create EAs on files so objects are referenced from different files.
204 do_rpc_nodes $(facet_host $1) duplicate_mdt_files $@
207 #********************************* Main Flow **********************************#
211 # get the server target devices
214 if is_empty_fs $MOUNT; then
215 # create test directory
216 TESTDIR=$DIR/d0.$TESTSUITE
217 mkdir -p $TESTDIR || error "mkdir $TESTDIR failed"
219 # create some dirs and files on the filesystem
220 create_files $TESTDIR $NUMDIRS $NUMFILES
222 # get the objids for files in group $OBJGRP on the OST with index $OSTIDX
223 OST_REMOVE=$(get_objects $OSTIDX $OBJGRP \
224 $(seq -f $TESTDIR/testfile.%g $NUMFILES))
226 # get the node name and target device for the OST with index $OSTIDX
227 OSTNODE=$(get_ost_node $OSTIDX) || error "get_ost_node by index $OSTIDX failed"
228 OSTDEV=$(get_ost_dev $OSTNODE $OSTIDX) || \
229 error "get_ost_dev $OSTNODE $OSTIDX failed"
231 # get the file names to be duplicated on the MDS
232 MDS_DUPE=$(get_files dup $TESTDIR $NUMFILES) || error "$MDS_DUPE"
233 # get the file names to be removed from the MDS
234 MDS_REMOVE=$(get_files remove $TESTDIR $NUMFILES) || error "$MDS_REMOVE"
236 stopall -f || error "cleanupall failed"
238 # remove objects associated with files in group $OBJGRP
239 # on the OST with index $OSTIDX
240 remove_objects $OSTNODE $OSTDEV $OBJGRP $OST_REMOVE || \
241 error "removing objects failed"
243 # remove files from MDS
244 remove_files $SINGLEMDS $MDTDEV $MDS_REMOVE || error "removing files failed"
246 # create EAs on files so objects are referenced from different files
247 duplicate_files $SINGLEMDS $MDTDEV $MDS_DUPE || \
248 error "duplicating files failed"
249 FSCK_MAX_ERR=1 # file system errors corrected
250 else # is_empty_fs $MOUNT
251 FSCK_MAX_ERR=4 # file system errors left uncorrected
254 # Test 1a - check and repair the filesystem
255 # lfsck will return 1 if the filesystem had errors fixed
256 # run e2fsck to generate databases used for lfsck
261 check_and_setup_lustre
266 if [ $rc -eq 0 ]; then
267 echo "clean after the first check"
269 # run e2fsck again to generate databases used for lfsck
275 if [ $rc -eq 0 ]; then
276 echo "clean after the second check"
278 error "lfsck test 2 - finished with rc=$rc"
282 complete $(basename $0) $SECONDS
283 check_and_cleanup_lustre