* [PATCH] xfsprogs: add fallocate command to xfs_io
@ 2009-05-11 0:30 Eric Sandeen
2009-05-15 17:13 ` Christoph Hellwig
0 siblings, 1 reply; 7+ messages in thread
From: Eric Sandeen @ 2009-05-11 0:30 UTC (permalink / raw)
To: xfs-oss
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>
---
diff --git a/configure.in b/configure.in
index 3fbd44e..8f5782a 100644
--- a/configure.in
+++ b/configure.in
@@ -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
diff --git a/include/builddefs.in b/include/builddefs.in
index c8f5c08..d6bf5c0 100644
--- a/include/builddefs.in
+++ b/include/builddefs.in
@@ -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
diff --git a/io/Makefile b/io/Makefile
index 6f10e8d..1a51879 100644
--- a/io/Makefile
+++ b/io/Makefile
@@ -59,6 +59,10 @@ ifeq ($(ENABLE_EDITLINE),yes)
LLDLIBS += $(LIBEDITLINE) $(LIBTERMCAP)
endif
+ifeq ($(HAVE_FALLOCATE),yes)
+LCFLAGS += -DHAVE_FALLOCATE
+endif
+
default: $(LTCOMMAND)
include $(BUILDRULES)
diff --git a/io/prealloc.c b/io/prealloc.c
index 6a2563e..7d9bd2f 100644
--- a/io/prealloc.c
+++ b/io/prealloc.c
@@ -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
}
diff --git a/m4/package_libcdev.m4 b/m4/package_libcdev.m4
index 5156ced..856794a 100644
--- a/m4/package_libcdev.m4
+++ b/m4/package_libcdev.m4
@@ -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_COMPILE([
+#include <linux/falloc.h>
+ ], [
+ fallocate(0, 0, 0, 0);
+ ], have_fallocate=yes
+ AC_MSG_RESULT(yes),
+ AC_MSG_RESULT(no))
+ AC_SUBST(have_fallocate)
+ ])
diff --git a/man/man8/xfs_io.8 b/man/man8/xfs_io.8
index 23bef94..6fc6bad 100644
--- a/man/man8/xfs_io.8
+++ b/man/man8/xfs_io.8
@@ -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).
_______________________________________________
xfs mailing list
xfs@oss.sgi.com
http://oss.sgi.com/mailman/listinfo/xfs
^ permalink raw reply related [flat|nested] 7+ messages in thread* Re: [PATCH] xfsprogs: add fallocate command to xfs_io
2009-05-11 0:30 [PATCH] xfsprogs: add fallocate command to xfs_io Eric Sandeen
@ 2009-05-15 17:13 ` Christoph Hellwig
2009-05-15 17:27 ` Christoph Hellwig
0 siblings, 1 reply; 7+ messages in thread
From: Christoph Hellwig @ 2009-05-15 17:13 UTC (permalink / raw)
To: Eric Sandeen; +Cc: xfs-oss
On Sun, May 10, 2009 at 07:30:13PM -0500, Eric Sandeen wrote:
> 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....)
Looks good to me and seems to work.
> +#if defined(HAVE_FALLOCATE)
> +#include <linux/falloc.h>
> +#endif
What about just using #ifdef HAVE_FALLOCATE everywhere?
Reviewed-by: Christoph Hellwig <hch@lst.de>
_______________________________________________
xfs mailing list
xfs@oss.sgi.com
http://oss.sgi.com/mailman/listinfo/xfs
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: [PATCH] xfsprogs: add fallocate command to xfs_io
2009-05-15 17:13 ` Christoph Hellwig
@ 2009-05-15 17:27 ` Christoph Hellwig
2009-05-15 18:50 ` Eric Sandeen
0 siblings, 1 reply; 7+ messages in thread
From: Christoph Hellwig @ 2009-05-15 17:27 UTC (permalink / raw)
To: Eric Sandeen; +Cc: xfs-oss
On Fri, May 15, 2009 at 01:13:24PM -0400, Christoph Hellwig wrote:
> On Sun, May 10, 2009 at 07:30:13PM -0500, Eric Sandeen wrote:
> > 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....)
>
> Looks good to me and seems to work.
Actually that was spoken too fast. On my Debian -testing system it
detects fallocate as available because <linux/falloc.h> exists, but the
glibc doesn't actually support a falloc(3) yet. So either the detection
needs to be improved or we need to use the raw syscall.
_______________________________________________
xfs mailing list
xfs@oss.sgi.com
http://oss.sgi.com/mailman/listinfo/xfs
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: [PATCH] xfsprogs: add fallocate command to xfs_io
2009-05-15 17:27 ` Christoph Hellwig
@ 2009-05-15 18:50 ` Eric Sandeen
2009-05-15 22:11 ` Eric Sandeen
0 siblings, 1 reply; 7+ messages in thread
From: Eric Sandeen @ 2009-05-15 18:50 UTC (permalink / raw)
To: Christoph Hellwig; +Cc: xfs-oss
Christoph Hellwig wrote:
> On Fri, May 15, 2009 at 01:13:24PM -0400, Christoph Hellwig wrote:
>> On Sun, May 10, 2009 at 07:30:13PM -0500, Eric Sandeen wrote:
>>> 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....)
>> Looks good to me and seems to work.
>
> Actually that was spoken too fast. On my Debian -testing system it
> detects fallocate as available because <linux/falloc.h> exists, but the
> glibc doesn't actually support a falloc(3) yet. So either the detection
> needs to be improved or we need to use the raw syscall.
Ok, I think I know how to make the detection work better, I'll fix that up.
-Eric
_______________________________________________
xfs mailing list
xfs@oss.sgi.com
http://oss.sgi.com/mailman/listinfo/xfs
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: [PATCH] xfsprogs: add fallocate command to xfs_io
2009-05-15 18:50 ` Eric Sandeen
@ 2009-05-15 22:11 ` Eric Sandeen
2009-05-16 20:40 ` Christoph Hellwig
0 siblings, 1 reply; 7+ messages in thread
From: Eric Sandeen @ 2009-05-15 22:11 UTC (permalink / raw)
To: Christoph Hellwig; +Cc: xfs-oss
Eric Sandeen wrote:
> Christoph Hellwig wrote:
>> On Fri, May 15, 2009 at 01:13:24PM -0400, Christoph Hellwig wrote:
>>> On Sun, May 10, 2009 at 07:30:13PM -0500, Eric Sandeen wrote:
>>>> 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....)
>>> Looks good to me and seems to work.
>> Actually that was spoken too fast. On my Debian -testing system it
>> detects fallocate as available because <linux/falloc.h> exists, but the
>> glibc doesn't actually support a falloc(3) yet. So either the detection
>> needs to be improved or we need to use the raw syscall.
>
> Ok, I think I know how to make the detection work better, I'll fix that up.
oh, hrm. It's already doing what I thought was sufficient but it won't
link will it:
(from m4/package_libcdev.m4)
+#
+# Check if we have a fallocate libc call (Linux)
+#
+AC_DEFUN([AC_HAVE_FALLOCATE],
+ [ AC_MSG_CHECKING([for fallocate])
+ AC_TRY_COMPILE([
+#include <linux/falloc.h>
+ ], [
+ fallocate(0, 0, 0, 0);
+ ], have_fallocate=yes
+ AC_MSG_RESULT(yes),
+ AC_MSG_RESULT(no))
+ AC_SUBST(have_fallocate)
+ ])
Instead of above does this work better?
(just change AC_TRY_COMPILE to AC_TRY_LINK)
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)
])
_______________________________________________
xfs mailing list
xfs@oss.sgi.com
http://oss.sgi.com/mailman/listinfo/xfs
^ permalink raw reply [flat|nested] 7+ messages in thread* Re: [PATCH] xfsprogs: add fallocate command to xfs_io
2009-05-15 22:11 ` Eric Sandeen
@ 2009-05-16 20:40 ` Christoph Hellwig
2009-05-16 22:08 ` Eric Sandeen
0 siblings, 1 reply; 7+ messages in thread
From: Christoph Hellwig @ 2009-05-16 20:40 UTC (permalink / raw)
To: Eric Sandeen; +Cc: Christoph Hellwig, xfs-oss
On Fri, May 15, 2009 at 05:11:24PM -0500, Eric Sandeen wrote:
> Instead of above does this work better?
>
> (just change AC_TRY_COMPILE to AC_TRY_LINK)
Yes, that correctly detects fallocate as not present for me and
thus gives a working fallocate.
>
> AC_DEFUN([AC_HAVE_FALLOCATE],
> [ AC_MSG_CHECKING([for fallocate])
> AC_TRY_LINK([
> #include <linux/falloc.h>
> ], [
> fallocate(0, 0, 0, 0);
Why do you nee to include <linux/falloc.h> here anyway? You don't use
any of the constants, and the fallocate libc call must be in another
headers, so it obviously compiles even without a defintion for it.
_______________________________________________
xfs mailing list
xfs@oss.sgi.com
http://oss.sgi.com/mailman/listinfo/xfs
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: [PATCH] xfsprogs: add fallocate command to xfs_io
2009-05-16 20:40 ` Christoph Hellwig
@ 2009-05-16 22:08 ` Eric Sandeen
0 siblings, 0 replies; 7+ messages in thread
From: Eric Sandeen @ 2009-05-16 22:08 UTC (permalink / raw)
To: Christoph Hellwig; +Cc: xfs-oss
Christoph Hellwig wrote:
> On Fri, May 15, 2009 at 05:11:24PM -0500, Eric Sandeen wrote:
>> Instead of above does this work better?
>>
>> (just change AC_TRY_COMPILE to AC_TRY_LINK)
>
> Yes, that correctly detects fallocate as not present for me and
> thus gives a working fallocate.
>
>> AC_DEFUN([AC_HAVE_FALLOCATE],
>> [ AC_MSG_CHECKING([for fallocate])
>> AC_TRY_LINK([
>> #include <linux/falloc.h>
>> ], [
>> fallocate(0, 0, 0, 0);
>
> Why do you nee to include <linux/falloc.h> here anyway? You don't use
> any of the constants, and the fallocate libc call must be in another
> headers, so it obviously compiles even without a defintion for it.
Well, the actual patch includes it for FALLOC_FL_KEEP_SIZE so it'd be
better to detect it at config time and if not there fail?
Or we could #ifndef and have a local define ...
-Eric
_______________________________________________
xfs mailing list
xfs@oss.sgi.com
http://oss.sgi.com/mailman/listinfo/xfs
^ permalink raw reply [flat|nested] 7+ messages in thread
end of thread, other threads:[~2009-05-16 22:08 UTC | newest]
Thread overview: 7+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2009-05-11 0:30 [PATCH] xfsprogs: add fallocate command to xfs_io Eric Sandeen
2009-05-15 17:13 ` Christoph Hellwig
2009-05-15 17:27 ` Christoph Hellwig
2009-05-15 18:50 ` Eric Sandeen
2009-05-15 22:11 ` Eric Sandeen
2009-05-16 20:40 ` Christoph Hellwig
2009-05-16 22:08 ` Eric Sandeen
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox