]> git.apps.os.sepia.ceph.com Git - ceph.git/commitdiff
mds: avoid wrapping contexts during logging
authorYan, Zheng <zyan@redhat.com>
Wed, 19 Oct 2016 15:41:43 +0000 (23:41 +0800)
committerYan, Zheng <zyan@redhat.com>
Fri, 21 Oct 2016 06:40:53 +0000 (14:40 +0800)
For each log event, mds allocate two extra contexts, one for
marking op tracker event, one for updating log's safe_pos after
executing the finish context. This is sub-optimization.

This patch defines MDSLogContextBase for log event context.
MDSLogContextBase::complete() function can do the extra jobs.

Signed-off-by: Yan, Zheng <zyan@redhat.com>
17 files changed:
src/mds/CInode.cc
src/mds/Locker.cc
src/mds/Locker.h
src/mds/MDCache.cc
src/mds/MDLog.cc
src/mds/MDLog.h
src/mds/MDSContext.cc
src/mds/MDSContext.h
src/mds/MDSTableClient.cc
src/mds/MDSTableServer.cc
src/mds/Migrator.cc
src/mds/Migrator.h
src/mds/Server.cc
src/mds/Server.h
src/mds/StrayManager.cc
src/mds/StrayManager.h
src/mds/journal.cc

index 5dcdcb1577f2fabe64ba92f937131b9d427d140e..12a0d9ca3164932297074eaf5db6b896dd0f80a2 100644 (file)
@@ -1874,7 +1874,7 @@ void CInode::start_scatter(ScatterLock *lock)
 }
 
 
