global_pre_init
预初始化函数,解析ceph.conf配置文件, 初始化定义global_context 和 config的全局变量.
全局预初始化函数
CINIT_FLAG_UNPRIVILEGED_DAEMON_DEFAULTS 默认DAEMON ,相对于下面的选项而言,一般会采用这个.
CINIT_FLAG_NO_DEFAULT_CONFIG_FILE 不去读config_file
CINIT_FLAG_NO_CLOSE_STDERR 不关闭stderr
CINIT_FLAG_NO_DAEMON_ACTIONS :
不生成/var/run/ceph 和 不打印banner .
CINIT_FLAG_DEFER_DROP_PRIVILEGES 设置RGW 使用者.uid gid
启动类型:
#define CEPH_ENTITY_TYPE_MON 0x01 : Monitor
#define CEPH_ENTITY_TYPE_MDS 0x02 : MDS
#define CEPH_ENTITY_TYPE_OSD 0x04 : OSD
#define CEPH_ENTITY_TYPE_CLIENT 0x08 : CLIENT ,RGW网关
#define CEPH_ENTITY_TYPE_AUTH 0x20 : 认证授权类型
#define CEPH_ENTITY_TYPE_ANY 0xFF
CODE_ENVIRONMENT_UTILITY = 0, 工具
CODE_ENVIRONMENT_DAEMON = 1, DAEMON
CODE_ENVIRONMENT_LIBRARY = 2, 库
CODE_ENVIRONMENT_UTILITY_NODOUT = 3, 工具类型没有stderr的输出
在该函数中进行了配置文件的解析,这是ceph的配置解析模块。整体读取配置文件,然后按照行进行解析。
global_init
初始化函数
作用:
初始化启动模式.
if (g_ceph_context->get_init_flags() != flags) {
g_ceph_context->set_init_flags(flags);
}
错误信号集处理器加载。
int siglist[] = { SIGPIPE, 0 };
block_signals(siglist, NULL);
退出时清空log
if (g_conf->log_flush_on_exit)
g_ceph_context->_log->set_flush_on_exit();
如果不是root用户,如果setuser和setgroup配置了,则将其置为””
// consider --setuser root a no-op, even if we're not root
if (getuid() != 0) {
if (g_conf->setuser.length()) {
cerr << "ignoring --setuser " << g_conf->setuser << " since I am not root"
<< std::endl;
g_conf->set_val("setuser", "", false, false);
}
if (g_conf->setgroup.length()) {
cerr << "ignoring --setgroup " << g_conf->setgroup
<< " since I am not root" << std::endl;
g_conf->set_val("setgroup", "", false, false);
}
}
设置run_dir的权限755
if (g_conf->run_dir.length() &&
code_env == CODE_ENVIRONMENT_DAEMON &&
!(flags & CINIT_FLAG_NO_DAEMON_ACTIONS)) {
int r = ::mkdir(g_conf->run_dir.c_str(), 0755);
if (r < 0 && errno != EEXIST) {
r = -errno;
cerr << "warning: unable to create " << g_conf->run_dir << ": " << cpp_strerror(r) << std::endl;
}
}
设置Assert中cct.
register_assert_context(g_ceph_context);
设置用户对run_dir的权限
if ((flags & CINIT_FLAG_DEFER_DROP_PRIVILEGES) &&
(g_ceph_context->get_set_uid() || g_ceph_context->get_set_gid())) {
// Fix ownership on log files and run directories if needed.
// Admin socket files are chown()'d during the common init path _after_
// the service thread has been started. This is sadly a bit of a hack :(
chown_path(g_conf->run_dir,
g_ceph_context->get_set_uid(),
g_ceph_context->get_set_gid(),
g_ceph_context->get_set_uid_string(),
g_ceph_context->get_set_gid_string());
g_ceph_context->_log->chown_log_file(
g_ceph_context->get_set_uid(),
g_ceph_context->get_set_gid());
}
内存泄漏检测
// test leak checking
if (g_conf->debug_deliberately_leak_memory) {
derr << "deliberately leaking some memory" << dendl;
char *s = new char[1234567];
(void)s;
// cppcheck-suppress memleak
}
打印banner
if (code_env == CODE_ENVIRONMENT_DAEMON && !(flags & CINIT_FLAG_NO_DAEMON_ACTIONS))
output_ceph_version();
common_init_finish函数
void common_init_finish(CephContext *cct)
{
cct->init_crypto();
//初始化压缩库
//如果不是CINIT_FLAG_NO_DAEMON_ACTIONS 启动service线程。
int flags = cct->get_init_flags(); 主要epoll接收外部的socket信号。
if (!(flags & CINIT_FLAG_NO_DAEMON_ACTIONS))
cct->start_service_thread();
if ((flags & CINIT_FLAG_DEFER_DROP_PRIVILEGES) &&
(cct->get_set_uid() || cct->get_set_gid())) {
cct->get_admin_socket()->chown(cct->get_set_uid(), cct->get_set_gid());
}
}
start_service_thread
说明:
Service_thread 启动一些服务类线程,比如:socket_admin线程和RGWAsyncRadosProcessor 和AsyncCompressor::compressor_tp线程等等。