2007-10-29 19:05:24 +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 "mon/Monitor.h"
|
2008-03-10 23:23:41 +00:00
|
|
|
#include "mon/MonitorStore.h"
|
2007-10-29 19:05:24 +00:00
|
|
|
|
|
|
|
#include "msg/SimpleMessenger.h"
|
|
|
|
|
|
|
|
#include "common/Timer.h"
|
|
|
|
|
2008-03-10 23:23:41 +00:00
|
|
|
void usage()
|
|
|
|
{
|
|
|
|
cerr << "usage: ./cmon [flags] <monfsdir>" << std::endl;
|
|
|
|
cerr << " -d daemonize" << std::endl;
|
|
|
|
cerr << " -o <dir> log output to dir/mon#" << std::endl;
|
|
|
|
cerr << " --debug_mon n debug monitor level (e.g. 10)" << std::endl;
|
|
|
|
cerr << " --debug_ms n debug messaging level (e.g. 1)" << std::endl;
|
|
|
|
exit(1);
|
|
|
|
}
|
2007-10-29 19:05:24 +00:00
|
|
|
|
2008-01-01 22:04:31 +00:00
|
|
|
int main(int argc, const char **argv)
|
2007-10-29 19:05:24 +00:00
|
|
|
{
|
2008-03-10 23:23:41 +00:00
|
|
|
int err;
|
|
|
|
|
2008-01-01 22:04:31 +00:00
|
|
|
vector<const char*> args;
|
2007-10-29 19:05:24 +00:00
|
|
|
argv_to_vec(argc, argv, args);
|
|
|
|
parse_config_options(args);
|
|
|
|
|
|
|
|
// args
|
2008-03-10 23:23:41 +00:00
|
|
|
const char *fsdir = 0;
|
2007-10-29 19:05:24 +00:00
|
|
|
for (unsigned i=0; i<args.size(); i++) {
|
2008-03-10 23:23:41 +00:00
|
|
|
if (!fsdir)
|
|
|
|
fsdir = args[i];
|
|
|
|
else
|
|
|
|
usage();
|
2007-10-29 19:05:24 +00:00
|
|
|
}
|
2008-03-10 23:23:41 +00:00
|
|
|
if (!fsdir)
|
|
|
|
usage();
|
2007-10-29 19:05:24 +00:00
|
|
|
|
|
|
|
if (g_conf.clock_tare) g_clock.tare();
|
|
|
|
|
2008-03-10 23:23:41 +00:00
|
|
|
MonitorStore store(fsdir);
|
|
|
|
err = store.mount();
|
|
|
|
if (err < 0) {
|
2008-05-19 22:06:19 +00:00
|
|
|
cerr << "problem opening monitor store in " << fsdir << ": " << strerror(-err) << std::endl;
|
2008-03-10 23:23:41 +00:00
|
|
|
exit(1);
|
|
|
|
}
|
|
|
|
|
|
|
|
// whoami?
|
|
|
|
if (!store.exists_bl_ss("whoami")) {
|
|
|
|
cerr << "mon fs missing 'whoami'" << std::endl;
|
|
|
|
exit(1);
|
|
|
|
}
|
|
|
|
int whoami = store.get_int("whoami");
|
|
|
|
|
|
|
|
// monmap?
|
|
|
|
bufferlist mapbl;
|
|
|
|
store.get_bl_ss(mapbl, "monmap", 0);
|
|
|
|
if (mapbl.length() == 0) {
|
|
|
|
cerr << "mon fs missing 'monmap'" << std::endl;
|
|
|
|
exit(1);
|
|
|
|
}
|
2007-10-29 19:05:24 +00:00
|
|
|
MonMap monmap;
|
2008-03-10 23:23:41 +00:00
|
|
|
monmap.decode(mapbl);
|
2007-10-29 19:05:24 +00:00
|
|
|
|
2008-03-10 23:23:41 +00:00
|
|
|
if ((unsigned)whoami >= monmap.size() || whoami < 0) {
|
|
|
|
cerr << "mon" << whoami << " does not exist in monmap" << std::endl;
|
|
|
|
exit(1);
|
2007-10-29 19:05:24 +00:00
|
|
|
}
|
|
|
|
|
2008-03-10 23:23:41 +00:00
|
|
|
// bind
|
|
|
|
cout << "starting mon" << whoami
|
|
|
|
<< " at " << monmap.get_inst(whoami).addr
|
|
|
|
<< " from " << fsdir << std::endl;
|
|
|
|
g_my_addr = monmap.get_inst(whoami).addr;
|
|
|
|
err = rank.bind();
|
|
|
|
if (err < 0)
|
|
|
|
return 1;
|
|
|
|
|
2008-11-05 22:09:04 +00:00
|
|
|
_dout_create_courtesy_output_symlink("mon", whoami);
|
2008-01-26 17:33:13 +00:00
|
|
|
|
2007-10-29 19:05:24 +00:00
|
|
|
// start monitor
|
|
|
|
Messenger *m = rank.register_entity(entity_name_t::MON(whoami));
|
2008-10-08 17:49:12 +00:00
|
|
|
m->set_default_send_priority(CEPH_MSG_PRIO_HIGH);
|
2008-03-10 23:23:41 +00:00
|
|
|
Monitor *mon = new Monitor(whoami, &store, m, &monmap);
|
2007-10-29 19:05:24 +00:00
|
|
|
|
2008-03-10 23:23:41 +00:00
|
|
|
rank.start(); // may daemonize
|
2008-04-09 17:42:46 +00:00
|
|
|
|
2008-10-29 21:03:05 +00:00
|
|
|
rank.set_policy(entity_name_t::TYPE_MON, Rank::Policy::lossless());
|
2008-10-13 18:56:31 +00:00
|
|
|
|
|
|
|
rank.set_policy(entity_name_t::TYPE_MDS, Rank::Policy::lossy_fast_fail());
|
|
|
|
rank.set_policy(entity_name_t::TYPE_CLIENT, Rank::Policy::lossy_fast_fail());
|
|
|
|
rank.set_policy(entity_name_t::TYPE_OSD, Rank::Policy::lossy_fast_fail());
|
|
|
|
rank.set_policy(entity_name_t::TYPE_ADMIN, Rank::Policy::lossy_fast_fail());
|
2008-04-09 17:42:46 +00:00
|
|
|
|
|
|
|
|
2008-03-10 23:23:41 +00:00
|
|
|
mon->init();
|
2007-10-29 19:05:24 +00:00
|
|
|
rank.wait();
|
|
|
|
|
2008-03-10 23:23:41 +00:00
|
|
|
store.umount();
|
2007-10-29 19:05:24 +00:00
|
|
|
delete mon;
|
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];
|
|
|
|
sprintf(s, "gmon/%d", getpid());
|
|
|
|
if (mkdir(s, 0755) == 0)
|
|
|
|
chdir(s);
|
|
|
|
|
2007-10-29 19:05:24 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|