diff --git a/src/ceph_osd.cc b/src/ceph_osd.cc index b6278fa72bc..df91666155c 100644 --- a/src/ceph_osd.cc +++ b/src/ceph_osd.cc @@ -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("fsid"), + int err = OSD::mkfs(g_ceph_context, std::move(store), g_conf().get_val("fsid"), whoami, osdspec_affinity); if (err < 0) { derr << TEXT_RED << " ** ERROR: error creating empty object store in " diff --git a/src/osd/OSD.cc b/src/osd/OSD.cc index 5883d921f6a..92df17e3c92 100644 --- a/src/osd/OSD.cc +++ b/src/osd/OSD.cc @@ -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 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; } diff --git a/src/osd/OSD.h b/src/osd/OSD.h index 5e405f3c18d..b702202273f 100644 --- a/src/osd/OSD.h +++ b/src/osd/OSD.h @@ -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 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& attrs) {