From: Kefu Chai Date: Thu, 27 May 2021 15:14:36 +0000 (+0800) Subject: tools/ceph_objectstore_tool: destruct ObjectStore using unique_ptr<> X-Git-Tag: v17.1.0~1806^2 X-Git-Url: http://git-server-git.apps.pok.os.sepia.ceph.com/?a=commitdiff_plain;h=d5445b8f113797718a0dbb05e884a6bffbfed76a;p=ceph.git tools/ceph_objectstore_tool: destruct ObjectStore using unique_ptr<> before this change, cot never destructs the created ObjectStore instances. after this change, they are destructed upon returning from main(). Signed-off-by: Kefu Chai --- diff --git a/src/tools/ceph_objectstore_tool.cc b/src/tools/ceph_objectstore_tool.cc index 1873b69a31ad..202695d89b08 100644 --- a/src/tools/ceph_objectstore_tool.cc +++ b/src/tools/ceph_objectstore_tool.cc @@ -3513,8 +3513,8 @@ int main(int argc, char **argv) } } - ObjectStore *fs = ObjectStore::create(g_ceph_context, type, dpath, jpath, flags).release(); - if (fs == NULL) { + std::unique_ptr fs = ObjectStore::create(g_ceph_context, type, dpath, jpath, flags); + if (!fs) { cerr << "Unable to create store of type " << type << std::endl; return 1; } @@ -3580,11 +3580,11 @@ int main(int argc, char **argv) unique_ptr targetfs = ObjectStore::create( g_ceph_context, target_type, target_data_path, "", 0); - if (targetfs == NULL) { + if (!targetfs) { cerr << "Unable to open store of type " << target_type << std::endl; return 1; } - int r = dup(dpath, fs, target_data_path, targetfs.get()); + int r = dup(dpath, fs.get(), target_data_path, targetfs.get()); if (r < 0) { cerr << "dup failed: " << cpp_strerror(r) << std::endl; return 1; @@ -3604,9 +3604,10 @@ int main(int argc, char **argv) if (op == "fuse") { #ifdef HAVE_LIBFUSE - FuseStore fuse(fs, mountpoint); + FuseStore fuse(fs.get(), mountpoint); cout << "mounting fuse at " << mountpoint << " ..." << std::endl; int r = fuse.main(); + fs->umount(); if (r < 0) { cerr << "failed to mount fuse: " << cpp_strerror(r) << std::endl; return 1; @@ -3672,7 +3673,7 @@ int main(int argc, char **argv) target_level = atoi(arg1.c_str()); } ceph_assert(superblock != nullptr); - ret = apply_layout_settings(fs, *superblock, pool, pgid, dry_run, target_level); + ret = apply_layout_settings(fs.get(), *superblock, pool, pgid, dry_run, target_level); goto out; } @@ -3691,11 +3692,11 @@ int main(int argc, char **argv) head = true; lookup_ghobject lookup(object, nspace, head); if (pgidstr == "meta") - ret = action_on_all_objects_in_exact_pg(fs, coll_t::meta(), lookup, debug); + ret = action_on_all_objects_in_exact_pg(fs.get(), coll_t::meta(), lookup, debug); else if (pgidstr.length()) - ret = action_on_all_objects_in_exact_pg(fs, coll_t(pgid), lookup, debug); + ret = action_on_all_objects_in_exact_pg(fs.get(), coll_t(pgid), lookup, debug); else - ret = action_on_all_objects(fs, lookup, debug); + ret = action_on_all_objects(fs.get(), lookup, debug); if (ret) { throw std::runtime_error("Internal error"); } else { @@ -3799,7 +3800,7 @@ int main(int argc, char **argv) if (op == "import") { ceph_assert(superblock != nullptr); try { - ret = tool.do_import(fs, *superblock, force, pgidstr); + ret = tool.do_import(fs.get(), *superblock, force, pgidstr); } catch (const buffer::error &e) { cerr << "do_import threw exception error " << e.what() << std::endl; @@ -3831,7 +3832,7 @@ int main(int argc, char **argv) ceph_assert(superblock != nullptr); epoch = superblock->current_epoch; } - ret = get_osdmap(fs, epoch, osdmap, bl); + ret = get_osdmap(fs.get(), epoch, osdmap, bl); if (ret) { cerr << "Failed to get osdmap#" << epoch << ": " << cpp_strerror(ret) << std::endl; @@ -3850,7 +3851,7 @@ int main(int argc, char **argv) if (ret < 0) { cerr << "Failed to read osdmap " << cpp_strerror(ret) << std::endl; } else { - ret = set_osdmap(fs, epoch, bl, force); + ret = set_osdmap(fs.get(), epoch, bl, force); } goto out; } else if (op == "get-inc-osdmap") { @@ -3859,7 +3860,7 @@ int main(int argc, char **argv) ceph_assert(superblock != nullptr); epoch = superblock->current_epoch; } - ret = get_inc_osdmap(fs, epoch, bl); + ret = get_inc_osdmap(fs.get(), epoch, bl); if (ret < 0) { cerr << "Failed to get incremental osdmap# " << epoch << ": " << cpp_strerror(ret) << std::endl; @@ -3879,7 +3880,7 @@ int main(int argc, char **argv) cerr << "Failed to read incremental osdmap " << cpp_strerror(ret) << std::endl; goto out; } else { - ret = set_inc_osdmap(fs, epoch, bl, force); + ret = set_inc_osdmap(fs.get(), epoch, bl, force); } goto out; } else if (op == "update-mon-db") { @@ -3899,7 +3900,7 @@ int main(int argc, char **argv) ret = -EINVAL; goto out; } - ret = initiate_new_remove_pg(fs, pgid); + ret = initiate_new_remove_pg(fs.get(), pgid); if (ret < 0) { cerr << "PG '" << pgid << "' not found" << std::endl; goto out; @@ -3912,14 +3913,14 @@ int main(int argc, char **argv) boost::scoped_ptr action; action.reset(new do_fix_lost()); if (pgidstr.length()) - ret = action_on_all_objects_in_exact_pg(fs, coll_t(pgid), *action, debug); + ret = action_on_all_objects_in_exact_pg(fs.get(), coll_t(pgid), *action, debug); else - ret = action_on_all_objects(fs, *action, debug); + ret = action_on_all_objects(fs.get(), *action, debug); goto out; } if (op == "list") { - ret = do_list(fs, pgidstr, object, nspace, formatter, debug, + ret = do_list(fs.get(), pgidstr, object, nspace, formatter, debug, human_readable, head); if (ret < 0) { cerr << "do_list failed: " << cpp_strerror(ret) << std::endl; @@ -3927,7 +3928,7 @@ int main(int argc, char **argv) goto out; } if (op == "list-slow-omap") { - ret = do_list_slow(fs, pgidstr, object, slow_threshold, formatter, debug, + ret = do_list_slow(fs.get(), pgidstr, object, slow_threshold, formatter, debug, human_readable); if (ret < 0) { cerr << "do_list failed: " << cpp_strerror(ret) << std::endl; @@ -3961,7 +3962,7 @@ int main(int argc, char **argv) } if (op == "meta-list") { - ret = do_meta(fs, object, formatter, debug, human_readable); + ret = do_meta(fs.get(), object, formatter, debug, human_readable); if (ret < 0) { cerr << "do_meta failed: " << cpp_strerror(ret) << std::endl; } @@ -4038,13 +4039,13 @@ int main(int argc, char **argv) type = NOSNAPMAP; else if (rmtypestr == "snapmap") type = SNAPMAP; - ret = do_remove_object(fs, coll, ghobj, all, force, type); + ret = do_remove_object(fs.get(), coll, ghobj, all, force, type); goto out; } else if (objcmd == "list-attrs") { - ret = do_list_attrs(fs, coll, ghobj); + ret = do_list_attrs(fs.get(), coll, ghobj); goto out; } else if (objcmd == "list-omap") { - ret = do_list_omap(fs, coll, ghobj); + ret = do_list_omap(fs.get(), coll, ghobj); goto out; } else if (objcmd == "get-bytes" || objcmd == "set-bytes") { if (objcmd == "get-bytes") { @@ -4059,7 +4060,7 @@ int main(int argc, char **argv) goto out; } } - ret = do_get_bytes(fs, coll, ghobj, fd); + ret = do_get_bytes(fs.get(), coll, ghobj, fd); if (fd != STDOUT_FILENO) close(fd); } else { @@ -4080,7 +4081,7 @@ int main(int argc, char **argv) goto out; } } - ret = do_set_bytes(fs, coll, ghobj, fd); + ret = do_set_bytes(fs.get(), coll, ghobj, fd); if (fd != STDIN_FILENO) close(fd); } @@ -4091,7 +4092,7 @@ int main(int argc, char **argv) ret = 1; goto out; } - ret = do_get_attr(fs, coll, ghobj, arg1); + ret = do_get_attr(fs.get(), coll, ghobj, arg1); goto out; } else if (objcmd == "set-attr") { if (vm.count("arg1") == 0) { @@ -4116,7 +4117,7 @@ int main(int argc, char **argv) goto out; } } - ret = do_set_attr(fs, coll, ghobj, arg1, fd); + ret = do_set_attr(fs.get(), coll, ghobj, arg1, fd); if (fd != STDIN_FILENO) close(fd); goto out; @@ -4126,7 +4127,7 @@ int main(int argc, char **argv) ret = 1; goto out; } - ret = do_rm_attr(fs, coll, ghobj, arg1); + ret = do_rm_attr(fs.get(), coll, ghobj, arg1); goto out; } else if (objcmd == "get-omap") { if (vm.count("arg1") == 0) { @@ -4134,7 +4135,7 @@ int main(int argc, char **argv) ret = 1; goto out; } - ret = do_get_omap(fs, coll, ghobj, arg1); + ret = do_get_omap(fs.get(), coll, ghobj, arg1); goto out; } else if (objcmd == "set-omap") { if (vm.count("arg1") == 0) { @@ -4159,7 +4160,7 @@ int main(int argc, char **argv) goto out; } } - ret = do_set_omap(fs, coll, ghobj, arg1, fd); + ret = do_set_omap(fs.get(), coll, ghobj, arg1, fd); if (fd != STDIN_FILENO) close(fd); goto out; @@ -4169,7 +4170,7 @@ int main(int argc, char **argv) ret = 1; goto out; } - ret = do_rm_omap(fs, coll, ghobj, arg1); + ret = do_rm_omap(fs.get(), coll, ghobj, arg1); goto out; } else if (objcmd == "get-omaphdr") { if (vm.count("arg1")) { @@ -4177,7 +4178,7 @@ int main(int argc, char **argv) ret = 1; goto out; } - ret = do_get_omaphdr(fs, coll, ghobj); + ret = do_get_omaphdr(fs.get(), coll, ghobj); goto out; } else if (objcmd == "set-omaphdr") { // Extra arg @@ -4203,7 +4204,7 @@ int main(int argc, char **argv) goto out; } } - ret = do_set_omaphdr(fs, coll, ghobj, fd); + ret = do_set_omaphdr(fs.get(), coll, ghobj, fd); if (fd != STDIN_FILENO) close(fd); goto out; @@ -4214,7 +4215,7 @@ int main(int argc, char **argv) ret = 1; goto out; } - ret = print_obj_info(fs, coll, ghobj, formatter); + ret = print_obj_info(fs.get(), coll, ghobj, formatter); goto out; } else if (objcmd == "corrupt-info") { // Undocumented testing feature // There should not be any other arguments @@ -4223,7 +4224,7 @@ int main(int argc, char **argv) ret = 1; goto out; } - ret = corrupt_info(fs, coll, ghobj, formatter); + ret = corrupt_info(fs.get(), coll, ghobj, formatter); goto out; } else if (objcmd == "set-size" || objcmd == "corrupt-size") { // Undocumented testing feature @@ -4240,10 +4241,10 @@ int main(int argc, char **argv) goto out; } uint64_t size = atoll(arg1.c_str()); - ret = set_size(fs, coll, ghobj, size, formatter, corrupt); + ret = set_size(fs.get(), coll, ghobj, size, formatter, corrupt); goto out; } else if (objcmd == "clear-data-digest") { - ret = clear_data_digest(fs, coll, ghobj); + ret = clear_data_digest(fs.get(), coll, ghobj); goto out; } else if (objcmd == "clear-snapset") { // UNDOCUMENTED: For testing zap SnapSet @@ -4253,7 +4254,7 @@ int main(int argc, char **argv) ret = 1; goto out; } - ret = clear_snapset(fs, coll, ghobj, arg1); + ret = clear_snapset(fs.get(), coll, ghobj, arg1); goto out; } else if (objcmd == "remove-clone-metadata") { // Extra arg @@ -4273,7 +4274,7 @@ int main(int argc, char **argv) goto out; } snapid_t cloneid = atoi(arg1.c_str()); - ret = remove_clone(fs, coll, ghobj, cloneid, force); + ret = remove_clone(fs.get(), coll, ghobj, cloneid, force); goto out; } cerr << "Unknown object command '" << objcmd << "'" << std::endl; @@ -4283,7 +4284,7 @@ int main(int argc, char **argv) } map_epoch = 0; - ret = PG::peek_map_epoch(fs, pgid, &map_epoch); + ret = PG::peek_map_epoch(fs.get(), pgid, &map_epoch); if (ret < 0) cerr << "peek_map_epoch reports error" << std::endl; if (debug) @@ -4292,7 +4293,7 @@ int main(int argc, char **argv) pg_info_t info(pgid); PastIntervals past_intervals; __u8 struct_ver; - ret = PG::read_info(fs, pgid, coll, info, past_intervals, struct_ver); + ret = PG::read_info(fs.get(), pgid, coll, info, past_intervals, struct_ver); if (ret < 0) { cerr << "read_info error " << cpp_strerror(ret) << std::endl; goto out; @@ -4307,11 +4308,11 @@ int main(int argc, char **argv) if (op == "export" || op == "export-remove") { ceph_assert(superblock != nullptr); - ret = tool.do_export(fs, coll, pgid, info, map_epoch, struct_ver, *superblock, past_intervals); + ret = tool.do_export(fs.get(), coll, pgid, info, map_epoch, struct_ver, *superblock, past_intervals); if (ret == 0) { cerr << "Export successful" << std::endl; if (op == "export-remove") { - ret = initiate_new_remove_pg(fs, pgid); + ret = initiate_new_remove_pg(fs.get(), pgid); // Export succeeded, so pgid is there ceph_assert(ret == 0); cerr << "Remove successful" << std::endl; @@ -4326,7 +4327,7 @@ int main(int argc, char **argv) } else if (op == "log") { PGLog::IndexedLog log; pg_missing_t missing; - ret = get_log(fs, struct_ver, pgid, info, log, missing); + ret = get_log(fs.get(), struct_ver, pgid, info, log, missing); if (ret < 0) goto out; @@ -4362,7 +4363,7 @@ int main(int argc, char **argv) } cout << "Marking complete succeeded" << std::endl; } else if (op == "trim-pg-log") { - ret = do_trim_pg_log(fs, coll, info, pgid, + ret = do_trim_pg_log(fs.get(), coll, info, pgid, map_epoch, past_intervals); if (ret < 0) { cerr << "Error trimming pg log: " << cpp_strerror(ret) << std::endl;