From: Adam C. Emerson Date: Sat, 7 Mar 2020 09:27:16 +0000 (-0500) Subject: osdc: Build target 'common' without using namespace in headers X-Git-Tag: v16.0.0~18^2~10 X-Git-Url: http://git-server-git.apps.pok.os.sepia.ceph.com/?a=commitdiff_plain;h=215facf57822df5716c90229f7e0ca4ab4693e1f;p=ceph.git osdc: 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/osdc/Filer.cc b/src/osdc/Filer.cc index 93abbb7cdb1c..d97e5de0a61a 100644 --- a/src/osdc/Filer.cc +++ b/src/osdc/Filer.cc @@ -34,6 +34,10 @@ #undef dout_prefix #define dout_prefix *_dout << objecter->messenger->get_myname() << ".filer " +using std::hex; +using std::dec; +using std::vector; + class Filer::C_Probe : public Context { public: Filer *filer; @@ -156,9 +160,7 @@ void Filer::_probe(Probe *probe, Probe::unique_lock& pl) probe->probing_len, 0, probe->probing); std::vector stat_extents; - for (vector::iterator p = probe->probing.begin(); - p != probe->probing.end(); - ++p) { + for (auto p = probe->probing.begin(); p != probe->probing.end(); ++p) { ldout(cct, 10) << "_probe probing " << p->oid << dendl; probe->ops.insert(p->oid); stat_extents.push_back(*p); @@ -211,9 +213,7 @@ bool Filer::_probed(Probe *probe, const object_t& oid, uint64_t size, std::reverse(probe->probing.begin(), probe->probing.end()); } - for (vector::iterator p = probe->probing.begin(); - p != probe->probing.end(); - ++p) { + for (auto p = probe->probing.begin(); p != probe->probing.end(); ++p) { uint64_t shouldbe = p->length + p->offset; ldout(cct, 10) << "_probed " << probe->ino << " object " << hex << p->oid << dec << " should be " << shouldbe @@ -231,8 +231,7 @@ bool Filer::_probed(Probe *probe, const object_t& oid, uint64_t size, // aha, we found the end! // calc offset into buffer_extent to get distance from probe->from. uint64_t oleft = probe->known_size[p->oid] - p->offset; - for (vector >::iterator i - = p->buffer_extents.begin(); + for (auto i = p->buffer_extents.begin(); i != p->buffer_extents.end(); ++i) { if (oleft <= (uint64_t)i->second) { diff --git a/src/osdc/ObjectCacher.cc b/src/osdc/ObjectCacher.cc index b5c336b3a9a9..f147bc69bb4a 100644 --- a/src/osdc/ObjectCacher.cc +++ b/src/osdc/ObjectCacher.cc @@ -13,9 +13,20 @@ #define MAX_FLUSH_UNDER_LOCK 20 ///< max bh's we start writeback on #define BUFFER_MEMORY_WEIGHT CEPH_PAGE_SHIFT // memory usage of BufferHead, count in (1<waitfor_read.empty()) { - map >::iterator start_remove - = left->waitfor_read.begin(); + auto start_remove = left->waitfor_read.begin(); while (start_remove != left->waitfor_read.end() && start_remove->first < right->start()) ++start_remove; - for (map >::iterator p = start_remove; - p != left->waitfor_read.end(); ++p) { + for (auto p = start_remove; p != left->waitfor_read.end(); ++p) { ldout(oc->cct, 20) << "split moving waiters at byte " << p->first << " to right bh" << dendl; right->waitfor_read[p->first].swap( p->second ); @@ -181,7 +190,7 @@ void ObjectCacher::Object::merge_left(BufferHead *left, BufferHead *right) left->set_nocache(right->get_nocache() ? left->get_nocache() : false); // waiters - for (map >::iterator p = right->waitfor_read.begin(); + for (auto p = right->waitfor_read.begin(); p != right->waitfor_read.end(); ++p) left->waitfor_read[p->first].splice(left->waitfor_read[p->first].begin(), @@ -214,7 +223,7 @@ void ObjectCacher::Object::try_merge_bh(BufferHead *bh) return; // to the left? - map::iterator p = data.find(bh->start()); + auto p = data.find(bh->start()); ceph_assert(p->second == bh); if (p != data.begin()) { --p; @@ -252,7 +261,7 @@ void ObjectCacher::Object::maybe_rebuild_buffer(BufferHead *bh) bool ObjectCacher::Object::is_cached(loff_t cur, loff_t left) const { ceph_assert(ceph_mutex_is_locked(oc->lock)); - map::const_iterator p = data_lower_bound(cur); + auto p = data_lower_bound(cur); while (left > 0) { if (p == data.end()) return false; @@ -282,8 +291,8 @@ bool ObjectCacher::Object::include_all_cached_data(loff_t off, loff_t len) ceph_assert(ceph_mutex_is_locked(oc->lock)); if (data.empty()) return true; - map::iterator first = data.begin(); - map::reverse_iterator last = data.rbegin(); + auto first = data.begin(); + auto last = data.rbegin(); if (first->second->start() >= off && last->second->end() <= (off + len)) return true; else @@ -307,7 +316,7 @@ int ObjectCacher::Object::map_read(ObjectExtent &ex, loff_t cur = ex.offset; loff_t left = ex.length; - map::const_iterator p = data_lower_bound(ex.offset); + auto p = data_lower_bound(ex.offset); while (left > 0) { // at end? if (p == data.end()) { @@ -384,8 +393,7 @@ int ObjectCacher::Object::map_read(ObjectExtent &ex, void ObjectCacher::Object::audit_buffers() { loff_t offset = 0; - for (map::const_iterator it = data.begin(); - it != data.end(); ++it) { + for (auto it = data.begin(); it != data.end(); ++it) { if (it->first != it->second->start()) { lderr(oc->cct) << "AUDIT FAILURE: map position " << it->first << " does not match bh start position: " @@ -399,8 +407,7 @@ void ObjectCacher::Object::audit_buffers() ceph_assert(it->first >= offset); } BufferHead *bh = it->second; - map >::const_iterator w_it; - for (w_it = bh->waitfor_read.begin(); + for (auto w_it = bh->waitfor_read.begin(); w_it != bh->waitfor_read.end(); ++w_it) { if (w_it->first < bh->start() || w_it->first >= bh->start() + bh->length()) { @@ -433,7 +440,7 @@ ObjectCacher::BufferHead *ObjectCacher::Object::map_write(ObjectExtent &ex, loff_t cur = ex.offset; loff_t left = ex.length; - map::const_iterator p = data_lower_bound(ex.offset); + auto p = data_lower_bound(ex.offset); while (left > 0) { loff_t max = left; @@ -596,7 +603,7 @@ void ObjectCacher::Object::discard(loff_t off, loff_t len, complete = false; } - map::const_iterator p = data_lower_bound(off); + auto p = data_lower_bound(off); while (p != data.end()) { BufferHead *bh = p->second; if (bh->start() >= off + len) @@ -680,10 +687,7 @@ ObjectCacher::~ObjectCacher() finisher.stop(); perf_stop(); // we should be empty. - for (vector >::iterator i - = objects.begin(); - i != objects.end(); - ++i) + for (auto i = objects.begin(); i != objects.end(); ++i) ceph_assert(i->empty()); ceph_assert(bh_lru_rest.lru_get_size() == 0); ceph_assert(bh_lru_dirty.lru_get_size() == 0); @@ -844,11 +848,9 @@ void ObjectCacher::bh_read_finish(int64_t poolid, sobject_t oid, // read 1~1 -> immediate ENOENT // reply to first 1~1 -> ooo ENOENT bool allzero = true; - for (map::iterator p = ob->data.begin(); - p != ob->data.end(); ++p) { + for (auto p = ob->data.begin(); p != ob->data.end(); ++p) { BufferHead *bh = p->second; - for (map >::iterator p - = bh->waitfor_read.begin(); + for (auto p = bh->waitfor_read.begin(); p != bh->waitfor_read.end(); ++p) ls.splice(ls.end(), p->second); @@ -882,7 +884,7 @@ void ObjectCacher::bh_read_finish(int64_t poolid, sobject_t oid, ldout(cct, 10) << "bh_read_finish ENOENT and allzero, getting rid of " << "bhs for " << *ob << dendl; - map::iterator p = ob->data.begin(); + auto p = ob->data.begin(); while (p != ob->data.end()) { BufferHead *bh = p->second; // current iterator will be invalidated by bh_remove() @@ -897,7 +899,7 @@ void ObjectCacher::bh_read_finish(int64_t poolid, sobject_t oid, // apply to bh's! loff_t opos = start; while (true) { - map::const_iterator p = ob->data_lower_bound(opos); + auto p = ob->data_lower_bound(opos); if (p == ob->data.end()) break; if (opos >= start+(loff_t)length) { @@ -911,8 +913,7 @@ void ObjectCacher::bh_read_finish(int64_t poolid, sobject_t oid, ldout(cct, 20) << "checking bh " << *bh << dendl; // finishers? - for (map >::iterator it - = bh->waitfor_read.begin(); + for (auto it = bh->waitfor_read.begin(); it != bh->waitfor_read.end(); ++it) ls.splice(ls.end(), it->second); diff --git a/src/osdc/ObjectCacher.h b/src/osdc/ObjectCacher.h index bc6133651e93..d5a77cd18aa1 100644 --- a/src/osdc/ObjectCacher.h +++ b/src/osdc/ObjectCacher.h @@ -61,34 +61,34 @@ class ObjectCacher { // read scatter/gather struct OSDRead { - vector extents; + std::vector extents; snapid_t snap; - bufferlist *bl; + ceph::buffer::list *bl; int fadvise_flags; - OSDRead(snapid_t s, bufferlist *b, int f) + OSDRead(snapid_t s, ceph::buffer::list *b, int f) : snap(s), bl(b), fadvise_flags(f) {} }; - OSDRead *prepare_read(snapid_t snap, bufferlist *b, int f) const { + OSDRead *prepare_read(snapid_t snap, ceph::buffer::list *b, int f) const { return new OSDRead(snap, b, f); } // write scatter/gather struct OSDWrite { - vector extents; + std::vector extents; SnapContext snapc; - bufferlist bl; + ceph::buffer::list bl; ceph::real_time mtime; int fadvise_flags; ceph_tid_t journal_tid; - OSDWrite(const SnapContext& sc, const bufferlist& b, ceph::real_time mt, + OSDWrite(const SnapContext& sc, const ceph::buffer::list& b, ceph::real_time mt, int f, ceph_tid_t _journal_tid) : snapc(sc), bl(b), mtime(mt), fadvise_flags(f), journal_tid(_journal_tid) {} }; OSDWrite *prepare_write(const SnapContext& sc, - const bufferlist &b, + const ceph::buffer::list &b, ceph::real_time mt, int f, ceph_tid_t journal_tid) const { @@ -121,7 +121,7 @@ class ObjectCacher { public: Object *ob; - bufferlist bl; + ceph::buffer::list bl; ceph_tid_t last_write_tid; // version of bh (if non-zero) ceph_tid_t last_read_tid; // tid of last read op (if any) ceph::real_time last_write; @@ -129,7 +129,7 @@ class ObjectCacher { ceph_tid_t journal_tid; int error; // holds return value for failed reads - map > waitfor_read; + std::map > waitfor_read; // cons explicit BufferHead(Object *o) : @@ -243,14 +243,14 @@ class ObjectCacher { bool complete; bool exists; - map data; + std::map data; ceph_tid_t last_write_tid; // version of bh (if non-zero) ceph_tid_t last_commit_tid; // last update committed. int dirty_or_tx; - map< ceph_tid_t, list > waitfor_commit; + std::map< ceph_tid_t, std::list > waitfor_commit; xlist reads; Object(const Object&) = delete; @@ -280,7 +280,7 @@ class ObjectCacher { object_t get_oid() { return oid.oid; } snapid_t get_snap() { return oid.snap; } ObjectSet *get_object_set() const { return oset; } - string get_namespace() { return oloc.nspace; } + std::string get_namespace() { return oloc.nspace; } uint64_t get_object_number() const { return object_no; } const object_locator_t& get_oloc() const { return oloc; } @@ -309,8 +309,8 @@ class ObjectCacher { * @param offset object byte offset * @return iterator pointing to buffer, or data.end() */ - map::const_iterator data_lower_bound(loff_t offset) const { - map::const_iterator p = data.lower_bound(offset); + std::map::const_iterator data_lower_bound(loff_t offset) const { + auto p = data.lower_bound(offset); if (p != data.begin() && (p == data.end() || p->first > offset)) { --p; // might overlap! @@ -347,10 +347,10 @@ class ObjectCacher { bool is_cached(loff_t off, loff_t len) const; bool include_all_cached_data(loff_t off, loff_t len); int map_read(ObjectExtent &ex, - map& hits, - map& missing, - map& rx, - map& errors); + std::map& hits, + std::map& missing, + std::map& rx, + std::map& errors); BufferHead *map_write(ObjectExtent &ex, ceph_tid_t tid); void replace_journal_tid(BufferHead *bh, ceph_tid_t tid); @@ -398,7 +398,7 @@ class ObjectCacher { WritebackHandler& writeback_handler; bool scattered_write; - string name; + std::string name; ceph::mutex& lock; uint64_t max_dirty, target_dirty, max_size, max_objects; @@ -411,13 +411,13 @@ class ObjectCacher { void *flush_set_callback_arg; // indexed by pool_id - vector > objects; + std::vector > objects; - list waitfor_read; + std::list waitfor_read; ceph_tid_t last_read_tid; - set dirty_or_tx_bh; + std::set dirty_or_tx_bh; LRU bh_lru_dirty, bh_lru_rest; LRU ob_lru; @@ -529,7 +529,7 @@ class ObjectCacher { void bh_read(BufferHead *bh, int op_flags, const ZTracer::Trace &parent_trace); void bh_write(BufferHead *bh, const ZTracer::Trace &parent_trace); - void bh_write_scattered(list& blist); + void bh_write_scattered(std::list& blist); void bh_write_adjacencies(BufferHead *bh, ceph::real_time cutoff, int64_t *amount, int *max_count); @@ -562,10 +562,10 @@ class ObjectCacher { public: void bh_read_finish(int64_t poolid, sobject_t oid, ceph_tid_t tid, loff_t offset, uint64_t length, - bufferlist &bl, int r, + ceph::buffer::list &bl, int r, bool trust_enoent); void bh_write_commit(int64_t poolid, sobject_t oid, - vector >& ranges, + std::vector >& ranges, ceph_tid_t t, int r); class C_WriteCommit; @@ -576,7 +576,7 @@ class ObjectCacher { - ObjectCacher(CephContext *cct_, string name, WritebackHandler& wb, ceph::mutex& l, + ObjectCacher(CephContext *cct_, std::string name, WritebackHandler& wb, ceph::mutex& l, flush_set_callback_t flush_callback, void *flush_callback_arg, uint64_t max_bytes, uint64_t max_objects, @@ -610,7 +610,7 @@ class ObjectCacher { ZTracer::Trace *parent_trace = nullptr); int writex(OSDWrite *wr, ObjectSet *oset, Context *onfreespace, ZTracer::Trace *parent_trace = nullptr); - bool is_cached(ObjectSet *oset, vector& extents, + bool is_cached(ObjectSet *oset, std::vector& extents, snapid_t snapid); private: @@ -620,7 +620,7 @@ private: void _maybe_wait_for_writeback(uint64_t len, ZTracer::Trace *trace); bool _flush_set_finish(C_GatherBuilder *gather, Context *onfinish); - void _discard(ObjectSet *oset, const vector& exls, + void _discard(ObjectSet *oset, const std::vector& exls, C_GatherBuilder* gather); void _discard_finish(ObjectSet *oset, bool was_dirty, Context* on_finish); @@ -630,7 +630,7 @@ public: bool set_is_dirty_or_committing(ObjectSet *oset); bool flush_set(ObjectSet *oset, Context *onfinish=0); - bool flush_set(ObjectSet *oset, vector& ex, + bool flush_set(ObjectSet *oset, std::vector& ex, ZTracer::Trace *trace, Context *onfinish = 0); bool flush_all(Context *onfinish = 0); @@ -640,8 +640,8 @@ public: loff_t release_set(ObjectSet *oset); uint64_t release_all(); - void discard_set(ObjectSet *oset, const vector& ex); - void discard_writeback(ObjectSet *oset, const vector& ex, + void discard_set(ObjectSet *oset, const std::vector& ex); + void discard_writeback(ObjectSet *oset, const std::vector& ex, Context* on_finish); /** @@ -664,7 +664,7 @@ public: max_size = v; } void set_max_dirty_age(double a) { - max_dirty_age = make_timespan(a); + max_dirty_age = ceph::make_timespan(a); } void set_max_objects(int64_t v) { max_objects = v; @@ -676,14 +676,14 @@ public: /*** async+caching (non-blocking) file interface ***/ int file_is_cached(ObjectSet *oset, file_layout_t *layout, snapid_t snapid, loff_t offset, uint64_t len) { - vector extents; + std::vector extents; Striper::file_to_extents(cct, oset->ino, layout, offset, len, oset->truncate_size, extents); return is_cached(oset, extents, snapid); } int file_read(ObjectSet *oset, file_layout_t *layout, snapid_t snapid, - loff_t offset, uint64_t len, bufferlist *bl, int flags, + loff_t offset, uint64_t len, ceph::buffer::list *bl, int flags, Context *onfinish) { OSDRead *rd = prepare_read(snapid, bl, flags); Striper::file_to_extents(cct, oset->ino, layout, offset, len, @@ -693,7 +693,7 @@ public: int file_write(ObjectSet *oset, file_layout_t *layout, const SnapContext& snapc, loff_t offset, uint64_t len, - bufferlist& bl, ceph::real_time mtime, int flags) { + ceph::buffer::list& bl, ceph::real_time mtime, int flags) { OSDWrite *wr = prepare_write(snapc, bl, mtime, flags, 0); Striper::file_to_extents(cct, oset->ino, layout, offset, len, oset->truncate_size, wr->extents); @@ -703,7 +703,7 @@ public: bool file_flush(ObjectSet *oset, file_layout_t *layout, const SnapContext& snapc, loff_t offset, uint64_t len, Context *onfinish) { - vector extents; + std::vector extents; Striper::file_to_extents(cct, oset->ino, layout, offset, len, oset->truncate_size, extents); ZTracer::Trace trace; @@ -712,7 +712,8 @@ public: }; -inline ostream& operator<<(ostream &out, const ObjectCacher::BufferHead &bh) +inline std::ostream& operator<<(std::ostream &out, + const ObjectCacher::BufferHead &bh) { out << "bh[ " << &bh << " " << bh.start() << "~" << bh.length() @@ -732,11 +733,9 @@ inline ostream& operator<<(ostream &out, const ObjectCacher::BufferHead &bh) if (bh.error) out << " error=" << bh.error; out << "]"; out << " waiters = {"; - for (map >::const_iterator it - = bh.waitfor_read.begin(); - it != bh.waitfor_read.end(); ++it) { + for (auto it = bh.waitfor_read.begin(); it != bh.waitfor_read.end(); ++it) { out << " " << it->first << "->["; - for (list::const_iterator lit = it->second.begin(); + for (auto lit = it->second.begin(); lit != it->second.end(); ++lit) { out << *lit << ", "; } @@ -746,7 +745,8 @@ inline ostream& operator<<(ostream &out, const ObjectCacher::BufferHead &bh) return out; } -inline ostream& operator<<(ostream &out, const ObjectCacher::ObjectSet &os) +inline std::ostream& operator<<(std::ostream &out, + const ObjectCacher::ObjectSet &os) { return out << "objectset[" << os.ino << " ts " << os.truncate_seq << "/" << os.truncate_size @@ -755,10 +755,11 @@ inline ostream& operator<<(ostream &out, const ObjectCacher::ObjectSet &os) << "]"; } -inline ostream& operator<<(ostream &out, const ObjectCacher::Object &ob) +inline std::ostream& operator<<(std::ostream &out, + const ObjectCacher::Object &ob) { out << "object[" - << ob.get_soid() << " oset " << ob.oset << dec + << ob.get_soid() << " oset " << ob.oset << std::dec << " wr " << ob.last_write_tid << "/" << ob.last_commit_tid; if (ob.complete) diff --git a/src/osdc/Objecter.cc b/src/osdc/Objecter.cc index 9a63f64f13be..d56a76dbd8d5 100644 --- a/src/osdc/Objecter.cc +++ b/src/osdc/Objecter.cc @@ -4518,7 +4518,7 @@ void Objecter::_dump_ops(const OSDSession *s, Formatter *fmt) p != s->ops.end(); ++p) { Op *op = p->second; - auto age = std::chrono::duration(coarse_mono_clock::now() - op->stamp); + auto age = std::chrono::duration(ceph::coarse_mono_clock::now() - op->stamp); fmt->open_object_section("op"); fmt->dump_unsigned("tid", op->tid); op->target.dump(fmt); diff --git a/src/osdc/Objecter.h b/src/osdc/Objecter.h index 8db785589010..91ebc0a14db2 100644 --- a/src/osdc/Objecter.h +++ b/src/osdc/Objecter.h @@ -1004,7 +1004,8 @@ struct ObjectOperation { } void omap_rm_range(std::string_view key_begin, std::string_view key_end) { - bufferlist bl; + ceph::buffer::list bl; + using ceph::encode; encode(key_begin, bl); encode(key_end, bl); add_data(CEPH_OSD_OP_OMAPRMKEYRANGE, 0, bl.length(), bl); @@ -2108,7 +2109,7 @@ private: return op_budget; } int take_linger_budget(LingerOp *info); - friend class WatchContext; // to invoke put_up_budget_bytes + friend struct WatchContext; // to invoke put_up_budget_bytes void put_op_budget_bytes(int op_budget) { ceph_assert(op_budget >= 0); op_throttle_bytes.put(op_budget); diff --git a/src/osdc/Striper.h b/src/osdc/Striper.h index 85b99f08fd0b..ddfb2c570ed1 100644 --- a/src/osdc/Striper.h +++ b/src/osdc/Striper.h @@ -122,7 +122,7 @@ private: void add_partial_sparse_result( - CephContext *cct, bufferlist& bl, + CephContext *cct, ceph::buffer::list& bl, std::map::const_iterator* it, const std::map::const_iterator& end_it, uint64_t* bl_off, uint64_t tofs, uint64_t tlen); diff --git a/src/osdc/WritebackHandler.h b/src/osdc/WritebackHandler.h index ef3b7f6efd17..4f4e9aef87fd 100644 --- a/src/osdc/WritebackHandler.h +++ b/src/osdc/WritebackHandler.h @@ -15,7 +15,7 @@ class WritebackHandler { virtual void read(const object_t& oid, uint64_t object_no, const object_locator_t& oloc, uint64_t off, uint64_t len, - snapid_t snapid, bufferlist *pbl, uint64_t trunc_size, + snapid_t snapid, ceph::buffer::list *pbl, uint64_t trunc_size, __u32 trunc_seq, int op_flags, const ZTracer::Trace &parent_trace, Context *onfinish) = 0; /** @@ -34,7 +34,7 @@ class WritebackHandler { virtual ceph_tid_t write(const object_t& oid, const object_locator_t& oloc, uint64_t off, uint64_t len, const SnapContext& snapc, - const bufferlist &bl, ceph::real_time mtime, + const ceph::buffer::list &bl, ceph::real_time mtime, uint64_t trunc_size, __u32 trunc_seq, ceph_tid_t journal_tid, const ZTracer::Trace &parent_trace, @@ -46,7 +46,7 @@ class WritebackHandler { virtual bool can_scattered_write() { return false; } virtual ceph_tid_t write(const object_t& oid, const object_locator_t& oloc, - vector >& io_vec, + std::vector >& io_vec, const SnapContext& snapc, ceph::real_time mtime, uint64_t trunc_size, __u32 trunc_seq, Context *oncommit) {