From patchwork Fri Oct 27 12:53:57 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Eryu Guan X-Patchwork-Id: 10029787 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 DDF716034B for ; Fri, 27 Oct 2017 12:55:53 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id D00B428F5F for ; Fri, 27 Oct 2017 12:55:53 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id C511928F69; Fri, 27 Oct 2017 12:55:53 +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 5A00428F5F for ; Fri, 27 Oct 2017 12:55:53 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752190AbdJ0Mzv (ORCPT ); Fri, 27 Oct 2017 08:55:51 -0400 Received: from mx1.redhat.com ([209.132.183.28]:29723 "EHLO mx1.redhat.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752624AbdJ0Mzs (ORCPT ); Fri, 27 Oct 2017 08:55:48 -0400 Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.phx2.redhat.com [10.5.11.16]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 1FF47C0587C9; Fri, 27 Oct 2017 12:55:48 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com 1FF47C0587C9 Authentication-Results: ext-mx08.extmail.prod.ext.phx2.redhat.com; dmarc=none (p=none dis=none) header.from=redhat.com Authentication-Results: ext-mx08.extmail.prod.ext.phx2.redhat.com; spf=fail smtp.mailfrom=eguan@redhat.com Received: from localhost (dhcp-12-147.nay.redhat.com [10.66.12.147]) by smtp.corp.redhat.com (Postfix) with ESMTP id 73D595C54A; Fri, 27 Oct 2017 12:55:47 +0000 (UTC) From: Eryu Guan To: fstests@vger.kernel.org Cc: linux-xfs@vger.kernel.org, Eryu Guan Subject: [PATCH 2/2] generic: ensure that mmap read doesn't see non-zero past EOF Date: Fri, 27 Oct 2017 20:53:57 +0800 Message-Id: <20171027125357.25222-2-eguan@redhat.com> In-Reply-To: <20171027125357.25222-1-eguan@redhat.com> References: <20171027125357.25222-1-eguan@redhat.com> X-Scanned-By: MIMEDefang 2.79 on 10.5.11.16 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.32]); Fri, 27 Oct 2017 12:55:48 +0000 (UTC) Sender: linux-xfs-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-xfs@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. This is inspired by an XFS bug that truncate down fails to zero partial block beyond new EOF because it sees unwritten extent and skipped zeroing wrongly. But the fact is the unwritten extent has been overwritten by a buffer write, just hasn't been converted to real allocation yet. Signed-off-by: Eryu Guan --- tests/generic/466 | 121 ++++++++++++++++++++++++++++++++++++++++++++++++++ tests/generic/466.out | 9 ++++ tests/generic/group | 1 + 3 files changed, 131 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..0c67bbd27484 --- /dev/null +++ b/tests/generic/466 @@ -0,0 +1,121 @@ +#! /bin/bash +# FS QA Test 466 +# +# Test that mmap read doesn't see non-zero data past EOF. +# +# This is inspired by an XFS bug that truncate down fails to zero partial block +# beyond new EOF because it sees unwritten extent and skipped zeroing wrongly. +# But the fact is the unwritten extent has been overwritten by a buffer write, +# just hasn't been converted to real allocation yet. +# +#----------------------------------------------------------------------- +# 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/$$ +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 +_supported_fs generic +_supported_os Linux +_require_test + +# run fsx with and without fsync(2) after write to get more coverage +do_fsx() +{ + echo "fsx --replay-ops ${1#*.}" + run_fsx --replay-ops $1 >>$seqres.full + echo "fsx -y --replay-ops ${1#*.}" + run_fsx -y --replay-ops $1 >>$seqres.full +} + +# simplified fsx operations that work on small and 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 <