From: Sage Weil Date: Wed, 20 Mar 2013 14:59:26 +0000 (-0700) Subject: crush: prevent formation of a loop X-Git-Tag: v0.62~177^2~10 X-Git-Url: http://git-server-git.apps.pok.os.sepia.ceph.com/?a=commitdiff_plain;h=fe4e86c6acd8424da625a0eb1b9171db44234201;p=ceph.git crush: prevent formation of a loop If we are adding an item, ensure it cannot form a loop in the tree/map/ DAG. Signed-off-by: Sage Weil --- diff --git a/src/crush/CrushWrapper.cc b/src/crush/CrushWrapper.cc index 766fad6e0afe..bb2390122361 100644 --- a/src/crush/CrushWrapper.cc +++ b/src/crush/CrushWrapper.cc @@ -305,6 +305,13 @@ int CrushWrapper::insert_item(CephContext *cct, int item, float weight, string n return -EEXIST; } + // are we forming a loop? + if (subtree_contains(cur, b->id)) { + ldout(cct, 1) << "insert_item " << cur << " already contains " << b->id + << "; cannot form loop" << dendl; + return -ELOOP; + } + ldout(cct, 5) << "insert_item adding " << cur << " weight " << weight << " to bucket " << id << dendl; int r = crush_bucket_add_item(b, cur, 0);