diff --git a/src/crushtool.cc b/src/crushtool.cc new file mode 100644 index 00000000000..b22a881ce94 --- /dev/null +++ b/src/crushtool.cc @@ -0,0 +1,142 @@ +// -*- 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 +#include + +#include +#include +#include +using namespace std; + +#include "config.h" + +#include "mon/MonMap.h" + +/* + +./monmaptool -f .ceph_monmap +./monmaptool -f .ceph_monmap --create --clobber --add 1.2.3.4:12345 +./monmaptool -f .ceph_monmap --add 1.2.3.4:12345 +./monmaptool -f .ceph_monmap --rm 1.2.3.4:12345 + + + */ + +void usage(const char *me) +{ + cout << me << " usage: [--print] [--create [--clobber]] [--add 1.2.3.4:567] [--rm 1.2.3.4:567]" << std::endl; + exit(1); +} + +void printmap(const char *me, MonMap *m) +{ + cout << me << ": monmap: epoch " << m->epoch << std::endl + << me << ": monmap: fsid " << m->fsid << std::endl; + for (unsigned i=0; imon_inst.size(); i++) + cout << me << ": monmap: " //<< "mon" << i << " " + << m->mon_inst[i] << std::endl; +} + +int main(int argc, const char **argv) +{ + vector args; + argv_to_vec(argc, argv, args); + + const char *me = argv[0]; + + const char *fn = ".ceph_monmap"; + bool print = false; + bool create = false; + bool clobber = false; + bool modified = false; + list add, rm; + + for (unsigned i=0; i= args.size()) usage(me); + entity_addr_t addr; + if (!parse_ip_port(args[i], addr)) { + cerr << me << ": invalid ip:port '" << args[i] << "'" << std::endl; + return -1; + } + //inst.name = entity_name_t::MON(monmap.size()); + if (strcmp(args[i-1], "--add") == 0) + add.push_back(addr); + else + rm.push_back(addr); + modified = true; + } else + usage(me); + } + + MonMap monmap; + + cout << me << ": monmap file " << fn << std::endl; + + int r = 0; + if (!(create && clobber)) + r = monmap.read(fn); + + if (!create && r < 0) { + cerr << me << ": couldn't open " << fn << ": " << strerror(errno) << std::endl; + return -1; + } + else if (create && !clobber && r == 0) { + cerr << me << ": " << fn << " exists, --clobber to overwrite" << std::endl; + return -1; + } + + for (list::iterator p = add.begin(); p != add.end(); p++) + monmap.add(*p); + for (list::iterator p = rm.begin(); p != rm.end(); p++) { + cout << me << ": removing " << *p << std::endl; + if (!monmap.remove(*p)) { + cerr << me << ": map does not contain " << *p << std::endl; + usage(me); + } + } + + if (!print && !modified) + usage(me); + + if (print) + printmap(me, &monmap); + + if (modified) { + monmap.epoch++; + + // write it out + cout << me << ": writing epoch " << monmap.epoch + << " to " << fn + << " (" << monmap.size() << " monitors)" + << std::endl; + int r = monmap.write(fn); + assert(r >= 0); + } + + + return 0; +} diff --git a/src/monmaptool.cc b/src/monmaptool.cc new file mode 100644 index 00000000000..b22a881ce94 --- /dev/null +++ b/src/monmaptool.cc @@ -0,0 +1,142 @@ +// -*- 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 +#include + +#include +#include +#include +using namespace std; + +#include "config.h" + +#include "mon/MonMap.h" + +/* + +./monmaptool -f .ceph_monmap +./monmaptool -f .ceph_monmap --create --clobber --add 1.2.3.4:12345 +./monmaptool -f .ceph_monmap --add 1.2.3.4:12345 +./monmaptool -f .ceph_monmap --rm 1.2.3.4:12345 + + + */ + +void usage(const char *me) +{ + cout << me << " usage: [--print] [--create [--clobber]] [--add 1.2.3.4:567] [--rm 1.2.3.4:567]" << std::endl; + exit(1); +} + +void printmap(const char *me, MonMap *m) +{ + cout << me << ": monmap: epoch " << m->epoch << std::endl + << me << ": monmap: fsid " << m->fsid << std::endl; + for (unsigned i=0; imon_inst.size(); i++) + cout << me << ": monmap: " //<< "mon" << i << " " + << m->mon_inst[i] << std::endl; +} + +int main(int argc, const char **argv) +{ + vector args; + argv_to_vec(argc, argv, args); + + const char *me = argv[0]; + + const char *fn = ".ceph_monmap"; + bool print = false; + bool create = false; + bool clobber = false; + bool modified = false; + list add, rm; + + for (unsigned i=0; i= args.size()) usage(me); + entity_addr_t addr; + if (!parse_ip_port(args[i], addr)) { + cerr << me << ": invalid ip:port '" << args[i] << "'" << std::endl; + return -1; + } + //inst.name = entity_name_t::MON(monmap.size()); + if (strcmp(args[i-1], "--add") == 0) + add.push_back(addr); + else + rm.push_back(addr); + modified = true; + } else + usage(me); + } + + MonMap monmap; + + cout << me << ": monmap file " << fn << std::endl; + + int r = 0; + if (!(create && clobber)) + r = monmap.read(fn); + + if (!create && r < 0) { + cerr << me << ": couldn't open " << fn << ": " << strerror(errno) << std::endl; + return -1; + } + else if (create && !clobber && r == 0) { + cerr << me << ": " << fn << " exists, --clobber to overwrite" << std::endl; + return -1; + } + + for (list::iterator p = add.begin(); p != add.end(); p++) + monmap.add(*p); + for (list::iterator p = rm.begin(); p != rm.end(); p++) { + cout << me << ": removing " << *p << std::endl; + if (!monmap.remove(*p)) { + cerr << me << ": map does not contain " << *p << std::endl; + usage(me); + } + } + + if (!print && !modified) + usage(me); + + if (print) + printmap(me, &monmap); + + if (modified) { + monmap.epoch++; + + // write it out + cout << me << ": writing epoch " << monmap.epoch + << " to " << fn + << " (" << monmap.size() << " monitors)" + << std::endl; + int r = monmap.write(fn); + assert(r >= 0); + } + + + return 0; +}