From f773307ec9fe82f48a3d5566e817a559ce5ee059 Mon Sep 17 00:00:00 2001 From: Greg Farnum Date: Fri, 7 Mar 2014 15:58:11 -0800 Subject: [PATCH] mds: MDRequest: rename to MDRequestImpl, and declare MDRequestRef We're switching the MDRequest to be used as a shared pointer. This is the first step on the path to inserting an OpTracker into the MDS. Give the MDRequestImpl a weak_ptr self_ref so that we can keep using the elist for now. Signed-off-by: Greg Farnum --- src/mds/Mutation.cc | 30 +++++++++++++++--------------- src/mds/Mutation.h | 34 +++++++++++++++------------------- src/mds/Server.cc | 7 ++++--- src/mds/SessionMap.h | 4 ++-- 4 files changed, 36 insertions(+), 39 deletions(-) diff --git a/src/mds/Mutation.cc b/src/mds/Mutation.cc index 0bf5475fae1..87ffc3ea554 100644 --- a/src/mds/Mutation.cc +++ b/src/mds/Mutation.cc @@ -174,9 +174,9 @@ void Mutation::cleanup() } -// MDRequest +// MDRequestImpl -MDRequest::~MDRequest() +MDRequestImpl::~MDRequestImpl() { if (client_request) client_request->put(); @@ -185,34 +185,34 @@ MDRequest::~MDRequest() delete _more; } -MDRequest::More* MDRequest::more() +MDRequestImpl::More* MDRequestImpl::more() { if (!_more) _more = new More(); return _more; } -bool MDRequest::has_more() +bool MDRequestImpl::has_more() { return _more; } -bool MDRequest::are_slaves() +bool MDRequestImpl::are_slaves() { return _more && !_more->slaves.empty(); } -bool MDRequest::slave_did_prepare() +bool MDRequestImpl::slave_did_prepare() { return more()->slave_commit; } -bool MDRequest::did_ino_allocation() +bool MDRequestImpl::did_ino_allocation() { return alloc_ino || used_prealloc_ino || prealloc_inos.size(); } -bool MDRequest::freeze_auth_pin(CInode *inode) +bool MDRequestImpl::freeze_auth_pin(CInode *inode) { assert(!more()->rename_inode || more()->rename_inode == inode); more()->rename_inode = inode; @@ -226,7 +226,7 @@ bool MDRequest::freeze_auth_pin(CInode *inode) return true; } -void MDRequest::unfreeze_auth_pin(bool clear_inode) +void MDRequestImpl::unfreeze_auth_pin(bool clear_inode) { assert(more()->is_freeze_authpin); CInode *inode = more()->rename_inode; @@ -239,14 +239,14 @@ void MDRequest::unfreeze_auth_pin(bool clear_inode) more()->rename_inode = NULL; } -void MDRequest::set_remote_frozen_auth_pin(CInode *inode) +void MDRequestImpl::set_remote_frozen_auth_pin(CInode *inode) { assert(!more()->rename_inode || more()->rename_inode == inode); more()->rename_inode = inode; more()->is_remote_frozen_authpin = true; } -void MDRequest::set_ambiguous_auth(CInode *inode) +void MDRequestImpl::set_ambiguous_auth(CInode *inode) { assert(!more()->rename_inode || more()->rename_inode == inode); assert(!more()->is_ambiguous_auth); @@ -256,7 +256,7 @@ void MDRequest::set_ambiguous_auth(CInode *inode) more()->is_ambiguous_auth = true; } -void MDRequest::clear_ambiguous_auth() +void MDRequestImpl::clear_ambiguous_auth() { CInode *inode = more()->rename_inode; assert(inode && more()->is_ambiguous_auth); @@ -264,7 +264,7 @@ void MDRequest::clear_ambiguous_auth() more()->is_ambiguous_auth = false; } -bool MDRequest::can_auth_pin(MDSCacheObject *object) +bool MDRequestImpl::can_auth_pin(MDSCacheObject *object) { return object->can_auth_pin() || (is_auth_pinned(object) && has_more() && @@ -272,14 +272,14 @@ bool MDRequest::can_auth_pin(MDSCacheObject *object) more()->rename_inode == object); } -void MDRequest::drop_local_auth_pins() +void MDRequestImpl::drop_local_auth_pins() { if (has_more() && more()->is_freeze_authpin) unfreeze_auth_pin(true); Mutation::drop_local_auth_pins(); } -void MDRequest::print(ostream &out) +void MDRequestImpl::print(ostream &out) { out << "request(" << reqid; //if (request) out << " " << *request; diff --git a/src/mds/Mutation.h b/src/mds/Mutation.h index 206b71a9158..0090641ca07 100644 --- a/src/mds/Mutation.h +++ b/src/mds/Mutation.h @@ -155,10 +155,10 @@ inline ostream& operator<<(ostream& out, Mutation &mut) * mostly information about locks held, so that we can drop them all * the request is finished or forwarded. see request_*(). */ -struct MDRequest : public Mutation { - int ref; +struct MDRequestImpl : public Mutation { + ceph::weak_ptr self_ref; Session *session; - elist::item item_session_request; // if not on list, op is aborted. + elist::item item_session_request; // if not on list, op is aborted. // -- i am a client (master) request MClientRequest *client_request; // client request (if any) @@ -251,8 +251,8 @@ struct MDRequest : public Mutation { // --------------------------------------------------- - MDRequest() : - ref(1), + MDRequestImpl() : + self_ref(), session(0), item_session_request(this), client_request(0), straydn(NULL), snapid(CEPH_NOSNAP), tracei(0), tracedn(0), alloc_ino(0), used_prealloc_ino(0), snap_caps(0), did_early_reply(false), @@ -265,9 +265,9 @@ struct MDRequest : public Mutation { _more(0) { in[0] = in[1] = 0; } - MDRequest(metareqid_t ri, __u32 attempt, MClientRequest *req) : + MDRequestImpl(metareqid_t ri, __u32 attempt, MClientRequest *req) : + self_ref(), Mutation(ri, attempt), - ref(1), session(0), item_session_request(this), client_request(req), straydn(NULL), snapid(CEPH_NOSNAP), tracei(0), tracedn(0), alloc_ino(0), used_prealloc_ino(0), snap_caps(0), did_early_reply(false), @@ -280,9 +280,9 @@ struct MDRequest : public Mutation { _more(0) { in[0] = in[1] = 0; } - MDRequest(metareqid_t ri, __u32 attempt, int by) : + MDRequestImpl(metareqid_t ri, __u32 attempt, int by) : + self_ref(), Mutation(ri, attempt, by), - ref(1), session(0), item_session_request(this), client_request(0), straydn(NULL), snapid(CEPH_NOSNAP), tracei(0), tracedn(0), alloc_ino(0), used_prealloc_ino(0), snap_caps(0), did_early_reply(false), @@ -295,16 +295,7 @@ struct MDRequest : public Mutation { _more(0) { in[0] = in[1] = 0; } - ~MDRequest(); - - MDRequest *get() { - ++ref; - return this; - } - void put() { - if (--ref == 0) - delete this; - } + ~MDRequestImpl(); More* more(); bool has_more(); @@ -320,8 +311,13 @@ struct MDRequest : public Mutation { void clear_ambiguous_auth(); void print(ostream &out); + void set_self_ref(ceph::shared_ptr& ref) { + self_ref = ref; + } }; +typedef ceph::shared_ptr MDRequestRef; + struct MDSlaveUpdate { int origop; diff --git a/src/mds/Server.cc b/src/mds/Server.cc index 984ad2909d8..986487f09c4 100644 --- a/src/mds/Server.cc +++ b/src/mds/Server.cc @@ -544,10 +544,11 @@ void Server::journal_close_session(Session *session, int state) mdlog->flush(); // clean up requests, too - elist::iterator p = session->requests.begin(member_offset(MDRequest, - item_session_request)); + elist::iterator p = + session->requests.begin(member_offset(MDRequestImpl, + item_session_request)); while (!p.end()) { - MDRequest *mdr = *p; + MDRequestImpl *mdr = *p; ++p; mdcache->request_kill(mdr); } diff --git a/src/mds/SessionMap.h b/src/mds/SessionMap.h index e06a7b7dde3..ac7fd46d46a 100644 --- a/src/mds/SessionMap.h +++ b/src/mds/SessionMap.h @@ -27,7 +27,7 @@ using std::set; #include "mdstypes.h" class CInode; -struct MDRequest; +struct MDRequestImpl; #include "CInode.h" #include "Capability.h" @@ -88,7 +88,7 @@ public: list preopen_out_queue; ///< messages for client, queued before they connect - elist requests; + elist requests; interval_set pending_prealloc_inos; // journaling prealloc, will be added to prealloc_inos