From patchwork Sat Jan 21 08:09:29 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: 9530077 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 CA0DA600CA for ; Sat, 21 Jan 2017 08:09:38 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id B84752842E for ; Sat, 21 Jan 2017 08:09:38 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id AD2DC28695; Sat, 21 Jan 2017 08:09:38 +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=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 B13172842E for ; Sat, 21 Jan 2017 08:09:37 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751288AbdAUIJh (ORCPT ); Sat, 21 Jan 2017 03:09:37 -0500 Received: from userp1040.oracle.com ([156.151.31.81]:26073 "EHLO userp1040.oracle.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751050AbdAUIJg (ORCPT ); Sat, 21 Jan 2017 03:09:36 -0500 Received: from aserv0021.oracle.com (aserv0021.oracle.com [141.146.126.233]) by userp1040.oracle.com (Sentrion-MTA-4.3.2/Sentrion-MTA-4.3.2) with ESMTP id v0L89XUL024685 (version=TLSv1 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK); Sat, 21 Jan 2017 08:09:33 GMT Received: from aserv0121.oracle.com (aserv0121.oracle.com [141.146.126.235]) by aserv0021.oracle.com (8.13.8/8.14.4) with ESMTP id v0L89W2U026477 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK); Sat, 21 Jan 2017 08:09:33 GMT Received: from abhmp0014.oracle.com (abhmp0014.oracle.com [141.146.116.20]) by aserv0121.oracle.com (8.13.8/8.13.8) with ESMTP id v0L89Ucg004035; Sat, 21 Jan 2017 08:09:31 GMT Received: from localhost (/24.21.211.40) by default (Oracle Beehive Gateway v4.0) with ESMTP ; Sat, 21 Jan 2017 00:09:30 -0800 Subject: [PATCH 12/17] xfs_io: provide an interface to the scrub ioctls From: "Darrick J. Wong" To: sandeen@redhat.com, darrick.wong@oracle.com Cc: linux-xfs@vger.kernel.org, linux-fsdevel@vger.kernel.org Date: Sat, 21 Jan 2017 00:09:29 -0800 Message-ID: <148498616931.16675.3359362451280245733.stgit@birch.djwong.org> In-Reply-To: <148498608472.16675.14848042961636871812.stgit@birch.djwong.org> References: <148498608472.16675.14848042961636871812.stgit@birch.djwong.org> User-Agent: StGit/0.17.1-dirty MIME-Version: 1.0 X-Source-IP: aserv0021.oracle.com [141.146.126.233] 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 Create a new xfs_io command to call the new XFS metadata scrub ioctl. Signed-off-by: Darrick J. Wong --- io/Makefile | 2 io/init.c | 2 io/inject.c | 4 - io/io.h | 2 io/scrub.c | 330 +++++++++++++++++++++++++++++++++++++++++++++++++++++ man/man8/xfs_io.8 | 20 +++ 6 files changed, 358 insertions(+), 2 deletions(-) create mode 100644 io/scrub.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/io/Makefile b/io/Makefile index fd07596..383f5cb 100644 --- a/io/Makefile +++ b/io/Makefile @@ -11,7 +11,7 @@ HFILES = init.h io.h CFILES = init.c \ attr.c bmap.c cowextsize.c encrypt.c file.c freeze.c fsmap.c fsync.c \ getrusage.c imap.c link.c mmap.c open.c parent.c pread.c prealloc.c \ - pwrite.c reflink.c seek.c shutdown.c sync.c truncate.c utimes.c + pwrite.c reflink.c scrub.c seek.c shutdown.c sync.c truncate.c utimes.c LLDLIBS = $(LIBXCMD) $(LIBHANDLE) $(LIBPTHREAD) LTDEPENDENCIES = $(LIBXCMD) $(LIBHANDLE) diff --git a/io/init.c b/io/init.c index 1532149..bef6f62 100644 --- a/io/init.c +++ b/io/init.c @@ -83,7 +83,9 @@ init_commands(void) quit_init(); readdir_init(); reflink_init(); + repair_init(); resblks_init(); + scrub_init(); seek_init(); sendfile_init(); shutdown_init(); diff --git a/io/inject.c b/io/inject.c index 25c7021..91b5fd7 100644 --- a/io/inject.c +++ b/io/inject.c @@ -86,7 +86,9 @@ error_tag(char *name) { XFS_ERRTAG_BMAP_FINISH_ONE, "bmap_finish_one" }, #define XFS_ERRTAG_AG_RESV_CRITICAL 27 { XFS_ERRTAG_AG_RESV_CRITICAL, "ag_resv_critical" }, -#define XFS_ERRTAG_MAX 28 +#define XFS_ERRTAG_FORCE_REPAIR 28 + { XFS_ERRTAG_FORCE_REPAIR, "force_repair" }, +#define XFS_ERRTAG_MAX 29 { XFS_ERRTAG_MAX, NULL } }; int count; diff --git a/io/io.h b/io/io.h index c7100c9..3dd6296 100644 --- a/io/io.h +++ b/io/io.h @@ -178,3 +178,5 @@ extern void readdir_init(void); extern void reflink_init(void); extern void cowextsize_init(void); +extern void scrub_init(void); +extern void repair_init(void); diff --git a/io/scrub.c b/io/scrub.c new file mode 100644 index 0000000..caa965e --- /dev/null +++ b/io/scrub.c @@ -0,0 +1,330 @@ +/* + * Copyright (C) 2017 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. + * + * 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 "command.h" +#include "input.h" +#include "init.h" +#include "path.h" +#include "io.h" + +static struct cmdinfo scrub_cmd; +static struct cmdinfo repair_cmd; + +/* Type info and names for the scrub types. */ +enum scrub_type { + ST_NONE, /* disabled */ + ST_PERAG, /* per-AG metadata */ + ST_FS, /* per-FS metadata */ + ST_INODE, /* per-inode metadata */ +}; + +/* These must correspond with XFS_SCRUB_TYPE_ */ +struct scrub_descr { + const char *name; + enum scrub_type type; +}; + +static const struct scrub_descr scrubbers[] = { + {"dummy", ST_NONE}, + {"sb", ST_PERAG}, + {"agf", ST_PERAG}, + {"agfl", ST_PERAG}, + {"agi", ST_PERAG}, + {"bnobt", ST_PERAG}, + {"cntbt", ST_PERAG}, + {"inobt", ST_PERAG}, + {"finobt", ST_PERAG}, + {"rmapbt", ST_PERAG}, + {"refcountbt", ST_PERAG}, + {"inode", ST_INODE}, + {"bmapbtd", ST_INODE}, + {"bmapbta", ST_INODE}, + {"bmapbtc", ST_INODE}, + {"directory", ST_INODE}, + {"xattr", ST_INODE}, + {"symlink", ST_INODE}, + {"rtbitmap", ST_FS}, + {"rtsummary", ST_FS}, + {NULL, ST_NONE}, +}; + +static void +scrub_help(void) +{ + const struct scrub_descr *d; + + printf(_("\n\ + Scrubs a piece of XFS filesystem metadata. The first argument is the type\n\ + of metadata to examine. Allocation group number(s) can be specified to\n\ + restrict the scrub operation to a subset of allocation groups.\n\ + Certain metadata types do not take AG numbers.\n\ +\n\ + Example:\n\ + 'scrub inobt 3' - scrub the inode btree in AG 3.\n\ + 'scrub bmapbtd 128 13525' - scrubs the extent map of inode 128 gen 13525.\n\ +\n\ + Known metadata scrub types are:")); + for (d = scrubbers; d->name; d++) + printf(" %s", d->name); + printf("\n"); +} + +static void +scrub_ioctl( + int fd, + int type, + uint64_t control, + uint32_t control2) +{ + struct xfs_scrub_metadata meta; + const struct scrub_descr *sc; + int error; + + sc = &scrubbers[type]; + memset(&meta, 0, sizeof(meta)); + meta.sm_type = type; + switch (sc->type) { + case ST_PERAG: + meta.sm_agno = control; + break; + case ST_INODE: + meta.sm_ino = control; + meta.sm_gen = control2; + break; + case ST_NONE: + case ST_FS: + /* no control parameters */ + break; + } + meta.sm_flags = 0; + + error = ioctl(fd, XFS_IOC_SCRUB_METADATA, &meta); + if (error) + perror("scrub"); + if (meta.sm_flags & XFS_SCRUB_FLAG_CORRUPT) + printf(_("Corruption detected.\n")); + if (meta.sm_flags & XFS_SCRUB_FLAG_PREEN) + printf(_("Optimization possible.\n")); + if (meta.sm_flags & XFS_SCRUB_FLAG_XFAIL) + printf(_("Cross-referencing failed.\n")); + if (meta.sm_flags & XFS_SCRUB_FLAG_XCORRUPT) + printf(_("Corruption detected during cross-referencing.\n")); +} + +static int +parse_args( + int argc, + char **argv, + struct cmdinfo *cmdinfo, + void (*fn)(int, int, uint64_t, uint32_t)) +{ + char *p; + int type = -1; + int i, c; + uint64_t control = 0; + uint32_t control2 = 0; + const struct scrub_descr *d = NULL; + + while ((c = getopt(argc, argv, "")) != EOF) { + switch (c) { + default: + return command_usage(cmdinfo); + } + } + if (optind > argc - 1) + return command_usage(cmdinfo); + + for (i = 0, d = scrubbers; d->name; i++, d++) { + if (strcmp(d->name, argv[optind]) == 0) { + type = i; + break; + } + } + optind++; + + if (type < 0) + return command_usage(cmdinfo); + + switch (d->type) { + case ST_INODE: + if (optind == argc) { + control = 0; + control2 = 0; + } else if (optind == argc - 2) { + control = strtoull(argv[optind], &p, 0); + if (*p != '\0') { + fprintf(stderr, + _("Bad inode number %s.\n"), argv[i]); + return 0; + } + control2 = strtoul(argv[optind + 1], &p, 0); + if (*p != '\0') { + fprintf(stderr, + _("Bad generation number %s.\n"), argv[i]); + return 0; + } + } else { + fprintf(stderr, + _("Must specify inode number and generation.\n")); + return 0; + } + break; + case ST_PERAG: + case ST_NONE: + if (optind != argc - 1) { + fprintf(stderr, + _("Must specify AG number.\n")); + return 0; + } + control = strtoul(argv[optind], &p, 0); + if (*p != '\0') { + fprintf(stderr, + _("Bad AG number %s.\n"), argv[i]); + return 0; + } + break; + default: + if (optind != argc) { + fprintf(stderr, + _("No parameters allowed.\n")); + return 0; + } + } + fn(file->fd, type, control, control2); + + return 0; +} + +static int +scrub_f( + int argc, + char **argv) +{ + return parse_args(argc, argv, &scrub_cmd, scrub_ioctl); +} + +void +scrub_init(void) +{ + scrub_cmd.name = "scrub"; + scrub_cmd.altname = "sc"; + scrub_cmd.cfunc = scrub_f; + scrub_cmd.argmin = 1; + scrub_cmd.argmax = -1; + scrub_cmd.flags = CMD_NOMAP_OK; + scrub_cmd.args = +_("type [agno...]"); + scrub_cmd.oneline = + _("scrubs filesystem metadata"); + scrub_cmd.help = scrub_help; + + add_command(&scrub_cmd); +} + +static void +repair_help(void) +{ + const struct scrub_descr *d; + + printf(_("\n\ + Repairs a piece of XFS filesystem metadata. The first argument is the type\n\ + of metadata to examine. Allocation group number(s) can be specified to\n\ + restrict the scrub operation to a subset of allocation groups.\n\ + Certain metadata types do not take AG numbers.\n\ +\n\ + Example:\n\ + 'repair inobt 3 5 7' - repairs the inode btree in groups 3, 5, and 7.\n\ +\n\ + Known metadata repairs types are:")); + for (d = scrubbers; d->name; d++) + printf(" %s", d->name); + printf("\n"); +} + +static void +repair_ioctl( + int fd, + int type, + uint64_t control, + uint32_t control2) +{ + struct xfs_scrub_metadata meta; + const struct scrub_descr *sc; + int error; + + sc = &scrubbers[type]; + memset(&meta, 0, sizeof(meta)); + meta.sm_type = type; + switch (sc->type) { + case ST_PERAG: + meta.sm_agno = control; + break; + case ST_INODE: + meta.sm_ino = control; + meta.sm_gen = control2; + break; + case ST_NONE: + case ST_FS: + /* no control parameters */ + break; + } + meta.sm_flags = XFS_SCRUB_FLAG_REPAIR; + + error = ioctl(fd, XFS_IOC_SCRUB_METADATA, &meta); + if (error) + perror("scrub"); + if (meta.sm_flags & XFS_SCRUB_FLAG_CORRUPT) + printf(_("Corruption remains.\n")); + if (meta.sm_flags & XFS_SCRUB_FLAG_PREEN) + printf(_("Optimization possible.\n")); + if (meta.sm_flags & XFS_SCRUB_FLAG_XFAIL) + printf(_("Cross-referencing failed.\n")); + if (meta.sm_flags & XFS_SCRUB_FLAG_XCORRUPT) + printf(_("Corruption still detected during cross-referencing.\n")); +} + +static int +repair_f( + int argc, + char **argv) +{ + return parse_args(argc, argv, &repair_cmd, repair_ioctl); +} + +void +repair_init(void) +{ + if (!expert) + return; + repair_cmd.name = "repair"; + repair_cmd.altname = "fix"; + repair_cmd.cfunc = repair_f; + repair_cmd.argmin = 1; + repair_cmd.argmax = -1; + repair_cmd.flags = CMD_NOMAP_OK; + repair_cmd.args = +_("type [agno...]"); + repair_cmd.oneline = + _("repairs filesystem metadata"); + repair_cmd.help = repair_help; + + add_command(&repair_cmd); +} diff --git a/man/man8/xfs_io.8 b/man/man8/xfs_io.8 index 479c39b..64f66b9 100644 --- a/man/man8/xfs_io.8 +++ b/man/man8/xfs_io.8 @@ -998,6 +998,26 @@ version of policy structure (numeric) .BR get_encpolicy On filesystems that support encryption, display the encryption policy of the current file. +.TP +.BI "scrub " type " [ " agnumber... " | " "ino" " " "gen" " ]" +Scrub internal XFS filesystem metadata. The +.BI type +parameter specifies which type of metadata to scrub. +For AG metadata, AG numbers can optionally be specified to restrict the +scrub operation to a particular set of allocation groups. +By default, all allocation groups are scrubbed. +For file metadata, the scrub is applied to the open file unless the +inode number and generation number are specified. +.TP +.BI "repair " type " [ " agnumber... " | " "ino" " " "gen" " ]" +Repair internal XFS filesystem metadata. The +.BI type +parameter specifies which type of metadata to repair. +For AG metadata, AG numbers can optionally be specified to restrict the +repair operation to a particular set of allocation groups. +By default, all allocation groups are repaired. +For file metadata, the repair is applied to the open file unless the +inode number and generation number are specified. .SH SEE ALSO .BR mkfs.xfs (8),