From patchwork Thu Oct 19 06:59:40 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christoph Hellwig X-Patchwork-Id: 10016093 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 8FDCF60215 for ; Thu, 19 Oct 2017 07:00:46 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 81B2328C64 for ; Thu, 19 Oct 2017 07:00:46 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 7689D28CA3; Thu, 19 Oct 2017 07:00:46 +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.8 required=2.0 tests=BAYES_00,DKIM_SIGNED, 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 F2E7728C64 for ; Thu, 19 Oct 2017 07:00:45 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751736AbdJSHAp (ORCPT ); Thu, 19 Oct 2017 03:00:45 -0400 Received: from bombadil.infradead.org ([65.50.211.133]:47827 "EHLO bombadil.infradead.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751656AbdJSHAo (ORCPT ); Thu, 19 Oct 2017 03:00:44 -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:To:From:Sender:Reply-To:Cc: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=rIs5FsTDmjamUoWpQwqXfZxpMgHlaClsNK+1iVDiQ9Y=; b=OY/r14ZwLbI/lC9rft0m3+Fpr VhWFQOIOiKfoRe1amuvJNnKhxf2hBlbo17JXPs+MrKlgbDCPfloT7ODd1IurUfSDAeqIAGcvLgxg3 oUmV+fNCZL+2jfFecqCXJ8FCG6AYzV4/QSFklGNa2GRjCTvziyWOTaKBGEs1Ja6hYDxjmmv0dMqCM coG+CcdtWYjQLnsb8BGi0kDgfxBcqSF8nihTzpG1lREEFsPipc2roq0lGJ8VT+Wj3jjFILBYZlgz+ cbwUKy3Pdx6D7A9dfAx75yOpvZ+D3z521qDkRVUVImlvoBBxNeSLueKgFNt5miJhdQS38rOiJIyqw RES+qmW3Q==; Received: from 212095007233.public.telering.at ([212.95.7.233] helo=localhost) by bombadil.infradead.org with esmtpsa (Exim 4.87 #1 (Red Hat Linux)) id 1e54ot-0005wj-K3 for linux-xfs@vger.kernel.org; Thu, 19 Oct 2017 07:00:44 +0000 From: Christoph Hellwig To: linux-xfs@vger.kernel.org Subject: [PATCH 13/15] xfs: don't rely on extent indices in xfs_bmap_collapse_extents Date: Thu, 19 Oct 2017 08:59:40 +0200 Message-Id: <20171019065942.18813-14-hch@lst.de> X-Mailer: git-send-email 2.14.1 In-Reply-To: <20171019065942.18813-1-hch@lst.de> References: <20171019065942.18813-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 Rewrite xfs_bmap_collapse_extents so that we don't rely on extent indices except for iterating over them. Not being able to iterate to the next extent is a sufficient exit condition, and we don't need to do any extent count games given that: a) we already flushed all delalloc extents past our start offset before doing the operation b) xfs_iext_count() includes delalloc extents anyway Signed-off-by: Christoph Hellwig Reviewed-by: Darrick J. Wong --- fs/xfs/libxfs/xfs_bmap.c | 54 +++++++++++------------------------------------- 1 file changed, 12 insertions(+), 42 deletions(-) diff --git a/fs/xfs/libxfs/xfs_bmap.c b/fs/xfs/libxfs/xfs_bmap.c index 2de9458903b6..4c89fdacda90 100644 --- a/fs/xfs/libxfs/xfs_bmap.c +++ b/fs/xfs/libxfs/xfs_bmap.c @@ -5626,8 +5626,6 @@ xfs_bmap_collapse_extents( struct xfs_btree_cur *cur = NULL; struct xfs_bmbt_irec got, prev; xfs_extnum_t current_ext; - xfs_extnum_t total_extents; - xfs_extnum_t stop_extent; xfs_fileoff_t new_startoff; int error = 0; int logflags = 0; @@ -5658,52 +5656,31 @@ xfs_bmap_collapse_extents( cur->bc_private.b.flags = 0; } - /* - * There may be delalloc extents in the data fork before the range we - * are collapsing out, so we cannot use the count of real extents here. - * Instead we have to calculate it from the incore fork. - */ - total_extents = xfs_iext_count(ifp); - if (total_extents == 0) { - *done = true; - goto del_cursor; - } - - /* - * Look up the extent index for the fsb where we start shifting. We can - * henceforth iterate with current_ext as extent list changes are locked - * out via ilock. - * - * If next_fsb lies in a hole beyond which there are no extents we are - * done. - */ if (!xfs_iext_lookup_extent(ip, ifp, *next_fsb, ¤t_ext, &got)) { *done = true; goto del_cursor; } XFS_WANT_CORRUPTED_RETURN(mp, !isnullstartblock(got.br_startblock)); - stop_extent = total_extents; - if (current_ext >= stop_extent) { - error = -EIO; - goto del_cursor; - } - new_startoff = got.br_startoff - offset_shift_fsb; - if (current_ext) { - xfs_iext_get_extent(ifp, current_ext - 1, &prev); + if (xfs_iext_get_extent(ifp, current_ext - 1, &prev)) { if (new_startoff < prev.br_startoff + prev.br_blockcount) { error = -EINVAL; goto del_cursor; } - /* check whether to merge the extent or shift it down */ if (xfs_bmse_can_merge(&prev, &got, offset_shift_fsb)) { error = xfs_bmse_merge(ip, whichfork, offset_shift_fsb, current_ext, &got, &prev, cur, &logflags, dfops); if (error) goto del_cursor; + + /* update got after merge */ + if (!xfs_iext_get_extent(ifp, current_ext, &got)) { + *done = true; + goto del_cursor; + } goto done; } } else { @@ -5717,20 +5694,13 @@ xfs_bmap_collapse_extents( cur, &logflags, dfops, new_startoff); if (error) goto del_cursor; - current_ext++; -done: - /* - * If there was an extent merge during the shift, the extent - * count can change. Update the total and grade the next record. - */ - total_extents = xfs_iext_count(ifp); - stop_extent = total_extents; - if (current_ext == stop_extent) { - *done = true; - goto del_cursor; + + if (!xfs_iext_get_extent(ifp, ++current_ext, &got)) { + *done = true; + goto del_cursor; } - xfs_iext_get_extent(ifp, current_ext, &got); +done: *next_fsb = got.br_startoff; del_cursor: if (cur)