]> git.apps.os.sepia.ceph.com Git - ceph.git/commitdiff
crush: hrm fix up builder too
authorSage Weil <sage@newdream.net>
Sun, 8 Nov 2009 04:12:21 +0000 (20:12 -0800)
committerSage Weil <sage@newdream.net>
Sun, 8 Nov 2009 04:39:31 +0000 (20:39 -0800)
fix

src/crush/CrushWrapper.h
src/crush/builder.c
src/crush/builder.h
src/crush/hash.h
src/crushtool.cc
src/osd/OSDMap.cc

index e24d572d7adcbacb06cc9836a84996c4760f421d..161529ec272f0156d1f72f4679dd9796f59c6349 100644 (file)
@@ -313,9 +313,9 @@ public:
   }
 
   /* modifiers */
-  int add_bucket(int bucketno, int alg, int type, int size,
+  int add_bucket(int bucketno, int alg, int hash, int type, int size,
                 int *items, int *weights) {
-    crush_bucket *b = crush_make_bucket(alg, type, size, items, weights);
+    crush_bucket *b = crush_make_bucket(alg, hash, type, size, items, weights);
     return crush_add_bucket(crush, bucketno, b);
   }
 
@@ -374,8 +374,8 @@ public:
 
       ::encode(crush->buckets[i]->id, bl);
       ::encode(crush->buckets[i]->type, bl);
-      ::encode(crush->buckets[i]->hash, bl);
       ::encode(crush->buckets[i]->alg, bl);
+      ::encode(crush->buckets[i]->hash, bl);
       ::encode(crush->buckets[i]->weight, bl);
       ::encode(crush->buckets[i]->size, bl);
       for (unsigned j=0; j<crush->buckets[i]->size; j++)
@@ -469,8 +469,8 @@ public:
 
       ::decode(crush->buckets[i]->id, blp);
       ::decode(crush->buckets[i]->type, blp);
-      ::decode(crush->buckets[i]->hash, blp);
       ::decode(crush->buckets[i]->alg, blp);
+      ::decode(crush->buckets[i]->hash, blp);
       ::decode(crush->buckets[i]->weight, blp);
       ::decode(crush->buckets[i]->size, blp);
 
index c0d9e7a2b404f758d5ac6fd86191a6cde3f930e6..4b0319197a8b6df5708ce9cb4cacc6076384e9b7 100644 (file)
@@ -141,7 +141,7 @@ int crush_add_bucket(struct crush_map *map,
 /* uniform bucket */
 
 struct crush_bucket_uniform *
-crush_make_uniform_bucket(int type, int size,
+crush_make_uniform_bucket(int hash, int type, int size,
                          int *items,
                          int item_weight)
 {
@@ -151,8 +151,8 @@ crush_make_uniform_bucket(int type, int size,
        bucket = malloc(sizeof(*bucket));
        memset(bucket, 0, sizeof(*bucket));
        bucket->h.alg = CRUSH_BUCKET_UNIFORM;
+       bucket->h.hash = hash;
        bucket->h.type = type;
-       bucket->h.hash = CRUSH_HASH_RJENKINS1;
        bucket->h.size = size;
        bucket->h.weight = size * item_weight;
 
@@ -170,7 +170,7 @@ crush_make_uniform_bucket(int type, int size,
 /* list bucket */
 
 struct crush_bucket_list*
-crush_make_list_bucket(int type, int size,
+crush_make_list_bucket(int hash, int type, int size,
                       int *items,
                       int *weights)
 {
@@ -181,8 +181,8 @@ crush_make_list_bucket(int type, int size,
        bucket = malloc(sizeof(*bucket));
        memset(bucket, 0, sizeof(*bucket));
        bucket->h.alg = CRUSH_BUCKET_LIST;
+       bucket->h.hash = hash;
        bucket->h.type = type;
-       bucket->h.hash = CRUSH_HASH_RJENKINS1;
        bucket->h.size = size;
 
        bucket->h.items = malloc(sizeof(__u32)*size);
@@ -228,7 +228,7 @@ static int parent(int n)
 }
 
 struct crush_bucket_tree*
-crush_make_tree_bucket(int type, int size,
+crush_make_tree_bucket(int hash, int type, int size,
                       int *items,    /* in leaf order */
                       int *weights)
 {
@@ -240,8 +240,8 @@ crush_make_tree_bucket(int type, int size,
        bucket = malloc(sizeof(*bucket));
        memset(bucket, 0, sizeof(*bucket));
        bucket->h.alg = CRUSH_BUCKET_TREE;
+       bucket->h.hash = hash;
        bucket->h.type = type;
-       bucket->h.hash = CRUSH_HASH_RJENKINS1;
        bucket->h.size = size;
 
        bucket->h.items = malloc(sizeof(__u32)*size);
@@ -282,7 +282,8 @@ crush_make_tree_bucket(int type, int size,
 /* straw bucket */
 
 struct crush_bucket_straw *
-crush_make_straw_bucket(int type,
+crush_make_straw_bucket(int hash, 
+                       int type,
                        int size,
                        int *items,
                        int *weights)
@@ -297,8 +298,8 @@ crush_make_straw_bucket(int type,
        bucket = malloc(sizeof(*bucket));
        memset(bucket, 0, sizeof(*bucket));
        bucket->h.alg = CRUSH_BUCKET_STRAW;
+       bucket->h.hash = hash;
        bucket->h.type = type;
-       bucket->h.hash = CRUSH_HASH_RJENKINS1;
        bucket->h.size = size;
 
        bucket->h.items = malloc(sizeof(__u32)*size);
@@ -382,7 +383,7 @@ crush_make_straw_bucket(int type,
 
 
 struct crush_bucket*
-crush_make_bucket(int alg, int type, int size,
+crush_make_bucket(int alg, int hash, int type, int size,
                  int *items,
                  int *weights)
 {
@@ -394,16 +395,16 @@ crush_make_bucket(int alg, int type, int size,
                        item_weight = weights[0];
                else
                        item_weight = 0;
-               return (struct crush_bucket *)crush_make_uniform_bucket(type, size, items, item_weight);
+               return (struct crush_bucket *)crush_make_uniform_bucket(hash, type, size, items, item_weight);
 
        case CRUSH_BUCKET_LIST:
-               return (struct crush_bucket *)crush_make_list_bucket(type, size, items, weights);
+               return (struct crush_bucket *)crush_make_list_bucket(hash, type, size, items, weights);
 
        case CRUSH_BUCKET_TREE:
-               return (struct crush_bucket *)crush_make_tree_bucket(type, size, items, weights);
+               return (struct crush_bucket *)crush_make_tree_bucket(hash, type, size, items, weights);
 
        case CRUSH_BUCKET_STRAW:
-               return (struct crush_bucket *)crush_make_straw_bucket(type, size, items, weights);
+               return (struct crush_bucket *)crush_make_straw_bucket(hash, type, size, items, weights);
        }
        return 0;
 }
index 2b36380e556469f667c41b0b3e16421ecaa2ac59..a83d858c76c8b129d3bcd0bfbf70395dab9dd621 100644 (file)
@@ -16,22 +16,22 @@ extern int crush_get_next_bucket_id(struct crush_map *map);
 extern int crush_add_bucket(struct crush_map *map,
                            int bucketno,
                            struct crush_bucket *bucket);
-struct crush_bucket *crush_make_bucket(int alg, int type, int size, int *items, int *weights);
+struct crush_bucket *crush_make_bucket(int alg, int hash, int type, int size, int *items, int *weights);
 
 struct crush_bucket_uniform *
-crush_make_uniform_bucket(int type, int size,
+crush_make_uniform_bucket(int hash, int type, int size,
                          int *items,
                          int item_weight);
 struct crush_bucket_list*
-crush_make_list_bucket(int type, int size,
+crush_make_list_bucket(int hash, int type, int size,
                       int *items,
                       int *weights);
 struct crush_bucket_tree*
-crush_make_tree_bucket(int type, int size,
+crush_make_tree_bucket(int hash, int type, int size,
                       int *items,    /* in leaf order */
                       int *weights);
 struct crush_bucket_straw *
-crush_make_straw_bucket(int type, int size,
+crush_make_straw_bucket(int hash, int type, int size,
                        int *items,
                        int *weights);
 
index ab7bb532d250eacb4d8b58ced9615fc84365e490..ff48e110e4bb44232102363a93809eaf4e793178 100644 (file)
@@ -3,6 +3,8 @@
 
 #define CRUSH_HASH_RJENKINS1   0
 
+#define CRUSH_HASH_DEFAULT CRUSH_HASH_RJENKINS1
+
 extern const char *crush_hash_name(int type);
 
 extern __u32 crush_hash32(int type, __u32 a);
index 7fd99a838b5b0a79a4869ff58786fd67ec107eb8..6665be2005692387ac283510f2a9de24f34e17ea 100644 (file)
@@ -113,6 +113,7 @@ void parse_bucket(iter_t const& i, CrushWrapper &crush)
 
   int id = 0;  // none, yet!
   int alg = -1;
+  int hash = -1;
   set<int> used_items;
   int size = 0;
   
@@ -137,6 +138,13 @@ void parse_bucket(iter_t const& i, CrushWrapper &crush)
        exit(1);
       }
     }
+    else if (tag == "hash") {
+      string a = string_node(sub->children[1]);
+      if (a == "rjenkins1")
+       hash = CRUSH_HASH_RJENKINS1;
+      else
+       hash = atoi(a.c_str());
+    }
     else if (tag == "item") {
       // first, just determine which item pos's are already used
       size++;
@@ -214,7 +222,7 @@ void parse_bucket(iter_t const& i, CrushWrapper &crush)
   item_id[name] = id;
   item_weight[id] = bucketweight;
   
-  crush.add_bucket(id, alg, type, size, &items[0], &weights[0]);
+  crush.add_bucket(id, alg, hash, type, size, &items[0], &weights[0]);
   crush.set_item_name(id, name.c_str());
 }
 
index b25e6e4e2cff06b481be3797bfc491c457ec87ca..334950ebb63f0733bc9c1f1cb01b2017a359b34a 100644 (file)
@@ -171,7 +171,7 @@ void OSDMap::build_simple_crush_map(CrushWrapper& crush, map<int, const char*>&
        rweights[i] += 0x10000;
       }
 
-      crush_bucket *domain = crush_make_bucket(CRUSH_BUCKET_UNIFORM, 1, j, items, weights);
+      crush_bucket *domain = crush_make_bucket(CRUSH_BUCKET_UNIFORM, CRUSH_HASH_DEFAULT, 1, j, items, weights);
       ritems[i] = crush_add_bucket(crush.crush, 0, domain);
       dout(20) << "added domain bucket i " << ritems[i] << " of size " << j << dendl;
 
@@ -181,7 +181,7 @@ void OSDMap::build_simple_crush_map(CrushWrapper& crush, map<int, const char*>&
     }
     
     // root
-    crush_bucket *root = crush_make_bucket(CRUSH_BUCKET_STRAW, 2, ndom, ritems, rweights);
+    crush_bucket *root = crush_make_bucket(CRUSH_BUCKET_STRAW, CRUSH_HASH_DEFAULT, 2, ndom, ritems, rweights);
     int rootid = crush_add_bucket(crush.crush, 0, root);
     crush.set_item_name(rootid, "root");
 
@@ -206,7 +206,7 @@ void OSDMap::build_simple_crush_map(CrushWrapper& crush, map<int, const char*>&
       weights[i] = 0x10000;
     }
 
-    crush_bucket *b = crush_make_bucket(CRUSH_BUCKET_STRAW, 1, num_osd, items, weights);
+    crush_bucket *b = crush_make_bucket(CRUSH_BUCKET_STRAW, CRUSH_HASH_DEFAULT, 1, num_osd, items, weights);
     int rootid = crush_add_bucket(crush.crush, 0, b);
     crush.set_item_name(rootid, "root");