Skip to contentSkip to conversation

xfsprogs: add fallocate command to xfs_io

PATCH In review Eric Sandeen 2 participants 7 messages May 11, 2009 – May 16, 2009

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 xfsprogs: add fallocate command to xfs_io

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....)

---

configure.in +1 -0
index 3fbd44e..8f5782a 100644
@@ -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
include/builddefs.in +1 -0
index c8f5c08..d6bf5c0 100644
@@ -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
io/Makefile +4 -0
index 6f10e8d..1a51879 100644
@@ -59,6 +59,10 @@ ifeq ($(ENABLE_EDITLINE),yes)
 LLDLIBS += $(LIBEDITLINE) $(LIBTERMCAP)
 endif
 
+ifeq ($(HAVE_FALLOCATE),yes)
+LCFLAGS += -DHAVE_FALLOCATE
+endif
+
 default: $(LTCOMMAND)
 
 include $(BUILDRULES)
io/prealloc.c +53 -0

75 lines not on this page · raw message

m4/package_libcdev.m4 +15 -0
index 5156ced..856794a 100644
@@ -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)
+  ])
man/man8/xfs_io.8 +14 -0
index 23bef94..6fc6bad 100644
@@ -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
[email protected]
http://oss.sgi.com/mailman/listinfo/xfs

Reviewed-by on v1 1/1
#1 lore raw
Quoted 5 lines · Eric Sandeen

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.

io/prealloc.c line 21

Quoted 3 lines
io/prealloc.c +3 -0
+#if defined(HAVE_FALLOCATE)
+#include <linux/falloc.h>
+#endif

What about just using #ifdef HAVE_FALLOCATE everywhere?

_______________________________________________
xfs mailing list
[email protected]
http://oss.sgi.com/mailman/listinfo/xfs

#2 lore raw
Quoted 8 lines · Christoph Hellwig
Quoted 5 lines · Eric Sandeen

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
[email protected]
http://oss.sgi.com/mailman/listinfo/xfs

#3 lore raw
Quoted 6 lines · Christoph Hellwig
Quoted 5 lines · Christoph Hellwig
Quoted 4 lines · Eric Sandeen

Based on Dave's earlier patch, but now we have an fallocate glibc call... this also adds autoconf magic and a manpage update.

Quoted 7 lines
Quoted 2 lines
Quoted 1 line

(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
[email protected]
http://oss.sgi.com/mailman/listinfo/xfs

#4 lore raw
Quoted 7 lines · Eric Sandeen
Quoted 6 lines · Christoph Hellwig
Quoted 5 lines · Christoph Hellwig
Quoted 4 lines · Eric Sandeen

Based on Dave's earlier patch, but now we have an fallocate glibc call... this also adds autoconf magic and a manpage update.

Quoted 8 lines
Quoted 6 lines
Quoted 2 lines
Quoted 1 line

(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
[email protected]
http://oss.sgi.com/mailman/listinfo/xfs

#5 lore raw
Quoted 3 lines · Eric Sandeen

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.

Quoted 7 lines

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
[email protected]
http://oss.sgi.com/mailman/listinfo/xfs

#6 lore raw
Quoted 15 lines · Christoph Hellwig
Quoted 3 lines · Eric Sandeen

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.

Quoted 6 lines

AC_DEFUN([AC_HAVE_FALLOCATE],
[ AC_MSG_CHECKING([for fallocate])

    AC_TRY_LINK([
#include <linux/falloc.h>
    ], [
         fallocate(0, 0, 0, 0);
Quoted 3 lines

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
[email protected]
http://oss.sgi.com/mailman/listinfo/xfs