From 530bd6e67a0842733edff7ac036f18ed990788f9 Mon Sep 17 00:00:00 2001 From: "Yan, Zheng" Date: Fri, 23 Dec 2016 16:36:41 +0800 Subject: [PATCH] mds: add -ESTALE recovery code for unlink/rmdir Signed-off-by: Yan, Zheng --- src/mds/Server.cc | 34 +++++++++++++++++++++------------- 1 file changed, 21 insertions(+), 13 deletions(-) diff --git a/src/mds/Server.cc b/src/mds/Server.cc index babb285f2c3..1e8f4177711 100644 --- a/src/mds/Server.cc +++ b/src/mds/Server.cc @@ -2443,7 +2443,17 @@ void Server::apply_allocated_inos(MDRequestRef& mdr, Session *session) } } - +class C_MDS_TryFindInode : public ServerContext { + MDRequestRef mdr; +public: + C_MDS_TryFindInode(Server *s, MDRequestRef& r) : ServerContext(s), mdr(r) {} + virtual void finish(int r) { + if (r == -ESTALE) // :( find_ino_peers failed + server->respond_to_request(mdr, r); + else + server->dispatch_client_request(mdr); + } +}; CDir *Server::traverse_to_auth_dir(MDRequestRef& mdr, vector &trace, filepath refpath) { @@ -2463,6 +2473,11 @@ CDir *Server::traverse_to_auth_dir(MDRequestRef& mdr, vector &trace, f int r = mdcache->path_traverse(mdr, NULL, NULL, refpath, &trace, &diri, MDS_TRAVERSE_FORWARD); if (r > 0) return 0; // delayed if (r < 0) { + if (r == -ESTALE) { + dout(10) << "FAIL on ESTALE but attempting recovery" << dendl; + mdcache->find_ino_peers(refpath.get_ino(), new C_MDS_TryFindInode(this, mdr)); + return 0; + } respond_to_request(mdr, r); return 0; } @@ -2476,18 +2491,6 @@ CDir *Server::traverse_to_auth_dir(MDRequestRef& mdr, vector &trace, f return dir; } -class C_MDS_TryFindInode : public ServerContext { - MDRequestRef mdr; -public: - C_MDS_TryFindInode(Server *s, MDRequestRef& r) : ServerContext(s), mdr(r) {} - virtual void finish(int r) { - if (r == -ESTALE) // :( find_ino_peers failed - server->respond_to_request(mdr, r); - else - server->dispatch_client_request(mdr); - } -}; - /* If this returns null, the request has been handled * as appropriate: forwarded on, or the client's been replied to */ CInode* Server::rdlock_path_pin_ref(MDRequestRef& mdr, int n, @@ -5469,6 +5472,11 @@ void Server::handle_client_unlink(MDRequestRef& mdr) int r = mdcache->path_traverse(mdr, NULL, NULL, req->get_filepath(), &trace, &in, MDS_TRAVERSE_FORWARD); if (r > 0) return; if (r < 0) { + if (r == -ESTALE) { + dout(10) << "FAIL on ESTALE but attempting recovery" << dendl; + mdcache->find_ino_peers(req->get_filepath().get_ino(), new C_MDS_TryFindInode(this, mdr)); + return; + } respond_to_request(mdr, r); return; }