]> git.apps.os.sepia.ceph.com Git - ceph.git/commitdiff
client: refactor / optimize chdir
authorPatrick Donnelly <pdonnell@ibm.com>
Tue, 11 Mar 2025 14:49:50 +0000 (10:49 -0400)
committerPatrick Donnelly <pdonnell@ibm.com>
Thu, 13 Mar 2025 14:07:13 +0000 (10:07 -0400)
In particular: there's no reason to do a getcwd after chdir.

Signed-off-by: Patrick Donnelly <pdonnell@ibm.com>
src/client/Client.cc
src/client/Client.h
src/client/SyntheticClient.cc
src/libcephfs.cc

index 5090e7182687ed918c7bc3c869da91cde8d8ade2..e32d2d3360c3132e88058df4a879712217e615f2 100644 (file)
@@ -12292,10 +12292,7 @@ int Client::statxat(int dirfd, const char *relpath,
   return r;
 }
 
-// not written yet, but i want to link!
-
-int Client::chdir(const char *relpath, std::string &new_cwd,
-                 const UserPerm& perms)
+int Client::chdir(const char *relpath, const UserPerm& perms)
 {
   RWRef_t mref_reader(mount_state, CLIENT_MOUNTING);
   if (!mref_reader.is_state_satisfied())
@@ -12311,18 +12308,17 @@ int Client::chdir(const char *relpath, std::string &new_cwd,
     return rc;
   }
 
-  if (!(in.get()->is_dir()))
+  if (!in->is_dir())
     return -ENOTDIR;
 
-  if (cwd != in)
-    cwd.swap(in);
+  cwd = std::move(in);
+
   ldout(cct, 3) << "chdir(" << relpath << ")  cwd now " << cwd->ino << dendl;
 
-  _getcwd(new_cwd, perms);
   return 0;
 }
 
-void Client::_getcwd(string& dir, const UserPerm& perms)
+int Client::_getcwd(string& dir, const UserPerm& perms)
 {
   filepath path;
   ldout(cct, 10) << __func__ << " " << *cwd << dendl;
@@ -12333,7 +12329,7 @@ void Client::_getcwd(string& dir, const UserPerm& perms)
 
     // A cwd or ancester is unlinked
     if (in->dentries.empty()) {
-      return;
+      return -ENOENT;
     }
 
     Dentry *dn = in->get_first_parent();
@@ -12360,17 +12356,17 @@ void Client::_getcwd(string& dir, const UserPerm& perms)
   }
   dir = "/";
   dir += path.get_path();
+  return 0;
 }
 
-void Client::getcwd(string& dir, const UserPerm& perms)
+int Client::getcwd(string& dir, const UserPerm& perms)
 {
   RWRef_t mref_reader(mount_state, CLIENT_MOUNTING);
   if (!mref_reader.is_state_satisfied())
-    return;
+    return -ENOTCONN;
 
   std::scoped_lock l(client_lock);
-
-  _getcwd(dir, perms);
+  return _getcwd(dir, perms);
 }
 
 int Client::statfs(const char *path, struct statvfs *stbuf,
index 23376052f9efc9020f2778603005ca95f828452d..e3612e75cc6c0d00c952c6a6672a086dfc0c376c 100644 (file)
@@ -343,10 +343,9 @@ public:
   // these should (more or less) mirror the actual system calls.
   int statfs(const char *path, struct statvfs *stbuf, const UserPerm& perms);
 
-  // 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);
+  int chdir(const char *path, const UserPerm& perms);
+  int _getcwd(std::string& cwd, const UserPerm& perms);
+  int getcwd(std::string& cwd, const UserPerm& perms);
 
   // namespace ops
   int opendir(const char *name, dir_result_t **dirpp, const UserPerm& perms);
index 1160b2dd7dea575b1a0033474292e5aef966a30e..7d12e2f0976848e6931885acd3ded653261cfdab 100644 (file)
@@ -1219,8 +1219,7 @@ int SyntheticClient::play_trace(Trace& t, string& prefix, bool metadata_only)
       const char *a = t.get_string(buf, p);
       // Client users should remember their path, but since this
       // is just a synthetic client we ignore it.
-      std::string ignore;
-      client->chdir(a, ignore, perms);
+      client->chdir(a, perms);
     } else if (strcmp(op, "statfs") == 0) {
       struct statvfs stbuf;
       client->statfs("/", &stbuf, perms);
index ce06ff7eef04ec26878b863f5ca51dbaf42a92c6..9fc20f731c523442b0112a6978ec99377a3a57fa 100644 (file)
@@ -322,7 +322,7 @@ public:
 
   int chdir(const char *to, const UserPerm& perms)
   {
-    return client->chdir(to, cwd, perms);
+    return client->chdir(to, perms);
   }
 
   CephContext *get_ceph_context() const {