From f27314b2c23f0aa2dab0bf70fa5dfce7197fd8fa Mon Sep 17 00:00:00 2001 From: Ilya Dryomov Date: Wed, 14 Aug 2024 19:42:09 +0200 Subject: [PATCH] librbd: assert on parent in ImageCtx destructor ... and switch to in-class initializers while at it. Signed-off-by: Ilya Dryomov (cherry picked from commit 23cd20e0d5523efaf6b925df378bb2dd865729aa) --- src/librbd/ImageCtx.cc | 3 ++- src/librbd/ImageCtx.h | 2 +- src/librbd/image/RefreshParentRequest.cc | 3 +-- src/librbd/image/RefreshParentRequest.h | 2 +- 4 files changed, 5 insertions(+), 5 deletions(-) diff --git a/src/librbd/ImageCtx.cc b/src/librbd/ImageCtx.cc index 7f04ee7cc9643..1a375177bba34 100644 --- a/src/librbd/ImageCtx.cc +++ b/src/librbd/ImageCtx.cc @@ -112,7 +112,7 @@ librados::IoCtx duplicate_io_ctx(librados::IoCtx& io_ctx) { old_format(false), order(0), size(0), features(0), format_string(NULL), - id(image_id), parent(NULL), + id(image_id), stripe_unit(0), stripe_count(0), flags(0), readahead(), total_bytes_read(0), @@ -157,6 +157,7 @@ librados::IoCtx duplicate_io_ctx(librados::IoCtx& io_ctx) { ImageCtx::~ImageCtx() { ldout(cct, 10) << this << " " << __func__ << dendl; + ceph_assert(parent == nullptr); ceph_assert(config_watcher == nullptr); ceph_assert(image_watcher == NULL); ceph_assert(exclusive_lock == NULL); diff --git a/src/librbd/ImageCtx.h b/src/librbd/ImageCtx.h index 197fea305b024..4edabf7fd0b11 100644 --- a/src/librbd/ImageCtx.h +++ b/src/librbd/ImageCtx.h @@ -163,7 +163,7 @@ namespace librbd { std::string header_oid; std::string id; // only used for new-format images ParentImageInfo parent_md; - ImageCtx *parent; + ImageCtx *parent = nullptr; ImageCtx *child = nullptr; MigrationInfo migration_info; cls::rbd::GroupSpec group_spec; diff --git a/src/librbd/image/RefreshParentRequest.cc b/src/librbd/image/RefreshParentRequest.cc index 348226c392b73..24b6d990885ed 100644 --- a/src/librbd/image/RefreshParentRequest.cc +++ b/src/librbd/image/RefreshParentRequest.cc @@ -28,8 +28,7 @@ RefreshParentRequest::RefreshParentRequest( const MigrationInfo &migration_info, Context *on_finish) : m_child_image_ctx(child_image_ctx), m_parent_md(parent_md), m_migration_info(migration_info), m_on_finish(on_finish), - m_parent_image_ctx(nullptr), m_parent_snap_id(CEPH_NOSNAP), - m_error_result(0) { + m_parent_snap_id(CEPH_NOSNAP), m_error_result(0) { } template diff --git a/src/librbd/image/RefreshParentRequest.h b/src/librbd/image/RefreshParentRequest.h index 086d8ec1b9a1b..40bb3e086344a 100644 --- a/src/librbd/image/RefreshParentRequest.h +++ b/src/librbd/image/RefreshParentRequest.h @@ -67,7 +67,7 @@ private: MigrationInfo m_migration_info; Context *m_on_finish; - ImageCtxT *m_parent_image_ctx; + ImageCtxT *m_parent_image_ctx = nullptr; uint64_t m_parent_snap_id; int m_error_result; -- 2.39.5