[Ocfs2-test-devel] [PATCH 1/3] Ocfs2-test: Add testing tool on ocfs2-tools for quota support.

Tristan Ye tristan.ye at oracle.com
Fri Sep 11 02:13:38 PDT 2009


The testing script for ocfs2-tools on quota support was much more
likely to do a sanity check on ocfs2-tools's binaries(mkfs, tunefs,
debugfs,fsck etc) with quota operations. also some stress tests included.
Another goal of this script is to test the quota support codes in libocfs2.

1. mkfs_test

It's quite simple in logic, the aim is to check the functionality of
mkfsing volume with quota support.

2. tunefs_test
Similar to mkfs_test, this test also validate the functionality of disabling/enabling
quota with tunefs.ocfs2, what's more,increament/decrement in quota system file should
be checked when slot number get changed by tunefs, and especially, we also should take
a close look at space increment when disabling sparse and inline-data feature in fs.

3. fsck_test
The major goal of this test is to verify if fsck.ocfs2 behaves correctly after quota
info getting corrupted.

Signed-off-by: Tristan Ye <tristan.ye at oracle.com>
---
 programs/quota_tests/Makefile            |    4 +-
 programs/quota_tests/quota_tools_test.sh |  705 ++++++++++++++++++++++++++++++
 2 files changed, 707 insertions(+), 2 deletions(-)
 create mode 100755 programs/quota_tests/quota_tools_test.sh

diff --git a/programs/quota_tests/Makefile b/programs/quota_tests/Makefile
index a814442..044cfa3 100755
--- a/programs/quota_tests/Makefile
+++ b/programs/quota_tests/Makefile
@@ -6,14 +6,14 @@ TESTS = quota_multi_tests
 
 CC = $(MPICC)
 
-CFLAGS = -O2 -Wall -g $(O2DLM_CFLAGS) $(OCFS2_CFLAGS)
+CFLAGS = $(O2DLM_CFLAGS) $(OCFS2_CFLAGS)
 
 SOURCES = quota_multi_tests.c quota.h
 OBJECTS = $(patsubst %.c,%.o,$(SOURCES))
 
 DIST_FILES = $(SOURCES)
 
-BIN_EXTRA = run_quota_multi_tests.py quota_tests.sh
+BIN_EXTRA = run_quota_multi_tests.py quota_tests.sh quota_tools_test.sh
 
 BIN_PROGRAMS = quota_multi_tests
 
