diff --git a/src/lib/device/device.h b/src/lib/device/device.h index 0dc483670..607211b5d 100644 --- a/src/lib/device/device.h +++ b/src/lib/device/device.h @@ -159,15 +159,15 @@ class DeviceManager { const Chunk* get_chunk(uint32_t chunk_id) const { std::unique_lock lg{m_vdev_mutex}; - // if a pdev is misssing when restart, chunk_id from cleint might be larger than m_chunks.size() - if (chunk_id == INVALID_CHUNK_ID || chunk_id >= m_chunks.size()) return nullptr; + // if a pdev is misssing when restart, chunk_id from client might be larger than m_chunks.size() + if (!m_chunks.index_exists(chunk_id)) return nullptr; return m_chunks[chunk_id].get(); } Chunk* get_chunk_mutable(uint32_t chunk_id) { std::unique_lock lg{m_vdev_mutex}; // if a pdev is misssing when restart, chunk_id from client might be larger than m_chunks.size() - if (chunk_id == INVALID_CHUNK_ID || chunk_id >= m_chunks.size()) return nullptr; + if (!m_chunks.index_exists(chunk_id)) return nullptr; return m_chunks[chunk_id].get(); } diff --git a/src/lib/device/virtual_dev.cpp b/src/lib/device/virtual_dev.cpp index 61cf4487a..23e6fe2aa 100644 --- a/src/lib/device/virtual_dev.cpp +++ b/src/lib/device/virtual_dev.cpp @@ -335,7 +335,7 @@ folly::Future< std::error_code > VirtualDev::async_write(const char* buf, uint32 folly::Future< std::error_code > VirtualDev::async_write(const char* buf, uint32_t size, cshared< Chunk >& chunk, uint64_t offset_in_chunk) { - if (sisl_unlikely(!is_chunk_loaded(chunk))) { + if (sisl_unlikely(!is_chunk_available(chunk))) { return folly::makeFuture< std::error_code >(std::make_error_code(std::errc::resource_unavailable_try_again)); } auto const dev_offset = chunk->start_offset() + offset_in_chunk; @@ -371,7 +371,7 @@ folly::Future< std::error_code > VirtualDev::async_writev(const iovec* iov, cons folly::Future< std::error_code > VirtualDev::async_writev(const iovec* iov, const int iovcnt, cshared< Chunk >& chunk, uint64_t offset_in_chunk) { - if (sisl_unlikely(!is_chunk_loaded(chunk))) { + if (sisl_unlikely(!is_chunk_available(chunk))) { return folly::makeFuture< std::error_code >(std::make_error_code(std::errc::resource_unavailable_try_again)); } auto const dev_offset = chunk->start_offset() + offset_in_chunk; @@ -400,7 +400,7 @@ std::error_code VirtualDev::sync_write(const char* buf, uint32_t size, BlkId con std::error_code VirtualDev::sync_write(const char* buf, uint32_t size, cshared< Chunk >& chunk, uint64_t offset_in_chunk) { - if (sisl_unlikely(!is_chunk_loaded(chunk))) { + if (sisl_unlikely(!is_chunk_available(chunk))) { return std::make_error_code(std::errc::resource_unavailable_try_again); } return chunk->physical_dev_mutable()->sync_write(buf, size, chunk->start_offset() + offset_in_chunk); @@ -427,7 +427,7 @@ std::error_code VirtualDev::sync_writev(const iovec* iov, int iovcnt, BlkId cons std::error_code VirtualDev::sync_writev(const iovec* iov, int iovcnt, cshared< Chunk >& chunk, uint64_t offset_in_chunk) { - if (sisl_unlikely(!is_chunk_loaded(chunk))) { + if (sisl_unlikely(!is_chunk_available(chunk))) { return std::make_error_code(std::errc::resource_unavailable_try_again); } uint64_t const dev_offset = chunk->start_offset() + offset_in_chunk; @@ -482,7 +482,7 @@ std::error_code VirtualDev::sync_read(char* buf, uint32_t size, BlkId const& bid } std::error_code VirtualDev::sync_read(char* buf, uint32_t size, cshared< Chunk >& chunk, uint64_t offset_in_chunk) { - if (sisl_unlikely(!is_chunk_loaded(chunk))) { + if (sisl_unlikely(!is_chunk_available(chunk))) { return std::make_error_code(std::errc::resource_unavailable_try_again); } return chunk->physical_dev_mutable()->sync_read(buf, size, chunk->start_offset() + offset_in_chunk); @@ -508,7 +508,7 @@ std::error_code VirtualDev::sync_readv(iovec* iov, int iovcnt, BlkId const& bid) } std::error_code VirtualDev::sync_readv(iovec* iov, int iovcnt, cshared< Chunk >& chunk, uint64_t offset_in_chunk) { - if (sisl_unlikely(!is_chunk_loaded(chunk))) { + if (sisl_unlikely(!is_chunk_available(chunk))) { return std::make_error_code(std::errc::resource_unavailable_try_again); } uint64_t const dev_offset = chunk->start_offset() + offset_in_chunk; @@ -652,7 +652,7 @@ uint64_t VirtualDev::to_dev_offset(BlkId const& b, Chunk** chunk) const { return uint64_cast(b.blk_num()) * block_size() + uint64_cast((*chunk)->start_offset()); } -bool VirtualDev::is_chunk_loaded(cshared< Chunk >& chunk) const { +bool VirtualDev::is_chunk_available(cshared< Chunk >& chunk) const { return m_dmgr.get_chunk(chunk->chunk_id()) != nullptr; } diff --git a/src/lib/device/virtual_dev.hpp b/src/lib/device/virtual_dev.hpp index 88dddeba0..cced52473 100644 --- a/src/lib/device/virtual_dev.hpp +++ b/src/lib/device/virtual_dev.hpp @@ -299,7 +299,7 @@ class VirtualDev { private: uint64_t to_dev_offset(BlkId const& b, Chunk** chunk) const; - bool is_chunk_loaded(cshared< Chunk >& chunk) const; + bool is_chunk_available(cshared< Chunk >& chunk) const; BlkAllocStatus alloc_blks_from_chunk(blk_count_t nblks, blk_alloc_hints const& hints, MultiBlkId& out_blkid, Chunk* chunk); };