From patchwork Tue Feb 14 20:36:17 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Filipe Manana X-Patchwork-Id: 9572851 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 D4DF760573 for ; Tue, 14 Feb 2017 20:36:41 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id C73FC283F9 for ; Tue, 14 Feb 2017 20:36:41 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id BC11728415; Tue, 14 Feb 2017 20:36:41 +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=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 3CAFE2840B for ; Tue, 14 Feb 2017 20:36:40 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751675AbdBNUgc (ORCPT ); Tue, 14 Feb 2017 15:36:32 -0500 Received: from mail.kernel.org ([198.145.29.136]:37340 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751517AbdBNUgb (ORCPT ); Tue, 14 Feb 2017 15:36:31 -0500 Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 5C32F202EB; Tue, 14 Feb 2017 20:36:24 +0000 (UTC) Received: from debian3.lan (bl12-226-64.dsl.telepac.pt [85.245.226.64]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-SHA256 (128/128 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id 62B352021A; Tue, 14 Feb 2017 20:36:22 +0000 (UTC) From: fdmanana@kernel.org To: fstests@vger.kernel.org Cc: linux-btrfs@vger.kernel.org, Filipe Manana Subject: [PATCH] fstests: add test for truncate after a mix of dio and buffered writes Date: Tue, 14 Feb 2017 20:36:17 +0000 Message-Id: <1487104577-14110-1-git-send-email-fdmanana@kernel.org> X-Mailer: git-send-email 2.7.0.rc3 X-Virus-Scanned: ClamAV using ClamSMTP Sender: fstests-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: fstests@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP From: Filipe Manana Test that if we have a file with a hole, do a mix of direct IO and buffered writes to it and truncate the file to a size that lies in the middle of the hole, after unmounting and mounting again the filesystem, the file has a correct size and no data loss happened. This test is motivated by a bug found in btrfs when used with the no-holes feature (i.e. MKFS_OPTIONS="-O no-holes") which is fixed by the following patch for the linux kernel: Btrfs: fix data loss after truncate when using the no-holes feature Signed-off-by: Filipe Manana --- tests/generic/409 | 75 +++++++++++++++++++++++++++++++++++++++++++++++++++ tests/generic/409.out | 9 +++++++ tests/generic/group | 1 + 3 files changed, 85 insertions(+) create mode 100755 tests/generic/409 create mode 100644 tests/generic/409.out diff --git a/tests/generic/409 b/tests/generic/409 new file mode 100755 index 0000000..8d3fd33 --- /dev/null +++ b/tests/generic/409 @@ -0,0 +1,75 @@ +#! /bin/bash +# FSQA Test No. 409 +# +# Test that if we have a file with a hole, do a mix of direct IO and buffered +# writes to it and truncate the file to a size that lies in the middle of the +# hole, after unmounting and mounting again the filesystem, the file has a +# correct size and no data loss happened. +# +#----------------------------------------------------------------------- +# +# Copyright (C) 2017 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 +_supported_fs generic +_supported_os Linux +_require_scratch + +rm -f $seqres.full + +_scratch_mkfs >>$seqres.full 2>&1 +_scratch_mount + +# Create out test file with two extents and a hole between those extents. +# The extent that lies beyond the hole must be written using direct IO and later +# we truncate the file to a size that lies within the hole's range. +$XFS_IO_PROG -f -c "pwrite -S 0x01 0K 32K" $SCRATCH_MNT/foo | _filter_xfs_io +$XFS_IO_PROG -d -c "pwrite -S 0x02 -b 32K 64K 32K" $SCRATCH_MNT/foo \ + | _filter_xfs_io + +# Now truncate our file to a smaller size that lies behind the offset used by +# the previous direct IO write and that lies in a file hole. +$XFS_IO_PROG -c "truncate 60K" $SCRATCH_MNT/foo + +# Now get file digests before unmounting the filesystem and after mounting it +# again. The digests should match (same file data and size in both cases). +echo "File digest before unmounting the filesystem:" +md5sum $SCRATCH_MNT/foo | _filter_scratch +_scratch_cycle_mount +echo "File digest after mounting again the filesystem:" +md5sum $SCRATCH_MNT/foo | _filter_scratch + +status=0 +exit diff --git a/tests/generic/409.out b/tests/generic/409.out new file mode 100644 index 0000000..02a7dc5 --- /dev/null +++ b/tests/generic/409.out @@ -0,0 +1,9 @@ +QA output created by 409 +wrote 32768/32768 bytes at offset 0 +XXX Bytes, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec) +wrote 32768/32768 bytes at offset 65536 +XXX Bytes, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec) +File digest before unmounting the filesystem: +3c5ca3c3ab42f4b04d7e7eb0b0d4d806 SCRATCH_MNT/foo +File digest after mounting again the filesystem: +3c5ca3c3ab42f4b04d7e7eb0b0d4d806 SCRATCH_MNT/foo diff --git a/tests/generic/group b/tests/generic/group index d0bc47d..074b494 100644 --- a/tests/generic/group +++ b/tests/generic/group @@ -411,3 +411,4 @@ 406 auto quick dangerous 407 auto quick clone metadata 408 auto quick clone dedupe metadata +409 auto quick metadata