From patchwork Thu May 31 18:07:54 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christoph Hellwig X-Patchwork-Id: 10441789 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 0B1F6602BF for ; Thu, 31 May 2018 18:08:58 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id EC68A28D8D for ; Thu, 31 May 2018 18:08:57 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id E144028EAF; Thu, 31 May 2018 18:08:57 +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.8 required=2.0 tests=BAYES_00,DKIM_SIGNED, MAILING_LIST_MULTI, RCVD_IN_DNSWL_HI, T_DKIM_INVALID 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 6201D28D8D for ; Thu, 31 May 2018 18:08:57 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S932761AbeEaSI4 (ORCPT ); Thu, 31 May 2018 14:08:56 -0400 Received: from bombadil.infradead.org ([198.137.202.133]:51222 "EHLO bombadil.infradead.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S932756AbeEaSIy (ORCPT ); Thu, 31 May 2018 14:08:54 -0400 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=bombadil.20170209; h=References:In-Reply-To:Message-Id: Date:Subject:Cc:To:From:Sender:Reply-To:MIME-Version:Content-Type: Content-Transfer-Encoding:Content-ID:Content-Description:Resent-Date: Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Id: List-Help:List-Unsubscribe:List-Subscribe:List-Post:List-Owner:List-Archive; bh=c8PwfGk0Xmw9ZBAtXaiKt/ixjTn/LcUiZzlLAj8Va/U=; b=dnLm4bAySAFLY+BaPqcWNYb8R BpWYnvto/jFGD0IE5LM32P8GC+sWYeWzRNMX2pXqw7YWoc9WWO1tAfYuPS2i/fQKkti1KRobtc0iL z4z1XTcJynn8rHQdvnTb8U2/pIpcAJCDe872giUzetBsfP30yXlDvBQNJX/IdjXGGrzPjBdSTmTBe FSGZHeNj9WnEwXczknbXcUXMKaBIWzPfeRP+dBbNnMxXpetlrxsMiGiTZKKMIPDl4CzJ+n7nhrgWm mr5ClI8Ez5FYFnY+q95VoSFTSSGqPOmha3dV1yv2hzot3Pt8vVj4+L5nDuut7HrcHgCtyU6s49NCx sMI+a0tvg==; Received: from 213-225-38-123.nat.highway.a1.net ([213.225.38.123] helo=localhost) by bombadil.infradead.org with esmtpsa (Exim 4.90_1 #2 (Red Hat Linux)) id 1fOS0L-0003xa-Ai; Thu, 31 May 2018 18:08:53 +0000 From: Christoph Hellwig To: linux-xfs@vger.kernel.org Cc: linux-fsdevel@vger.kernel.org Subject: [PATCH 16/21] xfs: remove the imap_valid flag Date: Thu, 31 May 2018 20:07:54 +0200 Message-Id: <20180531180759.21631-17-hch@lst.de> X-Mailer: git-send-email 2.17.0 In-Reply-To: <20180531180759.21631-1-hch@lst.de> References: <20180531180759.21631-1-hch@lst.de> X-SRS-Rewrite: SMTP reverse-path rewritten from by bombadil.infradead.org. See http://www.infradead.org/rpr.html 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 Simplify the way we check for a valid imap - we know we have a valid mapping after xfs_map_blocks returned successfully, and we know we can call xfs_imap_valid on any imap, as it will always fail on a zero-initialized map. We can also remove the xfs_imap_valid function and fold it into xfs_map_blocks now. Signed-off-by: Christoph Hellwig Reviewed-by: Brian Foster Reviewed-by: Darrick J. Wong --- fs/xfs/xfs_aops.c | 78 +++++++++++++++++++---------------------------- 1 file changed, 31 insertions(+), 47 deletions(-) diff --git a/fs/xfs/xfs_aops.c b/fs/xfs/xfs_aops.c index 5c4cc713edba..5f8e40a032b1 100644 --- a/fs/xfs/xfs_aops.c +++ b/fs/xfs/xfs_aops.c @@ -42,7 +42,6 @@ */ struct xfs_writepage_ctx { struct xfs_bmbt_irec imap; - bool imap_valid; unsigned int io_type; struct xfs_ioend *ioend; sector_t last_block; @@ -382,15 +381,40 @@ xfs_map_blocks( struct xfs_inode *ip = XFS_I(inode); struct xfs_mount *mp = ip->i_mount; ssize_t count = i_blocksize(inode); - xfs_fileoff_t offset_fsb, end_fsb; + xfs_fileoff_t offset_fsb = XFS_B_TO_FSBT(mp, offset), end_fsb; struct xfs_bmbt_irec imap; int whichfork = XFS_DATA_FORK; struct xfs_iext_cursor icur; + bool imap_valid; int error = 0; + /* + * We have to make sure the cached mapping is within EOF to protect + * against eofblocks trimming on file release leaving us with a stale + * mapping. Otherwise, a page for a subsequent file extending buffered + * write could get picked up by this writeback cycle and written to the + * wrong blocks. + * + * Note that what we really want here is a generic mapping invalidation + * mechanism to protect us from arbitrary extent modifying contexts, not + * just eofblocks. + */ + xfs_trim_extent_eof(&wpc->imap, ip); + + imap_valid = offset_fsb >= wpc->imap.br_startoff && + offset_fsb < wpc->imap.br_startoff + wpc->imap.br_blockcount; + if (imap_valid && !xfs_is_reflink_inode(ip)) + return 0; + if (XFS_FORCED_SHUTDOWN(mp)) return -EIO; + /* + * If we don't have a valid map, now it's time to get a new one for this + * offset. This will convert delayed allocations (including COW ones) + * into real extents. If we return without a valid map, it means we + * landed in a hole and we skip the block. + */ xfs_ilock(ip, XFS_ILOCK_SHARED); ASSERT(ip->i_d.di_format != XFS_DINODE_FMT_BTREE || (ip->i_df.if_flags & XFS_IFEXTENTS)); @@ -399,7 +423,6 @@ xfs_map_blocks( if (offset > mp->m_super->s_maxbytes - count) count = mp->m_super->s_maxbytes - offset; end_fsb = XFS_B_TO_FSB(mp, (xfs_ufsize_t)offset + count); - offset_fsb = XFS_B_TO_FSBT(mp, offset); /* * Check if this is offset is covered by a COW extents, and if yes use @@ -432,7 +455,7 @@ xfs_map_blocks( /* * Map valid and no COW extent in the way? We're done. */ - if (wpc->imap_valid) { + if (imap_valid) { xfs_iunlock(ip, XFS_ILOCK_SHARED); return 0; } @@ -477,31 +500,6 @@ xfs_map_blocks( return 0; } -STATIC bool -xfs_imap_valid( - struct inode *inode, - struct xfs_bmbt_irec *imap, - xfs_off_t offset) -{ - offset >>= inode->i_blkbits; - - /* - * We have to make sure the cached mapping is within EOF to protect - * against eofblocks trimming on file release leaving us with a stale - * mapping. Otherwise, a page for a subsequent file extending buffered - * write could get picked up by this writeback cycle and written to the - * wrong blocks. - * - * Note that what we really want here is a generic mapping invalidation - * mechanism to protect us from arbitrary extent modifying contexts, not - * just eofblocks. - */ - xfs_trim_extent_eof(imap, XFS_I(inode)); - - return offset >= imap->br_startoff && - offset < imap->br_startoff + imap->br_blockcount; -} - STATIC void xfs_start_buffer_writeback( struct buffer_head *bh) @@ -858,25 +856,11 @@ xfs_writepage_map( continue; } - if (wpc->imap_valid) - wpc->imap_valid = xfs_imap_valid(inode, &wpc->imap, - file_offset); - /* - * If we don't have a valid map, now it's time to get a new one - * for this offset. This will convert delayed allocations - * (including COW ones) into real extents. If we return without - * a valid map, it means we landed in a hole and we skip the - * block. - */ - if (!wpc->imap_valid || xfs_is_reflink_inode(XFS_I(inode))) { - error = xfs_map_blocks(wpc, inode, file_offset); - if (error) - goto out; - wpc->imap_valid = xfs_imap_valid(inode, &wpc->imap, - file_offset); - } + error = xfs_map_blocks(wpc, inode, file_offset); + if (error) + goto out; - if (!wpc->imap_valid || wpc->io_type == XFS_IO_HOLE) + if (wpc->io_type == XFS_IO_HOLE) continue; lock_buffer(bh);