From d1a59879cb549ee67bc23919091a57af7a70c70e Mon Sep 17 00:00:00 2001 From: Arvid Norberg Date: Sat, 29 Oct 2016 13:42:42 -0400 Subject: [PATCH 1/2] deprecate mmap_cache (#1269) deprecated mmap_cache feature --- ChangeLog | 1 + examples/client_test.cpp | 5 ----- include/libtorrent/alert_types.hpp | 4 +++- include/libtorrent/disk_buffer_pool.hpp | 2 +- include/libtorrent/settings_pack.hpp | 4 ++++ src/alert.cpp | 2 ++ src/disk_buffer_pool.cpp | 23 +++++++++++++---------- src/disk_io_thread.cpp | 4 ++++ test/test_settings_pack.cpp | 2 +- 9 files changed, 29 insertions(+), 18 deletions(-) diff --git a/ChangeLog b/ChangeLog index 9851584c6..1ef192835 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,4 @@ + * deprecated mmap_cache feature * add utility function for generating peer ID fingerprint * fix bug in last-seen-complete * remove file size limit in torrent_info filename constructor diff --git a/examples/client_test.cpp b/examples/client_test.cpp index fa5f328da..ce42693d4 100644 --- a/examples/client_test.cpp +++ b/examples/client_test.cpp @@ -1301,7 +1301,6 @@ int main(int argc, char* argv[]) " -C sets the max cache size. Specified in 16kB blocks\n" " -j disable disk read-ahead\n" " -z disable piece hash checks (used for benchmarking)\n" - " -Z mmap the disk cache to the specified file, should be an SSD\n" " -0 disable disk I/O, read garbage and don't flush to disk\n" "\n\n" "TORRENT is a path to a .torrent file\n" @@ -1537,10 +1536,6 @@ int main(int argc, char* argv[]) break; } case 'X': settings.set_bool(settings_pack::enable_lsd, false); --i; break; - case 'Z': - settings.set_str(settings_pack::mmap_cache, arg); - settings.set_bool(settings_pack::contiguous_recv_buffer, false); - break; case 'v': settings.set_int(settings_pack::active_downloads, atoi(arg)); settings.set_int(settings_pack::active_limit, atoi(arg) * 2); break; diff --git a/include/libtorrent/alert_types.hpp b/include/libtorrent/alert_types.hpp index 06e571ba6..324f9097e 100644 --- a/include/libtorrent/alert_types.hpp +++ b/include/libtorrent/alert_types.hpp @@ -1878,7 +1878,8 @@ namespace libtorrent std::vector status; }; - struct TORRENT_EXPORT mmap_cache_alert TORRENT_FINAL : alert +#ifndef TORRENT_NO_DEPRECATE + struct TORRENT_DEPRECATED TORRENT_EXPORT mmap_cache_alert TORRENT_FINAL : alert { mmap_cache_alert(aux::stack_allocator& alloc , error_code const& ec); @@ -1889,6 +1890,7 @@ namespace libtorrent error_code error; }; +#endif // The session_stats_alert is posted when the user requests session statistics by // calling post_session_stats() on the session object. Its category is diff --git a/include/libtorrent/disk_buffer_pool.hpp b/include/libtorrent/disk_buffer_pool.hpp index 79f46a169..6748d8e03 100644 --- a/include/libtorrent/disk_buffer_pool.hpp +++ b/include/libtorrent/disk_buffer_pool.hpp @@ -143,7 +143,7 @@ namespace libtorrent int m_cache_buffer_chunk_size; -#if TORRENT_HAVE_MMAP +#if TORRENT_HAVE_MMAP && !defined TORRENT_NO_DEPRECATE // the file descriptor of the cache mmap file int m_cache_fd; // the pointer to the block of virtual address space diff --git a/include/libtorrent/settings_pack.hpp b/include/libtorrent/settings_pack.hpp index 1608083ac..3a042c0ef 100644 --- a/include/libtorrent/settings_pack.hpp +++ b/include/libtorrent/settings_pack.hpp @@ -120,6 +120,7 @@ namespace libtorrent // omitted. announce_ip, +#ifndef TORRENT_NO_DEPRECATE // ``mmap_cache`` may be set to a filename where the disk cache will // be mmapped to. This could be useful, for instance, to map the disk // cache from regular rotating hard drives onto an SSD drive. Doing @@ -144,6 +145,9 @@ namespace libtorrent // This feature requires the ``mmap`` system call, on systems that // don't have ``mmap`` this setting is ignored. mmap_cache, +#else + deprecated12, +#endif // this is the client name and version identifier sent to peers in the // handshake message. If this is an empty string, the user_agent is diff --git a/src/alert.cpp b/src/alert.cpp index 465268176..6db3bce69 100644 --- a/src/alert.cpp +++ b/src/alert.cpp @@ -1349,6 +1349,7 @@ namespace libtorrent { return msg; } +#ifndef TORRENT_NO_DEPRECATE mmap_cache_alert::mmap_cache_alert(aux::stack_allocator& , error_code const& ec): error(ec) {} @@ -1360,6 +1361,7 @@ namespace libtorrent { , convert_from_native(error.message()).c_str()); return msg; } +#endif peer_error_alert::peer_error_alert(aux::stack_allocator& alloc, torrent_handle const& h , tcp::endpoint const& ep, peer_id const& peer_id, int op diff --git a/src/disk_buffer_pool.cpp b/src/disk_buffer_pool.cpp index f8442418e..d60127ee2 100644 --- a/src/disk_buffer_pool.cpp +++ b/src/disk_buffer_pool.cpp @@ -93,7 +93,7 @@ namespace libtorrent , m_exceeded_max_size(false) , m_ios(ios) , m_cache_buffer_chunk_size(0) -#if TORRENT_HAVE_MMAP +#if TORRENT_HAVE_MMAP && !defined TORRENT_NO_DEPRECATE , m_cache_fd(-1) , m_cache_pool(0) #endif @@ -116,7 +116,7 @@ namespace libtorrent m_magic = 0; #endif -#if TORRENT_HAVE_MMAP +#if TORRENT_HAVE_MMAP && !defined TORRENT_NO_DEPRECATE if (m_cache_pool) { munmap(m_cache_pool, boost::uint64_t(m_max_use) * 0x4000); @@ -175,7 +175,7 @@ namespace libtorrent TORRENT_ASSERT(l.locked()); TORRENT_UNUSED(l); -#if TORRENT_HAVE_MMAP +#if TORRENT_HAVE_MMAP && !defined TORRENT_NO_DEPRECATE if (m_cache_pool) { return buffer >= m_cache_pool && buffer < m_cache_pool @@ -270,7 +270,7 @@ namespace libtorrent TORRENT_UNUSED(l); char* ret; -#if TORRENT_HAVE_MMAP +#if TORRENT_HAVE_MMAP && !defined TORRENT_NO_DEPRECATE if (m_cache_pool) { if (m_free_list.size() <= (m_max_use - m_low_watermark) @@ -377,7 +377,7 @@ namespace libtorrent m_using_pool_allocator = m_want_pool_allocator; #endif -#if TORRENT_HAVE_MMAP +#if TORRENT_HAVE_MMAP && !defined TORRENT_NO_DEPRECATE // if we've already allocated an mmap, we can't change // anything unless there are no allocations in use if (m_cache_pool && m_in_use > 0) return; @@ -386,10 +386,13 @@ namespace libtorrent // only allow changing size if we're not using mmapped // cache, or if we're just about to turn it off if ( -#if TORRENT_HAVE_MMAP +#if TORRENT_HAVE_MMAP && !defined TORRENT_NO_DEPRECATE m_cache_pool == 0 || + sett.get_str(settings_pack::mmap_cache).empty() +#else + true #endif - sett.get_str(settings_pack::mmap_cache).empty()) + ) { int const cache_size = sett.get_int(settings_pack::cache_size); if (cache_size < 0) @@ -452,7 +455,7 @@ namespace libtorrent m_settings_set = true; #endif -#if TORRENT_HAVE_MMAP +#if TORRENT_HAVE_MMAP && !defined TORRENT_NO_DEPRECATE // #error support resizing the map if (m_cache_pool && sett.get_str(settings_pack::mmap_cache).empty()) { @@ -509,7 +512,7 @@ namespace libtorrent } } } -#endif +#endif // TORRENT_HAVE_MMAP } void disk_buffer_pool::free_buffer_impl(char* buf, mutex::scoped_lock& l) @@ -521,7 +524,7 @@ namespace libtorrent TORRENT_ASSERT(l.locked()); TORRENT_UNUSED(l); -#if TORRENT_HAVE_MMAP +#if TORRENT_HAVE_MMAP && !defined TORRENT_NO_DEPRECATE if (m_cache_pool) { TORRENT_ASSERT(buf >= m_cache_pool); diff --git a/src/disk_io_thread.cpp b/src/disk_io_thread.cpp index 64be2ebc3..886bfb408 100644 --- a/src/disk_io_thread.cpp +++ b/src/disk_io_thread.cpp @@ -282,10 +282,14 @@ namespace libtorrent apply_pack(pack, m_settings); error_code ec; m_disk_cache.set_settings(m_settings, ec); +#ifndef TORRENT_NO_DEPRECATE if (ec && alerts.should_post()) { alerts.emplace_alert(ec); } +#else + TORRENT_UNUSED(alerts); +#endif } // flush all blocks that are below p->hash.offset, since we've diff --git a/test/test_settings_pack.cpp b/test/test_settings_pack.cpp index bf05d52f8..5cebc9020 100644 --- a/test/test_settings_pack.cpp +++ b/test/test_settings_pack.cpp @@ -102,9 +102,9 @@ TORRENT_TEST(test_name) TEST_NAME(seeding_piece_quota); #ifndef TORRENT_NO_DEPRECATE TEST_NAME(half_open_limit); + TEST_NAME(mmap_cache); #endif TEST_NAME(peer_turnover_interval); - TEST_NAME(mmap_cache); } TORRENT_TEST(clear) From 7476f7875eac08699f646ba30971903ed5d62e12 Mon Sep 17 00:00:00 2001 From: Arvid Norberg Date: Sat, 29 Oct 2016 13:53:24 -0400 Subject: [PATCH 2/2] don't check file-sizes resume data for files that likely is in the partfile (#1268) --- ChangeLog | 1 + src/storage.cpp | 8 ++++++++ 2 files changed, 9 insertions(+) diff --git a/ChangeLog b/ChangeLog index 1ef192835..c65b47eb5 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,4 @@ + * fix resumedata check issue with files with priority 0 * deprecated mmap_cache feature * add utility function for generating peer ID fingerprint * fix bug in last-seen-complete diff --git a/src/storage.cpp b/src/storage.cpp index 64091f732..5ea984c19 100644 --- a/src/storage.cpp +++ b/src/storage.cpp @@ -1016,6 +1016,14 @@ namespace libtorrent for (int i = 0; i < file_sizes_ent.list_size(); ++i) { if (fs.pad_file_at(i)) continue; + + // files with priority zero may not have been saved to disk at their + // expected location, but is likely to be in a partfile. Just exempt it + // from checking + if (i < int(m_file_priority.size()) + && m_file_priority[i] == 0) + continue; + bdecode_node e = file_sizes_ent.list_at(i); if (e.type() != bdecode_node::list_t || e.list_size() < 2