]> git.apps.os.sepia.ceph.com Git - ceph.git/commitdiff
crimson/osd: add OSD::get_pg()
authorKefu Chai <kchai@redhat.com>
Sun, 6 Sep 2020 06:47:01 +0000 (14:47 +0800)
committerKefu Chai <kchai@redhat.com>
Sun, 6 Sep 2020 07:30:15 +0000 (15:30 +0800)
for implementing asock commands.

and add `PGMap::get_pg()` as a helper

Signed-off-by: Kefu Chai <kchai@redhat.com>
src/crimson/osd/osd.cc
src/crimson/osd/osd.h
src/crimson/osd/pg_map.cc
src/crimson/osd/pg_map.h

index 427bb15ba0275fead5ced2893aa36acd006545e9..d271f289ea41e18d961189bee8d7bb33f08f8098 100644 (file)
@@ -1294,18 +1294,27 @@ OSD::get_or_create_pg(
   epoch_t epoch,
   std::unique_ptr<PGCreateInfo> info)
 {
-  auto [fut, creating] = pg_map.get_pg(pgid, bool(info));
-  if (!creating && info) {
-    pg_map.set_creating(pgid);
-    (void)handle_pg_create_info(std::move(info));
+  if (info) {
+    auto [fut, creating] = pg_map.wait_for_pg(pgid);
+    if (!creating) {
+      pg_map.set_creating(pgid);
+      (void)handle_pg_create_info(std::move(info));
+    }
+    return std::move(fut);
+  } else {
+    return make_ready_blocking_future<Ref<PG>>(pg_map.get_pg(pgid));
   }
-  return std::move(fut);
 }
 
 blocking_future<Ref<PG>> OSD::wait_for_pg(
   spg_t pgid)
 {
-  return pg_map.get_pg(pgid).first;
+  return pg_map.wait_for_pg(pgid).first;
+}
+
+Ref<PG> OSD::get_pg(spg_t pgid)
+{
+  return pg_map.get_pg(pgid);
 }
 
 seastar::future<> OSD::prepare_to_stop()
index ba9bdf575d9461624af3ae4db1e019f9b783ae12..48df70f6233e1dc9e2703fe777c1e2ff0e7196b5 100644 (file)
@@ -232,6 +232,7 @@ public:
     std::unique_ptr<PGCreateInfo> info);
   blocking_future<Ref<PG>> wait_for_pg(
     spg_t pgid);
+  Ref<PG> get_pg(spg_t pgid);
 
   bool should_restart() const;
   seastar::future<> restart();
index 93d99ce9982ed0313d618931ff555645fb172da8..08071f2604fecc37176997e42ab59e8a050e0c8d 100644 (file)
@@ -23,12 +23,10 @@ void PGMap::PGCreationState::dump_detail(Formatter *f) const
   f->dump_bool("creating", creating);
 }
 
-std::pair<blocking_future<Ref<PG>>, bool> PGMap::get_pg(spg_t pgid, bool wait)
+std::pair<blocking_future<Ref<PG>>, bool> PGMap::wait_for_pg(spg_t pgid)
 {
-  if (auto pg = pgs.find(pgid); pg != pgs.end()) {
-    return make_pair(make_ready_blocking_future<Ref<PG>>(pg->second), true);
-  } else if (!wait) {
-    return make_pair(make_ready_blocking_future<Ref<PG>>(nullptr), true);
+  if (auto pg = get_pg(pgid)) {
+    return make_pair(make_ready_blocking_future<Ref<PG>>(pg), true);
   } else {
     auto &state = pgs_creating.emplace(pgid, pgid).first->second;
     return make_pair(
@@ -37,6 +35,15 @@ std::pair<blocking_future<Ref<PG>>, bool> PGMap::get_pg(spg_t pgid, bool wait)
   }
 }
 
+Ref<PG> PGMap::get_pg(spg_t pgid)
+{
+  if (auto pg = pgs.find(pgid); pg != pgs.end()) {
+    return pg->second;
+  } else {
+    return nullptr;
+  }
+}
+
 void PGMap::set_creating(spg_t pgid)
 {
   logger().debug("Creating {}", pgid);
index 67f1a6a505b99765f1c6cc9b6c2a9ac3a01fcecf..b3fe4b562db03d4190db8ab65ccbd51c325e0502 100644 (file)
@@ -45,7 +45,12 @@ public:
    * Get future for pg with a bool indicating whether it's already being
    * created.
    */
-  std::pair<blocking_future<Ref<PG>>, bool> get_pg(spg_t pgid, bool wait=true);
+  std::pair<blocking_future<Ref<PG>>, bool> wait_for_pg(spg_t pgid);
+
+  /**
+   * get PG in non-blocking manner
+   */
+  Ref<PG> get_pg(spg_t pgid);
 
   /**
    * Set creating