]> 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)
committerNathan Cutler <ncutler@suse.com>
Thu, 8 Apr 2021 13:03:22 +0000 (15:03 +0200)
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>
(cherry picked from commit c808abea64f00e25c6fd3bcaa7ebf9bc763e7ca0)

src/librbd/api/Trash.cc

index 092bf6e96b25f5f806416fca6dad6bc1709bba45..0559db2194fa312c7f05e81a84ddda725623c928 100644 (file)
@@ -352,12 +352,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;
@@ -533,6 +533,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;
@@ -567,8 +571,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;
   }