~ubuntu-branches/ubuntu/precise/ceph/precise-proposed

« back to all changes in this revision

Viewing changes to src/cmds.cc

  • Committer: Bazaar Package Importer
  • Author(s): Laszlo Boszormenyi (GCS)
  • Date: 2011-04-25 10:09:05 UTC
  • mfrom: (1.1.3 upstream) (0.1.5 sid)
  • Revision ID: james.westby@ubuntu.com-20110425100905-exm7dfvi2v5ick02
Tags: 0.27-1
New upstream release.

Show diffs side-by-side

added added

removed removed

Lines of Context:
21
21
#include <string>
22
22
using namespace std;
23
23
 
24
 
#include "config.h"
 
24
#include "common/config.h"
25
25
 
26
26
#include "mon/MonMap.h"
27
27
#include "mds/MDS.h"
28
28
#include "mds/Dumper.h"
 
29
#include "mds/Resetter.h"
29
30
 
30
31
#include "msg/SimpleMessenger.h"
31
32
 
32
33
#include "common/Timer.h"
33
34
#include "common/common_init.h"
 
35
#include "common/ceph_argparse.h"
34
36
 
35
37
#include "mon/MonClient.h"
36
38
 
38
40
 
39
41
void usage()
40
42
{
41
 
  cerr << "usage: cmds -i name [flags] [--mds rank] [--journal_check]\n";
42
 
  cerr << "  -m monitorip:port\n";
43
 
  cerr << "        connect to monitor at given address\n";
44
 
  cerr << "  --debug_mds n\n";
45
 
  cerr << "        debug MDS level (e.g. 10)\n";
 
43
  derr << "usage: cmds -i name [flags] [[--journal_check rank]|[--hot-standby][rank]]\n"
 
44
       << "  -m monitorip:port\n"
 
45
       << "        connect to monitor at given address\n"
 
46
       << "  --debug_mds n\n"
 
47
       << "        debug MDS level (e.g. 10)\n"
 
48
       << "  --dump-journal rank filename\n"
 
49
       << "        dump the MDS journal for rank. Defaults to mds.journal.dump\n"
 
50
       << "  --journal-check rank\n"
 
51
       << "        replay the journal for rank, then exit\n"
 
52
       << "  --hot-standby rank\n"
 
53
       << "        stat up as a hot standby for rank\n"
 
54
       << "  --reset-journal rank\n"
 
55
       << "        discard the MDS journal for rank, and replace it with a single\n"
 
56
       << "        event that updates/resets inotable and sessionmap on replay.\n"
 
57
       << dendl;
46
58
  generic_server_usage();
47
59
}
48
60
 
