From: Kefu Chai Date: Wed, 11 Aug 2021 03:48:33 +0000 (+0800) Subject: mgr: build without "using namespace std" X-Git-Tag: v17.1.0~1121^2~34 X-Git-Url: http://git-server-git.apps.pok.os.sepia.ceph.com/?a=commitdiff_plain;h=c63ecb602e5916d5e0beed137787fdfc67707f15;p=ceph-ci.git mgr: 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/ceph_mgr.cc b/src/ceph_mgr.cc index 308ce8403d3..a80eb2f2433 100644 --- a/src/ceph_mgr.cc +++ b/src/ceph_mgr.cc @@ -30,8 +30,8 @@ static void usage() { - cout << "usage: ceph-mgr -i [flags]\n" - << std::endl; + std::cout << "usage: ceph-mgr -i [flags]\n" + << std::endl; generic_server_usage(); } @@ -43,10 +43,10 @@ int main(int argc, const char **argv) { ceph_pthread_setname(pthread_self(), "ceph-mgr"); - vector args; + std::vector args; argv_to_vec(argc, argv, args); if (args.empty()) { - cerr << argv[0] << ": -h or --help for usage" << std::endl; + std::cerr << argv[0] << ": -h or --help for usage" << std::endl; exit(1); } if (ceph_argparse_need_usage(args)) { @@ -54,7 +54,7 @@ int main(int argc, const char **argv) exit(0); } - map defaults = { + std::map defaults = { { "keyring", "$mgr_data/keyring" } }; auto cct = global_init(&defaults, args, CEPH_ENTITY_TYPE_MGR, diff --git a/src/mgr/ActivePyModule.cc b/src/mgr/ActivePyModule.cc index 20cf1b945fa..c244966e598 100644 --- a/src/mgr/ActivePyModule.cc +++ b/src/mgr/ActivePyModule.cc @@ -25,6 +25,9 @@ #undef dout_prefix #define dout_prefix *_dout << "mgr " << __func__ << " " +using std::string; +using namespace std::literals; + int ActivePyModule::load(ActivePyModules *py_modules) { ceph_assert(py_modules); diff --git a/src/mgr/ActivePyModules.cc b/src/mgr/ActivePyModules.cc index 4981a53b8db..e1179d4debb 100644 --- a/src/mgr/ActivePyModules.cc +++ b/src/mgr/ActivePyModules.cc @@ -38,6 +38,10 @@ #undef dout_prefix #define dout_prefix *_dout << "mgr " << __func__ << " " +using std::pair; +using std::string; +using namespace std::literals; + ActivePyModules::ActivePyModules( PyModuleConfig &module_config_, std::map store_data, diff --git a/src/mgr/BaseMgrModule.cc b/src/mgr/BaseMgrModule.cc index c1335bee1dd..6386265fc7e 100644 --- a/src/mgr/BaseMgrModule.cc +++ b/src/mgr/BaseMgrModule.cc @@ -38,6 +38,8 @@ #define PLACEHOLDER "" +using std::list; +using std::string; typedef struct { PyObject_HEAD diff --git a/src/mgr/BaseMgrStandbyModule.cc b/src/mgr/BaseMgrStandbyModule.cc index 6f35088d030..22dfd3be84c 100644 --- a/src/mgr/BaseMgrStandbyModule.cc +++ b/src/mgr/BaseMgrStandbyModule.cc @@ -21,6 +21,8 @@ #define dout_context g_ceph_context #define dout_subsys ceph_subsys_mgr +using std::string; + typedef struct { PyObject_HEAD StandbyPyModule *this_module; diff --git a/src/mgr/ClusterState.cc b/src/mgr/ClusterState.cc index 28340d56ddd..2d7efe4dfd8 100644 --- a/src/mgr/ClusterState.cc +++ b/src/mgr/ClusterState.cc @@ -24,6 +24,11 @@ #undef dout_prefix #define dout_prefix *_dout << "mgr " << __func__ << " " +using std::ostream; +using std::set; +using std::string; +using std::stringstream; + ClusterState::ClusterState( MonClient *monc_, Objecter *objecter_, diff --git a/src/mgr/ClusterState.h b/src/mgr/ClusterState.h index eeff1f76bd9..7939cd8eb8f 100644 --- a/src/mgr/ClusterState.h +++ b/src/mgr/ClusterState.h @@ -43,7 +43,7 @@ protected: MgrMap mgr_map; - map existing_pools; ///< pools that exist, and pg_num, as of PGMap epoch + std::map existing_pools; ///< pools that exist, and pg_num, as of PGMap epoch PGMap pg_map; PGMap::Incremental pending_inc; @@ -156,7 +156,7 @@ public: bool asok_command(std::string_view admin_command, const cmdmap_t& cmdmap, Formatter *f, - ostream& ss); + std::ostream& ss); }; #endif diff --git a/src/mgr/DaemonHealthMetricCollector.cc b/src/mgr/DaemonHealthMetricCollector.cc index 53c0b78a690..bf206015aba 100644 --- a/src/mgr/DaemonHealthMetricCollector.cc +++ b/src/mgr/DaemonHealthMetricCollector.cc @@ -6,6 +6,10 @@ namespace { +using std::unique_ptr; +using std::vector; +using std::ostringstream; + class SlowOps final : public DaemonHealthMetricCollector { bool _is_relevant(daemon_metric type) const override { return type == daemon_metric::SLOW_OPS; diff --git a/src/mgr/DaemonServer.cc b/src/mgr/DaemonServer.cc index 552f8322ff5..36ab66db999 100644 --- a/src/mgr/DaemonServer.cc +++ b/src/mgr/DaemonServer.cc @@ -45,7 +45,16 @@ #define dout_subsys ceph_subsys_mgr #undef dout_prefix #define dout_prefix *_dout << "mgr.server " << __func__ << " " + using namespace TOPNSPC::common; + +using std::list; +using std::ostringstream; +using std::string; +using std::stringstream; +using std::vector; +using std::unique_ptr; + namespace { template bool map_compare(Map const &lhs, Map const &rhs) { @@ -1064,7 +1073,7 @@ bool DaemonServer::_handle_command( auto dump_cmd = [&cmdnum, &f, m](const MonCommand &mc){ ostringstream secname; - secname << "cmd" << setfill('0') << std::setw(3) << cmdnum; + secname << "cmd" << std::setfill('0') << std::setw(3) << cmdnum; dump_cmddesc_to_json(&f, m->get_connection()->get_features(), secname.str(), mc.cmdstring, mc.helpstring, mc.module, mc.req_perms, 0); diff --git a/src/mgr/DaemonServer.h b/src/mgr/DaemonServer.h index 3adcf6ccaf9..b3c9f191aa1 100644 --- a/src/mgr/DaemonServer.h +++ b/src/mgr/DaemonServer.h @@ -146,7 +146,7 @@ protected: std::set daemon_connections; /// connections for osds - ceph::unordered_map> osd_cons; + ceph::unordered_map> osd_cons; ServiceMap pending_service_map; // uncommitted @@ -155,13 +155,13 @@ protected: ceph::mutex lock = ceph::make_mutex("DaemonServer"); static void _generate_command_map(cmdmap_t& cmdmap, - map ¶m_str_map); - static const MonCommand *_get_mgrcommand(const string &cmd_prefix, + std::map ¶m_str_map); + static const MonCommand *_get_mgrcommand(const std::string &cmd_prefix, const std::vector &commands); bool _allowed_command( - MgrSession *s, const string &service, const string &module, - const string &prefix, const cmdmap_t& cmdmap, - const map& param_str_map, + MgrSession *s, const std::string &service, const std::string &module, + const std::string &prefix, const cmdmap_t& cmdmap, + const std::map& param_str_map, const MonCommand *this_cmd); private: @@ -172,7 +172,7 @@ private: void _prune_pending_service_map(); void _check_offlines_pgs( - const set& osds, + const std::set& osds, const OSDMap& osdmap, const PGMap& pgmap, offline_pg_report *report); diff --git a/src/mgr/DaemonState.cc b/src/mgr/DaemonState.cc index 32cbbe3b9c0..f8286c64fcb 100644 --- a/src/mgr/DaemonState.cc +++ b/src/mgr/DaemonState.cc @@ -24,6 +24,15 @@ #undef dout_prefix #define dout_prefix *_dout << "mgr " << __func__ << " " +using std::list; +using std::make_pair; +using std::map; +using std::ostream; +using std::ostringstream; +using std::string; +using std::stringstream; +using std::unique_ptr; + void DeviceState::set_metadata(map&& m) { metadata = std::move(m); diff --git a/src/mgr/DaemonState.h b/src/mgr/DaemonState.h index a9684aa6629..8e72cff0419 100644 --- a/src/mgr/DaemonState.h +++ b/src/mgr/DaemonState.h @@ -169,7 +169,7 @@ class DaemonState metadata = m; auto p = m.find("device_ids"); if (p != m.end()) { - map devs, paths; // devname -> id or path + std::map devs, paths; // devname -> id or path get_str_map(p->second, &devs, ",; "); auto q = m.find("device_paths"); if (q != m.end()) { @@ -215,20 +215,20 @@ struct DeviceState : public RefCountedObject std::set> attachments; std::set daemons; - std::map metadata; ///< persistent metadata + std::map metadata; ///< persistent metadata - pair life_expectancy; ///< when device failure is expected + std::pair life_expectancy; ///< when device failure is expected utime_t life_expectancy_stamp; ///< when life expectency was recorded float wear_level = -1; ///< SSD wear level (negative if unknown) - void set_metadata(map&& m); + void set_metadata(std::map&& m); void set_life_expectancy(utime_t from, utime_t to, utime_t now); void rm_life_expectancy(); void set_wear_level(float wear); - string get_life_expectancy_str(utime_t now) const; + std::string get_life_expectancy_str(utime_t now) const; /// true of we can be safely forgotten/removed from memory bool empty() const { @@ -236,7 +236,7 @@ struct DeviceState : public RefCountedObject } void dump(Formatter *f) const; - void print(ostream& out) const; + void print(std::ostream& out) const; private: FRIEND_MAKE_REF(DeviceState); @@ -382,7 +382,7 @@ public: } void update_metadata(DaemonStatePtr state, - const map& meta) { + const std::map& meta) { // remove and re-insert in case the device metadata changed std::unique_lock l{lock}; _rm(state->key); diff --git a/src/mgr/Mgr.cc b/src/mgr/Mgr.cc index c20242e9fe6..b609c7d1d5c 100644 --- a/src/mgr/Mgr.cc +++ b/src/mgr/Mgr.cc @@ -43,6 +43,11 @@ #undef dout_prefix #define dout_prefix *_dout << "mgr " << __func__ << " " +using namespace std::literals; + +using std::map; +using std::ostringstream; +using std::string; Mgr::Mgr(MonClient *monc_, const MgrMap& mgrmap, PyModuleRegistry *py_module_registry_, diff --git a/src/mgr/MgrStandby.cc b/src/mgr/MgrStandby.cc index 14d95ab5158..f3d1b38770a 100644 --- a/src/mgr/MgrStandby.cc +++ b/src/mgr/MgrStandby.cc @@ -36,6 +36,9 @@ #undef dout_prefix #define dout_prefix *_dout << "mgr " << __func__ << " " +using std::map; +using std::string; +using std::vector; MgrStandby::MgrStandby(int argc, const char **argv) : Dispatcher(g_ceph_context), diff --git a/src/mgr/MgrStandby.h b/src/mgr/MgrStandby.h index cac31a57640..0f06e3074a0 100644 --- a/src/mgr/MgrStandby.h +++ b/src/mgr/MgrStandby.h @@ -81,7 +81,7 @@ public: int init(); void shutdown(); void respawn(); - int main(vector args); + int main(std::vector args); void tick(); }; diff --git a/src/mgr/PyModule.cc b/src/mgr/PyModule.cc index 144f4354c2f..87100c50421 100644 --- a/src/mgr/PyModule.cc +++ b/src/mgr/PyModule.cc @@ -46,6 +46,9 @@ std::string PyModule::mgr_store_prefix = "mgr/"; #include "include/ceph_assert.h" // boost clobbers this +using std::string; +using std::wstring; + // decode a Python exception into a string std::string handle_pyerror( bool crash_dump, diff --git a/src/mgr/PyOSDMap.cc b/src/mgr/PyOSDMap.cc index 782b3bc6a04..ad188afccbc 100644 --- a/src/mgr/PyOSDMap.cc +++ b/src/mgr/PyOSDMap.cc @@ -15,6 +15,10 @@ #define dout_context g_ceph_context #define dout_subsys ceph_subsys_mgr +using std::map; +using std::set; +using std::string; +using std::vector; typedef struct { PyObject_HEAD diff --git a/src/mgr/ServiceMap.cc b/src/mgr/ServiceMap.cc index 04b32b27ee4..fd91d19abb0 100644 --- a/src/mgr/ServiceMap.cc +++ b/src/mgr/ServiceMap.cc @@ -98,8 +98,8 @@ std::string ServiceMap::Service::get_summary() const p != d.second.metadata.end()) { type = p->second; } - for (auto k : {make_pair("zone", "zone_id"), - make_pair("host", "hostname")}) { + for (auto k : {std::make_pair("zone", "zone_id"), + std::make_pair("host", "hostname")}) { auto p = d.second.metadata.find(k.second); if (p != d.second.metadata.end()) { groupings[k.first].insert(p->second);