]> git.apps.os.sepia.ceph.com Git - ceph.git/commitdiff
crush: send debug output to dout, not stdout/err
authorSage Weil <sage.weil@dreamhost.com>
Sun, 13 Nov 2011 22:18:19 +0000 (14:18 -0800)
committerSage Weil <sage.weil@dreamhost.com>
Sun, 13 Nov 2011 22:18:19 +0000 (14:18 -0800)
Signed-off-by: Sage Weil <sage.weil@dreamhost.com>
src/common/config_opts.h
src/crush/CrushWrapper.cc
src/crush/CrushWrapper.h
src/crushtool.cc
src/mon/OSDMonitor.cc
src/osd/OSDMap.cc

index 363911fc23aec760d696a9dd0dd4db0287aac29f..5f4da5f65e45a9b81e6c1e9d6290abcca620d998 100644 (file)
@@ -37,6 +37,7 @@ OPTION(max_open_files, OPT_LONGLONG, 0)
 OPTION(debug, OPT_INT, 0)
 OPTION(debug_lockdep, OPT_INT, 0)
 OPTION(debug_context, OPT_INT, 0)
+OPTION(debug_crush, OPT_INT, 1)
 OPTION(debug_mds, OPT_INT, 1)
 OPTION(debug_mds_balancer, OPT_INT, 1)
 OPTION(debug_mds_locker, OPT_INT, 1)
index ecdfd04eecaeac8387cd54e0eb4d0c3c938ac5b5..c979ab55760d792a4119cbbfa1ee8c0f1f9a5f0c 100644 (file)
@@ -3,6 +3,9 @@
 
 #include "CrushWrapper.h"
 
+#define DOUT_SUBSYS crush
+
+
 void CrushWrapper::find_roots(set<int>& roots) const
 {
   for (unsigned i=0; i<crush->max_rules; i++) {
@@ -17,9 +20,9 @@ void CrushWrapper::find_roots(set<int>& roots) const
 }
 
 
-int CrushWrapper::remove_item(int item)
+int CrushWrapper::remove_item(CephContext *cct, int item)
 {
-  cout << "remove_item " << item << std::endl;
+  ldout(cct, 5) << "remove_item " << item << dendl;
 
   crush_bucket *was_bucket = 0;
   int ret = -ENOENT;
@@ -35,12 +38,12 @@ int CrushWrapper::remove_item(int item)
        if (item < 0) {
          crush_bucket *t = get_bucket(item);
          if (t && t->size) {
-           cout << "remove_device bucket " << item << " has " << t->size << " items, not empty" << std::endl;
+           ldout(cct, 1) << "remove_device bucket " << item << " has " << t->size << " items, not empty" << dendl;
            return -ENOTEMPTY;
          }         
          was_bucket = t;
        }
-       cout << "remove_device removing item " << item << " from bucket " << b->id << std::endl;
+       ldout(cct, 5) << "remove_device removing item " << item << " from bucket " << b->id << dendl;
        crush_bucket_remove_item(b, item);
        ret = 0;
       }
@@ -48,7 +51,7 @@ int CrushWrapper::remove_item(int item)
   }
 
   if (was_bucket) {
-    cout << "remove_device removing bucket " << item << std::endl;
+    ldout(cct, 5) << "remove_device removing bucket " << item << dendl;
     crush_remove_bucket(crush, was_bucket);
   }
   if (item >= 0 && name_map.count(item)) {
@@ -60,15 +63,15 @@ int CrushWrapper::remove_item(int item)
   return ret;
 }
 
