]> git.ipfire.org Git - thirdparty/samba.git/commitdiff
vfs_ceph_new: use low-level APIs for mknodat
authorShachar Sharon <ssharon@redhat.com>
Sun, 23 Jun 2024 10:08:25 +0000 (13:08 +0300)
committerGünther Deschner <gd@samba.org>
Mon, 29 Jul 2024 14:51:37 +0000 (14:51 +0000)
Implement mknodat operations using libcephfs' low-level APIs. Requires
parent directory to have valid inode-ref associated with its 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 986c66372a43bf7b91b863c7e05df9a563f9b03c..4bb6cb59d1f297109de452314376e460a8b74101 100644 (file)
@@ -970,6 +970,35 @@ static int vfs_ceph_ll_rename(const struct vfs_handle_struct *handle,
                              newparent->uperm);
 }
 
+static int vfs_ceph_ll_mknod(const struct vfs_handle_struct *handle,
+                            const struct vfs_ceph_fh *parent,
+                            const char *name,
+                            mode_t mode,
+                            dev_t rdev,
+                            struct vfs_ceph_iref *iref)
+{
+       struct ceph_statx stx = {.stx_ino = 0};
+       struct Inode *inode = NULL;
+       int ret = -1;
+
+       ret = ceph_ll_mknod(cmount_of(handle),
+                           parent->iref.inode,
+                           name,
+                           mode,
+                           rdev,
+                           &inode,
+                           &stx,
+                           CEPH_STATX_INO,
+                           0,
+                           parent->uperm);
+       if (ret == 0) {
+               iref->inode = inode;
+               iref->ino = stx.stx_ino;
+               iref->owner = true;
+       }
+       return ret;
+}
+
 /* Ceph Inode-refernce get/put wrappers */
 static int vfs_ceph_iget(const struct vfs_handle_struct *handle,
                         uint64_t ino,
@@ -2249,25 +2278,26 @@ static int vfs_ceph_mknodat(struct vfs_handle_struct *handle,
                mode_t mode,
                SMB_DEV_T dev)
 {
-       struct smb_filename *full_fname = NULL;
+       struct vfs_ceph_iref iref = {0};
+       struct vfs_ceph_fh *dircfh = NULL;
+       const char *name = smb_fname->base_name;
        int result = -1;
 
-       full_fname = full_path_from_dirfsp_atname(talloc_tos(),
-                                               dirfsp,
-                                               smb_fname);
-       if (full_fname == NULL) {
-               return -1;
+       result = vfs_ceph_fetch_fh(handle, dirfsp, &dircfh);
+       if (result != 0) {
+               goto out;
        }
 
-       DBG_DEBUG("[CEPH] mknodat(%p, %s)\n", handle, full_fname->base_name);
-       result = ceph_mknod(cmount_of(handle),
-                           full_fname->base_name,
-                           mode,
-                           dev);
-       DBG_DEBUG("[CEPH] mknodat(...) = %d\n", result);
+       DBG_DEBUG("[CEPH] mknodat(%p, %s)\n", handle, name);
 
-       TALLOC_FREE(full_fname);
+       result = vfs_ceph_ll_mknod(handle, dircfh, name, mode, dev, &iref);
+       if (result != 0) {
+               goto out;
+       }
 
+       vfs_ceph_iput(handle, &iref);
+out:
+       DBG_DEBUG("[CEPH] mknodat(...) = %d\n", result);
        return status_code(result);
 }