From: Adam C. Emerson Date: Sat, 7 Mar 2020 09:30:35 +0000 (-0500) Subject: common: Build target 'common' without using namespace in headers X-Git-Tag: v16.0.0~18^2~5 X-Git-Url: http://git-server-git.apps.pok.os.sepia.ceph.com/?a=commitdiff_plain;h=aa516b484365e6c519e680d162b9383e14070964;p=ceph.git common: Build target 'common' without using namespace in headers Part of a changeset to allow building all of 'common' without relying on 'using namespace std' or 'using namespace ceph' at toplevel in headers. Signed-off-by: Adam C. Emerson --- diff --git a/src/common/CommandTable.h b/src/common/CommandTable.h index 419988f7748b8..53218d65351fc 100644 --- a/src/common/CommandTable.h +++ b/src/common/CommandTable.h @@ -34,13 +34,13 @@ class CommandOp bool mgr=false) const { if (mgr) { - auto m = make_message(fsid); + auto m = ceph::make_message(fsid); m->cmd = cmd; m->set_data(inbl); m->set_tid(tid); return m; } else { - auto m = make_message(fsid); + auto m = ceph::make_message(fsid); m->cmd = cmd; m->set_data(inbl); m->set_tid(tid); diff --git a/src/common/DecayCounter.cc b/src/common/DecayCounter.cc index f34a6eba386e9..4e9e68cc1525d 100644 --- a/src/common/DecayCounter.cc +++ b/src/common/DecayCounter.cc @@ -17,7 +17,7 @@ #include "include/encoding.h" -void DecayCounter::encode(bufferlist& bl) const +void DecayCounter::encode(ceph::buffer::list& bl) const { decay(); ENCODE_START(5, 4, bl); @@ -25,7 +25,7 @@ void DecayCounter::encode(bufferlist& bl) const ENCODE_FINISH(bl); } -void DecayCounter::decode(bufferlist::const_iterator &p) +void DecayCounter::decode(ceph::buffer::list::const_iterator &p) { DECODE_START_LEGACY_COMPAT_LEN(5, 4, 4, p); if (struct_v < 2) { @@ -47,7 +47,7 @@ void DecayCounter::decode(bufferlist::const_iterator &p) DECODE_FINISH(p); } -void DecayCounter::dump(Formatter *f) const +void DecayCounter::dump(ceph::Formatter *f) const { decay(); f->dump_float("value", val); diff --git a/src/common/DecayCounter.h b/src/common/DecayCounter.h index b9545b1516194..2202b596e2adc 100644 --- a/src/common/DecayCounter.h +++ b/src/common/DecayCounter.h @@ -60,9 +60,9 @@ public: DecayCounter() : DecayCounter(DecayRate()) {} explicit DecayCounter(const DecayRate &rate) : last_decay(clock::now()), rate(rate) {} - void encode(bufferlist& bl) const; - void decode(bufferlist::const_iterator& p); - void dump(Formatter *f) const; + void encode(ceph::buffer::list& bl) const; + void decode(ceph::buffer::list::const_iterator& p); + void dump(ceph::Formatter *f) const; static void generate_test_instances(std::list& ls); /** @@ -117,10 +117,10 @@ private: DecayRate rate; }; -inline void encode(const DecayCounter &c, bufferlist &bl) { +inline void encode(const DecayCounter &c, ceph::buffer::list &bl) { c.encode(bl); } -inline void decode(DecayCounter &c, bufferlist::const_iterator &p) { +inline void decode(DecayCounter &c, ceph::buffer::list::const_iterator &p) { c.decode(p); } diff --git a/src/common/Graylog.cc b/src/common/Graylog.cc index 79a537eeddeea..accde0900a50e 100644 --- a/src/common/Graylog.cc +++ b/src/common/Graylog.cc @@ -7,8 +7,9 @@ #include "log/Entry.h" #include "log/SubsystemMap.h" -namespace ceph { -namespace logging { +using std::cerr; + +namespace ceph::logging { Graylog::Graylog(const SubsystemMap * const s, const std::string &logger) : m_subs(s), @@ -166,5 +167,4 @@ void Graylog::log_log_entry(LogEntry const * const e) } } -} // ceph::logging:: -} // ceph:: +} // name ceph::logging diff --git a/src/common/HeartbeatMap.cc b/src/common/HeartbeatMap.cc index 165fdbb3fac3a..7e5b814063275 100644 --- a/src/common/HeartbeatMap.cc +++ b/src/common/HeartbeatMap.cc @@ -24,6 +24,10 @@ #undef dout_prefix #define dout_prefix *_dout << "heartbeat_map " +using std::chrono::duration_cast; +using std::chrono::seconds; +using std::string; + namespace ceph { HeartbeatMap::HeartbeatMap(CephContext *cct) @@ -88,8 +92,8 @@ void HeartbeatMap::reset_timeout(heartbeat_handle_d *h, { ldout(m_cct, 20) << "reset_timeout '" << h->name << "' grace " << grace << " suicide " << suicide_grace << dendl; - auto now = chrono::duration_cast( - ceph::coarse_mono_clock::now().time_since_epoch()).count(); + auto now = duration_cast(coarse_mono_clock::now() + .time_since_epoch()).count(); _check(h, "reset_timeout", now); h->timeout = now + grace; @@ -105,8 +109,8 @@ void HeartbeatMap::reset_timeout(heartbeat_handle_d *h, void HeartbeatMap::clear_timeout(heartbeat_handle_d *h) { ldout(m_cct, 20) << "clear_timeout '" << h->name << "'" << dendl; - auto now = chrono::duration_cast( - ceph::coarse_mono_clock::now().time_since_epoch()).count(); + auto now = duration_cast(coarse_mono_clock::now() + .time_since_epoch()).count(); _check(h, "clear_timeout", now); h->timeout = 0; h->suicide_timeout = 0; @@ -132,11 +136,11 @@ bool HeartbeatMap::is_healthy() healthy = false; } - for (list::iterator p = m_workers.begin(); + for (auto p = m_workers.begin(); p != m_workers.end(); ++p) { heartbeat_handle_d *h = *p; - auto epoch = chrono::duration_cast(now.time_since_epoch()).count(); + auto epoch = duration_cast(now.time_since_epoch()).count(); if (!_check(h, "is_healthy", epoch)) { healthy = false; unhealthy++; diff --git a/src/common/LogClient.cc b/src/common/LogClient.cc index b941bd47e3974..05e7101559b68 100644 --- a/src/common/LogClient.cc +++ b/src/common/LogClient.cc @@ -22,6 +22,11 @@ #define dout_subsys ceph_subsys_monc +using std::map; +using std::ostream; +using std::ostringstream; +using std::string; + int parse_log_client_options(CephContext *cct, map &log_to_monitors, map &log_to_syslog, @@ -351,7 +356,7 @@ bool LogClient::handle_log_ack(MLogAck *m) version_t last = m->last; - deque::iterator q = log_queue.begin(); + auto q = log_queue.begin(); while (q != log_queue.end()) { const LogEntry &entry(*q); if (entry.seq > last) @@ -361,4 +366,3 @@ bool LogClient::handle_log_ack(MLogAck *m) } return true; } - diff --git a/src/common/LogEntry.cc b/src/common/LogEntry.cc index 993bf444dc393..dfa1ab2fa1dfd 100644 --- a/src/common/LogEntry.cc +++ b/src/common/LogEntry.cc @@ -8,6 +8,17 @@ #include "Formatter.h" #include "include/stringify.h" +using std::list; +using std::map; +using std::make_pair; +using std::pair; +using std::string; + +using ceph::bufferlist; +using ceph::decode; +using ceph::encode; +using ceph::Formatter; + // ---- // LogEntryKey @@ -372,4 +383,3 @@ void LogSummary::generate_test_instances(list& o) o.push_back(new LogSummary); // more! } - diff --git a/src/common/OutputDataSocket.cc b/src/common/OutputDataSocket.cc index 33b27e6da76bf..2221de6462f37 100644 --- a/src/common/OutputDataSocket.cc +++ b/src/common/OutputDataSocket.cc @@ -255,7 +255,7 @@ bool OutputDataSocket::do_accept() void OutputDataSocket::handle_connection(int fd) { - bufferlist bl; + ceph::buffer::list bl; m_lock.lock(); init_connection(bl); @@ -294,13 +294,13 @@ void OutputDataSocket::handle_connection(int fd) int OutputDataSocket::dump_data(int fd) { m_lock.lock(); - vector l = std::move(data); + auto l = std::move(data); data.clear(); data_size = 0; m_lock.unlock(); for (auto iter = l.begin(); iter != l.end(); ++iter) { - bufferlist& bl = *iter; + ceph::buffer::list& bl = *iter; int ret = safe_write(fd, bl.c_str(), bl.length()); if (ret >= 0) { ret = safe_write(fd, delim.c_str(), delim.length()); @@ -308,7 +308,7 @@ int OutputDataSocket::dump_data(int fd) if (ret < 0) { std::scoped_lock lock(m_lock); for (; iter != l.end(); ++iter) { - bufferlist& bl = *iter; + ceph::buffer::list& bl = *iter; data.push_back(bl); data_size += bl.length(); } @@ -384,7 +384,7 @@ void OutputDataSocket::shutdown() m_path.clear(); } -void OutputDataSocket::append_output(bufferlist& bl) +void OutputDataSocket::append_output(ceph::buffer::list& bl) { std::lock_guard l(m_lock); diff --git a/src/common/OutputDataSocket.h b/src/common/OutputDataSocket.h index 5a6bc4ff9fca8..397d93f16f85f 100644 --- a/src/common/OutputDataSocket.h +++ b/src/common/OutputDataSocket.h @@ -29,10 +29,10 @@ public: bool init(const std::string &path); - void append_output(bufferlist& bl); + void append_output(ceph::buffer::list& bl); protected: - virtual void init_connection(bufferlist& bl) {} + virtual void init_connection(ceph::buffer::list& bl) {} void shutdown(); std::string create_shutdown_pipe(int *pipe_rd, int *pipe_wr); @@ -57,11 +57,11 @@ protected: uint64_t data_size; uint32_t skipped; - std::vector data; + std::vector data; ceph::mutex m_lock = ceph::make_mutex("OutputDataSocket::m_lock"); ceph::condition_variable cond; - buffer::list delim; + ceph::buffer::list delim; }; #endif diff --git a/src/common/PluginRegistry.cc b/src/common/PluginRegistry.cc index 2cb7fcee8db28..c697aaa17f006 100644 --- a/src/common/PluginRegistry.cc +++ b/src/common/PluginRegistry.cc @@ -34,6 +34,11 @@ #define dout_subsys ceph_subsys_context +using std::map; +using std::string; + +namespace ceph { + PluginRegistry::PluginRegistry(CephContext *cct) : cct(cct), loading(false), @@ -211,6 +216,7 @@ int PluginRegistry::load(const std::string &type, << " loaded and registered" << dendl; return 0; } +} /* int ErasureCodePluginRegistry::preload(const std::string &plugins, diff --git a/src/common/Readahead.cc b/src/common/Readahead.cc index 2d2b35ff781f2..5ce820fedeee7 100644 --- a/src/common/Readahead.cc +++ b/src/common/Readahead.cc @@ -4,6 +4,8 @@ #include "common/Readahead.h" #include "common/Cond.h" +using std::vector; + Readahead::Readahead() : m_trigger_requests(10), m_readahead_min_bytes(0), @@ -30,7 +32,7 @@ Readahead::extent_t Readahead::update(const vector& extents, uint64_t m_lock.unlock(); return extent_t(0, 0); } - pair extent = _compute_readahead(limit); + std::pair extent = _compute_readahead(limit); m_lock.unlock(); return extent; } diff --git a/src/common/SloppyCRCMap.cc b/src/common/SloppyCRCMap.cc index 102a6399765d1..ec9cbdf53a6a7 100644 --- a/src/common/SloppyCRCMap.cc +++ b/src/common/SloppyCRCMap.cc @@ -5,6 +5,7 @@ #include "common/Formatter.h" using namespace std; +using ceph::bufferlist; void SloppyCRCMap::write(uint64_t offset, uint64_t len, const bufferlist& bl, std::ostream *out) diff --git a/src/common/SloppyCRCMap.h b/src/common/SloppyCRCMap.h index 0c2d646fa8c57..6bbfe978a4c0f 100644 --- a/src/common/SloppyCRCMap.h +++ b/src/common/SloppyCRCMap.h @@ -33,7 +33,7 @@ public: block_size = b; //zero_crc = ceph_crc32c(0xffffffff, NULL, block_size); if (b) { - bufferlist bl; + ceph::buffer::list bl; bl.append_zero(block_size); zero_crc = bl.crc32c(crc_iv); } else { @@ -42,7 +42,7 @@ public: } /// update based on a write - void write(uint64_t offset, uint64_t len, const bufferlist& bl, + void write(uint64_t offset, uint64_t len, const ceph::buffer::list& bl, std::ostream *out = NULL); /// update based on a truncate @@ -64,10 +64,10 @@ public: * @param err option ostream to describe errors in detail * @returns error count, 0 for success */ - int read(uint64_t offset, uint64_t len, const bufferlist& bl, std::ostream *err); + int read(uint64_t offset, uint64_t len, const ceph::buffer::list& bl, std::ostream *err); - void encode(bufferlist& bl) const; - void decode(bufferlist::const_iterator& bl); + void encode(ceph::buffer::list& bl) const; + void decode(ceph::buffer::list::const_iterator& bl); void dump(ceph::Formatter *f) const; static void generate_test_instances(std::list& ls); }; diff --git a/src/common/Throttle.cc b/src/common/Throttle.cc index 69d0f1086b010..e483e154c9eaa 100644 --- a/src/common/Throttle.cc +++ b/src/common/Throttle.cc @@ -16,8 +16,13 @@ #undef dout_prefix #define dout_prefix *_dout << "throttle(" << name << " " << (void*)this << ") " +using std::list; +using std::ostream; +using std::string; + using ceph::mono_clock; using ceph::mono_time; +using ceph::timespan; enum { l_throttle_first = 532430, diff --git a/src/common/Timer.cc b/src/common/Timer.cc index dceee9b0c0b19..39ad453191582 100644 --- a/src/common/Timer.cc +++ b/src/common/Timer.cc @@ -20,7 +20,9 @@ #undef dout_prefix #define dout_prefix *_dout << "timer(" << this << ")." +using std::pair; +using ceph::operator <<; class SafeTimerThread : public Thread { SafeTimer *parent; diff --git a/src/common/TrackedOp.cc b/src/common/TrackedOp.cc index 494cfcdf686e5..f1b35e7e57aa5 100644 --- a/src/common/TrackedOp.cc +++ b/src/common/TrackedOp.cc @@ -17,6 +17,16 @@ #undef dout_prefix #define dout_prefix _prefix(_dout) +using std::list; +using std::make_pair; +using std::ostream; +using std::pair; +using std::set; +using std::string; +using std::stringstream; + +using ceph::Formatter; + static ostream& _prefix(std::ostream* _dout) { return *_dout << "-- op tracker -- "; diff --git a/src/common/WorkQueue.cc b/src/common/WorkQueue.cc index 93b2aadd8a887..c1b8c18e09729 100644 --- a/src/common/WorkQueue.cc +++ b/src/common/WorkQueue.cc @@ -20,8 +20,7 @@ #undef dout_prefix #define dout_prefix *_dout << name << " " - -ThreadPool::ThreadPool(CephContext *cct_, string nm, string tn, int n, const char *option) +ThreadPool::ThreadPool(CephContext *cct_, std::string nm, std::string tn, int n, const char *option) : cct(cct_), name(std::move(nm)), thread_name(std::move(tn)), lockname(name + "::lock"), _lock(ceph::make_mutex(lockname)), // this should be safe due to declaration order @@ -83,10 +82,10 @@ void ThreadPool::worker(WorkThread *wt) { std::unique_lock ul(_lock); ldout(cct,10) << "worker start" << dendl; - + std::stringstream ss; ss << name << " thread " << (void *)pthread_self(); - heartbeat_handle_d *hb = cct->get_heartbeat_map()->add_worker(ss.str(), pthread_self()); + auto hb = cct->get_heartbeat_map()->add_worker(ss.str(), pthread_self()); while (!_stop) { @@ -197,9 +196,7 @@ void ThreadPool::stop(bool clear_after) _cond.notify_all(); join_old_threads(); _lock.unlock(); - for (set::iterator p = _threads.begin(); - p != _threads.end(); - ++p) { + for (auto p = _threads.begin(); p != _threads.end(); ++p) { (*p)->join(); delete *p; } @@ -252,8 +249,8 @@ void ThreadPool::drain(WorkQueue_* wq) _draining--; } -ShardedThreadPool::ShardedThreadPool(CephContext *pcct_, string nm, string tn, - uint32_t pnum_threads): +ShardedThreadPool::ShardedThreadPool(CephContext *pcct_, std::string nm, std::string tn, + uint32_t pnum_threads): cct(pcct_), name(std::move(nm)), thread_name(std::move(tn)), @@ -271,7 +268,7 @@ void ShardedThreadPool::shardedthreadpool_worker(uint32_t thread_index) std::stringstream ss; ss << name << " thread " << (void *)pthread_self(); - heartbeat_handle_d *hb = cct->get_heartbeat_map()->add_worker(ss.str(), pthread_self()); + auto hb = cct->get_heartbeat_map()->add_worker(ss.str(), pthread_self()); while (!stop_threads) { if (pause_threads) { @@ -348,7 +345,7 @@ void ShardedThreadPool::stop() stop_threads = true; ceph_assert(wq != NULL); wq->return_waiting_threads(); - for (vector::iterator p = threads_shardedpool.begin(); + for (auto p = threads_shardedpool.begin(); p != threads_shardedpool.end(); ++p) { (*p)->join(); diff --git a/src/common/address_helper.cc b/src/common/address_helper.cc index cdb8591f17a76..29f99a8cd5e62 100644 --- a/src/common/address_helper.cc +++ b/src/common/address_helper.cc @@ -19,8 +19,8 @@ int entity_addr_from_url(entity_addr_t *addr /* out */, const char *url) std::cmatch m; if (std::regex_match(url, m, expr)) { - string host(m[2].first, m[2].second); - string port(m[3].first, m[3].second); + std::string host(m[2].first, m[2].second); + std::string port(m[3].first, m[3].second); addrinfo hints; // FIPS zeroization audit 20191115: this memset is fine. memset(&hints, 0, sizeof(hints)); @@ -36,4 +36,3 @@ int entity_addr_from_url(entity_addr_t *addr /* out */, const char *url) return 1; } - diff --git a/src/common/admin_socket.cc b/src/common/admin_socket.cc index 1f57ca0832f1f..f7c042e5d14f2 100644 --- a/src/common/admin_socket.cc +++ b/src/common/admin_socket.cc @@ -41,10 +41,19 @@ #undef dout_prefix #define dout_prefix *_dout << "asok(" << (void*)m_cct << ") " +using namespace std::literals; using std::ostringstream; +using std::string; +using std::stringstream; + using namespace TOPNSPC::common; +using ceph::bufferlist; +using ceph::cref_t; +using ceph::Formatter; + + /* * UNIX domain sockets created by an application persist even after that * application closes, unless they're explicitly unlinked. This is because the @@ -490,7 +499,7 @@ void AdminSocket::execute_command( empty); } - Formatter *f = Formatter::create(format, "json-pretty", "json-pretty"); + auto f = Formatter::create(format, "json-pretty", "json-pretty"); std::unique_lock l(lock); decltype(hooks)::iterator p; @@ -651,7 +660,7 @@ public: // do what you'd expect. GCC 7 does not. (void)command; ostringstream secname; - secname << "cmd" << setfill('0') << std::setw(3) << cmdnum; + secname << "cmd" << std::setfill('0') << std::setw(3) << cmdnum; dump_cmd_and_help_to_json(f, CEPH_FEATURES_ALL, secname.str().c_str(), diff --git a/src/common/admin_socket.h b/src/common/admin_socket.h index 2105097bbeeb6..429b69e00394c 100644 --- a/src/common/admin_socket.h +++ b/src/common/admin_socket.h @@ -30,13 +30,10 @@ #include "common/ref.h" #include "common/cmdparse.h" -class AdminSocket; class MCommand; class MMonCommand; -using namespace std::literals; - -inline constexpr auto CEPH_ADMIN_SOCK_VERSION = "2"sv; +inline constexpr auto CEPH_ADMIN_SOCK_VERSION = std::string_view("2"); class AdminSocketHook { public: @@ -63,7 +60,7 @@ public: virtual int call( std::string_view command, const cmdmap_t& cmdmap, - Formatter *f, + ceph::Formatter *f, std::ostream& errss, ceph::buffer::list& out) = 0; @@ -93,11 +90,11 @@ public: virtual void call_async( std::string_view command, const cmdmap_t& cmdmap, - Formatter *f, - const bufferlist& inbl, - std::function on_finish) { + ceph::Formatter *f, + const ceph::buffer::list& inbl, + std::function on_finish) { // by default, call the synchronous handler and then finish - bufferlist out; + ceph::buffer::list out; std::ostringstream errss; int r = call(command, cmdmap, f, errss, out); on_finish(r, errss.str(), out); @@ -152,18 +149,18 @@ public: /// execute (async) void execute_command( const std::vector& cmd, - const bufferlist& inbl, - std::function on_fin); + const ceph::buffer::list& inbl, + std::function on_fin); /// execute (blocking) int execute_command( const std::vector& cmd, - const bufferlist& inbl, + const ceph::buffer::list& inbl, std::ostream& errss, - bufferlist *outbl); + ceph::buffer::list *outbl); - void queue_tell_command(cref_t m); - void queue_tell_command(cref_t m); // for compat + void queue_tell_command(ceph::cref_t m); + void queue_tell_command(ceph::cref_t m); // for compat private: @@ -194,8 +191,8 @@ private: std::unique_ptr getdescs_hook; std::mutex tell_lock; - std::list> tell_queue; - std::list> tell_legacy_queue; + std::list> tell_queue; + std::list> tell_legacy_queue; struct hook_info { AdminSocketHook* hook; diff --git a/src/common/assert.cc b/src/common/assert.cc index 6fb50014f4399..a663c16e907d1 100644 --- a/src/common/assert.cc +++ b/src/common/assert.cc @@ -15,6 +15,8 @@ #include "include/compat.h" #include "common/debug.h" +using std::ostringstream; + namespace ceph { static CephContext *g_assert_context = NULL; @@ -156,7 +158,7 @@ namespace ceph { } [[gnu::cold]] void __ceph_abort(const char *file, int line, - const char *func, const string& msg) + const char *func, const std::string& msg) { ostringstream tss; tss << ceph_clock_now(); diff --git a/src/common/blkdev.cc b/src/common/blkdev.cc index 0260a69e470d2..8c76a90b6bb8d 100644 --- a/src/common/blkdev.cc +++ b/src/common/blkdev.cc @@ -38,6 +38,7 @@ #include "json_spirit/json_spirit_reader.h" + int get_device_by_path(const char *path, char* partition, char* device, size_t max) { @@ -77,6 +78,12 @@ int get_device_by_path(const char *path, char* partition, char* device, #endif +using namespace std::literals; + +using std::string; + +using ceph::bufferlist; + BlkDev::BlkDev(int f) : fd(f) diff --git a/src/common/bloom_filter.cc b/src/common/bloom_filter.cc index 789e8ba685d38..9033f04544464 100644 --- a/src/common/bloom_filter.cc +++ b/src/common/bloom_filter.cc @@ -5,6 +5,10 @@ MEMPOOL_DEFINE_FACTORY(unsigned char, byte, bloom_filter); +using ceph::bufferlist; +using ceph::bufferptr; +using ceph::Formatter; + void bloom_filter::encode(bufferlist& bl) const { ENCODE_START(2, 2, bl); diff --git a/src/common/buffer.cc b/src/common/buffer.cc index 3204db6e63628..4e276743b57d4 100644 --- a/src/common/buffer.cc +++ b/src/common/buffer.cc @@ -36,6 +36,11 @@ #include "include/spinlock.h" #include "include/scope_guard.h" +using std::cerr; +using std::make_pair; +using std::pair; +using std::string; + using namespace ceph; #define CEPH_BUFFER_ALLOC_UNIT 4096u diff --git a/src/common/ceph_argparse.cc b/src/common/ceph_argparse.cc index 631bc7c547043..85705982c164c 100644 --- a/src/common/ceph_argparse.cc +++ b/src/common/ceph_argparse.cc @@ -55,9 +55,9 @@ struct strict_str_convert { void string_to_vec(std::vector& args, std::string argstr) { - istringstream iss(argstr); + std::istringstream iss(argstr); while(iss) { - string sub; + std::string sub; iss >> sub; if (sub == "") break; args.push_back(sub); @@ -79,7 +79,7 @@ split_dashdash(const std::vector& args) { } static std::mutex g_str_vec_lock; -static vector g_str_vec; +static std::vector g_str_vec; void clear_g_str_vec() { @@ -138,7 +138,7 @@ void vec_to_argv(const char *argv0, std::vector& args, { *argv = (const char**)malloc(sizeof(char*) * (args.size() + 1)); if (!*argv) - throw bad_alloc(); + throw std::bad_alloc(); *argc = 1; (*argv)[0] = argv0; @@ -191,10 +191,10 @@ void ceph_arg_value_type(const char * nextargstr, bool *bool_option, bool *bool_ } -bool parse_ip_port_vec(const char *s, vector& vec, int type) +bool parse_ip_port_vec(const char *s, std::vector& vec, int type) { // first split by [ ;], which are not valid for an addrvec - list items; + std::list items; get_str_list(s, " ;", items); for (auto& i : items) { @@ -480,7 +480,7 @@ bool ceph_argparse_witharg(std::vector &args, int r; va_list ap; va_start(ap, ret); - r = va_ceph_argparse_witharg(args, i, ret, cerr, ap); + r = va_ceph_argparse_witharg(args, i, ret, std::cerr, ap); va_end(ap); if (r < 0) _exit(1); @@ -494,7 +494,7 @@ CephInitParameters ceph_argparse_early_args CephInitParameters iparams(module_type); std::string val; - vector orig_args = args; + auto orig_args = args; for (std::vector::iterator i = args.begin(); i != args.end(); ) { if (strcmp(*i, "--") == 0) { @@ -504,7 +504,7 @@ CephInitParameters ceph_argparse_early_args break; } else if (ceph_argparse_flag(args, i, "--version", "-v", (char*)NULL)) { - cout << pretty_version_to_str() << std::endl; + std::cout << pretty_version_to_str() << std::endl; _exit(0); } else if (ceph_argparse_witharg(args, i, &val, "--conf", "-c", (char*)NULL)) { @@ -525,20 +525,20 @@ CephInitParameters ceph_argparse_early_args } else if (ceph_argparse_witharg(args, i, &val, "--name", "-n", (char*)NULL)) { if (!iparams.name.from_str(val)) { - cerr << "error parsing '" << val << "': expected string of the form TYPE.ID, " - << "valid types are: " << EntityName::get_valid_types_as_str() - << std::endl; + std::cerr << "error parsing '" << val << "': expected string of the form TYPE.ID, " + << "valid types are: " << EntityName::get_valid_types_as_str() + << std::endl; _exit(1); } } else if (ceph_argparse_flag(args, i, "--show_args", (char*)NULL)) { - cout << "args: "; + std::cout << "args: "; for (std::vector::iterator ci = orig_args.begin(); ci != orig_args.end(); ++ci) { - if (ci != orig_args.begin()) - cout << " "; - cout << *ci; + if (ci != orig_args.begin()) + std::cout << " "; + std::cout << *ci; } - cout << std::endl; + std::cout << std::endl; } else { // ignore @@ -550,7 +550,7 @@ CephInitParameters ceph_argparse_early_args static void generic_usage(bool is_server) { - cout << + std::cout << " --conf/-c FILE read configuration from the given configuration file" << std::endl << (is_server ? " --id/-i ID set ID portion of my name" : @@ -563,14 +563,14 @@ static void generic_usage(bool is_server) << std::endl; if (is_server) { - cout << + std::cout << " -d run in foreground, log to stderr" << std::endl << " -f run in foreground, log to usual location" << std::endl << std::endl << " --debug_ms N set message debug level (e.g. 1)" << std::endl; } - cout.flush(); + std::cout.flush(); } bool ceph_argparse_need_usage(const std::vector& args) diff --git a/src/common/ceph_context.cc b/src/common/ceph_context.cc index e7116e38875cd..d4248d9e9b1d9 100644 --- a/src/common/ceph_context.cc +++ b/src/common/ceph_context.cc @@ -46,15 +46,18 @@ #include "common/valgrind.h" #include "include/spinlock.h" -using ceph::bufferlist; -using ceph::HeartbeatMap; - // for CINIT_FLAGS #include "common/common_init.h" #include #include +using namespace std::literals; + +using ceph::bufferlist; +using ceph::HeartbeatMap; + + #if defined(WITH_SEASTAR) && !defined(WITH_ALIEN) namespace crimson::common { CephContext::CephContext() @@ -171,7 +174,7 @@ public: // AdminSocketHook int call(std::string_view command, const cmdmap_t& cmdmap, - Formatter *f, + ceph::Formatter *f, std::ostream& errss, bufferlist& out) override { if (command == "dump_mempools") { @@ -316,7 +319,7 @@ public: } if (changed.count("log_stderr_prefix")) { - log->set_log_stderr_prefix(conf.get_val("log_stderr_prefix")); + log->set_log_stderr_prefix(conf.get_val("log_stderr_prefix")); } if (changed.count("log_max_new")) { @@ -426,7 +429,7 @@ public: bool CephContext::check_experimental_feature_enabled(const std::string& feat) { - stringstream message; + std::stringstream message; bool enabled = check_experimental_feature_enabled(feat, &message); lderr(this) << message.str() << dendl; return enabled; @@ -562,13 +565,13 @@ int CephContext::_do_command( r = -EINVAL; } else { // val may be multiple words - string valstr = str_join(val, " "); + auto valstr = str_join(val, " "); r = _conf.set_val(var.c_str(), valstr.c_str()); if (r < 0) { ss << "error setting '" << var << "' to '" << valstr << "': " << cpp_strerror(r); } else { - stringstream ss; + std::stringstream ss; _conf.apply_changes(&ss); f->dump_string("success", ss.str()); } @@ -620,12 +623,10 @@ int CephContext::_do_command( f->close_section(); // unknown } else if (command == "injectargs") { - vector argsvec; + std::vector argsvec; cmd_getval(cmdmap, "injected_args", argsvec); if (!argsvec.empty()) { - string args = joinify(argsvec.begin(), - argsvec.end(), - " "); + auto args = joinify(argsvec.begin(), argsvec.end(), " "); r = _conf.injectargs(args, &ss); } } @@ -890,13 +891,13 @@ void CephContext::_enable_perf_counter() _mempool_perf_names.reserve(mempool::num_pools * 2); _mempool_perf_descriptions.reserve(mempool::num_pools * 2); for (unsigned i = 0; i < mempool::num_pools; ++i) { - string n = mempool::get_pool_name(mempool::pool_index_t(i)); - _mempool_perf_names.push_back(n + "_bytes"); + std::string n = mempool::get_pool_name(mempool::pool_index_t(i)); + _mempool_perf_names.push_back(n + "_bytes"s); _mempool_perf_descriptions.push_back( - string("mempool ") + n + " total bytes"); - _mempool_perf_names.push_back(n + "_items"); + "mempool "s + n + " total bytes"); + _mempool_perf_names.push_back(n + "_items"s); _mempool_perf_descriptions.push_back( - string("mempool ") + n + " total items"); + "mempool "s + n + " total items"s); } PerfCountersBuilder plb2(this, "mempool", l_mempool_first, diff --git a/src/common/ceph_json.cc b/src/common/ceph_json.cc index 8b79a969fa966..50906a42e6d9d 100644 --- a/src/common/ceph_json.cc +++ b/src/common/ceph_json.cc @@ -13,11 +13,18 @@ using namespace json_spirit; -#define dout_subsys ceph_subsys_rgw +using std::ifstream; +using std::pair; +using std::ostream; +using std::string; +using std::vector; +using ceph::bufferlist; +using ceph::Formatter; -static JSONFormattable default_formattable; +#define dout_subsys ceph_subsys_rgw +static JSONFormattable default_formattable; void encode_json(const char *name, const JSONObj::data_val& v, Formatter *f) { @@ -61,8 +68,7 @@ ostream& operator<<(ostream &out, const JSONObj &obj) { JSONObj::~JSONObj() { - multimap::iterator iter; - for (iter = children.begin(); iter != children.end(); ++iter) { + for (auto iter = children.begin(); iter != children.end(); ++iter) { JSONObj *obj = iter->second; delete obj; } @@ -86,11 +92,9 @@ bool JSONObj::get_attr(string name, data_val& attr) JSONObjIter JSONObj::find(const string& name) { JSONObjIter iter; - map::iterator first; - map::iterator last; - first = children.find(name); + auto first = children.find(name); if (first != children.end()) { - last = children.upper_bound(name); + auto last = children.upper_bound(name); iter.set(first, last); } return iter; @@ -106,8 +110,7 @@ JSONObjIter JSONObj::find_first() JSONObjIter JSONObj::find_first(const string& name) { JSONObjIter iter; - map::iterator first; - first = children.find(name); + auto first = children.find(name); iter.set(first, children.end()); return iter; } @@ -457,7 +460,7 @@ void decode_json_obj(bufferlist& val, JSONObj *obj) bl.append(s.c_str(), s.size()); try { val.decode_base64(bl); - } catch (buffer::error& err) { + } catch (ceph::buffer::error& err) { throw JSONDecoder::err("failed to decode base64"); } } diff --git a/src/common/ceph_time.cc b/src/common/ceph_time.cc index bb708bb467564..1d3b0e1d6b744 100644 --- a/src/common/ceph_time.cc +++ b/src/common/ceph_time.cc @@ -52,6 +52,8 @@ int clock_gettime(int clk_id, struct timespec *tp) } #endif +using namespace std::literals; + namespace ceph { namespace time_detail { void real_clock::to_ceph_timespec(const time_point& t, @@ -155,7 +157,7 @@ namespace ceph { // FIXME: somebody pretty please make a version of this function // that isn't as lame as this one! uint64_t nsec = std::chrono::nanoseconds(t).count(); - ostringstream ss; + std::ostringstream ss; if (nsec < 2000000000) { ss << ((float)nsec / 1000000000) << "s"; return ss.str(); @@ -201,7 +203,7 @@ namespace ceph { uint64_t sec = nsec / 1000000000; nsec %= 1000000000; uint64_t yr = sec / (60 * 60 * 24 * 365); - ostringstream ss; + std::ostringstream ss; if (yr) { ss << yr << "y"; sec -= yr * (60 * 60 * 24 * 365); @@ -245,7 +247,7 @@ namespace ceph { std::chrono::seconds parse_timespan(const std::string& s) { - static std::map units = { + static std::map units = { { "s", 1 }, { "sec", 1 }, { "second", 1 }, @@ -291,13 +293,13 @@ namespace ceph { ++pos; } if (val_start == pos) { - throw invalid_argument("expected digit"); + throw std::invalid_argument("expected digit"); } - string n = s.substr(val_start, pos - val_start); - string err; + auto n = s.substr(val_start, pos - val_start); + std::string err; auto val = strict_strtoll(n.c_str(), 10, &err); if (err.size()) { - throw invalid_argument(err); + throw std::invalid_argument(err); } // skip whitespace @@ -311,16 +313,16 @@ namespace ceph { ++pos; } if (unit_start != pos) { - string unit = s.substr(unit_start, pos - unit_start); + auto unit = s.substr(unit_start, pos - unit_start); auto p = units.find(unit); if (p == units.end()) { - throw invalid_argument("unrecogized unit '"s + unit + "'"); + throw std::invalid_argument("unrecogized unit '"s + unit + "'"); } val *= p->second; } else if (pos < s.size()) { - throw invalid_argument("unexpected trailing '"s + s.substr(pos) + "'"); + throw std::invalid_argument("unexpected trailing '"s + s.substr(pos) + "'"); } - r += chrono::seconds(val); + r += std::chrono::seconds(val); } return r; } diff --git a/src/common/cmdparse.cc b/src/common/cmdparse.cc index a19041845e1fe..6dbbb3925dd2b 100644 --- a/src/common/cmdparse.cc +++ b/src/common/cmdparse.cc @@ -19,6 +19,13 @@ #include "common/strtol.h" #include "json_spirit/json_spirit.h" +using std::is_same_v; +using std::ostringstream; +using std::string; +using std::stringstream; +using std::string_view; +using std::vector; + /** * Given a cmddesc like "foo baz name=bar,type=CephString", * return the prefix "foo baz". @@ -293,15 +300,14 @@ cmdmap_from_json(const vector& cmd, cmdmap_t *mapp, stringstream &ss) try { if (!json_spirit::read(fullcmd, v)) - throw runtime_error("unparseable JSON " + fullcmd); + throw std::runtime_error("unparseable JSON " + fullcmd); if (v.type() != json_spirit::obj_type) - throw(runtime_error("not JSON object " + fullcmd)); + throw std::runtime_error("not JSON object " + fullcmd); // allocate new mObject (map) to return // make sure all contents are simple types (not arrays or objects) json_spirit::mObject o = v.get_obj(); - for (map::iterator it = o.begin(); - it != o.end(); ++it) { + for (auto it = o.begin(); it != o.end(); ++it) { // ok, marshal it into our string->cmd_vartype map, or throw an // exception if it's not a simple datatype. This is kind of @@ -312,7 +318,7 @@ cmdmap_from_json(const vector& cmd, cmdmap_t *mapp, stringstream &ss) case json_spirit::obj_type: default: - throw(runtime_error("JSON array/object not allowed " + fullcmd)); + throw std::runtime_error("JSON array/object not allowed " + fullcmd); break; case json_spirit::array_type: @@ -329,7 +335,7 @@ cmdmap_from_json(const vector& cmd, cmdmap_t *mapp, stringstream &ss) vector outv; for (const auto& sv : spvals) { if (sv.type() != json_spirit::str_type) { - throw(runtime_error("Can't handle arrays of multiple types")); + throw std::runtime_error("Can't handle arrays of multiple types"); } outv.push_back(sv.get_str()); } @@ -338,7 +344,7 @@ cmdmap_from_json(const vector& cmd, cmdmap_t *mapp, stringstream &ss) vector outv; for (const auto& sv : spvals) { if (spvals.front().type() != json_spirit::int_type) { - throw(runtime_error("Can't handle arrays of multiple types")); + throw std::runtime_error("Can't handle arrays of multiple types"); } outv.push_back(sv.get_int64()); } @@ -347,14 +353,14 @@ cmdmap_from_json(const vector& cmd, cmdmap_t *mapp, stringstream &ss) vector outv; for (const auto& sv : spvals) { if (spvals.front().type() != json_spirit::real_type) { - throw(runtime_error("Can't handle arrays of multiple types")); + throw std::runtime_error("Can't handle arrays of multiple types"); } outv.push_back(sv.get_real()); } (*mapp)[it->first] = std::move(outv); } else { - throw(runtime_error("Can't handle arrays of types other than " - "int, string, or double")); + throw std::runtime_error("Can't handle arrays of types other than " + "int, string, or double"); } } break; @@ -376,7 +382,7 @@ cmdmap_from_json(const vector& cmd, cmdmap_t *mapp, stringstream &ss) } } return true; - } catch (runtime_error &e) { + } catch (const std::runtime_error &e) { ss << e.what(); return false; } @@ -502,7 +508,7 @@ bool arg_in_range(T value, const arg_desc_t& desc, std::ostream& os) { } auto min_max = get_str_list(string(range->second), "|"); auto min = str_to_num(min_max.front()); - auto max = numeric_limits::max(); + auto max = std::numeric_limits::max(); if (min_max.size() > 1) { max = str_to_num(min_max.back()); } @@ -546,9 +552,9 @@ bool validate_str_arg(std::string_view value, template, - T>> + typename Value = std::conditional_t, + T>> bool validate_arg(CephContext* cct, const cmdmap_t& cmdmap, const arg_desc_t& desc, diff --git a/src/common/common_init.cc b/src/common/common_init.cc index 2ad93a958c488..6e6a7ecf8100e 100644 --- a/src/common/common_init.cc +++ b/src/common/common_init.cc @@ -71,7 +71,7 @@ CephContext *common_preinit(const CephInitParameters &iparams, #endif // #ifndef WITH_SEASTAR void complain_about_parse_error(CephContext *cct, - const string& parse_error) + const std::string& parse_error) { if (parse_error.empty()) return; diff --git a/src/common/config.cc b/src/common/config.cc index eb6b721e12e39..792cf5fa68cb4 100644 --- a/src/common/config.cc +++ b/src/common/config.cc @@ -37,11 +37,22 @@ // set set_mon_vals() #define dout_subsys ceph_subsys_monc +using std::cerr; +using std::cout; using std::map; +using std::less; using std::list; +using std::ostream; using std::ostringstream; using std::pair; using std::string; +using std::string_view; +using std::vector; + +using ceph::bufferlist; +using ceph::decode; +using ceph::encode; +using ceph::Formatter; static const char *CEPH_CONF_FILE_DEFAULT = "$data_dir/config, /etc/ceph/$cluster.conf, $home/.ceph/$cluster.conf, $cluster.conf" #if defined(__FreeBSD__) diff --git a/src/common/dns_resolve.cc b/src/common/dns_resolve.cc index 5b74ea065b495..a44510d6deab3 100644 --- a/src/common/dns_resolve.cc +++ b/src/common/dns_resolve.cc @@ -20,6 +20,8 @@ #define dout_subsys ceph_subsys_ +using std::map; +using std::string; namespace ceph { @@ -52,8 +54,7 @@ int ResolvHWrapper::res_search(const char *hostname, int cls, DNSResolver::~DNSResolver() { #ifdef HAVE_RES_NQUERY - list::iterator iter; - for (iter = states.begin(); iter != states.end(); ++iter) { + for (auto iter = states.begin(); iter != states.end(); ++iter) { struct __res_state *s = *iter; delete s; } diff --git a/src/common/fs_types.cc b/src/common/fs_types.cc index feb9167264fb8..0dd5528eaa2e6 100644 --- a/src/common/fs_types.cc +++ b/src/common/fs_types.cc @@ -1,9 +1,11 @@ +// -*- mode:C++; tab-width:8; c-basic-offset:2; indent-tabs-mode:t -*- +// vim: ts=8 sw=2 smarttab #include "include/fs_types.h" #include "common/Formatter.h" #include "include/ceph_features.h" -void dump(const ceph_file_layout& l, Formatter *f) +void dump(const ceph_file_layout& l, ceph::Formatter *f) { f->dump_unsigned("stripe_unit", l.fl_stripe_unit); f->dump_unsigned("stripe_count", l.fl_stripe_count); @@ -16,7 +18,7 @@ void dump(const ceph_file_layout& l, Formatter *f) f->dump_unsigned("pg_pool", l.fl_pg_pool); } -void dump(const ceph_dir_layout& l, Formatter *f) +void dump(const ceph_dir_layout& l, ceph::Formatter *f) { f->dump_unsigned("dir_hash", l.dl_dir_hash); f->dump_unsigned("unused1", l.dl_unused1); @@ -71,7 +73,7 @@ void file_layout_t::to_legacy(ceph_file_layout *fl) const fl->fl_pg_pool = 0; } -void file_layout_t::encode(bufferlist& bl, uint64_t features) const +void file_layout_t::encode(ceph::buffer::list& bl, uint64_t features) const { using ceph::encode; if ((features & CEPH_FEATURE_FS_FILE_LAYOUT_V2) == 0) { @@ -91,7 +93,7 @@ void file_layout_t::encode(bufferlist& bl, uint64_t features) const ENCODE_FINISH(bl); } -void file_layout_t::decode(bufferlist::const_iterator& p) +void file_layout_t::decode(ceph::buffer::list::const_iterator& p) { using ceph::decode; if (*p == 0) { @@ -109,7 +111,7 @@ void file_layout_t::decode(bufferlist::const_iterator& p) DECODE_FINISH(p); } -void file_layout_t::dump(Formatter *f) const +void file_layout_t::dump(ceph::Formatter *f) const { f->dump_unsigned("stripe_unit", stripe_unit); f->dump_unsigned("stripe_count", stripe_count); @@ -118,7 +120,7 @@ void file_layout_t::dump(Formatter *f) const f->dump_string("pool_ns", pool_ns); } -void file_layout_t::generate_test_instances(list& o) +void file_layout_t::generate_test_instances(std::list& o) { o.push_back(new file_layout_t); o.push_back(new file_layout_t); @@ -129,11 +131,10 @@ void file_layout_t::generate_test_instances(list& o) o.back()->pool_ns = "myns"; } -ostream& operator<<(ostream& out, const file_layout_t &layout) +std::ostream& operator<<(std::ostream& out, const file_layout_t &layout) { - JSONFormatter f; + ceph::JSONFormatter f; layout.dump(&f); f.flush(out); return out; } - diff --git a/src/common/histogram.cc b/src/common/histogram.cc index b8a71b67e1a38..62a7f44926bdc 100644 --- a/src/common/histogram.cc +++ b/src/common/histogram.cc @@ -16,7 +16,7 @@ #include "common/Formatter.h" // -- pow2_hist_t -- -void pow2_hist_t::dump(Formatter *f) const +void pow2_hist_t::dump(ceph::Formatter *f) const { f->open_array_section("histogram"); for (std::vector::const_iterator p = h.begin(); p != h.end(); ++p) @@ -25,14 +25,14 @@ void pow2_hist_t::dump(Formatter *f) const f->dump_int("upper_bound", upper_bound()); } -void pow2_hist_t::encode(bufferlist& bl) const +void pow2_hist_t::encode(ceph::buffer::list& bl) const { ENCODE_START(1, 1, bl); encode(h, bl); ENCODE_FINISH(bl); } -void pow2_hist_t::decode(bufferlist::const_iterator& p) +void pow2_hist_t::decode(ceph::buffer::list::const_iterator& p) { DECODE_START(1, p); decode(h, p); diff --git a/src/common/hobject.cc b/src/common/hobject.cc index e5da4a35d86b0..85d4237dcd58c 100644 --- a/src/common/hobject.cc +++ b/src/common/hobject.cc @@ -4,6 +4,14 @@ #include "hobject.h" #include "common/Formatter.h" +using std::list; +using std::ostream; +using std::set; +using std::string; + +using ceph::bufferlist; +using ceph::Formatter; + static void append_escaped(const string &in, string *out) { for (string::const_iterator i = in.begin(); i != in.end(); ++i) { diff --git a/src/common/ipaddr.cc b/src/common/ipaddr.cc index a899df697856a..d166dc8b41205 100644 --- a/src/common/ipaddr.cc +++ b/src/common/ipaddr.cc @@ -1,3 +1,5 @@ +// -*- mode:C++; tab-width:8; c-basic-offset:2; indent-tabs-mode:t -*- +// vim: ts=8 sw=2 smarttab #include #include @@ -14,6 +16,8 @@ #include "msg/msg_types.h" #include "common/pick_address.h" +using std::string; + void netmask_ipv4(const struct in_addr *addr, unsigned int prefix_len, struct in_addr *out) { diff --git a/src/common/lockdep.cc b/src/common/lockdep.cc index cd87adce325b0..c62332c0cfc20 100644 --- a/src/common/lockdep.cc +++ b/src/common/lockdep.cc @@ -29,16 +29,18 @@ struct lockdep_stopper_t { g_lockdep = 0; } }; + + static pthread_mutex_t lockdep_mutex = PTHREAD_MUTEX_INITIALIZER; static CephContext *g_lockdep_ceph_ctx = NULL; static lockdep_stopper_t lockdep_stopper; static ceph::unordered_map lock_ids; -static map lock_names; -static map lock_refs; +static std::map lock_names; +static std::map lock_refs; static char free_ids[MAX_LOCKS/8]; // bit set = free -static ceph::unordered_map > held; +static ceph::unordered_map > held; static char follows[MAX_LOCKS][MAX_LOCKS/8]; // follows[a][b] means b taken after a -static BackTrace *follows_bt[MAX_LOCKS][MAX_LOCKS]; +static ceph::BackTrace *follows_bt[MAX_LOCKS][MAX_LOCKS]; unsigned current_maxid; int last_freed_id = -1; static bool free_ids_inited; @@ -93,7 +95,7 @@ void lockdep_unregister_ceph_context(CephContext *cct) lock_ids.clear(); // FIPS zeroization audit 20191115: these memsets are not security related. memset((void*)&follows[0][0], 0, current_maxid * MAX_LOCKS/8); - memset((void*)&follows_bt[0][0], 0, sizeof(BackTrace*) * current_maxid * MAX_LOCKS); + memset((void*)&follows_bt[0][0], 0, sizeof(ceph::BackTrace*) * current_maxid * MAX_LOCKS); } pthread_mutex_unlock(&lockdep_mutex); } @@ -104,11 +106,9 @@ int lockdep_dump_locks() if (!g_lockdep) goto out; - for (ceph::unordered_map >::iterator p = held.begin(); - p != held.end(); - ++p) { + for (auto p = held.begin(); p != held.end(); ++p) { lockdep_dout(0) << "--- thread " << p->first << " ---" << dendl; - for (map::iterator q = p->second.begin(); + for (auto q = p->second.begin(); q != p->second.end(); ++q) { lockdep_dout(0) << " * " << lock_names[q->first] << "\n"; @@ -205,7 +205,7 @@ void lockdep_unregister(int id) pthread_mutex_lock(&lockdep_mutex); std::string name; - map::iterator p = lock_names.find(id); + auto p = lock_names.find(id); if (p == lock_names.end()) name = "unknown" ; else @@ -289,15 +289,13 @@ int lockdep_will_lock(const char *name, int id, bool force_backtrace, lockdep_dout(20) << "_will_lock " << name << " (" << id << ")" << dendl; // check dependency graph - map &m = held[p]; - for (map::iterator p = m.begin(); - p != m.end(); - ++p) { + auto& m = held[p]; + for (auto p = m.begin(); p != m.end(); ++p) { if (p->first == id) { if (!recursive) { lockdep_dout(0) << "\n"; *_dout << "recursive lock of " << name << " (" << id << ")\n"; - BackTrace *bt = new BackTrace(BACKTRACE_SKIP); + auto bt = new ceph::BackTrace(BACKTRACE_SKIP); bt->print(*_dout); if (p->second) { *_dout << "\npreviously locked at\n"; @@ -313,7 +311,7 @@ int lockdep_will_lock(const char *name, int id, bool force_backtrace, // did we just create a cycle? if (does_follow(id, p->first)) { - BackTrace *bt = new BackTrace(BACKTRACE_SKIP); + auto bt = new ceph::BackTrace(BACKTRACE_SKIP); lockdep_dout(0) << "new dependency " << lock_names[p->first] << " (" << p->first << ") -> " << name << " (" << id << ")" << " creates a cycle at\n"; @@ -321,9 +319,7 @@ int lockdep_will_lock(const char *name, int id, bool force_backtrace, *_dout << dendl; lockdep_dout(0) << "btw, i am holding these locks:" << dendl; - for (map::iterator q = m.begin(); - q != m.end(); - ++q) { + for (auto q = m.begin(); q != m.end(); ++q) { lockdep_dout(0) << " " << lock_names[q->first] << " (" << q->first << ")" << dendl; if (q->second) { lockdep_dout(0) << " "; @@ -339,9 +335,9 @@ int lockdep_will_lock(const char *name, int id, bool force_backtrace, ceph_abort(); // actually, we should just die here. } else { - BackTrace *bt = NULL; + ceph::BackTrace* bt = NULL; if (force_backtrace || lockdep_force_backtrace()) { - bt = new BackTrace(BACKTRACE_SKIP); + bt = new ceph::BackTrace(BACKTRACE_SKIP); } follows[p->first][id/8] |= 1 << (id % 8); follows_bt[p->first][id] = bt; @@ -366,7 +362,7 @@ int lockdep_locked(const char *name, int id, bool force_backtrace) lockdep_dout(20) << "_locked " << name << dendl; if (force_backtrace || lockdep_force_backtrace()) - held[p][id] = new BackTrace(BACKTRACE_SKIP); + held[p][id] = new ceph::BackTrace(BACKTRACE_SKIP); else held[p][id] = 0; out: diff --git a/src/common/numa.cc b/src/common/numa.cc index dc80d0f33bde8..89368bd4005f3 100644 --- a/src/common/numa.cc +++ b/src/common/numa.cc @@ -10,6 +10,10 @@ #include "include/stringify.h" #include "common/safe_io.h" +using namespace std::literals; + +using std::set; + // list #if defined(__linux__) diff --git a/src/common/options.cc b/src/common/options.cc index 449e5ea585c45..581f9da0e284b 100644 --- a/src/common/options.cc +++ b/src/common/options.cc @@ -18,6 +18,12 @@ // rbd feature validation #include "librbd/Features.h" +using std::ostream; +using std::ostringstream; + +using ceph::Formatter; +using ceph::parse_timespan; + namespace { class printer : public boost::static_visitor<> { ostream& out; @@ -198,7 +204,7 @@ int Option::parse_value( } else if (type == Option::TYPE_SECS) { try { *out = parse_timespan(val); - } catch (const invalid_argument& e) { + } catch (const std::invalid_argument& e) { *error_message = e.what(); return -EINVAL; } diff --git a/src/common/perf_counters.cc b/src/common/perf_counters.cc index 80c96413eb16b..420ff928c06ca 100644 --- a/src/common/perf_counters.cc +++ b/src/common/perf_counters.cc @@ -19,6 +19,8 @@ #include "include/common_fwd.h" using std::ostringstream; +using std::make_pair; +using std::pair; namespace TOPNSPC::common { PerfCountersCollectionImpl::PerfCountersCollectionImpl() @@ -544,13 +546,13 @@ void PerfCountersBuilder::add_u64_counter_histogram( { add_impl(idx, name, description, nick, prio, PERFCOUNTER_U64 | PERFCOUNTER_HISTOGRAM | PERFCOUNTER_COUNTER, unit, - unique_ptr>{new PerfHistogram<>{x_axis_config, y_axis_config}}); + std::unique_ptr>{new PerfHistogram<>{x_axis_config, y_axis_config}}); } void PerfCountersBuilder::add_impl( int idx, const char *name, const char *description, const char *nick, int prio, int ty, int unit, - unique_ptr> histogram) + std::unique_ptr> histogram) { ceph_assert(idx > m_perf_counters->m_lower_bound); ceph_assert(idx < m_perf_counters->m_upper_bound); diff --git a/src/common/pick_address.cc b/src/common/pick_address.cc index ec464c1b8e165..a2b72371eec2a 100644 --- a/src/common/pick_address.cc +++ b/src/common/pick_address.cc @@ -34,6 +34,9 @@ #define dout_subsys ceph_subsys_ +using std::string; +using std::vector; + const struct sockaddr *find_ip_in_subnet_list( CephContext *cct, const struct ifaddrs *ifa, @@ -465,7 +468,7 @@ std::string pick_iface(CephContext *cct, const struct sockaddr_storage &network) return {}; } - const unsigned int prefix_len = max(sizeof(in_addr::s_addr), sizeof(in6_addr::s6_addr)) * CHAR_BIT; + const unsigned int prefix_len = std::max(sizeof(in_addr::s_addr), sizeof(in6_addr::s6_addr)) * CHAR_BIT; const struct ifaddrs *found = find_ip_in_subnet( ifa, (const struct sockaddr *) &network, prefix_len); @@ -481,7 +484,7 @@ std::string pick_iface(CephContext *cct, const struct sockaddr_storage &network) } -bool have_local_addr(CephContext *cct, const list& ls, entity_addr_t *match) +bool have_local_addr(CephContext *cct, const std::list& ls, entity_addr_t *match) { struct ifaddrs *ifa; int r = getifaddrs(&ifa); @@ -518,7 +521,7 @@ int get_iface_numa_node( PHY_PORT, BOND_PORT } ifatype = iface_t::PHY_PORT; - string_view ifa{iface}; + std::string_view ifa{iface}; if (auto pos = ifa.find(":"); pos != ifa.npos) { ifa.remove_suffix(ifa.size() - pos); } diff --git a/src/common/rabin.cc b/src/common/rabin.cc index 794627a09aa76..658ab37243877 100644 --- a/src/common/rabin.cc +++ b/src/common/rabin.cc @@ -1,9 +1,10 @@ // -*- mode:C++; tab-width:8; c-basic-offset:2; indent-tabs-mode:t -*- // vim: ts=8 sw=2 smarttab +#include + #include "include/types.h" #include "rabin.h" -#include uint64_t RabinChunk::gen_rabin_hash(char* chunk_data, uint64_t off, uint64_t len) { @@ -35,8 +36,8 @@ bool RabinChunk::end_of_chunk(const uint64_t fp , int numbits) { * output_chunks split by Rabin */ -int RabinChunk::do_rabin_chunks(bufferlist & inputdata, - vector> & chunks, +int RabinChunk::do_rabin_chunks(ceph::buffer::list& inputdata, + std::vector>& chunks, uint64_t min_val = 0, uint64_t max_val = 0) { char *ptr = inputdata.c_str(); @@ -56,7 +57,7 @@ int RabinChunk::do_rabin_chunks(bufferlist & inputdata, } if (data_size < min) { - chunks.push_back(make_pair(0, data_size)); + chunks.push_back(std::make_pair(0, data_size)); return 0; } @@ -113,7 +114,7 @@ int RabinChunk::do_rabin_chunks(bufferlist & inputdata, } if (store_chunk) { - chunks.push_back(make_pair(c_start, c_size)); + chunks.push_back(std::make_pair(c_start, c_size)); c_start += c_size; c_offset = c_start; start_new_chunk = true; @@ -127,7 +128,7 @@ int RabinChunk::do_rabin_chunks(bufferlist & inputdata, if (c_start < data_size) { c_size = data_size - c_start; - chunks.push_back(make_pair(c_start, c_size)); + chunks.push_back(std::make_pair(c_start, c_size)); } return 0; diff --git a/src/common/rabin.h b/src/common/rabin.h index 30148fea8444d..6ffaa2bcf92b6 100644 --- a/src/common/rabin.h +++ b/src/common/rabin.h @@ -15,19 +15,27 @@ #ifndef CEPH_COMMON_RABIN_H_ #define CEPH_COMMON_RABIN_H_ +#include +#include +#include + +#include "include/buffer_fwd.h" + class RabinChunk { public: - RabinChunk(uint32_t window_size, uint32_t rabin_prime, - uint64_t mod_prime, uint64_t pow, vector rabin_mask, uint64_t min, - uint64_t max, uint32_t num_bits): - window_size(window_size), rabin_prime(rabin_prime), mod_prime(mod_prime), - pow(pow), rabin_mask(rabin_mask), min(min), max(max), num_bits(num_bits) {} + RabinChunk(uint32_t window_size, uint32_t rabin_prime, + uint64_t mod_prime, uint64_t pow, std::vector rabin_mask, + uint64_t min, uint64_t max, uint32_t num_bits): + window_size(window_size), rabin_prime(rabin_prime), + mod_prime(mod_prime), pow(pow), rabin_mask(rabin_mask), min(min), + max(max), num_bits(num_bits) {} RabinChunk() { default_init_rabin_options(); } void default_init_rabin_options() { - vector _rabin_mask = {0,1,3,7,15,31,63,127,255,511,1023,2047,4095,8191,16383,32767,65535}; + std::vector _rabin_mask = {0,1,3,7,15,31,63,127,255,511,1023,2047, + 4095,8191,16383,32767,65535}; window_size = 48; rabin_prime = 3; mod_prime = 6148914691236517051; @@ -38,8 +46,8 @@ public: rabin_mask = _rabin_mask; } - int do_rabin_chunks(bufferlist & inputdata, - vector> & chunks, + int do_rabin_chunks(ceph::buffer::list& inputdata, + std::vector>& chunks, uint64_t min, uint64_t max); uint64_t gen_rabin_hash(char* chunk_data, uint64_t off, uint64_t len = 0); bool end_of_chunk(const uint64_t fp , int numbits); @@ -47,10 +55,10 @@ public: void set_rabin_prime(uint32_t r_prime) { rabin_prime = r_prime; } void set_mod_prime(uint64_t m_prime) { mod_prime = m_prime; } void set_pow(uint64_t p) { pow = p; } - void set_rabin_mask(vector & mask) { rabin_mask = mask; } + void set_rabin_mask(std::vector & mask) { rabin_mask = mask; } void set_min_chunk(uint32_t c_min) { min = c_min; } void set_max_chunk(uint32_t c_max) { max = c_max; } - int add_rabin_mask(uint64_t mask) { + int add_rabin_mask(uint64_t mask) { rabin_mask.push_back(mask); for (int i = 0; rabin_mask.size(); i++) { if (rabin_mask[i] == mask) { @@ -66,8 +74,8 @@ private: uint32_t window_size; uint32_t rabin_prime; uint64_t mod_prime; - uint64_t pow; - vector rabin_mask; + uint64_t pow; + std::vector rabin_mask; uint64_t min; uint64_t max; uint32_t num_bits; diff --git a/src/common/scrub_types.cc b/src/common/scrub_types.cc index d0385138bbdba..4b2cfa613d66f 100644 --- a/src/common/scrub_types.cc +++ b/src/common/scrub_types.cc @@ -1,5 +1,7 @@ #include "scrub_types.h" +using std::map; + using namespace librados; void object_id_wrapper::encode(bufferlist& bl) const diff --git a/src/common/signal.cc b/src/common/signal.cc index 31e33d4677130..edb6aa17aa6db 100644 --- a/src/common/signal.cc +++ b/src/common/signal.cc @@ -12,18 +12,23 @@ * */ +#include +#include + +#include +#include + +#include + #include "common/BackTrace.h" -#include "common/perf_counters.h" -#include "global/pidfile.h" +#include "common/config.h" #include "common/debug.h" #include "common/signal.h" -#include "common/config.h" +#include "common/perf_counters.h" -#include -#include -#include -#include -#include +#include "global/pidfile.h" + +using namespace std::literals; std::string signal_mask_to_str() { @@ -32,9 +37,9 @@ std::string signal_mask_to_str() return "(pthread_signmask failed)"; } - ostringstream oss; + std::ostringstream oss; oss << "show_signal_mask: { "; - string sep(""); + auto sep = ""s; for (int signum = 0; signum < NSIG; ++signum) { if (sigismember(&old_sigset, signum) == 1) { oss << sep << signum; diff --git a/src/common/snap_types.cc b/src/common/snap_types.cc index 3e33583db16fd..521404ca2b5b0 100644 --- a/src/common/snap_types.cc +++ b/src/common/snap_types.cc @@ -1,26 +1,28 @@ +// -*- mode:C++; tab-width:8; c-basic-offset:2; indent-tabs-mode:t -*- +// vim: ts=8 sw=2 smarttab #include "snap_types.h" #include "common/Formatter.h" -void SnapRealmInfo::encode(bufferlist& bl) const +void SnapRealmInfo::encode(ceph::buffer::list& bl) const { h.num_snaps = my_snaps.size(); h.num_prior_parent_snaps = prior_parent_snaps.size(); using ceph::encode; encode(h, bl); - encode_nohead(my_snaps, bl); - encode_nohead(prior_parent_snaps, bl); + ceph::encode_nohead(my_snaps, bl); + ceph::encode_nohead(prior_parent_snaps, bl); } -void SnapRealmInfo::decode(bufferlist::const_iterator& bl) +void SnapRealmInfo::decode(ceph::buffer::list::const_iterator& bl) { using ceph::decode; decode(h, bl); - decode_nohead(h.num_snaps, my_snaps, bl); - decode_nohead(h.num_prior_parent_snaps, prior_parent_snaps, bl); + ceph::decode_nohead(h.num_snaps, my_snaps, bl); + ceph::decode_nohead(h.num_prior_parent_snaps, prior_parent_snaps, bl); } -void SnapRealmInfo::dump(Formatter *f) const +void SnapRealmInfo::dump(ceph::Formatter *f) const { f->dump_unsigned("ino", ino()); f->dump_unsigned("parent", parent()); @@ -29,17 +31,17 @@ void SnapRealmInfo::dump(Formatter *f) const f->dump_unsigned("created", created()); f->open_array_section("snaps"); - for (vector::const_iterator p = my_snaps.begin(); p != my_snaps.end(); ++p) + for (auto p = my_snaps.begin(); p != my_snaps.end(); ++p) f->dump_unsigned("snap", *p); f->close_section(); f->open_array_section("prior_parent_snaps"); - for (vector::const_iterator p = prior_parent_snaps.begin(); p != prior_parent_snaps.end(); ++p) + for (auto p = prior_parent_snaps.begin(); p != prior_parent_snaps.end(); ++p) f->dump_unsigned("snap", *p); - f->close_section(); + f->close_section(); } -void SnapRealmInfo::generate_test_instances(list& o) +void SnapRealmInfo::generate_test_instances(std::list& o) { o.push_back(new SnapRealmInfo); o.push_back(new SnapRealmInfo(1, 10, 10, 0)); @@ -74,19 +76,19 @@ bool SnapContext::is_valid() const return true; } -void SnapContext::dump(Formatter *f) const +void SnapContext::dump(ceph::Formatter *f) const { f->dump_unsigned("seq", seq); f->open_array_section("snaps"); - for (vector::const_iterator p = snaps.begin(); p != snaps.end(); ++p) + for (auto p = snaps.cbegin(); p != snaps.cend(); ++p) f->dump_unsigned("snap", *p); f->close_section(); } -void SnapContext::generate_test_instances(list& o) +void SnapContext::generate_test_instances(std::list& o) { o.push_back(new SnapContext); - vector v; + std::vector v; o.push_back(new SnapContext(10, v)); v.push_back(18); v.push_back(3); diff --git a/src/common/types.cc b/src/common/types.cc index 3686132924216..7f11cd798fb34 100644 --- a/src/common/types.cc +++ b/src/common/types.cc @@ -24,7 +24,7 @@ const shard_id_t shard_id_t::NO_SHARD(-1); -ostream &operator<<(ostream &lhs, const shard_id_t &rhs) +std::ostream& operator<<(std::ostream& lhs, const shard_id_t& rhs) { return lhs << (unsigned)(uint8_t)rhs.id; } diff --git a/src/common/util.cc b/src/common/util.cc index f816ff41db0bd..b4846328ce132 100644 --- a/src/common/util.cc +++ b/src/common/util.cc @@ -39,6 +39,13 @@ #include +using std::list; +using std::map; +using std::string; + +using ceph::bufferlist; +using ceph::Formatter; + int get_fs_stats(ceph_data_stats_t &stats, const char *path) { if (!path) @@ -72,7 +79,7 @@ static char* value_sanitize(char *value) } static bool value_set(char *buf, const char *prefix, - map *pm, const char *key) + map *pm, const char *key) { if (strncmp(buf, prefix, strlen(prefix))) { return false; @@ -287,12 +294,12 @@ void dump_services(Formatter* f, const map >& services, const ceph_assert(f); f->open_object_section(type); - for (map >::const_iterator host = services.begin(); + for (auto host = services.begin(); host != services.end(); ++host) { f->open_array_section(host->first.c_str()); const list& hosted = host->second; - for (list::const_iterator s = hosted.begin(); - s != hosted.end(); ++s) { + for (auto s = hosted.cbegin(); + s != hosted.cend(); ++s) { f->dump_int(type, *s); } f->close_section();