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"
49 * Helper to convert struct stat to struct stat_ex.
51 static void smb_stat_ex_from_stat(struct stat_ex
*dst
, const struct stat
*src
)
55 dst
->st_ex_dev
= src
->st_dev
;
56 dst
->st_ex_ino
= src
->st_ino
;
57 dst
->st_ex_mode
= src
->st_mode
;
58 dst
->st_ex_nlink
= src
->st_nlink
;
59 dst
->st_ex_uid
= src
->st_uid
;
60 dst
->st_ex_gid
= src
->st_gid
;
61 dst
->st_ex_rdev
= src
->st_rdev
;
62 dst
->st_ex_size
= src
->st_size
;
63 dst
->st_ex_atime
.tv_sec
= src
->st_atime
;
64 dst
->st_ex_mtime
.tv_sec
= src
->st_mtime
;
65 dst
->st_ex_ctime
.tv_sec
= src
->st_ctime
;
66 dst
->st_ex_btime
.tv_sec
= src
->st_mtime
;
67 dst
->st_ex_blksize
= src
->st_blksize
;
68 dst
->st_ex_blocks
= src
->st_blocks
;
70 dst
->st_ex_atime
.tv_nsec
= src
->st_atime_nsec
;
71 dst
->st_ex_mtime
.tv_nsec
= src
->st_mtime_nsec
;
72 dst
->st_ex_ctime
.tv_nsec
= src
->st_ctime_nsec
;
73 dst
->st_ex_btime
.tv_nsec
= src
->st_mtime_nsec
;
77 /* pre-opened glfs_t */
79 static struct glfs_preopened
{
83 struct glfs_preopened
*next
, *prev
;
87 static int glfs_set_preopened(const char *volume
, glfs_t
*fs
)
89 struct glfs_preopened
*entry
= NULL
;
91 entry
= talloc_zero(NULL
, struct glfs_preopened
);
97 entry
->volume
= talloc_strdup(entry
, volume
);
107 DLIST_ADD(glfs_preopened
, entry
);
112 static glfs_t
*glfs_find_preopened(const char *volume
)
114 struct glfs_preopened
*entry
= NULL
;
116 for (entry
= glfs_preopened
; entry
; entry
= entry
->next
) {
117 if (strcmp(entry
->volume
, volume
) == 0) {
126 static void glfs_clear_preopened(glfs_t
*fs
)
128 struct glfs_preopened
*entry
= NULL
;
130 for (entry
= glfs_preopened
; entry
; entry
= entry
->next
) {
131 if (entry
->fs
== fs
) {
135 DLIST_REMOVE(glfs_preopened
, entry
);
137 glfs_fini(entry
->fs
);
143 /* Disk Operations */
145 static int vfs_gluster_connect(struct vfs_handle_struct
*handle
,
149 const char *volfile_server
;
157 tmp_ctx
= talloc_new(NULL
);
158 if (tmp_ctx
== NULL
) {
162 logfile
= lp_parm_talloc_string(tmp_ctx
, SNUM(handle
->conn
), "glusterfs",
165 loglevel
= lp_parm_int(SNUM(handle
->conn
), "glusterfs", "loglevel", -1);
167 volfile_server
= lp_parm_const_string(SNUM(handle
->conn
), "glusterfs",
168 "volfile_server", NULL
);
169 if (volfile_server
== NULL
) {
170 volfile_server
= DEFAULT_VOLFILE_SERVER
;
173 volume
= lp_parm_const_string(SNUM(handle
->conn
), "glusterfs", "volume",
175 if (volume
== NULL
) {
179 fs
= glfs_find_preopened(volume
);
184 fs
= glfs_new(volume
);
190 ret
= glfs_set_volfile_server(fs
, "tcp", volfile_server
, 0);
192 DEBUG(0, ("Failed to set volfile_server %s\n", volfile_server
));
196 ret
= glfs_set_xlator_option(fs
, "*-md-cache", "cache-posix-acl",
199 DEBUG(0, ("%s: Failed to set xlator options\n", volume
));
203 ret
= glfs_set_logging(fs
, logfile
, loglevel
);
205 DEBUG(0, ("%s: Failed to set logfile %s loglevel %d\n",
206 volume
, logfile
, loglevel
));
212 DEBUG(0, ("%s: Failed to initialize volume (%s)\n",
213 volume
, strerror(errno
)));
217 ret
= glfs_set_preopened(volume
, fs
);
219 DEBUG(0, ("%s: Failed to register volume (%s)\n",
220 volume
, strerror(errno
)));
224 talloc_free(tmp_ctx
);
230 DEBUG(0, ("%s: Initialized volume from server %s\n",
231 volume
, volfile_server
));
237 static void vfs_gluster_disconnect(struct vfs_handle_struct
*handle
)
243 glfs_clear_preopened(fs
);
246 static uint64_t vfs_gluster_disk_free(struct vfs_handle_struct
*handle
,
247 const char *path
, bool small_query
,
248 uint64_t *bsize_p
, uint64_t *dfree_p
,
251 struct statvfs statvfs
= { 0, };
254 ret
= glfs_statvfs(handle
->data
, path
, &statvfs
);
259 if (bsize_p
!= NULL
) {
260 *bsize_p
= (uint64_t)statvfs
.f_bsize
; /* Block size */
262 if (dfree_p
!= NULL
) {
263 *dfree_p
= (uint64_t)statvfs
.f_bavail
; /* Available Block units */
265 if (dsize_p
!= NULL
) {
266 *dsize_p
= (uint64_t)statvfs
.f_blocks
; /* Total Block units */
269 return (uint64_t)statvfs
.f_bavail
;
272 static int vfs_gluster_get_quota(struct vfs_handle_struct
*handle
,
273 enum SMB_QUOTA_TYPE qtype
, unid_t id
,
281 vfs_gluster_set_quota(struct vfs_handle_struct
*handle
,
282 enum SMB_QUOTA_TYPE qtype
, unid_t id
, SMB_DISK_QUOTA
*qt
)
288 static int vfs_gluster_statvfs(struct vfs_handle_struct
*handle
,
290 struct vfs_statvfs_struct
*vfs_statvfs
)
292 struct statvfs statvfs
= { 0, };
295 ret
= glfs_statvfs(handle
->data
, path
, &statvfs
);
297 DEBUG(0, ("glfs_statvfs(%s) failed: %s\n",
298 path
, strerror(errno
)));
302 ZERO_STRUCTP(vfs_statvfs
);
304 vfs_statvfs
->OptimalTransferSize
= statvfs
.f_frsize
;
305 vfs_statvfs
->BlockSize
= statvfs
.f_bsize
;
306 vfs_statvfs
->TotalBlocks
= statvfs
.f_blocks
;
307 vfs_statvfs
->BlocksAvail
= statvfs
.f_bfree
;
308 vfs_statvfs
->UserBlocksAvail
= statvfs
.f_bavail
;
309 vfs_statvfs
->TotalFileNodes
= statvfs
.f_files
;
310 vfs_statvfs
->FreeFileNodes
= statvfs
.f_ffree
;
311 vfs_statvfs
->FsIdentifier
= statvfs
.f_fsid
;
312 vfs_statvfs
->FsCapabilities
=
313 FILE_CASE_SENSITIVE_SEARCH
| FILE_CASE_PRESERVED_NAMES
;
318 static uint32_t vfs_gluster_fs_capabilities(struct vfs_handle_struct
*handle
,
319 enum timestamp_set_resolution
*p_ts_res
)
321 uint32_t caps
= FILE_CASE_SENSITIVE_SEARCH
| FILE_CASE_PRESERVED_NAMES
;
323 #ifdef STAT_HAVE_NSEC
324 *p_ts_res
= TIMESTAMP_SET_NT_OR_BETTER
;
330 static DIR *vfs_gluster_opendir(struct vfs_handle_struct
*handle
,
331 const char *path
, const char *mask
,
336 fd
= glfs_opendir(handle
->data
, path
);
338 DEBUG(0, ("glfs_opendir(%s) failed: %s\n",
339 path
, strerror(errno
)));
345 static DIR *vfs_gluster_fdopendir(struct vfs_handle_struct
*handle
,
346 files_struct
*fsp
, const char *mask
,
349 return (DIR *) *(glfs_fd_t
**)VFS_FETCH_FSP_EXTENSION(handle
, fsp
);
352 static int vfs_gluster_closedir(struct vfs_handle_struct
*handle
, DIR *dirp
)
354 return glfs_closedir((void *)dirp
);
357 static struct dirent
*vfs_gluster_readdir(struct vfs_handle_struct
*handle
,
358 DIR *dirp
, SMB_STRUCT_STAT
*sbuf
)
360 static char direntbuf
[512];
363 struct dirent
*dirent
= 0;
366 ret
= glfs_readdirplus_r((void *)dirp
, &stat
, (void *)direntbuf
,
369 ret
= glfs_readdir_r((void *)dirp
, (void *)direntbuf
, &dirent
);
372 if ((ret
< 0) || (dirent
== NULL
)) {
377 smb_stat_ex_from_stat(sbuf
, &stat
);
383 static long vfs_gluster_telldir(struct vfs_handle_struct
*handle
, DIR *dirp
)
385 return glfs_telldir((void *)dirp
);
388 static void vfs_gluster_seekdir(struct vfs_handle_struct
*handle
, DIR *dirp
,
391 glfs_seekdir((void *)dirp
, offset
);
394 static void vfs_gluster_rewinddir(struct vfs_handle_struct
*handle
, DIR *dirp
)
396 glfs_seekdir((void *)dirp
, 0);
399 static void vfs_gluster_init_search_op(struct vfs_handle_struct
*handle
,
405 static int vfs_gluster_mkdir(struct vfs_handle_struct
*handle
, const char *path
,
408 return glfs_mkdir(handle
->data
, path
, mode
);
411 static int vfs_gluster_rmdir(struct vfs_handle_struct
*handle
, const char *path
)
413 return glfs_rmdir(handle
->data
, path
);
416 static int vfs_gluster_open(struct vfs_handle_struct
*handle
,
417 struct smb_filename
*smb_fname
, files_struct
*fsp
,
418 int flags
, mode_t mode
)
423 if (flags
& O_DIRECTORY
) {
424 glfd
= glfs_opendir(handle
->data
, smb_fname
->base_name
);
425 } else if (flags
& O_CREAT
) {
426 glfd
= glfs_creat(handle
->data
, smb_fname
->base_name
, flags
,
429 glfd
= glfs_open(handle
->data
, smb_fname
->base_name
, flags
);
435 p_tmp
= (glfs_fd_t
**)VFS_ADD_FSP_EXTENSION(handle
, fsp
,
438 /* An arbitrary value for error reporting, so you know its us. */
442 static int vfs_gluster_close(struct vfs_handle_struct
*handle
,
446 glfd
= *(glfs_fd_t
**)VFS_FETCH_FSP_EXTENSION(handle
, fsp
);
447 VFS_REMOVE_FSP_EXTENSION(handle
, fsp
);
448 return glfs_close(glfd
);
451 static ssize_t
vfs_gluster_read(struct vfs_handle_struct
*handle
,
452 files_struct
*fsp
, void *data
, size_t n
)
454 return glfs_read(*(glfs_fd_t
**)VFS_FETCH_FSP_EXTENSION(handle
, fsp
), data
, n
, 0);
457 static ssize_t
vfs_gluster_pread(struct vfs_handle_struct
*handle
,
458 files_struct
*fsp
, void *data
, size_t n
,
461 return glfs_pread(*(glfs_fd_t
**)VFS_FETCH_FSP_EXTENSION(handle
, fsp
), data
, n
, offset
, 0);
464 static struct tevent_req
*vfs_gluster_pread_send(struct vfs_handle_struct
465 *handle
, TALLOC_CTX
*mem_ctx
,
466 struct tevent_context
*ev
,
467 files_struct
*fsp
, void *data
,
468 size_t n
, off_t offset
)
474 static ssize_t
vfs_gluster_pread_recv(struct tevent_req
*req
, int *err
)
480 static ssize_t
vfs_gluster_write(struct vfs_handle_struct
*handle
,
481 files_struct
*fsp
, const void *data
, size_t n
)
483 return glfs_write(*(glfs_fd_t
**)VFS_FETCH_FSP_EXTENSION(handle
, fsp
), data
, n
, 0);
486 static ssize_t
vfs_gluster_pwrite(struct vfs_handle_struct
*handle
,
487 files_struct
*fsp
, const void *data
,
488 size_t n
, off_t offset
)
490 return glfs_pwrite(*(glfs_fd_t
**)VFS_FETCH_FSP_EXTENSION(handle
, fsp
), data
, n
, offset
, 0);
493 static struct tevent_req
*vfs_gluster_pwrite_send(struct vfs_handle_struct
494 *handle
, TALLOC_CTX
*mem_ctx
,
495 struct tevent_context
*ev
,
497 const void *data
, size_t n
,
504 static ssize_t
vfs_gluster_pwrite_recv(struct tevent_req
*req
, int *err
)
510 static off_t
vfs_gluster_lseek(struct vfs_handle_struct
*handle
,
511 files_struct
*fsp
, off_t offset
, int whence
)
513 return glfs_lseek(*(glfs_fd_t
**)VFS_FETCH_FSP_EXTENSION(handle
, fsp
), offset
, whence
);
516 static ssize_t
vfs_gluster_sendfile(struct vfs_handle_struct
*handle
, int tofd
,
517 files_struct
*fromfsp
,
518 const DATA_BLOB
*hdr
,
519 off_t offset
, size_t n
)
525 static ssize_t
vfs_gluster_recvfile(struct vfs_handle_struct
*handle
,
526 int fromfd
, files_struct
*tofsp
,
527 off_t offset
, size_t n
)
533 static int vfs_gluster_rename(struct vfs_handle_struct
*handle
,
534 const struct smb_filename
*smb_fname_src
,
535 const struct smb_filename
*smb_fname_dst
)
537 return glfs_rename(handle
->data
, smb_fname_src
->base_name
,
538 smb_fname_dst
->base_name
);
541 static int vfs_gluster_fsync(struct vfs_handle_struct
*handle
,
544 return glfs_fsync(*(glfs_fd_t
**)VFS_FETCH_FSP_EXTENSION(handle
, fsp
));
547 static struct tevent_req
*vfs_gluster_fsync_send(struct vfs_handle_struct
548 *handle
, TALLOC_CTX
*mem_ctx
,
549 struct tevent_context
*ev
,
556 static int vfs_gluster_fsync_recv(struct tevent_req
*req
, int *err
)
562 static int vfs_gluster_stat(struct vfs_handle_struct
*handle
,
563 struct smb_filename
*smb_fname
)
568 ret
= glfs_stat(handle
->data
, smb_fname
->base_name
, &st
);
570 smb_stat_ex_from_stat(&smb_fname
->st
, &st
);
572 if (ret
< 0 && errno
!= ENOENT
) {
573 DEBUG(0, ("glfs_stat(%s) failed: %s\n",
574 smb_fname
->base_name
, strerror(errno
)));
579 static int vfs_gluster_fstat(struct vfs_handle_struct
*handle
,
580 files_struct
*fsp
, SMB_STRUCT_STAT
*sbuf
)
585 ret
= glfs_fstat(*(glfs_fd_t
**)VFS_FETCH_FSP_EXTENSION(handle
, fsp
), &st
);
587 smb_stat_ex_from_stat(sbuf
, &st
);
590 DEBUG(0, ("glfs_fstat(%d) failed: %s\n",
591 fsp
->fh
->fd
, strerror(errno
)));
596 static int vfs_gluster_lstat(struct vfs_handle_struct
*handle
,
597 struct smb_filename
*smb_fname
)
602 ret
= glfs_lstat(handle
->data
, smb_fname
->base_name
, &st
);
604 smb_stat_ex_from_stat(&smb_fname
->st
, &st
);
606 if (ret
< 0 && errno
!= ENOENT
) {
607 DEBUG(0, ("glfs_lstat(%s) failed: %s\n",
608 smb_fname
->base_name
, strerror(errno
)));
613 static uint64_t vfs_gluster_get_alloc_size(struct vfs_handle_struct
*handle
,
615 const SMB_STRUCT_STAT
*sbuf
)
617 return sbuf
->st_ex_blocks
* 512;
620 static int vfs_gluster_unlink(struct vfs_handle_struct
*handle
,
621 const struct smb_filename
*smb_fname
)
623 return glfs_unlink(handle
->data
, smb_fname
->base_name
);
626 static int vfs_gluster_chmod(struct vfs_handle_struct
*handle
,
627 const char *path
, mode_t mode
)
629 return glfs_chmod(handle
->data
, path
, mode
);
632 static int vfs_gluster_fchmod(struct vfs_handle_struct
*handle
,
633 files_struct
*fsp
, mode_t mode
)
635 return glfs_fchmod(*(glfs_fd_t
**)VFS_FETCH_FSP_EXTENSION(handle
, fsp
), mode
);
638 static int vfs_gluster_chown(struct vfs_handle_struct
*handle
,
639 const char *path
, uid_t uid
, gid_t gid
)
641 return glfs_chown(handle
->data
, path
, uid
, gid
);
644 static int vfs_gluster_fchown(struct vfs_handle_struct
*handle
,
645 files_struct
*fsp
, uid_t uid
, gid_t gid
)
647 return glfs_fchown(*(glfs_fd_t
**)VFS_FETCH_FSP_EXTENSION(handle
, fsp
), uid
, gid
);
650 static int vfs_gluster_lchown(struct vfs_handle_struct
*handle
,
651 const char *path
, uid_t uid
, gid_t gid
)
653 return glfs_lchown(handle
->data
, path
, uid
, gid
);
656 static int vfs_gluster_chdir(struct vfs_handle_struct
*handle
, const char *path
)
658 return glfs_chdir(handle
->data
, path
);
661 static char *vfs_gluster_getwd(struct vfs_handle_struct
*handle
)
666 cwd
= SMB_CALLOC_ARRAY(char, PATH_MAX
);
671 ret
= glfs_getcwd(handle
->data
, cwd
, PATH_MAX
- 1);
678 static int vfs_gluster_ntimes(struct vfs_handle_struct
*handle
,
679 const struct smb_filename
*smb_fname
,
680 struct smb_file_time
*ft
)
682 struct timespec times
[2];
684 if (null_timespec(ft
->atime
)) {
685 times
[0].tv_sec
= smb_fname
->st
.st_ex_atime
.tv_sec
;
686 times
[0].tv_nsec
= smb_fname
->st
.st_ex_atime
.tv_nsec
;
688 times
[0].tv_sec
= ft
->atime
.tv_sec
;
689 times
[0].tv_nsec
= ft
->atime
.tv_nsec
;
692 if (null_timespec(ft
->mtime
)) {
693 times
[1].tv_sec
= smb_fname
->st
.st_ex_mtime
.tv_sec
;
694 times
[1].tv_nsec
= smb_fname
->st
.st_ex_mtime
.tv_nsec
;
696 times
[1].tv_sec
= ft
->mtime
.tv_sec
;
697 times
[1].tv_nsec
= ft
->mtime
.tv_nsec
;
700 if ((timespec_compare(×
[0],
701 &smb_fname
->st
.st_ex_atime
) == 0) &&
702 (timespec_compare(×
[1],
703 &smb_fname
->st
.st_ex_mtime
) == 0)) {
707 return glfs_utimens(handle
->data
, smb_fname
->base_name
, times
);
710 static int vfs_gluster_ftruncate(struct vfs_handle_struct
*handle
,
711 files_struct
*fsp
, off_t offset
)
713 return glfs_ftruncate(*(glfs_fd_t
**)VFS_FETCH_FSP_EXTENSION(handle
, fsp
), offset
);
716 static int vfs_gluster_fallocate(struct vfs_handle_struct
*handle
,
717 struct files_struct
*fsp
,
718 enum vfs_fallocate_mode mode
,
719 off_t offset
, off_t len
)
725 static char *vfs_gluster_realpath(struct vfs_handle_struct
*handle
,
728 return glfs_realpath(handle
->data
, path
, 0);
731 static bool vfs_gluster_lock(struct vfs_handle_struct
*handle
,
732 files_struct
*fsp
, int op
, off_t offset
,
733 off_t count
, int type
)
735 struct flock flock
= { 0, };
739 flock
.l_whence
= SEEK_SET
;
740 flock
.l_start
= offset
;
744 ret
= glfs_posix_lock(*(glfs_fd_t
**)VFS_FETCH_FSP_EXTENSION(handle
, fsp
), op
, &flock
);
747 /* lock query, true if someone else has locked */
749 (flock
.l_type
!= F_UNLCK
) &&
750 (flock
.l_pid
!= 0) && (flock
.l_pid
!= getpid()))
763 static int vfs_gluster_kernel_flock(struct vfs_handle_struct
*handle
,
764 files_struct
*fsp
, uint32 share_mode
,
765 uint32_t access_mask
)
771 static int vfs_gluster_linux_setlease(struct vfs_handle_struct
*handle
,
772 files_struct
*fsp
, int leasetype
)
778 static bool vfs_gluster_getlock(struct vfs_handle_struct
*handle
,
779 files_struct
*fsp
, off_t
*poffset
,
780 off_t
*pcount
, int *ptype
, pid_t
*ppid
)
782 struct flock flock
= { 0, };
785 flock
.l_type
= *ptype
;
786 flock
.l_whence
= SEEK_SET
;
787 flock
.l_start
= *poffset
;
788 flock
.l_len
= *pcount
;
791 ret
= glfs_posix_lock(*(glfs_fd_t
**)VFS_FETCH_FSP_EXTENSION(handle
, fsp
), F_GETLK
, &flock
);
797 *ptype
= flock
.l_type
;
798 *poffset
= flock
.l_start
;
799 *pcount
= flock
.l_len
;
805 static int vfs_gluster_symlink(struct vfs_handle_struct
*handle
,
806 const char *oldpath
, const char *newpath
)
808 return glfs_symlink(handle
->data
, oldpath
, newpath
);
811 static int vfs_gluster_readlink(struct vfs_handle_struct
*handle
,
812 const char *path
, char *buf
, size_t bufsiz
)
814 return glfs_readlink(handle
->data
, path
, buf
, bufsiz
);
817 static int vfs_gluster_link(struct vfs_handle_struct
*handle
,
818 const char *oldpath
, const char *newpath
)
820 return glfs_link(handle
->data
, oldpath
, newpath
);
823 static int vfs_gluster_mknod(struct vfs_handle_struct
*handle
, const char *path
,
824 mode_t mode
, SMB_DEV_T dev
)
826 return glfs_mknod(handle
->data
, path
, mode
, dev
);
829 static NTSTATUS
vfs_gluster_notify_watch(struct vfs_handle_struct
*handle
,
830 struct sys_notify_context
*ctx
,
831 const char *path
, uint32_t *filter
,
832 uint32_t *subdir_filter
,
833 void (*callback
) (struct sys_notify_context
*ctx
,
835 struct notify_event
*ev
),
836 void *private_data
, void *handle_p
)
838 return NT_STATUS_NOT_IMPLEMENTED
;
841 static int vfs_gluster_chflags(struct vfs_handle_struct
*handle
,
842 const char *path
, unsigned int flags
)
848 static int vfs_gluster_get_real_filename(struct vfs_handle_struct
*handle
,
849 const char *path
, const char *name
,
850 TALLOC_CTX
*mem_ctx
, char **found_name
)
853 char key_buf
[NAME_MAX
+ 64];
854 char val_buf
[NAME_MAX
+ 1];
856 if (strlen(name
) >= NAME_MAX
) {
857 errno
= ENAMETOOLONG
;
861 snprintf(key_buf
, NAME_MAX
+ 64,
862 "user.glusterfs.get_real_filename:%s", name
);
864 ret
= glfs_getxattr(handle
->data
, path
, key_buf
, val_buf
, NAME_MAX
+ 1);
866 if (errno
== ENODATA
) {
872 *found_name
= talloc_strdup(mem_ctx
, val_buf
);
873 if (found_name
[0] == NULL
) {
880 static const char *vfs_gluster_connectpath(struct vfs_handle_struct
*handle
,
881 const char *filename
)
883 return handle
->conn
->connectpath
;
888 static ssize_t
vfs_gluster_getxattr(struct vfs_handle_struct
*handle
,
889 const char *path
, const char *name
,
890 void *value
, size_t size
)
892 return glfs_getxattr(handle
->data
, path
, name
, value
, size
);
895 static ssize_t
vfs_gluster_fgetxattr(struct vfs_handle_struct
*handle
,
896 files_struct
*fsp
, const char *name
,
897 void *value
, size_t size
)
899 return glfs_fgetxattr(*(glfs_fd_t
**)VFS_FETCH_FSP_EXTENSION(handle
, fsp
), name
, value
, size
);
902 static ssize_t
vfs_gluster_listxattr(struct vfs_handle_struct
*handle
,
903 const char *path
, char *list
, size_t size
)
905 return glfs_listxattr(handle
->data
, path
, list
, size
);
908 static ssize_t
vfs_gluster_flistxattr(struct vfs_handle_struct
*handle
,
909 files_struct
*fsp
, char *list
,
912 return glfs_flistxattr(*(glfs_fd_t
**)VFS_FETCH_FSP_EXTENSION(handle
, fsp
), list
, size
);
915 static int vfs_gluster_removexattr(struct vfs_handle_struct
*handle
,
916 const char *path
, const char *name
)
918 return glfs_removexattr(handle
->data
, path
, name
);
921 static int vfs_gluster_fremovexattr(struct vfs_handle_struct
*handle
,
922 files_struct
*fsp
, const char *name
)
924 return glfs_fremovexattr(*(glfs_fd_t
**)VFS_FETCH_FSP_EXTENSION(handle
, fsp
), name
);
927 static int vfs_gluster_setxattr(struct vfs_handle_struct
*handle
,
928 const char *path
, const char *name
,
929 const void *value
, size_t size
, int flags
)
931 return glfs_setxattr(handle
->data
, path
, name
, value
, size
, flags
);
934 static int vfs_gluster_fsetxattr(struct vfs_handle_struct
*handle
,
935 files_struct
*fsp
, const char *name
,
936 const void *value
, size_t size
, int flags
)
938 return glfs_fsetxattr(*(glfs_fd_t
**)VFS_FETCH_FSP_EXTENSION(handle
, fsp
), name
, value
, size
,
944 static bool vfs_gluster_aio_force(struct vfs_handle_struct
*handle
,
950 /* Offline Operations */
952 static bool vfs_gluster_is_offline(struct vfs_handle_struct
*handle
,
953 const struct smb_filename
*fname
,
954 SMB_STRUCT_STAT
*sbuf
)
959 static int vfs_gluster_set_offline(struct vfs_handle_struct
*handle
,
960 const struct smb_filename
*fname
)
969 Size = 4 (header) + N * 8 (entry)
971 Offset Size Field (Little Endian)
972 -------------------------------------
975 4-5 2-byte Entry-1 tag
976 6-7 2-byte Entry-1 perm
977 8-11 4-byte Entry-1 id
979 12-13 2-byte Entry-2 tag
980 14-15 2-byte Entry-2 perm
981 16-19 4-byte Entry-2 id
988 #define GLUSTER_ACL_VERSION 2
991 #define GLUSTER_ACL_READ 0x04
992 #define GLUSTER_ACL_WRITE 0x02
993 #define GLUSTER_ACL_EXECUTE 0x01
996 #define GLUSTER_ACL_UNDEFINED_TAG 0x00
997 #define GLUSTER_ACL_USER_OBJ 0x01
998 #define GLUSTER_ACL_USER 0x02
999 #define GLUSTER_ACL_GROUP_OBJ 0x04
1000 #define GLUSTER_ACL_GROUP 0x08
1001 #define GLUSTER_ACL_MASK 0x10
1002 #define GLUSTER_ACL_OTHER 0x20
1004 #define GLUSTER_ACL_UNDEFINED_ID (-1)
1006 #define GLUSTER_ACL_HEADER_SIZE 4
1007 #define GLUSTER_ACL_ENTRY_SIZE 8
1009 static SMB_ACL_T
gluster_to_smb_acl(const char *buf
, size_t xattr_size
,
1010 TALLOC_CTX
*mem_ctx
)
1014 struct smb_acl_entry
*smb_ace
;
1015 struct smb_acl_t
*result
;
1024 if (size
< GLUSTER_ACL_HEADER_SIZE
) {
1025 /* ACL should be at least as big as the header (4 bytes) */
1030 size
-= GLUSTER_ACL_HEADER_SIZE
; /* size of header = 4 bytes */
1032 if (size
% GLUSTER_ACL_ENTRY_SIZE
) {
1033 /* Size of entries must strictly be a multiple of
1034 size of an ACE (8 bytes)
1040 count
= size
/ GLUSTER_ACL_ENTRY_SIZE
;
1042 /* Version is the first 4 bytes of the ACL */
1043 if (IVAL(buf
, 0) != GLUSTER_ACL_VERSION
) {
1044 DEBUG(0, ("Unknown gluster ACL version: %d\n",
1048 offset
= GLUSTER_ACL_HEADER_SIZE
;
1050 result
= sys_acl_init(mem_ctx
);
1056 result
->acl
= talloc_array(result
, struct smb_acl_entry
, count
);
1059 talloc_free(result
);
1063 result
->count
= count
;
1065 smb_ace
= result
->acl
;
1067 for (i
= 0; i
< count
; i
++) {
1068 /* TAG is the first 2 bytes of an entry */
1069 tag
= SVAL(buf
, offset
);
1072 /* PERM is the next 2 bytes of an entry */
1073 perm
= SVAL(buf
, offset
);
1076 /* ID is the last 4 bytes of an entry */
1077 id
= IVAL(buf
, offset
);
1081 case GLUSTER_ACL_USER
:
1082 smb_ace
->a_type
= SMB_ACL_USER
;
1084 case GLUSTER_ACL_USER_OBJ
:
1085 smb_ace
->a_type
= SMB_ACL_USER_OBJ
;
1087 case GLUSTER_ACL_GROUP
:
1088 smb_ace
->a_type
= SMB_ACL_GROUP
;
1090 case GLUSTER_ACL_GROUP_OBJ
:
1091 smb_ace
->a_type
= SMB_ACL_GROUP_OBJ
;
1093 case GLUSTER_ACL_OTHER
:
1094 smb_ace
->a_type
= SMB_ACL_OTHER
;
1096 case GLUSTER_ACL_MASK
:
1097 smb_ace
->a_type
= SMB_ACL_MASK
;
1100 DEBUG(0, ("unknown tag type %d\n", (unsigned int) tag
));
1105 switch(smb_ace
->a_type
) {
1107 smb_ace
->info
.user
.uid
= id
;
1110 smb_ace
->info
.group
.gid
= id
;
1116 smb_ace
->a_perm
= 0;
1118 ((perm
& GLUSTER_ACL_READ
) ? SMB_ACL_READ
: 0);
1120 ((perm
& GLUSTER_ACL_WRITE
) ? SMB_ACL_WRITE
: 0);
1122 ((perm
& GLUSTER_ACL_EXECUTE
) ? SMB_ACL_EXECUTE
: 0);
1131 static int gluster_ace_cmp(const void *left
, const void *right
)
1134 uint16_t tag_left
, tag_right
;
1135 uint32_t id_left
, id_right
;
1140 - Smaller TAG values must be earlier.
1142 - Within same TAG, smaller identifiers must be earlier, E.g:
1143 UID 0 entry must be earlier than UID 200
1144 GID 17 entry must be earlier than GID 19
1147 /* TAG is the first element in the entry */
1148 tag_left
= SVAL(left
, 0);
1149 tag_right
= SVAL(right
, 0);
1151 ret
= (tag_left
- tag_right
);
1153 /* ID is the third element in the entry, after two short
1154 integers (tag and perm), i.e at offset 4.
1156 id_left
= IVAL(left
, 4);
1157 id_right
= IVAL(right
, 4);
1158 ret
= id_left
- id_right
;
1165 static ssize_t
smb_to_gluster_acl(SMB_ACL_T theacl
, char *buf
, size_t len
)
1168 struct smb_acl_entry
*smb_ace
;
1176 count
= theacl
->count
;
1178 size
= GLUSTER_ACL_HEADER_SIZE
+ (count
* GLUSTER_ACL_ENTRY_SIZE
);
1188 smb_ace
= theacl
->acl
;
1190 /* Version is the first 4 bytes of the ACL */
1191 SIVAL(buf
, 0, GLUSTER_ACL_VERSION
);
1192 offset
= GLUSTER_ACL_HEADER_SIZE
;
1194 for (i
= 0; i
< count
; i
++) {
1196 switch(smb_ace
->a_type
) {
1198 tag
= GLUSTER_ACL_USER
;
1200 case SMB_ACL_USER_OBJ
:
1201 tag
= GLUSTER_ACL_USER_OBJ
;
1204 tag
= GLUSTER_ACL_GROUP
;
1206 case SMB_ACL_GROUP_OBJ
:
1207 tag
= GLUSTER_ACL_GROUP_OBJ
;
1210 tag
= GLUSTER_ACL_OTHER
;
1213 tag
= GLUSTER_ACL_MASK
;
1216 DEBUG(0, ("Unknown tag value %d\n",
1224 switch(smb_ace
->a_type
) {
1226 id
= smb_ace
->info
.user
.uid
;
1229 id
= smb_ace
->info
.group
.gid
;
1232 id
= GLUSTER_ACL_UNDEFINED_ID
;
1236 /* Calculate perm */
1240 ((smb_ace
->a_perm
& SMB_ACL_READ
) ? GLUSTER_ACL_READ
: 0);
1242 ((smb_ace
->a_perm
& SMB_ACL_WRITE
) ? GLUSTER_ACL_WRITE
: 0);
1244 ((smb_ace
->a_perm
& SMB_ACL_EXECUTE
) ? GLUSTER_ACL_EXECUTE
: 0);
1247 /* TAG is the first 2 bytes of an entry */
1248 SSVAL(buf
, offset
, tag
);
1251 /* PERM is the next 2 bytes of an entry */
1252 SSVAL(buf
, offset
, perm
);
1255 /* ID is the last 4 bytes of an entry */
1256 SIVAL(buf
, offset
, id
);
1262 /* Skip the header, sort @count number of 8-byte entries */
1263 qsort(buf
+GLUSTER_ACL_HEADER_SIZE
, count
, GLUSTER_ACL_ENTRY_SIZE
,
1270 static SMB_ACL_T
vfs_gluster_sys_acl_get_file(struct vfs_handle_struct
*handle
,
1272 SMB_ACL_TYPE_T type
,
1273 TALLOC_CTX
*mem_ctx
)
1275 struct smb_acl_t
*result
;
1281 case SMB_ACL_TYPE_ACCESS
:
1282 key
= "system.posix_acl_access";
1284 case SMB_ACL_TYPE_DEFAULT
:
1285 key
= "system.posix_acl_default";
1292 ret
= glfs_getxattr(handle
->data
, path_p
, key
, 0, 0);
1298 ret
= glfs_getxattr(handle
->data
, path_p
, key
, buf
, ret
);
1303 result
= gluster_to_smb_acl(buf
, ret
, mem_ctx
);
1308 static SMB_ACL_T
vfs_gluster_sys_acl_get_fd(struct vfs_handle_struct
*handle
,
1309 struct files_struct
*fsp
,
1310 TALLOC_CTX
*mem_ctx
)
1312 struct smb_acl_t
*result
;
1317 glfd
= *(glfs_fd_t
**)VFS_FETCH_FSP_EXTENSION(handle
, fsp
);
1318 ret
= glfs_fgetxattr(glfd
, "system.posix_acl_access", 0, 0);
1324 ret
= glfs_fgetxattr(glfd
, "system.posix_acl_access", buf
, ret
);
1329 result
= gluster_to_smb_acl(buf
, ret
, mem_ctx
);
1334 static int vfs_gluster_sys_acl_set_file(struct vfs_handle_struct
*handle
,
1336 SMB_ACL_TYPE_T acltype
,
1345 case SMB_ACL_TYPE_ACCESS
:
1346 key
= "system.posix_acl_access";
1348 case SMB_ACL_TYPE_DEFAULT
:
1349 key
= "system.posix_acl_default";
1356 size
= smb_to_gluster_acl(theacl
, 0, 0);
1359 size
= smb_to_gluster_acl(theacl
, buf
, size
);
1364 ret
= glfs_setxattr(handle
->data
, name
, key
, buf
, size
, 0);
1369 static int vfs_gluster_sys_acl_set_fd(struct vfs_handle_struct
*handle
,
1370 struct files_struct
*fsp
,
1377 size
= smb_to_gluster_acl(theacl
, 0, 0);
1380 size
= smb_to_gluster_acl(theacl
, buf
, size
);
1385 ret
= glfs_fsetxattr(*(glfs_fd_t
**)VFS_FETCH_FSP_EXTENSION(handle
, fsp
),
1386 "system.posix_acl_access", buf
, size
, 0);
1390 static int vfs_gluster_sys_acl_delete_def_file(struct vfs_handle_struct
*handle
,
1393 return glfs_removexattr(handle
->data
, path
, "system.posix_acl_default");
1396 static struct vfs_fn_pointers glusterfs_fns
= {
1398 /* Disk Operations */
1400 .connect_fn
= vfs_gluster_connect
,
1401 .disconnect_fn
= vfs_gluster_disconnect
,
1402 .disk_free_fn
= vfs_gluster_disk_free
,
1403 .get_quota_fn
= vfs_gluster_get_quota
,
1404 .set_quota_fn
= vfs_gluster_set_quota
,
1405 .statvfs_fn
= vfs_gluster_statvfs
,
1406 .fs_capabilities_fn
= vfs_gluster_fs_capabilities
,
1408 .get_dfs_referrals_fn
= NULL
,
1410 /* Directory Operations */
1412 .opendir_fn
= vfs_gluster_opendir
,
1413 .fdopendir_fn
= vfs_gluster_fdopendir
,
1414 .readdir_fn
= vfs_gluster_readdir
,
1415 .seekdir_fn
= vfs_gluster_seekdir
,
1416 .telldir_fn
= vfs_gluster_telldir
,
1417 .rewind_dir_fn
= vfs_gluster_rewinddir
,
1418 .mkdir_fn
= vfs_gluster_mkdir
,
1419 .rmdir_fn
= vfs_gluster_rmdir
,
1420 .closedir_fn
= vfs_gluster_closedir
,
1421 .init_search_op_fn
= vfs_gluster_init_search_op
,
1423 /* File Operations */
1425 .open_fn
= vfs_gluster_open
,
1426 .create_file_fn
= NULL
,
1427 .close_fn
= vfs_gluster_close
,
1428 .read_fn
= vfs_gluster_read
,
1429 .pread_fn
= vfs_gluster_pread
,
1430 .pread_send_fn
= vfs_gluster_pread_send
,
1431 .pread_recv_fn
= vfs_gluster_pread_recv
,
1432 .write_fn
= vfs_gluster_write
,
1433 .pwrite_fn
= vfs_gluster_pwrite
,
1434 .pwrite_send_fn
= vfs_gluster_pwrite_send
,
1435 .pwrite_recv_fn
= vfs_gluster_pwrite_recv
,
1436 .lseek_fn
= vfs_gluster_lseek
,
1437 .sendfile_fn
= vfs_gluster_sendfile
,
1438 .recvfile_fn
= vfs_gluster_recvfile
,
1439 .rename_fn
= vfs_gluster_rename
,
1440 .fsync_fn
= vfs_gluster_fsync
,
1441 .fsync_send_fn
= vfs_gluster_fsync_send
,
1442 .fsync_recv_fn
= vfs_gluster_fsync_recv
,
1444 .stat_fn
= vfs_gluster_stat
,
1445 .fstat_fn
= vfs_gluster_fstat
,
1446 .lstat_fn
= vfs_gluster_lstat
,
1447 .get_alloc_size_fn
= vfs_gluster_get_alloc_size
,
1448 .unlink_fn
= vfs_gluster_unlink
,
1450 .chmod_fn
= vfs_gluster_chmod
,
1451 .fchmod_fn
= vfs_gluster_fchmod
,
1452 .chown_fn
= vfs_gluster_chown
,
1453 .fchown_fn
= vfs_gluster_fchown
,
1454 .lchown_fn
= vfs_gluster_lchown
,
1455 .chdir_fn
= vfs_gluster_chdir
,
1456 .getwd_fn
= vfs_gluster_getwd
,
1457 .ntimes_fn
= vfs_gluster_ntimes
,
1458 .ftruncate_fn
= vfs_gluster_ftruncate
,
1459 .fallocate_fn
= vfs_gluster_fallocate
,
1460 .lock_fn
= vfs_gluster_lock
,
1461 .kernel_flock_fn
= vfs_gluster_kernel_flock
,
1462 .linux_setlease_fn
= vfs_gluster_linux_setlease
,
1463 .getlock_fn
= vfs_gluster_getlock
,
1464 .symlink_fn
= vfs_gluster_symlink
,
1465 .readlink_fn
= vfs_gluster_readlink
,
1466 .link_fn
= vfs_gluster_link
,
1467 .mknod_fn
= vfs_gluster_mknod
,
1468 .realpath_fn
= vfs_gluster_realpath
,
1469 .notify_watch_fn
= vfs_gluster_notify_watch
,
1470 .chflags_fn
= vfs_gluster_chflags
,
1471 .file_id_create_fn
= NULL
,
1472 .copy_chunk_send_fn
= NULL
,
1473 .copy_chunk_recv_fn
= NULL
,
1474 .streaminfo_fn
= NULL
,
1475 .get_real_filename_fn
= vfs_gluster_get_real_filename
,
1476 .connectpath_fn
= vfs_gluster_connectpath
,
1478 .brl_lock_windows_fn
= NULL
,
1479 .brl_unlock_windows_fn
= NULL
,
1480 .brl_cancel_windows_fn
= NULL
,
1481 .strict_lock_fn
= NULL
,
1482 .strict_unlock_fn
= NULL
,
1483 .translate_name_fn
= NULL
,
1486 /* NT ACL Operations */
1487 .fget_nt_acl_fn
= NULL
,
1488 .get_nt_acl_fn
= NULL
,
1489 .fset_nt_acl_fn
= NULL
,
1490 .audit_file_fn
= NULL
,
1492 /* Posix ACL Operations */
1493 .chmod_acl_fn
= NULL
, /* passthrough to default */
1494 .fchmod_acl_fn
= NULL
, /* passthrough to default */
1495 .sys_acl_get_file_fn
= vfs_gluster_sys_acl_get_file
,
1496 .sys_acl_get_fd_fn
= vfs_gluster_sys_acl_get_fd
,
1497 .sys_acl_blob_get_file_fn
= posix_sys_acl_blob_get_file
,
1498 .sys_acl_blob_get_fd_fn
= posix_sys_acl_blob_get_fd
,
1499 .sys_acl_set_file_fn
= vfs_gluster_sys_acl_set_file
,
1500 .sys_acl_set_fd_fn
= vfs_gluster_sys_acl_set_fd
,
1501 .sys_acl_delete_def_file_fn
= vfs_gluster_sys_acl_delete_def_file
,
1504 .getxattr_fn
= vfs_gluster_getxattr
,
1505 .fgetxattr_fn
= vfs_gluster_fgetxattr
,
1506 .listxattr_fn
= vfs_gluster_listxattr
,
1507 .flistxattr_fn
= vfs_gluster_flistxattr
,
1508 .removexattr_fn
= vfs_gluster_removexattr
,
1509 .fremovexattr_fn
= vfs_gluster_fremovexattr
,
1510 .setxattr_fn
= vfs_gluster_setxattr
,
1511 .fsetxattr_fn
= vfs_gluster_fsetxattr
,
1513 /* AIO Operations */
1514 .aio_force_fn
= vfs_gluster_aio_force
,
1516 /* Offline Operations */
1517 .is_offline_fn
= vfs_gluster_is_offline
,
1518 .set_offline_fn
= vfs_gluster_set_offline
,
1520 /* Durable handle Operations */
1521 .durable_cookie_fn
= NULL
,
1522 .durable_disconnect_fn
= NULL
,
1523 .durable_reconnect_fn
= NULL
,
1526 NTSTATUS
vfs_glusterfs_init(void);
1527 NTSTATUS
vfs_glusterfs_init(void)
1529 return smb_register_vfs(SMB_VFS_INTERFACE_VERSION
,
1530 "glusterfs", &glusterfs_fns
);