]> git.ipfire.org Git - thirdparty/samba.git/commitdiff
vfs_ceph_new: use low-level APIs for lchown
authorShachar Sharon <ssharon@redhat.com>
Mon, 17 Jun 2024 13:59:05 +0000 (16:59 +0300)
committerGünther Deschner <gd@samba.org>
Mon, 29 Jul 2024 14:51:36 +0000 (14:51 +0000)
Use libcephfs' low-level API ceph_ll_setattr to implement VFS lchown_fn
hook. Use to standard pattern of iget/iput to allow operation by Inode
reference.

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 22228d32b7810157e3f9052e53956953aeeb1792..d005eb7d92f1cd9f7117e1343d7014c8fb59804c 100644 (file)
@@ -447,6 +447,28 @@ static int vfs_ceph_ll_getattr(const struct vfs_handle_struct *handle,
        return ret;
 }
 
+static int vfs_ceph_ll_chown(struct vfs_handle_struct *handle,
+                            const struct vfs_ceph_iref *iref,
+                            uid_t uid,
+                            gid_t gid)
+{
+       struct ceph_statx stx = {.stx_uid = uid, .stx_gid = gid};
+       struct UserPerm *uperm = NULL;
+       int ret = -1;
+
+       uperm = vfs_ceph_userperm_new(handle);
+       if (uperm == NULL) {
+               return -ENOMEM;
+       }
+       ret = ceph_ll_setattr(handle->data,
+                             iref->inode,
+                             &stx,
+                             CEPH_STATX_UID | CEPH_STATX_GID,
+                             uperm);
+       vfs_ceph_userperm_del(uperm);
+       return ret;
+}
+
 /* Ceph Inode-refernce get/put wrappers */
 static int vfs_ceph_iget(const struct vfs_handle_struct *handle,
                         uint64_t ino,
@@ -1401,12 +1423,22 @@ static int vfs_ceph_lchown(struct vfs_handle_struct *handle,
                        gid_t gid)
 {
        int result;
+       struct vfs_ceph_iref iref = {0};
+
        DBG_DEBUG("[CEPH] lchown(%p, %s, %d, %d)\n",
                  handle,
                  smb_fname->base_name,
                  uid,
                  gid);
-       result = ceph_lchown(handle->data, smb_fname->base_name, uid, gid);
+
+       result = vfs_ceph_igetl(handle, smb_fname, &iref);
+       if (result != 0) {
+               goto out;
+       }
+
+       result = vfs_ceph_ll_chown(handle, &iref, uid, gid);
+       vfs_ceph_iput(handle, &iref);
+out:
        DBG_DEBUG("[CEPH] lchown(...) = %d\n", result);
        return status_code(result);
 }