FOR_EACH_ARG(args) {
if (CONF_ARG_EQ("type", 't')) {
- CONF_SAFE_SET_ARG_VAL(&type, OPT_STR);
+ CONF_SAFE_SET_ARG_VAL(&type, OPT_STR);
} else {
- nargs.push_back(args[i]);
+ nargs.push_back(args[i]);
}
}
args.swap(nargs);
-int main(int argc, const char **argv, const char *envp[]) {
-
+int main(int argc, const char **argv, const char *envp[])
+{
+ DEFINE_CONF_VARS(usage);
vector<const char*> args;
argv_to_vec(argc, argv, args);
env_to_vec(args);
bufferlist indata;
vector<const char*> nargs;
- for (unsigned i=0; i<args.size(); i++) {
- if (strcmp(args[i],"-o") == 0)
- outfile = args[++i];
- else if (strcmp(args[i], "-i") == 0) {
+ FOR_EACH_ARG(args) {
+ if (CONF_ARG_EQ("out_file", 'o')) {
+ CONF_SAFE_SET_ARG_VAL(&outfile, OPT_STR);
+ } else if (CONF_ARG_EQ("in_data", 'i')) {
int fd = ::open(args[++i], O_RDONLY);
struct stat st;
if (::fstat(fd, &st) == 0) {
::close(fd);
cout << "read " << st.st_size << " bytes from " << args[i] << std::endl;
}
- } else if (strcmp(args[i], "-w") == 0 ||
- strcmp(args[i], "--watch") == 0) {
+ } else if (CONF_ARG_EQ("watch", 'w')) {
observe = 1;
- } else if (strcmp(args[i], "-p") == 0 ||
- strcmp(args[i], "--poll") == 0) {
+ } else if (CONF_ARG_EQ("poll", 'p')) {
watch = 1;
} else if (args[i][0] == '-') {
- if (strcmp(args[i], "-h"))
+ if (!CONF_ARG_EQ("help", 'h'))
cerr << "unrecognized option " << args[i] << std::endl;
usage();
} else
__isarg = 1 < args.size(); \
for (unsigned i=0; i<args.size(); i++, __isarg = i+1 < args.size())
+#define ARGS_USAGE() args_usage();
+
#include "common/debug.h"
#endif
int main(int argc, const char **argv)
{
+ DEFINE_CONF_VARS(usage);
vector<const char*> args;
argv_to_vec(argc, argv, args);
env_to_vec(args);
// osd specific args
bool mkfs = 0;
- for (unsigned i=0; i<args.size(); i++) {
- if (strcmp(args[i],"--mkfs") == 0)
+ FOR_EACH_ARG(args) {
+ if (CONF_ARG_EQ("mkfs", '\0')) {
mkfs = 1;
- else {
+ } else {
cerr << "unrecognized arg " << args[i] << std::endl;
- usage();
+ ARGS_USAGE();
}
}
}
-int usage(const char *me)
+void usage()
{
- cout << me << ": usage: crushtool [-d map] [-c map.txt] [-o outfile [--clobber]] [--build --num_osd N layer1 ...]" << std::endl;
- cout << me << " (where each 'layer' is 'name (uniform|straw|list|tree) size')" << std::endl;
+ cout << "usage: crushtool [-d map] [-c map.txt] [-o outfile [--clobber]] [--build --num_osd N layer1 ...]" << std::endl;
+ cout << " (where each 'layer' is 'name (uniform|straw|list|tree) size')" << std::endl;
exit(1);
}
int build = 0;
int num_osds =0;
vector<layer_t> layers;
+ DEFINE_CONF_VARS(usage);
- for (unsigned i=0; i<args.size(); i++) {
- if (strcmp(args[i], "--clobber") == 0)
+ FOR_EACH_ARG(args) {
+ if (CONF_ARG_EQ("clobber", '\0')) {
clobber = true;
- else if (strcmp(args[i], "-d") == 0)
- dinfn = args[++i];
- else if (strcmp(args[i], "-o") == 0)
- outfn = args[++i];
- else if (strcmp(args[i], "-c") == 0)
- cinfn = args[++i];
- else if (strcmp(args[i], "-v") == 0)
- verbose++;
- else if (strcmp(args[i], "--build") == 0)
- build = 1;
- else if (strcmp(args[i], "--num_osds") == 0)
- num_osds = atoi(args[++i]);
- else if (!build)
- usage(me);
+ } else if (CONF_ARG_EQ("dinfn", 'd')) {
+ CONF_SAFE_SET_ARG_VAL(&dinfn, OPT_STR);
+ } else if (CONF_ARG_EQ("outfn", 'o')) {
+ CONF_SAFE_SET_ARG_VAL(&outfn, OPT_STR);
+ } else if (CONF_ARG_EQ("cinfn", 'c')) {
+ CONF_SAFE_SET_ARG_VAL(&cinfn, OPT_STR);
+ } else if (CONF_ARG_EQ("verbose", 'v')) {
+ CONF_SAFE_SET_ARG_VAL(&verbose, OPT_BOOL);
+ } else if (CONF_ARG_EQ("build", '\0')) {
+ CONF_SAFE_SET_ARG_VAL(&build, OPT_BOOL);
+ } else if (CONF_ARG_EQ("num_osds", '\0')) {
+ CONF_SAFE_SET_ARG_VAL(&num_osds, OPT_INT);
+ } else if (!build)
+ usage();
else if (i + 3 <= args.size()) {
layer_t l;
l.name = args[i++];
}
}
if ((cinfn?1:0) + (dinfn?1:0) + build > 1)
- usage(me);
+ usage();
if (!cinfn && !dinfn && !build)
- usage(me);
+ usage();
/*
if (outfn) cout << "outfn " << outfn << std::endl;
{
vector<const char*> args;
argv_to_vec(argc, argv, args);
+ DEFINE_CONF_VARS(usage);
bool clobber = false;
const char *fsdir = 0;
int whoami = -1;
const char *monmapfn = 0;
const char *osdmapfn = 0;
- for (unsigned i = 0; i < args.size(); i++) {
- if (strcmp(args[i], "--clobber") == 0)
- clobber = true;
- else if (strcmp(args[i], "--mon") == 0 ||
- strcmp(args[i], "-i") == 0)
- whoami = atoi(args[++i]);
- else if (strcmp(args[i], "--monmap") == 0)
- monmapfn = args[++i];
- else if (strcmp(args[i], "--osdmap") == 0)
- osdmapfn = args[++i];
- else if (strcmp(args[i], "--mon_data") == 0 ||
- strcmp(args[i], "--mon-data") == 0)
- fsdir = args[++i];
- else
+
+ FOR_EACH_ARG(args) {
+ if (CONF_ARG_EQ("clobber", '\0')) {
+ CONF_SAFE_SET_ARG_VAL(&clobber, OPT_BOOL);
+ } else if (CONF_ARG_EQ("mon", 'i')) {
+ CONF_SAFE_SET_ARG_VAL(&whoami, OPT_INT);
+ } else if (CONF_ARG_EQ("monmap", '\0')) {
+ CONF_SAFE_SET_ARG_VAL(&monmapfn, OPT_STR);
+ } else if (CONF_ARG_EQ("osdmap", '\0')) {
+ CONF_SAFE_SET_ARG_VAL(&osdmapfn, OPT_STR);
+ } else if (CONF_ARG_EQ("mon_data", '\0')) {
+ CONF_SAFE_SET_ARG_VAL(&fsdir, OPT_STR);
+ } else
usage();
}
if (!fsdir || !monmapfn || whoami < 0)
#include "mon/MonMap.h"
-void usage(const char *me)
+void usage()
{
- cout << me << " usage: [--print] [--create [--clobber]] [--add 1.2.3.4:567] [--rm 1.2.3.4:567] <mapfilename>" << std::endl;
+ cout << " usage: [--print] [--create [--clobber]] [--add 1.2.3.4:567] [--rm 1.2.3.4:567] <mapfilename>" << std::endl;
exit(1);
}
{
vector<const char*> args;
argv_to_vec(argc, argv, args);
+ DEFINE_CONF_VARS(usage);
const char *me = argv[0];
bool modified = false;
list<entity_addr_t> add, rm;
- for (unsigned i=0; i<args.size(); i++) {
- if (strcmp(args[i], "--print") == 0)
- print = true;
- else if (strcmp(args[i], "--create") == 0)
- create = true;
- else if (strcmp(args[i], "--clobber") == 0)
- clobber = true;
- else if (strcmp(args[i], "--add") == 0 ||
- strcmp(args[i], "--rm") == 0) {
+ FOR_EACH_ARG(args) {
+ if (CONF_ARG_EQ("print", '\0')) {
+ CONF_SAFE_SET_ARG_VAL(&print, OPT_BOOL);
+ } else if (CONF_ARG_EQ("create", '\0')) {
+ CONF_SAFE_SET_ARG_VAL(&create, OPT_BOOL);
+ } else if (CONF_ARG_EQ("clobber", '\0')) {
+ CONF_SAFE_SET_ARG_VAL(&clobber, OPT_BOOL);
+ } else if (CONF_ARG_EQ("add", '\0') ||
+ CONF_ARG_EQ("rm", '\0')) {
+ bool is_add=CONF_ARG_EQ("add", '\0');
if (++i >= args.size())
- usage(me);
+ usage();
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)
+ if (is_add)
add.push_back(addr);
else
rm.push_back(addr);
} else if (!fn)
fn = args[i];
else {
- cout << "what is '" << args[i] << "'" << std::endl;
- usage(me);
+ cout << "invalid argument: '" << args[i] << "'" << std::endl;
+ usage();
}
}
if (!fn)
- usage(me);
+ usage();
MonMap monmap;
cout << me << ": removing " << *p << std::endl;
if (!monmap.remove(*p)) {
cerr << me << ": map does not contain " << *p << std::endl;
- usage(me);
+ usage();
}
}
if (!print && !modified)
- usage(me);
+ usage();
if (modified)
monmap.epoch++;
#include "mon/MonMap.h"
#include "common/common_init.h"
-void usage(const char *me)
+void usage()
{
- cout << me << " usage: [--print] [--createsimple <numosd> [--clobber] [--pgbits <bitsperosd>]] <mapfilename>" << std::endl;
- cout << me << " --export-crush <file> write osdmap's crush map to <file>" << std::endl;
- cout << me << " --import-crush <file> replace osdmap's crush map with <file>" << std::endl;
+ cout << " usage: [--print] [--createsimple <numosd> [--clobber] [--pgbits <bitsperosd>]] <mapfilename>" << std::endl;
+ cout << " --export-crush <file> write osdmap's crush map to <file>" << std::endl;
+ cout << " --import-crush <file> replace osdmap's crush map with <file>" << std::endl;
exit(1);
}
vector<const char*> args;
argv_to_vec(argc, argv, args);
env_to_vec(args);
+ DEFINE_CONF_VARS(usage);
common_init(args, "osdmaptool");
const char *me = argv[0];
list<entity_addr_t> add, rm;
const char *test_map_pg = 0;
- for (unsigned i=0; i<args.size(); i++) {
- if (strcmp(args[i], "--print") == 0 ||
- strcmp(args[i], "-p") == 0)
- print = true;
- else if (strcmp(args[i], "--createsimple") == 0) {
+ FOR_EACH_ARG(args) {
+ if (CONF_ARG_EQ("print", 'p')) {
+ CONF_SAFE_SET_ARG_VAL(&print, OPT_BOOL);
+ } else if (CONF_ARG_EQ("createsimple", '\0')) {
createsimple = true;
- num_osd = atoi(args[++i]);
- } else if (strcmp(args[i], "--clobber") == 0)
- clobber = true;
- else if (strcmp(args[i], "--pg_bits") == 0)
- pg_bits = atoi(args[++i]);
- else if (strcmp(args[i], "--lpg_bits") == 0)
- lpg_bits = atoi(args[++i]);
- else if (strcmp(args[i], "--num_dom") == 0)
- num_dom = atoi(args[++i]);
- else if (strcmp(args[i], "--export-crush") == 0)
- export_crush = args[++i];
- else if (strcmp(args[i], "--import-crush") == 0)
- import_crush = args[++i];
- else if (strcmp(args[i], "--test-map-pg") == 0)
- test_map_pg = args[++i];
- else if (!fn)
+ CONF_SAFE_SET_ARG_VAL(&num_osd, OPT_INT);
+ } else if (CONF_ARG_EQ("clobber", '\0')) {
+ CONF_SAFE_SET_ARG_VAL(&clobber, OPT_BOOL);
+ } else if (CONF_ARG_EQ("pg_bits", '\0')) {
+ CONF_SAFE_SET_ARG_VAL(&pg_bits, OPT_INT);
+ } else if (CONF_ARG_EQ("lpg_bits", '\0')) {
+ CONF_SAFE_SET_ARG_VAL(&lpg_bits, OPT_INT);
+ } else if (CONF_ARG_EQ("num_dom", '\0')) {
+ CONF_SAFE_SET_ARG_VAL(&num_dom, OPT_INT);
+ } else if (CONF_ARG_EQ("export_crush", '\0')) {
+ CONF_SAFE_SET_ARG_VAL(&export_crush, OPT_STR);
+ } else if (CONF_ARG_EQ("import_crush", '\0')) {
+ CONF_SAFE_SET_ARG_VAL(&import_crush, OPT_STR);
+ } else if (CONF_ARG_EQ("test_map_pg", '\0')) {
+ CONF_SAFE_SET_ARG_VAL(&test_map_pg, OPT_STR);
+ } else if (!fn)
fn = args[i];
else
- usage(me);
+ usage();
}
if (!fn) {
cerr << me << ": must specify osdmap filename" << std::endl;
- usage(me);
+ usage();
}
OSDMap osdmap;
if (pgid.parse(test_map_pg) < 0) {
cerr << me << ": failed to parse pg '" << test_map_pg
<< "', r = " << r << std::endl;
- usage(me);
+ usage();
}
cout << " parsed '" << test_map_pg << "' -> " << pgid << std::endl;
if (!print && !modified && !export_crush && !import_crush && !test_map_pg) {
cerr << me << ": no action specified?" << std::endl;
- usage(me);
+ usage();
}
if (modified)