]> git.apps.os.sepia.ceph.com Git - ceph.git/commitdiff
osd: implement `get_pgs_by_osd()`
authorLaura Flores <lflores@redhat.com>
Tue, 22 Feb 2022 06:36:26 +0000 (06:36 +0000)
committerLaura Flores <lflores@redhat.com>
Tue, 22 Feb 2022 06:36:26 +0000 (06:36 +0000)
Code borrowed from `build_pool_pgs_info()`. Used to calculate
the number of pgs per osd in `calc_desired_primary_distribution()`.

Signed-off-by: Laura Flores <lflores@redhat.com>
src/osd/OSDMap.cc
src/osd/OSDMap.h

index 8ef6a1607ad6792e2761fe6b675356eb0796175d..85bf4e08544fefae12bbb8335c182e4eafa75d53 100644 (file)
@@ -4931,6 +4931,27 @@ int OSDMap::calc_pg_upmaps(
   return num_changed;
 }
 
+
+map<uint64_t,set<pg_t>> OSDMap::get_pgs_by_osd()
+{
+  OSDMap tmp_osd_map;
+  tmp_osd_map.deepish_copy_from(*this);
+
+  map<uint64_t,set<pg_t>> pgs_by_osd;
+  for (auto& [pid, pdata] : pools) {
+    for (unsigned ps = 0; ps < pdata.get_pg_num(); ++ps) {
+      pg_t pg(ps, pid);
+      vector<int> up;
+      tmp_osd_map.pg_to_up_acting_osds(pg, &up, nullptr, nullptr, nullptr);
+      for (auto osd : up) {
+       if (osd != CRUSH_ITEM_NONE)
+         pgs_by_osd[osd].insert(pg);
+      }
+    }
+  }
+  return pgs_by_osd;
+}
+
 float OSDMap::build_pool_pgs_info (
   CephContext *cct,
   const std::set<int64_t>& only_pools,        ///< [optional] restrict to pool
index 4cf02756c1d85bb49b01c236cbef6b5fa3a48996..4e0f66baacbc2108c90754f0ad7c298090cf6eac 100644 (file)
@@ -1435,6 +1435,9 @@ public:
     );
 
 private: // Bunch of internal functions used only by calc_pg_upmaps (result of code refactoring)
+
+  std::map<uint64_t,std::set<pg_t>> get_pgs_by_osd(); // used in calc_desired_primary_distribution()
+
   float build_pool_pgs_info (
     CephContext *cct,
     const std::set<int64_t>& pools,        ///< [optional] restrict to pool