From patchwork Wed Jan 11 17:54:06 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Brian Foster X-Patchwork-Id: 9510889 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 821286075C for ; Wed, 11 Jan 2017 17:54:23 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 6C6CB28619 for ; Wed, 11 Jan 2017 17:54:23 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 6167328628; Wed, 11 Jan 2017 17:54:23 +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 0365428619 for ; Wed, 11 Jan 2017 17:54:23 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S935288AbdAKRyV (ORCPT ); Wed, 11 Jan 2017 12:54:21 -0500 Received: from mx1.redhat.com ([209.132.183.28]:35718 "EHLO mx1.redhat.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1765703AbdAKRyS (ORCPT ); Wed, 11 Jan 2017 12:54:18 -0500 Received: from int-mx10.intmail.prod.int.phx2.redhat.com (int-mx10.intmail.prod.int.phx2.redhat.com [10.5.11.23]) (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 3BA9B4E4FC 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-mx10.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id v0BHsAj8008692 for ; Wed, 11 Jan 2017 12:54:10 -0500 Received: by bfoster.bfoster (Postfix, from userid 1000) id 86CF0120C5C; Wed, 11 Jan 2017 12:54:09 -0500 (EST) From: Brian Foster To: linux-xfs@vger.kernel.org Subject: [PATCH v2 2/5] xfs: logically separate iomap range from allocation range Date: Wed, 11 Jan 2017 12:54:06 -0500 Message-Id: <1484157249-464-3-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.23 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.38]); 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 xfs_file_iomap_begin_delay() uses the got variable for the extent returned by the in-core extent list lookup, the allocated extent returned by xfs_bmapi_reserve_delalloc() and the extent mapped to the iomap data structure for the caller. This is fine for current usage, but doesn't work for COW fork reservation. In that case, the extent returned by xfs_bmapi_reserve_delalloc() is the COW reservation and not the extent to be mapped to the iomap. Instead, the shared data fork extent should be trimmed appropriately and mapped to the iomap. To prepare *_begin_delay() to support COW fork reservation, add a new imap variable to separately track the data fork extent (for iomap) from the extent returned from the lookup. The latter extent may refer to either the data or COW fork in the future. Signed-off-by: Brian Foster Reviewed-by: Darrick J. Wong --- fs/xfs/xfs_iomap.c | 33 +++++++++++++++++++++------------ 1 file changed, 21 insertions(+), 12 deletions(-) diff --git a/fs/xfs/xfs_iomap.c b/fs/xfs/xfs_iomap.c index ec86262..8791ed5 100644 --- a/fs/xfs/xfs_iomap.c +++ b/fs/xfs/xfs_iomap.c @@ -536,6 +536,7 @@ xfs_iomap_search_extents( struct xfs_inode *ip, xfs_fileoff_t offset_fsb, xfs_fileoff_t end_fsb, + struct xfs_bmbt_irec *imap, /* for iomap mapping */ int *eof, int *idx, struct xfs_bmbt_irec *got, @@ -546,15 +547,21 @@ xfs_iomap_search_extents( *found = false; - *eof = !xfs_iext_lookup_extent(ip, ifp, offset_fsb, idx, got); - if (*eof || got->br_startoff > offset_fsb) + /* + * Look up a preexisting extent directly into imap. Set got for the + * bmapi delalloc call if nothing is found. + */ + *eof = !xfs_iext_lookup_extent(ip, ifp, offset_fsb, idx, imap); + if (*eof || imap->br_startoff > offset_fsb) { + *got = *imap; 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); + xfs_trim_extent(imap, offset_fsb, end_fsb - offset_fsb); + error = xfs_reflink_reserve_cow(ip, imap, &shared); if (error) return error; } @@ -580,6 +587,7 @@ xfs_file_iomap_begin_delay( xfs_fileoff_t maxbytes_fsb = XFS_B_TO_FSB(mp, mp->m_super->s_maxbytes); int error = 0, eof = 0; + struct xfs_bmbt_irec imap; struct xfs_bmbt_irec got; xfs_extnum_t idx; xfs_fsblock_t prealloc_blocks = 0; @@ -614,12 +622,12 @@ xfs_file_iomap_begin_delay( * 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); + error = xfs_iomap_search_extents(ip, offset_fsb, end_fsb, &imap, &eof, + &idx, &got, &found); if (error) goto out_unlock; if (found) { - trace_xfs_iomap_found(ip, offset, count, 0, &got); + trace_xfs_iomap_found(ip, offset, count, 0, &imap); goto done; } @@ -680,17 +688,18 @@ xfs_file_iomap_begin_delay( } trace_xfs_iomap_alloc(ip, offset, count, 0, &got); + imap = got; done: - if (isnullstartblock(got.br_startblock)) - got.br_startblock = DELAYSTARTBLOCK; + if (isnullstartblock(imap.br_startblock)) + imap.br_startblock = DELAYSTARTBLOCK; - if (!got.br_startblock) { - error = xfs_alert_fsblock_zero(ip, &got); + if (!imap.br_startblock) { + error = xfs_alert_fsblock_zero(ip, &imap); if (error) goto out_unlock; } - xfs_bmbt_to_iomap(ip, iomap, &got); + xfs_bmbt_to_iomap(ip, iomap, &imap); out_unlock: xfs_iunlock(ip, XFS_ILOCK_EXCL);