From 88dda3be5aed38c8f587af9b27cb54a0fcca7530 Mon Sep 17 00:00:00 2001 From: Josh Durgin Date: Fri, 27 Apr 2012 11:20:59 -0700 Subject: [PATCH] librbd: use unique error code for image removal failures This allows the rbd tool to provide a useful error message, instead of compounding more possible causes into one error code. Signed-off-by: Josh Durgin --- src/librbd.cc | 2 +- src/rbd.cc | 11 +++++++++-- 2 files changed, 10 insertions(+), 3 deletions(-) diff --git a/src/librbd.cc b/src/librbd.cc index 0a2264bda683e..bb7043682aa9b 100644 --- a/src/librbd.cc +++ b/src/librbd.cc @@ -1025,7 +1025,7 @@ int remove(IoCtx& io_ctx, const char *imgname, ProgressContext& prog_ctx) if (r >= 0) { if (has_snaps(io_ctx, md_oid)) { lderr(cct) << "image has snapshots - not removing" << dendl; - return -EBUSY; + return -ENOTEMPTY; } trim_image(io_ctx, header, 0, prog_ctx); ldout(cct, 2) << "removing header..." << dendl; diff --git a/src/rbd.cc b/src/rbd.cc index cb82f9cc70fe6..1c43fb544be9d 100644 --- a/src/rbd.cc +++ b/src/rbd.cc @@ -1193,14 +1193,21 @@ int main(int argc, const char **argv) case OPT_RM: r = do_delete(rbd, io_ctx, imgname); if (r < 0) { - if (r == -EBUSY) { + if (r == -ENOTEMPTY) { cerr << "delete error: image has snapshots - these must be deleted" << " with 'rbd snap purge' before the image can be removed." << std::endl; + } else if (r == -EBUSY) { + cerr << "delete error: image still has watchers" + << std::endl + << "This means the image is still open or the client using " + << "it crashed. Try again after closing/unmapping it or " + << "waiting 30s for the crashed client to timeout." + << std::endl; } else { cerr << "delete error: " << cpp_strerror(-r) << std::endl; } - exit(1); + exit(-r); } break; -- 2.39.5