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"
|
2008-03-10 05:32:16 +00:00
|
|
|
#include "mon/MonClient.h"
|
2007-10-17 23:34:54 +00:00
|
|
|
|
|
|
|
#include "osd/OSD.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
|
|
|
|
2009-04-28 18:02:55 +00:00
|
|
|
#include "include/color.h"
|
|
|
|
|
2008-03-11 01:36:50 +00:00
|
|
|
void usage()
|
|
|
|
{
|
2009-11-18 18:49:38 +00:00
|
|
|
cerr << "usage: cosd -i osdid [--osd-data=path] [--osd-journal=path] [--mkfs] [--mkjournal]" << std::endl;
|
2008-03-11 01:36:50 +00:00
|
|
|
cerr << " --debug_osd N set debug level (e.g. 10)" << std::endl;
|
2009-03-10 22:22:52 +00:00
|
|
|
generic_server_usage();
|
2008-03-11 01:36:50 +00:00
|
|
|
}
|
|
|
|
|
2007-10-17 23:34:54 +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
|
|
|
{
|
2009-03-12 23:08:13 +00:00
|
|
|
DEFINE_CONF_VARS(usage);
|
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-10-01 20:54:21 +00:00
|
|
|
bool should_authenticate = true;
|
|
|
|
vector<const char *>::iterator args_iter;
|
|
|
|
|
|
|
|
for (args_iter = args.begin(); args_iter != args.end(); ++args_iter) {
|
|
|
|
if (strcmp(*args_iter, "--mkfs") == 0) {
|
|
|
|
should_authenticate = false;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
common_init(args, "osd", true, should_authenticate);
|
2007-10-17 23:34:54 +00:00
|
|
|
|
|
|
|
if (g_conf.clock_tare) g_clock.tare();
|
|
|
|
|
|
|
|
// osd specific args
|
2009-11-18 18:49:38 +00:00
|
|
|
bool mkfs = false;
|
|
|
|
bool mkjournal = false;
|
2010-05-20 17:58:56 +00:00
|
|
|
bool flushjournal = false;
|
2009-03-12 23:08:13 +00:00
|
|
|
FOR_EACH_ARG(args) {
|
|
|
|
if (CONF_ARG_EQ("mkfs", '\0')) {
|
2009-11-18 18:49:38 +00:00
|
|
|
mkfs = true;
|
|
|
|
} else if (CONF_ARG_EQ("mkjournal", '\0')) {
|
|
|
|
mkjournal = true;
|
2010-05-20 17:58:56 +00:00
|
|
|
} else if (CONF_ARG_EQ("flush-journal", '\0')) {
|
|
|
|
flushjournal = true;
|
2009-03-12 23:08:13 +00:00
|
|
|
} else {
|
2007-10-17 23:34:54 +00:00
|
|
|
cerr << "unrecognized arg " << args[i] << std::endl;
|
2009-03-12 23:08:13 +00:00
|
|
|
ARGS_USAGE();
|
2007-10-17 23:34:54 +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) {
|
|
|
|
cerr << "must specify '-i #' where # is the osd number" << std::endl;
|
2008-03-11 01:36:50 +00:00
|
|
|
usage();
|
2007-10-17 23:34:54 +00:00
|
|
|
}
|
|
|
|
|
2009-03-11 21:58:58 +00:00
|
|
|
if (!g_conf.osd_data) {
|
|
|
|
cerr << "must specify '--osd-data=foo' data path" << std::endl;
|
2008-03-11 01:36:50 +00:00
|
|
|
usage();
|
|
|
|
}
|
2008-01-25 20:04:31 +00:00
|
|
|
|
2009-03-30 20:01:22 +00:00
|
|
|
_dout_create_courtesy_output_symlink("osd", whoami);
|
|
|
|
|
2008-03-10 05:32:16 +00:00
|
|
|
// get monmap
|
2010-02-04 21:48:23 +00:00
|
|
|
RotatingKeyRing rkeys(CEPH_ENTITY_TYPE_OSD, &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)
|
|
|
|
return -1;
|
2007-10-17 23:34:54 +00:00
|
|
|
|
2009-09-18 23:17:04 +00:00
|
|
|
char buf[80];
|
2008-03-11 01:36:50 +00:00
|
|
|
if (mkfs) {
|
2010-02-12 00:18:54 +00:00
|
|
|
if (mc.get_monmap_privately() < 0)
|
|
|
|
return -1;
|
|
|
|
|
2009-06-26 20:49:12 +00:00
|
|
|
int err = OSD::mkfs(g_conf.osd_data, g_conf.osd_journal, mc.monmap.fsid, whoami);
|
2008-03-11 01:36:50 +00:00
|
|
|
if (err < 0) {
|
2010-05-20 17:58:56 +00:00
|
|
|
cerr << "error creating empty object store in " << g_conf.osd_data
|
|
|
|
<< ": " << strerror_r(-err, buf, sizeof(buf)) << std::endl;
|
2008-03-11 01:36:50 +00:00
|
|
|
exit(1);
|
|
|
|
}
|
2010-05-20 17:58:56 +00:00
|
|
|
cout << "created object store " << g_conf.osd_data;
|
|
|
|
if (g_conf.osd_journal)
|
|
|
|
cout << " journal " << g_conf.osd_journal;
|
|
|
|
cout << " for osd" << whoami << " fsid " << mc.monmap.fsid << std::endl;
|
2008-03-11 01:36:50 +00:00
|
|
|
exit(0);
|
|
|
|
}
|
2010-05-20 17:58:56 +00:00
|
|
|
if (mkjournal) {
|
|
|
|
int err = OSD::mkjournal(g_conf.osd_data, g_conf.osd_journal);
|
|
|
|
if (err < 0) {
|
|
|
|
cerr << "error creating fresh journal " << g_conf.osd_journal
|
|
|
|
<< " for object store " << g_conf.osd_data
|
|
|
|
<< ": " << strerror_r(-err, buf, sizeof(buf)) << std::endl;
|
|
|
|
exit(1);
|
|
|
|
}
|
|
|
|
cout << "created new journal " << g_conf.osd_journal
|
|
|
|
<< " for object store " << g_conf.osd_data
|
|
|
|
<< std::endl;
|
|
|
|
exit(0);
|
|
|
|
}
|
|
|
|
if (flushjournal) {
|
|
|
|
int err = OSD::flushjournal(g_conf.osd_data, g_conf.osd_journal);
|
|
|
|
if (err < 0) {
|
|
|
|
cerr << "error flushing journal " << g_conf.osd_journal
|
|
|
|
<< " for object store " << g_conf.osd_data
|
|
|
|
<< ": " << strerror_r(-err, buf, sizeof(buf)) << std::endl;
|
|
|
|
exit(1);
|
|
|
|
}
|
|
|
|
cout << "flushed journal " << g_conf.osd_journal
|
|
|
|
<< " for object store " << g_conf.osd_data
|
|
|
|
<< std::endl;
|
|
|
|
exit(0);
|
|
|
|
}
|
|
|
|
|
2010-04-28 20:45:55 +00:00
|
|
|
string magic;
|
2009-03-11 21:58:58 +00:00
|
|
|
ceph_fsid_t fsid;
|
|
|
|
int w;
|
2010-02-09 04:29:09 +00:00
|
|
|
int r = OSD::peek_meta(g_conf.osd_data, magic, fsid, w);
|
2009-03-11 21:58:58 +00:00
|
|
|
if (r < 0) {
|
2009-04-28 18:02:55 +00:00
|
|
|
cerr << TEXT_RED << " ** " << TEXT_HAZARD << "ERROR: " << TEXT_RED
|
2009-09-18 23:17:04 +00:00
|
|
|
<< "unable to open OSD superblock on " << g_conf.osd_data << ": " << strerror_r(-r, buf, sizeof(buf)) << TEXT_NORMAL << std::endl;
|
2009-03-30 20:01:22 +00:00
|
|
|
if (r == -ENOTSUP)
|
2009-04-28 18:02:55 +00:00
|
|
|
cerr << TEXT_RED << " ** please verify that underlying storage supports xattrs" << TEXT_NORMAL << std::endl;
|
2009-09-18 23:17:04 +00:00
|
|
|
derr(0) << "unable to open OSD superblock on " << g_conf.osd_data << ": " << strerror_r(-r, buf, sizeof(buf)) << dendl;
|
2009-03-11 21:58:58 +00:00
|
|
|
exit(1);
|
|
|
|
}
|
|
|
|
if (w != whoami) {
|
|
|
|
cerr << "OSD id " << w << " != my id " << whoami << std::endl;
|
|
|
|
exit(1);
|
|
|
|
}
|
|
|
|
if (strcmp(magic.c_str(), CEPH_OSD_ONDISK_MAGIC)) {
|
|
|
|
cerr << "OSD magic " << magic << " != my " << CEPH_OSD_ONDISK_MAGIC << std::endl;
|
|
|
|
exit(1);
|
|
|
|
}
|
2009-12-04 22:37:28 +00:00
|
|
|
|
2010-01-08 00:53:51 +00:00
|
|
|
SimpleMessenger *messenger = new SimpleMessenger();
|
|
|
|
SimpleMessenger *messenger_hb = new SimpleMessenger();
|
|
|
|
messenger->bind();
|
|
|
|
messenger_hb->bind();
|
2008-01-26 17:33:13 +00:00
|
|
|
|
|
|
|
cout << "starting osd" << whoami
|
2010-01-08 00:53:51 +00:00
|
|
|
<< " at " << messenger->get_ms_addr()
|
2009-03-12 17:56:37 +00:00
|
|
|
<< " osd_data " << g_conf.osd_data
|
|
|
|
<< " " << ((g_conf.osd_journal && g_conf.osd_journal[0]) ? g_conf.osd_journal:"(no journal)")
|
2008-01-26 17:33:13 +00:00
|
|
|
<< std::endl;
|
|
|
|
|
2010-01-08 00:53:51 +00:00
|
|
|
messenger->register_entity(entity_name_t::OSD(whoami));
|
|
|
|
if (!messenger)
|
2009-02-13 00:47:56 +00:00
|
|
|
return 1;
|
2010-01-08 00:53:51 +00:00
|
|
|
messenger_hb->register_entity(entity_name_t::OSD(whoami));
|
|
|
|
if (!messenger_hb)
|
2009-02-13 00:47:56 +00:00
|
|
|
return 1;
|
2007-10-17 23:34:54 +00:00
|
|
|
|
2010-06-04 20:37:25 +00:00
|
|
|
Throttle *client_throttler = new Throttle(g_conf.osd_client_message_size_cap);
|
2010-06-04 19:04:08 +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::client());
|
|
|
|
messenger->set_policy(entity_name_t::TYPE_OSD, SimpleMessenger::Policy::lossless_peer());
|
2010-06-04 19:04:08 +00:00
|
|
|
messenger->set_policy(entity_name_t::TYPE_CLIENT, SimpleMessenger::Policy(true, true, client_throttler));
|
2008-10-13 18:56:31 +00:00
|
|
|
|
2010-02-12 19:20:30 +00:00
|
|
|
|
2010-05-20 17:58:56 +00:00
|
|
|
OSD *osd = new OSD(whoami, messenger, messenger_hb, &mc, g_conf.osd_data, g_conf.osd_journal);
|
2010-02-12 19:20:30 +00:00
|
|
|
|
|
|
|
int err = osd->pre_init();
|
|
|
|
if (err < 0) {
|
|
|
|
char buf[80];
|
|
|
|
cerr << "error initializing osd: " << strerror_r(-err, buf, sizeof(buf)) << std::endl;
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
2010-01-08 00:53:51 +00:00
|
|
|
messenger->start();
|
|
|
|
messenger_hb->start(true); // only need to daemon() once
|
2008-11-13 18:40:11 +00:00
|
|
|
|
2007-10-17 23:34:54 +00:00
|
|
|
// start osd
|
2009-02-12 23:05:12 +00:00
|
|
|
if (osd->init() < 0) {
|
2010-02-12 19:20:30 +00:00
|
|
|
cout << "error starting osd" << std::endl;
|
2009-02-12 23:05:12 +00:00
|
|
|
return 1;
|
|
|
|
}
|
2007-10-17 23:34:54 +00:00
|
|
|
|
2010-01-08 00:53:51 +00:00
|
|
|
messenger->wait();
|
|
|
|
messenger_hb->wait();
|
2007-10-17 23:34:54 +00:00
|
|
|
// done
|
|
|
|
delete osd;
|
2010-01-08 00:53:51 +00:00
|
|
|
messenger->destroy();
|
|
|
|
messenger_hb->destroy();
|
2010-06-04 19:04:08 +00:00
|
|
|
delete client_throttler;
|
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-17 23:34:54 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|