1 // -*- mode:C++; tab-width:8; c-basic-offset:2; indent-tabs-mode:t -*-
2 // vim: ts=8 sw=2 smarttab
4 * Ceph - scalable distributed file system
6 * Copyright (C) 2011 New Dream Network
7 * Copyright (C) 2017 OVH
9 * This is free software; you can redistribute it and/or
10 * modify it under the terms of the GNU Lesser General Public
11 * License version 2.1, as published by the Free Software
12 * Foundation. See file COPYING.
16 #include "common/ceph_context.h"
23 #include <boost/algorithm/string.hpp>
25 #include "include/mempool.h"
26 #include "common/admin_socket.h"
27 #include "common/code_environment.h"
28 #include "common/ceph_mutex.h"
29 #include "common/debug.h"
30 #include "common/config.h"
31 #include "common/ceph_crypto.h"
32 #include "common/HeartbeatMap.h"
33 #include "common/errno.h"
34 #include "common/Graylog.h"
38 #include "auth/Crypto.h"
39 #include "include/str_list.h"
40 #include "common/config.h"
41 #include "common/config_obs.h"
42 #include "common/PluginRegistry.h"
43 #include "common/valgrind.h"
44 #include "include/spinlock.h"
46 using ceph::bufferlist
;
47 using ceph::HeartbeatMap
;
50 #include "common/common_init.h"
56 CephContext::CephContext()
57 : _conf
{ceph::common::local_conf()},
58 _perf_counters_collection
{ceph::common::local_perf_coll()},
59 _crypto_random
{std::make_unique
<CryptoRandom
>()}
62 // define the dtor in .cc as CryptoRandom is an incomplete type in the header
63 CephContext::~CephContext()
66 uint32_t CephContext::get_module_type() const
68 return CEPH_ENTITY_TYPE_OSD
;
71 CryptoRandom
* CephContext::random() const
73 return _crypto_random
.get();
76 CephContext
* CephContext::get()
82 void CephContext::put()
89 PerfCountersCollectionImpl
* CephContext::get_perfcounters_collection()
91 return _perf_counters_collection
.get_perf_collection();
97 class LockdepObs
: public md_config_obs_t
{
99 explicit LockdepObs(CephContext
*cct
)
100 : m_cct(cct
), m_registered(false), lock(ceph::make_mutex("lock_dep_obs")) {
102 ~LockdepObs() override
{
104 lockdep_unregister_ceph_context(m_cct
);
108 const char** get_tracked_conf_keys() const override
{
109 static const char *KEYS
[] = {"lockdep", NULL
};
113 void handle_conf_change(const ConfigProxy
& conf
,
114 const std::set
<std::string
> &changed
) override
{
115 std::unique_lock
locker(lock
);
116 if (conf
->lockdep
&& !m_registered
) {
117 lockdep_register_ceph_context(m_cct
);
119 } else if (!conf
->lockdep
&& m_registered
) {
120 lockdep_unregister_ceph_context(m_cct
);
121 m_registered
= false;
130 class MempoolObs
: public md_config_obs_t
,
131 public AdminSocketHook
{
136 explicit MempoolObs(CephContext
*cct
)
137 : cct(cct
), lock(ceph::make_mutex("mem_pool_obs")) {
138 cct
->_conf
.add_observer(this);
139 int r
= cct
->get_admin_socket()->register_command(
143 "get mempool stats");
146 ~MempoolObs() override
{
147 cct
->_conf
.remove_observer(this);
148 cct
->get_admin_socket()->unregister_command("dump_mempools");
152 const char** get_tracked_conf_keys() const override
{
153 static const char *KEYS
[] = {
160 void handle_conf_change(const ConfigProxy
& conf
,
161 const std::set
<std::string
> &changed
) override
{
162 std::unique_lock
locker(lock
);
163 if (changed
.count("mempool_debug")) {
164 mempool::set_debug_mode(cct
->_conf
->mempool_debug
);
169 bool call(std::string_view command
, const cmdmap_t
& cmdmap
,
170 std::string_view format
, bufferlist
& out
) override
{
171 if (command
== "dump_mempools") {
172 std::unique_ptr
<Formatter
> f(Formatter::create(format
));
173 f
->open_object_section("mempools");
174 mempool::dump(f
.get());
183 } // anonymous namespace
185 class CephContextServiceThread
: public Thread
188 explicit CephContextServiceThread(CephContext
*cct
)
189 : _reopen_logs(false), _exit_thread(false), _cct(cct
)
193 ~CephContextServiceThread() override
{}
195 void *entry() override
198 std::unique_lock
l(_lock
);
200 if (_cct
->_conf
->heartbeat_interval
) {
201 auto interval
= ceph::make_timespan(_cct
->_conf
->heartbeat_interval
);
202 _cond
.wait_for(l
, interval
);
211 _cct
->_log
->reopen_log_file();
212 _reopen_logs
= false;
214 _cct
->_heartbeat_map
->check_touch_file();
216 // refresh the perf coutners
217 _cct
->_refresh_perf_values();
224 std::lock_guard
l(_lock
);
231 std::lock_guard
l(_lock
);
237 ceph::mutex _lock
= ceph::make_mutex("CephContextServiceThread::_lock");
238 ceph::condition_variable _cond
;
246 * observe logging config changes
248 * The logging subsystem sits below most of the ceph code, including
249 * the config subsystem, to keep it simple and self-contained. Feed
250 * logging-related config changes to the log.
252 class LogObs
: public md_config_obs_t
{
253 ceph::logging::Log
*log
;
257 explicit LogObs(ceph::logging::Log
*l
)
258 : log(l
), lock(ceph::make_mutex("log_obs")) {
261 const char** get_tracked_conf_keys() const override
{
262 static const char *KEYS
[] = {
276 "log_coarse_timestamps",
284 void handle_conf_change(const ConfigProxy
& conf
,
285 const std::set
<std::string
> &changed
) override
{
286 std::unique_lock
locker(lock
);
288 if (changed
.count("log_to_stderr") || changed
.count("err_to_stderr")) {
289 int l
= conf
->log_to_stderr
? 99 : (conf
->err_to_stderr
? -1 : -2);
290 log
->set_stderr_level(l
, l
);
294 if (changed
.count("log_to_syslog")) {
295 int l
= conf
->log_to_syslog
? 99 : (conf
->err_to_syslog
? -1 : -2);
296 log
->set_syslog_level(l
, l
);
300 if (changed
.count("log_file") ||
301 changed
.count("log_to_file")) {
302 if (conf
->log_to_file
) {
303 log
->set_log_file(conf
->log_file
);
305 log
->set_log_file({});
307 log
->reopen_log_file();
310 if (changed
.count("log_stderr_prefix")) {
311 log
->set_log_stderr_prefix(conf
.get_val
<string
>("log_stderr_prefix"));
314 if (changed
.count("log_max_new")) {
316 log
->set_max_new(conf
->log_max_new
);
319 if (changed
.count("log_max_recent")) {
320 log
->set_max_recent(conf
->log_max_recent
);
324 if (changed
.count("log_to_graylog") || changed
.count("err_to_graylog")) {
325 int l
= conf
->log_to_graylog
? 99 : (conf
->err_to_graylog
? -1 : -2);
326 log
->set_graylog_level(l
, l
);
328 if (conf
->log_to_graylog
|| conf
->err_to_graylog
) {
329 log
->start_graylog();
330 } else if (! (conf
->log_to_graylog
&& conf
->err_to_graylog
)) {
335 if (log
->graylog() && (changed
.count("log_graylog_host") || changed
.count("log_graylog_port"))) {
336 log
->graylog()->set_destination(conf
->log_graylog_host
, conf
->log_graylog_port
);
339 if (changed
.find("log_coarse_timestamps") != changed
.end()) {
340 log
->set_coarse_timestamps(conf
.get_val
<bool>("log_coarse_timestamps"));
344 if (log
->graylog() && changed
.count("host")) {
345 log
->graylog()->set_hostname(conf
->host
);
348 if (log
->graylog() && changed
.count("fsid")) {
349 log
->graylog()->set_fsid(conf
.get_val
<uuid_d
>("fsid"));
355 // cct config watcher
356 class CephContextObs
: public md_config_obs_t
{
360 explicit CephContextObs(CephContext
*cct
) : cct(cct
) {}
362 const char** get_tracked_conf_keys() const override
{
363 static const char *KEYS
[] = {
364 "enable_experimental_unrecoverable_data_corrupting_features",
371 void handle_conf_change(const ConfigProxy
& conf
,
372 const std::set
<std::string
> &changed
) override
{
374 "enable_experimental_unrecoverable_data_corrupting_features")) {
375 std::lock_guard
lg(cct
->_feature_lock
);
377 conf
->enable_experimental_unrecoverable_data_corrupting_features
,
378 cct
->_experimental_features
);
379 if (getenv("CEPH_DEV") == NULL
) {
380 if (!cct
->_experimental_features
.empty()) {
381 if (cct
->_experimental_features
.count("*")) {
382 lderr(cct
) << "WARNING: all dangerous and experimental features are enabled." << dendl
;
384 lderr(cct
) << "WARNING: the following dangerous and experimental features are enabled: "
385 << cct
->_experimental_features
<< dendl
;
391 if (changed
.count("crush_location")) {
392 cct
->crush_location
.update_from_conf();
397 bool CephContext::check_experimental_feature_enabled(const std::string
& feat
)
399 stringstream message
;
400 bool enabled
= check_experimental_feature_enabled(feat
, &message
);
401 lderr(this) << message
.str() << dendl
;
405 bool CephContext::check_experimental_feature_enabled(const std::string
& feat
,
406 std::ostream
*message
)
408 std::unique_lock
<ceph::spinlock
> lg(_feature_lock
);
410 bool enabled
= (_experimental_features
.count(feat
) ||
411 _experimental_features
.count("*"));
414 (*message
) << "WARNING: experimental feature '" << feat
<< "' is enabled\n";
415 (*message
) << "Please be aware that this feature is experimental, untested,\n";
416 (*message
) << "unsupported, and may result in data corruption, data loss,\n";
417 (*message
) << "and/or irreparable damage to your cluster. Do not use\n";
418 (*message
) << "feature with important data.\n";
420 (*message
) << "*** experimental feature '" << feat
<< "' is not enabled ***\n";
421 (*message
) << "This feature is marked as experimental, which means it\n";
422 (*message
) << " - is untested\n";
423 (*message
) << " - is unsupported\n";
424 (*message
) << " - may corrupt your data\n";
425 (*message
) << " - may break your cluster is an unrecoverable fashion\n";
426 (*message
) << "To enable this feature, add this to your ceph.conf:\n";
427 (*message
) << " enable experimental unrecoverable data corrupting features = " << feat
<< "\n";
434 class CephContextHook
: public AdminSocketHook
{
438 explicit CephContextHook(CephContext
*cct
) : m_cct(cct
) {}
440 bool call(std::string_view command
, const cmdmap_t
& cmdmap
,
441 std::string_view format
, bufferlist
& out
) override
{
443 m_cct
->do_command(command
, cmdmap
, format
, &out
);
444 } catch (const bad_cmd_get
& e
) {
451 void CephContext::do_command(std::string_view command
, const cmdmap_t
& cmdmap
,
452 std::string_view format
, bufferlist
*out
)
454 Formatter
*f
= Formatter::create(format
, "json-pretty", "json-pretty");
456 for (auto it
= cmdmap
.begin(); it
!= cmdmap
.end(); ++it
) {
457 if (it
->first
!= "prefix") {
458 ss
<< it
->first
<< ":" << cmd_vartype_stringify(it
->second
) << " ";
461 lgeneric_dout(this, 1) << "do_command '" << command
<< "' '"
462 << ss
.str() << dendl
;
463 ceph_assert_always(!(command
== "assert" && _conf
->debug_asok_assert_abort
));
464 if (command
== "abort" && _conf
->debug_asok_assert_abort
) {
467 if (command
== "perfcounters_dump" || command
== "1" ||
468 command
== "perf dump") {
471 cmd_getval(this, cmdmap
, "logger", logger
);
472 cmd_getval(this, cmdmap
, "counter", counter
);
473 _perf_counters_collection
->dump_formatted(f
, false, logger
, counter
);
475 else if (command
== "perfcounters_schema" || command
== "2" ||
476 command
== "perf schema") {
477 _perf_counters_collection
->dump_formatted(f
, true);
479 else if (command
== "perf histogram dump") {
482 cmd_getval(this, cmdmap
, "logger", logger
);
483 cmd_getval(this, cmdmap
, "counter", counter
);
484 _perf_counters_collection
->dump_formatted_histograms(f
, false, logger
,
487 else if (command
== "perf histogram schema") {
488 _perf_counters_collection
->dump_formatted_histograms(f
, true);
490 else if (command
== "perf reset") {
492 std::string
section(command
);
493 f
->open_object_section(section
.c_str());
494 if (!cmd_getval(this, cmdmap
, "var", var
)) {
495 f
->dump_string("error", "syntax error: 'perf reset <var>'");
497 if(!_perf_counters_collection
->reset(var
))
498 f
->dump_stream("error") << "Not find: " << var
;
500 f
->dump_string("success", std::string(command
) + ' ' + var
);
505 std::string
section(command
);
506 boost::replace_all(section
, " ", "_");
507 f
->open_object_section(section
.c_str());
508 if (command
== "config show") {
509 _conf
.show_config(f
);
511 else if (command
== "config unset") {
513 if (!(cmd_getval(this, cmdmap
, "var", var
))) {
514 f
->dump_string("error", "syntax error: 'config unset <var>'");
516 int r
= _conf
.rm_val(var
.c_str());
517 if (r
< 0 && r
!= -ENOENT
) {
518 f
->dump_stream("error") << "error unsetting '" << var
<< "': "
522 _conf
.apply_changes(&ss
);
523 f
->dump_string("success", ss
.str());
528 else if (command
== "config set") {
530 std::vector
<std::string
> val
;
532 if (!(cmd_getval(this, cmdmap
, "var", var
)) ||
533 !(cmd_getval(this, cmdmap
, "val", val
))) {
534 f
->dump_string("error", "syntax error: 'config set <var> <value>'");
536 // val may be multiple words
537 string valstr
= str_join(val
, " ");
538 int r
= _conf
.set_val(var
.c_str(), valstr
.c_str());
540 f
->dump_stream("error") << "error setting '" << var
<< "' to '" << valstr
<< "': " << cpp_strerror(r
);
543 _conf
.apply_changes(&ss
);
544 f
->dump_string("success", ss
.str());
547 } else if (command
== "config get") {
549 if (!cmd_getval(this, cmdmap
, "var", var
)) {
550 f
->dump_string("error", "syntax error: 'config get <var>'");
553 memset(buf
, 0, sizeof(buf
));
555 int r
= _conf
.get_val(var
.c_str(), &tmp
, sizeof(buf
));
557 f
->dump_stream("error") << "error getting '" << var
<< "': " << cpp_strerror(r
);
559 f
->dump_string(var
.c_str(), buf
);
562 } else if (command
== "config help") {
564 if (cmd_getval(this, cmdmap
, "var", var
)) {
565 // Output a single one
566 std::string key
= ConfFile::normalize_key_name(var
);
567 auto schema
= _conf
.get_schema(key
);
569 std::ostringstream msg
;
570 msg
<< "Setting not found: '" << key
<< "'";
571 f
->dump_string("error", msg
.str());
573 f
->dump_object("option", *schema
);
577 f
->open_array_section("options");
578 for (const auto &option
: ceph_options
) {
579 f
->dump_object("option", option
);
583 } else if (command
== "config diff") {
584 f
->open_object_section("diff");
586 f
->close_section(); // unknown
587 } else if (command
== "config diff get") {
589 f
->open_object_section("diff");
590 _conf
.diff(f
, setting
);
591 f
->close_section(); // unknown
592 } else if (command
== "log flush") {
595 else if (command
== "log dump") {
598 else if (command
== "log reopen") {
599 _log
->reopen_log_file();
602 ceph_abort_msg("registered under wrong command?");
608 lgeneric_dout(this, 1) << "do_command '" << command
<< "' '" << ss
.str()
609 << "result is " << out
->length() << " bytes" << dendl
;
612 CephContext::CephContext(uint32_t module_type_
,
613 enum code_environment_t code_env
,
616 _conf
{code_env
== CODE_ENVIRONMENT_DAEMON
},
618 _module_type(module_type_
),
619 _init_flags(init_flags_
),
625 _service_thread(NULL
),
628 _perf_counters_collection(NULL
),
629 _perf_counters_conf_obs(NULL
),
630 _heartbeat_map(NULL
),
633 _plugin_registry(NULL
),
637 _log
= new ceph::logging::Log(&_conf
->subsys
);
639 _log_obs
= new LogObs(_log
);
640 _conf
.add_observer(_log_obs
);
642 _cct_obs
= new CephContextObs(this);
643 _conf
.add_observer(_cct_obs
);
645 _lockdep_obs
= new LockdepObs(this);
646 _conf
.add_observer(_lockdep_obs
);
648 _perf_counters_collection
= new PerfCountersCollection(this);
650 _admin_socket
= new AdminSocket(this);
651 _heartbeat_map
= new HeartbeatMap(this);
653 _plugin_registry
= new PluginRegistry(this);
655 _admin_hook
= new CephContextHook(this);
656 _admin_socket
->register_command("assert", "assert", _admin_hook
, "");
657 _admin_socket
->register_command("abort", "abort", _admin_hook
, "");
658 _admin_socket
->register_command("perfcounters_dump", "perfcounters_dump", _admin_hook
, "");
659 _admin_socket
->register_command("1", "1", _admin_hook
, "");
660 _admin_socket
->register_command("perf dump", "perf dump name=logger,type=CephString,req=false name=counter,type=CephString,req=false", _admin_hook
, "dump perfcounters value");
661 _admin_socket
->register_command("perfcounters_schema", "perfcounters_schema", _admin_hook
, "");
662 _admin_socket
->register_command("perf histogram dump", "perf histogram dump name=logger,type=CephString,req=false name=counter,type=CephString,req=false", _admin_hook
, "dump perf histogram values");
663 _admin_socket
->register_command("2", "2", _admin_hook
, "");
664 _admin_socket
->register_command("perf schema", "perf schema", _admin_hook
, "dump perfcounters schema");
665 _admin_socket
->register_command("perf histogram schema", "perf histogram schema", _admin_hook
, "dump perf histogram schema");
666 _admin_socket
->register_command("perf reset", "perf reset name=var,type=CephString", _admin_hook
, "perf reset <name>: perf reset all or one perfcounter name");
667 _admin_socket
->register_command("config show", "config show", _admin_hook
, "dump current config settings");
668 _admin_socket
->register_command("config help", "config help name=var,type=CephString,req=false", _admin_hook
, "get config setting schema and descriptions");
669 _admin_socket
->register_command("config set", "config set name=var,type=CephString name=val,type=CephString,n=N", _admin_hook
, "config set <field> <val> [<val> ...]: set a config variable");
670 _admin_socket
->register_command("config unset", "config unset name=var,type=CephString", _admin_hook
, "config unset <field>: unset a config variable");
671 _admin_socket
->register_command("config get", "config get name=var,type=CephString", _admin_hook
, "config get <field>: get the config value");
672 _admin_socket
->register_command("config diff",
673 "config diff", _admin_hook
,
674 "dump diff of current config and default config");
675 _admin_socket
->register_command("config diff get",
676 "config diff get name=var,type=CephString", _admin_hook
,
677 "dump diff get <field>: dump diff of current and default config setting <field>");
678 _admin_socket
->register_command("log flush", "log flush", _admin_hook
, "flush log entries to log file");
679 _admin_socket
->register_command("log dump", "log dump", _admin_hook
, "dump recent log entries to log file");
680 _admin_socket
->register_command("log reopen", "log reopen", _admin_hook
, "reopen log file");
682 _crypto_none
= CryptoHandler::create(CEPH_CRYPTO_NONE
);
683 _crypto_aes
= CryptoHandler::create(CEPH_CRYPTO_AES
);
684 _crypto_random
.reset(new CryptoRandom());
686 lookup_or_create_singleton_object
<MempoolObs
>("mempool_obs", false, this);
689 CephContext::~CephContext()
691 associated_objs
.clear();
692 join_service_thread();
695 _perf_counters_collection
->remove(_cct_perf
);
700 delete _plugin_registry
;
702 _admin_socket
->unregister_commands(_admin_hook
);
704 delete _admin_socket
;
706 delete _heartbeat_map
;
708 delete _perf_counters_collection
;
709 _perf_counters_collection
= NULL
;
711 delete _perf_counters_conf_obs
;
712 _perf_counters_conf_obs
= NULL
;
714 _conf
.remove_observer(_log_obs
);
718 _conf
.remove_observer(_cct_obs
);
722 _conf
.remove_observer(_lockdep_obs
);
732 if (_crypto_inited
> 0) {
733 ceph_assert(_crypto_inited
== 1); // or else someone explicitly did
734 // init but not shutdown
739 void CephContext::put() {
741 ANNOTATE_HAPPENS_AFTER(&nref
);
742 ANNOTATE_HAPPENS_BEFORE_FORGET_ALL(&nref
);
745 ANNOTATE_HAPPENS_BEFORE(&nref
);
749 void CephContext::init_crypto()
751 if (_crypto_inited
++ == 0) {
752 ceph::crypto::init(this);
756 void CephContext::shutdown_crypto()
758 if (--_crypto_inited
== 0) {
759 ceph::crypto::shutdown(g_code_env
== CODE_ENVIRONMENT_LIBRARY
);
763 void CephContext::start_service_thread()
766 std::lock_guard
lg(_service_thread_lock
);
767 if (_service_thread
) {
770 _service_thread
= new CephContextServiceThread(this);
771 _service_thread
->create("service");
774 if (!(get_init_flags() & CINIT_FLAG_NO_CCT_PERF_COUNTERS
))
775 _enable_perf_counter();
777 // make logs flush on_exit()
778 if (_conf
->log_flush_on_exit
)
779 _log
->set_flush_on_exit();
781 // Trigger callbacks on any config observers that were waiting for
782 // it to become safe to start threads.
783 _conf
.set_safe_to_start_threads();
784 _conf
.call_all_observers();
786 // start admin socket
787 if (_conf
->admin_socket
.length())
788 _admin_socket
->init(_conf
->admin_socket
);
791 void CephContext::reopen_logs()
793 std::lock_guard
lg(_service_thread_lock
);
795 _service_thread
->reopen_logs();
798 void CephContext::join_service_thread()
800 std::unique_lock
<ceph::spinlock
> lg(_service_thread_lock
);
802 CephContextServiceThread
*thread
= _service_thread
;
806 _service_thread
= NULL
;
810 thread
->exit_thread();
814 if (!(get_init_flags() & CINIT_FLAG_NO_CCT_PERF_COUNTERS
))
815 _disable_perf_counter();
818 uint32_t CephContext::get_module_type() const
823 void CephContext::set_init_flags(int flags
)
828 int CephContext::get_init_flags() const
833 PerfCountersCollection
*CephContext::get_perfcounters_collection()
835 return _perf_counters_collection
;
838 void CephContext::_enable_perf_counter()
841 PerfCountersBuilder
plb(this, "cct", l_cct_first
, l_cct_last
);
842 plb
.add_u64(l_cct_total_workers
, "total_workers", "Total workers");
843 plb
.add_u64(l_cct_unhealthy_workers
, "unhealthy_workers", "Unhealthy workers");
844 _cct_perf
= plb
.create_perf_counters();
845 _perf_counters_collection
->add(_cct_perf
);
847 assert(_mempool_perf_names
.empty());
848 assert(_mempool_perf_descriptions
.empty());
849 _mempool_perf_names
.reserve(mempool::num_pools
* 2);
850 _mempool_perf_descriptions
.reserve(mempool::num_pools
* 2);
851 for (unsigned i
= 0; i
< mempool::num_pools
; ++i
) {
852 string n
= mempool::get_pool_name(mempool::pool_index_t(i
));
853 _mempool_perf_names
.push_back(n
+ "_bytes");
854 _mempool_perf_descriptions
.push_back(
855 string("mempool ") + n
+ " total bytes");
856 _mempool_perf_names
.push_back(n
+ "_items");
857 _mempool_perf_descriptions
.push_back(
858 string("mempool ") + n
+ " total items");
861 PerfCountersBuilder
plb2(this, "mempool", l_mempool_first
,
862 l_mempool_first
+ 1 + 2*mempool::num_pools
);
863 unsigned l
= l_mempool_first
+ 1;
864 for (unsigned i
= 0; i
< mempool::num_pools
; ++i
) {
865 plb2
.add_u64(l
++, _mempool_perf_names
[i
*2].c_str(),
866 _mempool_perf_descriptions
[i
*2].c_str());
867 plb2
.add_u64(l
++, _mempool_perf_names
[i
*2+1].c_str(),
868 _mempool_perf_descriptions
[i
*2+1].c_str());
870 _mempool_perf
= plb2
.create_perf_counters();
871 _perf_counters_collection
->add(_mempool_perf
);
874 void CephContext::_disable_perf_counter()
879 _perf_counters_collection
->remove(_cct_perf
);
883 _perf_counters_collection
->remove(_mempool_perf
);
884 delete _mempool_perf
;
885 _mempool_perf
= nullptr;
886 _mempool_perf_names
.clear();
887 _mempool_perf_descriptions
.clear();
890 void CephContext::_refresh_perf_values()
893 _cct_perf
->set(l_cct_total_workers
, _heartbeat_map
->get_total_workers());
894 _cct_perf
->set(l_cct_unhealthy_workers
, _heartbeat_map
->get_unhealthy_workers());
896 unsigned l
= l_mempool_first
+ 1;
897 for (unsigned i
= 0; i
< mempool::num_pools
; ++i
) {
898 mempool::pool_t
& p
= mempool::get_pool(mempool::pool_index_t(i
));
899 _mempool_perf
->set(l
++, p
.allocated_bytes());
900 _mempool_perf
->set(l
++, p
.allocated_items());
904 AdminSocket
*CephContext::get_admin_socket()
906 return _admin_socket
;
909 CryptoHandler
*CephContext::get_crypto_handler(int type
)
912 case CEPH_CRYPTO_NONE
:
914 case CEPH_CRYPTO_AES
:
921 void CephContext::notify_pre_fork()
924 std::lock_guard
lg(_fork_watchers_lock
);
925 for (auto &&t
: _fork_watchers
) {
926 t
->handle_pre_fork();
930 // note: we don't hold a lock here, but we assume we are idle at
931 // fork time, which happens during process init and startup.
932 auto i
= associated_objs
.begin();
933 while (i
!= associated_objs
.end()) {
934 if (associated_objs_drop_on_fork
.count(i
->first
.first
)) {
935 i
= associated_objs
.erase(i
);
940 associated_objs_drop_on_fork
.clear();
944 void CephContext::notify_post_fork()
946 ceph::spin_unlock(&_fork_watchers_lock
);
947 for (auto &&t
: _fork_watchers
)
948 t
->handle_post_fork();
950 #endif // WITH_SEASTAR