From patchwork Mon Mar 26 23:57:11 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Darrick J. Wong" X-Patchwork-Id: 10308993 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 B48F060386 for ; Mon, 26 Mar 2018 23:57:16 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id A17CC29967 for ; Mon, 26 Mar 2018 23:57:16 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 963FF29969; Mon, 26 Mar 2018 23:57:16 +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, UNPARSEABLE_RELAY 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 E746329967 for ; Mon, 26 Mar 2018 23:57:15 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751174AbeCZX5P (ORCPT ); Mon, 26 Mar 2018 19:57:15 -0400 Received: from userp2130.oracle.com ([156.151.31.86]:37118 "EHLO userp2130.oracle.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751160AbeCZX5P (ORCPT ); Mon, 26 Mar 2018 19:57:15 -0400 Received: from pps.filterd (userp2130.oracle.com [127.0.0.1]) by userp2130.oracle.com (8.16.0.22/8.16.0.22) with SMTP id w2QNpwoi056312 for ; Mon, 26 Mar 2018 23:57:14 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-2017-10-26; bh=VjwPetlddJFSJJzpLJACMFNUw+I5caaT9WCrVO+FD3E=; b=fIPO9siMCNmlIJ48udZ3Ty0cOMZJEKqzDytNy6bW8+zCBPkMWHj3ILekDof/w2IFymXq BfQFFrFR6Cwg18IugPs1cNMbJWgnFhPne8VwKwHtGhR1wH8N4RNNdK8qXxc1Lunff7n6 HqIQ4043VtAIF9wBV+5B52cS5STzE83sch2FMTakHV7PDjFXEoMlFChpI9yIKjaUOpUi xbWsnSbPCm8t8B6gsDXOmjr3PHjprNyyMecLg4ImMXqEL0iroeDFt0XuFo53C2YHIdqH xl46VBZs66Qnc40D47eHwYPsjeD5a4J7LU4uoqXtlvnko7o8RojHpk81EwPCAx5FqFdT SQ== Received: from aserv0021.oracle.com (aserv0021.oracle.com [141.146.126.233]) by userp2130.oracle.com with ESMTP id 2gyaweg0a8-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK) for ; Mon, 26 Mar 2018 23:57:14 +0000 Received: from userv0121.oracle.com (userv0121.oracle.com [156.151.31.72]) by aserv0021.oracle.com (8.14.4/8.14.4) with ESMTP id w2QNvC8n002630 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK) for ; Mon, 26 Mar 2018 23:57:13 GMT Received: from abhmp0005.oracle.com (abhmp0005.oracle.com [141.146.116.11]) by userv0121.oracle.com (8.14.4/8.13.8) with ESMTP id w2QNvCBG009667 for ; Mon, 26 Mar 2018 23:57:12 GMT Received: from localhost (/10.159.239.252) by default (Oracle Beehive Gateway v4.0) with ESMTP ; Mon, 26 Mar 2018 16:57:12 -0700 Subject: [PATCH 12/20] xfs: repair the AGI From: "Darrick J. Wong" To: darrick.wong@oracle.com Cc: linux-xfs@vger.kernel.org Date: Mon, 26 Mar 2018 16:57:11 -0700 Message-ID: <152210863140.13184.9547259515714141786.stgit@magnolia> In-Reply-To: <152210855435.13184.6475770131389744177.stgit@magnolia> References: <152210855435.13184.6475770131389744177.stgit@magnolia> User-Agent: StGit/0.17.1-dirty MIME-Version: 1.0 X-Proofpoint-Virus-Version: vendor=nai engine=5900 definitions=8844 signatures=668695 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-1711220000 definitions=main-1803260228 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 From: Darrick J. Wong Rebuild the AGI header items with some help from the rmapbt. Signed-off-by: Darrick J. Wong --- fs/xfs/scrub/agheader_repair.c | 112 ++++++++++++++++++++++++++++++++++++++++ fs/xfs/scrub/repair.h | 2 + fs/xfs/scrub/scrub.c | 1 3 files changed, 115 insertions(+) -- To unsubscribe from this list: send the line "unsubscribe linux-xfs" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html diff --git a/fs/xfs/scrub/agheader_repair.c b/fs/xfs/scrub/agheader_repair.c index a694d8f..639cf88 100644 --- a/fs/xfs/scrub/agheader_repair.c +++ b/fs/xfs/scrub/agheader_repair.c @@ -568,3 +568,115 @@ xfs_repair_agfl( XFS_BTREE_NOERROR); return error; } + +/* AGI */ + +int +xfs_repair_agi( + struct xfs_scrub_context *sc, + uint32_t scrub_oflags) +{ + struct xfs_repair_find_ag_btree fab[] = { + { + .rmap_owner = XFS_RMAP_OWN_INOBT, + .buf_ops = &xfs_inobt_buf_ops, + .magic = XFS_IBT_CRC_MAGIC, + }, + { + .rmap_owner = XFS_RMAP_OWN_INOBT, + .buf_ops = &xfs_inobt_buf_ops, + .magic = XFS_FIBT_CRC_MAGIC, + }, + { + .buf_ops = NULL + }, + }; + struct xfs_agi old_agi; + struct xfs_mount *mp = sc->mp; + struct xfs_buf *agi_bp; + struct xfs_buf *agf_bp; + struct xfs_agi *agi; + struct xfs_btree_cur *cur; + struct xfs_perag *pag; + xfs_agino_t old_count; + xfs_agino_t old_freecount; + xfs_agino_t count; + xfs_agino_t freecount; + int bucket; + int error; + + /* We require the rmapbt to rebuild anything. */ + if (!xfs_sb_version_hasrmapbt(&mp->m_sb)) + return -EOPNOTSUPP; + + error = xfs_trans_read_buf(mp, sc->tp, mp->m_ddev_targp, + XFS_AG_DADDR(mp, sc->sa.agno, XFS_AGI_DADDR(mp)), + XFS_FSS_TO_BB(mp, 1), 0, &agi_bp, NULL); + if (error) + return error; + agi_bp->b_ops = &xfs_agi_buf_ops; + + error = xfs_alloc_read_agf(mp, sc->tp, sc->sa.agno, 0, &agf_bp); + if (error) + return error; + if (!agf_bp) + return -ENOMEM; + + /* Find the btree roots. */ + error = xfs_repair_find_ag_btree_roots(sc, agf_bp, fab, NULL); + if (error) + return error; + if (fab[0].root == NULLAGBLOCK || fab[0].level > XFS_BTREE_MAXLEVELS) + return -EFSCORRUPTED; + if (xfs_sb_version_hasfinobt(&mp->m_sb) && + (fab[1].root == NULLAGBLOCK || fab[1].level > XFS_BTREE_MAXLEVELS)) + return -EFSCORRUPTED; + + /* Start rewriting the header. */ + agi = XFS_BUF_TO_AGI(agi_bp); + old_agi = *agi; + old_count = be32_to_cpu(old_agi.agi_count); + old_freecount = be32_to_cpu(old_agi.agi_freecount); + memset(agi, 0, mp->m_sb.sb_sectsize); + agi->agi_magicnum = cpu_to_be32(XFS_AGI_MAGIC); + agi->agi_versionnum = cpu_to_be32(XFS_AGI_VERSION); + agi->agi_seqno = cpu_to_be32(sc->sa.agno); + agi->agi_length = cpu_to_be32(xfs_ag_block_count(mp, sc->sa.agno)); + agi->agi_newino = cpu_to_be32(NULLAGINO); + agi->agi_dirino = cpu_to_be32(NULLAGINO); + if (xfs_sb_version_hascrc(&mp->m_sb)) + uuid_copy(&agi->agi_uuid, &mp->m_sb.sb_meta_uuid); + for (bucket = 0; bucket < XFS_AGI_UNLINKED_BUCKETS; bucket++) + agi->agi_unlinked[bucket] = cpu_to_be32(NULLAGINO); + agi->agi_root = cpu_to_be32(fab[0].root); + agi->agi_level = cpu_to_be32(fab[0].level); + if (xfs_sb_version_hasfinobt(&mp->m_sb)) { + agi->agi_free_root = cpu_to_be32(fab[1].root); + agi->agi_free_level = cpu_to_be32(fab[1].level); + } + + /* Update the AGI counters. */ + cur = xfs_inobt_init_cursor(mp, sc->tp, agi_bp, sc->sa.agno, + XFS_BTNUM_INO); + error = xfs_ialloc_count_inodes(cur, &count, &freecount); + xfs_btree_del_cursor(cur, XFS_BTREE_NOERROR); + if (error) + goto err; + agi->agi_count = cpu_to_be32(count); + agi->agi_freecount = cpu_to_be32(freecount); + if (old_count != count || old_freecount != freecount) { + pag = xfs_perag_get(mp, sc->sa.agno); + pag->pagi_init = 0; + xfs_perag_put(pag); + sc->reset_counters = true; + } + + /* Write this to disk. */ + xfs_trans_buf_set_type(sc->tp, agi_bp, XFS_BLFT_AGI_BUF); + xfs_trans_log_buf(sc->tp, agi_bp, 0, mp->m_sb.sb_sectsize - 1); + return error; + +err: + *agi = old_agi; + return error; +} diff --git a/fs/xfs/scrub/repair.h b/fs/xfs/scrub/repair.h index f883813..7f1c609 100644 --- a/fs/xfs/scrub/repair.h +++ b/fs/xfs/scrub/repair.h @@ -121,6 +121,7 @@ int xfs_repair_setup_btree_extent_collection(struct xfs_scrub_context *sc); int xfs_repair_superblock(struct xfs_scrub_context *sc, uint32_t scrub_oflags); int xfs_repair_agf(struct xfs_scrub_context *sc, uint32_t scrub_oflags); int xfs_repair_agfl(struct xfs_scrub_context *sc, uint32_t scrub_oflags); +int xfs_repair_agi(struct xfs_scrub_context *sc, uint32_t scrub_oflags); #else @@ -146,6 +147,7 @@ xfs_repair_calc_ag_resblks( # define xfs_repair_superblock (NULL) # define xfs_repair_agf (NULL) # define xfs_repair_agfl (NULL) +# define xfs_repair_agi (NULL) #endif /* IS_ENABLED(CONFIG_XFS_ONLINE_REPAIR) */ diff --git a/fs/xfs/scrub/scrub.c b/fs/xfs/scrub/scrub.c index 8922ff6..d2162c9 100644 --- a/fs/xfs/scrub/scrub.c +++ b/fs/xfs/scrub/scrub.c @@ -232,6 +232,7 @@ static const struct xfs_scrub_meta_ops meta_scrub_ops[] = { .type = ST_PERAG, .setup = xfs_scrub_setup_fs, .scrub = xfs_scrub_agi, + .repair = xfs_repair_agi, }, [XFS_SCRUB_TYPE_BNOBT] = { /* bnobt */ .type = ST_PERAG,