From patchwork Thu Aug 25 23:41:03 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: 9300379 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 BFD3D60757 for ; Thu, 25 Aug 2016 23:41:48 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id B02E329354 for ; Thu, 25 Aug 2016 23:41:48 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id A5298293CD; Thu, 25 Aug 2016 23:41:48 +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 F2E5729354 for ; Thu, 25 Aug 2016 23:41:47 +0000 (UTC) Received: from oss.sgi.com (localhost [IPv6:::1]) by oss.sgi.com (Postfix) with ESMTP id 106787F07; Thu, 25 Aug 2016 18:41:12 -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 793087F06 for ; Thu, 25 Aug 2016 18:41:10 -0500 (CDT) Received: from cuda.sgi.com (cuda3.sgi.com [192.48.176.15]) by relay3.corp.sgi.com (Postfix) with ESMTP id D3491AC001 for ; Thu, 25 Aug 2016 16:41:09 -0700 (PDT) X-ASG-Debug-ID: 1472168467-0bf57c55b21c7ac0001-NocioJ Received: from userp1040.oracle.com (userp1040.oracle.com [156.151.31.81]) by cuda.sgi.com with ESMTP id xcmzOKikXm6CGtu4 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NO) for ; Thu, 25 Aug 2016 16:41:07 -0700 (PDT) X-Barracuda-Envelope-From: darrick.wong@oracle.com X-Barracuda-Effective-Source-IP: userp1040.oracle.com[156.151.31.81] X-Barracuda-Apparent-Source-IP: 156.151.31.81 Received: from aserv0022.oracle.com (aserv0022.oracle.com [141.146.126.234]) by userp1040.oracle.com (Sentrion-MTA-4.3.2/Sentrion-MTA-4.3.2) with ESMTP id u7PNf5GC024456 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Thu, 25 Aug 2016 23:41:06 GMT Received: from aserv0122.oracle.com (aserv0122.oracle.com [141.146.126.236]) by aserv0022.oracle.com (8.14.4/8.14.4) with ESMTP id u7PNf5Fo013483 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Thu, 25 Aug 2016 23:41:05 GMT 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 u7PNf4M0030546; Thu, 25 Aug 2016 23:41:05 GMT Received: from localhost (/10.145.178.207) by default (Oracle Beehive Gateway v4.0) with ESMTP ; Thu, 25 Aug 2016 16:41:04 -0700 Subject: [PATCH 08/25] xfs: scrub the backup superblocks From: "Darrick J. Wong" X-ASG-Orig-Subj: [PATCH 08/25] xfs: scrub the backup superblocks To: david@fromorbit.com, darrick.wong@oracle.com Date: Thu, 25 Aug 2016 16:41:03 -0700 Message-ID: <147216846337.3108.10510729691563285944.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: aserv0022.oracle.com [141.146.126.234] X-Barracuda-Connect: userp1040.oracle.com[156.151.31.81] X-Barracuda-Start-Time: 1472168467 X-Barracuda-Encrypted: ECDHE-RSA-AES256-GCM-SHA384 X-Barracuda-URL: https://192.48.176.15:443/cgi-mod/mark.cgi X-Barracuda-Scan-Msg-Size: 3348 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 Ensure that the geometry presented in the backup superblocks matches the primary superblock so that repair can recover the filesystem if that primary gets corrupted. Signed-off-by: Darrick J. Wong --- fs/xfs/libxfs/xfs_fs.h | 1 + fs/xfs/xfs_scrub.c | 75 ++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 76 insertions(+) diff --git a/fs/xfs/libxfs/xfs_fs.h b/fs/xfs/libxfs/xfs_fs.h index 22559ab..8d58061 100644 --- a/fs/xfs/libxfs/xfs_fs.h +++ b/fs/xfs/libxfs/xfs_fs.h @@ -535,6 +535,7 @@ 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_FLAGS_ALL 0x0 /* no flags yet */ diff --git a/fs/xfs/xfs_scrub.c b/fs/xfs/xfs_scrub.c index fd24af7..3def216 100644 --- a/fs/xfs/xfs_scrub.c +++ b/fs/xfs/xfs_scrub.c @@ -704,6 +704,80 @@ out_badcursor: return error; } +/* Metadata scrubbers */ + +/* Scrub the filesystem superblock. */ +STATIC int +xfs_scrub_sb( + struct xfs_inode *ip, + struct xfs_scrub_metadata *sm) +{ + struct xfs_mount *mp = ip->i_mount; + struct xfs_buf *bp; + struct xfs_sb sb; + xfs_agnumber_t agno; + int error; + + if (sm->control >= mp->m_sb.sb_agcount || sm->flags) + return -EINVAL; + agno = sm->control; + + error = xfs_trans_read_buf(mp, NULL, mp->m_ddev_targp, + XFS_AGB_TO_DADDR(mp, agno, XFS_SB_BLOCK(mp)), + XFS_FSS_TO_BB(mp, 1), 0, &bp, + &xfs_sb_buf_ops); + if (error) + return error; + + if (agno == 0) + goto out; + + xfs_sb_from_disk(&sb, XFS_BUF_TO_SBP(bp)); + + /* Verify the geometries match. */ +#define XFS_SCRUB_SB_FIELD(fn) \ + XFS_SCRUB_CHECK(mp, bp, "superblock", \ + sb.sb_##fn == mp->m_sb.sb_##fn) + XFS_SCRUB_SB_FIELD(blocksize); + XFS_SCRUB_SB_FIELD(dblocks); + XFS_SCRUB_SB_FIELD(rblocks); + XFS_SCRUB_SB_FIELD(rextents); + XFS_SCRUB_SB_FIELD(logstart); + XFS_SCRUB_SB_FIELD(rextsize); + XFS_SCRUB_SB_FIELD(agblocks); + XFS_SCRUB_SB_FIELD(agcount); + XFS_SCRUB_SB_FIELD(rbmblocks); + XFS_SCRUB_SB_FIELD(logblocks); + XFS_SCRUB_SB_FIELD(sectsize); + XFS_SCRUB_SB_FIELD(inodesize); +#undef XFS_SCRUB_SB_FIELD + +#define XFS_SCRUB_SB_FEAT(fn) \ + XFS_SCRUB_CHECK(mp, bp, "superblock", \ + xfs_sb_version_has##fn(&sb) == xfs_sb_version_has##fn(&mp->m_sb)) + XFS_SCRUB_SB_FEAT(align); + XFS_SCRUB_SB_FEAT(dalign); + XFS_SCRUB_SB_FEAT(logv2); + XFS_SCRUB_SB_FEAT(extflgbit); + XFS_SCRUB_SB_FEAT(sector); + XFS_SCRUB_SB_FEAT(asciici); + XFS_SCRUB_SB_FEAT(morebits); + XFS_SCRUB_SB_FEAT(lazysbcount); + XFS_SCRUB_SB_FEAT(crc); + XFS_SCRUB_SB_FEAT(_pquotino); + XFS_SCRUB_SB_FEAT(ftype); + XFS_SCRUB_SB_FEAT(finobt); + XFS_SCRUB_SB_FEAT(sparseinodes); + XFS_SCRUB_SB_FEAT(metauuid); + XFS_SCRUB_SB_FEAT(rmapbt); + XFS_SCRUB_SB_FEAT(reflink); +#undef XFS_SCRUB_SB_FEAT + +out: + xfs_buf_relse(bp); + return error; +} + /* Scrubbing dispatch. */ struct xfs_scrub_meta_fns { @@ -712,6 +786,7 @@ struct xfs_scrub_meta_fns { }; static const struct xfs_scrub_meta_fns meta_scrub_fns[] = { + {xfs_scrub_sb, NULL}, }; /* Dispatch metadata scrubbing. */