]> git.apps.os.sepia.ceph.com Git - ceph.git/commitdiff
rbd: rename image-cache invalidate command
authorYin Congmin <congmin.yin@intel.com>
Mon, 27 Dec 2021 03:50:18 +0000 (11:50 +0800)
committerIlya Dryomov <idryomov@gmail.com>
Wed, 13 Apr 2022 10:51:21 +0000 (12:51 +0200)
Rename command image-cache to persistent-cache. Refactoring the code
of invalidate command.

[ idryomov: error message, incorporate doc and help.t hunks, drop
  do_persistent_cache_invalidate() ]

Signed-off-by: Yin Congmin <congmin.yin@intel.com>
Signed-off-by: Ilya Dryomov <idryomov@gmail.com>
(cherry picked from commit 05bfe10ad9fde533aa728f9aa0cc8a8f155c03c5)

doc/rbd/rbd-persistent-write-back-cache.rst
src/test/cli/rbd/help.t
src/tools/rbd/CMakeLists.txt
src/tools/rbd/action/ImageCache.cc [deleted file]
src/tools/rbd/action/PersistentCache.cc [new file with mode: 0644]

index 6bf65f1a0f717a681fd79ea109c1be876571fe4a..5ac70714e709e90cf5a66cf8b97b25332326f624 100644 (file)
@@ -98,20 +98,20 @@ For example::
                 hit_bytes: 192 MiB / 66%
                 miss_bytes: 97 MiB
 
-Discard Cache
--------------
+Invalidate Cache
+----------------
 
-To discard a cache file with ``rbd``, specify the ``image-cache invalidate``
-option, the pool name and the image name.  ::
+To invalidate (discard) a cache file with ``rbd``, specify the
+``persistent-cache invalidate`` command, the pool name and the image name.  ::
 
-        rbd image-cache invalidate {pool-name}/{image-name}
+        rbd persistent-cache invalidate {pool-name}/{image-name}
 
-The command removes the cache metadata of the corresponding image, disable
+The command removes the cache metadata of the corresponding image, disables
 the cache feature and deletes the local cache file if it exists.
 
 For example::
 
-        $ rbd image-cache invalidate rbd/foo
+        $ rbd persistent-cache invalidate rbd/foo
 
 .. _section: ../../rados/configuration/ceph-conf/#configuration-sections
 .. _commands: ../../man/8/rbd#commands
index 2b4c14eeacecdd167967989ad1f49b258642e478..563c5571a4aa0f44c502fa8a66d1ba3bbc0f8df3 100644 (file)
@@ -55,7 +55,6 @@
       group snap remove (... rm)        Remove a snapshot from a group.
       group snap rename                 Rename group's snapshot.
       group snap rollback               Rollback group to snapshot.
-      image-cache invalidate            Discard existing / dirty image cache
       image-meta get                    Image metadata get the value associated
                                         with the key.
       image-meta list (image-meta ls)   Image metadata list keys with values.
       object-map rebuild                Rebuild an invalid object map.
       perf image iostat                 Display image IO statistics.
       perf image iotop                  Display a top-like IO monitor.
+      persistent-cache invalidate       Invalidate (discard) existing / dirty
+                                        persistent cache.
       pool init                         Initialize pool for use by RBD.
       pool stats                        Display pool statistics.
       remove (rm)                       Delete an image.
     --group arg          group name
     --snap arg           snapshot name
   
-  rbd help image-cache invalidate
-  usage: rbd image-cache invalidate [--pool <pool>] [--namespace <namespace>] 
-                                    [--image <image>] [--image-id <image-id>] 
-                                    <image-spec> 
-  
-  Discard existing / dirty image cache
-  
-  Positional arguments
-    <image-spec>         image specification
-                         (example: [<pool-name>/[<namespace>/]]<image-name>)
-  
-  Optional arguments
-    -p [ --pool ] arg    pool name
-    --namespace arg      namespace name
-    --image arg          image name
-    --image-id arg       image id
-  
   rbd help image-meta get
   usage: rbd image-meta get [--pool <pool>] [--namespace <namespace>] 
                             [--image <image>] 
     -p [ --pool ] arg    pool name
     --namespace arg      namespace name
   
+  rbd help persistent-cache invalidate
+  usage: rbd persistent-cache invalidate
+                                        [--pool <pool>] 
+                                        [--namespace <namespace>] 
+                                        [--image <image>] [--image-id <image-id>] 
+                                        <image-spec> 
+  
+  Invalidate (discard) existing / dirty persistent cache.
+  
+  Positional arguments
+    <image-spec>         image specification
+                         (example: [<pool-name>/[<namespace>/]]<image-name>)
+  
+  Optional arguments
+    -p [ --pool ] arg    pool name
+    --namespace arg      namespace name
+    --image arg          image name
+    --image-id arg       image id
+  
   rbd help pool init
   usage: rbd pool init [--pool <pool>] [--force] 
                        <pool-name> 
