]> git.proxmox.com Git - ceph.git/blob - ceph/src/common/common_init.cc
update sources to v12.2.3
[ceph.git] / ceph / src / common / common_init.cc
1 // -*- mode:C++; tab-width:8; c-basic-offset:2; indent-tabs-mode:t -*-
2 // vim: ts=8 sw=2 smarttab
3 /*
4 * Ceph - scalable distributed file system
5 *
6 * Copyright (C) 2010-2011 Dreamhost
7 *
8 * This is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU Lesser General Public
10 * License version 2.1, as published by the Free Software
11 * Foundation. See file COPYING.
12 *
13 */
14
15 #include "common/admin_socket.h"
16 #include "common/ceph_argparse.h"
17 #include "common/common_init.h"
18 #include "common/valgrind.h"
19 #include "common/zipkin_trace.h"
20
21 #define dout_subsys ceph_subsys_
22
23 #define _STR(x) #x
24 #define STRINGIFY(x) _STR(x)
25
26 CephContext *common_preinit(const CephInitParameters &iparams,
27 enum code_environment_t code_env, int flags)
28 {
29 // set code environment
30 ANNOTATE_BENIGN_RACE_SIZED(&g_code_env, sizeof(g_code_env), "g_code_env");
31 g_code_env = code_env;
32
33 // Create a configuration object
34 CephContext *cct = new CephContext(iparams.module_type, code_env, flags);
35
36 md_config_t *conf = cct->_conf;
37 // add config observers here
38
39 // Set up our entity name.
40 conf->name = iparams.name;
41
42 // different default keyring locations for osd and mds. this is
43 // for backward compatibility. moving forward, we want all keyrings
44 // in these locations. the mon already forces $mon_data/keyring.
45 if (conf->name.is_mds()) {
46 conf->set_val("keyring", "$mds_data/keyring", false);
47 } else if (conf->name.is_osd()) {
48 conf->set_val("keyring", "$osd_data/keyring", false);
49 }
50
51 if (code_env == CODE_ENVIRONMENT_LIBRARY ||
52 code_env == CODE_ENVIRONMENT_UTILITY_NODOUT) {
53 conf->set_val_or_die("log_to_stderr", "false");
54 conf->set_val_or_die("err_to_stderr", "false");
55 conf->set_val_or_die("log_flush_on_exit", "false");
56 }
57 if (code_env != CODE_ENVIRONMENT_DAEMON) {
58 // NOTE: disable ms subsystem gathering in clients by default
59 conf->set_val_or_die("debug_ms", "0/0");
60 }
61
62 return cct;
63 }
64
65 void complain_about_parse_errors(CephContext *cct,
66 std::deque<std::string> *parse_errors)
67 {
68 if (parse_errors->empty())
69 return;
70 lderr(cct) << "Errors while parsing config file!" << dendl;
71 int cur_err = 0;
72 static const int MAX_PARSE_ERRORS = 20;
73 for (std::deque<std::string>::const_iterator p = parse_errors->begin();
74 p != parse_errors->end(); ++p)
75 {
76 lderr(cct) << *p << dendl;
77 if (cur_err == MAX_PARSE_ERRORS) {
78 lderr(cct) << "Suppressed " << (parse_errors->size() - MAX_PARSE_ERRORS)
79 << " more errors." << dendl;
80 break;
81 }
82 ++cur_err;
83 }
84 }
85
86 /* Please be sure that this can safely be called multiple times by the
87 * same application. */
88 void common_init_finish(CephContext *cct)
89 {
90 cct->init_crypto();
91 ZTracer::ztrace_init();
92
93 int flags = cct->get_init_flags();
94 if (!(flags & CINIT_FLAG_NO_DAEMON_ACTIONS))
95 cct->start_service_thread();
96
97 if ((flags & CINIT_FLAG_DEFER_DROP_PRIVILEGES) &&
98 (cct->get_set_uid() || cct->get_set_gid())) {
99 cct->get_admin_socket()->chown(cct->get_set_uid(), cct->get_set_gid());
100 }
101
102 md_config_t *conf = cct->_conf;
103
104 if (!conf->admin_socket.empty() && !conf->admin_socket_mode.empty()) {
105 int ret = 0;
106 std::string err;
107
108 ret = strict_strtol(conf->admin_socket_mode.c_str(), 8, &err);
109 if (err.empty()) {
110 if (!(ret & (~ACCESSPERMS))) {
111 cct->get_admin_socket()->chmod(static_cast<mode_t>(ret));
112 } else {
113 lderr(cct) << "Invalid octal permissions string: "
114 << conf->admin_socket_mode << dendl;
115 }
116 } else {
117 lderr(cct) << "Invalid octal string: " << err << dendl;
118 }
119 }
120 }