[Libtorrent-devel] Partial Allocation & XFS?

Jan Willies jan at willies.info
Thu Oct 9 14:55:35 UTC 2008


Brian Stentzel wrote:
> I noticed that Azureus has an XFS-specific partial allocation mode, 
> and am wondering if my use of XFS is causing the problem here.  I 
> don't have any non-XFS partitions to test with (except NTFS ones 
> mounted with ntfs-3g), so I'm hoping someone else will know what I 
> should do.  Also, is there a way to force "full allocation" with 
> libtorrent/rtorrent?  It seems like that would solve the problem too.

Attached you'll find a patch for libtorrent (not written by me) which 
enables XFS's feature of preallocation. Configure libtorrent with 
./configure --with-xfs and recompile afterwards.


HTH

- Jan
-------------- next part --------------
Index: src/data/socket_file.cc
===================================================================
--- src/data/socket_file.cc	(revision 1072)
+++ src/data/socket_file.cc	(working copy)
@@ -98,16 +98,17 @@
 #endif
 
 bool
-SocketFile::reserve(RESERVE_PARAM uint64_t offset, RESERVE_PARAM uint64_t length) {
+SocketFile::reserve(RESERVE_PARAM uint64_t offset, RESERVE_PARAM uint64_t length) const {
 #ifdef USE_XFS
-  struct xfs_flock64 flock;
+  struct ::xfs_flock64 flock;
 
   flock.l_whence = SEEK_SET;
   flock.l_start = offset;
   flock.l_len = length;
 
-  if (ioctl(m_fd, XFS_IOC_RESVSP64, &flock) >= 0)
-    return true;
+  if (platform_test_xfs_fd(m_fd)) {
+    if (ioctl(m_fd, XFS_IOC_RESVSP64, &flock) < 0) return false;
+  }
 #endif
 
 #ifdef USE_POSIX_FALLOCATE
@@ -134,6 +135,8 @@
   if (!is_open())
     throw internal_error("SocketFile::set_size() called on a closed file");
 
+  if (!reserve(0, size)) return false;
+
   if (ftruncate(m_fd, size) == 0)
     return true;
 
Index: src/data/socket_file.h
===================================================================
--- src/data/socket_file.h	(revision 1072)
+++ src/data/socket_file.h	(working copy)
@@ -67,7 +67,7 @@
 
   // Reserve the space on disk if a system call is defined. 'length'
   // of zero indicates to the end of the file.
-  bool                reserve(uint64_t offset = 0, uint64_t length = 0);
+  bool                reserve(uint64_t offset = 0, uint64_t length = 0) const;
 
   bool                is_open() const                                   { return m_fd != invalid_fd; }
 
Index: configure.ac
===================================================================
--- configure.ac	(revision 1072)
+++ configure.ac	(working copy)
@@ -43,7 +43,7 @@
 TORRENT_ENABLE_ARCH
 TORRENT_WITH_SYSROOT
 
-dnl TORRENT_WITH_XFS
+TORRENT_WITH_XFS
 TORRENT_WITH_KQUEUE
 TORRENT_WITHOUT_EPOLL
 TORRENT_WITH_POSIX_FALLOCATE


More information about the Libtorrent-devel mailing list