]> git.apps.os.sepia.ceph.com Git - ceph.git/commitdiff
crush: some crushwrapper methods, initial swig makefile?
authorSage Weil <sage@newdream.net>
Fri, 1 Feb 2008 21:46:27 +0000 (13:46 -0800)
committerSage Weil <sage@newdream.net>
Fri, 1 Feb 2008 21:46:27 +0000 (13:46 -0800)
src/Makefile.swig [new file with mode: 0644]
src/crush/CrushWrapper.h
src/crush/crush.h
src/include/err.h [new file with mode: 0644]
src/mon/MonMap.cc
src/mon/MonMap.h
src/mon/OSDMonitor.cc

diff --git a/src/Makefile.swig b/src/Makefile.swig
new file mode 100644 (file)
index 0000000..1e42273
--- /dev/null
@@ -0,0 +1,105 @@
+
+EXTRA_CFLAGS += -g
+EXTRA_CFLAGS += -pg
+#EXTRA_CFLAGS += -O3
+
+# base
+CFLAGS = -Wall -I. -D_FILE_OFFSET_BITS=64 -D_REENTRANT -D_THREAD_SAFE ${EXTRA_CFLAGS}
+LDINC = ld -i -o
+CXX = g++
+CC = gcc
+LIBS = -pthread
+
+MON_OBJS= \
+       mon/Monitor.o\
+       mon/Paxos.o\
+       mon/PaxosService.o\
+       mon/OSDMonitor.o\
+       mon/MDSMonitor.o\
+       mon/ClientMonitor.o\
+       mon/PGMonitor.o\
+       mon/Elector.o\
+       mon/MonitorStore.o
+
+COMMON_OBJS= \
+       msg/Message.o\
+       common/Logger.o\
+       common/Clock.o\
+       common/Timer.o\
+       mon/MonMap.o\
+       config.o
+
+#
+perl: common.o crush.o
+       swig -perl5 -c++ -shadow crush/CrushWrapper.i
+       ${CXX} ${CFLAGS} -c crush/CrushWrapper_wrap.cxx -fno-strict-aliasing -pipe
+       ${CXX} -shared crush/CrushWrapper_wrap.o common.o crush.o -o CrushWrapper.so
+
+
+
+#/usr/local/include -D_LARGEFILE_SOURCE -D_FILE_OFFSET_BITS=64 -I/usr/lib/perl/5.8/CORE -I. -I/home/michael/ceph/src/
+
+# targets
+TARGETS = cmon cosd cmds csyn mkmonmap cmonctl fakesyn dupstore
+SRCS=*.cc */*.cc *.h */*.h */*/*.h
+
+ifneq ($(fuse),no)
+TARGETS += cfuse fakefuse
+endif
+
+ifneq ($(mpi),no)
+TARGETS += newsyn
+endif
+
+all: depend ${TARGETS}
+
+# crush
+# lameness: use .co extension for .c files
+%.co: %.c
+       ${CC} ${CFLAGS} -c $< -o $@
+
+crush.o: crush/builder.co crush/mapper.co crush/crush.co
+       ${LDINC} $@ $^
+
+# bits
+common.o: ${COMMON_OBJS}
+       ${LDINC} $@ $^
+
+
+# generic rules
+%.so: %.cc
+       ${CXX} -shared -fPIC ${CFLAGS} $< -o $@
+
+%.o: %.cc
+       ${CXX} -fPIC ${CFLAGS} -c $< -o $@
+
+%.po: %.cc
+       ${CXX} -fPIC ${CFLAGS} -c $< -o $@
+
+
+# handy
+clean:
+       rm -f *.o */*.o crush/*.co ${TARGETS}
+
+count:
+       cat ${SRCS} | wc -l
+       cat ${SRCS} | grep -c \;
+
+TAGS:
+       etags `find . -name "*.[h|c|cc]"|grep -v '\.\#'`
+
+tags:
+       ctags `find . -name "*.[h|c|cc]"|grep -v '\.\#'`
+
+.depend:
+       touch .depend
+
+depend:
+       $(RM) .depend
+       makedepend -f- -- $(CFLAGS) -- $(SRCS) > .depend 2>/dev/null
+#      for f in $(SRCS) ; do cpp -MM $(CFLAGS) $$f 2> /dev/null >> .depend ; done
+
+
+# now add a line to include the dependency list.
+include .depend
+# DO NOT DELETE
index f9c2ba2c578d70d3be7223f0f616f67f1aa64d86..a9e7ffc2d9f9e0743deebe42a736fbc01d562d70 100644 (file)
 #include "mapper.h"
 #include "builder.h"
 
+#include "include/err.h"
 #include "include/encodable.h"
 
 #include <stdlib.h>
 #include <map>
 #include <set>
+#include <string>
 
 class CrushWrapper {
 public:
-  struct crush_map *map;
+  struct crush_map *crush;
+  map<int, string> type_map; /* bucket type names */
+  map<int, string> name_map; /* bucket/device names */
+
+  /* reverse maps */
+  map<string, int> type_rmap, name_rmap;
+
+private:
+  void build_rmaps() {
+    build_rmap(type_map, type_rmap);
+    build_rmap(name_map, name_rmap);
+  }
+  void build_rmap(map<int, string> &f, std::map<string, int> &r) {
+    r.clear();
+    for (std::map<int, string>::iterator p = f.begin(); p != f.end(); p++)
+      r[p->second] = p->first;
+  }
   
