]> git-server-git.apps.pok.os.sepia.ceph.com Git - ceph.git/commitdiff
crimson: coroutinize SegmentManager::get_segment_manager()
authorKefu Chai <k.chai@proxmox.com>
Mon, 11 May 2026 04:43:47 +0000 (12:43 +0800)
committerKefu Chai <k.chai@proxmox.com>
Tue, 12 May 2026 03:03:03 +0000 (11:03 +0800)
this change was inspired by following warning:

```
[1/3] Building CXX object src/crimson/os/seastore/CMakeFiles/crimson-seastore.dir/segment_manager.cc.o
/home/kefu/dev/ceph/src/crimson/os/seastore/segment_manager.cc:45:15: warning: lambda capture 'FNAME' is not used [-Wunused-lambda-capture]
   45 |       ).then([FNAME,
      |               ^
```

but we went further by coroutinize the whole method. because the return
value of ioctl() is not checked before this change, and clang correctly
flagged this with a warning, we marker it with `[[maybe_unused]]`, we
will fix it in a separate change.

Signed-off-by: Kefu Chai <k.chai@proxmox.com>
src/crimson/os/seastore/segment_manager.cc

index e87c9639ec0cf0713b3a1c8b3abfde930ba2a2a8..899abf61c828e84a81e2c353683c3fbf4e5d9d4b 100644 (file)
@@ -33,48 +33,22 @@ SegmentManager::get_segment_manager(
   const std::string &device, device_type_t dtype)
 {
 #ifdef HAVE_ZNS
-LOG_PREFIX(SegmentManager::get_segment_manager);
-  return seastar::do_with(
-    static_cast<size_t>(0),
-    [FNAME,
-     dtype,
-     device](auto &nr_zones) {
-      return seastar::open_file_dma(
+  LOG_PREFIX(SegmentManager::get_segment_manager);
+  auto file = co_await seastar::open_file_dma(
        device + "/block",
-       seastar::open_flags::rw
-      ).then([FNAME,
-             dtype,
-             device,
-             &nr_zones](auto file) {
-       return seastar::do_with(
-         file,
-         [&nr_zones](auto &f) -> seastar::future<int> {
-           ceph_assert(f);
-           return f.ioctl(BLKGETNRZONES, (void *)&nr_zones);
-         });
-      }).then([FNAME,
-              dtype,
-              device,
-              &nr_zones](auto ret) -> crimson::os::seastore::SegmentManagerRef {
-       crimson::os::seastore::SegmentManagerRef sm;
-       INFO("Found {} zones.", nr_zones);
-       if (nr_zones != 0) {
-         return std::make_unique<
-           segment_manager::zbd::ZBDSegmentManager
-           >(device + "/block");
-       } else {
-         return std::make_unique<
-           segment_manager::block::BlockSegmentManager
-           >(device + "/block", dtype);
-       }
-      });
-    });
+       seastar::open_flags::rw);
+  ceph_assert(file);
+  size_t nr_zones = 0;
+  [[maybe_unused]] auto ret = co_await file.ioctl(BLKGETNRZONES, (void *)&nr_zones);
+  INFO("Found {} zones.", nr_zones);
+  if (nr_zones != 0) {
+    co_return std::make_unique<segment_manager::zbd::ZBDSegmentManager>(device + "/block");
+  } else {
+    co_return std::make_unique<segment_manager::block::BlockSegmentManager>(device + "/block", dtype);
+  }
 #else
-  return seastar::make_ready_future<crimson::os::seastore::SegmentManagerRef>(
-    std::make_unique<
-      segment_manager::block::BlockSegmentManager
-    >(device + "/block", dtype));
+  co_return std::make_unique<segment_manager::block::BlockSegmentManager>(device + "/block", dtype);
 #endif
 }
 
-}
+} // namespace crimson::os::seastore