From: Sage Weil Date: Mon, 15 Dec 2008 19:15:55 +0000 (-0800) Subject: rename cmonctl -> ceph X-Git-Tag: v0.6~66 X-Git-Url: http://git-server-git.apps.pok.os.sepia.ceph.com/?a=commitdiff_plain;h=8b0bd3ea172390d28928211b742390bb4df0fd24;p=ceph.git rename cmonctl -> ceph --- diff --git a/src/.gitignore b/src/.gitignore index 429ad7333dc..aeb04a87f00 100644 --- a/src/.gitignore +++ b/src/.gitignore @@ -1,7 +1,7 @@ cfuse cmds cmon -cmonctl +ceph cosd csyn dupstore diff --git a/src/Makefile.am b/src/Makefile.am index b0d7d66dc92..42e1ab11d6c 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -11,8 +11,8 @@ cmon_LDADD = libcommon.a libmon.a libcrush.a libcommon.a # admin tools cobserver_SOURCES = cobserver.cc msg/SimpleMessenger.cc cobserver_LDADD = libcrush.a libcommon.a -cmonctl_SOURCES = cmonctl.cc msg/SimpleMessenger.cc -cmonctl_LDADD = libcommon.a -ledit +ceph_SOURCES = ceph.cc msg/SimpleMessenger.cc +ceph_LDADD = libcommon.a -ledit mkmonfs_SOURCES = mkmonfs.cc mkmonfs_LDADD = libcommon.a libmon.a libcrush.a libcommon.a monmaptool_SOURCES = monmaptool.cc @@ -43,7 +43,7 @@ csyn_LDADD = libcommon.a libclient.a libosdc.a libcrush.a libcommon.a bin_PROGRAMS = \ cmon cmds cosd csyn \ - cmonctl cobserver \ + ceph cobserver \ mkmonfs monmaptool osdmaptool crushtool \ streamtest dupstore dumpjournal testmsgr diff --git a/src/ceph.cc b/src/ceph.cc new file mode 100644 index 00000000000..323fd6dc0fb --- /dev/null +++ b/src/ceph.cc @@ -0,0 +1,390 @@ +// -*- 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 + * + * 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 +#include +#include +using namespace std; + +#include "config.h" + +#include "mon/MonMap.h" +#include "mon/MonClient.h" +#include "msg/SimpleMessenger.h" +#include "messages/MMonCommand.h" +#include "messages/MMonCommandAck.h" + +#include "common/Timer.h" + +#ifndef DARWIN +#include +#endif // DARWIN + +#include +#include +#include + +extern "C" { +#include +} + + + +Mutex lock("ceph.cc lock"); +Cond cond; + +Messenger *messenger = 0; + +const char *outfile = 0; +int watch = 0; + +MonMap monmap; + +// sync command +vector pending_cmd; +bufferlist pending_bl; +bool reply; +string reply_rs; +int reply_rc; +bufferlist reply_bl; +entity_inst_t reply_from; +Context *resend_event = 0; + + +// watch +enum { OSD, MON, MDS, CLIENT, LAST }; +int which = 0; +int same = 0; +const char *prefix[4] = { "mds", "osd", "pg", "client" }; +map status; + +int lines = 0; + +// refresh every second +void get_status(bool newmon=false); + +struct C_Refresh : public Context { + void finish(int r) { + get_status(true); + } +}; + +SafeTimer timer(lock); +Context *event = 0; + +void get_status(bool newmon) +{ + int mon = monmap.pick_mon(newmon); + + vector vcmd(2); + vcmd[0] = prefix[which]; + vcmd[1] = "stat"; + + MMonCommand *m = new MMonCommand(monmap.fsid); + m->cmd.swap(vcmd); + messenger->send_message(m, monmap.get_inst(mon)); + + event = new C_Refresh; + timer.add_event_after(.2, event); +} + + +void handle_ack(MMonCommandAck *ack) +{ + if (watch) { + lock.Lock(); + + which++; + which = which % LAST; + + string w = ack->cmd[0]; + if (ack->rs != status[w]) { + status[w] = ack->rs; + generic_dout(0) << w << " " << status[w] << dendl; + lines++; + + if (lines > 20) { + generic_dout(0) << dendl; + for (map::iterator p = status.begin(); p != status.end(); p++) + generic_dout(0) << p->first << " " << p->second << dendl; + generic_dout(0) << dendl; + lines = 0; + } + + if (event) + timer.cancel_event(event); + get_status(); + } + + lock.Unlock(); + } else { + lock.Lock(); + reply = true; + reply_from = ack->get_source_inst(); + reply_rs = ack->rs; + reply_rc = ack->r; + reply_bl = ack->get_data(); + cond.Signal(); + if (resend_event) { + timer.cancel_event(resend_event); + resend_event = 0; + } + lock.Unlock(); + } +} + +class Admin : public Dispatcher { + bool dispatch_impl(Message *m) { + switch (m->get_type()) { + case MSG_MON_COMMAND_ACK: + handle_ack((MMonCommandAck*)m); + break; + default: + return false; + } + return true; + } +} dispatcher; + +void send_command(); + +struct C_Resend : public Context { + void finish(int) { + monmap.pick_mon(true); // pick a new mon + if (!reply) + send_command(); + } +}; +void send_command() +{ + MMonCommand *m = new MMonCommand(monmap.fsid); + m->cmd = pending_cmd; + m->get_data() = pending_bl; + + int mon = monmap.pick_mon(); + generic_dout(0) << "mon" << mon << " <- " << pending_cmd << dendl; + messenger->send_message(m, monmap.get_inst(mon)); + + resend_event = new C_Resend; + timer.add_event_after(5.0, resend_event); +} + +int do_command(vector& cmd, bufferlist& bl, string& rs, bufferlist& rbl) +{ + Mutex::Locker l(lock); + + pending_cmd = cmd; + pending_bl = bl; + reply = false; + + send_command(); + + while (!reply) + cond.Wait(lock); + + rs = rs; + rbl = reply_bl; + generic_dout(0) << reply_from.name << " -> '" + << reply_rs << "' (" << reply_rc << ")" + << dendl; + + return reply_rc; +} + + + +void usage() +{ + cerr << "usage: ceph [options] monhost] command" << std::endl; + cerr << "Options:" << std::endl; + cerr << " -m monhost -- specify monitor hostname or ip" << std::endl; + cerr << " -i infile -- specify input file" << std::endl; + cerr << " -o outfile -- specify output file" << std::endl; + cerr << " -w or --watch -- watch mds, osd, pg status" << std::endl; + cerr << "Commands:" << std::endl; + cerr << " stop -- cleanly shut down file system" << std::endl + << " (osd|pg|mds) stat -- get monitor subsystem status" << std::endl + << " ..." << std::endl; + exit(1); +} + + +const char *cli_prompt(EditLine *e) { + return "monctl> "; +} + +int do_cli() +{ + /* emacs style */ + EditLine *el = el_init("ceph", stdin, stdout, stderr); + el_set(el, EL_PROMPT, &cli_prompt); + el_set(el, EL_EDITOR, "emacs"); + + History *myhistory = history_init(); + if (myhistory == 0) { + fprintf(stderr, "history could not be initialized\n"); + return 1; + } + + HistEvent ev; + + /* Set the size of the history */ + history(myhistory, &ev, H_SETSIZE, 800); + + /* This sets up the call back functions for history functionality */ + el_set(el, EL_HIST, history, myhistory); + + Tokenizer *tok = tok_init(NULL); + + while (1) { + int count; // # chars read + const char *line = el_gets(el, &count); + + if (!count) { + cout << "quit" << std::endl; + break; + } + + //cout << "typed '" << line << "'" << std::endl; + + if (strcmp(line, "quit\n") == 0) + break; + + history(myhistory, &ev, H_ENTER, line); + + int argc; + const char **argv; + tok_str(tok, line, &argc, &argv); + tok_reset(tok); + + vector cmd; + for (int i=0; i args; + argv_to_vec(argc, argv, args); + env_to_vec(args); + parse_config_options(args); + + vec_to_argv(args, argc, argv); + + srand(getpid()); + + bufferlist indata; + vector nargs; + for (unsigned i=0; i vcmd; + string cmd; + if (!watch) { + for (unsigned i=0; iset_dispatcher(&dispatcher); + + rank.start(); + rank.set_policy(entity_name_t::TYPE_MON, Rank::Policy::lossy_fail_after(1.0)); + + if (watch) { + lock.Lock(); + get_status(); + lock.Unlock(); + } else { + if (vcmd.size()) { + + string rs; + bufferlist odata; + do_command(vcmd, indata, rs, odata); + + int len = odata.length(); + if (len) { + if (outfile) { + if (strcmp(outfile, "-") == 0) { + ::write(1, odata.c_str(), len); + } else { + odata.write_file(outfile); + } + generic_dout(0) << "wrote " << len << " byte payload to " << outfile << dendl; + } else { + generic_dout(0) << "got " << len << " byte payload, discarding (specify -o shutdown(); + } + + + // wait for messenger to finish + rank.wait(); + messenger->destroy(); + return 0; +} + diff --git a/src/cmonctl b/src/cmonctl new file mode 100755 index 00000000000..a494148ce46 --- /dev/null +++ b/src/cmonctl @@ -0,0 +1,3 @@ +#!/bin/sh + +echo "*** cmonctl has been renamed ceph ***" diff --git a/src/cmonctl.cc b/src/cmonctl.cc deleted file mode 100644 index e35b85ff2a4..00000000000 --- a/src/cmonctl.cc +++ /dev/null @@ -1,390 +0,0 @@ -// -*- 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 - * - * 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 -#include -#include -using namespace std; - -#include "config.h" - -#include "mon/MonMap.h" -#include "mon/MonClient.h" -#include "msg/SimpleMessenger.h" -#include "messages/MMonCommand.h" -#include "messages/MMonCommandAck.h" - -#include "common/Timer.h" - -#ifndef DARWIN -#include -#endif // DARWIN - -#include -#include -#include - -extern "C" { -#include -} - - - -Mutex lock("cmonctl.cc lock"); -Cond cond; - -Messenger *messenger = 0; - -const char *outfile = 0; -int watch = 0; - -MonMap monmap; - -// sync command -vector pending_cmd; -bufferlist pending_bl; -bool reply; -string reply_rs; -int reply_rc; -bufferlist reply_bl; -entity_inst_t reply_from; -Context *resend_event = 0; - - -// watch -enum { OSD, MON, MDS, CLIENT, LAST }; -int which = 0; -int same = 0; -const char *prefix[4] = { "mds", "osd", "pg", "client" }; -map status; - -int lines = 0; - -// refresh every second -void get_status(bool newmon=false); - -struct C_Refresh : public Context { - void finish(int r) { - get_status(true); - } -}; - -SafeTimer timer(lock); -Context *event = 0; - -void get_status(bool newmon) -{ - int mon = monmap.pick_mon(newmon); - - vector vcmd(2); - vcmd[0] = prefix[which]; - vcmd[1] = "stat"; - - MMonCommand *m = new MMonCommand(monmap.fsid); - m->cmd.swap(vcmd); - messenger->send_message(m, monmap.get_inst(mon)); - - event = new C_Refresh; - timer.add_event_after(.2, event); -} - - -void handle_ack(MMonCommandAck *ack) -{ - if (watch) { - lock.Lock(); - - which++; - which = which % LAST; - - string w = ack->cmd[0]; - if (ack->rs != status[w]) { - status[w] = ack->rs; - generic_dout(0) << w << " " << status[w] << dendl; - lines++; - - if (lines > 20) { - generic_dout(0) << dendl; - for (map::iterator p = status.begin(); p != status.end(); p++) - generic_dout(0) << p->first << " " << p->second << dendl; - generic_dout(0) << dendl; - lines = 0; - } - - if (event) - timer.cancel_event(event); - get_status(); - } - - lock.Unlock(); - } else { - lock.Lock(); - reply = true; - reply_from = ack->get_source_inst(); - reply_rs = ack->rs; - reply_rc = ack->r; - reply_bl = ack->get_data(); - cond.Signal(); - if (resend_event) { - timer.cancel_event(resend_event); - resend_event = 0; - } - lock.Unlock(); - } -} - -class Admin : public Dispatcher { - bool dispatch_impl(Message *m) { - switch (m->get_type()) { - case MSG_MON_COMMAND_ACK: - handle_ack((MMonCommandAck*)m); - break; - default: - return false; - } - return true; - } -} dispatcher; - -void send_command(); - -struct C_Resend : public Context { - void finish(int) { - monmap.pick_mon(true); // pick a new mon - if (!reply) - send_command(); - } -}; -void send_command() -{ - MMonCommand *m = new MMonCommand(monmap.fsid); - m->cmd = pending_cmd; - m->get_data() = pending_bl; - - int mon = monmap.pick_mon(); - generic_dout(0) << "mon" << mon << " <- " << pending_cmd << dendl; - messenger->send_message(m, monmap.get_inst(mon)); - - resend_event = new C_Resend; - timer.add_event_after(5.0, resend_event); -} - -int do_command(vector& cmd, bufferlist& bl, string& rs, bufferlist& rbl) -{ - Mutex::Locker l(lock); - - pending_cmd = cmd; - pending_bl = bl; - reply = false; - - send_command(); - - while (!reply) - cond.Wait(lock); - - rs = rs; - rbl = reply_bl; - generic_dout(0) << reply_from.name << " -> '" - << reply_rs << "' (" << reply_rc << ")" - << dendl; - - return reply_rc; -} - - - -void usage() -{ - cerr << "usage: cmonctl [options] monhost] command" << std::endl; - cerr << "Options:" << std::endl; - cerr << " -m monhost -- specify monitor hostname or ip" << std::endl; - cerr << " -i infile -- specify input file" << std::endl; - cerr << " -o outfile -- specify output file" << std::endl; - cerr << " -w or --watch -- watch mds, osd, pg status" << std::endl; - cerr << "Commands:" << std::endl; - cerr << " stop -- cleanly shut down file system" << std::endl - << " (osd|pg|mds) stat -- get monitor subsystem status" << std::endl - << " ..." << std::endl; - exit(1); -} - - -const char *cli_prompt(EditLine *e) { - return "monctl> "; -} - -int do_cli() -{ - /* emacs style */ - EditLine *el = el_init("cmonctl", stdin, stdout, stderr); - el_set(el, EL_PROMPT, &cli_prompt); - el_set(el, EL_EDITOR, "emacs"); - - History *myhistory = history_init(); - if (myhistory == 0) { - fprintf(stderr, "history could not be initialized\n"); - return 1; - } - - HistEvent ev; - - /* Set the size of the history */ - history(myhistory, &ev, H_SETSIZE, 800); - - /* This sets up the call back functions for history functionality */ - el_set(el, EL_HIST, history, myhistory); - - Tokenizer *tok = tok_init(NULL); - - while (1) { - int count; // # chars read - const char *line = el_gets(el, &count); - - if (!count) { - cout << "quit" << std::endl; - break; - } - - //cout << "typed '" << line << "'" << std::endl; - - if (strcmp(line, "quit\n") == 0) - break; - - history(myhistory, &ev, H_ENTER, line); - - int argc; - const char **argv; - tok_str(tok, line, &argc, &argv); - tok_reset(tok); - - vector cmd; - for (int i=0; i args; - argv_to_vec(argc, argv, args); - env_to_vec(args); - parse_config_options(args); - - vec_to_argv(args, argc, argv); - - srand(getpid()); - - bufferlist indata; - vector nargs; - for (unsigned i=0; i vcmd; - string cmd; - if (!watch) { - for (unsigned i=0; iset_dispatcher(&dispatcher); - - rank.start(); - rank.set_policy(entity_name_t::TYPE_MON, Rank::Policy::lossy_fail_after(1.0)); - - if (watch) { - lock.Lock(); - get_status(); - lock.Unlock(); - } else { - if (vcmd.size()) { - - string rs; - bufferlist odata; - do_command(vcmd, indata, rs, odata); - - int len = odata.length(); - if (len) { - if (outfile) { - if (strcmp(outfile, "-") == 0) { - ::write(1, odata.c_str(), len); - } else { - odata.write_file(outfile); - } - generic_dout(0) << "wrote " << len << " byte payload to " << outfile << dendl; - } else { - generic_dout(0) << "got " << len << " byte payload, discarding (specify -o shutdown(); - } - - - // wait for messenger to finish - rank.wait(); - messenger->destroy(); - return 0; -} - diff --git a/src/dstart.sh b/src/dstart.sh index 82839b017a9..de1a606f31c 100755 --- a/src/dstart.sh +++ b/src/dstart.sh @@ -94,7 +94,7 @@ if [ $new -eq 1 ]; then ./crushtool -c cm.txt -o cm ./osdmaptool --clobber --import-crush cm .ceph_osdmap - ./cmonctl osd setmap -i .ceph_osdmap + ./ceph osd setmap -i .ceph_osdmap fi diff --git a/src/vstart.sh b/src/vstart.sh index ce85fd318bb..ef16d900ab4 100755 --- a/src/vstart.sh +++ b/src/vstart.sh @@ -153,7 +153,7 @@ if [ $start_mon -eq 1 ]; then if [ $new -eq 1 ]; then # build and inject an initial osd map $CEPH_BIN/osdmaptool --clobber --createsimple .ceph_monmap 4 .ceph_osdmap # --pgbits 2 - $CEPH_BIN/cmonctl osd setmap -i .ceph_osdmap + $CEPH_BIN/ceph osd setmap -i .ceph_osdmap fi fi @@ -179,7 +179,7 @@ if [ $start_mds -eq 1 ]; then #valgrind --tool=massif $CEPH_BIN/cmds $ARGS --mds_log_max_segments 2 --mds_thrash_fragments 0 --mds_thrash_exports 0 > m #--debug_ms 20 #$CEPH_BIN/cmds -d $ARGS --mds_thrash_fragments 0 --mds_thrash_exports 0 #--debug_ms 20 -#$CEPH_BIN/cmonctl mds set_max_mds 2 +#$CEPH_BIN/ceph mds set_max_mds 2 done fi