From 504b6fca9b4d4a577dcca8e04960d9e65feedee1 Mon Sep 17 00:00:00 2001 From: Kefu Chai Date: Wed, 11 Aug 2021 11:53:25 +0800 Subject: [PATCH] osd: build without "using namespace std" * add "std::" prefix in headers * add "using" declarations in .cc files. so we don't rely on "using namespace std" in one or more included headers. Signed-off-by: Kefu Chai --- src/osd/ECBackend.cc | 1 + src/osd/ECTransaction.cc | 1 + src/osd/OSD.h | 5 +++-- src/osd/PG.cc | 2 +- src/osd/PG.h | 36 ++++++++++++++++++------------------ src/osd/PGBackend.cc | 1 + src/osd/PeeringState.cc | 1 + src/osd/PeeringState.h | 14 +++++++------- src/osd/PrimaryLogPG.cc | 8 +++++--- src/osd/PrimaryLogPG.h | 6 +++--- src/osd/PrimaryLogScrub.cc | 2 ++ src/osd/ReplicatedBackend.cc | 1 + src/osd/Watch.cc | 1 + src/osd/osd_types.cc | 1 + src/osd/osd_types.h | 6 +++--- src/osd/pg_scrubber.cc | 10 ++++++++-- src/osd/pg_scrubber.h | 2 +- src/osd/recovery_types.cc | 2 +- src/osd/scrubber_common.h | 8 ++++---- 19 files changed, 63 insertions(+), 45 deletions(-) diff --git a/src/osd/ECBackend.cc b/src/osd/ECBackend.cc index f9398c17220..5388391c4f0 100644 --- a/src/osd/ECBackend.cc +++ b/src/osd/ECBackend.cc @@ -34,6 +34,7 @@ using std::dec; using std::hex; +using std::less; using std::list; using std::make_pair; using std::map; diff --git a/src/osd/ECTransaction.cc b/src/osd/ECTransaction.cc index 2a6c67d13eb..d48b20d73f8 100644 --- a/src/osd/ECTransaction.cc +++ b/src/osd/ECTransaction.cc @@ -21,6 +21,7 @@ #include "os/ObjectStore.h" #include "common/inline_variant.h" +using std::less; using std::make_pair; using std::map; using std::pair; diff --git a/src/osd/OSD.h b/src/osd/OSD.h index 57964679afd..2a30d7afadb 100644 --- a/src/osd/OSD.h +++ b/src/osd/OSD.h @@ -1178,12 +1178,13 @@ protected: friend class OSDSocketHook; class OSDSocketHook *asok_hook; using PGRefOrError = std::tuple, int>; - PGRefOrError locate_asok_target(const cmdmap_t& cmdmap, stringstream& ss, bool only_primary); + PGRefOrError locate_asok_target(const cmdmap_t& cmdmap, + std::stringstream& ss, bool only_primary); int asok_route_to_pg(bool only_primary, std::string_view prefix, cmdmap_t cmdmap, Formatter *f, - stringstream& ss, + std::stringstream& ss, const bufferlist& inbl, bufferlist& outbl, std::function on_finish); diff --git a/src/osd/PG.cc b/src/osd/PG.cc index 10829def639..7991b3d9294 100644 --- a/src/osd/PG.cc +++ b/src/osd/PG.cc @@ -2092,7 +2092,7 @@ void PG::replica_scrub(epoch_t epoch_queued, dout(10) << __func__ << " queued at: " << epoch_queued << (is_primary() ? " (primary)" : " (replica)") << dendl; scrub_queued = false; - forward_scrub_event(&ScrubPgIF::send_start_replica, epoch_queued, "StartReplica/nw"sv); + forward_scrub_event(&ScrubPgIF::send_start_replica, epoch_queued, "StartReplica/nw"); } bool PG::ops_blocked_by_scrub() const diff --git a/src/osd/PG.h b/src/osd/PG.h index e46a63c395c..c288ff265e7 100644 --- a/src/osd/PG.h +++ b/src/osd/PG.h @@ -378,7 +378,7 @@ public: { // a new scrub scrub_queued = false; - forward_scrub_event(&ScrubPgIF::initiate_regular_scrub, queued, "StartScrub"sv); + forward_scrub_event(&ScrubPgIF::initiate_regular_scrub, queued, "StartScrub"); } /** @@ -391,7 +391,7 @@ public: // a new scrub scrub_queued = false; forward_scrub_event(&ScrubPgIF::initiate_scrub_after_repair, queued, - "AfterRepairScrub"sv); + "AfterRepairScrub"); } void replica_scrub(epoch_t queued, ThreadPool::TPHandle &handle); @@ -399,87 +399,87 @@ public: void replica_scrub_resched(epoch_t queued, ThreadPool::TPHandle& handle) { scrub_queued = false; - forward_scrub_event(&ScrubPgIF::send_sched_replica, queued, "SchedReplica"sv); + forward_scrub_event(&ScrubPgIF::send_sched_replica, queued, "SchedReplica"); } void scrub_send_resources_granted(epoch_t queued, ThreadPool::TPHandle& handle) { - forward_scrub_event(&ScrubPgIF::send_remotes_reserved, queued, "RemotesReserved"sv); + forward_scrub_event(&ScrubPgIF::send_remotes_reserved, queued, "RemotesReserved"); } void scrub_send_resources_denied(epoch_t queued, ThreadPool::TPHandle& handle) { forward_scrub_event(&ScrubPgIF::send_reservation_failure, queued, - "ReservationFailure"sv); + "ReservationFailure"); } void scrub_send_scrub_resched(epoch_t queued, ThreadPool::TPHandle& handle) { scrub_queued = false; - forward_scrub_event(&ScrubPgIF::send_scrub_resched, queued, "InternalSchedScrub"sv); + forward_scrub_event(&ScrubPgIF::send_scrub_resched, queued, "InternalSchedScrub"); } void scrub_send_pushes_update(epoch_t queued, ThreadPool::TPHandle& handle) { forward_scrub_event(&ScrubPgIF::active_pushes_notification, queued, - "ActivePushesUpd"sv); + "ActivePushesUpd"); } void scrub_send_applied_update(epoch_t queued, ThreadPool::TPHandle& handle) { forward_scrub_event(&ScrubPgIF::update_applied_notification, queued, - "UpdatesApplied"sv); + "UpdatesApplied"); } void scrub_send_unblocking(epoch_t queued, ThreadPool::TPHandle& handle) { - forward_scrub_event(&ScrubPgIF::send_scrub_unblock, queued, "Unblocked"sv); + forward_scrub_event(&ScrubPgIF::send_scrub_unblock, queued, "Unblocked"); } void scrub_send_digest_update(epoch_t queued, ThreadPool::TPHandle& handle) { - forward_scrub_event(&ScrubPgIF::digest_update_notification, queued, "DigestUpdate"sv); + forward_scrub_event(&ScrubPgIF::digest_update_notification, queued, "DigestUpdate"); } void scrub_send_local_map_ready(epoch_t queued, ThreadPool::TPHandle& handle) { - forward_scrub_event(&ScrubPgIF::send_local_map_done, queued, "IntLocalMapDone"sv); + forward_scrub_event(&ScrubPgIF::send_local_map_done, queued, "IntLocalMapDone"); } void scrub_send_replmaps_ready(epoch_t queued, ThreadPool::TPHandle& handle) { - forward_scrub_event(&ScrubPgIF::send_replica_maps_ready, queued, "GotReplicas"sv); + forward_scrub_event(&ScrubPgIF::send_replica_maps_ready, queued, "GotReplicas"); } void scrub_send_replica_pushes(epoch_t queued, ThreadPool::TPHandle& handle) { forward_scrub_event(&ScrubPgIF::send_replica_pushes_upd, queued, - "ReplicaPushesUpd"sv); + "ReplicaPushesUpd"); } void scrub_send_maps_compared(epoch_t queued, ThreadPool::TPHandle& handle) { - forward_scrub_event(&ScrubPgIF::send_maps_compared, queued, "MapsCompared"sv); + forward_scrub_event(&ScrubPgIF::send_maps_compared, queued, "MapsCompared"); } void scrub_send_get_next_chunk(epoch_t queued, ThreadPool::TPHandle& handle) { - forward_scrub_event(&ScrubPgIF::send_get_next_chunk, queued, "NextChunk"sv); + forward_scrub_event(&ScrubPgIF::send_get_next_chunk, queued, "NextChunk"); } void scrub_send_scrub_is_finished(epoch_t queued, ThreadPool::TPHandle& handle) { - forward_scrub_event(&ScrubPgIF::send_scrub_is_finished, queued, "ScrubFinished"sv); + forward_scrub_event(&ScrubPgIF::send_scrub_is_finished, queued, "ScrubFinished"); } void scrub_send_chunk_free(epoch_t queued, ThreadPool::TPHandle& handle) { - forward_scrub_event(&ScrubPgIF::send_chunk_free, queued, "SelectedChunkFree"sv); + forward_scrub_event(&ScrubPgIF::send_chunk_free, queued, "SelectedChunkFree"); } void scrub_send_chunk_busy(epoch_t queued, ThreadPool::TPHandle& handle) { - forward_scrub_event(&ScrubPgIF::send_chunk_busy, queued, "ChunkIsBusy"sv); + forward_scrub_event(&ScrubPgIF::send_chunk_busy, queued, "ChunkIsBusy"); } void reg_next_scrub(); diff --git a/src/osd/PGBackend.cc b/src/osd/PGBackend.cc index 3b1525bd271..4e8c74c487e 100644 --- a/src/osd/PGBackend.cc +++ b/src/osd/PGBackend.cc @@ -30,6 +30,7 @@ #include "messages/MOSDPGRecoveryDelete.h" #include "messages/MOSDPGRecoveryDeleteReply.h" +using std::less; using std::list; using std::make_pair; using std::map; diff --git a/src/osd/PeeringState.cc b/src/osd/PeeringState.cc index 78de9527809..698b767de82 100644 --- a/src/osd/PeeringState.cc +++ b/src/osd/PeeringState.cc @@ -28,6 +28,7 @@ using std::map; using std::ostream; using std::pair; using std::set; +using std::string; using std::stringstream; using std::vector; diff --git a/src/osd/PeeringState.h b/src/osd/PeeringState.h index c49a46697d0..992af4c5768 100644 --- a/src/osd/PeeringState.h +++ b/src/osd/PeeringState.h @@ -1518,7 +1518,7 @@ public: } void update_heartbeat_peers(); - void query_unfound(Formatter *f, string state); + void query_unfound(Formatter *f, std::string state); bool proc_replica_info( pg_shard_t from, const pg_info_t &oinfo, epoch_t send_epoch); void remove_down_peer_info(const OSDMapRef &osdmap); @@ -1578,18 +1578,18 @@ public: std::set *acting_backfill, std::ostream &ss); - static std::pair::const_iterator, eversion_t> + static std::pair::const_iterator, eversion_t> select_replicated_primary( - map::const_iterator auth_log_shard, + std::map::const_iterator auth_log_shard, uint64_t force_auth_primary_missing_objects, const std::vector &up, pg_shard_t up_primary, - const map &all_info, + const std::map &all_info, const OSDMapRef osdmap, - ostream &ss); + std::ostream &ss); static void calc_replicated_acting( - map::const_iterator primary_shard, + std::map::const_iterator primary_shard, eversion_t oldest_auth_log_entry, unsigned size, const std::vector &acting, @@ -1604,7 +1604,7 @@ public: const PGPool& pool, std::ostream &ss); static void calc_replicated_acting_stretch( - map::const_iterator primary_shard, + std::map::const_iterator primary_shard, eversion_t oldest_auth_log_entry, unsigned size, const std::vector &acting, diff --git a/src/osd/PrimaryLogPG.cc b/src/osd/PrimaryLogPG.cc index 64e596b107a..2dd1e4acae9 100644 --- a/src/osd/PrimaryLogPG.cc +++ b/src/osd/PrimaryLogPG.cc @@ -83,10 +83,12 @@ MEMPOOL_DEFINE_OBJECT_FACTORY(PrimaryLogPG, replicatedpg, osd); +using std::less; using std::list; using std::ostream; using std::pair; using std::make_pair; +using std::make_unique; using std::map; using std::ostringstream; using std::set; @@ -3726,7 +3728,7 @@ ceph_tid_t PrimaryLogPG::refcount_manifest(hobject_t src_soid, hobject_t tgt_soi cls_cas_chunk_create_or_get_ref_op get_call; get_call.source = src_soid.get_head(); ceph_assert(chunk); - get_call.data = move(*chunk); + get_call.data = std::move(*chunk); ::encode(get_call, in); obj_op.call("cas", "chunk_create_or_get_ref", in); } else { @@ -10493,7 +10495,7 @@ int PrimaryLogPG::start_dedup(OpRequestRef op, ObjectContextRef obc) } C_SetDedupChunks *fin = new C_SetDedupChunks(this, soid, get_last_peering_reset(), p.first); ceph_tid_t tid = refcount_manifest(soid, target, refcount_t::CREATE_OR_GET_REF, - fin, move(chunks[p.first])); + fin, std::move(chunks[p.first])); mop->chunks[target] = make_pair(p.first, p.second.length()); mop->num_chunks++; mop->tids[p.first] = tid; @@ -10560,7 +10562,7 @@ int PrimaryLogPG::do_cdc(const object_info_t& oi, bufferlist chunk; chunk.substr_of(bl, p.first, p.second); hobject_t target = get_fpoid_from_chunk(oi.soid, chunk); - chunks[p.first] = move(chunk); + chunks[p.first] = std::move(chunk); chunk_map[p.first] = chunk_info_t(0, p.second, target); total_length += p.second; } diff --git a/src/osd/PrimaryLogPG.h b/src/osd/PrimaryLogPG.h index ea69db4f0bd..d7d075c77af 100644 --- a/src/osd/PrimaryLogPG.h +++ b/src/osd/PrimaryLogPG.h @@ -278,7 +278,7 @@ public: OpRequestRef op; std::map results; std::map tids; - std::map> chunks; + std::map> chunks; uint64_t num_chunks = 0; object_manifest_t new_manifest; @@ -1368,7 +1368,7 @@ protected: // -- cls_gather -- std::map cls_gather_ops; - void cancel_cls_gather(map::iterator iter, bool requeue, std::vector *tids); + void cancel_cls_gather(std::map::iterator iter, bool requeue, std::vector *tids); void cancel_cls_gather_ops(bool requeue, std::vector *tids); // -- scrub -- @@ -1442,7 +1442,7 @@ protected: void process_copy_chunk_manifest(hobject_t oid, ceph_tid_t tid, int r, uint64_t offset); void finish_promote_manifest(int r, CopyResults *results, ObjectContextRef obc); void cancel_and_requeue_proxy_ops(hobject_t oid); - void cancel_manifest_ops(bool requeue, vector *tids); + void cancel_manifest_ops(bool requeue, std::vector *tids); ceph_tid_t refcount_manifest(hobject_t src_soid, hobject_t tgt_soid, refcount_t type, Context *cb, std::optional chunk); void dec_all_refcount_manifest(const object_info_t& oi, OpContext* ctx); diff --git a/src/osd/PrimaryLogScrub.cc b/src/osd/PrimaryLogScrub.cc index 3747cd69841..2bdcbf36c7c 100644 --- a/src/osd/PrimaryLogScrub.cc +++ b/src/osd/PrimaryLogScrub.cc @@ -14,6 +14,8 @@ #undef dout_prefix #define dout_prefix _prefix(_dout, this->m_pg) +using std::vector; + template static ostream& _prefix(std::ostream* _dout, T* t) { return t->gen_prefix(*_dout) << " PrimaryLog scrubber pg(" << t->pg_id << ") "; diff --git a/src/osd/ReplicatedBackend.cc b/src/osd/ReplicatedBackend.cc index f26650bb86d..b0715e2decb 100644 --- a/src/osd/ReplicatedBackend.cc +++ b/src/osd/ReplicatedBackend.cc @@ -33,6 +33,7 @@ static ostream& _prefix(std::ostream *_dout, ReplicatedBackend *pgb) { return pgb->get_parent()->gen_dbg_prefix(*_dout); } +using std::less; using std::list; using std::make_pair; using std::map; diff --git a/src/osd/Watch.cc b/src/osd/Watch.cc index ca71620d0df..c36ecdc5413 100644 --- a/src/osd/Watch.cc +++ b/src/osd/Watch.cc @@ -23,6 +23,7 @@ using std::make_pair; using std::pair; using std::ostream; using std::set; +using std::vector; using ceph::bufferlist; using ceph::decode; diff --git a/src/osd/osd_types.cc b/src/osd/osd_types.cc index 2c5da52158f..bdcd47b6263 100644 --- a/src/osd/osd_types.cc +++ b/src/osd/osd_types.cc @@ -46,6 +46,7 @@ using std::map; using std::ostream; using std::pair; using std::set; +using std::shared_ptr; using std::string; using std::unique_ptr; using std::vector; diff --git a/src/osd/osd_types.h b/src/osd/osd_types.h index 94693bdfc0f..43b969c9e34 100644 --- a/src/osd/osd_types.h +++ b/src/osd/osd_types.h @@ -1517,12 +1517,12 @@ public: return peering_crush_bucket_count != 0; } - bool stretch_set_can_peer(const set& want, const OSDMap& osdmap, + bool stretch_set_can_peer(const std::set& want, const OSDMap& osdmap, std::ostream *out) const; - bool stretch_set_can_peer(const vector& want, const OSDMap& osdmap, + bool stretch_set_can_peer(const std::vector& want, const OSDMap& osdmap, std::ostream *out) const { if (!is_stretch_pool()) return true; - set swant; + std::set swant; for (auto i : want) swant.insert(i); return stretch_set_can_peer(swant, osdmap, out); } diff --git a/src/osd/pg_scrubber.cc b/src/osd/pg_scrubber.cc index 0a98f5addc0..41128b2f1b5 100644 --- a/src/osd/pg_scrubber.cc +++ b/src/osd/pg_scrubber.cc @@ -19,10 +19,16 @@ #include "ScrubStore.h" #include "scrub_machine.h" +using std::list; +using std::map; +using std::pair; +using std::set; +using std::stringstream; +using std::vector; using namespace Scrub; using namespace std::chrono; using namespace std::chrono_literals; - +using namespace std::literals; #define dout_context (m_pg->cct) #define dout_subsys ceph_subsys_osd @@ -838,7 +844,7 @@ std::string PgScrubber::dump_awaited_maps() const void PgScrubber::update_op_mode_text() { auto visible_repair = state_test(PG_STATE_REPAIR); - m_mode_desc = (visible_repair ? "repair"sv : (m_is_deep ? "deep-scrub"sv : "scrub"sv)); + m_mode_desc = (visible_repair ? "repair" : (m_is_deep ? "deep-scrub" : "scrub")); dout(10) << __func__ << ": repair: visible: " << (visible_repair ? "true" : "false") << ", internal: " << (m_is_repair ? "true" : "false") diff --git a/src/osd/pg_scrubber.h b/src/osd/pg_scrubber.h index 0145ae6515f..cc1f5d81711 100644 --- a/src/osd/pg_scrubber.h +++ b/src/osd/pg_scrubber.h @@ -339,7 +339,7 @@ class PgScrubber : public ScrubPgIF, public ScrubMachineListener { int asok_debug(std::string_view cmd, std::string param, Formatter* f, - stringstream& ss) override; + std::stringstream& ss) override; int m_debug_blockrange{0}; // ------------------------------------------------------------------------------------------- diff --git a/src/osd/recovery_types.cc b/src/osd/recovery_types.cc index 3dd49a82d06..70ba1fd797e 100644 --- a/src/osd/recovery_types.cc +++ b/src/osd/recovery_types.cc @@ -3,7 +3,7 @@ #include "recovery_types.h" -ostream& operator<<(ostream& out, const BackfillInterval& bi) +std::ostream& operator<<(std::ostream& out, const BackfillInterval& bi) { out << "BackfillInfo(" << bi.begin << "-" << bi.end << " " << bi.objects.size() << " objects"; diff --git a/src/osd/scrubber_common.h b/src/osd/scrubber_common.h index 30883bf8bf3..b733464baf6 100644 --- a/src/osd/scrubber_common.h +++ b/src/osd/scrubber_common.h @@ -101,7 +101,7 @@ struct requested_scrub_t { bool check_repair{false}; }; -ostream& operator<<(ostream& out, const requested_scrub_t& sf); +std::ostream& operator<<(std::ostream& out, const requested_scrub_t& sf); /** * The interface used by the PG when requesting scrub-related info or services @@ -110,9 +110,9 @@ struct ScrubPgIF { virtual ~ScrubPgIF() = default; - friend ostream& operator<<(ostream& out, const ScrubPgIF& s) { return s.show(out); } + friend std::ostream& operator<<(std::ostream& out, const ScrubPgIF& s) { return s.show(out); } - virtual ostream& show(ostream& out) const = 0; + virtual std::ostream& show(std::ostream& out) const = 0; // --------------- triggering state-machine events: @@ -283,5 +283,5 @@ struct ScrubPgIF { virtual int asok_debug(std::string_view cmd, std::string param, Formatter* f, - stringstream& ss) = 0; + std::stringstream& ss) = 0; }; -- 2.39.5