]> git.apps.os.sepia.ceph.com Git - ceph.git/commitdiff
include/interval_set: define denc_traits for interval_set<T>
authorSage Weil <sage@redhat.com>
Wed, 14 Sep 2016 17:34:17 +0000 (13:34 -0400)
committerSage Weil <sage@redhat.com>
Sun, 16 Oct 2016 14:32:50 +0000 (10:32 -0400)
Signed-off-by: Sage Weil <sage@redhat.com>
src/include/interval_set.h
src/osd/osd_types.cc
src/osd/osd_types.h

index c903dc33311ac48b87d42c684afcb8f71a534df7..4108f1dd082a37f53e4bdb8f105dfcf9bd7d3ce2 100644 (file)
@@ -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<std::map<T,T>>::bound_encode(m, p);
   }
-  void encode_nohead(bufferlist& bl) const {
-    ::encode_nohead(m, bl);
+  void encode(bufferlist::contiguous_appender& p) const {
+    denc_traits<std::map<T,T>>::encode(m, p);
   }
-  void decode(bufferlist::iterator& bl) {
-    ::decode(m, bl);
+  void decode(bufferptr::iterator& p) {
+    denc_traits<std::map<T,T>>::decode(m, p);
     _size = 0;
-    for (typename std::map<T,T>::const_iterator p = m.begin();
-         p != m.end();
-         p++)
-      _size += p->second;
+    for (typename std::map<T,T>::const_iterator i = m.begin();
+         i != m.end();
+         i++)
+      _size += i->second;
+  }
+
+  void encode_nohead(bufferlist::contiguous_appender& p) const {
+    denc_traits<std::map<T,T>>::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<std::map<T,T>>::decode_nohead(n, m, p);
     _size = 0;
-    for (typename std::map<T,T>::const_iterator p = m.begin();
-         p != m.end();
-         p++)
-      _size += p->second;
+    for (typename std::map<T,T>::const_iterator i = m.begin();
+         i != m.end();
+         i++)
+      _size += i->second;
   }
 
   void clear() {
@@ -545,6 +549,33 @@ private:
   std::map<T,T> m;   // map start -> len
 };
 
+// declare traits explicitly because (1) it's templatized, and (2) we
+// want to include _nohead variants.
+template<typename T>
+struct denc_traits<interval_set<T>> {
+  enum { supported = true };
+  enum { bounded = false };
+  enum { featured = false };
+  static void bound_encode(const interval_set<T>& v, size_t& p) {
+    v.bound_encode(p);
+  }
+  static void encode(const interval_set<T>& v,
+                    bufferlist::contiguous_appender& p) {
+    v.encode(p);
+  }
+  static void decode(interval_set<T>& v, bufferptr::iterator& p) {
+    v.decode(p);
+  }
+  static void encode_nohead(const interval_set<T>& v,
+                           bufferlist::contiguous_appender& p) {
+    v.encode_nohead(p);
+  }
+  static void decode_nohead(size_t n, interval_set<T>& v,
+                           bufferptr::iterator& p) {
+    v.decode_nohead(n, p);
+  }
+};
+
 
 template<class T>
 inline std::ostream& operator<<(std::ostream& out, const interval_set<T> &s) {
@@ -561,15 +592,5 @@ inline std::ostream& operator<<(std::ostream& out, const interval_set<T> &s) {
   return out;
 }
 
-template<class T>
-inline void encode(const interval_set<T>& s, bufferlist& bl)
-{
-  s.encode(bl);
-}
-template<class T>
-inline void decode(interval_set<T>& s, bufferlist::iterator& p)
-{
-  s.decode(p);
-}
 
 #endif
index 8e0e73e48791c8fa75bc454413ff69df44668247..b29e17766e38c05bd6494ae0fd201501c49eccb6 100644 (file)
@@ -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) {
index 23c4cd18e3dc576f265912693633c3f7c17f1c66..2593d4b465b59c1aae7e15c2698b26e21910e494 100644 (file)
@@ -3481,7 +3481,6 @@ inline ostream& operator<<(ostream& out, const OSDSuperblock& sb)
 
 // -------
 
-WRITE_CLASS_ENCODER(interval_set<uint64_t>)