-  CrushWrapper() : map(0) {}
+public:
+  CrushWrapper() : crush(0) {}
   ~CrushWrapper() {
-    if (map) crush_destroy(map);
+    if (crush) crush_destroy(crush);
   }  
 
+  /* building */
   void create() {
-    if (map) crush_destroy(map);
-    map = crush_create();
+    if (crush) crush_destroy(crush);
+    crush = crush_create();
+  }
+
+  /*** types and names ***/
+  int get_type_id(const char *s) {
+    string name(s);
+    if (type_rmap.count(name))
+      return type_rmap[name];
+    return 0;
+  }
+  const char *get_type_name(int t) {
+    if (type_map.count(t))
+      return type_map[t].c_str();
+  }
+  int get_name_id(const char *s) {
+    string name(s);
+    if (type_rmap.count(name))
+      return type_rmap[name];
+    return 0;
+  }
+
+  /*** rules ***/
+private:
+  crush_rule *get_rule(unsigned ruleno) {
+    if (!crush) return (crush_rule *)(-ENOENT);
+    if (crush->max_rules >= ruleno) 
+      return 0;
+    return crush->rules[ruleno];
+  }
+  crush_rule_step *get_rule_step(unsigned ruleno, unsigned step) {
+    crush_rule *n = get_rule(ruleno);
+    if (!n) return (crush_rule_step *)(-EINVAL);
+    if (step >= n->len) return (crush_rule_step *)(-EINVAL);
+    return &n->steps[step];
+  }
+
+public:
+  /* accessors */
+  int get_max_rules() {
+    if (!crush) return 0;
+    return crush->max_rules;
+  }
+  int get_rule_op(unsigned ruleno, unsigned step) {
+    crush_rule_step *s = get_rule_step(ruleno, step);
+    if (IS_ERR(s)) return PTR_ERR(s);
+    return s->op;
+  }
+  int get_rule_arg1(unsigned ruleno, unsigned step) {
+    crush_rule_step *s = get_rule_step(ruleno, step);
+    if (IS_ERR(s)) return PTR_ERR(s);
+    return s->arg1;
+  }
+  int get_rule_arg2(unsigned ruleno, unsigned step) {
+    crush_rule_step *s = get_rule_step(ruleno, step);
+    if (IS_ERR(s)) return PTR_ERR(s);
+    return s->arg2;
+  }
+
+  /* modifiers */
+  int add_rule(unsigned ruleno, int len) {
+    if (!crush) return -ENOENT;
+    crush_rule *n = crush_make_rule(len);
+    crush_add_rule(crush, ruleno, n);
+    return 0;
+  }
+  int set_rule_step(unsigned ruleno, unsigned step, int op, int arg1, int arg2) {
+    if (!crush) return -ENOENT;
+    crush_rule *n = get_rule(ruleno);
+    if (!n) return -1;
+    crush_rule_set_step(n, step, op, arg1, arg2);
+    return 0;
   }
