]> git.apps.os.sepia.ceph.com Git - ceph.git/commitdiff
mds: do not dump multiple JSON obj
authordparmar18 <dparmar@redhat.com>
Wed, 25 Jan 2023 09:52:16 +0000 (15:22 +0530)
committerDhairya Parmar <dparmar@redhat.com>
Fri, 31 Mar 2023 10:14:12 +0000 (15:44 +0530)
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 <dparmar@redhat.com>
(cherry picked from commit 4a976b5b0110c787b9a8e39360fd41164355036d)

src/mds/MDCache.cc
src/mds/MDCache.h
src/mds/MDSRank.cc

index ec5c32468434f9e6ed0c672f17d178bf01cc6d6c..c03d328d512aa6c14d7a824d652a93cf8b3c8a66 100644 (file)
@@ -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<ScrubHeader>(tag_str, is_internal, force, recursive, repair);
 
   mdr->internal_op_finish = cs;
index 56fe1164b4435d65cbafca1cbe888b7d0b8853c5..a5b70532539065afdfb7e2dcd9961cbc82fcd41b 100644 (file)
@@ -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);
index f177e57a4f4722eabc85a8b108f81b5a8381535b..d4f258d6bcf4d9569968ca8de2943bcc0643b6cb 100644 (file)
@@ -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!
 }