From e54e29dedc743d2546e19f4b211b11bf66453376 Mon Sep 17 00:00:00 2001 From: Jason Dillaman Date: Wed, 10 Mar 2021 15:29:11 -0500 Subject: [PATCH] librbd/api: trash remove/purge should indicate interrupted move 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 (cherry picked from commit c808abea64f00e25c6fd3bcaa7ebf9bc763e7ca0) --- src/librbd/api/Trash.cc | 22 +++++++++++++++------- 1 file changed, 15 insertions(+), 7 deletions(-) diff --git a/src/librbd/api/Trash.cc b/src/librbd/api/Trash.cc index 092bf6e96b25f..0559db2194fa3 100644 --- a/src/librbd/api/Trash.cc +++ b/src/librbd/api/Trash.cc @@ -352,12 +352,12 @@ int Trash::list(IoCtx &io_ctx, vector &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(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(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::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::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; } -- 2.39.5