From patchwork Fri Jan 24 00:17:32 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: 11349387 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 5D53B17EA for ; Fri, 24 Jan 2020 00:17:39 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 360C7214AF for ; Fri, 24 Jan 2020 00:17:39 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=oracle.com header.i=@oracle.com header.b="jlfblQI3" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729600AbgAXARi (ORCPT ); Thu, 23 Jan 2020 19:17:38 -0500 Received: from aserp2120.oracle.com ([141.146.126.78]:33182 "EHLO aserp2120.oracle.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727056AbgAXARi (ORCPT ); Thu, 23 Jan 2020 19:17:38 -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 00O09MsX183357; Fri, 24 Jan 2020 00:17:36 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=grYQK3PXfdhZe9HX4XjWffOEhxMbJCu5gI0+JOkVNnA=; b=jlfblQI3S+EzAZbtw4z9f9wVCigC1DdvIgxtUkhaEO7calqtKlGecAEy7ARHRqOGgaTY G/YlKNmV1Qn09oBnjwx36Qy0YH4Bv8QARynkFQRXZTNDqF8av+gVARlYMMBkkJh1hWfP 2vrSjF9fu7AUwrjmgi603/MArMqSD6844Ml0jTSgKevxkSpLlgUjIiQXqFs1Wf+2aQgz 6iin6/7/TdFtbKDD0s5ohanZb+biMu91ZmPWVBEHRvKpDb08uV9MYYyIETu2fvMFy5q2 wE2ACZtgEgvdNe1sh8IBgF+S2Rfc3+wA8+6Q+aIXMC+WGPHwG9zZRBN5Dp9M3VX67QJT Lg== Received: from aserp3020.oracle.com (aserp3020.oracle.com [141.146.126.70]) by aserp2120.oracle.com with ESMTP id 2xksyqns3y-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Fri, 24 Jan 2020 00:17:36 +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 00O0E6Ym111069; Fri, 24 Jan 2020 00:17:35 GMT Received: from aserv0121.oracle.com (aserv0121.oracle.com [141.146.126.235]) by aserp3020.oracle.com with ESMTP id 2xqmwb1h5f-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Fri, 24 Jan 2020 00:17:35 +0000 Received: from abhmp0005.oracle.com (abhmp0005.oracle.com [141.146.116.11]) by aserv0121.oracle.com (8.14.4/8.13.8) with ESMTP id 00O0HZ9r020321; Fri, 24 Jan 2020 00:17:35 GMT Received: from localhost (/10.145.179.16) by default (Oracle Beehive Gateway v4.0) with ESMTP ; Thu, 23 Jan 2020 16:17:35 -0800 Subject: [PATCH 1/6] mkfs: check root inode location From: "Darrick J. Wong" To: sandeen@sandeen.net, darrick.wong@oracle.com Cc: linux-xfs@vger.kernel.org, alex@zadara.com Date: Thu, 23 Jan 2020 16:17:32 -0800 Message-ID: <157982505230.2765631.2328249334657581135.stgit@magnolia> In-Reply-To: <157982504556.2765631.630298760136626647.stgit@magnolia> References: <157982504556.2765631.630298760136626647.stgit@magnolia> User-Agent: StGit/0.17.1-dirty MIME-Version: 1.0 X-Proofpoint-Virus-Version: vendor=nai engine=6000 definitions=9509 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-2001240000 X-Proofpoint-Virus-Version: vendor=nai engine=6000 definitions=9509 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-2001240000 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 --- 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 cc7304ad..9ede0125 100644 --- a/libxfs/libxfs_api_defs.h +++ b/libxfs/libxfs_api_defs.h @@ -172,6 +172,7 @@ #define xfs_ag_init_headers libxfs_ag_init_headers #define xfs_buf_delwri_submit libxfs_buf_delwri_submit +#define xfs_ialloc_calc_rootino libxfs_ialloc_calc_rootino #define xfs_refcountbt_calc_reserves libxfs_refcountbt_calc_reserves #define xfs_finobt_calc_reserves libxfs_finobt_calc_reserves diff --git a/mkfs/xfs_mkfs.c b/mkfs/xfs_mkfs.c index 784fe6a9..91a25bf5 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 Fri Jan 24 00:17:39 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: 11349389 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 0C83917EA for ; Fri, 24 Jan 2020 00:17:48 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id DB071214AF for ; Fri, 24 Jan 2020 00:17:47 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=oracle.com header.i=@oracle.com header.b="oTa9zYIH" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729625AbgAXARr (ORCPT ); Thu, 23 Jan 2020 19:17:47 -0500 Received: from userp2130.oracle.com ([156.151.31.86]:34712 "EHLO userp2130.oracle.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729616AbgAXARr (ORCPT ); Thu, 23 Jan 2020 19:17:47 -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 00O08mbf024614; Fri, 24 Jan 2020 00:17:44 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=oTa9zYIH8705UskBllg6W0oeZY01dABBDgb+fgkFVTYSNAhwopoMLhnxCMV+Z6bptBPs moFWx7VNhNhnuH2smSvuolHT9drGd94VW4TSQmGjrDljpoe5XAskmEP0MtmwnvrR9qWj Ay4ejKySyAGIQ2XqIJfI+b+GtuCqmTPfQxe06KfT8TlMI0AoS4SrY2c73gTJuwiaz8CK WfHN7V7GRoN7NRfSQcETbhfVNziR9mp5gzK8yVJflFXdjQQ4z0y6zej069NZjfQyR7gl VCpyuyOBQMOUFspS9tvb1f6XhE7jgCY0QKr5SFdCCkOZ5U/TFiSc+zrl5437qz/O0kG0 cw== Received: from aserp3020.oracle.com (aserp3020.oracle.com [141.146.126.70]) by userp2130.oracle.com with ESMTP id 2xkseuwvxt-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Fri, 24 Jan 2020 00:17:44 +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 00O0E7Mc111177; Fri, 24 Jan 2020 00:17:43 GMT Received: from userv0121.oracle.com (userv0121.oracle.com [156.151.31.72]) by aserp3020.oracle.com with ESMTP id 2xqmwb1j3y-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Fri, 24 Jan 2020 00:17:43 +0000 Received: from abhmp0011.oracle.com (abhmp0011.oracle.com [141.146.116.17]) by userv0121.oracle.com (8.14.4/8.13.8) with ESMTP id 00O0Hf7v031002; Fri, 24 Jan 2020 00:17:41 GMT Received: from localhost (/10.145.179.16) by default (Oracle Beehive Gateway v4.0) with ESMTP ; Thu, 23 Jan 2020 16:17:41 -0800 Subject: [PATCH 2/6] 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: Thu, 23 Jan 2020 16:17:39 -0800 Message-ID: <157982505923.2765631.10587375380960098225.stgit@magnolia> In-Reply-To: <157982504556.2765631.630298760136626647.stgit@magnolia> References: <157982504556.2765631.630298760136626647.stgit@magnolia> User-Agent: StGit/0.17.1-dirty MIME-Version: 1.0 X-Proofpoint-Virus-Version: vendor=nai engine=6000 definitions=9509 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-2001240000 X-Proofpoint-Virus-Version: vendor=nai engine=6000 definitions=9509 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-2001240000 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 --- 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 Fri Jan 24 00:17:45 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: 11349391 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 38BA2109A for ; Fri, 24 Jan 2020 00:17:52 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 1397B214AF for ; Fri, 24 Jan 2020 00:17:52 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=oracle.com header.i=@oracle.com header.b="CokuUsUR" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729639AbgAXARv (ORCPT ); Thu, 23 Jan 2020 19:17:51 -0500 Received: from userp2120.oracle.com ([156.151.31.85]:55976 "EHLO userp2120.oracle.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729616AbgAXARv (ORCPT ); Thu, 23 Jan 2020 19:17:51 -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 00O092Bf002932; Fri, 24 Jan 2020 00:17:49 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=20d1TRDNni/vKObZLnWSe7pAkwlMgXONdCRh39zXf7k=; b=CokuUsURtGqeimewPdy5XWEuiRt/YlIe4EYrOZYXGrl96Ps7lrvs1SaFrqcOI3WYd5/J /zOIicDSNLwG05EQ/99iAdVmrU53b+KpzaKDratOl42wqnvHXOqbVe6OFfDtdMT6tKhY EmiNy1UJACxxQnGycv4q8h5mFEe/JCDwPyuQob/3FFce+zNd3lyrw2KNAloRwDeuEBuZ gSA6VE48HMaXqsADJJDv9YoaKDssXlTbd5aaoDYPnTntodS7NINjM6k0IvdyQSVwMzTf zJ/8LRYfmgNy5aeuRlQhoKrGG10sKauXCA73hGap6xpjQpPXQVOukRJfkROsRQ45cacE Tg== Received: from userp3030.oracle.com (userp3030.oracle.com [156.151.31.80]) by userp2120.oracle.com with ESMTP id 2xktnrnn3d-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Fri, 24 Jan 2020 00:17:49 +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 00O0DWq2037288; Fri, 24 Jan 2020 00:17:48 GMT Received: from aserv0122.oracle.com (aserv0122.oracle.com [141.146.126.236]) by userp3030.oracle.com with ESMTP id 2xqmuxkjkb-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Fri, 24 Jan 2020 00:17:48 +0000 Received: from abhmp0015.oracle.com (abhmp0015.oracle.com [141.146.116.21]) by aserv0122.oracle.com (8.14.4/8.14.4) with ESMTP id 00O0HliY008186; Fri, 24 Jan 2020 00:17:47 GMT Received: from localhost (/10.145.179.16) by default (Oracle Beehive Gateway v4.0) with ESMTP ; Thu, 23 Jan 2020 16:17:47 -0800 Subject: [PATCH 3/6] 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, alex@zadara.com Date: Thu, 23 Jan 2020 16:17:45 -0800 Message-ID: <157982506534.2765631.12930539731426168994.stgit@magnolia> In-Reply-To: <157982504556.2765631.630298760136626647.stgit@magnolia> References: <157982504556.2765631.630298760136626647.stgit@magnolia> User-Agent: StGit/0.17.1-dirty MIME-Version: 1.0 X-Proofpoint-Virus-Version: vendor=nai engine=6000 definitions=9509 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-2001240000 X-Proofpoint-Virus-Version: vendor=nai engine=6000 definitions=9509 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-2001240000 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 --- 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..94673750 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 +ensure_fixed_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; - } - + ensure_fixed_ino(&mp->m_sb.sb_rootino, first_prealloc_ino, + _("root")); + ensure_fixed_ino(&mp->m_sb.sb_rbmino, first_prealloc_ino + 1, + _("realtime bitmap")); + ensure_fixed_ino(&mp->m_sb.sb_rsumino, first_prealloc_ino + 2, + _("realtime summary")); } /* From patchwork Fri Jan 24 00:17:51 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: 11349393 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 B461A109A for ; Fri, 24 Jan 2020 00:17:58 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 8EE34214AF for ; Fri, 24 Jan 2020 00:17:58 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=oracle.com header.i=@oracle.com header.b="L4MvfqCe" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729648AbgAXAR6 (ORCPT ); Thu, 23 Jan 2020 19:17:58 -0500 Received: from userp2120.oracle.com ([156.151.31.85]:56060 "EHLO userp2120.oracle.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729616AbgAXAR6 (ORCPT ); Thu, 23 Jan 2020 19:17:58 -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 00O08mQ7002813; Fri, 24 Jan 2020 00:17:56 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=DfLzYe+ZJg79fUZjeJz8m53/FM9GM9N88IGyETV2wrM=; b=L4MvfqCeV3YJfRCKNGO1l2xfbHBuW4ZFIPM/etG89r3hLXuimW0FeP/3DwFGh7XqBO6b S/TG3a97StryuZG7AOsU40lxEiOEaFVYsRRYQ1tbduRmInx3WouA4yyEdKRhtJRuUED9 ljQIm64Spa8r1qQMixUs32ocmlRvX//JquaU/q8faHShAsGyuqu9lY658nHDBrdILlPQ AemlPd9+cYnr0HvCwZwg3rlihsgUtomR7NLyk3mHsMZRfjuRoFxMZNyBXyL1kampy535 LiSnWnYhFZj3Gc0mfoxwR19CFTdrIbqc3a0jk+cyX7TB5b3ay/BLKu9ZjO9Monc5wnbg Jw== Received: from aserp3020.oracle.com (aserp3020.oracle.com [141.146.126.70]) by userp2120.oracle.com with ESMTP id 2xktnrnn3s-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Fri, 24 Jan 2020 00:17:55 +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 00O0E4Nw110958; Fri, 24 Jan 2020 00:17:55 GMT Received: from userv0121.oracle.com (userv0121.oracle.com [156.151.31.72]) by aserp3020.oracle.com with ESMTP id 2xqmwb1kkg-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Fri, 24 Jan 2020 00:17:54 +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 00O0HrQ8031171; Fri, 24 Jan 2020 00:17:53 GMT Received: from localhost (/10.145.179.16) by default (Oracle Beehive Gateway v4.0) with ESMTP ; Thu, 23 Jan 2020 16:17:53 -0800 Subject: [PATCH 4/6] 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, alex@zadara.com Date: Thu, 23 Jan 2020 16:17:51 -0800 Message-ID: <157982507143.2765631.5497851947437763176.stgit@magnolia> In-Reply-To: <157982504556.2765631.630298760136626647.stgit@magnolia> References: <157982504556.2765631.630298760136626647.stgit@magnolia> User-Agent: StGit/0.17.1-dirty MIME-Version: 1.0 X-Proofpoint-Virus-Version: vendor=nai engine=6000 definitions=9509 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-2001240000 X-Proofpoint-Virus-Version: vendor=nai engine=6000 definitions=9509 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-2001240000 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 --- 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 94673750..53b04dae 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 - */ - ensure_fixed_ino(&mp->m_sb.sb_rootino, first_prealloc_ino, + ensure_fixed_ino(&mp->m_sb.sb_rootino, rootino, _("root")); - ensure_fixed_ino(&mp->m_sb.sb_rbmino, first_prealloc_ino + 1, + ensure_fixed_ino(&mp->m_sb.sb_rbmino, rootino + 1, _("realtime bitmap")); - ensure_fixed_ino(&mp->m_sb.sb_rsumino, first_prealloc_ino + 2, + ensure_fixed_ino(&mp->m_sb.sb_rsumino, rootino + 2, _("realtime summary")); } From patchwork Fri Jan 24 00:17:57 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: 11349395 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 674AB109A for ; Fri, 24 Jan 2020 00:18:04 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 420C921569 for ; Fri, 24 Jan 2020 00:18:04 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=oracle.com header.i=@oracle.com header.b="bJooEgDf" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729238AbgAXASD (ORCPT ); Thu, 23 Jan 2020 19:18:03 -0500 Received: from userp2120.oracle.com ([156.151.31.85]:56166 "EHLO userp2120.oracle.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726584AbgAXASD (ORCPT ); Thu, 23 Jan 2020 19:18:03 -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 00O08uAO002855; Fri, 24 Jan 2020 00:18:01 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=EU1fv0NHuGomy0PkH+Ql1ABZvYEyeIguXxoao66n240=; b=bJooEgDf4ebjWLangxrGWdzhlW102NV2mzHfjwluEgwIsmvNT8WhLmjfFwAE6nbAsnHI ly6hwbz2AhGChBJPDVppYjv9w+FoB9q/Bjnzo46js2dEy9ggUuYb+16ZNmemv48a5y7b xg9UNqfEYfrxXTJKMIXMc2x4aAEJ1bBXAq1/V0F8zikFzeFF55SbDuCK44gACoP0lEOP O3dHByEFrtljoq1VURW1OjJCrxaDzWeb1pGLunD1VrzvCmF/D0OqZc/2EmrdHH5UFhnL F9OEXO8U8QbVak/4XVdB/OaNpv2lRTXbrRIJ/XJGWpko1uhvqJWeLZWhhy/Vxnyvd9G3 dQ== Received: from aserp3020.oracle.com (aserp3020.oracle.com [141.146.126.70]) by userp2120.oracle.com with ESMTP id 2xktnrnn4e-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Fri, 24 Jan 2020 00:18:01 +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 00O0E76b111238; Fri, 24 Jan 2020 00:18:00 GMT Received: from aserv0121.oracle.com (aserv0121.oracle.com [141.146.126.235]) by aserp3020.oracle.com with ESMTP id 2xqmwb1m5w-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Fri, 24 Jan 2020 00:18:00 +0000 Received: from abhmp0010.oracle.com (abhmp0010.oracle.com [141.146.116.16]) by aserv0121.oracle.com (8.14.4/8.13.8) with ESMTP id 00O0Hx0t020623; Fri, 24 Jan 2020 00:17:59 GMT Received: from localhost (/10.145.179.16) by default (Oracle Beehive Gateway v4.0) with ESMTP ; Thu, 23 Jan 2020 16:17:59 -0800 Subject: [PATCH 5/6] 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: Thu, 23 Jan 2020 16:17:57 -0800 Message-ID: <157982507752.2765631.16955377241063712365.stgit@magnolia> In-Reply-To: <157982504556.2765631.630298760136626647.stgit@magnolia> References: <157982504556.2765631.630298760136626647.stgit@magnolia> User-Agent: StGit/0.17.1-dirty MIME-Version: 1.0 X-Proofpoint-Virus-Version: vendor=nai engine=6000 definitions=9509 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-2001240000 X-Proofpoint-Virus-Version: vendor=nai engine=6000 definitions=9509 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-2001240000 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 --- repair/xfs_repair.c | 45 +++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 45 insertions(+) diff --git a/repair/xfs_repair.c b/repair/xfs_repair.c index 53b04dae..372616c4 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 " inconsistent with alignment (expected %"PRIu64")\n"), + mp->m_sb.sb_rootino, rootino); + rootino = mp->m_sb.sb_rootino; + } + ensure_fixed_ino(&mp->m_sb.sb_rootino, rootino, _("root")); ensure_fixed_ino(&mp->m_sb.sb_rbmino, rootino + 1, From patchwork Fri Jan 24 00:18:03 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: 11349397 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 D965A17EA for ; Fri, 24 Jan 2020 00:18:10 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id B39E92071E for ; Fri, 24 Jan 2020 00:18:10 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=oracle.com header.i=@oracle.com header.b="IMZw5GRe" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729149AbgAXASK (ORCPT ); Thu, 23 Jan 2020 19:18:10 -0500 Received: from userp2120.oracle.com ([156.151.31.85]:56252 "EHLO userp2120.oracle.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726584AbgAXASK (ORCPT ); Thu, 23 Jan 2020 19:18:10 -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 00O08mQ8002813; Fri, 24 Jan 2020 00:18:08 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=tfb+mOaTHUDN4882XgkvjbPShz2zxmMV461ap3Y6Qos=; b=IMZw5GRe/HDSyIt38FTENP0zJZkuYfd4KXvLl2ArnVNsOGq8XcpSalDQYdqif2ZDhO9s JWocCGobD297P/J05TqRFJxmimbA6lDUVdhSmCR4q7b99TYiTS5a7yfrx+O24uPnCBBc 0zPyjtKwHzrtc3oKAbQS2FXvCgvkN+6y+bLqsoMuSPgidJ0re0Wl4VQsYQcFh54ECnk5 DU8gf0igK4OGlcvk3WJX9RhWVXXBbCAT1HOwNC7ooHaQrRHu2Q9EJdarEdTSZNRIV+LU mFcBa16qm1KJJ/FZWGUnDfElrcP8KLdacIVX34TEdWZgqIl1bsLyWYa4cXqooR8NKRfY bA== Received: from aserp3030.oracle.com (aserp3030.oracle.com [141.146.126.71]) by userp2120.oracle.com with ESMTP id 2xktnrnn4t-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Fri, 24 Jan 2020 00:18:08 +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 00O0Eb2N145960; Fri, 24 Jan 2020 00:18:07 GMT Received: from userv0121.oracle.com (userv0121.oracle.com [156.151.31.72]) by aserp3030.oracle.com with ESMTP id 2xqmudkvrs-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Fri, 24 Jan 2020 00:18:07 +0000 Received: from abhmp0013.oracle.com (abhmp0013.oracle.com [141.146.116.19]) by userv0121.oracle.com (8.14.4/8.13.8) with ESMTP id 00O0I6D2031252; Fri, 24 Jan 2020 00:18:06 GMT Received: from localhost (/10.145.179.16) by default (Oracle Beehive Gateway v4.0) with ESMTP ; Thu, 23 Jan 2020 16:18:05 -0800 Subject: [PATCH 6/6] 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: Thu, 23 Jan 2020 16:18:03 -0800 Message-ID: <157982508365.2765631.12815545024134566792.stgit@magnolia> In-Reply-To: <157982504556.2765631.630298760136626647.stgit@magnolia> References: <157982504556.2765631.630298760136626647.stgit@magnolia> User-Agent: StGit/0.17.1-dirty MIME-Version: 1.0 X-Proofpoint-Virus-Version: vendor=nai engine=6000 definitions=9509 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-2001240000 X-Proofpoint-Virus-Version: vendor=nai engine=6000 definitions=9509 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-2001240000 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 --- 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 9ede0125..d9f497e0 100644 --- a/libxfs/libxfs_api_defs.h +++ b/libxfs/libxfs_api_defs.h @@ -178,5 +178,6 @@ #define xfs_finobt_calc_reserves libxfs_finobt_calc_reserves #define xfs_rmapbt_calc_reserves libxfs_rmapbt_calc_reserves #define xfs_read_agf libxfs_read_agf +#define xfs_sb_read_secondary libxfs_sb_read_secondary #endif /* __LIBXFS_API_DEFS_H__ */ diff --git a/repair/xfs_repair.c b/repair/xfs_repair.c index 372616c4..66e2c335 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 " inconsistent with alignment (expected %"PRIu64")\n"), mp->m_sb.sb_rootino, rootino); + guess_correct_sunit(mp); rootino = mp->m_sb.sb_rootino; }