From 9b25018fb8230197370dcba73de3bb2e03ba9ed0 Mon Sep 17 00:00:00 2001 From: Sage Weil Date: Wed, 14 Sep 2016 13:34:17 -0400 Subject: [PATCH] include/interval_set: define denc_traits for interval_set Signed-off-by: Sage Weil --- src/include/interval_set.h | 73 ++++++++++++++++++++++++-------------- src/osd/osd_types.cc | 4 +-- src/osd/osd_types.h | 1 - 3 files changed, 49 insertions(+), 29 deletions(-) diff --git a/src/include/interval_set.h b/src/include/interval_set.h index c903dc33311..4108f1dd082 100644 --- a/src/include/interval_set.h +++ b/src/include/interval_set.h @@ -238,27 +238,31 @@ class interval_set { return _size; } - void encode(bufferlist& bl) const { - ::encode(m, bl); + void bound_encode(size_t& p) const { + denc_traits>::bound_encode(m, p); } - void encode_nohead(bufferlist& bl) const { - ::encode_nohead(m, bl); + void encode(bufferlist::contiguous_appender& p) const { + denc_traits>::encode(m, p); } - void decode(bufferlist::iterator& bl) { - ::decode(m, bl); + void decode(bufferptr::iterator& p) { + denc_traits>::decode(m, p); _size = 0; - for (typename std::map::const_iterator p = m.begin(); - p != m.end(); - p++) - _size += p->second; + for (typename std::map::const_iterator i = m.begin(); + i != m.end(); + i++) + _size += i->second; + } + + void encode_nohead(bufferlist::contiguous_appender& p) const { + denc_traits>::encode_nohead(m, p); } - void decode_nohead(int n, bufferlist::iterator& bl) { - ::decode_nohead(n, m, bl); + void decode_nohead(int n, bufferptr::iterator& p) { + denc_traits>::decode_nohead(n, m, p); _size = 0; - for (typename std::map::const_iterator p = m.begin(); - p != m.end(); - p++) - _size += p->second; + for (typename std::map::const_iterator i = m.begin(); + i != m.end(); + i++) + _size += i->second; } void clear() { @@ -545,6 +549,33 @@ private: std::map m; // map start -> len }; +// declare traits explicitly because (1) it's templatized, and (2) we +// want to include _nohead variants. +template +struct denc_traits> { + enum { supported = true }; + enum { bounded = false }; + enum { featured = false }; + static void bound_encode(const interval_set& v, size_t& p) { + v.bound_encode(p); + } + static void encode(const interval_set& v, + bufferlist::contiguous_appender& p) { + v.encode(p); + } + static void decode(interval_set& v, bufferptr::iterator& p) { + v.decode(p); + } + static void encode_nohead(const interval_set& v, + bufferlist::contiguous_appender& p) { + v.encode_nohead(p); + } + static void decode_nohead(size_t n, interval_set& v, + bufferptr::iterator& p) { + v.decode_nohead(n, p); + } +}; + template inline std::ostream& operator<<(std::ostream& out, const interval_set &s) { @@ -561,15 +592,5 @@ inline std::ostream& operator<<(std::ostream& out, const interval_set &s) { return out; } -template -inline void encode(const interval_set& s, bufferlist& bl) -{ - s.encode(bl); -} -template -inline void decode(interval_set& s, bufferlist::iterator& p) -{ - s.decode(p); -} #endif diff --git a/src/osd/osd_types.cc b/src/osd/osd_types.cc index 8e0e73e4879..b29e17766e3 100644 --- a/src/osd/osd_types.cc +++ b/src/osd/osd_types.cc @@ -1418,7 +1418,7 @@ void pg_pool_t::encode(bufferlist& bl, uint64_t features) const ::encode(auid, bl); ::encode_nohead(snaps, bl, features); - removed_snaps.encode_nohead(bl); + ::encode_nohead(removed_snaps, bl); return; } @@ -1574,7 +1574,7 @@ void pg_pool_t::decode(bufferlist::iterator& bl) ::decode(m, bl); ::decode(auid, bl); ::decode_nohead(n, snaps, bl); - removed_snaps.decode_nohead(m, bl); + ::decode_nohead(m, removed_snaps, bl); } if (struct_v >= 4) { diff --git a/src/osd/osd_types.h b/src/osd/osd_types.h index 23c4cd18e3d..2593d4b465b 100644 --- a/src/osd/osd_types.h +++ b/src/osd/osd_types.h @@ -3481,7 +3481,6 @@ inline ostream& operator<<(ostream& out, const OSDSuperblock& sb) // ------- -WRITE_CLASS_ENCODER(interval_set) -- 2.39.5