]> git.ipfire.org Git - thirdparty/samba.git/commitdiff
vfs_ceph_new: use low-level APIs for renameat
authorShachar Sharon <ssharon@redhat.com>
Sun, 23 Jun 2024 09:47:19 +0000 (12:47 +0300)
committerGünther Deschner <gd@samba.org>
Mon, 29 Jul 2024 14:51:37 +0000 (14:51 +0000)
Implement renameat operations using libcephfs' low-level APIs. Requires
both directories to have valid inode-ref associated with their fsp
extension.

BUG: https://bugzilla.samba.org/show_bug.cgi?id=15686

Signed-off-by: Shachar Sharon <ssharon@redhat.com>
Reviewed-by: Guenther Deschner <gd@samba.org>
Reviewed-by: Anoop C S <anoopcs@samba.org>
source3/modules/vfs_ceph_new.c

index fcce851c5f9d38692b2879ed4551ef7d7db248e0..986c66372a43bf7b91b863c7e05df9a563f9b03c 100644 (file)
@@ -956,6 +956,20 @@ static int vfs_ceph_ll_link(const struct vfs_handle_struct *handle,
                            dircfh->uperm);
 }
 
+static int vfs_ceph_ll_rename(const struct vfs_handle_struct *handle,
+                             const struct vfs_ceph_fh *parent,
+                             const char *name,
+                             const struct vfs_ceph_fh *newparent,
+                             const char *newname)
+{
+       return ceph_ll_rename(cmount_of(handle),
+                             parent->iref.inode,
+                             name,
+                             newparent->iref.inode,
+                             newname,
+                             newparent->uperm);
+}
+
 /* Ceph Inode-refernce get/put wrappers */
 static int vfs_ceph_iget(const struct vfs_handle_struct *handle,
                         uint64_t ino,
@@ -1573,8 +1587,8 @@ static int vfs_ceph_renameat(struct vfs_handle_struct *handle,
                        files_struct *dstfsp,
                        const struct smb_filename *smb_fname_dst)
 {
-       struct smb_filename *full_fname_src = NULL;
-       struct smb_filename *full_fname_dst = NULL;
+       struct vfs_ceph_fh *src_dircfh = NULL;
+       struct vfs_ceph_fh *dst_dircfh = NULL;
        int result = -1;
 
        DBG_DEBUG("[CEPH] vfs_ceph_renameat\n");
@@ -1583,29 +1597,22 @@ static int vfs_ceph_renameat(struct vfs_handle_struct *handle,
                return result;
        }
 
-       full_fname_src = full_path_from_dirfsp_atname(talloc_tos(),
-                                                 srcfsp,
-                                                 smb_fname_src);
-       if (full_fname_src == NULL) {
-               errno = ENOMEM;
-               return -1;
-       }
-       full_fname_dst = full_path_from_dirfsp_atname(talloc_tos(),
-                                                 dstfsp,
-                                                 smb_fname_dst);
-       if (full_fname_dst == NULL) {
-               TALLOC_FREE(full_fname_src);
-               errno = ENOMEM;
-               return -1;
+       result = vfs_ceph_fetch_fh(handle, srcfsp, &src_dircfh);
+       if (result != 0) {
+               goto out;
        }
 
-       result = ceph_rename(cmount_of(handle),
-                            full_fname_src->base_name,
-                            full_fname_dst->base_name);
-
-       TALLOC_FREE(full_fname_src);
-       TALLOC_FREE(full_fname_dst);
+       result = vfs_ceph_fetch_fh(handle, dstfsp, &dst_dircfh);
+       if (result != 0) {
+               goto out;
+       }
 
+       result = vfs_ceph_ll_rename(handle,
+                                   src_dircfh,
+                                   smb_fname_src->base_name,
+                                   dst_dircfh,
+                                   smb_fname_dst->base_name);
+out:
        return status_code(result);
 }