From patchwork Thu Aug 25 23:57:46 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Darrick J. Wong" X-Patchwork-Id: 9300643 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 1392F607D8 for ; Thu, 25 Aug 2016 23:58:20 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 03C2729412 for ; Thu, 25 Aug 2016 23:58:20 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id EB27B29415; Thu, 25 Aug 2016 23:58:19 +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=-4.2 required=2.0 tests=BAYES_00, RCVD_IN_DNSWL_MED, UNPARSEABLE_RELAY autolearn=ham version=3.3.1 Received: from oss.sgi.com (oss.sgi.com [192.48.182.195]) (using TLSv1 with cipher DHE-RSA-CAMELLIA256-SHA (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id C5D1129412 for ; Thu, 25 Aug 2016 23:58:18 +0000 (UTC) Received: from oss.sgi.com (localhost [IPv6:::1]) by oss.sgi.com (Postfix) with ESMTP id 3EB8E83A9; Thu, 25 Aug 2016 18:57:55 -0500 (CDT) X-Original-To: xfs@oss.sgi.com Delivered-To: xfs@oss.sgi.com Received: from relay.sgi.com (relay1.corp.sgi.com [137.38.102.111]) by oss.sgi.com (Postfix) with ESMTP id 5656983A6 for ; Thu, 25 Aug 2016 18:57:53 -0500 (CDT) Received: from cuda.sgi.com (cuda2.sgi.com [192.48.176.25]) by relay1.corp.sgi.com (Postfix) with ESMTP id 19D088F8033 for ; Thu, 25 Aug 2016 16:57:53 -0700 (PDT) X-ASG-Debug-ID: 1472169470-0bf57b5311209e50001-NocioJ Received: from aserp1040.oracle.com (aserp1040.oracle.com [141.146.126.69]) by cuda.sgi.com with ESMTP id mVRwCexNP2hLZsyT (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NO) for ; Thu, 25 Aug 2016 16:57:50 -0700 (PDT) X-Barracuda-Envelope-From: darrick.wong@oracle.com X-Barracuda-Effective-Source-IP: aserp1040.oracle.com[141.146.126.69] X-Barracuda-Apparent-Source-IP: 141.146.126.69 Received: from userv0022.oracle.com (userv0022.oracle.com [156.151.31.74]) by aserp1040.oracle.com (Sentrion-MTA-4.3.2/Sentrion-MTA-4.3.2) with ESMTP id u7PNvmHY030438 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Thu, 25 Aug 2016 23:57:48 GMT Received: from userv0122.oracle.com (userv0122.oracle.com [156.151.31.75]) by userv0022.oracle.com (8.14.4/8.13.8) with ESMTP id u7PNvmQh014720 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Thu, 25 Aug 2016 23:57:48 GMT Received: from abhmp0017.oracle.com (abhmp0017.oracle.com [141.146.116.23]) by userv0122.oracle.com (8.14.4/8.14.4) with ESMTP id u7PNvl4g025463; Thu, 25 Aug 2016 23:57:47 GMT Received: from localhost (/10.145.178.207) by default (Oracle Beehive Gateway v4.0) with ESMTP ; Thu, 25 Aug 2016 16:57:47 -0700 Subject: [PATCH 23/24] xfs_io: provide an interface to the scrub ioctls From: "Darrick J. Wong" X-ASG-Orig-Subj: [PATCH 23/24] xfs_io: provide an interface to the scrub ioctls To: david@fromorbit.com, darrick.wong@oracle.com Date: Thu, 25 Aug 2016 16:57:46 -0700 Message-ID: <147216946601.6398.16187695052276931699.stgit@birch.djwong.org> In-Reply-To: <147216931783.6398.1716678878794493264.stgit@birch.djwong.org> References: <147216931783.6398.1716678878794493264.stgit@birch.djwong.org> User-Agent: StGit/0.17.1-dirty MIME-Version: 1.0 X-Source-IP: userv0022.oracle.com [156.151.31.74] X-Barracuda-Connect: aserp1040.oracle.com[141.146.126.69] X-Barracuda-Start-Time: 1472169470 X-Barracuda-Encrypted: ECDHE-RSA-AES256-GCM-SHA384 X-Barracuda-URL: https://192.48.176.25:443/cgi-mod/mark.cgi X-Barracuda-Scan-Msg-Size: 6287 X-Virus-Scanned: by bsmtpd at sgi.com X-Barracuda-BRTS-Status: 1 X-Barracuda-Spam-Score: 0.50 X-Barracuda-Spam-Status: No, SCORE=0.50 using per-user scores of TAG_LEVEL=1000.0 QUARANTINE_LEVEL=1000.0 KILL_LEVEL=2.7 tests=BSF_SC0_MISMATCH_TO, BSF_SC0_MV0713, UNPARSEABLE_RELAY X-Barracuda-Spam-Report: Code version 3.2, rules version 3.2.3.32328 Rule breakdown below pts rule name description ---- ---------------------- -------------------------------------------------- 0.00 BSF_SC0_MISMATCH_TO Envelope rcpt doesn't match header 0.00 UNPARSEABLE_RELAY Informational: message has unparseable relay lines 0.50 BSF_SC0_MV0713 Custom rule MV0713 Cc: linux-xfs@vger.kernel.org, xfs@oss.sgi.com X-BeenThere: xfs@oss.sgi.com X-Mailman-Version: 2.1.14 Precedence: list List-Id: XFS Filesystem from SGI List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: xfs-bounces@oss.sgi.com Sender: xfs-bounces@oss.sgi.com 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 | 1 io/io.h | 2 + io/scrub.c | 174 +++++++++++++++++++++++++++++++++++++++++++++++++++++ man/man8/xfs_io.8 | 8 ++ 5 files changed, 186 insertions(+), 1 deletion(-) create mode 100644 io/scrub.c diff --git a/io/Makefile b/io/Makefile index cc27dba..c430418 100644 --- a/io/Makefile +++ b/io/Makefile @@ -11,7 +11,7 @@ HFILES = init.h io.h CFILES = init.c \ attr.c bmap.c file.c freeze.c fsync.c getrusage.c imap.c link.c \ mmap.c open.c parent.c pread.c prealloc.c pwrite.c seek.c shutdown.c \ - sync.c truncate.c reflink.c fsmap.c + sync.c truncate.c reflink.c fsmap.c scrub.c LLDLIBS = $(LIBXCMD) $(LIBHANDLE) LTDEPENDENCIES = $(LIBXCMD) $(LIBHANDLE) diff --git a/io/init.c b/io/init.c index 9c0da0e..c16bc69 100644 --- a/io/init.c +++ b/io/init.c @@ -87,6 +87,7 @@ init_commands(void) truncate_init(); reflink_init(); cowextsize_init(); + scrub_init(); } static int diff --git a/io/io.h b/io/io.h index 83a8366..10be081 100644 --- a/io/io.h +++ b/io/io.h @@ -176,3 +176,5 @@ extern void cowextsize_init(void); #else #define cowextsize_init() do { } while (0) #endif + +extern void scrub_init(void); diff --git a/io/scrub.c b/io/scrub.c new file mode 100644 index 0000000..8b93121 --- /dev/null +++ b/io/scrub.c @@ -0,0 +1,174 @@ +/* + * Copyright (C) 2016 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 "io.h" + +static cmdinfo_t scrub_cmd; + +/* These must correspond with XFS_SCRUB_TYPE_ */ +struct scrub_descr { + const char *name; + bool is_ag; +}; + +static const struct scrub_descr scrubbers[] = { + {"sb", true}, + {"agf", true}, + {"agfl", true}, + {"agi", true}, + {"bnobt", true}, + {"cntbt", true}, + {"inobt", true}, + {"finobt", true}, + {"rmapbt", true}, + {"refcountbt", true}, + {"inode", false}, + {"bmapbtd", false}, + {"bmapbta", false}, + {"bmapbtc", false}, + {"rtbitmap", false}, + {"rtsummary", false}, + {NULL, false}, +}; + +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 5 7' - scrubs the inode btree in groups 3, 5, and 7.\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, + unsigned long long control) +{ + struct xfs_scrub_metadata meta; + int error; + + memset(&meta, 0, sizeof(meta)); + meta.type = type; + meta.control = control; + + error = ioctl(fd, XFS_IOC_SCRUB_METADATA, &meta); + if (error) + perror("scrub"); +} + +static int +scrub_f( + int argc, + char **argv) +{ + char *p; + int type = -1; + int i, c; + unsigned long long control; + bool is_ag; + struct xfs_fsop_geom geom; + const struct scrub_descr *d; + + while ((c = getopt(argc, argv, "")) != EOF) { + switch (c) { + default: + return command_usage(&scrub_cmd); + } + } + if (optind > argc - 1) + return command_usage(&scrub_cmd); + + for (i = 0, d = scrubbers; d->name; i++, d++) { + if (strcmp(d->name, argv[optind]) == 0) { + type = i; + is_ag = d->is_ag; + } + } + optind++; + + if (type < 0) + return command_usage(&scrub_cmd); + + if (!is_ag) + geom.agcount = 1; + else { + i = xfsctl(file->name, file->fd, XFS_IOC_FSGEOMETRY_V1, &geom); + if (i < 0) { + fprintf(stderr, + _("%s: can't get geometry [\"%s\"]: %s\n"), + progname, file->name, strerror(errno)); + exitcode = 1; + return 0; + } + } + + if (optind == argc) { + for (control = 0; control < geom.agcount; control++) + scrub_ioctl(file->fd, type, control); + return 0; + } + + for (i = optind; i < argc; i++) { + control = strtoull(argv[i], &p, 0); + if (*p != '\0') { + fprintf(stderr, + _("bad control number %s\n"), argv[i]); + return 0; + } + + scrub_ioctl(file->fd, type, control); + } + return 0; +} + +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); +} diff --git a/man/man8/xfs_io.8 b/man/man8/xfs_io.8 index a275a63..884db2a 100644 --- a/man/man8/xfs_io.8 +++ b/man/man8/xfs_io.8 @@ -926,6 +926,14 @@ verbose output will be printed. .IP .B [NOTE: Not currently operational on Linux.] .PD +.TP +.BI "scrub " type " [ " agnumber... " ]" +Scrub internal XFS filesystem metadata. The +.BI type +parameter specifies which type of metadata to scrub. +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. .SH SEE ALSO .BR mkfs.xfs (8),