Skip to content

Commit 0b13fdb

Browse files
committed
crimson/os/seastore: SeaStore::mkfs() into coroutines
Signed-off-by: Matan Breizman <[email protected]>
1 parent d77caf3 commit 0b13fdb

File tree

2 files changed

+69
-95
lines changed

2 files changed

+69
-95
lines changed

src/crimson/os/seastore/seastore.cc

Lines changed: 59 additions & 93 deletions
Original file line numberDiff line numberDiff line change
@@ -428,105 +428,71 @@ seastar::future<> SeaStore::prepare_meta(uuid_d new_osd_fsid)
428428
co_await write_meta("mkfs_done", "yes");
429429
}
430430

431-
SeaStore::mkfs_ertr::future<> SeaStore::mkfs(uuid_d new_osd_fsid)
431+
Device::access_ertr::future<> SeaStore::_mkfs(uuid_d new_osd_fsid)
432432
{
433-
LOG_PREFIX(SeaStore::mkfs);
433+
LOG_PREFIX(SeaStore::_mkfs);
434434
INFO("uuid={}, root={} ...", new_osd_fsid, root);
435-
436435
ceph_assert(seastar::this_shard_id() == primary_core);
437-
return read_meta("mkfs_done"
438-
).then([this, new_osd_fsid, FNAME](auto tuple) {
439-
auto [done, value] = tuple;
440-
if (done == 0) {
441-
ERROR("failed");
442-
return seastar::now();
443-
} else {
444-
return seastar::do_with(
445-
secondary_device_set_t(),
446-
[this, new_osd_fsid, FNAME](auto& sds) {
447-
auto fut = seastar::now();
448-
if (!root.empty()) {
449-
fut = seastar::open_directory(root
450-
).then([this, &sds, new_osd_fsid, FNAME](seastar::file rdir) mutable {
451-
std::unique_ptr<seastar::file> root_f =
452-
std::make_unique<seastar::file>(std::move(rdir));
453-
auto sub = root_f->list_directory(
454-
[this, &sds, new_osd_fsid, FNAME](auto de) mutable -> seastar::future<>
455-
{
456-
DEBUG("found file: {}", de.name);
457-
if (de.name.find("block.") == 0
458-
&& de.name.length() > 6 /* 6 for "block." */) {
459-
std::string entry_name = de.name;
460-
auto dtype_end = entry_name.find_first_of('.', 6);
461-
device_type_t dtype =
462-
string_to_device_type(
463-
entry_name.substr(6, dtype_end - 6));
464-
if (dtype == device_type_t::NONE) {
465-
// invalid device type
466-
return seastar::now();
467-
}
468-
auto id = std::stoi(entry_name.substr(dtype_end + 1));
469-
std::string path = fmt::format("{}/{}", root, entry_name);
470-
return Device::make_device(path, dtype
471-
).then([this, &sds, id, dtype, new_osd_fsid](DeviceRef sec_dev) {
472-
auto p_sec_dev = sec_dev.get();
473-
secondaries.emplace_back(std::move(sec_dev));
474-
return p_sec_dev->start(
475-
).then([&sds, id, dtype, new_osd_fsid, p_sec_dev]() {
476-
magic_t magic = (magic_t)std::rand();
477-
sds.emplace(
478-
(device_id_t)id,
479-
device_spec_t{magic, dtype, (device_id_t)id});
480-
return p_sec_dev->mkfs(device_config_t::create_secondary(
481-
new_osd_fsid, id, dtype, magic)
482-
).handle_error(crimson::ct_error::assert_all{"not possible"});
483-
});
484-
}).then([this] {
485-
return set_secondaries();
486-
});
487-
}
488-
return seastar::now();
489-
});
490-
return sub.done().then([root_f=std::move(root_f)] {});
491-
});
492-
}
493-
return fut.then([this, &sds, new_osd_fsid] {
494-
device_id_t id = 0;
495-
device_type_t d_type = device->get_device_type();
496-
assert(d_type == device_type_t::SSD ||
497-
d_type == device_type_t::RANDOM_BLOCK_SSD);
498-
if (d_type == device_type_t::RANDOM_BLOCK_SSD) {
499-
id = static_cast<device_id_t>(DEVICE_ID_RANDOM_BLOCK_MIN);
500-
}
501-
502-
return device->mkfs(
503-
device_config_t::create_primary(new_osd_fsid, id, d_type, sds)
504-
);
505-
}).safe_then([this] {
506-
return crimson::do_for_each(secondaries, [](auto& sec_dev) {
507-
return sec_dev->mount();
508-
});
509-
});
510-
}).safe_then([this] {
511-
return device->mount();
512-
}).safe_then([this] {
513-
return shard_stores.invoke_on_all([] (auto &local_store) {
514-
return local_store.mkfs_managers().handle_error(
515-
crimson::ct_error::assert_all{"Invalid error in SeaStoreS::mkfs_managers"});
516-
});
517-
}).safe_then([this, new_osd_fsid] {
518-
return prepare_meta(new_osd_fsid);
519-
}).safe_then([this] {
520-
return umount();
521-
}).safe_then([FNAME] {
522-
INFO("done");
523-
}).handle_error(
524-
crimson::ct_error::assert_all{
525-
"Invalid error in SeaStore::mkfs"
436+
// todo: read_meta to return errorator
437+
auto [done, value] = co_await read_meta("mkfs_done");
438+
if (done == 0) {
439+
ERROR("failed");
440+
co_return;
441+
}
442+
secondary_device_set_t sds;
443+
if (!root.empty()) {
444+
seastar::file rdir = co_await seastar::open_directory(root);
445+
// hmm?
446+
auto lister = rdir.experimental_list_directory();
447+
while (auto de = co_await lister()) {
448+
DEBUG("found file: {}", de->name);
449+
if (de->name.find("block.") == 0 && de->name.length() > 6 ) {
450+
// 6 for "block."
451+
std::string entry_name = de->name;
452+
auto dtype_end = entry_name.find_first_of('.', 6);
453+
device_type_t dtype =
454+
string_to_device_type(
455+
entry_name.substr(6, dtype_end - 6));
456+
if (dtype == device_type_t::NONE) {
457+
// invalid device type
458+
co_return;
526459
}
527-
);
460+
auto id = std::stoi(entry_name.substr(dtype_end + 1));
461+
std::string path = fmt::format("{}/{}", root, entry_name);
462+
DeviceRef sec_dev = co_await Device::make_device(path, dtype);
463+
auto p_sec_dev = sec_dev.get();
464+
secondaries.emplace_back(std::move(sec_dev));
465+
co_await p_sec_dev->start();
466+
magic_t magic = (magic_t)std::rand();
467+
sds.emplace((device_id_t)id, device_spec_t{magic, dtype, (device_id_t)id});
468+
co_await p_sec_dev->mkfs(
469+
device_config_t::create_secondary(new_osd_fsid, id, dtype, magic)
470+
).handle_error(crimson::ct_error::assert_all{"not possible"});
471+
co_await set_secondaries();
472+
}
528473
}
474+
co_await rdir.close();
475+
}
476+
477+
device_id_t id = 0;
478+
device_type_t d_type = device->get_device_type();
479+
assert(d_type == device_type_t::SSD ||
480+
d_type == device_type_t::RANDOM_BLOCK_SSD);
481+
if (d_type == device_type_t::RANDOM_BLOCK_SSD) {
482+
id = static_cast<device_id_t>(DEVICE_ID_RANDOM_BLOCK_MIN);
483+
}
484+
co_await device->mkfs(device_config_t::create_primary(new_osd_fsid, id, d_type, sds));
485+
for (auto& sec_dev : secondaries) {
486+
co_await sec_dev->mount();
487+
}
488+
co_await device->mount();
489+
co_await shard_stores.invoke_on_all([] (auto &local_store) {
490+
return local_store.mkfs_managers().handle_error(
491+
crimson::ct_error::assert_all{"Invalid error in SeaStoreS::mkfs_managers"});
529492
});
493+
co_await prepare_meta(new_osd_fsid);
494+
co_await umount();
495+
INFO("done");
530496
}
531497

532498
using coll_core_t = SeaStore::coll_core_t;

src/crimson/os/seastore/seastore.h

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -591,7 +591,7 @@ class SeaStore final : public FuturizedStore {
591591

592592
Device::access_ertr::future<> _mount();
593593

594-
// FuturizedStore::mount_ertr only supports a stateful_ec
594+
// FuturizedStore::mount_ertr/mkfs_ertr only supports a stateful_ec
595595
// to keep the interface intact, convert to stateful_ec.
596596
crimson::os::FuturizedStore::mount_ertr::future<> mount() final {
597597
return _mount().handle_error(
@@ -601,7 +601,15 @@ class SeaStore final : public FuturizedStore {
601601
}
602602
seastar::future<> umount() final;
603603

604-
mkfs_ertr::future<> mkfs(uuid_d new_osd_fsid) final;
604+
Device::access_ertr::future<> _mkfs(uuid_d new_osd_fsid);
605+
606+
crimson::os::FuturizedStore::mkfs_ertr::future<> mkfs(uuid_d new_osd_fsid) final {
607+
return _mkfs(new_osd_fsid).handle_error(
608+
Device::access_ertr::all_same_way([](auto& code) {
609+
return crimson::stateful_ec{code};
610+
}));
611+
}
612+
605613
seastar::future<store_statfs_t> stat() const final;
606614
seastar::future<store_statfs_t> pool_statfs(int64_t pool_id) const final;
607615

0 commit comments

Comments
 (0)