From patchwork Sat Jan 21 08:08:36 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Dave Chinner X-Patchwork-Id: 9530049 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 7D92F600CA for ; Sat, 21 Jan 2017 08:08:45 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 6A6012842E for ; Sat, 21 Jan 2017 08:08:45 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 5DC5628620; Sat, 21 Jan 2017 08:08:45 +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 CB1F92842E for ; Sat, 21 Jan 2017 08:08:44 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751263AbdAUIIo (ORCPT ); Sat, 21 Jan 2017 03:08:44 -0500 Received: from aserp1040.oracle.com ([141.146.126.69]:20489 "EHLO aserp1040.oracle.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751169AbdAUIIn (ORCPT ); Sat, 21 Jan 2017 03:08:43 -0500 Received: from userv0021.oracle.com (userv0021.oracle.com [156.151.31.71]) by aserp1040.oracle.com (Sentrion-MTA-4.3.2/Sentrion-MTA-4.3.2) with ESMTP id v0L88evK017128 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Sat, 21 Jan 2017 08:08:41 GMT Received: from userv0121.oracle.com (userv0121.oracle.com [156.151.31.72]) by userv0021.oracle.com (8.14.4/8.14.4) with ESMTP id v0L88e0Y021554 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Sat, 21 Jan 2017 08:08:40 GMT Received: from abhmp0007.oracle.com (abhmp0007.oracle.com [141.146.116.13]) by userv0121.oracle.com (8.14.4/8.13.8) with ESMTP id v0L88dmP026711; Sat, 21 Jan 2017 08:08:40 GMT Received: from localhost (/24.21.211.40) by default (Oracle Beehive Gateway v4.0) with ESMTP ; Sat, 21 Jan 2017 00:08:39 -0800 Subject: [PATCH 05/17] spaceman: AG state control From: Dave Chinner 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:08:36 -0800 Message-ID: <148498611676.16675.16955329166090889514.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: userv0021.oracle.com [156.151.31.71] 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 Add support for a new allocation group state control ioctl. This allows control of various AG parameters, such as whether inode allocation is allowed in the AG, metadata preference, whether new allocations are allowed, etc. This requires a new ioctl. Signed-off-by: Dave Chinner --- spaceman/Makefile | 2 spaceman/ag.c | 221 +++++++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 222 insertions(+), 1 deletion(-) create mode 100644 spaceman/ag.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/spaceman/Makefile b/spaceman/Makefile index b1f1136..08709b3 100644 --- a/spaceman/Makefile +++ b/spaceman/Makefile @@ -8,7 +8,7 @@ include $(TOPDIR)/include/builddefs LTCOMMAND = xfs_spaceman HFILES = init.h space.h CFILES = init.c \ - file.c prealloc.c trim.c + ag.c file.c prealloc.c trim.c LLDLIBS = $(LIBXCMD) LTDEPENDENCIES = $(LIBXCMD) diff --git a/spaceman/ag.c b/spaceman/ag.c new file mode 100644 index 0000000..567fe7a --- /dev/null +++ b/spaceman/ag.c @@ -0,0 +1,221 @@ +/* + * Copyright (c) 2012 Red Hat, Inc. + * All Rights Reserved. + * + * 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 "libxfs.h" +#include +#include "command.h" +#include "input.h" +#include "init.h" +#include "space.h" + +#ifndef XFS_IOC_AGCONTROL +#define XFS_IOC_AGCONTROL _IOWR ('X', 60, struct xfs_agcontrol) + +#define XFS_AGCONTROL_VERSION 1 +struct xfs_agcontrol { + __u32 version; + __u32 flags; + __u32 agno; + __u32 state; + __u64 pad[8]; +}; + +/* control flags */ +#define XFS_AGCONTROL_GETAGFSTATE (1 << 0) /* get AGF state */ +#define XFS_AGCONTROL_SETAGFSTATE (1 << 1) /* set AGF state */ +#define XFS_AGCONTROL_GETAGISTATE (1 << 2) /* get AGI state */ +#define XFS_AGCONTROL_SETAGISTATE (1 << 3) /* set AGI state */ + +/* state flags */ + +/* + * inode and allocation states are split. AGF and AGI online state will move in + * sync as it is really a whole AG state. No allocation flags imply no new + * allocations, but inodes and extents can be removed. Readonly means no + * modification (alloc or free) is allowed. This is to allow different + * operations to be performed. e.g. emptying an AG in preparation for a shrink + * require NOALLOC state, but an AG that has a corrupted freespace btree might + * be switched to READONLY until the freespace tree is rebuilt. An AGF/AGI in + * this corrupt/ro state will set the relevant corruption flag in the state + * field.... + */ +#define XFS_AGFSTATE_ONLINE (1 << 0) /* AGF online */ +#define XFS_AGFSTATE_NOALLOC (1 << 1) /* No new allocation */ +#define XFS_AGFSTATE_READONLY (1 << 2) /* AGF is immutable */ +#define XFS_AGFSTATE_METADATA (1 << 3) /* metadata preferred */ +#define XFS_AGFSTATE_CORRUPT_BNO (1 << 4) /* bno freespace corrupt */ +#define XFS_AGFSTATE_CORRUPT_CNT (1 << 5) /* cnt freespace corrupt */ +#define XFS_AGFSTATE_CORRUPT_AGFL (1 << 6) /* AGFL freespace corrupt */ + +#define XFS_AGISTATE_ONLINE (1 << 0) /* AGI online */ +#define XFS_AGISTATE_NOALLOC (1 << 1) /* No new allocation */ +#define XFS_AGISTATE_READONLY (1 << 2) /* AGI is immutable */ +#define XFS_AGISTATE_CORRUPT_TREE (1 << 2) /* AGI btree corrupt */ + +#endif + +static cmdinfo_t agfctl_cmd; +static cmdinfo_t agictl_cmd; + +static int +agfctl_f( + int argc, + char **argv) +{ + struct xfs_agcontrol agctl = {0}; + xfs_agnumber_t agno; + int gflag = 0; + int c; + + while ((c = getopt(argc, argv, "gs")) != EOF) { + switch (c) { + case 'g': + gflag = 1; + break; + default: + return command_usage(&agfctl_cmd); + } + } + if (optind != argc - 1) + return command_usage(&agfctl_cmd); + + agno = atoi(argv[optind]); + if (agno >= file->geom.agcount) { + fprintf(stderr, _("%s: agno %d out of range (max %d)\n"), + progname, agno, file->geom.agcount); + exitcode = 1; + return 0; + } + + agctl.version = XFS_AGCONTROL_VERSION; + agctl.agno = agno; + if (gflag) + agctl.flags = XFS_AGCONTROL_GETAGFSTATE; + + if (xfsctl(file->name, file->fd, XFS_IOC_AGCONTROL, &agctl) < 0) { + fprintf(stderr, _("%s: XFS_IOC_AGCONTROL on %s: %s\n"), + progname, file->name, strerror(errno)); + } + return 0; +} + +static void +agfctl_help(void) +{ + printf(_( +"\n" +"AGF state control\n" +"\n" +"Options: [-g] agno\n" +"\n" +" -g -- get state\n" +" agno -- AG to operate on\n" +"\n")); + +} + +void +agfctl_init(void) +{ + agfctl_cmd.name = "agfctl"; + agfctl_cmd.altname = "agfctl"; + agfctl_cmd.cfunc = agfctl_f; + agfctl_cmd.argmin = 2; + agfctl_cmd.argmax = -1; + agfctl_cmd.args = "agno\n"; + agfctl_cmd.flags = CMD_FLAG_ONESHOT; + agfctl_cmd.oneline = _("AGF state control"); + agfctl_cmd.help = agfctl_help; + + add_command(&agfctl_cmd); +} + +static int +agictl_f( + int argc, + char **argv) +{ + struct xfs_agcontrol agctl = {0}; + xfs_agnumber_t agno; + int gflag = 0; + int c; + + while ((c = getopt(argc, argv, "gs")) != EOF) { + switch (c) { + case 'g': + gflag = 1; + break; + default: + return command_usage(&agictl_cmd); + } + } + if (optind != argc - 1) + return command_usage(&agictl_cmd); + + agno = atoi(argv[optind]); + if (agno >= file->geom.agcount) { + fprintf(stderr, _("%s: agno %d out of range (max %d)\n"), + progname, agno, file->geom.agcount); + exitcode = 1; + return 0; + } + + agctl.version = XFS_AGCONTROL_VERSION; + agctl.agno = agno; + if (gflag) + agctl.flags = XFS_AGCONTROL_GETAGISTATE; + + if (xfsctl(file->name, file->fd, XFS_IOC_AGCONTROL, &agctl) < 0) { + fprintf(stderr, _("%s: XFS_IOC_AGCONTROL on %s: %s\n"), + progname, file->name, strerror(errno)); + exitcode = 1; + return 0; + } + return 0; +} + +static void +agictl_help(void) +{ + printf(_( +"\n" +"AGI state control\n" +"\n" +"Options: [-g] agno\n" +"\n" +" -g -- get state\n" +" agno -- AG to operate on\n" +"\n")); + +} + +void +agictl_init(void) +{ + agictl_cmd.name = "agictl"; + agictl_cmd.altname = "agictl"; + agictl_cmd.cfunc = agictl_f; + agictl_cmd.argmin = 2; + agictl_cmd.argmax = -1; + agictl_cmd.args = "agno\n"; + agictl_cmd.flags = CMD_FLAG_ONESHOT; + agictl_cmd.oneline = _("AGI state control"); + agictl_cmd.help = agictl_help; + + add_command(&agictl_cmd); +}