From: Yin Congmin Date: Thu, 11 Nov 2021 09:13:44 +0000 (+0800) Subject: librbd/cache/pwl/rwl: add pmemobj_close() during error handle X-Git-Tag: v17.1.0~124^2~4 X-Git-Url: http://git-server-git.apps.pok.os.sepia.ceph.com/?a=commitdiff_plain;h=265cedbf360f4b87ee73b26ef16b19c3921e032b;p=ceph-ci.git librbd/cache/pwl/rwl: add pmemobj_close() during error handle After create/open pmem device, add pmemobj_close() during error handle. Merge the same error handle to the end of function. Signed-off-by: Yin Congmin --- diff --git a/src/librbd/cache/pwl/rwl/WriteLog.cc b/src/librbd/cache/pwl/rwl/WriteLog.cc index 3e3d8ad6d32..c340fe6a8c8 100644 --- a/src/librbd/cache/pwl/rwl/WriteLog.cc +++ b/src/librbd/cache/pwl/rwl/WriteLog.cc @@ -261,6 +261,7 @@ void WriteLog::remove_pool_file() { template bool WriteLog::initialize_pool(Context *on_finish, pwl::DeferredContexts &later) { CephContext *cct = m_image_ctx.cct; + int r = -EINVAL; TOID(struct WriteLogPoolRoot) pool_root; ceph_assert(ceph_mutex_is_locked_by_me(m_lock)); if (access(this->m_log_pool_name.c_str(), F_OK) != 0) { @@ -292,8 +293,7 @@ bool WriteLog::initialize_pool(Context *on_finish, pwl::DeferredContexts &lat } if (num_small_writes <= 2) { lderr(cct) << "num_small_writes needs to > 2" << dendl; - on_finish->complete(-EINVAL); - return false; + goto err_close_pool; } this->m_bytes_allocated_cap = effective_pool_size; /* Log ring empty */ @@ -318,8 +318,8 @@ bool WriteLog::initialize_pool(Context *on_finish, pwl::DeferredContexts &lat this->m_total_log_entries = 0; this->m_free_log_entries = 0; lderr(cct) << "failed to initialize pool (" << this->m_log_pool_name << ")" << dendl; - on_finish->complete(-pmemobj_tx_errno()); - return false; + r = -pmemobj_tx_errno(); + goto err_close_pool; } TX_FINALLY { } TX_END; } else { @@ -339,14 +339,12 @@ bool WriteLog::initialize_pool(Context *on_finish, pwl::DeferredContexts &lat lderr(cct) << "Pool layout version is " << D_RO(pool_root)->header.layout_version << " expected " << RWL_LAYOUT_VERSION << dendl; - on_finish->complete(-EINVAL); - return false; + goto err_close_pool; } if (D_RO(pool_root)->block_size != MIN_WRITE_ALLOC_SIZE) { lderr(cct) << "Pool block size is " << D_RO(pool_root)->block_size << " expected " << MIN_WRITE_ALLOC_SIZE << dendl; - on_finish->complete(-EINVAL); - return false; + goto err_close_pool; } this->m_log_pool_size = D_RO(pool_root)->pool_size; this->m_flushed_sync_gen = D_RO(pool_root)->flushed_sync_gen; @@ -371,6 +369,11 @@ bool WriteLog::initialize_pool(Context *on_finish, pwl::DeferredContexts &lat m_cache_state->empty = m_log_entries.empty(); } return true; + +err_close_pool: + pmemobj_close(m_log_pool); + on_finish->complete(r); + return false; } /* diff --git a/src/librbd/cache/pwl/ssd/WriteLog.cc b/src/librbd/cache/pwl/ssd/WriteLog.cc index 62e98e5dfe8..b537ce948a6 100644 --- a/src/librbd/cache/pwl/ssd/WriteLog.cc +++ b/src/librbd/cache/pwl/ssd/WriteLog.cc @@ -210,7 +210,7 @@ bool WriteLog::initialize_pool(Context *on_finish, r = bdev->read(0, MIN_WRITE_ALLOC_SSD_SIZE, &bl, &ioctx, false); if (r < 0) { lderr(cct) << "Read ssd cache superblock failed " << dendl; - goto error_handle; + goto err_close_bdev; } auto p = bl.cbegin(); decode(superblock, p); @@ -226,13 +226,13 @@ bool WriteLog::initialize_pool(Context *on_finish, << pool_root.layout_version << " expected " << SSD_LAYOUT_VERSION << dendl; - goto error_handle; + goto err_close_bdev; } if (pool_root.block_size != MIN_WRITE_ALLOC_SSD_SIZE) { lderr(cct) << "Pool block size is " << pool_root.block_size << " expected " << MIN_WRITE_ALLOC_SSD_SIZE << dendl; - goto error_handle; + goto err_close_bdev; } this->m_log_pool_size = pool_root.pool_size; @@ -249,7 +249,7 @@ bool WriteLog::initialize_pool(Context *on_finish, } return true; -error_handle: +err_close_bdev: bdev->close(); delete bdev; on_finish->complete(-EINVAL);