From patchwork Tue Jan 9 21:26:33 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Darrick J. Wong" X-Patchwork-Id: 10153541 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 362E0601A1 for ; Tue, 9 Jan 2018 21:28:33 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 2A4C6200E7 for ; Tue, 9 Jan 2018 21:28:33 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 1F01822B1F; Tue, 9 Jan 2018 21:28:33 +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=-6.8 required=2.0 tests=BAYES_00,DKIM_SIGNED, RCVD_IN_DNSWL_HI, T_DKIM_INVALID, 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 9D45922701 for ; Tue, 9 Jan 2018 21:28:32 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751817AbeAIV2b (ORCPT ); Tue, 9 Jan 2018 16:28:31 -0500 Received: from aserp2120.oracle.com ([141.146.126.78]:59052 "EHLO aserp2120.oracle.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752305AbeAIV2a (ORCPT ); Tue, 9 Jan 2018 16:28:30 -0500 Received: from pps.filterd (aserp2120.oracle.com [127.0.0.1]) by aserp2120.oracle.com (8.16.0.22/8.16.0.22) with SMTP id w09LQVWY088913 for ; Tue, 9 Jan 2018 21:28:30 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=oracle.com; h=date : from : to : subject : message-id : references : mime-version : content-type : in-reply-to; s=corp-2017-10-26; bh=wcDgJ8rllT+vxJKcwaLLq29cbS4iTg6msJN3/EfKE4Q=; b=OxycM25oU0wN0WU63iknOksjp+s33WxtCF9DT+lfTl2cEtpfaiH36jnZL6LiCuReJ//P y8wAWGVnxl+2TfPYf42ZFyT4270XTOhJJ+5W6ba8fCeQU0JV7ncnBvztKVHB2ANJWnQt EC74C7zlmwSGuc9uipVa5yMYAJXExIH2HWIvC83itezoXPdjbRLXF1V6xCAX0qi3ba2i 8v4Fbzj3QZhbGSGfa6swr0c8Qx6r69ehH+4dOOqXjA5jRiwUuea/8Ss6l9e/D1paLpKp sMYXFeBR7shiILu20YMvAV0qhA5R5CeqZlIqJkLq/7JxX43MLJf+LdJi4DWF6bBULdHY VQ== Received: from userv0022.oracle.com (userv0022.oracle.com [156.151.31.74]) by aserp2120.oracle.com with ESMTP id 2fd5fv825f-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK) for ; Tue, 09 Jan 2018 21:28:29 +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 w09LQZfE002118 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=FAIL) for ; Tue, 9 Jan 2018 21:26:35 GMT Received: from abhmp0011.oracle.com (abhmp0011.oracle.com [141.146.116.17]) by aserv0122.oracle.com (8.14.4/8.14.4) with ESMTP id w09LQYbC013254 for ; Tue, 9 Jan 2018 21:26:34 GMT Received: from localhost (/67.169.218.210) by default (Oracle Beehive Gateway v4.0) with ESMTP ; Tue, 09 Jan 2018 13:26:34 -0800 Date: Tue, 9 Jan 2018 13:26:33 -0800 From: "Darrick J. Wong" To: linux-xfs@vger.kernel.org Subject: [PATCH v2 21/21] xfs: cross-reference the block mappings when possible Message-ID: <20180109212633.GP5602@magnolia> References: <151398977028.18741.12031215574014508438.stgit@magnolia> <151398990147.18741.17837826861246689519.stgit@magnolia> MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: <151398990147.18741.17837826861246689519.stgit@magnolia> User-Agent: Mutt/1.5.24 (2015-08-30) X-Proofpoint-Virus-Version: vendor=nai engine=5900 definitions=8769 signatures=668652 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-1711220000 definitions=main-1801090292 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 Use an inode's block mappings to cross-reference inode block counters. Signed-off-by: Darrick J. Wong Reviewed-by: Dave Chinner --- v2: streamline scrubber arguments, remove stack allocated objects --- fs/xfs/scrub/inode.c | 34 ++++++++++++++++++++++++++++++++++ 1 file changed, 34 insertions(+) -- To unsubscribe from this list: send the line "unsubscribe linux-xfs" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html diff --git a/fs/xfs/scrub/inode.c b/fs/xfs/scrub/inode.c index f12586c..b2fc3ac 100644 --- a/fs/xfs/scrub/inode.c +++ b/fs/xfs/scrub/inode.c @@ -37,6 +37,8 @@ #include "xfs_da_format.h" #include "xfs_reflink.h" #include "xfs_rmap.h" +#include "xfs_bmap.h" +#include "xfs_bmap_util.h" #include "scrub/xfs_scrub.h" #include "scrub/scrub.h" #include "scrub/common.h" @@ -626,6 +628,37 @@ xfs_scrub_inode_xref_finobt( xfs_scrub_btree_xref_set_corrupt(sc, sc->sa.fino_cur, 0); } +/* Cross reference the inode fields with the forks. */ +STATIC void +xfs_scrub_inode_xref_bmap( + struct xfs_scrub_context *sc, + struct xfs_dinode *dip) +{ + xfs_extnum_t nextents; + xfs_filblks_t count; + xfs_filblks_t acount; + int error; + + /* Walk all the extents to check nextents/naextents/nblocks. */ + error = xfs_bmap_count_blocks(sc->tp, sc->ip, XFS_DATA_FORK, + &nextents, &count); + if (!xfs_scrub_should_check_xref(sc, &error, NULL)) + return; + if (nextents < be32_to_cpu(dip->di_nextents)) + xfs_scrub_ino_xref_set_corrupt(sc, sc->ip->i_ino, NULL); + + error = xfs_bmap_count_blocks(sc->tp, sc->ip, XFS_ATTR_FORK, + &nextents, &acount); + if (!xfs_scrub_should_check_xref(sc, &error, NULL)) + return; + if (nextents != be16_to_cpu(dip->di_anextents)) + xfs_scrub_ino_xref_set_corrupt(sc, sc->ip->i_ino, NULL); + + /* Check nblocks against the inode. */ + if (count + acount != be64_to_cpu(dip->di_nblocks)) + xfs_scrub_ino_xref_set_corrupt(sc, sc->ip->i_ino, NULL); +} + /* Cross-reference with the other btrees. */ STATIC void xfs_scrub_inode_xref( @@ -653,6 +686,7 @@ xfs_scrub_inode_xref( xfs_rmap_ag_owner(&oinfo, XFS_RMAP_OWN_INODES); xfs_scrub_xref_owned_by(sc, agbno, 1, &oinfo); xfs_scrub_xref_not_shared(sc, agbno, 1); + xfs_scrub_inode_xref_bmap(sc, dip); xfs_scrub_ag_free(sc, &sc->sa); }