+test_78() {
+ [[ $(facet_fstype $SINGLEMDS) != ldiskfs ||
+ $(facet_fstype ost1) != ldiskfs ]] &&
+ skip "only applicable to ldiskfs-based MDTs and OSTs" && return
+
+ # reformat the Lustre filesystem with a smaller size
+ local saved_MDSSIZE=$MDSSIZE
+ local saved_OSTSIZE=$OSTSIZE
+ MDSSIZE=$((MDSSIZE - 20000))
+ OSTSIZE=$((OSTSIZE - 20000))
+ reformat || error "(1) reformat Lustre filesystem failed"
+ MDSSIZE=$saved_MDSSIZE
+ OSTSIZE=$saved_OSTSIZE
+
+ # mount the Lustre filesystem
+ setup_noconfig || error "(2) setup Lustre filesystem failed"
+
+ # create some files
+ log "create test files"
+ local i
+ local file
+ local num_files=100
+ mkdir -p $MOUNT/$tdir || error "(3) mkdir $MOUNT/$tdir failed"
+ for i in $(seq $num_files); do
+ file=$MOUNT/$tdir/$tfile-$i
+ dd if=/dev/urandom of=$file count=1 bs=1M ||
+ error "(4) create $file failed"
+ done
+
+ # unmount the Lustre filesystem
+ cleanup || error "(5) cleanup Lustre filesystem failed"
+
+ # run e2fsck on the MDT and OST devices
+ local mds_host=$(facet_active_host $SINGLEMDS)
+ local ost_host=$(facet_active_host ost1)
+ local mds_dev=$(mdsdevname ${SINGLEMDS//mds/})
+ local ost_dev=$(ostdevname 1)
+
+ run_e2fsck $mds_host $mds_dev "-y"
+ run_e2fsck $ost_host $ost_dev "-y"
+
+ # get the original block count of the MDT and OST filesystems
+ local mds_orig_blks=$(get_block_count $SINGLEMDS $mds_dev)
+ local ost_orig_blks=$(get_block_count ost1 $ost_dev)
+
+ # expand the MDT and OST filesystems to the device size
+ run_resize2fs $SINGLEMDS $mds_dev "" || error "expand $SINGLEMDS failed"
+ run_resize2fs ost1 $ost_dev "" || error "expand ost1 failed"
+
+ # run e2fsck on the MDT and OST devices again
+ run_e2fsck $mds_host $mds_dev "-y"
+ run_e2fsck $ost_host $ost_dev "-y"
+
+ # mount the Lustre filesystem
+ setup
+
+ # check the files
+ log "check files after expanding the MDT and OST filesystems"
+ for i in $(seq $num_files); do
+ file=$MOUNT/$tdir/$tfile-$i
+ $CHECKSTAT -t file -s 1048576 $file ||
+ error "(6) checkstat $file failed"
+ done
+
+ # create more files
+ log "create more files after expanding the MDT and OST filesystems"
+ for i in $(seq $((num_files + 1)) $((num_files + 10))); do
+ file=$MOUNT/$tdir/$tfile-$i
+ dd if=/dev/urandom of=$file count=1 bs=1M ||
+ error "(7) create $file failed"
+ done
+
+ # unmount the Lustre filesystem
+ cleanup || error "(8) cleanup Lustre filesystem failed"
+
+ # run e2fsck on the MDT and OST devices
+ run_e2fsck $mds_host $mds_dev "-y"
+ run_e2fsck $ost_host $ost_dev "-y"
+
+ # get the maximum block count of the MDT and OST filesystems
+ local mds_max_blks=$(get_block_count $SINGLEMDS $mds_dev)
+ local ost_max_blks=$(get_block_count ost1 $ost_dev)
+
+ # get the minimum block count of the MDT and OST filesystems
+ local mds_min_blks=$(run_resize2fs $SINGLEMDS $mds_dev "" "-P" 2>&1 |
+ grep minimum | sed -e 's/^.*filesystem: //g')
+ local ost_min_blks=$(run_resize2fs ost1 $ost_dev "" "-P" 2>&1 |
+ grep minimum | sed -e 's/^.*filesystem: //g')
+
+ # shrink the MDT and OST filesystems to a smaller size
+ local shrunk=false
+ local new_blks
+ local base_blks
+ if [[ $mds_max_blks -gt $mds_min_blks &&
+ $mds_max_blks -gt $mds_orig_blks ]]; then
+ [[ $mds_orig_blks -gt $mds_min_blks ]] &&
+ base_blks=$mds_orig_blks || base_blks=$mds_min_blks
+ new_blks=$(( (mds_max_blks - base_blks) / 2 + base_blks ))
+ run_resize2fs $SINGLEMDS $mds_dev $new_blks ||
+ error "shrink $SINGLEMDS to $new_blks failed"
+ shrunk=true
+ fi
+
+ if [[ $ost_max_blks -gt $ost_min_blks &&
+ $ost_max_blks -gt $ost_orig_blks ]]; then
+ [[ $ost_orig_blks -gt $ost_min_blks ]] &&
+ base_blks=$ost_orig_blks || base_blks=$ost_min_blks
+ new_blks=$(( (ost_max_blks - base_blks) / 2 + base_blks ))
+ run_resize2fs ost1 $ost_dev $new_blks ||
+ error "shrink ost1 to $new_blks failed"
+ shrunk=true
+ fi
+
+ # check whether the MDT or OST filesystem was shrunk or not
+ if ! $shrunk; then
+ combined_mgs_mds || stop_mgs || error "(9) stop mgs failed"
+ reformat || error "(10) reformat Lustre filesystem failed"
+ return 0
+ fi
+
+ # run e2fsck on the MDT and OST devices again
+ run_e2fsck $mds_host $mds_dev "-y"
+ run_e2fsck $ost_host $ost_dev "-y"
+
+ # mount the Lustre filesystem again
+ setup
+
+ # check the files
+ log "check files after shrinking the MDT and OST filesystems"
+ for i in $(seq $((num_files + 10))); do
+ file=$MOUNT/$tdir/$tfile-$i
+ $CHECKSTAT -t file -s 1048576 $file ||
+ error "(11) checkstat $file failed"
+ done
+
+ # unmount and reformat the Lustre filesystem
+ cleanup || error "(12) cleanup Lustre filesystem failed"
+ combined_mgs_mds || stop_mgs || error "(13) stop mgs failed"
+ reformat || error "(14) reformat Lustre filesystem failed"
+}
+run_test 78 "run resize2fs on MDT and OST filesystems"
+