]> git-server-git.apps.pok.os.sepia.ceph.com Git - ceph.git/commitdiff
crush: fix up constness some
authorSage Weil <sage@newdream.net>
Tue, 17 May 2011 20:03:01 +0000 (13:03 -0700)
committerSage Weil <sage@newdream.net>
Tue, 17 May 2011 20:03:01 +0000 (13:03 -0700)
Signed-off-by: Sage Weil <sage@newdream.net>
src/crush/CrushWrapper.h
src/crush/crush.c
src/crush/crush.h

index 6070d8b405ec77e1851f0ded018d963d7126b8ad..5d0dfe27621562a16db1fbdf836a4bf8d7a62dbf 100644 (file)
@@ -50,8 +50,8 @@ public:
   std::map<int, string> rule_name_map;
 
   /* reverse maps */
-  bool have_rmaps;
-  std::map<string, int> type_rmap, name_rmap, rule_name_rmap;
+  mutable bool have_rmaps;
+  mutable std::map<string, int> type_rmap, name_rmap, rule_name_rmap;
 
 private:
   void build_rmaps() {
@@ -90,9 +90,10 @@ public:
       return type_rmap[name];
     return 0;
   }
-  const char *get_type_name(int t) {
-    if (type_map.count(t))
-      return type_map[t].c_str();
+  const char *get_type_name(int t) const {
+    std::map<int,string>::const_iterator p = type_map.find(t);
+    if (p != type_map.end())
+      return p->second.c_str();
     return 0;
   }
   void set_type_name(int i, const char *n) {
@@ -110,9 +111,10 @@ public:
       return name_rmap[name];
     return 0;  /* hrm */
   }
-  const char *get_item_name(int t) {
-    if (name_map.count(t))
-      return name_map[t].c_str();
+  const char *get_item_name(int t) const {
+    std::map<int,string>::const_iterator p = name_map.find(t);
+    if (p != name_map.end())
+      return p->second.c_str();
     return 0;
   }
   void set_item_name(int i, const char *n) {
@@ -255,7 +257,7 @@ public:
 
   /** buckets **/
 private:
-  crush_bucket *get_bucket(int id) {
+  const crush_bucket *get_bucket(int id) const {
     if (!crush)
       return (crush_bucket *)(-EINVAL);
     unsigned int pos = (unsigned int)(-1 - id);
@@ -269,54 +271,59 @@ private:
   }
 
 public:
-  int get_max_buckets() {
+  int get_max_buckets() const {
     if (!crush) return -EINVAL;
     return crush->max_buckets;
   }
-  int get_next_bucket_id() {
+  int get_next_bucket_id() const {
     if (!crush) return -EINVAL;
     return crush_get_next_bucket_id(crush);
   }
-  bool bucket_exists(int id) {
-    crush_bucket *b = get_bucket(id);
+  bool bucket_exists(int id) const {
+    const crush_bucket *b = get_bucket(id);
     if (IS_ERR(b))
       return false;
     return true;
   }
-  int get_bucket_weight(int id) {
-    crush_bucket *b = get_bucket(id);
+  int get_bucket_weight(int id) const {
+    const crush_bucket *b = get_bucket(id);
     if (IS_ERR(b)) return PTR_ERR(b);
     return b->weight;
   }
-  int get_bucket_type(int id) {
-    crush_bucket *b = get_bucket(id);
+  float get_bucket_weightf(int id) const {
+    const crush_bucket *b = get_bucket(id);
+    if (IS_ERR(b)) return 0;
+    return b->weight / (float)0x10000;
+  }
+  int get_bucket_type(int id) const {
+    const crush_bucket *b = get_bucket(id);
     if (IS_ERR(b)) return PTR_ERR(b);
     return b->type;
   }
-  int get_bucket_alg(int id) {
-    crush_bucket *b = get_bucket(id);
+  int get_bucket_alg(int id) const {
+    const crush_bucket *b = get_bucket(id);
     if (IS_ERR(b)) return PTR_ERR(b);
     return b->alg;
   }
-  int get_bucket_hash(int id) {
-    crush_bucket *b = get_bucket(id);
+  int get_bucket_hash(int id) const {
+    const crush_bucket *b = get_bucket(id);
     if (IS_ERR(b)) return PTR_ERR(b);
     return b->hash;
   }
-  int get_bucket_size(int id) {
-    crush_bucket *b = get_bucket(id);
+  int get_bucket_size(int id) const {
+    const crush_bucket *b = get_bucket(id);
     if (IS_ERR(b)) return PTR_ERR(b);
     return b->size;
   }
-  int get_bucket_item(int id, int pos) {
-    crush_bucket *b = get_bucket(id);
+  int get_bucket_item(int id, int pos) const {
+    const crush_bucket *b = get_bucket(id);
     if (IS_ERR(b)) return PTR_ERR(b);
     if ((__u32)pos >= b->size)
       return PTR_ERR(b);
     return b->items[pos];
   }
-  int get_bucket_item_weight(int id, int pos) {
-    crush_bucket *b = get_bucket(id);
+  int get_bucket_item_weight(int id, int pos) const {
+    const crush_bucket *b = get_bucket(id);
     if (IS_ERR(b)) return PTR_ERR(b);
     return crush_get_bucket_item_weight(b, pos);
   }
index 1f7cc0c2e6ae6f2e5234aade3fffc7b395d4975a..040cbbd6360617c54d057944a7dd0b40eee42202 100644 (file)
@@ -26,7 +26,7 @@ const char *crush_bucket_alg_name(int alg)
  * @b: bucket pointer
  * @p: item index in bucket
  */
-int crush_get_bucket_item_weight(struct crush_bucket *b, int p)
+int crush_get_bucket_item_weight(const struct crush_bucket *b, int p)
 {
        if ((__u32)p >= b->size)
                return 0;
index bf01cc78c21579b8ad97457c15846c35c5cf10bc..eabd059dc850d9569c35b9730b43eaf209aa3e56 100644 (file)
@@ -167,7 +167,7 @@ struct crush_map {
 
 
 /* crush.c */
-extern int crush_get_bucket_item_weight(struct crush_bucket *b, int pos);
+extern int crush_get_bucket_item_weight(const struct crush_bucket *b, int pos);
 extern void crush_calc_parents(struct crush_map *map);
 extern void crush_destroy_bucket_uniform(struct crush_bucket_uniform *b);
 extern void crush_destroy_bucket_list(struct crush_bucket_list *b);