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 * @file vfs_glusterfs.c
24 * @author Anand Avati <avati@redhat.com>
26 * @brief Samba VFS module for glusterfs
30 * See, for example \c vfs_aio_linux.c in the \c sourc3/modules directory
31 * - sendfile/recvfile support
33 * A Samba VFS module for GlusterFS, based on Gluster's libgfapi.
34 * This is a "bottom" vfs module (not something to be stacked on top of
35 * another module), and translates (most) calls to the closest actions
36 * available in libgfapi.
41 #include "smbd/smbd.h"
44 #include "lib/util/dlinklist.h"
46 #define DEFAULT_VOLFILE_SERVER "localhost"
48 /* Helpers to provide 'integer' fds */
50 /* This is global. gfapi's FD operations do not
51 require filesystem context.
54 static glfs_fd_t
**glfd_fd
;
55 static int glfd_fd_size
;
56 static int glfd_fd_used
;
58 static int glfd_fd_store(glfs_fd_t
*glfd
)
63 if (glfd_fd_size
== glfd_fd_used
) {
64 if (glfd_fd_size
>= INT_MAX
- 1) {
69 tmp
= talloc_realloc(glfd_fd
, glfd_fd
, glfs_fd_t
*,
77 glfd_fd
[glfd_fd_size
] = 0;
81 for (i
= 0; i
< glfd_fd_size
; i
++) {
82 if (glfd_fd
[i
] == NULL
) {
91 static glfs_fd_t
*glfd_fd_get(int i
)
93 if (i
< 0 || i
>= glfd_fd_size
) {
99 static glfs_fd_t
*glfd_fd_clear(int i
)
101 glfs_fd_t
*glfd
= NULL
;
103 if (i
< 0 || i
>= glfd_fd_size
) {
115 * Helper to convert struct stat to struct stat_ex.
117 static void smb_stat_ex_from_stat(struct stat_ex
*dst
, const struct stat
*src
)
121 dst
->st_ex_dev
= src
->st_dev
;
122 dst
->st_ex_ino
= src
->st_ino
;
123 dst
->st_ex_mode
= src
->st_mode
;
124 dst
->st_ex_nlink
= src
->st_nlink
;
125 dst
->st_ex_uid
= src
->st_uid
;
126 dst
->st_ex_gid
= src
->st_gid
;
127 dst
->st_ex_rdev
= src
->st_rdev
;
128 dst
->st_ex_size
= src
->st_size
;
129 dst
->st_ex_atime
.tv_sec
= src
->st_atime
;
130 dst
->st_ex_mtime
.tv_sec
= src
->st_mtime
;
131 dst
->st_ex_ctime
.tv_sec
= src
->st_ctime
;
132 dst
->st_ex_btime
.tv_sec
= src
->st_mtime
;
133 dst
->st_ex_blksize
= src
->st_blksize
;
134 dst
->st_ex_blocks
= src
->st_blocks
;
135 #ifdef STAT_HAVE_NSEC
136 dst
->st_ex_atime
.tv_nsec
= src
->st_atime_nsec
;
137 dst
->st_ex_mtime
.tv_nsec
= src
->st_mtime_nsec
;
138 dst
->st_ex_ctime
.tv_nsec
= src
->st_ctime_nsec
;
139 dst
->st_ex_btime
.tv_nsec
= src
->st_mtime_nsec
;
143 /* pre-opened glfs_t */
145 static struct glfs_preopened
{
149 struct glfs_preopened
*next
, *prev
;
153 static int glfs_set_preopened(const char *volume
, glfs_t
*fs
)
155 struct glfs_preopened
*entry
= NULL
;
157 entry
= talloc_zero(NULL
, struct glfs_preopened
);
163 entry
->volume
= talloc_strdup(entry
, volume
);
164 if (!entry
->volume
) {
173 DLIST_ADD(glfs_preopened
, entry
);
178 static glfs_t
*glfs_find_preopened(const char *volume
)
180 struct glfs_preopened
*entry
= NULL
;
182 for (entry
= glfs_preopened
; entry
; entry
= entry
->next
) {
183 if (strcmp(entry
->volume
, volume
) == 0) {
192 static void glfs_clear_preopened(glfs_t
*fs
)
194 struct glfs_preopened
*entry
= NULL
;
196 for (entry
= glfs_preopened
; entry
; entry
= entry
->next
) {
197 if (entry
->fs
== fs
) {
201 DLIST_REMOVE(glfs_preopened
, entry
);
203 glfs_fini(entry
->fs
);
209 /* Disk Operations */
211 static int vfs_gluster_connect(struct vfs_handle_struct
*handle
,
215 const char *volfile_server
;
223 tmp_ctx
= talloc_new(NULL
);
224 if (tmp_ctx
== NULL
) {
228 logfile
= lp_parm_talloc_string(tmp_ctx
, SNUM(handle
->conn
), "glusterfs",
231 loglevel
= lp_parm_int(SNUM(handle
->conn
), "glusterfs", "loglevel", -1);
233 volfile_server
= lp_parm_const_string(SNUM(handle
->conn
), "glusterfs",
234 "volfile_server", NULL
);
235 if (volfile_server
== NULL
) {
236 volfile_server
= DEFAULT_VOLFILE_SERVER
;
239 volume
= lp_parm_const_string(SNUM(handle
->conn
), "glusterfs", "volume",
241 if (volume
== NULL
) {
245 fs
= glfs_find_preopened(volume
);
250 fs
= glfs_new(volume
);
256 ret
= glfs_set_volfile_server(fs
, "tcp", volfile_server
, 0);
258 DEBUG(0, ("Failed to set volfile_server %s\n", volfile_server
));
262 ret
= glfs_set_xlator_option(fs
, "*-md-cache", "cache-posix-acl",
265 DEBUG(0, ("%s: Failed to set xlator options\n", volume
));
269 ret
= glfs_set_logging(fs
, logfile
, loglevel
);
271 DEBUG(0, ("%s: Failed to set logfile %s loglevel %d\n",
272 volume
, logfile
, loglevel
));
278 DEBUG(0, ("%s: Failed to initialize volume (%s)\n",
279 volume
, strerror(errno
)));
283 ret
= glfs_set_preopened(volume
, fs
);
285 DEBUG(0, ("%s: Failed to register volume (%s)\n",
286 volume
, strerror(errno
)));
290 talloc_free(tmp_ctx
);
296 DEBUG(0, ("%s: Initialized volume from server %s\n",
297 volume
, volfile_server
));
303 static void vfs_gluster_disconnect(struct vfs_handle_struct
*handle
)
309 glfs_clear_preopened(fs
);
312 static uint64_t vfs_gluster_disk_free(struct vfs_handle_struct
*handle
,
313 const char *path
, bool small_query
,
314 uint64_t *bsize_p
, uint64_t *dfree_p
,
317 struct statvfs statvfs
= { 0, };
320 ret
= glfs_statvfs(handle
->data
, path
, &statvfs
);
325 if (bsize_p
!= NULL
) {
326 *bsize_p
= (uint64_t)statvfs
.f_bsize
; /* Block size */
328 if (dfree_p
!= NULL
) {
329 *dfree_p
= (uint64_t)statvfs
.f_bavail
; /* Available Block units */
331 if (dsize_p
!= NULL
) {
332 *dsize_p
= (uint64_t)statvfs
.f_blocks
; /* Total Block units */
335 return (uint64_t)statvfs
.f_bavail
;
338 static int vfs_gluster_get_quota(struct vfs_handle_struct
*handle
,
339 enum SMB_QUOTA_TYPE qtype
, unid_t id
,
347 vfs_gluster_set_quota(struct vfs_handle_struct
*handle
,
348 enum SMB_QUOTA_TYPE qtype
, unid_t id
, SMB_DISK_QUOTA
*qt
)
354 static int vfs_gluster_statvfs(struct vfs_handle_struct
*handle
,
356 struct vfs_statvfs_struct
*vfs_statvfs
)
358 struct statvfs statvfs
= { 0, };
361 ret
= glfs_statvfs(handle
->data
, path
, &statvfs
);
363 DEBUG(0, ("glfs_statvfs(%s) failed: %s\n",
364 path
, strerror(errno
)));
368 ZERO_STRUCTP(vfs_statvfs
);
370 vfs_statvfs
->OptimalTransferSize
= statvfs
.f_frsize
;
371 vfs_statvfs
->BlockSize
= statvfs
.f_bsize
;
372 vfs_statvfs
->TotalBlocks
= statvfs
.f_blocks
;
373 vfs_statvfs
->BlocksAvail
= statvfs
.f_bfree
;
374 vfs_statvfs
->UserBlocksAvail
= statvfs
.f_bavail
;
375 vfs_statvfs
->TotalFileNodes
= statvfs
.f_files
;
376 vfs_statvfs
->FreeFileNodes
= statvfs
.f_ffree
;
377 vfs_statvfs
->FsIdentifier
= statvfs
.f_fsid
;
378 vfs_statvfs
->FsCapabilities
=
379 FILE_CASE_SENSITIVE_SEARCH
| FILE_CASE_PRESERVED_NAMES
;
384 static uint32_t vfs_gluster_fs_capabilities(struct vfs_handle_struct
*handle
,
385 enum timestamp_set_resolution
*p_ts_res
)
387 uint32_t caps
= FILE_CASE_SENSITIVE_SEARCH
| FILE_CASE_PRESERVED_NAMES
;
389 #ifdef STAT_HAVE_NSEC
390 *p_ts_res
= TIMESTAMP_SET_NT_OR_BETTER
;
396 static DIR *vfs_gluster_opendir(struct vfs_handle_struct
*handle
,
397 const char *path
, const char *mask
,
402 fd
= glfs_opendir(handle
->data
, path
);
404 DEBUG(0, ("glfs_opendir(%s) failed: %s\n",
405 path
, strerror(errno
)));
411 static DIR *vfs_gluster_fdopendir(struct vfs_handle_struct
*handle
,
412 files_struct
*fsp
, const char *mask
,
415 return (DIR *) glfd_fd_get(fsp
->fh
->fd
);
418 static int vfs_gluster_closedir(struct vfs_handle_struct
*handle
, DIR *dirp
)
420 return glfs_closedir((void *)dirp
);
423 static struct dirent
*vfs_gluster_readdir(struct vfs_handle_struct
*handle
,
424 DIR *dirp
, SMB_STRUCT_STAT
*sbuf
)
426 static char direntbuf
[512];
429 struct dirent
*dirent
= 0;
432 ret
= glfs_readdirplus_r((void *)dirp
, &stat
, (void *)direntbuf
,
435 ret
= glfs_readdir_r((void *)dirp
, (void *)direntbuf
, &dirent
);
438 if ((ret
< 0) || (dirent
== NULL
)) {
443 smb_stat_ex_from_stat(sbuf
, &stat
);
449 static long vfs_gluster_telldir(struct vfs_handle_struct
*handle
, DIR *dirp
)
451 return glfs_telldir((void *)dirp
);
454 static void vfs_gluster_seekdir(struct vfs_handle_struct
*handle
, DIR *dirp
,
457 glfs_seekdir((void *)dirp
, offset
);
460 static void vfs_gluster_rewinddir(struct vfs_handle_struct
*handle
, DIR *dirp
)
462 glfs_seekdir((void *)dirp
, 0);
465 static void vfs_gluster_init_search_op(struct vfs_handle_struct
*handle
,
471 static int vfs_gluster_mkdir(struct vfs_handle_struct
*handle
, const char *path
,
474 return glfs_mkdir(handle
->data
, path
, mode
);
477 static int vfs_gluster_rmdir(struct vfs_handle_struct
*handle
, const char *path
)
479 return glfs_rmdir(handle
->data
, path
);
482 static int vfs_gluster_open(struct vfs_handle_struct
*handle
,
483 struct smb_filename
*smb_fname
, files_struct
*fsp
,
484 int flags
, mode_t mode
)
488 if (flags
& O_DIRECTORY
) {
489 glfd
= glfs_opendir(handle
->data
, smb_fname
->base_name
);
490 } else if (flags
& O_CREAT
) {
491 glfd
= glfs_creat(handle
->data
, smb_fname
->base_name
, flags
,
494 glfd
= glfs_open(handle
->data
, smb_fname
->base_name
, flags
);
500 return glfd_fd_store(glfd
);
503 static int vfs_gluster_close(struct vfs_handle_struct
*handle
,
506 return glfs_close(glfd_fd_clear(fsp
->fh
->fd
));
509 static ssize_t
vfs_gluster_read(struct vfs_handle_struct
*handle
,
510 files_struct
*fsp
, void *data
, size_t n
)
512 return glfs_read(glfd_fd_get(fsp
->fh
->fd
), data
, n
, 0);
515 static ssize_t
vfs_gluster_pread(struct vfs_handle_struct
*handle
,
516 files_struct
*fsp
, void *data
, size_t n
,
519 return glfs_pread(glfd_fd_get(fsp
->fh
->fd
), data
, n
, offset
, 0);
522 static struct tevent_req
*vfs_gluster_pread_send(struct vfs_handle_struct
523 *handle
, TALLOC_CTX
*mem_ctx
,
524 struct tevent_context
*ev
,
525 files_struct
*fsp
, void *data
,
526 size_t n
, off_t offset
)
532 static ssize_t
vfs_gluster_pread_recv(struct tevent_req
*req
, int *err
)
538 static ssize_t
vfs_gluster_write(struct vfs_handle_struct
*handle
,
539 files_struct
*fsp
, const void *data
, size_t n
)
541 return glfs_write(glfd_fd_get(fsp
->fh
->fd
), data
, n
, 0);
544 static ssize_t
vfs_gluster_pwrite(struct vfs_handle_struct
*handle
,
545 files_struct
*fsp
, const void *data
,
546 size_t n
, off_t offset
)
548 return glfs_pwrite(glfd_fd_get(fsp
->fh
->fd
), data
, n
, offset
, 0);
551 static struct tevent_req
*vfs_gluster_pwrite_send(struct vfs_handle_struct
552 *handle
, TALLOC_CTX
*mem_ctx
,
553 struct tevent_context
*ev
,
555 const void *data
, size_t n
,
562 static ssize_t
vfs_gluster_pwrite_recv(struct tevent_req
*req
, int *err
)
568 static off_t
vfs_gluster_lseek(struct vfs_handle_struct
*handle
,
569 files_struct
*fsp
, off_t offset
, int whence
)
571 return glfs_lseek(glfd_fd_get(fsp
->fh
->fd
), offset
, whence
);
574 static ssize_t
vfs_gluster_sendfile(struct vfs_handle_struct
*handle
, int tofd
,
575 files_struct
*fromfsp
,
576 const DATA_BLOB
*hdr
,
577 off_t offset
, size_t n
)
583 static ssize_t
vfs_gluster_recvfile(struct vfs_handle_struct
*handle
,
584 int fromfd
, files_struct
*tofsp
,
585 off_t offset
, size_t n
)
591 static int vfs_gluster_rename(struct vfs_handle_struct
*handle
,
592 const struct smb_filename
*smb_fname_src
,
593 const struct smb_filename
*smb_fname_dst
)
595 return glfs_rename(handle
->data
, smb_fname_src
->base_name
,
596 smb_fname_dst
->base_name
);
599 static int vfs_gluster_fsync(struct vfs_handle_struct
*handle
,
602 return glfs_fsync(glfd_fd_get(fsp
->fh
->fd
));
605 static struct tevent_req
*vfs_gluster_fsync_send(struct vfs_handle_struct
606 *handle
, TALLOC_CTX
*mem_ctx
,
607 struct tevent_context
*ev
,
614 static int vfs_gluster_fsync_recv(struct tevent_req
*req
, int *err
)
620 static int vfs_gluster_stat(struct vfs_handle_struct
*handle
,
621 struct smb_filename
*smb_fname
)
626 ret
= glfs_stat(handle
->data
, smb_fname
->base_name
, &st
);
628 smb_stat_ex_from_stat(&smb_fname
->st
, &st
);
630 if (ret
< 0 && errno
!= ENOENT
) {
631 DEBUG(0, ("glfs_stat(%s) failed: %s\n",
632 smb_fname
->base_name
, strerror(errno
)));
637 static int vfs_gluster_fstat(struct vfs_handle_struct
*handle
,
638 files_struct
*fsp
, SMB_STRUCT_STAT
*sbuf
)
643 ret
= glfs_fstat(glfd_fd_get(fsp
->fh
->fd
), &st
);
645 smb_stat_ex_from_stat(sbuf
, &st
);
648 DEBUG(0, ("glfs_fstat(%d) failed: %s\n",
649 fsp
->fh
->fd
, strerror(errno
)));
654 static int vfs_gluster_lstat(struct vfs_handle_struct
*handle
,
655 struct smb_filename
*smb_fname
)
660 ret
= glfs_lstat(handle
->data
, smb_fname
->base_name
, &st
);
662 smb_stat_ex_from_stat(&smb_fname
->st
, &st
);
664 if (ret
< 0 && errno
!= ENOENT
) {
665 DEBUG(0, ("glfs_lstat(%s) failed: %s\n",
666 smb_fname
->base_name
, strerror(errno
)));
671 static uint64_t vfs_gluster_get_alloc_size(struct vfs_handle_struct
*handle
,
673 const SMB_STRUCT_STAT
*sbuf
)
675 return sbuf
->st_ex_blocks
* 512;
678 static int vfs_gluster_unlink(struct vfs_handle_struct
*handle
,
679 const struct smb_filename
*smb_fname
)
681 return glfs_unlink(handle
->data
, smb_fname
->base_name
);
684 static int vfs_gluster_chmod(struct vfs_handle_struct
*handle
,
685 const char *path
, mode_t mode
)
687 return glfs_chmod(handle
->data
, path
, mode
);
690 static int vfs_gluster_fchmod(struct vfs_handle_struct
*handle
,
691 files_struct
*fsp
, mode_t mode
)
693 return glfs_fchmod(glfd_fd_get(fsp
->fh
->fd
), mode
);
696 static int vfs_gluster_chown(struct vfs_handle_struct
*handle
,
697 const char *path
, uid_t uid
, gid_t gid
)
699 return glfs_chown(handle
->data
, path
, uid
, gid
);
702 static int vfs_gluster_fchown(struct vfs_handle_struct
*handle
,
703 files_struct
*fsp
, uid_t uid
, gid_t gid
)
705 return glfs_fchown(glfd_fd_get(fsp
->fh
->fd
), uid
, gid
);
708 static int vfs_gluster_lchown(struct vfs_handle_struct
*handle
,
709 const char *path
, uid_t uid
, gid_t gid
)
711 return glfs_lchown(handle
->data
, path
, uid
, gid
);
714 static int vfs_gluster_chdir(struct vfs_handle_struct
*handle
, const char *path
)
716 return glfs_chdir(handle
->data
, path
);
719 static char *vfs_gluster_getwd(struct vfs_handle_struct
*handle
)
724 cwd
= SMB_CALLOC_ARRAY(char, PATH_MAX
);
729 ret
= glfs_getcwd(handle
->data
, cwd
, PATH_MAX
- 1);
736 static int vfs_gluster_ntimes(struct vfs_handle_struct
*handle
,
737 const struct smb_filename
*smb_fname
,
738 struct smb_file_time
*ft
)
740 struct timespec times
[2];
742 if (null_timespec(ft
->atime
)) {
743 times
[0].tv_sec
= smb_fname
->st
.st_ex_atime
.tv_sec
;
744 times
[0].tv_nsec
= smb_fname
->st
.st_ex_atime
.tv_nsec
;
746 times
[0].tv_sec
= ft
->atime
.tv_sec
;
747 times
[0].tv_nsec
= ft
->atime
.tv_nsec
;
750 if (null_timespec(ft
->mtime
)) {
751 times
[1].tv_sec
= smb_fname
->st
.st_ex_mtime
.tv_sec
;
752 times
[1].tv_nsec
= smb_fname
->st
.st_ex_mtime
.tv_nsec
;
754 times
[1].tv_sec
= ft
->mtime
.tv_sec
;
755 times
[1].tv_nsec
= ft
->mtime
.tv_nsec
;
758 if ((timespec_compare(×
[0],
759 &smb_fname
->st
.st_ex_atime
) == 0) &&
760 (timespec_compare(×
[1],
761 &smb_fname
->st
.st_ex_mtime
) == 0)) {
765 return glfs_utimens(handle
->data
, smb_fname
->base_name
, times
);
768 static int vfs_gluster_ftruncate(struct vfs_handle_struct
*handle
,
769 files_struct
*fsp
, off_t offset
)
771 return glfs_ftruncate(glfd_fd_get(fsp
->fh
->fd
), offset
);
774 static int vfs_gluster_fallocate(struct vfs_handle_struct
*handle
,
775 struct files_struct
*fsp
,
776 enum vfs_fallocate_mode mode
,
777 off_t offset
, off_t len
)
783 static char *vfs_gluster_realpath(struct vfs_handle_struct
*handle
,
786 return glfs_realpath(handle
->data
, path
, 0);
789 static bool vfs_gluster_lock(struct vfs_handle_struct
*handle
,
790 files_struct
*fsp
, int op
, off_t offset
,
791 off_t count
, int type
)
793 struct flock flock
= { 0, };
797 flock
.l_whence
= SEEK_SET
;
798 flock
.l_start
= offset
;
802 ret
= glfs_posix_lock(glfd_fd_get(fsp
->fh
->fd
), op
, &flock
);
805 /* lock query, true if someone else has locked */
807 (flock
.l_type
!= F_UNLCK
) &&
808 (flock
.l_pid
!= 0) && (flock
.l_pid
!= getpid()))
821 static int vfs_gluster_kernel_flock(struct vfs_handle_struct
*handle
,
822 files_struct
*fsp
, uint32 share_mode
,
823 uint32_t access_mask
)
829 static int vfs_gluster_linux_setlease(struct vfs_handle_struct
*handle
,
830 files_struct
*fsp
, int leasetype
)
836 static bool vfs_gluster_getlock(struct vfs_handle_struct
*handle
,
837 files_struct
*fsp
, off_t
*poffset
,
838 off_t
*pcount
, int *ptype
, pid_t
*ppid
)
840 struct flock flock
= { 0, };
843 flock
.l_type
= *ptype
;
844 flock
.l_whence
= SEEK_SET
;
845 flock
.l_start
= *poffset
;
846 flock
.l_len
= *pcount
;
849 ret
= glfs_posix_lock(glfd_fd_get(fsp
->fh
->fd
), F_GETLK
, &flock
);
855 *ptype
= flock
.l_type
;
856 *poffset
= flock
.l_start
;
857 *pcount
= flock
.l_len
;
863 static int vfs_gluster_symlink(struct vfs_handle_struct
*handle
,
864 const char *oldpath
, const char *newpath
)
866 return glfs_symlink(handle
->data
, oldpath
, newpath
);
869 static int vfs_gluster_readlink(struct vfs_handle_struct
*handle
,
870 const char *path
, char *buf
, size_t bufsiz
)
872 return glfs_readlink(handle
->data
, path
, buf
, bufsiz
);
875 static int vfs_gluster_link(struct vfs_handle_struct
*handle
,
876 const char *oldpath
, const char *newpath
)
878 return glfs_link(handle
->data
, oldpath
, newpath
);
881 static int vfs_gluster_mknod(struct vfs_handle_struct
*handle
, const char *path
,
882 mode_t mode
, SMB_DEV_T dev
)
884 return glfs_mknod(handle
->data
, path
, mode
, dev
);
887 static NTSTATUS
vfs_gluster_notify_watch(struct vfs_handle_struct
*handle
,
888 struct sys_notify_context
*ctx
,
889 const char *path
, uint32_t *filter
,
890 uint32_t *subdir_filter
,
891 void (*callback
) (struct sys_notify_context
*ctx
,
893 struct notify_event
*ev
),
894 void *private_data
, void *handle_p
)
896 return NT_STATUS_NOT_IMPLEMENTED
;
899 static int vfs_gluster_chflags(struct vfs_handle_struct
*handle
,
900 const char *path
, unsigned int flags
)
906 static int vfs_gluster_get_real_filename(struct vfs_handle_struct
*handle
,
907 const char *path
, const char *name
,
908 TALLOC_CTX
*mem_ctx
, char **found_name
)
911 char key_buf
[NAME_MAX
+ 64];
912 char val_buf
[NAME_MAX
+ 1];
914 if (strlen(name
) >= NAME_MAX
) {
915 errno
= ENAMETOOLONG
;
919 snprintf(key_buf
, NAME_MAX
+ 64,
920 "user.glusterfs.get_real_filename:%s", name
);
922 ret
= glfs_getxattr(handle
->data
, path
, key_buf
, val_buf
, NAME_MAX
+ 1);
924 if (errno
== ENODATA
) {
930 *found_name
= talloc_strdup(mem_ctx
, val_buf
);
931 if (found_name
[0] == NULL
) {
938 static const char *vfs_gluster_connectpath(struct vfs_handle_struct
*handle
,
939 const char *filename
)
941 return handle
->conn
->connectpath
;
946 static ssize_t
vfs_gluster_getxattr(struct vfs_handle_struct
*handle
,
947 const char *path
, const char *name
,
948 void *value
, size_t size
)
950 return glfs_getxattr(handle
->data
, path
, name
, value
, size
);
953 static ssize_t
vfs_gluster_fgetxattr(struct vfs_handle_struct
*handle
,
954 files_struct
*fsp
, const char *name
,
955 void *value
, size_t size
)
957 return glfs_fgetxattr(glfd_fd_get(fsp
->fh
->fd
), name
, value
, size
);
960 static ssize_t
vfs_gluster_listxattr(struct vfs_handle_struct
*handle
,
961 const char *path
, char *list
, size_t size
)
963 return glfs_listxattr(handle
->data
, path
, list
, size
);
966 static ssize_t
vfs_gluster_flistxattr(struct vfs_handle_struct
*handle
,
967 files_struct
*fsp
, char *list
,
970 return glfs_flistxattr(glfd_fd_get(fsp
->fh
->fd
), list
, size
);
973 static int vfs_gluster_removexattr(struct vfs_handle_struct
*handle
,
974 const char *path
, const char *name
)
976 return glfs_removexattr(handle
->data
, path
, name
);
979 static int vfs_gluster_fremovexattr(struct vfs_handle_struct
*handle
,
980 files_struct
*fsp
, const char *name
)
982 return glfs_fremovexattr(glfd_fd_get(fsp
->fh
->fd
), name
);
985 static int vfs_gluster_setxattr(struct vfs_handle_struct
*handle
,
986 const char *path
, const char *name
,
987 const void *value
, size_t size
, int flags
)
989 return glfs_setxattr(handle
->data
, path
, name
, value
, size
, flags
);
992 static int vfs_gluster_fsetxattr(struct vfs_handle_struct
*handle
,
993 files_struct
*fsp
, const char *name
,
994 const void *value
, size_t size
, int flags
)
996 return glfs_fsetxattr(glfd_fd_get(fsp
->fh
->fd
), name
, value
, size
,
1000 /* AIO Operations */
1002 static bool vfs_gluster_aio_force(struct vfs_handle_struct
*handle
,
1008 /* Offline Operations */
1010 static bool vfs_gluster_is_offline(struct vfs_handle_struct
*handle
,
1011 const struct smb_filename
*fname
,
1012 SMB_STRUCT_STAT
*sbuf
)
1017 static int vfs_gluster_set_offline(struct vfs_handle_struct
*handle
,
1018 const struct smb_filename
*fname
)
1027 Size = 4 (header) + N * 8 (entry)
1029 Offset Size Field (Little Endian)
1030 -------------------------------------
1033 4-5 2-byte Entry-1 tag
1034 6-7 2-byte Entry-1 perm
1035 8-11 4-byte Entry-1 id
1037 12-13 2-byte Entry-2 tag
1038 14-15 2-byte Entry-2 perm
1039 16-19 4-byte Entry-2 id
1045 /* header version */
1046 #define GLUSTER_ACL_VERSION 2
1049 #define GLUSTER_ACL_READ 0x04
1050 #define GLUSTER_ACL_WRITE 0x02
1051 #define GLUSTER_ACL_EXECUTE 0x01
1054 #define GLUSTER_ACL_UNDEFINED_TAG 0x00
1055 #define GLUSTER_ACL_USER_OBJ 0x01
1056 #define GLUSTER_ACL_USER 0x02
1057 #define GLUSTER_ACL_GROUP_OBJ 0x04
1058 #define GLUSTER_ACL_GROUP 0x08
1059 #define GLUSTER_ACL_MASK 0x10
1060 #define GLUSTER_ACL_OTHER 0x20
1062 #define GLUSTER_ACL_UNDEFINED_ID (-1)
1064 #define GLUSTER_ACL_HEADER_SIZE 4
1065 #define GLUSTER_ACL_ENTRY_SIZE 8
1067 static SMB_ACL_T
gluster_to_smb_acl(const char *buf
, size_t xattr_size
,
1068 TALLOC_CTX
*mem_ctx
)
1072 struct smb_acl_entry
*smb_ace
;
1073 struct smb_acl_t
*result
;
1082 if (size
< GLUSTER_ACL_HEADER_SIZE
) {
1083 /* ACL should be at least as big as the header (4 bytes) */
1088 size
-= GLUSTER_ACL_HEADER_SIZE
; /* size of header = 4 bytes */
1090 if (size
% GLUSTER_ACL_ENTRY_SIZE
) {
1091 /* Size of entries must strictly be a multiple of
1092 size of an ACE (8 bytes)
1098 count
= size
/ GLUSTER_ACL_ENTRY_SIZE
;
1100 /* Version is the first 4 bytes of the ACL */
1101 if (IVAL(buf
, 0) != GLUSTER_ACL_VERSION
) {
1102 DEBUG(0, ("Unknown gluster ACL version: %d\n",
1106 offset
= GLUSTER_ACL_HEADER_SIZE
;
1108 result
= sys_acl_init(mem_ctx
);
1114 result
->acl
= talloc_array(result
, struct smb_acl_entry
, count
);
1117 talloc_free(result
);
1121 result
->count
= count
;
1123 smb_ace
= result
->acl
;
1125 for (i
= 0; i
< count
; i
++) {
1126 /* TAG is the first 2 bytes of an entry */
1127 tag
= SVAL(buf
, offset
);
1130 /* PERM is the next 2 bytes of an entry */
1131 perm
= SVAL(buf
, offset
);
1134 /* ID is the last 4 bytes of an entry */
1135 id
= IVAL(buf
, offset
);
1139 case GLUSTER_ACL_USER
:
1140 smb_ace
->a_type
= SMB_ACL_USER
;
1142 case GLUSTER_ACL_USER_OBJ
:
1143 smb_ace
->a_type
= SMB_ACL_USER_OBJ
;
1145 case GLUSTER_ACL_GROUP
:
1146 smb_ace
->a_type
= SMB_ACL_GROUP
;
1148 case GLUSTER_ACL_GROUP_OBJ
:
1149 smb_ace
->a_type
= SMB_ACL_GROUP_OBJ
;
1151 case GLUSTER_ACL_OTHER
:
1152 smb_ace
->a_type
= SMB_ACL_OTHER
;
1154 case GLUSTER_ACL_MASK
:
1155 smb_ace
->a_type
= SMB_ACL_MASK
;
1158 DEBUG(0, ("unknown tag type %d\n", (unsigned int) tag
));
1163 switch(smb_ace
->a_type
) {
1165 smb_ace
->info
.user
.uid
= id
;
1168 smb_ace
->info
.group
.gid
= id
;
1174 smb_ace
->a_perm
= 0;
1176 ((perm
& GLUSTER_ACL_READ
) ? SMB_ACL_READ
: 0);
1178 ((perm
& GLUSTER_ACL_WRITE
) ? SMB_ACL_WRITE
: 0);
1180 ((perm
& GLUSTER_ACL_EXECUTE
) ? SMB_ACL_EXECUTE
: 0);
1189 static int gluster_ace_cmp(const void *left
, const void *right
)
1192 uint16_t tag_left
, tag_right
;
1193 uint32_t id_left
, id_right
;
1198 - Smaller TAG values must be earlier.
1200 - Within same TAG, smaller identifiers must be earlier, E.g:
1201 UID 0 entry must be earlier than UID 200
1202 GID 17 entry must be earlier than GID 19
1205 /* TAG is the first element in the entry */
1206 tag_left
= SVAL(left
, 0);
1207 tag_right
= SVAL(right
, 0);
1209 ret
= (tag_left
- tag_right
);
1211 /* ID is the third element in the entry, after two short
1212 integers (tag and perm), i.e at offset 4.
1214 id_left
= IVAL(left
, 4);
1215 id_right
= IVAL(right
, 4);
1216 ret
= id_left
- id_right
;
1223 static ssize_t
smb_to_gluster_acl(SMB_ACL_T theacl
, char *buf
, size_t len
)
1226 struct smb_acl_entry
*smb_ace
;
1234 count
= theacl
->count
;
1236 size
= GLUSTER_ACL_HEADER_SIZE
+ (count
* GLUSTER_ACL_ENTRY_SIZE
);
1246 smb_ace
= theacl
->acl
;
1248 /* Version is the first 4 bytes of the ACL */
1249 SIVAL(buf
, 0, GLUSTER_ACL_VERSION
);
1250 offset
= GLUSTER_ACL_HEADER_SIZE
;
1252 for (i
= 0; i
< count
; i
++) {
1254 switch(smb_ace
->a_type
) {
1256 tag
= GLUSTER_ACL_USER
;
1258 case SMB_ACL_USER_OBJ
:
1259 tag
= GLUSTER_ACL_USER_OBJ
;
1262 tag
= GLUSTER_ACL_GROUP
;
1264 case SMB_ACL_GROUP_OBJ
:
1265 tag
= GLUSTER_ACL_GROUP_OBJ
;
1268 tag
= GLUSTER_ACL_OTHER
;
1271 tag
= GLUSTER_ACL_MASK
;
1274 DEBUG(0, ("Unknown tag value %d\n",
1282 switch(smb_ace
->a_type
) {
1284 id
= smb_ace
->info
.user
.uid
;
1287 id
= smb_ace
->info
.group
.gid
;
1290 id
= GLUSTER_ACL_UNDEFINED_ID
;
1294 /* Calculate perm */
1298 ((smb_ace
->a_perm
& SMB_ACL_READ
) ? GLUSTER_ACL_READ
: 0);
1300 ((smb_ace
->a_perm
& SMB_ACL_WRITE
) ? GLUSTER_ACL_WRITE
: 0);
1302 ((smb_ace
->a_perm
& SMB_ACL_EXECUTE
) ? GLUSTER_ACL_EXECUTE
: 0);
1305 /* TAG is the first 2 bytes of an entry */
1306 SSVAL(buf
, offset
, tag
);
1309 /* PERM is the next 2 bytes of an entry */
1310 SSVAL(buf
, offset
, perm
);
1313 /* ID is the last 4 bytes of an entry */
1314 SIVAL(buf
, offset
, id
);
1320 /* Skip the header, sort @count number of 8-byte entries */
1321 qsort(buf
+GLUSTER_ACL_HEADER_SIZE
, count
, GLUSTER_ACL_ENTRY_SIZE
,
1328 static SMB_ACL_T
vfs_gluster_sys_acl_get_file(struct vfs_handle_struct
*handle
,
1330 SMB_ACL_TYPE_T type
,
1331 TALLOC_CTX
*mem_ctx
)
1333 struct smb_acl_t
*result
;
1339 case SMB_ACL_TYPE_ACCESS
:
1340 key
= "system.posix_acl_access";
1342 case SMB_ACL_TYPE_DEFAULT
:
1343 key
= "system.posix_acl_default";
1350 ret
= glfs_getxattr(handle
->data
, path_p
, key
, 0, 0);
1356 ret
= glfs_getxattr(handle
->data
, path_p
, key
, buf
, ret
);
1361 result
= gluster_to_smb_acl(buf
, ret
, mem_ctx
);
1366 static SMB_ACL_T
vfs_gluster_sys_acl_get_fd(struct vfs_handle_struct
*handle
,
1367 struct files_struct
*fsp
,
1368 TALLOC_CTX
*mem_ctx
)
1370 struct smb_acl_t
*result
;
1374 ret
= glfs_fgetxattr(glfd_fd_get(fsp
->fh
->fd
),
1375 "system.posix_acl_access", 0, 0);
1381 ret
= glfs_fgetxattr(glfd_fd_get(fsp
->fh
->fd
),
1382 "system.posix_acl_access", buf
, ret
);
1387 result
= gluster_to_smb_acl(buf
, ret
, mem_ctx
);
1392 static int vfs_gluster_sys_acl_set_file(struct vfs_handle_struct
*handle
,
1394 SMB_ACL_TYPE_T acltype
,
1403 case SMB_ACL_TYPE_ACCESS
:
1404 key
= "system.posix_acl_access";
1406 case SMB_ACL_TYPE_DEFAULT
:
1407 key
= "system.posix_acl_default";
1414 size
= smb_to_gluster_acl(theacl
, 0, 0);
1417 size
= smb_to_gluster_acl(theacl
, buf
, size
);
1422 ret
= glfs_setxattr(handle
->data
, name
, key
, buf
, size
, 0);
1427 static int vfs_gluster_sys_acl_set_fd(struct vfs_handle_struct
*handle
,
1428 struct files_struct
*fsp
,
1435 size
= smb_to_gluster_acl(theacl
, 0, 0);
1438 size
= smb_to_gluster_acl(theacl
, buf
, size
);
1443 ret
= glfs_fsetxattr(glfd_fd_get(fsp
->fh
->fd
),
1444 "system.posix_acl_access", buf
, size
, 0);
1448 static int vfs_gluster_sys_acl_delete_def_file(struct vfs_handle_struct
*handle
,
1451 return glfs_removexattr(handle
->data
, path
, "system.posix_acl_default");
1454 static struct vfs_fn_pointers glusterfs_fns
= {
1456 /* Disk Operations */
1458 .connect_fn
= vfs_gluster_connect
,
1459 .disconnect_fn
= vfs_gluster_disconnect
,
1460 .disk_free_fn
= vfs_gluster_disk_free
,
1461 .get_quota_fn
= vfs_gluster_get_quota
,
1462 .set_quota_fn
= vfs_gluster_set_quota
,
1463 .statvfs_fn
= vfs_gluster_statvfs
,
1464 .fs_capabilities_fn
= vfs_gluster_fs_capabilities
,
1466 .get_dfs_referrals_fn
= NULL
,
1468 /* Directory Operations */
1470 .opendir_fn
= vfs_gluster_opendir
,
1471 .fdopendir_fn
= vfs_gluster_fdopendir
,
1472 .readdir_fn
= vfs_gluster_readdir
,
1473 .seekdir_fn
= vfs_gluster_seekdir
,
1474 .telldir_fn
= vfs_gluster_telldir
,
1475 .rewind_dir_fn
= vfs_gluster_rewinddir
,
1476 .mkdir_fn
= vfs_gluster_mkdir
,
1477 .rmdir_fn
= vfs_gluster_rmdir
,
1478 .closedir_fn
= vfs_gluster_closedir
,
1479 .init_search_op_fn
= vfs_gluster_init_search_op
,
1481 /* File Operations */
1483 .open_fn
= vfs_gluster_open
,
1484 .create_file_fn
= NULL
,
1485 .close_fn
= vfs_gluster_close
,
1486 .read_fn
= vfs_gluster_read
,
1487 .pread_fn
= vfs_gluster_pread
,
1488 .pread_send_fn
= vfs_gluster_pread_send
,
1489 .pread_recv_fn
= vfs_gluster_pread_recv
,
1490 .write_fn
= vfs_gluster_write
,
1491 .pwrite_fn
= vfs_gluster_pwrite
,
1492 .pwrite_send_fn
= vfs_gluster_pwrite_send
,
1493 .pwrite_recv_fn
= vfs_gluster_pwrite_recv
,
1494 .lseek_fn
= vfs_gluster_lseek
,
1495 .sendfile_fn
= vfs_gluster_sendfile
,
1496 .recvfile_fn
= vfs_gluster_recvfile
,
1497 .rename_fn
= vfs_gluster_rename
,
1498 .fsync_fn
= vfs_gluster_fsync
,
1499 .fsync_send_fn
= vfs_gluster_fsync_send
,
1500 .fsync_recv_fn
= vfs_gluster_fsync_recv
,
1502 .stat_fn
= vfs_gluster_stat
,
1503 .fstat_fn
= vfs_gluster_fstat
,
1504 .lstat_fn
= vfs_gluster_lstat
,
1505 .get_alloc_size_fn
= vfs_gluster_get_alloc_size
,
1506 .unlink_fn
= vfs_gluster_unlink
,
1508 .chmod_fn
= vfs_gluster_chmod
,
1509 .fchmod_fn
= vfs_gluster_fchmod
,
1510 .chown_fn
= vfs_gluster_chown
,
1511 .fchown_fn
= vfs_gluster_fchown
,
1512 .lchown_fn
= vfs_gluster_lchown
,
1513 .chdir_fn
= vfs_gluster_chdir
,
1514 .getwd_fn
= vfs_gluster_getwd
,
1515 .ntimes_fn
= vfs_gluster_ntimes
,
1516 .ftruncate_fn
= vfs_gluster_ftruncate
,
1517 .fallocate_fn
= vfs_gluster_fallocate
,
1518 .lock_fn
= vfs_gluster_lock
,
1519 .kernel_flock_fn
= vfs_gluster_kernel_flock
,
1520 .linux_setlease_fn
= vfs_gluster_linux_setlease
,
1521 .getlock_fn
= vfs_gluster_getlock
,
1522 .symlink_fn
= vfs_gluster_symlink
,
1523 .readlink_fn
= vfs_gluster_readlink
,
1524 .link_fn
= vfs_gluster_link
,
1525 .mknod_fn
= vfs_gluster_mknod
,
1526 .realpath_fn
= vfs_gluster_realpath
,
1527 .notify_watch_fn
= vfs_gluster_notify_watch
,
1528 .chflags_fn
= vfs_gluster_chflags
,
1529 .file_id_create_fn
= NULL
,
1530 .copy_chunk_send_fn
= NULL
,
1531 .copy_chunk_recv_fn
= NULL
,
1532 .streaminfo_fn
= NULL
,
1533 .get_real_filename_fn
= vfs_gluster_get_real_filename
,
1534 .connectpath_fn
= vfs_gluster_connectpath
,
1536 .brl_lock_windows_fn
= NULL
,
1537 .brl_unlock_windows_fn
= NULL
,
1538 .brl_cancel_windows_fn
= NULL
,
1539 .strict_lock_fn
= NULL
,
1540 .strict_unlock_fn
= NULL
,
1541 .translate_name_fn
= NULL
,
1544 /* NT ACL Operations */
1545 .fget_nt_acl_fn
= NULL
,
1546 .get_nt_acl_fn
= NULL
,
1547 .fset_nt_acl_fn
= NULL
,
1548 .audit_file_fn
= NULL
,
1550 /* Posix ACL Operations */
1551 .chmod_acl_fn
= NULL
, /* passthrough to default */
1552 .fchmod_acl_fn
= NULL
, /* passthrough to default */
1553 .sys_acl_get_file_fn
= vfs_gluster_sys_acl_get_file
,
1554 .sys_acl_get_fd_fn
= vfs_gluster_sys_acl_get_fd
,
1555 .sys_acl_blob_get_file_fn
= posix_sys_acl_blob_get_file
,
1556 .sys_acl_blob_get_fd_fn
= posix_sys_acl_blob_get_fd
,
1557 .sys_acl_set_file_fn
= vfs_gluster_sys_acl_set_file
,
1558 .sys_acl_set_fd_fn
= vfs_gluster_sys_acl_set_fd
,
1559 .sys_acl_delete_def_file_fn
= vfs_gluster_sys_acl_delete_def_file
,
1562 .getxattr_fn
= vfs_gluster_getxattr
,
1563 .fgetxattr_fn
= vfs_gluster_fgetxattr
,
1564 .listxattr_fn
= vfs_gluster_listxattr
,
1565 .flistxattr_fn
= vfs_gluster_flistxattr
,
1566 .removexattr_fn
= vfs_gluster_removexattr
,
1567 .fremovexattr_fn
= vfs_gluster_fremovexattr
,
1568 .setxattr_fn
= vfs_gluster_setxattr
,
1569 .fsetxattr_fn
= vfs_gluster_fsetxattr
,
1571 /* AIO Operations */
1572 .aio_force_fn
= vfs_gluster_aio_force
,
1574 /* Offline Operations */
1575 .is_offline_fn
= vfs_gluster_is_offline
,
1576 .set_offline_fn
= vfs_gluster_set_offline
,
1578 /* Durable handle Operations */
1579 .durable_cookie_fn
= NULL
,
1580 .durable_disconnect_fn
= NULL
,
1581 .durable_reconnect_fn
= NULL
,
1584 NTSTATUS
vfs_glusterfs_init(void);
1585 NTSTATUS
vfs_glusterfs_init(void)
1587 return smb_register_vfs(SMB_VFS_INTERFACE_VERSION
,
1588 "glusterfs", &glusterfs_fns
);