]> git.apps.os.sepia.ceph.com Git - ceph-ci.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>
Mon, 17 Mar 2025 19:43:24 +0000 (15:43 -0400)
In particular: there's no reason to do a getcwd after chdir.

Signed-off-by: Patrick Donnelly <pdonnell@ibm.com>
(cherry picked from commit 3bfd614a358dc664469f8d5f56e9248818495bb2)

src/client/Client.cc
src/client/Client.h
src/client/SyntheticClient.cc
src/libcephfs.cc

index d0d60a2735c3a70b475d335ab6418a29563886bf..e2f0ee0fa2357dc7975b3dee3599cedacbc474b8 100644 (file)
@@ -12226,10 +12226,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())
@@ -12245,18 +12242,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;
@@ -12267,7 +12263,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();
@@ -12294,17 +12290,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 3c26b0a86c2245c3f392a939883124cb343fdf7c..0f2cbb172c6b29499b4d21440af325e8fcdba790 100644 (file)
@@ -340,10 +340,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 3b408dd3f2df85ff8635c0a69b3fcabd1146f125..4b7bde6a0889a7fbb8a8cd1fd1a16b24a486b0cf 100644 (file)
@@ -1218,8 +1218,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 12c4c5d229e064771cf63cbc623cd9d6f91c0ef4..f1188dab080b8f40c268bbb32e8eac1a3d1d134f 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 {