Skip to content

Commit

Permalink
ocfs2-test: Add testing cases for online filecheck
Browse files Browse the repository at this point in the history
This include skeleton for testing online filecheck,
and testing cases for inode block which has been merged
into kernel mainline.

This testcase won't run with "-t all" options now unless
"filecheck" is explicitly specified, because it's still
under developing progress.

Signed-off-by: Eric Ren <[email protected]>
Reviewed-by: He Gang <[email protected]>
  • Loading branch information
Eric Ren committed Jul 20, 2016
1 parent 329c811 commit b64f500
Show file tree
Hide file tree
Showing 6 changed files with 684 additions and 2 deletions.
3 changes: 2 additions & 1 deletion programs/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,8 @@ SUBDIRS = \
reflink_tests \
directio_test \
discontig_bg_test \
verify_readonly
verify_readonly \
online_filecheck

ifdef OCFS2_TEST_DX_DIRS
SUBDIRS += dx_dirs_tests
Expand Down
9 changes: 9 additions & 0 deletions programs/online_filecheck/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
TOPDIR = ../..

include $(TOPDIR)/Preamble.make

DIST_FILES = filecheck_test_run.sh inode_block_test.sh filecheck_utils.sh

BIN_EXTRA = filecheck_test_run.sh inode_block_test.sh filecheck_utils.sh

include $(TOPDIR)/Postamble.make
187 changes: 187 additions & 0 deletions programs/online_filecheck/filecheck_test_run.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,187 @@
#!/bin/bash
#
# filecheck_run.sh
#
# descritpion: This script will perform a thorough single node test on online
# filecheck for OCFS2. Following testcases will be involed.
#
# 1. inode block: inode number, inode generation, block ECC
#
# Author: Eric Ren, [email protected]
# History: 22 Mar, 2016
#
# Copyright (C) 2016 SUSE. 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 as published by the Free Software Foundation, version 2.
#
# 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.

################################################################################
# Global Variables
################################################################################
if [ -f `dirname ${0}`/o2tf.sh ]; then
. `dirname ${0}`/o2tf.sh
fi

USERNAME="`id -un`"
GROUPNAME="`id -gn`"

SUDO="`which sudo` -u root"
MKFS_BIN="`which sudo` -u root `which mkfs.ocfs2`"
MOUNT_BIN="`which sudo` -u root `which mount.ocfs2`"
UMOUNT_BIN="`which sudo` -u root `which umount`"

LABELNAME=ocfs2-filecheck-tests
OCFS2_DEVICE=
MOUNT_POINT=
MOUNT_OPTS="errors=continue"
FEATURES="local,metaecc"
BLOCKSIZE=4096
CLUSTERSIZE=32768
WORKSPACE=

DEFAULT_LOG="filecheck-test-logs"
LOG_OUT_DIR=
DETAIL_LOG_FILE=

TEST_NO=0
TEST_PASS=0

set -o pipefail

################################################################################
# Utility Functions
################################################################################

f_usage()
{
echo "usage: `basename ${0}` [-o output log dir] <-d <device>> <mountpoint>"
echo " -o output directory for logs."
echo " -d specify the device to be formated as an ocfs2 volume."
echo " <mountpoint> path of mount point where the ocfs2 volume will be mounted on."
}

f_getoptions()
{
if [ $# -eq 0 ];then
f_usage
exit 1
fi

while getopts "o:d:" options; do
case $options in
o ) LOG_OUT_DIR="$OPTARG";;
d ) OCFS2_DEVICE="$OPTARG";;
* ) f_usage
exit 1;;
esac
done
shift $(($OPTIND - 1))
MOUNT_POINT=${1}
}

f_setup()
{
f_getoptions $*

if [ -z "${MOUNT_POINT}" -o ! -d ${MOUNT_POINT} ];then
echo "Mount point ${MOUNT_POINT} does not exist."
f_usage
fi

LOG_OUT_DIR="${LOG_OUT_DIR:-$DEFAULT_LOG}/filecheck"
mkdir -p ${LOG_OUT_DIR} || exit 1

LOG_SURFIX=$(date +%Y%m%d-%H%M%S)
DETAIL_LOG_FILE="${LOG_OUT_DIR}/filecheck_test-${LOG_SURFIX}.log"
RUN_LOG_FILE="$LOG_OUT_DIR/run-filecheck-${LOG_SURFIX}.log"

WORKSPACE="${MOUNT_POINT}/filecheck_test_place"
}