index 6fe867af3611cca4c5721c4f5cdda067cc71464b..5a895354d536519e9890061154a785b0f62b68f6 100644 (file)
@@ -26,7 +26,6 @@ set(rbd_srcs
   action/Flatten.cc
   action/Ggate.cc
   action/Group.cc
-  action/ImageCache.cc
   action/ImageMeta.cc
   action/Import.cc
   action/Info.cc
@@ -43,6 +42,7 @@ set(rbd_srcs
   action/Nbd.cc
   action/ObjectMap.cc
   action/Perf.cc
+  action/PersistentCache.cc
   action/Pool.cc
   action/Remove.cc
   action/Rename.cc
diff --git a/src/tools/rbd/action/ImageCache.cc b/src/tools/rbd/action/ImageCache.cc
deleted file mode 100644 (file)
index 0edd289..0000000
+++ /dev/null
@@ -1,71 +0,0 @@
-// -*- mode:C++; tab-width:8; c-basic-offset:2; indent-tabs-mode:t -*-
-// vim: ts=8 sw=2 smarttab
-
-#include "tools/rbd/ArgumentTypes.h"
-#include "tools/rbd/Shell.h"
-#include "tools/rbd/Utils.h"
-#include "include/types.h"
-#include "include/rbd_types.h"
-#include "include/stringify.h"
-#include "common/errno.h"
-#include "common/Formatter.h"
-#include <iostream>
-#include <boost/program_options.hpp>
-
-namespace rbd {
-namespace action {
-namespace image_cache {
-
-namespace at = argument_types;
-namespace po = boost::program_options;
-
-void get_arguments(po::options_description *positional,
-                   po::options_description *options) {
-  at::add_image_spec_options(positional, options,
-                               at::ARGUMENT_MODIFIER_NONE);
-  at::add_image_id_option(options);
-}
-
-int execute_discard(const po::variables_map &vm,
-                    const std::vector<std::string> &ceph_global_init_args) {
-  size_t arg_index = 0;
-  std::string pool_name;
-  std::string namespace_name;
-  std::string image_name;
-  int r = utils::get_pool_image_snapshot_names(
-    vm, at::ARGUMENT_MODIFIER_NONE, &arg_index, &pool_name, &namespace_name,
-    &image_name, nullptr, true, utils::SNAPSHOT_PRESENCE_NONE,
-    utils::SPEC_VALIDATION_NONE);
-  if (r < 0) {
-    return r;
-  }
-
-  librados::Rados rados;
-  librados::IoCtx io_ctx;
-  librbd::Image image;
-  r = utils::init_and_open_image(pool_name, namespace_name, image_name, "",
-                                 "", false, &rados, &io_ctx, &image);
-  if (r < 0) {
-    std::cerr << "rbd: failed to open image " << image_name << ": "
-              << cpp_strerror(r) << std::endl;
-    return r;
-  }
-
-  r = image.invalidate_cache();
-  if (r < 0) {
-    std::cerr << "rbd: failed to discard the cache of image " << image_name << ": "
-              << cpp_strerror(r) << std::endl;
-    return r;
-  }
-
-  image.close();
-  return 0;
-}
-
-Shell::Action action_discard(
-  {"image-cache", "invalidate"}, {}, "Discard existing / dirty image cache", "",
-  &get_arguments, &execute_discard);
-
-} // namespace image_cache
-} // namespace action
-} // namespace rbd
diff --git a/src/tools/rbd/action/PersistentCache.cc b/src/tools/rbd/action/PersistentCache.cc
new file mode 100644 (file)
index 0000000..75ee8ed
--- /dev/null
@@ -0,0 +1,69 @@
+// -*- mode:C++; tab-width:8; c-basic-offset:2; indent-tabs-mode:t -*-
+// vim: ts=8 sw=2 smarttab
+
+#include "tools/rbd/ArgumentTypes.h"
+#include "tools/rbd/Shell.h"
+#include "tools/rbd/Utils.h"
+#include "include/types.h"
+#include "include/rbd_types.h"
+#include "include/stringify.h"
+#include "common/errno.h"
+#include "common/Formatter.h"
+#include <iostream>
+#include <boost/program_options.hpp>
+
+namespace rbd {
+namespace action {
+namespace persistent_cache {
+
+namespace at = argument_types;
+namespace po = boost::program_options;
+
+void get_arguments_invalidate(po::options_description *positional,
+                              po::options_description *options) {
+  at::add_image_spec_options(positional, options, at::ARGUMENT_MODIFIER_NONE);
+  at::add_image_id_option(options);
+}
+
+int execute_invalidate(const po::variables_map &vm,
+                       const std::vector<std::string> &ceph_global_init_args) {
+  size_t arg_index = 0;
+  std::string pool_name;
+  std::string namespace_name;
+  std::string image_name;
+  std::string snap_name;
+  int r = utils::get_pool_image_snapshot_names(
+    vm, at::ARGUMENT_MODIFIER_NONE, &arg_index, &pool_name, &namespace_name,
+    &image_name, &snap_name, true, utils::SNAPSHOT_PRESENCE_NONE,
+    utils::SPEC_VALIDATION_NONE);
+  if (r < 0) {
+    return r;
+  }
+
+  librados::Rados rados;
+  librados::IoCtx io_ctx;
+  librbd::Image image;
+  r = utils::init_and_open_image(pool_name, namespace_name, image_name, "", "",
+                                 false, &rados, &io_ctx, &image);
+  if (r < 0) {
+    return r;
+  }
+
+  r = image.invalidate_cache();
+  if (r < 0) {
+    std::cerr << "rbd: invalidating persistent cache failed: "
+              << cpp_strerror(r) << std::endl;
+    return r;
+  }
+
+  return 0;
+}
+
+Shell::Action action_invalidate(
+  {"persistent-cache", "invalidate"}, {},
+  "Invalidate (discard) existing / dirty persistent cache.", "",
+  &get_arguments_invalidate, &execute_invalidate);
+
+} // namespace persistent_cache
+} // namespace action
+} // namespace rbd