From cff82e06d58b6a6180bd4a616b3620861d1fe2d5 Mon Sep 17 00:00:00 2001 From: Kefu Chai Date: Thu, 27 Sep 2018 21:28:57 +0800 Subject: [PATCH] mon/MonClient: use scoped_guard instead of goto also silences the unused label warning. as "out_shutdown" is not used anymore after f35e10f4849440f0583d021e23a83563dd3b1607 . Signed-off-by: Kefu Chai --- src/mon/MonClient.cc | 30 ++++++++++++++---------------- 1 file changed, 14 insertions(+), 16 deletions(-) diff --git a/src/mon/MonClient.cc b/src/mon/MonClient.cc index 356e0cff923..a7cc57f62d7 100644 --- a/src/mon/MonClient.cc +++ b/src/mon/MonClient.cc @@ -103,11 +103,14 @@ int MonClient::get_monmap_and_config() interval.set_from_double(cct->_conf->mon_client_hunt_interval); cct->init_crypto(); + auto shutdown_crypto = make_scope_guard([this] { + cct->shutdown_crypto(); + }); int r = build_initial_monmap(); if (r < 0) { lderr(cct) << __func__ << " cannot identify monitors to contact" << dendl; - goto out; + return r; } messenger = Messenger::create_client_messenger( @@ -115,11 +118,20 @@ int MonClient::get_monmap_and_config() ceph_assert(messenger); messenger->add_dispatcher_head(this); messenger->start(); + auto shutdown_msgr = make_scope_guard([this] { + messenger->shutdown(); + messenger->wait(); + delete messenger; + messenger = nullptr; + if (!monmap.fsid.is_zero()) { + cct->_conf.set_val("fsid", stringify(monmap.fsid)); + } + }); while (tries-- > 0) { r = init(); if (r < 0) { - goto out_msgr; + return r; } r = authenticate(cct->_conf->client_mount_timeout); if (r == -ETIMEDOUT) { @@ -154,21 +166,7 @@ int MonClient::get_monmap_and_config() continue; } -out_shutdown: shutdown(); - -out_msgr: - messenger->shutdown(); - messenger->wait(); - delete messenger; - messenger = nullptr; - - if (!monmap.fsid.is_zero()) { - cct->_conf.set_val("fsid", stringify(monmap.fsid)); - } - -out: - cct->shutdown_crypto(); return r; } -- 2.47.3