+  int set_rule_step_take(unsigned ruleno, unsigned step, int val) {
+    return set_rule_step(ruleno, step, CRUSH_RULE_TAKE, val, 0);
+  }
+  int set_rule_step_choose_firstn(unsigned ruleno, unsigned step, int val, int type) {
+    return set_rule_step(ruleno, step, CRUSH_RULE_CHOOSE_FIRSTN, val, type);
+  }
+  int set_rule_step_choose_indep(unsigned ruleno, unsigned step, int val, int type) {
+    return set_rule_step(ruleno, step, CRUSH_RULE_CHOOSE_INDEP, val, type);
+  }
+  int set_rule_step_emit(unsigned ruleno, unsigned step) {
+    return set_rule_step(ruleno, step, CRUSH_RULE_EMIT, 0, 0);
+  }
+  
+  
+  
+
+
+
+
+
+
+
+
+
   void finalize() {
-    assert(map);
-    crush_finalize(map);
+    assert(crush);
+    crush_finalize(crush);
   }
 
+
+
+
+
   void set_offload(int i, unsigned o) {
-    assert(i < map->max_devices);
-    map->device_offload[i] = o;
+    assert(i < crush->max_devices);
+    crush->device_offload[i] = o;
   }
   unsigned get_offload(int i) {
-    assert(i < map->max_devices);
-    return map->device_offload[i];
+    assert(i < crush->max_devices);
+    return crush->device_offload[i];
   }
 
   void do_rule(int rule, int x, vector<int>& out, int maxout, int forcefeed) {
     int rawout[maxout];
     
-    int numrep = crush_do_rule(map, rule, x, rawout, maxout, forcefeed);
+    int numrep = crush_do_rule(crush, rule, x, rawout, maxout, forcefeed);
 
     out.resize(numrep);
     for (int i=0; i<numrep; i++)
@@ -53,82 +171,82 @@ public:
   }
 
   void _encode(bufferlist &bl) {
-    ::_encode_simple(map->max_buckets, bl);
-    ::_encode_simple(map->max_rules, bl);
-    ::_encode_simple(map->max_devices, bl);
+    ::_encode_simple(crush->max_buckets, bl);
+    ::_encode_simple(crush->max_rules, bl);
+    ::_encode_simple(crush->max_devices, bl);
 
     // simple arrays
-    bl.append((char*)map->device_offload, sizeof(map->device_offload[0]) * map->max_devices);
+    bl.append((char*)crush->device_offload, sizeof(crush->device_offload[0]) * crush->max_devices);
 
     // buckets
-    for (unsigned i=0; i<map->max_buckets; i++) {
+    for (unsigned i=0; i<crush->max_buckets; i++) {
       __u32 type = 0;
-      if (map->buckets[i]) type = map->buckets[i]->bucket_type;
+      if (crush->buckets[i]) type = crush->buckets[i]->bucket_type;
       ::_encode_simple(type, bl);
       if (!type) continue;
 
-      ::_encode_simple(map->buckets[i]->id, bl);
-      ::_encode_simple(map->buckets[i]->type, bl);
-      ::_encode_simple(map->buckets[i]->bucket_type, bl);
-      ::_encode_simple(map->buckets[i]->weight, bl);
-      ::_encode_simple(map->buckets[i]->size, bl);
-      for (unsigned j=0; j<map->buckets[i]->size; j++)
-       ::_encode_simple(map->buckets[i]->items[j], bl);
+      ::_encode_simple(crush->buckets[i]->id, bl);
+      ::_encode_simple(crush->buckets[i]->type, bl);
+      ::_encode_simple(crush->buckets[i]->bucket_type, bl);
+      ::_encode_simple(crush->buckets[i]->weight, bl);
+      ::_encode_simple(crush->buckets[i]->size, bl);
+      for (unsigned j=0; j<crush->buckets[i]->size; j++)
+       ::_encode_simple(crush->buckets[i]->items[j], bl);
       
-      switch (map->buckets[i]->type) {
+      switch (crush->buckets[i]->type) {
       case CRUSH_BUCKET_UNIFORM:
-       for (unsigned j=0; j<map->buckets[i]->size; j++)
-         ::_encode_simple(((crush_bucket_uniform*)map->buckets[i])->primes[j], bl);
-       ::_encode_simple(((crush_bucket_uniform*)map->buckets[i])->item_weight, bl);
+       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);
        break;
 
       case CRUSH_BUCKET_LIST:
-       for (unsigned j=0; j<map->buckets[i]->size; j++) {
-         ::_encode_simple(((crush_bucket_list*)map->buckets[i])->item_weights[j], bl);
-         ::_encode_simple(((crush_bucket_list*)map->buckets[i])->sum_weights[j], bl);
+       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);
        }
        break;
 
       case CRUSH_BUCKET_TREE:
-       for (unsigned j=0; j<map->buckets[i]->size; j++) 
-         ::_encode_simple(((crush_bucket_tree*)map->buckets[i])->node_weights[j], bl);
+       for (unsigned j=0; j<crush->buckets[i]->size; j++) 
+         ::_encode_simple(((crush_bucket_tree*)crush->buckets[i])->node_weights[j], bl);
        break;
 
       case CRUSH_BUCKET_STRAW:
-       for (unsigned j=0; j<map->buckets[i]->size; j++) 
-         ::_encode_simple(((crush_bucket_straw*)map->buckets[i])->straws[j], bl);
+       for (unsigned j=0; j<crush->buckets[i]->size; j++) 
+         ::_encode_simple(((crush_bucket_straw*)crush->buckets[i])->straws[j], bl);
        break;
       }
     }
 
     // rules
-    for (unsigned i=0; i<map->max_rules; i++) {
-      __u32 yes = map->rules[i] ? 1:0;
+    for (unsigned i=0; i<crush->max_rules; i++) {
+      __u32 yes = crush->rules[i] ? 1:0;
       ::_encode_simple(yes, bl);
       if (!yes) continue;
 
-      ::_encode_simple(map->rules[i]->len, bl);
-      for (unsigned j=0; j<map->rules[i]->len; j++)
-       ::_encode_simple(map->rules[i]->steps[j], bl);
+      ::_encode_simple(crush->rules[i]->len, bl);
+      for (unsigned j=0; j<crush->rules[i]->len; j++)
+       ::_encode_simple(crush->rules[i]->steps[j], bl);
     }
   }
 
   void _decode(bufferlist::iterator &blp) {
     create();
-    ::_decode_simple(map->max_buckets, blp);
-    ::_decode_simple(map->max_rules, blp);
-    ::_decode_simple(map->max_devices, blp);
+    ::_decode_simple(crush->max_buckets, blp);
+    ::_decode_simple(crush->max_rules, blp);
+    ::_decode_simple(crush->max_devices, blp);
 
-    map->device_offload = (__u32*)malloc(sizeof(map->device_offload[0])*map->max_devices);
-    blp.copy(sizeof(map->device_offload[0])*map->max_devices, (char*)map->device_offload);
+    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);
     
     // buckets
-    map->buckets = (crush_bucket**)malloc(sizeof(crush_bucket*)*map->max_buckets);
-    for (unsigned i=0; i<map->max_buckets; i++) {
+    crush->buckets = (crush_bucket**)malloc(sizeof(crush_bucket*)*crush->max_buckets);
+    for (unsigned i=0; i<crush->max_buckets; i++) {
       __u32 type;
       ::_decode_simple(type, blp);
       if (!type) {
-       map->buckets[i] = 0;
+       crush->buckets[i] = 0;
        continue;
       }
 
@@ -149,72 +267,72 @@ public:
       default:
        assert(0);
       }
-      map->buckets[i] = (crush_bucket*)malloc(size);
-      memset(map->buckets[i], 0, size);
+      crush->buckets[i] = (crush_bucket*)malloc(size);
+      memset(crush->buckets[i], 0, size);
       
-      ::_decode_simple(map->buckets[i]->id, blp);
-      ::_decode_simple(map->buckets[i]->type, blp);
-      ::_decode_simple(map->buckets[i]->bucket_type, blp);
-      ::_decode_simple(map->buckets[i]->weight, blp);
-      ::_decode_simple(map->buckets[i]->size, blp);
+      ::_decode_simple(crush->buckets[i]->id, blp);
+      ::_decode_simple(crush->buckets[i]->type, blp);
+      ::_decode_simple(crush->buckets[i]->bucket_type, blp);
+      ::_decode_simple(crush->buckets[i]->weight, blp);
+      ::_decode_simple(crush->buckets[i]->size, blp);
 
-      map->buckets[i]->items = (__s32*)malloc(sizeof(__s32)*map->buckets[i]->size);
-      for (unsigned j=0; j<map->buckets[i]->size; j++)
-       ::_decode_simple(map->buckets[i]->items[j], 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);
 
-      switch (map->buckets[i]->type) {
+      switch (crush->buckets[i]->type) {
       case CRUSH_BUCKET_UNIFORM:
-       ((crush_bucket_uniform*)map->buckets[i])->primes = 
-         (__u32*)malloc(map->buckets[i]->size * sizeof(__u32));
-       for (unsigned j=0; j<map->buckets[i]->size; j++)
-         ::_decode_simple(((crush_bucket_uniform*)map->buckets[i])->primes[j], blp);
-       ::_decode_simple(((crush_bucket_uniform*)map->buckets[i])->item_weight, blp);
+       ((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);
        break;
 
       case CRUSH_BUCKET_LIST:
-       ((crush_bucket_list*)map->buckets[i])->item_weights = 
-         (__u32*)malloc(map->buckets[i]->size * sizeof(__u32));
-       ((crush_bucket_list*)map->buckets[i])->sum_weights = 
-         (__u32*)malloc(map->buckets[i]->size * sizeof(__u32));
-
-       for (unsigned j=0; j<map->buckets[i]->size; j++) {
-         ::_decode_simple(((crush_bucket_list*)map->buckets[i])->item_weights[j], blp);
-         ::_decode_simple(((crush_bucket_list*)map->buckets[i])->sum_weights[j], blp);
+       ((crush_bucket_list*)crush->buckets[i])->item_weights = 
+         (__u32*)malloc(crush->buckets[i]->size * sizeof(__u32));
+       ((crush_bucket_list*)crush->buckets[i])->sum_weights = 
+         (__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);
        }
        break;
 
       case CRUSH_BUCKET_TREE:
-       ((crush_bucket_tree*)map->buckets[i])->node_weights = 
-         (__u32*)malloc(map->buckets[i]->size * sizeof(__u32));
-       for (unsigned j=0; j<map->buckets[i]->size; j++) 
-         ::_decode_simple(((crush_bucket_tree*)map->buckets[i])->node_weights[j], blp);
+       ((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);
        break;
 
       case CRUSH_BUCKET_STRAW:
-       ((crush_bucket_straw*)map->buckets[i])->straws = 
-         (__u32*)malloc(map->buckets[i]->size * sizeof(__u32));
-       for (unsigned j=0; j<map->buckets[i]->size; j++) 
-         ::_decode_simple(((crush_bucket_straw*)map->buckets[i])->straws[j], blp);
+       ((crush_bucket_straw*)crush->buckets[i])->straws = 
+         (__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])->straws[j], blp);
        break;
       }
     }
 
     // rules
-    map->rules = (crush_rule**)malloc(sizeof(crush_rule*)*map->max_rules);
-    for (unsigned i=0; i<map->max_rules; i++) {
+    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);
       if (!yes) {
-       map->rules[i] = 0;
+       crush->rules[i] = 0;
        continue;
       }
 
       __u32 len;
       ::_decode_simple(len, blp);
-      map->rules[i] = (crush_rule*)malloc(crush_rule_size(len));
-      map->rules[i]->len = len;
-      for (unsigned j=0; j<map->rules[i]->len; j++)
-       ::_decode_simple(map->rules[i]->steps[j], blp);
+      crush->rules[i] = (crush_rule*)malloc(crush_rule_size(len));
+      crush->rules[i]->len = len;
+      for (unsigned j=0; j<crush->rules[i]->len; j++)
+       ::_decode_simple(crush->rules[i]->steps[j], blp);
     }
 
     finalize();
index d6743a5d0e49ec9c7cfdd75dc3c93251d376216b..284f64d47d80e7a17c03a6f60d22d6d2980d7a53 100644 (file)
@@ -17,10 +17,12 @@ extern "C" {
 
 /*** RULES ***/
 enum {
-       CRUSH_RULE_TAKE,
-       CRUSH_RULE_CHOOSE_FIRSTN,
-       CRUSH_RULE_CHOOSE_INDEP,
-       CRUSH_RULE_EMIT
+       CRUSH_RULE_NOOP = 0,
+       CRUSH_RULE_TAKE = 1,          /* arg1 = value to start with */
+       CRUSH_RULE_CHOOSE_FIRSTN = 2, /* arg1 = num items to pick */
+                                     /* arg2 = type */
+       CRUSH_RULE_CHOOSE_INDEP = 3,  /* same */ 
+       CRUSH_RULE_EMIT = 4           /* no args */
 };
 
 #define CRUSH_MAX_DEPTH 10
diff --git a/src/include/err.h b/src/include/err.h
new file mode 100644 (file)
index 0000000..f94a18a
--- /dev/null
@@ -0,0 +1,29 @@
+#ifndef __CEPH_ERR_H
+#define __CEPH_ERR_H
+
+/*
+ * adapted from linux 2.6.24 include/linux/err.h
+ */
+#define MAX_ERRNO 4095
+#define IS_ERR_VALUE(x) ((x) >= (unsigned long)-MAX_ERRNO)
+
+#include <asm/errno.h>
+
+/* this generates a warning in c++; caller can do the cast manually
+static inline void *ERR_PTR(long error)
+{
+  return (void *) error;
+}
+*/
+
+static inline long PTR_ERR(const void *ptr)
+{
+  return (long) ptr;
+}
+
+static inline long IS_ERR(const void *ptr)
+{
+  return IS_ERR_VALUE((unsigned long)ptr);
+}
+
+#endif
index d018eddb82c3382aadbcfbac5872d77ec6bade44..c17d1838484428ca9b54ace0899bf798ffcd5416 100644 (file)
@@ -5,6 +5,7 @@
 #include <sys/stat.h>
 #include <fcntl.h>
 
+
 // read from/write to a file
 int MonMap::write(const char *fn) 
 {
index 655d660de88f7addd0fefb4baf37364a1234bf96..f707b54fd1f3fb660aa75d1fd6af6e1c126a7698 100644 (file)
 #ifndef __MONMAP_H
 #define __MONMAP_H
 
+#include <asm/errno.h>
 #include "msg/Message.h"
 #include "include/types.h"
+//#include "config.h"
 
 class MonMap {
  public:
@@ -39,6 +41,16 @@ class MonMap {
     mon_inst.push_back(inst);
   }
 
+  /*
+  int add(const char *a) {
+    entity_addr_t addr;
+    if (!parse_ip_port(a, addr))
+      return -EINVAL;
+    if (contains(addr))
+      return -EEXIST;
+    add(addr);
+  }
+  */
   void add(entity_addr_t a) {
     entity_inst_t i;
     i.addr = a;
index c3f01ec68201014e2add5d9ef44c1e6d60a9e439..c7adeadd9b274ef2e68223440aa742d80601f966 100644 (file)
@@ -204,13 +204,13 @@ void OSDMonitor::build_crush_map(CrushWrapper& crush,
       }
 
       crush_bucket_uniform *domain = crush_make_uniform_bucket(1, j, items, 0x10000);
-      ritems[i] = crush_add_bucket(crush.map, (crush_bucket*)domain);
+      ritems[i] = crush_add_bucket(crush.crush, (crush_bucket*)domain);
       dout(20) << "added domain bucket i " << ritems[i] << " of size " << j << dendl;
     }
     
     // root
     crush_bucket_list *root = crush_make_list_bucket(2, ndom, ritems, rweights);
-    int rootid = crush_add_bucket(crush.map, (crush_bucket*)root);
+    int rootid = crush_add_bucket(crush.crush, (crush_bucket*)root);
     
     // rules
     // replication
@@ -220,7 +220,7 @@ void OSDMonitor::build_crush_map(CrushWrapper& crush,
       crush_rule_set_step(rule, 1, CRUSH_RULE_CHOOSE_FIRSTN, i, 1);
       crush_rule_set_step(rule, 2, CRUSH_RULE_CHOOSE_FIRSTN, 1, 0);
       crush_rule_set_step(rule, 3, CRUSH_RULE_EMIT, 0, 0);
-      crush_add_rule(crush.map, CRUSH_REP_RULE(i), rule);
+      crush_add_rule(crush.crush, CRUSH_REP_RULE(i), rule);
     }
 
     // raid
@@ -231,13 +231,13 @@ void OSDMonitor::build_crush_map(CrushWrapper& crush,
        crush_rule_set_step(rule, 1, CRUSH_RULE_CHOOSE_INDEP, i, 1);
        crush_rule_set_step(rule, 2, CRUSH_RULE_CHOOSE_INDEP, 1, 0);
        crush_rule_set_step(rule, 3, CRUSH_RULE_EMIT, 0, 0);
-       crush_add_rule(crush.map, CRUSH_RAID_RULE(i), rule);
+       crush_add_rule(crush.crush, CRUSH_RAID_RULE(i), rule);
       } else {
        crush_rule *rule = crush_make_rule(3);
        crush_rule_set_step(rule, 0, CRUSH_RULE_TAKE, rootid, 0);
        crush_rule_set_step(rule, 1, CRUSH_RULE_CHOOSE_INDEP, i, 0);
        crush_rule_set_step(rule, 2, CRUSH_RULE_EMIT, 0, 0);
-       crush_add_rule(crush.map, CRUSH_RAID_RULE(i), rule);
+       crush_add_rule(crush.crush, CRUSH_RAID_RULE(i), rule);
       }
     }
     
@@ -249,7 +249,7 @@ void OSDMonitor::build_crush_map(CrushWrapper& crush,
       items[i] = i;
     
     crush_bucket_uniform *b = crush_make_uniform_bucket(1, g_conf.num_osd, items, 0x10000);
-    int root = crush_add_bucket(crush.map, (crush_bucket*)b);
+    int root = crush_add_bucket(crush.crush, (crush_bucket*)b);
     
     // rules
     // replication
@@ -258,7 +258,7 @@ void OSDMonitor::build_crush_map(CrushWrapper& crush,
       crush_rule_set_step(rule, 0, CRUSH_RULE_TAKE, root, 0);
       crush_rule_set_step(rule, 1, CRUSH_RULE_CHOOSE_FIRSTN, i, 0);
       crush_rule_set_step(rule, 2, CRUSH_RULE_EMIT, 0, 0);
-      crush_add_rule(crush.map, CRUSH_REP_RULE(i), rule);
+      crush_add_rule(crush.crush, CRUSH_REP_RULE(i), rule);
     }
     // raid4
     for (int i=g_conf.osd_min_raid_width; i <= g_conf.osd_max_raid_width; i++) {
@@ -266,7 +266,7 @@ void OSDMonitor::build_crush_map(CrushWrapper& crush,
       crush_rule_set_step(rule, 0, CRUSH_RULE_TAKE, root, 0);
       crush_rule_set_step(rule, 1, CRUSH_RULE_CHOOSE_INDEP, i, 0);
       crush_rule_set_step(rule, 2, CRUSH_RULE_EMIT, 0, 0);
-      crush_add_rule(crush.map, CRUSH_RAID_RULE(i), rule);
+      crush_add_rule(crush.crush, CRUSH_RAID_RULE(i), rule);
     }
   }
   
@@ -276,7 +276,7 @@ void OSDMonitor::build_crush_map(CrushWrapper& crush,
   for (int i=0; i<g_conf.num_osd; i++)
     crush.set_offload(i, CEPH_OSD_IN);
 
-  dout(20) << "crush max_devices " << crush.map->max_devices << dendl;
+  dout(20) << "crush max_devices " << crush.crush->max_devices << dendl;
 }