From: Ramana Raja Date: Thu, 28 Mar 2024 20:15:44 +0000 (-0400) Subject: librbd: remove image directory object during rollback X-Git-Tag: v19.1.1~204^2~2 X-Git-Url: http://git.apps.os.sepia.ceph.com/?a=commitdiff_plain;h=e29be42fec0305c8a29767ba7edf6a5ba3293878;p=ceph.git librbd: remove image directory object during rollback ... of rbd namespace creation. During rbd namespace creation, the image directory object may leak if the initalization of the image directory fails. Initialization of image directory involves creation of the rbd_directory object and a state being set in the object's omap. After creation of the object, error can occur when setting the state in the object's omap. This would fail the rbd namespace creation and leave behind the rbd_directory object. So try to remove the rbd_directory object when rolling back namespace creation. Signed-off-by: Ramana Raja (cherry picked from commit bdc50a9720276fa38d30b4f1aa23143333b861be) --- diff --git a/src/librbd/api/Namespace.cc b/src/librbd/api/Namespace.cc index 86ed70c06acec..aa33a1ad9f3f6 100644 --- a/src/librbd/api/Namespace.cc +++ b/src/librbd/api/Namespace.cc @@ -79,7 +79,12 @@ int Namespace::create(librados::IoCtx& io_ctx, const std::string& name) return 0; rollback: - int ret_val = cls_client::namespace_remove(&default_ns_ctx, name); + int ret_val = ns_ctx.remove(RBD_DIRECTORY); + if (ret_val < 0 && ret_val != -ENOENT) { + lderr(cct) << "failed to remove image directory: " << cpp_strerror(ret_val) << dendl; + } + + ret_val = cls_client::namespace_remove(&default_ns_ctx, name); if (ret_val < 0) { lderr(cct) << "failed to remove namespace: " << cpp_strerror(ret_val) << dendl; }