]> git.apps.os.sepia.ceph.com Git - ceph.git/commitdiff
crimson/osd: add "--mkfs" support to crimson-osd
authorKefu Chai <kchai@redhat.com>
Tue, 22 Jan 2019 12:37:18 +0000 (20:37 +0800)
committerKefu Chai <kchai@redhat.com>
Tue, 29 Jan 2019 09:58:18 +0000 (17:58 +0800)
Signed-off-by: Kefu Chai <kchai@redhat.com>
src/crimson/osd/main.cc
src/crimson/osd/osd.cc
src/crimson/osd/osd.h

index 1d7e9297a3f527ed44dc491b478e233590c57c03..04a0c97dfc8f30515b22d5ccf7801d9e2ead78de 100644 (file)
@@ -37,6 +37,8 @@ int main(int argc, char* argv[])
                                               &cluster,
                                               &conf_file_list);
   seastar::app_template app;
+  app.add_options()
+    ("mkfs", "create a [new] data directory");
   seastar::sharded<OSD> osd;
 
   using ceph::common::sharded_conf;
@@ -46,6 +48,7 @@ int main(int argc, char* argv[])
   args.insert(begin(args), argv[0]);
   try {
     return app.run_deprecated(args.size(), const_cast<char**>(args.data()), [&] {
+      auto& config = app.configuration();
       seastar::engine().at_exit([] {
         return sharded_conf().stop();
       });
@@ -62,8 +65,13 @@ int main(int argc, char* argv[])
       }).then([&] {
         return osd.start_single(std::stoi(local_conf()->name.get_id()),
                                 static_cast<uint32_t>(getpid()));
-      }).then([&] {
-        return osd.invoke_on(0, &OSD::start);
+      }).then([&osd, mkfs = config.count("mkfs")] {
+        if (mkfs) {
+          return osd.invoke_on(0, &OSD::mkfs,
+                               local_conf().get_val<uuid_d>("fsid"));
+        } else {
+          return osd.invoke_on(0, &OSD::start);
+        }
       });
     });
   } catch (...) {
index 82d4f2520134aee9a8024c00f7736f6c6ed1a7d1..062b7b741885e06720f43308af2f38f8ab49b8c9 100644 (file)
@@ -51,15 +51,62 @@ OSD::OSD(int id, uint32_t nonce)
 
 OSD::~OSD() = default;
 
-seastar::future<> OSD::mkfs(uuid_d cluster_fsid, int whoami)
+namespace {
+// Initial features in new superblock.
+// Features here are also automatically upgraded
+CompatSet get_osd_initial_compat_set()
+{
+  CompatSet::FeatureSet ceph_osd_feature_compat;
+  CompatSet::FeatureSet ceph_osd_feature_ro_compat;
+  CompatSet::FeatureSet ceph_osd_feature_incompat;
+  ceph_osd_feature_incompat.insert(CEPH_OSD_FEATURE_INCOMPAT_BASE);
+  ceph_osd_feature_incompat.insert(CEPH_OSD_FEATURE_INCOMPAT_PGINFO);
+  ceph_osd_feature_incompat.insert(CEPH_OSD_FEATURE_INCOMPAT_OLOC);
+  ceph_osd_feature_incompat.insert(CEPH_OSD_FEATURE_INCOMPAT_LEC);
+  ceph_osd_feature_incompat.insert(CEPH_OSD_FEATURE_INCOMPAT_CATEGORIES);
+  ceph_osd_feature_incompat.insert(CEPH_OSD_FEATURE_INCOMPAT_HOBJECTPOOL);
+  ceph_osd_feature_incompat.insert(CEPH_OSD_FEATURE_INCOMPAT_BIGINFO);
+  ceph_osd_feature_incompat.insert(CEPH_OSD_FEATURE_INCOMPAT_LEVELDBINFO);
+  ceph_osd_feature_incompat.insert(CEPH_OSD_FEATURE_INCOMPAT_LEVELDBLOG);
+  ceph_osd_feature_incompat.insert(CEPH_OSD_FEATURE_INCOMPAT_SNAPMAPPER);
+  ceph_osd_feature_incompat.insert(CEPH_OSD_FEATURE_INCOMPAT_HINTS);
+  ceph_osd_feature_incompat.insert(CEPH_OSD_FEATURE_INCOMPAT_PGMETA);
+  ceph_osd_feature_incompat.insert(CEPH_OSD_FEATURE_INCOMPAT_MISSING);
+  ceph_osd_feature_incompat.insert(CEPH_OSD_FEATURE_INCOMPAT_FASTINFO);
+  ceph_osd_feature_incompat.insert(CEPH_OSD_FEATURE_INCOMPAT_RECOVERY_DELETES);
+  return CompatSet(ceph_osd_feature_compat,
+                   ceph_osd_feature_ro_compat,
+                   ceph_osd_feature_incompat);
+}
+}
+
+seastar::future<> OSD::mkfs(uuid_d cluster_fsid)
 {
-  ceph::os::CyanStore store{local_conf().get_val<std::string>("osd_data")};
+  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();
-  store.write_meta("fsid", osd_fsid.to_string());
-  store.write_meta("ceph_fsid", cluster_fsid.to_string());
-  store.write_meta("whoami", std::to_string(whoami));
-  return seastar::now();
+  return store->mkfs(osd_fsid).then([this] {
+    return store->mount();
+  }).then([cluster_fsid, osd_fsid, this] {
+    superblock.cluster_fsid = cluster_fsid;
+    superblock.osd_fsid = osd_fsid;
+    superblock.whoami = whoami;
+    superblock.compat_features = get_osd_initial_compat_set();
+
+    bufferlist bl;
+    encode(superblock, bl);
+
+    auto ch = store->create_new_collection(coll_t::meta());
+    ceph::os::Transaction t;
+    t.create_collection(coll_t::meta(), 0);
+    t.write(coll_t::meta(), OSD_SUPERBLOCK_GOBJECT, 0, bl.length(), bl);
+    return store->do_transaction(ch, std::move(t));
+  }).then([cluster_fsid, this] {
+    store->write_meta("ceph_fsid", cluster_fsid.to_string());
+    store->write_meta("whoami", std::to_string(whoami));
+    return seastar::now();
+  });
 }
 
 seastar::future<> OSD::start()
index f565bfbf943edc237bd7f5732358e00972c9dff1..47d77e48f7789ef604750ee09d6cb7b662a29faf 100644 (file)
@@ -67,7 +67,7 @@ public:
   OSD(int id, uint32_t nonce);
   ~OSD();
 
-  static seastar::future<> mkfs(uuid_d fsid, int whoami);
+  seastar::future<> mkfs(uuid_d fsid);
 
   seastar::future<> start();
   seastar::future<> stop();