-int CrushWrapper::insert_item(int item, float weight, string name,
+int CrushWrapper::insert_item(CephContext *cct, int item, float weight, string name,
                                map<string,string>& loc)  // typename -> bucketname
 {
-  cout << "insert_item item " << item << " weight " << weight
-         << " name " << name << " loc " << loc << std::endl;
+  ldout(cct, 5) << "insert_item item " << item << " weight " << weight
+               << " name " << name << " loc " << loc << dendl;
 
   if (name_exists(name.c_str())) {
-    cerr << "error: device name '" << name << "' already exists as id "
-        << get_item_id(name.c_str()) << std::endl;
+    ldout(cct, 1) << "error: device name '" << name << "' already exists as id "
+                 << get_item_id(name.c_str()) << dendl;
     return -EEXIST;
   }
 
@@ -81,15 +84,15 @@ int CrushWrapper::insert_item(int item, float weight, string name,
       continue;
 
     if (loc.count(p->second) == 0) {
-      cerr << "error: did not specify location for '" << p->second << "' level (levels are "
-          << type_map << ")" << std::endl;
+      ldout(cct, 1) << "error: did not specify location for '" << p->second << "' level (levels are "
+                   << type_map << ")" << dendl;
       return -EINVAL;
     }
 
     int id = get_item_id(loc[p->second].c_str());
     if (!id) {
       // create the bucket
-      cout << "insert_item creating bucket " << loc[p->second] << std::endl;
+      ldout(cct, 5) << "insert_item creating bucket " << loc[p->second] << dendl;
       int empty = 0;
       id = add_bucket(0, CRUSH_BUCKET_STRAW, CRUSH_HASH_DEFAULT, p->first, 1, &cur, &empty);
       set_item_name(id, loc[p->second].c_str());
@@ -99,7 +102,7 @@ int CrushWrapper::insert_item(int item, float weight, string name,
 
     // add to an existing bucket
     if (!bucket_exists(id)) {
-      cout << "insert_item don't have bucket " << id << std::endl;
+      ldout(cct, 1) << "insert_item don't have bucket " << id << dendl;
       return -EINVAL;
     }
 
@@ -109,26 +112,26 @@ int CrushWrapper::insert_item(int item, float weight, string name,
     // make sure the item doesn't already exist in this bucket
     for (unsigned j=0; j<b->size; j++)
       if (b->items[j] == cur) {
-       cerr << "insert_item " << cur << " already exists in bucket " << b->id << std::endl;
+       ldout(cct, 1) << "insert_item " << cur << " already exists in bucket " << b->id << dendl;
        return -EEXIST;
       }
     
-    cout << "insert_item adding " << cur << " weight " << weight
-        << " to bucket " << id << std::endl;
+    ldout(cct, 5) << "insert_item adding " << cur << " weight " << weight
+                 << " to bucket " << id << dendl;
     crush_bucket_add_item(b, cur, 0);
 
     // now that we've added the (0-weighted) item and any parent buckets, adjust the weight.
-    adjust_item_weightf(item, weight);
+    adjust_item_weightf(cct, item, weight);
     return 0;
   }
 
-  cerr << "error: didn't find anywhere to add item " << item << " in " << loc << std::endl;
+  ldout(cct, 1) << "error: didn't find anywhere to add item " << item << " in " << loc << dendl;
   return -EINVAL;
 }
 
-int CrushWrapper::adjust_item_weight(int id, int weight)
+int CrushWrapper::adjust_item_weight(CephContext *cct, int id, int weight)
 {
-  cout << "adjust_item_weight " << id << " weight " << weight << std::endl;
+  ldout(cct, 5) << "adjust_item_weight " << id << " weight " << weight << dendl;
   for (int bidx = 0; bidx < crush->max_buckets; bidx++) {
     crush_bucket *b = crush->buckets[bidx];
     if (b == 0)
@@ -136,15 +139,15 @@ int CrushWrapper::adjust_item_weight(int id, int weight)
     for (unsigned i = 0; i < b->size; i++)
       if (b->items[i] == id) {
        int diff = crush_bucket_adjust_item_weight(b, id, weight);
-       cout << "adjust_item_weight " << id << " diff " << diff << std::endl;
-       adjust_item_weight(-1 - bidx, b->weight);
+       ldout(cct, 5) << "adjust_item_weight " << id << " diff " << diff << dendl;
+       adjust_item_weight(cct, -1 - bidx, b->weight);
        return 0;
       }
   }
   return -ENOENT;
 }
 
-void CrushWrapper::reweight()
+void CrushWrapper::reweight(CephContext *cct)
 {
   set<int> roots;
   find_roots(roots);
@@ -152,7 +155,7 @@ void CrushWrapper::reweight()
     if (*p >= 0)
       continue;
     crush_bucket *b = get_bucket(*p);
-    cout << "reweight bucket " << *p << std::endl;
+    ldout(cct, 5) << "reweight bucket " << *p << dendl;
     crush_reweight_bucket(crush, b);
   }
 }
index 0e57779ca4a2546e4caaddc3378a87a37b62393a..df62b8abcc9b4674de9e1e583f4b16c306a58e1e 100644 (file)
@@ -39,8 +39,6 @@ inline static void decode(crush_rule_step &s, bufferlist::iterator &p)
   ::decode(s.arg2, p);
 }
 
-
-
 using namespace std;
 class CrushWrapper {
 public:
@@ -161,13 +159,13 @@ public:
 
 
   void find_roots(set<int>& roots) const;
-  int insert_item(int id, float weight, string name, map<string,string>& loc);
-  int remove_item(int id);
-  int adjust_item_weight(int id, int weight);
-  int adjust_item_weightf(int id, float weight) {
-    return adjust_item_weight(id, (int)(weight * (float)0x10000));
+  int insert_item(CephContext *cct, int id, float weight, string name, map<string,string>& loc);
+  int remove_item(CephContext *cct, int id);
+  int adjust_item_weight(CephContext *cct, int id, int weight);
+  int adjust_item_weightf(CephContext *cct, int id, float weight) {
+    return adjust_item_weight(cct, id, (int)(weight * (float)0x10000));
   }
-  void reweight();
+  void reweight(CephContext *cct);
 
 
   /*** devices ***/
index a022fcf5f5fdd8f970f7b8f8ea3068f1255ea7fe..9918a6c62fdca0d804f497ca0358bbb28f2e4db8 100644 (file)
@@ -1150,7 +1150,7 @@ int main(int argc, const char **argv)
       r = -ENOENT;
     } else {
       int item = crush.get_item_id(reweight_name.c_str());
-      r = crush.adjust_item_weightf(item, reweight_weight);
+      r = crush.adjust_item_weightf(g_ceph_context, item, reweight_weight);
     }
     if (r == 0)
       modified = true;
@@ -1168,7 +1168,7 @@ int main(int argc, const char **argv)
       r = -ENOENT;
     } else {
       int remove_item = crush.get_item_id(remove_name.c_str());
-      r = crush.remove_item(remove_item);
+      r = crush.remove_item(g_ceph_context, remove_item);
     }
     if (r == 0)
       modified = true;
@@ -1180,7 +1180,7 @@ int main(int argc, const char **argv)
   if (add_item >= 0) {
     cout << me << " adding item " << add_item << " weight " << add_weight
         << " at " << add_loc << std::endl;
-    int r = crush.insert_item(add_item, add_weight, add_name.c_str(), add_loc);
+    int r = crush.insert_item(g_ceph_context, add_item, add_weight, add_name.c_str(), add_loc);
     if (r == 0)
       modified = true;
     else {
@@ -1189,7 +1189,7 @@ int main(int argc, const char **argv)
     }
   }
   if (reweight) {
-    crush.reweight();
+    crush.reweight(g_ceph_context);
     modified = true;
   }
 
index 431b5f1d2fda97d2d8450e22374d45f65b8b61f5..226c7575c237bb9c39e76bfa485f55f6482006aa 100644 (file)
@@ -1523,7 +1523,7 @@ bool OSDMonitor::prepare_command(MMonCommand *m)
        bufferlist::iterator p = bl.begin();
        newcrush.decode(p);
 
-       err = newcrush.insert_item(id, weight, name, loc);
+       err = newcrush.insert_item(g_ceph_context, id, weight, name, loc);
        if (err == 0) {
          if (newcrush.get_max_devices() > osdmap.get_max_osd()) {
            err = -ERANGE;
@@ -1559,7 +1559,7 @@ bool OSDMonitor::prepare_command(MMonCommand *m)
          ss << "device '" << m->cmd[3] << "' does not appear in the crush map";
          break;
        }
-       err = newcrush.remove_item(id);
+       err = newcrush.remove_item(g_ceph_context, id);
        if (err == 0) {
          pending_inc.crush.clear();
          newcrush.encode(pending_inc.crush);
@@ -1590,7 +1590,7 @@ bool OSDMonitor::prepare_command(MMonCommand *m)
        }
        float w = atof(m->cmd[4].c_str());
 
-       err = newcrush.adjust_item_weightf(id, w);
+       err = newcrush.adjust_item_weightf(g_ceph_context, id, w);
        if (err == 0) {
          pending_inc.crush.clear();
          newcrush.encode(pending_inc.crush);
index f2cc845b1e6fd20a78f5637e31a8c81e8740c15b..388a64da17822eef20693ebbddb32ae247bfbcc3 100644 (file)
@@ -944,7 +944,7 @@ void OSDMap::build_simple_crush_map(CephContext *cct, CrushWrapper& crush,
     ldout(cct, 10) << " adding osd." << o << " at " << loc << dendl;
     char name[8];
     sprintf(name, "osd.%d", o);
-    crush.insert_item(o, 1.0, name, loc);
+    crush.insert_item(cct, o, 1.0, name, loc);
   }
 
   // rules
@@ -1083,7 +1083,7 @@ void OSDMap::build_simple_crush_map_from_conf(CephContext *cct, CrushWrapper& cr
     loc["pool"] = "default";
 
     ldout(cct, 0) << " adding osd." << o << " at " << loc << dendl;
-    crush.insert_item(o, 1.0, *i, loc);
+    crush.insert_item(cct, o, 1.0, *i, loc);
   }
 
   // rules