1
0
Fork 0
mirror of https://github.com/transmission/transmission synced 2025-03-04 10:38:13 +00:00

(trunk libT) #1966: add explicit support for preallocating files on XFS filesystems

This commit is contained in:
Charles Kerr 2009-04-05 14:04:07 +00:00
parent 822a192758
commit 1e327f593d
2 changed files with 38 additions and 23 deletions

View file

@ -146,6 +146,8 @@ if test "x$want_kqueue" = "xyes" ; then
fi fi
fi fi
AC_CHECK_HEADERS([xfs/xfs.h])
dnl ---------------------------------------------------------------------------- dnl ----------------------------------------------------------------------------
dnl dnl

View file

@ -47,6 +47,10 @@
#include <linux/falloc.h> #include <linux/falloc.h>
#endif #endif
#ifdef HAVE_XFS_XFS_H
#include <xfs/xfs.h>
#endif
#include <sys/types.h> #include <sys/types.h>
#include <sys/stat.h> #include <sys/stat.h>
#ifdef HAVE_GETRLIMIT #ifdef HAVE_GETRLIMIT
@ -158,17 +162,19 @@ preallocateFileFull( const char * filename, uint64_t length )
int fd = open( filename, flags, 0666 ); int fd = open( filename, flags, 0666 );
if( fd >= 0 ) if( fd >= 0 )
{ {
# ifdef HAVE_XFS_XFS_H
# ifdef HAVE_FALLOCATE if( !success && platform_test_xfs_fd( fd ) )
{
success = !fallocate( fd, FALLOC_FL_KEEP_SIZE, 0, length ); xfs_flock64_t fl;
fl.l_whence = 0;
# elif defined(HAVE_POSIX_FALLOCATE) fl.l_start = 0;
fl.l_len = length;
success = !posix_fallocate( fd, 0, length ); success = !xfsctl( NULL, fd, XFS_IOC_RESVSP64, &fl );
}
# elif defined(SYS_DARWIN) # endif
# ifdef SYS_DARWIN
if( !success )
{
fstore_t fst; fstore_t fst;
fst.fst_flags = F_ALLOCATECONTIG; fst.fst_flags = F_ALLOCATECONTIG;
fst.fst_posmode = F_PEOFPOSMODE; fst.fst_posmode = F_PEOFPOSMODE;
@ -176,12 +182,19 @@ preallocateFileFull( const char * filename, uint64_t length )
fst.fst_length = length; fst.fst_length = length;
fst.fst_bytesalloc = 0; fst.fst_bytesalloc = 0;
success = !fcntl( fd, F_PREALLOCATE, &fst ); success = !fcntl( fd, F_PREALLOCATE, &fst );
}
# else # endif
# ifdef HAVE_FALLOCATE
#warning no known method to preallocate files on this platform if( !success )
success = 0; {
success = !fallocate( fd, FALLOC_FL_KEEP_SIZE, 0, length );
}
# endif
# ifdef HAVE_POSIX_FALLOCATE
if( !success )
{
success = !posix_fallocate( fd, 0, length );
}
# endif # endif
close( fd ); close( fd );