From 5f2ffc12eea2c1695c1da0c4f14abc380092652d Mon Sep 17 00:00:00 2001 From: lixiaoy1 Date: Sat, 10 Oct 2020 09:38:20 -0400 Subject: [PATCH] rbd/cache: save full cach path instead of folder Signed-off-by: Li, Xiaoyan --- src/librbd/cache/pwl/AbstractWriteLog.cc | 23 +++++++++++++++++------ src/librbd/cache/pwl/ImageCacheState.cc | 7 ++----- src/librbd/cache/pwl/ImageCacheState.h | 4 ++-- 3 files changed, 21 insertions(+), 13 deletions(-) diff --git a/src/librbd/cache/pwl/AbstractWriteLog.cc b/src/librbd/cache/pwl/AbstractWriteLog.cc index a3a0a33fb29..f1e5ed702c9 100644 --- a/src/librbd/cache/pwl/AbstractWriteLog.cc +++ b/src/librbd/cache/pwl/AbstractWriteLog.cc @@ -9,6 +9,7 @@ #include "common/dout.h" #include "common/environment.h" #include "common/errno.h" +#include "common/hostname.h" #include "common/WorkQueue.h" #include "common/Timer.h" #include "common/perf_counters.h" @@ -487,14 +488,20 @@ void AbstractWriteLog::pwl_init(Context *on_finish, DeferredContexts &later) std::lock_guard locker(m_lock); ceph_assert(!m_initialized); ldout(cct,5) << "image name: " << m_image_ctx.name << " id: " << m_image_ctx.id << dendl; - ldout(cct,5) << "pwl_size: " << m_cache_state->size << dendl; - std::string pwl_path = m_cache_state->path; - ldout(cct,5) << "pwl_path: " << pwl_path << dendl; - std::string pool_name = m_image_ctx.md_ctx.get_pool_name(); - std::string log_pool_name = pwl_path + "/rbd-pwl." + pool_name + "." + m_image_ctx.id + ".pool"; - m_log_pool_name = log_pool_name; + if (!m_cache_state->present) { + m_cache_state->host = ceph_get_short_hostname(); + m_cache_state->size = m_image_ctx.config.template get_val("rbd_rwl_size"); + + string path = m_image_ctx.config.template get_val("rbd_rwl_path"); + std::string pool_name = m_image_ctx.md_ctx.get_pool_name(); + m_cache_state->path = path + "/rbd-pwl." + pool_name + "." + m_image_ctx.id + ".pool"; + } + + ldout(cct,5) << "pwl_size: " << m_cache_state->size << dendl; + ldout(cct,5) << "pwl_path: " << m_cache_state->path << dendl; + m_log_pool_name = m_cache_state->path; m_log_pool_config_size = max(m_cache_state->size, MIN_POOL_SIZE); if ((!m_cache_state->present) && @@ -509,6 +516,10 @@ void AbstractWriteLog::pwl_init(Context *on_finish, DeferredContexts &later) } else { ldout(cct, 5) << "Removed the existing pool file." << dendl; } + } else if ((m_cache_state->present) && + (access(m_log_pool_name.c_str(), F_OK) != 0)) { + ldout(cct, 5) << "Can't find the existed pool file " << m_log_pool_name << dendl; + on_finish->complete(-errno); } initialize_pool(on_finish, later); diff --git a/src/librbd/cache/pwl/ImageCacheState.cc b/src/librbd/cache/pwl/ImageCacheState.cc index 5f2ac52f0dd..b36896a6915 100644 --- a/src/librbd/cache/pwl/ImageCacheState.cc +++ b/src/librbd/cache/pwl/ImageCacheState.cc @@ -6,10 +6,10 @@ #include "librbd/cache/pwl/ImageCacheState.h" #include "librbd/ImageCtx.h" #include "librbd/Operations.h" -#include "common/environment.h" -#include "common/hostname.h" #include "common/config_proxy.h" #include "common/ceph_json.h" +#include "common/environment.h" +#include "common/hostname.h" #undef dout_subsys #define dout_subsys ceph_subsys_rbd_pwl @@ -38,9 +38,6 @@ ImageCacheState::ImageCacheState(I *image_ctx) : m_image_ctx(image_ctx) { << dendl; ConfigProxy &config = image_ctx->config; - host = ceph_get_short_hostname(); - path = config.get_val("rbd_rwl_path"); - size = config.get_val("rbd_rwl_size"); log_periodic_stats = config.get_val("rbd_rwl_log_periodic_stats"); } diff --git a/src/librbd/cache/pwl/ImageCacheState.h b/src/librbd/cache/pwl/ImageCacheState.h index 2bdf31ffeed..bdc8cb080ff 100644 --- a/src/librbd/cache/pwl/ImageCacheState.h +++ b/src/librbd/cache/pwl/ImageCacheState.h @@ -22,12 +22,12 @@ class ImageCacheState { private: ImageCtxT* m_image_ctx; public: - bool present = true; + bool present = false; bool empty = true; bool clean = true; std::string host; std::string path; - uint64_t size; + uint64_t size = 0; bool log_periodic_stats; ImageCacheState(ImageCtxT* image_ctx); -- 2.39.5