From 91d6ac1121f42d3f730f38e077cfa111e1b94e84 Mon Sep 17 00:00:00 2001 From: Jason Dillaman Date: Tue, 17 Apr 2018 14:15:47 -0400 Subject: [PATCH] librbd: normalize clone state machine method names and debug logs Signed-off-by: Jason Dillaman --- src/librbd/image/CloneRequest.cc | 164 ++++++++++++++++--------------- src/librbd/image/CloneRequest.h | 34 +++---- 2 files changed, 101 insertions(+), 97 deletions(-) diff --git a/src/librbd/image/CloneRequest.cc b/src/librbd/image/CloneRequest.cc index 5389abf34498d..71b4951a09195 100644 --- a/src/librbd/image/CloneRequest.cc +++ b/src/librbd/image/CloneRequest.cc @@ -15,7 +15,8 @@ #define dout_subsys ceph_subsys_rbd #undef dout_prefix -#define dout_prefix *_dout << "librbd::image::CloneRequest: " +#define dout_prefix *_dout << "librbd::image::CloneRequest: " << this << " " \ + << __func__ << ": " #define MAX_KEYS 64 @@ -58,13 +59,13 @@ CloneRequest::CloneRequest(I *p_imctx, IoCtx &c_ioctx, template void CloneRequest::send() { - ldout(m_cct, 20) << this << " " << __func__ << dendl; + ldout(m_cct, 20) << dendl; validate_options(); } template void CloneRequest::validate_options() { - ldout(m_cct, 20) << this << " " << __func__ << dendl; + ldout(m_cct, 20) << dendl; uint64_t format = 0; m_opts.get(RBD_IMAGE_OPTION_FORMAT, &format); @@ -108,7 +109,7 @@ void CloneRequest::validate_options() { template void CloneRequest::validate_parent() { - ldout(m_cct, 20) << this << " " << __func__ << dendl; + ldout(m_cct, 20) << dendl; if (m_p_imctx->operations_disabled) { lderr(m_cct) << "image operations disabled due to unsupported op features" @@ -155,12 +156,12 @@ void CloneRequest::validate_parent() { return; } - send_validate_child(); + validate_child(); } template -void CloneRequest::send_validate_child() { - ldout(m_cct, 20) << this << " " << __func__ << dendl; +void CloneRequest::validate_child() { + ldout(m_cct, 20) << dendl; using klass = CloneRequest; librados::AioCompletion *comp = create_rados_callback< @@ -177,7 +178,7 @@ void CloneRequest::send_validate_child() { template void CloneRequest::handle_validate_child(int r) { - ldout(m_cct, 20) << this << " " << __func__ << " r=" << r << dendl; + ldout(m_cct, 20) << "r=" << r << dendl; if (r != -ENOENT) { lderr(m_cct) << "rbd image " << m_name << " already exists" << dendl; @@ -185,12 +186,12 @@ void CloneRequest::handle_validate_child(int r) { return; } - send_create(); + create_child(); } template -void CloneRequest::send_create() { - ldout(m_cct, 20) << this << " " << __func__ << dendl; +void CloneRequest::create_child() { + ldout(m_cct, 20) << dendl; if (m_use_p_features) { m_features = (m_p_features & ~RBD_FEATURES_IMPLICIT_ENABLE); @@ -208,7 +209,8 @@ void CloneRequest::send_create() { m_opts.set(RBD_IMAGE_OPTION_FEATURES, m_features); using klass = CloneRequest; - Context *ctx = create_context_callback(this); + Context *ctx = create_context_callback< + klass, &klass::handle_create_child>(this); RWLock::RLocker snap_locker(m_p_imctx->snap_lock); CreateRequest *req = CreateRequest::create( @@ -218,25 +220,26 @@ void CloneRequest::send_create() { } template -void CloneRequest::handle_create(int r) { - ldout(m_cct, 20) << this << " " << __func__ << " r=" << r << dendl; +void CloneRequest::handle_create_child(int r) { + ldout(m_cct, 20) << "r=" << r << dendl; if (r < 0) { lderr(m_cct) << "error creating child: " << cpp_strerror(r) << dendl; complete(r); return; } - send_open(); + open_child(); } template -void CloneRequest::send_open() { - ldout(m_cct, 20) << this << " " << __func__ << dendl; +void CloneRequest::open_child() { + ldout(m_cct, 20) << dendl; m_imctx = I::create(m_name, "", NULL, m_ioctx, false); using klass = CloneRequest; - Context *ctx = create_context_callback(this); + Context *ctx = create_context_callback< + klass, &klass::handle_open_child>(this); uint64_t flags = OPEN_FLAG_SKIP_OPEN_PARENT; if ((m_features & RBD_FEATURE_MIGRATING) != 0) { @@ -247,22 +250,22 @@ void CloneRequest::send_open() { } template -void CloneRequest::handle_open(int r) { - ldout(m_cct, 20) << this << " " << __func__ << " r=" << r << dendl; +void CloneRequest::handle_open_child(int r) { + ldout(m_cct, 20) << "r=" << r << dendl; if (r < 0) { lderr(m_cct) << "Error opening new image: " << cpp_strerror(r) << dendl; m_r_saved = r; - send_remove(); + remove_child(); return; } - send_set_parent(); + set_parent(); } template -void CloneRequest::send_set_parent() { - ldout(m_cct, 20) << this << " " << __func__ << dendl; +void CloneRequest::set_parent() { + ldout(m_cct, 20) << dendl; librados::ObjectWriteOperation op; librbd::cls_client::set_parent(&op, m_pspec, m_size); @@ -277,26 +280,26 @@ void CloneRequest::send_set_parent() { template void CloneRequest::handle_set_parent(int r) { - ldout(m_cct, 20) << this << " " << __func__ << " r=" << r << dendl; + ldout(m_cct, 20) << "r=" << r << dendl; if (r < 0) { lderr(m_cct) << "couldn't set parent: " << cpp_strerror(r) << dendl; m_r_saved = r; - send_close(); + close_child(); return; } - send_v2_set_op_feature(); + v2_set_op_feature(); } template -void CloneRequest::send_v2_set_op_feature() { +void CloneRequest::v2_set_op_feature() { if (m_clone_format == 1) { - send_v1_add_child(); + v1_add_child(); return; } - ldout(m_cct, 20) << this << " " << __func__ << dendl; + ldout(m_cct, 20) << dendl; librados::ObjectWriteOperation op; cls_client::op_features_set(&op, RBD_OPERATION_FEATURE_CLONE_CHILD, @@ -311,21 +314,21 @@ void CloneRequest::send_v2_set_op_feature() { template void CloneRequest::handle_v2_set_op_feature(int r) { - ldout(m_cct, 20) << this << " " << __func__ << " r=" << r << dendl; + ldout(m_cct, 20) << "r=" << r << dendl; if (r < 0) { lderr(m_cct) << "failed to enable clone v2: " << cpp_strerror(r) << dendl; m_r_saved = r; - send_close(); + close_child(); return; } - send_v2_child_attach(); + v2_child_attach(); } template -void CloneRequest::send_v2_child_attach() { - ldout(m_cct, 20) << this << " " << __func__ << dendl; +void CloneRequest::v2_child_attach() { + ldout(m_cct, 20) << dendl; librados::ObjectWriteOperation op; cls_client::child_attach(&op, m_p_imctx->snap_id, @@ -340,22 +343,22 @@ void CloneRequest::send_v2_child_attach() { template void CloneRequest::handle_v2_child_attach(int r) { - ldout(m_cct, 20) << this << " " << __func__ << " r=" << r << dendl; + ldout(m_cct, 20) << "r=" << r << dendl; if (r < 0) { lderr(m_cct) << "failed to attach child image: " << cpp_strerror(r) << dendl; m_r_saved = r; - send_close(); + close_child(); return; } - send_metadata_list(); + metadata_list(); } template -void CloneRequest::send_v1_add_child() { - ldout(m_cct, 20) << this << " " << __func__ << dendl; +void CloneRequest::v1_add_child() { + ldout(m_cct, 20) << dendl; librados::ObjectWriteOperation op; cls_client::add_child(&op, m_pspec, m_id); @@ -370,21 +373,21 @@ void CloneRequest::send_v1_add_child() { template void CloneRequest::handle_v1_add_child(int r) { - ldout(m_cct, 20) << this << " " << __func__ << " r=" << r << dendl; + ldout(m_cct, 20) << "r=" << r << dendl; if (r < 0) { lderr(m_cct) << "couldn't add child: " << cpp_strerror(r) << dendl; m_r_saved = r; - send_close(); + close_child(); return; } - send_v1_refresh(); + v1_refresh(); } template -void CloneRequest::send_v1_refresh() { - ldout(m_cct, 20) << this << " " << __func__ << dendl; +void CloneRequest::v1_refresh() { + ldout(m_cct, 20) << dendl; using klass = CloneRequest; RefreshRequest *req = RefreshRequest::create( @@ -395,7 +398,7 @@ void CloneRequest::send_v1_refresh() { template void CloneRequest::handle_v1_refresh(int r) { - ldout(m_cct, 20) << this << " " << __func__ << " r=" << r << dendl; + ldout(m_cct, 20) << "r=" << r << dendl; bool snap_protected = false; if (r == 0) { @@ -406,16 +409,16 @@ void CloneRequest::handle_v1_refresh(int r) { if (r < 0 || !snap_protected) { m_r_saved = -EINVAL; - send_close(); + close_child(); return; } - send_metadata_list(); + metadata_list(); } template -void CloneRequest::send_metadata_list() { - ldout(m_cct, 20) << this << " " << __func__ << ": " +void CloneRequest::metadata_list() { + ldout(m_cct, 20) << ": " << "start_key=" << m_last_metadata_key << dendl; librados::ObjectReadOperation op; @@ -432,7 +435,7 @@ void CloneRequest::send_metadata_list() { template void CloneRequest::handle_metadata_list(int r) { - ldout(m_cct, 20) << this << " " << __func__ << " r=" << r << dendl; + ldout(m_cct, 20) << "r=" << r << dendl; map metadata; if (r == 0) { @@ -447,7 +450,7 @@ void CloneRequest::handle_metadata_list(int r) { } else { lderr(m_cct) << "couldn't list metadata: " << cpp_strerror(r) << dendl; m_r_saved = r; - send_close(); + close_child(); } return; } @@ -458,20 +461,20 @@ void CloneRequest::handle_metadata_list(int r) { } if (metadata.size() == MAX_KEYS) { - send_metadata_list(); + metadata_list(); } else { - send_metadata_set(); + metadata_set(); } } template -void CloneRequest::send_metadata_set() { +void CloneRequest::metadata_set() { if (m_pairs.empty()) { get_mirror_mode(); return; } - ldout(m_cct, 20) << this << " " << __func__ << dendl; + ldout(m_cct, 20) << dendl; librados::ObjectWriteOperation op; cls_client::metadata_set(&op, m_pairs); @@ -486,12 +489,12 @@ void CloneRequest::send_metadata_set() { template void CloneRequest::handle_metadata_set(int r) { - ldout(m_cct, 20) << this << " " << __func__ << " r=" << r << dendl; + ldout(m_cct, 20) << "r=" << r << dendl; if (r < 0) { lderr(m_cct) << "couldn't set metadata: " << cpp_strerror(r) << dendl; m_r_saved = r; - send_close(); + close_child(); } else { get_mirror_mode(); } @@ -499,10 +502,10 @@ void CloneRequest::handle_metadata_set(int r) { template void CloneRequest::get_mirror_mode() { - ldout(m_cct, 20) << this << " " << __func__ << dendl; + ldout(m_cct, 20) << dendl; if (!m_imctx->test_features(RBD_FEATURE_JOURNALING)) { - send_close(); + close_child(); return; } @@ -520,7 +523,7 @@ void CloneRequest::get_mirror_mode() { template void CloneRequest::handle_get_mirror_mode(int r) { - ldout(m_cct, 20) << this << " " << __func__ << " r=" << r << dendl; + ldout(m_cct, 20) << "r=" << r << dendl; if (r == 0) { auto it = m_out_bl.cbegin(); @@ -532,20 +535,20 @@ void CloneRequest::handle_get_mirror_mode(int r) { << dendl; m_r_saved = r; - send_close(); + close_child(); } else { if (m_mirror_mode == cls::rbd::MIRROR_MODE_POOL || !m_non_primary_global_image_id.empty()) { - send_enable_mirror(); + enable_mirror(); } else { - send_close(); + close_child(); } } } template -void CloneRequest::send_enable_mirror() { - ldout(m_cct, 20) << this << " " << __func__ << dendl; +void CloneRequest::enable_mirror() { + ldout(m_cct, 20) << dendl; using klass = CloneRequest; Context *ctx = create_context_callback< @@ -559,32 +562,32 @@ void CloneRequest::send_enable_mirror() { template void CloneRequest::handle_enable_mirror(int r) { - ldout(m_cct, 20) << this << " " << __func__ << " r=" << r << dendl; + ldout(m_cct, 20) << "r=" << r << dendl; if (r < 0) { lderr(m_cct) << "failed to enable mirroring: " << cpp_strerror(r) << dendl; m_r_saved = r; } - send_close(); + close_child(); } template -void CloneRequest::send_close() { - ldout(m_cct, 20) << this << " " << __func__ << dendl; +void CloneRequest::close_child() { + ldout(m_cct, 20) << dendl; assert(m_imctx != nullptr); using klass = CloneRequest; Context *ctx = create_async_context_callback( *m_imctx, create_context_callback< - klass, &klass::handle_close>(this)); + klass, &klass::handle_close_child>(this)); m_imctx->state->close(ctx); } template -void CloneRequest::handle_close(int r) { - ldout(m_cct, 20) << this << " " << __func__ << dendl; +void CloneRequest::handle_close_child(int r) { + ldout(m_cct, 20) << dendl; m_imctx->destroy(); m_imctx = nullptr; @@ -598,16 +601,17 @@ void CloneRequest::handle_close(int r) { if (m_r_saved == 0) { complete(0); } else { - send_remove(); + remove_child(); } } template -void CloneRequest::send_remove() { - ldout(m_cct, 20) << this << " " << __func__ << dendl; +void CloneRequest::remove_child() { + ldout(m_cct, 20) << dendl; using klass = CloneRequest; - Context *ctx = create_context_callback(this); + Context *ctx = create_context_callback< + klass, &klass::handle_remove_child>(this); auto req = librbd::image::RemoveRequest::create( m_ioctx, m_name, m_id, false, false, m_no_op, m_op_work_queue, ctx); @@ -615,8 +619,8 @@ void CloneRequest::send_remove() { } template -void CloneRequest::handle_remove(int r) { - ldout(m_cct, 20) << this << " " << __func__ << " r=" << r << dendl; +void CloneRequest::handle_remove_child(int r) { + ldout(m_cct, 20) << "r=" << r << dendl; if (r < 0) { lderr(m_cct) << "Error removing failed clone: " @@ -627,7 +631,7 @@ void CloneRequest::handle_remove(int r) { template void CloneRequest::complete(int r) { - ldout(m_cct, 20) << this << " " << __func__ << " r=" << r << dendl; + ldout(m_cct, 20) << "r=" << r << dendl; if (r == 0) { ldout(m_cct, 20) << "done." << dendl; diff --git a/src/librbd/image/CloneRequest.h b/src/librbd/image/CloneRequest.h index 7c3d3ea44702b..45ac351a7f0c6 100644 --- a/src/librbd/image/CloneRequest.h +++ b/src/librbd/image/CloneRequest.h @@ -117,47 +117,47 @@ private: void validate_options(); void validate_parent(); - void send_validate_child(); + void validate_child(); void handle_validate_child(int r); - void send_create(); - void handle_create(int r); + void create_child(); + void handle_create_child(int r); - void send_open(); - void handle_open(int r); + void open_child(); + void handle_open_child(int r); - void send_set_parent(); + void set_parent(); void handle_set_parent(int r); - void send_v2_set_op_feature(); + void v2_set_op_feature(); void handle_v2_set_op_feature(int r); - void send_v2_child_attach(); + void v2_child_attach(); void handle_v2_child_attach(int r); - void send_v1_add_child(); + void v1_add_child(); void handle_v1_add_child(int r); - void send_v1_refresh(); + void v1_refresh(); void handle_v1_refresh(int r); - void send_metadata_list(); + void metadata_list(); void handle_metadata_list(int r); - void send_metadata_set(); + void metadata_set(); void handle_metadata_set(int r); void get_mirror_mode(); void handle_get_mirror_mode(int r); - void send_enable_mirror(); + void enable_mirror(); void handle_enable_mirror(int r); - void send_close(); - void handle_close(int r); + void close_child(); + void handle_close_child(int r); - void send_remove(); - void handle_remove(int r); + void remove_child(); + void handle_remove_child(int r); void complete(int r); }; -- 2.39.5