]> git.apps.os.sepia.ceph.com Git - ceph.git/commitdiff
librbd: optionally move image to trash when removed by user
authorJason Dillaman <dillaman@redhat.com>
Mon, 8 Oct 2018 14:46:18 +0000 (10:46 -0400)
committerJason Dillaman <dillaman@redhat.com>
Wed, 10 Oct 2018 13:08:02 +0000 (09:08 -0400)
Signed-off-by: Jason Dillaman <dillaman@redhat.com>
src/common/options.cc
src/librbd/api/Image.cc

index 99211a2740109b201db50224d8a5b544315242f2..ffed4884eff31baeebb2d85a8150b548a4df7811 100644 (file)
@@ -6555,6 +6555,14 @@ static std::vector<Option> get_rbd_options() {
     .set_default(true)
     .set_description("automatically acquire/release exclusive lock until it is explicitly requested"),
 
+    Option("rbd_move_to_trash_on_remove", Option::TYPE_BOOL, Option::LEVEL_BASIC)
+    .set_default(false)
+    .set_description("automatically move images to the trash when deleted"),
+
+    Option("rbd_move_to_trash_on_remove_expire_seconds", Option::TYPE_UINT, Option::LEVEL_BASIC)
+    .set_default(0)
+    .set_description("default number of seconds to protect deleted images in the trash"),
+
     Option("rbd_mirroring_resync_after_disconnect", Option::TYPE_BOOL, Option::LEVEL_ADVANCED)
     .set_default(false)
     .set_description("automatically start image resync after mirroring is disconnected due to being laggy"),
index 2d6fb757e6b1944e19741899fc83b0ace6531fa0..c2d887e48f9da617d89366ac915555b7a46364d0 100644 (file)
@@ -16,6 +16,7 @@
 #include "librbd/internal.h"
 #include "librbd/Utils.h"
 #include "librbd/api/Config.h"
+#include "librbd/api/Trash.h"
 
 #define dout_subsys ceph_subsys_rbd
 #undef dout_prefix
@@ -379,6 +380,18 @@ int Image<I>::remove(IoCtx& io_ctx, const std::string &image_name,
   CephContext *cct((CephContext *)io_ctx.cct());
   ldout(cct, 20) << (image_id.empty() ? image_name : image_id) << dendl;
 
+  if (image_id.empty()) {
+    // id will only be supplied when used internally
+    ConfigProxy config(cct->_conf);
+    Config<I>::apply_pool_overrides(io_ctx, &config);
+
+    if (config.get_val<bool>("rbd_move_to_trash_on_remove")) {
+      return Trash<I>::move(
+        io_ctx, RBD_TRASH_IMAGE_SOURCE_USER, image_name,
+        config.get_val<uint64_t>("rbd_move_to_trash_on_remove_expire_seconds"));
+    }
+  }
+
   ThreadPool *thread_pool;
   ContextWQ *op_work_queue;
   ImageCtx::get_thread_pool_instance(cct, &thread_pool, &op_work_queue);