From: dparmar18 Date: Wed, 25 Jan 2023 09:52:16 +0000 (+0530) Subject: mds: do not dump multiple JSON obj X-Git-Tag: v16.2.14~51^2~10 X-Git-Url: http://git-server-git.apps.pok.os.sepia.ceph.com/?a=commitdiff_plain;h=28a27e45873f84466d5ac4aa87cbdd55483cb56e;p=ceph.git mds: do not dump multiple JSON obj As enqueue_scrub is invoked twice to perform stray evaluation at root using new op scrub_mdsdir, tests fail as command scrub start / scrub_mdsdir would return two JSON object which JSONDecodeError cannot parse, this patch would make sure we do not dump JSON for recursive scrub on ~mdsdir than happens along with scrubbing root (only when using scrub_mdsdir op) Signed-off-by: Dhairya Parmar (cherry picked from commit 4a976b5b0110c787b9a8e39360fd41164355036d) --- diff --git a/src/mds/MDCache.cc b/src/mds/MDCache.cc index ec5c32468434..c03d328d512a 100644 --- a/src/mds/MDCache.cc +++ b/src/mds/MDCache.cc @@ -12756,19 +12756,24 @@ class C_MDS_EnqueueScrub : public Context std::string tag; Formatter *formatter; Context *on_finish; + bool dump_values; public: ScrubHeaderRef header; - C_MDS_EnqueueScrub(std::string_view tag, Formatter *f, Context *fin) : - tag(tag), formatter(f), on_finish(fin), header(nullptr) {} + C_MDS_EnqueueScrub(std::string_view tag, Formatter *f, Context *fin, + bool dump_values = true) : + tag(tag), formatter(f), on_finish(fin), dump_values(dump_values), + header(nullptr) {} void finish(int r) override { - formatter->open_object_section("results"); - formatter->dump_int("return_code", r); - if (r == 0) { - formatter->dump_string("scrub_tag", tag); - formatter->dump_string("mode", "asynchronous"); + if (dump_values) { + formatter->open_object_section("results"); + formatter->dump_int("return_code", r); + if (r == 0) { + formatter->dump_string("scrub_tag", tag); + formatter->dump_string("mode", "asynchronous"); + } + formatter->close_section(); } - formatter->close_section(); r = 0; if (on_finish) @@ -12780,7 +12785,7 @@ void MDCache::enqueue_scrub( std::string_view path, std::string_view tag, bool force, bool recursive, bool repair, - Formatter *f, Context *fin) + bool scrub_mdsdir, Formatter *f, Context *fin) { dout(10) << __func__ << " " << path << dendl; @@ -12806,14 +12811,19 @@ void MDCache::enqueue_scrub( bool is_internal = false; std::string tag_str(tag); - if (tag_str.empty()) { - uuid_d uuid_gen; - uuid_gen.generate_random(); - tag_str = uuid_gen.to_string(); + C_MDS_EnqueueScrub *cs; + if ((path == "~mdsdir" && scrub_mdsdir)) { is_internal = true; + cs = new C_MDS_EnqueueScrub(tag_str, f, fin, false); + } else { + if (tag_str.empty()) { + uuid_d uuid_gen; + uuid_gen.generate_random(); + tag_str = uuid_gen.to_string(); + is_internal = true; + } + cs = new C_MDS_EnqueueScrub(tag_str, f, fin); } - - C_MDS_EnqueueScrub *cs = new C_MDS_EnqueueScrub(tag_str, f, fin); cs->header = std::make_shared(tag_str, is_internal, force, recursive, repair); mdr->internal_op_finish = cs; diff --git a/src/mds/MDCache.h b/src/mds/MDCache.h index 56fe1164b443..a5b705325390 100644 --- a/src/mds/MDCache.h +++ b/src/mds/MDCache.h @@ -937,7 +937,7 @@ class MDCache { */ void enqueue_scrub(std::string_view path, std::string_view tag, bool force, bool recursive, bool repair, - Formatter *f, Context *fin); + bool scrub_mdsdir, Formatter *f, Context *fin); void repair_inode_stats(CInode *diri); void repair_dirfrag_stats(CDir *dir); void rdlock_dirfrags_stats(CInode *diri, MDSInternalContext *fin); diff --git a/src/mds/MDSRank.cc b/src/mds/MDSRank.cc index f177e57a4f47..d4f258d6bcf4 100644 --- a/src/mds/MDSRank.cc +++ b/src/mds/MDSRank.cc @@ -2964,11 +2964,13 @@ void MDSRank::command_scrub_start(Formatter *f, std::lock_guard l(mds_lock); if (scrub_mdsdir) { MDSGatherBuilder gather(g_ceph_context); - mdcache->enqueue_scrub("~mdsdir", tag, false, true, false, f, gather.new_sub()); + mdcache->enqueue_scrub("~mdsdir", "", false, true, false, scrub_mdsdir, + f, gather.new_sub()); gather.set_finisher(new C_MDSInternalNoop); gather.activate(); } - mdcache->enqueue_scrub(path, tag, force, recursive, repair, f, on_finish); + mdcache->enqueue_scrub(path, tag, force, recursive, repair, scrub_mdsdir, + f, on_finish); // scrub_dentry() finishers will dump the data for us; we're done! }