-class C_Inode_FragUpdate : public MDSInternalContextBase {
+class C_Inode_FragUpdate : public MDSLogContextBase {
 protected:
   CInode *in;
   CDir *dir;
index 4cb7304ad91cf91c9b5b6155123794b2a98d9180..64a56af7fd5ca309bb0328150bf928cc30cd5788 100644 (file)
@@ -56,19 +56,32 @@ static ostream& _prefix(std::ostream *_dout, MDSRank *mds) {
 
 
 class LockerContext : public MDSInternalContextBase {
-  protected:
+protected:
   Locker *locker;
   MDSRank *get_mds()
   {
     return locker->mds;
   }
 
-  public:
+public:
   explicit LockerContext(Locker *locker_) : locker(locker_) {
     assert(locker != NULL);
   }
 };
 
+class LockerLogContext : public MDSLogContextBase {
+protected:
+  Locker *locker;
+  MDSRank *get_mds()
+  {
+    return locker->mds;
+  }
+
+public:
+  explicit LockerLogContext(Locker *locker_) : locker(locker_) {
+    assert(locker != NULL);
+  }
+};
 
 /* This function DOES put the passed message before returning */
 void Locker::dispatch(Message *m)
@@ -1686,7 +1699,7 @@ version_t Locker::issue_file_data_version(CInode *in)
   return in->inode.file_data_version;
 }
 
-class C_Locker_FileUpdate_finish : public LockerContext {
+class C_Locker_FileUpdate_finish : public LockerLogContext {
   CInode *in;
   MutationRef mut;
   bool share;
@@ -1698,7 +1711,7 @@ public:
                                bool e=false, client_t c=-1,
                                Capability *cp = 0,
                                MClientCaps *ac = 0)
-    : LockerContext(l), in(i), mut(m), share(e), client(c), cap(cp),
+    : LockerLogContext(l), in(i), mut(m), share(e), client(c), cap(cp),
       ack(ac) {
     in->get(CInode::PIN_PTRWAITER);
   }
@@ -4188,12 +4201,12 @@ Some notes on scatterlocks.
 
 */
 
-class C_Locker_ScatterWB : public LockerContext {
+class C_Locker_ScatterWB : public LockerLogContext {
   ScatterLock *lock;
   MutationRef mut;
 public:
   C_Locker_ScatterWB(Locker *l, ScatterLock *sl, MutationRef& m) :
-    LockerContext(l), lock(sl), mut(m) {}
+    LockerLogContext(l), lock(sl), mut(m) {}
   void finish(int r) { 
     locker->scatter_writebehind_finish(lock, mut); 
   }
index 189078f4f2c08c8187038f3dc47215d5f6ee4c09..5d9bde5803539404a3811ecfe1bcabf1ec172be1 100644 (file)
@@ -266,8 +266,9 @@ private:
   friend class C_Locker_FileUpdate_finish;
   friend class C_Locker_RetryCapRelease;
   friend class C_Locker_Eval;
-  friend class LockerContext;
   friend class C_Locker_ScatterWB;
+  friend class LockerContext;
+  friend class LockerLogContext;
 
   
   // -- client leases --
index e6c600d84b98599facc9870762e937385311392f..630c9be84399c9c1cf03b8a07163598acdd6fadd 100644 (file)
@@ -164,6 +164,17 @@ public:
   explicit MDCacheIOContext(MDCache *mdc_) : mdcache(mdc_) {}
 };
 
+class MDCacheLogContext : public virtual MDSLogContextBase {
+protected:
+  MDCache *mdcache;
+  virtual MDSRank *get_mds()
+  {
+    assert(mdcache != NULL);
+    return mdcache->mds;
+  }
+public:
+  explicit MDCacheLogContext(MDCache *mdc_) : mdcache(mdc_) {}
+};
 
 MDCache::MDCache(MDSRank *m) :
   mds(m),
@@ -472,13 +483,13 @@ void MDCache::create_mydir_hierarchy(MDSGather *gather)
   myin->store(gather->new_sub());
 }
 
-struct C_MDC_CreateSystemFile : public MDCacheContext {
+struct C_MDC_CreateSystemFile : public MDCacheLogContext {
   MutationRef mut;
   CDentry *dn;
   version_t dpv;
   MDSInternalContextBase *fin;
   C_MDC_CreateSystemFile(MDCache *c, MutationRef& mu, CDentry *d, version_t v, MDSInternalContextBase *f) :
-    MDCacheContext(c), mut(mu), dn(d), dpv(v), fin(f) {}
+    MDCacheLogContext(c), mut(mu), dn(d), dpv(v), fin(f) {}
   void finish(int r) {
     mdcache->_create_system_file_finish(mut, dn, dpv, fin);
   }
@@ -884,11 +895,11 @@ void MDCache::try_subtree_merge(CDir *dir)
     try_subtree_merge_at(*p);
 }
 
-class C_MDC_SubtreeMergeWB : public MDCacheContext {
+class C_MDC_SubtreeMergeWB : public MDCacheLogContext {
   CInode *in;
   MutationRef mut;
 public:
-  C_MDC_SubtreeMergeWB(MDCache *mdc, CInode *i, MutationRef& m) : MDCacheContext(mdc), in(i), mut(m) {}
+  C_MDC_SubtreeMergeWB(MDCache *mdc, CInode *i, MutationRef& m) : MDCacheLogContext(mdc), in(i), mut(m) {}
   void finish(int r) { 
     mdcache->subtree_merge_writebehind_finish(in, mut);
   }
@@ -2390,9 +2401,9 @@ void MDCache::predirty_journal_parents(MutationRef mut, EMetaBlob *blob,
  * remove them from the uncommitted_masters map (used during recovery
  * to commit|abort slaves).
  */
-struct C_MDC_CommittedMaster : public MDCacheContext {
+struct C_MDC_CommittedMaster : public MDCacheLogContext {
   metareqid_t reqid;
-  C_MDC_CommittedMaster(MDCache *s, metareqid_t r) : MDCacheContext(s), reqid(r) {}
+  C_MDC_CommittedMaster(MDCache *s, metareqid_t r) : MDCacheLogContext(s), reqid(r) {}
   void finish(int r) {
     mdcache->_logged_master_commit(reqid);
   }
@@ -2465,10 +2476,10 @@ void MDCache::finish_committed_masters()
  * masters when it reaches up:active (all other recovering nodes must
  * complete resolve before that happens).
  */
-struct C_MDC_SlaveCommit : public MDCacheContext {
+struct C_MDC_SlaveCommit : public MDCacheLogContext {
   mds_rank_t from;
   metareqid_t reqid;
-  C_MDC_SlaveCommit(MDCache *c, int f, metareqid_t r) : MDCacheContext(c), from(f), reqid(r) {}
+  C_MDC_SlaveCommit(MDCache *c, int f, metareqid_t r) : MDCacheLogContext(c), from(f), reqid(r) {}
   void finish(int r) {
     mdcache->_logged_slave_commit(from, reqid);
   }
@@ -5225,13 +5236,13 @@ void MDCache::rejoin_open_ino_finish(inodeno_t ino, int ret)
   }
 }
 
-class C_MDC_RejoinSessionsOpened : public MDCacheContext {
+class C_MDC_RejoinSessionsOpened : public MDCacheLogContext {
 public:
   map<client_t,entity_inst_t> client_map;
   map<client_t,uint64_t> sseqmap;
 
   C_MDC_RejoinSessionsOpened(MDCache *c, map<client_t,entity_inst_t>& cm) :
-    MDCacheContext(c), client_map(cm) {}
+    MDCacheLogContext(c), client_map(cm) {}
   void finish(int r) {
     assert(r == 0);
     mdcache->rejoin_open_sessions_finish(client_map, sseqmap);
@@ -6229,11 +6240,11 @@ void MDCache::_truncate_inode(CInode *in, LogSegment *ls)
                                           mds->finisher));
 }
 
-struct C_MDC_TruncateLogged : public MDCacheContext {
+struct C_MDC_TruncateLogged : public MDCacheLogContext {
   CInode *in;
   MutationRef mut;
   C_MDC_TruncateLogged(MDCache *m, CInode *i, MutationRef& mu) :
-    MDCacheContext(m), in(i), mut(mu) {}
+    MDCacheLogContext(m), in(i), mut(mu) {}
   void finish(int r) {
     mdcache->truncate_inode_logged(in, mut);
   }
@@ -9111,13 +9122,13 @@ void MDCache::request_kill(MDRequestRef& mdr)
 // -------------------------------------------------------------------------------
 // SNAPREALMS
 
-struct C_MDC_snaprealm_create_finish : public MDCacheContext {
+struct C_MDC_snaprealm_create_finish : public MDCacheLogContext {
   MDRequestRef mdr;
   MutationRef mut;
   CInode *in;
   C_MDC_snaprealm_create_finish(MDCache *c, MDRequestRef& m,
                                 MutationRef& mu, CInode *i) :
-    MDCacheContext(c), mdr(m), mut(mu), in(i) {}
+    MDCacheLogContext(c), mdr(m), mut(mu), in(i) {}
   void finish(int r) {
     mdcache->_snaprealm_create_finish(mdr, mut, in);
   }
@@ -10960,33 +10971,30 @@ void MDCache::find_stale_fragment_freeze()
   }
 }
 
-class C_MDC_FragmentPrep : public MDSInternalContext {
-  MDCache *mdcache;
+class C_MDC_FragmentPrep : public MDCacheLogContext {
   MDRequestRef mdr;
 public:
-  C_MDC_FragmentPrep(MDCache *m, MDRequestRef& r) : MDSInternalContext(m->mds), mdcache(m), mdr(r) {}
+  C_MDC_FragmentPrep(MDCache *m, MDRequestRef& r) : MDCacheLogContext(m),  mdr(r) {}
   virtual void finish(int r) {
     mdcache->_fragment_logged(mdr);
   }
 };
 
-class C_MDC_FragmentStore : public MDSInternalContext {
-  MDCache *mdcache;
+class C_MDC_FragmentStore : public MDCacheContext {
   MDRequestRef mdr;
 public:
-  C_MDC_FragmentStore(MDCache *m, MDRequestRef& r) : MDSInternalContext(m->mds), mdcache(m), mdr(r) {}
+  C_MDC_FragmentStore(MDCache *m, MDRequestRef& r) : MDCacheContext(m), mdr(r) {}
   virtual void finish(int r) {
     mdcache->_fragment_stored(mdr);
   }
 };
 
-class C_MDC_FragmentCommit : public MDSInternalContext {
-  MDCache *mdcache;
+class C_MDC_FragmentCommit : public MDCacheLogContext {
   dirfrag_t basedirfrag;
   list<CDir*> resultfrags;
 public:
   C_MDC_FragmentCommit(MDCache *m, dirfrag_t df, list<CDir*>& l) :
-    MDSInternalContext(m->mds), mdcache(m), basedirfrag(df), resultfrags(l) {}
+    MDCacheLogContext(m), basedirfrag(df), resultfrags(l) {}
   virtual void finish(int r) {
     mdcache->_fragment_committed(basedirfrag, resultfrags);
   }
@@ -11915,13 +11923,13 @@ void MDCache::enqueue_scrub_work(MDRequestRef& mdr)
   return;
 }
 
-struct C_MDC_RepairDirfragStats : public MDSInternalContext {
+struct C_MDC_RepairDirfragStats : public MDCacheLogContext {
   MDRequestRef mdr;
-  C_MDC_RepairDirfragStats(MDSRank *_mds, MDRequestRef& m) :
-    MDSInternalContext(_mds), mdr(m) {}
+  C_MDC_RepairDirfragStats(MDCache *c, MDRequestRef& m) :
+    MDCacheLogContext(c), mdr(m) {}
   void finish(int r) {
     mdr->apply();
-    mds->server->respond_to_request(mdr, r);
+    get_mds()->server->respond_to_request(mdr, r);
   }
 };
 
@@ -12024,7 +12032,7 @@ void MDCache::repair_dirfrag_stats_work(MDRequestRef& mdr)
   le->metablob.add_dir_context(dir);
   le->metablob.add_dir(dir, true);
 
-  mds->mdlog->submit_entry(le, new C_MDC_RepairDirfragStats(mds, mdr));
+  mds->mdlog->submit_entry(le, new C_MDC_RepairDirfragStats(this, mdr));
 }
 
 void MDCache::repair_inode_stats(CInode *diri)
index 77d1269bfff61491a32323582248f742a3e98e86..3a8b7ddb268c6de972a6b112d927ae3cb2c037c4 100644 (file)
@@ -271,7 +271,7 @@ void MDLog::cancel_entry(LogEvent *le)
   delete le;
 }
 
-void MDLog::_submit_entry(LogEvent *le, MDSInternalContextBase *c)
+void MDLog::_submit_entry(LogEvent *le, MDSLogContextBase *c)
 {
   assert(submit_mutex.is_locked_by_me());
   assert(!mds->is_any_replay());
@@ -283,7 +283,7 @@ void MDLog::_submit_entry(LogEvent *le, MDSInternalContextBase *c)
   if (!g_conf->mds_log) {
     // hack: log is disabled.
     if (c) {
-      c->complete(0);
+      mds->finisher->queue(c, 0);
     }
     return;
   }
@@ -334,27 +334,23 @@ void MDLog::_submit_entry(LogEvent *le, MDSInternalContextBase *c)
 /**
  * Invoked on the flush after each entry submitted
  */
-class C_MDL_Flushed : public MDSIOContextBase {
-  protected:
+class C_MDL_Flushed : public MDSLogContextBase {
+protected:
   MDLog *mdlog;
   MDSRank *get_mds() {return mdlog->mds;}
-  uint64_t flushed_to;
   MDSInternalContextBase *wrapped;
 
   void finish(int r) {
-    if (wrapped) {
+    if (wrapped)
       wrapped->complete(r);
-    }
-
-    mdlog->submit_mutex.Lock();
-    assert(mdlog->safe_pos <= flushed_to);
-    mdlog->safe_pos = flushed_to;
-    mdlog->submit_mutex.Unlock();
   }
 
-  public:
-  C_MDL_Flushed(MDLog *m, uint64_t ft, MDSInternalContextBase *w)
-    : mdlog(m), flushed_to(ft), wrapped(w) {}
+public:
+  C_MDL_Flushed(MDLog *m, MDSInternalContextBase *w)
+    : mdlog(m), wrapped(w) {}
+  C_MDL_Flushed(MDLog *m, uint64_t wp) : mdlog(m), wrapped(NULL) {
+    set_write_pos(wp);
+  }
 };
 
 void MDLog::_submit_thread()
@@ -405,8 +401,16 @@ void MDLog::_submit_thread()
       const uint64_t new_write_pos = journaler->append_entry(bl);  // bl is destroyed.
       ls->end = new_write_pos;
 
-      journaler->wait_for_flush(new C_MDL_Flushed(
-            this, new_write_pos, data.fin));
+      MDSLogContextBase *fin;
+      if (data.fin) {
+       fin = dynamic_cast<MDSLogContextBase*>(data.fin);
+       assert(fin);
+       fin->set_write_pos(new_write_pos);
+      } else {
+       fin = new C_MDL_Flushed(this, new_write_pos);
+      }
+
+      journaler->wait_for_flush(fin);
 
       if (data.flush)
        journaler->flush();
@@ -416,8 +420,14 @@ void MDLog::_submit_thread()
 
       delete le;
     } else {
-      journaler->wait_for_flush(new C_MDL_Flushed(
-            this, journaler->get_write_pos(), data.fin));
+      if (data.fin) {
+       MDSInternalContextBase* fin =
+               dynamic_cast<MDSInternalContextBase*>(data.fin);
+       assert(fin);
+       C_MDL_Flushed *fin2 = new C_MDL_Flushed(this, fin);
+       fin2->set_write_pos(journaler->get_write_pos());
+       journaler->wait_for_flush(fin2);
+      }
       if (data.flush)
        journaler->flush();
     }
@@ -566,7 +576,8 @@ void MDLog::_journal_segment_subtree_map(MDSInternalContextBase *onsync)
   dout(7) << __func__ << dendl;
   ESubtreeMap *sle = mds->mdcache->create_subtree_map();
   sle->event_seq = get_last_segment_seq();
-  _submit_entry(sle, onsync);
+
+  _submit_entry(sle, new C_MDL_Flushed(this, onsync));
 }
 
 void MDLog::trim(int m)
index e7658534117cfc8c80f7b2fedabffa851d030f3c..df22e68a8b1898b20af8c66fd27cfd867b31bd78 100644 (file)
@@ -129,15 +129,23 @@ protected:
 
   struct PendingEvent {
     LogEvent *le;
-    MDSInternalContextBase *fin;
+    MDSContext *fin;
     bool flush;
-    PendingEvent(LogEvent *e, MDSInternalContextBase *c, bool f=false) : le(e), fin(c), flush(f) {}
+    PendingEvent(LogEvent *e, MDSContext *c, bool f=false) : le(e), fin(c), flush(f) {}
   };
 
   map<uint64_t,list<PendingEvent> > pending_events; // log segment -> event list
   Mutex submit_mutex;
   Cond submit_cond;
 
+  void set_safe_pos(uint64_t pos)
+  {
+    Mutex::Locker l(submit_mutex);
+    assert(pos >= safe_pos);
+    safe_pos = pos;
+  }
+  friend class MDSLogContextBase;
+
   void _submit_thread();
   class SubmitThread : public Thread {
     MDLog *log;
@@ -268,13 +276,13 @@ public:
     _start_entry(e);
   }
   void cancel_entry(LogEvent *e);
-  void _submit_entry(LogEvent *e, MDSInternalContextBase *c);
-  void submit_entry(LogEvent *e, MDSInternalContextBase *c = 0) {
+  void _submit_entry(LogEvent *e, MDSLogContextBase *c);
+  void submit_entry(LogEvent *e, MDSLogContextBase *c = 0) {
     Mutex::Locker l(submit_mutex);
     _submit_entry(e, c);
     submit_cond.Signal();
   }
-  void start_submit_entry(LogEvent *e, MDSInternalContextBase *c = 0) {
+  void start_submit_entry(LogEvent *e, MDSLogContextBase *c = 0) {
     Mutex::Locker l(submit_mutex);
     _start_entry(e);
     _submit_entry(e, c);
index 493e97bb4204c8cf1d66bcb323ce38af8d2baa42..607031020c8de450683d72e5531d65afe91285bc 100644 (file)
@@ -45,7 +45,6 @@ void MDSInternalContextWrapper::finish(int r)
   fin->complete(r);
 }
 
-
 void MDSIOContextBase::complete(int r) {
   MDSRank *mds = get_mds();
 
@@ -66,6 +65,15 @@ void MDSIOContextBase::complete(int r) {
   }
 }
 
+void MDSLogContextBase::complete(int r) {
+  MDLog *mdlog = get_mds()->mdlog;
+  uint64_t safe_pos = write_pos;
+  pre_finish(r);
+  // MDSContextBase::complete() free this
+  MDSIOContextBase::complete(r);
+  mdlog->set_safe_pos(safe_pos);
+}
+
 MDSRank *MDSIOContext::get_mds() {
   return mds;
 }
index 57ab7d0660defe1254e33a9951ea3c9d87d85f44..1f46510b86f59c9b961ce5ccaef9936f30b57b30 100644 (file)
@@ -81,6 +81,22 @@ public:
   void complete(int r);
 };
 
+/**
+ * Completion for an log operation, takes big MDSRank lock
+ * before executing finish function. Update log's safe pos
+ * after finish functuon return.
+ */
+class MDSLogContextBase : public MDSIOContextBase
+{
+protected:
+  uint64_t write_pos;
+public:
+  MDSLogContextBase() : write_pos(0) {}
+  void complete(int r) final;
+  void set_write_pos(uint64_t wp) { write_pos = wp; }
+  virtual void pre_finish(int r) {}
+};
+
 /**
  * Completion for an I/O operation, takes big MDSRank lock
  * before executing finish function.
@@ -137,7 +153,6 @@ protected:
     wrapped->complete(r);
     wrapped = nullptr;
   }
-  virtual void complete(int r) final;
 public:
   C_IO_Wrapper(MDSRank *mds_, MDSInternalContextBase *wrapped_) :
     MDSIOContext(mds_), async(true), wrapped(wrapped_) {
@@ -150,6 +165,7 @@ public:
       wrapped = nullptr;
     }
   }
+  virtual void complete(int r) final;
 };
 
 
index b4eacf5ffe5ed2b0ca0d174792047e6082ebfba9..f56c4ff8fbbc84059159faa3971515fe3ce5ea65 100644 (file)
 #define dout_prefix *_dout << "mds." << mds->get_nodeid() << ".tableclient(" << get_mdstable_name(table) << ") "
 
 
-class C_LoggedAck : public MDSInternalContext {
+class C_LoggedAck : public MDSLogContextBase {
   MDSTableClient *tc;
   version_t tid;
+  MDSRank *get_mds() { return tc->mds; }
 public:
-  C_LoggedAck(MDSTableClient *a, version_t t) : MDSInternalContext(a->mds), tc(a), tid(t) {}
+  C_LoggedAck(MDSTableClient *a, version_t t) : tc(a), tid(t) {}
   void finish(int r) {
     tc->_logged_ack(tid);
   }
index 13463e00906fb267b79130a1ea45e82434993bd1..5e7ec3fbdedb0a0fa82439f8600d435325d19185 100644 (file)
@@ -37,13 +37,14 @@ void MDSTableServer::handle_request(MMDSTableRequest *req)
   }
 }
 
-class C_Prepare : public MDSInternalContext {
+class C_Prepare : public MDSLogContextBase {
   MDSTableServer *server;
   MMDSTableRequest *req;
   version_t tid;
+  MDSRank *get_mds() { return server->mds; }
 public:
 
-  C_Prepare(MDSTableServer *s, MMDSTableRequest *r, version_t v) : MDSInternalContext(s->mds), server(s), req(r), tid(v) {}
+  C_Prepare(MDSTableServer *s, MMDSTableRequest *r, version_t v) : server(s), req(r), tid(v) {}
   void finish(int r) {
     server->_prepare_logged(req, tid);
   }
@@ -81,11 +82,12 @@ void MDSTableServer::_prepare_logged(MMDSTableRequest *req, version_t tid)
   req->put();
 }
 
-class C_Commit : public MDSInternalContext {
+class C_Commit : public MDSLogContextBase {
   MDSTableServer *server;
   MMDSTableRequest *req;
+  MDSRank *get_mds() { return server->mds; }
 public:
-  C_Commit(MDSTableServer *s, MMDSTableRequest *r) : MDSInternalContext(s->mds), server(s), req(r) {}
+  C_Commit(MDSTableServer *s, MMDSTableRequest *r) : server(s), req(r) {}
   void finish(int r) {
     server->_commit_logged(req);
   }
index 501216d079e19686e50076605eae42e471625486..c5bdd04f378f20d8afdff2d5c924fa6b0df0abea 100644 (file)
@@ -95,6 +95,17 @@ public:
   }
 };
 
+class MigratorLogContext : public MDSLogContextBase {
+protected:
+  Migrator *mig;
+  MDSRank *get_mds() {
+    return mig->mds;
+  }
+public:
+  explicit MigratorLogContext(Migrator *mig_) : mig(mig_) {
+    assert(mig != NULL);
+  }
+};
 
 /* This function DOES put the passed message before returning*/
 void Migrator::dispatch(Message *m)
@@ -1535,10 +1546,10 @@ void Migrator::finish_export_dir(CDir *dir, utime_t now, mds_rank_t peer,
     finish_export_dir(*it, now, peer, peer_imported, finished, num_dentries);
 }
 
-class C_MDS_ExportFinishLogged : public MigratorContext {
+class C_MDS_ExportFinishLogged : public MigratorLogContext {
   CDir *dir;
 public:
-  C_MDS_ExportFinishLogged(Migrator *m, CDir *d) : MigratorContext(m), dir(d) {}
+  C_MDS_ExportFinishLogged(Migrator *m, CDir *d) : MigratorLogContext(m), dir(d) {}
   void finish(int r) {
     mig->export_logged_finish(dir);
   }
@@ -2183,7 +2194,7 @@ void Migrator::handle_export_prep(MExportDirPrep *m)
 
 
 
-class C_MDS_ImportDirLoggedStart : public MigratorContext {
+class C_MDS_ImportDirLoggedStart : public MigratorLogContext {
   dirfrag_t df;
   CDir *dir;
   mds_rank_t from;
@@ -2192,7 +2203,7 @@ public:
   map<client_t,uint64_t> sseqmap;
 
   C_MDS_ImportDirLoggedStart(Migrator *m, CDir *d, mds_rank_t f) :
-    MigratorContext(m), df(d->dirfrag()), dir(d), from(f) {
+    MigratorLogContext(m), df(d->dirfrag()), dir(d), from(f) {
   }
   void finish(int r) {
     mig->import_logged_start(df, dir, from, imported_client_map, sseqmap);
@@ -3037,7 +3048,7 @@ out:
   m->put();
 }
 
-class C_M_LoggedImportCaps : public MigratorContext {
+class C_M_LoggedImportCaps : public MigratorLogContext {
   CInode *in;
   mds_rank_t from;
 public:
@@ -3045,7 +3056,7 @@ public:
   map<client_t,entity_inst_t> client_map;
   map<client_t,uint64_t> sseqmap;
 
-  C_M_LoggedImportCaps(Migrator *m, CInode *i, mds_rank_t f) : MigratorContext(m), in(i), from(f) {}
+  C_M_LoggedImportCaps(Migrator *m, CInode *i, mds_rank_t f) : MigratorLogContext(m), in(i), from(f) {}
   void finish(int r) {
     mig->logged_import_caps(in, from, peer_exports, client_map, sseqmap);
   }  
index 5872933f77947b246f03a56dd1a3546d992700ff..d991ef873242ee4beabf3ec692ecc0cf4a73f221 100644 (file)
@@ -291,6 +291,7 @@ public:
   friend class C_M_ExportGo;
   friend class C_M_ExportSessionsFlushed;
   friend class MigratorContext;
+  friend class MigratorLogContext;
 
   // importer
   void handle_export_discover(MExportDirDiscover *m);
index 3a7b88778d4ce0d925052a54d47d977a7b114c61..9207cde01a4289a51b6962b6bdd1ea8acd56a5cc 100644 (file)
@@ -85,6 +85,27 @@ class ServerContext : public MDSInternalContextBase {
   }
 };
 
+class ServerLogContext : public MDSLogContextBase {
+protected:
+  Server *server;
+  MDSRank *get_mds()
+  {
+    return server->mds;
+  }
+
+  MDRequestRef mdr;
+  void pre_finish(int r) {
+    if (mdr)
+      mdr->mark_event("journal_committed: ");
+  }
+public:
+  explicit ServerLogContext(Server *s) : server(s) {
+    assert(server != NULL);
+  }
+  explicit ServerLogContext(Server *s, MDRequestRef& r) : server(s), mdr(r) {
+    assert(server != NULL);
+  }
+};
 
 void Server::create_logger()
 {
@@ -205,7 +226,7 @@ void Server::dispatch(Message *m)
 // ----------------------------------------------------------
 // SESSION management
 
-class C_MDS_session_finish : public MDSInternalContext {
+class C_MDS_session_finish : public ServerLogContext {
   Session *session;
   uint64_t state_seq;
   bool open;
@@ -214,13 +235,13 @@ class C_MDS_session_finish : public MDSInternalContext {
   version_t inotablev;
   Context *fin;
 public:
-  C_MDS_session_finish(MDSRank *m, Session *se, uint64_t sseq, bool s, version_t mv, Context *fin_ = NULL) :
-    MDSInternalContext(m), session(se), state_seq(sseq), open(s), cmapv(mv), inotablev(0), fin(fin_) { }
-  C_MDS_session_finish(MDSRank *m, Session *se, uint64_t sseq, bool s, version_t mv, interval_set<inodeno_t>& i, version_t iv, Context *fin_ = NULL) :
-    MDSInternalContext(m), session(se), state_seq(sseq), open(s), cmapv(mv), inos(i), inotablev(iv), fin(fin_) { }
+  C_MDS_session_finish(Server *srv, Session *se, uint64_t sseq, bool s, version_t mv, Context *fin_ = NULL) :
+    ServerLogContext(srv), session(se), state_seq(sseq), open(s), cmapv(mv), inotablev(0), fin(fin_) { }
+  C_MDS_session_finish(Server *srv, Session *se, uint64_t sseq, bool s, version_t mv, interval_set<inodeno_t>& i, version_t iv, Context *fin_ = NULL) :
+    ServerLogContext(srv), session(se), state_seq(sseq), open(s), cmapv(mv), inos(i), inotablev(iv), fin(fin_) { }
   void finish(int r) {
     assert(r == 0);
-    mds->server->_session_logged(session, state_seq, open, cmapv, inos, inotablev);
+    server->_session_logged(session, state_seq, open, cmapv, inos, inotablev);
     if (fin) {
       fin->complete(r);
     }
@@ -307,7 +328,7 @@ void Server::handle_client_session(MClientSession *m)
     sseq = mds->sessionmap.set_state(session, Session::STATE_OPENING);
     mds->sessionmap.touch_session(session);
     mdlog->start_submit_entry(new ESession(m->get_source_inst(), true, pv, m->client_meta),
-                             new C_MDS_session_finish(mds, session, sseq, true, pv));
+                             new C_MDS_session_finish(this, session, sseq, true, pv));
     mdlog->flush();
     break;
 
@@ -696,7 +717,7 @@ void Server::journal_close_session(Session *session, int state, Context *on_safe
     piv = 0;
 
   mdlog->start_submit_entry(new ESession(session->info.inst, false, pv, both, piv),
-                           new C_MDS_session_finish(mds, session, sseq, false, pv, both, piv, on_safe));
+                           new C_MDS_session_finish(this, session, sseq, false, pv, both, piv, on_safe));
   mdlog->flush();
 
   // clean up requests, too
@@ -960,7 +981,7 @@ void Server::force_clients_readonly()
 /*******
  * some generic stuff for finishing off requests
  */
-void Server::journal_and_reply(MDRequestRef& mdr, CInode *in, CDentry *dn, LogEvent *le, MDSInternalContextBase *fin)
+void Server::journal_and_reply(MDRequestRef& mdr, CInode *in, CDentry *dn, LogEvent *le, MDSLogContextBase *fin)
 {
   dout(10) << "journal_and_reply tracei " << in << " tracedn " << dn << dendl;
   assert(!mdr->has_completed);
@@ -992,35 +1013,15 @@ void Server::journal_and_reply(MDRequestRef& mdr, CInode *in, CDentry *dn, LogEv
     mdlog->flush();
 }
 
-class C_MarkEvent : public MDSInternalContext
-{
-  Context *true_finisher;
-  MDRequestRef mdr;
-  string event_str;
-public:
-  C_MarkEvent(MDSRank *mds_, Context *f, MDRequestRef& _mdr,
-                const char *evt)
-    : MDSInternalContext(mds_), true_finisher(f), mdr(_mdr),
-      event_str("journal_committed: ") {
-    event_str += evt;
-  }
-  virtual void finish(int r) {
-    mdr->mark_event(event_str);
-    true_finisher->complete(r);
-  }
-};
-
-
-void Server::submit_mdlog_entry(LogEvent *le, MDSInternalContextBase *fin, MDRequestRef& mdr,
+void Server::submit_mdlog_entry(LogEvent *le, MDSLogContextBase *fin, MDRequestRef& mdr,
                                 const char *event)
 {
   if (mdr) {
     string event_str("submit entry: ");
     event_str += event;
     mdr->mark_event(event_str);
-    mdlog->submit_entry(le, new C_MarkEvent(mds, fin, mdr, event));
-  } else
-    mdlog->submit_entry(le, fin);
+  } 
+  mdlog->submit_entry(le, fin);
 }
 
 /*
@@ -3077,14 +3078,13 @@ void Server::handle_client_open(MDRequestRef& mdr)
   respond_to_request(mdr, 0);
 }
 
-class C_MDS_openc_finish : public MDSInternalContext {
-  MDRequestRef mdr;
+class C_MDS_openc_finish : public ServerLogContext { 
   CDentry *dn;
   CInode *newi;
   snapid_t follows;
 public:
-  C_MDS_openc_finish(MDSRank *m, MDRequestRef& r, CDentry *d, CInode *ni, snapid_t f) :
-    MDSInternalContext(m), mdr(r), dn(d), newi(ni), follows(f) {}
+  C_MDS_openc_finish(Server *s, MDRequestRef& r, CDentry *d, CInode *ni, snapid_t f) :
+    ServerLogContext(s, r), dn(d), newi(ni), follows(f) {}
   void finish(int r) {
     assert(r == 0);
 
@@ -3097,14 +3097,14 @@ public:
 
     mdr->apply();
 
-    mds->locker->share_inode_max_size(newi);
+    get_mds()->locker->share_inode_max_size(newi);
 
     MDRequestRef null_ref;
-    mds->mdcache->send_dentry_link(dn, null_ref);
+    get_mds()->mdcache->send_dentry_link(dn, null_ref);
 
-    mds->balancer->hit_inode(mdr->get_mds_stamp(), newi, META_POP_IWR);
+    get_mds()->balancer->hit_inode(mdr->get_mds_stamp(), newi, META_POP_IWR);
 
-    mds->server->respond_to_request(mdr, 0);
+    server->respond_to_request(mdr, 0);
 
     assert(g_conf->mds_kill_openc_at != 1);
   }
@@ -3277,7 +3277,7 @@ void Server::handle_client_openc(MDRequestRef& mdr)
   LogSegment *ls = mds->mdlog->get_current_segment();
   ls->open_files.push_back(&in->item_open_file);
 
-  C_MDS_openc_finish *fin = new C_MDS_openc_finish(mds, mdr, dn, in, follows);
+  C_MDS_openc_finish *fin = new C_MDS_openc_finish(this, mdr, dn, in, follows);
 
   if (mdr->client_request->get_connection()->has_feature(CEPH_FEATURE_REPLY_CREATE_INODE)) {
     dout(10) << "adding ino to reply to indicate inode was created" << dendl;
@@ -3535,14 +3535,13 @@ void Server::handle_client_readdir(MDRequestRef& mdr)
 /* 
  * finisher for basic inode updates
  */
-class C_MDS_inode_update_finish : public MDSInternalContext {
-  MDRequestRef mdr;
+class C_MDS_inode_update_finish : public ServerLogContext {
   CInode *in;
   bool truncating_smaller, changed_ranges;
 public:
-  C_MDS_inode_update_finish(MDSRank *m, MDRequestRef& r, CInode *i,
+  C_MDS_inode_update_finish(Server *s, MDRequestRef& r, CInode *i,
                            bool sm=false, bool cr=false) :
-    MDSInternalContext(m), mdr(r), in(i), truncating_smaller(sm), changed_ranges(cr) { }
+    ServerLogContext(s, r), in(i), truncating_smaller(sm), changed_ranges(cr) { }
   void finish(int r) {
     assert(r == 0);
 
@@ -3552,16 +3551,16 @@ public:
 
     // notify any clients
     if (truncating_smaller && in->inode.is_truncating()) {
-      mds->locker->issue_truncate(in);
-      mds->mdcache->truncate_inode(in, mdr->ls);
+      get_mds()->locker->issue_truncate(in);
+      get_mds()->mdcache->truncate_inode(in, mdr->ls);
     }
 
-    mds->balancer->hit_inode(mdr->get_mds_stamp(), in, META_POP_IWR);
+    get_mds()->balancer->hit_inode(mdr->get_mds_stamp(), in, META_POP_IWR);
 
-    mds->server->respond_to_request(mdr, 0);
+    server->respond_to_request(mdr, 0);
 
     if (changed_ranges)
-      mds->locker->share_inode_max_size(in);
+      get_mds()->locker->share_inode_max_size(in);
   }
 };
 
@@ -3837,7 +3836,7 @@ void Server::handle_client_setattr(MDRequestRef& mdr)
   mdcache->predirty_journal_parents(mdr, &le->metablob, cur, 0, PREDIRTY_PRIMARY);
   mdcache->journal_dirty_inode(mdr.get(), &le->metablob, cur);
   
-  journal_and_reply(mdr, cur, 0, le, new C_MDS_inode_update_finish(mds, mdr, cur,
+  journal_and_reply(mdr, cur, 0, le, new C_MDS_inode_update_finish(this, mdr, cur,
                                                                   truncating_smaller, changed_ranges));
 
   // flush immediately if there are readers/writers waiting
@@ -3900,7 +3899,7 @@ void Server::do_open_truncate(MDRequestRef& mdr, int cmode)
     dn = mdr->dn[0].back();
   }
 
-  journal_and_reply(mdr, in, dn, le, new C_MDS_inode_update_finish(mds, mdr, in, old_size > 0,
+  journal_and_reply(mdr, in, dn, le, new C_MDS_inode_update_finish(this, mdr, in, old_size > 0,
                                                                   changed_ranges));
   // Although the `open` part can give an early reply, the truncation won't
   // happen until our EUpdate is persistent, to give the client a prompt
@@ -3992,7 +3991,7 @@ void Server::handle_client_setlayout(MDRequestRef& mdr)
   mdcache->predirty_journal_parents(mdr, &le->metablob, cur, 0, PREDIRTY_PRIMARY);
   mdcache->journal_dirty_inode(mdr.get(), &le->metablob, cur);
   
-  journal_and_reply(mdr, cur, 0, le, new C_MDS_inode_update_finish(mds, mdr, cur));
+  journal_and_reply(mdr, cur, 0, le, new C_MDS_inode_update_finish(this, mdr, cur));
 }
 
 void Server::handle_client_setdirlayout(MDRequestRef& mdr)
@@ -4073,7 +4072,7 @@ void Server::handle_client_setdirlayout(MDRequestRef& mdr)
   mdcache->predirty_journal_parents(mdr, &le->metablob, cur, 0, PREDIRTY_PRIMARY);
   mdcache->journal_dirty_inode(mdr.get(), &le->metablob, cur);
 
-  journal_and_reply(mdr, cur, 0, le, new C_MDS_inode_update_finish(mds, mdr, cur));
+  journal_and_reply(mdr, cur, 0, le, new C_MDS_inode_update_finish(this, mdr, cur));
 }
 
 // XATTRS
@@ -4375,7 +4374,7 @@ void Server::handle_set_vxattr(MDRequestRef& mdr, CInode *cur,
   mdcache->predirty_journal_parents(mdr, &le->metablob, cur, 0, PREDIRTY_PRIMARY);
   mdcache->journal_dirty_inode(mdr.get(), &le->metablob, cur);
 
-  journal_and_reply(mdr, cur, 0, le, new C_MDS_inode_update_finish(mds, mdr, cur));
+  journal_and_reply(mdr, cur, 0, le, new C_MDS_inode_update_finish(this, mdr, cur));
   return;
 }
 
@@ -4418,20 +4417,19 @@ void Server::handle_remove_vxattr(MDRequestRef& mdr, CInode *cur,
     mdcache->predirty_journal_parents(mdr, &le->metablob, cur, 0, PREDIRTY_PRIMARY);
     mdcache->journal_dirty_inode(mdr.get(), &le->metablob, cur);
 
-    journal_and_reply(mdr, cur, 0, le, new C_MDS_inode_update_finish(mds, mdr, cur));
+    journal_and_reply(mdr, cur, 0, le, new C_MDS_inode_update_finish(this, mdr, cur));
     return;
   }
 
   respond_to_request(mdr, -ENODATA);
 }
 
-class C_MDS_inode_xattr_update_finish : public MDSInternalContext {
-  MDRequestRef mdr;
+class C_MDS_inode_xattr_update_finish : public ServerLogContext {
   CInode *in;
 public:
 
-  C_MDS_inode_xattr_update_finish(MDSRank *m, MDRequestRef& r, CInode *i) :
-    MDSInternalContext(m), mdr(r), in(i) { }
+  C_MDS_inode_xattr_update_finish(Server *s, MDRequestRef& r, CInode *i) :
+    ServerLogContext(s, r), in(i) { }
   void finish(int r) {
     assert(r == 0);
 
@@ -4440,9 +4438,9 @@ public:
     
     mdr->apply();
 
-    mds->balancer->hit_inode(mdr->get_mds_stamp(), in, META_POP_IWR);
+    get_mds()->balancer->hit_inode(mdr->get_mds_stamp(), in, META_POP_IWR);
 
-    mds->server->respond_to_request(mdr, 0);
+    server->respond_to_request(mdr, 0);
   }
 };
 
@@ -4518,7 +4516,7 @@ void Server::handle_client_setxattr(MDRequestRef& mdr)
   mdcache->predirty_journal_parents(mdr, &le->metablob, cur, 0, PREDIRTY_PRIMARY);
   mdcache->journal_dirty_inode(mdr.get(), &le->metablob, cur);
 
-  journal_and_reply(mdr, cur, 0, le, new C_MDS_inode_update_finish(mds, mdr, cur));
+  journal_and_reply(mdr, cur, 0, le, new C_MDS_inode_update_finish(this, mdr, cur));
 }
 
 void Server::handle_client_removexattr(MDRequestRef& mdr)
@@ -4575,7 +4573,7 @@ void Server::handle_client_removexattr(MDRequestRef& mdr)
   mdcache->predirty_journal_parents(mdr, &le->metablob, cur, 0, PREDIRTY_PRIMARY);
   mdcache->journal_dirty_inode(mdr.get(), &le->metablob, cur);
 
-  journal_and_reply(mdr, cur, 0, le, new C_MDS_inode_update_finish(mds, mdr, cur));
+  journal_and_reply(mdr, cur, 0, le, new C_MDS_inode_update_finish(this, mdr, cur));
 }
 
 
@@ -4587,13 +4585,12 @@ void Server::handle_client_removexattr(MDRequestRef& mdr)
 
 // MKNOD
 
-class C_MDS_mknod_finish : public MDSInternalContext {
-  MDRequestRef mdr;
+class C_MDS_mknod_finish : public ServerLogContext {
   CDentry *dn;
   CInode *newi;
 public:
-  C_MDS_mknod_finish(MDSRank *m, MDRequestRef& r, CDentry *d, CInode *ni) :
-    MDSInternalContext(m), mdr(r), dn(d), newi(ni) {}
+  C_MDS_mknod_finish(Server *s, MDRequestRef& r, CDentry *d, CInode *ni) :
+    ServerLogContext(s, r), dn(d), newi(ni) {}
   void finish(int r) {
     assert(r == 0);
 
@@ -4619,16 +4616,16 @@ public:
     mdr->apply();
 
     MDRequestRef null_ref;
-    mds->mdcache->send_dentry_link(dn, null_ref);
+    get_mds()->mdcache->send_dentry_link(dn, null_ref);
 
     if (newi->inode.is_file())
-      mds->locker->share_inode_max_size(newi);
+      get_mds()->locker->share_inode_max_size(newi);
 
     // hit pop
-    mds->balancer->hit_inode(mdr->get_mds_stamp(), newi, META_POP_IWR);
+    get_mds()->balancer->hit_inode(mdr->get_mds_stamp(), newi, META_POP_IWR);
 
     // reply
-    mds->server->respond_to_request(mdr, 0);
+    server->respond_to_request(mdr, 0);
   }
 };
 
@@ -4723,7 +4720,7 @@ void Server::handle_client_mknod(MDRequestRef& mdr)
                                    PREDIRTY_PRIMARY|PREDIRTY_DIR, 1);
   le->metablob.add_primary_dentry(dn, newi, true, true, true);
 
-  journal_and_reply(mdr, newi, dn, le, new C_MDS_mknod_finish(mds, mdr, dn, newi));
+  journal_and_reply(mdr, newi, dn, le, new C_MDS_mknod_finish(this, mdr, dn, newi));
 }
 
 
@@ -4808,7 +4805,7 @@ void Server::handle_client_mkdir(MDRequestRef& mdr)
   LogSegment *ls = mds->mdlog->get_current_segment();
   ls->open_files.push_back(&newi->item_open_file);
 
-  journal_and_reply(mdr, newi, dn, le, new C_MDS_mknod_finish(mds, mdr, dn, newi));
+  journal_and_reply(mdr, newi, dn, le, new C_MDS_mknod_finish(this, mdr, dn, newi));
 }
 
 
@@ -4861,7 +4858,7 @@ void Server::handle_client_symlink(MDRequestRef& mdr)
   mdcache->predirty_journal_parents(mdr, &le->metablob, newi, dn->get_dir(), PREDIRTY_PRIMARY|PREDIRTY_DIR, 1);
   le->metablob.add_primary_dentry(dn, newi, true, true);
 
-  journal_and_reply(mdr, newi, dn, le, new C_MDS_mknod_finish(mds, mdr, dn, newi));
+  journal_and_reply(mdr, newi, dn, le, new C_MDS_mknod_finish(this, mdr, dn, newi));
 }
 
 
@@ -4923,20 +4920,19 @@ void Server::handle_client_link(MDRequestRef& mdr)
 }
 
 
-class C_MDS_link_local_finish : public MDSInternalContext {
-  MDRequestRef mdr;
+class C_MDS_link_local_finish : public ServerLogContext {
   CDentry *dn;
   CInode *targeti;
   version_t dnpv;
   version_t tipv;
 public:
-  C_MDS_link_local_finish(MDSRank *m, MDRequestRef& r, CDentry *d, CInode *ti,
+  C_MDS_link_local_finish(Server *s, MDRequestRef& r, CDentry *d, CInode *ti,
                          version_t dnpv_, version_t tipv_) :
-    MDSInternalContext(m), mdr(r), dn(d), targeti(ti),
+    ServerLogContext(s, r), dn(d), targeti(ti),
     dnpv(dnpv_), tipv(tipv_) { }
   void finish(int r) {
     assert(r == 0);
-    mds->server->_link_local_finish(mdr, dn, targeti, dnpv, tipv);
+    server->_link_local_finish(mdr, dn, targeti, dnpv, tipv);
   }
 };
 
@@ -4970,7 +4966,7 @@ void Server::_link_local(MDRequestRef& mdr, CDentry *dn, CInode *targeti)
   // do this after predirty_*, to avoid funky extra dnl arg
   dn->push_projected_linkage(targeti->ino(), targeti->d_type());
 
-  journal_and_reply(mdr, targeti, dn, le, new C_MDS_link_local_finish(mds, mdr, dn, targeti, dnpv, tipv));
+  journal_and_reply(mdr, targeti, dn, le, new C_MDS_link_local_finish(this, mdr, dn, targeti, dnpv, tipv));
 }
 
 void Server::_link_local_finish(MDRequestRef& mdr, CDentry *dn, CInode *targeti,
@@ -5001,19 +4997,18 @@ void Server::_link_local_finish(MDRequestRef& mdr, CDentry *dn, CInode *targeti,
 
 // link / unlink remote
 
-class C_MDS_link_remote_finish : public MDSInternalContext {
-  MDRequestRef mdr;
+class C_MDS_link_remote_finish : public ServerLogContext {
   bool inc;
   CDentry *dn;
   CInode *targeti;
   version_t dpv;
 public:
-  C_MDS_link_remote_finish(MDSRank *m, MDRequestRef& r, bool i, CDentry *d, CInode *ti) :
-    MDSInternalContext(m), mdr(r), inc(i), dn(d), targeti(ti),
+  C_MDS_link_remote_finish(Server *s, MDRequestRef& r, bool i, CDentry *d, CInode *ti) :
+    ServerLogContext(s, r), inc(i), dn(d), targeti(ti),
     dpv(d->get_projected_version()) {}
   void finish(int r) {
     assert(r == 0);
-    mds->server->_link_remote_finish(mdr, inc, dn, targeti, dpv);
+    server->_link_remote_finish(mdr, inc, dn, targeti, dpv);
   }
 };
 
@@ -5078,7 +5073,7 @@ void Server::_link_remote(MDRequestRef& mdr, bool inc, CDentry *dn, CInode *targ
     le->metablob.add_null_dentry(dn, true);
   }
 
-  journal_and_reply(mdr, targeti, dn, le, new C_MDS_link_remote_finish(mds, mdr, inc, dn, targeti));
+  journal_and_reply(mdr, targeti, dn, le, new C_MDS_link_remote_finish(this, mdr, inc, dn, targeti));
 }
 
 void Server::_link_remote_finish(MDRequestRef& mdr, bool inc,
@@ -5127,12 +5122,11 @@ void Server::_link_remote_finish(MDRequestRef& mdr, bool inc,
 
 // remote linking/unlinking
 
-class C_MDS_SlaveLinkPrep : public ServerContext {
-  MDRequestRef mdr;
+class C_MDS_SlaveLinkPrep : public ServerLogContext {
   CInode *targeti;
 public:
   C_MDS_SlaveLinkPrep(Server *s, MDRequestRef& r, CInode *t) :
-    ServerContext(s), mdr(r), targeti(t) { }
+    ServerLogContext(s, r), targeti(t) { }
   void finish(int r) {
     assert(r == 0);
     server->_logged_slave_link(mdr, targeti);
@@ -5250,9 +5244,8 @@ void Server::_logged_slave_link(MDRequestRef& mdr, CInode *targeti)
 }
 
 
-struct C_MDS_CommittedSlave : public ServerContext {
-  MDRequestRef mdr;
-  C_MDS_CommittedSlave(Server *s, MDRequestRef& m) : ServerContext(s), mdr(m) {}
+struct C_MDS_CommittedSlave : public ServerLogContext {
+  C_MDS_CommittedSlave(Server *s, MDRequestRef& m) : ServerLogContext(s, m) {}
   void finish(int r) {
     server->_committed_slave(mdr);
   }
@@ -5292,10 +5285,9 @@ void Server::_committed_slave(MDRequestRef& mdr)
   mdcache->request_finish(mdr);
 }
 
-struct C_MDS_LoggedLinkRollback : public ServerContext {
+struct C_MDS_LoggedLinkRollback : public ServerLogContext {
   MutationRef mut;
-  MDRequestRef mdr;
-  C_MDS_LoggedLinkRollback(Server *s, MutationRef& m, MDRequestRef& r) : ServerContext(s), mut(m), mdr(r) {}
+  C_MDS_LoggedLinkRollback(Server *s, MutationRef& m, MDRequestRef& r) : ServerLogContext(s, r), mut(m) {}
   void finish(int r) {
     server->_link_rollback_finish(mut, mdr);
   }
@@ -5552,18 +5544,17 @@ void Server::handle_client_unlink(MDRequestRef& mdr)
     _unlink_local(mdr, dn, straydn);
 }
 
-class C_MDS_unlink_local_finish : public MDSInternalContext {
-  MDRequestRef mdr;
+class C_MDS_unlink_local_finish : public ServerLogContext {
   CDentry *dn;
   CDentry *straydn;
   version_t dnpv;  // deleted dentry
 public:
-  C_MDS_unlink_local_finish(MDSRank *m, MDRequestRef& r, CDentry *d, CDentry *sd) :
-    MDSInternalContext(m), mdr(r), dn(d), straydn(sd),
+  C_MDS_unlink_local_finish(Server *s, MDRequestRef& r, CDentry *d, CDentry *sd) :
+    ServerLogContext(s, r), dn(d), straydn(sd),
     dnpv(d->get_projected_version()) {}
   void finish(int r) {
     assert(r == 0);
-    mds->server->_unlink_local_finish(mdr, dn, straydn, dnpv);
+    server->_unlink_local_finish(mdr, dn, straydn, dnpv);
   }
 };
 
@@ -5644,7 +5635,7 @@ void Server::_unlink_local(MDRequestRef& mdr, CDentry *dn, CDentry *straydn)
     mdcache->project_subtree_rename(in, dn->get_dir(), straydn->get_dir());
   }
 
-  journal_and_reply(mdr, 0, dn, le, new C_MDS_unlink_local_finish(mds, mdr, dn, straydn));
+  journal_and_reply(mdr, 0, dn, le, new C_MDS_unlink_local_finish(this, mdr, dn, straydn));
 }
 
 void Server::_unlink_local_finish(MDRequestRef& mdr,
@@ -5727,11 +5718,10 @@ bool Server::_rmdir_prepare_witness(MDRequestRef& mdr, mds_rank_t who, CDentry *
   return true;
 }
 
-struct C_MDS_SlaveRmdirPrep : public ServerContext {
-  MDRequestRef mdr;
+struct C_MDS_SlaveRmdirPrep : public ServerLogContext {
   CDentry *dn, *straydn;
   C_MDS_SlaveRmdirPrep(Server *s, MDRequestRef& r, CDentry *d, CDentry *st)
-    : ServerContext(s), mdr(r), dn(d), straydn(st) {}
+    : ServerLogContext(s, r), dn(d), straydn(st) {}
   void finish(int r) {
     server->_logged_slave_rmdir(mdr, dn, straydn);
   }
@@ -5904,13 +5894,12 @@ void Server::_commit_slave_rmdir(MDRequestRef& mdr, int r)
   }
 }
 
-struct C_MDS_LoggedRmdirRollback : public ServerContext {
-  MDRequestRef mdr;
+struct C_MDS_LoggedRmdirRollback : public ServerLogContext {
   metareqid_t reqid;
   CDentry *dn;
   CDentry *straydn;
   C_MDS_LoggedRmdirRollback(Server *s, MDRequestRef& m, metareqid_t mr, CDentry *d, CDentry *st)
-    : ServerContext(s), mdr(m), reqid(mr), dn(d), straydn(st) {}
+    : ServerLogContext(s, m), reqid(mr), dn(d), straydn(st) {}
   void finish(int r) {
     server->_rmdir_rollback_finish(mdr, reqid, dn, straydn);
   }
@@ -6068,19 +6057,18 @@ bool Server::_dir_is_nonempty(MDRequestRef& mdr, CInode *in)
 // ======================================================
 
 
-class C_MDS_rename_finish : public MDSInternalContext {
-  MDRequestRef mdr;
+class C_MDS_rename_finish : public ServerLogContext {
   CDentry *srcdn;
   CDentry *destdn;
   CDentry *straydn;
 public:
-  C_MDS_rename_finish(MDSRank *m, MDRequestRef& r,
+  C_MDS_rename_finish(Server *s, MDRequestRef& r,
                      CDentry *sdn, CDentry *ddn, CDentry *stdn) :
-    MDSInternalContext(m), mdr(r),
+    ServerLogContext(s, r),
     srcdn(sdn), destdn(ddn), straydn(stdn) { }
   void finish(int r) {
     assert(r == 0);
-    mds->server->_rename_finish(mdr, srcdn, destdn, straydn);
+    server->_rename_finish(mdr, srcdn, destdn, straydn);
   }
 };
 
@@ -6504,7 +6492,7 @@ void Server::handle_client_rename(MDRequestRef& mdr)
     le->cmapv = mds->sessionmap.get_projected();
 
   // -- commit locally --
-  C_MDS_rename_finish *fin = new C_MDS_rename_finish(mds, mdr, srcdn, destdn, straydn);
+  C_MDS_rename_finish *fin = new C_MDS_rename_finish(this, mdr, srcdn, destdn, straydn);
 
   journal_and_reply(mdr, srci, destdn, le, fin);
 }
@@ -7106,12 +7094,11 @@ void Server::_rename_apply(MDRequestRef& mdr, CDentry *srcdn, CDentry *destdn, C
 // ------------
 // SLAVE
 
-class C_MDS_SlaveRenamePrep : public ServerContext {
-  MDRequestRef mdr;
+class C_MDS_SlaveRenamePrep : public ServerLogContext {
   CDentry *srcdn, *destdn, *straydn;
 public:
   C_MDS_SlaveRenamePrep(Server *s, MDRequestRef& m, CDentry *sr, CDentry *de, CDentry *st) :
-    ServerContext(s), mdr(m), srcdn(sr), destdn(de), straydn(st) {}
+    ServerLogContext(s, m), srcdn(sr), destdn(de), straydn(st) {}
   void finish(int r) {
     server->_logged_slave_rename(mdr, srcdn, destdn, straydn);
   }
@@ -7545,9 +7532,8 @@ void _rollback_repair_dir(MutationRef& mut, CDir *dir, rename_rollback::drec &r,
   mut->add_updated_lock(&dir->get_inode()->nestlock);
 }
 
-struct C_MDS_LoggedRenameRollback : public ServerContext {
+struct C_MDS_LoggedRenameRollback : public ServerLogContext {
   MutationRef mut;
-  MDRequestRef mdr;
   CDentry *srcdn;
   version_t srcdnpv;
   CDentry *destdn;
@@ -7556,7 +7542,7 @@ struct C_MDS_LoggedRenameRollback : public ServerContext {
   C_MDS_LoggedRenameRollback(Server *s, MutationRef& m, MDRequestRef& r,
                             CDentry *sd, version_t pv, CDentry *dd,
                             CDentry *st, bool f) :
-    ServerContext(s), mut(m), mdr(r), srcdn(sd), srcdnpv(pv), destdn(dd),
+    ServerLogContext(s, r), mut(m), srcdn(sd), srcdnpv(pv), destdn(dd),
     straydn(st), finish_mdr(f) {}
   void finish(int r) {
     server->_rename_rollback_finish(mut, mdr, srcdn, srcdnpv,
@@ -7790,7 +7776,7 @@ void Server::do_rename_rollback(bufferlist &rbl, mds_rank_t master, MDRequestRef
     assert(!le->commit.empty());
     if (mdr)
       mdr->more()->slave_update_journaled = false;
-    MDSInternalContextBase *fin = new C_MDS_LoggedRenameRollback(this, mut, mdr, srcdn, srcdnpv,
+    MDSLogContextBase *fin = new C_MDS_LoggedRenameRollback(this, mut, mdr, srcdn, srcdnpv,
                                                  destdn, straydn, finish_mdr);
     submit_mdlog_entry(le, fin, mdr, __func__);
     mdlog->flush();
@@ -8043,14 +8029,13 @@ void Server::handle_client_lssnap(MDRequestRef& mdr)
 
 // MKSNAP
 
-struct C_MDS_mksnap_finish : public MDSInternalContext {
-  MDRequestRef mdr;
+struct C_MDS_mksnap_finish : public ServerLogContext {
   CInode *diri;
   SnapInfo info;
-  C_MDS_mksnap_finish(MDSRank *m, MDRequestRef& r, CInode *di, SnapInfo &i) :
-    MDSInternalContext(m), mdr(r), diri(di), info(i) {}
+  C_MDS_mksnap_finish(Server *s, MDRequestRef& r, CInode *di, SnapInfo &i) :
+    ServerLogContext(s, r), diri(di), info(i) {}
   void finish(int r) {
-    mds->server->_mksnap_finish(mdr, diri, info);
+    server->_mksnap_finish(mdr, diri, info);
   }
 };
 
@@ -8165,7 +8150,7 @@ void Server::handle_client_mksnap(MDRequestRef& mdr)
   mdcache->journal_dirty_inode(mdr.get(), &le->metablob, diri);
 
   // journal the snaprealm changes
-  submit_mdlog_entry(le, new C_MDS_mksnap_finish(mds, mdr, diri, info),
+  submit_mdlog_entry(le, new C_MDS_mksnap_finish(this, mdr, diri, info),
                      mdr, __func__);
   mdlog->flush();
 }
@@ -8196,14 +8181,13 @@ void Server::_mksnap_finish(MDRequestRef& mdr, CInode *diri, SnapInfo &info)
 
 // RMSNAP
 
-struct C_MDS_rmsnap_finish : public MDSInternalContext {
-  MDRequestRef mdr;
+struct C_MDS_rmsnap_finish : public ServerLogContext {
   CInode *diri;
   snapid_t snapid;
-  C_MDS_rmsnap_finish(MDSRank *m, MDRequestRef& r, CInode *di, snapid_t sn) :
-    MDSInternalContext(m), mdr(r), diri(di), snapid(sn) {}
+  C_MDS_rmsnap_finish(Server *s, MDRequestRef& r, CInode *di, snapid_t sn) :
+    ServerLogContext(s, r), diri(di), snapid(sn) {}
   void finish(int r) {
-    mds->server->_rmsnap_finish(mdr, diri, snapid);
+    server->_rmsnap_finish(mdr, diri, snapid);
   }
 };
 
@@ -8292,7 +8276,7 @@ void Server::handle_client_rmsnap(MDRequestRef& mdr)
   mdcache->predirty_journal_parents(mdr, &le->metablob, diri, 0, PREDIRTY_PRIMARY, false);
   mdcache->journal_dirty_inode(mdr.get(), &le->metablob, diri);
 
-  submit_mdlog_entry(le, new C_MDS_rmsnap_finish(mds, mdr, diri, snapid),
+  submit_mdlog_entry(le, new C_MDS_rmsnap_finish(this, mdr, diri, snapid),
                      mdr, __func__);
   mdlog->flush();
 }
@@ -8323,14 +8307,13 @@ void Server::_rmsnap_finish(MDRequestRef& mdr, CInode *diri, snapid_t snapid)
     diri->purge_stale_snap_data(diri->snaprealm->get_snaps());
 }
 
-struct C_MDS_renamesnap_finish : public MDSInternalContext {
-  MDRequestRef mdr;
+struct C_MDS_renamesnap_finish : public ServerLogContext {
   CInode *diri;
   snapid_t snapid;
-  C_MDS_renamesnap_finish(MDSRank *m, MDRequestRef& r, CInode *di, snapid_t sn) :
-    MDSInternalContext(m), mdr(r), diri(di), snapid(sn) {}
+  C_MDS_renamesnap_finish(Server *s, MDRequestRef& r, CInode *di, snapid_t sn) :
+    ServerLogContext(s, r), diri(di), snapid(sn) {}
   void finish(int r) {
-    mds->server->_renamesnap_finish(mdr, diri, snapid);
+    server->_renamesnap_finish(mdr, diri, snapid);
   }
 };
 
@@ -8437,7 +8420,7 @@ void Server::handle_client_renamesnap(MDRequestRef& mdr)
   mdcache->journal_dirty_inode(mdr.get(), &le->metablob, diri);
 
   // journal the snaprealm changes
-  submit_mdlog_entry(le, new C_MDS_renamesnap_finish(mds, mdr, diri, snapid),
+  submit_mdlog_entry(le, new C_MDS_renamesnap_finish(this, mdr, diri, snapid),
                      mdr, __func__);
   mdlog->flush();
 }
index 70d5a2b626cf9e6c1a9d03eb9478c44026843b68..de73820378753c291f419a461794a61485b93e26 100644 (file)
@@ -59,6 +59,7 @@ private:
 
   friend class MDSContinuation;
   friend class ServerContext;
+  friend class ServerLogContext;
 
 public:
   bool terminating_sessions;
@@ -112,8 +113,8 @@ public:
   void handle_client_request(MClientRequest *m);
 
   void journal_and_reply(MDRequestRef& mdr, CInode *tracei, CDentry *tracedn,
-                        LogEvent *le, MDSInternalContextBase *fin);
-  void submit_mdlog_entry(LogEvent *le, MDSInternalContextBase *fin,
+                        LogEvent *le, MDSLogContextBase *fin);
+  void submit_mdlog_entry(LogEvent *le, MDSLogContextBase *fin,
                           MDRequestRef& mdr, const char *evt);
   void dispatch_client_request(MDRequestRef& mdr);
   void early_reply(MDRequestRef& mdr, CInode *tracei, CDentry *tracedn);
index 4ba8572c81005ba419435faf03f21cb93d948806..f5bba7b526fd1c06a6a3ba13df11bfd33c2b58fe 100644 (file)
@@ -45,6 +45,16 @@ public:
   explicit StrayManagerIOContext(StrayManager *sm_) : sm(sm_) {}
 };
 
+class StrayManagerLogContext : public virtual MDSLogContextBase {
+protected:
+  StrayManager *sm;
+  virtual MDSRank *get_mds()
+  {
+    return sm->mds;
+  }
+public:
+  explicit StrayManagerLogContext(StrayManager *sm_) : sm(sm_) {}
+};
 
 class StrayManagerContext : public virtual MDSInternalContextBase {
 protected:
@@ -170,24 +180,24 @@ void StrayManager::purge(CDentry *dn, uint32_t op_allowance)
   gather.activate();
 }
 
-class C_PurgeStrayLogged : public StrayManagerContext {
+class C_PurgeStrayLogged : public StrayManagerLogContext {
   CDentry *dn;
   version_t pdv;
   LogSegment *ls;
 public:
   C_PurgeStrayLogged(StrayManager *sm_, CDentry *d, version_t v, LogSegment *s) : 
-    StrayManagerContext(sm_), dn(d), pdv(v), ls(s) { }
+    StrayManagerLogContext(sm_), dn(d), pdv(v), ls(s) { }
   void finish(int r) {
     sm->_purge_stray_logged(dn, pdv, ls);
   }
 };
 
-class C_TruncateStrayLogged : public StrayManagerContext {
+class C_TruncateStrayLogged : public StrayManagerLogContext {
   CDentry *dn;
   LogSegment *ls;
 public:
   C_TruncateStrayLogged(StrayManager *sm, CDentry *d, LogSegment *s) :
-    StrayManagerContext(sm), dn(d), ls(s) { }
+    StrayManagerLogContext(sm), dn(d), ls(s) { }
   void finish(int r) {
     sm->_truncate_stray_logged(dn, ls);
   }
index 264d5ff9022cca5ceb241c5a37037770c6d93f0f..7c9f04e7b1eb7fa9eeec72adf4bf0fa2dd26038c 100644 (file)
@@ -93,6 +93,7 @@ class StrayManager
   void _truncate_stray_logged(CDentry *dn, LogSegment *ls);
 
   friend class StrayManagerIOContext;
+  friend class StrayManagerLogContext;
   friend class StrayManagerContext;
 
   friend class C_StraysFetched;
index 70a843be1df2e447612b6b86a75dc64c74758017..9ef69bac6dd9036c68547bd099da338836d06512 100644 (file)
@@ -196,7 +196,8 @@ void LogSegment::try_to_expire(MDSRank *mds, MDSGatherBuilder &gather_bld, int o
       }
     }
     if (le) {
-      mds->mdlog->submit_entry(le, gather_bld.new_sub());
+      mds->mdlog->submit_entry(le);
+      mds->mdlog->wait_for_safe(gather_bld.new_sub());
       dout(10) << "try_to_expire waiting for open files to rejournal" << dendl;
     }
   }