]> git.proxmox.com Git - ceph.git/blame - ceph/src/common/common_init.cc
update sources to ceph Nautilus 14.2.1
[ceph.git] / ceph / src / common / common_init.cc
CommitLineData
7c673cae
FG
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
11fdf7f2
TL
15#include "include/compat.h"
16#include "common/common_init.h"
7c673cae
FG
17#include "common/admin_socket.h"
18#include "common/ceph_argparse.h"
11fdf7f2
TL
19#include "common/ceph_context.h"
20#include "common/config.h"
21#include "common/dout.h"
22#include "common/strtol.h"
7c673cae 23#include "common/valgrind.h"
7c673cae 24#include "common/zipkin_trace.h"
7c673cae
FG
25
26#define dout_subsys ceph_subsys_
27
28#define _STR(x) #x
29#define STRINGIFY(x) _STR(x)
30
11fdf7f2 31#ifndef WITH_SEASTAR
7c673cae 32CephContext *common_preinit(const CephInitParameters &iparams,
b32b8144 33 enum code_environment_t code_env, int flags)
7c673cae
FG
34{
35 // set code environment
36 ANNOTATE_BENIGN_RACE_SIZED(&g_code_env, sizeof(g_code_env), "g_code_env");
37 g_code_env = code_env;
38
39 // Create a configuration object
c07f9fc5 40 CephContext *cct = new CephContext(iparams.module_type, code_env, flags);
7c673cae 41
11fdf7f2 42 auto& conf = cct->_conf;
7c673cae
FG
43 // add config observers here
44
45 // Set up our entity name.
46 conf->name = iparams.name;
47
c07f9fc5
FG
48 // different default keyring locations for osd and mds. this is
49 // for backward compatibility. moving forward, we want all keyrings
50 // in these locations. the mon already forces $mon_data/keyring.
51 if (conf->name.is_mds()) {
11fdf7f2 52 conf.set_val_default("keyring", "$mds_data/keyring");
c07f9fc5 53 } else if (conf->name.is_osd()) {
11fdf7f2
TL
54 conf.set_val_default("keyring", "$osd_data/keyring");
55 }
56
57 if ((flags & CINIT_FLAG_UNPRIVILEGED_DAEMON_DEFAULTS)) {
58 // make this unique despite multiple instances by the same name.
59 conf.set_val_default("admin_socket",
60 "$run_dir/$cluster-$name.$pid.$cctid.asok");
c07f9fc5 61 }
7c673cae 62
c07f9fc5
FG
63 if (code_env == CODE_ENVIRONMENT_LIBRARY ||
64 code_env == CODE_ENVIRONMENT_UTILITY_NODOUT) {
11fdf7f2
TL
65 conf.set_val_default("log_to_stderr", "false");
66 conf.set_val_default("err_to_stderr", "false");
67 conf.set_val_default("log_flush_on_exit", "false");
3efd9988 68 }
7c673cae
FG
69
70 return cct;
71}
11fdf7f2 72#endif // #ifndef WITH_SEASTAR
7c673cae
FG
73
74void complain_about_parse_errors(CephContext *cct,
75 std::deque<std::string> *parse_errors)
76{
77 if (parse_errors->empty())
78 return;
79 lderr(cct) << "Errors while parsing config file!" << dendl;
80 int cur_err = 0;
81 static const int MAX_PARSE_ERRORS = 20;
82 for (std::deque<std::string>::const_iterator p = parse_errors->begin();
83 p != parse_errors->end(); ++p)
84 {
85 lderr(cct) << *p << dendl;
86 if (cur_err == MAX_PARSE_ERRORS) {
87 lderr(cct) << "Suppressed " << (parse_errors->size() - MAX_PARSE_ERRORS)
88 << " more errors." << dendl;
89 break;
90 }
91 ++cur_err;
92 }
93}
94
11fdf7f2
TL
95#ifndef WITH_SEASTAR
96
7c673cae
FG
97/* Please be sure that this can safely be called multiple times by the
98 * same application. */
99void common_init_finish(CephContext *cct)
100{
11fdf7f2
TL
101 // only do this once per cct
102 if (cct->_finished) {
103 return;
104 }
105 cct->_finished = true;
7c673cae
FG
106 cct->init_crypto();
107 ZTracer::ztrace_init();
108
11fdf7f2
TL
109 if (!cct->_log->is_started()) {
110 cct->_log->start();
111 }
112
7c673cae
FG
113 int flags = cct->get_init_flags();
114 if (!(flags & CINIT_FLAG_NO_DAEMON_ACTIONS))
115 cct->start_service_thread();
116
117 if ((flags & CINIT_FLAG_DEFER_DROP_PRIVILEGES) &&
118 (cct->get_set_uid() || cct->get_set_gid())) {
119 cct->get_admin_socket()->chown(cct->get_set_uid(), cct->get_set_gid());
120 }
121
11fdf7f2 122 const auto& conf = cct->_conf;
7c673cae
FG
123
124 if (!conf->admin_socket.empty() && !conf->admin_socket_mode.empty()) {
125 int ret = 0;
126 std::string err;
127
128 ret = strict_strtol(conf->admin_socket_mode.c_str(), 8, &err);
129 if (err.empty()) {
130 if (!(ret & (~ACCESSPERMS))) {
131 cct->get_admin_socket()->chmod(static_cast<mode_t>(ret));
132 } else {
133 lderr(cct) << "Invalid octal permissions string: "
134 << conf->admin_socket_mode << dendl;
135 }
136 } else {
137 lderr(cct) << "Invalid octal string: " << err << dendl;
138 }
139 }
140}
11fdf7f2
TL
141
142#endif // #ifndef WITH_SEASTAR