@@ -261,34 +261,43 @@ class NVMeBlockDevice : public RBMDevice {
261261 device_path,
262262 seastar::open_flags::rw | seastar::open_flags::dsync
263263 ).then ([this , stat](auto file) mutable {
264- return file.size ().then ([this , stat, file](auto size) mutable {
265- stat.size = size;
266- return identify_namespace (file
267- ).safe_then ([stat] (auto id_namespace_data) mutable {
268- // LBA format provides LBA size which is power of 2. LBA is the
269- // minimum size of read and write.
270- stat.block_size = (1 << id_namespace_data.lbaf [0 ].lbads );
271- if (stat.block_size < RBM_SUPERBLOCK_SIZE) {
272- stat.block_size = RBM_SUPERBLOCK_SIZE;
273- }
264+ return seastar::do_with (
265+ file,
266+ [this , stat](auto &file) mutable
267+ {
268+ return file.size ().then ([this , stat, &file](auto size) mutable {
269+ stat.size = size;
274270 return stat_device_ret (
275271 read_ertr::ready_future_marker{},
276272 stat
277273 );
278- }).handle_error (crimson::ct_error::input_output_error::handle (
279- [stat]{
280- return stat_device_ret (
281- read_ertr::ready_future_marker{},
282- stat
283- );
284- }), crimson::ct_error::pass_further_all{});
285- }).safe_then ([file](auto st) mutable {
286- return file.close (
287- ).then ([st] {
288- return stat_device_ret (
289- read_ertr::ready_future_marker{},
290- st
291- );
274+ return identify_namespace (file
275+ ).safe_then ([stat] (auto id_namespace_data) mutable {
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_namespace_data.lbaf [0 ].lbads );
279+ if (stat.block_size < RBM_SUPERBLOCK_SIZE) {
280+ stat.block_size = RBM_SUPERBLOCK_SIZE;
281+ }
282+ return stat_device_ret (
283+ read_ertr::ready_future_marker{},
284+ stat
285+ );
286+ }).handle_error (crimson::ct_error::input_output_error::handle (
287+ [stat]{
288+ return stat_device_ret (
289+ read_ertr::ready_future_marker{},
290+ stat
291+ );
292+ }), crimson::ct_error::pass_further_all{});
293+ }).safe_then ([&file](auto st) mutable {
294+ return file.close (
295+ ).then ([st] {
296+ return stat_device_ret (
297+ read_ertr::ready_future_marker{},
298+ st
299+ );
300+ });
292301 });
293302 });
294303 });
0 commit comments