Skip to content

Commit

Permalink
crimson/osd: check existing superblock when mkfs
Browse files Browse the repository at this point in the history
in case mkfs on an existing store.

this change mirrors the behavior of classic osd, also addresses the
assert failure when BlueStore tries to create a collection when it
already contains a colloection with the same collection id.

Signed-off-by: Kefu Chai <kchai@redhat.com>
  • Loading branch information
tchaikov committed Jun 2, 2021
1 parent d04b425 commit 6b66c30
Showing 1 changed file with 31 additions and 11 deletions.
42 changes: 31 additions & 11 deletions src/crimson/osd/osd.cc
Original file line number Diff line number Diff line change
Expand Up @@ -169,17 +169,37 @@ seastar::future<> OSD::mkfs(uuid_d osd_uuid, uuid_d cluster_fsid)

seastar::future<> OSD::_write_superblock()
{
logger().info(
"{} writing superblock cluster_fsid {} osd_fsid {}",
__func__,
superblock.cluster_fsid,
superblock.osd_fsid);
return store->create_new_collection(coll_t::meta()).then([this] (auto ch) {
meta_coll = make_unique<OSDMeta>(ch , store.get());
ceph::os::Transaction t;
meta_coll->create(t);
meta_coll->store_superblock(t, superblock);
return store->do_transaction(meta_coll->collection(), std::move(t));
return store->open_collection(coll_t::meta()).then([this] (auto ch) {
if (ch) {
// if we already have superblock, check if it matches
meta_coll = make_unique<OSDMeta>(ch, store.get());
return meta_coll->load_superblock().then([this](OSDSuperblock&& sb) {
if (sb.cluster_fsid != superblock.cluster_fsid) {
logger().error("provided cluster fsid {} != superblock's {}",
sb.cluster_fsid, superblock.cluster_fsid);
throw std::invalid_argument("mismatched fsid");
}
if (sb.whoami != superblock.whoami) {
logger().error("provided osd id {} != superblock's {}",
sb.whoami, superblock.whoami);
throw std::invalid_argument("mismatched osd id");
}
});
} else {
// meta collection does not yet, create superblock
logger().info(
"{} writing superblock cluster_fsid {} osd_fsid {}",
__func__,
superblock.cluster_fsid,
superblock.osd_fsid);
return store->create_new_collection(coll_t::meta()).then([this] (auto ch) {
meta_coll = make_unique<OSDMeta>(ch , store.get());
ceph::os::Transaction t;
meta_coll->create(t);
meta_coll->store_superblock(t, superblock);
return store->do_transaction(meta_coll->collection(), std::move(t));
});
}
});
}

Expand Down

0 comments on commit 6b66c30

Please sign in to comment.