From: Kefu Chai Date: Thu, 14 Mar 2019 08:42:02 +0000 (+0800) Subject: crimson/os: do not fail if fsid file exists when mkfs X-Git-Tag: v15.0.0~199^2 X-Git-Url: http://git-server-git.apps.pok.os.sepia.ceph.com/?a=commitdiff_plain;h=bc0896ec7fe351a75e36d803290517c11eac26e7;p=ceph-ci.git crimson/os: do not fail if fsid file exists when mkfs instead of passing a random uuid down to CyanStore::mkfs(), let it create one if necessary. Signed-off-by: chunmei Liu Signed-off-by: Kefu Chai --- diff --git a/src/crimson/os/cyan_store.cc b/src/crimson/os/cyan_store.cc index d395c863109..3950e29cade 100644 --- a/src/crimson/os/cyan_store.cc +++ b/src/crimson/os/cyan_store.cc @@ -75,17 +75,20 @@ seastar::future<> CyanStore::umount() return seastar::now(); } -seastar::future<> CyanStore::mkfs(uuid_d osd_fsid) +seastar::future<> CyanStore::mkfs() { string fsid_str; int r = read_meta("fsid", &fsid_str); if (r == -ENOENT) { + osd_fsid.generate_random(); write_meta("fsid", fmt::format("{}", osd_fsid)); } else if (r < 0) { throw std::runtime_error("read_meta"); } else { - logger().error("{} already has fsid {}", __func__, fsid_str); - throw std::runtime_error("mkfs"); + logger().info("{} already has fsid {}", __func__, fsid_str); + if (!osd_fsid.parse(fsid_str.c_str())) { + throw std::runtime_error("failed to parse fsid"); + } } string fn = path + "/collections"; @@ -304,4 +307,9 @@ int CyanStore::read_meta(const std::string& key, *value = string{buf, static_cast(r)}; return 0; } + +uuid_d CyanStore::get_fsid() const +{ + return osd_fsid; +} } diff --git a/src/crimson/os/cyan_store.h b/src/crimson/os/cyan_store.h index 2a9c58989f7..4315650667d 100644 --- a/src/crimson/os/cyan_store.h +++ b/src/crimson/os/cyan_store.h @@ -23,6 +23,7 @@ class CyanStore { std::unordered_map coll_map; std::map new_coll_map; uint64_t used_bytes = 0; + uuid_d osd_fsid; public: CyanStore(const std::string& path); @@ -31,7 +32,7 @@ public: seastar::future<> mount(); seastar::future<> umount(); - seastar::future<> mkfs(uuid_d osd_fsid); + seastar::future<> mkfs(); seastar::future read(CollectionRef c, const ghobject_t& oid, uint64_t offset, @@ -57,6 +58,7 @@ public: void write_meta(const std::string& key, const std::string& value); int read_meta(const std::string& key, std::string* value); + uuid_d get_fsid() const; private: int _write(const coll_t& cid, const ghobject_t& oid, diff --git a/src/crimson/osd/osd.cc b/src/crimson/osd/osd.cc index d8c6bbcfb87..891f720208e 100644 --- a/src/crimson/osd/osd.cc +++ b/src/crimson/osd/osd.cc @@ -79,13 +79,11 @@ seastar::future<> OSD::mkfs(uuid_d cluster_fsid) { const auto data_path = local_conf().get_val("osd_data"); store = std::make_unique(data_path); - uuid_d osd_fsid; - osd_fsid.generate_random(); - return store->mkfs(osd_fsid).then([this] { + return store->mkfs().then([this] { return store->mount(); - }).then([cluster_fsid, osd_fsid, this] { + }).then([cluster_fsid, this] { superblock.cluster_fsid = cluster_fsid; - superblock.osd_fsid = osd_fsid; + superblock.osd_fsid = store->get_fsid(); superblock.whoami = whoami; superblock.compat_features = get_osd_initial_compat_set();