From patchwork Fri Jan 5 11:01:24 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Gu Jinxiang X-Patchwork-Id: 10146311 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id EB91E601A1 for ; Fri, 5 Jan 2018 11:17:36 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id DDFCB28816 for ; Fri, 5 Jan 2018 11:17:36 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id D32A32882D; Fri, 5 Jan 2018 11:17:36 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-6.9 required=2.0 tests=BAYES_00,RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 408D328816 for ; Fri, 5 Jan 2018 11:17:36 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751596AbeAELRd (ORCPT ); Fri, 5 Jan 2018 06:17:33 -0500 Received: from mail.cn.fujitsu.com ([183.91.158.132]:34826 "EHLO heian.cn.fujitsu.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1751539AbeAELRb (ORCPT ); Fri, 5 Jan 2018 06:17:31 -0500 X-IronPort-AV: E=Sophos;i="5.43,368,1503331200"; d="scan'208";a="34719074" Received: from bogon (HELO cn.fujitsu.com) ([10.167.33.5]) by heian.cn.fujitsu.com with ESMTP; 05 Jan 2018 19:17:28 +0800 Received: from G08CNEXCHPEKD02.g08.fujitsu.local (unknown [10.167.33.83]) by cn.fujitsu.com (Postfix) with ESMTP id 5D8BC48AEA0A for ; Fri, 5 Jan 2018 19:17:27 +0800 (CST) Received: from localhost.localdomain (10.167.226.132) by G08CNEXCHPEKD02.g08.fujitsu.local (10.167.33.89) with Microsoft SMTP Server (TLS) id 14.3.361.1; Fri, 5 Jan 2018 19:17:26 +0800 From: Gu Jinxiang To: Subject: [v6 16/16] btrfs-progs: add test for offline-scrub Date: Fri, 5 Jan 2018 19:01:24 +0800 Message-ID: <1515150084-17231-17-git-send-email-gujx@cn.fujitsu.com> X-Mailer: git-send-email 1.9.1 In-Reply-To: <1515150084-17231-1-git-send-email-gujx@cn.fujitsu.com> References: <1515150084-17231-1-git-send-email-gujx@cn.fujitsu.com> MIME-Version: 1.0 X-Originating-IP: [10.167.226.132] X-yoursite-MailScanner-ID: 5D8BC48AEA0A.A7F1E X-yoursite-MailScanner: Found to be clean X-yoursite-MailScanner-From: gujx@cn.fujitsu.com Sender: linux-btrfs-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-btrfs@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP Add a test for offline-scrub. The process of this test case: 1)create a filesystem with profile raid10 2)mount the filesystem, create a file in the mount point, and write some data to the file 3)get the logical address of the file's extent data 4)get the physical address of the logical address 5)overwrite the contents in the physical address 6)use offline scrub to check and repair it Signed-off-by: Gu Jinxiang --- Makefile | 6 ++- tests/scrub-tests.sh | 43 +++++++++++++++++++ tests/scrub-tests/001-offline-scrub-raid10/test.sh | 50 ++++++++++++++++++++++ 3 files changed, 98 insertions(+), 1 deletion(-) create mode 100755 tests/scrub-tests.sh create mode 100755 tests/scrub-tests/001-offline-scrub-raid10/test.sh diff --git a/Makefile b/Makefile index fa3ebc86..0a3060f5 100644 --- a/Makefile +++ b/Makefile @@ -322,6 +322,10 @@ test-cli: btrfs @echo " [TEST] cli-tests.sh" $(Q)bash tests/cli-tests.sh +test-scrub: btrfs mkfs.btrfs + @echo " [TEST] scrub-tests.sh" + $(Q)bash tests/scrub-tests.sh + test-clean: @echo "Cleaning tests" $(Q)bash tests/clean-tests.sh @@ -332,7 +336,7 @@ test-inst: all $(MAKE) $(MAKEOPTS) DESTDIR=$$tmpdest install && \ $(RM) -rf -- $$tmpdest -test: test-fsck test-mkfs test-convert test-misc test-fuzz test-cli +test: test-fsck test-mkfs test-convert test-misc test-fuzz test-cli test-scrub # # NOTE: For static compiles, you need to have all the required libs diff --git a/tests/scrub-tests.sh b/tests/scrub-tests.sh new file mode 100755 index 00000000..697137f4 --- /dev/null +++ b/tests/scrub-tests.sh @@ -0,0 +1,43 @@ +#!/bin/bash +# +# btrfs scrub tests + +LANG=C +SCRIPT_DIR=$(dirname $(readlink -f "$0")) +TOP=$(readlink -f "$SCRIPT_DIR/../") +TEST_DEV=${TEST_DEV:-} +RESULTS="$TOP/tests/scrub-tests-results.txt" +IMAGE="$TOP/tests/test.img" + +source "$TOP/tests/common" + +export TOP +export RESULTS +export LANG +export IMAGE +export TEST_DEV + +rm -f "$RESULTS" + +check_prereq btrfs +check_kernel_support + +# The tests are driven by their custom script called 'test.sh' + +for i in $(find "$TOP/tests/scrub-tests" -maxdepth 1 -mindepth 1 -type d \ + ${TEST:+-name "$TEST"} | sort) +do + echo " [TEST/scrub] $(basename $i)" + cd "$i" + echo "=== Entering $i" >> "$RESULTS" + if [ -x test.sh ]; then + ./test.sh + if [ $? -ne 0 ]; then + if [[ $TEST_LOG =~ dump ]]; then + cat "$RESULTS" + fi + _fail "test failed for case $(basename $i)" + fi + fi + cd "$TOP" +done diff --git a/tests/scrub-tests/001-offline-scrub-raid10/test.sh b/tests/scrub-tests/001-offline-scrub-raid10/test.sh new file mode 100755 index 00000000..c609d870 --- /dev/null +++ b/tests/scrub-tests/001-offline-scrub-raid10/test.sh @@ -0,0 +1,50 @@ +#!/bin/bash + +source $TOP/tests/common + +check_prereq mkfs.btrfs +check_prereq btrfs +check_prereq btrfs-debug-tree +check_prereq btrfs-map-logical + +setup_root_helper + +setup_loopdevs 4 +prepare_loopdevs + +dev1=${loopdevs[1]} +file=$TEST_MNT/file + +mkfs_multi() +{ + run_check $SUDO_HELPER $TOP/mkfs.btrfs -f $@ ${loopdevs[@]} +} + +#create filesystem +mkfs_multi -d raid10 -m raid10 +run_check $SUDO_HELPER mount -t btrfs $dev1 "$TEST_MNT" + +#write some data +run_check $SUDO_HELPER touch $file +run_check $SUDO_HELPER dd if=/dev/zero of=$file bs=64K count=1 +run_check sync -f $file + +#get the extent data's logical address of $file +logical=$($SUDO_HELPER $TOP/btrfs-debug-tree -t 5 $dev1 | grep -oP '(?<=byte\s)\d+') + +#get the first physical address and device of $file's data +read physical dev< <($SUDO_HELPER $TOP/btrfs-map-logical -l $logical $dev1| head -1 |cut -d ' ' -f6,8) + +#then modify the data +run_check $SUDO_HELPER dd if=/dev/random of=$dev seek=$(($physical/65536)) bs=64K count=1 +run_check sync -f $file + +run_check $SUDO_HELPER umount "$TEST_MNT" +log=$(run_check_stdout $SUDO_HELPER $TOP/btrfs scrub start --offline $dev1) +cleanup_loopdevs + +#check result +result=$(echo $log | grep 'len 65536 REPARIED: has corrupted mirror, repaired') +if [[ -z "$result" ]] ;then + _fail "scrub repair faild" +fi