]> git.apps.os.sepia.ceph.com Git - ceph.git/commitdiff
libcephfs_proxy: optimize ceph_chdir/ceph_getcwd 64716/head
authorXavi Hernandez <xhernandez@gmail.com>
Sun, 27 Jul 2025 20:48:09 +0000 (22:48 +0200)
committerXavi Hernandez <xhernandez@gmail.com>
Thu, 31 Jul 2025 09:15:02 +0000 (11:15 +0200)
Signed-off-by: Xavi Hernandez <xhernandez@gmail.com>
src/libcephfs_proxy/libcephfs_proxy.c

index 13e4db5a4fc696abb9dc3b8ac6597a230ff30c01..19bd14a3f85c6ec07403c04b2eb6b761319169f3 100644 (file)
@@ -25,6 +25,7 @@ struct ceph_mount_info {
        proxy_link_t link;
        proxy_link_negotiate_t neg;
        proxy_async_t async;
+       char *cwd_path;
        uint64_t cmount;
 };
 
@@ -161,10 +162,28 @@ static bool proxy_embed_perms(struct ceph_mount_info *cmount,
 __public int ceph_chdir(struct ceph_mount_info *cmount, const char *path)
 {
        CEPH_REQ(ceph_chdir, req, 1, ans, 0);
+       char *new_path;
+       int32_t err;
+
+       if (strcmp(path, cmount->cwd_path) == 0) {
+               return 0;
+       }
+
+       new_path = proxy_strdup(path);
+       if (new_path == NULL) {
+               return -ENOMEM;
+       }
 
        CEPH_STR_ADD(req, v0.path, path);
 
-       return CEPH_PROCESS(cmount, LIBCEPHFSD_OP_CHDIR, req, ans);
+       err = CEPH_PROCESS(cmount, LIBCEPHFSD_OP_CHDIR, req, ans);
+       if (err >= 0) {
+               new_path = __atomic_exchange_n(&cmount->cwd_path, new_path,
+                                              __ATOMIC_SEQ_CST);
+       }
+       proxy_free(new_path);
+
+       return err;
 }
 
 __public int ceph_conf_get(struct ceph_mount_info *cmount, const char *option,
@@ -211,6 +230,11 @@ __public int ceph_create(struct ceph_mount_info **cmount, const char *const id)
        if (ceph_mount == NULL) {
                return -ENOMEM;
        }
+       ceph_mount->cwd_path = proxy_strdup("/");
+       if (ceph_mount->cwd_path == NULL) {
+               err = -ENOMEM;
+               goto failed;
+       }
 
        err = proxy_connect(&ceph_mount->link);
        if (err < 0) {
@@ -262,21 +286,7 @@ failed:
 
 __public const char *ceph_getcwd(struct ceph_mount_info *cmount)
 {
-       static char cwd[PATH_MAX];
-       int32_t err;
-
-       CEPH_REQ(ceph_getcwd, req, 0, ans, 1);
-
-       CEPH_BUFF_ADD(ans, cwd, sizeof(cwd));
-
-       err = CEPH_PROCESS(cmount, LIBCEPHFSD_OP_GETCWD, req, ans);
-       if (err >= 0) {
-               return cwd;
-       }
-
-       errno = -err;
-
-       return NULL;
+       return cmount->cwd_path;
 }
 
 __public int ceph_init(struct ceph_mount_info *cmount)