From: Sage Weil Date: Sat, 27 Sep 2014 14:51:24 +0000 (-0700) Subject: crushtool: add --show-location command X-Git-Tag: v0.88~144^2 X-Git-Url: http://git-server-git.apps.pok.os.sepia.ceph.com/?a=commitdiff_plain;h=7849d792a809e7c13c80571dad5bd95b0abfd27b;p=ceph.git crushtool: add --show-location command Include some tests. Signed-off-by: Sage Weil --- diff --git a/src/test/cli/crushtool/add-item.t b/src/test/cli/crushtool/add-item.t index f058b639c614..0dd43c8bb7c5 100644 --- a/src/test/cli/crushtool/add-item.t +++ b/src/test/cli/crushtool/add-item.t @@ -11,5 +11,8 @@ $ crushtool -d five -o final $ cmp final "$TESTDIR/simple.template.five" $ crushtool -i five --update-item 1 2.0 osd1 --loc host host1 --loc cluster cluster0 -o six > /dev/null + $ crushtool -i five --show-location 1 + cluster\tcluster0 (esc) + host\thost1 (esc) $ crushtool -d six -o final $ cmp final "$TESTDIR/simple.template.five" diff --git a/src/test/cli/crushtool/help.t b/src/test/cli/crushtool/help.t index 3b489301c48d..9d7c8cc7c135 100644 --- a/src/test/cli/crushtool/help.t +++ b/src/test/cli/crushtool/help.t @@ -29,6 +29,8 @@ reweight a given item (and adjust ancestor weights as needed) -i mapfn --reweight recalculate all bucket weights + -i mapfn --show-location id + show location for given device id --show-utilization show OSD usage --show utilization-all include zero weight items diff --git a/src/test/cli/crushtool/location.t b/src/test/cli/crushtool/location.t new file mode 100644 index 000000000000..4252f5c27841 --- /dev/null +++ b/src/test/cli/crushtool/location.t @@ -0,0 +1,16 @@ + $ crushtool -i $TESTDIR/test-map-big-1.crushmap --show-location 44 + $ crushtool -i $TESTDIR/test-map-big-1.crushmap --show-location 16 + $ crushtool -i $TESTDIR/test-map-big-1.crushmap --show-location 167 + host\tp05151113587529 (esc) + rack\tRJ45 (esc) + room\t0513-R-0050 (esc) + root\tdefault (esc) + $ crushtool -i $TESTDIR/test-map-big-1.crushmap --show-location 258 + host\tlxfssi44a06 (esc) + rack\tSI44 (esc) + root\tcastor (esc) + $ crushtool -i $TESTDIR/test-map-big-1.crushmap --show-location 87 + host\tp05151113576052 (esc) + rack\tRJ43 (esc) + room\t0513-R-0050 (esc) + root\tdefault (esc) diff --git a/src/test/cli/crushtool/test-map-big-1.crushmap b/src/test/cli/crushtool/test-map-big-1.crushmap new file mode 100644 index 000000000000..e0b0ae9b1d03 Binary files /dev/null and b/src/test/cli/crushtool/test-map-big-1.crushmap differ diff --git a/src/tools/crushtool.cc b/src/tools/crushtool.cc index ccb0efda74a7..b520255af24a 100644 --- a/src/tools/crushtool.cc +++ b/src/tools/crushtool.cc @@ -114,6 +114,8 @@ void usage() cout << " reweight a given item (and adjust ancestor\n" << " weights as needed)\n"; cout << " -i mapfn --reweight recalculate all bucket weights\n"; + cout << " -i mapfn --show-location id\n"; + cout << " show location for given device id\n"; cout << " --show-utilization show OSD usage\n"; cout << " --show utilization-all\n"; cout << " include zero weight items\n"; @@ -168,6 +170,7 @@ int main(int argc, const char **argv) bool decompile = false; bool test = false; bool display = false; + int full_location = -1; bool write_to_file = false; int verbose = 0; bool unsafe_tunables = false; @@ -244,6 +247,7 @@ int main(int argc, const char **argv) compile = true; } else if (ceph_argparse_flag(args, i, "-t", "--test", (char*)NULL)) { test = true; + } else if (ceph_argparse_withint(args, i, &full_location, &err, "--show-location", (char*)NULL)) { } else if (ceph_argparse_flag(args, i, "-s", "--simulate", (char*)NULL)) { tester.set_random_placement(); } else if (ceph_argparse_flag(args, i, "--enable-unsafe-tunables", (char*)NULL)) { @@ -431,7 +435,7 @@ int main(int argc, const char **argv) exit(EXIT_FAILURE); } if (!compile && !decompile && !build && !test && !reweight && !adjust && - add_item < 0 && + add_item < 0 && full_location < 0 && remove_name.empty() && reweight_name.empty()) { cerr << "no action specified; -h for help" << std::endl; exit(EXIT_FAILURE); @@ -477,6 +481,15 @@ int main(int argc, const char **argv) crush.decode(p); } + if (full_location >= 0) { + map loc = crush.get_full_location(full_location); + for (map::iterator p = loc.begin(); + p != loc.end(); + ++p) { + cout << p->first << "\t" << p->second << std::endl; + } + exit(0); + } if (decompile) { CrushCompiler cc(crush, cerr, verbose); if (!outfn.empty()) {