From patchwork Wed Feb 5 00:46:44 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: 11365639 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 DFD6614B4 for ; Wed, 5 Feb 2020 00:46:50 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id B52C921582 for ; Wed, 5 Feb 2020 00:46:50 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=oracle.com header.i=@oracle.com header.b="o74ZD/Mz" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727796AbgBEAqu (ORCPT ); Tue, 4 Feb 2020 19:46:50 -0500 Received: from userp2130.oracle.com ([156.151.31.86]:45358 "EHLO userp2130.oracle.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727494AbgBEAqu (ORCPT ); Tue, 4 Feb 2020 19:46:50 -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 0150d5X5123736; Wed, 5 Feb 2020 00:46:47 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=cH0PZIdPyXAw6L0KvmF3tUKumkD1LfD5F9/caLVEJJM=; b=o74ZD/MzVwB/JWa5yfENJcCPL5RX2yAYqtp3cKAi7Oi86Zfv8R0bAttpKpGOnUdwOqT2 CClgPo1+CyIkjrFDtjl9o+01PN8K77NX5WWYoDjN6NIDJW/m1yj+JEF5GQh8uKSZV/gV SvIVTDSlNXkc3sTmFUPie2FPCR0VqUU60UFP38h931X4SMK1UqWoc0MeuYLRqWGHTRxw lKqvuZpZKrLFgVZ/mu0a0pmRj9W9umRXi0KSINwL6/RCgjZOm73HDfLfoFUIcXvpvUr1 9KorGSP6iba0g08JN4GGR3u7/sW3zYN4aVJ48XZ1PS68G/2N3KvVOKuxuIWPWIJNlNCm EQ== Received: from aserp3020.oracle.com (aserp3020.oracle.com [141.146.126.70]) by userp2130.oracle.com with ESMTP id 2xykbp00j4-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Wed, 05 Feb 2020 00:46:47 +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 0150e5UB115836; Wed, 5 Feb 2020 00:46:46 GMT Received: from userv0121.oracle.com (userv0121.oracle.com [156.151.31.72]) by aserp3020.oracle.com with ESMTP id 2xykc30xn2-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Wed, 05 Feb 2020 00:46:46 +0000 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 0150kjVH010286; Wed, 5 Feb 2020 00:46:45 GMT Received: from localhost (/10.159.250.52) by default (Oracle Beehive Gateway v4.0) with ESMTP ; Tue, 04 Feb 2020 16:46:45 -0800 Subject: [PATCH 1/7] xfs_repair: replace verify_inum with libxfs inode validators From: "Darrick J. Wong" To: sandeen@sandeen.net, darrick.wong@oracle.com Cc: linux-xfs@vger.kernel.org, alex@zadara.com Date: Tue, 04 Feb 2020 16:46:44 -0800 Message-ID: <158086360402.2079685.8627541630086580270.stgit@magnolia> In-Reply-To: <158086359783.2079685.9581209719946834913.stgit@magnolia> References: <158086359783.2079685.9581209719946834913.stgit@magnolia> User-Agent: StGit/0.17.1-dirty MIME-Version: 1.0 X-Proofpoint-Virus-Version: vendor=nai engine=6000 definitions=9521 signatures=668685 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 suspectscore=0 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-2002050001 X-Proofpoint-Virus-Version: vendor=nai engine=6000 definitions=9521 signatures=668685 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 priorityscore=1501 malwarescore=0 suspectscore=0 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-2002050001 Sender: linux-xfs-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-xfs@vger.kernel.org From: Darrick J. Wong Repair uses the verify_inum function to validate inode numbers that it finds in the superblock and in directories. libxfs now has validator functions to cover that kind of thing, so remove verify_inum(). As a side bonus, this means that we will flag directories that point to the quota/realtime metadata inodes. This fixes a regression found by fuzzing u3.sfdir3.hdr.parent.i4 to lastbit (aka making a directory's .. point to the user quota inode) in xfs/384. Signed-off-by: Darrick J. Wong Reviewed-by: Christoph Hellwig Reviewed-by: Eric Sandeen --- libxfs/libxfs_api_defs.h | 1 + repair/dino_chunks.c | 2 +- repair/dinode.c | 29 ----------------------------- repair/dinode.h | 4 ---- repair/dir2.c | 7 +++---- repair/phase4.c | 12 ++++++------ repair/phase6.c | 8 ++++---- 7 files changed, 15 insertions(+), 48 deletions(-) diff --git a/libxfs/libxfs_api_defs.h b/libxfs/libxfs_api_defs.h index 6e09685b..9daf2635 100644 --- a/libxfs/libxfs_api_defs.h +++ b/libxfs/libxfs_api_defs.h @@ -176,6 +176,7 @@ #define xfs_trans_roll libxfs_trans_roll #define xfs_verify_cksum libxfs_verify_cksum +#define xfs_verify_dir_ino libxfs_verify_dir_ino #define xfs_verify_ino libxfs_verify_ino #define xfs_verify_rtbno libxfs_verify_rtbno #define xfs_zero_extent libxfs_zero_extent diff --git a/repair/dino_chunks.c b/repair/dino_chunks.c index 00b67468..dbf3d37a 100644 --- a/repair/dino_chunks.c +++ b/repair/dino_chunks.c @@ -65,7 +65,7 @@ check_aginode_block(xfs_mount_t *mp, * inode chunk. returns number of new inodes if things are good * and 0 if bad. start is the start of the discovered inode chunk. * routine assumes that ino is a legal inode number - * (verified by verify_inum()). If the inode chunk turns out + * (verified by libxfs_verify_ino()). If the inode chunk turns out * to be good, this routine will put the inode chunk into * the good inode chunk tree if required. * diff --git a/repair/dinode.c b/repair/dinode.c index 8af2cb25..0d9c96be 100644 --- a/repair/dinode.c +++ b/repair/dinode.c @@ -171,35 +171,6 @@ verify_ag_bno(xfs_sb_t *sbp, return 1; } -/* - * returns 0 if inode number is valid, 1 if bogus - */ -int -verify_inum(xfs_mount_t *mp, - xfs_ino_t ino) -{ - xfs_agnumber_t agno; - xfs_agino_t agino; - xfs_agblock_t agbno; - xfs_sb_t *sbp = &mp->m_sb;; - - /* range check ag #, ag block. range-checking offset is pointless */ - - agno = XFS_INO_TO_AGNO(mp, ino); - agino = XFS_INO_TO_AGINO(mp, ino); - agbno = XFS_AGINO_TO_AGBNO(mp, agino); - if (agbno == 0) - return 1; - - if (ino == 0 || ino == NULLFSINO) - return(1); - - if (ino != XFS_AGINO_TO_INO(mp, agno, agino)) - return(1); - - return verify_ag_bno(sbp, agno, agbno); -} - /* * have a separate routine to ensure that we don't accidentally * lose illegally set bits in the agino by turning it into an FSINO diff --git a/repair/dinode.h b/repair/dinode.h index aa177465..98238357 100644 --- a/repair/dinode.h +++ b/repair/dinode.h @@ -77,10 +77,6 @@ verify_uncertain_dinode(xfs_mount_t *mp, xfs_agnumber_t agno, xfs_agino_t ino); -int -verify_inum(xfs_mount_t *mp, - xfs_ino_t ino); - int verify_aginum(xfs_mount_t *mp, xfs_agnumber_t agno, diff --git a/repair/dir2.c b/repair/dir2.c index e43a9732..723aee1f 100644 --- a/repair/dir2.c +++ b/repair/dir2.c @@ -215,7 +215,7 @@ process_sf_dir2( if (lino == ino) { junkit = 1; junkreason = _("current"); - } else if (verify_inum(mp, lino)) { + } else if (!libxfs_verify_dir_ino(mp, lino)) { junkit = 1; junkreason = _("invalid"); } else if (lino == mp->m_sb.sb_rbmino) { @@ -486,8 +486,7 @@ _("corrected entry offsets in directory %" PRIu64 "\n"), * If the validation fails for the root inode we fix it in * the next else case. */ - if (verify_inum(mp, *parent) && ino != mp->m_sb.sb_rootino) { - + if (!libxfs_verify_dir_ino(mp, *parent) && ino != mp->m_sb.sb_rootino) { do_warn( _("bogus .. inode number (%" PRIu64 ") in directory inode %" PRIu64 ", "), *parent, ino); @@ -674,7 +673,7 @@ process_dir2_data( * (or did it ourselves) during phase 3. */ clearino = 0; - } else if (verify_inum(mp, ent_ino)) { + } else if (!libxfs_verify_dir_ino(mp, ent_ino)) { /* * Bad inode number. Clear the inode number and the * entry will get removed later. We don't trash the diff --git a/repair/phase4.c b/repair/phase4.c index e1ba778f..8197db06 100644 --- a/repair/phase4.c +++ b/repair/phase4.c @@ -36,7 +36,7 @@ quotino_check(xfs_mount_t *mp) ino_tree_node_t *irec; if (mp->m_sb.sb_uquotino != NULLFSINO && mp->m_sb.sb_uquotino != 0) { - if (verify_inum(mp, mp->m_sb.sb_uquotino)) + if (!libxfs_verify_ino(mp, mp->m_sb.sb_uquotino)) irec = NULL; else irec = find_inode_rec(mp, @@ -52,7 +52,7 @@ quotino_check(xfs_mount_t *mp) } if (mp->m_sb.sb_gquotino != NULLFSINO && mp->m_sb.sb_gquotino != 0) { - if (verify_inum(mp, mp->m_sb.sb_gquotino)) + if (!libxfs_verify_ino(mp, mp->m_sb.sb_gquotino)) irec = NULL; else irec = find_inode_rec(mp, @@ -68,7 +68,7 @@ quotino_check(xfs_mount_t *mp) } if (mp->m_sb.sb_pquotino != NULLFSINO && mp->m_sb.sb_pquotino != 0) { - if (verify_inum(mp, mp->m_sb.sb_pquotino)) + if (!libxfs_verify_ino(mp, mp->m_sb.sb_pquotino)) irec = NULL; else irec = find_inode_rec(mp, @@ -112,9 +112,9 @@ quota_sb_check(xfs_mount_t *mp) (mp->m_sb.sb_pquotino == NULLFSINO || mp->m_sb.sb_pquotino == 0)) { lost_quotas = 1; fs_quotas = 0; - } else if (!verify_inum(mp, mp->m_sb.sb_uquotino) && - !verify_inum(mp, mp->m_sb.sb_gquotino) && - !verify_inum(mp, mp->m_sb.sb_pquotino)) { + } else if (libxfs_verify_ino(mp, mp->m_sb.sb_uquotino) && + libxfs_verify_ino(mp, mp->m_sb.sb_gquotino) && + libxfs_verify_ino(mp, mp->m_sb.sb_pquotino)) { fs_quotas = 1; } } diff --git a/repair/phase6.c b/repair/phase6.c index 0874b649..70135694 100644 --- a/repair/phase6.c +++ b/repair/phase6.c @@ -1814,7 +1814,7 @@ longform_dir2_entry_check_data( } continue; } - ASSERT(no_modify || !verify_inum(mp, inum)); + ASSERT(no_modify || libxfs_verify_dir_ino(mp, inum)); /* * special case the . entry. we know there's only one * '.' and only '.' points to itself because bogus entries @@ -1845,7 +1845,7 @@ longform_dir2_entry_check_data( /* * skip entries with bogus inumbers if we're in no modify mode */ - if (no_modify && verify_inum(mp, inum)) + if (no_modify && !libxfs_verify_dir_ino(mp, inum)) continue; /* validate ftype field if supported */ @@ -2634,14 +2634,14 @@ shortform_dir2_entry_check(xfs_mount_t *mp, fname[sfep->namelen] = '\0'; ASSERT(no_modify || (lino != NULLFSINO && lino != 0)); - ASSERT(no_modify || !verify_inum(mp, lino)); + ASSERT(no_modify || libxfs_verify_dir_ino(mp, lino)); /* * Also skip entries with bogus inode numbers if we're * in no modify mode. */ - if (no_modify && verify_inum(mp, lino)) { + if (no_modify && !libxfs_verify_dir_ino(mp, lino)) { next_sfep = libxfs_dir2_sf_nextentry(mp, sfp, sfep); continue; } From patchwork Wed Feb 5 00:46:50 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: 11365641 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 C7040139A for ; Wed, 5 Feb 2020 00:46:57 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id A4A1821744 for ; Wed, 5 Feb 2020 00:46:57 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=oracle.com header.i=@oracle.com header.b="BSq28NGy" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727627AbgBEAq5 (ORCPT ); Tue, 4 Feb 2020 19:46:57 -0500 Received: from aserp2120.oracle.com ([141.146.126.78]:34102 "EHLO aserp2120.oracle.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727619AbgBEAq5 (ORCPT ); Tue, 4 Feb 2020 19:46:57 -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 0150eM9n103863; Wed, 5 Feb 2020 00:46:53 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=RFCf/t+rnDm8sEvpwuW3IGQ2dOZidV0SqRh+7RMw4e4=; b=BSq28NGyY5YIdBJvw+uDWYwGCCfDNmyHREtfh72lCvYNLqj+fr7mBdnG41dceZyrmvDu oC/hItfC1jery5Rau3Lu50GFwg5SdsJe9IghtoashfBvukMWoupUK8m8wMPzWTgiJaM4 3kittzditELZfvUziL8X0yqs7iSGYjdEjtPtfg3VRVFQFWE1U3ks1HuLJcKFjJMpH4iz iau0dCfhyPcBzjgd6tjwlmIAE7hMZ/kJ+sl3WjZsfSi7dQQrp8p/DAO4L0NCOhnwugTK hYgkXnHvM+cp52MvA40lYg+I+cygFjlbT+5cxvw7NWEnfCkwZvtjLemqqSX6Pc8XcBSB rg== Received: from aserp3030.oracle.com (aserp3030.oracle.com [141.146.126.71]) by aserp2120.oracle.com with ESMTP id 2xykbp00mb-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Wed, 05 Feb 2020 00:46:53 +0000 Received: from pps.filterd (aserp3030.oracle.com [127.0.0.1]) by aserp3030.oracle.com (8.16.0.27/8.16.0.27) with SMTP id 0150d4NI166192; Wed, 5 Feb 2020 00:46:52 GMT Received: from userv0121.oracle.com (userv0121.oracle.com [156.151.31.72]) by aserp3030.oracle.com with ESMTP id 2xykbqgdbu-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Wed, 05 Feb 2020 00:46:52 +0000 Received: from abhmp0017.oracle.com (abhmp0017.oracle.com [141.146.116.23]) by userv0121.oracle.com (8.14.4/8.13.8) with ESMTP id 0150kprY010307; Wed, 5 Feb 2020 00:46:51 GMT Received: from localhost (/10.159.250.52) by default (Oracle Beehive Gateway v4.0) with ESMTP ; Tue, 04 Feb 2020 16:46:51 -0800 Subject: [PATCH 2/7] mkfs: check root inode location From: "Darrick J. Wong" To: sandeen@sandeen.net, darrick.wong@oracle.com Cc: linux-xfs@vger.kernel.org, Eric Sandeen , alex@zadara.com Date: Tue, 04 Feb 2020 16:46:50 -0800 Message-ID: <158086361042.2079685.15091609361190214982.stgit@magnolia> In-Reply-To: <158086359783.2079685.9581209719946834913.stgit@magnolia> References: <158086359783.2079685.9581209719946834913.stgit@magnolia> User-Agent: StGit/0.17.1-dirty MIME-Version: 1.0 X-Proofpoint-Virus-Version: vendor=nai engine=6000 definitions=9521 signatures=668685 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 suspectscore=0 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-2002050001 X-Proofpoint-Virus-Version: vendor=nai engine=6000 definitions=9521 signatures=668685 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 priorityscore=1501 malwarescore=0 suspectscore=0 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-2002050001 Sender: linux-xfs-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-xfs@vger.kernel.org From: Darrick J. Wong Make sure the root inode gets created where repair thinks it should be created. Signed-off-by: Darrick J. Wong Reviewed-by: Eric Sandeen Reviewed-by: Christoph Hellwig --- libxfs/libxfs_api_defs.h | 1 + mkfs/xfs_mkfs.c | 39 +++++++++++++++++++++++++++++++++------ 2 files changed, 34 insertions(+), 6 deletions(-) diff --git a/libxfs/libxfs_api_defs.h b/libxfs/libxfs_api_defs.h index 9daf2635..7c629c62 100644 --- a/libxfs/libxfs_api_defs.h +++ b/libxfs/libxfs_api_defs.h @@ -98,6 +98,7 @@ #define xfs_fs_geometry libxfs_fs_geometry #define xfs_highbit32 libxfs_highbit32 #define xfs_highbit64 libxfs_highbit64 +#define xfs_ialloc_calc_rootino libxfs_ialloc_calc_rootino #define xfs_idata_realloc libxfs_idata_realloc #define xfs_idestroy_fork libxfs_idestroy_fork #define xfs_iext_lookup_extent libxfs_iext_lookup_extent diff --git a/mkfs/xfs_mkfs.c b/mkfs/xfs_mkfs.c index 606f79da..cc71fd39 100644 --- a/mkfs/xfs_mkfs.c +++ b/mkfs/xfs_mkfs.c @@ -3549,6 +3549,38 @@ rewrite_secondary_superblocks( libxfs_writebuf(buf, LIBXFS_EXIT_ON_FAILURE); } +static void +check_root_ino( + struct xfs_mount *mp) +{ + xfs_ino_t ino; + + if (XFS_INO_TO_AGNO(mp, mp->m_sb.sb_rootino) != 0) { + fprintf(stderr, + _("%s: root inode created in AG %u, not AG 0\n"), + progname, XFS_INO_TO_AGNO(mp, mp->m_sb.sb_rootino)); + exit(1); + } + + /* + * The superblock points to the root directory inode, but xfs_repair + * expects to find the root inode in a very specific location computed + * from the filesystem geometry for an extra level of verification. + * + * Fail the format immediately if those assumptions ever break, because + * repair will toss the root directory. + */ + ino = libxfs_ialloc_calc_rootino(mp, mp->m_sb.sb_unit); + if (mp->m_sb.sb_rootino != ino) { + fprintf(stderr, + _("%s: root inode (%llu) not allocated in expected location (%llu)\n"), + progname, + (unsigned long long)mp->m_sb.sb_rootino, + (unsigned long long)ino); + exit(1); + } +} + int main( int argc, @@ -3835,12 +3867,7 @@ main( /* * Protect ourselves against possible stupidity */ - if (XFS_INO_TO_AGNO(mp, mp->m_sb.sb_rootino) != 0) { - fprintf(stderr, - _("%s: root inode created in AG %u, not AG 0\n"), - progname, XFS_INO_TO_AGNO(mp, mp->m_sb.sb_rootino)); - exit(1); - } + check_root_ino(mp); /* * Re-write multiple secondary superblocks with rootinode field set From patchwork Wed Feb 5 00:46:56 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: 11365643 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 04C64139A for ; Wed, 5 Feb 2020 00:47:03 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id D8F1521744 for ; Wed, 5 Feb 2020 00:47:02 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=oracle.com header.i=@oracle.com header.b="As7PagEn" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727494AbgBEArC (ORCPT ); Tue, 4 Feb 2020 19:47:02 -0500 Received: from userp2130.oracle.com ([156.151.31.86]:45482 "EHLO userp2130.oracle.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727619AbgBEArC (ORCPT ); Tue, 4 Feb 2020 19:47:02 -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 0150dQQA123829; Wed, 5 Feb 2020 00:47:00 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=GpHvEWcZReaWylEgfeiVILojJZeJJoOInPnYwY6LYPU=; b=As7PagEn16Op65FLaofADeQxtmNFkGhx07+znrQJxxmlwsAGuxVTP4ILnI+c0E6dDzpw ppJbLF0kvrbg1NynZf1mqCpopD9t1TBDqwrxefgUvbIvuh9cv3vRn1GXBVEpLxnkRLcA HM728F6+PwXPHkraJ+ZLqDeDbIMm1qxKVdC1r3RMgKdtyFIpPSBV3ZKnFlKZp+S12DNM /zzMqXTo2HPB/1s0W/O7Xte1hUaswz3xNBbXzhIAKA/wWBxnmMN4He6rw0vj8pINTZNO WCYiJYV0SbO4GvfBp1YdFCwwN0d8ALpXZsAlkyW80ZhS0rjXSJUkTys22pd2Z7YB5IF3 qw== Received: from aserp3020.oracle.com (aserp3020.oracle.com [141.146.126.70]) by userp2130.oracle.com with ESMTP id 2xykbp00jf-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Wed, 05 Feb 2020 00:46:59 +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 0150e5B3115820; Wed, 5 Feb 2020 00:46:59 GMT Received: from userv0121.oracle.com (userv0121.oracle.com [156.151.31.72]) by aserp3020.oracle.com with ESMTP id 2xykc30y2s-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Wed, 05 Feb 2020 00:46:59 +0000 Received: from abhmp0010.oracle.com (abhmp0010.oracle.com [141.146.116.16]) by userv0121.oracle.com (8.14.4/8.13.8) with ESMTP id 0150kvnN010320; Wed, 5 Feb 2020 00:46:57 GMT Received: from localhost (/10.159.250.52) by default (Oracle Beehive Gateway v4.0) with ESMTP ; Tue, 04 Feb 2020 16:46:57 -0800 Subject: [PATCH 3/7] xfs_repair: enforce that inode btree chunks can't point to AG headers From: "Darrick J. Wong" To: sandeen@sandeen.net, darrick.wong@oracle.com Cc: linux-xfs@vger.kernel.org, alex@zadara.com Date: Tue, 04 Feb 2020 16:46:56 -0800 Message-ID: <158086361666.2079685.8451949513769071894.stgit@magnolia> In-Reply-To: <158086359783.2079685.9581209719946834913.stgit@magnolia> References: <158086359783.2079685.9581209719946834913.stgit@magnolia> User-Agent: StGit/0.17.1-dirty MIME-Version: 1.0 X-Proofpoint-Virus-Version: vendor=nai engine=6000 definitions=9521 signatures=668685 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 suspectscore=0 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-2002050001 X-Proofpoint-Virus-Version: vendor=nai engine=6000 definitions=9521 signatures=668685 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 priorityscore=1501 malwarescore=0 suspectscore=0 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-2002050001 Sender: linux-xfs-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-xfs@vger.kernel.org From: Darrick J. Wong xfs_repair has a very old check that evidently excuses the AG 0 inode btrees pointing to blocks that are already marked XR_E_INUSE_FS* (e.g. AG headers). mkfs never formats filesystems that way and it looks like an error, so purge the check. After this, we always complain if inodes overlap with AG headers because that should never happen. Signed-off-by: Darrick J. Wong Reviewed-by: Christoph Hellwig --- repair/globals.c | 1 - repair/globals.h | 1 - repair/scan.c | 19 ------------------- repair/xfs_repair.c | 7 ------- 4 files changed, 28 deletions(-) diff --git a/repair/globals.c b/repair/globals.c index dcd79ea4..8a60e706 100644 --- a/repair/globals.c +++ b/repair/globals.c @@ -73,7 +73,6 @@ int lost_gquotino; int lost_pquotino; xfs_agino_t first_prealloc_ino; -xfs_agino_t last_prealloc_ino; xfs_agblock_t bnobt_root; xfs_agblock_t bcntbt_root; xfs_agblock_t inobt_root; diff --git a/repair/globals.h b/repair/globals.h index 008bdd90..2ed5c894 100644 --- a/repair/globals.h +++ b/repair/globals.h @@ -114,7 +114,6 @@ extern int lost_gquotino; extern int lost_pquotino; extern xfs_agino_t first_prealloc_ino; -extern xfs_agino_t last_prealloc_ino; extern xfs_agblock_t bnobt_root; extern xfs_agblock_t bcntbt_root; extern xfs_agblock_t inobt_root; diff --git a/repair/scan.c b/repair/scan.c index c383f3aa..05707dd2 100644 --- a/repair/scan.c +++ b/repair/scan.c @@ -1645,13 +1645,6 @@ scan_single_ino_chunk( break; case XR_E_INUSE_FS: case XR_E_INUSE_FS1: - if (agno == 0 && - ino + j >= first_prealloc_ino && - ino + j < last_prealloc_ino) { - set_bmap(agno, agbno, XR_E_INO); - break; - } - /* fall through */ default: /* XXX - maybe should mark block a duplicate */ do_warn( @@ -1782,18 +1775,6 @@ _("inode chunk claims untracked block, finobt block - agno %d, bno %d, inopb %d\ break; case XR_E_INUSE_FS: case XR_E_INUSE_FS1: - if (agno == 0 && - ino + j >= first_prealloc_ino && - ino + j < last_prealloc_ino) { - do_warn( -_("inode chunk claims untracked block, finobt block - agno %d, bno %d, inopb %d\n"), - agno, agbno, mp->m_sb.sb_inopblock); - - set_bmap(agno, agbno, XR_E_INO); - suspect++; - break; - } - /* fall through */ default: do_warn( _("inode chunk claims used block, finobt block - agno %d, bno %d, inopb %d\n"), diff --git a/repair/xfs_repair.c b/repair/xfs_repair.c index 9295673d..3e9059f3 100644 --- a/repair/xfs_repair.c +++ b/repair/xfs_repair.c @@ -460,13 +460,6 @@ calc_mkfs(xfs_mount_t *mp) first_prealloc_ino = XFS_AGB_TO_AGINO(mp, fino_bno); } - ASSERT(M_IGEO(mp)->ialloc_blks > 0); - - if (M_IGEO(mp)->ialloc_blks > 1) - last_prealloc_ino = first_prealloc_ino + XFS_INODES_PER_CHUNK; - else - last_prealloc_ino = XFS_AGB_TO_AGINO(mp, fino_bno + 1); - /* * now the first 3 inodes in the system */ From patchwork Wed Feb 5 00:47:02 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: 11365645 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 956B914D5 for ; Wed, 5 Feb 2020 00:47:14 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 74BC721582 for ; Wed, 5 Feb 2020 00:47:14 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=oracle.com header.i=@oracle.com header.b="dFC+sa5o" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727714AbgBEArO (ORCPT ); Tue, 4 Feb 2020 19:47:14 -0500 Received: from userp2120.oracle.com ([156.151.31.85]:45510 "EHLO userp2120.oracle.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727647AbgBEArN (ORCPT ); Tue, 4 Feb 2020 19:47:13 -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 0150dH10112978; Wed, 5 Feb 2020 00:47:06 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=QZhadxrK/BZfxx/YKchKaRQC2LQTCdpLVmRFRpNqNIk=; b=dFC+sa5ooqk6Bjd8LjAYuJYH8cuOEtcmDglAbrHnz+8wHqExFhO5st61ll5DB22DZrWg zCni8IvxfK61xXKxbz5+cPZNyabLMWMX9fUMVgwk+hOjqQEJfsAB7lae6G4KxdtpRJtX WcStTELMF5ymZC4CcguhxezPlI0ivWDFen0iun4sAKjSyWYVuRrNrhyX9V3soU54vXNV DsNKiuKXnkMsCH8lAFPhfQVzZG/1Ndf4rMOEaRhoPP1JjxH/URcp24Aueop+Ap+nHPhc 9+EbqYYpfN7nxnYTRx5ze///T8cwnIBqtkY0ASf5/676bCRckb3aLMMxvLvaxJOS1/IP cA== Received: from aserp3020.oracle.com (aserp3020.oracle.com [141.146.126.70]) by userp2120.oracle.com with ESMTP id 2xykbp80m5-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Wed, 05 Feb 2020 00:47:06 +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 0150dlU8115090; Wed, 5 Feb 2020 00:47:05 GMT Received: from userv0122.oracle.com (userv0122.oracle.com [156.151.31.75]) by aserp3020.oracle.com with ESMTP id 2xykc30ya8-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Wed, 05 Feb 2020 00:47:05 +0000 Received: from abhmp0013.oracle.com (abhmp0013.oracle.com [141.146.116.19]) by userv0122.oracle.com (8.14.4/8.14.4) with ESMTP id 0150l4wv023704; Wed, 5 Feb 2020 00:47:04 GMT Received: from localhost (/10.159.250.52) by default (Oracle Beehive Gateway v4.0) with ESMTP ; Tue, 04 Feb 2020 16:47:03 -0800 Subject: [PATCH 4/7] xfs_repair: refactor fixed inode location checks From: "Darrick J. Wong" To: sandeen@sandeen.net, darrick.wong@oracle.com Cc: linux-xfs@vger.kernel.org, Eric Sandeen , alex@zadara.com Date: Tue, 04 Feb 2020 16:47:02 -0800 Message-ID: <158086362282.2079685.17208024677816310215.stgit@magnolia> In-Reply-To: <158086359783.2079685.9581209719946834913.stgit@magnolia> References: <158086359783.2079685.9581209719946834913.stgit@magnolia> User-Agent: StGit/0.17.1-dirty MIME-Version: 1.0 X-Proofpoint-Virus-Version: vendor=nai engine=6000 definitions=9521 signatures=668685 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 suspectscore=0 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-2002050001 X-Proofpoint-Virus-Version: vendor=nai engine=6000 definitions=9521 signatures=668685 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 priorityscore=1501 malwarescore=0 suspectscore=0 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-2002050001 Sender: linux-xfs-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-xfs@vger.kernel.org From: Darrick J. Wong Refactor the checking and resetting of fixed-location inodes (root, rbmino, rsumino) into a helper function. Signed-off-by: Darrick J. Wong Reviewed-by: Eric Sandeen Reviewed-by: Christoph Hellwig --- repair/xfs_repair.c | 106 ++++++++++++++++++--------------------------------- 1 file changed, 37 insertions(+), 69 deletions(-) diff --git a/repair/xfs_repair.c b/repair/xfs_repair.c index 3e9059f3..f8005f8a 100644 --- a/repair/xfs_repair.c +++ b/repair/xfs_repair.c @@ -395,6 +395,37 @@ do_log(char const *msg, ...) va_end(args); } +/* Make sure a fixed-location inode is where it should be. */ +static void +validate_sb_ino( + xfs_ino_t *ino, + xfs_ino_t expected_ino, + const char *tag) +{ + if (*ino == expected_ino) + return; + + do_warn( +_("sb %s inode value %" PRIu64 " %sinconsistent with calculated value %"PRIu64"\n"), + tag, *ino, *ino == NULLFSINO ? "(NULLFSINO) " : "", + expected_ino); + + if (!no_modify) + do_warn( +_("resetting superblock %s inode pointer to %"PRIu64"\n"), + tag, expected_ino); + else + do_warn( +_("would reset superblock %s inode pointer to %"PRIu64"\n"), + tag, expected_ino); + + /* + * Just set the value -- safe since the superblock doesn't get flushed + * out if no_modify is set. + */ + *ino = expected_ino; +} + static void calc_mkfs(xfs_mount_t *mp) { @@ -463,75 +494,12 @@ calc_mkfs(xfs_mount_t *mp) /* * now the first 3 inodes in the system */ - if (mp->m_sb.sb_rootino != first_prealloc_ino) { - do_warn( -_("sb root inode value %" PRIu64 " %sinconsistent with calculated value %u\n"), - mp->m_sb.sb_rootino, - (mp->m_sb.sb_rootino == NULLFSINO ? "(NULLFSINO) ":""), - first_prealloc_ino); - - if (!no_modify) - do_warn( - _("resetting superblock root inode pointer to %u\n"), - first_prealloc_ino); - else - do_warn( - _("would reset superblock root inode pointer to %u\n"), - first_prealloc_ino); - - /* - * just set the value -- safe since the superblock - * doesn't get flushed out if no_modify is set - */ - mp->m_sb.sb_rootino = first_prealloc_ino; - } - - if (mp->m_sb.sb_rbmino != first_prealloc_ino + 1) { - do_warn( -_("sb realtime bitmap inode %" PRIu64 " %sinconsistent with calculated value %u\n"), - mp->m_sb.sb_rbmino, - (mp->m_sb.sb_rbmino == NULLFSINO ? "(NULLFSINO) ":""), - first_prealloc_ino + 1); - - if (!no_modify) - do_warn( - _("resetting superblock realtime bitmap ino pointer to %u\n"), - first_prealloc_ino + 1); - else - do_warn( - _("would reset superblock realtime bitmap ino pointer to %u\n"), - first_prealloc_ino + 1); - - /* - * just set the value -- safe since the superblock - * doesn't get flushed out if no_modify is set - */ - mp->m_sb.sb_rbmino = first_prealloc_ino + 1; - } - - if (mp->m_sb.sb_rsumino != first_prealloc_ino + 2) { - do_warn( -_("sb realtime summary inode %" PRIu64 " %sinconsistent with calculated value %u\n"), - mp->m_sb.sb_rsumino, - (mp->m_sb.sb_rsumino == NULLFSINO ? "(NULLFSINO) ":""), - first_prealloc_ino + 2); - - if (!no_modify) - do_warn( - _("resetting superblock realtime summary ino pointer to %u\n"), - first_prealloc_ino + 2); - else - do_warn( - _("would reset superblock realtime summary ino pointer to %u\n"), - first_prealloc_ino + 2); - - /* - * just set the value -- safe since the superblock - * doesn't get flushed out if no_modify is set - */ - mp->m_sb.sb_rsumino = first_prealloc_ino + 2; - } - + validate_sb_ino(&mp->m_sb.sb_rootino, first_prealloc_ino, + _("root")); + validate_sb_ino(&mp->m_sb.sb_rbmino, first_prealloc_ino + 1, + _("realtime bitmap")); + validate_sb_ino(&mp->m_sb.sb_rsumino, first_prealloc_ino + 2, + _("realtime summary")); } /* From patchwork Wed Feb 5 00:47:09 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: 11365647 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 EAC6014B4 for ; Wed, 5 Feb 2020 00:47:15 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id C8B1721582 for ; Wed, 5 Feb 2020 00:47:15 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=oracle.com header.i=@oracle.com header.b="gD1hKVA9" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727795AbgBEArP (ORCPT ); Tue, 4 Feb 2020 19:47:15 -0500 Received: from aserp2120.oracle.com ([141.146.126.78]:34268 "EHLO aserp2120.oracle.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727647AbgBEArP (ORCPT ); Tue, 4 Feb 2020 19:47:15 -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 0150dMvv103195; Wed, 5 Feb 2020 00:47:12 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=4DRjuQkjfasMFDnZPv7FsJi9/586E0SLABbkB6lT2C8=; b=gD1hKVA9ydAhzVIRCheO5M1SUHvs7UI7JZ8u4bw2BgzeKWbsG8z2rOAp1gIxyAPU2EHr INLSvvvdOojZ0tYRAwwiThfwSteACVAP+8YGGqvkJumbej211ZhJQ1bCkBtHR0F2Zhhe 3g1AjQ2ymZIo3+SqIUUJIg8ZLkOY2mjnKZkv2/leeEJJkKT6uoVOyk1+HoYqJzGGpsLs Mp/8Gxm8bOvAmiggdiXMMpZzgbwA7jdtaiHgroGWazOzGvQUOVh2D1eC98uRhs1fhnUR ynFJeeut+wODOvb9H4QVNqmEacAW6fbXG7hB5Vwm6USCcGTXWUOnQ0XlAJQquKJJreQS mw== Received: from userp3030.oracle.com (userp3030.oracle.com [156.151.31.80]) by aserp2120.oracle.com with ESMTP id 2xykbp00n0-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Wed, 05 Feb 2020 00:47:12 +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 0150dYxh149394; Wed, 5 Feb 2020 00:47:11 GMT Received: from aserv0122.oracle.com (aserv0122.oracle.com [141.146.126.236]) by userp3030.oracle.com with ESMTP id 2xykc007yu-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Wed, 05 Feb 2020 00:47:11 +0000 Received: from abhmp0016.oracle.com (abhmp0016.oracle.com [141.146.116.22]) by aserv0122.oracle.com (8.14.4/8.14.4) with ESMTP id 0150lAHj011441; Wed, 5 Feb 2020 00:47:10 GMT Received: from localhost (/10.159.250.52) by default (Oracle Beehive Gateway v4.0) with ESMTP ; Tue, 04 Feb 2020 16:47:10 -0800 Subject: [PATCH 5/7] xfs_repair: use libxfs function to calculate root inode location From: "Darrick J. Wong" To: sandeen@sandeen.net, darrick.wong@oracle.com Cc: linux-xfs@vger.kernel.org, Eric Sandeen , alex@zadara.com Date: Tue, 04 Feb 2020 16:47:09 -0800 Message-ID: <158086362904.2079685.11538498774856180130.stgit@magnolia> In-Reply-To: <158086359783.2079685.9581209719946834913.stgit@magnolia> References: <158086359783.2079685.9581209719946834913.stgit@magnolia> User-Agent: StGit/0.17.1-dirty MIME-Version: 1.0 X-Proofpoint-Virus-Version: vendor=nai engine=6000 definitions=9521 signatures=668685 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 suspectscore=0 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-2002050001 X-Proofpoint-Virus-Version: vendor=nai engine=6000 definitions=9521 signatures=668685 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 priorityscore=1501 malwarescore=0 suspectscore=0 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-2002050001 Sender: linux-xfs-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-xfs@vger.kernel.org From: Darrick J. Wong Use libxfs_ialloc_calc_rootino to compute the location of the root inode, and improve the function comments while we're at it. Signed-off-by: Darrick J. Wong Reviewed-by: Eric Sandeen Reviewed-by: Christoph Hellwig --- repair/globals.c | 5 --- repair/globals.h | 5 --- repair/xfs_repair.c | 78 +++++++-------------------------------------------- 3 files changed, 11 insertions(+), 77 deletions(-) diff --git a/repair/globals.c b/repair/globals.c index 8a60e706..299bacd1 100644 --- a/repair/globals.c +++ b/repair/globals.c @@ -72,11 +72,6 @@ int lost_uquotino; int lost_gquotino; int lost_pquotino; -xfs_agino_t first_prealloc_ino; -xfs_agblock_t bnobt_root; -xfs_agblock_t bcntbt_root; -xfs_agblock_t inobt_root; - /* configuration vars -- fs geometry dependent */ int inodes_per_block; diff --git a/repair/globals.h b/repair/globals.h index 2ed5c894..953e3dfb 100644 --- a/repair/globals.h +++ b/repair/globals.h @@ -113,11 +113,6 @@ extern int lost_uquotino; extern int lost_gquotino; extern int lost_pquotino; -extern xfs_agino_t first_prealloc_ino; -extern xfs_agblock_t bnobt_root; -extern xfs_agblock_t bcntbt_root; -extern xfs_agblock_t inobt_root; - /* configuration vars -- fs geometry dependent */ extern int inodes_per_block; diff --git a/repair/xfs_repair.c b/repair/xfs_repair.c index f8005f8a..111306fe 100644 --- a/repair/xfs_repair.c +++ b/repair/xfs_repair.c @@ -426,79 +426,23 @@ _("would reset superblock %s inode pointer to %"PRIu64"\n"), *ino = expected_ino; } +/* + * Make sure that the first 3 inodes in the filesystem are the root directory, + * the realtime bitmap, and the realtime summary, in that order. + */ static void -calc_mkfs(xfs_mount_t *mp) +calc_mkfs( + struct xfs_mount *mp) { - xfs_agblock_t fino_bno; - int do_inoalign; - - do_inoalign = M_IGEO(mp)->ialloc_align; - - /* - * Pre-calculate the geometry of ag 0. We know what it looks like - * because we know what mkfs does: 2 allocation btree roots (by block - * and by size), the inode allocation btree root, the free inode - * allocation btree root (if enabled) and some number of blocks to - * prefill the agfl. - * - * Because the current shape of the btrees may differ from the current - * shape, we open code the mkfs freelist block count here. mkfs creates - * single level trees, so the calculation is pertty straight forward for - * the trees that use the AGFL. - */ - bnobt_root = howmany(4 * mp->m_sb.sb_sectsize, mp->m_sb.sb_blocksize); - bcntbt_root = bnobt_root + 1; - inobt_root = bnobt_root + 2; - fino_bno = inobt_root + (2 * min(2, mp->m_ag_maxlevels)) + 1; - if (xfs_sb_version_hasfinobt(&mp->m_sb)) - fino_bno++; - if (xfs_sb_version_hasrmapbt(&mp->m_sb)) { - fino_bno += min(2, mp->m_rmap_maxlevels); /* agfl blocks */ - fino_bno++; - } - if (xfs_sb_version_hasreflink(&mp->m_sb)) - fino_bno++; + xfs_ino_t rootino; - /* - * If the log is allocated in the first allocation group we need to - * add the number of blocks used by the log to the above calculation. - * - * This can happens with filesystems that only have a single - * allocation group, or very odd geometries created by old mkfs - * versions on very small filesystems. - */ - if (mp->m_sb.sb_logstart && - XFS_FSB_TO_AGNO(mp, mp->m_sb.sb_logstart) == 0) { + rootino = libxfs_ialloc_calc_rootino(mp, mp->m_sb.sb_unit); - /* - * XXX(hch): verify that sb_logstart makes sense? - */ - fino_bno += mp->m_sb.sb_logblocks; - } - - /* - * ditto the location of the first inode chunks in the fs ('/') - */ - if (xfs_sb_version_hasdalign(&mp->m_sb) && do_inoalign) { - first_prealloc_ino = XFS_AGB_TO_AGINO(mp, roundup(fino_bno, - mp->m_sb.sb_unit)); - } else if (xfs_sb_version_hasalign(&mp->m_sb) && - mp->m_sb.sb_inoalignmt > 1) { - first_prealloc_ino = XFS_AGB_TO_AGINO(mp, - roundup(fino_bno, - mp->m_sb.sb_inoalignmt)); - } else { - first_prealloc_ino = XFS_AGB_TO_AGINO(mp, fino_bno); - } - - /* - * now the first 3 inodes in the system - */ - validate_sb_ino(&mp->m_sb.sb_rootino, first_prealloc_ino, + validate_sb_ino(&mp->m_sb.sb_rootino, rootino, _("root")); - validate_sb_ino(&mp->m_sb.sb_rbmino, first_prealloc_ino + 1, + validate_sb_ino(&mp->m_sb.sb_rbmino, rootino + 1, _("realtime bitmap")); - validate_sb_ino(&mp->m_sb.sb_rsumino, first_prealloc_ino + 2, + validate_sb_ino(&mp->m_sb.sb_rsumino, rootino + 2, _("realtime summary")); } From patchwork Wed Feb 5 00:47:15 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: 11365649 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 29EAF139A for ; Wed, 5 Feb 2020 00:47:21 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 0896821744 for ; Wed, 5 Feb 2020 00:47:21 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=oracle.com header.i=@oracle.com header.b="GyAdvE7u" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727647AbgBEArU (ORCPT ); Tue, 4 Feb 2020 19:47:20 -0500 Received: from userp2120.oracle.com ([156.151.31.85]:45576 "EHLO userp2120.oracle.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727619AbgBEArU (ORCPT ); Tue, 4 Feb 2020 19:47:20 -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 0150dH11112978; Wed, 5 Feb 2020 00:47:17 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=lLpFIE7rxrR7E5mZj4M3DsEJc3LehYaDEYtlPiUmyys=; b=GyAdvE7uYhQlvK5LCM87gADk/10bBhGWhniSq5e+k1ay1kbRQUOAFUOBc66PBBnkib/a FwkLauIsHATBxh2gMY3kDHHktfOpMgwbB4l9+5nWW9EV2vLlJwZnCTMysH/dfEByq9Ga ZL/TbKfyNCwKqoCtTp+RZ54/d+ZgSj5q5vEJPu3xV2SXxYiHJWkD2rzKNwi0FpWnvgNk ZtIkc1e5HKRdtLXUnh5bL2XGJDX55VmEeNObDSWGVOiG1Efo2eMMpC3sQvEmmqbuSp82 vS4rXSQ2I8z+GLKvUEmq2RdgKqvjc8tIYykNlyiJVgbmj25Dfwc7sEJBFLt3B883TEn6 rg== Received: from aserp3020.oracle.com (aserp3020.oracle.com [141.146.126.70]) by userp2120.oracle.com with ESMTP id 2xykbp80mf-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Wed, 05 Feb 2020 00:47:17 +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 0150e1RM115692; Wed, 5 Feb 2020 00:47:16 GMT Received: from aserv0121.oracle.com (aserv0121.oracle.com [141.146.126.235]) by aserp3020.oracle.com with ESMTP id 2xykc30ym8-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Wed, 05 Feb 2020 00:47:16 +0000 Received: from abhmp0003.oracle.com (abhmp0003.oracle.com [141.146.116.9]) by aserv0121.oracle.com (8.14.4/8.13.8) with ESMTP id 0150lGwJ011224; Wed, 5 Feb 2020 00:47:16 GMT Received: from localhost (/10.159.250.52) by default (Oracle Beehive Gateway v4.0) with ESMTP ; Tue, 04 Feb 2020 16:47:16 -0800 Subject: [PATCH 6/7] xfs_repair: check plausibility of root dir pointer before trashing it From: "Darrick J. Wong" To: sandeen@sandeen.net, darrick.wong@oracle.com Cc: linux-xfs@vger.kernel.org, alex@zadara.com Date: Tue, 04 Feb 2020 16:47:15 -0800 Message-ID: <158086363533.2079685.15692340020655871081.stgit@magnolia> In-Reply-To: <158086359783.2079685.9581209719946834913.stgit@magnolia> References: <158086359783.2079685.9581209719946834913.stgit@magnolia> User-Agent: StGit/0.17.1-dirty MIME-Version: 1.0 X-Proofpoint-Virus-Version: vendor=nai engine=6000 definitions=9521 signatures=668685 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 suspectscore=0 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-2002050001 X-Proofpoint-Virus-Version: vendor=nai engine=6000 definitions=9521 signatures=668685 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 priorityscore=1501 malwarescore=0 suspectscore=0 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-2002050001 Sender: linux-xfs-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-xfs@vger.kernel.org From: Darrick J. Wong If sb_rootino doesn't point to where we think mkfs should have allocated the root directory, check to see if the alleged root directory actually looks like a root directory. If so, we'll let it live because someone could have changed sunit since formatting time, and that changes the root directory inode estimate. Signed-off-by: Darrick J. Wong Reviewed-by: Christoph Hellwig --- repair/xfs_repair.c | 45 +++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 45 insertions(+) diff --git a/repair/xfs_repair.c b/repair/xfs_repair.c index 111306fe..b34d41d4 100644 --- a/repair/xfs_repair.c +++ b/repair/xfs_repair.c @@ -426,6 +426,37 @@ _("would reset superblock %s inode pointer to %"PRIu64"\n"), *ino = expected_ino; } +/* Does the root directory inode look like a plausible root directory? */ +static bool +has_plausible_rootdir( + struct xfs_mount *mp) +{ + struct xfs_inode *ip; + xfs_ino_t ino; + int error; + bool ret = false; + + error = -libxfs_iget(mp, NULL, mp->m_sb.sb_rootino, 0, &ip, + &xfs_default_ifork_ops); + if (error) + goto out; + if (!S_ISDIR(VFS_I(ip)->i_mode)) + goto out_rele; + + error = -libxfs_dir_lookup(NULL, ip, &xfs_name_dotdot, &ino, NULL); + if (error) + goto out_rele; + + /* The root directory '..' entry points to the directory. */ + if (ino == mp->m_sb.sb_rootino) + ret = true; + +out_rele: + libxfs_irele(ip); +out: + return ret; +} + /* * Make sure that the first 3 inodes in the filesystem are the root directory, * the realtime bitmap, and the realtime summary, in that order. @@ -438,6 +469,20 @@ calc_mkfs( rootino = libxfs_ialloc_calc_rootino(mp, mp->m_sb.sb_unit); + /* + * If the root inode isn't where we think it is, check its plausibility + * as a root directory. It's possible that somebody changed sunit + * since the filesystem was created, which can change the value of the + * above computation. Don't blow up the root directory if this is the + * case. + */ + if (mp->m_sb.sb_rootino != rootino && has_plausible_rootdir(mp)) { + do_warn( +_("sb root inode value %" PRIu64 " valid but in unaligned location (expected %"PRIu64") possibly due to sunit change\n"), + mp->m_sb.sb_rootino, rootino); + rootino = mp->m_sb.sb_rootino; + } + validate_sb_ino(&mp->m_sb.sb_rootino, rootino, _("root")); validate_sb_ino(&mp->m_sb.sb_rbmino, rootino + 1, From patchwork Wed Feb 5 00:47:21 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: 11365651 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 0EFFE14B4 for ; Wed, 5 Feb 2020 00:47:27 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id E1F4621582 for ; Wed, 5 Feb 2020 00:47:26 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=oracle.com header.i=@oracle.com header.b="EwviaqU4" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727674AbgBEAr0 (ORCPT ); Tue, 4 Feb 2020 19:47:26 -0500 Received: from userp2120.oracle.com ([156.151.31.85]:45648 "EHLO userp2120.oracle.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727619AbgBEAr0 (ORCPT ); Tue, 4 Feb 2020 19:47:26 -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 0150eDrm113746; Wed, 5 Feb 2020 00:47:23 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=zHZXIE5pH6OmKEtmAW/Gct69ohGSY03S9u7u3Sx5TmQ=; b=EwviaqU4WvjCk2ICh1qRr/QV7wxiyRUCxDg40AaRidcbr7+dPId81mAnOrk876tK/7oH 7t6lnf8pmo2lz99hrLK7JRpPLcUvAripwmTLu9OSiBVJAB2sQEs+A5cdBP2CLgfYAsQn 83pAX4Klgpo6RbUb6Ysowzljw5qhGwSOQar7FHzz1HPgJXLOTzKTbGpFIoBiAbDPECy/ uuEwldEO4T2xeac2+Lieo+YLi8bi56Sdjf4Z6lLaPkg1h5jfEKaQ7hfkv74DzCqXm2O+ EZZdD/QElIjPzTZtsk+EwWPh9mvO1kBnuqS94SsCchZ6OcRJGF2mmtbFx06yFCYyKbNt BA== Received: from aserp3020.oracle.com (aserp3020.oracle.com [141.146.126.70]) by userp2120.oracle.com with ESMTP id 2xykbp80mm-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Wed, 05 Feb 2020 00:47:23 +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 0150e5B7115820; Wed, 5 Feb 2020 00:47:23 GMT Received: from aserv0122.oracle.com (aserv0122.oracle.com [141.146.126.236]) by aserp3020.oracle.com with ESMTP id 2xykc30yrx-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Wed, 05 Feb 2020 00:47:22 +0000 Received: from abhmp0012.oracle.com (abhmp0012.oracle.com [141.146.116.18]) by aserv0122.oracle.com (8.14.4/8.14.4) with ESMTP id 0150lMQL011542; Wed, 5 Feb 2020 00:47:22 GMT Received: from localhost (/10.159.250.52) by default (Oracle Beehive Gateway v4.0) with ESMTP ; Tue, 04 Feb 2020 16:47:22 -0800 Subject: [PATCH 7/7] xfs_repair: try to correct sb_unit value from secondaries From: "Darrick J. Wong" To: sandeen@sandeen.net, darrick.wong@oracle.com Cc: linux-xfs@vger.kernel.org, alex@zadara.com Date: Tue, 04 Feb 2020 16:47:21 -0800 Message-ID: <158086364145.2079685.5986767044268901944.stgit@magnolia> In-Reply-To: <158086359783.2079685.9581209719946834913.stgit@magnolia> References: <158086359783.2079685.9581209719946834913.stgit@magnolia> User-Agent: StGit/0.17.1-dirty MIME-Version: 1.0 X-Proofpoint-Virus-Version: vendor=nai engine=6000 definitions=9521 signatures=668685 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 suspectscore=0 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-2002050001 X-Proofpoint-Virus-Version: vendor=nai engine=6000 definitions=9521 signatures=668685 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 priorityscore=1501 malwarescore=0 suspectscore=0 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-2002050001 Sender: linux-xfs-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-xfs@vger.kernel.org From: Darrick J. Wong If the primary superblock's sb_unit leads to a rootino calculation that doesn't match sb_rootino /but/ we can find a secondary superblock whose sb_unit does match, fix the primary. Signed-off-by: Darrick J. Wong Reviewed-by: Christoph Hellwig --- libxfs/libxfs_api_defs.h | 1 + repair/xfs_repair.c | 79 ++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 80 insertions(+) diff --git a/libxfs/libxfs_api_defs.h b/libxfs/libxfs_api_defs.h index 7c629c62..1a438e58 100644 --- a/libxfs/libxfs_api_defs.h +++ b/libxfs/libxfs_api_defs.h @@ -143,6 +143,7 @@ #define xfs_rtfree_extent libxfs_rtfree_extent #define xfs_sb_from_disk libxfs_sb_from_disk #define xfs_sb_quota_from_disk libxfs_sb_quota_from_disk +#define xfs_sb_read_secondary libxfs_sb_read_secondary #define xfs_sb_to_disk libxfs_sb_to_disk #define xfs_symlink_blocks libxfs_symlink_blocks #define xfs_symlink_hdr_ok libxfs_symlink_hdr_ok diff --git a/repair/xfs_repair.c b/repair/xfs_repair.c index b34d41d4..eb1ce546 100644 --- a/repair/xfs_repair.c +++ b/repair/xfs_repair.c @@ -457,6 +457,84 @@ has_plausible_rootdir( return ret; } +/* + * If any of the secondary SBs contain a *correct* value for sunit, write that + * back to the primary superblock. + */ +static void +guess_correct_sunit( + struct xfs_mount *mp) +{ + struct xfs_sb sb; + struct xfs_buf *bp; + xfs_ino_t calc_rootino = NULLFSINO; + xfs_agnumber_t agno; + unsigned int new_sunit; + unsigned int sunit_guess; + int error; + + /* Try reading secondary supers to see if we find a good sb_unit. */ + for (agno = 1; agno < mp->m_sb.sb_agcount; agno++) { + error = -libxfs_sb_read_secondary(mp, NULL, agno, &bp); + if (error) + continue; + libxfs_sb_from_disk(&sb, XFS_BUF_TO_SBP(bp)); + libxfs_putbuf(bp); + + calc_rootino = libxfs_ialloc_calc_rootino(mp, sb.sb_unit); + if (calc_rootino == mp->m_sb.sb_rootino) + break; + } + + /* If we found a reasonable value, log where we found it. */ + if (calc_rootino == mp->m_sb.sb_rootino) { + do_warn(_("AG %u superblock contains plausible sb_unit value\n"), + agno); + new_sunit = sb.sb_unit; + goto fix; + } + + /* Try successive powers of two. */ + for (sunit_guess = 1; + sunit_guess <= XFS_AG_MAX_BLOCKS(mp->m_sb.sb_blocklog); + sunit_guess *= 2) { + calc_rootino = libxfs_ialloc_calc_rootino(mp, sunit_guess); + if (calc_rootino == mp->m_sb.sb_rootino) + break; + } + + /* If we found a reasonable value, log where we found it. */ + if (calc_rootino == mp->m_sb.sb_rootino) { + do_warn(_("Found an sb_unit value that looks plausible\n")); + new_sunit = sunit_guess; + goto fix; + } + + do_warn(_("Could not estimate a plausible sb_unit value\n")); + return; + +fix: + if (!no_modify) + do_warn(_("Resetting sb_unit to %u\n"), new_sunit); + else + do_warn(_("Would reset sb_unit to %u\n"), new_sunit); + + /* + * Just set the value -- safe since the superblock doesn't get flushed + * out if no_modify is set. + */ + mp->m_sb.sb_unit = new_sunit; + + /* Make sure that swidth is still a multiple of sunit. */ + if (mp->m_sb.sb_width % mp->m_sb.sb_unit == 0) + return; + + if (!no_modify) + do_warn(_("Resetting sb_width to %u\n"), new_sunit); + else + do_warn(_("Would reset sb_width to %u\n"), new_sunit); +} + /* * Make sure that the first 3 inodes in the filesystem are the root directory, * the realtime bitmap, and the realtime summary, in that order. @@ -480,6 +558,7 @@ calc_mkfs( do_warn( _("sb root inode value %" PRIu64 " valid but in unaligned location (expected %"PRIu64") possibly due to sunit change\n"), mp->m_sb.sb_rootino, rootino); + guess_correct_sunit(mp); rootino = mp->m_sb.sb_rootino; }