From 72909729254f70f3d8c6ec4191b1fead2212f3ed Mon Sep 17 00:00:00 2001 From: Jeff Layton Date: Wed, 23 Aug 2017 13:49:40 -0400 Subject: [PATCH] client: fix locking in Client::getcwd Currently, it doesn't take the client_lock at all, which is problematic as make_request may very well end up unlocking it. Rename the current function to _getcwd, and add a new getcwd wrapper that takes the mutex before calling _getcwd. This fixes: http://tracker.ceph.com/issues/21082 Signed-off-by: Jeff Layton --- src/client/Client.cc | 10 ++++++++-- src/client/Client.h | 1 + 2 files changed, 9 insertions(+), 2 deletions(-) diff --git a/src/client/Client.cc b/src/client/Client.cc index 65b7181f940..2a203321626 100644 --- a/src/client/Client.cc +++ b/src/client/Client.cc @@ -9380,11 +9380,11 @@ int Client::chdir(const char *relpath, std::string &new_cwd, cwd.swap(in); ldout(cct, 3) << "chdir(" << relpath << ") cwd now " << cwd->ino << dendl; - getcwd(new_cwd, perms); + _getcwd(new_cwd, perms); return 0; } -void Client::getcwd(string& dir, const UserPerm& perms) +void Client::_getcwd(string& dir, const UserPerm& perms) { filepath path; ldout(cct, 10) << "getcwd " << *cwd << dendl; @@ -9424,6 +9424,12 @@ void Client::getcwd(string& dir, const UserPerm& perms) dir += path.get_path(); } +void Client::getcwd(string& dir, const UserPerm& perms) +{ + Mutex::Locker l(client_lock); + _getcwd(dir, perms); +} + int Client::statfs(const char *path, struct statvfs *stbuf, const UserPerm& perms) { diff --git a/src/client/Client.h b/src/client/Client.h index beefa1eba5c..8a1852e7af0 100644 --- a/src/client/Client.h +++ b/src/client/Client.h @@ -956,6 +956,7 @@ public: // crap int chdir(const char *s, std::string &new_cwd, const UserPerm& perms); + void _getcwd(std::string& cwd, const UserPerm& perms); void getcwd(std::string& cwd, const UserPerm& perms); // namespace ops