]> git.apps.os.sepia.ceph.com Git - ceph.git/commitdiff
osd: construct ObjectStore outside of OSD
authorSage Weil <sage@inktank.com>
Sun, 3 Nov 2013 02:19:09 +0000 (19:19 -0700)
committerSage Weil <sage@inktank.com>
Sat, 30 Nov 2013 06:28:36 +0000 (22:28 -0800)
This lets ceph_osd.cc handle the config details and use it directly for
all of the random command-line stuff, eliminating a bunch of mostly-
useless static wrappers in OSD.

Signed-off-by: Sage Weil <sage@inktank.com>
src/ceph_osd.cc
src/osd/OSD.cc
src/osd/OSD.h

index 3298fedf42f4eabf032fff8c1e638df45d37ea2b..83035c8ffd737fc86dda7a58d651628f5d1318c2 100644 (file)
@@ -162,6 +162,15 @@ int main(int argc, const char **argv)
     usage();
   }
 
+  // the store
+  ObjectStore *store = ObjectStore::create(g_conf->osd_objectstore,
+                                          g_conf->osd_data,
+                                          g_conf->osd_journal);
+  if (!store) {
+    derr << "unable to create object store" << dendl;
+    return -ENODEV;
+  }
+
   if (mkfs) {
     common_init_finish(g_ceph_context);
     MonClient mc(g_ceph_context);
@@ -170,7 +179,8 @@ int main(int argc, const char **argv)
     if (mc.get_monmap_privately() < 0)
       return -1;
 
-    int err = OSD::mkfs(g_ceph_context, g_conf->osd_data, g_conf->osd_journal, mc.monmap.fsid, whoami);
+    int err = OSD::mkfs(g_ceph_context, store, g_conf->osd_data,
+                       mc.monmap.fsid, whoami);
     if (err < 0) {
       derr << TEXT_RED << " ** ERROR: error creating empty object store in "
           << g_conf->osd_data << ": " << cpp_strerror(-err) << TEXT_NORMAL << dendl;
@@ -213,7 +223,7 @@ int main(int argc, const char **argv)
     exit(0);
   if (mkjournal) {
     common_init_finish(g_ceph_context);
-    int err = OSD::mkjournal(g_ceph_context, g_conf->osd_data, g_conf->osd_journal);
+    int err = store->mkjournal();
     if (err < 0) {
       derr << TEXT_RED << " ** ERROR: error creating fresh journal " << g_conf->osd_journal
           << " for object store " << g_conf->osd_data
@@ -226,13 +236,15 @@ int main(int argc, const char **argv)
   }
   if (flushjournal) {
     common_init_finish(g_ceph_context);
-    int err = OSD::flushjournal(g_ceph_context, g_conf->osd_data, g_conf->osd_journal);
+    int err = store->mount();
     if (err < 0) {
       derr << TEXT_RED << " ** ERROR: error flushing journal " << g_conf->osd_journal
           << " for object store " << g_conf->osd_data
           << ": " << cpp_strerror(-err) << TEXT_NORMAL << dendl;
       exit(1);
     }
+    store->sync_and_flush();
+    store->umount();
     derr << "flushed journal " << g_conf->osd_journal
         << " for object store " << g_conf->osd_data
         << dendl;
@@ -240,7 +252,7 @@ int main(int argc, const char **argv)
   }
   if (dump_journal) {
     common_init_finish(g_ceph_context);
-    int err = OSD::dump_journal(g_ceph_context, g_conf->osd_data, g_conf->osd_journal, cout);
+    int err = store->dump_journal(cout);
     if (err < 0) {
       derr << TEXT_RED << " ** ERROR: error dumping journal " << g_conf->osd_journal
           << " for object store " << g_conf->osd_data
@@ -256,7 +268,7 @@ int main(int argc, const char **argv)
 
 
   if (convertfilestore) {
-    int err = OSD::convertfs(g_ceph_context);
+    int err = OSD::do_convertfs(store);
     if (err < 0) {
       derr << TEXT_RED << " ** ERROR: error converting store " << g_conf->osd_data
           << ": " << cpp_strerror(-err) << TEXT_NORMAL << dendl;
@@ -424,7 +436,7 @@ int main(int argc, const char **argv)
   common_init_finish(g_ceph_context);
 
   if (g_conf->filestore_update_to >= (int)FileStore::target_version) {
-    int err = OSD::convertfs(g_ceph_context);
+    int err = OSD::do_convertfs(store);
     if (err < 0) {
       derr << TEXT_RED << " ** ERROR: error converting store " << g_conf->osd_data
           << ": " << cpp_strerror(-err) << TEXT_NORMAL << dendl;
@@ -437,7 +449,9 @@ int main(int argc, const char **argv)
     return -1;
   global_init_chdir(g_ceph_context);
 
-  osd = new OSD(g_ceph_context, whoami,
+  osd = new OSD(g_ceph_context,
+               store,
+               whoami,
                ms_cluster,
                ms_public,
                ms_hbclient,
index 075c505d4cd88122b3a427bd0467c21b5fc2f5ee..821a3ab7eb69fb4bc99c8988585b6db5a952f12b 100644 (file)
@@ -569,27 +569,12 @@ int OSD::do_convertfs(ObjectStore *store)
   return store->umount();
 }
 
-int OSD::convertfs(CephContext *cct)
-{
-  boost::scoped_ptr<ObjectStore> store(ObjectStore::create(cct->_conf->osd_objectstore,
-                                                          cct->_conf->osd_data,
-                                                          cct->_conf->osd_journal));
-  int r = do_convertfs(store.get());
-  return r;
-}
-
-int OSD::mkfs(CephContext *cct, const std::string &dev, const std::string &jdev, uuid_d fsid, int whoami)
+int OSD::mkfs(CephContext *cct, ObjectStore *store, const string &dev,
+             uuid_d fsid, int whoami)
 {
   int ret;
-  ObjectStore *store = NULL;
 
   try {
-    store = ObjectStore::create(cct->_conf->osd_objectstore, dev, jdev);
-    if (!store) {
-      ret = -ENOENT;
-      goto out;
-    }
-
     // if we are fed a uuid for this osd, use it.
     store->set_fsid(cct->_conf->osd_uuid);
 
@@ -719,42 +704,9 @@ umount_store:
   store->umount();
 free_store:
   delete store;
-out:
   return ret;
 }
 
-int OSD::mkjournal(CephContext *cct, const std::string &dev, const std::string &jdev)
-{
-  ObjectStore *store = ObjectStore::create(cct->_conf->osd_objectstore, dev, jdev);
-  if (!store)
-    return -ENOENT;
-  return store->mkjournal();
-}
-
-int OSD::flushjournal(CephContext *cct, const std::string &dev, const std::string &jdev)
-{
-  ObjectStore *store = ObjectStore::create(cct->_conf->osd_objectstore, dev, jdev);
-  if (!store)
-    return -ENOENT;
-  int err = store->mount();
-  if (!err) {
-    store->sync_and_flush();
-    store->umount();
-  }
-  delete store;
-  return err;
-}
-
-int OSD::dump_journal(CephContext *cct, const std::string &dev, const std::string &jdev, ostream& out)
-{
-  ObjectStore *store = ObjectStore::create(cct->_conf->osd_objectstore, dev, jdev);
-  if (!store)
-    return -ENOENT;
-  int err = store->dump_journal(out);
-  delete store;
-  return err;
-}
-
 int OSD::write_meta(const std::string &base, uuid_d& cluster_fsid, uuid_d& osd_fsid, int whoami)
 {
   char val[80];
@@ -820,7 +772,8 @@ int OSD::peek_journal_fsid(string path, uuid_d& fsid)
 
 // cons/des
 
-OSD::OSD(CephContext *cct_, int id, Messenger *internal_messenger, Messenger *external_messenger,
+OSD::OSD(CephContext *cct_, ObjectStore *store_,
+        int id, Messenger *internal_messenger, Messenger *external_messenger,
         Messenger *hb_clientm,
         Messenger *hb_front_serverm,
         Messenger *hb_back_serverm,
@@ -844,7 +797,7 @@ OSD::OSD(CephContext *cct_, int id, Messenger *internal_messenger, Messenger *ex
   monc(mc),
   logger(NULL),
   recoverystate_perf(NULL),
-  store(NULL),
+  store(store_),
   clog(cct, client_messenger, &mc->monmap, LogClient::NO_FLAGS),
   whoami(id),
   dev_path(dev), journal_path(jdev),
@@ -927,13 +880,6 @@ int OSD::pre_init()
   if (is_stopping())
     return 0;
   
-  assert(!store);
-  store = ObjectStore::create(cct->_conf->osd_objectstore, dev_path, journal_path);
-  if (!store) {
-    derr << "OSD::pre_init: unable to create object store" << dendl;
-    return -ENODEV;
-  }
-
   if (store->test_mount_in_use()) {
     derr << "OSD::pre_init: object store '" << dev_path << "' is "
          << "currently in use. (Is ceph-osd already running?)" << dendl;
index ff9c66679e7ed8ceb8bb07945d1dffd0278448a0..0280e5ad219e8516e9920bc74950cc2a2f3ed743 100644 (file)
@@ -1708,6 +1708,7 @@ protected:
   /* internal and external can point to the same messenger, they will still
    * be cleaned up properly*/
   OSD(CephContext *cct_,
+      ObjectStore *store_,
       int id,
       Messenger *internal,
       Messenger *external,
@@ -1720,14 +1721,11 @@ protected:
 
   // static bits
   static int find_osd_dev(char *result, int whoami);
-  static int convertfs(CephContext *cct);
   static int do_convertfs(ObjectStore *store);
   static int convert_collection(ObjectStore *store, coll_t cid);
-  static int mkfs(CephContext *cct, const std::string &dev, const std::string &jdev,
+  static int mkfs(CephContext *cct, ObjectStore *store,
+                 const string& dev,
                  uuid_d fsid, int whoami);
-  static int mkjournal(CephContext *cct, const std::string &dev, const std::string &jdev);
-  static int flushjournal(CephContext *cct, const std::string &dev, const std::string &jdev);
-  static int dump_journal(CephContext *cct, const std::string &dev, const std::string &jdev, ostream& out);
   /* remove any non-user xattrs from a map of them */
   void filter_xattrs(map<string, bufferptr>& attrs) {
     for (map<string, bufferptr>::iterator iter = attrs.begin();