From 6e80f1f615390b2697d27cd2feaf623790d85e29 Mon Sep 17 00:00:00 2001 From: Arvid Norberg Date: Sun, 19 Aug 2018 21:55:31 +0200 Subject: [PATCH] improve handling of filesystems not supporting fallocate() --- ChangeLog | 1 + src/disk_io_thread.cpp | 6 +++++- src/file.cpp | 4 ++-- src/storage.cpp | 6 +----- 4 files changed, 9 insertions(+), 8 deletions(-) diff --git a/ChangeLog b/ChangeLog index f8fd081b1..1d32f234d 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,4 @@ + * improve handling of filesystems not supporting fallocate() * force-proxy no longer disables DHT * improve connect-boost feature, to make new torrents quickly connect peers diff --git a/src/disk_io_thread.cpp b/src/disk_io_thread.cpp index 86493ef7c..de7c8b0fd 100644 --- a/src/disk_io_thread.cpp +++ b/src/disk_io_thread.cpp @@ -1184,7 +1184,7 @@ namespace libtorrent int ret = j->storage->get_storage_impl()->readv(&b, 1 , j->piece, j->d.io.offset, file_flags, j->error); - TORRENT_ASSERT(ret >= 0 || j->error.ec); + TORRENT_ASSERT(ret >= 0 || (j->error.ec && j->error.operation != 0)); if (!j->error.ec) { @@ -1258,6 +1258,8 @@ namespace libtorrent ret = j->storage->get_storage_impl()->readv(iov, iov_len , j->piece, adjusted_offset, file_flags, j->error); + TORRENT_ASSERT(ret >= 0 || (j->error.ec && j->error.operation != 0)); + if (!j->error.ec) { boost::uint32_t const read_time = total_microseconds(clock_type::now() - start_time); @@ -1418,6 +1420,8 @@ namespace libtorrent int ret = j->storage->get_storage_impl()->writev(&b, 1 , j->piece, j->d.io.offset, file_flags, j->error); + TORRENT_ASSERT(ret >= 0 || (j->error.ec && j->error.operation != 0)); + m_stats_counters.inc_stats_counter(counters::num_writing_threads, -1); if (!j->error.ec) diff --git a/src/file.cpp b/src/file.cpp index d17a37216..187058779 100644 --- a/src/file.cpp +++ b/src/file.cpp @@ -2154,9 +2154,9 @@ typedef struct _FILE_ALLOCATED_RANGE_BUFFER { // if you get a compile error here, you might want to // define TORRENT_HAS_FALLOCATE to 0. ret = posix_fallocate(native_handle(), 0, s); - // posix_allocate fails with EINVAL in case the underlying + // posix_allocate fails with EINVAL or ENOTSUP in case the underlying // filesystem does not support this operation - if (ret != 0 && ret != EINVAL) + if (ret != 0 && ret != EINVAL && ret != ENOTSUP) { ec.assign(ret, system_category()); return false; diff --git a/src/storage.cpp b/src/storage.cpp index d6bf3be13..19108008c 100644 --- a/src/storage.cpp +++ b/src/storage.cpp @@ -457,8 +457,6 @@ namespace libtorrent file_handle f = open_file(i, file::read_write, ec); if (ec) { - ec.file = i; - ec.operation = storage_error::open; prio = m_file_priority; return; } @@ -489,8 +487,6 @@ namespace libtorrent { if (ec) { - ec.file = i; - ec.operation = storage_error::open; prio = m_file_priority; return; } @@ -1600,7 +1596,7 @@ namespace libtorrent { ec.ec = e; ec.file = file; - ec.operation = storage_error::fallocate; + ec.operation = storage_error::stat; return h; }