From bd66fdda910f02ffe91bb026f82a85f28a6ff225 Mon Sep 17 00:00:00 2001 From: Yin Congmin Date: Wed, 22 Dec 2021 15:07:11 +0800 Subject: [PATCH] librbd/cache/pwl: rename persistent cache key librbd "internal" metadata keys was change to ".rbd" prefix. Change peristent cache to ".rbd" too. And the name of persistent cache key is IMAGE_CACHE_STATE. Since this key is planned to be used outside the pwl directory, it seems more appropriate to change it to a clear name as PERSISTENT_CACHE_STATE. Signed-off-by: Yin Congmin --- src/librbd/cache/Types.h | 2 +- src/librbd/cache/pwl/ImageCacheState.cc | 8 ++++---- src/librbd/cache/pwl/ShutdownRequest.cc | 2 +- src/tools/rbd/action/Status.cc | 9 ++------- 4 files changed, 8 insertions(+), 13 deletions(-) diff --git a/src/librbd/cache/Types.h b/src/librbd/cache/Types.h index b791d590873..43dcd758f0b 100644 --- a/src/librbd/cache/Types.h +++ b/src/librbd/cache/Types.h @@ -20,7 +20,7 @@ enum ImageCacheType { typedef std::list Contexts; -const std::string IMAGE_CACHE_STATE = ".librbd/image_cache_state"; +const std::string PERSISTENT_CACHE_STATE = ".rbd_persistent_cache_state"; } // namespace cache } // namespace librbd diff --git a/src/librbd/cache/pwl/ImageCacheState.cc b/src/librbd/cache/pwl/ImageCacheState.cc index 1dd81e6480c..fe6e1087d05 100644 --- a/src/librbd/cache/pwl/ImageCacheState.cc +++ b/src/librbd/cache/pwl/ImageCacheState.cc @@ -85,7 +85,7 @@ void ImageCacheState::write_image_cache_state(Context *on_finish) { ldout(m_image_ctx->cct, 20) << __func__ << " Store state: " << image_state_json << dendl; - m_plugin_api.execute_image_metadata_set(m_image_ctx, IMAGE_CACHE_STATE, + m_plugin_api.execute_image_metadata_set(m_image_ctx, PERSISTENT_CACHE_STATE, image_state_json, on_finish); } @@ -94,7 +94,7 @@ void ImageCacheState::clear_image_cache_state(Context *on_finish) { std::shared_lock owner_lock{m_image_ctx->owner_lock}; ldout(m_image_ctx->cct, 20) << __func__ << " Remove state: " << dendl; m_plugin_api.execute_image_metadata_remove( - m_image_ctx, IMAGE_CACHE_STATE, on_finish); + m_image_ctx, PERSISTENT_CACHE_STATE, on_finish); } template @@ -107,7 +107,7 @@ ImageCacheState* ImageCacheState::create_image_cache_state( bool dirty_cache = plugin_api.test_image_features(image_ctx, RBD_FEATURE_DIRTY_CACHE); if (dirty_cache) { cls_client::metadata_get(&image_ctx->md_ctx, image_ctx->header_oid, - IMAGE_CACHE_STATE, &cache_state_str); + PERSISTENT_CACHE_STATE, &cache_state_str); } ldout(image_ctx->cct, 20) << "image_cache_state: " << cache_state_str << dendl; @@ -155,7 +155,7 @@ ImageCacheState* ImageCacheState::get_image_cache_state( ImageCacheState* cache_state = nullptr; string cache_state_str; cls_client::metadata_get(&image_ctx->md_ctx, image_ctx->header_oid, - IMAGE_CACHE_STATE, &cache_state_str); + PERSISTENT_CACHE_STATE, &cache_state_str); if (!cache_state_str.empty()) { // ignore errors, best effort cache_state = new ImageCacheState(image_ctx, plugin_api); diff --git a/src/librbd/cache/pwl/ShutdownRequest.cc b/src/librbd/cache/pwl/ShutdownRequest.cc index 4475712dd6b..e022328ba70 100644 --- a/src/librbd/cache/pwl/ShutdownRequest.cc +++ b/src/librbd/cache/pwl/ShutdownRequest.cc @@ -132,7 +132,7 @@ void ShutdownRequest::send_remove_image_cache_state() { Context *ctx = create_context_callback( this); std::shared_lock owner_lock{m_image_ctx.owner_lock}; - m_plugin_api.execute_image_metadata_remove(&m_image_ctx, IMAGE_CACHE_STATE, ctx); + m_plugin_api.execute_image_metadata_remove(&m_image_ctx, PERSISTENT_CACHE_STATE, ctx); } template diff --git a/src/tools/rbd/action/Status.cc b/src/tools/rbd/action/Status.cc index 4cc01c62821..958a686c416 100644 --- a/src/tools/rbd/action/Status.cc +++ b/src/tools/rbd/action/Status.cc @@ -9,6 +9,7 @@ #include "tools/rbd/Utils.h" #include "include/rbd_types.h" #include "include/stringify.h" +#include "librbd/cache/Types.h" #include #include @@ -19,12 +20,6 @@ namespace status { namespace at = argument_types; namespace po = boost::program_options; -namespace { - -const std::string IMAGE_CACHE_STATE = ".librbd/image_cache_state"; - -} // anonymous namespace - static int do_show_status(librados::IoCtx& io_ctx, const std::string &image_name, librbd::Image &image, Formatter *f) { @@ -133,7 +128,7 @@ static int do_show_status(librados::IoCtx& io_ctx, const std::string &image_name } cache_state; std::string cache_str; if (features & RBD_FEATURE_DIRTY_CACHE) { - r = image.metadata_get(IMAGE_CACHE_STATE, &cache_str); + r = image.metadata_get(librbd::cache::PERSISTENT_CACHE_STATE, &cache_str); if (r < 0) { std::cerr << "rbd: getting persistent cache state failed: " << cpp_strerror(r) << std::endl; -- 2.39.5