xfs
[Top] [All Lists]

[patch] rudimetary fallocate support for xfs_io

To: xfs-dev <xfs-dev@xxxxxxx>
Subject: [patch] rudimetary fallocate support for xfs_io
From: David Chinner <dgc@xxxxxxx>
Date: Thu, 22 May 2008 16:10:29 +1000
Cc: xfs-oss <xfs@xxxxxxxxxxx>
Sender: xfs-bounce@xxxxxxxxxxx
User-agent: Mutt/1.4.2.1i
Rudimentary fallocate support for xfs_io. Supports the two
known methods that fallocate currently implements. When glibc
support for the syscall comes around this should be changed
to use that interface.

Signed-off-by: Dave Chinner <dgc@xxxxxxx>
---
 xfsprogs/io/prealloc.c |   82 +++++++++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 82 insertions(+)

Index: xfs-cmds/xfsprogs/io/prealloc.c
===================================================================
--- xfs-cmds.orig/xfsprogs/io/prealloc.c        2007-10-30 15:00:49.338718381 
+1100
+++ xfs-cmds/xfsprogs/io/prealloc.c     2007-11-08 11:45:56.538926493 +1100
@@ -26,6 +26,8 @@ static cmdinfo_t allocsp_cmd;
 static cmdinfo_t freesp_cmd;
 static cmdinfo_t resvsp_cmd;
 static cmdinfo_t unresvsp_cmd;
+static cmdinfo_t falloc_allocsp_cmd;
+static cmdinfo_t falloc_resvsp_cmd;
 
 static int
 offset_length(
@@ -119,6 +121,66 @@ unresvsp_f(
        return 0;
 }
 
+/*
+ * someday there'll be a real header file in user space.
+ * (kernel is include/linux/falloc.h). In the mean time....
+ */
+#define FALLOC_FL_KEEP_SIZE     0x01
+#define FALLOC_ALLOCATE         0x0
+#define FALLOC_RESV_SPACE       FALLOC_FL_KEEP_SIZE
+
+#if defined(__i386__)
+#define __NR_fallocate 324
+#elif defined(__x86_64__)
+#define __NR_fallocate 285
+#elif defined(__ia64__)
+#define __NR_fallocate 1303
+#endif
+
+static int
+fallocate(int fd, int cmd, off64_t start, off64_t len)
+{
+       return syscall(__NR_fallocate, fd, cmd, start, len);
+}
+
+static int
+fallocate_allocsp_f(
+       int             argc,
+       char            **argv)
+{
+       xfs_flock64_t   segment;
+
+       if (!offset_length(argv[1], argv[2], &segment))
+               return 0;
+
+       /* syscall(__NR_fallocate, ...) */
+       if (fallocate(file->fd, FALLOC_ALLOCATE,
+                       segment.l_start, segment.l_len)) {
+               perror("FALLOC_ALLOCATE");
+               return 0;
+       }
+       return 0;
+}
+
+static int
+fallocate_resvsp_f(
+       int             argc,
+       char            **argv)
+{
+       xfs_flock64_t   segment;
+
+       if (!offset_length(argv[1], argv[2], &segment))
+               return 0;
+
+       /* syscall(__NR_fallocate, ...) */
+       if (fallocate(file->fd, FALLOC_RESV_SPACE,
+                       segment.l_start, segment.l_len)) {
+               perror("FALLOC_RESVSP");
+               return 0;
+       }
+       return 0;
+}
+
 void
 prealloc_init(void)
 {
@@ -156,8 +218,28 @@ prealloc_init(void)
        unresvsp_cmd.oneline =
                _("frees reserved space associated with part of a file");
 
+       falloc_allocsp_cmd.name = _("falloc_allocsp");
+       falloc_allocsp_cmd.cfunc = fallocate_allocsp_f;
+       falloc_allocsp_cmd.argmin = 2;
+       falloc_allocsp_cmd.argmax = 2;
+       falloc_allocsp_cmd.flags = CMD_NOMAP_OK;
+       falloc_allocsp_cmd.args = _("off len");
+       falloc_allocsp_cmd.oneline =
+               _("allocates space associated with part of a file via 
fallocate");
+
+       falloc_resvsp_cmd.name = _("falloc_resvsp");
+       falloc_resvsp_cmd.cfunc = fallocate_resvsp_f;
+       falloc_resvsp_cmd.argmin = 2;
+       falloc_resvsp_cmd.argmax = 2;
+       falloc_resvsp_cmd.flags = CMD_NOMAP_OK;
+       falloc_resvsp_cmd.args = _("off len");
+       falloc_resvsp_cmd.oneline =
+               _("reserves space associated with part of a file via 
fallocate");
+
        add_command(&allocsp_cmd);
        add_command(&freesp_cmd);
        add_command(&resvsp_cmd);
        add_command(&unresvsp_cmd);
+       add_command(&falloc_allocsp_cmd);
+       add_command(&falloc_resvsp_cmd);
 }


<Prev in Thread] Current Thread [Next in Thread>