]> git-server-git.apps.pok.os.sepia.ceph.com Git - ceph.git/commitdiff
mds: tidy up ScrubHeader
authorJohn Spray <john.spray@redhat.com>
Mon, 19 Sep 2016 17:26:42 +0000 (18:26 +0100)
committerJohn Spray <john.spray@redhat.com>
Thu, 22 Sep 2016 12:42:02 +0000 (13:42 +0100)
Signed-off-by: John Spray <john.spray@redhat.com>
src/mds/CDir.cc
src/mds/CInode.cc
src/mds/MDCache.cc
src/mds/ScrubHeader.h
src/mds/ScrubStack.cc

index 2d6025f2d68e9ade6d64af5bc120c9d9af6a3abb..7d101ce44b73e775cf71fb803bf4a752b16a2370 100644 (file)
@@ -3020,7 +3020,7 @@ int CDir::_next_dentry_on_set(set<dentry_key_t>& dns, bool missing_okay,
     dns.erase(dnkey);
 
     if (dn->get_projected_version() < scrub_infop->last_recursive.version &&
-       !(scrub_infop->header->force)) {
+       !(scrub_infop->header->get_force())) {
       dout(15) << " skip dentry " << dnkey.name
               << ", no change since last scrub" << dendl;
       continue;
@@ -3126,7 +3126,7 @@ bool CDir::scrub_local()
     scrub_infop->last_scrub_dirty = true;
   } else {
     scrub_infop->pending_scrub_error = true;
-    if (scrub_infop->header->repair)
+    if (scrub_infop->header->get_repair())
       cache->repair_dirfrag_stats(this);
   }
   return rval;
index e878a26ba35190045158bfb30912369c37137cf3..5dcdcb1577f2fabe64ba92f937131b9d427d140e 100644 (file)
@@ -3787,7 +3787,7 @@ void CInode::validate_disk_state(CInode::validated_data *results,
       // present)
       if (in->scrub_infop) {
         // I'm a non-orphan, so look up my ScrubHeader via my linkage
-        const std::string &tag = in->scrub_infop->header->tag;
+        const std::string &tag = in->scrub_infop->header->get_tag();
         // Rather than using the usual CInode::fetch_backtrace,
         // use a special variant that optionally writes a tag in the same
         // operation.
@@ -3867,7 +3867,7 @@ next:
           clog->error() << "scrub: inode wrongly marked free: 0x" << std::hex
             << inode.ino;
 
-          if (in->scrub_infop->header->repair) {
+          if (in->scrub_infop->header->get_repair()) {
             bool repaired = inotable->repair(inode.ino);
             if (repaired) {
               clog->error() << "inode table repaired for inode: 0x" << std::hex
@@ -3987,7 +3987,7 @@ next:
        if (dir->scrub_infop &&
            dir->scrub_infop->pending_scrub_error) {
          dir->scrub_infop->pending_scrub_error = false;
-         if (dir->scrub_infop->header->repair) {
+         if (dir->scrub_infop->header->get_repair()) {
            results->raw_stats.error_str
              << "dirfrag(" << p->first << ") has bad stats (will be fixed); ";
          } else {
@@ -4002,7 +4002,7 @@ next:
       if (!dir_info.same_sums(in->inode.dirstat) ||
          !nest_info.same_sums(in->inode.rstat)) {
        if (in->scrub_infop &&
-           in->scrub_infop->header->repair) {
+           in->scrub_infop->header->get_repair()) {
          results->raw_stats.error_str
            << "freshly-calculated rstats don't match existing ones (will be fixed)";
          in->mdcache->repair_inode_stats(in);
@@ -4231,7 +4231,7 @@ void CInode::scrub_initialize(CDentry *scrub_parent,
     for (std::list<frag_t>::iterator i = frags.begin();
         i != frags.end();
         ++i) {
-      if (header->force)
+      if (header->get_force())
        scrub_infop->dirfrag_stamps[*i].reset();
       else
        scrub_infop->dirfrag_stamps[*i];
@@ -4342,10 +4342,10 @@ void CInode::scrub_finished(MDSInternalContextBase **c) {
   *c = scrub_infop->on_finish;
   scrub_infop->on_finish = NULL;
 
-  if (scrub_infop->header->origin == this) {
+  if (scrub_infop->header->get_origin() == this) {
     // We are at the point that a tagging scrub was initiated
     LogChannelRef clog = mdcache->mds->clog;
-    clog->info() << "scrub complete with tag '" << scrub_infop->header->tag << "'";
+    clog->info() << "scrub complete with tag '" << scrub_infop->header->get_tag() << "'";
   }
 }
 
index 7d03cf9281202d6708a314c005c053d09cba5c79..bcd6628f98308e90245208d61b61775bc2285f8b 100644 (file)
@@ -11845,7 +11845,7 @@ class C_MDS_EnqueueScrub : public Context
 public:
   ScrubHeaderRef header;
   C_MDS_EnqueueScrub(Formatter *f, Context *fin) :
-    formatter(f), on_finish(fin), header(new ScrubHeader()) {}
+    formatter(f), on_finish(fin), header(nullptr) {}
 
   Context *take_finisher() {
     Context *fin = on_finish;
@@ -11876,12 +11876,8 @@ void MDCache::enqueue_scrub(
   mdr->set_filepath(fp);
 
   C_MDS_EnqueueScrub *cs = new C_MDS_EnqueueScrub(f, fin);
-  ScrubHeaderRef &header = cs->header;
-  header->tag = tag;
-  header->force = force;
-  header->recursive = recursive;
-  header->repair = repair;
-  header->formatter = f;
+  cs->header = std::make_shared<ScrubHeader>(
+      tag, force, recursive, repair, f);
 
   mdr->internal_op_finish = cs;
   enqueue_scrub_work(mdr);
@@ -11912,11 +11908,11 @@ void MDCache::enqueue_scrub_work(MDRequestRef& mdr)
     in->scrub_info();
   }
 
-  header->origin = in;
+  header->set_origin(in);
 
   // only set completion context for non-recursive scrub, because we don't 
   // want to block asok caller on long running scrub
-  if (!header->recursive) {
+  if (!header->get_recursive()) {
     Context *fin = cs->take_finisher();
     mds->scrubstack->enqueue_inode_top(in, header,
                                       new MDSInternalContextWrapper(mds, fin));
index c5939304d4fd8db045348b14c11b0ec285af40dd..fc4a5a989eeecc88e23e1ab5bc4a908bfaf2bad3 100644 (file)
@@ -1,3 +1,17 @@
+// -*- mode:C++; tab-width:8; c-basic-offset:2; indent-tabs-mode:t -*- 
+// vim: ts=8 sw=2 smarttab
+/*
+ * Ceph - scalable distributed file system
+ *
+ * Copyright (C) 2016 Red Hat Inc
+ *
+ * This is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License version 2.1, as published by the Free Software
+ * Foundation.  See file COPYING.
+ *
+ */
+
 
 #ifndef SCRUB_HEADER_H_
 #define SCRUB_HEADER_H_
@@ -10,14 +24,34 @@ class CInode;
  */
 class ScrubHeader {
 public:
-  CInode *origin;
-  std::string tag;
+  ScrubHeader(std::string tag_, bool force_, bool recursive_,
+              bool repair_, Formatter *f_)
+      : tag(tag_), force(force_), recursive(recursive_), repair(repair_),
+        formatter(f_), origin(nullptr)
+  {
+    assert(formatter != nullptr);
+  }
+
+  // Set after construction because it won't be known until we've
+  // started resolving path and locking
+  void set_origin(CInode *origin_) { origin = origin_; }
 
-  bool force;
-  bool recursive;
-  bool repair;
-  Formatter *formatter;
+  bool get_recursive() const { return recursive; }
+  bool get_repair() const { return repair; }
+  bool get_force() const { return force; }
+  const CInode *get_origin() const { return origin; }
+  const std::string &get_tag() const { return tag; }
+  Formatter &get_formatter() const { return *formatter; }
+
+protected:
+  const std::string tag;
+  const bool force;
+  const bool recursive;
+  const bool repair;
+  Formatter * const formatter;
+  CInode *origin;
 };
+
 typedef ceph::shared_ptr<ScrubHeader> ScrubHeaderRef;
 typedef ceph::shared_ptr<const ScrubHeader> ScrubHeaderRefConst;
 
index 77525f3d3b3b2eaee487ba1319e2a60b2ba1aa11..5c9993bac14fabfab92fd938a8b81fec2b359156 100644 (file)
@@ -135,7 +135,7 @@ void ScrubStack::scrub_dir_inode(CInode *in,
 
   const ScrubHeaderRefConst& header = in->scrub_info()->header;
 
-  if (header->recursive) {
+  if (header->get_recursive()) {
     list<frag_t> scrubbing_frags;
     list<CDir*> scrubbing_cdirs;
     in->scrub_dirfrags_scrubbing(&scrubbing_frags);
@@ -379,13 +379,13 @@ void ScrubStack::_validate_inode_done(CInode *in, int r,
   MDSInternalContextBase *c = NULL;
   in->scrub_finished(&c);
 
-  if (!header->recursive && in == header->origin) {
+  if (!header->get_recursive() && in == header->get_origin()) {
     if (r >= 0) { // we got into the scrubbing dump it
-      result.dump(header->formatter);
+      result.dump(&(header->get_formatter()));
     } else { // we failed the lookup or something; dump ourselves
-      header->formatter->open_object_section("results");
-      header->formatter->dump_int("return_code", r);
-      header->formatter->close_section(); // results
+      header->get_formatter().open_object_section("results");
+      header->get_formatter().dump_int("return_code", r);
+      header->get_formatter().close_section(); // results
     }
   }
   if (c) {