|
7 | 7 | #include <fmt/format.h> |
8 | 8 |
|
9 | 9 | #include <seastar/core/metrics.hh> |
| 10 | +#include <seastar/util/defer.hh> |
10 | 11 |
|
11 | 12 | #include "include/buffer.h" |
12 | 13 |
|
13 | 14 | #include "crimson/common/config_proxy.h" |
14 | 15 | #include "crimson/common/errorator-loop.h" |
| 16 | +#include "crimson/common/coroutine.h" |
15 | 17 |
|
16 | 18 | #include "crimson/os/seastore/logging.h" |
17 | 19 | #include "crimson/os/seastore/segment_manager/block.h" |
@@ -513,36 +515,27 @@ BlockSegmentManager::mkfs_ret BlockSegmentManager::primary_mkfs( |
513 | 515 | set_device_id(sm_config.spec.id); |
514 | 516 | INFO("{} path={}, {}", |
515 | 517 | device_id_printer_t{get_device_id()}, device_path, sm_config); |
516 | | - return seastar::do_with( |
517 | | - seastar::file{}, |
518 | | - seastar::stat_data{}, |
519 | | - block_sm_superblock_t{}, |
520 | | - std::unique_ptr<SegmentStateTracker>(), |
521 | | - [=, this](auto &device, auto &stat, auto &sb, auto &tracker) |
522 | | - { |
523 | | - check_create_device_ret maybe_create = check_create_device_ertr::now(); |
524 | | - using crimson::common::get_conf; |
525 | | - if (get_conf<bool>("seastore_block_create")) { |
526 | | - auto size = get_conf<Option::size_t>("seastore_device_size"); |
527 | | - maybe_create = check_create_device(device_path, size); |
528 | | - } |
529 | 518 |
|
530 | | - return maybe_create.safe_then([this] { |
531 | | - return open_device(device_path); |
532 | | - }).safe_then([&, sm_config](auto p) { |
533 | | - device = p.first; |
534 | | - stat = p.second; |
535 | | - sb = make_superblock(get_device_id(), sm_config, stat); |
536 | | - stats.metadata_write.increment( |
537 | | - ceph::encoded_sizeof<block_sm_superblock_t>(sb)); |
538 | | - return write_superblock(get_device_id(), device, sb); |
539 | | - }).finally([&] { |
540 | | - return device.close(); |
541 | | - }).safe_then([FNAME, this] { |
542 | | - INFO("{} complete", device_id_printer_t{get_device_id()}); |
543 | | - return mkfs_ertr::now(); |
544 | | - }); |
| 519 | + seastar::file device; |
| 520 | + seastar::stat_data stat; |
| 521 | + block_sm_superblock_t sb; |
| 522 | + std::unique_ptr<SegmentStateTracker> tracker; |
| 523 | + |
| 524 | + using crimson::common::get_conf; |
| 525 | + if (get_conf<bool>("seastore_block_create")) { |
| 526 | + auto size = get_conf<Option::size_t>("seastore_device_size"); |
| 527 | + co_await check_create_device(device_path, size); |
| 528 | + } |
| 529 | + auto p = co_await open_device(device_path); |
| 530 | + device = p.first; |
| 531 | + stat = p.second; |
| 532 | + auto closer = seastar::defer([&device] { |
| 533 | + std::ignore = device.close(); |
545 | 534 | }); |
| 535 | + sb = make_superblock(get_device_id(), sm_config, stat); |
| 536 | + stats.metadata_write.increment(ceph::encoded_sizeof<block_sm_superblock_t>(sb)); |
| 537 | + co_await write_superblock(get_device_id(), device, sb); |
| 538 | + INFO("{} complete", device_id_printer_t{get_device_id()}); |
546 | 539 | } |
547 | 540 |
|
548 | 541 | BlockSegmentManager::mkfs_ret BlockSegmentManager::shard_mkfs() |
|
0 commit comments