From: Sage Weil Date: Wed, 3 Dec 2014 01:17:10 +0000 (-0800) Subject: crush: move default bucket choice into CrushWrapper helper X-Git-Tag: v0.93~161^2~8 X-Git-Url: http://git-server-git.apps.pok.os.sepia.ceph.com/?a=commitdiff_plain;h=d4ec7570688586eba66cab0a8039fa5adb369c63;p=ceph.git crush: move default bucket choice into CrushWrapper helper Signed-off-by: Sage Weil --- diff --git a/src/crush/CrushWrapper.cc b/src/crush/CrushWrapper.cc index 1ef4458e1b61..1d00b994bb05 100644 --- a/src/crush/CrushWrapper.cc +++ b/src/crush/CrushWrapper.cc @@ -544,7 +544,8 @@ int CrushWrapper::insert_item(CephContext *cct, int item, float weight, string n if (!name_exists(q->second)) { ldout(cct, 5) << "insert_item creating bucket " << q->second << dendl; int empty = 0, newid; - int r = add_bucket(0, CRUSH_BUCKET_STRAW, CRUSH_HASH_DEFAULT, p->first, 1, &cur, &empty, &newid); + int r = add_bucket(0, 0, + CRUSH_HASH_DEFAULT, p->first, 1, &cur, &empty, &newid); if (r < 0) { ldout(cct, 1) << "add_bucket failure error: " << cpp_strerror(r) << dendl; return r; diff --git a/src/crush/CrushWrapper.h b/src/crush/CrushWrapper.h index d5deed8d9f2c..5b7124b908bb 100644 --- a/src/crush/CrushWrapper.h +++ b/src/crush/CrushWrapper.h @@ -249,6 +249,11 @@ public: bool is_v2_rule(unsigned ruleid) const; bool is_v3_rule(unsigned ruleid) const; + // default bucket types + unsigned get_default_bucket_alg() const { + return CRUSH_BUCKET_STRAW; + } + // bucket types int get_num_type_names() const { return type_map.size(); @@ -904,8 +909,11 @@ public: /* modifiers */ int add_bucket(int bucketno, int alg, int hash, int type, int size, int *items, int *weights, int *idout) { - if (type == 0) - return -EINVAL; + if (alg == 0) { + alg = get_default_bucket_alg(); + if (alg == 0) + return -EINVAL; + } crush_bucket *b = crush_make_bucket(crush, alg, hash, type, size, items, weights); assert(b); return crush_add_bucket(crush, bucketno, b, idout); diff --git a/src/mon/OSDMonitor.cc b/src/mon/OSDMonitor.cc index 6029bf0a3dfd..5794d4b2257c 100644 --- a/src/mon/OSDMonitor.cc +++ b/src/mon/OSDMonitor.cc @@ -4507,9 +4507,9 @@ bool OSDMonitor::prepare_command_impl(MMonCommand *m, goto reply; } int bucketno; - err = newcrush.add_bucket(0, CRUSH_BUCKET_STRAW, - CRUSH_HASH_DEFAULT, type, 0, NULL, - NULL, &bucketno); + err = newcrush.add_bucket(0, 0, + CRUSH_HASH_DEFAULT, type, 0, NULL, + NULL, &bucketno); if (err < 0) { ss << "add_bucket error: '" << cpp_strerror(err) << "'"; goto reply; diff --git a/src/osd/OSDMap.cc b/src/osd/OSDMap.cc index cc158617575f..a9ab413d1617 100644 --- a/src/osd/OSDMap.cc +++ b/src/osd/OSDMap.cc @@ -2730,7 +2730,7 @@ int OSDMap::build_simple_crush_map(CephContext *cct, CrushWrapper& crush, // root int root_type = _build_crush_types(crush); int rootid; - int r = crush.add_bucket(0, CRUSH_BUCKET_STRAW, CRUSH_HASH_DEFAULT, + int r = crush.add_bucket(0, 0, CRUSH_HASH_DEFAULT, root_type, 0, NULL, NULL, &rootid); assert(r == 0); crush.set_item_name(rootid, "default"); @@ -2766,7 +2766,8 @@ int OSDMap::build_simple_crush_map_from_conf(CephContext *cct, // root int root_type = _build_crush_types(crush); int rootid; - int r = crush.add_bucket(0, CRUSH_BUCKET_STRAW, CRUSH_HASH_DEFAULT, + int r = crush.add_bucket(0, 0, + CRUSH_HASH_DEFAULT, root_type, 0, NULL, NULL, &rootid); assert(r == 0); crush.set_item_name(rootid, "default");