From db494081588c90524cb0a63f26512fcf5bb3ac1a Mon Sep 17 00:00:00 2001 From: myoungwon oh Date: Wed, 19 Feb 2025 13:50:32 +0000 Subject: [PATCH] crimson/os/seastore/rbm: add do_with() to prevent accessing unavailable reference Signed-off-by: Myoungwon Oh --- .../random_block_manager/nvme_block_device.h | 57 +++++++++++-------- 1 file changed, 33 insertions(+), 24 deletions(-) diff --git a/src/crimson/os/seastore/random_block_manager/nvme_block_device.h b/src/crimson/os/seastore/random_block_manager/nvme_block_device.h index 2abf0af7a9e..056b5d211a3 100644 --- a/src/crimson/os/seastore/random_block_manager/nvme_block_device.h +++ b/src/crimson/os/seastore/random_block_manager/nvme_block_device.h @@ -261,34 +261,43 @@ public: device_path, seastar::open_flags::rw | seastar::open_flags::dsync ).then([this, stat](auto file) mutable { - return file.size().then([this, stat, file](auto size) mutable { - stat.size = size; - return identify_namespace(file - ).safe_then([stat] (auto id_namespace_data) mutable { - // LBA format provides LBA size which is power of 2. LBA is the - // minimum size of read and write. - stat.block_size = (1 << id_namespace_data.lbaf[0].lbads); - if (stat.block_size < RBM_SUPERBLOCK_SIZE) { - stat.block_size = RBM_SUPERBLOCK_SIZE; - } + return seastar::do_with( + file, + [this, stat](auto &file) mutable + { + return file.size().then([this, stat, &file](auto size) mutable { + stat.size = size; return stat_device_ret( read_ertr::ready_future_marker{}, stat ); - }).handle_error(crimson::ct_error::input_output_error::handle( - [stat]{ - return stat_device_ret( - read_ertr::ready_future_marker{}, - stat - ); - }), crimson::ct_error::pass_further_all{}); - }).safe_then([file](auto st) mutable { - return file.close( - ).then([st] { - return stat_device_ret( - read_ertr::ready_future_marker{}, - st - ); + return identify_namespace(file + ).safe_then([stat] (auto id_namespace_data) mutable { + // LBA format provides LBA size which is power of 2. LBA is the + // minimum size of read and write. + stat.block_size = (1 << id_namespace_data.lbaf[0].lbads); + if (stat.block_size < RBM_SUPERBLOCK_SIZE) { + stat.block_size = RBM_SUPERBLOCK_SIZE; + } + return stat_device_ret( + read_ertr::ready_future_marker{}, + stat + ); + }).handle_error(crimson::ct_error::input_output_error::handle( + [stat]{ + return stat_device_ret( + read_ertr::ready_future_marker{}, + stat + ); + }), crimson::ct_error::pass_further_all{}); + }).safe_then([&file](auto st) mutable { + return file.close( + ).then([st] { + return stat_device_ret( + read_ertr::ready_future_marker{}, + st + ); + }); }); }); }); -- 2.39.5