From patchwork Fri Apr 6 13:59:15 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Filipe Manana X-Patchwork-Id: 10331261 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 DE6786020F for ; Mon, 9 Apr 2018 12:29:58 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id CEF1228814 for ; Mon, 9 Apr 2018 12:29:58 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id C36522897B; Mon, 9 Apr 2018 12:29:58 +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=-7.9 required=2.0 tests=BAYES_00, MAILING_LIST_MULTI, RCVD_IN_DNSWL_HI autolearn=unavailable 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 55CD928814 for ; Mon, 9 Apr 2018 12:29:58 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751505AbeDIM34 (ORCPT ); Mon, 9 Apr 2018 08:29:56 -0400 Received: from mail.kernel.org ([198.145.29.99]:35828 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1750759AbeDIM3z (ORCPT ); Mon, 9 Apr 2018 08:29:55 -0400 Received: from debian3.lan (bl12-226-64.dsl.telepac.pt [85.245.226.64]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id 6E82B20838; Mon, 9 Apr 2018 12:29:54 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 6E82B20838 Authentication-Results: mail.kernel.org; dmarc=none (p=none dis=none) header.from=kernel.org Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=fdmanana@kernel.org From: fdmanana@kernel.org To: fstests@vger.kernel.org Cc: linux-btrfs@vger.kernel.org, Filipe Manana Subject: [PATCH v2] fstests: generic test for fsync after fallocate Date: Fri, 6 Apr 2018 14:59:15 +0100 Message-Id: <20180406135915.17619-1-fdmanana@kernel.org> X-Mailer: git-send-email 2.11.0 In-Reply-To: <20180405215614.611-1-fdmanana@kernel.org> References: <20180405215614.611-1-fdmanana@kernel.org> 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 Test that fsync operations preserve extents allocated with fallocate(2) that are placed beyond a file's size. This test is motivated by a bug found in btrfs where unwritten extents beyond the inode's i_size were not preserved after a fsync and power failure. The btrfs bug is fixed by the following patch for the linux kernel: "Btrfs: fix loss of prealloc extents past i_size after fsync log replay" Signed-off-by: Filipe Manana --- V2: Use different fiemap filter to not relly on written vs unwritten differences in extents beyond eof, since has xfs a specific but valid behaviour. Also check file sizes after the power failure since the new fiemap filter now merges written and unwritten extents. tests/generic/482 | 124 ++++++++++++++++++++++++++++++++++++++++++++++++++ tests/generic/482.out | 13 ++++++ tests/generic/group | 1 + 3 files changed, 138 insertions(+) create mode 100755 tests/generic/482 create mode 100644 tests/generic/482.out diff --git a/tests/generic/482 b/tests/generic/482 new file mode 100755 index 00000000..a1947693 --- /dev/null +++ b/tests/generic/482 @@ -0,0 +1,124 @@ +#! /bin/bash +# FSQA Test No. 482 +# +# Test that fsync operations preserve extents allocated with fallocate(2) that +# are placed beyond a file's size. +# +#----------------------------------------------------------------------- +# +# Copyright (C) 2018 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() +{ + _cleanup_flakey + cd / + rm -f $tmp.* +} + +# get standard environment, filters and checks +. ./common/rc +. ./common/filter +. ./common/dmflakey +. ./common/punch + +# real QA test starts here +_supported_fs generic +_supported_os Linux +_require_scratch +_require_dm_target flakey +_require_xfs_io_command "falloc" "-k" +_require_xfs_io_command "fiemap" + +rm -f $seqres.full + +_scratch_mkfs >>$seqres.full 2>&1 +_require_metadata_journaling $SCRATCH_DEV +_init_flakey +_mount_flakey + +# Create our test files. +$XFS_IO_PROG -f -c "pwrite -S 0xea 0 256K" $SCRATCH_MNT/foo >/dev/null + +# Create a file with many extents. We later want to shrink truncate it and +# add a prealloc extent beyond its new size. +for ((i = 1; i <= 500; i++)); do + offset=$(((i - 1) * 4 * 1024)) + $XFS_IO_PROG -f -s -c "pwrite -S 0xcf $offset 4K" \ + $SCRATCH_MNT/bar >/dev/null +done + +# A file which already has a prealloc extent beyond its size. +# The fsync done on it is motivated by differences in the btrfs implementation +# of fsync (first fsync has different logic from subsequent fsyncs). +$XFS_IO_PROG -f -c "pwrite -S 0xf1 0 256K" \ + -c "falloc -k 256K 768K" \ + -c "fsync" \ + $SCRATCH_MNT/baz >/dev/null + +# Make sure everything done so far is durably persisted. +sync + +# Allocate an extent beyond the size of the first test file and fsync it. +$XFS_IO_PROG -c "falloc -k 256K 1M"\ + -c "fsync" \ + $SCRATCH_MNT/foo + +# Do a shrinking truncate of our test file, add a prealloc extent to it after +# its new size and fsync it. +$XFS_IO_PROG -c "truncate 256K" \ + -c "falloc -k 256K 1M"\ + -c "fsync" \ + $SCRATCH_MNT/bar + +# Allocate another extent beyond the size of file baz. +$XFS_IO_PROG -c "falloc -k 1M 2M"\ + -c "fsync" \ + $SCRATCH_MNT/baz + +# Simulate a power failure and mount the filesystem to check that the extents +# previously allocated were not lost and the file sizes are correct. +_flakey_drop_and_remount + +echo "File foo fiemap:" +$XFS_IO_PROG -c "fiemap -v" $SCRATCH_MNT/foo | _filter_hole_fiemap +echo "File foo size:" +stat --format %s $SCRATCH_MNT/foo + +echo "File bar fiemap:" +$XFS_IO_PROG -c "fiemap -v" $SCRATCH_MNT/bar | _filter_hole_fiemap +echo "File bar size:" +stat --format %s $SCRATCH_MNT/bar + +echo "File baz fiemap:" +$XFS_IO_PROG -c "fiemap -v" $SCRATCH_MNT/baz | _filter_hole_fiemap +echo "File baz size:" +stat --format %s $SCRATCH_MNT/baz + +_unmount_flakey +_cleanup_flakey + +status=0 +exit diff --git a/tests/generic/482.out b/tests/generic/482.out new file mode 100644 index 00000000..4848894f --- /dev/null +++ b/tests/generic/482.out @@ -0,0 +1,13 @@ +QA output created by 482 +File foo fiemap: +0: [0..2559]: extent +File foo size: +262144 +File bar fiemap: +0: [0..2559]: extent +File bar size: +262144 +File baz fiemap: +0: [0..6143]: extent +File baz size: +262144 diff --git a/tests/generic/group b/tests/generic/group index e8676062..58ac1f00 100644 --- a/tests/generic/group +++ b/tests/generic/group @@ -484,3 +484,4 @@ 479 auto quick metadata 480 auto quick metadata 481 auto quick log metadata +482 auto quick log metadata