49
61
int main(int argc, const char **argv) 
50
62
{
 
63
  DEFINE_CONF_VARS(usage);
51
64
  vector<const char*> args;
52
65
  argv_to_vec(argc, argv, args);
53
66
  env_to_vec(args);
54
 
  bool dump_journal = false;
 
67
 
 
68
  common_init(args, CEPH_ENTITY_TYPE_MDS, CODE_ENVIRONMENT_DAEMON, 0);
 
69
  keyring_init(&g_conf);
 
70
 
 
71
  // mds specific args
 
72
  int shadow = 0;
 
73
  int dump_journal = -1;
55
74
  const char *dump_file = NULL;
56
 
  bool shadow = false;
57
 
 
58
 
  common_set_defaults(true);
59
 
#ifdef HAVE_LIBTCMALLOC
60
 
  g_conf.profiler_start = HeapProfilerStart;
61
 
  g_conf.profiler_running = IsHeapProfilerRunning;
62
 
  g_conf.profiler_stop = HeapProfilerStop;
63
 
  g_conf.profiler_dump = HeapProfilerDump;
64
 
  g_conf.tcmalloc_have = true;
65
 
#endif //HAVE_LIBTCMALLOC
66
 
  common_init(args, "mds", true);
67
 
 
68
 
  // mds specific args
69
 
  for (unsigned i=0; i<args.size(); i++) {
70
 
    if (!strcmp(args[i], "--dump-journal")) {
71
 
      if (i + 1 < args.size() &&
72
 
          (args[i+1][0] != '-')) { // another argument?
73
 
        dump_file = args[i+1];
74
 
        ++i;
75
 
      } else
76
 
        dump_file = "mds.journal.dump";
77
 
      dump_journal = true;
78
 
      dout(0) << "dumping journal" << dendl;
79
 
    } else if (!strcmp(args[i], "--journal_check")) {
80
 
      dout(0) << "checking journal"  << dendl;
81
 
      shadow = true;
 
75
  int reset_journal = -1;
 
76
  FOR_EACH_ARG(args) {
 
77
    if (CEPH_ARGPARSE_EQ("dump-journal", '\0')) {
 
78
      CEPH_ARGPARSE_SET_ARG_VAL(&dump_journal, OPT_INT);
 
79
      CEPH_ARGPARSE_SET_ARG_VAL(&dump_file, OPT_STR);
 
80
      dout(0) << "dumping journal for mds" << dump_journal << " to " << dump_file << dendl;
 
81
    } else if (CEPH_ARGPARSE_EQ("reset-journal", '\0')) {
 
82
      CEPH_ARGPARSE_SET_ARG_VAL(&reset_journal, OPT_INT);
 
83
    } else if (CEPH_ARGPARSE_EQ("journal-check", '\0')) {
 
84
      int check_rank;
 
85
      CEPH_ARGPARSE_SET_ARG_VAL(&check_rank, OPT_INT);
 
86
      
 
87
      if (shadow) {
 
88
        dout(0) << "Error: can only select one standby state" << dendl;
 
89
        return -1;
 
90
      }
 
91
      dout(0) << "requesting oneshot_replay for mds" << check_rank << dendl;
 
92
      shadow = MDSMap::STATE_ONESHOT_REPLAY;
 
93
      g_conf.mds_standby_for_rank = check_rank;
 
94
      ++i;
 
95
    } else if (CEPH_ARGPARSE_EQ("hot-standby", '\0')) {
 
96
      int check_rank;
 
97
      CEPH_ARGPARSE_SET_ARG_VAL(&check_rank, OPT_INT);
 
98
      if (shadow) {
 
99
        dout(0) << "Error: can only select one standby state" << dendl;
 
100
        return -1;
 
101
      }
 
102
      dout(0) << "requesting standby_replay for mds" << check_rank << dendl;
 
103
      shadow = MDSMap::STATE_STANDBY_REPLAY;
 
104
      g_conf.mds_standby_for_rank = check_rank;
82
105
    } else {
83
 
      cerr << "unrecognized arg " << args[i] << std::endl;
 
106
      derr << "unrecognized arg " << args[i] << dendl;
84
107
      usage();
85
108
    }
86
109
  }
87
 
  if (!g_conf.id) {
88
 
    cerr << "must specify '-i name' with the cmds instance name" << std::endl;
 
110
  if (g_conf.name.has_default_id() && dump_journal < 0 && reset_journal < 0) {
 
111
    derr << "must specify '-i name' with the cmds instance name" << dendl;
89
112
    usage();
90
113
  }
91
114
 
92
 
  if (g_conf.clock_tare) g_clock.tare();
93
 
 
94
115
  // get monmap
95
116
  RotatingKeyRing rkeys(CEPH_ENTITY_TYPE_MDS, &g_keyring);
96
117
  MonClient mc(&rkeys);
98
119
    return -1;
99
120
 
100
121
  SimpleMessenger *messenger = new SimpleMessenger();
101
 
  messenger->bind();
102
 
  if (dump_journal) {
 
122
  messenger->bind(getpid());
 
123
  if (dump_journal >= 0) {
103
124
    Dumper *journal_dumper = new Dumper(messenger, &mc);
104
 
    journal_dumper->init();
 
125
    journal_dumper->init(dump_journal);
105
126
    journal_dumper->dump(dump_file);
106
127
    mc.shutdown();
 
128
  } else if (reset_journal >= 0) {
 
129
    Resetter *jr = new Resetter(messenger, &mc);
 
130
    jr->init(reset_journal);
 
131
    jr->reset();
 
132
    mc.shutdown();
107
133
  } else {
108
 
    cout << "starting mds." << g_conf.id
109
 
        << " at " << messenger->get_ms_addr()
110
 
        << std::endl;
 
134
    cout << "starting " << g_conf.name << " at " << messenger->get_ms_addr()
 
135
         << std::endl;
111
136
 
112
137
    messenger->register_entity(entity_name_t::MDS(-1));
113
138
    assert_warn(messenger);
128
153
    messenger->set_policy(entity_name_t::TYPE_CLIENT,
129
154
                          SimpleMessenger::Policy::stateful_server(supported, 0));
130
155
 
131
 
    messenger->start();
 
156
    messenger->start(g_conf.daemonize);
132
157
 
133
158
    // start mds
134
 
    MDS *mds = new MDS(g_conf.id, messenger, &mc);
 
159
    MDS *mds = new MDS(g_conf.name.get_id().c_str(), messenger, &mc);
135
160
 
136
161
    // in case we have to respawn...
137
162
    mds->orig_argc = argc;
138
163
    mds->orig_argv = argv;
139
164
 
140
165
    if (shadow)
141
 
      mds->init(MDSMap::STATE_STANDBY);
 
166
      mds->init(shadow);
142
167
    else
143
168
      mds->init();
144
169
 
157
182
    // cd on exit, so that gmon.out (if any) goes into a separate directory for each node.
158
183
    char s[20];
159
184
    snprintf(s, sizeof(s), "gmon/%d", getpid());
160
 
    if (mkdir(s, 0755) == 0)
161
 
      chdir(s);
 
185
    if ((mkdir(s, 0755) == 0) && (chdir(s) == 0)) {
 
186
      dout(0) << "cmds: gmon.out should be in " << s << dendl;
 
187
    }
162
188
 
163
189
    generic_dout(0) << "stopped." << dendl;
164
190
  }