~ubuntu-branches/ubuntu/raring/ceph/raring

« back to all changes in this revision

Viewing changes to src/crush/CrushWrapper.cc

  • Committer: Package Import Robot
  • Author(s): Laszlo Boszormenyi (GCS)
  • Date: 2012-02-05 10:07:38 UTC
  • mfrom: (1.1.7) (0.1.11 sid)
  • Revision ID: package-import@ubuntu.com-20120205100738-00s0bxx93mamy8tk
Tags: 0.41-1
New upstream release.

Show diffs side-by-side

added added

removed removed

Lines of Context:
3
3
 
4
4
#include "CrushWrapper.h"
5
5
 
 
6
#define DOUT_SUBSYS crush
 
7
 
 
8
 
6
9
void CrushWrapper::find_roots(set<int>& roots) const
7
10
{
8
11
  for (unsigned i=0; i<crush->max_rules; i++) {
17
20
}
18
21
 
19
22
 
20
 
int CrushWrapper::remove_item(int item)
 
23
int CrushWrapper::remove_item(CephContext *cct, int item)
21
24
{
22
 
  cout << "remove_item " << item << std::endl;
 
25
  ldout(cct, 5) << "remove_item " << item << dendl;
23
26
 
24
27
  crush_bucket *was_bucket = 0;
25
28
  int ret = -ENOENT;
35
38
        if (item < 0) {
36
39
          crush_bucket *t = get_bucket(item);
37
40
          if (t && t->size) {
38
 
            cout << "remove_device bucket " << item << " has " << t->size << " items, not empty" << std::endl;
 
41
            ldout(cct, 1) << "remove_device bucket " << item << " has " << t->size << " items, not empty" << dendl;
39
42
            return -ENOTEMPTY;
40
43
          }         
41
44
          was_bucket = t;
42
45
        }
43
 
        cout << "remove_device removing item " << item << " from bucket " << b->id << std::endl;
 
46
        ldout(cct, 5) << "remove_device removing item " << item << " from bucket " << b->id << dendl;
44
47
        crush_bucket_remove_item(b, item);
45
48
        ret = 0;
46
49
      }
48
51
  }
49
52
 
50
53
  if (was_bucket) {
51
 
    cout << "remove_device removing bucket " << item << std::endl;
 
54
    ldout(cct, 5) << "remove_device removing bucket " << item << dendl;
52
55
    crush_remove_bucket(crush, was_bucket);
53
56
  }
54
57
  if (item >= 0 && name_map.count(item)) {
60
63
  return ret;
61
64
}
62
65
 
63
 
