From: xinxin shu Date: Mon, 22 Feb 2016 02:46:35 +0000 (+0800) Subject: osdmaptool: allow add --pg-num to osdmaptool --test-map-pgs to override the map's... X-Git-Tag: v11.0.0~406^2 X-Git-Url: http://git-server-git.apps.pok.os.sepia.ceph.com/?a=commitdiff_plain;h=30db35cdd673fda101bfdce7d964cd387d7a1c51;p=ceph.git osdmaptool: allow add --pg-num to osdmaptool --test-map-pgs to override the map's pg_num value Fixes: #14701 Signed-off-by: xinxin shu --- diff --git a/src/osd/OSDMap.h b/src/osd/OSDMap.h index 6694e27b3bb9..1a83912a0bd4 100644 --- a/src/osd/OSDMap.h +++ b/src/osd/OSDMap.h @@ -731,6 +731,9 @@ public: const map& get_pools() const { return pools; } + map& get_pools() { + return pools; + } const string& get_pool_name(int64_t p) const { map::const_iterator i = pool_name.find(p); assert(i != pool_name.end()); diff --git a/src/test/cli/osdmaptool/help.t b/src/test/cli/osdmaptool/help.t index 02f56efddfff..d6d75470de88 100644 --- a/src/test/cli/osdmaptool/help.t +++ b/src/test/cli/osdmaptool/help.t @@ -3,7 +3,7 @@ usage: [--print] [--createsimple [--clobber] [--pg_bits ]] --export-crush write osdmap's crush map to --import-crush replace osdmap's crush map with - --test-map-pgs [--pool ] map all pgs + --test-map-pgs [--pool ] [--pg_num ] map all pgs --test-map-pgs-dump [--pool ] map all pgs --mark-up-in mark osds up and in (but do not persist) --clear-temp clear pg_temp and primary_temp diff --git a/src/test/cli/osdmaptool/missing-argument.t b/src/test/cli/osdmaptool/missing-argument.t index 87ab3eb10d64..b872696b9cd5 100644 --- a/src/test/cli/osdmaptool/missing-argument.t +++ b/src/test/cli/osdmaptool/missing-argument.t @@ -3,7 +3,7 @@ usage: [--print] [--createsimple [--clobber] [--pg_bits ]] --export-crush write osdmap's crush map to --import-crush replace osdmap's crush map with - --test-map-pgs [--pool ] map all pgs + --test-map-pgs [--pool ] [--pg_num ] map all pgs --test-map-pgs-dump [--pool ] map all pgs --mark-up-in mark osds up and in (but do not persist) --clear-temp clear pg_temp and primary_temp diff --git a/src/tools/osdmaptool.cc b/src/tools/osdmaptool.cc index 810f82adcc89..6b4a3f18c30c 100644 --- a/src/tools/osdmaptool.cc +++ b/src/tools/osdmaptool.cc @@ -28,7 +28,7 @@ void usage() cout << " usage: [--print] [--createsimple [--clobber] [--pg_bits ]] " << std::endl; cout << " --export-crush write osdmap's crush map to " << std::endl; cout << " --import-crush replace osdmap's crush map with " << std::endl; - cout << " --test-map-pgs [--pool ] map all pgs" << std::endl; + cout << " --test-map-pgs [--pool ] [--pg_num ] map all pgs" << std::endl; cout << " --test-map-pgs-dump [--pool ] map all pgs" << std::endl; cout << " --mark-up-in mark osds up and in (but do not persist)" << std::endl; cout << " --clear-temp clear pg_temp and primary_temp" << std::endl; @@ -73,6 +73,7 @@ int main(int argc, const char **argv) bool test_map_pgs = false; bool test_map_pgs_dump = false; bool test_random = false; + int64_t pg_num = -1; std::string val; std::ostringstream err; @@ -133,6 +134,11 @@ int main(int argc, const char **argv) test_map_object = val; } else if (ceph_argparse_flag(args, i, "--test_crush", (char*)NULL)) { test_crush = true; + } else if (ceph_argparse_witharg(args, i, &val, err, "--pg_num", (char*)NULL)) { + string interr; + pg_num = strict_strtoll(val.c_str(), 10, &interr); + if (interr.length() > 0) + cerr << "error parsing integer value " << interr << std::endl; } else if (ceph_argparse_witharg(args, i, &range_first, err, "--range_first", (char*)NULL)) { } else if (ceph_argparse_witharg(args, i, &range_last, err, "--range_last", (char*)NULL)) { } else if (ceph_argparse_witharg(args, i, &pool, err, "--pool", (char*)NULL)) { @@ -330,11 +336,14 @@ int main(int argc, const char **argv) vector size(30, 0); if (test_random) srand(getpid()); - const map& pools = osdmap.get_pools(); - for (map::const_iterator p = pools.begin(); + map& pools = osdmap.get_pools(); + for (map::iterator p = pools.begin(); p != pools.end(); ++p) { if (pool != -1 && p->first != pool) continue; + if (pg_num > 0) + p->second.set_pg_num(pg_num); + cout << "pool " << p->first << " pg_num " << p->second.get_pg_num() << std::endl; for (unsigned i = 0; i < p->second.get_pg_num(); ++i) {