~ubuntu-branches/ubuntu/quantal/ceph/quantal

« back to all changes in this revision

Viewing changes to src/mon/OSDMonitor.cc

  • Committer: Package Import Robot
  • Author(s): James Page
  • Date: 2012-07-16 09:56:24 UTC
  • mfrom: (0.3.11)
  • mto: This revision was merged to the branch mainline in revision 17.
  • Revision ID: package-import@ubuntu.com-20120716095624-azr2w4hbhei1rxmx
Tags: upstream-0.48
ImportĀ upstreamĀ versionĀ 0.48

Show diffs side-by-side

added added

removed removed

Lines of Context:
12
12
 * 
13
13
 */
14
14
 
 
15
#include <sstream>
 
16
 
15
17
#include "OSDMonitor.h"
16
18
#include "Monitor.h"
17
19
#include "MDSMonitor.h"
42
44
#include "common/errno.h"
43
45
 
44
46
#include "include/compat.h"
45
 
 
46
 
#include <sstream>
 
47
#include "include/assert.h"
47
48
 
48
49
#define dout_subsys ceph_subsys_mon
49
50
#undef dout_prefix
233
234
 
234
235
  if (thrash_map && thrash())
235
236
    propose_pending();
 
237
 
 
238
  if (mon->is_leader())
 
239
    mon->clog.info() << "osdmap " << osdmap << "\n"; 
236
240
}
237
241
 
238
242
void OSDMonitor::update_logger()
313
317
  oss << buf;
314
318
  std::string sep;
315
319
  oss << "overloaded osds: ";
 
320
  bool changed = false;
316
321
  for (hash_map<int,osd_stat_t>::const_iterator p = pgm.osd_stat.begin();
317
322
       p != pgm.osd_stat.end();
318
323
       ++p) {
323
328
      // Assign a lower weight to overloaded OSDs. The current weight
324
329
      // is a factor to take into account the original weights,
325
330
      // to represent e.g. differing storage capacities
326
 
      float weight = osdmap.get_weightf(p->first);
327
 
      float new_weight = (average_util / util) * weight;
328
 
      osdmap.set_weightf(p->first, new_weight);
 
331
      unsigned weight = osdmap.get_weight(p->first);
 
332
      unsigned new_weight = (unsigned)((average_util / util) * (float)weight);
 
333
      pending_inc.new_weight[p->first] = new_weight;
329
334
      char buf[128];
330
335
      snprintf(buf, sizeof(buf), "%d [%04f -> %04f]", p->first,
331
 
               weight, new_weight);
 
336
               (float)weight / (float)0x10000,
 
337
               (float)new_weight / (float)0x10000);
332
338
      oss << buf << sep;
 
339
      changed = true;
333
340
    }
334
341
  }
335
342
  if (sep.empty()) {
337
344
  }
338
345
  out_str = oss.str();
339
346
  dout(0) << "reweight_by_utilization: finished with " << out_str << dendl;
340
 
  return 0;
 
347
  return changed;
341
348
}
342
349
 
343
350
void OSDMonitor::create_pending()
389
396
 
390
397
  // encode
391
398
  assert(paxos->get_version() + 1 == pending_inc.epoch);
392
 
  ::encode(pending_inc, bl, -1);
 
399
  ::encode(pending_inc, bl, CEPH_FEATURES_ALL);
393
400
}
394
401
 
395
402
 
597
604
  return true;
598
605
}
599
606
 
 
607
/**
 
608
 * @note the parameter @p i apparently only exists here so we can output the
 
609
 *       osd's id on messages.
 
610
 */
