Skip to content

Commit

Permalink
librbd/cache/pwl/ssd: ensure bdev and pool sizes match
Browse files Browse the repository at this point in the history
m_log_pool_size should be multiple of 1M but, just in case, prevent
is_valid_io() assert in KernelDevice::aio_write().

Signed-off-by: Ilya Dryomov <[email protected]>
  • Loading branch information
idryomov committed Aug 17, 2021
1 parent 1fc722b commit 41b95ac
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 11 deletions.
41 changes: 30 additions & 11 deletions src/librbd/cache/pwl/ssd/WriteLog.cc
Original file line number Diff line number Diff line change
Expand Up @@ -94,10 +94,37 @@ void WriteLog<I>::complete_read(
}
}

template <typename I>
int WriteLog<I>::create_and_open_bdev() {
CephContext *cct = m_image_ctx.cct;

bdev = BlockDevice::create(cct, this->m_log_pool_name, aio_cache_cb,
nullptr, nullptr, nullptr);
int r = bdev->open(this->m_log_pool_name);
if (r < 0) {
lderr(cct) << "failed to open bdev" << dendl;
delete bdev;
return r;
}

ceph_assert(this->m_log_pool_size % MIN_WRITE_ALLOC_SSD_SIZE == 0);
if (bdev->get_size() != this->m_log_pool_size) {
lderr(cct) << "size mismatch: bdev size " << bdev->get_size()
<< " (block size " << bdev->get_block_size()
<< ") != pool size " << this->m_log_pool_size << dendl;
bdev->close();
delete bdev;
return -EINVAL;
}

return 0;
}

template <typename I>
bool WriteLog<I>::initialize_pool(Context *on_finish,
pwl::DeferredContexts &later) {
CephContext *cct = m_image_ctx.cct;
int r;

ceph_assert(ceph_mutex_is_locked_by_me(m_lock));
if (access(this->m_log_pool_name.c_str(), F_OK) != 0) {
int fd = ::open(this->m_log_pool_name.c_str(), O_RDWR|O_CREAT, 0644);
Expand All @@ -120,12 +147,8 @@ bool WriteLog<I>::initialize_pool(Context *on_finish,
return false;
}

bdev = BlockDevice::create(cct, this->m_log_pool_name, aio_cache_cb,
nullptr, nullptr, nullptr);
int r = bdev->open(this->m_log_pool_name);
r = create_and_open_bdev();
if (r < 0) {
lderr(m_image_ctx.cct) << "fail to open block device." << dendl;
delete bdev;
on_finish->complete(r);
return false;
}
Expand Down Expand Up @@ -164,12 +187,8 @@ bool WriteLog<I>::initialize_pool(Context *on_finish,
}
} else {
m_cache_state->present = true;
bdev = BlockDevice::create(
cct, this->m_log_pool_name, aio_cache_cb,
static_cast<void*>(this), nullptr, static_cast<void*>(this));
int r = bdev->open(this->m_log_pool_name);
r = create_and_open_bdev();
if (r < 0) {
delete bdev;
on_finish->complete(r);
return false;
}
Expand Down
1 change: 1 addition & 0 deletions src/librbd/cache/pwl/ssd/WriteLog.h
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,7 @@ class WriteLog : public AbstractWriteLog<ImageCtxT> {
Builder<This> *m_builderobj;

Builder<This>* create_builder();
int create_and_open_bdev();
void load_existing_entries(pwl::DeferredContexts &later);
void collect_read_extents(
uint64_t read_buffer_offset, LogMapEntry<GenericWriteLogEntry> map_entry,
Expand Down

0 comments on commit 41b95ac

Please sign in to comment.