From 32a9f4048c5af977ed76d8e01db3783c39be1508 Mon Sep 17 00:00:00 2001 From: "Adam C. Emerson" Date: Fri, 22 Dec 2017 23:34:07 -0500 Subject: [PATCH] include: Use unqualified encode/decode This is a portion of the namespace project. Signed-off-by: Adam C. Emerson --- src/include/CompatSet.h | 44 ++++++++++++++++++++++----------------- src/include/compact_map.h | 18 ++++++++++------ src/include/compact_set.h | 10 +++++---- src/include/filepath.h | 14 +++++++------ src/include/frag.h | 19 +++++++++++------ src/include/fs_types.h | 8 ++++--- src/include/health.h | 10 +++++---- src/include/object.h | 20 +++++++++++------- src/include/types.h | 18 ++++++++++------ src/include/util.h | 16 +++++++------- src/include/utime.h | 10 +++++---- 11 files changed, 114 insertions(+), 73 deletions(-) diff --git a/src/include/CompatSet.h b/src/include/CompatSet.h index 0a7b009f37c..b623447b915 100644 --- a/src/include/CompatSet.h +++ b/src/include/CompatSet.h @@ -14,29 +14,36 @@ #ifndef CEPH_COMPATSET_H #define CEPH_COMPATSET_H + +#include +#include +#include + #include "include/buffer.h" +#include "include/encoding.h" +#include "include/types.h" #include "common/Formatter.h" struct CompatSet { struct Feature { uint64_t id; - string name; + std::string name; - Feature(uint64_t _id, const string& _name) : id(_id), name(_name) {} + Feature(uint64_t _id, const std::string& _name) : id(_id), name(_name) {} }; class FeatureSet { uint64_t mask; - map names; + std::map names; public: friend struct CompatSet; friend class CephCompatSet_AllSet_Test; friend class CephCompatSet_other_Test; friend class CephCompatSet_merge_Test; - friend ostream& operator<<(ostream& out, const CompatSet::FeatureSet& fs); - friend ostream& operator<<(ostream& out, const CompatSet& compat); + friend std::ostream& operator<<(std::ostream& out, const CompatSet::FeatureSet& fs); + friend std::ostream& operator<<(std::ostream& out, const CompatSet& compat); FeatureSet() : mask(1), names() {} void insert(const Feature& f) { assert(f.id > 0); @@ -71,15 +78,17 @@ struct CompatSet { } void encode(bufferlist& bl) const { + using ceph::encode; /* See below, mask always has the lowest bit set in memory, but * unset in the encoding */ - ::encode(mask & (~(uint64_t)1), bl); - ::encode(names, bl); + encode(mask & (~(uint64_t)1), bl); + encode(names, bl); } void decode(bufferlist::iterator& bl) { - ::decode(mask, bl); - ::decode(names, bl); + using ceph::decode; + decode(mask, bl); + decode(names, bl); /** * Previously, there was a bug where insert did * mask |= f.id rather than mask |= (1 << f.id). @@ -92,11 +101,9 @@ struct CompatSet { */ if (mask & 1) { mask = 1; - map temp_names; + std::map temp_names; temp_names.swap(names); - for (map::iterator i = temp_names.begin(); - i != temp_names.end(); - ++i) { + for (auto i = temp_names.begin(); i != temp_names.end(); ++i) { insert(Feature(i->first, i->second)); } } else { @@ -105,9 +112,7 @@ struct CompatSet { } void dump(Formatter *f) const { - for (map::const_iterator p = names.begin(); - p != names.end(); - ++p) { + for (auto p = names.cbegin(); p != names.cend(); ++p) { char s[18]; snprintf(s, sizeof(s), "feature_%llu", (unsigned long long)p->first); f->dump_string(s, p->second); @@ -241,7 +246,7 @@ struct CompatSet { f->close_section(); } - static void generate_test_instances(list& o) { + static void generate_test_instances(std::list& o) { o.push_back(new CompatSet); o.push_back(new CompatSet); o.back()->compat.insert(Feature(1, "one")); @@ -252,12 +257,13 @@ struct CompatSet { }; WRITE_CLASS_ENCODER(CompatSet) -inline ostream& operator<<(ostream& out, const CompatSet::FeatureSet& fs) +using ceph::operator <<; +inline std::ostream& operator<<(std::ostream& out, const CompatSet::FeatureSet& fs) { return out << fs.names; } -inline ostream& operator<<(ostream& out, const CompatSet& compat) +inline std::ostream& operator<<(std::ostream& out, const CompatSet& compat) { return out << "compat=" << compat.compat << ",rocompat=" << compat.ro_compat diff --git a/src/include/compact_map.h b/src/include/compact_map.h index 975baa064d3..1fa286e8984 100644 --- a/src/include/compact_map.h +++ b/src/include/compact_map.h @@ -14,6 +14,8 @@ #include +#include "include/encoding.h" + template class compact_map_base { protected: @@ -285,23 +287,27 @@ public: return const_iterator(this, map->upper_bound(k)); } void encode(bufferlist &bl) const { + using ceph::encode; if (map) - ::encode(*map, bl); + encode(*map, bl); else - ::encode((uint32_t)0, bl); + encode((uint32_t)0, bl); } void encode(bufferlist &bl, uint64_t features) const { + using ceph::encode; if (map) - ::encode(*map, bl, features); + encode(*map, bl, features); else - ::encode((uint32_t)0, bl); + encode((uint32_t)0, bl); } void decode(bufferlist::iterator& p) { + using ceph::decode; + using ceph::decode_nohead; uint32_t n; - ::decode(n, p); + decode(n, p); if (n > 0) { alloc_internal(); - ::decode_nohead(n, *map, p); + decode_nohead(n, *map, p); } else free_internal(); } diff --git a/src/include/compact_set.h b/src/include/compact_set.h index 63707abc4c7..dcbeec12a3e 100644 --- a/src/include/compact_set.h +++ b/src/include/compact_set.h @@ -251,17 +251,19 @@ public: return const_iterator(this, set->upper_bound(t)); } void encode(bufferlist &bl) const { + using ceph::encode; if (set) - ::encode(*set, bl); + encode(*set, bl); else - ::encode((uint32_t)0, bl); + encode((uint32_t)0, bl); } void decode(bufferlist::iterator& p) { + using ceph::decode; uint32_t n; - ::decode(n, p); + decode(n, p); if (n > 0) { alloc_internal(); - ::decode_nohead(n, *set, p); + decode_nohead(n, *set, p); } else free_internal(); } diff --git a/src/include/filepath.h b/src/include/filepath.h index 1e28cffd0a1..ae3430f6f80 100644 --- a/src/include/filepath.h +++ b/src/include/filepath.h @@ -186,17 +186,19 @@ class filepath { // encoding void encode(bufferlist& bl) const { + using ceph::encode; __u8 struct_v = 1; - ::encode(struct_v, bl); - ::encode(ino, bl); - ::encode(path, bl); + encode(struct_v, bl); + encode(ino, bl); + encode(path, bl); } void decode(bufferlist::iterator& blp) { + using ceph::decode; bits.clear(); __u8 struct_v; - ::decode(struct_v, blp); - ::decode(ino, blp); - ::decode(path, blp); + decode(struct_v, blp); + decode(ino, blp); + decode(path, blp); encoded = true; } void dump(Formatter *f) const { diff --git a/src/include/frag.h b/src/include/frag.h index 3b1456cbbe7..0b7977acf1d 100644 --- a/src/include/frag.h +++ b/src/include/frag.h @@ -24,8 +24,11 @@ #include "compact_map.h" #include "ceph_frag.h" +#include "include/encoding.h" #include "include/assert.h" +#include "common/dout.h" + /* * * the goal here is to use a binary split strategy to partition a namespace. @@ -454,25 +457,29 @@ public: // encoding void encode(bufferlist& bl) const { - ::encode(_splits, bl); + using ceph::encode; + encode(_splits, bl); } void decode(bufferlist::iterator& p) { - ::decode(_splits, p); + using ceph::decode; + decode(_splits, p); } void encode_nohead(bufferlist& bl) const { + using ceph::encode; for (compact_map::const_iterator p = _splits.begin(); p != _splits.end(); ++p) { - ::encode(p->first, bl); - ::encode(p->second, bl); + encode(p->first, bl); + encode(p->second, bl); } } void decode_nohead(int n, bufferlist::iterator& p) { + using ceph::decode; _splits.clear(); while (n-- > 0) { frag_t f; - ::decode(f, p); - ::decode(_splits[f], p); + decode(f, p); + decode(_splits[f], p); } } diff --git a/src/include/fs_types.h b/src/include/fs_types.h index 36dede85a4d..0a958e3179f 100644 --- a/src/include/fs_types.h +++ b/src/include/fs_types.h @@ -19,10 +19,12 @@ struct inodeno_t { operator _inodeno_t() const { return val; } void encode(bufferlist& bl) const { - ::encode(val, bl); + using ceph::encode; + encode(val, bl); } void decode(bufferlist::iterator& p) { - ::decode(val, p); + using ceph::decode; + decode(val, p); } } __attribute__ ((__may_alias__)); WRITE_CLASS_ENCODER(inodeno_t) @@ -62,7 +64,7 @@ namespace std { // file modes -static inline bool file_mode_is_readonly(int mode) { +inline bool file_mode_is_readonly(int mode) { return (mode & CEPH_FILE_MODE_WR) == 0; } diff --git a/src/include/health.h b/src/include/health.h index b23a4d4e2b3..3cf7442adde 100644 --- a/src/include/health.h +++ b/src/include/health.h @@ -15,13 +15,15 @@ enum health_status_t { HEALTH_OK = 2, }; -static inline void encode(health_status_t hs, bufferlist& bl) { +inline void encode(health_status_t hs, bufferlist& bl) { + using ceph::encode; uint8_t v = hs; - ::encode(v, bl); + encode(v, bl); } -static inline void decode(health_status_t& hs, bufferlist::iterator& p) { +inline void decode(health_status_t& hs, bufferlist::iterator& p) { + using ceph::decode; uint8_t v; - ::decode(v, p); + decode(v, p); hs = health_status_t(v); } template<> diff --git a/src/include/object.h b/src/include/object.h index 50aa3fee240..849b698c4ab 100644 --- a/src/include/object.h +++ b/src/include/object.h @@ -20,8 +20,8 @@ #include #include -using namespace std; +#include "include/rados.h" #include "include/unordered_map.h" #include "hash.h" @@ -29,6 +29,8 @@ using namespace std; #include "ceph_hash.h" #include "cmp.h" +using namespace std; + struct object_t { string name; @@ -46,10 +48,12 @@ struct object_t { } void encode(bufferlist &bl) const { - ::encode(name, bl); + using ceph::encode; + encode(name, bl); } void decode(bufferlist::iterator &bl) { - ::decode(name, bl); + using ceph::decode; + decode(name, bl); } }; WRITE_CLASS_ENCODER(object_t) @@ -164,12 +168,14 @@ struct sobject_t { } void encode(bufferlist& bl) const { - ::encode(oid, bl); - ::encode(snap, bl); + using ceph::encode; + encode(oid, bl); + encode(snap, bl); } void decode(bufferlist::iterator& bl) { - ::decode(oid, bl); - ::decode(snap, bl); + using ceph::decode; + decode(oid, bl); + decode(snap, bl); } }; WRITE_CLASS_ENCODER(sobject_t) diff --git a/src/include/types.h b/src/include/types.h index 902aa149064..a5d533530e0 100644 --- a/src/include/types.h +++ b/src/include/types.h @@ -314,10 +314,12 @@ struct client_t { client_t(int64_t _v = -2) : v(_v) {} void encode(bufferlist& bl) const { - ::encode(v, bl); + using ceph::encode; + encode(v, bl); } void decode(bufferlist::iterator& bl) { - ::decode(v, bl); + using ceph::decode; + decode(v, bl); } }; WRITE_CLASS_ENCODER(client_t) @@ -487,10 +489,12 @@ struct shard_id_t { const static shard_id_t NO_SHARD; void encode(bufferlist &bl) const { - ::encode(id, bl); + using ceph::encode; + encode(id, bl); } void decode(bufferlist::iterator &bl) { - ::decode(id, bl); + using ceph::decode; + decode(id, bl); } }; WRITE_CLASS_ENCODER(shard_id_t) @@ -522,11 +526,13 @@ struct errorcode32_t { int operator<=(int i) { return code <= i; } void encode(bufferlist &bl) const { + using ceph::encode; __s32 newcode = hostos_to_ceph_errno(code); - ::encode(newcode, bl); + encode(newcode, bl); } void decode(bufferlist::iterator &bl) { - ::decode(code, bl); + using ceph::decode; + decode(code, bl); code = ceph_to_hostos_errno(code); } }; diff --git a/src/include/util.h b/src/include/util.h index 3de4c3d3ec1..4b27cc1f3e3 100644 --- a/src/include/util.h +++ b/src/include/util.h @@ -45,19 +45,19 @@ struct ceph_data_stats void encode(bufferlist &bl) const { ENCODE_START(1, 1, bl); - ::encode(byte_total, bl); - ::encode(byte_used, bl); - ::encode(byte_avail, bl); - ::encode(avail_percent, bl); + encode(byte_total, bl); + encode(byte_used, bl); + encode(byte_avail, bl); + encode(avail_percent, bl); ENCODE_FINISH(bl); } void decode(bufferlist::iterator &p) { DECODE_START(1, p); - ::decode(byte_total, p); - ::decode(byte_used, p); - ::decode(byte_avail, p); - ::decode(avail_percent, p); + decode(byte_total, p); + decode(byte_used, p); + decode(byte_avail, p); + decode(avail_percent, p); DECODE_FINISH(p); } diff --git a/src/include/utime.h b/src/include/utime.h index 3f053d4d6f0..69a6429c663 100644 --- a/src/include/utime.h +++ b/src/include/utime.h @@ -124,16 +124,18 @@ public: #if defined(CEPH_LITTLE_ENDIAN) bl.append((char *)(this), sizeof(__u32) + sizeof(__u32)); #else - ::encode(tv.tv_sec, bl); - ::encode(tv.tv_nsec, bl); + using ceph::encode; + encode(tv.tv_sec, bl); + encode(tv.tv_nsec, bl); #endif } void decode(bufferlist::iterator &p) { #if defined(CEPH_LITTLE_ENDIAN) p.copy(sizeof(__u32) + sizeof(__u32), (char *)(this)); #else - ::decode(tv.tv_sec, p); - ::decode(tv.tv_nsec, p); + using ceph::decode; + decode(tv.tv_sec, p); + decode(tv.tv_nsec, p); #endif } -- 2.39.5