* [patch] rudimetary fallocate support for xfs_io
@ 2008-05-22 6:10 David Chinner
2008-05-22 6:39 ` Nathan Scott
0 siblings, 1 reply; 2+ messages in thread
From: David Chinner @ 2008-05-22 6:10 UTC (permalink / raw)
To: xfs-dev; +Cc: xfs-oss
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@sgi.com>
---
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);
}
^ permalink raw reply [flat|nested] 2+ messages in thread
* Re: [patch] rudimetary fallocate support for xfs_io
2008-05-22 6:10 [patch] rudimetary fallocate support for xfs_io David Chinner
@ 2008-05-22 6:39 ` Nathan Scott
0 siblings, 0 replies; 2+ messages in thread
From: Nathan Scott @ 2008-05-22 6:39 UTC (permalink / raw)
To: David Chinner; +Cc: xfs-dev, xfs-oss
On Thu, 2008-05-22 at 16:10 +1000, David Chinner wrote:
>
> +#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);
> +}
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.
--
Nathan
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2008-05-22 6:38 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2008-05-22 6:10 [patch] rudimetary fallocate support for xfs_io David Chinner
2008-05-22 6:39 ` Nathan Scott
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox