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/common_fwd.h"
26 #include "include/mempool.h"
27 #include "include/stringify.h"
28 #include "common/admin_socket.h"
29 #include "common/code_environment.h"
30 #include "common/ceph_mutex.h"
31 #include "common/debug.h"
32 #include "common/config.h"
33 #include "common/ceph_crypto.h"
34 #include "common/hostname.h"
35 #include "common/HeartbeatMap.h"
36 #include "common/errno.h"
37 #include "common/Graylog.h"
38 #ifdef CEPH_DEBUG_MUTEX
39 #include "common/lockdep.h"
44 #include "auth/Crypto.h"
45 #include "include/str_list.h"
46 #include "common/config.h"
47 #include "common/config_obs.h"
48 #include "common/PluginRegistry.h"
49 #include "common/valgrind.h"
50 #include "include/spinlock.h"
51 #if !(defined(WITH_SEASTAR) && !defined(WITH_ALIEN))
52 #include "mon/MonMap.h"
56 #include "common/common_init.h"
61 using namespace std::literals
;
63 using ceph::bufferlist
;
64 using ceph::HeartbeatMap
;
67 #if defined(WITH_SEASTAR) && !defined(WITH_ALIEN)
68 namespace crimson::common
{
69 CephContext::CephContext()
70 : _conf
{crimson::common::local_conf()},
71 _perf_counters_collection
{crimson::common::local_perf_coll()},
72 _crypto_random
{std::make_unique
<CryptoRandom
>()}
75 // define the dtor in .cc as CryptoRandom is an incomplete type in the header
76 CephContext::~CephContext()
79 uint32_t CephContext::get_module_type() const
81 return CEPH_ENTITY_TYPE_OSD
;
84 CryptoRandom
* CephContext::random() const
86 return _crypto_random
.get();
89 CephContext
* CephContext::get()
95 void CephContext::put()
102 PerfCountersCollectionImpl
* CephContext::get_perfcounters_collection()
104 return _perf_counters_collection
.get_perf_collection();
108 #else // WITH_SEASTAR
111 #ifdef CEPH_DEBUG_MUTEX
112 class LockdepObs
: public md_config_obs_t
{
114 explicit LockdepObs(CephContext
*cct
)
115 : m_cct(cct
), m_registered(false), lock(ceph::make_mutex("lock_dep_obs")) {
117 ~LockdepObs() override
{
119 lockdep_unregister_ceph_context(m_cct
);
123 const char** get_tracked_conf_keys() const override
{
124 static const char *KEYS
[] = {"lockdep", NULL
};
128 void handle_conf_change(const ConfigProxy
& conf
,
129 const std::set
<std::string
> &changed
) override
{
130 std::unique_lock
locker(lock
);
131 if (conf
->lockdep
&& !m_registered
) {
132 lockdep_register_ceph_context(m_cct
);
134 } else if (!conf
->lockdep
&& m_registered
) {
135 lockdep_unregister_ceph_context(m_cct
);
136 m_registered
= false;
144 #endif // CEPH_DEBUG_MUTEX
146 class MempoolObs
: public md_config_obs_t
,
147 public AdminSocketHook
{
152 explicit MempoolObs(CephContext
*cct
)
153 : cct(cct
), lock(ceph::make_mutex("mem_pool_obs")) {
154 cct
->_conf
.add_observer(this);
155 int r
= cct
->get_admin_socket()->register_command(
158 "get mempool stats");
161 ~MempoolObs() override
{
162 cct
->_conf
.remove_observer(this);
163 cct
->get_admin_socket()->unregister_commands(this);
167 const char** get_tracked_conf_keys() const override
{
168 static const char *KEYS
[] = {
175 void handle_conf_change(const ConfigProxy
& conf
,
176 const std::set
<std::string
> &changed
) override
{
177 std::unique_lock
locker(lock
);
178 if (changed
.count("mempool_debug")) {
179 mempool::set_debug_mode(cct
->_conf
->mempool_debug
);
184 int call(std::string_view command
, const cmdmap_t
& cmdmap
,
185 const bufferlist
& inbl
,
188 bufferlist
& out
) override
{
189 if (command
== "dump_mempools") {
190 f
->open_object_section("mempools");
199 } // anonymous namespace
201 namespace ceph::common
{
202 class CephContextServiceThread
: public Thread
205 explicit CephContextServiceThread(CephContext
*cct
)
206 : _reopen_logs(false), _exit_thread(false), _cct(cct
)
210 ~CephContextServiceThread() override
{}
212 void *entry() override
215 std::unique_lock
l(_lock
);
220 if (_cct
->_conf
->heartbeat_interval
) {
221 auto interval
= ceph::make_timespan(_cct
->_conf
->heartbeat_interval
);
222 _cond
.wait_for(l
, interval
);
231 _cct
->_log
->reopen_log_file();
232 _reopen_logs
= false;
234 _cct
->_heartbeat_map
->check_touch_file();
236 // refresh the perf coutners
237 _cct
->_refresh_perf_values();
244 std::lock_guard
l(_lock
);
251 std::lock_guard
l(_lock
);
257 ceph::mutex _lock
= ceph::make_mutex("CephContextServiceThread::_lock");
258 ceph::condition_variable _cond
;
266 * observe logging config changes
268 * The logging subsystem sits below most of the ceph code, including
269 * the config subsystem, to keep it simple and self-contained. Feed
270 * logging-related config changes to the log.
272 class LogObs
: public md_config_obs_t
{
273 ceph::logging::Log
*log
;
277 explicit LogObs(ceph::logging::Log
*l
)
278 : log(l
), lock(ceph::make_mutex("log_obs")) {
281 const char** get_tracked_conf_keys() const override
{
282 static const char *KEYS
[] = {
298 "log_coarse_timestamps",
306 void handle_conf_change(const ConfigProxy
& conf
,
307 const std::set
<std::string
> &changed
) override
{
308 std::unique_lock
locker(lock
);
310 if (changed
.count("log_to_stderr") || changed
.count("err_to_stderr")) {
311 int l
= conf
->log_to_stderr
? 99 : (conf
->err_to_stderr
? -1 : -2);
312 log
->set_stderr_level(l
, l
);
316 if (changed
.count("log_to_syslog")) {
317 int l
= conf
->log_to_syslog
? 99 : (conf
->err_to_syslog
? -1 : -2);
318 log
->set_syslog_level(l
, l
);
322 if (changed
.count("log_file") ||
323 changed
.count("log_to_file")) {
324 if (conf
->log_to_file
) {
325 log
->set_log_file(conf
->log_file
);
327 log
->set_log_file({});
329 log
->reopen_log_file();
332 if (changed
.count("log_stderr_prefix")) {
333 log
->set_log_stderr_prefix(conf
.get_val
<std::string
>("log_stderr_prefix"));
336 if (changed
.count("log_max_new")) {
338 log
->set_max_new(conf
->log_max_new
);
341 if (changed
.count("log_max_recent")) {
342 log
->set_max_recent(conf
->log_max_recent
);
346 if (changed
.count("log_to_graylog") || changed
.count("err_to_graylog")) {
347 int l
= conf
->log_to_graylog
? 99 : (conf
->err_to_graylog
? -1 : -2);
348 log
->set_graylog_level(l
, l
);
350 if (conf
->log_to_graylog
|| conf
->err_to_graylog
) {
351 log
->start_graylog(conf
->host
, conf
.get_val
<uuid_d
>("fsid"));
352 } else if (! (conf
->log_to_graylog
&& conf
->err_to_graylog
)) {
357 if (log
->graylog() && (changed
.count("log_graylog_host") || changed
.count("log_graylog_port"))) {
358 log
->graylog()->set_destination(conf
->log_graylog_host
, conf
->log_graylog_port
);
362 if (changed
.count("log_to_journald") || changed
.count("err_to_journald")) {
363 int l
= conf
.get_val
<bool>("log_to_journald") ? 99 : (conf
.get_val
<bool>("err_to_journald") ? -1 : -2);
364 log
->set_journald_level(l
, l
);
367 log
->start_journald_logger();
369 log
->stop_journald_logger();
373 if (changed
.find("log_coarse_timestamps") != changed
.end()) {
374 log
->set_coarse_timestamps(conf
.get_val
<bool>("log_coarse_timestamps"));
378 if (log
->graylog() && changed
.count("host")) {
379 log
->graylog()->set_hostname(conf
->host
);
382 if (log
->graylog() && changed
.count("fsid")) {
383 log
->graylog()->set_fsid(conf
.get_val
<uuid_d
>("fsid"));
389 namespace ceph::common
{
390 // cct config watcher
391 class CephContextObs
: public md_config_obs_t
{
395 explicit CephContextObs(CephContext
*cct
) : cct(cct
) {}
397 const char** get_tracked_conf_keys() const override
{
398 static const char *KEYS
[] = {
399 "enable_experimental_unrecoverable_data_corrupting_features",
401 "container_image", // just so we don't hear complaints about it!
407 void handle_conf_change(const ConfigProxy
& conf
,
408 const std::set
<std::string
> &changed
) override
{
410 "enable_experimental_unrecoverable_data_corrupting_features")) {
411 std::lock_guard
lg(cct
->_feature_lock
);
413 cct
->_experimental_features
.clear();
414 auto add_experimental_feature
= [this] (auto feature
) {
415 cct
->_experimental_features
.emplace(std::string
{feature
});
417 for_each_substr(conf
->enable_experimental_unrecoverable_data_corrupting_features
,
418 ";,= \t", add_experimental_feature
);
420 if (getenv("CEPH_DEV") == NULL
) {
421 if (!cct
->_experimental_features
.empty()) {
422 if (cct
->_experimental_features
.count("*")) {
423 lderr(cct
) << "WARNING: all dangerous and experimental features are enabled." << dendl
;
425 lderr(cct
) << "WARNING: the following dangerous and experimental features are enabled: "
426 << cct
->_experimental_features
<< dendl
;
432 if (changed
.count("crush_location")) {
433 cct
->crush_location
.update_from_conf();
439 class CephContextHook
: public AdminSocketHook
{
443 explicit CephContextHook(CephContext
*cct
) : m_cct(cct
) {}
445 int call(std::string_view command
, const cmdmap_t
& cmdmap
,
446 const bufferlist
& inbl
,
449 bufferlist
& out
) override
{
451 return m_cct
->do_command(command
, cmdmap
, f
, errss
, &out
);
452 } catch (const bad_cmd_get
& e
) {
459 bool CephContext::check_experimental_feature_enabled(const std::string
& feat
)
461 std::stringstream message
;
462 bool enabled
= check_experimental_feature_enabled(feat
, &message
);
463 lderr(this) << message
.str() << dendl
;
467 bool CephContext::check_experimental_feature_enabled(const std::string
& feat
,
468 std::ostream
*message
)
470 std::unique_lock
<ceph::spinlock
> lg(_feature_lock
);
472 bool enabled
= (_experimental_features
.count(feat
) ||
473 _experimental_features
.count("*"));
476 (*message
) << "WARNING: experimental feature '" << feat
<< "' is enabled\n";
477 (*message
) << "Please be aware that this feature is experimental, untested,\n";
478 (*message
) << "unsupported, and may result in data corruption, data loss,\n";
479 (*message
) << "and/or irreparable damage to your cluster. Do not use\n";
480 (*message
) << "feature with important data.\n";
482 (*message
) << "*** experimental feature '" << feat
<< "' is not enabled ***\n";
483 (*message
) << "This feature is marked as experimental, which means it\n";
484 (*message
) << " - is untested\n";
485 (*message
) << " - is unsupported\n";
486 (*message
) << " - may corrupt your data\n";
487 (*message
) << " - may break your cluster is an unrecoverable fashion\n";
488 (*message
) << "To enable this feature, add this to your ceph.conf:\n";
489 (*message
) << " enable experimental unrecoverable data corrupting features = " << feat
<< "\n";
494 int CephContext::do_command(std::string_view command
, const cmdmap_t
& cmdmap
,
500 return _do_command(command
, cmdmap
, f
, ss
, out
);
501 } catch (const bad_cmd_get
& e
) {
507 #pragma GCC push_options
508 #pragma GCC optimize ("O0")
509 static void leak_some_memory() {
510 volatile char *foo
= new char[1234];
513 #pragma GCC pop_options
515 int CephContext::_do_command(
516 std::string_view command
, const cmdmap_t
& cmdmap
,
522 lgeneric_dout(this, 1) << "do_command '" << command
<< "' '" << cmdmap
<< "'"
524 ceph_assert_always(!(command
== "assert" && _conf
->debug_asok_assert_abort
));
525 if (command
== "abort") {
526 if (_conf
->debug_asok_assert_abort
) {
532 if (command
== "leak_some_memory") {
535 else if (command
== "perfcounters_dump" || command
== "1" ||
536 command
== "perf dump") {
539 cmd_getval(cmdmap
, "logger", logger
);
540 cmd_getval(cmdmap
, "counter", counter
);
541 _perf_counters_collection
->dump_formatted(f
, false, logger
, counter
);
543 else if (command
== "perfcounters_schema" || command
== "2" ||
544 command
== "perf schema") {
545 _perf_counters_collection
->dump_formatted(f
, true);
547 else if (command
== "perf histogram dump") {
550 cmd_getval(cmdmap
, "logger", logger
);
551 cmd_getval(cmdmap
, "counter", counter
);
552 _perf_counters_collection
->dump_formatted_histograms(f
, false, logger
,
555 else if (command
== "perf histogram schema") {
556 _perf_counters_collection
->dump_formatted_histograms(f
, true);
558 else if (command
== "perf reset") {
560 std::string
section(command
);
561 f
->open_object_section(section
.c_str());
562 if (!cmd_getval(cmdmap
, "var", var
)) {
563 f
->dump_string("error", "syntax error: 'perf reset <var>'");
565 if(!_perf_counters_collection
->reset(var
))
566 f
->dump_stream("error") << "Not find: " << var
;
568 f
->dump_string("success", std::string(command
) + ' ' + var
);
573 std::string
section(command
);
574 boost::replace_all(section
, " ", "_");
575 f
->open_object_section(section
.c_str());
576 if (command
== "config show") {
577 _conf
.show_config(f
);
579 else if (command
== "config unset") {
581 if (!(cmd_getval(cmdmap
, "var", var
))) {
584 r
= _conf
.rm_val(var
.c_str());
585 if (r
< 0 && r
!= -ENOENT
) {
586 ss
<< "error unsetting '" << var
<< "': "
589 _conf
.apply_changes(&ss
);
595 else if (command
== "config set") {
597 std::vector
<std::string
> val
;
599 if (!(cmd_getval(cmdmap
, "var", var
)) ||
600 !(cmd_getval(cmdmap
, "val", val
))) {
603 // val may be multiple words
604 auto valstr
= str_join(val
, " ");
605 r
= _conf
.set_val(var
.c_str(), valstr
.c_str());
607 ss
<< "error setting '" << var
<< "' to '" << valstr
<< "': "
610 std::stringstream ss
;
611 _conf
.apply_changes(&ss
);
612 f
->dump_string("success", ss
.str());
615 } else if (command
== "config get") {
617 if (!cmd_getval(cmdmap
, "var", var
)) {
621 // FIPS zeroization audit 20191115: this memset is not security related.
622 memset(buf
, 0, sizeof(buf
));
624 r
= _conf
.get_val(var
.c_str(), &tmp
, sizeof(buf
));
626 ss
<< "error getting '" << var
<< "': " << cpp_strerror(r
);
628 f
->dump_string(var
.c_str(), buf
);
631 } else if (command
== "config help") {
633 if (cmd_getval(cmdmap
, "var", var
)) {
634 // Output a single one
635 std::string key
= ConfFile::normalize_key_name(var
);
636 auto schema
= _conf
.get_schema(key
);
638 ss
<< "Setting not found: '" << key
<< "'";
641 f
->dump_object("option", *schema
);
645 f
->open_array_section("options");
646 for (const auto &option
: ceph_options
) {
647 f
->dump_object("option", option
);
651 } else if (command
== "config diff") {
652 f
->open_object_section("diff");
654 f
->close_section(); // unknown
655 } else if (command
== "config diff get") {
657 f
->open_object_section("diff");
658 _conf
.diff(f
, setting
);
659 f
->close_section(); // unknown
661 else if (command
== "injectargs") {
662 std::vector
<std::string
> argsvec
;
663 cmd_getval(cmdmap
, "injected_args", argsvec
);
664 if (!argsvec
.empty()) {
665 auto args
= joinify
<std::string
>(argsvec
.begin(), argsvec
.end(), " ");
666 r
= _conf
.injectargs(args
, &ss
);
669 else if (command
== "log flush") {
672 else if (command
== "log dump") {
675 else if (command
== "log reopen") {
676 _log
->reopen_log_file();
679 ceph_abort_msg("registered under wrong command?");
683 lgeneric_dout(this, 1) << "do_command '" << command
<< "' '" << cmdmap
684 << "' result is " << out
->length() << " bytes" << dendl
;
688 CephContext::CephContext(uint32_t module_type_
,
689 enum code_environment_t code_env
,
692 _conf
{code_env
== CODE_ENVIRONMENT_DAEMON
},
694 _module_type(module_type_
),
695 _init_flags(init_flags_
),
701 _service_thread(NULL
),
704 _perf_counters_collection(NULL
),
705 _perf_counters_conf_obs(NULL
),
706 _heartbeat_map(NULL
),
709 _plugin_registry(NULL
),
710 #ifdef CEPH_DEBUG_MUTEX
715 _log
= new ceph::logging::Log(&_conf
->subsys
);
717 _log_obs
= new LogObs(_log
);
718 _conf
.add_observer(_log_obs
);
720 _cct_obs
= new CephContextObs(this);
721 _conf
.add_observer(_cct_obs
);
722 #ifdef CEPH_DEBUG_MUTEX
723 _lockdep_obs
= new LockdepObs(this);
724 _conf
.add_observer(_lockdep_obs
);
726 _perf_counters_collection
= new PerfCountersCollection(this);
728 _admin_socket
= new AdminSocket(this);
729 _heartbeat_map
= new HeartbeatMap(this);
731 _plugin_registry
= new PluginRegistry(this);
733 _admin_hook
= new CephContextHook(this);
734 _admin_socket
->register_command("assert", _admin_hook
, "");
735 _admin_socket
->register_command("abort", _admin_hook
, "");
736 _admin_socket
->register_command("leak_some_memory", _admin_hook
, "");
737 _admin_socket
->register_command("perfcounters_dump", _admin_hook
, "");
738 _admin_socket
->register_command("1", _admin_hook
, "");
739 _admin_socket
->register_command("perf dump name=logger,type=CephString,req=false name=counter,type=CephString,req=false", _admin_hook
, "dump perfcounters value");
740 _admin_socket
->register_command("perfcounters_schema", _admin_hook
, "");
741 _admin_socket
->register_command("perf histogram dump name=logger,type=CephString,req=false name=counter,type=CephString,req=false", _admin_hook
, "dump perf histogram values");
742 _admin_socket
->register_command("2", _admin_hook
, "");
743 _admin_socket
->register_command("perf schema", _admin_hook
, "dump perfcounters schema");
744 _admin_socket
->register_command("perf histogram schema", _admin_hook
, "dump perf histogram schema");
745 _admin_socket
->register_command("perf reset name=var,type=CephString", _admin_hook
, "perf reset <name>: perf reset all or one perfcounter name");
746 _admin_socket
->register_command("config show", _admin_hook
, "dump current config settings");
747 _admin_socket
->register_command("config help name=var,type=CephString,req=false", _admin_hook
, "get config setting schema and descriptions");
748 _admin_socket
->register_command("config set name=var,type=CephString name=val,type=CephString,n=N", _admin_hook
, "config set <field> <val> [<val> ...]: set a config variable");
749 _admin_socket
->register_command("config unset name=var,type=CephString", _admin_hook
, "config unset <field>: unset a config variable");
750 _admin_socket
->register_command("config get name=var,type=CephString", _admin_hook
, "config get <field>: get the config value");
751 _admin_socket
->register_command(
752 "config diff", _admin_hook
,
753 "dump diff of current config and default config");
754 _admin_socket
->register_command(
755 "config diff get name=var,type=CephString", _admin_hook
,
756 "dump diff get <field>: dump diff of current and default config setting <field>");
757 _admin_socket
->register_command("injectargs name=injected_args,type=CephString,n=N", _admin_hook
, "inject configuration arguments into running daemon"),
758 _admin_socket
->register_command("log flush", _admin_hook
, "flush log entries to log file");
759 _admin_socket
->register_command("log dump", _admin_hook
, "dump recent log entries to log file");
760 _admin_socket
->register_command("log reopen", _admin_hook
, "reopen log file");
762 _crypto_none
= CryptoHandler::create(CEPH_CRYPTO_NONE
);
763 _crypto_aes
= CryptoHandler::create(CEPH_CRYPTO_AES
);
764 _crypto_random
.reset(new CryptoRandom());
766 lookup_or_create_singleton_object
<MempoolObs
>("mempool_obs", false, this);
769 CephContext::~CephContext()
771 associated_objs
.clear();
772 join_service_thread();
775 _perf_counters_collection
->remove(_cct_perf
);
780 delete _plugin_registry
;
782 _admin_socket
->unregister_commands(_admin_hook
);
784 delete _admin_socket
;
786 delete _heartbeat_map
;
788 delete _perf_counters_collection
;
789 _perf_counters_collection
= NULL
;
791 delete _perf_counters_conf_obs
;
792 _perf_counters_conf_obs
= NULL
;
794 _conf
.remove_observer(_log_obs
);
798 _conf
.remove_observer(_cct_obs
);
801 #ifdef CEPH_DEBUG_MUTEX
802 _conf
.remove_observer(_lockdep_obs
);
812 if (_crypto_inited
> 0) {
813 ceph_assert(_crypto_inited
== 1); // or else someone explicitly did
814 // init but not shutdown
819 void CephContext::put() {
821 ANNOTATE_HAPPENS_AFTER(&nref
);
822 ANNOTATE_HAPPENS_BEFORE_FORGET_ALL(&nref
);
823 if (g_ceph_context
== this)
824 g_ceph_context
= nullptr;
827 ANNOTATE_HAPPENS_BEFORE(&nref
);
831 void CephContext::init_crypto()
833 if (_crypto_inited
++ == 0) {
834 TOPNSPC::crypto::init();
838 void CephContext::shutdown_crypto()
840 if (--_crypto_inited
== 0) {
841 TOPNSPC::crypto::shutdown(g_code_env
== CODE_ENVIRONMENT_LIBRARY
);
845 void CephContext::start_service_thread()
848 std::lock_guard
lg(_service_thread_lock
);
849 if (_service_thread
) {
852 _service_thread
= new CephContextServiceThread(this);
853 _service_thread
->create("service");
856 if (!(get_init_flags() & CINIT_FLAG_NO_CCT_PERF_COUNTERS
))
857 _enable_perf_counter();
859 // make logs flush on_exit()
860 if (_conf
->log_flush_on_exit
)
861 _log
->set_flush_on_exit();
863 // Trigger callbacks on any config observers that were waiting for
864 // it to become safe to start threads.
865 _conf
.set_safe_to_start_threads();
866 _conf
.call_all_observers();
868 // start admin socket
869 if (_conf
->admin_socket
.length())
870 _admin_socket
->init(_conf
->admin_socket
);
873 void CephContext::reopen_logs()
875 std::lock_guard
lg(_service_thread_lock
);
877 _service_thread
->reopen_logs();
880 void CephContext::join_service_thread()
882 std::unique_lock
<ceph::spinlock
> lg(_service_thread_lock
);
884 CephContextServiceThread
*thread
= _service_thread
;
888 _service_thread
= NULL
;
892 thread
->exit_thread();
896 if (!(get_init_flags() & CINIT_FLAG_NO_CCT_PERF_COUNTERS
))
897 _disable_perf_counter();
900 uint32_t CephContext::get_module_type() const
905 void CephContext::set_init_flags(int flags
)
910 int CephContext::get_init_flags() const
915 PerfCountersCollection
*CephContext::get_perfcounters_collection()
917 return _perf_counters_collection
;
920 void CephContext::_enable_perf_counter()
923 PerfCountersBuilder
plb(this, "cct", l_cct_first
, l_cct_last
);
924 plb
.add_u64(l_cct_total_workers
, "total_workers", "Total workers");
925 plb
.add_u64(l_cct_unhealthy_workers
, "unhealthy_workers", "Unhealthy workers");
926 _cct_perf
= plb
.create_perf_counters();
927 _perf_counters_collection
->add(_cct_perf
);
929 assert(_mempool_perf_names
.empty());
930 assert(_mempool_perf_descriptions
.empty());
931 _mempool_perf_names
.reserve(mempool::num_pools
* 2);
932 _mempool_perf_descriptions
.reserve(mempool::num_pools
* 2);
933 for (unsigned i
= 0; i
< mempool::num_pools
; ++i
) {
934 std::string n
= mempool::get_pool_name(mempool::pool_index_t(i
));
935 _mempool_perf_names
.push_back(n
+ "_bytes"s
);
936 _mempool_perf_descriptions
.push_back(
937 "mempool "s
+ n
+ " total bytes");
938 _mempool_perf_names
.push_back(n
+ "_items"s
);
939 _mempool_perf_descriptions
.push_back(
940 "mempool "s
+ n
+ " total items"s
);
943 PerfCountersBuilder
plb2(this, "mempool", l_mempool_first
,
944 l_mempool_first
+ 1 + 2*mempool::num_pools
);
945 unsigned l
= l_mempool_first
+ 1;
946 for (unsigned i
= 0; i
< mempool::num_pools
; ++i
) {
947 plb2
.add_u64(l
++, _mempool_perf_names
[i
*2].c_str(),
948 _mempool_perf_descriptions
[i
*2].c_str());
949 plb2
.add_u64(l
++, _mempool_perf_names
[i
*2+1].c_str(),
950 _mempool_perf_descriptions
[i
*2+1].c_str());
952 _mempool_perf
= plb2
.create_perf_counters();
953 _perf_counters_collection
->add(_mempool_perf
);
956 void CephContext::_disable_perf_counter()
961 _perf_counters_collection
->remove(_cct_perf
);
965 _perf_counters_collection
->remove(_mempool_perf
);
966 delete _mempool_perf
;
967 _mempool_perf
= nullptr;
968 _mempool_perf_names
.clear();
969 _mempool_perf_descriptions
.clear();
972 void CephContext::_refresh_perf_values()
975 _cct_perf
->set(l_cct_total_workers
, _heartbeat_map
->get_total_workers());
976 _cct_perf
->set(l_cct_unhealthy_workers
, _heartbeat_map
->get_unhealthy_workers());
978 unsigned l
= l_mempool_first
+ 1;
979 for (unsigned i
= 0; i
< mempool::num_pools
; ++i
) {
980 mempool::pool_t
& p
= mempool::get_pool(mempool::pool_index_t(i
));
981 _mempool_perf
->set(l
++, p
.allocated_bytes());
982 _mempool_perf
->set(l
++, p
.allocated_items());
986 AdminSocket
*CephContext::get_admin_socket()
988 return _admin_socket
;
991 CryptoHandler
*CephContext::get_crypto_handler(int type
)
994 case CEPH_CRYPTO_NONE
:
996 case CEPH_CRYPTO_AES
:
1003 void CephContext::notify_pre_fork()
1006 std::lock_guard
lg(_fork_watchers_lock
);
1007 for (auto &&t
: _fork_watchers
) {
1008 t
->handle_pre_fork();
1012 // note: we don't hold a lock here, but we assume we are idle at
1013 // fork time, which happens during process init and startup.
1014 auto i
= associated_objs
.begin();
1015 while (i
!= associated_objs
.end()) {
1016 if (associated_objs_drop_on_fork
.count(i
->first
.first
)) {
1017 i
= associated_objs
.erase(i
);
1022 associated_objs_drop_on_fork
.clear();
1026 void CephContext::notify_post_fork()
1028 ceph::spin_unlock(&_fork_watchers_lock
);
1029 for (auto &&t
: _fork_watchers
)
1030 t
->handle_post_fork();
1033 void CephContext::set_mon_addrs(const MonMap
& mm
) {
1034 std::vector
<entity_addrvec_t
> mon_addrs
;
1035 for (auto& i
: mm
.mon_info
) {
1036 mon_addrs
.push_back(i
.second
.public_addrs
);
1039 set_mon_addrs(mon_addrs
);
1042 #endif // WITH_SEASTAR