]> git.apps.os.sepia.ceph.com Git - ceph-ci.git/commitdiff
crimson/os: do not fail if fsid file exists when mkfs
authorKefu Chai <kchai@redhat.com>
Thu, 14 Mar 2019 08:42:02 +0000 (16:42 +0800)
committerKefu Chai <kchai@redhat.com>
Tue, 19 Mar 2019 14:39:38 +0000 (22:39 +0800)
instead of passing a random uuid down to CyanStore::mkfs(), let it
create one if necessary.

Signed-off-by: chunmei Liu <chunmei.liu@intel.com>
Signed-off-by: Kefu Chai <kchai@redhat.com>
src/crimson/os/cyan_store.cc
src/crimson/os/cyan_store.h
src/crimson/osd/osd.cc

index d395c8631090045116e7ca2090609a674f1616c3..3950e29cade7619b35c67a86a7722597b64e8129 100644 (file)
@@ -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<size_t>(r)};
   return 0;
 }
+
+uuid_d CyanStore::get_fsid() const
+{
+  return osd_fsid;
+}
 }
index 2a9c58989f72ba53a5a101271b61d05607cfe634..4315650667de51e59b848f16dfacded4e09db077 100644 (file)
@@ -23,6 +23,7 @@ class CyanStore {
   std::unordered_map<coll_t, CollectionRef> coll_map;
   std::map<coll_t,CollectionRef> 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<bufferlist> 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,
index d8c6bbcfb87189d1fc03637f1e7b235926d47b1c..891f720208e276d0b1f9c0e4a0d3f0bcbee7b7e9 100644 (file)
@@ -79,13 +79,11 @@ seastar::future<> OSD::mkfs(uuid_d cluster_fsid)
 {
   const auto data_path = local_conf().get_val<std::string>("osd_data");
   store = std::make_unique<ceph::os::CyanStore>(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();