Skip to content

Commit a34bfe5

Browse files
Matan-Bmyoungwon
authored andcommitted
crimson/os/seastore/nvme_block_device: switch to coroutines in stat_device
Signed-off-by: Matan Breizman <[email protected]> Signed-off-by: Myoungwon Oh <[email protected]>
1 parent 202275a commit a34bfe5

File tree

1 file changed

+27
-39
lines changed

1 file changed

+27
-39
lines changed

src/crimson/os/seastore/random_block_manager/nvme_block_device.h

Lines changed: 27 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -253,48 +253,36 @@ class NVMeBlockDevice : public RBMDevice {
253253
uint64_t offset, size_t len, void *buffer_ptr);
254254

255255
stat_device_ret stat_device() final {
256-
return seastar::file_stat(device_path, seastar::follow_symlink::yes
256+
auto stat = co_await seastar::file_stat(
257+
device_path, seastar::follow_symlink::yes
257258
).handle_exception([](auto e) -> stat_device_ret {
258259
return crimson::ct_error::input_output_error::make();
259-
}).then([this](auto stat) {
260-
return seastar::open_file_dma(
261-
device_path,
262-
seastar::open_flags::rw | seastar::open_flags::dsync
263-
).then([this, stat](auto file) mutable {
264-
return seastar::do_with(
265-
file, stat,
266-
[this](auto &file, auto &stat) mutable
267-
{
268-
return file.size().then([this, &stat, &file](auto size) mutable {
269-
stat.size = size;
270-
return identify_namespace(file
271-
).safe_then([&stat] (auto id_namespace_data) mutable {
272-
// LBA format provides LBA size which is power of 2. LBA is the
273-
// minimum size of read and write.
274-
stat.block_size = (1 << id_namespace_data.lbaf[0].lbads);
275-
if (stat.block_size < RBM_SUPERBLOCK_SIZE) {
276-
stat.block_size = RBM_SUPERBLOCK_SIZE;
277-
}
278-
return read_ertr::now();
279-
}).handle_error(crimson::ct_error::input_output_error::handle(
280-
[&stat]() mutable {
281-
if (stat.block_size < RBM_SUPERBLOCK_SIZE) {
282-
stat.block_size = RBM_SUPERBLOCK_SIZE;
283-
}
284-
return read_ertr::now();
285-
}), crimson::ct_error::pass_further_all{});
286-
}).safe_then([&file, &stat]() mutable {
287-
return file.close(
288-
).then([&stat] {
289-
return stat_device_ret(
290-
read_ertr::ready_future_marker{},
291-
stat
292-
);
293-
});
294-
});
295-
});
296-
});
297260
});
261+
262+
auto file = co_await seastar::open_file_dma(device_path,
263+
seastar::open_flags::rw | seastar::open_flags::dsync);
264+
265+
auto size = co_await file.size();
266+
stat.size = size;
267+
std::optional<nvme_identify_namespace_data_t> id_ns_data =
268+
co_await identify_namespace(file
269+
).safe_then([] (auto id_namespace_data) mutable {
270+
return std::optional<nvme_identify_namespace_data_t>(id_namespace_data);
271+
}).handle_error(crimson::ct_error::input_output_error::handle([]{
272+
return std::nullopt;
273+
}));
274+
275+
if (id_ns_data) {
276+
// LBA format provides LBA size which is power of 2. LBA is the
277+
// minimum size of read and write.
278+
stat.block_size = (1 << (*id_ns_data).lbaf[0].lbads);
279+
}
280+
if (stat.block_size < RBM_SUPERBLOCK_SIZE) {
281+
stat.block_size = RBM_SUPERBLOCK_SIZE;
282+
}
283+
284+
co_await file.close();
285+
co_return std::move(stat);
298286
}
299287

300288
std::string get_device_path() const final {

0 commit comments

Comments
 (0)