]>
git.proxmox.com Git - ceph.git/blob - ceph/src/ceph_mds.cc
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) 2004-2006 Sage Weil <sage@newdream.net>
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.
15 #include <sys/types.h>
23 #include "include/ceph_features.h"
24 #include "include/compat.h"
25 #include "include/random.h"
27 #include "common/config.h"
28 #include "common/strtol.h"
29 #include "common/numa.h"
31 #include "mon/MonMap.h"
32 #include "mds/MDSDaemon.h"
34 #include "msg/Messenger.h"
36 #include "common/Timer.h"
37 #include "common/ceph_argparse.h"
38 #include "common/pick_address.h"
39 #include "common/Preforker.h"
41 #include "global/global_init.h"
42 #include "global/signal_handler.h"
43 #include "global/pidfile.h"
45 #include "mon/MonClient.h"
47 #include "auth/KeyRing.h"
49 #include "perfglue/heap_profiler.h"
51 #include "include/ceph_assert.h"
53 #define dout_context g_ceph_context
54 #define dout_subsys ceph_subsys_mds
58 cout
<< "usage: ceph-mds -i <ID> [flags]\n"
59 << " -m monitorip:port\n"
60 << " connect to monitor at given address\n"
62 << " debug MDS level (e.g. 10)\n"
64 generic_server_usage();
68 MDSDaemon
*mds
= NULL
;
71 static void handle_mds_signal(int signum
)
74 mds
->handle_signal(signum
);
77 int main(int argc
, const char **argv
)
79 ceph_pthread_setname(pthread_self(), "ceph-mds");
81 vector
<const char*> args
;
82 argv_to_vec(argc
, argv
, args
);
84 cerr
<< argv
[0] << ": -h or --help for usage" << std::endl
;
87 if (ceph_argparse_need_usage(args
)) {
92 auto cct
= global_init(NULL
, args
,
93 CEPH_ENTITY_TYPE_MDS
, CODE_ENVIRONMENT_DAEMON
,
95 ceph_heap_profiler_init();
97 int numa_node
= g_conf().get_val
<int64_t>("mds_numa_node");
98 size_t numa_cpu_set_size
= 0;
99 cpu_set_t numa_cpu_set
;
100 if (numa_node
>= 0) {
101 int r
= get_numa_node_cpu_set(numa_node
, &numa_cpu_set_size
, &numa_cpu_set
);
103 dout(1) << __func__
<< " unable to determine mds numa node " << numa_node
107 r
= set_cpu_affinity_all_threads(numa_cpu_set_size
, &numa_cpu_set
);
109 derr
<< __func__
<< " failed to set numa affinity: " << cpp_strerror(r
)
114 dout(1) << __func__
<< " not setting numa affinity" << dendl
;
116 std::string val
, action
;
117 for (std::vector
<const char*>::iterator i
= args
.begin(); i
!= args
.end(); ) {
118 if (ceph_argparse_double_dash(args
, i
)) {
121 else if (ceph_argparse_witharg(args
, i
, &val
, "--hot-standby", (char*)NULL
)) {
122 dout(0) << "--hot-standby is obsolete and has no effect" << dendl
;
125 derr
<< "Error: can't understand argument: " << *i
<< "\n" << dendl
;
132 entity_addrvec_t addrs
;
133 pick_addresses(g_ceph_context
, CEPH_PICK_ADDRESS_PUBLIC
, &addrs
);
136 if (g_conf()->name
.has_default_id()) {
137 derr
<< "must specify '-i name' with the ceph-mds instance name" << dendl
;
141 if (g_conf()->name
.get_id().empty() ||
142 (g_conf()->name
.get_id()[0] >= '0' && g_conf()->name
.get_id()[0] <= '9')) {
143 derr
<< "MDS id '" << g_conf()->name
<< "' is invalid. "
144 "MDS names may not start with a numeric digit." << dendl
;
148 if (global_init_prefork(g_ceph_context
) >= 0) {
150 int r
= forker
.prefork(err
);
152 cerr
<< err
<< std::endl
;
155 if (forker
.is_parent()) {
156 if (forker
.parent_wait(err
) != 0) {
161 global_init_postfork_start(g_ceph_context
);
163 common_init_finish(g_ceph_context
);
164 global_init_chdir(g_ceph_context
);
166 std::string public_msgr_type
= g_conf()->ms_public_type
.empty() ? g_conf().get_val
<std::string
>("ms_type") : g_conf()->ms_public_type
;
167 Messenger
*msgr
= Messenger::create(g_ceph_context
, public_msgr_type
,
168 entity_name_t::MDS(-1), "mds",
169 Messenger::get_random_nonce(),
170 Messenger::HAS_MANY_CONNECTIONS
);
173 msgr
->set_cluster_protocol(CEPH_MDS_PROTOCOL
);
175 cout
<< "starting " << g_conf()->name
<< " at " << msgr
->get_myaddrs()
178 CEPH_FEATURE_OSDREPLYMUX
;
180 msgr
->set_default_policy(Messenger::Policy::lossy_client(required
));
181 msgr
->set_policy(entity_name_t::TYPE_MON
,
182 Messenger::Policy::lossy_client(CEPH_FEATURE_UID
|
183 CEPH_FEATURE_PGID64
));
184 msgr
->set_policy(entity_name_t::TYPE_MDS
,
185 Messenger::Policy::lossless_peer(CEPH_FEATURE_UID
));
186 msgr
->set_policy(entity_name_t::TYPE_CLIENT
,
187 Messenger::Policy::stateful_server(0));
189 int r
= msgr
->bindv(addrs
);
193 // set up signal handlers, now that we've daemonized/forked.
194 init_async_signal_handler();
195 register_async_signal_handler(SIGHUP
, sighup_handler
);
198 MonClient
mc(g_ceph_context
);
199 if (mc
.build_initial_monmap() < 0)
201 global_init_chdir(g_ceph_context
);
206 mds
= new MDSDaemon(g_conf()->name
.get_id().c_str(), msgr
, &mc
);
208 // in case we have to respawn...
209 mds
->orig_argc
= argc
;
210 mds
->orig_argv
= argv
;
212 if (g_conf()->daemonize
) {
213 global_init_postfork_finish(g_ceph_context
);
223 register_async_signal_handler_oneshot(SIGINT
, handle_mds_signal
);
224 register_async_signal_handler_oneshot(SIGTERM
, handle_mds_signal
);
226 if (g_conf()->inject_early_sigterm
)
227 kill(getpid(), SIGTERM
);
231 unregister_async_signal_handler(SIGHUP
, sighup_handler
);
232 unregister_async_signal_handler(SIGINT
, handle_mds_signal
);
233 unregister_async_signal_handler(SIGTERM
, handle_mds_signal
);
234 shutdown_async_signal_handler();
237 // yuck: grab the mds lock, so we can be sure that whoever in *mds
238 // called shutdown finishes what they were doing.
239 mds
->mds_lock
.lock();
240 mds
->mds_lock
.unlock();
244 // only delete if it was a clean shutdown (to aid memory leak
245 // detection, etc.). don't bother if it was a suicide.
246 if (mds
->is_clean_shutdown()) {
251 // cd on exit, so that gmon.out (if any) goes into a separate directory for each node.
253 snprintf(s
, sizeof(s
), "gmon/%d", getpid());
254 if ((mkdir(s
, 0755) == 0) && (chdir(s
) == 0)) {
255 cerr
<< "ceph-mds: gmon.out should be in " << s
<< std::endl
;