From: Kefu Chai Date: Wed, 11 Aug 2021 03:54:56 +0000 (+0800) Subject: cls: build without "using namespace std" X-Git-Tag: v17.1.0~1121^2~25 X-Git-Url: http://git-server-git.apps.pok.os.sepia.ceph.com/?a=commitdiff_plain;h=9bc2e9d253fc89d39d2ce520e6f95109b78983a4;p=ceph.git cls: 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 --- diff --git a/src/cls/2pc_queue/cls_2pc_queue_client.cc b/src/cls/2pc_queue/cls_2pc_queue_client.cc index 3eb2d0f6a0bd..6868b2b6f83e 100644 --- a/src/cls/2pc_queue/cls_2pc_queue_client.cc +++ b/src/cls/2pc_queue/cls_2pc_queue_client.cc @@ -32,7 +32,7 @@ int cls_2pc_queue_get_capacity_result(const bufferlist& bl, uint64_t& size) { } #ifndef CLS_CLIENT_HIDE_IOCTX -int cls_2pc_queue_get_capacity(IoCtx& io_ctx, const string& queue_name, uint64_t& size) { +int cls_2pc_queue_get_capacity(IoCtx& io_ctx, const std::string& queue_name, uint64_t& size) { bufferlist in, out; const auto r = io_ctx.exec(queue_name, TPC_QUEUE_CLASS, TPC_QUEUE_GET_CAPACITY, in, out); if (r < 0 ) { @@ -64,7 +64,7 @@ int cls_2pc_queue_reserve_result(const bufferlist& bl, cls_2pc_reservation::id_t return 0; } -int cls_2pc_queue_reserve(IoCtx& io_ctx, const string& queue_name, +int cls_2pc_queue_reserve(IoCtx& io_ctx, const std::string& queue_name, uint64_t res_size, uint32_t entries, cls_2pc_reservation::id_t& res_id) { bufferlist in, out; cls_2pc_queue_reserve_op reserve_op; @@ -131,9 +131,11 @@ int cls_2pc_queue_list_entries_result(const bufferlist& bl, std::vector& entries, - bool *truncated, std::string& next_marker) { +int cls_2pc_queue_list_entries(IoCtx& io_ctx, + const std::string& queue_name, + const std::string& marker, uint32_t max, + std::vector& entries, + bool *truncated, std::string& next_marker) { bufferlist in, out; cls_queue_list_op op; op.start_marker = marker; diff --git a/src/cls/2pc_queue/cls_2pc_queue_client.h b/src/cls/2pc_queue/cls_2pc_queue_client.h index bbdfcc2e0893..e0bdeafd5909 100644 --- a/src/cls/2pc_queue/cls_2pc_queue_client.h +++ b/src/cls/2pc_queue/cls_2pc_queue_client.h @@ -18,7 +18,7 @@ void cls_2pc_queue_init(librados::ObjectWriteOperation& op, const std::string& q // rgw_rados_operate() should be called after the overloads w/o calls to io_ctx.operate()/exec() #ifndef CLS_CLIENT_HIDE_IOCTX // return capacity (bytes) -int cls_2pc_queue_get_capacity(librados::IoCtx& io_ctx, const string& queue_name, uint64_t& size); +int cls_2pc_queue_get_capacity(librados::IoCtx& io_ctx, const std::string& queue_name, uint64_t& size); // make a reservation on the queue (in bytes) and number of expected entries (to calculate overhead) // return a reservation id if reservations is possible, 0 otherwise diff --git a/src/cls/cas/cls_cas_internal.cc b/src/cls/cas/cls_cas_internal.cc index edaa96d27370..891b1c311bf1 100644 --- a/src/cls/cas/cls_cas_internal.cc +++ b/src/cls/cas/cls_cas_internal.cc @@ -129,7 +129,8 @@ void chunk_refs_t::decode(ceph::buffer::list::const_iterator& p) break; default: throw ceph::buffer::malformed_input( - "unrecognized chunk ref encoding type "s + stringify((int)t)); + std::string("unrecognized chunk ref encoding type ") + + stringify((int)t)); } DECODE_FINISH(p); } diff --git a/src/cls/cas/cls_cas_internal.h b/src/cls/cas/cls_cas_internal.h index 14d3119a9d24..09e7f9f1f69d 100644 --- a/src/cls/cas/cls_cas_internal.h +++ b/src/cls/cas/cls_cas_internal.h @@ -157,12 +157,13 @@ struct chunk_refs_by_hash_t : public chunk_refs_t::refs_t { chunk_refs_by_hash_t(const chunk_refs_by_object_t *o) { total = o->count(); for (auto& i : o->by_object) { - by_hash[make_pair(i.pool, i.get_hash())]++; + by_hash[std::make_pair(i.pool, i.get_hash())]++; } } std::string describe_encoding() const { - return "by_hash("s + stringify(hash_bits) + " bits)"s; + using namespace std::literals; + return "by_hash("s + stringify(hash_bits) + " bits)"; } uint32_t mask() { @@ -181,7 +182,7 @@ struct chunk_refs_by_hash_t : public chunk_refs_t::refs_t { old.swap(by_hash); auto m = mask(); for (auto& i : old) { - by_hash[make_pair(i.first.first, i.first.second & m)] = i.second; + by_hash[std::make_pair(i.first.first, i.first.second & m)] = i.second; } return true; } @@ -196,11 +197,11 @@ struct chunk_refs_by_hash_t : public chunk_refs_t::refs_t { return total; } void get(const hobject_t& o) override { - by_hash[make_pair(o.pool, o.get_hash() & mask())]++; + by_hash[std::make_pair(o.pool, o.get_hash() & mask())]++; ++total; } bool put(const hobject_t& o) override { - auto p = by_hash.find(make_pair(o.pool, o.get_hash() & mask())); + auto p = by_hash.find(std::make_pair(o.pool, o.get_hash() & mask())); if (p == by_hash.end()) { return false; } @@ -242,7 +243,7 @@ struct chunk_refs_by_hash_t : public chunk_refs_t::refs_t { denc_signed_varint(poolid, p); memcpy(&hash, p.get_pos_add(hash_bytes), hash_bytes); denc_varint(count, p); - by_hash[make_pair(poolid, (uint32_t)hash)] = count; + by_hash[std::make_pair(poolid, (uint32_t)hash)] = count; } DENC_FINISH(p); } @@ -265,7 +266,7 @@ WRITE_CLASS_DENC(chunk_refs_by_hash_t) struct chunk_refs_by_pool_t : public chunk_refs_t::refs_t { uint64_t total = 0; - map by_pool; + std::map by_pool; chunk_refs_by_pool_t() {} chunk_refs_by_pool_t(const chunk_refs_by_hash_t *o) { diff --git a/src/cls/fifo/cls_fifo_ops.h b/src/cls/fifo/cls_fifo_ops.h index a3f4ae237c9c..91a012c0847e 100644 --- a/src/cls/fifo/cls_fifo_ops.h +++ b/src/cls/fifo/cls_fifo_ops.h @@ -215,7 +215,7 @@ WRITE_CLASS_ENCODER(trim_part) struct list_part { - std::optional tag; + std::optional tag; std::uint64_t ofs{0}; int max_entries{100}; diff --git a/src/cls/fifo/cls_fifo_types.h b/src/cls/fifo/cls_fifo_types.h index 749f66e7b96e..8a471828b7a5 100644 --- a/src/cls/fifo/cls_fifo_types.h +++ b/src/cls/fifo/cls_fifo_types.h @@ -76,7 +76,7 @@ struct objv { } }; WRITE_CLASS_ENCODER(objv) -inline ostream& operator <<(std::ostream& os, const objv& objv) +inline std::ostream& operator <<(std::ostream& os, const objv& objv) { return os << objv.to_str(); } @@ -310,7 +310,7 @@ struct info { std::int64_t max_push_part_num{-1}; std::string head_tag; - std::map tags; + std::map tags; std::multimap journal; diff --git a/src/cls/lock/cls_lock_ops.cc b/src/cls/lock/cls_lock_ops.cc index ef4190c0a3c7..1f878be48eb7 100644 --- a/src/cls/lock/cls_lock_ops.cc +++ b/src/cls/lock/cls_lock_ops.cc @@ -18,6 +18,9 @@ #include "cls/lock/cls_lock_ops.h" using namespace rados::cls::lock; +using std::list; +using std::map; +using std::string; static void generate_lock_id(locker_id_t& i, int n, const string& cookie) { diff --git a/src/cls/lua/cls_lua.cc b/src/cls/lua/cls_lua.cc index ecc5417fca46..dea5fe1a8248 100644 --- a/src/cls/lua/cls_lua.cc +++ b/src/cls/lua/cls_lua.cc @@ -12,6 +12,8 @@ #include "cls_lua.h" #include "cls_lua_ops.h" +using namespace std; + CLS_VER(1,0) CLS_NAME(lua) diff --git a/src/cls/queue/cls_queue_client.cc b/src/cls/queue/cls_queue_client.cc index 97f67d3d74ee..87d17bb9e315 100644 --- a/src/cls/queue/cls_queue_client.cc +++ b/src/cls/queue/cls_queue_client.cc @@ -6,6 +6,7 @@ #include "cls/queue/cls_queue_const.h" #include "cls/queue/cls_queue_client.h" +using namespace std; using namespace librados; void cls_queue_init(ObjectWriteOperation& op, const string& queue_name, uint64_t size) diff --git a/src/cls/queue/cls_queue_client.h b/src/cls/queue/cls_queue_client.h index 59d32bfa1a75..895a51c11737 100644 --- a/src/cls/queue/cls_queue_client.h +++ b/src/cls/queue/cls_queue_client.h @@ -6,11 +6,11 @@ #include "cls_queue_ops.h" #include "common/ceph_time.h" -void cls_queue_init(librados::ObjectWriteOperation& op, const string& queue_name, uint64_t size); -int cls_queue_get_capacity(librados::IoCtx& io_ctx, const string& oid, uint64_t& size); -void cls_queue_enqueue(librados::ObjectWriteOperation& op, uint32_t expiration_secs, vector bl_data_vec); -int cls_queue_list_entries(librados::IoCtx& io_ctx, const string& oid, const string& marker, uint32_t max, - vector& entries, bool *truncated, string& next_marker); -void cls_queue_remove_entries(librados::ObjectWriteOperation& op, const string& end_marker); +void cls_queue_init(librados::ObjectWriteOperation& op, const std::string& queue_name, uint64_t size); +int cls_queue_get_capacity(librados::IoCtx& io_ctx, const std::string& oid, uint64_t& size); +void cls_queue_enqueue(librados::ObjectWriteOperation& op, uint32_t expiration_secs, std::vector bl_data_vec); +int cls_queue_list_entries(librados::IoCtx& io_ctx, const std::string& oid, const std::string& marker, uint32_t max, + std::vector& entries, bool *truncated, std::string& next_marker); +void cls_queue_remove_entries(librados::ObjectWriteOperation& op, const std::string& end_marker); -#endif \ No newline at end of file +#endif diff --git a/src/cls/queue/cls_queue_src.cc b/src/cls/queue/cls_queue_src.cc index 8806b5804971..bd973352d425 100644 --- a/src/cls/queue/cls_queue_src.cc +++ b/src/cls/queue/cls_queue_src.cc @@ -9,6 +9,7 @@ #include "cls/queue/cls_queue_const.h" #include "cls/queue/cls_queue_src.h" +using std::string; using ceph::bufferlist; using ceph::decode; using ceph::encode; diff --git a/src/cls/rgw/cls_rgw_client.h b/src/cls/rgw/cls_rgw_client.h index 67508b21f277..74cc25f0eaab 100644 --- a/src/cls/rgw/cls_rgw_client.h +++ b/src/cls/rgw/cls_rgw_client.h @@ -599,13 +599,13 @@ int cls_rgw_gc_list(librados::IoCtx& io_ctx, std::string& oid, std::string& mark #ifndef CLS_CLIENT_HIDE_IOCTX int cls_rgw_lc_get_head(librados::IoCtx& io_ctx, const std::string& oid, cls_rgw_lc_obj_head& head); int cls_rgw_lc_put_head(librados::IoCtx& io_ctx, const std::string& oid, cls_rgw_lc_obj_head& head); -int cls_rgw_lc_get_next_entry(librados::IoCtx& io_ctx, const std::string& oid, string& marker, cls_rgw_lc_entry& entry); +int cls_rgw_lc_get_next_entry(librados::IoCtx& io_ctx, const std::string& oid, std::string& marker, cls_rgw_lc_entry& entry); int cls_rgw_lc_rm_entry(librados::IoCtx& io_ctx, const std::string& oid, const cls_rgw_lc_entry& entry); int cls_rgw_lc_set_entry(librados::IoCtx& io_ctx, const std::string& oid, const cls_rgw_lc_entry& entry); int cls_rgw_lc_get_entry(librados::IoCtx& io_ctx, const std::string& oid, const std::string& marker, cls_rgw_lc_entry& entry); int cls_rgw_lc_list(librados::IoCtx& io_ctx, const std::string& oid, const std::string& marker, uint32_t max_entries, - vector& entries); + std::vector& entries); #endif /* resharding */ diff --git a/src/cls/rgw/cls_rgw_ops.h b/src/cls/rgw/cls_rgw_ops.h index a90c5e103a97..c5e252e645a4 100644 --- a/src/cls/rgw/cls_rgw_ops.h +++ b/src/cls/rgw/cls_rgw_ops.h @@ -1221,7 +1221,7 @@ struct cls_rgw_lc_list_entries_op { WRITE_CLASS_ENCODER(cls_rgw_lc_list_entries_op) struct cls_rgw_lc_list_entries_ret { - vector entries; + std::vector entries; bool is_truncated{false}; uint8_t compat_v; @@ -1231,7 +1231,7 @@ cls_rgw_lc_list_entries_ret(uint8_t compat_v = 3) void encode(ceph::buffer::list& bl) const { ENCODE_START(compat_v, 1, bl); if (compat_v <= 2) { - map oes; + std::map oes; std::for_each(entries.begin(), entries.end(), [&oes](const cls_rgw_lc_entry& elt) {oes.insert({elt.bucket, elt.status});}); @@ -1247,10 +1247,10 @@ cls_rgw_lc_list_entries_ret(uint8_t compat_v = 3) DECODE_START(3, bl); compat_v = struct_v; if (struct_v <= 2) { - map oes; + std::map oes; decode(oes, bl); std::for_each(oes.begin(), oes.end(), - [this](const std::pair& oe) + [this](const std::pair& oe) {entries.push_back({oe.first, 0 /* start */, uint32_t(oe.second)});}); } else { diff --git a/src/cls/timeindex/cls_timeindex_types.cc b/src/cls/timeindex/cls_timeindex_types.cc index 98c3741863fb..1a748967bd82 100644 --- a/src/cls/timeindex/cls_timeindex_types.cc +++ b/src/cls/timeindex/cls_timeindex_types.cc @@ -8,7 +8,7 @@ void cls_timeindex_entry::dump(Formatter *f) const f->dump_string("value", value.to_str()); } -void cls_timeindex_entry::generate_test_instances(list& o) +void cls_timeindex_entry::generate_test_instances(std::list& o) { cls_timeindex_entry *i = new cls_timeindex_entry; i->key_ts = utime_t(0,0);