From 7849d792a809e7c13c80571dad5bd95b0abfd27b Mon Sep 17 00:00:00 2001 From: Sage Weil Date: Sat, 27 Sep 2014 07:51:24 -0700 Subject: [PATCH] crushtool: add --show-location command Include some tests. Signed-off-by: Sage Weil --- src/test/cli/crushtool/add-item.t | 3 +++ src/test/cli/crushtool/help.t | 2 ++ src/test/cli/crushtool/location.t | 16 ++++++++++++++++ src/test/cli/crushtool/test-map-big-1.crushmap | Bin 0 -> 8936 bytes src/tools/crushtool.cc | 15 ++++++++++++++- 5 files changed, 35 insertions(+), 1 deletion(-) create mode 100644 src/test/cli/crushtool/location.t create mode 100644 src/test/cli/crushtool/test-map-big-1.crushmap diff --git a/src/test/cli/crushtool/add-item.t b/src/test/cli/crushtool/add-item.t index f058b639c61..0dd43c8bb7c 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 3b489301c48..9d7c8cc7c13 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 00000000000..4252f5c2784 --- /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 0000000000000000000000000000000000000000..e0b0ae9b1d032a007bba66b9297fbf7001ac885e GIT binary patch literal 8936 zcmd6r2b2}n8OPsSno5i%#MqE3CNbd5y>qA7djT6I7R0h_5u_~cE+AqTY_Y}OTVhGk zBpMS_RK#Af_f8X5Kq*Sc|9|(*o9~+wPxPGSxO2|$&HV1YbKkw+n>TakD-?=_?uA03 z6X;Vc6xw6I4qHbYo!iv6h@!%3IFAcx%lftOmLmu@maRcqMe`9`wX|U!H`cR{_Bdic z{4Ta%36_Jez*4Xnd;xe4x2a8C@mVa?)`o?l+y4JOzh@QB=h!CW+|KZMULBp3#c1;>Ho!TOq8YxT<*@LFJu_+b7Zj6Br% zzyJ#zVCx9PU>C3(*aPeZ_67Tc{@`FR1RM>9f@45y&1HS{!x-_uB4fmu$QUil#i$zR z)PP!WA{YTq0;9lKPzT0=lR-Ub0F7Wgmk0?q^HgA2fg;39A_xCC4ZE(5JKm-W>TW5j!{j1glZ zWAtS%MwjE9E5McDDsVNp7F-9e2RDEl!A;<1a0|E<+y-t3cYr&=UEpr8zUJ0i{W3;; z7ReYfCNf5gN->(YY}>-7Xn!v_3LFTI0DFVcU?i9TehnS~2Z1r*L2y3^zgU7)WV0+L9>;QfaegS?7b_8u9hVycB>Wy(d37!H^gJ;0A;5qO- zcmcc!UIH_~%itC8DtHaFg*owe<-H*NUvQ3dLHd74_xw#+E`QURD0>~e0p0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?hK{jnM$Lxl*VT(P0o>Oy>p>rnAV@7>dn+#y**FW2j?qw7bp!cR2p5R zH2w`#es^-QtPi|Pl=_z{HJ2&1mn#i^3l)6_?g~{OUa2&?N@;wx(&QSb=*)T7%6jKt zr_@}p)ZU;pxKXLQNojbq(&!eY@vTae+oXox?MnSSl$zf`#Uw)e`&>bAr#ivir8K-- zX>^a$_zzIod-6wJ5P5&f75IP76_|TbQ2v`o_P$(w@RwYH`)jTs{9CRdx*r8um+=Ei zlfUccvG<^?kNtn->dilM1@@s_LGZ6!f%|u^ApB3RAo_2vAbuDHK1MM{$| z^x1*;Wv;+qEKdl`5~X&j(qLKcZ1+{JApAO45G_|d#4D60E2TPbl~RATQnN;>U8^)$ zr_?dqm;U*U3z-DWG-7@*)0nBhOcQ1f%Nlx23TEmvx0I=2N-9&!Y*eNJlTw*FCVVmt znX1Y(Vm2$&n2D}T6XvqY8hK2AW$H7_m8oe?mLVcsVw%V@UzXJdOs8e)m^I5ZWHK$& zh;<~Y;Cw0UjX-V7Qpm{U+WY>jn09>GC$p8QV literal 0 HcmV?d00001 diff --git a/src/tools/crushtool.cc b/src/tools/crushtool.cc index ccb0efda74a..b520255af24 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()) { -- 2.47.3