* [PATCH 1/2] xfsprogs: Introduce a new subcommand agstate to xfs_fio
@ 2012-11-16 6:51 Jeff Liu
2012-11-17 2:02 ` Dave Chinner
0 siblings, 1 reply; 4+ messages in thread
From: Jeff Liu @ 2012-11-16 6:51 UTC (permalink / raw)
To: xfs
Introduce a new xfs_io command: agstate.
This command is used to get/set state for a given allocation group.
Signed-off-by: Jie Liu <jeff.liu@oracle.com>
---
include/xfs_ag.h | 32 ++++++++++++++++++++++++++++----
include/xfs_fs.h | 2 ++
io/Makefile | 2 +-
io/init.c | 1 +
4 files changed, 32 insertions(+), 5 deletions(-)
diff --git a/include/xfs_ag.h b/include/xfs_ag.h
index 5adce91..bd5f4d4 100644
--- a/include/xfs_ag.h
+++ b/include/xfs_ag.h
@@ -69,6 +69,10 @@ typedef struct xfs_agf {
__be32 agf_freeblks; /* total free blocks */
__be32 agf_longest; /* longest free space */
__be32 agf_btreeblks; /* # of blocks held in AGF btrees */
+ /*
+ * state
+ */
+ __be32 agf_state; /* persistent a.g. state */
} xfs_agf_t;
#define XFS_AGF_MAGICNUM 0x00000001
@@ -83,7 +87,8 @@ typedef struct xfs_agf {
#define XFS_AGF_FREEBLKS 0x00000200
#define XFS_AGF_LONGEST 0x00000400
#define XFS_AGF_BTREEBLKS 0x00000800
-#define XFS_AGF_NUM_BITS 12
+#define XFS_AGF_STATE 0x00001000
+#define XFS_AGF_NUM_BITS 13
#define XFS_AGF_ALL_BITS ((1 << XFS_AGF_NUM_BITS) - 1)
#define XFS_AGF_FLAGS \
@@ -98,7 +103,8 @@ typedef struct xfs_agf {
{ XFS_AGF_FLCOUNT, "FLCOUNT" }, \
{ XFS_AGF_FREEBLKS, "FREEBLKS" }, \
{ XFS_AGF_LONGEST, "LONGEST" }, \
- { XFS_AGF_BTREEBLKS, "BTREEBLKS" }
+ { XFS_AGF_BTREEBLKS, "BTREEBLKS" }, \
+ { XFS_AGF_STATE, "STATE" }
/* disk block (xfs_daddr_t) in the AG */
#define XFS_AGF_DADDR(mp) ((xfs_daddr_t)(1 << (mp)->m_sectbb_log))
@@ -184,8 +190,8 @@ typedef struct xfs_agfl {
struct xfs_busy_extent {
#ifdef __KERNEL__
struct rb_node rb_node; /* ag by-bno indexed search tree */
-#endif
struct list_head list; /* transaction busy extent list */
+#endif
xfs_agnumber_t agno;
xfs_agblock_t bno;
xfs_extlen_t length;
@@ -197,7 +203,7 @@ struct xfs_busy_extent {
* to improve the performance of allocation group selection.
*/
#define XFS_PAGB_NUM_SLOTS 128
-
+typedef int atomic_t; /* to make compiler happy */
typedef struct xfs_perag {
struct xfs_mount *pag_mount; /* owner filesystem */
xfs_agnumber_t pag_agno; /* AG this structure belongs to */
@@ -243,9 +249,27 @@ typedef struct xfs_perag {
struct rcu_head rcu_head;
#endif
int pagb_count; /* pagb slots in use */
+ __uint32_t pag_state; /* persistent a.g. state */
} xfs_perag_t;
/*
+ * Structure for ioctl per a.g. state get/set.
+ */
+typedef struct xfs_ioc_agstate {
+ xfs_agnumber_t agno;
+ __uint32_t state;
+} xfs_ioc_agstate_t;
+
+/*
+ * Skip an AG with below state for inodes/blocks allocation.
+ */
+#define XFS_AG_STATE_ALLOC_DENY (1 << 0)
+extern int xfs_get_agstate(struct xfs_mount *mp,
+ struct xfs_ioc_agstate *agstate);
+extern int xfs_set_agstate(struct xfs_mount *mp,
+ struct xfs_ioc_agstate *agstate);
+
+/*
* tags for inode radix tree
*/
#define XFS_ICI_NO_TAG (-1) /* special flag for an untagged lookup
diff --git a/include/xfs_fs.h b/include/xfs_fs.h
index faac5af..c749474 100644
--- a/include/xfs_fs.h
+++ b/include/xfs_fs.h
@@ -483,6 +483,8 @@ typedef struct xfs_handle {
#define XFS_IOC_ATTRMULTI_BY_HANDLE _IOW ('X', 123, struct xfs_fsop_attrmulti_handlereq)
#define XFS_IOC_FSGEOMETRY _IOR ('X', 124, struct xfs_fsop_geom)
#define XFS_IOC_GOINGDOWN _IOR ('X', 125, __uint32_t)
+#define XFS_IOC_SET_AGSTATE _IOW ('X', 126, struct xfs_ioc_agstate)
+#define XFS_IOC_GET_AGSTATE _IOR ('X', 127, struct xfs_ioc_agstate)
/* XFS_IOC_GETFSUUID ---------- deprecated 140 */
diff --git a/io/Makefile b/io/Makefile
index 50edf91..80a2817 100644
--- a/io/Makefile
+++ b/io/Makefile
@@ -9,7 +9,7 @@ LTCOMMAND = xfs_io
LSRCFILES = xfs_bmap.sh xfs_freeze.sh xfs_mkfile.sh
HFILES = init.h io.h
CFILES = init.c \
- attr.c bmap.c file.c freeze.c fsync.c getrusage.c imap.c mmap.c \
+ agstate.c attr.c bmap.c file.c freeze.c fsync.c getrusage.c imap.c mmap.c \
open.c parent.c pread.c prealloc.c pwrite.c shutdown.c truncate.c
LLDLIBS = $(LIBXCMD) $(LIBHANDLE)
diff --git a/io/init.c b/io/init.c
index fb93082..b81ca4f 100644
--- a/io/init.c
+++ b/io/init.c
@@ -54,6 +54,7 @@ init_cvtnum(
static void
init_commands(void)
{
+ agstate_init();
attr_init();
bmap_init();
fadvise_init();
--
1.7.9.5
_______________________________________________
xfs mailing list
xfs@oss.sgi.com
http://oss.sgi.com/mailman/listinfo/xfs
^ permalink raw reply related [flat|nested] 4+ messages in thread
* Re: [PATCH 1/2] xfsprogs: Introduce a new subcommand agstate to xfs_fio
2012-11-16 6:51 [PATCH 1/2] xfsprogs: Introduce a new subcommand agstate to xfs_fio Jeff Liu
@ 2012-11-17 2:02 ` Dave Chinner
2012-11-17 4:33 ` Jeff Liu
0 siblings, 1 reply; 4+ messages in thread
From: Dave Chinner @ 2012-11-17 2:02 UTC (permalink / raw)
To: Jeff Liu; +Cc: xfs
On Fri, Nov 16, 2012 at 02:51:04PM +0800, Jeff Liu wrote:
> Introduce a new xfs_io command: agstate.
>
> This command is used to get/set state for a given allocation group.
xfs_io is not the place for this command.
A couple of weeks ago I started writing an xfs_spaceman module and
an ioctl interface for exactly this purpose, I just hadn't got
around to completing it and the kernel patch to test it so I hadn't
posted it. Once the userspace release is out of the way, I'll post
the patches to get xfs_spaceman into xfs_progs, and we can use that
for this AG control from the start.
The reason for this is that the AG state in future is going to be a
lot more complex than just enabling/disabling allocation, and the
ioctl interface I prototyped supports a lot of that future
functionality.
The patch is below so you can see what sort of AG control/state
functionality I think we'll be needing sooner rather than later, and
the interface I think we should be using...
> Signed-off-by: Jie Liu <jeff.liu@oracle.com>
> ---
> include/xfs_ag.h | 32 ++++++++++++++++++++++++++++----
> include/xfs_fs.h | 2 ++
> io/Makefile | 2 +-
> io/init.c | 1 +
> 4 files changed, 32 insertions(+), 5 deletions(-)
FWIW, I think you forgot to include the file that introduces the
command in the patch :)
Cheers,
Dave.
--
Dave Chinner
david@fromorbit.com
spaceman: AG state control
From: Dave Chinner <dchinner@redhat.com>
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 <dchinner@redhat.com>
---
spaceman/Makefile | 2 +-
spaceman/ag.c | 221 +++++++++++++++++++++++++++++++++++++++++++++++++++++
2 files changed, 222 insertions(+), 1 deletion(-)
diff --git a/spaceman/Makefile b/spaceman/Makefile
index 4743ad8..dd19cb0 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 freesp.c prealloc.c trim.c
+ ag.c file.c freesp.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..40333c2
--- /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 <xfs/xfs.h>
+#include <xfs/xfs_types.h>
+#include <xfs/command.h>
+#include <linux/dqblk_xfs.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_GLOBAL;
+ 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_GLOBAL;
+ agictl_cmd.oneline = _("AGI state control");
+ agictl_cmd.help = agictl_help;
+
+ add_command(&agictl_cmd);
+}
_______________________________________________
xfs mailing list
xfs@oss.sgi.com
http://oss.sgi.com/mailman/listinfo/xfs
^ permalink raw reply related [flat|nested] 4+ messages in thread
* Re: [PATCH 1/2] xfsprogs: Introduce a new subcommand agstate to xfs_fio
2012-11-17 2:02 ` Dave Chinner
@ 2012-11-17 4:33 ` Jeff Liu
2012-11-17 22:59 ` Dave Chinner
0 siblings, 1 reply; 4+ messages in thread
From: Jeff Liu @ 2012-11-17 4:33 UTC (permalink / raw)
To: Dave Chinner; +Cc: xfs
On 11/17/2012 10:02 AM, Dave Chinner wrote:
> On Fri, Nov 16, 2012 at 02:51:04PM +0800, Jeff Liu wrote:
>> Introduce a new xfs_io command: agstate.
>>
>> This command is used to get/set state for a given allocation group.
>
> xfs_io is not the place for this command.
I was also wonder why we place the agflags command on there since xfs_io is aimed
at examining the regular file I/O paths, but I can not found out a better place
while implementing it.
>
> A couple of weeks ago I started writing an xfs_spaceman module and
> an ioctl interface for exactly this purpose, I just hadn't got
> around to completing it and the kernel patch to test it so I hadn't
> posted it. Once the userspace release is out of the way, I'll post
> the patches to get xfs_spaceman into xfs_progs, and we can use that
> for this AG control from the start.
>
> The reason for this is that the AG state in future is going to be a
> lot more complex than just enabling/disabling allocation, and the
> ioctl interface I prototyped supports a lot of that future
> functionality.
Definitely, so that we can have fine-granted AG controls, that's why I didn't
chose to re-base/post the previous agflags patch but proposed the agstate command
because the naming would sounds more reasonable.
>
> The patch is below so you can see what sort of AG control/state
> functionality I think we'll be needing sooner rather than later, and
> the interface I think we should be using...
Ok, I'll waiting for this feature. :)
BTW, Does it sounds make sense if we implement parent pointer support at first?
http://www.xfs.org/index.php/Unfinished_work#Parent_Pointers.2FCreate.2BEA
I propose this because it would reduce many efforts for implementing xfs_shrinkfs
command, and reduce the overhead for iterating overall file systems to find out
files which are located at offline AGs.
>
>> Signed-off-by: Jie Liu <jeff.liu@oracle.com>
>> ---
>> include/xfs_ag.h | 32 ++++++++++++++++++++++++++++----
>> include/xfs_fs.h | 2 ++
>> io/Makefile | 2 +-
>> io/init.c | 1 +
>> 4 files changed, 32 insertions(+), 5 deletions(-)
>
> FWIW, I think you forgot to include the file that introduces the
> command in the patch :)
Oops! sorry for the mistake.
Thanks,
-Jeff
_______________________________________________
xfs mailing list
xfs@oss.sgi.com
http://oss.sgi.com/mailman/listinfo/xfs
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [PATCH 1/2] xfsprogs: Introduce a new subcommand agstate to xfs_fio
2012-11-17 4:33 ` Jeff Liu
@ 2012-11-17 22:59 ` Dave Chinner
0 siblings, 0 replies; 4+ messages in thread
From: Dave Chinner @ 2012-11-17 22:59 UTC (permalink / raw)
To: Jeff Liu; +Cc: xfs
On Sat, Nov 17, 2012 at 12:33:10PM +0800, Jeff Liu wrote:
> On 11/17/2012 10:02 AM, Dave Chinner wrote:
> > On Fri, Nov 16, 2012 at 02:51:04PM +0800, Jeff Liu wrote:
> >> Introduce a new xfs_io command: agstate.
> >>
> >> This command is used to get/set state for a given allocation group.
> >
> > xfs_io is not the place for this command.
> I was also wonder why we place the agflags command on there since xfs_io is aimed
> at examining the regular file I/O paths, but I can not found out a better place
> while implementing it.
Right. That's exactly why I'm adding the xfs_spaceman command :)
> > A couple of weeks ago I started writing an xfs_spaceman module
> > and an ioctl interface for exactly this purpose, I just hadn't
> > got around to completing it and the kernel patch to test it so I
> > hadn't posted it. Once the userspace release is out of the way,
> > I'll post the patches to get xfs_spaceman into xfs_progs, and we
> > can use that for this AG control from the start.
> >
> > The reason for this is that the AG state in future is going to
> > be a lot more complex than just enabling/disabling allocation,
> > and the ioctl interface I prototyped supports a lot of that
> > future functionality.
> Definitely, so that we can have fine-granted AG controls, that's
> why I didn't chose to re-base/post the previous agflags patch but
> proposed the agstate command because the naming would sounds more
> reasonable.
*nod*
> >
> > The patch is below so you can see what sort of AG control/state
> > functionality I think we'll be needing sooner rather than later,
> > and the interface I think we should be using...
> Ok, I'll waiting for this feature. :)
>
> BTW, Does it sounds make sense if we implement parent pointer
> support at first?
> http://www.xfs.org/index.php/Unfinished_work#Parent_Pointers.2FCreate.2BEA
> I propose this because it would reduce many efforts for
> implementing xfs_shrinkfs command, and reduce the overhead for
> iterating overall file systems to find out files which are located
> at offline AGs.
That does need to be completed, though it's more of an optimisation
for the shrink process than absolutely necessary functionality.
Similarly for the rmap allocation btree (tracks used space and it's
owner) that I'm also working on. Being able to walk the used space
in an AG directly and immediately resolve the owner without a
directory tree walk or inode scan will make things ever faster....
Hence I think just having shrink dumb and slow as a first step is
just fine and speed can wait until we have all the necessary
infrastructure in place.
Cheers,
Dave.
--
Dave Chinner
david@fromorbit.com
_______________________________________________
xfs mailing list
xfs@oss.sgi.com
http://oss.sgi.com/mailman/listinfo/xfs
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2012-11-17 22:57 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2012-11-16 6:51 [PATCH 1/2] xfsprogs: Introduce a new subcommand agstate to xfs_fio Jeff Liu
2012-11-17 2:02 ` Dave Chinner
2012-11-17 4:33 ` Jeff Liu
2012-11-17 22:59 ` Dave Chinner
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.