From patchwork Tue Jul 14 15:37:14 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Filipe Manana X-Patchwork-Id: 6787891 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.29.136]) by patchwork2.web.kernel.org (Postfix) with ESMTP id 29901C05AC for ; Tue, 14 Jul 2015 15:38:51 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 2DE1F205B5 for ; Tue, 14 Jul 2015 15:38:50 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 920A92066F for ; Tue, 14 Jul 2015 15:38:48 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753154AbbGNPhY (ORCPT ); Tue, 14 Jul 2015 11:37:24 -0400 Received: from mail.kernel.org ([198.145.29.136]:44874 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752380AbbGNPhX (ORCPT ); Tue, 14 Jul 2015 11:37:23 -0400 Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 1FE4620498; Tue, 14 Jul 2015 15:37:22 +0000 (UTC) Received: from debian3.lan (bl13-157-51.dsl.telepac.pt [85.246.157.51]) (using TLSv1.2 with cipher AES128-SHA256 (128/128 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id 5F795205B9; Tue, 14 Jul 2015 15:37:20 +0000 (UTC) From: fdmanana@kernel.org To: fstests@vger.kernel.org Cc: linux-btrfs@vger.kernel.org, Filipe Manana Subject: [PATCH] fstests: regression test for the btrfs clone ioctl Date: Tue, 14 Jul 2015 16:37:14 +0100 Message-Id: <1436888234-16254-1-git-send-email-fdmanana@kernel.org> X-Mailer: git-send-email 2.1.3 X-Spam-Status: No, score=-8.3 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 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 From: Filipe Manana This tests that we can not clone an inline extent into a non-zero file offset. Inline extents at non-zero offsets is something btrfs is not prepared for and results in all sorts of corruption and crashes on future IO operations, such as the following BUG_ON() triggered by the last write operation done by this test: [152154.035903] ------------[ cut here ]------------ [152154.036424] kernel BUG at mm/page-writeback.c:2286! [152154.036424] invalid opcode: 0000 [#1] PREEMPT SMP DEBUG_PAGEALLOC (...) [152154.036424] RIP: 0010:[] [] clear_page_dirty_for_io+0x1e/0x90 (...) [152154.036424] Call Trace: [152154.036424] [] lock_and_cleanup_extent_if_need+0x147/0x18d [btrfs] [152154.036424] [] __btrfs_buffered_write+0x245/0x4c8 [btrfs] [152154.036424] [] ? btrfs_file_write_iter+0x150/0x3e0 [btrfs] [152154.036424] [] ? btrfs_file_write_iter+0x15f/0x3e0 [btrfs] [152154.036424] [] btrfs_file_write_iter+0x2cc/0x3e0 [btrfs] [152154.036424] [] __vfs_write+0x7c/0xa5 [152154.036424] [] vfs_write+0xa0/0xe4 [152154.036424] [] SyS_pwrite64+0x64/0x82 [152154.036424] [] system_call_fastpath+0x12/0x6f (...) [152154.242621] ---[ end trace e3d3376b23a57041 ]--- This issue is addressed by the following linux kernel patch for btrfs: "Btrfs: fix file corruption after cloning inline extents". Signed-off-by: Filipe Manana Reviewed-by: Omar Sandoval --- tests/btrfs/096 | 80 +++++++++++++++++++++++++++++++++++++++++++++++++++++ tests/btrfs/096.out | 12 ++++++++ tests/btrfs/group | 1 + 3 files changed, 93 insertions(+) create mode 100755 tests/btrfs/096 create mode 100644 tests/btrfs/096.out diff --git a/tests/btrfs/096 b/tests/btrfs/096 new file mode 100755 index 0000000..f5b3a7f --- /dev/null +++ b/tests/btrfs/096 @@ -0,0 +1,80 @@ +#! /bin/bash +# FSQA Test No. 096 +# +# Test that we can not clone an inline extent into a non-zero file offset. +# +#----------------------------------------------------------------------- +# +# Copyright (C) 2015 SUSE Linux Products GmbH. All Rights Reserved. +# Author: Filipe Manana +# +# 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" +tmp=/tmp/$$ +status=1 # failure is the default! +trap "_cleanup; exit \$status" 0 1 2 3 15 + +_cleanup() +{ + rm -f $tmp.* +} + +# get standard environment, filters and checks +. ./common/rc +. ./common/filter + +# real QA test starts here +_need_to_be_root +_supported_fs btrfs +_supported_os Linux +_require_scratch +_require_cloner + +rm -f $seqres.full + +_scratch_mkfs >>$seqres.full 2>&1 +_scratch_mount + +# Create our test files. File foo has the same 2K of data at offset 4K as file +# bar has at its offset 0. +$XFS_IO_PROG -f -s -c "pwrite -S 0xaa 0 4K" \ + -c "pwrite -S 0xbb 4k 2K" \ + -c "pwrite -S 0xcc 8K 4K" \ + $SCRATCH_MNT/foo | _filter_xfs_io + +# File bar consists of a single inline extent (2K size). +$XFS_IO_PROG -f -s -c "pwrite -S 0xbb 0 2K" \ + $SCRATCH_MNT/bar | _filter_xfs_io + +# Now call the clone ioctl to clone the extent of file bar into file foo at its +# offset 4K. This made file foo have an inline extent at offset 4K, something +# which the btrfs code can not deal with in future IO operations because all +# inline extents are supposed to start at an offset of 0, resulting in all sorts +# of chaos. +# So here we validate that the clone ioctl returns an EOPNOTSUPP, which is what +# it returns for other cases dealing with inlined extents. +$CLONER_PROG -s 0 -d $((4 * 1024)) -l $((2 * 1024)) \ + $SCRATCH_MNT/bar $SCRATCH_MNT/foo + +# Because of the inline extent at offset 4K, the following write made the kernel +# crash with a BUG_ON(). +$XFS_IO_PROG -c "pwrite -S 0xdd 6K 2K" $SCRATCH_MNT/foo | _filter_xfs_io + +status=0 +exit diff --git a/tests/btrfs/096.out b/tests/btrfs/096.out new file mode 100644 index 0000000..235198d --- /dev/null +++ b/tests/btrfs/096.out @@ -0,0 +1,12 @@ +QA output created by 096 +wrote 4096/4096 bytes at offset 0 +XXX Bytes, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec) +wrote 2048/2048 bytes at offset 4096 +XXX Bytes, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec) +wrote 4096/4096 bytes at offset 8192 +XXX Bytes, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec) +wrote 2048/2048 bytes at offset 0 +XXX Bytes, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec) +clone failed: Operation not supported +wrote 2048/2048 bytes at offset 6144 +XXX Bytes, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec) diff --git a/tests/btrfs/group b/tests/btrfs/group index 79feea9..6ff5f3d 100644 --- a/tests/btrfs/group +++ b/tests/btrfs/group @@ -97,3 +97,4 @@ 093 auto quick clone 094 auto quick send 095 auto quick metadata +096 auto quick clone