600
611
bool OSDMonitor::can_mark_out(int i)
601
612
{
602
613
  if (osdmap.test_flag(CEPH_OSDMAP_NOOUT)) {
1246
1257
  // mark down osds out?
1247
1258
  utime_t now = ceph_clock_now(g_ceph_context);
1248
1259
 
 
1260
 
 
1261
  /* can_mark_out() checks if we can mark osds as being out. The -1 has no
 
1262
   * influence at all. The decision is made based on the ratio of "in" osds,
 
1263
   * and the function returns false if this ratio is lower that the minimum
 
1264
   * ratio set by g_conf->mon_osd_min_in_ratio. So it's not really up to us.
 
1265
   */
1249
1266
  if (can_mark_out(-1)) {
1250
1267
    map<int,utime_t>::iterator i = down_pending_out.begin();
1251
1268
    while (i != down_pending_out.end()) {
1438
1455
  bufferlist rdata;
1439
1456
  stringstream ss;
1440
1457
 
 
1458
  MonSession *session = m->get_session();
 
1459
  if (!session ||
 
1460
      (!session->caps.get_allow_all() &&
 
1461
       !session->caps.check_privileges(PAXOS_OSDMAP, MON_CAP_R) &&
 
1462
       !mon->_allowed_command(session, m->cmd))) {
 
1463
    mon->reply_command(m, -EACCES, "access denied", rdata, paxos->get_version());
 
1464
    return true;
 
1465
  }
 
1466
 
1441
1467
  vector<const char*> args;
1442
1468
  for (unsigned i = 1; i < m->cmd.size(); i++)
1443
1469
    args.push_back(m->cmd[i].c_str());
1718
1744
  stringstream ss;
1719
1745
  string rs;
1720
1746
  int err = -EINVAL;
 
1747
 
 
1748
  MonSession *session = m->get_session();
 
1749
  if (!session ||
 
1750
      (!session->caps.get_allow_all() &&
 
1751
       !session->caps.check_privileges(PAXOS_OSDMAP, MON_CAP_W) &&
 
1752
       !mon->_allowed_command(session, m->cmd))) {
 
1753
    mon->reply_command(m, -EACCES, "access denied", paxos->get_version());
 
1754
    return true;
 
1755
  }
 
1756
 
1721
1757
  if (m->cmd.size() > 1) {
1722
1758
    if ((m->cmd.size() == 2 && m->cmd[1] == "setcrushmap") ||
1723
1759
        (m->cmd.size() == 3 && m->cmd[1] == "crush" && m->cmd[2] == "set")) {
1773
1809
            break;
1774
1810
          string key(s, 0, pos-s);
1775
1811
          string value(pos+1);
1776
 
          loc[key] = value;
 
1812
          if (value.length())
 
1813
            loc[key] = value;
 
1814
          else
 
1815
            loc.erase(key);
1777
1816
        }
1778
1817
 
1779
1818
        dout(0) << "adding/updating crush item id " << id << " name '" << name << "' weight " << weight
2243
2282
          paxos->wait_for_commit(new Monitor::C_Command(mon, m, ret, rs, paxos->get_version()));
2244
2283
          return true;
2245
2284
        }
 
2285
      } else if (m->cmd[2] == "rename" && m->cmd.size() == 5) {
 
2286
        int64_t pool = osdmap.lookup_pg_pool_name(m->cmd[3].c_str());
 
2287
        if (pool < 0) {
 
2288
          ss << "unrecognized pool '" << m->cmd[3] << "'";
 
2289
          err = -ENOENT;
 
2290
        } else if (osdmap.lookup_pg_pool_name(m->cmd[4].c_str()) >= 0) {
 
2291
          ss << "pool '" << m->cmd[4] << "' already exists";
 
2292
          err = -EEXIST;
 
2293
        } else {
 
2294
          int ret = _prepare_rename_pool(pool, m->cmd[4]);
 
2295
          if (ret == 0) {
 
2296
            ss << "pool '" << m->cmd[3] << "' renamed to '" << m->cmd[4] << "'";
 
2297
          } else {
 
2298
            ss << "failed to rename pool '" << m->cmd[3] << "' to '" << m->cmd[4] << "': "
 
2299
               << cpp_strerror(ret);
 
2300
          }
 
2301
          getline(ss, rs);
 
2302
          paxos->wait_for_commit(new Monitor::C_Command(mon, m, ret, rs, paxos->get_version()));
 
2303
          return true;
 
2304
        }
2246
2305
      } else if (m->cmd[2] == "set") {
2247
2306
        if (m->cmd.size() != 6) {
2248
2307
          err = -EINVAL;
2369
2428
      }
2370
2429
      string out_str;
2371
2430
      err = reweight_by_utilization(oload, out_str);
2372
 
      if (err) {
2373
 
        ss << "FAILED to reweight-by-utilization: " << out_str;
 
2431
      if (err < 0) {
 
2432
        ss << "FAILED reweight-by-utilization: " << out_str;
2374
2433
      }
2375
 
      else {
 
2434
      else if (err == 0) {
 
2435
        ss << "no change: " << out_str;
 
2436
      } else {
2376
2437
        ss << "SUCCESSFUL reweight-by-utilization: " << out_str;
 
2438
        getline(ss, rs);
 
2439
        paxos->wait_for_commit(new Monitor::C_Command(mon, m, 0, rs, paxos->get_version()));
 
2440
        return true;
2377
2441
      }
2378
2442
    }
2379
2443
    else if (m->cmd.size() == 3 && m->cmd[1] == "thrash") {
2585
2649
  return 0;
2586
2650
}
2587
2651
 
 
2652
int OSDMonitor::_prepare_rename_pool(uint64_t pool, string newname)
 
2653
{
 
2654
  dout(10) << "_prepare_rename_pool " << pool << dendl;
 
2655
  if (pending_inc.old_pools.count(pool)) {
 
2656
    dout(10) << "_prepare_rename_pool " << pool << " pending removal" << dendl;    
 
2657
    return -ENOENT;
 
2658
  }
 
2659
  for (map<int64_t,string>::iterator p = pending_inc.new_pool_names.begin();
 
2660
       p != pending_inc.new_pool_names.end();
 
2661
       ++p) {
 
2662
    if (p->second == newname) {
 
2663
      return -EEXIST;
 
2664
    }
 
2665
  }
 
2666
 
 
2667
  pending_inc.new_pool_names[pool] = newname;
 
2668
  return 0;
 
2669
}
 
2670
 
2588
2671
bool OSDMonitor::prepare_pool_op_delete(MPoolOp *m)
2589
2672
{
2590
2673
  int ret = _prepare_remove_pool(m->pool);