]> git.apps.os.sepia.ceph.com Git - ceph.git/commitdiff
librbd: reuse async trash remove state machine
authorMykola Golub <mgolub@suse.com>
Mon, 15 Apr 2019 10:34:07 +0000 (11:34 +0100)
committerJason Dillaman <dillaman@redhat.com>
Wed, 9 Oct 2019 21:24:08 +0000 (17:24 -0400)
Signed-off-by: Mykola Golub <mgolub@suse.com>
(cherry picked from commit bf8a67f3b8bde4c8759c6b7251358148a85f63d4)

Conflicts:
src/librbd/api/Trash.cc: TRASH_IMAGE_SOURCE_USER_PARENT not valid enum

src/librbd/api/Trash.cc

index 79f7bdfa4c5bfbbfe96c0099e17829aa78465214..de1f97d90da713aab265b1fadbd254d8e9748906 100644 (file)
@@ -19,6 +19,7 @@
 #include "librbd/mirror/DisableRequest.h"
 #include "librbd/mirror/EnableRequest.h"
 #include "librbd/trash/MoveRequest.h"
+#include "librbd/trash/RemoveRequest.h"
 #include <json_spirit/json_spirit.h>
 #include "librbd/journal/DisabledPolicy.h"
 #include "librbd/image/ListWatchersRequest.h"
@@ -517,41 +518,17 @@ int Trash<I>::remove(IoCtx &io_ctx, const std::string &image_id, bool force,
     return -EBUSY;
   }
 
-  r = cls_client::trash_state_set(&io_ctx, image_id,
-                                  cls::rbd::TRASH_IMAGE_STATE_REMOVING,
-                                  cls::rbd::TRASH_IMAGE_STATE_NORMAL);
-  if (r < 0 && r != -EOPNOTSUPP) {
-    lderr(cct) << "error setting trash image state: "
-               << cpp_strerror(r) << dendl;
-    return r;
-  }
-
   ThreadPool *thread_pool;
   ContextWQ *op_work_queue;
   ImageCtx::get_thread_pool_instance(cct, &thread_pool, &op_work_queue);
 
   C_SaferCond cond;
-  auto req = librbd::image::RemoveRequest<I>::create(
-    io_ctx, "", image_id, force, true, prog_ctx, op_work_queue, &cond);
+  auto req = librbd::trash::RemoveRequest<I>::create(
+      io_ctx, image_id, op_work_queue, force, prog_ctx, &cond);
   req->send();
 
   r = cond.wait();
   if (r < 0) {
-    lderr(cct) << "error removing image " << image_id
-               << ", which is pending deletion" << dendl;
-    int ret = cls_client::trash_state_set(&io_ctx, image_id,
-                                          cls::rbd::TRASH_IMAGE_STATE_NORMAL,
-                                          cls::rbd::TRASH_IMAGE_STATE_REMOVING);
-    if (ret < 0 && ret != -EOPNOTSUPP) {
-      lderr(cct) << "error setting trash image state: "
-                 << cpp_strerror(ret) << dendl;
-    }
-    return r;
-  }
-  r = cls_client::trash_remove(&io_ctx, image_id);
-  if (r < 0 && r != -ENOENT) {
-    lderr(cct) << "error removing image " << image_id
-               << " from rbd_trash object" << dendl;
     return r;
   }