]> git.apps.os.sepia.ceph.com Git - ceph.git/commitdiff
crushwrapper and a few others
authorSage Weil <sage@newdream.net>
Thu, 8 May 2008 18:25:55 +0000 (11:25 -0700)
committerSage Weil <sage@newdream.net>
Thu, 8 May 2008 18:25:55 +0000 (11:25 -0700)
src/crush/CrushWrapper.h
src/crushtool.cc
src/mds/CDir.cc
src/mds/SessionMap.cc
src/mds/mdstypes.h
src/messages/MClientReconnect.h
src/mon/OSDMonitor.cc
src/osd/OSDMap.h
src/osdmaptool.cc

index 6c9011c07157ff87d08ff3e88e429fb56072bb43..2e6741beef00da605490f31272361aa700649f79 100644 (file)
@@ -10,7 +10,7 @@
 #include "builder.h"
 
 #include "include/err.h"
-#include "include/encodable.h"
+#include "include/encoding.h"
 
 #include <stdlib.h>
 #include <map>
 
 #include <iostream> //for testing, remove
 
+WRITE_RAW_ENCODER(crush_rule_mask)   // it's all u8's
+
+inline static void encode(const crush_rule_step &s, bufferlist &bl)
+{
+  ::encode(s.op, bl);
+  ::encode(s.arg1, bl);
+  ::encode(s.arg2, bl);
+}
+inline static void decode(crush_rule_step &s, bufferlist::iterator &p)
+{
+  ::decode(s.op, p);
+  ::decode(s.arg1, p);
+  ::decode(s.arg2, p);
+}
+
+
+
 using namespace std;
 class CrushWrapper {
 public:
@@ -327,62 +344,63 @@ public:
     int r = bl.read_file(fn);
     if (r < 0) return r;
     bufferlist::iterator blp = bl.begin();
-    _decode(blp);
+    decode(blp);
     return 0;
   }
   int write_to_file(const char *fn) {
     bufferlist bl;
-    _encode(bl);
+    encode(bl);
     return bl.write_file(fn);
   }
 
