From e03edc587d5449d2473ca7f2c8e8e0e8997c81d4 Mon Sep 17 00:00:00 2001 From: Sage Weil Date: Tue, 23 May 2017 17:56:14 -0400 Subject: [PATCH] osdmaptool: require --upmap-save before modifying input osdmap IMO it is dangerous to modify the provided osdmap in this case unless the user explicitly asks for it. This was super annoying while I was testing this code. Signed-off-by: Sage Weil --- src/test/cli/osdmaptool/help.t | 1 + src/test/cli/osdmaptool/missing-argument.t | 1 + src/test/cli/osdmaptool/upmap.t | 1 - src/tools/osdmaptool.cc | 12 +++++++++--- 4 files changed, 11 insertions(+), 4 deletions(-) diff --git a/src/test/cli/osdmaptool/help.t b/src/test/cli/osdmaptool/help.t index 69374a82dfa..c7fff989b83 100644 --- a/src/test/cli/osdmaptool/help.t +++ b/src/test/cli/osdmaptool/help.t @@ -19,4 +19,5 @@ --upmap-deviation max deviation from target [default: .01] --upmap-pool restrict upmap balancing to 1 or more pools + --upmap-save write modified OSDMap with upmap changes [1] diff --git a/src/test/cli/osdmaptool/missing-argument.t b/src/test/cli/osdmaptool/missing-argument.t index 9c7c6563127..9ca73052c78 100644 --- a/src/test/cli/osdmaptool/missing-argument.t +++ b/src/test/cli/osdmaptool/missing-argument.t @@ -19,4 +19,5 @@ --upmap-deviation max deviation from target [default: .01] --upmap-pool restrict upmap balancing to 1 or more pools + --upmap-save write modified OSDMap with upmap changes [1] diff --git a/src/test/cli/osdmaptool/upmap.t b/src/test/cli/osdmaptool/upmap.t index c833da3991f..b79bf86a0d5 100644 --- a/src/test/cli/osdmaptool/upmap.t +++ b/src/test/cli/osdmaptool/upmap.t @@ -7,7 +7,6 @@ writing upmap command output to: c checking for upmap cleanups upmap, max-count 11, max deviation 0.01 - osdmaptool: writing epoch 3 to om $ cat c ceph osd pg-upmap-items 0.3 54 52 156 155 ceph osd pg-upmap-items 0.1b 158 155 231 227 143 142 diff --git a/src/tools/osdmaptool.cc b/src/tools/osdmaptool.cc index 2738412e538..ab6346f80f3 100644 --- a/src/tools/osdmaptool.cc +++ b/src/tools/osdmaptool.cc @@ -46,6 +46,7 @@ void usage() cout << " --upmap-deviation " << std::endl; cout << " max deviation from target [default: .01]" << std::endl; cout << " --upmap-pool restrict upmap balancing to 1 or more pools" << std::endl; + cout << " --upmap-save write modified OSDMap with upmap changes" << std::endl; exit(1); } @@ -117,6 +118,7 @@ int main(int argc, const char **argv) bool test_random = false; bool upmap_cleanup = false; bool upmap = false; + bool upmap_save = false; std::string upmap_file = "-"; int upmap_max = 100; float upmap_deviation = .01; @@ -145,6 +147,8 @@ int main(int argc, const char **argv) } } else if (ceph_argparse_witharg(args, i, &upmap_file, "--upmap-cleanup", (char*)NULL)) { upmap_cleanup = true; + } else if (ceph_argparse_witharg(args, i, &upmap_file, "--upmap-save", (char*)NULL)) { + upmap_save = true; } else if (ceph_argparse_witharg(args, i, &upmap_file, "--upmap", (char*)NULL)) { upmap_cleanup = true; upmap = true; @@ -350,9 +354,11 @@ int main(int argc, const char **argv) &pending_inc); if (changed) { print_inc_upmaps(pending_inc, upmap_fd); - int r = osdmap.apply_incremental(pending_inc); - assert(r == 0); - modified = true; + if (upmap_save) { + int r = osdmap.apply_incremental(pending_inc); + assert(r == 0); + modified = true; + } } else { cout << "no upmaps proposed" << std::endl; } -- 2.47.3