]> git.apps.os.sepia.ceph.com Git - ceph-ci.git/commitdiff
crimson/os/seastore/rbm: add do_with() to prevent accessing unavailable reference
authormyoungwon oh <ohmyoungwon@gmail.com>
Wed, 19 Feb 2025 13:50:32 +0000 (13:50 +0000)
committermyoungwon oh <ohmyoungwon@gmail.com>
Fri, 7 Mar 2025 02:01:34 +0000 (02:01 +0000)
Signed-off-by: Myoungwon Oh <ohmyoungwon@gmail.com>
src/crimson/os/seastore/random_block_manager/nvme_block_device.h

index 2abf0af7a9e2a01c396905cb81e12b614d2b1862..056b5d211a30af3bcfcc142d05d5510ac0e7cada 100644 (file)
@@ -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
+             );
+           });
          });
        });
       });