From patchwork Sat Jan 21 08:04:41 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Darrick J. Wong" X-Patchwork-Id: 9529971 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 273246020B for ; Sat, 21 Jan 2017 08:04:47 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 16A8528427 for ; Sat, 21 Jan 2017 08:04:47 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 0B6CC28698; Sat, 21 Jan 2017 08:04:47 +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.9 required=2.0 tests=BAYES_00, RCVD_IN_DNSWL_HI, UNPARSEABLE_RELAY autolearn=unavailable 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 B798528427 for ; Sat, 21 Jan 2017 08:04:46 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751218AbdAUIEp (ORCPT ); Sat, 21 Jan 2017 03:04:45 -0500 Received: from aserp1040.oracle.com ([141.146.126.69]:19912 "EHLO aserp1040.oracle.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751212AbdAUIEo (ORCPT ); Sat, 21 Jan 2017 03:04:44 -0500 Received: from aserv0022.oracle.com (aserv0022.oracle.com [141.146.126.234]) by aserp1040.oracle.com (Sentrion-MTA-4.3.2/Sentrion-MTA-4.3.2) with ESMTP id v0L84h59014499 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Sat, 21 Jan 2017 08:04:43 GMT Received: from userv0122.oracle.com (userv0122.oracle.com [156.151.31.75]) by aserv0022.oracle.com (8.14.4/8.14.4) with ESMTP id v0L84hOC016176 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Sat, 21 Jan 2017 08:04:43 GMT Received: from abhmp0003.oracle.com (abhmp0003.oracle.com [141.146.116.9]) by userv0122.oracle.com (8.14.4/8.14.4) with ESMTP id v0L84g9Z006990; Sat, 21 Jan 2017 08:04:42 GMT Received: from localhost (/24.21.211.40) by default (Oracle Beehive Gateway v4.0) with ESMTP ; Sat, 21 Jan 2017 00:04:42 -0800 Subject: [PATCH 40/55] xfs: cross-reference the block mappings when possible From: "Darrick J. Wong" To: darrick.wong@oracle.com Cc: linux-xfs@vger.kernel.org, linux-fsdevel@vger.kernel.org Date: Sat, 21 Jan 2017 00:04:41 -0800 Message-ID: <148498588148.15323.1003787360040383897.stgit@birch.djwong.org> In-Reply-To: <148498561504.15323.8531512066874274553.stgit@birch.djwong.org> References: <148498561504.15323.8531512066874274553.stgit@birch.djwong.org> User-Agent: StGit/0.17.1-dirty MIME-Version: 1.0 X-Source-IP: aserv0022.oracle.com [141.146.126.234] Sender: linux-fsdevel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-fsdevel@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP Check inode field contents against the block mappings when possible. Signed-off-by: Darrick J. Wong --- fs/xfs/scrub/inode.c | 43 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 43 insertions(+) -- To unsubscribe from this list: send the line "unsubscribe linux-fsdevel" 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 8b625b5..e79fe5b 100644 --- a/fs/xfs/scrub/inode.c +++ b/fs/xfs/scrub/inode.c @@ -39,6 +39,8 @@ #include "xfs_log.h" #include "xfs_trans_priv.h" #include "xfs_rmap.h" +#include "xfs_bmap.h" +#include "xfs_bmap_util.h" #include "scrub/common.h" /* @@ -181,6 +183,7 @@ xfs_scrub_inode( struct xfs_dinode *dip; xfs_ino_t ino; unsigned long long isize; + unsigned long long count; uint64_t flags2; uint32_t nextents; uint32_t extsize; @@ -396,6 +399,46 @@ xfs_scrub_inode( xfs_scrub_ag_free(&sa); } + /* Walk all the extents to check nextents/naextents/nblocks. */ + count = 0; + err2 = xfs_bmap_count_blocks(sc->tp, sc->ip, XFS_DATA_FORK, + &nextents, &count); + if (!xfs_scrub_should_xref(sc, err2, NULL)) + goto skip_block_check; + XFS_SCRUB_INODE_XCHECK(nextents >= be32_to_cpu(dip->di_nextents)); + + err2 = xfs_bmap_count_blocks(sc->tp, sc->ip, XFS_ATTR_FORK, + &nextents, &count); + if (!xfs_scrub_should_xref(sc, err2, NULL)) + goto skip_block_check; + XFS_SCRUB_INODE_XCHECK(nextents == be16_to_cpu(dip->di_anextents)); + + /* Check nblocks, taking any delalloc extents into account. */ + if (sc->ip) + count -= sc->ip->i_delayed_blks; + XFS_SCRUB_INODE_XCHECK(count == be64_to_cpu(dip->di_nblocks)); + +skip_block_check: + /* Make sure we don't have any written extents after EOF. */ + if (S_ISREG(mode) && !(flags & XFS_DIFLAG_PREALLOC) && + (dip->di_format == XFS_DINODE_FMT_EXTENTS || + dip->di_format == XFS_DINODE_FMT_BTREE)) { + struct xfs_bmbt_irec got; + struct xfs_ifork *ifp; + xfs_fileoff_t lblk; + xfs_extnum_t idx; + bool found; + + lblk = XFS_B_TO_FSB(mp, i_size_read(VFS_I(sc->ip))); + ifp = XFS_IFORK_PTR(sc->ip, XFS_DATA_FORK); + found = xfs_iext_lookup_extent(sc->ip, ifp, lblk, &idx, &got); + while (found) { + XFS_SCRUB_INODE_PREEN(got.br_startoff < lblk || + got.br_state != XFS_EXT_NORM); + lblk = got.br_startoff + got.br_blockcount; + found = xfs_iext_get_extent(ifp, ++idx, &got); + } + } out: if (bp) xfs_trans_brelse(sc->tp, bp);