]> git.apps.os.sepia.ceph.com Git - ceph.git/commitdiff
osd: pass unique_ptr<ObjectStore> to OSD::mkfs()
authorKefu Chai <kchai@redhat.com>
Tue, 25 May 2021 07:34:34 +0000 (15:34 +0800)
committerKefu Chai <kchai@redhat.com>
Thu, 27 May 2021 15:07:10 +0000 (23:07 +0800)
less error prune this way.

Signed-off-by: Kefu Chai <kchai@redhat.com>
src/ceph_osd.cc
src/osd/OSD.cc
src/osd/OSD.h

index b6278fa72bc4e90f534ba7340dce060ade457759..df91666155cb57aa08c8a50173d45d37efe5a39d 100644 (file)
@@ -369,7 +369,7 @@ int main(int argc, const char **argv)
       forker.exit(-EINVAL);
     }
 
-    int err = OSD::mkfs(g_ceph_context, store.release(), g_conf().get_val<uuid_d>("fsid"),
+    int err = OSD::mkfs(g_ceph_context, std::move(store), g_conf().get_val<uuid_d>("fsid"),
                         whoami, osdspec_affinity);
     if (err < 0) {
       derr << TEXT_RED << " ** ERROR: error creating empty object store in "
index 5883d921f6a5a23fe9680e0c25f552a54fcdba6d..92df17e3c9292d9985a0638a4e973c32cf87d612 100644 (file)
@@ -2030,7 +2030,11 @@ int heap(CephContext& cct, const cmdmap_t& cmdmap, Formatter& f, std::ostream& o
 
 } // namespace ceph::osd_cmds
 
-int OSD::mkfs(CephContext *cct, ObjectStore *store, uuid_d fsid, int whoami, string osdspec_affinity)
+int OSD::mkfs(CephContext *cct,
+             std::unique_ptr<ObjectStore> store,
+             uuid_d fsid,
+             int whoami,
+             string osdspec_affinity)
 {
   int ret;
 
@@ -2045,7 +2049,7 @@ int OSD::mkfs(CephContext *cct, ObjectStore *store, uuid_d fsid, int whoami, str
   if (ret) {
     derr << "OSD::mkfs: ObjectStore::mkfs failed with error "
          << cpp_strerror(ret) << dendl;
-    goto free_store;
+    return ret;
   }
 
   store->set_cache_shards(1);  // doesn't matter for mkfs!
@@ -2054,7 +2058,7 @@ int OSD::mkfs(CephContext *cct, ObjectStore *store, uuid_d fsid, int whoami, str
   if (ret) {
     derr << "OSD::mkfs: couldn't mount ObjectStore: error "
          << cpp_strerror(ret) << dendl;
-    goto free_store;
+    return ret;
   }
 
   ch = store->open_collection(coll_t::meta());
@@ -2062,7 +2066,7 @@ int OSD::mkfs(CephContext *cct, ObjectStore *store, uuid_d fsid, int whoami, str
     ret = store->read(ch, OSD_SUPERBLOCK_GOBJECT, 0, 0, sbbl);
     if (ret < 0) {
       derr << "OSD::mkfs: have meta collection but no superblock" << dendl;
-      goto free_store;
+      return ret;
     }
     /* if we already have superblock, check content of superblock */
     dout(0) << " have superblock" << dendl;
@@ -2103,7 +2107,7 @@ int OSD::mkfs(CephContext *cct, ObjectStore *store, uuid_d fsid, int whoami, str
     }
   }
 
-  ret = write_meta(cct, store, sb.cluster_fsid, sb.osd_fsid, whoami, osdspec_affinity);
+  ret = write_meta(cct, store.get(), sb.cluster_fsid, sb.osd_fsid, whoami, osdspec_affinity);
   if (ret) {
     derr << "OSD::mkfs: failed to write fsid file: error "
          << cpp_strerror(ret) << dendl;
@@ -2115,8 +2119,6 @@ umount_store:
     ch.reset();
   }
   store->umount();
-free_store:
-  delete store;
   return ret;
 }
 
index 5e405f3c18d719f5ad5265a19b7a28f8c8b18f43..b702202273fb5ee8d097ca34ac84ec91ec0f9bec 100644 (file)
@@ -2024,7 +2024,11 @@ private:
   ~OSD() override;
 
   // static bits
-  static int mkfs(CephContext *cct, ObjectStore *store, uuid_d fsid, int whoami, std::string osdspec_affinity);
+  static int mkfs(CephContext *cct,
+                 std::unique_ptr<ObjectStore> store,
+                 uuid_d fsid,
+                 int whoami,
+                 std::string osdspec_affinity);
 
   /* remove any non-user xattrs from a std::map of them */
   void filter_xattrs(std::map<std::string, ceph::buffer::ptr>& attrs) {