From patchwork Wed Jan 31 03:08:07 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: 10193131 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 71DC76020C for ; Wed, 31 Jan 2018 03:08:13 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 63422281DB for ; Wed, 31 Jan 2018 03:08:13 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 57CA928329; Wed, 31 Jan 2018 03:08:13 +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 C6646281DB for ; Wed, 31 Jan 2018 03:08:12 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752135AbeAaDIM (ORCPT ); Tue, 30 Jan 2018 22:08:12 -0500 Received: from aserp2130.oracle.com ([141.146.126.79]:58828 "EHLO aserp2130.oracle.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751647AbeAaDIL (ORCPT ); Tue, 30 Jan 2018 22:08:11 -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 w0V37JVp004418; Wed, 31 Jan 2018 03:08:10 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-2017-10-26; bh=4xk5tucupYFCOH9vhYD40PMgSHaasY4UehOrPthVKSU=; b=u6DDHQlRSwhjTH0MtVv0jWGhxztKBe+q9TW5HUMn+kSpzoh3AhMVwZA3zfGh8By+VxQm S8mYd6gomr53GvhAfXtIOGfJOxrmJDCtbgXUAPJtLLb959EpqKlCKgOCUwolDkCTNAo2 yVjspmvl8HGxHZzjaIlkO7coTfyt3oDSlrCytD/dU2sKr68h79a1YxKlYJb85qZ6hMif VOVGQy+nuA8EHxmdYAsAmW1/sFBhgDItf5jpGEsgj5aPeUCaGncBRYq95X6gI+ueHe5K 8WDuFHxJ/zOquXIouMc0g0zrb5bn+uI+RgvGRXwa/nm3+hNZvKlCiikm8O/wGPUN0tys CQ== Received: from aserv0021.oracle.com (aserv0021.oracle.com [141.146.126.233]) by aserp2130.oracle.com with ESMTP id 2fu54yg3gq-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Wed, 31 Jan 2018 03:08:09 +0000 Received: from userv0122.oracle.com (userv0122.oracle.com [156.151.31.75]) by aserv0021.oracle.com (8.14.4/8.14.4) with ESMTP id w0V388j7021056 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=FAIL); Wed, 31 Jan 2018 03:08:09 GMT Received: from abhmp0019.oracle.com (abhmp0019.oracle.com [141.146.116.25]) by userv0122.oracle.com (8.14.4/8.14.4) with ESMTP id w0V388QF008096; Wed, 31 Jan 2018 03:08:08 GMT Received: from localhost (/67.169.218.210) by default (Oracle Beehive Gateway v4.0) with ESMTP ; Tue, 30 Jan 2018 19:08:08 -0800 Subject: [PATCH 15/29] xfs_scrub: scan inodes From: "Darrick J. Wong" To: sandeen@redhat.com, darrick.wong@oracle.com Cc: linux-xfs@vger.kernel.org Date: Tue, 30 Jan 2018 19:08:07 -0800 Message-ID: <151736808735.32164.12551189639292943964.stgit@magnolia> In-Reply-To: <151736799098.32164.15446216987522359103.stgit@magnolia> References: <151736799098.32164.15446216987522359103.stgit@magnolia> User-Agent: StGit/0.17.1-dirty MIME-Version: 1.0 X-Proofpoint-Virus-Version: vendor=nai engine=5900 definitions=8790 signatures=668657 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 suspectscore=2 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-1801310037 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 Scan all the inodes in the system for problems. Signed-off-by: Darrick J. Wong --- scrub/Makefile | 1 scrub/phase3.c | 152 +++++++++++++++++++++++++++++++++++++++++++++++++++++ scrub/xfs_scrub.c | 1 scrub/xfs_scrub.h | 2 + 4 files changed, 156 insertions(+) create mode 100644 scrub/phase3.c -- 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/scrub/Makefile b/scrub/Makefile index 30dbe54..e0d15d8 100644 --- a/scrub/Makefile +++ b/scrub/Makefile @@ -35,6 +35,7 @@ fscounters.c \ inodes.c \ phase1.c \ phase2.c \ +phase3.c \ scrub.c \ spacemap.c \ xfs_scrub.c diff --git a/scrub/phase3.c b/scrub/phase3.c new file mode 100644 index 0000000..b3fc510 --- /dev/null +++ b/scrub/phase3.c @@ -0,0 +1,152 @@ +/* + * Copyright (C) 2018 Oracle. All Rights Reserved. + * + * Author: Darrick J. Wong + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 2 + * of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it would be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA. + */ +#include +#include +#include +#include +#include +#include +#include "xfs.h" +#include "path.h" +#include "workqueue.h" +#include "xfs_scrub.h" +#include "common.h" +#include "counter.h" +#include "inodes.h" +#include "scrub.h" + +/* Phase 3: Scan all inodes. */ + +/* + * Run a per-file metadata scanner. We use the ino/gen interface to + * ensure that the inode we're checking matches what the inode scan + * told us to look at. + */ +static bool +xfs_scrub_fd( + struct scrub_ctx *ctx, + bool (*fn)(struct scrub_ctx *, uint64_t, + uint32_t, int), + struct xfs_bstat *bs) +{ + return fn(ctx, bs->bs_ino, bs->bs_gen, ctx->mnt_fd); +} + +struct scrub_inode_ctx { + struct ptcounter *icount; + bool moveon; +}; + +/* Verify the contents, xattrs, and extent maps of an inode. */ +static int +xfs_scrub_inode( + struct scrub_ctx *ctx, + struct xfs_handle *handle, + struct xfs_bstat *bstat, + void *arg) +{ + struct scrub_inode_ctx *ictx = arg; + struct ptcounter *icount = ictx->icount; + bool moveon = true; + int fd = -1; + + background_sleep(); + + /* Try to open the inode to pin it. */ + if (S_ISREG(bstat->bs_mode)) { + fd = xfs_open_handle(handle); + /* Stale inode means we scan the whole cluster again. */ + if (fd < 0 && errno == ESTALE) + return ESTALE; + } + + /* Scrub the inode. */ + moveon = xfs_scrub_fd(ctx, xfs_scrub_inode_fields, bstat); + if (!moveon) + goto out; + + /* Scrub all block mappings. */ + moveon = xfs_scrub_fd(ctx, xfs_scrub_data_fork, bstat); + if (!moveon) + goto out; + moveon = xfs_scrub_fd(ctx, xfs_scrub_attr_fork, bstat); + if (!moveon) + goto out; + moveon = xfs_scrub_fd(ctx, xfs_scrub_cow_fork, bstat); + if (!moveon) + goto out; + + if (S_ISLNK(bstat->bs_mode)) { + /* Check symlink contents. */ + moveon = xfs_scrub_symlink(ctx, bstat->bs_ino, + bstat->bs_gen, ctx->mnt_fd); + } else if (S_ISDIR(bstat->bs_mode)) { + /* Check the directory entries. */ + moveon = xfs_scrub_fd(ctx, xfs_scrub_dir, bstat); + } + if (!moveon) + goto out; + + /* Check all the extended attributes. */ + moveon = xfs_scrub_fd(ctx, xfs_scrub_attr, bstat); + if (!moveon) + goto out; + + /* Check parent pointers. */ + moveon = xfs_scrub_fd(ctx, xfs_scrub_parent, bstat); + if (!moveon) + goto out; + +out: + ptcounter_add(icount, 1); + if (fd >= 0) + close(fd); + if (!moveon) + ictx->moveon = false; + return ictx->moveon ? 0 : XFS_ITERATE_INODES_ABORT; +} + +/* Verify all the inodes in a filesystem. */ +bool +xfs_scan_inodes( + struct scrub_ctx *ctx) +{ + struct scrub_inode_ctx ictx; + bool ret; + + ictx.moveon = true; + ictx.icount = ptcounter_init(scrub_nproc(ctx)); + if (!ictx.icount) { + str_error(ctx, ctx->mntpoint, _("Could not create counter.")); + return false; + } + + ret = xfs_scan_all_inodes(ctx, xfs_scrub_inode, &ictx); + if (!ret) + ictx.moveon = false; + if (!ictx.moveon) + goto free; + xfs_scrub_report_preen_triggers(ctx); + ctx->inodes_checked = ptcounter_value(ictx.icount); + +free: + ptcounter_free(ictx.icount); + return ictx.moveon; +} diff --git a/scrub/xfs_scrub.c b/scrub/xfs_scrub.c index 4c32dd7..be809fc 100644 --- a/scrub/xfs_scrub.c +++ b/scrub/xfs_scrub.c @@ -372,6 +372,7 @@ run_scrub_phases( }, { .descr = _("Scan all inodes."), + .fn = xfs_scan_inodes, }, { .descr = _("Defer filesystem repairs."), diff --git a/scrub/xfs_scrub.h b/scrub/xfs_scrub.h index 7802101..462b590 100644 --- a/scrub/xfs_scrub.h +++ b/scrub/xfs_scrub.h @@ -86,6 +86,7 @@ struct scrub_ctx { unsigned long long runtime_errors; unsigned long long errors_found; unsigned long long warnings_found; + unsigned long long inodes_checked; bool need_repair; bool preen_triggers[XFS_SCRUB_TYPE_NR]; }; @@ -95,5 +96,6 @@ void xfs_shutdown_fs(struct scrub_ctx *ctx); bool xfs_cleanup_fs(struct scrub_ctx *ctx); bool xfs_setup_fs(struct scrub_ctx *ctx); bool xfs_scan_metadata(struct scrub_ctx *ctx); +bool xfs_scan_inodes(struct scrub_ctx *ctx); #endif /* XFS_SCRUB_XFS_SCRUB_H_ */