From: Greg Farnum Date: Mon, 22 Nov 2010 20:39:34 +0000 (-0800) Subject: Journaler: make reread_head an asynchronous function. X-Git-Tag: v0.25~367^2~28 X-Git-Url: http://git-server-git.apps.pok.os.sepia.ceph.com/?a=commitdiff_plain;h=8da26fde3e220a9e446bbf7a16fc5dd44123d9e8;p=ceph.git Journaler: make reread_head an asynchronous function. This better fits the spirit of the other functions, and the MDS itself. Signed-off-by: Greg Farnum --- diff --git a/src/osdc/Journaler.cc b/src/osdc/Journaler.cc index 5d98aeb1b692..27e9c485853a 100644 --- a/src/osdc/Journaler.cc +++ b/src/osdc/Journaler.cc @@ -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) diff --git a/src/osdc/Journaler.h b/src/osdc/Journaler.h index 178db3ad4bb4..22648ab4b6bd 100644 --- a/src/osdc/Journaler.h +++ b/src/osdc/Journaler.h @@ -145,12 +145,15 @@ private: list 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);