Skip to content

Commit

Permalink
address comments
Browse files Browse the repository at this point in the history
  • Loading branch information
JacksonYao287 committed May 8, 2024
1 parent dc2f760 commit a7de024
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 11 deletions.
6 changes: 3 additions & 3 deletions src/lib/device/device.h
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}

Expand Down
14 changes: 7 additions & 7 deletions src/lib/device/virtual_dev.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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);
Expand All @@ -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;
Expand Down Expand Up @@ -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);
Expand All @@ -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;
Expand Down Expand Up @@ -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;
}

Expand Down
2 changes: 1 addition & 1 deletion src/lib/device/virtual_dev.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
};
Expand Down

0 comments on commit a7de024

Please sign in to comment.