rudimetary fallocate support for xfs_io
PATCH 1/1 rudimetary fallocate support for xfs_io
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 <[email protected]>
--- xfsprogs/io/prealloc.c | 82 +++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 82 insertions(+)
xfsprogs/io/prealloc.c +82 -0
@@ -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); }
Quoted 4 lines · David Chinner
xfsprogs/io/prealloc.c +3
-0+#if defined(__i386__) +#define __NR_fallocate 324 +#elif defined(__x86_64__)
xfsprogs/io/prealloc.c unresvsp_f( · line 144
Quoted 10 lines
xfsprogs/io/prealloc.c +10
-0+#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); +}
This will cause xfsprogs build breakage on any architecture other than the above three; check out the approach taken in xfs-cmds/attr/libattr/syscalls.c to avoid this (give ENOSYS for the unknown archs).
cheers.
Signature · 1 line
Nathan