-  void _encode(bufferlist &bl, bool lean=false) {
+  void encode(bufferlist &bl, bool lean=false) {
     if (!crush) create();  // duh.
-    ::_encode_simple(crush->max_buckets, bl);
-    ::_encode_simple(crush->max_rules, bl);
-    ::_encode_simple(crush->max_devices, bl);
+    ::encode(crush->max_buckets, bl);
+    ::encode(crush->max_rules, bl);
+    ::encode(crush->max_devices, bl);
 
     // simple arrays
-    bl.append((char*)crush->device_offload, sizeof(crush->device_offload[0]) * crush->max_devices);
+    for (int i=0; i < crush->max_devices; i++)
+      ::encode(crush->device_offload[i], bl);
 
     // buckets
     for (unsigned i=0; i<crush->max_buckets; i++) {
       __u32 alg = 0;
       if (crush->buckets[i]) alg = crush->buckets[i]->alg;
-      ::_encode_simple(alg, bl);
+      ::encode(alg, bl);
       if (!alg) continue;
 
-      ::_encode_simple(crush->buckets[i]->id, bl);
-      ::_encode_simple(crush->buckets[i]->type, bl);
-      ::_encode_simple(crush->buckets[i]->alg, bl);
-      ::_encode_simple(crush->buckets[i]->weight, bl);
-      ::_encode_simple(crush->buckets[i]->size, bl);
+      ::encode(crush->buckets[i]->id, bl);
+      ::encode(crush->buckets[i]->type, bl);
+      ::encode(crush->buckets[i]->alg, bl);
+      ::encode(crush->buckets[i]->weight, bl);
+      ::encode(crush->buckets[i]->size, bl);
       for (unsigned j=0; j<crush->buckets[i]->size; j++)
-       ::_encode_simple(crush->buckets[i]->items[j], bl);
+       ::encode(crush->buckets[i]->items[j], bl);
       
       switch (crush->buckets[i]->alg) {
       case CRUSH_BUCKET_UNIFORM:
        for (unsigned j=0; j<crush->buckets[i]->size; j++)
-         ::_encode_simple(((crush_bucket_uniform*)crush->buckets[i])->primes[j], bl);
-       ::_encode_simple(((crush_bucket_uniform*)crush->buckets[i])->item_weight, bl);
+         ::encode(((crush_bucket_uniform*)crush->buckets[i])->primes[j], bl);
+       ::encode(((crush_bucket_uniform*)crush->buckets[i])->item_weight, bl);
        break;
 
       case CRUSH_BUCKET_LIST:
        for (unsigned j=0; j<crush->buckets[i]->size; j++) {
-         ::_encode_simple(((crush_bucket_list*)crush->buckets[i])->item_weights[j], bl);
-         ::_encode_simple(((crush_bucket_list*)crush->buckets[i])->sum_weights[j], bl);
+         ::encode(((crush_bucket_list*)crush->buckets[i])->item_weights[j], bl);
+         ::encode(((crush_bucket_list*)crush->buckets[i])->sum_weights[j], bl);
        }
        break;
 
       case CRUSH_BUCKET_TREE:
        for (unsigned j=0; j<crush->buckets[i]->size; j++) 
-         ::_encode_simple(((crush_bucket_tree*)crush->buckets[i])->node_weights[j], bl);
+         ::encode(((crush_bucket_tree*)crush->buckets[i])->node_weights[j], bl);
        break;
 
       case CRUSH_BUCKET_STRAW:
        for (unsigned j=0; j<crush->buckets[i]->size; j++) {
-         ::_encode_simple(((crush_bucket_straw*)crush->buckets[i])->item_weights[j], bl);
-         ::_encode_simple(((crush_bucket_straw*)crush->buckets[i])->straws[j], bl);
+         ::encode(((crush_bucket_straw*)crush->buckets[i])->item_weights[j], bl);
+         ::encode(((crush_bucket_straw*)crush->buckets[i])->straws[j], bl);
        }
        break;
       }
@@ -391,35 +409,36 @@ public:
     // rules
     for (unsigned i=0; i<crush->max_rules; i++) {
       __u32 yes = crush->rules[i] ? 1:0;
-      ::_encode_simple(yes, bl);
+      ::encode(yes, bl);
       if (!yes) continue;
 
-      ::_encode_simple(crush->rules[i]->len, bl);
-      ::_encode_simple(crush->rules[i]->mask, bl);
+      ::encode(crush->rules[i]->len, bl);
+      ::encode(crush->rules[i]->mask, bl);
       for (unsigned j=0; j<crush->rules[i]->len; j++)
-       ::_encode_simple(crush->rules[i]->steps[j], bl);
+       ::encode(crush->rules[i]->steps[j], bl);
     }
 
     // name info
-    ::_encode_simple(type_map, bl);
-    ::_encode_simple(name_map, bl);
-    ::_encode_simple(rule_name_map, bl);
+    ::encode(type_map, bl);
+    ::encode(name_map, bl);
+    ::encode(rule_name_map, bl);
   }
 
-  void _decode(bufferlist::iterator &blp) {
+  void decode(bufferlist::iterator &blp) {
     create();
-    ::_decode_simple(crush->max_buckets, blp);
-    ::_decode_simple(crush->max_rules, blp);
-    ::_decode_simple(crush->max_devices, blp);
+    ::decode(crush->max_buckets, blp);
+    ::decode(crush->max_rules, blp);
+    ::decode(crush->max_devices, blp);
 
     crush->device_offload = (__u32*)malloc(sizeof(crush->device_offload[0])*crush->max_devices);
-    blp.copy(sizeof(crush->device_offload[0])*crush->max_devices, (char*)crush->device_offload);
+    for (int i=0; i < crush->max_devices; i++)
+      ::decode(crush->device_offload[i], blp);
     
     // buckets
     crush->buckets = (crush_bucket**)malloc(sizeof(crush_bucket*)*crush->max_buckets);
     for (unsigned i=0; i<crush->max_buckets; i++) {
       __u32 alg;
-      ::_decode_simple(alg, blp);
+      ::decode(alg, blp);
       if (!alg) {
        crush->buckets[i] = 0;
        continue;
@@ -445,23 +464,23 @@ public:
       crush->buckets[i] = (crush_bucket*)malloc(size);
       memset(crush->buckets[i], 0, size);
       
-      ::_decode_simple(crush->buckets[i]->id, blp);
-      ::_decode_simple(crush->buckets[i]->type, blp);
-      ::_decode_simple(crush->buckets[i]->alg, blp);
-      ::_decode_simple(crush->buckets[i]->weight, blp);
-      ::_decode_simple(crush->buckets[i]->size, blp);
+      ::decode(crush->buckets[i]->id, blp);
+      ::decode(crush->buckets[i]->type, blp);
+      ::decode(crush->buckets[i]->alg, blp);
+      ::decode(crush->buckets[i]->weight, blp);
+      ::decode(crush->buckets[i]->size, blp);
 
       crush->buckets[i]->items = (__s32*)malloc(sizeof(__s32)*crush->buckets[i]->size);
       for (unsigned j=0; j<crush->buckets[i]->size; j++)
-       ::_decode_simple(crush->buckets[i]->items[j], blp);
+       ::decode(crush->buckets[i]->items[j], blp);
 
       switch (crush->buckets[i]->alg) {
       case CRUSH_BUCKET_UNIFORM:
        ((crush_bucket_uniform*)crush->buckets[i])->primes = 
          (__u32*)malloc(crush->buckets[i]->size * sizeof(__u32));
        for (unsigned j=0; j<crush->buckets[i]->size; j++)
-         ::_decode_simple(((crush_bucket_uniform*)crush->buckets[i])->primes[j], blp);
-       ::_decode_simple(((crush_bucket_uniform*)crush->buckets[i])->item_weight, blp);
+         ::decode(((crush_bucket_uniform*)crush->buckets[i])->primes[j], blp);
+       ::decode(((crush_bucket_uniform*)crush->buckets[i])->item_weight, blp);
        break;
 
       case CRUSH_BUCKET_LIST:
@@ -471,8 +490,8 @@ public:
          (__u32*)malloc(crush->buckets[i]->size * sizeof(__u32));
 
        for (unsigned j=0; j<crush->buckets[i]->size; j++) {
-         ::_decode_simple(((crush_bucket_list*)crush->buckets[i])->item_weights[j], blp);
-         ::_decode_simple(((crush_bucket_list*)crush->buckets[i])->sum_weights[j], blp);
+         ::decode(((crush_bucket_list*)crush->buckets[i])->item_weights[j], blp);
+         ::decode(((crush_bucket_list*)crush->buckets[i])->sum_weights[j], blp);
        }
        break;
 
@@ -480,7 +499,7 @@ public:
        ((crush_bucket_tree*)crush->buckets[i])->node_weights = 
          (__u32*)malloc(crush->buckets[i]->size * sizeof(__u32));
        for (unsigned j=0; j<crush->buckets[i]->size; j++) 
-         ::_decode_simple(((crush_bucket_tree*)crush->buckets[i])->node_weights[j], blp);
+         ::decode(((crush_bucket_tree*)crush->buckets[i])->node_weights[j], blp);
        break;
 
       case CRUSH_BUCKET_STRAW:
@@ -489,8 +508,8 @@ public:
        ((crush_bucket_straw*)crush->buckets[i])->item_weights = 
          (__u32*)malloc(crush->buckets[i]->size * sizeof(__u32));
        for (unsigned j=0; j<crush->buckets[i]->size; j++) {
-         ::_decode_simple(((crush_bucket_straw*)crush->buckets[i])->item_weights[j], blp);
-         ::_decode_simple(((crush_bucket_straw*)crush->buckets[i])->straws[j], blp);
+         ::decode(((crush_bucket_straw*)crush->buckets[i])->item_weights[j], blp);
+         ::decode(((crush_bucket_straw*)crush->buckets[i])->straws[j], blp);
        }
        break;
       }
@@ -500,25 +519,25 @@ public:
     crush->rules = (crush_rule**)malloc(sizeof(crush_rule*)*crush->max_rules);
     for (unsigned i=0; i<crush->max_rules; i++) {
       __u32 yes;
-      ::_decode_simple(yes, blp);
+      ::decode(yes, blp);
       if (!yes) {
        crush->rules[i] = 0;
        continue;
       }
 
       __u32 len;
-      ::_decode_simple(len, blp);
+      ::decode(len, blp);
       crush->rules[i] = (crush_rule*)malloc(crush_rule_size(len));
       crush->rules[i]->len = len;
-      ::_decode_simple(crush->rules[i]->mask, blp);
+      ::decode(crush->rules[i]->mask, blp);
       for (unsigned j=0; j<crush->rules[i]->len; j++)
-       ::_decode_simple(crush->rules[i]->steps[j], blp);
+       ::decode(crush->rules[i]->steps[j], blp);
     }
 
     // name info
-    ::_decode_simple(type_map, blp);
-    ::_decode_simple(name_map, blp);
-    ::_decode_simple(rule_name_map, blp);
+    ::decode(type_map, blp);
+    ::decode(name_map, blp);
+    ::decode(rule_name_map, blp);
     build_rmaps();
 
     finalize();
index 8ecb34116119b5e8707d7125b06da6382c84f15e..e4e116f5389810f65aab9e101daad0b6d8247099 100644 (file)
@@ -673,7 +673,7 @@ int main(int argc, const char **argv)
       exit(1);
     }
     bufferlist::iterator p = bl.begin();
-    crush._decode(p);
+    crush.decode(p);
 
     if (outfn) {
       ofstream o;
@@ -697,7 +697,7 @@ int main(int argc, const char **argv)
 
     if (outfn) {
       bufferlist bl;
-      crush._encode(bl);
+      crush.encode(bl);
       int r = bl.write_file(outfn);
       if (r < 0) {
        cerr << me << ": error writing '" << outfn << "': " << strerror(-r) << std::endl;
index 091777d75ffdad4a14e4cec405b484313fbfa53c..bc2e17c56ca469390ec09a0eb0b14aec6b266434 100644 (file)
@@ -1284,18 +1284,18 @@ void CDir::_committed(version_t v)
 
 void CDir::encode_export(bufferlist& bl)
 {
-  ::_encode_simple(version, bl);
-  ::_encode_simple(committed_version, bl);
-  ::_encode_simple(committed_version_equivalent, bl);
+  ::encode(version, bl);
+  ::encode(committed_version, bl);
+  ::encode(committed_version_equivalent, bl);
 
-  ::_encode_simple(state, bl);
-  ::_encode_simple(dir_rep, bl);
+  ::encode(state, bl);
+  ::encode(dir_rep, bl);
 
-  ::_encode_simple(pop_me, bl);
-  ::_encode_simple(pop_auth_subtree, bl);
+  ::encode(pop_me, bl);
+  ::encode(pop_auth_subtree, bl);
 
-  ::_encode_simple(dir_rep_by, bl);  
-  ::_encode_simple(replica_map, bl);
+  ::encode(dir_rep_by, bl);  
+  ::encode(replica_map, bl);
 
   get(PIN_TEMPEXPORTING);
 }
@@ -1310,26 +1310,26 @@ void CDir::finish_export(utime_t now)
 
 void CDir::decode_import(bufferlist::iterator& blp)
 {
-  ::_decode_simple(version, blp);
-  ::_decode_simple(committed_version, blp);
-  ::_decode_simple(committed_version_equivalent, blp);
+  ::decode(version, blp);
+  ::decode(committed_version, blp);
+  ::decode(committed_version_equivalent, blp);
   committing_version = committed_version;
   projected_version = version;
 
   unsigned s;
-  ::_decode_simple(s, blp);
+  ::decode(s, blp);
   state &= MASK_STATE_IMPORT_KEPT;
   state |= (s & MASK_STATE_EXPORTED);
   if (is_dirty()) get(PIN_DIRTY);
 
-  ::_decode_simple(dir_rep, blp);
+  ::decode(dir_rep, blp);
 
-  ::_decode_simple(pop_me, blp);
-  ::_decode_simple(pop_auth_subtree, blp);
+  ::decode(pop_me, blp);
+  ::decode(pop_auth_subtree, blp);
   pop_auth_subtree_nested += pop_auth_subtree;
 
-  ::_decode_simple(dir_rep_by, blp);
-  ::_decode_simple(replica_map, blp);
+  ::decode(dir_rep_by, blp);
+  ::decode(replica_map, blp);
   if (!replica_map.empty()) get(PIN_REPLICATED);
 
   replica_nonce = 0;  // no longer defined
index 0c3b603ae13d65dd38244eb90546366e400b61cf..8dc510adc12e7f30f19873927d1de9dcb08e08e7 100644 (file)
@@ -132,9 +132,9 @@ void SessionMap::_save_finish(version_t v)
 
 void SessionMap::encode(bufferlist& bl)
 {
-  ::_encode_simple(version, bl);
+  ::encode(version, bl);
   __u32 n = session_map.size();
-  ::_encode_simple(n, bl);
+  ::encode(n, bl);
   for (hash_map<entity_name_t,Session*>::iterator p = session_map.begin(); 
        p != session_map.end(); 
        ++p) 
@@ -145,9 +145,9 @@ void SessionMap::decode(bufferlist::iterator& p)
 {
   utime_t now = g_clock.now();
 
-  ::_decode_simple(version, p);
+  ::decode(version, p);
   __u32 n;
-  ::_decode_simple(n, p);
+  ::decode(n, p);
   while (n--) {
     Session *s = new Session;
     s->_decode(p);
index b1a30545be803447988fae6ee562834f724dd1e8..0a2b8c2d73368e25fce11ae134bdd7f8f1203ba4 100644 (file)
@@ -101,6 +101,23 @@ struct inode_caps_reconnect_t {
     wanted(w), issued(i), size(sz), mtime(mt), atime(at) {}
 };
 
+static inline void encode(const inode_caps_reconnect_t &ic, bufferlist &bl)
+{
+  ::encode(ic.wanted, bl);
+  ::encode(ic.issued, bl);
+  ::encode(ic.size, bl);
+  ::encode(ic.mtime, bl);
+  ::encode(ic.atime, bl);
+}
+static inline void decode(inode_caps_reconnect_t &ic, bufferlist::iterator &p)
+{
+  ::decode(ic.wanted, p);
+  ::decode(ic.issued, p);
+  ::decode(ic.size, p);
+  ::decode(ic.mtime, p);
+  ::decode(ic.atime, p);
+}
+
 
 // ================================================================
 // dir frag
@@ -186,6 +203,16 @@ class dirfrag_load_vec_t {
 public:
   static const int NUM = 5;
   DecayCounter vec[NUM];
+
+  void encode(bufferlist &bl) const {
+    for (int i=0; i<NUM; i++)
+      ::encode(vec[i], bl);
+  }
+  void decode(bufferlist::iterator &p) {
+    for (int i=0; i<NUM; i++)
+      ::decode(vec[i], p);
+  }
+
   DecayCounter &get(int t) { 
     assert(t < NUM);
     return vec[t]; 
@@ -216,6 +243,8 @@ public:
   }
 };
 
+WRITE_CLASS_ENCODERS(dirfrag_load_vec_t)
+
 inline dirfrag_load_vec_t& operator+=(dirfrag_load_vec_t& l, dirfrag_load_vec_t& r)
 {
   utime_t now = g_clock.now();
@@ -251,6 +280,8 @@ inline ostream& operator<<(ostream& out, dirfrag_load_vec_t& dl)
 
 
 
+
+
 /* mds_load_t
  * mds load
  */
index 66efb64a6e2c26e9bdf916c1e271b233c6433e17..1cbcce1d75381b23db6e497f11c293a996bd8e94 100644 (file)
@@ -43,26 +43,26 @@ public:
 
   void encode_payload() {
     __u32 n = inode_caps.size();
-    ::_encode_simple(closed, payload);
-    ::_encode_simple(n, payload);
+    ::encode(closed, payload);
+    ::encode(n, payload);
     for (map<inodeno_t, inode_caps_reconnect_t>::iterator p = inode_caps.begin();
         p != inode_caps.end();
         p++) {
-      ::_encode_simple(p->first, payload);
-      ::_encode_simple(p->second, payload);
-      ::_encode_simple(inode_path[p->first], payload);
+      ::encode(p->first, payload);
+      ::encode(p->second, payload);
+      ::encode(inode_path[p->first], payload);
     }
   }
   void decode_payload() {
     bufferlist::iterator p = payload.begin();
-    ::_decode_simple(closed, p);
+    ::decode(closed, p);
     __u32 n;
-    ::_decode_simple(n, p);
+    ::decode(n, p);
     while (n--) {
       inodeno_t ino;
-      ::_decode_simple(ino, p);
-      ::_decode_simple(inode_caps[ino], p);
-      ::_decode_simple(inode_path[ino], p);
+      ::decode(ino, p);
+      ::decode(inode_caps[ino], p);
+      ::decode(inode_path[ino], p);
     }
   }
 
index fbfd9776058bcb2678ba345ada4ec62f87d7bbd6..f96a5785893a7ec710bb04fcd0d14af1fb11dc0b 100644 (file)
@@ -325,7 +325,7 @@ bool OSDMonitor::should_propose(double& delay)
       if (g_conf.osd_auto_weight) {
        CrushWrapper crush;
        OSDMap::build_simple_crush_map(crush, osdmap.get_max_osd(), osd_weight);
-       crush._encode(pending_inc.crush);
+       crush.encode(pending_inc.crush);
       }
       return true;
     } else 
@@ -758,7 +758,7 @@ bool OSDMonitor::preprocess_command(MMonCommand *m)
       r = 0;
     }
     else if (m->cmd[1] == "getcrushmap") {
-      osdmap.crush._encode(rdata);
+      osdmap.crush.encode(rdata);
       ss << "got crush map from osdmap epoch " << osdmap.get_epoch();
       r = 0;
     }
index f41e6412d3fc607eddf2bb2d14a498889bfe92e4..e1cf5bb9ab2aa8329bc591378b183aa2bfc62743 100644 (file)
@@ -343,7 +343,7 @@ private:
 
     if (inc.crush.length()) {
       bufferlist::iterator blp = inc.crush.begin();
-      crush._decode(blp);
+      crush.decode(blp);
     }
 
     // nope, incremental.
@@ -416,7 +416,7 @@ private:
     ::encode(pg_swap_primary, blist);
     
     bufferlist cbl;
-    crush._encode(cbl);
+    crush.encode(cbl);
     ::encode(cbl, blist);
   }
   
@@ -441,7 +441,7 @@ private:
     bufferlist cbl;
     ::decode(cbl, p);
     bufferlist::iterator cblp = cbl.begin();
-    crush._decode(cblp);
+    crush.decode(cblp);
   }
  
 
index 8af6515fb7a851e5730e23210a3dd3abd207bf66..bb81e0e72f113f322e543644a3050b9d3a2b7f72 100644 (file)
@@ -132,14 +132,14 @@ int main(int argc, const char **argv)
     CrushWrapper cw;
     //cw._decode(cbl,    FIXME
     bufferlist::iterator p = cbl.begin();
-    osdmap.crush._decode(p);
+    osdmap.crush.decode(p);
     cout << me << ": imported crush map from " << import_crush << std::endl;
     modified = true;
   }
 
   if (export_crush) {
     bufferlist cbl;
-    osdmap.crush._encode(cbl);
+    osdmap.crush.encode(cbl);
     r = cbl.write_file(export_crush);
     if (r < 0) {
       cerr << me << ": error writing crush map to " << import_crush << std::endl;