f_do_mkfs_and_mount()
{
echo -n "Mkfsing device:" | tee -a ${DETAIL_LOG_FILE}

echo y | ${MKFS_BIN} --fs-features=${FEATURES} --label ${LABELNAME} -b ${BLOCKSIZE} -C ${CLUSTERSIZE} ${OCFS2_DEVICE} >> ${DETAIL_LOG_FILE} 2>&1
RET=$?
f_echo_status ${RET} | tee -a ${DETAIL_LOG_FILE}
f_exit_or_not ${RET}

echo -n "Mounting device to ${MOUNT_POINT}:" | tee -a ${DETAIL_LOG_FILE}
${MOUNT_BIN} -t ocfs2 -o ${MOUNT_OPTS} ${OCFS2_DEVICE} ${MOUNT_POINT} >> ${DETAIL_LOG_FILE} 2>&1
RET=$?
f_echo_status ${RET} | tee -a ${DETAIL_LOG_FILE}
f_exit_or_not ${RET}

${SUDO} chown -R ${USERNAME}:${GROUPNAME} ${MOUNT_POINT}
${SUDO} chmod -R 777 ${MOUNT_POINT}

mkdir -p ${WORKSPACE} || exit 1
}

f_do_umount()
{
echo -n "Umounting device to ${MOUNT_POINT}:" | tee -a ${DETAIL_LOG_FILE}

rm -rf ${WORKSPACE} || exit 1

${UMOUNT_BIN} ${MOUNT_POINT} >> ${DETAIL_LOG_FILE} 2>&1
RET=$?
f_echo_status ${RET} | tee -a ${DETAIL_LOG_FILE}
f_exit_or_not ${RET}
}

f_runtest()
{
# put testing units here
f_do_mkfs_and_mount

((TEST_NO++))
echo -ne "[${TEST_NO}] Inode block corrupt & check & fix:" | tee -a ${RUN_LOG_FILE}
inode_block_test.sh -d ${OCFS2_DEVICE} -m ${MOUNT_POINT} -l ${LOG_OUT_DIR}
RET=$?
f_echo_status ${RET} | tee -a ${RUN_LOG_FILE}
f_exit_or_not ${RET}
((TEST_PASS++))

f_do_umount
}

function f_cleanup()
{
:
}

################################################################################
# Main Entry
################################################################################

#redefine 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_setup $*

START_TIME=${SECONDS}
f_LogRunMsg ${RUN_LOG_FILE} "=====================Filecheck tests start: `date`\
=====================\n"
f_LogMsg ${DETAIL_LOG_FILE} "=====================Filecheck tests start: `date`\
====================="

f_runtest

END_TIME=${SECONDS}
f_LogRunMsg ${RUN_LOG_FILE} "=====================Filecheck tests end: `date`\
=====================\n"
f_LogMsg ${DETAIL_LOG_FILE} "=====================Filecheck tests end: `date`\
====================="

f_LogRunMsg ${RUN_LOG_FILE} "Time elapsed(s): $((${END_TIME}-${START_TIME}))\n"
f_LogRunMsg ${RUN_LOG_FILE} "Tests total: ${TEST_NO}\n"
f_LogRunMsg ${RUN_LOG_FILE} "Tests passed: ${TEST_PASS}\n"
53 changes: 53 additions & 0 deletions programs/online_filecheck/filecheck_utils.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
#!/bin/bash

PATH=$PATH:/usr/sbin/

DEBUGFS_BIN="`which sudo` -u root `which debugfs.ocfs2`"
FSWRECK_BIN="`which sudo` -u root `dirname ${0}`/fswreck"
SUDO_BASH="`which sudo` -u root bash -c"
SUDO_CAT="`which sudo` -u root `which cat`"

f_check_file()
{
local inode=$1
local check_file=$2
local error_type=$3
local log_file=$4

echo -e "${SUDO_BASH} \"echo ${inode} > ${check_file}\"" >> ${log_file} 2>&1
${SUDO_BASH} "echo ${inode} > ${check_file}"
sleep 0.1
${SUDO_CAT} ${check_file} > .tmp 2>&1
cat .tmp | head -n 1 >> ${log_file} 2>&1
LINE=`cat .tmp | tail -n 1`
rm -f -- .tmp
echo -e "${LINE}" >> ${log_file}
local ERROR=`echo ${LINE} | awk '{print $3}'`
f_LogMsg ${log_file} "Error type: ${ERROR}"
if [ ${ERROR} != "${error_type}" ];then
f_LogMsg ${log_file} "Unexpected error type, exit..."
false
fi
}

f_fix_file()
{
local inode=$1
local fix_file=$2
local log_file=$3

echo -e "${SUDO_BASH} \"echo ${inode} > ${fix_file}\"" >> ${log_file} 2>&1
${SUDO_BASH} "echo ${inode} > ${fix_file}"
sleep 0.1
${SUDO_CAT} ${fix_file} > .tmp 2>&1
cat .tmp | head -n 1 >> ${log_file} 2>&1
LINE=`cat .tmp | tail -n 1`
rm -f -- .tmp
echo -e "${LINE}" >> ${log_file}
local RESULT=`echo ${LINE} | awk '{print $3}'`
f_LogMsg ${log_file} "Fix result: ${RESULT}"
if [ ${RESULT} != "SUCCESS" ];then
f_LogMsg ${log_file} "Failed to fix! Exit..."
false
fi
}
Loading

0 comments on commit b64f500

Please sign in to comment.