]> git-server-git.apps.pok.os.sepia.ceph.com Git - ceph.git/commitdiff
osdmaptool: Add options to change CRUSH weights
authorAlex Marangone <amarangone@digitalocean.com>
Sun, 16 Feb 2020 17:56:27 +0000 (09:56 -0800)
committerKefu Chai <kchai@redhat.com>
Mon, 12 Oct 2020 06:17:42 +0000 (14:17 +0800)
Signed-off-by: Alex Marangone <amarangone@digitalocean.com>
src/tools/osdmaptool.cc

index 325450e0aa80cce603fb7d0dccde5d87e3c179a7..834546d414a465ac72fd8afa80c32cab111fee67 100644 (file)
@@ -64,6 +64,8 @@ void usage()
   cout << "   --dump <format>         displays the map in plain text when <format> is 'plain', 'json' if specified format is not supported" << std::endl;
   cout << "   --tree                  displays a tree of the map" << std::endl;
   cout << "   --test-crush [--range-first <first> --range-last <last>] map pgs to acting osds" << std::endl;
+  cout << "   --adjust-crush-weight <osdid:weight>[,<osdid:weight>,<...>] change <osdid> CRUSH <weight> (but do not persist)" << std::endl;
+  cout << "   --crush-adjust-save     saves adjust-crush-weight to CRUSHmap" << std::endl;
   exit(1);
 }
 
@@ -131,7 +133,8 @@ int main(int argc, const char **argv)
   int pgp_bits = 6;
   bool clobber = false;
   bool modified = false;
-  std::string export_crush, import_crush, test_map_pg, test_map_object;
+  std::string export_crush, import_crush, test_map_pg, test_map_object, adjust_crush_weight;
+  bool crush_adjust_save = false;
   bool test_crush = false;
   int range_first = -1;
   int range_last = -1;
@@ -257,6 +260,10 @@ int main(int argc, const char **argv)
         cerr << err.str() << std::endl;
         exit(EXIT_FAILURE);
       }
+    } else if (ceph_argparse_witharg(args, i, &val, err, "--adjust-crush-weight", (char*)NULL)) {
+      adjust_crush_weight = val;
+    } else if (ceph_argparse_flag(args, i, "--crush-adjust-save", (char*)NULL)) {
+      crush_adjust_save = true;
     } else {
       ++i;
     }
@@ -378,6 +385,27 @@ int main(int argc, const char **argv)
     osdmap.set_weight(id, CEPH_OSD_IN);
   }
 
+  for_each_substr(adjust_crush_weight, ",", [&](auto osd_to_adjust) {
+    std::string_view osd_to_weight_delimiter{":"};
+    size_t pos = osd_to_adjust.find(osd_to_weight_delimiter);
+    if (pos == osd_to_adjust.npos) {
+      cerr << me << ": use ':' as separator of osd id and its weight"
+          << std::endl;
+      usage();
+    }
+    int osd_id = std::stoi(string(osd_to_adjust.substr(0, pos)));
+    float new_weight = std::stof(string(osd_to_adjust.substr(pos + 1)));
+    osdmap.crush->adjust_item_weightf(g_ceph_context, osd_id, new_weight);
+    std::cout << "Adjusted osd." << osd_id << " CRUSH weight to " << new_weight
+             << std::endl;
+    if (crush_adjust_save) {
+      OSDMap::Incremental inc;
+      inc.fsid = osdmap.get_fsid();
+      inc.epoch = osdmap.get_epoch() + 1;
+      osdmap.apply_incremental(inc);
+      modified = true;
+    }
+  });
 
   if (clear_temp) {
     cout << "clearing pg/primary temp" << std::endl;
@@ -763,7 +791,7 @@ skip_upmap:
       export_crush.empty() && import_crush.empty() && 
       test_map_pg.empty() && test_map_object.empty() &&
       !test_map_pgs && !test_map_pgs_dump && !test_map_pgs_dump_all &&
-      !upmap && !upmap_cleanup) {
+      adjust_crush_weight.empty() && !upmap && !upmap_cleanup) {
     cerr << me << ": no action specified?" << std::endl;
     usage();
   }