]> git.apps.os.sepia.ceph.com Git - ceph.git/commitdiff
crush: fix mishandle result of get_bucket() method
authorxie xingguo <xie.xingguo@zte.com.cn>
Thu, 21 Apr 2016 03:50:05 +0000 (11:50 +0800)
committerxie xingguo <xie.xingguo@zte.com.cn>
Thu, 21 Apr 2016 07:49:07 +0000 (15:49 +0800)
Get_bucket() is supposed to return a pointer to a specific bucket on success.
However, it never returns a null pointer if error occurs. It returns
-ENOENT instead. That's why most caller is misjudge the result code of get_bucket()
method.

Signed-off-by: xie xingguo <xie.xingguo@zte.com.cn>
src/crush/CrushWrapper.cc

index 3450b48fb8ff977b37b4d9c5b72c16bd4bfa4330..dc6280ee8507e6843a95c3904c5f08ea8ac52edf 100644 (file)
@@ -202,7 +202,7 @@ bool CrushWrapper::subtree_contains(int root, int item) const
     return false;  // root is a leaf
 
   const crush_bucket *b = get_bucket(root);
-  if (!b)
+  if (IS_ERR(b))
     return false;
 
   for (unsigned j=0; j<b->size; j++) {
@@ -243,7 +243,12 @@ int CrushWrapper::remove_item(CephContext *cct, int item, bool unlink_only)
 
   if (item < 0 && !unlink_only) {
     crush_bucket *t = get_bucket(item);
-    if (t && t->size) {
+    if (IS_ERR(t)) {
+      ldout(cct, 1) << "remove_item bucket " << item << " does not exist" << dendl;
+      return -ENOENT;
+    }
+
+    if (t->size) {
       ldout(cct, 1) << "remove_item bucket " << item << " has " << t->size
                    << " items, not empty" << dendl;
       return -ENOTEMPTY;
@@ -352,7 +357,13 @@ int CrushWrapper::remove_item_under(CephContext *cct, int item, int ancestor, bo
 
   if (item < 0 && !unlink_only) {
     crush_bucket *t = get_bucket(item);
-    if (t && t->size) {
+    if (IS_ERR(t)) {
+      ldout(cct, 1) << "remove_item_under bucket " << item
+                    << " does not exist" << dendl;
+      return -ENOENT;
+    }
+
+    if (t->size) {
       ldout(cct, 1) << "remove_item_under bucket " << item << " has " << t->size
                    << " items, not empty" << dendl;
       return -ENOTEMPTY;
@@ -555,7 +566,7 @@ int CrushWrapper::get_children(int id, list<int> *children)
   }
 
   crush_bucket *b = get_bucket(id);
-  if (!b) {
+  if (IS_ERR(b)) {
     return -ENOENT;
   }