From patchwork Mon Dec 3 23:01:33 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Eric Sandeen X-Patchwork-Id: 10710881 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 052FB14BD for ; Mon, 3 Dec 2018 23:01:37 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id E77CD2AE8A for ; Mon, 3 Dec 2018 23:01:36 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id DACD52AE90; Mon, 3 Dec 2018 23:01:36 +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=-7.9 required=2.0 tests=BAYES_00,MAILING_LIST_MULTI, RCVD_IN_DNSWL_HI 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 7752D2AE8A for ; Mon, 3 Dec 2018 23:01:36 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1725920AbeLCXBf (ORCPT ); Mon, 3 Dec 2018 18:01:35 -0500 Received: from mx1.redhat.com ([209.132.183.28]:36686 "EHLO mx1.redhat.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725858AbeLCXBf (ORCPT ); Mon, 3 Dec 2018 18:01:35 -0500 Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.11]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 5481664D85; Mon, 3 Dec 2018 23:01:35 +0000 (UTC) Received: from [IPv6:::1] (ovpn04.gateway.prod.ext.phx2.redhat.com [10.5.9.4]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 0BAD6600C7; Mon, 3 Dec 2018 23:01:34 +0000 (UTC) To: linux-xfs From: Eric Sandeen Subject: [PATCH] xfs_db: teach the frag command about sparse inode chunks Cc: Matthias Bodenbinder Message-ID: Date: Mon, 3 Dec 2018 17:01:33 -0600 User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.13; rv:52.0) Gecko/20100101 Thunderbird/52.9.1 MIME-Version: 1.0 Content-Language: en-US X-Scanned-By: MIMEDefang 2.79 on 10.5.11.11 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.38]); Mon, 03 Dec 2018 23:01:35 +0000 (UTC) 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 This is the equivalent of: ea8a48f xfs_check: process sparse inode chunks correctly for the frag_f() command in xfs_db. Without this, the xfs_db frag command shows corruption as it wanders into blocks that are not inodes. Bugzilla: https://bugzilla.kernel.org/show_bug.cgi?id=201823 Signed-off-by: Eric Sandeen Reviewed-by: Brian Foster diff --git a/db/frag.c b/db/frag.c index 6792d47..5f33cb7 100644 --- a/db/frag.c +++ b/db/frag.c @@ -466,29 +466,56 @@ scanfunc_ino( int off; xfs_inobt_ptr_t *pp; xfs_inobt_rec_t *rp; + xfs_agblock_t agbno; + xfs_agblock_t end_agbno; + struct xfs_dinode *dip; + int blks_per_buf; + int inodes_per_buf; + int ioff; + + if (xfs_sb_version_hassparseinodes(&mp->m_sb)) + blks_per_buf = xfs_icluster_size_fsb(mp); + else + blks_per_buf = mp->m_ialloc_blks; + inodes_per_buf = min(blks_per_buf << mp->m_sb.sb_inopblog, + XFS_INODES_PER_CHUNK); if (level == 0) { rp = XFS_INOBT_REC_ADDR(mp, block, 1); for (i = 0; i < be16_to_cpu(block->bb_numrecs); i++) { agino = be32_to_cpu(rp[i].ir_startino); - off = XFS_INO_TO_OFFSET(mp, agino); + agbno = XFS_AGINO_TO_AGBNO(mp, agino); + off = XFS_AGINO_TO_OFFSET(mp, agino); + end_agbno = agbno + mp->m_ialloc_blks; + push_cur(); - set_cur(&typtab[TYP_INODE], - XFS_AGB_TO_DADDR(mp, seqno, - XFS_AGINO_TO_AGBNO(mp, agino)), - XFS_FSB_TO_BB(mp, mp->m_ialloc_blks), - DB_RING_IGN, NULL); - if (iocur_top->data == NULL) { - dbprintf(_("can't read inode block %u/%u\n"), - seqno, XFS_AGINO_TO_AGBNO(mp, agino)); - continue; - } - for (j = 0; j < XFS_INODES_PER_CHUNK; j++) { - if (XFS_INOBT_IS_FREE_DISK(&rp[i], j)) - continue; - process_inode(agf, agino + j, (xfs_dinode_t *) - ((char *)iocur_top->data + - ((off + j) << mp->m_sb.sb_inodelog))); + ioff = 0; + while (agbno < end_agbno && + ioff < XFS_INODES_PER_CHUNK) { + if (xfs_inobt_is_sparse_disk(&rp[i], ioff)) + goto next_buf; + + set_cur(&typtab[TYP_INODE], + XFS_AGB_TO_DADDR(mp, seqno, agbno), + XFS_FSB_TO_BB(mp, blks_per_buf), + DB_RING_IGN, NULL); + if (iocur_top->data == NULL) { + dbprintf(_("can't read inode block %u/%u\n"), + seqno, agbno); + goto next_buf; + } + + for (j = 0; j < inodes_per_buf; j++) { + if (XFS_INOBT_IS_FREE_DISK(&rp[i], ioff + j)) + goto next_buf; + dip = (xfs_dinode_t *)((char *)iocur_top->data + + ((off + j) << mp->m_sb.sb_inodelog)); + process_inode(agf, agino + ioff + j, dip); + } + +next_buf: + agbno += blks_per_buf; + ioff += inodes_per_buf; } pop_cur(); }