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"
|
|
|
|
|
2010-01-14 19:12:23 +00:00
|
|
|
#include "include/CompatSet.h"
|
2008-11-21 00:59:08 +00:00
|
|
|
#include "include/nstring.h"
|
|
|
|
|
2007-10-29 19:05:24 +00:00
|
|
|
#include "common/Timer.h"
|
2009-02-09 23:46:02 +00:00
|
|
|
#include "common/common_init.h"
|
2007-10-29 19:05:24 +00:00
|
|
|
|
2010-01-14 19:12:23 +00:00
|
|
|
extern const int ceph_mon_feature_compat_size;
|
|
|
|
extern const char *ceph_mon_feature_compat[];
|
|
|
|
extern const int ceph_mon_feature_ro_compat_size;
|
|
|
|
extern const char *ceph_mon_feature_ro_compat[];
|
|
|
|
extern const int ceph_mon_feature_incompat_size;
|
|
|
|
extern const char *ceph_mon_feature_incompat[];
|
|
|
|
|
2008-03-10 23:23:41 +00:00
|
|
|
void usage()
|
|
|
|
{
|
2009-03-11 21:58:58 +00:00
|
|
|
cerr << "usage: cmon -i monid [--mon-data=pathtodata] [flags]" << std::endl;
|
2009-03-10 22:22:52 +00:00
|
|
|
cerr << " --debug_mon n\n";
|
|
|
|
cerr << " debug monitor level (e.g. 10)\n";
|
|
|
|
generic_server_usage();
|
2008-03-10 23:23:41 +00:00
|
|
|
}
|
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);
|
2008-11-05 22:54:13 +00:00
|
|
|
env_to_vec(args);
|
2009-09-25 23:19:38 +00:00
|
|
|
common_init(args, "mon", true, true);
|
2007-10-29 19:05:24 +00:00
|
|
|
|
2009-03-11 21:58:58 +00:00
|
|
|
// whoami
|
|
|
|
char *end;
|
|
|
|
int whoami = strtol(g_conf.id, &end, 10);
|
|
|
|
if (*end || end == g_conf.id || whoami < 0) {
|
2009-03-12 16:33:16 +00:00
|
|
|
cerr << "must specify '-i #' where # is the mon number" << std::endl;
|
2009-03-11 21:58:58 +00:00
|
|
|
usage();
|
2007-10-29 19:05:24 +00:00
|
|
|
}
|
2009-02-28 01:11:10 +00:00
|
|
|
|
2009-03-11 21:58:58 +00:00
|
|
|
if (!g_conf.mon_data) {
|
|
|
|
cerr << "must specify '--mon-data=foo' data path" << std::endl;
|
2008-03-10 23:23:41 +00:00
|
|
|
usage();
|
2009-03-11 21:58:58 +00:00
|
|
|
}
|
2007-10-29 19:05:24 +00:00
|
|
|
|
|
|
|
if (g_conf.clock_tare) g_clock.tare();
|
|
|
|
|
2010-01-14 19:12:23 +00:00
|
|
|
CompatSet mon_features(ceph_mon_feature_compat, ceph_mon_feature_compat_size,
|
|
|
|
ceph_mon_feature_ro_compat,
|
|
|
|
ceph_mon_feature_ro_compat_size,
|
|
|
|
ceph_mon_feature_incompat,
|
|
|
|
ceph_mon_feature_incompat_size);
|
|
|
|
CompatSet ondisk_features;
|
|
|
|
|
2009-03-11 21:58:58 +00:00
|
|
|
MonitorStore store(g_conf.mon_data);
|
2008-03-10 23:23:41 +00:00
|
|
|
err = store.mount();
|
|
|
|
if (err < 0) {
|
2009-09-18 23:17:04 +00:00
|
|
|
char buf[80];
|
|
|
|
cerr << "problem opening monitor store in " << g_conf.mon_data << ": " << strerror_r(-err, buf, sizeof(buf)) << 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);
|
|
|
|
}
|
2009-03-11 21:58:58 +00:00
|
|
|
int w = store.get_int("whoami");
|
|
|
|
if (w != whoami) {
|
|
|
|
cerr << "monitor data is for mon" << w << ", but you said i was mon" << whoami << std::endl;
|
|
|
|
exit(1);
|
|
|
|
}
|
2008-03-10 23:23:41 +00:00
|
|
|
|
2008-11-21 00:59:08 +00:00
|
|
|
bufferlist magicbl;
|
|
|
|
store.get_bl_ss(magicbl, "magic", 0);
|
|
|
|
nstring magic(magicbl.length()-1, magicbl.c_str()); // ignore trailing \n
|
|
|
|
if (strcmp(magic.c_str(), CEPH_MON_ONDISK_MAGIC)) {
|
|
|
|
cerr << "mon fs magic '" << magic << "' != current '" << CEPH_MON_ONDISK_MAGIC << "'" << std::endl;
|
|
|
|
exit(1);
|
|
|
|
}
|
|
|
|
|
2010-01-14 19:12:23 +00:00
|
|
|
bufferlist features;
|
|
|
|
store.get_bl_ss(features, COMPAT_SET_LOC, 0);
|
|
|
|
if (features.length() == 0) {
|
2010-01-15 00:27:14 +00:00
|
|
|
cerr << "WARNING: mon fs missing feature list.\n"
|
|
|
|
<< "Assuming it is old-style and introducing one." << std::endl;
|
|
|
|
//we only want the baseline ~v.18 features assumed to be on disk.
|
|
|
|
//They'll be first in the incompat list.
|
|
|
|
ondisk_features = CompatSet(NULL, 0, NULL, 0,
|
|
|
|
ceph_mon_feature_incompat,
|
|
|
|
1);
|
|
|
|
} else {
|
|
|
|
bufferlist::iterator it = features.begin();
|
|
|
|
ondisk_features.decode(it);
|
2010-01-14 19:12:23 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (!mon_features.writeable(ondisk_features)) {
|
|
|
|
cerr << "monitor executable cannot read disk! Missing features: "
|
|
|
|
<< std::endl;
|
|
|
|
CompatSet diff = mon_features.unsupported(ondisk_features);
|
|
|
|
for (CompatSet::iterator iter = diff.begin(); iter != diff.end(); ++iter) {
|
|
|
|
cerr << *iter << std::endl;
|
|
|
|
}
|
|
|
|
exit(1);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2008-03-10 23:23:41 +00:00
|
|
|
// monmap?
|
2007-10-29 19:05:24 +00:00
|
|
|
MonMap monmap;
|
2009-10-11 04:26:53 +00:00
|
|
|
{
|
|
|
|
bufferlist latest;
|
|
|
|
store.get_bl_ss(latest, "monmap/latest", 0);
|
|
|
|
if (latest.length() == 0) {
|
|
|
|
cerr << "mon fs missing 'monmap'" << std::endl;
|
|
|
|
exit(1);
|
|
|
|
}
|
|
|
|
bufferlist::iterator p = latest.begin();
|
|
|
|
version_t v;
|
|
|
|
::decode(v, p);
|
|
|
|
bufferlist mapbl;
|
|
|
|
::decode(mapbl, p);
|
|
|
|
monmap.decode(mapbl);
|
|
|
|
assert(v == monmap.get_epoch());
|
|
|
|
}
|
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
|
|
|
}
|
|
|
|
|
2009-10-02 20:39:17 +00:00
|
|
|
entity_addr_t ipaddr = monmap.get_inst(whoami).addr;
|
2009-03-24 23:44:07 +00:00
|
|
|
entity_addr_t conf_addr;
|
|
|
|
char *mon_addr_str;
|
|
|
|
|
2009-10-02 20:39:17 +00:00
|
|
|
if (conf_read_key(NULL, "mon addr", OPT_STR, &mon_addr_str, NULL) &&
|
|
|
|
parse_ip_port(mon_addr_str, conf_addr, NULL) &&
|
|
|
|
ipaddr != conf_addr)
|
|
|
|
cerr << "WARNING: 'mon addr' config option does not match monmap file" << std::endl
|
|
|
|
<< " continuing with monmap configuration" << std::endl;
|
2009-03-24 23:44:07 +00:00
|
|
|
|
2008-03-10 23:23:41 +00:00
|
|
|
// bind
|
2010-01-08 00:53:51 +00:00
|
|
|
SimpleMessenger *messenger = new SimpleMessenger();
|
2009-05-01 14:11:46 +00:00
|
|
|
|
2008-03-10 23:23:41 +00:00
|
|
|
cout << "starting mon" << whoami
|
|
|
|
<< " at " << monmap.get_inst(whoami).addr
|
2009-03-12 17:56:37 +00:00
|
|
|
<< " mon_data " << g_conf.mon_data
|
|
|
|
<< " fsid " << monmap.get_fsid()
|
|
|
|
<< std::endl;
|
2008-03-10 23:23:41 +00:00
|
|
|
g_my_addr = monmap.get_inst(whoami).addr;
|
2010-01-08 00:53:51 +00:00
|
|
|
err = messenger->bind();
|
2008-03-10 23:23:41 +00:00
|
|
|
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
|
2010-01-08 00:53:51 +00:00
|
|
|
messenger->register_entity(entity_name_t::MON(whoami));
|
|
|
|
messenger->set_default_send_priority(CEPH_MSG_PRIO_HIGH);
|
|
|
|
Monitor *mon = new Monitor(whoami, &store, messenger, &monmap);
|
2007-10-29 19:05:24 +00:00
|
|
|
|
2010-01-08 00:53:51 +00:00
|
|
|
messenger->start(); // may daemonize
|
2008-04-09 17:42:46 +00:00
|
|
|
|
2010-01-08 00:53:51 +00:00
|
|
|
messenger->set_default_policy(SimpleMessenger::Policy::stateless_server());
|
|
|
|
messenger->set_policy(entity_name_t::TYPE_MON, SimpleMessenger::Policy::lossless_peer());
|
2008-10-13 18:56:31 +00:00
|
|
|
|
2008-03-10 23:23:41 +00:00
|
|
|
mon->init();
|
2010-01-08 00:53:51 +00:00
|
|
|
messenger->wait();
|
2007-10-29 19:05:24 +00:00
|
|
|
|
2008-03-10 23:23:41 +00:00
|
|
|
store.umount();
|
2007-10-29 19:05:24 +00:00
|
|
|
delete mon;
|
2010-01-08 00:53:51 +00:00
|
|
|
messenger->destroy();
|
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);
|
|
|
|
|
2007-10-29 19:05:24 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|