From patchwork Tue Jan 8 20:33:18 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Darrick J. Wong" X-Patchwork-Id: 10752851 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 036D61399 for ; Tue, 8 Jan 2019 20:33:31 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id E2C9A28D9B for ; Tue, 8 Jan 2019 20:33:30 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id D288728DB0; Tue, 8 Jan 2019 20:33:30 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-8.0 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,MAILING_LIST_MULTI,RCVD_IN_DNSWL_HI, UNPARSEABLE_RELAY autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 622AF28D9B for ; Tue, 8 Jan 2019 20:33:30 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729245AbfAHUda (ORCPT ); Tue, 8 Jan 2019 15:33:30 -0500 Received: from aserp2130.oracle.com ([141.146.126.79]:42654 "EHLO aserp2130.oracle.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728644AbfAHUd3 (ORCPT ); Tue, 8 Jan 2019 15:33:29 -0500 Received: from pps.filterd (aserp2130.oracle.com [127.0.0.1]) by aserp2130.oracle.com (8.16.0.22/8.16.0.22) with SMTP id x08KOHN0102298; Tue, 8 Jan 2019 20:33:26 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-2018-07-02; bh=jDgDryhBrNN7rPkFUZYobh24CCy0s749Tsn/NQTs1iA=; b=MVz9dIwoLUs3ALkI3rOZ+BkT9CrJlXg8QLeYKXP5DTq6EMGxSytTnh9CrsrvT2x0Kzrl MkBqgfbtZrWxwIEIQITjVO0e+7hTJnMcSsmalhgzKXenwPA482i3ejE6Sf3yQ1kywt7O Db/GHZb+K7oD8JTWYHYxCmFIlzWExTzEQ59JIwLEpcONeha1MKYjZVInu+KMov6+5EZH hDIx4EdD44fGs8/k71efgQtgGNlVg+6DqlkOQN03n7Cr604A8s28XEhN2rvRLEhQL/GF M6ZSyBQdz97PvzGkE7BsNbTWt6Y5xCC2ssMl8iEOjSVsQ/Yjx5h0Zu7md0Bc5vAqgGiT 5A== Received: from userv0022.oracle.com (userv0022.oracle.com [156.151.31.74]) by aserp2130.oracle.com with ESMTP id 2ptj3dx1dq-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Tue, 08 Jan 2019 20:33:26 +0000 Received: from aserv0122.oracle.com (aserv0122.oracle.com [141.146.126.236]) by userv0022.oracle.com (8.14.4/8.14.4) with ESMTP id x08KXKi4018844 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Tue, 8 Jan 2019 20:33:20 GMT Received: from abhmp0020.oracle.com (abhmp0020.oracle.com [141.146.116.26]) by aserv0122.oracle.com (8.14.4/8.14.4) with ESMTP id x08KXJhM028454; Tue, 8 Jan 2019 20:33:19 GMT Received: from localhost (/67.169.218.210) by default (Oracle Beehive Gateway v4.0) with ESMTP ; Tue, 08 Jan 2019 12:33:19 -0800 Subject: [PATCH 7/7] xfs: consolidate scrub dinode mapping code into a single function From: "Darrick J. Wong" To: darrick.wong@oracle.com Cc: linux-xfs@vger.kernel.org, bfoster@redhat.com Date: Tue, 08 Jan 2019 12:33:18 -0800 Message-ID: <154697959877.2494.10993090686249072444.stgit@magnolia> In-Reply-To: <154697955494.2494.5221420762912855354.stgit@magnolia> References: <154697955494.2494.5221420762912855354.stgit@magnolia> User-Agent: StGit/0.17.1-dirty MIME-Version: 1.0 X-Proofpoint-Virus-Version: vendor=nai engine=5900 definitions=9130 signatures=668680 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 suspectscore=3 malwarescore=0 phishscore=0 bulkscore=0 spamscore=0 mlxscore=0 mlxlogscore=999 adultscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.0.1-1810050000 definitions=main-1901080158 Sender: linux-xfs-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-xfs@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP From: Darrick J. Wong Move all the confusing dinode mapping code that's split between xchk_iallocbt_check_cluster and xchk_iallocbt_check_cluster_ifree into the first function so that it's clearer how we find the dinode for a given inode. Signed-off-by: Darrick J. Wong Reviewed-by: Brian Foster --- fs/xfs/scrub/ialloc.c | 48 +++++++++++++++++++++++++++--------------------- 1 file changed, 27 insertions(+), 21 deletions(-) diff --git a/fs/xfs/scrub/ialloc.c b/fs/xfs/scrub/ialloc.c index 1929d79ea6b3..663cc8a98fc9 100644 --- a/fs/xfs/scrub/ialloc.c +++ b/fs/xfs/scrub/ialloc.c @@ -146,7 +146,7 @@ xchk_iallocbt_freecount( * * @irec is the inobt record. * @cluster_base is the inode offset of the cluster within the @irec. - * @cluster_bp is the cluster buffer. + * @dip is the on-disk inode. * @cluster_index is the inode offset within the inode cluster. */ STATIC int @@ -154,15 +154,12 @@ xchk_iallocbt_check_cluster_ifree( struct xchk_btree *bs, struct xfs_inobt_rec_incore *irec, unsigned int cluster_base, - struct xfs_buf *cluster_bp, + struct xfs_dinode *dip, unsigned int cluster_index) { struct xfs_mount *mp = bs->cur->bc_mp; - struct xfs_dinode *dip; xfs_ino_t fsino; xfs_agino_t agino; - unsigned int offset; - unsigned int cluster_buf_base; bool irec_free; bool ino_inuse; bool freemask_ok; @@ -174,23 +171,10 @@ xchk_iallocbt_check_cluster_ifree( /* * Given an inobt record, an offset of a cluster within the record, and * an offset of an inode within a cluster, compute which fs inode we're - * talking about and the offset of that inode within the buffer. - * - * Be careful about inobt records that don't align with the start of - * the inode buffer when block sizes are large enough to hold multiple - * inode chunks. When this happens, cluster_base will be zero but - * ir_startino can be large enough to make cluster_buf_base nonzero. + * talking about. */ agino = irec->ir_startino + cluster_base + cluster_index; fsino = XFS_AGINO_TO_INO(mp, bs->cur->bc_private.a.agno, agino); - cluster_buf_base = XFS_INO_TO_OFFSET(mp, irec->ir_startino); - ASSERT(cluster_buf_base == 0 || cluster_base == 0); - offset = (cluster_buf_base + cluster_index) * mp->m_sb.sb_inodesize; - if (offset >= BBTOB(cluster_bp->b_length)) { - xchk_btree_set_corrupt(bs->sc, bs->cur, 0); - goto out; - } - dip = xfs_buf_offset(cluster_bp, offset); irec_free = (irec->ir_free & XFS_INOBT_MASK(cluster_base + cluster_index)); @@ -262,10 +246,23 @@ xchk_iallocbt_check_cluster( cluster_mask |= XFS_INOBT_MASK((cluster_base + cluster_index) / XFS_INODES_PER_HOLEMASK_BIT); + /* + * Map the first inode of this cluster to a buffer and offset. + * Be careful about inobt records that don't align with the start of + * the inode buffer when block sizes are large enough to hold multiple + * inode chunks. When this happens, cluster_base will be zero but + * ir_startino can be large enough to make im_boffset nonzero. + */ ir_holemask = (irec->ir_holemask & cluster_mask); imap.im_blkno = XFS_AGB_TO_DADDR(mp, agno, agbno); imap.im_len = XFS_FSB_TO_BB(mp, mp->m_blocks_per_cluster); - imap.im_boffset = 0; + imap.im_boffset = XFS_INO_TO_OFFSET(mp, irec->ir_startino); + + if (imap.im_boffset != 0 && cluster_base != 0) { + ASSERT(imap.im_boffset == 0 || cluster_base == 0); + xchk_btree_set_corrupt(bs->sc, bs->cur, 0); + return 0; + } trace_xchk_iallocbt_check_cluster(mp, agno, irec->ir_startino, imap.im_blkno, imap.im_len, cluster_base, nr_inodes, @@ -298,10 +295,19 @@ xchk_iallocbt_check_cluster( /* Check free status of each inode within this cluster. */ for (cluster_index = 0; cluster_index < nr_inodes; cluster_index++) { + struct xfs_dinode *dip; + + if (imap.im_boffset >= BBTOB(cluster_bp->b_length)) { + xchk_btree_set_corrupt(bs->sc, bs->cur, 0); + break; + } + + dip = xfs_buf_offset(cluster_bp, imap.im_boffset); error = xchk_iallocbt_check_cluster_ifree(bs, irec, - cluster_base, cluster_bp, cluster_index); + cluster_base, dip, cluster_index); if (error) break; + imap.im_boffset += mp->m_sb.sb_inodesize; } xfs_trans_brelse(bs->cur->bc_tp, cluster_bp);