crush: send debug output to dout, not stdout/err

Signed-off-by: Sage Weil <sage.weil@dreamhost.com>
This commit is contained in:
Sage Weil 2011-11-13 14:18:19 -08:00
parent 25eee416fd
commit 102c434297
6 changed files with 44 additions and 42 deletions

View 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)

View 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);
}
}

View 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 ***/

View 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;
}

View 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);

View 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