From patchwork Thu Dec 25 01:32:14 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Qu Wenruo X-Patchwork-Id: 5540791 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 1DF5FBEEBA for ; Thu, 25 Dec 2014 01:34:28 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 222AE201E4 for ; Thu, 25 Dec 2014 01:34:27 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 1099B201DD for ; Thu, 25 Dec 2014 01:34:26 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752078AbaLYBeX (ORCPT ); Wed, 24 Dec 2014 20:34:23 -0500 Received: from cn.fujitsu.com ([59.151.112.132]:5529 "EHLO heian.cn.fujitsu.com" rhost-flags-OK-FAIL-OK-FAIL) by vger.kernel.org with ESMTP id S1752013AbaLYBeQ (ORCPT ); Wed, 24 Dec 2014 20:34:16 -0500 X-IronPort-AV: E=Sophos;i="5.04,848,1406563200"; d="scan'208";a="47022182" Received: from unknown (HELO edo.cn.fujitsu.com) ([10.167.33.5]) by heian.cn.fujitsu.com with ESMTP; 25 Dec 2014 09:30:53 +0800 Received: from G08CNEXCHPEKD02.g08.fujitsu.local (localhost.localdomain [127.0.0.1]) by edo.cn.fujitsu.com (8.14.3/8.13.1) with ESMTP id sBP1XlSg020168 for ; Thu, 25 Dec 2014 09:33:47 +0800 Received: from localhost.localdomain (10.167.226.33) by G08CNEXCHPEKD02.g08.fujitsu.local (10.167.33.89) with Microsoft SMTP Server (TLS) id 14.3.181.6; Thu, 25 Dec 2014 09:34:14 +0800 From: Qu Wenruo To: Subject: [PATCH 4/5] btrfs-progs: Move leaf-corruption no extent data case and add verification script Date: Thu, 25 Dec 2014 09:32:14 +0800 Message-ID: <1419471135-10878-5-git-send-email-quwenruo@cn.fujitsu.com> X-Mailer: git-send-email 2.2.1 In-Reply-To: <1419471135-10878-1-git-send-email-quwenruo@cn.fujitsu.com> References: <1419471135-10878-1-git-send-email-quwenruo@cn.fujitsu.com> MIME-Version: 1.0 X-Originating-IP: [10.167.226.33] 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, T_RP_MATCHES_RCVD, UNPARSEABLE_RELAY autolearn=ham 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 Move leaf-corruption type no extent data case to its dir, and add verification script in test.sh The verification script is based on manual btrfs-debug-tree check. The image can also be reused to other leaf-corruption type, like corrupted leaf contains regular file extent data case. Signed-off-by: Qu Wenruo --- .../no_data_extent.tar.xz} | Bin tests/fsck-tests/012-leaf-corruption/test.sh | 119 +++++++++++++++++++++ 2 files changed, 119 insertions(+) rename tests/fsck-tests/{013-leaf-corruption-no-extent-data.tar.xz => 012-leaf-corruption/no_data_extent.tar.xz} (100%) create mode 100755 tests/fsck-tests/012-leaf-corruption/test.sh diff --git a/tests/fsck-tests/013-leaf-corruption-no-extent-data.tar.xz b/tests/fsck-tests/012-leaf-corruption/no_data_extent.tar.xz similarity index 100% rename from tests/fsck-tests/013-leaf-corruption-no-extent-data.tar.xz rename to tests/fsck-tests/012-leaf-corruption/no_data_extent.tar.xz diff --git a/tests/fsck-tests/012-leaf-corruption/test.sh b/tests/fsck-tests/012-leaf-corruption/test.sh new file mode 100755 index 0000000..edf7719 --- /dev/null +++ b/tests/fsck-tests/012-leaf-corruption/test.sh @@ -0,0 +1,119 @@ +#!/bin/bash + +source $top/tests/common + +# Check file list for leaf corruption, no regular/preallocated +# file extent case. +# Corrupted leaf is 20832256, which contains inode 1862~1872 +# +# 1862, ref from leaf 20828160 key 24(DIR_ITEM) +# 1863, ref from leaf 605388 item key 11(DIR_ITEM) +# 1864, no ref to rebuild, no need to rebuild +# 1865, ref from leaf 19767296 key 23(DIR_ITEM) +# 1866-1868 no ref to rebuild, all refs in corrupted leaf +# 1869, ref from leaf 4976640 key 22(DIR_ITEM) +# 1870 no ref to rebuild, all refs in corrupted leaf +# 1871, ref from leaf 19746816 key 38(DIR_ITEM) +# 1872, ref from leaf 19767296 key 14(DIR_ITEM) +# The list format is: +# INO SIZE MODE NAME +# INO: inode number +# SIZE: file size, only checked for regular file +# MODE: raw file mode, get from stat +# NAME: file name +leaf_no_data_ext_list=( + 1862 0 40700 "install.d" + 1862 0 40700 "install.d" + 1863 0 40700 "gdb" + 1865 0 40700 "iptables" + 1869 0 40700 "snmp" + 1871 0 100700 "machine-id" + 1872 0 100700 "adjtime" +) + +generate_leaf_corrupt_no_data_ext() +{ + dest=$1 + echo "generating leaf_corrupt_no_data_ext.btrfs-image" >> $RESULT + tar xJf ./no_data_extent.tar.xz || \ + _fail "failed to extract leaf_corrupt_no_data_ext.btrfs-image" + btrfs-image -r test.img.btrfs-image $dest || \ + _fail "failed to extract leaf_corrupt_no_data_ext.btrfs-image" + + # leaf at 20832256 contains no regular data extent, clear its csum to + # corrupt the leaf. + dd if=/dev/zero of=$dest bs=1 count=32 conv=notrunc seek=20832256 \ + 1>/dev/null 2>&1 +} + +check_inode() +{ + path=$1 + ino=$2 + size=$3 + mode=$4 + name=$5 + + # Check whether the inode exists + exists=$(find $path -inum $ino) + if [ -z "$exists" ]; then + _fail "inode $ino not recovered correctly" + fi + + # Check inode type + found_mode=$(printf "%o" 0x$(stat $exists -c %f)) + if [ $found_mode -ne $mode ]; then + echo "$found_mode" + _fail "inode $ino modes not recovered" + fi + + # Check inode size + found_size=$(stat $exists -c %s) + if [ $mode -ne 41700 -a $found_size -ne $size ]; then + _fail "inode $ino size not recovered correctly" + fi + + # Check inode name + if [ "$(basename $exists)" != "$name" ]; then + _fail "inode $ino name not recovered correctly" + else + return 0 + fi +} + +# Check salvaged data in the recovered image +check_leaf_corrupt_no_data_ext() +{ + image=$1 + if [ $UID -ne 0 ]; then + echo " [NOTRUN] verify recovery. need root privilege" + exit 0 + fi + if [ -z $TEST_MNT ]; then + echo "\$TEST_MNT not set, use $(pwd)/tmp as fallback" + TEST_MNT="$(pwd)/tmp" + fi + mkdir -p $TEST_MNT || _fail "failed to create mount point" + mount $image -o ro $TEST_MNT + + i=0 + while [ $i -lt ${#leaf_no_data_ext_list[@]} ]; do + check_inode $TEST_MNT/lost+found \ + ${leaf_no_data_ext_list[i]} \ + ${leaf_no_data_ext_list[i + 1]} \ + ${leaf_no_data_ext_list[i + 2]} \ + ${leaf_no_data_ext_list[i + 3]} \ + ${leaf_no_data_ext_list[i + 4]} + ((i+=4)) + done + umount $TEST_MNT +} + +generate_leaf_corrupt_no_data_ext test.img +check_image test.img +check_leaf_corrupt_no_data_ext test.img + +rm test.img +rm test.img.btrfs-image +# Not used, its function is the same as generate_leaf_corrupt_no_data_ext() +rm generate_image.sh