From patchwork Thu Nov 9 08:32:42 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Eryu Guan X-Patchwork-Id: 10050483 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 58937601EB for ; Thu, 9 Nov 2017 08:32:52 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 45E272ABC2 for ; Thu, 9 Nov 2017 08:32:52 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 3ABFF2ABC6; Thu, 9 Nov 2017 08:32:52 +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 B1CE52ABC2 for ; Thu, 9 Nov 2017 08:32:51 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753651AbdKIIcv (ORCPT ); Thu, 9 Nov 2017 03:32:51 -0500 Received: from mx1.redhat.com ([209.132.183.28]:56084 "EHLO mx1.redhat.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753644AbdKIIct (ORCPT ); Thu, 9 Nov 2017 03:32:49 -0500 Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.phx2.redhat.com [10.5.11.13]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 40F2982111; Thu, 9 Nov 2017 08:32:49 +0000 (UTC) Received: from localhost (dhcp-12-147.nay.redhat.com [10.66.12.147]) by smtp.corp.redhat.com (Postfix) with ESMTP id B1B446E53F; Thu, 9 Nov 2017 08:32:48 +0000 (UTC) From: Eryu Guan To: fstests@vger.kernel.org Cc: linux-xfs@vger.kernel.org, Eryu Guan Subject: [PATCH v2 2/2] generic: test zero page cache beyond new EOF on truncate down Date: Thu, 9 Nov 2017 16:32:42 +0800 Message-Id: <20171109083242.32373-2-eguan@redhat.com> In-Reply-To: <20171109083242.32373-1-eguan@redhat.com> References: <20171109083242.32373-1-eguan@redhat.com> X-Scanned-By: MIMEDefang 2.79 on 10.5.11.13 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.26]); Thu, 09 Nov 2017 08:32:49 +0000 (UTC) Sender: fstests-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: fstests@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP From mmap(2) manpage, "a file is mapped in multiples of the page size. For a file that is not a multiple of the page size, the remaining memory is zeroed when mapped", this test is to test this behavior on truncate down. This is inspired by an XFS bug that truncate down fails to zero page cache beyond new EOF and causes stale data written to disk unexpectedly and a subsequent mmap sees non-zeros post EOF. Patch "xfs: truncate pagecache before writeback in xfs_setattr_size()" fixed the bug on XFS. Signed-off-by: Eryu Guan Reviewed-by: Darrick J. Wong --- v2: - update comments and commit log to reflect the final fix of the bug - dump fsx error message to stdout on error, so it's easier to know what is failing tests/generic/466 | 135 ++++++++++++++++++++++++++++++++++++++++++++++++++ tests/generic/466.out | 9 ++++ tests/generic/group | 1 + 3 files changed, 145 insertions(+) create mode 100755 tests/generic/466 create mode 100644 tests/generic/466.out diff --git a/tests/generic/466 b/tests/generic/466 new file mode 100755 index 000000000000..435bd39a42cc --- /dev/null +++ b/tests/generic/466 @@ -0,0 +1,135 @@ +#! /bin/bash +# FS QA Test 466 +# +# Test that mmap read doesn't see non-zero data past EOF on truncate down. +# +# This is inspired by an XFS bug that truncate down fails to zero page cache +# beyond new EOF and causes stale data written to disk unexpectedly and a +# subsequent mmap reads and sees non-zeros post EOF. +# +# Patch "xfs: truncate pagecache before writeback in xfs_setattr_size()" fixed +# the bug on XFS. +# +#----------------------------------------------------------------------- +# Copyright (c) 2017 Red Hat Inc., 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/$$ +file=$TEST_DIR/$seq.fsx +status=1 # failure is the default! +trap "_cleanup; exit \$status" 0 1 2 3 15 + +_cleanup() +{ + cd / + rm -f $file $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 +_supported_fs generic +_supported_os Linux +_require_test + +run_fsx() +{ + $here/ltp/fsx $2 --replay-ops $1 $file 2>&1 | tee -a $seqres.full >$tmp.fsx + if [ ${PIPESTATUS[0]} -ne 0 ]; then + cat $tmp.fsx + exit 1 + fi +} + +# run fsx with and without fsync(2) after write to get more coverage +test_fsx() +{ + echo "fsx --replay-ops ${1#*.}" + run_fsx $1 + + echo "fsx -y --replay-ops ${1#*.}" + run_fsx $1 -y +} + +# simplified fsx operations that work on small & not blocksize-aligned offsets, +# so filesystems with small block size could reproduce too +cat >$tmp.fsxops.0 <$tmp.fsxops.1 <$tmp.fsxops.2 <$tmp.fsxops.3 <