int CrushWrapper::insert_item(int item, float weight, string name,
 
66
int CrushWrapper::insert_item(CephContext *cct, int item, float weight, string name,
64
67
                                map<string,string>& loc)  // typename -> bucketname
65
68
{
66
 
  cout << "insert_item item " << item << " weight " << weight
67
 
          << " name " << name << " loc " << loc << std::endl;
 
69
  ldout(cct, 5) << "insert_item item " << item << " weight " << weight
 
70
                << " name " << name << " loc " << loc << dendl;
68
71
 
69
72
  if (name_exists(name.c_str())) {
70
 
    cerr << "error: device name '" << name << "' already exists as id "
71
 
         << get_item_id(name.c_str()) << std::endl;
 
73
    ldout(cct, 1) << "error: device name '" << name << "' already exists as id "
 
74
                  << get_item_id(name.c_str()) << dendl;
72
75
    return -EEXIST;
73
76
  }
74
77
 
81
84
      continue;
82
85
 
83
86
    if (loc.count(p->second) == 0) {
84
 
      cerr << "error: did not specify location for '" << p->second << "' level (levels are "
85
 
           << type_map << ")" << std::endl;
 
87
      ldout(cct, 1) << "error: did not specify location for '" << p->second << "' level (levels are "
 
88
                    << type_map << ")" << dendl;
86
89
      return -EINVAL;
87
90
    }
88
91
 
89
92
    int id = get_item_id(loc[p->second].c_str());
90
93
    if (!id) {
91
94
      // create the bucket
92
 
      cout << "insert_item creating bucket " << loc[p->second] << std::endl;
 
95
      ldout(cct, 5) << "insert_item creating bucket " << loc[p->second] << dendl;
93
96
      int empty = 0;
94
97
      id = add_bucket(0, CRUSH_BUCKET_STRAW, CRUSH_HASH_DEFAULT, p->first, 1, &cur, &empty);
95
98
      set_item_name(id, loc[p->second].c_str());
99
102
 
100
103
    // add to an existing bucket
101
104
    if (!bucket_exists(id)) {
102
 
      cout << "insert_item don't have bucket " << id << std::endl;
 
105
      ldout(cct, 1) << "insert_item don't have bucket " << id << dendl;
103
106
      return -EINVAL;
104
107
    }
105
108
 
109
112
    // make sure the item doesn't already exist in this bucket
110
113
    for (unsigned j=0; j<b->size; j++)
111
114
      if (b->items[j] == cur) {
112
 
        cerr << "insert_item " << cur << " already exists in bucket " << b->id << std::endl;
 
115
        ldout(cct, 1) << "insert_item " << cur << " already exists in bucket " << b->id << dendl;
113
116
        return -EEXIST;
114
117
      }
115
118
    
116
 
    cout << "insert_item adding " << cur << " weight " << weight
117
 
         << " to bucket " << id << std::endl;
 
119
    ldout(cct, 5) << "insert_item adding " << cur << " weight " << weight
 
120
                  << " to bucket " << id << dendl;
118
121
    crush_bucket_add_item(b, cur, 0);
119
122
 
120
123
    // now that we've added the (0-weighted) item and any parent buckets, adjust the weight.
121
 
    adjust_item_weightf(item, weight);
 
124
    adjust_item_weightf(cct, item, weight);
122
125
    return 0;
123
126
  }
124
127
 
125
 
  cerr << "error: didn't find anywhere to add item " << item << " in " << loc << std::endl;
 
128
  ldout(cct, 1) << "error: didn't find anywhere to add item " << item << " in " << loc << dendl;
126
129
  return -EINVAL;
127
130
}
128
131
 
129
 
int CrushWrapper::adjust_item_weight(int id, int weight)
 
132
int CrushWrapper::adjust_item_weight(CephContext *cct, int id, int weight)
130
133
{
131
 
  cout << "adjust_item_weight " << id << " weight " << weight << std::endl;
 
134
  ldout(cct, 5) << "adjust_item_weight " << id << " weight " << weight << dendl;
132
135
  for (int bidx = 0; bidx < crush->max_buckets; bidx++) {
133
136
    crush_bucket *b = crush->buckets[bidx];
134
137
    if (b == 0)
136
139
    for (unsigned i = 0; i < b->size; i++)
137
140
      if (b->items[i] == id) {
138
141
        int diff = crush_bucket_adjust_item_weight(b, id, weight);
139
 
        cout << "adjust_item_weight " << id << " diff " << diff << std::endl;
140
 
        adjust_item_weight(-1 - bidx, b->weight);
 
142
        ldout(cct, 5) << "adjust_item_weight " << id << " diff " << diff << dendl;
 
143
        adjust_item_weight(cct, -1 - bidx, b->weight);
141
144
        return 0;
142
145
      }
143
146
  }
144
147
  return -ENOENT;
145
148
}
146
149
 
147
 
void CrushWrapper::reweight()
 
150
void CrushWrapper::reweight(CephContext *cct)
148
151
{
149
152
  set<int> roots;
150
153
  find_roots(roots);
152
155
    if (*p >= 0)
153
156
      continue;
154
157
    crush_bucket *b = get_bucket(*p);
155
 
    cout << "reweight bucket " << *p << std::endl;
 
158
    ldout(cct, 5) << "reweight bucket " << *p << dendl;
156
159
    crush_reweight_bucket(crush, b);
157
160
  }
158
161
}