]> git.ipfire.org Git - thirdparty/xfsprogs-dev.git/commitdiff
xfs_io: add fallocate command
authorEric Sandeen <sandeen@redhat.com>
Mon, 18 May 2009 16:11:44 +0000 (11:11 -0500)
committerEric Sandeen <sandeen@redhat.com>
Mon, 18 May 2009 16:11:44 +0000 (11:11 -0500)
Based on Dave's earlier patch, but now we have an fallocate
glibc call... this also adds autoconf magic and a manpage
update.

(hopefully not too #ifdef-heavy....)

Signed-off-by: Eric Sandeen <sandeen@sandeen.net>
Reviewed-by: Christoph Hellwig <hch@lst.de>
configure.in
include/builddefs.in
io/Makefile
io/prealloc.c
m4/package_libcdev.m4
man/man8/xfs_io.8

index 3fbd44e53f8fdbfc8afc73fceb3b1c3700bbec82..8f5782a3cb7f2dc40de039f55f2afa7b322b458d 100644 (file)
@@ -66,6 +66,7 @@ AC_HAVE_MINCORE
 AC_HAVE_SENDFILE
 AC_HAVE_GETMNTENT
 AC_HAVE_GETMNTINFO
+AC_HAVE_FALLOCATE
 
 AC_TYPE_PSINT
 AC_TYPE_PSUNSIGNED
index c8f5c080760bc68ade9dc32bba10407b5c9b022e..d6bf5c0c2421a2969164a138ce1867322051c7c7 100644 (file)
@@ -94,6 +94,7 @@ HAVE_MINCORE = @have_mincore@
 HAVE_SENDFILE = @have_sendfile@
 HAVE_GETMNTENT = @have_getmntent@
 HAVE_GETMNTINFO = @have_getmntinfo@
+HAVE_FALLOCATE = @have_fallocate@
 
 GCCFLAGS = -funsigned-char -fno-strict-aliasing -Wall 
 #         -Wbitwise -Wno-transparent-union -Wno-old-initializer -Wno-decl
index 6f10e8de97411be80c549625d8d8e7feb885c5d8..1a51879988d00be96ccb600965c1dcd82e846638 100644 (file)
@@ -59,6 +59,10 @@ ifeq ($(ENABLE_EDITLINE),yes)
 LLDLIBS += $(LIBEDITLINE) $(LIBTERMCAP)
 endif
 
+ifeq ($(HAVE_FALLOCATE),yes)
+LCFLAGS += -DHAVE_FALLOCATE
+endif
+
 default: $(LTCOMMAND)
 
 include $(BUILDRULES)
index 6a2563e8b60b38f43a48a8fd2b7a315e7c4ae32b..7d9bd2f3cd6bd841f57d96c6572e1e79511f78bf 100644 (file)
@@ -16,6 +16,9 @@
  * Inc.,  51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
  */
 
+#if defined(HAVE_FALLOCATE)
+#include <linux/falloc.h>
+#endif
 #include <xfs/xfs.h>
 #include <xfs/command.h>
 #include <xfs/input.h>
@@ -26,6 +29,9 @@ static cmdinfo_t allocsp_cmd;
 static cmdinfo_t freesp_cmd;
 static cmdinfo_t resvsp_cmd;
 static cmdinfo_t unresvsp_cmd;
+#if defined(HAVE_FALLOCATE)
+static cmdinfo_t falloc_cmd;
+#endif
 
 static int
 offset_length(
@@ -119,6 +125,40 @@ unresvsp_f(
        return 0;
 }
 
+#if defined (HAVE_FALLOCATE)
+static int
+fallocate_f(
+       int             argc,
+       char            **argv)
+{
+       xfs_flock64_t   segment;
+       int             mode = 0;
+       int             c;
+
+       while ((c = getopt(argc, argv, "k")) != EOF) {
+               switch (c) {
+               case 'k':
+                       mode = FALLOC_FL_KEEP_SIZE;
+                       break;
+               default:
+                       command_usage(&falloc_cmd);
+               }
+       }
+        if (optind != argc - 2)
+                return command_usage(&falloc_cmd);
+
+       if (!offset_length(argv[optind], argv[optind+1], &segment))
+               return 0;
+
+       if (fallocate(file->fd, mode,
+                       segment.l_start, segment.l_len)) {
+               perror("fallocate");
+               return 0;
+       }
+       return 0;
+}
+#endif
+
 void
 prealloc_init(void)
 {
@@ -160,4 +200,17 @@ prealloc_init(void)
        add_command(&freesp_cmd);
        add_command(&resvsp_cmd);
        add_command(&unresvsp_cmd);
+
+#if defined (HAVE_FALLOCATE)
+       falloc_cmd.name = _("falloc");
+       falloc_cmd.cfunc = fallocate_f;
+       falloc_cmd.argmin = 2;
+       falloc_cmd.argmax = -1;
+       falloc_cmd.flags = CMD_NOMAP_OK | CMD_FOREIGN_OK;
+       falloc_cmd.args = _("[-k] off len");
+       falloc_cmd.oneline =
+               _("allocates space associated with part of a file via fallocate");
+
+       add_command(&falloc_cmd);
+#endif
 }
index 5156ced652b9adaebb86cd3d10021d555ea31477..1ac466664abd95c50d370d4ed3e12a2605f88416 100644 (file)
@@ -98,3 +98,18 @@ AC_DEFUN([AC_HAVE_GETMNTINFO],
        AC_MSG_RESULT(no))
     AC_SUBST(have_getmntinfo)
   ])
+
+#
+# Check if we have a fallocate libc call (Linux)
+#
+AC_DEFUN([AC_HAVE_FALLOCATE],
+  [ AC_MSG_CHECKING([for fallocate])
+    AC_TRY_LINK([
+#include <linux/falloc.h>
+    ], [
+         fallocate(0, 0, 0, 0);
+    ], have_fallocate=yes
+       AC_MSG_RESULT(yes),
+       AC_MSG_RESULT(no))
+    AC_SUBST(have_fallocate)
+  ])
index 23bef94519cdb9cbd4c851dd3a46177b35cd57f0..6fc6bad90ace472a5b4d40a151c14a4e6fef9753 100644 (file)
@@ -295,6 +295,20 @@ system call described in the
 .BR xfsctl (3)
 manual page.
 .TP
+.BI "falloc [ \-k ]" " offset length"
+Allocates reserved, unwritten space for part of a file using the
+fallocate routine as described in the
+.BR fallocate (3)
+manual page.
+.RS 1.0i
+.PD 0
+.TP 0.4i
+.B \-k
+will set the FALLOC_FL_KEEP_SIZE flag as described in
+.BR fallocate (3).
+.PD
+.RE
+.TP
 .BI truncate " offset"
 Truncates the current file at the given offset using
 .BR ftruncate (2).