From 25d6576a52231833911d72b048f86111f6c22106 Mon Sep 17 00:00:00 2001 From: Greg Farnum Date: Thu, 18 Nov 2010 11:56:04 -0800 Subject: [PATCH] Journaler: add new reread_head function and state. This is to facilitate the forthcoming up_shadow MDS state. Signed-off-by: Greg Farnum --- src/osdc/Journaler.cc | 43 ++++++++++++++++++++++++++++++++++++++++++- src/osdc/Journaler.h | 3 +++ 2 files changed, 45 insertions(+), 1 deletion(-) diff --git a/src/osdc/Journaler.cc b/src/osdc/Journaler.cc index 8ecda4f2c7ada..5cfe282ad7925 100644 --- a/src/osdc/Journaler.cc +++ b/src/osdc/Journaler.cc @@ -86,6 +86,7 @@ public: void Journaler::recover(Context *onread) { + dout(1) << "recover start" << dendl; assert(state != STATE_ACTIVE); if (onread) @@ -99,10 +100,50 @@ void Journaler::recover(Context *onread) dout(1) << "read_head" << dendl; state = STATE_READHEAD; C_ReadHead *fin = new C_ReadHead(this); + read_head(fin, &fin->bl); +} + +void Journaler::read_head(Context *on_finish, bufferlist *bl) +{ + assert(state == STATE_READHEAD || state == STATE_REREADHEAD); object_t oid = file_object_t(ino, 0); object_locator_t oloc(pg_pool); - objecter->read_full(oid, oloc, CEPH_NOSNAP, &fin->bl, 0, fin); + objecter->read_full(oid, oloc, CEPH_NOSNAP, bl, 0, on_finish); +} + +/** + * Re-read the head from disk, and set the write_pos, expire_pos, trimmed_pos + * from the on-disk header. This switches the state to STATE_REREADHEAD for + * the duration, and you shouldn't start a re-read while other operations are + * in-flight, nor start other operations while a re-read is in progress. + * Also, don't call this until the Journaler has finished its recovery and has + * gone STATE_ACTIVE! + */ +void Journaler::reread_head() +{ + 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); + + //read on-disk header into + assert (bl.length()); + + // unpack header + Header h; + bufferlist::iterator p = bl.begin(); + ::decode(h, p); + write_pos = h.write_pos; + expire_pos = h.expire_pos; + trimmed_pos = h.trimmed_pos; + state = STATE_ACTIVE; } void Journaler::_finish_read_head(int r, bufferlist& bl) diff --git a/src/osdc/Journaler.h b/src/osdc/Journaler.h index 705de92641d09..30a973f875ec3 100644 --- a/src/osdc/Journaler.h +++ b/src/osdc/Journaler.h @@ -129,6 +129,7 @@ public: static const int STATE_READHEAD = 1; static const int STATE_PROBING = 2; static const int STATE_ACTIVE = 2; + static const int STATE_REREADHEAD = 3; int state; int error; @@ -232,6 +233,8 @@ public: */ void create(ceph_file_layout *layout); void recover(Context *onfinish); + void read_head(Context *on_finish, bufferlist *bl); + void reread_head(); void write_head(Context *onsave=0); void set_layout(ceph_file_layout *l); -- 2.39.5