2 Unix SMB/CIFS implementation.
4 Wrap GlusterFS GFAPI calls in vfs functions.
6 Copyright (c) 2013 Anand Avati <avati@redhat.com>
8 This program is free software; you can redistribute it and/or modify
9 it under the terms of the GNU General Public License as published by
10 the Free Software Foundation; either version 3 of the License, or
11 (at your option) any later version.
13 This program is distributed in the hope that it will be useful,
14 but WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 GNU General Public License for more details.
18 You should have received a copy of the GNU General Public License
19 along with this program. If not, see <http://www.gnu.org/licenses/>.
23 #include "smbd/smbd.h"
26 #include "lib/util/dlinklist.h"
28 #define DEFAULT_VOLFILE_SERVER "localhost"
35 - sendfile/recvfile support
38 /* Helpers to provide 'integer' fds */
40 /* This is global. gfapi's FD operations do not
41 require filesystem context.
44 static glfs_fd_t
**glfd_fd
;
45 static int glfd_fd_size
;
46 static int glfd_fd_used
;
48 static int glfd_fd_store(glfs_fd_t
*glfd
)
53 if (glfd_fd_size
== glfd_fd_used
) {
54 if (glfd_fd_size
>= INT_MAX
- 1) {
59 tmp
= talloc_realloc(glfd_fd
, glfd_fd
, glfs_fd_t
*,
67 glfd_fd
[glfd_fd_size
] = 0;
71 for (i
= 0; i
< glfd_fd_size
; i
++) {
72 if (glfd_fd
[i
] == NULL
) {
81 static glfs_fd_t
*glfd_fd_get(int i
)
83 if (i
< 0 || i
>= glfd_fd_size
) {
89 static glfs_fd_t
*glfd_fd_clear(int i
)
91 glfs_fd_t
*glfd
= NULL
;
93 if (i
< 0 || i
>= glfd_fd_size
) {
104 /* Helper to convert stat to stat_ex */
106 static void smb_stat_ex_from_stat(struct stat_ex
*dst
, const struct stat
*src
)
110 dst
->st_ex_dev
= src
->st_dev
;
111 dst
->st_ex_ino
= src
->st_ino
;
112 dst
->st_ex_mode
= src
->st_mode
;
113 dst
->st_ex_nlink
= src
->st_nlink
;
114 dst
->st_ex_uid
= src
->st_uid
;
115 dst
->st_ex_gid
= src
->st_gid
;
116 dst
->st_ex_rdev
= src
->st_rdev
;
117 dst
->st_ex_size
= src
->st_size
;
118 dst
->st_ex_atime
.tv_sec
= src
->st_atime
;
119 #ifdef STAT_HAVE_NSEC
120 dst
->st_ex_atime
.tv_nsec
= src
->st_atime_nsec
;
122 dst
->st_ex_mtime
.tv_sec
= src
->st_mtime
;
123 #ifdef STAT_HAVE_NSEC
124 dst
->st_ex_mtime
.tv_nsec
= src
->st_mtime_nsec
;
126 dst
->st_ex_ctime
.tv_sec
= src
->st_ctime
;
127 #ifdef STAT_HAVE_NSEC
128 dst
->st_ex_ctime
.tv_nsec
= src
->st_ctime_nsec
;
130 dst
->st_ex_btime
.tv_sec
= src
->st_mtime
;
131 #ifdef STAT_HAVE_NSEC
132 dst
->st_ex_btime
.tv_nsec
= src
->st_mtime_nsec
;
134 dst
->st_ex_blksize
= src
->st_blksize
;
135 dst
->st_ex_blocks
= src
->st_blocks
;
138 /* pre-opened glfs_t */
140 static struct glfs_preopened
{
144 struct glfs_preopened
*next
, *prev
;
148 static int glfs_set_preopened(const char *volume
, glfs_t
*fs
)
150 struct glfs_preopened
*entry
= NULL
;
152 entry
= talloc_zero(NULL
, struct glfs_preopened
);
158 entry
->volume
= talloc_strdup(entry
, volume
);
159 if (!entry
->volume
) {
168 DLIST_ADD(glfs_preopened
, entry
);
173 static glfs_t
*glfs_find_preopened(const char *volume
)
175 struct glfs_preopened
*entry
= NULL
;
177 for (entry
= glfs_preopened
; entry
; entry
= entry
->next
) {
178 if (strcmp(entry
->volume
, volume
) == 0) {
187 static void glfs_clear_preopened(glfs_t
*fs
)
189 struct glfs_preopened
*entry
= NULL
;
191 for (entry
= glfs_preopened
; entry
; entry
= entry
->next
) {
192 if (entry
->fs
== fs
) {
196 DLIST_REMOVE(glfs_preopened
, entry
);
198 glfs_fini(entry
->fs
);
204 /* Disk Operations */
206 static int vfs_gluster_connect(struct vfs_handle_struct
*handle
,
210 const char *volfile_server
;
218 tmp_ctx
= talloc_new(NULL
);
219 if (tmp_ctx
== NULL
) {
223 logfile
= lp_parm_talloc_string(tmp_ctx
, SNUM(handle
->conn
), "glusterfs",
226 loglevel
= lp_parm_int(SNUM(handle
->conn
), "glusterfs", "loglevel", -1);
228 volfile_server
= lp_parm_const_string(SNUM(handle
->conn
), "glusterfs",
229 "volfile_server", NULL
);
230 if (volfile_server
== NULL
) {
231 volfile_server
= DEFAULT_VOLFILE_SERVER
;
234 volume
= lp_parm_const_string(SNUM(handle
->conn
), "glusterfs", "volume",
236 if (volume
== NULL
) {
240 fs
= glfs_find_preopened(volume
);
245 fs
= glfs_new(volume
);
251 ret
= glfs_set_volfile_server(fs
, "tcp", volfile_server
, 0);
253 DEBUG(0, ("Failed to set volfile_server %s\n", volfile_server
));
257 ret
= glfs_set_xlator_option(fs
, "*-md-cache", "cache-posix-acl",
260 DEBUG(0, ("%s: Failed to set xlator options\n", volume
));
264 ret
= glfs_set_logging(fs
, logfile
, loglevel
);
266 DEBUG(0, ("%s: Failed to set logfile %s loglevel %d\n",
267 volume
, logfile
, loglevel
));
273 DEBUG(0, ("%s: Failed to initialize volume (%s)\n",
274 volume
, strerror(errno
)));
278 ret
= glfs_set_preopened(volume
, fs
);
280 DEBUG(0, ("%s: Failed to register volume (%s)\n",
281 volume
, strerror(errno
)));
285 talloc_free(tmp_ctx
);
291 DEBUG(0, ("%s: Initialized volume from server %s\n",
292 volume
, volfile_server
));
298 static void vfs_gluster_disconnect(struct vfs_handle_struct
*handle
)
304 glfs_clear_preopened(fs
);
307 static uint64_t vfs_gluster_disk_free(struct vfs_handle_struct
*handle
,
308 const char *path
, bool small_query
,
309 uint64_t *bsize_p
, uint64_t *dfree_p
,
312 struct statvfs statvfs
= { 0, };
315 ret
= glfs_statvfs(handle
->data
, path
, &statvfs
);
320 if (bsize_p
!= NULL
) {
321 *bsize_p
= (uint64_t)statvfs
.f_bsize
; /* Block size */
323 if (dfree_p
!= NULL
) {
324 *dfree_p
= (uint64_t)statvfs
.f_bavail
; /* Available Block units */
326 if (dsize_p
!= NULL
) {
327 *dsize_p
= (uint64_t)statvfs
.f_blocks
; /* Total Block units */
330 return (uint64_t)statvfs
.f_bavail
;
333 static int vfs_gluster_get_quota(struct vfs_handle_struct
*handle
,
334 enum SMB_QUOTA_TYPE qtype
, unid_t id
,
342 vfs_gluster_set_quota(struct vfs_handle_struct
*handle
,
343 enum SMB_QUOTA_TYPE qtype
, unid_t id
, SMB_DISK_QUOTA
*qt
)
349 static int vfs_gluster_statvfs(struct vfs_handle_struct
*handle
,
351 struct vfs_statvfs_struct
*vfs_statvfs
)
353 struct statvfs statvfs
= { 0, };
356 ret
= glfs_statvfs(handle
->data
, path
, &statvfs
);
358 DEBUG(0, ("glfs_statvfs(%s) failed: %s\n",
359 path
, strerror(errno
)));
363 ZERO_STRUCTP(vfs_statvfs
);
365 vfs_statvfs
->OptimalTransferSize
= statvfs
.f_frsize
;
366 vfs_statvfs
->BlockSize
= statvfs
.f_bsize
;
367 vfs_statvfs
->TotalBlocks
= statvfs
.f_blocks
;
368 vfs_statvfs
->BlocksAvail
= statvfs
.f_bfree
;
369 vfs_statvfs
->UserBlocksAvail
= statvfs
.f_bavail
;
370 vfs_statvfs
->TotalFileNodes
= statvfs
.f_files
;
371 vfs_statvfs
->FreeFileNodes
= statvfs
.f_ffree
;
372 vfs_statvfs
->FsIdentifier
= statvfs
.f_fsid
;
373 vfs_statvfs
->FsCapabilities
=
374 FILE_CASE_SENSITIVE_SEARCH
| FILE_CASE_PRESERVED_NAMES
;
379 static uint32_t vfs_gluster_fs_capabilities(struct vfs_handle_struct
*handle
,
380 enum timestamp_set_resolution
*p_ts_res
)
382 uint32_t caps
= FILE_CASE_SENSITIVE_SEARCH
| FILE_CASE_PRESERVED_NAMES
;
384 #ifdef STAT_HAVE_NSEC
385 *p_ts_res
= TIMESTAMP_SET_NT_OR_BETTER
;
391 static DIR *vfs_gluster_opendir(struct vfs_handle_struct
*handle
,
392 const char *path
, const char *mask
,
397 fd
= glfs_opendir(handle
->data
, path
);
399 DEBUG(0, ("glfs_opendir(%s) failed: %s\n",
400 path
, strerror(errno
)));
406 static DIR *vfs_gluster_fdopendir(struct vfs_handle_struct
*handle
,
407 files_struct
*fsp
, const char *mask
,
410 return (DIR *) glfd_fd_get(fsp
->fh
->fd
);
413 static int vfs_gluster_closedir(struct vfs_handle_struct
*handle
, DIR *dirp
)
415 return glfs_closedir((void *)dirp
);
418 static struct dirent
*vfs_gluster_readdir(struct vfs_handle_struct
*handle
,
419 DIR *dirp
, SMB_STRUCT_STAT
*sbuf
)
421 static char direntbuf
[512];
424 struct dirent
*dirent
= 0;
427 ret
= glfs_readdirplus_r((void *)dirp
, &stat
, (void *)direntbuf
,
430 ret
= glfs_readdir_r((void *)dirp
, (void *)direntbuf
, &dirent
);
433 if ((ret
< 0) || (dirent
== NULL
)) {
438 smb_stat_ex_from_stat(sbuf
, &stat
);
444 static long vfs_gluster_telldir(struct vfs_handle_struct
*handle
, DIR *dirp
)
446 return glfs_telldir((void *)dirp
);
449 static void vfs_gluster_seekdir(struct vfs_handle_struct
*handle
, DIR *dirp
,
452 glfs_seekdir((void *)dirp
, offset
);
455 static void vfs_gluster_rewinddir(struct vfs_handle_struct
*handle
, DIR *dirp
)
457 glfs_seekdir((void *)dirp
, 0);
460 static void vfs_gluster_init_search_op(struct vfs_handle_struct
*handle
,
466 static int vfs_gluster_mkdir(struct vfs_handle_struct
*handle
, const char *path
,
469 return glfs_mkdir(handle
->data
, path
, mode
);
472 static int vfs_gluster_rmdir(struct vfs_handle_struct
*handle
, const char *path
)
474 return glfs_rmdir(handle
->data
, path
);
477 static int vfs_gluster_open(struct vfs_handle_struct
*handle
,
478 struct smb_filename
*smb_fname
, files_struct
*fsp
,
479 int flags
, mode_t mode
)
483 if (flags
& O_DIRECTORY
) {
484 glfd
= glfs_opendir(handle
->data
, smb_fname
->base_name
);
485 } else if (flags
& O_CREAT
) {
486 glfd
= glfs_creat(handle
->data
, smb_fname
->base_name
, flags
,
489 glfd
= glfs_open(handle
->data
, smb_fname
->base_name
, flags
);
495 return glfd_fd_store(glfd
);
498 static int vfs_gluster_close(struct vfs_handle_struct
*handle
,
501 return glfs_close(glfd_fd_clear(fsp
->fh
->fd
));
504 static ssize_t
vfs_gluster_read(struct vfs_handle_struct
*handle
,
505 files_struct
*fsp
, void *data
, size_t n
)
507 return glfs_read(glfd_fd_get(fsp
->fh
->fd
), data
, n
, 0);
510 static ssize_t
vfs_gluster_pread(struct vfs_handle_struct
*handle
,
511 files_struct
*fsp
, void *data
, size_t n
,
514 return glfs_pread(glfd_fd_get(fsp
->fh
->fd
), data
, n
, offset
, 0);
517 static struct tevent_req
*vfs_gluster_pread_send(struct vfs_handle_struct
518 *handle
, TALLOC_CTX
*mem_ctx
,
519 struct tevent_context
*ev
,
520 files_struct
*fsp
, void *data
,
521 size_t n
, off_t offset
)
527 static ssize_t
vfs_gluster_pread_recv(struct tevent_req
*req
, int *err
)
533 static ssize_t
vfs_gluster_write(struct vfs_handle_struct
*handle
,
534 files_struct
*fsp
, const void *data
, size_t n
)
536 return glfs_write(glfd_fd_get(fsp
->fh
->fd
), data
, n
, 0);
539 static ssize_t
vfs_gluster_pwrite(struct vfs_handle_struct
*handle
,
540 files_struct
*fsp
, const void *data
,
541 size_t n
, off_t offset
)
543 return glfs_pwrite(glfd_fd_get(fsp
->fh
->fd
), data
, n
, offset
, 0);
546 static struct tevent_req
*vfs_gluster_pwrite_send(struct vfs_handle_struct
547 *handle
, TALLOC_CTX
*mem_ctx
,
548 struct tevent_context
*ev
,
550 const void *data
, size_t n
,
557 static ssize_t
vfs_gluster_pwrite_recv(struct tevent_req
*req
, int *err
)
563 static off_t
vfs_gluster_lseek(struct vfs_handle_struct
*handle
,
564 files_struct
*fsp
, off_t offset
, int whence
)
566 return glfs_lseek(glfd_fd_get(fsp
->fh
->fd
), offset
, whence
);
569 static ssize_t
vfs_gluster_sendfile(struct vfs_handle_struct
*handle
, int tofd
,
570 files_struct
*fromfsp
,
571 const DATA_BLOB
*hdr
,
572 off_t offset
, size_t n
)
578 static ssize_t
vfs_gluster_recvfile(struct vfs_handle_struct
*handle
,
579 int fromfd
, files_struct
*tofsp
,
580 off_t offset
, size_t n
)
586 static int vfs_gluster_rename(struct vfs_handle_struct
*handle
,
587 const struct smb_filename
*smb_fname_src
,
588 const struct smb_filename
*smb_fname_dst
)
590 return glfs_rename(handle
->data
, smb_fname_src
->base_name
,
591 smb_fname_dst
->base_name
);
594 static int vfs_gluster_fsync(struct vfs_handle_struct
*handle
,
597 return glfs_fsync(glfd_fd_get(fsp
->fh
->fd
));
600 static struct tevent_req
*vfs_gluster_fsync_send(struct vfs_handle_struct
601 *handle
, TALLOC_CTX
*mem_ctx
,
602 struct tevent_context
*ev
,
609 static int vfs_gluster_fsync_recv(struct tevent_req
*req
, int *err
)
615 static int vfs_gluster_stat(struct vfs_handle_struct
*handle
,
616 struct smb_filename
*smb_fname
)
621 ret
= glfs_stat(handle
->data
, smb_fname
->base_name
, &st
);
623 smb_stat_ex_from_stat(&smb_fname
->st
, &st
);
625 if (ret
< 0 && errno
!= ENOENT
) {
626 DEBUG(0, ("glfs_stat(%s) failed: %s\n",
627 smb_fname
->base_name
, strerror(errno
)));
632 static int vfs_gluster_fstat(struct vfs_handle_struct
*handle
,
633 files_struct
*fsp
, SMB_STRUCT_STAT
*sbuf
)
638 ret
= glfs_fstat(glfd_fd_get(fsp
->fh
->fd
), &st
);
640 smb_stat_ex_from_stat(sbuf
, &st
);
643 DEBUG(0, ("glfs_fstat(%d) failed: %s\n",
644 fsp
->fh
->fd
, strerror(errno
)));
649 static int vfs_gluster_lstat(struct vfs_handle_struct
*handle
,
650 struct smb_filename
*smb_fname
)
655 ret
= glfs_lstat(handle
->data
, smb_fname
->base_name
, &st
);
657 smb_stat_ex_from_stat(&smb_fname
->st
, &st
);
659 if (ret
< 0 && errno
!= ENOENT
) {
660 DEBUG(0, ("glfs_lstat(%s) failed: %s\n",
661 smb_fname
->base_name
, strerror(errno
)));
666 static uint64_t vfs_gluster_get_alloc_size(struct vfs_handle_struct
*handle
,
668 const SMB_STRUCT_STAT
*sbuf
)
670 return sbuf
->st_ex_blocks
* 512;
673 static int vfs_gluster_unlink(struct vfs_handle_struct
*handle
,
674 const struct smb_filename
*smb_fname
)
676 return glfs_unlink(handle
->data
, smb_fname
->base_name
);
679 static int vfs_gluster_chmod(struct vfs_handle_struct
*handle
,
680 const char *path
, mode_t mode
)
682 return glfs_chmod(handle
->data
, path
, mode
);
685 static int vfs_gluster_fchmod(struct vfs_handle_struct
*handle
,
686 files_struct
*fsp
, mode_t mode
)
688 return glfs_fchmod(glfd_fd_get(fsp
->fh
->fd
), mode
);
691 static int vfs_gluster_chown(struct vfs_handle_struct
*handle
,
692 const char *path
, uid_t uid
, gid_t gid
)
694 return glfs_chown(handle
->data
, path
, uid
, gid
);
697 static int vfs_gluster_fchown(struct vfs_handle_struct
*handle
,
698 files_struct
*fsp
, uid_t uid
, gid_t gid
)
700 return glfs_fchown(glfd_fd_get(fsp
->fh
->fd
), uid
, gid
);
703 static int vfs_gluster_lchown(struct vfs_handle_struct
*handle
,
704 const char *path
, uid_t uid
, gid_t gid
)
706 return glfs_lchown(handle
->data
, path
, uid
, gid
);
709 static int vfs_gluster_chdir(struct vfs_handle_struct
*handle
, const char *path
)
711 return glfs_chdir(handle
->data
, path
);
714 static char *vfs_gluster_getwd(struct vfs_handle_struct
*handle
)
719 cwd
= SMB_CALLOC_ARRAY(char, PATH_MAX
);
724 ret
= glfs_getcwd(handle
->data
, cwd
, PATH_MAX
- 1);
731 static int vfs_gluster_ntimes(struct vfs_handle_struct
*handle
,
732 const struct smb_filename
*smb_fname
,
733 struct smb_file_time
*ft
)
735 struct timespec times
[2];
737 if (null_timespec(ft
->atime
)) {
738 times
[0].tv_sec
= smb_fname
->st
.st_ex_atime
.tv_sec
;
739 times
[0].tv_nsec
= smb_fname
->st
.st_ex_atime
.tv_nsec
;
741 times
[0].tv_sec
= ft
->atime
.tv_sec
;
742 times
[0].tv_nsec
= ft
->atime
.tv_nsec
;
745 if (null_timespec(ft
->mtime
)) {
746 times
[1].tv_sec
= smb_fname
->st
.st_ex_mtime
.tv_sec
;
747 times
[1].tv_nsec
= smb_fname
->st
.st_ex_mtime
.tv_nsec
;
749 times
[1].tv_sec
= ft
->mtime
.tv_sec
;
750 times
[1].tv_nsec
= ft
->mtime
.tv_nsec
;
753 if ((timespec_compare(×
[0],
754 &smb_fname
->st
.st_ex_atime
) == 0) &&
755 (timespec_compare(×
[1],
756 &smb_fname
->st
.st_ex_mtime
) == 0)) {
760 return glfs_utimens(handle
->data
, smb_fname
->base_name
, times
);
763 static int vfs_gluster_ftruncate(struct vfs_handle_struct
*handle
,
764 files_struct
*fsp
, off_t offset
)
766 return glfs_ftruncate(glfd_fd_get(fsp
->fh
->fd
), offset
);
769 static int vfs_gluster_fallocate(struct vfs_handle_struct
*handle
,
770 struct files_struct
*fsp
,
771 enum vfs_fallocate_mode mode
,
772 off_t offset
, off_t len
)
778 static char *vfs_gluster_realpath(struct vfs_handle_struct
*handle
,
781 return glfs_realpath(handle
->data
, path
, 0);
784 static bool vfs_gluster_lock(struct vfs_handle_struct
*handle
,
785 files_struct
*fsp
, int op
, off_t offset
,
786 off_t count
, int type
)
788 struct flock flock
= { 0, };
792 flock
.l_whence
= SEEK_SET
;
793 flock
.l_start
= offset
;
797 ret
= glfs_posix_lock(glfd_fd_get(fsp
->fh
->fd
), op
, &flock
);
800 /* lock query, true if someone else has locked */
802 (flock
.l_type
!= F_UNLCK
) &&
803 (flock
.l_pid
!= 0) && (flock
.l_pid
!= getpid()))
816 static int vfs_gluster_kernel_flock(struct vfs_handle_struct
*handle
,
817 files_struct
*fsp
, uint32 share_mode
,
818 uint32_t access_mask
)
824 static int vfs_gluster_linux_setlease(struct vfs_handle_struct
*handle
,
825 files_struct
*fsp
, int leasetype
)
831 static bool vfs_gluster_getlock(struct vfs_handle_struct
*handle
,
832 files_struct
*fsp
, off_t
*poffset
,
833 off_t
*pcount
, int *ptype
, pid_t
*ppid
)
835 struct flock flock
= { 0, };
838 flock
.l_type
= *ptype
;
839 flock
.l_whence
= SEEK_SET
;
840 flock
.l_start
= *poffset
;
841 flock
.l_len
= *pcount
;
844 ret
= glfs_posix_lock(glfd_fd_get(fsp
->fh
->fd
), F_GETLK
, &flock
);
850 *ptype
= flock
.l_type
;
851 *poffset
= flock
.l_start
;
852 *pcount
= flock
.l_len
;
858 static int vfs_gluster_symlink(struct vfs_handle_struct
*handle
,
859 const char *oldpath
, const char *newpath
)
861 return glfs_symlink(handle
->data
, oldpath
, newpath
);
864 static int vfs_gluster_readlink(struct vfs_handle_struct
*handle
,
865 const char *path
, char *buf
, size_t bufsiz
)
867 return glfs_readlink(handle
->data
, path
, buf
, bufsiz
);
870 static int vfs_gluster_link(struct vfs_handle_struct
*handle
,
871 const char *oldpath
, const char *newpath
)
873 return glfs_link(handle
->data
, oldpath
, newpath
);
876 static int vfs_gluster_mknod(struct vfs_handle_struct
*handle
, const char *path
,
877 mode_t mode
, SMB_DEV_T dev
)
879 return glfs_mknod(handle
->data
, path
, mode
, dev
);
882 static NTSTATUS
vfs_gluster_notify_watch(struct vfs_handle_struct
*handle
,
883 struct sys_notify_context
*ctx
,
884 const char *path
, uint32_t *filter
,
885 uint32_t *subdir_filter
,
886 void (*callback
) (struct sys_notify_context
*ctx
,
888 struct notify_event
*ev
),
889 void *private_data
, void *handle_p
)
891 return NT_STATUS_NOT_IMPLEMENTED
;
894 static int vfs_gluster_chflags(struct vfs_handle_struct
*handle
,
895 const char *path
, unsigned int flags
)
901 static int vfs_gluster_get_real_filename(struct vfs_handle_struct
*handle
,
902 const char *path
, const char *name
,
903 TALLOC_CTX
*mem_ctx
, char **found_name
)
906 char key_buf
[NAME_MAX
+ 64];
907 char val_buf
[NAME_MAX
+ 1];
909 if (strlen(name
) >= NAME_MAX
) {
910 errno
= ENAMETOOLONG
;
914 snprintf(key_buf
, NAME_MAX
+ 64,
915 "user.glusterfs.get_real_filename:%s", name
);
917 ret
= glfs_getxattr(handle
->data
, path
, key_buf
, val_buf
, NAME_MAX
+ 1);
919 if (errno
== ENODATA
) {
925 *found_name
= talloc_strdup(mem_ctx
, val_buf
);
926 if (found_name
[0] == NULL
) {
933 static const char *vfs_gluster_connectpath(struct vfs_handle_struct
*handle
,
934 const char *filename
)
936 return handle
->conn
->connectpath
;
941 static ssize_t
vfs_gluster_getxattr(struct vfs_handle_struct
*handle
,
942 const char *path
, const char *name
,
943 void *value
, size_t size
)
945 return glfs_getxattr(handle
->data
, path
, name
, value
, size
);
948 static ssize_t
vfs_gluster_fgetxattr(struct vfs_handle_struct
*handle
,
949 files_struct
*fsp
, const char *name
,
950 void *value
, size_t size
)
952 return glfs_fgetxattr(glfd_fd_get(fsp
->fh
->fd
), name
, value
, size
);
955 static ssize_t
vfs_gluster_listxattr(struct vfs_handle_struct
*handle
,
956 const char *path
, char *list
, size_t size
)
958 return glfs_listxattr(handle
->data
, path
, list
, size
);
961 static ssize_t
vfs_gluster_flistxattr(struct vfs_handle_struct
*handle
,
962 files_struct
*fsp
, char *list
,
965 return glfs_flistxattr(glfd_fd_get(fsp
->fh
->fd
), list
, size
);
968 static int vfs_gluster_removexattr(struct vfs_handle_struct
*handle
,
969 const char *path
, const char *name
)
971 return glfs_removexattr(handle
->data
, path
, name
);
974 static int vfs_gluster_fremovexattr(struct vfs_handle_struct
*handle
,
975 files_struct
*fsp
, const char *name
)
977 return glfs_fremovexattr(glfd_fd_get(fsp
->fh
->fd
), name
);
980 static int vfs_gluster_setxattr(struct vfs_handle_struct
*handle
,
981 const char *path
, const char *name
,
982 const void *value
, size_t size
, int flags
)
984 return glfs_setxattr(handle
->data
, path
, name
, value
, size
, flags
);
987 static int vfs_gluster_fsetxattr(struct vfs_handle_struct
*handle
,
988 files_struct
*fsp
, const char *name
,
989 const void *value
, size_t size
, int flags
)
991 return glfs_fsetxattr(glfd_fd_get(fsp
->fh
->fd
), name
, value
, size
,
997 static bool vfs_gluster_aio_force(struct vfs_handle_struct
*handle
,
1003 /* Offline Operations */
1005 static bool vfs_gluster_is_offline(struct vfs_handle_struct
*handle
,
1006 const struct smb_filename
*fname
,
1007 SMB_STRUCT_STAT
*sbuf
)
1012 static int vfs_gluster_set_offline(struct vfs_handle_struct
*handle
,
1013 const struct smb_filename
*fname
)
1022 Size = 4 (header) + N * 8 (entry)
1024 Offset Size Field (Little Endian)
1025 -------------------------------------
1028 4-5 2-byte Entry-1 tag
1029 6-7 2-byte Entry-1 perm
1030 8-11 4-byte Entry-1 id
1032 12-13 2-byte Entry-2 tag
1033 14-15 2-byte Entry-2 perm
1034 16-19 4-byte Entry-2 id
1040 /* header version */
1041 #define GLUSTER_ACL_VERSION 2
1044 #define GLUSTER_ACL_READ 0x04
1045 #define GLUSTER_ACL_WRITE 0x02
1046 #define GLUSTER_ACL_EXECUTE 0x01
1049 #define GLUSTER_ACL_UNDEFINED_TAG 0x00
1050 #define GLUSTER_ACL_USER_OBJ 0x01
1051 #define GLUSTER_ACL_USER 0x02
1052 #define GLUSTER_ACL_GROUP_OBJ 0x04
1053 #define GLUSTER_ACL_GROUP 0x08
1054 #define GLUSTER_ACL_MASK 0x10
1055 #define GLUSTER_ACL_OTHER 0x20
1057 #define GLUSTER_ACL_UNDEFINED_ID (-1)
1059 #define GLUSTER_ACL_HEADER_SIZE 4
1060 #define GLUSTER_ACL_ENTRY_SIZE 8
1062 static SMB_ACL_T
gluster_to_smb_acl(const char *buf
, size_t xattr_size
,
1063 TALLOC_CTX
*mem_ctx
)
1067 struct smb_acl_entry
*smb_ace
;
1068 struct smb_acl_t
*result
;
1077 if (size
< GLUSTER_ACL_HEADER_SIZE
) {
1078 /* ACL should be at least as big as the header (4 bytes) */
1083 size
-= GLUSTER_ACL_HEADER_SIZE
; /* size of header = 4 bytes */
1085 if (size
% GLUSTER_ACL_ENTRY_SIZE
) {
1086 /* Size of entries must strictly be a multiple of
1087 size of an ACE (8 bytes)
1093 count
= size
/ GLUSTER_ACL_ENTRY_SIZE
;
1095 /* Version is the first 4 bytes of the ACL */
1096 if (IVAL(buf
, 0) != GLUSTER_ACL_VERSION
) {
1097 DEBUG(0, ("Unknown gluster ACL version: %d\n",
1101 offset
= GLUSTER_ACL_HEADER_SIZE
;
1103 result
= sys_acl_init(mem_ctx
);
1109 result
->acl
= talloc_array(result
, struct smb_acl_entry
, count
);
1112 talloc_free(result
);
1116 result
->count
= count
;
1118 smb_ace
= result
->acl
;
1120 for (i
= 0; i
< count
; i
++) {
1121 /* TAG is the first 2 bytes of an entry */
1122 tag
= SVAL(buf
, offset
);
1125 /* PERM is the next 2 bytes of an entry */
1126 perm
= SVAL(buf
, offset
);
1129 /* ID is the last 4 bytes of an entry */
1130 id
= IVAL(buf
, offset
);
1134 case GLUSTER_ACL_USER
:
1135 smb_ace
->a_type
= SMB_ACL_USER
;
1137 case GLUSTER_ACL_USER_OBJ
:
1138 smb_ace
->a_type
= SMB_ACL_USER_OBJ
;
1140 case GLUSTER_ACL_GROUP
:
1141 smb_ace
->a_type
= SMB_ACL_GROUP
;
1143 case GLUSTER_ACL_GROUP_OBJ
:
1144 smb_ace
->a_type
= SMB_ACL_GROUP_OBJ
;
1146 case GLUSTER_ACL_OTHER
:
1147 smb_ace
->a_type
= SMB_ACL_OTHER
;
1149 case GLUSTER_ACL_MASK
:
1150 smb_ace
->a_type
= SMB_ACL_MASK
;
1153 DEBUG(0, ("unknown tag type %d\n", (unsigned int) tag
));
1158 switch(smb_ace
->a_type
) {
1160 smb_ace
->info
.user
.uid
= id
;
1163 smb_ace
->info
.group
.gid
= id
;
1169 smb_ace
->a_perm
= 0;
1171 ((perm
& GLUSTER_ACL_READ
) ? SMB_ACL_READ
: 0);
1173 ((perm
& GLUSTER_ACL_WRITE
) ? SMB_ACL_WRITE
: 0);
1175 ((perm
& GLUSTER_ACL_EXECUTE
) ? SMB_ACL_EXECUTE
: 0);
1184 static int gluster_ace_cmp(const void *left
, const void *right
)
1187 uint16_t tag_left
, tag_right
;
1188 uint32_t id_left
, id_right
;
1193 - Smaller TAG values must be earlier.
1195 - Within same TAG, smaller identifiers must be earlier, E.g:
1196 UID 0 entry must be earlier than UID 200
1197 GID 17 entry must be earlier than GID 19
1200 /* TAG is the first element in the entry */
1201 tag_left
= SVAL(left
, 0);
1202 tag_right
= SVAL(right
, 0);
1204 ret
= (tag_left
- tag_right
);
1206 /* ID is the third element in the entry, after two short
1207 integers (tag and perm), i.e at offset 4.
1209 id_left
= IVAL(left
, 4);
1210 id_right
= IVAL(right
, 4);
1211 ret
= id_left
- id_right
;
1218 static ssize_t
smb_to_gluster_acl(SMB_ACL_T theacl
, char *buf
, size_t len
)
1221 struct smb_acl_entry
*smb_ace
;
1229 count
= theacl
->count
;
1231 size
= GLUSTER_ACL_HEADER_SIZE
+ (count
* GLUSTER_ACL_ENTRY_SIZE
);
1241 smb_ace
= theacl
->acl
;
1243 /* Version is the first 4 bytes of the ACL */
1244 SIVAL(buf
, 0, GLUSTER_ACL_VERSION
);
1245 offset
= GLUSTER_ACL_HEADER_SIZE
;
1247 for (i
= 0; i
< count
; i
++) {
1249 switch(smb_ace
->a_type
) {
1251 tag
= GLUSTER_ACL_USER
;
1253 case SMB_ACL_USER_OBJ
:
1254 tag
= GLUSTER_ACL_USER_OBJ
;
1257 tag
= GLUSTER_ACL_GROUP
;
1259 case SMB_ACL_GROUP_OBJ
:
1260 tag
= GLUSTER_ACL_GROUP_OBJ
;
1263 tag
= GLUSTER_ACL_OTHER
;
1266 tag
= GLUSTER_ACL_MASK
;
1269 DEBUG(0, ("Unknown tag value %d\n",
1277 switch(smb_ace
->a_type
) {
1279 id
= smb_ace
->info
.user
.uid
;
1282 id
= smb_ace
->info
.group
.gid
;
1285 id
= GLUSTER_ACL_UNDEFINED_ID
;
1289 /* Calculate perm */
1293 ((smb_ace
->a_perm
& SMB_ACL_READ
) ? GLUSTER_ACL_READ
: 0);
1295 ((smb_ace
->a_perm
& SMB_ACL_WRITE
) ? GLUSTER_ACL_WRITE
: 0);
1297 ((smb_ace
->a_perm
& SMB_ACL_EXECUTE
) ? GLUSTER_ACL_EXECUTE
: 0);
1300 /* TAG is the first 2 bytes of an entry */
1301 SSVAL(buf
, offset
, tag
);
1304 /* PERM is the next 2 bytes of an entry */
1305 SSVAL(buf
, offset
, perm
);
1308 /* ID is the last 4 bytes of an entry */
1309 SIVAL(buf
, offset
, id
);
1315 /* Skip the header, sort @count number of 8-byte entries */
1316 qsort(buf
+GLUSTER_ACL_HEADER_SIZE
, count
, GLUSTER_ACL_ENTRY_SIZE
,
1323 static SMB_ACL_T
vfs_gluster_sys_acl_get_file(struct vfs_handle_struct
*handle
,
1325 SMB_ACL_TYPE_T type
,
1326 TALLOC_CTX
*mem_ctx
)
1328 struct smb_acl_t
*result
;
1334 case SMB_ACL_TYPE_ACCESS
:
1335 key
= "system.posix_acl_access";
1337 case SMB_ACL_TYPE_DEFAULT
:
1338 key
= "system.posix_acl_default";
1345 ret
= glfs_getxattr(handle
->data
, path_p
, key
, 0, 0);
1351 ret
= glfs_getxattr(handle
->data
, path_p
, key
, buf
, ret
);
1356 result
= gluster_to_smb_acl(buf
, ret
, mem_ctx
);
1361 static SMB_ACL_T
vfs_gluster_sys_acl_get_fd(struct vfs_handle_struct
*handle
,
1362 struct files_struct
*fsp
,
1363 TALLOC_CTX
*mem_ctx
)
1365 struct smb_acl_t
*result
;
1369 ret
= glfs_fgetxattr(glfd_fd_get(fsp
->fh
->fd
),
1370 "system.posix_acl_access", 0, 0);
1376 ret
= glfs_fgetxattr(glfd_fd_get(fsp
->fh
->fd
),
1377 "system.posix_acl_access", buf
, ret
);
1382 result
= gluster_to_smb_acl(buf
, ret
, mem_ctx
);
1387 static int vfs_gluster_sys_acl_set_file(struct vfs_handle_struct
*handle
,
1389 SMB_ACL_TYPE_T acltype
,
1398 case SMB_ACL_TYPE_ACCESS
:
1399 key
= "system.posix_acl_access";
1401 case SMB_ACL_TYPE_DEFAULT
:
1402 key
= "system.posix_acl_default";
1409 size
= smb_to_gluster_acl(theacl
, 0, 0);
1412 size
= smb_to_gluster_acl(theacl
, buf
, size
);
1417 ret
= glfs_setxattr(handle
->data
, name
, key
, buf
, size
, 0);
1422 static int vfs_gluster_sys_acl_set_fd(struct vfs_handle_struct
*handle
,
1423 struct files_struct
*fsp
,
1430 size
= smb_to_gluster_acl(theacl
, 0, 0);
1433 size
= smb_to_gluster_acl(theacl
, buf
, size
);
1438 ret
= glfs_fsetxattr(glfd_fd_get(fsp
->fh
->fd
),
1439 "system.posix_acl_access", buf
, size
, 0);
1443 static int vfs_gluster_sys_acl_delete_def_file(struct vfs_handle_struct
*handle
,
1446 return glfs_removexattr(handle
->data
, path
, "system.posix_acl_default");
1449 static struct vfs_fn_pointers glusterfs_fns
= {
1451 /* Disk Operations */
1453 .connect_fn
= vfs_gluster_connect
,
1454 .disconnect_fn
= vfs_gluster_disconnect
,
1455 .disk_free_fn
= vfs_gluster_disk_free
,
1456 .get_quota_fn
= vfs_gluster_get_quota
,
1457 .set_quota_fn
= vfs_gluster_set_quota
,
1458 .statvfs_fn
= vfs_gluster_statvfs
,
1459 .fs_capabilities_fn
= vfs_gluster_fs_capabilities
,
1461 .get_dfs_referrals_fn
= NULL
,
1463 /* Directory Operations */
1465 .opendir_fn
= vfs_gluster_opendir
,
1466 .fdopendir_fn
= vfs_gluster_fdopendir
,
1467 .readdir_fn
= vfs_gluster_readdir
,
1468 .seekdir_fn
= vfs_gluster_seekdir
,
1469 .telldir_fn
= vfs_gluster_telldir
,
1470 .rewind_dir_fn
= vfs_gluster_rewinddir
,
1471 .mkdir_fn
= vfs_gluster_mkdir
,
1472 .rmdir_fn
= vfs_gluster_rmdir
,
1473 .closedir_fn
= vfs_gluster_closedir
,
1474 .init_search_op_fn
= vfs_gluster_init_search_op
,
1476 /* File Operations */
1478 .open_fn
= vfs_gluster_open
,
1479 .create_file_fn
= NULL
,
1480 .close_fn
= vfs_gluster_close
,
1481 .read_fn
= vfs_gluster_read
,
1482 .pread_fn
= vfs_gluster_pread
,
1483 .pread_send_fn
= vfs_gluster_pread_send
,
1484 .pread_recv_fn
= vfs_gluster_pread_recv
,
1485 .write_fn
= vfs_gluster_write
,
1486 .pwrite_fn
= vfs_gluster_pwrite
,
1487 .pwrite_send_fn
= vfs_gluster_pwrite_send
,
1488 .pwrite_recv_fn
= vfs_gluster_pwrite_recv
,
1489 .lseek_fn
= vfs_gluster_lseek
,
1490 .sendfile_fn
= vfs_gluster_sendfile
,
1491 .recvfile_fn
= vfs_gluster_recvfile
,
1492 .rename_fn
= vfs_gluster_rename
,
1493 .fsync_fn
= vfs_gluster_fsync
,
1494 .fsync_send_fn
= vfs_gluster_fsync_send
,
1495 .fsync_recv_fn
= vfs_gluster_fsync_recv
,
1497 .stat_fn
= vfs_gluster_stat
,
1498 .fstat_fn
= vfs_gluster_fstat
,
1499 .lstat_fn
= vfs_gluster_lstat
,
1500 .get_alloc_size_fn
= vfs_gluster_get_alloc_size
,
1501 .unlink_fn
= vfs_gluster_unlink
,
1503 .chmod_fn
= vfs_gluster_chmod
,
1504 .fchmod_fn
= vfs_gluster_fchmod
,
1505 .chown_fn
= vfs_gluster_chown
,
1506 .fchown_fn
= vfs_gluster_fchown
,
1507 .lchown_fn
= vfs_gluster_lchown
,
1508 .chdir_fn
= vfs_gluster_chdir
,
1509 .getwd_fn
= vfs_gluster_getwd
,
1510 .ntimes_fn
= vfs_gluster_ntimes
,
1511 .ftruncate_fn
= vfs_gluster_ftruncate
,
1512 .fallocate_fn
= vfs_gluster_fallocate
,
1513 .lock_fn
= vfs_gluster_lock
,
1514 .kernel_flock_fn
= vfs_gluster_kernel_flock
,
1515 .linux_setlease_fn
= vfs_gluster_linux_setlease
,
1516 .getlock_fn
= vfs_gluster_getlock
,
1517 .symlink_fn
= vfs_gluster_symlink
,
1518 .readlink_fn
= vfs_gluster_readlink
,
1519 .link_fn
= vfs_gluster_link
,
1520 .mknod_fn
= vfs_gluster_mknod
,
1521 .realpath_fn
= vfs_gluster_realpath
,
1522 .notify_watch_fn
= vfs_gluster_notify_watch
,
1523 .chflags_fn
= vfs_gluster_chflags
,
1524 .file_id_create_fn
= NULL
,
1525 .copy_chunk_send_fn
= NULL
,
1526 .copy_chunk_recv_fn
= NULL
,
1527 .streaminfo_fn
= NULL
,
1528 .get_real_filename_fn
= vfs_gluster_get_real_filename
,
1529 .connectpath_fn
= vfs_gluster_connectpath
,
1531 .brl_lock_windows_fn
= NULL
,
1532 .brl_unlock_windows_fn
= NULL
,
1533 .brl_cancel_windows_fn
= NULL
,
1534 .strict_lock_fn
= NULL
,
1535 .strict_unlock_fn
= NULL
,
1536 .translate_name_fn
= NULL
,
1539 /* NT ACL Operations */
1540 .fget_nt_acl_fn
= NULL
,
1541 .get_nt_acl_fn
= NULL
,
1542 .fset_nt_acl_fn
= NULL
,
1543 .audit_file_fn
= NULL
,
1545 /* Posix ACL Operations */
1546 .chmod_acl_fn
= NULL
, /* passthrough to default */
1547 .fchmod_acl_fn
= NULL
, /* passthrough to default */
1548 .sys_acl_get_file_fn
= vfs_gluster_sys_acl_get_file
,
1549 .sys_acl_get_fd_fn
= vfs_gluster_sys_acl_get_fd
,
1550 .sys_acl_blob_get_file_fn
= posix_sys_acl_blob_get_file
,
1551 .sys_acl_blob_get_fd_fn
= posix_sys_acl_blob_get_fd
,
1552 .sys_acl_set_file_fn
= vfs_gluster_sys_acl_set_file
,
1553 .sys_acl_set_fd_fn
= vfs_gluster_sys_acl_set_fd
,
1554 .sys_acl_delete_def_file_fn
= vfs_gluster_sys_acl_delete_def_file
,
1557 .getxattr_fn
= vfs_gluster_getxattr
,
1558 .fgetxattr_fn
= vfs_gluster_fgetxattr
,
1559 .listxattr_fn
= vfs_gluster_listxattr
,
1560 .flistxattr_fn
= vfs_gluster_flistxattr
,
1561 .removexattr_fn
= vfs_gluster_removexattr
,
1562 .fremovexattr_fn
= vfs_gluster_fremovexattr
,
1563 .setxattr_fn
= vfs_gluster_setxattr
,
1564 .fsetxattr_fn
= vfs_gluster_fsetxattr
,
1566 /* AIO Operations */
1567 .aio_force_fn
= vfs_gluster_aio_force
,
1569 /* Offline Operations */
1570 .is_offline_fn
= vfs_gluster_is_offline
,
1571 .set_offline_fn
= vfs_gluster_set_offline
,
1573 /* Durable handle Operations */
1574 .durable_cookie_fn
= NULL
,
1575 .durable_disconnect_fn
= NULL
,
1576 .durable_reconnect_fn
= NULL
,
1579 NTSTATUS
vfs_glusterfs_init(void);
1580 NTSTATUS
vfs_glusterfs_init(void)
1582 return smb_register_vfs(SMB_VFS_INTERFACE_VERSION
,
1583 "glusterfs", &glusterfs_fns
);