From patchwork Thu Aug 25 23:41:09 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Darrick J. Wong" X-Patchwork-Id: 9300381 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 D72FC60757 for ; Thu, 25 Aug 2016 23:41:56 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id C75EB292E8 for ; Thu, 25 Aug 2016 23:41:56 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id BB3FF293CD; Thu, 25 Aug 2016 23:41:56 +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=-4.2 required=2.0 tests=BAYES_00, RCVD_IN_DNSWL_MED, UNPARSEABLE_RELAY autolearn=ham version=3.3.1 Received: from oss.sgi.com (oss.sgi.com [192.48.182.195]) (using TLSv1 with cipher DHE-RSA-CAMELLIA256-SHA (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id 11D9D292E8 for ; Thu, 25 Aug 2016 23:41:56 +0000 (UTC) Received: from oss.sgi.com (localhost [IPv6:::1]) by oss.sgi.com (Postfix) with ESMTP id 714E77F11; Thu, 25 Aug 2016 18:41:24 -0500 (CDT) X-Original-To: xfs@oss.sgi.com Delivered-To: xfs@oss.sgi.com Received: from relay.sgi.com (relay3.corp.sgi.com [198.149.34.15]) by oss.sgi.com (Postfix) with ESMTP id 961667F0F for ; Thu, 25 Aug 2016 18:41:22 -0500 (CDT) Received: from cuda.sgi.com (cuda2.sgi.com [192.48.176.25]) by relay3.corp.sgi.com (Postfix) with ESMTP id F0AE6AC001 for ; Thu, 25 Aug 2016 16:41:21 -0700 (PDT) X-ASG-Debug-ID: 1472168479-0bf57b53122095e0001-NocioJ Received: from aserp1040.oracle.com (aserp1040.oracle.com [141.146.126.69]) by cuda.sgi.com with ESMTP id 4ws8Hm3bBrc904ki (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NO) for ; Thu, 25 Aug 2016 16:41:20 -0700 (PDT) X-Barracuda-Envelope-From: darrick.wong@oracle.com X-Barracuda-Effective-Source-IP: aserp1040.oracle.com[141.146.126.69] X-Barracuda-Apparent-Source-IP: 141.146.126.69 Received: from aserv0021.oracle.com (aserv0021.oracle.com [141.146.126.233]) by aserp1040.oracle.com (Sentrion-MTA-4.3.2/Sentrion-MTA-4.3.2) with ESMTP id u7PNfI3l017776 (version=TLSv1 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK); Thu, 25 Aug 2016 23:41:18 GMT Received: from userv0121.oracle.com (userv0121.oracle.com [156.151.31.72]) by aserv0021.oracle.com (8.13.8/8.13.8) with ESMTP id u7PNfHWt028596 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK); Thu, 25 Aug 2016 23:41:18 GMT Received: from abhmp0015.oracle.com (abhmp0015.oracle.com [141.146.116.21]) by userv0121.oracle.com (8.13.8/8.13.8) with ESMTP id u7PNfBQH016449; Thu, 25 Aug 2016 23:41:17 GMT Received: from localhost (/10.145.178.207) by default (Oracle Beehive Gateway v4.0) with ESMTP ; Thu, 25 Aug 2016 16:41:11 -0700 Subject: [PATCH 09/25] xfs: scrub AGF and AGFL From: "Darrick J. Wong" X-ASG-Orig-Subj: [PATCH 09/25] xfs: scrub AGF and AGFL To: david@fromorbit.com, darrick.wong@oracle.com Date: Thu, 25 Aug 2016 16:41:09 -0700 Message-ID: <147216846953.3108.18345853853421759907.stgit@birch.djwong.org> In-Reply-To: <147216841262.3108.10746252464845687338.stgit@birch.djwong.org> References: <147216841262.3108.10746252464845687338.stgit@birch.djwong.org> User-Agent: StGit/0.17.1-dirty MIME-Version: 1.0 X-Source-IP: aserv0021.oracle.com [141.146.126.233] X-Barracuda-Connect: aserp1040.oracle.com[141.146.126.69] X-Barracuda-Start-Time: 1472168479 X-Barracuda-Encrypted: ECDHE-RSA-AES256-GCM-SHA384 X-Barracuda-URL: https://192.48.176.25:443/cgi-mod/mark.cgi X-Barracuda-Scan-Msg-Size: 6440 X-Virus-Scanned: by bsmtpd at sgi.com X-Barracuda-BRTS-Status: 1 X-Barracuda-Spam-Score: 0.00 X-Barracuda-Spam-Status: No, SCORE=0.00 using per-user scores of TAG_LEVEL=1000.0 QUARANTINE_LEVEL=1000.0 KILL_LEVEL=2.7 tests=BSF_SC0_MISMATCH_TO, UNPARSEABLE_RELAY X-Barracuda-Spam-Report: Code version 3.2, rules version 3.2.3.32328 Rule breakdown below pts rule name description ---- ---------------------- -------------------------------------------------- 0.00 BSF_SC0_MISMATCH_TO Envelope rcpt doesn't match header 0.00 UNPARSEABLE_RELAY Informational: message has unparseable relay lines Cc: linux-xfs@vger.kernel.org, xfs@oss.sgi.com X-BeenThere: xfs@oss.sgi.com X-Mailman-Version: 2.1.14 Precedence: list List-Id: XFS Filesystem from SGI List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: xfs-bounces@oss.sgi.com Sender: xfs-bounces@oss.sgi.com X-Virus-Scanned: ClamAV using ClamSMTP Check the block references in the AGF and AGFL headers to make sure they make sense. Signed-off-by: Darrick J. Wong --- fs/xfs/libxfs/xfs_alloc.c | 2 - fs/xfs/libxfs/xfs_alloc.h | 2 + fs/xfs/libxfs/xfs_fs.h | 4 + fs/xfs/xfs_scrub.c | 133 +++++++++++++++++++++++++++++++++++++++++++++ 4 files changed, 139 insertions(+), 2 deletions(-) diff --git a/fs/xfs/libxfs/xfs_alloc.c b/fs/xfs/libxfs/xfs_alloc.c index 8b3e6b3..37782a1 100644 --- a/fs/xfs/libxfs/xfs_alloc.c +++ b/fs/xfs/libxfs/xfs_alloc.c @@ -629,7 +629,7 @@ const struct xfs_buf_ops xfs_agfl_buf_ops = { /* * Read in the allocation group free block array. */ -STATIC int /* error */ +int /* error */ xfs_alloc_read_agfl( xfs_mount_t *mp, /* mount point structure */ xfs_trans_t *tp, /* transaction pointer */ diff --git a/fs/xfs/libxfs/xfs_alloc.h b/fs/xfs/libxfs/xfs_alloc.h index 0b00de0..c3ada6b 100644 --- a/fs/xfs/libxfs/xfs_alloc.h +++ b/fs/xfs/libxfs/xfs_alloc.h @@ -204,6 +204,8 @@ xfs_alloc_get_rec( int xfs_read_agf(struct xfs_mount *mp, struct xfs_trans *tp, xfs_agnumber_t agno, int flags, struct xfs_buf **bpp); +int xfs_alloc_read_agfl(struct xfs_mount *mp, struct xfs_trans *tp, + xfs_agnumber_t agno, struct xfs_buf **bpp); int xfs_alloc_fix_freelist(struct xfs_alloc_arg *args, int flags); int xfs_free_extent_fix_freelist(struct xfs_trans *tp, xfs_agnumber_t agno, struct xfs_buf **agbp); diff --git a/fs/xfs/libxfs/xfs_fs.h b/fs/xfs/libxfs/xfs_fs.h index 8d58061..8249ae0 100644 --- a/fs/xfs/libxfs/xfs_fs.h +++ b/fs/xfs/libxfs/xfs_fs.h @@ -536,7 +536,9 @@ struct xfs_scrub_metadata { * Metadata types and flags for scrub operation. */ #define XFS_SCRUB_TYPE_SB 0 /* superblock */ -#define XFS_SCRUB_TYPE_MAX 0 +#define XFS_SCRUB_TYPE_AGF 1 /* AG free header */ +#define XFS_SCRUB_TYPE_AGFL 2 /* AG free list */ +#define XFS_SCRUB_TYPE_MAX 2 #define XFS_SCRUB_FLAGS_ALL 0x0 /* no flags yet */ diff --git a/fs/xfs/xfs_scrub.c b/fs/xfs/xfs_scrub.c index 3def216..c04a097 100644 --- a/fs/xfs/xfs_scrub.c +++ b/fs/xfs/xfs_scrub.c @@ -778,6 +778,137 @@ out: return error; } +/* Scrub the AGF. */ +STATIC int +xfs_scrub_agf( + struct xfs_inode *ip, + struct xfs_scrub_metadata *sm) +{ + struct xfs_mount *mp = ip->i_mount; + struct xfs_agf *agf; + struct xfs_buf *agi_bp = NULL; + struct xfs_buf *agf_bp = NULL; + xfs_agnumber_t agno; + xfs_agblock_t agbno; + xfs_agblock_t eoag; + xfs_daddr_t daddr; + xfs_daddr_t eofs; + int error; + + if (sm->control >= mp->m_sb.sb_agcount || sm->flags) + return -EINVAL; + agno = sm->control; + + /* Let the verifier check most of the AGF fields. */ + error = xfs_scrub_get_ag_headers(mp, agno, &agi_bp, &agf_bp); + if (error) + return error; + + agf = XFS_BUF_TO_AGF(agf_bp); + eofs = XFS_FSB_TO_BB(mp, mp->m_sb.sb_dblocks); + + /* Check the AG length */ + eoag = be32_to_cpu(agf->agf_length); + if (agno == mp->m_sb.sb_agcount - 1) { + XFS_SCRUB_CHECK(mp, agf_bp, "AGF", + eoag <= mp->m_sb.sb_agblocks); + } else { + XFS_SCRUB_CHECK(mp, agf_bp, "AGF", + eoag == mp->m_sb.sb_agblocks); + } + daddr = XFS_AGB_TO_DADDR(mp, agno, eoag); + XFS_SCRUB_CHECK(mp, agf_bp, "AGF", daddr <= eofs); + + /* Check the AGF btree roots */ + agbno = be32_to_cpu(agf->agf_roots[XFS_BTNUM_BNO]); + daddr = XFS_AGB_TO_DADDR(mp, agno, agbno); + XFS_SCRUB_CHECK(mp, agf_bp, "AGF", agbno < mp->m_sb.sb_agblocks); + XFS_SCRUB_CHECK(mp, agf_bp, "AGF", agbno < eoag); + XFS_SCRUB_CHECK(mp, agf_bp, "AGF", daddr < eofs); + + agbno = be32_to_cpu(agf->agf_roots[XFS_BTNUM_CNT]); + daddr = XFS_AGB_TO_DADDR(mp, agno, agbno); + XFS_SCRUB_CHECK(mp, agf_bp, "AGF", agbno < mp->m_sb.sb_agblocks); + XFS_SCRUB_CHECK(mp, agf_bp, "AGF", agbno < eoag); + XFS_SCRUB_CHECK(mp, agf_bp, "AGF", daddr < eofs); + + if (xfs_sb_version_hasrmapbt(&mp->m_sb)) { + agbno = be32_to_cpu(agf->agf_roots[XFS_BTNUM_RMAP]); + daddr = XFS_AGB_TO_DADDR(mp, agno, agbno); + XFS_SCRUB_CHECK(mp, agf_bp, "AGF", + agbno < mp->m_sb.sb_agblocks); + XFS_SCRUB_CHECK(mp, agf_bp, "AGF", agbno < eoag); + XFS_SCRUB_CHECK(mp, agf_bp, "AGF", daddr < eofs); + } + + if (xfs_sb_version_hasreflink(&mp->m_sb)) { + agbno = be32_to_cpu(agf->agf_refcount_root); + daddr = XFS_AGB_TO_DADDR(mp, agno, agbno); + XFS_SCRUB_CHECK(mp, agf_bp, "AGF", + agbno < mp->m_sb.sb_agblocks); + XFS_SCRUB_CHECK(mp, agf_bp, "AGF", agbno < eoag); + XFS_SCRUB_CHECK(mp, agf_bp, "AGF", daddr < eofs); + } + + xfs_scrub_put_ag_headers(&agi_bp, &agf_bp); + return error; +} + +/* Scrub the AGFL. */ +STATIC int +xfs_scrub_agfl( + struct xfs_inode *ip, + struct xfs_scrub_metadata *sm) +{ + struct xfs_mount *mp = ip->i_mount; + struct xfs_agf *agf; + struct xfs_buf *agi_bp = NULL; + struct xfs_buf *agf_bp = NULL; + struct xfs_buf *agfl_bp; + __be32 *agfl_bno; + xfs_agnumber_t agno; + xfs_agblock_t agbno; + xfs_agblock_t eoag; + xfs_daddr_t eofs; + int i; + int error; + + if (sm->control >= mp->m_sb.sb_agcount || sm->flags) + return -EINVAL; + agno = sm->control; + + /* Let the verifier check most of the AGF fields. */ + error = xfs_scrub_get_ag_headers(mp, agno, &agi_bp, &agf_bp); + if (error) + return error; + + error = xfs_alloc_read_agfl(mp, NULL, agno, &agfl_bp); + if (error) + goto err_no_agfl; + + agf = XFS_BUF_TO_AGF(agf_bp); + eofs = XFS_FSB_TO_BB(mp, mp->m_sb.sb_dblocks); + eoag = be32_to_cpu(agf->agf_length); + + agfl_bno = XFS_BUF_TO_AGFL_BNO(mp, agfl_bp); + for (i = be32_to_cpu(agf->agf_flfirst); + i <= be32_to_cpu(agf->agf_fllast); + i++) { + agbno = be32_to_cpu(agfl_bno[i]); + XFS_SCRUB_CHECK(mp, agfl_bp, "AGFL", + XFS_AGB_TO_DADDR(mp, agno, agbno) < eofs); + XFS_SCRUB_CHECK(mp, agfl_bp, "AGFL", + agbno < mp->m_sb.sb_agblocks); + XFS_SCRUB_CHECK(mp, agfl_bp, "AGFL", + agbno < eoag); + } + + xfs_buf_relse(agfl_bp); +err_no_agfl: + xfs_scrub_put_ag_headers(&agi_bp, &agf_bp); + return error; +} + /* Scrubbing dispatch. */ struct xfs_scrub_meta_fns { @@ -787,6 +918,8 @@ struct xfs_scrub_meta_fns { static const struct xfs_scrub_meta_fns meta_scrub_fns[] = { {xfs_scrub_sb, NULL}, + {xfs_scrub_agf, NULL}, + {xfs_scrub_agfl, NULL}, }; /* Dispatch metadata scrubbing. */