From patchwork Wed Jan 1 01:01:24 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Darrick J. Wong" X-Patchwork-Id: 11314563 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id B50D8109A for ; Wed, 1 Jan 2020 01:01:33 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 91EEA206E4 for ; Wed, 1 Jan 2020 01:01:33 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=oracle.com header.i=@oracle.com header.b="D98kE1oM" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727186AbgAABBd (ORCPT ); Tue, 31 Dec 2019 20:01:33 -0500 Received: from aserp2120.oracle.com ([141.146.126.78]:47708 "EHLO aserp2120.oracle.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727187AbgAABBd (ORCPT ); Tue, 31 Dec 2019 20:01:33 -0500 Received: from pps.filterd (aserp2120.oracle.com [127.0.0.1]) by aserp2120.oracle.com (8.16.0.27/8.16.0.27) with SMTP id 0010x7AB083286; Wed, 1 Jan 2020 01:01:29 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=oracle.com; h=subject : from : to : cc : date : message-id : in-reply-to : references : mime-version : content-type : content-transfer-encoding; s=corp-2019-08-05; bh=oFSOsY8I+PnatbzfX1cwBS0pQc8hw8tpMm3eF8ArcAo=; b=D98kE1oMsZiSeKwo5CLP5wwTNjY+ZWXJRm+I9EXsGPQMN/wyTTdVmTb780pOj32v99Wi TidFQF5esRnsHqmckynL/NJ1t9ynX9ce8SsIRPQq+1NSsnfHyh1AQzduOLc8cvJSbY2b WPiniLM8HtIodUZ0F1rYI5snZv18RpFCtBhziyqbV0946iERwPS4YhLywuGCCL62b87y 05ZtUFHZ8PKM5Yg7yKk2dQ9b07Auxm6HGsR7nZ/6f1cNUtK4wFpuDH52qdK7ZW6WtdHy 2AnmV1oX2JOYih982Thm0N1di4NfGSY42+w6YJdNk6codb01hfxspV/88wleFDoURKEP yg== Received: from userp3030.oracle.com (userp3030.oracle.com [156.151.31.80]) by aserp2120.oracle.com with ESMTP id 2x5y0pjxhr-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Wed, 01 Jan 2020 01:01:28 +0000 Received: from pps.filterd (userp3030.oracle.com [127.0.0.1]) by userp3030.oracle.com (8.16.0.27/8.16.0.27) with SMTP id 0010x2iJ154798; Wed, 1 Jan 2020 01:01:28 GMT Received: from aserv0121.oracle.com (aserv0121.oracle.com [141.146.126.235]) by userp3030.oracle.com with ESMTP id 2x8gj910cc-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Wed, 01 Jan 2020 01:01:27 +0000 Received: from abhmp0011.oracle.com (abhmp0011.oracle.com [141.146.116.17]) by aserv0121.oracle.com (8.14.4/8.13.8) with ESMTP id 00111Qnw002683; Wed, 1 Jan 2020 01:01:27 GMT Received: from localhost (/10.159.150.156) by default (Oracle Beehive Gateway v4.0) with ESMTP ; Tue, 31 Dec 2019 17:01:26 -0800 Subject: [PATCH 1/3] xfs: xrep_reap_extents should not destroy the bitmap From: "Darrick J. Wong" To: darrick.wong@oracle.com Cc: linux-xfs@vger.kernel.org, Brian Foster Date: Tue, 31 Dec 2019 17:01:24 -0800 Message-ID: <157784048460.1357430.2294347936319130263.stgit@magnolia> In-Reply-To: <157784047838.1357430.18292934559846279176.stgit@magnolia> References: <157784047838.1357430.18292934559846279176.stgit@magnolia> User-Agent: StGit/0.17.1-dirty MIME-Version: 1.0 X-Proofpoint-Virus-Version: vendor=nai engine=6000 definitions=9487 signatures=668685 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 suspectscore=1 malwarescore=0 phishscore=0 bulkscore=0 spamscore=0 mlxscore=0 mlxlogscore=999 adultscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.0.1-1911140001 definitions=main-2001010007 X-Proofpoint-Virus-Version: vendor=nai engine=6000 definitions=9487 signatures=668685 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 priorityscore=1501 malwarescore=0 suspectscore=1 phishscore=0 bulkscore=0 spamscore=0 clxscore=1015 lowpriorityscore=0 mlxscore=0 impostorscore=0 mlxlogscore=999 adultscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.0.1-1911140001 definitions=main-2001010007 Sender: linux-xfs-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-xfs@vger.kernel.org From: Darrick J. Wong Remove the xfs_bitmap_destroy call from the end of xrep_reap_extents because this sort of violates our rule that the function initializing a structure should destroy it. Signed-off-by: Darrick J. Wong Reviewed-by: Brian Foster --- fs/xfs/scrub/agheader_repair.c | 2 +- fs/xfs/scrub/repair.c | 4 +--- 2 files changed, 2 insertions(+), 4 deletions(-) diff --git a/fs/xfs/scrub/agheader_repair.c b/fs/xfs/scrub/agheader_repair.c index 7a1a38b636a9..8fcd43040c96 100644 --- a/fs/xfs/scrub/agheader_repair.c +++ b/fs/xfs/scrub/agheader_repair.c @@ -698,7 +698,7 @@ xrep_agfl( goto err; /* Dump any AGFL overflow. */ - return xrep_reap_extents(sc, &agfl_extents, &XFS_RMAP_OINFO_AG, + error = xrep_reap_extents(sc, &agfl_extents, &XFS_RMAP_OINFO_AG, XFS_AG_RESV_AGFL); err: xfs_bitmap_destroy(&agfl_extents); diff --git a/fs/xfs/scrub/repair.c b/fs/xfs/scrub/repair.c index b70a88bc975e..3a58788e0bd8 100644 --- a/fs/xfs/scrub/repair.c +++ b/fs/xfs/scrub/repair.c @@ -613,11 +613,9 @@ xrep_reap_extents( error = xrep_reap_block(sc, fsbno, oinfo, type); if (error) - goto out; + break; } -out: - xfs_bitmap_destroy(bitmap); return error; } From patchwork Wed Jan 1 01:01:30 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Darrick J. Wong" X-Patchwork-Id: 11314565 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id C3585109A for ; Wed, 1 Jan 2020 01:01:36 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id A116620718 for ; Wed, 1 Jan 2020 01:01:36 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=oracle.com header.i=@oracle.com header.b="q5B4hjC7" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727188AbgAABBg (ORCPT ); Tue, 31 Dec 2019 20:01:36 -0500 Received: from userp2120.oracle.com ([156.151.31.85]:44492 "EHLO userp2120.oracle.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727187AbgAABBf (ORCPT ); Tue, 31 Dec 2019 20:01:35 -0500 Received: from pps.filterd (userp2120.oracle.com [127.0.0.1]) by userp2120.oracle.com (8.16.0.27/8.16.0.27) with SMTP id 0010x7SB085448 for ; Wed, 1 Jan 2020 01:01:34 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=oracle.com; h=subject : from : to : cc : date : message-id : in-reply-to : references : mime-version : content-type : content-transfer-encoding; s=corp-2019-08-05; bh=iT+Ux4xo7gCN6qrq1i+LgRK64M7EqLWtNIb0cmQyZGE=; b=q5B4hjC7oskA62bH9krFKs/7H/YXP7bE1FW9cRyeoZGmFHMpQtIOd5555OiZD6M3Uo5M qyI7dG3sGW8T4cK9u/6XitXBTawq3t8Ou5qu9OJDIt7RDkNx99KoLCtNSxBvFSAIHpwT /HkMzhTNNfsUGBZqZg6nkbMbnw/95RUGFvCOAKeShMljFyYxq+p/zgGzDdqgOGca3pAs ucDHHngonNpYf05IO/SVfSb8UFd8uZnH+zu7oB3ONTnPZcAfoNhdrZon6xpeM4GP04PU ocYtEVdsyM5lu4x3hcX2ykDqMg350MpiMOtT1oxOGaTDnYg1rC9ikcupWlp/HbZsyDn5 SA== Received: from aserp3020.oracle.com (aserp3020.oracle.com [141.146.126.70]) by userp2120.oracle.com with ESMTP id 2x5ypqjw2k-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK) for ; Wed, 01 Jan 2020 01:01:34 +0000 Received: from pps.filterd (aserp3020.oracle.com [127.0.0.1]) by aserp3020.oracle.com (8.16.0.27/8.16.0.27) with SMTP id 0010ww7H190720 for ; Wed, 1 Jan 2020 01:01:33 GMT Received: from aserv0122.oracle.com (aserv0122.oracle.com [141.146.126.236]) by aserp3020.oracle.com with ESMTP id 2x8guedbnt-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK) for ; Wed, 01 Jan 2020 01:01:33 +0000 Received: from abhmp0007.oracle.com (abhmp0007.oracle.com [141.146.116.13]) by aserv0122.oracle.com (8.14.4/8.14.4) with ESMTP id 00111X0q023306 for ; Wed, 1 Jan 2020 01:01:33 GMT Received: from localhost (/10.159.150.156) by default (Oracle Beehive Gateway v4.0) with ESMTP ; Tue, 31 Dec 2019 17:01:32 -0800 Subject: [PATCH 2/3] xfs: only invalidate blocks if we're going to free them From: "Darrick J. Wong" To: darrick.wong@oracle.com Cc: linux-xfs@vger.kernel.org Date: Tue, 31 Dec 2019 17:01:30 -0800 Message-ID: <157784049081.1357430.998170313426535186.stgit@magnolia> In-Reply-To: <157784047838.1357430.18292934559846279176.stgit@magnolia> References: <157784047838.1357430.18292934559846279176.stgit@magnolia> User-Agent: StGit/0.17.1-dirty MIME-Version: 1.0 X-Proofpoint-Virus-Version: vendor=nai engine=6000 definitions=9487 signatures=668685 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 suspectscore=3 malwarescore=0 phishscore=0 bulkscore=0 spamscore=0 mlxscore=0 mlxlogscore=999 adultscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.0.1-1911140001 definitions=main-2001010007 X-Proofpoint-Virus-Version: vendor=nai engine=6000 definitions=9487 signatures=668685 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 priorityscore=1501 malwarescore=0 suspectscore=3 phishscore=0 bulkscore=0 spamscore=0 clxscore=1015 lowpriorityscore=0 mlxscore=0 impostorscore=0 mlxlogscore=999 adultscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.0.1-1911140001 definitions=main-2001010007 Sender: linux-xfs-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-xfs@vger.kernel.org From: Darrick J. Wong When we're discarding old btree blocks after a repair, only invalidate the buffers for the ones that we're freeing -- if the metadata was crosslinked with another data structure, we don't want to touch it. Signed-off-by: Darrick J. Wong --- fs/xfs/scrub/repair.c | 74 ++++++++++++++++++++++--------------------------- fs/xfs/scrub/repair.h | 1 - 2 files changed, 33 insertions(+), 42 deletions(-) diff --git a/fs/xfs/scrub/repair.c b/fs/xfs/scrub/repair.c index 3a58788e0bd8..62a9b77eba3d 100644 --- a/fs/xfs/scrub/repair.c +++ b/fs/xfs/scrub/repair.c @@ -423,44 +423,6 @@ xrep_init_btblock( * buffers associated with @bitmap. */ -/* - * Invalidate buffers for per-AG btree blocks we're dumping. This function - * is not intended for use with file data repairs; we have bunmapi for that. - */ -int -xrep_invalidate_blocks( - struct xfs_scrub *sc, - struct xfs_bitmap *bitmap) -{ - struct xfs_bitmap_range *bmr; - struct xfs_bitmap_range *n; - struct xfs_buf *bp; - xfs_fsblock_t fsbno; - - /* - * For each block in each extent, see if there's an incore buffer for - * exactly that block; if so, invalidate it. The buffer cache only - * lets us look for one buffer at a time, so we have to look one block - * at a time. Avoid invalidating AG headers and post-EOFS blocks - * because we never own those; and if we can't TRYLOCK the buffer we - * assume it's owned by someone else. - */ - for_each_xfs_bitmap_block(fsbno, bmr, n, bitmap) { - /* Skip AG headers and post-EOFS blocks */ - if (!xfs_verify_fsbno(sc->mp, fsbno)) - continue; - bp = xfs_buf_incore(sc->mp->m_ddev_targp, - XFS_FSB_TO_DADDR(sc->mp, fsbno), - XFS_FSB_TO_BB(sc->mp, 1), XBF_TRYLOCK); - if (bp) { - xfs_trans_bjoin(sc->tp, bp); - xfs_trans_binval(sc->tp, bp); - } - } - - return 0; -} - /* Ensure the freelist is the correct size. */ int xrep_fix_freelist( @@ -515,6 +477,33 @@ xrep_put_freelist( return 0; } +/* Try to invalidate the incore buffer for a block that we're about to free. */ +STATIC void +xrep_reap_invalidate_block( + struct xfs_scrub *sc, + xfs_fsblock_t fsbno) +{ + struct xfs_buf *bp; + + /* + * If there's an incore buffer for exactly this block, invalidate it. + * Avoid invalidating AG headers and post-EOFS blocks because we never + * own those; and if we can't TRYLOCK the buffer we assume it's owned + * by someone else. + */ + if (!xfs_verify_fsbno(sc->mp, fsbno)) + return; + + bp = xfs_buf_incore(sc->mp->m_ddev_targp, + XFS_FSB_TO_DADDR(sc->mp, fsbno), + XFS_FSB_TO_BB(sc->mp, 1), XBF_TRYLOCK); + if (!bp) + return; + + xfs_trans_bjoin(sc->tp, bp); + xfs_trans_binval(sc->tp, bp); +} + /* Dispose of a single block. */ STATIC int xrep_reap_block( @@ -568,12 +557,15 @@ xrep_reap_block( * blow on writeout, the filesystem will shut down, and the admin gets * to run xfs_repair. */ - if (has_other_rmap) + if (has_other_rmap) { error = xfs_rmap_free(sc->tp, agf_bp, agno, agbno, 1, oinfo); - else if (resv == XFS_AG_RESV_AGFL) + } else if (resv == XFS_AG_RESV_AGFL) { + xrep_reap_invalidate_block(sc, fsbno); error = xrep_put_freelist(sc, agbno); - else + } else { + xrep_reap_invalidate_block(sc, fsbno); error = xfs_free_extent(sc->tp, fsbno, 1, oinfo, resv); + } if (agf_bp != sc->sa.agf_bp) xfs_trans_brelse(sc->tp, agf_bp); if (error) diff --git a/fs/xfs/scrub/repair.h b/fs/xfs/scrub/repair.h index 60c61d7052a8..eab41928990f 100644 --- a/fs/xfs/scrub/repair.h +++ b/fs/xfs/scrub/repair.h @@ -31,7 +31,6 @@ int xrep_init_btblock(struct xfs_scrub *sc, xfs_fsblock_t fsb, struct xfs_bitmap; int xrep_fix_freelist(struct xfs_scrub *sc, bool can_shrink); -int xrep_invalidate_blocks(struct xfs_scrub *sc, struct xfs_bitmap *btlist); int xrep_reap_extents(struct xfs_scrub *sc, struct xfs_bitmap *exlist, const struct xfs_owner_info *oinfo, enum xfs_ag_resv_type type); From patchwork Wed Jan 1 01:01:37 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Darrick J. Wong" X-Patchwork-Id: 11314567 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 08A4B109A for ; Wed, 1 Jan 2020 01:01:44 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id DB7EB20718 for ; Wed, 1 Jan 2020 01:01:43 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=oracle.com header.i=@oracle.com header.b="gwdy6tPp" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727187AbgAABBn (ORCPT ); Tue, 31 Dec 2019 20:01:43 -0500 Received: from userp2130.oracle.com ([156.151.31.86]:48906 "EHLO userp2130.oracle.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727175AbgAABBn (ORCPT ); Tue, 31 Dec 2019 20:01:43 -0500 Received: from pps.filterd (userp2130.oracle.com [127.0.0.1]) by userp2130.oracle.com (8.16.0.27/8.16.0.27) with SMTP id 0010xCj4104005 for ; Wed, 1 Jan 2020 01:01:41 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=oracle.com; h=subject : from : to : cc : date : message-id : in-reply-to : references : mime-version : content-type : content-transfer-encoding; s=corp-2019-08-05; bh=zcpUAYKGm1MyZlO/X1kyakV+CJLmLoSHKGWQnSn8wdg=; b=gwdy6tPp4jn6YapM5qtMmnzfPkPeUtQZTASaS1D4VlxeojUAOAvD6ZFyPba2R9M2vT6o eJ2RugJpwau9RCoWBkUe0k/rBHzviSi7fHPZD8vKZURzc/PQ/ujnLTDVGwD831IcNDv7 QRWLrmGEjPLGIWZ8GfPamecWyeEklTmn8K2ecf6lLJFxHY9sS3yto21uMj0Scj7fPgZ9 DBOGjFvMdaCHewzUkyZVoVkbFz2S2ky3+Ay7TJ61KBXg+5p2h3Jbquy/XGdgxEN7YYsy Zv3OZ+32UyVhAACub9eFfAYoc93Ve/Ic7f9AKr7L/gZPlR7Z3giQOdbsXxc2cyvvf64H xw== Received: from aserp3020.oracle.com (aserp3020.oracle.com [141.146.126.70]) by userp2130.oracle.com with ESMTP id 2x5xftk24j-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK) for ; Wed, 01 Jan 2020 01:01:41 +0000 Received: from pps.filterd (aserp3020.oracle.com [127.0.0.1]) by aserp3020.oracle.com (8.16.0.27/8.16.0.27) with SMTP id 0010wwsF190729 for ; Wed, 1 Jan 2020 01:01:40 GMT Received: from userv0121.oracle.com (userv0121.oracle.com [156.151.31.72]) by aserp3020.oracle.com with ESMTP id 2x8guedcf8-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK) for ; Wed, 01 Jan 2020 01:01:40 +0000 Received: from abhmp0003.oracle.com (abhmp0003.oracle.com [141.146.116.9]) by userv0121.oracle.com (8.14.4/8.13.8) with ESMTP id 00111dqd019118 for ; Wed, 1 Jan 2020 01:01:39 GMT Received: from localhost (/10.159.150.156) by default (Oracle Beehive Gateway v4.0) with ESMTP ; Tue, 31 Dec 2019 17:01:39 -0800 Subject: [PATCH 3/3] xfs: use deferred frees to reap old btree blocks From: "Darrick J. Wong" To: darrick.wong@oracle.com Cc: linux-xfs@vger.kernel.org Date: Tue, 31 Dec 2019 17:01:37 -0800 Message-ID: <157784049699.1357430.2709645557384623682.stgit@magnolia> In-Reply-To: <157784047838.1357430.18292934559846279176.stgit@magnolia> References: <157784047838.1357430.18292934559846279176.stgit@magnolia> User-Agent: StGit/0.17.1-dirty MIME-Version: 1.0 X-Proofpoint-Virus-Version: vendor=nai engine=6000 definitions=9487 signatures=668685 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 suspectscore=3 malwarescore=0 phishscore=0 bulkscore=0 spamscore=0 mlxscore=0 mlxlogscore=999 adultscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.0.1-1911140001 definitions=main-2001010007 X-Proofpoint-Virus-Version: vendor=nai engine=6000 definitions=9487 signatures=668685 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 priorityscore=1501 malwarescore=0 suspectscore=3 phishscore=0 bulkscore=0 spamscore=0 clxscore=1015 lowpriorityscore=0 mlxscore=0 impostorscore=0 mlxlogscore=999 adultscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.0.1-1911140001 definitions=main-2001010007 Sender: linux-xfs-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-xfs@vger.kernel.org From: Darrick J. Wong Use deferred frees (EFIs) to reap the blocks of a btree that we just replaced. This helps us to shrink the window in which those old blocks could be lost due to a system crash, though we try to flush the EFIs every few hundred blocks so that we don't also overflow the transaction reservations during and after we commit the new btree. Signed-off-by: Darrick J. Wong --- fs/xfs/scrub/repair.c | 29 ++++++++++++++++++++++++----- 1 file changed, 24 insertions(+), 5 deletions(-) diff --git a/fs/xfs/scrub/repair.c b/fs/xfs/scrub/repair.c index 62a9b77eba3d..477df76174b9 100644 --- a/fs/xfs/scrub/repair.c +++ b/fs/xfs/scrub/repair.c @@ -24,6 +24,7 @@ #include "xfs_extent_busy.h" #include "xfs_ag_resv.h" #include "xfs_quota.h" +#include "xfs_bmap.h" #include "scrub/scrub.h" #include "scrub/common.h" #include "scrub/trace.h" @@ -510,13 +511,15 @@ xrep_reap_block( struct xfs_scrub *sc, xfs_fsblock_t fsbno, const struct xfs_owner_info *oinfo, - enum xfs_ag_resv_type resv) + enum xfs_ag_resv_type resv, + unsigned int *deferred) { struct xfs_btree_cur *cur; struct xfs_buf *agf_bp = NULL; xfs_agnumber_t agno; xfs_agblock_t agbno; bool has_other_rmap; + bool need_roll = true; int error; agno = XFS_FSB_TO_AGNO(sc->mp, fsbno); @@ -563,14 +566,24 @@ xrep_reap_block( xrep_reap_invalidate_block(sc, fsbno); error = xrep_put_freelist(sc, agbno); } else { + /* + * Use deferred frees to get rid of the old btree blocks to try + * to minimize the window in which we could crash and lose the + * old blocks. However, we still need to roll the transaction + * every 100 or so EFIs so that we don't exceed the log + * reservation. + */ xrep_reap_invalidate_block(sc, fsbno); - error = xfs_free_extent(sc->tp, fsbno, 1, oinfo, resv); + __xfs_bmap_add_free(sc->tp, fsbno, 1, oinfo, false); + (*deferred)++; + need_roll = *deferred > 100; } if (agf_bp != sc->sa.agf_bp) xfs_trans_brelse(sc->tp, agf_bp); - if (error) + if (error || !need_roll) return error; + *deferred = 0; if (sc->ip) return xfs_trans_roll_inode(&sc->tp, sc->ip); return xrep_roll_ag_trans(sc); @@ -592,6 +605,7 @@ xrep_reap_extents( struct xfs_bitmap_range *bmr; struct xfs_bitmap_range *n; xfs_fsblock_t fsbno; + unsigned int deferred = 0; int error = 0; ASSERT(xfs_sb_version_hasrmapbt(&sc->mp->m_sb)); @@ -603,12 +617,17 @@ xrep_reap_extents( XFS_FSB_TO_AGNO(sc->mp, fsbno), XFS_FSB_TO_AGBNO(sc->mp, fsbno), 1); - error = xrep_reap_block(sc, fsbno, oinfo, type); + error = xrep_reap_block(sc, fsbno, oinfo, type, &deferred); if (error) break; } - return error; + if (error || deferred == 0) + return error; + + if (sc->ip) + return xfs_trans_roll_inode(&sc->tp, sc->ip); + return xrep_roll_ag_trans(sc); } /*