]> git-server-git.apps.pok.os.sepia.ceph.com Git - ceph.git/commitdiff
Journaler: make reread_head an asynchronous function.
authorGreg Farnum <gregf@hq.newdream.net>
Mon, 22 Nov 2010 20:39:34 +0000 (12:39 -0800)
committerGreg Farnum <gregf@hq.newdream.net>
Thu, 6 Jan 2011 18:35:24 +0000 (10:35 -0800)
This better fits the spirit of the other functions, and the MDS itself.

Signed-off-by: Greg Farnum <gregf@hq.newdream.net>
src/osdc/Journaler.cc
src/osdc/Journaler.h

index 5d98aeb1b692b31bbcc6cb99df3acc90a89c16c0..27e9c485853ac516e4c10a7f8d71d4116988d709 100644 (file)
@@ -76,6 +76,17 @@ public:
   }
 };
 
+class Journaler::C_RereadHead : public Context {
+  Journaler *ls;
+  Context *onfinish;
+public:
+  bufferlist bl;
+  C_RereadHead(Journaler *l, Context *onfinish_) : ls (l), onfinish(onfinish_){}
+  void finish(int r) {
+    ls->_finish_reread_head(r, bl, onfinish);
+  }
+};
+
 class Journaler::C_ProbeEnd : public Context {
   Journaler *ls;
 public:
@@ -122,19 +133,18 @@ void Journaler::read_head(Context *on_finish, bufferlist *bl)
  * Also, don't call this until the Journaler has finished its recovery and has
  * gone STATE_ACTIVE!
  */
-void Journaler::reread_head()
+void Journaler::reread_head(Context *onfinish)
 {
   dout(10) << "reread_head" << dendl;
   assert(state == STATE_ACTIVE);
 
-  Mutex lock("Journaler::reread_head");
-  Cond cond;
-  bool done = false;
-  bufferlist bl;
   state = STATE_REREADHEAD;
-  read_head(new C_SafeCond(&lock, &cond, &done), &bl);
-  while (!done) cond.Wait(lock);
+  C_RereadHead *fin = new C_RereadHead(this, onfinish);
+  read_head(fin, &fin->bl);
+}
 
+void Journaler::_finish_reread_head(int r, bufferlist& bl, Context *finish)
+{
   //read on-disk header into
   assert (bl.length());
 
@@ -142,10 +152,11 @@ void Journaler::reread_head()
   Header h;
   bufferlist::iterator p = bl.begin();
   ::decode(h, p);
-  write_pos = h.write_pos;
+  write_pos = flush_pos = h.write_pos;
   expire_pos = h.expire_pos;
   trimmed_pos = h.trimmed_pos;
   state = STATE_ACTIVE;
+  finish->finish(r);
 }
 
 void Journaler::_finish_read_head(int r, bufferlist& bl)
index 178db3ad4bb446c36b59e5cbeac0cd812dee3cda..22648ab4b6bd7fd838668e088b8834bdb7a2ac3b 100644 (file)
@@ -145,12 +145,15 @@ private:
   list<Context*> waitfor_recover;
   void read_head(Context *on_finish, bufferlist *bl);
   void _finish_read_head(int r, bufferlist& bl);
+  void _finish_reread_head(int r, bufferlist& bl, Context *finish);
   void probe(Context *finish, uint64_t *end);
   void _finish_probe_end(int r, uint64_t end);
   class C_ReadHead;
   friend class C_ReadHead;
   class C_ProbeEnd;
   friend class C_ProbeEnd;
+  class C_RereadHead;
+  friend class C_RereadHead;
 
 
 
@@ -261,7 +264,7 @@ public:
    */
   void create(ceph_file_layout *layout);
   void recover(Context *onfinish);
-  void reread_head();
+  void reread_head(Context *onfinish);
   void reprobe();
   void write_head(Context *onsave=0);