From patchwork Wed Feb 26 02:32:58 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Qu Wenruo X-Patchwork-Id: 3720521 Return-Path: X-Original-To: patchwork-linux-btrfs@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork2.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.19.201]) by patchwork2.web.kernel.org (Postfix) with ESMTP id 39813BF13A for ; Wed, 26 Feb 2014 02:38:04 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 2335B201F7 for ; Wed, 26 Feb 2014 02:38:02 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 20ADD201F0 for ; Wed, 26 Feb 2014 02:38:01 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752074AbaBZCh4 (ORCPT ); Tue, 25 Feb 2014 21:37:56 -0500 Received: from cn.fujitsu.com ([222.73.24.84]:11365 "EHLO song.cn.fujitsu.com" rhost-flags-OK-FAIL-OK-OK) by vger.kernel.org with ESMTP id S1751399AbaBZCh4 (ORCPT ); Tue, 25 Feb 2014 21:37:56 -0500 X-IronPort-AV: E=Sophos;i="4.97,544,1389715200"; d="scan'208";a="9605312" Received: from unknown (HELO tang.cn.fujitsu.com) ([10.167.250.3]) by song.cn.fujitsu.com with ESMTP; 26 Feb 2014 10:33:34 +0800 Received: from fnstmail02.fnst.cn.fujitsu.com (tang.cn.fujitsu.com [127.0.0.1]) by tang.cn.fujitsu.com (8.14.3/8.13.1) with ESMTP id s1Q2bJuS002205 for ; Wed, 26 Feb 2014 10:37:24 +0800 Received: from adam-work.lan ([10.167.226.24]) by fnstmail02.fnst.cn.fujitsu.com (Lotus Domino Release 8.5.3) with ESMTP id 2014022610293640-224633 ; Wed, 26 Feb 2014 10:29:36 +0800 From: Qu Wenruo To: linux-btrfs@vger.kernel.org Subject: [PATCH] btrfs-progs: Add test for btrfsck on "--init-csum/extent-tree" Date: Wed, 26 Feb 2014 10:32:58 +0800 Message-Id: <1393381978-11709-1-git-send-email-quwenruo@cn.fujitsu.com> X-Mailer: git-send-email 1.9.0 X-MIMETrack: Itemize by SMTP Server on mailserver/fnst(Release 8.5.3|September 15, 2011) at 2014/02/26 10:29:36, Serialize by Router on mailserver/fnst(Release 8.5.3|September 15, 2011) at 2014/02/26 10:35:04, Serialize complete at 2014/02/26 10:35:04 Sender: linux-btrfs-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-btrfs@vger.kernel.org X-Spam-Status: No, score=-6.9 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_HI, RP_MATCHES_RCVD, UNPARSEABLE_RELAY autolearn=unavailable version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP Before this patchset btrfsck with "--init-csum-tree --extent-tree" will corrupt the btrfs fs. This patch will add test case for the bug. Signed-off-by: Qu Wenruo --- tests/fsck-tests.sh | 49 +++++++++++++++++++++++++++++++++++++++++-------- 1 file changed, 41 insertions(+), 8 deletions(-) diff --git a/tests/fsck-tests.sh b/tests/fsck-tests.sh index 25c390d..03b0586 100644 --- a/tests/fsck-tests.sh +++ b/tests/fsck-tests.sh @@ -6,27 +6,60 @@ # here=`pwd` +log=fsck-tests-results.txt +img=test.img +mp=mount_point _fail() { - echo "$*" | tee -a fsck-tests-results.txt + echo "$*" | tee -a $log exit 1 } -rm -f fsck-tests-results.txt +_clean() +{ + rm -f $log &> /dev/null + rm -f $img &> /dev/null + umount $mp &> /dev/null + rm -rf $mp &> /dev/null +} + +_init() +{ + _clean + touch $img + truncate -s 5G $img + mkdir $mp +} + +_init for i in $(find $here/tests/fsck-tests -name '*.img') do echo " [TEST] $(basename $i)" - echo "testing image $i" >> fsck-tests-results.txt - $here/btrfs-image -r $i test.img >> fsck-tests-results.txt 2>&1 \ - || _fail "restore failed" - $here/btrfsck test.img >> fsck-test-results.txt 2>&1 + echo "testing image $i" >> $log + $here/btrfs-image -r $i $img >> $log 2>&1 || _fail "restore failed" + $here/btrfsck $img >> $log 2>&1 [ $? -eq 0 ] && _fail "btrfsck should have detected corruption" - $here/btrfsck --repair test.img >> fsck-test-results.txt 2>&1 || \ + $here/btrfsck --repair $img >> $log 2>&1 || \ _fail "btrfsck should have repaired the image" - $here/btrfsck test.img >> fsck-test-results.txt 2>&1 || \ + $here/btrfsck $img >> $log 2>&1 || \ _fail "btrfsck did not correct corruption" + done + +if [[ $EUID -ne 0 ]]; then + echo "init extent csum tree test needs to be run by root" + _clean + exit 0 +fi +echo " [TEST] init extent csum tree" +$here/mkfs.btrfs $img -f >> $log 2>&1 +$here/btrfsck $img --init-extent-tree --init-csum-tree >> $log 2>&1 +# just test whether the mount will success, since extent/csum tree is cleared +# it will never pass btrfsck, but it should be OK to be mounted. +mount $img $mp -t btrfs >> $log 2>&1 || _fail "btrfsck corrupt the img" + +_clean