From 0c9af9397c1c5ba1c5943823901c8b84b887d427 Mon Sep 17 00:00:00 2001 From: Greg Farnum Date: Wed, 12 Mar 2014 09:38:15 -0700 Subject: [PATCH] Migrator: use MDRequestRef and MutationRef instead of raw pointers Signed-off-by: Greg Farnum --- src/mds/Migrator.cc | 26 ++++++++++++-------------- src/mds/Migrator.h | 12 +++++------- 2 files changed, 17 insertions(+), 21 deletions(-) diff --git a/src/mds/Migrator.cc b/src/mds/Migrator.cc index 05e8dce1a761c..969cb8b050e67 100644 --- a/src/mds/Migrator.cc +++ b/src/mds/Migrator.cc @@ -325,15 +325,15 @@ void Migrator::export_try_cancel(CDir *dir, bool notify_peer) mds->queue_waiters(it->second.waiting_for_finish); // drop locks if (state == EXPORT_LOCKING || state == EXPORT_DISCOVERING) { - MDRequest *mdr = dynamic_cast(it->second.mut); + MDRequestRef mdr = ceph::static_pointer_cast(it->second.mut); assert(mdr); if (mdr->more()->waiting_on_slave.empty()) mds->mdcache->request_finish(mdr); } else if (it->second.mut) { - Mutation *mut = it->second.mut; + MutationRef& mut = it->second.mut; mds->locker->drop_locks(mut); mut->cleanup(); - delete mut; } export_state.erase(it); @@ -753,12 +753,12 @@ void Migrator::export_dir(CDir *dir, int dest) stat.state = EXPORT_LOCKING; stat.peer = dest; stat.tid = mdr->reqid.tid; - stat.mut = mdr.get(); + stat.mut = mdr; dispatch_export_dir(mdr); } -void Migrator::dispatch_export_dir(MDRequest *mdr) +void Migrator::dispatch_export_dir(MDRequestRef& mdr) { dout(7) << "dispatch_export_dir " << *mdr << dendl; CDir *dir = mdr->more()->export_dir; @@ -845,10 +845,11 @@ void Migrator::handle_export_discover_ack(MExportDirDiscoverAck *m) } else { assert(it->second.state == EXPORT_DISCOVERING); // release locks to avoid deadlock - MDRequest *mdr = dynamic_cast(it->second.mut); + MDRequestRef mdr = ceph::static_pointer_cast(it->second.mut); assert(mdr); mds->mdcache->request_finish(mdr); - it->second.mut = NULL; + it->second.mut.reset(); // freeze the subtree it->second.state = EXPORT_FREEZING; dir->auth_unpin(this); @@ -921,7 +922,7 @@ void Migrator::export_frozen(CDir *dir) return; } - it->second.mut = new Mutation; + it->second.mut = MutationRef(new MutationImpl); if (diri->is_auth()) it->second.mut->auth_pin(diri); mds->locker->rdlock_take_set(rdlocks, it->second.mut); @@ -1800,11 +1801,10 @@ void Migrator::export_finish(CDir *dir) mds->queue_waiters(it->second.waiting_for_finish); // unpin path - Mutation *mut = it->second.mut; + MutationRef& mut = it->second.mut; if (mut) { mds->locker->drop_locks(mut); mut->cleanup(); - delete mut; } export_state.erase(it); @@ -2117,7 +2117,7 @@ void Migrator::handle_export_prep(MExportDirPrep *m) bool success = true; if (dir->get_inode()->filelock.can_wrlock(-1) && dir->get_inode()->nestlock.can_wrlock(-1)) { - it->second.mut = new Mutation; + it->second.mut = MutationRef(new MutationImpl); // force some locks. hacky. mds->locker->wrlock_force(&dir->inode->filelock, it->second.mut); mds->locker->wrlock_force(&dir->inode->nestlock, it->second.mut); @@ -2474,7 +2474,6 @@ void Migrator::import_reverse_final(CDir *dir) if (it->second.mut) { mds->locker->drop_locks(it->second.mut); it->second.mut->cleanup(); - delete it->second.mut; } import_state.erase(it); @@ -2618,7 +2617,7 @@ void Migrator::import_finish(CDir *dir, bool notify, bool last) it->second.peer_exports.swap(peer_exports); // clear import state (we're done!) - Mutation *mut = it->second.mut; + MutationRef& mut = it->second.mut; import_state.erase(it); mds->mdlog->start_submit_entry(new EImportFinish(dir, true)); @@ -2638,7 +2637,6 @@ void Migrator::import_finish(CDir *dir, bool notify, bool last) if (mut) { mds->locker->drop_locks(mut); mut->cleanup(); - delete mut; } // re-eval imported caps diff --git a/src/mds/Migrator.h b/src/mds/Migrator.h index d3a21292a003f..0819c821e23d6 100644 --- a/src/mds/Migrator.h +++ b/src/mds/Migrator.h @@ -48,8 +48,6 @@ class MExportCapsAck; class EImportStart; -struct Mutation; - class Migrator { private: MDS *mds; @@ -91,12 +89,12 @@ protected: set notify_ack_waiting; map > peer_imported; list waiting_for_finish; - Mutation *mut; + MutationRef mut; // for freeze tree deadlock detection utime_t last_cum_auth_pins_change; int last_cum_auth_pins; int num_remote_waiters; // number of remote authpin waiters - export_state_t() : state(0), peer(0), tid(0), mut(NULL), + export_state_t() : state(0), peer(0), tid(0), mut(), last_cum_auth_pins(0), num_remote_waiters(0) {} }; @@ -140,8 +138,8 @@ protected: list updated_scatterlocks; map client_map; map > peer_exports; - Mutation *mut; - import_state_t() : state(0), peer(0), tid(0), mut(NULL) {} + MutationRef mut; + import_state_t() : state(0), peer(0), tid(0), mut() {} }; map import_state; @@ -228,7 +226,7 @@ public: // -- import/export -- // exporter public: - void dispatch_export_dir(MDRequest *mdr); + void dispatch_export_dir(MDRequestRef& mdr); void export_dir(CDir *dir, int dest); void export_empty_import(CDir *dir); -- 2.39.5