]> git.ipfire.org Git - thirdparty/xfsprogs-dev.git/commitdiff
xfs_spaceman: add new speculative prealloc control
authorDave Chinner <dchinner@redhat.com>
Wed, 21 Jun 2017 22:14:30 +0000 (17:14 -0500)
committerEric Sandeen <sandeen@redhat.com>
Wed, 21 Jun 2017 22:14:30 +0000 (17:14 -0500)
Add an control interface for purging speculative
preallocation via the new ioctls.

Signed-off-by: Dave Chinner <dchinner@redhat.com>
[darrick: change xfsctl to ioctl]
Signed-off-by: Darrick J. Wong <darrick.wong@oracle.com>
Reviewed-by: Eric Sandeen <sandeen@redhat.com>
[sandeen: change help to "removes" not "controls"]
Signed-off-by: Eric Sandeen <sandeen@sandeen.net>
spaceman/Makefile
spaceman/init.c
spaceman/prealloc.c [new file with mode: 0644]
spaceman/space.h

index c63a4fc9ca2689483d5d0d17f57f9538d699b4d9..6aad7465ebd868ae65e0c8b88492707630580dfc 100644 (file)
@@ -7,7 +7,7 @@ include $(TOPDIR)/include/builddefs
 
 LTCOMMAND = xfs_spaceman
 HFILES = init.h space.h
-CFILES = init.c file.c trim.c
+CFILES = init.c file.c prealloc.c trim.c
 
 LLDLIBS = $(LIBXCMD)
 LTDEPENDENCIES = $(LIBXCMD)
index 107a692423c061359b108470b1c964e70748788a..a51007d7418e2f7287c7c27e26cef21982d6038b 100644 (file)
@@ -39,6 +39,7 @@ init_commands(void)
 {
        print_init();
        help_init();
+       prealloc_init();
        quit_init();
        trim_init();
 }
diff --git a/spaceman/prealloc.c b/spaceman/prealloc.c
new file mode 100644 (file)
index 0000000..543b074
--- /dev/null
@@ -0,0 +1,118 @@
+/*
+ * 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 "command.h"
+#include "input.h"
+#include "init.h"
+#include "space.h"
+
+static cmdinfo_t prealloc_cmd;
+
+/*
+ * Control preallocation amounts.
+ */
+static int
+prealloc_f(
+       int     argc,
+       char    **argv)
+{
+       struct xfs_fs_eofblocks eofb = {0};
+       int     c;
+
+       eofb.eof_version = XFS_EOFBLOCKS_VERSION;
+
+       while ((c = getopt(argc, argv, "g:m:p:su:")) != EOF) {
+               switch (c) {
+               case 'g':
+                       eofb.eof_flags |= XFS_EOF_FLAGS_GID;
+                       eofb.eof_gid = cvt_u32(optarg, 10);
+                       if (errno)
+                               return command_usage(&prealloc_cmd);
+                       break;
+               case 'u':
+                       eofb.eof_flags |= XFS_EOF_FLAGS_UID;
+                       eofb.eof_uid = cvt_u32(optarg, 10);
+                       if (errno)
+                               return command_usage(&prealloc_cmd);
+                       break;
+               case 'p':
+                       eofb.eof_flags |= XFS_EOF_FLAGS_PRID;
+                       eofb.eof_prid = cvt_u32(optarg, 10);
+                       if (errno)
+                               return command_usage(&prealloc_cmd);
+                       break;
+               case 's':
+                       eofb.eof_flags |= XFS_EOF_FLAGS_SYNC;
+                       break;
+               case 'm':
+                       eofb.eof_flags |= XFS_EOF_FLAGS_MINFILESIZE;
+                       eofb.eof_min_file_size = cvtnum(file->geom.blocksize,
+                                                       file->geom.sectsize,
+                                                       optarg);
+                       break;
+               case '?':
+               default:
+                       return command_usage(&prealloc_cmd);
+               }
+       }
+       if (optind != argc)
+               return command_usage(&prealloc_cmd);
+
+       if (ioctl(file->fd, XFS_IOC_FREE_EOFBLOCKS, &eofb) < 0) {
+               fprintf(stderr, _("%s: XFS_IOC_FREE_EOFBLOCKS on %s: %s\n"),
+                       progname, file->name, strerror(errno));
+       }
+       return 0;
+}
+
+static void
+prealloc_help(void)
+{
+       printf(_(
+"\n"
+"Remove speculative preallocation\n"
+"\n"
+" -g gid    -- remove prealloc on files matching group <gid>\n"
+" -m minlen -- only consider files larger than <minlen>\n"
+" -p prid   -- remove prealloc on files matching project <prid>\n"
+" -s        -- wait for removal to complete\n"
+" -u uid    -- remove prealloc on files matching user <uid>\n"
+"\n"
+"If none of -u, -g, or -p are specified, this command acts on all files.\n"
+"minlen can take units.\n"
+"\n"));
+
+}
+
+void
+prealloc_init(void)
+{
+       prealloc_cmd.name = "prealloc";
+       prealloc_cmd.altname = "prealloc";
+       prealloc_cmd.cfunc = prealloc_f;
+       prealloc_cmd.argmin = 1;
+       prealloc_cmd.argmax = -1;
+       prealloc_cmd.args = "[-s] [-u id] [-g id] [-p id] [-m minlen]";
+       prealloc_cmd.flags = CMD_FLAG_ONESHOT;
+       prealloc_cmd.oneline = _("Remove speculative preallocation");
+       prealloc_cmd.help = prealloc_help;
+
+       add_command(&prealloc_cmd);
+}
+
index 8cd39537f9d60fd63a6d5e0d8dee66ad76437417..de971396ac06cb96ec9552cfedc4a959d6df3414 100644 (file)
@@ -33,6 +33,7 @@ extern int    addfile(char *, int , xfs_fsop_geom_t *);
 
 extern void    print_init(void);
 extern void    help_init(void);
+extern void    prealloc_init(void);
 extern void    quit_init(void);
 extern void    trim_init(void);