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 <sys/stat.h>
|
|
|
|
#include <iostream>
|
|
|
|
#include <string>
|
|
|
|
using namespace std;
|
|
|
|
|
|
|
|
#include "config.h"
|
|
|
|
|
|
|
|
#include "mon/MonMap.h"
|
|
|
|
#include "mds/MDS.h"
|
|
|
|
|
|
|
|
#include "msg/SimpleMessenger.h"
|
|
|
|
|
|
|
|
#include "common/Timer.h"
|
2009-02-09 23:46:02 +00:00
|
|
|
#include "common/common_init.h"
|
2007-10-17 23:34:54 +00:00
|
|
|
|
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"
|
|
|
|
|
2009-03-10 21:57:24 +00:00
|
|
|
void usage()
|
|
|
|
{
|
2009-03-11 21:58:58 +00:00
|
|
|
cerr << "usage: cmds -i name [flags] [--mds rank] [--shadow rank]\n";
|
2009-03-10 22:22:52 +00:00
|
|
|
cerr << " -m monitorip:port\n";
|
|
|
|
cerr << " connect to monitor at given address\n";
|
|
|
|
cerr << " --debug_mds n\n";
|
|
|
|
cerr << " debug MDS level (e.g. 10)\n";
|
|
|
|
generic_server_usage();
|
2009-03-10 21:57:24 +00:00
|
|
|
}
|
|
|
|
|
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);
|
2009-09-25 23:19:38 +00:00
|
|
|
common_init(args, "mds", true, true);
|
2007-10-17 23:34:54 +00:00
|
|
|
|
|
|
|
// mds specific args
|
|
|
|
for (unsigned i=0; i<args.size(); i++) {
|
2009-03-11 21:58:58 +00:00
|
|
|
cerr << "unrecognized arg " << args[i] << std::endl;
|
|
|
|
usage();
|
2007-10-17 23:34:54 +00:00
|
|
|
}
|
2009-03-11 21:58:58 +00:00
|
|
|
if (!g_conf.id) {
|
|
|
|
cerr << "must specify '-i name' with the cmds instance name" << std::endl;
|
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
|
|
|
|
|
|
|
if (g_conf.clock_tare) g_clock.tare();
|
|
|
|
|
2008-03-10 05:32:16 +00:00
|
|
|
// get monmap
|
2010-02-04 21:48:23 +00:00
|
|
|
RotatingKeyRing rkeys(CEPH_ENTITY_TYPE_MDS, &g_keyring);
|
2010-02-04 18:45:42 +00:00
|
|
|
MonClient mc(&rkeys);
|
2009-06-26 20:49:12 +00:00
|
|
|
if (mc.build_initial_monmap() < 0)
|
2008-01-31 22:43:18 +00:00
|
|
|
return -1;
|
2007-10-17 23:34:54 +00:00
|
|
|
|
2010-01-08 00:53:51 +00:00
|
|
|
SimpleMessenger *messenger = new SimpleMessenger();
|
|
|
|
messenger->bind();
|
2009-03-12 17:56:25 +00:00
|
|
|
cout << "starting mds." << g_conf.id
|
2010-01-08 00:53:51 +00:00
|
|
|
<< " at " << messenger->get_ms_addr()
|
2009-03-12 17:56:25 +00:00
|
|
|
<< std::endl;
|
2008-11-13 18:40:11 +00:00
|
|
|
|
2010-01-08 00:53:51 +00:00
|
|
|
messenger->register_entity(entity_name_t::MDS(-1));
|
|
|
|
assert_warn(messenger);
|
|
|
|
if (!messenger)
|
2009-02-13 00:47:56 +00:00
|
|
|
return 1;
|
2008-11-13 18:40:11 +00:00
|
|
|
|
2010-01-08 00:53:51 +00:00
|
|
|
messenger->set_policy(entity_name_t::TYPE_CLIENT, SimpleMessenger::Policy::stateful_server());
|
|
|
|
messenger->set_policy(entity_name_t::TYPE_MDS, SimpleMessenger::Policy::lossless_peer());
|
2007-10-17 23:34:54 +00:00
|
|
|
|
2010-01-08 00:53:51 +00:00
|
|
|
messenger->start();
|
2008-11-13 18:40:11 +00:00
|
|
|
|
2007-10-17 23:34:54 +00:00
|
|
|
// start mds
|
2010-01-08 00:53:51 +00:00
|
|
|
MDS *mds = new MDS(g_conf.id, messenger, &mc);
|
2009-03-10 21:57:24 +00:00
|
|
|
mds->init();
|
2007-10-17 23:34:54 +00:00
|
|
|
|
2010-01-08 00:53:51 +00:00
|
|
|
messenger->wait();
|
2007-10-17 23:34:54 +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();
|
|
|
|
|
2009-04-20 23:14:52 +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_stopped())
|
|
|
|
delete mds;
|
2007-10-17 23:34:54 +00:00
|
|
|
|
2008-11-04 22:50:21 +00:00
|
|
|
// cd on exit, so that gmon.out (if any) goes into a separate directory for each node.
|
|
|
|
char s[20];
|
2010-01-15 00:07:39 +00:00
|
|
|
snprintf(s, sizeof(s), "gmon/%d", getpid());
|
2008-11-04 22:50:21 +00:00
|
|
|
if (mkdir(s, 0755) == 0)
|
|
|
|
chdir(s);
|
|
|
|
|
2008-04-17 20:00:40 +00:00
|
|
|
generic_dout(0) << "stopped." << dendl;
|
2007-10-17 23:34:54 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|