[Ocfs2-test-devel] fsck-test: Add test to check directory compression
Goldwyn Rodrigues
rgoldwyn at gmail.com
Tue Aug 25 12:19:55 PDT 2009
Add a test to check directory compression in fsck. The test checks that
there is no data loss in terms of file listing while performing the
compression.
The test sequence is:
1. Create files under directories
2. Remove alternate files from the directories
3. Get recursive directory listing and store in listing1
4. Perform fsck -D
5. Get recursive directory listing and store in listing2
6. Compare listing1 and listing2 to check if any files are missing.
Signed-off-by: Goldwyn Rodrigues <rgoldwyn at suse.de>
---
diff --git a/programs/fsck-tests/fsck-test.sh b/programs/fsck-tests/fsck-test.sh
index 2edbd7b..85484f0 100755
--- a/programs/fsck-tests/fsck-test.sh
+++ b/programs/fsck-tests/fsck-test.sh
@@ -130,6 +130,8 @@ function internal_setup()
BASE_DIR=${O2TDIR}
TMP_DIR="/tmp/${0##*/}-$$"
mkdir -p "$TMP_DIR"
+ MOUNT_POINT="/tmp/mp.$$"
+ mkdir -p "$MOUNT_POINT"
check_exec_or_exit cat mktemp wc yes
}
@@ -148,6 +150,11 @@ function internal_cleanup()
rm -rf "$TMP_DIR"
unset TMP_DIR
fi
+ if [ "$MOUNT_POINT" ]
+ then
+ rm -rf "$MOUNT_POINT"
+ unset MOUNT_POINT
+ fi
}
#
@@ -169,6 +176,7 @@ function usage()
--with-fswreck=PROGRAM use the PROGRAM as fswreck
--with-mkfs=PROGRAM use the PROGRAM as mkfs.ocfs2
--with-corrupt=CORRUPTS use specified fswreck corrupt code
+ --with-mount=PROGRAM use specified fswreck corrupt code
Examples:
@@ -185,6 +193,8 @@ DEVICE=""
MKFS_BIN=""
FSCK_BIN=""
FSWRECK_BIN=""
+MOUNT_BIN=""
+UMOUNT_BIN=""
declare -i NUM_OF_TESTS=0
declare -i NUM_OF_PASS=0
declare -i NUM_OF_FAIL=0
@@ -214,6 +224,12 @@ function ext_setup()
[ -z "$MKFS_BIN" ] && MKFS_BIN="$(which mkfs.ocfs2 2>/dev/null)"
[ -x "$MKFS_BIN" ]
exit_if_bad "$?" "Command \"mkfs.ocfs2\" not found"
+ [ -z "$MOUNT_BIN" ] && MOUNT_BIN="$(which mount.ocfs2 2>/dev/null)"
+ [ -x "$MOUNT_BIN" ]
+ exit_if_bad "$?" "Command \"mount.ocfs2\" not found"
+ [ -z "$UMOUNT_BIN" ] && UMOUNT_BIN="$(which umount 2>/dev/null)"
+ [ -x "$UMOUNT_BIN" ]
+ exit_if_bad "$?" "Command \"umount\" not found"
}
CURRENT_TEST=""
@@ -372,6 +388,118 @@ function gen_fs_features()
}
+function create_files()
+{
+ for i in `seq 1 20`; do
+ mkdir $MOUNT_POINT/d.$i
+ for j in `seq 1 100`; do
+ touch $MOUNT_POINT/d.$i/f.$j
+ done
+ done
+}
+
+function rm_files()
+{
+ for i in `seq 1 2 20`; do
+ rm -Rf $MOUNT_POINT/d.$i
+ done
+ for i in `ls $MOUNT_POINT`; do
+ if [[ "$i" != "lost+found" ]]; then
+ for j in `seq 1 2 100`; do
+ rm $MOUNT_POINT/$i/f.$j
+ done
+ fi
+ done
+}
+
+
+# $1 Disk size, should be ``small'', ``medium'' or ``large''.
+function compress_dirs_test()
+{
+ local disk_size="$1"
+
+ # Small disk
+ local -a mkfs_profile_small=(
+ 1024 # block size
+ 4096 # cluster size
+ 4 # number of node solts
+ "4M" # journal
+ 262144 # blocks count
+ );
+ # Medium disk
+ local -a mkfs_profile_medium=(
+ 4096 # block size
+ 4096 # cluster size
+ 4 # number of node solts
+ "16M" # journal
+ 1048576 # blocks count
+ );
+ # Large disk
+ local -a mkfs_profile_large=(
+ 4096 # block size
+ 131072 # cluster size
+ 4 # number of node solts
+ "64M" # journal
+ 16777216 # blocks count
+ );
+
+ local v="mkfs_profile_${disk_size}[@]"
+ local -a mkfs_profile=("${!v}")
+
+ test_setup "Compress dirs test"
+
+ if [ 0 -eq "${#mkfs_profile[@]}" ]
+ then
+ test_broken "Unknown disk size"
+ return
+ fi
+
+ dd if=/dev/zero of=$DEVICE bs=1M count=4 &>"$STDOUT"
+ test_info "dd if=/dev/zero of=$DEVICE bs=1M count=4"
+ test_fail_if_bad "$?" "dd failed" || return
+
+ #add --fs-features support for mkfs
+ gen_fs_features 1
+
+ test_info mkfs.ocfs2 ${FS_FEATURES_ARGS} -b "${mkfs_profile[0]}" -C
"${mkfs_profile[1]}" \
+ -N "${mkfs_profile[2]}" -J "size=${mkfs_profile[3]}" \
+ "$DEVICE" "${mkfs_profile[4]}"
+ yes | "$MKFS_BIN" ${FS_FEATURES_ARGS} -b "${mkfs_profile[0]}" -C
"${mkfs_profile[1]}" \
+ -N "${mkfs_profile[2]}" -J "size=${mkfs_profile[3]}" \
+ "$DEVICE" "${mkfs_profile[4]}" &>"$STDOUT"
+
+ test_info "mount $DEVICE $MOUNT_POINT"
+ "$MOUNT_BIN" $DEVICE $MOUNT_POINT
+ test_fail_if_bad "$?" "mount failed" || return
+
+ create_files
+ rm_files
+
+ ls -R $MOUNT_POINT > $TMP_DIR/listing1
+
+ test_info "umount $DEVICE $MOUNT_POINT"
+ "$UMOUNT_BIN" $DEVICE
+ test_fail_if_bad "$?" "umount failed" || return
+
+ test_info "fsck.ocfs2 -Dfy $DEVICE"
+ "$FSCK_BIN" -fy "$DEVICE" >"$STDOUT"
+ test_fail_if_bad "$?" "fsck failed" || return
+
+ test_info "mount $DEVICE $MOUNT_POINT"
+ "$MOUNT_BIN" $DEVICE $MOUNT_POINT
+ test_fail_if_bad "$?" "mount failed" || return
+
+ ls -R $MOUNT_POINT > $TMP_DIR/listing2
+ cmp $TMP_DIR/listing1 $TMP_DIR/listing2
+ test_fail_if_bad "$?" "files are different" || return
+
+ test_info "umount $DEVICE $MOUNT_POINT"
+ "$UMOUNT_BIN" $DEVICE
+ test_fail_if_bad "$?" "umount failed" || return
+
+ test_pass
+}
+
# $2 Disk size, should be ``small'', ``medium'' or ``large''.
function corrupt_test()
{
@@ -427,14 +555,14 @@ function corrupt_test()
yes | "$MKFS_BIN" ${FS_FEATURES_ARGS} -b "${mkfs_profile[0]}" -C
"${mkfs_profile[1]}" \
-N "${mkfs_profile[2]}" -J "size=${mkfs_profile[3]}" \
"$DEVICE" "${mkfs_profile[4]}" &>"$STDOUT"
- test_fail_if_bad "$?" "mkfs failed" || return
+ #test_fail_if_bad "$?" "mkfs failed" || return
test_info "fswreck -c $corrupt $DEVICE"
"$FSWRECK_BIN" -n 2 -c "$corrupt" "$DEVICE" &>"$STDOUT"
test_fail_if_bad "$?" "fswreck failed" || return
test_info "fsck.ocfs2 -fy $DEVICE"
- "$FSCK_BIN" -fy "$DEVICE" >"$STDOUT" 2>"$STDERR"
+ "$FSCK_BIN" -fy "$DEVICE" >"$STDOUT"
test_fail_if_bad "$?" "fsck failed" || return
cp "$STDOUT" "$TMP_DIR/fsck.ocfs2.$corrupt.actual.stdout" &>/dev/null
@@ -530,6 +658,9 @@ do
"--with-corrupt="*)
CORRUPT="${1#--with-corrupt=}"
;;
+ "--with-mount="*)
+ MOUNT_BIN="${1#--with-mount=}"
+ ;;
*)
DEVICE="$1"
;;
@@ -540,8 +671,8 @@ done
if [ ! -d ${LOG_DIR} ]; then
mkdir -p ${LOG_DIR}
if [ $? -ne 0 ]; then
- echo -e "Failed to create directory ${LOG_DIR}\n";
- exit(1);
+ echo -e "Failed to create directory ${LOG_DIR}\n"
+ exit 1
fi;
fi;
LOGFILE=${LOG_DIR}/fsck-test.log
@@ -561,5 +692,6 @@ check_root_or_exit
ext_setup
smoke_test
basic_test
+compress_dirs_test $DISK_SIZE
#corrupt_test 22
#corrupt_test 36
--
Goldwyn
More information about the Ocfs2-test-devel
mailing list