From: runsisi Date: Thu, 27 Apr 2017 12:28:59 +0000 (+0800) Subject: librbd: get image id from directory if open image failed X-Git-Tag: v12.0.3~76^2 X-Git-Url: http://git.apps.os.sepia.ceph.com/?a=commitdiff_plain;h=c5c5d2fe5f3a402a6546bfc06b56ebefa16147dc;p=ceph-ci.git librbd: get image id from directory if open image failed Signed-off-by: runsisi --- diff --git a/src/librbd/internal.cc b/src/librbd/internal.cc index 780f2df6c65..a14c6013516 100644 --- a/src/librbd/internal.cc +++ b/src/librbd/internal.cc @@ -1350,9 +1350,21 @@ int validate_pool(IoCtx &io_ctx, CephContext *cct) { ImageCtx *ictx = new ImageCtx(image_name, "", nullptr, io_ctx, false); int r = ictx->state->open(true); if (r < 0) { - ldout(cct, 2) << "error opening image: " << cpp_strerror(-r) << dendl; + ictx = nullptr; + if (r != -ENOENT) { - return r; + ldout(cct, 2) << "error opening image: " << cpp_strerror(-r) << dendl; + return r; + } + + // try to get image id from the directory + r = cls_client::dir_get_id(&io_ctx, RBD_DIRECTORY, image_name, &image_id); + if (r < 0) { + if (r != -ENOENT) { + ldout(cct, 2) << "error reading image id from dirctory: " + << cpp_strerror(-r) << dendl; + } + return r; } } else { if (ictx->old_format) { @@ -1375,6 +1387,9 @@ int validate_pool(IoCtx &io_ctx, CephContext *cct) { } BOOST_SCOPE_EXIT_ALL(ictx, cct) { + if (ictx == nullptr) + return; + bool is_locked = ictx->exclusive_lock != nullptr && ictx->exclusive_lock->is_lock_owner(); if (is_locked) {