diff --git a/programs/quota_tests/quota_tools_test.sh b/programs/quota_tests/quota_tools_test.sh
new file mode 100755
index 0000000..91ea45f
--- /dev/null
+++ b/programs/quota_tests/quota_tools_test.sh
@@ -0,0 +1,705 @@
+#!/bin/bash
+#
+# Copyright (C) 2008 Oracle.  All rights reserved.
+#
+# This program is free software; you can redistribute it and/or
+# modify it under the terms of the GNU General Public
+# License, version 2,  as published by the Free Software Foundation.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+# General Public License for more details.
+#
+# You should have received a copy of the GNU General Public
+# License along with this program; if not, write to the
+# Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+# Boston, MA 021110-1307, USA.
+#
+#
+# Description:  This script will perform a sanity check on ocfs2-tools for
+#		quota support.
+#
+
+################################################################################
+# Global Variables
+################################################################################
+
+if [ -f `dirname ${0}`/o2tf.sh ]; then
+        . `dirname ${0}`/o2tf.sh
+fi
+
+
+
+BLOCKSIZE=4096
+CLUSTERSIZE=32768
+SLOTS=4
+MAX_SLOTS=160
+JOURNALSIZE=0
+BLOCKS=0
+LABELNAME=ocfs2-quota-tools-test
+DEVICE=
+MOUNT_POINT=
+WORK_PLACE_DIRENT=ocfs2-quota-tools-test
+WORK_PLACE=
+
+LOCAL_HOST=`hostname`
+DEFAULT_RANKS=4
+MPI_RANKS=
+MPI_HOSTS=
+MPI_ACCESS_METHOD="ssh"
+MPI_PLS_AGENT_ARG="-mca pls_rsh_agent ssh:rsh"
+MPI_BTL_ARG="-mca btl tcp,self -mca btl_tcp_if_include eth0"
+MPI_BTL_IF_ARG=
+MULTI_QUOTA_TEST_BIN="${BINDIR}/quota_multi_tests"
+
+DEFAULT_LOG_DIR=${O2TDIR}/log
+LOG_DIR=
+RUN_LOG_FILE=
+LOG_FILE=
+
+TEST_NUM=0
+TEST_PASS=0
+
+QUOTA_SYNC_INTERVAL=10
+
+QUOTA_BIN="`which sudo` -u root `which quota`"
+QUOTACHECK_BIN="`which sudo` -u root `which quotacheck`"
+EDQUOTA_BIN="`which sudo` -u root `which edquota`"
+SETQUOTA_BIN="`which sudo` -u root `which setquota`"
+QUOTAON_BIN="`which sudo` -u root `which quotaon`"
+QUOTAOFF_BIN="`which sudo` -u root `which quotaoff`"
+
+GROUPADD_BIN="`which sudo` -u root /usr/sbin/groupadd"
+GROUPDEL_BIN="`which sudo` -u root /usr/sbin/groupdel"
+USERADD_BIN="`which sudo` -u root /usr/sbin/useradd"
+USERDEL_BIN="`which sudo` -u root /usr/sbin/userdel"
+USERMOD_BIN="`which sudo` -u root /usr/sbin/usermod"
+
+DD_BIN="`which sudo` -u root `which dd`"
+
+set -o pipefail
+
+################################################################################
+# Utility Functions
+################################################################################
+function f_usage()
+{
+	echo "       -r size of MPI rank"
+	echo "       -a access method for mpi execution,should be ssh or rsh"
+	echo "       -f MPI hosts list,separated by comma"
+	echo "       -o output directory for the logs"
+	echo "       -d block device name used for ocfs2 volume"
+	echo "       <mountpoint path> path of mountpoint where the ocfs2 volume will be mounted on."
+	exit 1;
+
+}
+
+function f_getoptions()
+{
+	if [ $# -eq 0 ]; then
+                f_usage;
+                exit 1
+         fi
+
+         while getopts "o:hd:f:a:r:" options; do
+                case $options in
+		r ) MPI_RANKS="$OPTARG";;
+                o ) LOG_DIR="$OPTARG";;
+                d ) DEVICE="$OPTARG";;
+		f ) MPI_HOSTS="$OPTARG";;
+		a ) MPI_ACCESS_METHOD="$OPTARG";;
+                h ) f_usage;;
+                * ) f_usage;;
+                esac
+        done
+        shift $(($OPTIND -1))
+        MOUNT_POINT=${1}
+}
+
+function f_check()
+{
+	if [ "${EUID}" == "0" ];then
+		echo "You're not allowed to be root to run these tests!"
+		exit 1
+	fi
+
+	f_getoptions $*
+
+	if [ "$MPI_ACCESS_METHOD" = "rsh" ];then
+		MPI_PLS_AGENT_ARG="-mca pls_rsh_agent rsh:ssh"
+	fi
+
+	if [ -z "${MOUNT_POINT}" ];then
+		f_usage
+	else
+		if [ ! -d ${MOUNT_POINT} ]; then
+			echo "Mount point ${MOUNT_POINT} does not exist."
+			exit 1
+		else
+			if [ "`dirname ${MOUNT_POINT}`" = "/" ]; then
+				MOUNT_POINT="`dirname ${MOUNT_POINT}``basename \
+					    ${MOUNT_POINT}`"
+			else
+				MOUNT_POINT="`dirname ${MOUNT_POINT}`/`basename \
+					    ${MOUNT_POINT}`"
+			fi
+		fi
+	fi
+
+	if [ -z "$MPI_HOSTS" ];then
+		f_usage
+	fi
+
+	LOG_DIR=${LOG_DIR:-$DEFAULT_LOG}
+	${MKDIR_BIN} -p ${LOG_DIR} || exit 1
+
+	RUN_LOG_FILE="`dirname ${LOG_DIR}`/`basename ${LOG_DIR}`/`date +%F-%H-\
+%M-%S`-quota-tools-tests-run.log"
+        LOG_FILE="`dirname ${LOG_DIR}`/`basename ${LOG_DIR}`/`date +%F-%H-\
+%M-%S`-quota-tools-tests.log"
+
+}
+
+function f_mkfs_test()
+{
+
+	local -i lines=
+
+	f_LogMsg ${LOG_FILE} "Mkfs ${DEVICE} with usrquota support"
+
+	f_mkfs ${LOG_FILE} ${BLOCKSIZE} ${CLUSTERSIZE} ${LABELNAME} ${SLOTS} \
+${DEVICE} "usrquota" ${JOURNALSIZE} ${BLOCKS}
+	if [ "$?" -ne "0" ];then
+		return -1
+	fi
+
+	f_LogMsg ${LOG_FILE} "Run debufs.ocfs2 to verify if usrquota bit was set"
+	${DEBUGFS_BIN} -R "stats" ${DEVICE}|grep -i 'Feature RO compat' | grep \
+-qi 'usrquota' || {
+		f_LogMsg ${LOG_FILE} "Debugfs.ocfs2 didn't detect the usrquota \
+bit set in SB."
+		retun -1
+	}
+
+	f_LogMsg ${LOG_FILE} "Run debufs.ocfs2 to verify if grpquota bit was set"
+	${DEBUGFS_BIN} -R "stats" ${DEVICE}|grep -i 'Feature RO compat' | grep \
+-qi 'grpquota' && {
+		f_LogMsg ${LOG_FILE} "Debugfs.ocfs2 detect the grpquota bit \
+set in SB,which was not allowed."
+		retun -1
+	}
+
+	f_LogMsg ${LOG_FILE} "Run debufs.ocfs2 to verify if quota.user files \
+created correctly"
+	lines=`${DEBUGFS_BIN} -R "ls //" ${DEVICE} | grep quota.user| wc -l`
+	if [ "${lines}" != "$((${SLOTS}+1))" ];then
+		f_LogMsg ${LOG_FILE} "Quota.user files were not created as \
+required."
+		return -1
+	else
+		f_LogMsg ${LOG_FILE} "Debugfs detects ${lines} quota files."
+	fi
+
+	f_LogMsg ${LOG_FILE} "Mkfs ${DEVICE} with qrpquota support"
+	f_mkfs ${LOG_FILE} ${BLOCKSIZE} ${CLUSTERSIZE} ${LABELNAME} ${SLOTS} \
+${DEVICE} "grpquota" ${JOURNALSIZE} ${BLOCKS}
+	if [ "$?" -ne "0" ];then
+		return -1
+	fi
+
+	f_LogMsg ${LOG_FILE} "Run debufs.ocfs2 to verify if grpquota bit was set"
+	${DEBUGFS_BIN} -R "stats" ${DEVICE}|grep -i 'Feature RO compat' | grep \
+-qi 'grpquota' || {
+		f_LogMsg ${LOG_FILE} "Debugfs.ocfs2 didn't detect the \
+grpquota bit set in SB."
+		retun -1
+	}
+
+	f_LogMsg ${LOG_FILE} "Run debufs.ocfs2 to verify if usrquota bit was set"
+	${DEBUGFS_BIN} -R "stats" ${DEVICE}|grep -i 'Feature RO compat' | grep \
+-qi 'usrquota' && {
+		f_LogMsg ${LOG_FILE} "Debugfs.ocfs2 detect the usrquota bit \
+set in SB,which was not allowed."
+		retun -1
+	}
+
+	f_LogMsg ${LOG_FILE} "Run debufs.ocfs2 to verify if quota.group files \
+created correctly"
+	lines=`${DEBUGFS_BIN} -R "ls //" ${DEVICE} | grep quota.group| wc -l`
+	if [ "${lines}" != "$((${SLOTS}+1))" ];then
+		f_LogMsg ${LOG_FILE} "Quota.user files were not create \
+as required."
+		return -1
+	else
+		f_LogMsg ${LOG_FILE} "Debugfs detects ${lines} quota files."
+	fi
+
+	f_LogMsg ${LOG_FILE} "Mkfs ${DEVICE} with usrquota,grpquota support"
+	f_mkfs ${LOG_FILE} ${BLOCKSIZE} ${CLUSTERSIZE} ${LABELNAME} ${SLOTS} \
+${DEVICE} "usrquota,grpquota" ${JOURNALSIZE} ${BLOCKS}
+	if [ "$?" -ne "0" ];then
+		return -1
+	fi
+
+	f_LogMsg ${LOG_FILE} "Run debufs.ocfs2 to verify if usrquota,grpquota \
+bits were set"
+	${DEBUGFS_BIN} -R "stats" ${DEVICE}|grep -i 'Feature RO compat' | grep \
+-i 'usrquota' | grep -qi 'grpquota' || {
+		f_LogMsg ${LOG_FILE} "Debugfs.ocfs2 didn't detect the usrquota \
+and grpquota bits SB."
+		retun -1
+	}
+
+	f_LogMsg ${LOG_FILE} "Run debufs.ocfs2 to verify if quota files \
+created correctly"
+	lines=`${DEBUGFS_BIN} -R "ls //" ${DEVICE} | grep quota | wc -l`
+	if [ "${lines}" != "$((${SLOTS}*2+2))" ];then
+		f_LogMsg ${LOG_FILE} "Quota files were not created as required."
+		return -1
+	else
+		f_LogMsg ${LOG_FILE} "Debugfs detects ${lines} quota files."
+	fi
+
+}
+
+function f_tunefs_test()
+{
+	local QUOTAUSER=quotauser
+	local OLD_SLOTS=${SLOTS}
+	local lines=
+	local SOFT_SPACE_LIMIT=
+	local HARD_SPACE_LIMIT=
+	local SOFT_INODES_LIMIT=
+	local HARD_INODES_LIMIT=
+	local CUR_SPACE=
+	local CUR_SPACE_WITH_HOLES=
+	local CUR_SPACE_WITH_EXTENTS=
+	local BLOCK_SZ=1024
+	local WORKPLACE=${MOUNT_POINT}/${QUOTAUSER}
+	local MAX_INLINE_SZ=$((${BLOCKSIZE}-200))
+	local BPC=$((${CLUSTERSIZE}/1024))
+
+	f_LogMsg ${LOG_FILE} "Test disalbing inline-data features"
+        f_mkfs ${LOG_FILE} ${BLOCKSIZE} ${CLUSTERSIZE} ${LABELNAME} ${SLOTS} \
+${DEVICE} "usrquota,grpquota,inline-data" ${JOURNALSIZE} ${BLOCKS} || return -1
+	f_mount ${LOG_FILE} ${DEVICE} ${MOUNT_POINT} ocfs2 usrquota,grpquota \
+|| return -1
+	f_LogMsg ${LOG_FILE} "Enable quota by quotaon"
+	${QUOTAON_BIN} ${MOUNT_POINT} >>${LOG_FILE} 2>&1
+	f_LogMsg ${LOG_FILE} "Add one user ${QUOTAUSER}"
+        ${USERADD_BIN} -m ${QUOTAUSER}
+	${MKDIR_BIN} -p ${WORKPLACE}
+        ${CHMOD_BIN} -R 777 ${WORKPLACE}
+	f_exit_or_not $?
+	f_LogMsg ${LOG_FILE} "Set quota limit"
+	SOFT_SPACE_LIMIT=1024000
+        HARD_SPACE_LIMIT=2048000
+        SOFT_INODES_LIMIT=100
+        HARD_INODES_LIMIT=200
+	${SETQUOTA_BIN} -u ${QUOTAUSER} ${SOFT_SPACE_LIMIT} ${HARD_SPACE_LIMIT}\
+ ${SOFT_INODES_LIMIT} ${HARD_INODES_LIMIT} -a ${DEVICE} >>${LOG_FILE} 2>&1
+	f_LogMsg ${LOG_FILE} "Dd inlined&extended files by user ${QUOTAUSER}"
+	for i in `seq 1 ${SOFT_INODES_LIMIT}`;do
+		if [ $((${i}%2)) -eq 0 ]; then
+			${SUDO} -u ${QUOTAUSER} dd if=/dev/zero \
+of=${WORKPLACE}/testfile_extend_${i} bs=${BLOCK_SZ} \
+count=${BPC} >>${LOG_FILE} 2>&1
+		else
+			${SUDO} -u ${QUOTAUSER} dd if=/dev/zero \
+of=${WORKPLACE}/testfile_inlined_${i} bs=1 \
+count=$((${RANDOM}%${MAX_INLINE_SZ}+1)) >>${LOG_FILE} 2>&1
+		fi
+	done
+
+	SPACE_DESIRED=$((${SOFT_INODES_LIMIT}/2*${BPC}))
+	CUR_SPACE=`${QUOTA_BIN} -u quotauser|grep -v Filesystem|grep -v \
+Disk|awk '{print $2}'|cut -d* -f1`
+
+	if [ "${CUR_SPACE}" != "${SPACE_DESIRED}" ];then
+		f_LogMsg ${LOG_FILE} "Current space should be ${SPACE_DESIRED} \
+before inline file getting extended, while we got ${CUR_SPACE}"
+		return -1
+	else
+		f_LogMsg ${LOG_FILE} "Current space usage is \
+${CUR_SPACE_WITH_EXTENTS} before inline file getting extended"
+	fi
+
+	f_umount ${LOG_FILE} ${MOUNT_POINT} || return -1
+	f_LogMsg ${LOG_FILE} "Disable the inline-data feature via tunefs.ocfs2"
+	${TUNEFS_BIN} -v --fs-features noinline-data ${DEVICE} \
+>>${LOG_FILE} 2>&1 || return -1
+	f_mount ${LOG_FILE} ${DEVICE} ${MOUNT_POINT} ocfs2 usrquota,grpquota \
+|| return -1
+	f_LogMsg ${LOG_FILE} "Enable quota by quotaon"
+        ${QUOTAON_BIN} ${MOUNT_POINT} >>${LOG_FILE} 2>&1
+	SPACE_DESIRED=$((${SOFT_INODES_LIMIT}*${BPC}))
+	CUR_SPACE_WITH_EXTENTS=`${QUOTA_BIN} -u quotauser|grep -v Filesystem\
+|grep -v Disk|awk '{print $2}'|cut -d* -f1`
+
+	if [ "${CUR_SPACE_WITH_EXTENTS}" != "${SPACE_DESIRED}" ];then
+		f_LogMsg ${LOG_FILE} "Space grown by extending inline files \
+should be added,it should be ${SPACE_DESIRED}, while we got \
+${CUR_SPACE_WITH_EXTENTS}"
+		return -1
+	else
+		f_LogMsg ${LOG_FILE} "Current space usage is \
+${CUR_SPACE_WITH_EXTENTS} after inline file getting extended"
+	fi
+
+	f_LogMsg ${LOG_FILE} "Remove one user ${QUOTAUSER}"
+	${USERDEL_BIN} -r ${QUOTAUSER}>>${LOG_FILE} 2>&1
+
+	f_LogMsg ${LOG_FILE} "Remove all testing files for user ${USERNAME}"
+	${RM_BIN} -rf ${WORKPLACE} >>${LOG_FILE} 2>&1
+
+        f_umount ${LOG_FILE} ${MOUNT_POINT}
+
+	f_LogMsg ${LOG_FILE} "Test enabling quota feature via tunefs.ocfs2"
+	f_mkfs ${LOG_FILE} ${BLOCKSIZE} ${CLUSTERSIZE} ${LABELNAME} ${SLOTS} \
+${DEVICE} "nousrquota,nogrpquota" ${JOURNALSIZE} ${BLOCKS}
+        if [ "$?" -ne "0" ];then
+                return -1
+        fi
+
+	f_LogMsg ${LOG_FILE} "Enable usrquota,grpquota via tunefs.ocfs2"
+	${TUNEFS_BIN} -v --fs-features usrquota,grpquota ${DEVICE} \
+>>${LOG_FILE} 2>&1 || return -1
+	f_LogMsg ${LOG_FILE} "Run debugfs to check if quota files get \
+created as required."
+	lines=`${DEBUGFS_BIN} -R "ls //" ${DEVICE} | grep quota| wc -l`
+	if [ "${lines}" != "$((${SLOTS}*2+2))" ];then
+		f_LogMsg ${LOG_FILE} "Quota files were not created as required."
+		return -1
+	else
+		f_LogMsg ${LOG_FILE} "Debugfs detects ${lines} quota files."
+	fi
+
+	f_LogMsg ${LOG_FILE} "Test disabling quota feature via tunefs.ocfs2"
+	f_mkfs ${LOG_FILE} ${BLOCKSIZE} ${CLUSTERSIZE} ${LABELNAME} ${SLOTS} \
+${DEVICE} "usrquota,grpquota" ${JOURNALSIZE} ${BLOCKS} || return -1
+	f_LogMsg ${LOG_FILE} "Disable usrquota via tunefs.ocfs2"
+	${TUNEFS_BIN} -v --fs-features nousrquota ${DEVICE} >>${LOG_FILE} 2>&1 \
+|| return -1
+	f_LogMsg ${LOG_FILE} "Run debugfs to check if user quota files get \
+deleted as required."
+	lines=`${DEBUGFS_BIN} -R "ls //" ${DEVICE} | grep quota.user| wc -l`
+        if [ "${lines}" != "0" ];then
+                f_LogMsg ${LOG_FILE} "Quota.user files were not deleted \
+as required."
+                return -1
+        else
+                f_LogMsg ${LOG_FILE} "Debugfs detects ${lines} quota files."
+        fi
+
+	f_LogMsg ${LOG_FILE} "Disable grpquota via tunefs.ocfs2"
+	${TUNEFS_BIN} -v --fs-features nogrpquota ${DEVICE} \
+>>${LOG_FILE} 2>&1 || return -1
+	f_LogMsg ${LOG_FILE} "Run debugfs to check if group quota files get \
+deleted as required."
+        lines=`${DEBUGFS_BIN} -R "ls //" ${DEVICE} | grep quota.group| wc -l`
+        if [ "${lines}" != "0" ];then
+                f_LogMsg ${LOG_FILE} "Quota.group files were not deleted as \
+required."
+                return -1
+        else
+                f_LogMsg ${LOG_FILE} "Debugfs detects ${lines} quota files."
+        fi
+
+	OLD_SLOTS=${SLOTS}
+	f_LogMsg ${LOG_FILE} "Test increase/decrease slot number"
+	f_mkfs ${LOG_FILE} ${BLOCKSIZE} ${CLUSTERSIZE} ${LABELNAME} ${SLOTS} \
+${DEVICE} "usrquota,grpquota" ${JOURNALSIZE} ${BLOCKS} || return -1
+	CHANGE=$((${RANDOM}%$((${MAX_SLOTS}-${SLOTS}))+1))
+	SLOTS=$((${SLOTS}+${CHANGE}))
+	f_LogMsg ${LOG_FILE} "Increase slots number via tunefs.ocfs2"
+	${TUNEFS_BIN} -v --node-slots ${SLOTS} ${DEVICE} >>${LOG_FILE} 2>&1 \
+|| return -1
+	f_LogMsg ${LOG_FILE} "Run debufs.ocfs2 to verify if quota files \
+added correctly"
+        lines=`${DEBUGFS_BIN} -R "ls //" ${DEVICE} | grep quota | wc -l`
+        if [ "${lines}" != "$((${SLOTS}*2+2))" ];then
+                f_LogMsg ${LOG_FILE} "Quota files were not added as required."
+                return -1
+        else
+                f_LogMsg ${LOG_FILE} "Debugfs detects ${lines} quota files."
+        fi
+
+	CHANGE=$((${RANDOM}%${SLOTS}))
+	SLOTS=$((${SLOTS}-${CHANGE}))
+	f_LogMsg ${LOG_FILE} "Decrease slots number via tunefs.ocfs2"
+        ${TUNEFS_BIN} -v --node-slots ${SLOTS} ${DEVICE} >>${LOG_FILE} 2>&1 \
+|| return -1
+        f_LogMsg ${LOG_FILE} "Run debufs.ocfs2 to verify if quota files \
+deleted correctly"
+        lines=`${DEBUGFS_BIN} -R "ls //" ${DEVICE} | grep quota | wc -l`
+        if [ "${lines}" != "$((${SLOTS}*2+2))" ];then
+                f_LogMsg ${LOG_FILE} "Quota files were not deleted as required."
+                return -1
+        else
+                f_LogMsg ${LOG_FILE} "Debugfs detects ${lines} quota files."
+        fi
+
+	SLOTS=${OLD_SLOTS}
+	f_LogMsg ${LOG_FILE} "Test disalbing sparse features"
+        f_mkfs ${LOG_FILE} ${BLOCKSIZE} ${CLUSTERSIZE} ${LABELNAME} ${SLOTS} \
+${DEVICE} "usrquota,grpquota,sparse" ${JOURNALSIZE} ${BLOCKS} || return -1
+	f_mount ${LOG_FILE} ${DEVICE} ${MOUNT_POINT} ocfs2 usrquota,grpquota \
+|| return -1
+	f_LogMsg ${LOG_FILE} "Enable quota by quotaon"
+	${QUOTAON_BIN} ${MOUNT_POINT} >>${LOG_FILE} 2>&1
+	f_LogMsg ${LOG_FILE} "Add one user ${QUOTAUSER}"
+        ${USERADD_BIN} -m ${QUOTAUSER}
+	${MKDIR_BIN} -p ${WORKPLACE}
+        ${CHMOD_BIN} -R 777 ${WORKPLACE}
+	f_exit_or_not $?
+	f_LogMsg ${LOG_FILE} "Set quota limit"
+	SOFT_SPACE_LIMIT=102400
+        HARD_SPACE_LIMIT=204800
+        SOFT_INODES_LIMIT=10
+        HARD_INODES_LIMIT=20
+	${SETQUOTA_BIN} -u ${QUOTAUSER} ${SOFT_SPACE_LIMIT} ${HARD_SPACE_LIMIT}\
+ ${SOFT_INODES_LIMIT} ${HARD_INODES_LIMIT} -a ${DEVICE} >>${LOG_FILE} 2>&1
+	f_LogMsg ${LOG_FILE} "Dd a sparse file by user ${QUOTAUSER}"
+	f_LogMsg ${LOG_FILE} "${SUDO} -u ${QUOTAUSER} dd if=/dev/zero \
+of=${WORKPLACE}/testfile bs=${BLOCK_SZ} count=10 seek=${HARD_SPACE_LIMIT}"
+	${SUDO} -u ${QUOTAUSER} dd if=/dev/zero of=${WORKPLACE}/testfile \
+bs=${BLOCK_SZ} count=10 seek=${HARD_SPACE_LIMIT} >>${LOG_FILE} 2>&1
+	CUR_SPACE=`${QUOTA_BIN} -u quotauser|grep -v Filesystem|grep -v Disk\
+|awk '{print $2}'|cut -d* -f1`
+	f_umount ${LOG_FILE} ${MOUNT_POINT} || return -1
+	f_LogMsg ${LOG_FILE} "Disable the sparse feature via tunefs.ocfs2"
+	${TUNEFS_BIN} -v --fs-features nosparse ${DEVICE} >>${LOG_FILE} 2>&1 \
+|| return -1
+	f_mount ${LOG_FILE} ${DEVICE} ${MOUNT_POINT} ocfs2 usrquota,grpquota \
+|| return -1
+	f_LogMsg ${LOG_FILE} "Enable quota by quotaon"
+        ${QUOTAON_BIN} ${MOUNT_POINT} >>${LOG_FILE} 2>&1
+	CUR_SPACE_WITH_HOLES=`${QUOTA_BIN} -u quotauser|grep -v Filesystem\
+|grep -v Disk|awk '{print $2}'|cut -d* -f1`
+
+	if [ "${CUR_SPACE_WITH_HOLES}" != "$((${CUR_SPACE}+${HARD_SPACE_LIMIT}))" ];then
+		f_LogMsg ${LOG_FILE} "Filled holes should be added to current \
+space usage,it should be $((${CUR_SPACE}+${HARD_SPACE_LIMIT})), while \
+we got ${CUR_SPACE_WITH_HOLES}"
+		return -1
+	else
+		f_LogMsg ${LOG_FILE} "Now the current space usage is \
+${CUR_SPACE_WITH_HOLES} after holes get filled."
+	fi
+
+	f_LogMsg ${LOG_FILE} "Remove one user ${QUOTAUSER}"
+	${USERDEL_BIN} -r ${QUOTAUSER}>>${LOG_FILE} 2>&1
+
+	f_LogMsg ${LOG_FILE} "Remove all testing files for user ${USERNAME}"
+	${RM_BIN} -rf ${WORKPLACE} >>${LOG_FILE} 2>&1
+
+        f_umount ${LOG_FILE} ${MOUNT_POINT}
+}
+
+function f_fsck_test()
+{
+
+	local USER_NUMS=
+	local GROUP_NUMS=
+	local CUR_INODES=
+	local SLMT_INODES=
+	local USER_NAME=
+
+	f_LogMsg ${LOG_FILE} "Test fsck.ocfs2 to fix corrupted quotas."
+	f_mkfs ${LOG_FILE} ${BLOCKSIZE} ${CLUSTERSIZE} ${LABELNAME} ${SLOTS} \
+${DEVICE} "usrquota,grpquota" ${JOURNALSIZE} ${BLOCKS}
+	f_remote_mount ${LOG_FILE} ${LABELNAME} ${MOUNT_POINT} ${MPI_HOSTS} \
+usrquota,grpquota
+        f_LogMsg ${LOG_FILE} "Enable quota by quotaon"
+        ${QUOTAON_BIN} ${MOUNT_POINT} >>${LOG_FILE} 2>&1
+
+	f_LogMsg ${LOG_FILE} "Corrupt quota usage info(cur_inodes) by \
+multi-nodes testing binary"
+	f_LogMsg ${LOG_FILE}
+	USER_NUMS=10
+	GROUP_NUMS=2
+	f_LogMsg ${LOG_FILE} "${SUDO} ${MPIRUN} ${MPI_PLS_AGENT_ARG} \
+${MPI_BTL_ARG} ${MPI_BTL_IF_ARG} -np ${MPI_RANKS} --host ${MPI_HOSTS} \
+${MULTI_QUOTA_TEST_BIN} -i 1 -u ${USER_NUMS} -g ${GROUP_NUMS} -d ${DEVICE} \
+${MOUNT_POINT} -c -p"
+	${SUDO} ${MPIRUN} ${MPI_PLS_AGENT_ARG} ${MPI_BTL_ARG} ${MPI_BTL_IF_ARG} \
+-np 1 --host `hostname` ${MULTI_QUOTA_TEST_BIN} -i 1 -u ${USER_NUMS} -g \
+${GROUP_NUMS} -d ${DEVICE} ${MOUNT_POINT} -c -p>>${LOG_FILE} 2>&1 || return -1
+	f_remote_umount ${LOG_FILE} ${MOUNT_POINT} ${MPI_HOSTS}
+	f_LogMsg ${LOG_FILE} "Run fsck.ocfs2 to fix the corrupted quota."
+	echo "yyyyyyyyyyyy"|${FSCK_BIN} -f ${DEVICE} >>${LOG_FILE} 2>&1
+        f_LogMsg ${LOG_FILE} "Mount volume with usrquota and grpquota options \
+among ${MPI_HOSTS}"
+	f_remote_mount ${LOG_FILE} ${LABELNAME} ${MOUNT_POINT} ${MPI_HOSTS} \
+usrquota,grpquota
+	USER_NAME=quota-usr-rank0-1
+	CUR_INODES=`${QUOTA_BIN} -u ${USER_NAME}|grep -v Filesystem|grep -v \
+Disk|awk '{print $5}'|cut -d* -f1`
+	SLMT_INODES=`${QUOTA_BIN} -u ${USER_NAME}|grep -v Filesystem|grep -v \
+Disk|awk '{print $6}'|cut -d* -f1`
+
+	if [ "${CUR_INODES}" != "${SLMT_INODES}" ];then
+		f_LogMsg ${LOG_FILE} "fsck.ocfs2 didn't fix the corrupted \
+cur_inodes number,it should be ${SLMT_INODES}, found ${CUR_INODES} instead."
+		return -1
+	else
+		f_LogMsg ${LOG_FILE} "fsck.ocfs2 successfully fix the \
+corrupted cur_inodes to ${SLMT_INODES}"
+	fi
+
+	f_LogMsg ${LOG_FILE} "Cleanup user accounts"
+	f_LogMsg ${LOG_FILE} "${SUDO} ${MPIRUN} ${MPI_PLS_AGENT_ARG} \
+${MPI_BTL_ARG} ${MPI_BTL_IF_ARG} -np ${MPI_RANKS} --host ${MPI_HOSTS} \
+${MULTI_QUOTA_TEST_BIN} -i 1 -u 1 -g 0 -d ${DEVICE} ${MOUNT_POINT} -w"
+	${SUDO} ${MPIRUN} ${MPI_PLS_AGENT_ARG} ${MPI_BTL_ARG} ${MPI_BTL_IF_ARG} \
+-np ${MPI_RANKS} --host ${MPI_HOSTS} ${MULTI_QUOTA_TEST_BIN} -i 1 -u 2 -g 0 -d \
+${DEVICE} ${MOUNT_POINT} -w >>${LOG_FILE} 2>&1 || return -1
+	f_remote_umount ${LOG_FILE} ${MOUNT_POINT} ${MPI_HOSTS}
+
+	f_LogMsg ${LOG_FILE} "Multi-nodes stress tests for fsck.ocfs2"
+	f_mkfs ${LOG_FILE} ${BLOCKSIZE} ${CLUSTERSIZE} ${LABELNAME} ${SLOTS} \
+${DEVICE} "usrquota,grpquota" ${JOURNALSIZE} ${BLOCKS}
+	f_remote_mount ${LOG_FILE} ${LABELNAME} ${MOUNT_POINT} ${MPI_HOSTS} \
+usrquota,grpquota
+	f_LogMsg ${LOG_FILE} "Enable quota by quotaon"
+	${SUDO} ${MPIRUN} ${MPI_PLS_AGENT_ARG} ${MPI_BTL_ARG} ${MPI_BTL_IF_ARG} \
+--host ${MPI_HOSTS} ${QUOTAON_BIN} ${MOUNT_POINT} >/dev/null 2>&1
+	f_LogMsg ${LOG_FILE} "${SUDO} ${MPIRUN} ${MPI_PLS_AGENT_ARG} \
+${MPI_BTL_ARG} ${MPI_BTL_IF_ARG} -np ${MPI_RANKS} --host ${MPI_HOSTS} \
+${MULTI_QUOTA_TEST_BIN} -i 1 -u 100 -g 100 -d ${DEVICE} ${MOUNT_POINT} -b -k"
+	${SUDO} ${MPIRUN} ${MPI_PLS_AGENT_ARG} ${MPI_BTL_ARG} ${MPI_BTL_IF_ARG} \
+-np ${MPI_RANKS} --host ${MPI_HOSTS} ${MULTI_QUOTA_TEST_BIN} -i 1 -u 100 -g 100 -d \
+${DEVICE} ${MOUNT_POINT} -b -k>>${LOG_FILE} 2>&1 || return -1
+
+	sleep ${QUOTA_SYNC_INTERVAL}
+
+	${SUDO} ${MPIRUN} ${MPI_PLS_AGENT_ARG} ${MPI_BTL_ARG} ${MPI_BTL_IF_ARG} \
+--host ${MPI_HOSTS} sync >/dev/null 2>&1
+
+	quotainfo="`dirname ${LOG_DIR}`/`basename ${LOG_DIR}`/quotainfo.log.$$"
+	quotainfo_r="`dirname ${LOG_DIR}`/`basename ${LOG_DIR}`/quotainfo.log.$$"
+
+	f_LogMsg ${LOG_FILE} "Gather quota info after stress tests among \
+multi-nodes done."
+
+	nodes=`echo ${MPI_HOSTS}|sed 's/,/ /g'`
+
+	for i in `seq 0 $((${MPI_RANKS}-1))`;do
+		for node in ${nodes};do
+			username=quota-usr-rank${i}-0
+			${SUDO} ${MPIRUN} ${MPI_PLS_AGENT_ARG} ${MPI_BTL_ARG} ${MPI_BTL_IF_ARG} \
+--host ${node} ${QUOTA_BIN} -u ${username} >/dev/null 2>&1
+			if [ $? -eq 0 ];then
+				 ${SUDO} ${MPIRUN} ${MPI_PLS_AGENT_ARG} ${MPI_BTL_ARG} ${MPI_BTL_IF_ARG} \
+--host ${node} ${QUOTA_BIN} -u ${username} >>${quotainfo} 2>&1
+			fi
+		done
+	done
+
+	f_remote_umount ${LOG_FILE} ${MOUNT_POINT} ${MPI_HOSTS}
+	f_LogMsg ${LOG_FILE} "Run fsck.ocfs2 to fix the corrupted quota."
+        yes|${FSCK_BIN} -f ${DEVICE} >>${LOG_FILE} 2>&1
+
+	f_remote_mount ${LOG_FILE} ${LABELNAME} ${MOUNT_POINT} ${MPI_HOSTS} \
+usrquota,grpquota
+
+	f_LogMsg ${LOG_FILE} "Enable quota by quotaon"
+	${SUDO} ${MPIRUN} ${MPI_PLS_AGENT_ARG} ${MPI_BTL_ARG} ${MPI_BTL_IF_ARG} \
+--host ${MPI_HOSTS} ${QUOTAON_BIN} ${MOUNT_POINT} >/dev/null 2>&1
+
+	f_LogMsg ${LOG_FILE} "Regather quota info after fsck.ocfs2 checking \
+done among multi-nodes."
+
+        for i in `seq 0 $((${MPI_RANKS}-1))`;do
+                for node in ${nodes};do
+			username=quota-usr-rank${i}-0
+			${SUDO} ${MPIRUN} ${MPI_PLS_AGENT_ARG} ${MPI_BTL_ARG} ${MPI_BTL_IF_ARG} \
+--host ${node} ${QUOTA_BIN} -u ${username} >/dev/null 2>&1
+			if [ $? -eq 0 ];then
+				${SUDO} ${MPIRUN} ${MPI_PLS_AGENT_ARG} ${MPI_BTL_ARG} ${MPI_BTL_IF_ARG} \
+--host ${node} ${QUOTA_BIN} -u ${username} >>${quotainfo_r} 2>&1
+			fi
+		done
+	done
+
+	f_LogMsg ${LOG_FILE} "Verify quotainfo after stress test and fsck"
+	
+	diff -q ${quotainfo} ${quotainfo_r} >/dev/null 2>&1
+
+	if [ "$?" != "0" ];then
+		f_LogMsg ${LOG_FILE} "Quota info gathered after stress tests \
+diffs from gathering after fsck.ocfs2"
+		return -1
+	fi
+
+	f_LogMsg ${LOG_FILE} "Cleanup user accounts"
+	f_LogMsg ${LOG_FILE} "${SUDO} ${MPIRUN} ${MPI_PLS_AGENT_ARG} \
+${MPI_BTL_ARG} ${MPI_BTL_IF_ARG} -np ${MPI_RANKS} --host ${MPI_HOSTS} \
+${MULTI_QUOTA_TEST_BIN} -i 1 -u 1 -g 0 -d ${DEVICE} ${MOUNT_POINT} -w"
+	${SUDO} ${MPIRUN} ${MPI_PLS_AGENT_ARG} ${MPI_BTL_ARG} ${MPI_BTL_IF_ARG} \
+-np ${MPI_RANKS} --host ${MPI_HOSTS} ${MULTI_QUOTA_TEST_BIN} -i 1 -u 2 -g 0 -d \
+${DEVICE} ${MOUNT_POINT} -w >>${LOG_FILE} 2>&1 || return -1
+	f_remote_umount ${LOG_FILE} ${MOUNT_POINT} ${MPI_HOSTS}
+
+}
+
+function f_runtest()
+{
+	((TEST_NUM++))
+	f_LogRunMsg ${RUN_LOG_FILE} "[${TEST_NUM}] Quota Support on Mkfs.ocfs2 Test:"
+	f_LogMsg ${LOG_FILE} "[${TEST_NUM}] Test quota support on mkfs.ocfs2:"
+	f_mkfs_test
+	RET=$?
+	f_echo_status ${RET} | tee -a ${RUN_LOG_FILE}
+	f_exit_or_not ${RET}
+	((TEST_PASS++))
+
+	((TEST_NUM++))
+	f_LogRunMsg ${RUN_LOG_FILE} "[${TEST_NUM}] Quota Support on tunefs.ocfs2 Test:"
+	f_LogMsg ${LOG_FILE} "[${TEST_NUM}] Test quota support on tunefs.ocfs2:"
+	f_tunefs_test
+	RET=$?
+	f_echo_status ${RET} | tee -a ${RUN_LOG_FILE}
+	f_exit_or_not ${RET}
+	((TEST_PASS++))
+
+	((TEST_NUM++))
+	f_LogRunMsg ${RUN_LOG_FILE} "[${TEST_NUM}] Quota Support on fsck.ocfs2 Test:"
+	f_LogMsg ${LOG_FILE} "[${TEST_NUM}] Test quota support on fsck.ocfs2:"
+	f_fsck_test
+	RET=$?
+	f_echo_status ${RET} | tee -a ${RUN_LOG_FILE}
+	f_exit_or_not ${RET}
+	((TEST_PASS++))
+
+}
+
+function f_cleanup()
+{
+	:
+}
+
+
+################################################################################
+# Main Entry
+################################################################################
+
+#redfine the int signal hander
+trap 'echo -ne "\n\n">>${RUN_LOG_FILE};echo  "Interrupted by Ctrl+C,Cleanuping... "|tee -a ${RUN_LOG_FILE}; f_cleanup;exit 1' SIGINT
+
+f_check $*
+
+START_TIME=${SECONDS}
+f_LogRunMsg ${RUN_LOG_FILE} "=====================Ocfs2 tools testing on quota starts:  `date`=====================\n"
+f_LogMsg ${LOG_FILE} "=====================Ocfs2 tools testing on quota starts:  `date`====================="
+
+f_runtest
+
+END_TIME=${SECONDS}
+f_LogRunMsg ${RUN_LOG_FILE} "=====================Ocfs2 tools testing on quota ends: `date`=====================\n"
+f_LogMsg ${LOG_FILE} "=====================Ocfs2 tools testing on quota ends: `date`====================="
+
+f_LogRunMsg ${RUN_LOG_FILE} "Time elapsed(s): $((${END_TIME}-${START_TIME}))\n"
+f_LogRunMsg ${RUN_LOG_FILE} "Tests total: ${TEST_NUM}\n"
+f_LogRunMsg ${RUN_LOG_FILE} "Tests passed: ${TEST_PASS}\n"
-- 
1.5.5




More information about the Ocfs2-test-devel mailing list