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 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
;
217 logfile
= lp_parm_const_string(SNUM(handle
->conn
), "glusterfs",
220 loglevel
= lp_parm_int(SNUM(handle
->conn
), "glusterfs", "loglevel", -1);
222 volfile_server
= lp_parm_const_string(SNUM(handle
->conn
), "glusterfs",
223 "volfile_server", NULL
);
224 if (volfile_server
== NULL
) {
225 volfile_server
= DEFAULT_VOLFILE_SERVER
;
228 volume
= lp_parm_const_string(SNUM(handle
->conn
), "glusterfs", "volume",
230 if (volume
== NULL
) {
234 fs
= glfs_find_preopened(volume
);
239 fs
= glfs_new(volume
);
244 ret
= glfs_set_volfile_server(fs
, "tcp", volfile_server
, 0);
246 DEBUG(0, ("Failed to set volfile_server %s\n", volfile_server
));
251 ret
= glfs_set_xlator_option(fs
, "*-md-cache", "cache-posix-acl",
254 DEBUG(0, ("%s: Failed to set xlator options\n", volume
));
259 ret
= glfs_set_logging(fs
, logfile
, loglevel
);
261 DEBUG(0, ("%s: Failed to set logfile %s loglevel %d\n",
262 volume
, logfile
, loglevel
));
269 DEBUG(0, ("%s: Failed to initialize volume (%s)\n",
270 volume
, strerror(errno
)));
275 ret
= glfs_set_preopened(volume
, fs
);
277 DEBUG(0, ("%s: Failed to register volume (%s)\n",
278 volume
, strerror(errno
)));
283 DEBUG(0, ("%s: Initialized volume from server %s\n",
284 volume
, volfile_server
));
289 static void vfs_gluster_disconnect(struct vfs_handle_struct
*handle
)
295 glfs_clear_preopened(fs
);
298 static uint64_t vfs_gluster_disk_free(struct vfs_handle_struct
*handle
,
299 const char *path
, bool small_query
,
300 uint64_t *bsize_p
, uint64_t *dfree_p
,
303 struct statvfs statvfs
= { 0, };
307 ret
= glfs_statvfs(handle
->data
, path
, &statvfs
);
312 dfree
= statvfs
.f_bsize
* statvfs
.f_bavail
;
314 if (bsize_p
!= NULL
) {
315 *bsize_p
= statvfs
.f_bsize
;
317 if (dfree_p
!= NULL
) {
320 if (dsize_p
!= NULL
) {
321 *dsize_p
= statvfs
.f_bsize
* statvfs
.f_blocks
;
327 static int vfs_gluster_get_quota(struct vfs_handle_struct
*handle
,
328 enum SMB_QUOTA_TYPE qtype
, unid_t id
,
336 vfs_gluster_set_quota(struct vfs_handle_struct
*handle
,
337 enum SMB_QUOTA_TYPE qtype
, unid_t id
, SMB_DISK_QUOTA
*qt
)
343 static int vfs_gluster_statvfs(struct vfs_handle_struct
*handle
,
345 struct vfs_statvfs_struct
*vfs_statvfs
)
347 struct statvfs statvfs
= { 0, };
350 ret
= glfs_statvfs(handle
->data
, path
, &statvfs
);
352 DEBUG(0, ("glfs_statvfs(%s) failed: %s\n",
353 path
, strerror(errno
)));
357 ZERO_STRUCTP(vfs_statvfs
);
359 vfs_statvfs
->OptimalTransferSize
= statvfs
.f_frsize
;
360 vfs_statvfs
->BlockSize
= statvfs
.f_bsize
;
361 vfs_statvfs
->TotalBlocks
= statvfs
.f_blocks
;
362 vfs_statvfs
->BlocksAvail
= statvfs
.f_bfree
;
363 vfs_statvfs
->UserBlocksAvail
= statvfs
.f_bavail
;
364 vfs_statvfs
->TotalFileNodes
= statvfs
.f_files
;
365 vfs_statvfs
->FreeFileNodes
= statvfs
.f_ffree
;
366 vfs_statvfs
->FsIdentifier
= statvfs
.f_fsid
;
367 vfs_statvfs
->FsCapabilities
=
368 FILE_CASE_SENSITIVE_SEARCH
| FILE_CASE_PRESERVED_NAMES
;
373 static uint32_t vfs_gluster_fs_capabilities(struct vfs_handle_struct
*handle
,
374 enum timestamp_set_resolution
*p_ts_res
)
376 uint32_t caps
= FILE_CASE_SENSITIVE_SEARCH
| FILE_CASE_PRESERVED_NAMES
;
378 #ifdef STAT_HAVE_NSEC
379 *p_ts_res
= TIMESTAMP_SET_NT_OR_BETTER
;
385 static DIR *vfs_gluster_opendir(struct vfs_handle_struct
*handle
,
386 const char *path
, const char *mask
,
391 fd
= glfs_opendir(handle
->data
, path
);
393 DEBUG(0, ("glfs_opendir(%s) failed: %s\n",
394 path
, strerror(errno
)));
400 static DIR *vfs_gluster_fdopendir(struct vfs_handle_struct
*handle
,
401 files_struct
*fsp
, const char *mask
,
404 return (DIR *) glfd_fd_get(fsp
->fh
->fd
);
407 static int vfs_gluster_closedir(struct vfs_handle_struct
*handle
, DIR *dirp
)
409 return glfs_closedir((void *)dirp
);
412 static struct dirent
*vfs_gluster_readdir(struct vfs_handle_struct
*handle
,
413 DIR *dirp
, SMB_STRUCT_STAT
*sbuf
)
415 static char direntbuf
[512];
418 struct dirent
*dirent
= 0;
421 ret
= glfs_readdirplus_r((void *)dirp
, &stat
, (void *)direntbuf
,
424 ret
= glfs_readdir_r((void *)dirp
, (void *)direntbuf
, &dirent
);
427 if ((ret
< 0) || (dirent
== NULL
)) {
432 smb_stat_ex_from_stat(sbuf
, &stat
);
438 static long vfs_gluster_telldir(struct vfs_handle_struct
*handle
, DIR *dirp
)
440 return glfs_telldir((void *)dirp
);
443 static void vfs_gluster_seekdir(struct vfs_handle_struct
*handle
, DIR *dirp
,
446 glfs_seekdir((void *)dirp
, offset
);
449 static void vfs_gluster_rewinddir(struct vfs_handle_struct
*handle
, DIR *dirp
)
451 glfs_seekdir((void *)dirp
, 0);
454 static void vfs_gluster_init_search_op(struct vfs_handle_struct
*handle
,
460 static int vfs_gluster_mkdir(struct vfs_handle_struct
*handle
, const char *path
,
463 return glfs_mkdir(handle
->data
, path
, mode
);
466 static int vfs_gluster_rmdir(struct vfs_handle_struct
*handle
, const char *path
)
468 return glfs_rmdir(handle
->data
, path
);
471 static int vfs_gluster_open(struct vfs_handle_struct
*handle
,
472 struct smb_filename
*smb_fname
, files_struct
*fsp
,
473 int flags
, mode_t mode
)
477 if (flags
& O_DIRECTORY
) {
478 glfd
= glfs_opendir(handle
->data
, smb_fname
->base_name
);
479 } else if (flags
& O_CREAT
) {
480 glfd
= glfs_creat(handle
->data
, smb_fname
->base_name
, flags
,
483 glfd
= glfs_open(handle
->data
, smb_fname
->base_name
, flags
);
487 DEBUG(0, ("glfs_{open[dir],creat}(%s) failed: %s\n",
488 smb_fname
->base_name
, strerror(errno
)));
492 return glfd_fd_store(glfd
);
495 static int vfs_gluster_close(struct vfs_handle_struct
*handle
,
498 return glfs_close(glfd_fd_clear(fsp
->fh
->fd
));
501 static ssize_t
vfs_gluster_read(struct vfs_handle_struct
*handle
,
502 files_struct
*fsp
, void *data
, size_t n
)
504 return glfs_read(glfd_fd_get(fsp
->fh
->fd
), data
, n
, 0);
507 static ssize_t
vfs_gluster_pread(struct vfs_handle_struct
*handle
,
508 files_struct
*fsp
, void *data
, size_t n
,
511 return glfs_pread(glfd_fd_get(fsp
->fh
->fd
), data
, n
, offset
, 0);
514 static struct tevent_req
*vfs_gluster_pread_send(struct vfs_handle_struct
515 *handle
, TALLOC_CTX
*mem_ctx
,
516 struct tevent_context
*ev
,
517 files_struct
*fsp
, void *data
,
518 size_t n
, off_t offset
)
524 static ssize_t
vfs_gluster_pread_recv(struct tevent_req
*req
, int *err
)
530 static ssize_t
vfs_gluster_write(struct vfs_handle_struct
*handle
,
531 files_struct
*fsp
, const void *data
, size_t n
)
533 return glfs_write(glfd_fd_get(fsp
->fh
->fd
), data
, n
, 0);
536 static ssize_t
vfs_gluster_pwrite(struct vfs_handle_struct
*handle
,
537 files_struct
*fsp
, const void *data
,
538 size_t n
, off_t offset
)
540 return glfs_pwrite(glfd_fd_get(fsp
->fh
->fd
), data
, n
, offset
, 0);
543 static struct tevent_req
*vfs_gluster_pwrite_send(struct vfs_handle_struct
544 *handle
, TALLOC_CTX
*mem_ctx
,
545 struct tevent_context
*ev
,
547 const void *data
, size_t n
,
554 static ssize_t
vfs_gluster_pwrite_recv(struct tevent_req
*req
, int *err
)
560 static off_t
vfs_gluster_lseek(struct vfs_handle_struct
*handle
,
561 files_struct
*fsp
, off_t offset
, int whence
)
563 return glfs_lseek(glfd_fd_get(fsp
->fh
->fd
), offset
, whence
);
566 static ssize_t
vfs_gluster_sendfile(struct vfs_handle_struct
*handle
, int tofd
,
567 files_struct
*fromfsp
,
568 const DATA_BLOB
*hdr
,
569 off_t offset
, size_t n
)
575 static ssize_t
vfs_gluster_recvfile(struct vfs_handle_struct
*handle
,
576 int fromfd
, files_struct
*tofsp
,
577 off_t offset
, size_t n
)
583 static int vfs_gluster_rename(struct vfs_handle_struct
*handle
,
584 const struct smb_filename
*smb_fname_src
,
585 const struct smb_filename
*smb_fname_dst
)
587 return glfs_rename(handle
->data
, smb_fname_src
->base_name
,
588 smb_fname_dst
->base_name
);
591 static int vfs_gluster_fsync(struct vfs_handle_struct
*handle
,
594 return glfs_fsync(glfd_fd_get(fsp
->fh
->fd
));
597 static struct tevent_req
*vfs_gluster_fsync_send(struct vfs_handle_struct
598 *handle
, TALLOC_CTX
*mem_ctx
,
599 struct tevent_context
*ev
,
606 static int vfs_gluster_fsync_recv(struct tevent_req
*req
, int *err
)
612 static int vfs_gluster_stat(struct vfs_handle_struct
*handle
,
613 struct smb_filename
*smb_fname
)
618 ret
= glfs_stat(handle
->data
, smb_fname
->base_name
, &st
);
620 smb_stat_ex_from_stat(&smb_fname
->st
, &st
);
622 if (ret
< 0 && errno
!= ENOENT
) {
623 DEBUG(0, ("glfs_stat(%s) failed: %s\n",
624 smb_fname
->base_name
, strerror(errno
)));
629 static int vfs_gluster_fstat(struct vfs_handle_struct
*handle
,
630 files_struct
*fsp
, SMB_STRUCT_STAT
*sbuf
)
635 ret
= glfs_fstat(glfd_fd_get(fsp
->fh
->fd
), &st
);
637 smb_stat_ex_from_stat(sbuf
, &st
);
640 DEBUG(0, ("glfs_fstat(%d) failed: %s\n",
641 fsp
->fh
->fd
, strerror(errno
)));
646 static int vfs_gluster_lstat(struct vfs_handle_struct
*handle
,
647 struct smb_filename
*smb_fname
)
652 ret
= glfs_lstat(handle
->data
, smb_fname
->base_name
, &st
);
654 smb_stat_ex_from_stat(&smb_fname
->st
, &st
);
656 if (ret
< 0 && errno
!= ENOENT
) {
657 DEBUG(0, ("glfs_lstat(%s) failed: %s\n",
658 smb_fname
->base_name
, strerror(errno
)));
663 static uint64_t vfs_gluster_get_alloc_size(struct vfs_handle_struct
*handle
,
665 const SMB_STRUCT_STAT
*sbuf
)
667 return sbuf
->st_ex_blocks
* 512;
670 static int vfs_gluster_unlink(struct vfs_handle_struct
*handle
,
671 const struct smb_filename
*smb_fname
)
673 return glfs_unlink(handle
->data
, smb_fname
->base_name
);
676 static int vfs_gluster_chmod(struct vfs_handle_struct
*handle
,
677 const char *path
, mode_t mode
)
679 return glfs_chmod(handle
->data
, path
, mode
);
682 static int vfs_gluster_fchmod(struct vfs_handle_struct
*handle
,
683 files_struct
*fsp
, mode_t mode
)
685 return glfs_fchmod(glfd_fd_get(fsp
->fh
->fd
), mode
);
688 static int vfs_gluster_chown(struct vfs_handle_struct
*handle
,
689 const char *path
, uid_t uid
, gid_t gid
)
691 return glfs_chown(handle
->data
, path
, uid
, gid
);
694 static int vfs_gluster_fchown(struct vfs_handle_struct
*handle
,
695 files_struct
*fsp
, uid_t uid
, gid_t gid
)
697 return glfs_fchown(glfd_fd_get(fsp
->fh
->fd
), uid
, gid
);
700 static int vfs_gluster_lchown(struct vfs_handle_struct
*handle
,
701 const char *path
, uid_t uid
, gid_t gid
)
703 return glfs_lchown(handle
->data
, path
, uid
, gid
);
706 static int vfs_gluster_chdir(struct vfs_handle_struct
*handle
, const char *path
)
708 return glfs_chdir(handle
->data
, path
);
711 static char *vfs_gluster_getwd(struct vfs_handle_struct
*handle
)
716 cwd
= calloc(1, PATH_MAX
+ 1);
721 ret
= glfs_getcwd(handle
->data
, cwd
, PATH_MAX
);
728 static int vfs_gluster_ntimes(struct vfs_handle_struct
*handle
,
729 const struct smb_filename
*smb_fname
,
730 struct smb_file_time
*ft
)
732 struct timespec times
[2];
734 times
[0].tv_sec
= ft
->atime
.tv_sec
;
735 times
[0].tv_nsec
= ft
->atime
.tv_nsec
;
736 times
[1].tv_sec
= ft
->mtime
.tv_sec
;
737 times
[1].tv_nsec
= ft
->mtime
.tv_nsec
;
739 return glfs_utimens(handle
->data
, smb_fname
->base_name
, times
);
742 static int vfs_gluster_ftruncate(struct vfs_handle_struct
*handle
,
743 files_struct
*fsp
, off_t offset
)
745 return glfs_ftruncate(glfd_fd_get(fsp
->fh
->fd
), offset
);
748 static int vfs_gluster_fallocate(struct vfs_handle_struct
*handle
,
749 struct files_struct
*fsp
,
750 enum vfs_fallocate_mode mode
,
751 off_t offset
, off_t len
)
757 static char *vfs_gluster_realpath(struct vfs_handle_struct
*handle
,
760 return glfs_realpath(handle
->data
, path
, 0);
763 static bool vfs_gluster_lock(struct vfs_handle_struct
*handle
,
764 files_struct
*fsp
, int op
, off_t offset
,
765 off_t count
, int type
)
767 struct flock flock
= { 0, };
771 flock
.l_whence
= SEEK_SET
;
772 flock
.l_start
= offset
;
776 ret
= glfs_posix_lock(glfd_fd_get(fsp
->fh
->fd
), op
, &flock
);
779 /* lock query, true if someone else has locked */
781 (flock
.l_type
!= F_UNLCK
) &&
782 (flock
.l_pid
!= 0) && (flock
.l_pid
!= getpid()))
795 static int vfs_gluster_kernel_flock(struct vfs_handle_struct
*handle
,
796 files_struct
*fsp
, uint32 share_mode
,
797 uint32_t access_mask
)
803 static int vfs_gluster_linux_setlease(struct vfs_handle_struct
*handle
,
804 files_struct
*fsp
, int leasetype
)
810 static bool vfs_gluster_getlock(struct vfs_handle_struct
*handle
,
811 files_struct
*fsp
, off_t
*poffset
,
812 off_t
*pcount
, int *ptype
, pid_t
*ppid
)
814 struct flock flock
= { 0, };
817 flock
.l_type
= *ptype
;
818 flock
.l_whence
= SEEK_SET
;
819 flock
.l_start
= *poffset
;
820 flock
.l_len
= *pcount
;
823 ret
= glfs_posix_lock(glfd_fd_get(fsp
->fh
->fd
), F_GETLK
, &flock
);
829 *ptype
= flock
.l_type
;
830 *poffset
= flock
.l_start
;
831 *pcount
= flock
.l_len
;
837 static int vfs_gluster_symlink(struct vfs_handle_struct
*handle
,
838 const char *oldpath
, const char *newpath
)
840 return glfs_symlink(handle
->data
, oldpath
, newpath
);
843 static int vfs_gluster_readlink(struct vfs_handle_struct
*handle
,
844 const char *path
, char *buf
, size_t bufsiz
)
846 return glfs_readlink(handle
->data
, path
, buf
, bufsiz
);
849 static int vfs_gluster_link(struct vfs_handle_struct
*handle
,
850 const char *oldpath
, const char *newpath
)
852 return glfs_link(handle
->data
, oldpath
, newpath
);
855 static int vfs_gluster_mknod(struct vfs_handle_struct
*handle
, const char *path
,
856 mode_t mode
, SMB_DEV_T dev
)
858 return glfs_mknod(handle
->data
, path
, mode
, dev
);
861 static NTSTATUS
vfs_gluster_notify_watch(struct vfs_handle_struct
*handle
,
862 struct sys_notify_context
*ctx
,
863 const char *path
, uint32_t *filter
,
864 uint32_t *subdir_filter
,
865 void (*callback
) (struct sys_notify_context
*ctx
,
867 struct notify_event
*ev
),
868 void *private_data
, void *handle_p
)
870 return NT_STATUS_NOT_IMPLEMENTED
;
873 static int vfs_gluster_chflags(struct vfs_handle_struct
*handle
,
874 const char *path
, unsigned int flags
)
880 static int vfs_gluster_get_real_filename(struct vfs_handle_struct
*handle
,
881 const char *path
, const char *name
,
882 TALLOC_CTX
*mem_ctx
, char **found_name
)
885 char key_buf
[NAME_MAX
+ 64];
886 char val_buf
[NAME_MAX
+ 1];
888 if (strlen(name
) >= NAME_MAX
) {
889 errno
= ENAMETOOLONG
;
893 snprintf(key_buf
, NAME_MAX
+ 64,
894 "user.glusterfs.get_real_filename:%s", name
);
896 ret
= glfs_getxattr(handle
->data
, path
, key_buf
, val_buf
, NAME_MAX
+ 1);
898 if (errno
== ENODATA
) {
904 *found_name
= talloc_strdup(mem_ctx
, val_buf
);
905 if (found_name
[0] == NULL
) {
912 static const char *vfs_gluster_connectpath(struct vfs_handle_struct
*handle
,
913 const char *filename
)
915 return handle
->conn
->connectpath
;
920 static ssize_t
vfs_gluster_getxattr(struct vfs_handle_struct
*handle
,
921 const char *path
, const char *name
,
922 void *value
, size_t size
)
924 return glfs_getxattr(handle
->data
, path
, name
, value
, size
);
927 static ssize_t
vfs_gluster_fgetxattr(struct vfs_handle_struct
*handle
,
928 files_struct
*fsp
, const char *name
,
929 void *value
, size_t size
)
931 return glfs_fgetxattr(glfd_fd_get(fsp
->fh
->fd
), name
, value
, size
);
934 static ssize_t
vfs_gluster_listxattr(struct vfs_handle_struct
*handle
,
935 const char *path
, char *list
, size_t size
)
937 return glfs_listxattr(handle
->data
, path
, list
, size
);
940 static ssize_t
vfs_gluster_flistxattr(struct vfs_handle_struct
*handle
,
941 files_struct
*fsp
, char *list
,
944 return glfs_flistxattr(glfd_fd_get(fsp
->fh
->fd
), list
, size
);
947 static int vfs_gluster_removexattr(struct vfs_handle_struct
*handle
,
948 const char *path
, const char *name
)
950 return glfs_removexattr(handle
->data
, path
, name
);
953 static int vfs_gluster_fremovexattr(struct vfs_handle_struct
*handle
,
954 files_struct
*fsp
, const char *name
)
956 return glfs_fremovexattr(glfd_fd_get(fsp
->fh
->fd
), name
);
959 static int vfs_gluster_setxattr(struct vfs_handle_struct
*handle
,
960 const char *path
, const char *name
,
961 const void *value
, size_t size
, int flags
)
963 return glfs_setxattr(handle
->data
, path
, name
, value
, size
, flags
);
966 static int vfs_gluster_fsetxattr(struct vfs_handle_struct
*handle
,
967 files_struct
*fsp
, const char *name
,
968 const void *value
, size_t size
, int flags
)
970 return glfs_fsetxattr(glfd_fd_get(fsp
->fh
->fd
), name
, value
, size
,
976 static bool vfs_gluster_aio_force(struct vfs_handle_struct
*handle
,
982 /* Offline Operations */
984 static bool vfs_gluster_is_offline(struct vfs_handle_struct
*handle
,
985 const struct smb_filename
*fname
,
986 SMB_STRUCT_STAT
*sbuf
)
991 static int vfs_gluster_set_offline(struct vfs_handle_struct
*handle
,
992 const struct smb_filename
*fname
)
998 /* Posix ACL Operations */
1000 #define GLUSTER_ACL_VERSION 2
1001 #define GLUSTER_ACL_READ 0x04
1002 #define GLUSTER_ACL_WRITE 0x02
1003 #define GLUSTER_ACL_EXECUTE 0x01
1005 #define GLUSTER_ACL_UNDEFINED_TAG 0x00
1006 #define GLUSTER_ACL_USER_OBJ 0x01
1007 #define GLUSTER_ACL_USER 0x02
1008 #define GLUSTER_ACL_GROUP_OBJ 0x04
1009 #define GLUSTER_ACL_GROUP 0x08
1010 #define GLUSTER_ACL_MASK 0x10
1011 #define GLUSTER_ACL_OTHER 0x20
1013 #define GLUSTER_ACL_UNDEFINED_ID (-1)
1015 struct gluster_ace
{
1021 struct gluster_acl_header
{
1023 struct gluster_ace entries
[];
1026 static SMB_ACL_T
gluster_to_smb_acl(const char *buf
, size_t xattr_size
,
1027 TALLOC_CTX
*mem_ctx
)
1031 struct gluster_ace
*ace
;
1032 struct smb_acl_entry
*smb_ace
;
1033 struct gluster_acl_header
*hdr
;
1034 struct smb_acl_t
*result
;
1042 if (size
< sizeof(*hdr
)) {
1043 /* ACL should be at least as big as the header */
1048 size
-= sizeof(*hdr
);
1050 if (size
% sizeof(*ace
)) {
1051 /* Size of entries must strictly be a multiple of
1058 count
= size
/ sizeof(*ace
);
1062 if (ntohl(hdr
->version
) != GLUSTER_ACL_VERSION
) {
1063 DEBUG(0, ("Unknown gluster ACL version: %d\n",
1064 ntohl(hdr
->version
)));
1068 result
= sys_acl_init(mem_ctx
);
1074 result
->acl
= talloc_array(result
, struct smb_acl_entry
, count
);
1077 talloc_free(result
);
1081 result
->count
= count
;
1083 smb_ace
= result
->acl
;
1086 for (i
= 0; i
< count
; i
++) {
1087 tag
= ntohs(ace
->tag
);
1090 case GLUSTER_ACL_USER
:
1091 smb_ace
->a_type
= SMB_ACL_USER
;
1093 case GLUSTER_ACL_USER_OBJ
:
1094 smb_ace
->a_type
= SMB_ACL_USER_OBJ
;
1096 case GLUSTER_ACL_GROUP
:
1097 smb_ace
->a_type
= SMB_ACL_GROUP
;
1099 case GLUSTER_ACL_GROUP_OBJ
:
1100 smb_ace
->a_type
= SMB_ACL_GROUP_OBJ
;
1102 case GLUSTER_ACL_OTHER
:
1103 smb_ace
->a_type
= SMB_ACL_OTHER
;
1105 case GLUSTER_ACL_MASK
:
1106 smb_ace
->a_type
= SMB_ACL_MASK
;
1109 DEBUG(0, ("unknown tag type %d\n", (unsigned int) tag
));
1113 id
= ntohl(ace
->id
);
1115 switch(smb_ace
->a_type
) {
1117 smb_ace
->info
.user
.uid
= id
;
1120 smb_ace
->info
.group
.gid
= id
;
1126 perm
= ntohs(ace
->perm
);
1128 smb_ace
->a_perm
= 0;
1130 ((perm
& GLUSTER_ACL_READ
) ? SMB_ACL_READ
: 0);
1132 ((perm
& GLUSTER_ACL_WRITE
) ? SMB_ACL_WRITE
: 0);
1134 ((perm
& GLUSTER_ACL_EXECUTE
) ? SMB_ACL_EXECUTE
: 0);
1144 static ssize_t
smb_to_gluster_acl(SMB_ACL_T theacl
, char *buf
, size_t len
)
1147 struct gluster_ace
*ace
;
1148 struct smb_acl_entry
*smb_ace
;
1149 struct gluster_acl_header
*hdr
;
1156 count
= theacl
->count
;
1158 size
= sizeof(*hdr
) + (count
* sizeof(*ace
));
1170 smb_ace
= theacl
->acl
;
1172 hdr
->version
= htonl(GLUSTER_ACL_VERSION
);
1174 for (i
= 0; i
< count
; i
++) {
1175 switch(smb_ace
->a_type
) {
1177 tag
= GLUSTER_ACL_USER
;
1179 case SMB_ACL_USER_OBJ
:
1180 tag
= GLUSTER_ACL_USER_OBJ
;
1183 tag
= GLUSTER_ACL_GROUP
;
1185 case SMB_ACL_GROUP_OBJ
:
1186 tag
= GLUSTER_ACL_GROUP_OBJ
;
1189 tag
= GLUSTER_ACL_OTHER
;
1192 tag
= GLUSTER_ACL_MASK
;
1195 DEBUG(0, ("Unknown tag value %d\n",
1201 ace
->tag
= ntohs(tag
);
1203 switch(smb_ace
->a_type
) {
1205 id
= smb_ace
->info
.user
.uid
;
1208 id
= smb_ace
->info
.group
.gid
;
1211 id
= GLUSTER_ACL_UNDEFINED_ID
;
1215 ace
->id
= ntohl(id
);
1219 ((smb_ace
->a_perm
& SMB_ACL_READ
) ? GLUSTER_ACL_READ
: 0);
1221 ((smb_ace
->a_perm
& SMB_ACL_WRITE
) ? GLUSTER_ACL_WRITE
: 0);
1223 ((smb_ace
->a_perm
& SMB_ACL_EXECUTE
) ? GLUSTER_ACL_EXECUTE
: 0);
1233 static SMB_ACL_T
vfs_gluster_sys_acl_get_file(struct vfs_handle_struct
*handle
,
1235 SMB_ACL_TYPE_T type
,
1236 TALLOC_CTX
*mem_ctx
)
1238 struct smb_acl_t
*result
;
1244 case SMB_ACL_TYPE_ACCESS
:
1245 key
= "system.posix_acl_access";
1247 case SMB_ACL_TYPE_DEFAULT
:
1248 key
= "system.posix_acl_default";
1255 ret
= glfs_getxattr(handle
->data
, path_p
, key
, 0, 0);
1261 ret
= glfs_getxattr(handle
->data
, path_p
, key
, buf
, ret
);
1266 result
= gluster_to_smb_acl(buf
, ret
, mem_ctx
);
1271 static SMB_ACL_T
vfs_gluster_sys_acl_get_fd(struct vfs_handle_struct
*handle
,
1272 struct files_struct
*fsp
,
1273 TALLOC_CTX
*mem_ctx
)
1275 struct smb_acl_t
*result
;
1279 ret
= glfs_fgetxattr(glfd_fd_get(fsp
->fh
->fd
),
1280 "system.posix_acl_access", 0, 0);
1286 ret
= glfs_fgetxattr(glfd_fd_get(fsp
->fh
->fd
),
1287 "system.posix_acl_access", buf
, ret
);
1292 result
= gluster_to_smb_acl(buf
, ret
, mem_ctx
);
1297 static int vfs_gluster_sys_acl_set_file(struct vfs_handle_struct
*handle
,
1299 SMB_ACL_TYPE_T acltype
,
1308 case SMB_ACL_TYPE_ACCESS
:
1309 key
= "system.posix_acl_access";
1311 case SMB_ACL_TYPE_DEFAULT
:
1312 key
= "system.posix_acl_default";
1319 size
= smb_to_gluster_acl(theacl
, 0, 0);
1322 size
= smb_to_gluster_acl(theacl
, buf
, size
);
1327 ret
= glfs_setxattr(handle
->data
, name
, key
, buf
, size
, 0);
1332 static int vfs_gluster_sys_acl_set_fd(struct vfs_handle_struct
*handle
,
1333 struct files_struct
*fsp
,
1341 size
= smb_to_gluster_acl(theacl
, 0, 0);
1344 size
= smb_to_gluster_acl(theacl
, buf
, size
);
1349 ret
= glfs_fsetxattr(glfd_fd_get(fsp
->fh
->fd
),
1350 "system.posix_acl_access", buf
, size
, 0);
1354 static int vfs_gluster_sys_acl_delete_def_file(struct vfs_handle_struct
*handle
,
1357 return glfs_removexattr(handle
->data
, path
, "system.posix_acl_default");
1360 static struct vfs_fn_pointers glusterfs_fns
= {
1362 /* Disk Operations */
1364 .connect_fn
= vfs_gluster_connect
,
1365 .disconnect_fn
= vfs_gluster_disconnect
,
1366 .disk_free_fn
= vfs_gluster_disk_free
,
1367 .get_quota_fn
= vfs_gluster_get_quota
,
1368 .set_quota_fn
= vfs_gluster_set_quota
,
1369 .statvfs_fn
= vfs_gluster_statvfs
,
1370 .fs_capabilities_fn
= vfs_gluster_fs_capabilities
,
1372 .get_dfs_referrals_fn
= NULL
,
1374 /* Directory Operations */
1376 .opendir_fn
= vfs_gluster_opendir
,
1377 .fdopendir_fn
= vfs_gluster_fdopendir
,
1378 .readdir_fn
= vfs_gluster_readdir
,
1379 .seekdir_fn
= vfs_gluster_seekdir
,
1380 .telldir_fn
= vfs_gluster_telldir
,
1381 .rewind_dir_fn
= vfs_gluster_rewinddir
,
1382 .mkdir_fn
= vfs_gluster_mkdir
,
1383 .rmdir_fn
= vfs_gluster_rmdir
,
1384 .closedir_fn
= vfs_gluster_closedir
,
1385 .init_search_op_fn
= vfs_gluster_init_search_op
,
1387 /* File Operations */
1389 .open_fn
= vfs_gluster_open
,
1390 .create_file_fn
= NULL
,
1391 .close_fn
= vfs_gluster_close
,
1392 .read_fn
= vfs_gluster_read
,
1393 .pread_fn
= vfs_gluster_pread
,
1394 .pread_send_fn
= vfs_gluster_pread_send
,
1395 .pread_recv_fn
= vfs_gluster_pread_recv
,
1396 .write_fn
= vfs_gluster_write
,
1397 .pwrite_fn
= vfs_gluster_pwrite
,
1398 .pwrite_send_fn
= vfs_gluster_pwrite_send
,
1399 .pwrite_recv_fn
= vfs_gluster_pwrite_recv
,
1400 .lseek_fn
= vfs_gluster_lseek
,
1401 .sendfile_fn
= vfs_gluster_sendfile
,
1402 .recvfile_fn
= vfs_gluster_recvfile
,
1403 .rename_fn
= vfs_gluster_rename
,
1404 .fsync_fn
= vfs_gluster_fsync
,
1405 .fsync_send_fn
= vfs_gluster_fsync_send
,
1406 .fsync_recv_fn
= vfs_gluster_fsync_recv
,
1408 .stat_fn
= vfs_gluster_stat
,
1409 .fstat_fn
= vfs_gluster_fstat
,
1410 .lstat_fn
= vfs_gluster_lstat
,
1411 .get_alloc_size_fn
= vfs_gluster_get_alloc_size
,
1412 .unlink_fn
= vfs_gluster_unlink
,
1414 .chmod_fn
= vfs_gluster_chmod
,
1415 .fchmod_fn
= vfs_gluster_fchmod
,
1416 .chown_fn
= vfs_gluster_chown
,
1417 .fchown_fn
= vfs_gluster_fchown
,
1418 .lchown_fn
= vfs_gluster_lchown
,
1419 .chdir_fn
= vfs_gluster_chdir
,
1420 .getwd_fn
= vfs_gluster_getwd
,
1421 .ntimes_fn
= vfs_gluster_ntimes
,
1422 .ftruncate_fn
= vfs_gluster_ftruncate
,
1423 .fallocate_fn
= vfs_gluster_fallocate
,
1424 .lock_fn
= vfs_gluster_lock
,
1425 .kernel_flock_fn
= vfs_gluster_kernel_flock
,
1426 .linux_setlease_fn
= vfs_gluster_linux_setlease
,
1427 .getlock_fn
= vfs_gluster_getlock
,
1428 .symlink_fn
= vfs_gluster_symlink
,
1429 .readlink_fn
= vfs_gluster_readlink
,
1430 .link_fn
= vfs_gluster_link
,
1431 .mknod_fn
= vfs_gluster_mknod
,
1432 .realpath_fn
= vfs_gluster_realpath
,
1433 .notify_watch_fn
= vfs_gluster_notify_watch
,
1434 .chflags_fn
= vfs_gluster_chflags
,
1435 .file_id_create_fn
= NULL
,
1436 .copy_chunk_send_fn
= NULL
,
1437 .copy_chunk_recv_fn
= NULL
,
1438 .streaminfo_fn
= NULL
,
1439 .get_real_filename_fn
= vfs_gluster_get_real_filename
,
1440 .connectpath_fn
= vfs_gluster_connectpath
,
1442 .brl_lock_windows_fn
= NULL
,
1443 .brl_unlock_windows_fn
= NULL
,
1444 .brl_cancel_windows_fn
= NULL
,
1445 .strict_lock_fn
= NULL
,
1446 .strict_unlock_fn
= NULL
,
1447 .translate_name_fn
= NULL
,
1450 /* NT ACL Operations */
1451 .fget_nt_acl_fn
= NULL
,
1452 .get_nt_acl_fn
= NULL
,
1453 .fset_nt_acl_fn
= NULL
,
1454 .audit_file_fn
= NULL
,
1456 /* Posix ACL Operations */
1457 .chmod_acl_fn
= NULL
, /* passthrough to default */
1458 .fchmod_acl_fn
= NULL
, /* passthrough to default */
1459 .sys_acl_get_file_fn
= vfs_gluster_sys_acl_get_file
,
1460 .sys_acl_get_fd_fn
= vfs_gluster_sys_acl_get_fd
,
1461 .sys_acl_blob_get_file_fn
= posix_sys_acl_blob_get_file
,
1462 .sys_acl_blob_get_fd_fn
= posix_sys_acl_blob_get_fd
,
1463 .sys_acl_set_file_fn
= vfs_gluster_sys_acl_set_file
,
1464 .sys_acl_set_fd_fn
= vfs_gluster_sys_acl_set_fd
,
1465 .sys_acl_delete_def_file_fn
= vfs_gluster_sys_acl_delete_def_file
,
1468 .getxattr_fn
= vfs_gluster_getxattr
,
1469 .fgetxattr_fn
= vfs_gluster_fgetxattr
,
1470 .listxattr_fn
= vfs_gluster_listxattr
,
1471 .flistxattr_fn
= vfs_gluster_flistxattr
,
1472 .removexattr_fn
= vfs_gluster_removexattr
,
1473 .fremovexattr_fn
= vfs_gluster_fremovexattr
,
1474 .setxattr_fn
= vfs_gluster_setxattr
,
1475 .fsetxattr_fn
= vfs_gluster_fsetxattr
,
1477 /* AIO Operations */
1478 .aio_force_fn
= vfs_gluster_aio_force
,
1480 /* Offline Operations */
1481 .is_offline_fn
= vfs_gluster_is_offline
,
1482 .set_offline_fn
= vfs_gluster_set_offline
,
1484 /* Durable handle Operations */
1485 .durable_cookie_fn
= NULL
,
1486 .durable_disconnect_fn
= NULL
,
1487 .durable_reconnect_fn
= NULL
,
1490 NTSTATUS
vfs_glusterfs_init(void);
1491 NTSTATUS
vfs_glusterfs_init(void)
1493 return smb_register_vfs(SMB_VFS_INTERFACE_VERSION
,
1494 "glusterfs", &glusterfs_fns
);