vfs_glusterfs: implement SMB_VFS_OPENAT()
authorRalph Boehme <slow@samba.org>
Wed, 20 May 2020 19:32:30 +0000 (21:32 +0200)
committerJeremy Allison <jra@samba.org>
Thu, 21 May 2020 20:38:33 +0000 (20:38 +0000)
Signed-off-by: Ralph Boehme <slow@samba.org>
Reviewed-by: Jeremy Allison <jra@samba.org>
source3/modules/vfs_glusterfs.c

index fc9fbb0f64656432abe6a58fb955c39c1ce66abe..c4b779a3c1c23602ed126c6193864614e5ce328d 100644 (file)
@@ -643,6 +643,53 @@ static int vfs_gluster_open(struct vfs_handle_struct *handle,
        return 13371337;
 }
 
+static int vfs_gluster_openat(struct vfs_handle_struct *handle,
+                             const struct files_struct *dirfsp,
+                             const struct smb_filename *smb_fname,
+                             files_struct *fsp,
+                             int flags,
+                             mode_t mode)
+{
+       glfs_fd_t *glfd;
+       glfs_fd_t **p_tmp;
+
+       START_PROFILE(syscall_openat);
+
+       /*
+        * Looks like glfs API doesn't have openat().
+        */
+       SMB_ASSERT(dirfsp->fh->fd == AT_FDCWD);
+
+       p_tmp = VFS_ADD_FSP_EXTENSION(handle, fsp, glfs_fd_t *, NULL);
+       if (p_tmp == NULL) {
+               END_PROFILE(syscall_openat);
+               errno = ENOMEM;
+               return -1;
+       }
+
+       if (flags & O_DIRECTORY) {
+               glfd = glfs_opendir(handle->data, smb_fname->base_name);
+       } else if (flags & O_CREAT) {
+               glfd = glfs_creat(handle->data, smb_fname->base_name, flags,
+                                 mode);
+       } else {
+               glfd = glfs_open(handle->data, smb_fname->base_name, flags);
+       }
+
+       if (glfd == NULL) {
+               END_PROFILE(syscall_openat);
+               /* no extension destroy_fn, so no need to save errno */
+               VFS_REMOVE_FSP_EXTENSION(handle, fsp);
+               return -1;
+       }
+
+       *p_tmp = glfd;
+
+       END_PROFILE(syscall_openat);
+       /* An arbitrary value for error reporting, so you know its us. */
+       return 13371337;
+}
+
 static int vfs_gluster_close(struct vfs_handle_struct *handle,
                             files_struct *fsp)
 {
@@ -2045,6 +2092,7 @@ static struct vfs_fn_pointers glusterfs_fns = {
        /* File Operations */
 
        .open_fn = vfs_gluster_open,
+       .openat_fn = vfs_gluster_openat,
        .create_file_fn = NULL,
        .close_fn = vfs_gluster_close,
        .pread_fn = vfs_gluster_pread,