From patchwork Mon Feb 11 12:54:23 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christoph Hellwig X-Patchwork-Id: 10805673 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 77E2713A4 for ; Mon, 11 Feb 2019 12:54:50 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 661222A1FB for ; Mon, 11 Feb 2019 12:54:50 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 5A9992A206; Mon, 11 Feb 2019 12:54:50 +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.7 required=2.0 tests=BAYES_00,DKIM_INVALID, DKIM_SIGNED,MAILING_LIST_MULTI,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 CE5BC2A1FB for ; Mon, 11 Feb 2019 12:54:49 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727700AbfBKMyt (ORCPT ); Mon, 11 Feb 2019 07:54:49 -0500 Received: from bombadil.infradead.org ([198.137.202.133]:35390 "EHLO bombadil.infradead.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727106AbfBKMyt (ORCPT ); Mon, 11 Feb 2019 07:54:49 -0500 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=bombadil.20170209; h=Content-Transfer-Encoding: MIME-Version:References:In-Reply-To:Message-Id:Date:Subject:Cc:To:From:Sender :Reply-To:Content-Type: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=Wi1YzB6zYEvYWgovdZrpJE1p+V9OwwjTgvIaNBS18kM=; b=LdIHfvAJAthO20pdr6RAnw6EVN wNH9FD3+Pb4oCn2fs5DrxakqwG66EazoXvMNrpO/DDy0pG28NLEmPWEGQBAUPSO8RtUQub46kd/Ay lKLXDlaLL29/V5qGAoPiA3j/NoDN5WYBptcc0hdiPGawfeygf527PawfR5W/0vEjeOFEr+h436IsM wKegu+W/n+s3aKtqv2fyIBziDxbgLyiVuIB2+lNNcHvlhh/FFSOrBov977oHBxbvkC8BcjkHDXeZn qQGQ820LgJnLLY0m/YLn19DegbbuunuCnba6tsRD28InkOQZEZ4jYiVOWtZ2neR1rB4OdsGcCfOXG OZtVlFvg==; Received: from 089144210182.atnat0019.highway.a1.net ([89.144.210.182] helo=localhost) by bombadil.infradead.org with esmtpsa (Exim 4.90_1 #2 (Red Hat Linux)) id 1gtB6l-0003SV-VK; Mon, 11 Feb 2019 12:54:48 +0000 From: Christoph Hellwig To: linux-xfs@vger.kernel.org Cc: Brian Foster Subject: [PATCH 06/10] xfs: move transaction handling to xfs_bmapi_convert_delalloc Date: Mon, 11 Feb 2019 13:54:23 +0100 Message-Id: <20190211125427.16577-7-hch@lst.de> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20190211125427.16577-1-hch@lst.de> References: <20190211125427.16577-1-hch@lst.de> MIME-Version: 1.0 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 No need to deal with the transaction and the inode locking in the caller. Also move to automatic unlocking on transaction commit or cancel to simplify the code a little more. Note that we also switch to passing whichfork as the second paramters, matching what most related functions do. Signed-off-by: Christoph Hellwig Reviewed-by: Brian Foster --- fs/xfs/libxfs/xfs_bmap.c | 35 ++++++++++++++++++++++++++++++----- fs/xfs/libxfs/xfs_bmap.h | 5 +++-- fs/xfs/xfs_iomap.c | 32 ++++---------------------------- 3 files changed, 37 insertions(+), 35 deletions(-) diff --git a/fs/xfs/libxfs/xfs_bmap.c b/fs/xfs/libxfs/xfs_bmap.c index be2cb5800e02..d9d66e1856d7 100644 --- a/fs/xfs/libxfs/xfs_bmap.c +++ b/fs/xfs/libxfs/xfs_bmap.c @@ -4446,16 +4446,30 @@ xfs_bmapi_write( */ int xfs_bmapi_convert_delalloc( - struct xfs_trans *tp, struct xfs_inode *ip, - xfs_fileoff_t offset_fsb, int whichfork, - struct xfs_bmbt_irec *imap) + xfs_fileoff_t offset_fsb, + struct xfs_bmbt_irec *imap, + unsigned int *seq) { struct xfs_ifork *ifp = XFS_IFORK_PTR(ip, whichfork); + struct xfs_mount *mp = ip->i_mount; struct xfs_bmalloca bma = { NULL }; + struct xfs_trans *tp; int error; + /* + * Space for the extent and indirect blocks was reserved when the + * delalloc extent was created so there's no need to do so here. + */ + error = xfs_trans_alloc(mp, &M_RES(mp)->tr_write, 0, 0, + XFS_TRANS_RESERVE, &tp); + if (error) + return error; + + xfs_ilock(ip, XFS_ILOCK_EXCL); + xfs_trans_ijoin(tp, ip, XFS_ILOCK_EXCL); + if (!xfs_iext_lookup_extent(ip, ifp, offset_fsb, &bma.icur, &bma.got) || bma.got.br_startoff > offset_fsb) { /* @@ -4464,7 +4478,8 @@ xfs_bmapi_convert_delalloc( * might have moved the extent to the data fork in the meantime. */ WARN_ON_ONCE(whichfork != XFS_COW_FORK); - return -EAGAIN; + error = -EAGAIN; + goto out_trans_cancel; } /* @@ -4473,7 +4488,8 @@ xfs_bmapi_convert_delalloc( */ if (!isnullstartblock(bma.got.br_startblock)) { *imap = bma.got; - return 0; + *seq = READ_ONCE(ifp->if_seq); + goto out_trans_cancel; } bma.tp = tp; @@ -4500,6 +4516,7 @@ xfs_bmapi_convert_delalloc( ASSERT(!isnullstartblock(bma.got.br_startblock)); ASSERT(bma.got.br_startblock || XFS_IS_REALTIME_INODE(ip)); *imap = bma.got; + *seq = READ_ONCE(ifp->if_seq); if (whichfork == XFS_COW_FORK) { error = xfs_refcount_alloc_cow_extent(tp, bma.blkno, @@ -4510,8 +4527,16 @@ xfs_bmapi_convert_delalloc( error = xfs_bmap_btree_to_extents(tp, ip, bma.cur, &bma.logflags, whichfork); + if (error) + goto out_finish; + + xfs_bmapi_finish(&bma, whichfork, 0); + return xfs_trans_commit(tp); + out_finish: xfs_bmapi_finish(&bma, whichfork, error); +out_trans_cancel: + xfs_trans_cancel(tp); return error; } diff --git a/fs/xfs/libxfs/xfs_bmap.h b/fs/xfs/libxfs/xfs_bmap.h index b5eca7a26949..78b190b6e908 100644 --- a/fs/xfs/libxfs/xfs_bmap.h +++ b/fs/xfs/libxfs/xfs_bmap.h @@ -223,8 +223,9 @@ int xfs_bmapi_reserve_delalloc(struct xfs_inode *ip, int whichfork, xfs_fileoff_t off, xfs_filblks_t len, xfs_filblks_t prealloc, struct xfs_bmbt_irec *got, struct xfs_iext_cursor *cur, int eof); -int xfs_bmapi_convert_delalloc(struct xfs_trans *, struct xfs_inode *, - xfs_fileoff_t, int, struct xfs_bmbt_irec *); +int xfs_bmapi_convert_delalloc(struct xfs_inode *ip, int whichfork, + xfs_fileoff_t offset_fsb, struct xfs_bmbt_irec *imap, + unsigned int *seq); static inline void xfs_bmap_add_free( diff --git a/fs/xfs/xfs_iomap.c b/fs/xfs/xfs_iomap.c index fd3aacd4bf02..39be741cac5a 100644 --- a/fs/xfs/xfs_iomap.c +++ b/fs/xfs/xfs_iomap.c @@ -684,11 +684,9 @@ xfs_iomap_write_allocate( unsigned int *seq) { struct xfs_mount *mp = ip->i_mount; - struct xfs_ifork *ifp = XFS_IFORK_PTR(ip, whichfork); xfs_fileoff_t offset_fsb; xfs_fileoff_t map_start_fsb; xfs_extlen_t map_count_fsb; - struct xfs_trans *tp; int error = 0; /* @@ -716,17 +714,8 @@ xfs_iomap_write_allocate( /* * Allocate in a loop because it may take several attempts to * allocate real blocks for a contiguous delalloc extent if free - * space is sufficiently fragmented. Note that space for the - * extent and indirect blocks was reserved when the delalloc - * extent was created so there's no need to do so here. + * space is sufficiently fragmented. */ - error = xfs_trans_alloc(mp, &M_RES(mp)->tr_write, 0, 0, - XFS_TRANS_RESERVE, &tp); - if (error) - return error; - - xfs_ilock(ip, XFS_ILOCK_EXCL); - xfs_trans_ijoin(tp, ip, 0); /* * ilock was dropped since imap was populated which means it @@ -737,17 +726,10 @@ xfs_iomap_write_allocate( * caller. We'll trim it down to the caller's most recently * validated range before we return. */ - error = xfs_bmapi_convert_delalloc(tp, ip, offset_fsb, - whichfork, imap); - if (error) - goto trans_cancel; - - error = xfs_trans_commit(tp); + error = xfs_bmapi_convert_delalloc(ip, whichfork, offset_fsb, + imap, seq); if (error) - goto error0; - - *seq = READ_ONCE(ifp->if_seq); - xfs_iunlock(ip, XFS_ILOCK_EXCL); + return error; /* * See if we were able to allocate an extent that covers at @@ -766,12 +748,6 @@ xfs_iomap_write_allocate( return 0; } } - -trans_cancel: - xfs_trans_cancel(tp); -error0: - xfs_iunlock(ip, XFS_ILOCK_EXCL); - return error; } int