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

« back to all changes in this revision

Viewing changes to src/common/ceph_context.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:
21
21
#include "common/config.h"
22
22
#include "common/debug.h"
23
23
#include "common/HeartbeatMap.h"
 
24
#include "common/errno.h"
24
25
#include "log/Log.h"
25
26
 
26
27
#include <iostream>
146
147
 
147
148
// perfcounter hooks
148
149
 
149
 
class PerfCountersHook : public AdminSocketHook {
150
 
  PerfCountersCollection *m_coll;
 
150
class CephContextHook : public AdminSocketHook {
 
151
  CephContext *m_cct;
151
152
 
152
153
public:
153
 
  PerfCountersHook(PerfCountersCollection *c) : m_coll(c) {}
 
154
  CephContextHook(CephContext *cct) : m_cct(cct) {}
154
155
 
155
 
  bool call(std::string command, bufferlist& out) {
156
 
    std::vector<char> v;
157
 
    if (command == "perfcounters_dump" ||
158
 
        command == "1")
159
 
      m_coll->write_json_to_buf(v, false);
160
 
    else if (command == "perfcounters_schema" ||
161
 
             command == "2")
162
 
      m_coll->write_json_to_buf(v, true);
163
 
    else 
164
 
      assert(0 == "registered under wrong command?");    
165
 
    out.append(&v[0], v.size());
 
156
  bool call(std::string command, std::string args, bufferlist& out) {
 
157
    m_cct->do_command(command, args, &out);
166
158
    return true;
167
159
  }
168
160
};
169
161
 
 
162
void CephContext::do_command(std::string command, std::string args, bufferlist *out)
 
163
{
 
164
  lgeneric_dout(this, 1) << "do_command '" << command << "' '" << args << "'" << dendl;
 
165
  if (command == "perfcounters_dump" || command == "1" ||
 
166
      command == "perf dump") {
 
167
    _perf_counters_collection->write_json_to_buf(*out, false);
 
168
  }
 
169
  else if (command == "perfcounters_schema" || command == "2" ||
 
170
           command == "perf schema") {
 
171
    _perf_counters_collection->write_json_to_buf(*out, true);
 
172
  }
 
173
  else if (command == "config show") {
 
174
    ostringstream ss;
 
175
    _conf->show_config(ss);
 
176
    out->append(ss.str());
 
177
  }
 
178
  else if (command == "config set ") {
 
179
    std::string var = args;
 
180
    size_t pos = var.find(' ');
 
181
    if (pos == string::npos) {
 
182
      out->append("set_config syntax is 'set_config <var> <value>'");
 
183
    } else {
 
184
      std::string val = var.substr(pos+1);
 
185
      var.resize(pos);
 
186
      std::vector<const char*> args;
 
187
      int r = _conf->set_val(var.c_str(), val.c_str());
 
188
      ostringstream ss;
 
189
      if (r < 0) {
 
190
        ss << "error setting '" << var << "' to '" << val << "': " << cpp_strerror(r);
 
191
      } else {
 
192
        _conf->apply_changes(&ss);
 
193
      }
 
194
      out->append(ss.str());
 
195
    }
 
196
  }
 
197
  else if (command == "log flush") {
 
198
    _log->flush();
 
199
  }
 
200
  else if (command == "log dump") {
 
201
    _log->dump_recent();
 
202
  }
 
203
  else if (command == "log reopen") {
 
204
    _log->reopen_log_file();
 
205
  }
 
206
  else {
 
207
    assert(0 == "registered under wrong command?");    
 
208
  }
 
209
  lgeneric_dout(this, 1) << "do_command '" << command << "' '" << args << "' result is " << out->length() << " bytes" << dendl;
 
210
};
 
211
 
170
212
 
171
213
CephContext::CephContext(uint32_t module_type_)
172
214
  : _conf(new md_config_t()),
189
231
 
190
232
  _perf_counters_collection = new PerfCountersCollection(this);
191
233
  _admin_socket = new AdminSocket(this);
192
 
  _conf->add_observer(_admin_socket);
193
234
  _heartbeat_map = new HeartbeatMap(this);
194
235
 
195
 
  _perf_counters_hook = new PerfCountersHook(_perf_counters_collection);
196
 
  _admin_socket->register_command("perfcounters_dump", _perf_counters_hook, "dump perfcounters value");
197
 
  _admin_socket->register_command("1", _perf_counters_hook, "");
198
 
  _admin_socket->register_command("perfcounters_schema", _perf_counters_hook, "dump perfcounters schema");
199
 
  _admin_socket->register_command("2", _perf_counters_hook, "");
 
236
  _admin_hook = new CephContextHook(this);
 
237
  _admin_socket->register_command("perfcounters_dump", _admin_hook, "");
 
238
  _admin_socket->register_command("1", _admin_hook, "");
 
239
  _admin_socket->register_command("perf dump", _admin_hook, "dump perfcounters value");
 
240
  _admin_socket->register_command("perfcounters_schema", _admin_hook, "");
 
241
  _admin_socket->register_command("2", _admin_hook, "");
 
242
  _admin_socket->register_command("perf schema", _admin_hook, "dump perfcounters schema");
 
243
  _admin_socket->register_command("config show", _admin_hook, "dump current config settings");
 
244
  _admin_socket->register_command("config set", _admin_hook, "set_config <field> <val>: set a config settings");
 
245
  _admin_socket->register_command("log flush", _admin_hook, "flush log entries to log file");
 
246
  _admin_socket->register_command("log dump", _admin_hook, "dump recent log entries to log file");
 
247
  _admin_socket->register_command("log reopen", _admin_hook, "reopen log file");
200
248
}
201
249
 
202
250
CephContext::~CephContext()
204
252
  join_service_thread();
205
253
 
206
254
  _admin_socket->unregister_command("perfcounters_dump");
 
255
  _admin_socket->unregister_command("perf dump");
207
256
  _admin_socket->unregister_command("1");
208
257
  _admin_socket->unregister_command("perfcounters_schema");
 
258
  _admin_socket->unregister_command("perf schema");
209
259
  _admin_socket->unregister_command("2");
210
 
  delete _perf_counters_hook;
 
260
  _admin_socket->unregister_command("config show");
 
261
  _admin_socket->unregister_command("config set");
 
262
  _admin_socket->unregister_command("log flush");
 
263
  _admin_socket->unregister_command("log dump");
 
264
  _admin_socket->unregister_command("log reopen");
 
265
  delete _admin_hook;
211
266
 
212
267
  delete _heartbeat_map;
213
268
 
214
 
  _conf->remove_observer(_admin_socket);
215
 
 
216
269
  delete _perf_counters_collection;
217
270
  _perf_counters_collection = NULL;
218
271
 
242
295
  _service_thread = new CephContextServiceThread(this);
243
296
  _service_thread->create();
244
297
  pthread_spin_unlock(&_service_thread_lock);
 
298
 
 
299
  // make logs flush on_exit()
 
300
  if (_conf->log_flush_on_exit)
 
301
    _log->set_flush_on_exit();
 
302
 
 
303
  // Trigger callbacks on any config observers that were waiting for
 
304
  // it to become safe to start threads.
 
305
  _conf->set_val("internal_safe_to_start_threads", "true");
 
306
  _conf->call_all_observers();
 
307
 
 
308
  // start admin socket
 
309
  if (_conf->admin_socket.length())
 
310
    _admin_socket->init(_conf->admin_socket);
245
311
}
246
312
 
247
313
void CephContext::reopen_logs()