]> git.apps.os.sepia.ceph.com Git - ceph.git/commitdiff
librbd/api: trash remove/purge should indicate interrupted move
authorJason Dillaman <dillaman@redhat.com>
Wed, 10 Mar 2021 20:29:11 +0000 (15:29 -0500)
committerJason Dillaman <dillaman@redhat.com>
Thu, 11 Mar 2021 15:48:04 +0000 (10:48 -0500)
This will help the user self-diagnose that a trash move operation
was interrupted and therefore the state is invalid.

Signed-off-by: Jason Dillaman <dillaman@redhat.com>
src/librbd/api/Trash.cc

index 6869d5a84a1c139b8b62af0d044d4dd6be3b814e..4d60361fbfbaf14fb6e02afbf786a82addc96a71 100644 (file)
@@ -360,12 +360,12 @@ int Trash<I>::list(IoCtx &io_ctx, vector<trash_image_info_t> &entries,
   }
 
   entries.reserve(trash_image_specs.size());
-  for (const auto &entry : trash_image_specs) {
+  for (const auto& [image_id, spec] : trash_image_specs) {
     rbd_trash_image_source_t source =
-        static_cast<rbd_trash_image_source_t>(entry.second.source);
-    entries.push_back({entry.first, entry.second.name, source,
-                       entry.second.deletion_time.sec(),
-                       entry.second.deferment_end_time.sec()});
+        static_cast<rbd_trash_image_source_t>(spec.source);
+    entries.push_back({image_id, spec.name, source,
+                       spec.deletion_time.sec(),
+                       spec.deferment_end_time.sec()});
   }
 
   return 0;
@@ -542,6 +542,10 @@ int Trash<I>::purge(IoCtx& io_ctx, time_t expire_ts,
                       << "using it crashed. Try again after closing/unmapping "
                       << "it or waiting 30s for the crashed client to timeout."
                       << dendl;
+      } else if (r == -EUCLEAN) {
+        ldout(cct, 5) << "Image is not in the expected state. Ensure moving "
+                      << "the image to the trash completed successfully."
+                      << dendl;
       } else if (r == -EMLINK) {
         ldout(cct, 5) << "Remove the image from the group and try again."
                       << dendl;
@@ -576,8 +580,12 @@ int Trash<I>::remove(IoCtx &io_ctx, const std::string &image_id, bool force,
     lderr(cct) << "error: deferment time has not expired." << dendl;
     return -EPERM;
   }
-  if (trash_spec.state != cls::rbd::TRASH_IMAGE_STATE_NORMAL &&
-      trash_spec.state != cls::rbd::TRASH_IMAGE_STATE_REMOVING) {
+  if (trash_spec.state == cls::rbd::TRASH_IMAGE_STATE_MOVING) {
+    lderr(cct) << "error: image is pending moving to the trash."
+               << dendl;
+    return -EUCLEAN;
+  } else if (trash_spec.state != cls::rbd::TRASH_IMAGE_STATE_NORMAL &&
+             trash_spec.state != cls::rbd::TRASH_IMAGE_STATE_REMOVING) {
     lderr(cct) << "error: image is pending restoration." << dendl;
     return -EBUSY;
   }