osd: pass unique_ptr<ObjectStore> to OSD::mkfs()

less error prune this way.

Signed-off-by: Kefu Chai <kchai@redhat.com>
This commit is contained in:
Kefu Chai 2021-05-25 15:34:34 +08:00
parent 7e8ec0c8ca
commit 3f659a4827
3 changed files with 15 additions and 9 deletions

View 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 "

View 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;
}

View 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) {