From patchwork Thu Apr 6 01:28:53 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Qu Wenruo X-Patchwork-Id: 9665947 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 153E760364 for ; Thu, 6 Apr 2017 01:29:12 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 02F6F28595 for ; Thu, 6 Apr 2017 01:29:12 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id EB2E72859A; Thu, 6 Apr 2017 01:29:11 +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 328EC2858B for ; Thu, 6 Apr 2017 01:29:11 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1754505AbdDFB3I (ORCPT ); Wed, 5 Apr 2017 21:29:08 -0400 Received: from cn.fujitsu.com ([59.151.112.132]:40745 "EHLO heian.cn.fujitsu.com" rhost-flags-OK-FAIL-OK-FAIL) by vger.kernel.org with ESMTP id S1756249AbdDFB3E (ORCPT ); Wed, 5 Apr 2017 21:29:04 -0400 X-IronPort-AV: E=Sophos;i="5.22,518,1449504000"; d="scan'208";a="17406419" Received: from unknown (HELO cn.fujitsu.com) ([10.167.33.5]) by heian.cn.fujitsu.com with ESMTP; 06 Apr 2017 09:29:01 +0800 Received: from G08CNEXCHPEKD01.g08.fujitsu.local (unknown [10.167.33.80]) by cn.fujitsu.com (Postfix) with ESMTP id 9DC0B4D14A5D; Thu, 6 Apr 2017 09:29:01 +0800 (CST) Received: from localhost.localdomain (10.167.226.34) by G08CNEXCHPEKD01.g08.fujitsu.local (10.167.33.89) with Microsoft SMTP Server (TLS) id 14.3.319.2; Thu, 6 Apr 2017 09:29:01 +0800 From: Qu Wenruo To: , , , Subject: [PATCH v3] fstests: btrfs: Check if btrfs will create inline-then-regular file extents Date: Thu, 6 Apr 2017 09:28:53 +0800 Message-ID: <20170406012853.31414-1-quwenruo@cn.fujitsu.com> X-Mailer: git-send-email 2.12.2 MIME-Version: 1.0 X-Originating-IP: [10.167.226.34] X-yoursite-MailScanner-ID: 9DC0B4D14A5D.AE299 X-yoursite-MailScanner: Found to be clean X-yoursite-MailScanner-From: quwenruo@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 Btrfs allows inline file extent if and only if 1) It's at offset 0 2) It's smaller than min(max_inline, page_size) Although we don't specify if the size is before compression or after compression. At least according to current behavior, we are only limiting the size after compression. 3) It's the only file extent So that if we append existing inline extent, it should be converted to regular file extents. However several users in btrfs mail list have reported invalid inline file extent, which only meets the first two condition, but with regular file extents following. The bug is here for a long long time, so long that we have modified kernel and btrfs-progs to accept such case, but it's still not designed behavior, and must be detected and fixed. Signed-off-by: Qu Wenruo --- v2: All suggested by Eryu Guan Use loop_counts instead of runtime to avoid naming confusion. Fix whitespace issues Use fsync instead of sync Use $XFS_IO_PROG instead of calling xfs_io directly Always output corruption possibility into seqres.full v3: All suggested by Filipe Manana Fix gramma errors Use simpler reproducer Add test case to compress group --- tests/btrfs/140 | 111 ++++++++++++++++++++++++++++++++++++++++++++++++++++ tests/btrfs/140.out | 2 + tests/btrfs/group | 1 + 3 files changed, 114 insertions(+) create mode 100755 tests/btrfs/140 create mode 100644 tests/btrfs/140.out diff --git a/tests/btrfs/140 b/tests/btrfs/140 new file mode 100755 index 0000000..183d9cd --- /dev/null +++ b/tests/btrfs/140 @@ -0,0 +1,111 @@ +#! /bin/bash +# FS QA Test 140 +# +# Check if btrfs will create inline-then-regular file layout. +# +# Btrfs only allows inline file extent if file is small enough, and any +# incoming write enlarges the file beyond max_inline should replace inline +# extents with regular extents. +# This is a long standing bug, so fsck won't detect it and kernel will allow +# normal read on it, but should be avoided. +# +#----------------------------------------------------------------------- +# Copyright (c) 2017 Fujitsu. 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. +# +# This program is distributed in the hope that it would 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 the Free Software Foundation, +# Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA +#----------------------------------------------------------------------- +# + +seq=`basename $0` +seqres=$RESULT_DIR/$seq +echo "QA output created by $seq" + +here=`pwd` +tmp=/tmp/$$ +status=1 # failure is the default! +trap "_cleanup; exit \$status" 0 1 2 3 15 + +_cleanup() +{ + cd / + rm -f $tmp.* +} + +# get standard environment, filters and checks +. ./common/rc +. ./common/filter + +# remove previous $seqres.full before test +rm -f $seqres.full + +# real QA test starts here + +# Modify as appropriate. +_supported_fs btrfs +_supported_os Linux +_require_scratch +_require_btrfs_command inspect-internal dump-tree + +inline_size=2048 +page_size=$(get_page_size) +loop_counts=$(($LOAD_FACTOR * 4)) #The possibility is over 80%, just in case + +do_test() +{ + _scratch_mkfs > /dev/null 2>&1 + + # specify max_inline and compress explicitly to create + # inlined compressed extent + _scratch_mount "-o max_inline=$inline_size,compress" + + # Page sized data will be compressed to quite small size, + # which is about 50 bytes for 4K, 100 bytes for 64K, + # far smaller than $inline_size, causing a inlined compressed + # file extent + $XFS_IO_PROG -f -c "pwrite 0 $page_size" -c "fsync" $SCRATCH_MNT/file \ + > /dev/null 2>&1 + + # Append another page to file in snapshot, since its offset is not + # 0, it will cause regular extent, and should convert inline extent + # to regular too. + $XFS_IO_PROG -c "pwrite $page_size $page_size" $SCRATCH_MNT/file \ + > /dev/null 2>&1 + _scratch_unmount + + # Fsck won't report inline-then-regular as error, as it's so long + # standing that we have no choice but to accept. + # So here we use dump-tree to catch inline extent. + $BTRFS_UTIL_PROG inspect-internal dump-tree -t 5 $SCRATCH_DEV \ + > $tmp.dump_tree 2>&1 + if grep -q inline $tmp.dump_tree; then + cat $tmp.dump_tree >> $seqres.full + echo "Invalid inline file extent detected" + return 1 + fi + return 0 +} + +for i in $(seq 1 $loop_counts); do + do_test + if [ $? -ne 0 ]; then + corrupted=$(($corrupted + 1)) + fi +done + +echo "Corruption possibility: $corrupted/$loop_counts" >> $seqres.full +echo "Silence is golden" + +# success, all done +status=0 +exit diff --git a/tests/btrfs/140.out b/tests/btrfs/140.out new file mode 100644 index 0000000..24e90bc --- /dev/null +++ b/tests/btrfs/140.out @@ -0,0 +1,2 @@ +QA output created by 140 +Silence is golden diff --git a/tests/btrfs/group b/tests/btrfs/group index 641d826..2c38fdd 100644 --- a/tests/btrfs/group +++ b/tests/btrfs/group @@ -142,3 +142,4 @@ 137 auto quick send 138 auto compress 139 auto qgroup +140 auto compress