From: lixiaoy1 Date: Thu, 20 Aug 2020 16:23:44 +0000 (-0400) Subject: rbd/tool: add image-cache invalidate X-Git-Tag: v17.0.0~746^2 X-Git-Url: http://git.apps.os.sepia.ceph.com/?a=commitdiff_plain;h=33b961e9a11e1ab3d5e5d39828579e82fcfa70b3;p=ceph-ci.git rbd/tool: add image-cache invalidate Add an rbd command image-cache invalidate to discard RWL cache. Signed-off-by: Peterson, Scott Signed-off-by: Li, Xiaoyan Signed-off-by: Lu, Yuan Signed-off-by: Chamarthy, Mahati --- diff --git a/src/test/cli/rbd/help.t b/src/test/cli/rbd/help.t index 6fa03762ce2..aeb1620a36e 100644 --- a/src/test/cli/rbd/help.t +++ b/src/test/cli/rbd/help.t @@ -52,6 +52,7 @@ 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. @@ -1022,6 +1023,23 @@ --group arg group name --snap arg snapshot name + rbd help image-cache invalidate + usage: rbd image-cache invalidate [--pool ] [--namespace ] + [--image ] [--image-id ] + + + Discard existing / dirty image cache + + Positional arguments + image specification + (example: [/[/]]) + + 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 ] [--namespace ] [--image ] diff --git a/src/tools/rbd/CMakeLists.txt b/src/tools/rbd/CMakeLists.txt index f1ee02c2ba8..eda58e6b8a8 100644 --- a/src/tools/rbd/CMakeLists.txt +++ b/src/tools/rbd/CMakeLists.txt @@ -25,6 +25,7 @@ set(rbd_srcs action/Flatten.cc action/Ggate.cc action/Group.cc + action/ImageCache.cc action/ImageMeta.cc action/Import.cc action/Info.cc diff --git a/src/tools/rbd/action/ImageCache.cc b/src/tools/rbd/action/ImageCache.cc new file mode 100644 index 00000000000..0edd2893125 --- /dev/null +++ b/src/tools/rbd/action/ImageCache.cc @@ -0,0 +1,71 @@ +// -*- 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 +#include + +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 &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