]> git-server-git.apps.pok.os.sepia.ceph.com Git - ceph.git/commitdiff
mds: re-use C_KickOffScrubs context
authorYan, Zheng <zyan@redhat.com>
Tue, 10 Nov 2015 13:23:43 +0000 (21:23 +0800)
committerYan, Zheng <zyan@redhat.com>
Tue, 10 Nov 2015 14:21:34 +0000 (22:21 +0800)
Signed-off-by: Yan, Zheng <zyan@redhat.com>
src/mds/ScrubStack.cc
src/mds/ScrubStack.h

index f4ada6ed24b9337e4146dd14b5e95673bea020c2..9fe1c4622d4f0ae3c65a5cf919d8e0b27aaf95cf 100644 (file)
@@ -101,7 +101,7 @@ void ScrubStack::kick_off_scrubs()
 
       if (curi->is_file()) {
        if (!cur->scrub_info()->on_finish)
-         cur->scrub_set_finisher(new C_KickOffScrubs(mdcache->mds, this));
+         cur->scrub_set_finisher(&scrub_kick);
         scrub_file_dentry(cur);
         can_continue = true;
       } else {
@@ -229,7 +229,7 @@ void ScrubStack::scrub_dir_dentry(CDentry *dn,
     assert (!*added_children); // can't do this if children are still pending
 
     if (!dn->scrub_info()->on_finish)
-      dn->scrub_set_finisher(new C_KickOffScrubs(mdcache->mds, this));
+      dn->scrub_set_finisher(&scrub_kick);
 
     // OK, so now I can... fire off a validate on the dir inode, and
     // when it completes, come through here again, noticing that we've
@@ -255,8 +255,7 @@ bool ScrubStack::get_next_cdir(CInode *in, CDir **new_dir)
     dout(25) << "looking up new frag " << next_frag << dendl;
     CDir *next_dir = in->get_or_open_dirfrag(mdcache, next_frag);
     if (!next_dir->is_complete()) {
-      C_KickOffScrubs *c = new C_KickOffScrubs(mdcache->mds, this);
-      next_dir->fetch(c);
+      next_dir->fetch(&scrub_kick);
       dout(25) << "fetching frag from RADOS" << dendl;
       return false;
     }
@@ -325,7 +324,7 @@ void ScrubStack::scrub_dirfrag(CDir *dir, bool *added_children,
     // scrub initialize, so that it can populate its lists
     // of dentries.
     if (!dir->is_complete()) {
-      dir->fetch(new C_KickOffScrubs(mdcache->mds, this));
+      dir->fetch(&scrub_kick);
       return;
     }
 
@@ -334,13 +333,11 @@ void ScrubStack::scrub_dirfrag(CDir *dir, bool *added_children,
 
   int r = 0;
   while(r == 0) {
-    MDSInternalContext *kick = new C_KickOffScrubs(mdcache->mds, this);
     CDentry *dn = NULL;
-    r = dir->scrub_dentry_next(kick, &dn);
+    r = dir->scrub_dentry_next(&scrub_kick, &dn);
     if (r != EAGAIN) {
       // ctx only used by scrub_dentry_next in EAGAIN case
       // FIXME It's kind of annoying to keep allocating and deleting a ctx here
-      delete kick;
     }
 
     if (r == EAGAIN) {
@@ -438,3 +435,5 @@ void ScrubStack::_validate_inode_done(CDentry *dn, int r,
   }
 }
 
+ScrubStack::C_KickOffScrubs::C_KickOffScrubs(MDCache *mdcache, ScrubStack *s)
+  : MDSInternalContext(mdcache->mds), stack(s) { }
index fa99859fd2783d82432bb556ae2a28305865db56..c9bbbd0770507f5576a056b639c3be5c0623e610 100644 (file)
@@ -27,7 +27,7 @@ class MDCache;
 class Finisher;
 
 class ScrubStack {
-  protected:
+protected:
   /// A finisher needed so that we don't re-enter kick_off_scrubs
   Finisher *finisher;
 
@@ -37,6 +37,19 @@ class ScrubStack {
   int scrubs_in_progress;
   ScrubStack *scrubstack; // hack for dout
   int stack_size;
+
+  class C_KickOffScrubs : public MDSInternalContext {
+    ScrubStack *stack;
+  public:
+    C_KickOffScrubs(MDCache *mdcache, ScrubStack *s);
+    void finish(int r) { }
+    void complete(int r) {
+      stack->kick_off_scrubs();
+      // don't delete self
+    }
+  };
+  C_KickOffScrubs scrub_kick;
+
 public:
   MDCache *mdcache;
   ScrubStack(MDCache *mdc, Finisher *finisher_) :
@@ -45,6 +58,7 @@ public:
     scrubs_in_progress(0),
     scrubstack(this),
     stack_size(0),
+    scrub_kick(mdc, this),
     mdcache(mdc) {}
   ~ScrubStack() {
     assert(dentry_stack.empty());
@@ -181,17 +195,6 @@ private:
    */
   bool get_next_cdir(CInode *in, CDir **new_dir);
 
-  class C_KickOffScrubs : public MDSInternalContext {
-    ScrubStack *stack;
-  public:
-    C_KickOffScrubs(MDSRank *mds, ScrubStack *s)
-      : MDSInternalContext(mds), stack(s)
-    {
-    }
-    void finish(int r){
-      stack->kick_off_scrubs();
-    }
-  };
 };
 
 #endif /* SCRUBSTACK_H_ */