From patchwork Wed Jan 11 17:54:05 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Brian Foster X-Patchwork-Id: 9510885 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 B4BD76075C for ; Wed, 11 Jan 2017 17:54:21 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 9FADF28619 for ; Wed, 11 Jan 2017 17:54:21 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 9479328626; Wed, 11 Jan 2017 17:54:21 +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 0997228628 for ; Wed, 11 Jan 2017 17:54:21 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1765035AbdAKRyT (ORCPT ); Wed, 11 Jan 2017 12:54:19 -0500 Received: from mx1.redhat.com ([209.132.183.28]:59866 "EHLO mx1.redhat.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1765126AbdAKRyS (ORCPT ); Wed, 11 Jan 2017 12:54:18 -0500 Received: from int-mx13.intmail.prod.int.phx2.redhat.com (int-mx13.intmail.prod.int.phx2.redhat.com [10.5.11.26]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 1DEBDC05683F for ; Wed, 11 Jan 2017 17:54:11 +0000 (UTC) Received: from bfoster.bfoster (dhcp-41-20.bos.redhat.com [10.18.41.20]) by int-mx13.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id v0BHsAhB027368 for ; Wed, 11 Jan 2017 12:54:10 -0500 Received: by bfoster.bfoster (Postfix, from userid 1000) id 7C68212003C; Wed, 11 Jan 2017 12:54:09 -0500 (EST) From: Brian Foster To: linux-xfs@vger.kernel.org Subject: [PATCH v2 1/5] xfs: refactor iomap delalloc existing extent search into helper Date: Wed, 11 Jan 2017 12:54:05 -0500 Message-Id: <1484157249-464-2-git-send-email-bfoster@redhat.com> In-Reply-To: <1484157249-464-1-git-send-email-bfoster@redhat.com> References: <1484157249-464-1-git-send-email-bfoster@redhat.com> X-Scanned-By: MIMEDefang 2.68 on 10.5.11.26 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.32]); Wed, 11 Jan 2017 17:54:11 +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 In preparation for reuse of the existing delayed allocation code for COW reservation, factor out the part of xfs_file_iomap_begin_delay() responsible for existing extent lookup into a new helper. This patch does not change behavior. Signed-off-by: Brian Foster Reviewed-by: Darrick J. Wong --- fs/xfs/xfs_iomap.c | 72 ++++++++++++++++++++++++++++++++++++++++++------------ 1 file changed, 57 insertions(+), 15 deletions(-) diff --git a/fs/xfs/xfs_iomap.c b/fs/xfs/xfs_iomap.c index 0d14742..ec86262 100644 --- a/fs/xfs/xfs_iomap.c +++ b/fs/xfs/xfs_iomap.c @@ -522,6 +522,48 @@ xfs_iomap_prealloc_size( return alloc_blocks; } +/* + * Prepare to handle delayed allocation based on whether extents exist in the + * inode data and COW forks. If an existing data extent is shared, determine + * whether COW fork reservation is necessary. + * + * The 'found' parameter indicates whether a writable mapping was found. If the + * mapping is shared, a COW reservation is performed for the corresponding + * range. + */ +static int +xfs_iomap_search_extents( + struct xfs_inode *ip, + xfs_fileoff_t offset_fsb, + xfs_fileoff_t end_fsb, + int *eof, + int *idx, + struct xfs_bmbt_irec *got, + bool *found) /* found usable extent */ +{ + struct xfs_ifork *ifp = XFS_IFORK_PTR(ip, XFS_DATA_FORK); + int error = 0; + + *found = false; + + *eof = !xfs_iext_lookup_extent(ip, ifp, offset_fsb, idx, got); + if (*eof || got->br_startoff > offset_fsb) + return 0; + + if (xfs_is_reflink_inode(ip)) { + bool shared; + + xfs_trim_extent(got, offset_fsb, end_fsb - offset_fsb); + error = xfs_reflink_reserve_cow(ip, got, &shared); + if (error) + return error; + } + + *found = true; + + return error; +} + static int xfs_file_iomap_begin_delay( struct inode *inode, @@ -533,18 +575,22 @@ xfs_file_iomap_begin_delay( struct xfs_inode *ip = XFS_I(inode); struct xfs_mount *mp = ip->i_mount; struct xfs_ifork *ifp = XFS_IFORK_PTR(ip, XFS_DATA_FORK); - xfs_fileoff_t offset_fsb = XFS_B_TO_FSBT(mp, offset); + xfs_fileoff_t offset_fsb; + xfs_fileoff_t end_fsb; xfs_fileoff_t maxbytes_fsb = XFS_B_TO_FSB(mp, mp->m_super->s_maxbytes); - xfs_fileoff_t end_fsb; int error = 0, eof = 0; struct xfs_bmbt_irec got; xfs_extnum_t idx; xfs_fsblock_t prealloc_blocks = 0; + bool found; ASSERT(!XFS_IS_REALTIME_INODE(ip)); ASSERT(!xfs_get_extsz_hint(ip)); + offset_fsb = XFS_B_TO_FSBT(mp, offset); + end_fsb = min(XFS_B_TO_FSB(mp, offset + count), maxbytes_fsb); + xfs_ilock(ip, XFS_ILOCK_EXCL); if (unlikely(XFS_TEST_ERROR( @@ -564,19 +610,15 @@ xfs_file_iomap_begin_delay( goto out_unlock; } - eof = !xfs_iext_lookup_extent(ip, ifp, offset_fsb, &idx, &got); - if (!eof && got.br_startoff <= offset_fsb) { - if (xfs_is_reflink_inode(ip)) { - bool shared; - - end_fsb = min(XFS_B_TO_FSB(mp, offset + count), - maxbytes_fsb); - xfs_trim_extent(&got, offset_fsb, end_fsb - offset_fsb); - error = xfs_reflink_reserve_cow(ip, &got, &shared); - if (error) - goto out_unlock; - } - + /* + * Search for preexisting extents. If an existing data extent is shared, + * this will perform COW fork reservation. + */ + error = xfs_iomap_search_extents(ip, offset_fsb, end_fsb, &eof, &idx, + &got, &found); + if (error) + goto out_unlock; + if (found) { trace_xfs_iomap_found(ip, offset, count, 0, &got); goto done; }