From patchwork Wed Oct 10 00:10:59 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Darrick J. Wong" X-Patchwork-Id: 10633437 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id EB7B946E4 for ; Wed, 10 Oct 2018 00:11:07 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id D9AC829C74 for ; Wed, 10 Oct 2018 00:11:07 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id D7F5229C98; Wed, 10 Oct 2018 00:11:07 +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=-3.0 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,MAILING_LIST_MULTI,RCVD_IN_DNSWL_NONE, UNPARSEABLE_RELAY autolearn=ham version=3.3.1 Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id A8E1E29C98 for ; Wed, 10 Oct 2018 00:11:06 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 6EA316B0010; Tue, 9 Oct 2018 20:11:05 -0400 (EDT) Delivered-To: linux-mm-outgoing@kvack.org Received: by kanga.kvack.org (Postfix, from userid 40) id 698CD6B0266; Tue, 9 Oct 2018 20:11:05 -0400 (EDT) X-Original-To: int-list-linux-mm@kvack.org X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 58B9C6B0269; Tue, 9 Oct 2018 20:11:05 -0400 (EDT) X-Original-To: linux-mm@kvack.org X-Delivered-To: linux-mm@kvack.org Received: from mail-pg1-f198.google.com (mail-pg1-f198.google.com [209.85.215.198]) by kanga.kvack.org (Postfix) with ESMTP id 1A34A6B0010 for ; Tue, 9 Oct 2018 20:11:05 -0400 (EDT) Received: by mail-pg1-f198.google.com with SMTP id i189-v6so2542361pge.6 for ; Tue, 09 Oct 2018 17:11:05 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:dkim-signature:subject:from:to:cc:date :message-id:in-reply-to:references:user-agent:mime-version :content-transfer-encoding; bh=cmK57nWF3xCycn+Xe37BmfeUz4DrJ92G4aMskuDnZos=; b=I5M4AY+XTX713HyiXabkTy7mnHuw5ZChaMmSvPZMtMW2K8725lk/TX1hHopMzSGDge bKQYJzEHkSrFhsXF2ETT+OWwzWwOUvlfgedLqM32IcL4QZyFi2cO3GCjWY+dARr42gXp 3Kfh30/eC4vql15UIxhEOfUFg7X4Gs2jlr/nG7hnvtLEzIEKn8IVXM1eZjBWhTuwKE/Z 3JK6qgGy5dccgg4KBbcQmTsvBqw9OaMDAa/WeDMh+Ygidx6894JMQHK/1Z6L/UrFTFaX u5Wd+2iyDCvIQUcPqIjL2VwuYkLNWQi2PoXMY2l6MMGpFXaSV7tnOQtPXri8WOBiZCf8 bxuA== X-Gm-Message-State: ABuFfogQzWpJAMpWEoZkCT6ldWS/9sHuhmXPcnEe1ArDmQlPg4mUkB6h rcdcAvg9UrD84Caxt5nfl/L8bv24H13z2qCK1FqFOyMUvcI3iFakZLYq3/59k3oy+8dvvLsyasD FnKJut8Xh6v64gIvwnPrHiwlDQSL+GDXnHnZHprH5WRPM9dVZ/DqafYQRfVTcfNdjxw== X-Received: by 2002:a62:c2c1:: with SMTP id w62-v6mr11946889pfk.35.1539130264763; Tue, 09 Oct 2018 17:11:04 -0700 (PDT) X-Google-Smtp-Source: ACcGV61rkUV5oH4EsHfYtV9mbIwV278VofhzlthsK9vt5WKOM4voykymqzlPU8kvTQIa4IJ8JKql X-Received: by 2002:a62:c2c1:: with SMTP id w62-v6mr11946842pfk.35.1539130263998; Tue, 09 Oct 2018 17:11:03 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1539130263; cv=none; d=google.com; s=arc-20160816; b=Ph/H+Ov3BSlzehzA/Av0qTggVzOBuItfWaROO009Z1EliM5kUsxgMU6vAiRBYHwDab sjzOYXq3y3Lp+hCIcBz+EkJaCrYr7Y6ECanILAwUuona3QIRzLG7fXO0sT6GxwQ/1oeI RyEtK55dqFIkhGx0r+gOuLkYsQo/byQbugcJD3H2FR6jGyyUVY4UqKHTHbwSxVitRCIK uUzIL94whZWPJsp3+JSDDeyA/c7Pu8ETzYcBiLj2kFe7vt1DgprjK9KFeUwESr9dWOne HKbXAawikFUQC7QRvgXlwGWQeyTOAVodYftLU3RSUL0xkY1UXRuEXXjRYJkF5cZQnFIv o4gQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:user-agent:references :in-reply-to:message-id:date:cc:to:from:subject:dkim-signature; bh=cmK57nWF3xCycn+Xe37BmfeUz4DrJ92G4aMskuDnZos=; b=c2Mqhg+n7TaRCgV5FBgkK/Tm5achwQfsyIwVW3ALCpbQBRN17JklRGeBNv5xw5dPb+ WBW3aviI9vriV4vIaRtL+6096Ba77Q6gBnxm+dY6b1abyRxx1iBmLKicpOZmCUIOtR79 h3DK/cRkLNAaB+uLZujLexsNC67f9lijUGr5y7preVjftkBxjUVv0XIuCD/CaedTSaLD pPgbT2Rx6SzFPJkMLg2ETxdaYks4lauSvyUzbqrA+7o2L+2jNyPOWOI72PdMj0CRTdkX qDJCYsFYnvIpbKwM5sHjNhp3p/DMm+wMhEEYXu9u1TVT/YrQxhxEd/qgID62rXC81Gn3 Y4/g== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@oracle.com header.s=corp-2018-07-02 header.b=RC0YFI13; spf=pass (google.com: domain of darrick.wong@oracle.com designates 141.146.126.78 as permitted sender) smtp.mailfrom=darrick.wong@oracle.com; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=oracle.com Received: from aserp2120.oracle.com (aserp2120.oracle.com. [141.146.126.78]) by mx.google.com with ESMTPS id o5-v6si22612144pgk.300.2018.10.09.17.11.03 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 09 Oct 2018 17:11:03 -0700 (PDT) Received-SPF: pass (google.com: domain of darrick.wong@oracle.com designates 141.146.126.78 as permitted sender) client-ip=141.146.126.78; Authentication-Results: mx.google.com; dkim=pass header.i=@oracle.com header.s=corp-2018-07-02 header.b=RC0YFI13; spf=pass (google.com: domain of darrick.wong@oracle.com designates 141.146.126.78 as permitted sender) smtp.mailfrom=darrick.wong@oracle.com; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=oracle.com Received: from pps.filterd (aserp2120.oracle.com [127.0.0.1]) by aserp2120.oracle.com (8.16.0.22/8.16.0.22) with SMTP id w9A08uCI138874; Wed, 10 Oct 2018 00:11:03 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=oracle.com; h=subject : from : to : cc : date : message-id : in-reply-to : references : mime-version : content-type : content-transfer-encoding; s=corp-2018-07-02; bh=cmK57nWF3xCycn+Xe37BmfeUz4DrJ92G4aMskuDnZos=; b=RC0YFI13Y+/d5uNT3It/7E/9kaExOdqIDbQoyV3metzGJTox2BQ/zNHz/Iqy1XSr/8Rd gETWBDOyUTEDlNCuMo0xKoA/rpz57qSduOcDRgPFOPjSnRZ+gBKO0WTICbSf74rKkaIk nPCE7QqI+Zwo6grHwFH4od2f71Ncv8KLf401L8Y3soY0x26NYOIqDC8GmrGR2N42sPjS QZK9TmByEa6m0AxOFKLhr1xkn+AZTcTnQEzIefZtsqIFUAxg6QgE9MyHVhkf9Nbu9X6X xPPuhiuNEfqfmh37cnMksE3PZGFjCMPa1+yehhlnDUkVikbmBfY/mHOE4BQp2rUJ31S1 2w== Received: from aserv0021.oracle.com (aserv0021.oracle.com [141.146.126.233]) by aserp2120.oracle.com with ESMTP id 2mxn0q0tge-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Wed, 10 Oct 2018 00:11:02 +0000 Received: from userv0121.oracle.com (userv0121.oracle.com [156.151.31.72]) by aserv0021.oracle.com (8.14.4/8.14.4) with ESMTP id w9A0B22o025716 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Wed, 10 Oct 2018 00:11:02 GMT Received: from abhmp0015.oracle.com (abhmp0015.oracle.com [141.146.116.21]) by userv0121.oracle.com (8.14.4/8.13.8) with ESMTP id w9A0B1ib020601; Wed, 10 Oct 2018 00:11:01 GMT Received: from localhost (/10.159.249.114) by default (Oracle Beehive Gateway v4.0) with ESMTP ; Wed, 10 Oct 2018 00:11:01 +0000 Subject: [PATCH 03/25] xfs: zero posteof blocks when cloning above eof From: "Darrick J. Wong" To: david@fromorbit.com, darrick.wong@oracle.com Cc: sandeen@redhat.com, linux-nfs@vger.kernel.org, linux-cifs@vger.kernel.org, Zorro Lang , linux-unionfs@vger.kernel.org, linux-xfs@vger.kernel.org, linux-mm@kvack.org, linux-btrfs@vger.kernel.org, Dave Chinner , linux-fsdevel@vger.kernel.org, ocfs2-devel@oss.oracle.com Date: Tue, 09 Oct 2018 17:10:59 -0700 Message-ID: <153913025949.32295.17548471289910846210.stgit@magnolia> In-Reply-To: <153913023835.32295.13962696655740190941.stgit@magnolia> References: <153913023835.32295.13962696655740190941.stgit@magnolia> User-Agent: StGit/0.17.1-dirty MIME-Version: 1.0 X-Proofpoint-Virus-Version: vendor=nai engine=5900 definitions=9041 signatures=668706 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 suspectscore=0 malwarescore=0 phishscore=0 bulkscore=0 spamscore=0 mlxscore=0 mlxlogscore=999 adultscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.0.1-1807170000 definitions=main-1810100000 X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: X-Virus-Scanned: ClamAV using ClamSMTP From: Darrick J. Wong When we're reflinking between two files and the destination file range is well beyond the destination file's EOF marker, zero any posteof speculative preallocations in the destination file so that we don't expose stale disk contents. The previous strategy of trying to clear the preallocations does not work if the destination file has the PREALLOC flag set. Uncovered by shared/010. Reported-by: Zorro Lang Bugzilla-id: https://bugzilla.kernel.org/show_bug.cgi?id=201259 Signed-off-by: Darrick J. Wong Reviewed-by: Dave Chinner --- fs/xfs/xfs_reflink.c | 33 +++++++++++++++++++++++++-------- 1 file changed, 25 insertions(+), 8 deletions(-) diff --git a/fs/xfs/xfs_reflink.c b/fs/xfs/xfs_reflink.c index ebd65d3e31f3..cbb359e68a72 100644 --- a/fs/xfs/xfs_reflink.c +++ b/fs/xfs/xfs_reflink.c @@ -1240,6 +1240,26 @@ xfs_reflink_remap_unlock( inode_unlock_shared(inode_in); } +/* + * If we're reflinking to a point past the destination file's EOF, we must + * zero any speculative post-EOF preallocations that sit between the old EOF + * and the destination file offset. + */ +static int +xfs_reflink_zero_posteof( + struct xfs_inode *ip, + loff_t pos) +{ + loff_t isize = i_size_read(VFS_I(ip)); + + if (pos <= isize) + return 0; + + trace_xfs_zero_eof(ip, isize, pos - isize); + return iomap_zero_range(VFS_I(ip), isize, pos - isize, NULL, + &xfs_iomap_ops); +} + /* * Prepare two files for range cloning. Upon a successful return both inodes * will have the iolock and mmaplock held, the page cache of the out file @@ -1293,15 +1313,12 @@ xfs_reflink_remap_prep( goto out_unlock; /* - * Clear out post-eof preallocations because we don't have page cache - * backing the delayed allocations and they'll never get freed on - * their own. + * Zero existing post-eof speculative preallocations in the destination + * file. */ - if (xfs_can_free_eofblocks(dest, true)) { - ret = xfs_free_eofblocks(dest); - if (ret) - goto out_unlock; - } + ret = xfs_reflink_zero_posteof(dest, pos_out); + if (ret) + goto out_unlock; /* Set flags and remap blocks. */ ret = xfs_reflink_set_inode_flag(src, dest);