From c7385c1d0eaa1bb3954c5a87ab354bae6b8e5b18 Mon Sep 17 00:00:00 2001 From: Sage Weil Date: Wed, 13 Apr 2011 18:34:55 -0700 Subject: [PATCH] mds: use helpers for import_reverse Use helpers for common code shared between handle_export_cancel and handle_mds_failure_or_stop. Also include handling for IMPORT_PREPPING state, even though we don't use it yet. Signed-off-by: Sage Weil --- src/mds/Migrator.cc | 62 +++++++++++++++++++++++++++------------------ src/mds/Migrator.h | 3 +++ 2 files changed, 40 insertions(+), 25 deletions(-) diff --git a/src/mds/Migrator.cc b/src/mds/Migrator.cc index cf714d549a144..c9209b239c38e 100644 --- a/src/mds/Migrator.cc +++ b/src/mds/Migrator.cc @@ -236,7 +236,6 @@ void Migrator::handle_mds_failure_or_stop(int who) dout(10) << "export state=warning : unpinning bounds, unfreezing, notifying" << dendl; // fall-thru - //case EXPORT_LOGGINGSTART: case EXPORT_PREPPING: if (p->second != EXPORT_WARNING) dout(10) << "export state=loggingstart|prepping : unpinning bounds, unfreezing" << dendl; @@ -346,30 +345,19 @@ void Migrator::handle_mds_failure_or_stop(int who) switch (q->second) { case IMPORT_DISCOVERING: dout(10) << "import state=discovering : clearing state" << dendl; - import_state.erase(df); - import_peer.erase(df); + import_reverse_discovering(df); break; case IMPORT_DISCOVERED: dout(10) << "import state=discovered : unpinning inode " << *diri << dendl; assert(diri); - // unpin base - diri->put(CInode::PIN_IMPORTING); - import_state.erase(df); - import_peer.erase(df); + import_reverse_discovered(df, diri); break; case IMPORT_PREPPING: - if (q->second == IMPORT_PREPPING) { - dout(10) << "import state=prepping : unpinning base+bounds " << *dir << dendl; - } + dout(10) << "import state=prepping : unpinning base+bounds " << *dir << dendl; assert(dir); - { - set bounds; - cache->map_dirfrag_set(import_bound_ls[dir], bounds); - import_remove_pins(dir, bounds); - import_reverse_final(dir); - } + import_reverse_prepping(dir); break; case IMPORT_PREPPED: @@ -1567,22 +1555,46 @@ void Migrator::handle_export_discover(MExportDirDiscover *m) assert (g_conf.mds_kill_import_at != 2); } +void Migrator::import_reverse_discovering(dirfrag_t df) +{ + import_state.erase(df); + import_peer.erase(df); +} + +void Migrator::import_reverse_discovered(dirfrag_t df, CInode *diri) +{ + // unpin base + diri->put(CInode::PIN_IMPORTING); + import_state.erase(df); + import_peer.erase(df); +} + +void Migrator::import_reverse_prepping(CDir *dir) +{ + set bounds; + cache->map_dirfrag_set(import_bound_ls[dir], bounds); + import_remove_pins(dir, bounds); + import_reverse_final(dir); +} + /* This function DOES put the passed message before returning*/ void Migrator::handle_export_cancel(MExportDirCancel *m) { dout(7) << "handle_export_cancel on " << m->get_dirfrag() << dendl; - - if (import_state[m->get_dirfrag()] == IMPORT_DISCOVERED) { - CInode *in = cache->get_inode(m->get_dirfrag().ino); + dirfrag_t df = m->get_dirfrag(); + if (import_state[df] == IMPORT_DISCOVERING) { + import_reverse_discovering(df); + } else if (import_state[df] == IMPORT_DISCOVERED) { + CInode *in = cache->get_inode(df.ino); assert(in); - in->put(CInode::PIN_IMPORTING); + import_reverse_discovered(df, in); + } else if (import_state[df] == IMPORT_PREPPING) { + CDir *dir = mds->mdcache->get_dirfrag(df); + assert(dir); + import_reverse_prepping(dir); } else { - assert(import_state[m->get_dirfrag()] == IMPORT_DISCOVERING); + assert(0 == "got export_cancel in weird state"); } - - import_state.erase(m->get_dirfrag()); - import_peer.erase(m->get_dirfrag()); - m->put(); } diff --git a/src/mds/Migrator.h b/src/mds/Migrator.h index e7816339c6947..cd712ae3e749c 100644 --- a/src/mds/Migrator.h +++ b/src/mds/Migrator.h @@ -253,6 +253,9 @@ public: public: void import_reverse(CDir *dir); protected: + void import_reverse_discovering(dirfrag_t df); + void import_reverse_discovered(dirfrag_t df, CInode *diri); + void import_reverse_prepping(CDir *dir); void import_remove_pins(CDir *dir, set& bounds); void import_reverse_unfreeze(CDir *dir); void import_reverse_final(CDir *dir); -- 2.39.5