From 8d6b25a1ebbf0f5e96aff0f9c3785cb959b0a160 Mon Sep 17 00:00:00 2001 From: "Yan, Zheng" Date: Sat, 1 Mar 2014 17:49:38 +0800 Subject: [PATCH] mds: use "lookup-by-ino" helper to handle LOOKUPPARENT request Signed-off-by: Yan, Zheng --- src/mds/Server.cc | 50 +++++++++++++++-------------------------------- src/mds/Server.h | 3 +-- 2 files changed, 17 insertions(+), 36 deletions(-) diff --git a/src/mds/Server.cc b/src/mds/Server.cc index def63b4d091e..43108524218f 100644 --- a/src/mds/Server.cc +++ b/src/mds/Server.cc @@ -1190,7 +1190,10 @@ void Server::dispatch_client_request(MDRequest *mdr) switch (req->get_op()) { case CEPH_MDS_OP_LOOKUPHASH: case CEPH_MDS_OP_LOOKUPINO: - handle_client_lookup_ino(mdr); + handle_client_lookup_ino(mdr, false); + break; + case CEPH_MDS_OP_LOOKUPPARENT: + handle_client_lookup_ino(mdr, true); break; // inodes ops. @@ -1204,10 +1207,6 @@ void Server::dispatch_client_request(MDRequest *mdr) handle_client_getattr(mdr, false); break; - case CEPH_MDS_OP_LOOKUPPARENT: - handle_client_lookup_parent(mdr); - break; - case CEPH_MDS_OP_SETATTR: handle_client_setattr(mdr); break; @@ -2360,31 +2359,6 @@ void Server::handle_client_getattr(MDRequest *mdr, bool is_lookup) is_lookup ? mdr->dn[0].back() : 0); } -/* This function will clean up the passed mdr*/ -void Server::handle_client_lookup_parent(MDRequest *mdr) -{ - MClientRequest *req = mdr->client_request; - - CInode *in = mdcache->get_inode(req->get_filepath().get_ino()); - if (!in) { - reply_request(mdr, -ESTALE); - return; - } - if (in->is_base()) { - reply_request(mdr, -EINVAL); - return; - } - - CDentry *dn = in->get_projected_parent_dn(); - - set rdlocks, wrlocks, xlocks; - rdlocks.insert(&dn->lock); - if (!mds->locker->acquire_locks(mdr, rdlocks, wrlocks, xlocks)) - return; - - reply_request(mdr, 0, in, dn); // reply -} - struct C_MDS_LookupIno2 : public Context { Server *server; MDRequest *mdr; @@ -2398,7 +2372,7 @@ struct C_MDS_LookupIno2 : public Context { /* * filepath: ino */ -void Server::handle_client_lookup_ino(MDRequest *mdr) +void Server::handle_client_lookup_ino(MDRequest *mdr, bool want_parent) { MClientRequest *req = mdr->client_request; @@ -2413,9 +2387,17 @@ void Server::handle_client_lookup_ino(MDRequest *mdr) return; } - dout(10) << "reply to lookup_ino " << *in << dendl; - MClientReply *reply = new MClientReply(req, 0); - reply_request(mdr, reply, in, NULL); + if (want_parent) { + CInode *pin = in->get_parent_inode(); + if (pin && !pin->is_stray()) { + dout(10) << "reply to lookup_parent " << *in << dendl; + reply_request(mdr, 0, pin); + } else + reply_request(mdr, -ESTALE); + } else { + dout(10) << "reply to lookup_ino " << *in << dendl; + reply_request(mdr, 0, in); + } } void Server::_lookup_ino_2(MDRequest *mdr, int r) diff --git a/src/mds/Server.h b/src/mds/Server.h index d7253f1f9da6..ef43efd6ffba 100644 --- a/src/mds/Server.h +++ b/src/mds/Server.h @@ -142,8 +142,7 @@ public: // requests on existing inodes. void handle_client_getattr(MDRequest *mdr, bool is_lookup); - void handle_client_lookup_parent(MDRequest *mdr); - void handle_client_lookup_ino(MDRequest *mdr); + void handle_client_lookup_ino(MDRequest *mdr, bool want_parent); void _lookup_ino_2(MDRequest *mdr, int r); void handle_client_readdir(MDRequest *mdr); void handle_client_file_setlock(MDRequest *mdr); -- 2.47.3