2007-10-17 23:34:54 +00:00
|
|
|
// -*- mode:C++; tab-width:8; c-basic-offset:2; indent-tabs-mode:t -*-
|
|
|
|
// vim: ts=8 sw=2 smarttab
|
|
|
|
/*
|
|
|
|
* Ceph - scalable distributed file system
|
|
|
|
*
|
|
|
|
* Copyright (C) 2004-2006 Sage Weil <sage@newdream.net>
|
|
|
|
*
|
|
|
|
* This is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU Lesser General Public
|
|
|
|
* License version 2.1, as published by the Free Software
|
|
|
|
* Foundation. See file COPYING.
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <sys/types.h>
|
|
|
|
#include <sys/stat.h>
|
|
|
|
#include <fcntl.h>
|
|
|
|
|
|
|
|
#include <iostream>
|
|
|
|
#include <string>
|
|
|
|
using namespace std;
|
|
|
|
|
2012-01-23 14:18:53 +00:00
|
|
|
#include "include/ceph_features.h"
|
|
|
|
|
2011-02-22 16:38:45 +00:00
|
|
|
#include "common/config.h"
|
2011-06-02 22:50:22 +00:00
|
|
|
#include "common/strtol.h"
|
2007-10-17 23:34:54 +00:00
|
|
|
|
|
|
|
#include "mon/MonMap.h"
|
2015-07-13 09:15:40 +00:00
|
|
|
#include "mds/MDSDaemon.h"
|
2007-10-17 23:34:54 +00:00
|
|
|
|
2012-03-14 23:33:39 +00:00
|
|
|
#include "msg/Messenger.h"
|
2007-10-17 23:34:54 +00:00
|
|
|
|
|
|
|
#include "common/Timer.h"
|
2011-02-20 17:18:03 +00:00
|
|
|
#include "common/ceph_argparse.h"
|
2011-11-21 21:32:45 +00:00
|
|
|
#include "common/pick_address.h"
|
2007-10-17 23:34:54 +00:00
|
|
|
|
2012-02-12 00:39:27 +00:00
|
|
|
#include "global/global_init.h"
|
|
|
|
#include "global/signal_handler.h"
|
|
|
|
#include "global/pidfile.h"
|
|
|
|
|
2008-03-10 05:32:16 +00:00
|
|
|
#include "mon/MonClient.h"
|
2007-10-17 23:34:54 +00:00
|
|
|
|
2010-02-04 21:48:23 +00:00
|
|
|
#include "auth/KeyRing.h"
|
|
|
|
|
2014-10-02 13:14:21 +00:00
|
|
|
#include "perfglue/heap_profiler.h"
|
|
|
|
|
2012-06-06 23:57:31 +00:00
|
|
|
#include "include/assert.h"
|
|
|
|
|
2012-03-27 17:41:12 +00:00
|
|
|
#define dout_subsys ceph_subsys_mds
|
|
|
|
|
2009-03-10 21:57:24 +00:00
|
|
|
void usage()
|
|
|
|
{
|
2011-09-21 23:28:43 +00:00
|
|
|
derr << "usage: ceph-mds -i name [flags] [[--journal_check rank]|[--hot-standby][rank]]\n"
|
2010-12-17 00:25:29 +00:00
|
|
|
<< " -m monitorip:port\n"
|
|
|
|
<< " connect to monitor at given address\n"
|
|
|
|
<< " --debug_mds n\n"
|
2011-01-25 22:07:48 +00:00
|
|
|
<< " debug MDS level (e.g. 10)\n"
|
2011-01-28 17:45:33 +00:00
|
|
|
<< " --journal-check rank\n"
|
|
|
|
<< " replay the journal for rank, then exit\n"
|
|
|
|
<< " --hot-standby rank\n"
|
2013-01-16 15:43:58 +00:00
|
|
|
<< " start up as a hot standby for rank\n"
|
2011-01-25 22:07:48 +00:00
|
|
|
<< dendl;
|
2009-03-10 22:22:52 +00:00
|
|
|
generic_server_usage();
|
2009-03-10 21:57:24 +00:00
|
|
|
}
|
|
|
|
|
2011-06-02 22:50:22 +00:00
|
|
|
|
|
|
|
static int parse_rank(const char *opt_name, const std::string &val)
|
|
|
|
{
|
|
|
|
std::string err;
|
|
|
|
int ret = strict_strtol(val.c_str(), 10, &err);
|
|
|
|
if (!err.empty()) {
|
|
|
|
derr << "error parsing " << opt_name << ": failed to parse rank. "
|
|
|
|
<< "It must be an int." << "\n" << dendl;
|
|
|
|
usage();
|
|
|
|
}
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2012-02-12 00:33:51 +00:00
|
|
|
|
|
|
|
|
2015-07-13 09:15:40 +00:00
|
|
|
MDSDaemon *mds = NULL;
|
2012-02-12 00:33:51 +00:00
|
|
|
|
|
|
|
|
|
|
|
static void handle_mds_signal(int signum)
|
|
|
|
{
|
|
|
|
if (mds)
|
|
|
|
mds->handle_signal(signum);
|
|
|
|
}
|
|
|
|
|
2008-01-01 22:04:31 +00:00
|
|
|
int main(int argc, const char **argv)
|
2007-10-17 23:34:54 +00:00
|
|
|
{
|
2008-01-01 22:04:31 +00:00
|
|
|
vector<const char*> args;
|
2007-10-17 23:34:54 +00:00
|
|
|
argv_to_vec(argc, argv, args);
|
2008-11-05 22:54:13 +00:00
|
|
|
env_to_vec(args);
|
2010-07-01 15:55:52 +00:00
|
|
|
|
2016-01-26 14:18:37 +00:00
|
|
|
global_init(NULL, args, CEPH_ENTITY_TYPE_MDS, CODE_ENVIRONMENT_DAEMON,
|
|
|
|
0, "mds_data");
|
2014-10-02 13:14:21 +00:00
|
|
|
ceph_heap_profiler_init();
|
2007-10-17 23:34:54 +00:00
|
|
|
|
|
|
|
// mds specific args
|
2014-07-21 19:22:46 +00:00
|
|
|
MDSMap::DaemonState shadow = MDSMap::STATE_NULL;
|
2011-06-02 22:50:22 +00:00
|
|
|
std::string dump_file;
|
|
|
|
|
|
|
|
std::string val, action;
|
|
|
|
for (std::vector<const char*>::iterator i = args.begin(); i != args.end(); ) {
|
2011-08-24 01:12:06 +00:00
|
|
|
if (ceph_argparse_double_dash(args, i)) {
|
|
|
|
break;
|
|
|
|
}
|
2015-12-08 09:00:58 +00:00
|
|
|
else if (ceph_argparse_flag(args, i, "--help", "-h", (char*)NULL)) {
|
|
|
|
usage();
|
|
|
|
break;
|
|
|
|
}
|
2011-06-02 22:50:22 +00:00
|
|
|
else if (ceph_argparse_witharg(args, i, &val, "--journal-check", (char*)NULL)) {
|
|
|
|
int r = parse_rank("journal-check", val);
|
2014-07-21 19:22:46 +00:00
|
|
|
if (shadow != MDSMap::STATE_NULL) {
|
2010-12-03 00:36:22 +00:00
|
|
|
dout(0) << "Error: can only select one standby state" << dendl;
|
|
|
|
return -1;
|
|
|
|
}
|
2011-09-28 04:42:35 +00:00
|
|
|
dout(0) << "requesting oneshot_replay for mds." << r << dendl;
|
2010-12-03 00:36:22 +00:00
|
|
|
shadow = MDSMap::STATE_ONESHOT_REPLAY;
|
2011-09-14 21:54:35 +00:00
|
|
|
char rb[32];
|
|
|
|
snprintf(rb, sizeof(rb), "%d", r);
|
|
|
|
g_conf->set_val("mds_standby_for_rank", rb);
|
|
|
|
g_conf->apply_changes(NULL);
|
2011-06-02 22:50:22 +00:00
|
|
|
}
|
|
|
|
else if (ceph_argparse_witharg(args, i, &val, "--hot-standby", (char*)NULL)) {
|
|
|
|
int r = parse_rank("hot-standby", val);
|
2015-11-03 11:43:54 +00:00
|
|
|
if (shadow != MDSMap::STATE_NULL) {
|
2010-12-03 00:36:22 +00:00
|
|
|
dout(0) << "Error: can only select one standby state" << dendl;
|
|
|
|
return -1;
|
|
|
|
}
|
2011-09-28 04:42:35 +00:00
|
|
|
dout(0) << "requesting standby_replay for mds." << r << dendl;
|
2010-12-03 00:36:22 +00:00
|
|
|
shadow = MDSMap::STATE_STANDBY_REPLAY;
|
2011-09-14 21:54:35 +00:00
|
|
|
char rb[32];
|
|
|
|
snprintf(rb, sizeof(rb), "%d", r);
|
|
|
|
g_conf->set_val("mds_standby_for_rank", rb);
|
|
|
|
g_conf->apply_changes(NULL);
|
2011-06-02 22:50:22 +00:00
|
|
|
}
|
|
|
|
else {
|
|
|
|
derr << "Error: can't understand argument: " << *i << "\n" << dendl;
|
2011-03-28 23:10:33 +00:00
|
|
|
usage();
|
2010-11-04 18:30:59 +00:00
|
|
|
}
|
2007-10-17 23:34:54 +00:00
|
|
|
}
|
2011-06-02 22:50:22 +00:00
|
|
|
|
2013-05-22 16:52:15 +00:00
|
|
|
pick_addresses(g_ceph_context, CEPH_PICK_ADDRESS_PUBLIC);
|
2011-11-21 21:32:45 +00:00
|
|
|
|
2011-06-02 22:50:22 +00:00
|
|
|
// Normal startup
|
2011-06-07 17:38:54 +00:00
|
|
|
if (g_conf->name.has_default_id()) {
|
2011-09-21 23:28:43 +00:00
|
|
|
derr << "must specify '-i name' with the ceph-mds instance name" << dendl;
|
2009-03-11 20:04:03 +00:00
|
|
|
usage();
|
2009-03-11 21:58:58 +00:00
|
|
|
}
|
2007-10-17 23:34:54 +00:00
|
|
|
|
2014-12-23 21:29:52 +00:00
|
|
|
if (g_conf->name.get_id().empty() ||
|
|
|
|
(g_conf->name.get_id()[0] >= '0' && g_conf->name.get_id()[0] <= '9')) {
|
2014-10-06 10:18:51 +00:00
|
|
|
derr << "deprecation warning: MDS id '" << g_conf->name
|
|
|
|
<< "' is invalid and will be forbidden in a future version. "
|
|
|
|
"MDS names may not start with a numeric digit." << dendl;
|
|
|
|
}
|
|
|
|
|
2014-12-23 21:29:52 +00:00
|
|
|
Messenger *msgr = Messenger::create(g_ceph_context, g_conf->ms_type,
|
|
|
|
entity_name_t::MDS(-1), "mds",
|
|
|
|
getpid());
|
2016-02-17 16:52:33 +00:00
|
|
|
if (!msgr)
|
|
|
|
exit(1);
|
2014-12-23 21:29:52 +00:00
|
|
|
msgr->set_cluster_protocol(CEPH_MDS_PROTOCOL);
|
2012-01-04 21:54:11 +00:00
|
|
|
|
2014-12-23 21:29:52 +00:00
|
|
|
cout << "starting " << g_conf->name << " at " << msgr->get_myaddr()
|
2011-06-02 22:50:22 +00:00
|
|
|
<< std::endl;
|
|
|
|
uint64_t supported =
|
|
|
|
CEPH_FEATURE_UID |
|
|
|
|
CEPH_FEATURE_NOSRCADDR |
|
2011-08-27 16:56:45 +00:00
|
|
|
CEPH_FEATURE_DIRLAYOUTHASH |
|
2013-12-20 09:36:32 +00:00
|
|
|
CEPH_FEATURE_MDS_INLINE_DATA |
|
2012-10-01 20:13:40 +00:00
|
|
|
CEPH_FEATURE_PGID64 |
|
2013-12-06 08:33:39 +00:00
|
|
|
CEPH_FEATURE_MSG_AUTH |
|
2014-01-07 12:25:10 +00:00
|
|
|
CEPH_FEATURE_EXPORT_PEER |
|
|
|
|
CEPH_FEATURE_MDS_QUOTA;
|
2012-01-13 23:08:17 +00:00
|
|
|
uint64_t required =
|
|
|
|
CEPH_FEATURE_OSDREPLYMUX;
|
2014-12-23 21:29:52 +00:00
|
|
|
|
|
|
|
msgr->set_default_policy(Messenger::Policy::lossy_client(supported, required));
|
|
|
|
msgr->set_policy(entity_name_t::TYPE_MON,
|
|
|
|
Messenger::Policy::lossy_client(supported,
|
|
|
|
CEPH_FEATURE_UID |
|
|
|
|
CEPH_FEATURE_PGID64));
|
|
|
|
msgr->set_policy(entity_name_t::TYPE_MDS,
|
|
|
|
Messenger::Policy::lossless_peer(supported,
|
|
|
|
CEPH_FEATURE_UID));
|
|
|
|
msgr->set_policy(entity_name_t::TYPE_CLIENT,
|
|
|
|
Messenger::Policy::stateful_server(supported, 0));
|
|
|
|
|
|
|
|
int r = msgr->bind(g_conf->public_addr);
|
2012-03-02 02:31:49 +00:00
|
|
|
if (r < 0)
|
|
|
|
exit(1);
|
|
|
|
|
2011-06-02 22:50:22 +00:00
|
|
|
if (shadow != MDSMap::STATE_ONESHOT_REPLAY)
|
2015-11-12 06:30:03 +00:00
|
|
|
global_init_daemonize(g_ceph_context);
|
2011-06-21 19:28:16 +00:00
|
|
|
common_init_finish(g_ceph_context);
|
2011-06-02 22:50:22 +00:00
|
|
|
|
2008-03-10 05:32:16 +00:00
|
|
|
// get monmap
|
2011-06-21 19:28:16 +00:00
|
|
|
MonClient mc(g_ceph_context);
|
2009-06-26 20:49:12 +00:00
|
|
|
if (mc.build_initial_monmap() < 0)
|
2008-01-31 22:43:18 +00:00
|
|
|
return -1;
|
2011-06-21 19:28:16 +00:00
|
|
|
global_init_chdir(g_ceph_context);
|
2007-10-17 23:34:54 +00:00
|
|
|
|
2014-12-23 21:29:52 +00:00
|
|
|
msgr->start();
|
2010-11-04 18:30:59 +00:00
|
|
|
|
2011-06-02 22:50:22 +00:00
|
|
|
// start mds
|
2015-07-13 09:15:40 +00:00
|
|
|
mds = new MDSDaemon(g_conf->name.get_id().c_str(), msgr, &mc);
|
2011-06-02 22:50:22 +00:00
|
|
|
|
|
|
|
// in case we have to respawn...
|
|
|
|
mds->orig_argc = argc;
|
|
|
|
mds->orig_argv = argv;
|
|
|
|
|
2015-07-02 13:15:38 +00:00
|
|
|
if (shadow != MDSMap::STATE_NULL)
|
2012-12-11 21:41:50 +00:00
|
|
|
r = mds->init(shadow);
|
2011-06-02 22:50:22 +00:00
|
|
|
else
|
2012-12-11 21:41:50 +00:00
|
|
|
r = mds->init();
|
2015-12-21 06:35:54 +00:00
|
|
|
if (r < 0) {
|
|
|
|
msgr->wait();
|
2013-07-20 15:37:44 +00:00
|
|
|
goto shutdown;
|
2015-12-21 06:35:54 +00:00
|
|
|
}
|
2011-06-02 22:50:22 +00:00
|
|
|
|
2013-07-20 15:37:44 +00:00
|
|
|
// set up signal handlers, now that we've daemonized/forked.
|
|
|
|
init_async_signal_handler();
|
|
|
|
register_async_signal_handler(SIGHUP, sighup_handler);
|
|
|
|
register_async_signal_handler_oneshot(SIGINT, handle_mds_signal);
|
|
|
|
register_async_signal_handler_oneshot(SIGTERM, handle_mds_signal);
|
|
|
|
|
2013-07-20 15:49:48 +00:00
|
|
|
if (g_conf->inject_early_sigterm)
|
|
|
|
kill(getpid(), SIGTERM);
|
|
|
|
|
2014-12-23 21:29:52 +00:00
|
|
|
msgr->wait();
|
2011-06-02 22:50:22 +00:00
|
|
|
|
2012-02-29 17:45:56 +00:00
|
|
|
unregister_async_signal_handler(SIGHUP, sighup_handler);
|
2012-02-12 00:33:51 +00:00
|
|
|
unregister_async_signal_handler(SIGINT, handle_mds_signal);
|
|
|
|
unregister_async_signal_handler(SIGTERM, handle_mds_signal);
|
2013-05-22 21:56:24 +00:00
|
|
|
shutdown_async_signal_handler();
|
2012-02-12 00:33:51 +00:00
|
|
|
|
2013-07-20 15:37:44 +00:00
|
|
|
shutdown:
|
2011-06-02 22:50:22 +00:00
|
|
|
// yuck: grab the mds lock, so we can be sure that whoever in *mds
|
|
|
|
// called shutdown finishes what they were doing.
|
|
|
|
mds->mds_lock.Lock();
|
|
|
|
mds->mds_lock.Unlock();
|
|
|
|
|
2012-02-12 00:39:27 +00:00
|
|
|
pidfile_remove();
|
|
|
|
|
2015-07-28 07:57:08 +00:00
|
|
|
// only delete if it was a clean shutdown (to aid memory leak
|
|
|
|
// detection, etc.). don't bother if it was a suicide.
|
|
|
|
if (mds->is_clean_shutdown()) {
|
|
|
|
delete mds;
|
|
|
|
delete msgr;
|
|
|
|
}
|
2011-06-02 22:50:22 +00:00
|
|
|
|
2013-07-20 15:47:51 +00:00
|
|
|
g_ceph_context->put();
|
|
|
|
|
2011-06-02 22:50:22 +00:00
|
|
|
// cd on exit, so that gmon.out (if any) goes into a separate directory for each node.
|
|
|
|
char s[20];
|
|
|
|
snprintf(s, sizeof(s), "gmon/%d", getpid());
|
|
|
|
if ((mkdir(s, 0755) == 0) && (chdir(s) == 0)) {
|
2013-07-20 15:47:51 +00:00
|
|
|
cerr << "ceph-mds: gmon.out should be in " << s << std::endl;
|
2010-11-04 18:30:59 +00:00
|
|
|
}
|
2011-06-02 22:50:22 +00:00
|
|
|
|
2007-10-17 23:34:54 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|