From 4b6a73417df271762735a63f05180ecfc8296b7d Mon Sep 17 00:00:00 2001 From: Arvid Norberg Date: Mon, 18 Oct 2010 07:38:14 +0000 Subject: [PATCH] fixed error reporting issue in disk I/O thread --- ChangeLog | 1 + src/disk_io_thread.cpp | 18 ++++++++++++++++++ src/storage.cpp | 2 ++ 3 files changed, 21 insertions(+) diff --git a/ChangeLog b/ChangeLog index 8e5a7dee8..fa2fd39a7 100644 --- a/ChangeLog +++ b/ChangeLog @@ -53,6 +53,7 @@ * added more detailed instrumentation of the disk I/O thread + * fixed error reporting issue in disk I/O thread * fixed file allocation issues on linux * fixed filename encoding and decoding issue on platforms using iconv * reports redundant downloads to tracker, fixed downloaded calculation to diff --git a/src/disk_io_thread.cpp b/src/disk_io_thread.cpp index c0a2277c8..d2ae5c706 100644 --- a/src/disk_io_thread.cpp +++ b/src/disk_io_thread.cpp @@ -2036,10 +2036,15 @@ namespace libtorrent mutex::scoped_lock l(m_piece_mutex); INVARIANT_CHECK; + TORRENT_ASSERT(!j.storage->error()); TORRENT_ASSERT(j.cache_min_time >= 0); if (in_use() >= m_settings.cache_size) + { flush_cache_blocks(l, in_use() - m_settings.cache_size + 1); + if (test_error(j)) break; + } + TORRENT_ASSERT(!j.storage->error()); cache_piece_index_t& idx = m_pieces.get<0>(); cache_piece_index_t::iterator p = find_cached_piece(m_pieces, j, l); @@ -2068,9 +2073,12 @@ namespace libtorrent flush_contiguous_blocks(const_cast(*p) , l, m_settings.write_cache_line_size); if (p->num_blocks == 0) idx.erase(p); + test_error(j); + TORRENT_ASSERT(!j.storage->error()); } else { + TORRENT_ASSERT(!j.storage->error()); if (cache_block(j, j.callback, j.cache_min_time, l) < 0) { l.unlock(); @@ -2082,8 +2090,11 @@ namespace libtorrent test_error(j); break; } + // we successfully wrote the block. Ignore previous errors + j.storage->clear_error(); break; } + TORRENT_ASSERT(!j.storage->error()); } // we've now inserted the buffer // in the cache, we should not @@ -2091,7 +2102,11 @@ namespace libtorrent holder.release(); if (in_use() > m_settings.cache_size) + { flush_cache_blocks(l, in_use() - m_settings.cache_size); + test_error(j); + } + TORRENT_ASSERT(!j.storage->error()); break; } @@ -2123,6 +2138,7 @@ namespace libtorrent #ifdef TORRENT_DISK_STATS m_log << log_time() << " hash" << std::endl; #endif + TORRENT_ASSERT(!j.storage->error()); mutex::scoped_lock l(m_piece_mutex); INVARIANT_CHECK; @@ -2374,6 +2390,8 @@ namespace libtorrent } #endif + TORRENT_ASSERT(!j.storage || !j.storage->error()); + // if (!j.callback) std::cerr << "DISK THREAD: no callback specified" << std::endl; // else std::cerr << "DISK THREAD: invoking callback" << std::endl; #ifndef BOOST_NO_EXCEPTIONS diff --git a/src/storage.cpp b/src/storage.cpp index 97c7dc0d6..ae016cb53 100644 --- a/src/storage.cpp +++ b/src/storage.cpp @@ -1647,6 +1647,8 @@ ret: sha1_hash piece_manager::hash_for_piece_impl(int piece) { + TORRENT_ASSERT(!m_storage->error()); + partial_hash ph; std::map::iterator i = m_piece_hasher.find(piece);