]> git.apps.os.sepia.ceph.com Git - ceph.git/commitdiff
rbd: add persistent-cache flush command
authorYin Congmin <congmin.yin@intel.com>
Mon, 27 Dec 2021 07:06:49 +0000 (15:06 +0800)
committerIlya Dryomov <idryomov@gmail.com>
Wed, 13 Apr 2022 10:51:21 +0000 (12:51 +0200)
Add a flush command so that users can manually flush cache.

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

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

doc/rbd/rbd-persistent-write-back-cache.rst
src/test/cli/rbd/help.t
src/tools/rbd/action/PersistentCache.cc

index 5ac70714e709e90cf5a66cf8b97b25332326f624..8066014e997b0b74a99fcbf95382f8de3b54cdb2 100644 (file)
@@ -98,6 +98,21 @@ For example::
                 hit_bytes: 192 MiB / 66%
                 miss_bytes: 97 MiB
 
+Flush Cache
+-----------
+
+To flush a cache file with ``rbd``, specify the ``persistent-cache flush``
+command, the pool name and the image name.  ::
+
+        rbd persistent-cache flush {pool-name}/{image-name}
+
+If the application dies unexpectedly, this command can also be used to flush
+the cache back to OSDs.
+
+For example::
+
+        $ rbd persistent-cache flush rbd/foo
+
 Invalidate Cache
 ----------------
 
index 563c5571a4aa0f44c502fa8a66d1ba3bbc0f8df3..1eee504602cade195ea97678db57cb081890e81d 100644 (file)
       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 flush            Flush persistent cache.
       persistent-cache invalidate       Invalidate (discard) existing / dirty
                                         persistent cache.
       pool init                         Initialize pool for use by RBD.
     -p [ --pool ] arg    pool name
     --namespace arg      namespace name
   
+  rbd help persistent-cache flush
+  usage: rbd persistent-cache flush [--pool <pool>] [--namespace <namespace>] 
+                                    [--image <image>] [--image-id <image-id>] 
+                                    <image-spec> 
+  
+  Flush 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 persistent-cache invalidate
   usage: rbd persistent-cache invalidate
                                         [--pool <pool>] 
index 75ee8ed7d89764bd85cfe214b2c62ac2567fe14e..949006b828fc498edfcc72cb8e3414549de65392 100644 (file)
@@ -59,10 +59,63 @@ int execute_invalidate(const po::variables_map &vm,
   return 0;
 }
 
+void get_arguments_flush(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_flush(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;
+  }
+
+  uint64_t features;
+  r = image.features(&features);
+  if (r < 0) {
+    return r;
+  }
+
+  if (features & RBD_FEATURE_DIRTY_CACHE) {
+    r = image.flush();
+    if (r < 0) {
+      std::cerr << "rbd: flushing persistent cache failed: "
+                << cpp_strerror(r) << std::endl;
+      return r;
+    }
+  } else {
+    std::cout << "rbd: persistent cache is clean or disabled" << std::endl;
+  }
+
+  return 0;
+}
+
 Shell::Action action_invalidate(
   {"persistent-cache", "invalidate"}, {},
   "Invalidate (discard) existing / dirty persistent cache.", "",
   &get_arguments_invalidate, &execute_invalidate);
+Shell::Action action_flush(
+  {"persistent-cache", "flush"}, {}, "Flush persistent cache.", "",
+  &get_arguments_flush, &execute_flush);
 
 } // namespace persistent_cache
 } // namespace action