]>
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>
24 #include "include/ceph_features.h"
25 #include "include/compat.h"
27 #include "common/config.h"
28 #include "common/strtol.h"
30 #include "mon/MonMap.h"
31 #include "mds/MDSDaemon.h"
33 #include "msg/Messenger.h"
35 #include "common/Timer.h"
36 #include "common/ceph_argparse.h"
37 #include "common/pick_address.h"
39 #include "global/global_init.h"
40 #include "global/signal_handler.h"
41 #include "global/pidfile.h"
43 #include "mon/MonClient.h"
45 #include "auth/KeyRing.h"
47 #include "perfglue/heap_profiler.h"
49 #include "include/assert.h"
51 #define dout_context g_ceph_context
52 #define dout_subsys ceph_subsys_mds
56 cout
<< "usage: ceph-mds -i name [flags] [[--hot-standby][rank]]\n"
57 << " -m monitorip:port\n"
58 << " connect to monitor at given address\n"
60 << " debug MDS level (e.g. 10)\n"
61 << " --hot-standby rank\n"
62 << " start up as a hot standby for rank\n"
64 generic_server_usage();
68 static int parse_rank(const char *opt_name
, const std::string
&val
)
71 int ret
= strict_strtol(val
.c_str(), 10, &err
);
73 derr
<< "error parsing " << opt_name
<< ": failed to parse rank. "
74 << "It must be an int." << "\n" << dendl
;
82 MDSDaemon
*mds
= NULL
;
85 static void handle_mds_signal(int signum
)
88 mds
->handle_signal(signum
);
91 #ifdef BUILDING_FOR_EMBEDDED
92 extern "C" int cephd_mds(int argc
, const char **argv
)
94 int main(int argc
, const char **argv
)
97 ceph_pthread_setname(pthread_self(), "ceph-mds");
99 vector
<const char*> args
;
100 argv_to_vec(argc
, argv
, args
);
103 auto cct
= global_init(NULL
, args
,
104 CEPH_ENTITY_TYPE_MDS
, CODE_ENVIRONMENT_DAEMON
,
106 ceph_heap_profiler_init();
108 std::string val
, action
;
109 for (std::vector
<const char*>::iterator i
= args
.begin(); i
!= args
.end(); ) {
110 if (ceph_argparse_double_dash(args
, i
)) {
113 else if (ceph_argparse_flag(args
, i
, "--help", "-h", (char*)NULL
)) {
114 // exit(1) will be called in the usage()
117 else if (ceph_argparse_witharg(args
, i
, &val
, "--hot-standby", (char*)NULL
)) {
118 int r
= parse_rank("hot-standby", val
);
119 dout(0) << "requesting standby_replay for mds." << r
<< dendl
;
121 snprintf(rb
, sizeof(rb
), "%d", r
);
122 g_conf
->set_val("mds_standby_for_rank", rb
);
123 g_conf
->set_val("mds_standby_replay", "true");
124 g_conf
->apply_changes(NULL
);
127 derr
<< "Error: can't understand argument: " << *i
<< "\n" << dendl
;
132 pick_addresses(g_ceph_context
, CEPH_PICK_ADDRESS_PUBLIC
);
135 if (g_conf
->name
.has_default_id()) {
136 derr
<< "must specify '-i name' with the ceph-mds instance name" << dendl
;
140 if (g_conf
->name
.get_id().empty() ||
141 (g_conf
->name
.get_id()[0] >= '0' && g_conf
->name
.get_id()[0] <= '9')) {
142 derr
<< "deprecation warning: MDS id '" << g_conf
->name
143 << "' is invalid and will be forbidden in a future version. "
144 "MDS names may not start with a numeric digit." << dendl
;
148 get_random_bytes((char*)&nonce
, sizeof(nonce
));
150 std::string public_msgr_type
= g_conf
->ms_public_type
.empty() ? g_conf
->get_val
<std::string
>("ms_type") : g_conf
->ms_public_type
;
151 Messenger
*msgr
= Messenger::create(g_ceph_context
, public_msgr_type
,
152 entity_name_t::MDS(-1), "mds",
153 nonce
, Messenger::HAS_MANY_CONNECTIONS
);
156 msgr
->set_cluster_protocol(CEPH_MDS_PROTOCOL
);
158 cout
<< "starting " << g_conf
->name
<< " at " << msgr
->get_myaddr()
161 CEPH_FEATURE_OSDREPLYMUX
;
163 msgr
->set_default_policy(Messenger::Policy::lossy_client(required
));
164 msgr
->set_policy(entity_name_t::TYPE_MON
,
165 Messenger::Policy::lossy_client(CEPH_FEATURE_UID
|
166 CEPH_FEATURE_PGID64
));
167 msgr
->set_policy(entity_name_t::TYPE_MDS
,
168 Messenger::Policy::lossless_peer(CEPH_FEATURE_UID
));
169 msgr
->set_policy(entity_name_t::TYPE_CLIENT
,
170 Messenger::Policy::stateful_server(0));
172 int r
= msgr
->bind(g_conf
->public_addr
);
176 global_init_daemonize(g_ceph_context
);
177 common_init_finish(g_ceph_context
);
180 MonClient
mc(g_ceph_context
);
181 if (mc
.build_initial_monmap() < 0)
183 global_init_chdir(g_ceph_context
);
188 mds
= new MDSDaemon(g_conf
->name
.get_id().c_str(), msgr
, &mc
);
190 // in case we have to respawn...
191 mds
->orig_argc
= argc
;
192 mds
->orig_argv
= argv
;
200 // set up signal handlers, now that we've daemonized/forked.
201 init_async_signal_handler();
202 register_async_signal_handler(SIGHUP
, sighup_handler
);
203 register_async_signal_handler_oneshot(SIGINT
, handle_mds_signal
);
204 register_async_signal_handler_oneshot(SIGTERM
, handle_mds_signal
);
206 if (g_conf
->inject_early_sigterm
)
207 kill(getpid(), SIGTERM
);
211 unregister_async_signal_handler(SIGHUP
, sighup_handler
);
212 unregister_async_signal_handler(SIGINT
, handle_mds_signal
);
213 unregister_async_signal_handler(SIGTERM
, handle_mds_signal
);
214 shutdown_async_signal_handler();
217 // yuck: grab the mds lock, so we can be sure that whoever in *mds
218 // called shutdown finishes what they were doing.
219 mds
->mds_lock
.Lock();
220 mds
->mds_lock
.Unlock();
224 // only delete if it was a clean shutdown (to aid memory leak
225 // detection, etc.). don't bother if it was a suicide.
226 if (mds
->is_clean_shutdown()) {
231 // cd on exit, so that gmon.out (if any) goes into a separate directory for each node.
233 snprintf(s
, sizeof(s
), "gmon/%d", getpid());
234 if ((mkdir(s
, 0755) == 0) && (chdir(s
) == 0)) {
235 cerr
<< "ceph-mds: gmon.out should be in " << s
<< std::endl
;