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
29 * - sendfile/recvfile support
31 * A Samba VFS module for GlusterFS, based on Gluster's libgfapi.
32 * This is a "bottom" vfs module (not something to be stacked on top of
33 * another module), and translates (most) calls to the closest actions
34 * available in libgfapi.
39 #include "smbd/smbd.h"
41 #include <glusterfs/api/glfs.h>
42 #include "lib/util/dlinklist.h"
43 #include "lib/util/tevent_unix.h"
44 #include "smbd/globals.h"
45 #include "lib/util/sys_rw.h"
46 #include "smbprofile.h"
47 #include "modules/posixacl_xattr.h"
48 #include "lib/pthreadpool/pthreadpool_tevent.h"
50 #define DEFAULT_VOLFILE_SERVER "localhost"
51 #define GLUSTER_NAME_MAX 255
54 * Helper to convert struct stat to struct stat_ex.
56 static void smb_stat_ex_from_stat(struct stat_ex *dst, const struct stat *src)
60 dst->st_ex_dev = src->st_dev;
61 dst->st_ex_ino = src->st_ino;
62 dst->st_ex_mode = src->st_mode;
63 dst->st_ex_nlink = src->st_nlink;
64 dst->st_ex_uid = src->st_uid;
65 dst->st_ex_gid = src->st_gid;
66 dst->st_ex_rdev = src->st_rdev;
67 dst->st_ex_size = src->st_size;
68 dst->st_ex_atime.tv_sec = src->st_atime;
69 dst->st_ex_mtime.tv_sec = src->st_mtime;
70 dst->st_ex_ctime.tv_sec = src->st_ctime;
71 dst->st_ex_btime.tv_sec = src->st_mtime;
72 dst->st_ex_blksize = src->st_blksize;
73 dst->st_ex_blocks = src->st_blocks;
74 dst->st_ex_file_id = dst->st_ex_ino;
75 dst->st_ex_iflags |= ST_EX_IFLAG_CALCULATED_FILE_ID;
77 dst->st_ex_atime.tv_nsec = src->st_atime_nsec;
78 dst->st_ex_mtime.tv_nsec = src->st_mtime_nsec;
79 dst->st_ex_ctime.tv_nsec = src->st_ctime_nsec;
80 dst->st_ex_btime.tv_nsec = src->st_mtime_nsec;
82 dst->st_ex_itime = dst->st_ex_btime;
83 dst->st_ex_iflags |= ST_EX_IFLAG_CALCULATED_ITIME;
86 /* pre-opened glfs_t */
88 static struct glfs_preopened {
93 struct glfs_preopened *next, *prev;
97 static int glfs_set_preopened(const char *volume, const char *connectpath, glfs_t *fs)
99 struct glfs_preopened *entry = NULL;
101 entry = talloc_zero(NULL, struct glfs_preopened);
107 entry->volume = talloc_strdup(entry, volume);
108 if (!entry->volume) {
114 entry->connectpath = talloc_strdup(entry, connectpath);
115 if (entry->connectpath == NULL) {
124 DLIST_ADD(glfs_preopened, entry);
129 static glfs_t *glfs_find_preopened(const char *volume, const char *connectpath)
131 struct glfs_preopened *entry = NULL;
133 for (entry = glfs_preopened; entry; entry = entry->next) {
134 if (strcmp(entry->volume, volume) == 0 &&
135 strcmp(entry->connectpath, connectpath) == 0)
145 static void glfs_clear_preopened(glfs_t *fs)
147 struct glfs_preopened *entry = NULL;
149 for (entry = glfs_preopened; entry; entry = entry->next) {
150 if (entry->fs == fs) {
154 DLIST_REMOVE(glfs_preopened, entry);
156 glfs_fini(entry->fs);
162 static int vfs_gluster_set_volfile_servers(glfs_t *fs,
163 const char *volfile_servers)
166 size_t server_count = 0;
167 size_t server_success = 0;
169 TALLOC_CTX *frame = talloc_stackframe();
171 DBG_INFO("servers list %s\n", volfile_servers);
173 while (next_token_talloc(frame, &volfile_servers, &server, " \t")) {
174 char *transport = NULL;
179 DBG_INFO("server %zu %s\n", server_count, server);
181 /* Determine the transport type */
182 if (strncmp(server, "unix+", 5) == 0) {
184 transport = talloc_strdup(frame, "unix");
189 host = talloc_strdup(frame, server + 5);
196 char *port_index = NULL;
198 if (strncmp(server, "tcp+", 4) == 0) {
202 /* IPv6 is enclosed in []
203 * ':' before ']' is part of IPv6
204 * ':' after ']' indicates port
207 if (server[0] == '[') {
209 p = index(server, ']');
218 port_index = index(p, ':');
220 if (port_index == NULL) {
223 port = atoi(port_index + 1);
224 port_index[0] = '\0';
226 transport = talloc_strdup(frame, "tcp");
231 host = talloc_strdup(frame, server);
238 DBG_INFO("Calling set volfile server with params "
239 "transport=%s, host=%s, port=%d\n", transport,
242 ret = glfs_set_volfile_server(fs, transport, host, port);
244 DBG_WARNING("Failed to set volfile_server "
245 "transport=%s, host=%s, port=%d (%s)\n",
246 transport, host, port, strerror(errno));
253 if (server_count == 0) {
255 } else if (server_success < server_count) {
256 DBG_WARNING("Failed to set %zu out of %zu servers parsed\n",
257 server_count - server_success, server_count);
265 /* Disk Operations */
267 static int vfs_gluster_connect(struct vfs_handle_struct *handle,
271 const struct loadparm_substitution *lp_sub =
272 loadparm_s3_global_substitution();
273 const char *volfile_servers;
281 tmp_ctx = talloc_new(NULL);
282 if (tmp_ctx == NULL) {
286 logfile = lp_parm_substituted_string(tmp_ctx,
293 loglevel = lp_parm_int(SNUM(handle->conn), "glusterfs", "loglevel", -1);
295 volfile_servers = lp_parm_substituted_string(tmp_ctx,
301 if (volfile_servers == NULL) {
302 volfile_servers = DEFAULT_VOLFILE_SERVER;
305 volume = lp_parm_const_string(SNUM(handle->conn), "glusterfs", "volume",
307 if (volume == NULL) {
311 fs = glfs_find_preopened(volume, handle->conn->connectpath);
316 fs = glfs_new(volume);
322 ret = vfs_gluster_set_volfile_servers(fs, volfile_servers);
324 DBG_ERR("Failed to set volfile_servers from list %s\n",
329 ret = glfs_set_xlator_option(fs, "*-md-cache", "cache-posix-acl",
332 DEBUG(0, ("%s: Failed to set xlator options\n", volume));
337 ret = glfs_set_xlator_option(fs, "*-snapview-client",
338 "snapdir-entry-path",
339 handle->conn->connectpath);
341 DEBUG(0, ("%s: Failed to set xlator option:"
342 " snapdir-entry-path\n", volume));
346 ret = glfs_set_logging(fs, logfile, loglevel);
348 DEBUG(0, ("%s: Failed to set logfile %s loglevel %d\n",
349 volume, logfile, loglevel));
355 DEBUG(0, ("%s: Failed to initialize volume (%s)\n",
356 volume, strerror(errno)));
360 ret = glfs_set_preopened(volume, handle->conn->connectpath, fs);
362 DEBUG(0, ("%s: Failed to register volume (%s)\n",
363 volume, strerror(errno)));
368 * The shadow_copy2 module will fail to export subdirectories
369 * of a gluster volume unless we specify the mount point,
370 * because the detection fails if the file system is not
372 * https://bugzilla.samba.org/show_bug.cgi?id=13091
374 lp_do_parameter(SNUM(handle->conn), "shadow:mountpoint", "/");
377 * Unless we have an async implementation of getxattrat turn this off.
379 lp_do_parameter(SNUM(handle->conn), "smbd async dosmode", "false");
386 DBG_ERR("%s: Initialized volume from servers %s\n",
387 volume, volfile_servers);
390 talloc_free(tmp_ctx);
394 static void vfs_gluster_disconnect(struct vfs_handle_struct *handle)
400 glfs_clear_preopened(fs);
403 static uint64_t vfs_gluster_disk_free(struct vfs_handle_struct *handle,
404 const struct smb_filename *smb_fname,
409 struct statvfs statvfs = { 0, };
412 ret = glfs_statvfs(handle->data, smb_fname->base_name, &statvfs);
417 if (bsize_p != NULL) {
418 *bsize_p = (uint64_t)statvfs.f_bsize; /* Block size */
420 if (dfree_p != NULL) {
421 *dfree_p = (uint64_t)statvfs.f_bavail; /* Available Block units */
423 if (dsize_p != NULL) {
424 *dsize_p = (uint64_t)statvfs.f_blocks; /* Total Block units */
427 return (uint64_t)statvfs.f_bavail;
430 static int vfs_gluster_get_quota(struct vfs_handle_struct *handle,
431 const struct smb_filename *smb_fname,
432 enum SMB_QUOTA_TYPE qtype,
441 vfs_gluster_set_quota(struct vfs_handle_struct *handle,
442 enum SMB_QUOTA_TYPE qtype, unid_t id, SMB_DISK_QUOTA *qt)
448 static int vfs_gluster_statvfs(struct vfs_handle_struct *handle,
449 const struct smb_filename *smb_fname,
450 struct vfs_statvfs_struct *vfs_statvfs)
452 struct statvfs statvfs = { 0, };
455 ret = glfs_statvfs(handle->data, smb_fname->base_name, &statvfs);
457 DEBUG(0, ("glfs_statvfs(%s) failed: %s\n",
458 smb_fname->base_name, strerror(errno)));
462 ZERO_STRUCTP(vfs_statvfs);
464 vfs_statvfs->OptimalTransferSize = statvfs.f_frsize;
465 vfs_statvfs->BlockSize = statvfs.f_bsize;
466 vfs_statvfs->TotalBlocks = statvfs.f_blocks;
467 vfs_statvfs->BlocksAvail = statvfs.f_bfree;
468 vfs_statvfs->UserBlocksAvail = statvfs.f_bavail;
469 vfs_statvfs->TotalFileNodes = statvfs.f_files;
470 vfs_statvfs->FreeFileNodes = statvfs.f_ffree;
471 vfs_statvfs->FsIdentifier = statvfs.f_fsid;
472 vfs_statvfs->FsCapabilities =
473 FILE_CASE_SENSITIVE_SEARCH | FILE_CASE_PRESERVED_NAMES;
478 static uint32_t vfs_gluster_fs_capabilities(struct vfs_handle_struct *handle,
479 enum timestamp_set_resolution *p_ts_res)
481 uint32_t caps = FILE_CASE_SENSITIVE_SEARCH | FILE_CASE_PRESERVED_NAMES;
483 #ifdef HAVE_GFAPI_VER_6
484 caps |= FILE_SUPPORTS_SPARSE_FILES;
487 #ifdef STAT_HAVE_NSEC
488 *p_ts_res = TIMESTAMP_SET_NT_OR_BETTER;
494 static glfs_fd_t *vfs_gluster_fetch_glfd(struct vfs_handle_struct *handle,
497 glfs_fd_t **glfd = (glfs_fd_t **)VFS_FETCH_FSP_EXTENSION(handle, fsp);
499 DBG_INFO("Failed to fetch fsp extension\n");
503 DBG_INFO("Empty glfs_fd_t pointer\n");
510 static DIR *vfs_gluster_fdopendir(struct vfs_handle_struct *handle,
511 files_struct *fsp, const char *mask,
514 glfs_fd_t *glfd = vfs_gluster_fetch_glfd(handle, fsp);
516 DBG_ERR("Failed to fetch gluster fd\n");
523 static int vfs_gluster_closedir(struct vfs_handle_struct *handle, DIR *dirp)
527 START_PROFILE(syscall_closedir);
528 ret = glfs_closedir((void *)dirp);
529 END_PROFILE(syscall_closedir);
534 static struct dirent *vfs_gluster_readdir(struct vfs_handle_struct *handle,
535 DIR *dirp, SMB_STRUCT_STAT *sbuf)
537 static char direntbuf[512];
540 struct dirent *dirent = 0;
542 START_PROFILE(syscall_readdir);
544 ret = glfs_readdirplus_r((void *)dirp, &stat, (void *)direntbuf,
547 ret = glfs_readdir_r((void *)dirp, (void *)direntbuf, &dirent);
550 if ((ret < 0) || (dirent == NULL)) {
551 END_PROFILE(syscall_readdir);
556 SET_STAT_INVALID(*sbuf);
557 if (!S_ISLNK(stat.st_mode)) {
558 smb_stat_ex_from_stat(sbuf, &stat);
562 END_PROFILE(syscall_readdir);
566 static long vfs_gluster_telldir(struct vfs_handle_struct *handle, DIR *dirp)
570 START_PROFILE(syscall_telldir);
571 ret = glfs_telldir((void *)dirp);
572 END_PROFILE(syscall_telldir);
577 static void vfs_gluster_seekdir(struct vfs_handle_struct *handle, DIR *dirp,
580 START_PROFILE(syscall_seekdir);
581 glfs_seekdir((void *)dirp, offset);
582 END_PROFILE(syscall_seekdir);
585 static void vfs_gluster_rewinddir(struct vfs_handle_struct *handle, DIR *dirp)
587 START_PROFILE(syscall_rewinddir);
588 glfs_seekdir((void *)dirp, 0);
589 END_PROFILE(syscall_rewinddir);
592 static int vfs_gluster_mkdirat(struct vfs_handle_struct *handle,
593 struct files_struct *dirfsp,
594 const struct smb_filename *smb_fname,
599 START_PROFILE(syscall_mkdirat);
600 SMB_ASSERT(dirfsp == dirfsp->conn->cwd_fsp);
601 ret = glfs_mkdir(handle->data, smb_fname->base_name, mode);
602 END_PROFILE(syscall_mkdirat);
607 static int vfs_gluster_open(struct vfs_handle_struct *handle,
608 struct smb_filename *smb_fname, files_struct *fsp,
609 int flags, mode_t mode)
614 START_PROFILE(syscall_open);
616 p_tmp = VFS_ADD_FSP_EXTENSION(handle, fsp, glfs_fd_t *, NULL);
618 END_PROFILE(syscall_open);
623 if (flags & O_DIRECTORY) {
624 glfd = glfs_opendir(handle->data, smb_fname->base_name);
625 } else if (flags & O_CREAT) {
626 glfd = glfs_creat(handle->data, smb_fname->base_name, flags,
629 glfd = glfs_open(handle->data, smb_fname->base_name, flags);
633 END_PROFILE(syscall_open);
634 /* no extension destroy_fn, so no need to save errno */
635 VFS_REMOVE_FSP_EXTENSION(handle, fsp);
641 END_PROFILE(syscall_open);
642 /* An arbitrary value for error reporting, so you know its us. */
646 static int vfs_gluster_close(struct vfs_handle_struct *handle,
650 glfs_fd_t *glfd = NULL;
652 START_PROFILE(syscall_close);
654 glfd = vfs_gluster_fetch_glfd(handle, fsp);
656 END_PROFILE(syscall_close);
657 DBG_ERR("Failed to fetch gluster fd\n");
661 VFS_REMOVE_FSP_EXTENSION(handle, fsp);
663 ret = glfs_close(glfd);
664 END_PROFILE(syscall_close);
669 static ssize_t vfs_gluster_pread(struct vfs_handle_struct *handle,
670 files_struct *fsp, void *data, size_t n,
674 glfs_fd_t *glfd = NULL;
676 START_PROFILE_BYTES(syscall_pread, n);
678 glfd = vfs_gluster_fetch_glfd(handle, fsp);
680 END_PROFILE_BYTES(syscall_pread);
681 DBG_ERR("Failed to fetch gluster fd\n");
685 #ifdef HAVE_GFAPI_VER_7_6
686 ret = glfs_pread(glfd, data, n, offset, 0, NULL);
688 ret = glfs_pread(glfd, data, n, offset, 0);
690 END_PROFILE_BYTES(syscall_pread);
695 struct vfs_gluster_pread_state {
702 struct vfs_aio_state vfs_aio_state;
703 SMBPROFILE_BYTES_ASYNC_STATE(profile_bytes);
706 static void vfs_gluster_pread_do(void *private_data);
707 static void vfs_gluster_pread_done(struct tevent_req *subreq);
708 static int vfs_gluster_pread_state_destructor(struct vfs_gluster_pread_state *state);
710 static struct tevent_req *vfs_gluster_pread_send(struct vfs_handle_struct
711 *handle, TALLOC_CTX *mem_ctx,
712 struct tevent_context *ev,
714 void *data, size_t n,
717 struct vfs_gluster_pread_state *state;
718 struct tevent_req *req, *subreq;
720 glfs_fd_t *glfd = vfs_gluster_fetch_glfd(handle, fsp);
722 DBG_ERR("Failed to fetch gluster fd\n");
726 req = tevent_req_create(mem_ctx, &state, struct vfs_gluster_pread_state);
735 state->offset = offset;
737 SMBPROFILE_BYTES_ASYNC_START(syscall_asys_pread, profile_p,
738 state->profile_bytes, n);
739 SMBPROFILE_BYTES_ASYNC_SET_IDLE(state->profile_bytes);
741 subreq = pthreadpool_tevent_job_send(
742 state, ev, handle->conn->sconn->pool,
743 vfs_gluster_pread_do, state);
744 if (tevent_req_nomem(subreq, req)) {
745 return tevent_req_post(req, ev);
747 tevent_req_set_callback(subreq, vfs_gluster_pread_done, req);
749 talloc_set_destructor(state, vfs_gluster_pread_state_destructor);
754 static void vfs_gluster_pread_do(void *private_data)
756 struct vfs_gluster_pread_state *state = talloc_get_type_abort(
757 private_data, struct vfs_gluster_pread_state);
758 struct timespec start_time;
759 struct timespec end_time;
761 SMBPROFILE_BYTES_ASYNC_SET_BUSY(state->profile_bytes);
763 PROFILE_TIMESTAMP(&start_time);
766 #ifdef HAVE_GFAPI_VER_7_6
767 state->ret = glfs_pread(state->fd, state->buf, state->count,
768 state->offset, 0, NULL);
770 state->ret = glfs_pread(state->fd, state->buf, state->count,
773 } while ((state->ret == -1) && (errno == EINTR));
775 if (state->ret == -1) {
776 state->vfs_aio_state.error = errno;
779 PROFILE_TIMESTAMP(&end_time);
781 state->vfs_aio_state.duration = nsec_time_diff(&end_time, &start_time);
783 SMBPROFILE_BYTES_ASYNC_SET_IDLE(state->profile_bytes);
786 static int vfs_gluster_pread_state_destructor(struct vfs_gluster_pread_state *state)
791 static void vfs_gluster_pread_done(struct tevent_req *subreq)
793 struct tevent_req *req = tevent_req_callback_data(
794 subreq, struct tevent_req);
795 struct vfs_gluster_pread_state *state = tevent_req_data(
796 req, struct vfs_gluster_pread_state);
799 ret = pthreadpool_tevent_job_recv(subreq);
801 SMBPROFILE_BYTES_ASYNC_END(state->profile_bytes);
802 talloc_set_destructor(state, NULL);
805 tevent_req_error(req, ret);
809 * If we get EAGAIN from pthreadpool_tevent_job_recv() this
810 * means the lower level pthreadpool failed to create a new
811 * thread. Fallback to sync processing in that case to allow
812 * some progress for the client.
814 vfs_gluster_pread_do(state);
817 tevent_req_done(req);
820 static ssize_t vfs_gluster_pread_recv(struct tevent_req *req,
821 struct vfs_aio_state *vfs_aio_state)
823 struct vfs_gluster_pread_state *state = tevent_req_data(
824 req, struct vfs_gluster_pread_state);
826 if (tevent_req_is_unix_error(req, &vfs_aio_state->error)) {
830 *vfs_aio_state = state->vfs_aio_state;
834 struct vfs_gluster_pwrite_state {
841 struct vfs_aio_state vfs_aio_state;
842 SMBPROFILE_BYTES_ASYNC_STATE(profile_bytes);
845 static void vfs_gluster_pwrite_do(void *private_data);
846 static void vfs_gluster_pwrite_done(struct tevent_req *subreq);
847 static int vfs_gluster_pwrite_state_destructor(struct vfs_gluster_pwrite_state *state);
849 static struct tevent_req *vfs_gluster_pwrite_send(struct vfs_handle_struct
850 *handle, TALLOC_CTX *mem_ctx,
851 struct tevent_context *ev,
853 const void *data, size_t n,
856 struct tevent_req *req, *subreq;
857 struct vfs_gluster_pwrite_state *state;
859 glfs_fd_t *glfd = vfs_gluster_fetch_glfd(handle, fsp);
861 DBG_ERR("Failed to fetch gluster fd\n");
865 req = tevent_req_create(mem_ctx, &state, struct vfs_gluster_pwrite_state);
874 state->offset = offset;
876 SMBPROFILE_BYTES_ASYNC_START(syscall_asys_pwrite, profile_p,
877 state->profile_bytes, n);
878 SMBPROFILE_BYTES_ASYNC_SET_IDLE(state->profile_bytes);
880 subreq = pthreadpool_tevent_job_send(
881 state, ev, handle->conn->sconn->pool,
882 vfs_gluster_pwrite_do, state);
883 if (tevent_req_nomem(subreq, req)) {
884 return tevent_req_post(req, ev);
886 tevent_req_set_callback(subreq, vfs_gluster_pwrite_done, req);
888 talloc_set_destructor(state, vfs_gluster_pwrite_state_destructor);
893 static void vfs_gluster_pwrite_do(void *private_data)
895 struct vfs_gluster_pwrite_state *state = talloc_get_type_abort(
896 private_data, struct vfs_gluster_pwrite_state);
897 struct timespec start_time;
898 struct timespec end_time;
900 SMBPROFILE_BYTES_ASYNC_SET_BUSY(state->profile_bytes);
902 PROFILE_TIMESTAMP(&start_time);
905 #ifdef HAVE_GFAPI_VER_7_6
906 state->ret = glfs_pwrite(state->fd, state->buf, state->count,
907 state->offset, 0, NULL, NULL);
909 state->ret = glfs_pwrite(state->fd, state->buf, state->count,
912 } while ((state->ret == -1) && (errno == EINTR));
914 if (state->ret == -1) {
915 state->vfs_aio_state.error = errno;
918 PROFILE_TIMESTAMP(&end_time);
920 state->vfs_aio_state.duration = nsec_time_diff(&end_time, &start_time);
922 SMBPROFILE_BYTES_ASYNC_SET_IDLE(state->profile_bytes);
925 static int vfs_gluster_pwrite_state_destructor(struct vfs_gluster_pwrite_state *state)
930 static void vfs_gluster_pwrite_done(struct tevent_req *subreq)
932 struct tevent_req *req = tevent_req_callback_data(
933 subreq, struct tevent_req);
934 struct vfs_gluster_pwrite_state *state = tevent_req_data(
935 req, struct vfs_gluster_pwrite_state);
938 ret = pthreadpool_tevent_job_recv(subreq);
940 SMBPROFILE_BYTES_ASYNC_END(state->profile_bytes);
941 talloc_set_destructor(state, NULL);
944 tevent_req_error(req, ret);
948 * If we get EAGAIN from pthreadpool_tevent_job_recv() this
949 * means the lower level pthreadpool failed to create a new
950 * thread. Fallback to sync processing in that case to allow
951 * some progress for the client.
953 vfs_gluster_pwrite_do(state);
956 tevent_req_done(req);
959 static ssize_t vfs_gluster_pwrite_recv(struct tevent_req *req,
960 struct vfs_aio_state *vfs_aio_state)
962 struct vfs_gluster_pwrite_state *state = tevent_req_data(
963 req, struct vfs_gluster_pwrite_state);
965 if (tevent_req_is_unix_error(req, &vfs_aio_state->error)) {
969 *vfs_aio_state = state->vfs_aio_state;
974 static ssize_t vfs_gluster_pwrite(struct vfs_handle_struct *handle,
975 files_struct *fsp, const void *data,
976 size_t n, off_t offset)
979 glfs_fd_t *glfd = NULL;
981 START_PROFILE_BYTES(syscall_pwrite, n);
983 glfd = vfs_gluster_fetch_glfd(handle, fsp);
985 END_PROFILE_BYTES(syscall_pwrite);
986 DBG_ERR("Failed to fetch gluster fd\n");
990 #ifdef HAVE_GFAPI_VER_7_6
991 ret = glfs_pwrite(glfd, data, n, offset, 0, NULL, NULL);
993 ret = glfs_pwrite(glfd, data, n, offset, 0);
995 END_PROFILE_BYTES(syscall_pwrite);
1000 static off_t vfs_gluster_lseek(struct vfs_handle_struct *handle,
1001 files_struct *fsp, off_t offset, int whence)
1004 glfs_fd_t *glfd = NULL;
1006 START_PROFILE(syscall_lseek);
1008 glfd = vfs_gluster_fetch_glfd(handle, fsp);
1010 END_PROFILE(syscall_lseek);
1011 DBG_ERR("Failed to fetch gluster fd\n");
1015 ret = glfs_lseek(glfd, offset, whence);
1016 END_PROFILE(syscall_lseek);
1021 static ssize_t vfs_gluster_sendfile(struct vfs_handle_struct *handle, int tofd,
1022 files_struct *fromfsp,
1023 const DATA_BLOB *hdr,
1024 off_t offset, size_t n)
1030 static ssize_t vfs_gluster_recvfile(struct vfs_handle_struct *handle,
1031 int fromfd, files_struct *tofsp,
1032 off_t offset, size_t n)
1038 static int vfs_gluster_renameat(struct vfs_handle_struct *handle,
1039 files_struct *srcfsp,
1040 const struct smb_filename *smb_fname_src,
1041 files_struct *dstfsp,
1042 const struct smb_filename *smb_fname_dst)
1046 START_PROFILE(syscall_renameat);
1047 ret = glfs_rename(handle->data, smb_fname_src->base_name,
1048 smb_fname_dst->base_name);
1049 END_PROFILE(syscall_renameat);
1054 struct vfs_gluster_fsync_state {
1058 struct vfs_aio_state vfs_aio_state;
1059 SMBPROFILE_BYTES_ASYNC_STATE(profile_bytes);
1062 static void vfs_gluster_fsync_do(void *private_data);
1063 static void vfs_gluster_fsync_done(struct tevent_req *subreq);
1064 static int vfs_gluster_fsync_state_destructor(struct vfs_gluster_fsync_state *state);
1066 static struct tevent_req *vfs_gluster_fsync_send(struct vfs_handle_struct
1067 *handle, TALLOC_CTX *mem_ctx,
1068 struct tevent_context *ev,
1071 struct tevent_req *req, *subreq;
1072 struct vfs_gluster_fsync_state *state;
1074 glfs_fd_t *glfd = vfs_gluster_fetch_glfd(handle, fsp);
1076 DBG_ERR("Failed to fetch gluster fd\n");
1080 req = tevent_req_create(mem_ctx, &state, struct vfs_gluster_fsync_state);
1088 SMBPROFILE_BYTES_ASYNC_START(syscall_asys_fsync, profile_p,
1089 state->profile_bytes, 0);
1090 SMBPROFILE_BYTES_ASYNC_SET_IDLE(state->profile_bytes);
1092 subreq = pthreadpool_tevent_job_send(
1093 state, ev, handle->conn->sconn->pool, vfs_gluster_fsync_do, state);
1094 if (tevent_req_nomem(subreq, req)) {
1095 return tevent_req_post(req, ev);
1097 tevent_req_set_callback(subreq, vfs_gluster_fsync_done, req);
1099 talloc_set_destructor(state, vfs_gluster_fsync_state_destructor);
1104 static void vfs_gluster_fsync_do(void *private_data)
1106 struct vfs_gluster_fsync_state *state = talloc_get_type_abort(
1107 private_data, struct vfs_gluster_fsync_state);
1108 struct timespec start_time;
1109 struct timespec end_time;
1111 SMBPROFILE_BYTES_ASYNC_SET_BUSY(state->profile_bytes);
1113 PROFILE_TIMESTAMP(&start_time);
1116 #ifdef HAVE_GFAPI_VER_7_6
1117 state->ret = glfs_fsync(state->fd, NULL, NULL);
1119 state->ret = glfs_fsync(state->fd);
1121 } while ((state->ret == -1) && (errno == EINTR));
1123 if (state->ret == -1) {
1124 state->vfs_aio_state.error = errno;
1127 PROFILE_TIMESTAMP(&end_time);
1129 state->vfs_aio_state.duration = nsec_time_diff(&end_time, &start_time);
1131 SMBPROFILE_BYTES_ASYNC_SET_IDLE(state->profile_bytes);
1134 static int vfs_gluster_fsync_state_destructor(struct vfs_gluster_fsync_state *state)
1139 static void vfs_gluster_fsync_done(struct tevent_req *subreq)
1141 struct tevent_req *req = tevent_req_callback_data(
1142 subreq, struct tevent_req);
1143 struct vfs_gluster_fsync_state *state = tevent_req_data(
1144 req, struct vfs_gluster_fsync_state);
1147 ret = pthreadpool_tevent_job_recv(subreq);
1148 TALLOC_FREE(subreq);
1149 SMBPROFILE_BYTES_ASYNC_END(state->profile_bytes);
1150 talloc_set_destructor(state, NULL);
1152 if (ret != EAGAIN) {
1153 tevent_req_error(req, ret);
1157 * If we get EAGAIN from pthreadpool_tevent_job_recv() this
1158 * means the lower level pthreadpool failed to create a new
1159 * thread. Fallback to sync processing in that case to allow
1160 * some progress for the client.
1162 vfs_gluster_fsync_do(state);
1165 tevent_req_done(req);
1168 static int vfs_gluster_fsync_recv(struct tevent_req *req,
1169 struct vfs_aio_state *vfs_aio_state)
1171 struct vfs_gluster_fsync_state *state = tevent_req_data(
1172 req, struct vfs_gluster_fsync_state);
1174 if (tevent_req_is_unix_error(req, &vfs_aio_state->error)) {
1178 *vfs_aio_state = state->vfs_aio_state;
1182 static int vfs_gluster_stat(struct vfs_handle_struct *handle,
1183 struct smb_filename *smb_fname)
1188 START_PROFILE(syscall_stat);
1189 ret = glfs_stat(handle->data, smb_fname->base_name, &st);
1191 smb_stat_ex_from_stat(&smb_fname->st, &st);
1193 if (ret < 0 && errno != ENOENT) {
1194 DEBUG(0, ("glfs_stat(%s) failed: %s\n",
1195 smb_fname->base_name, strerror(errno)));
1197 END_PROFILE(syscall_stat);
1202 static int vfs_gluster_fstat(struct vfs_handle_struct *handle,
1203 files_struct *fsp, SMB_STRUCT_STAT *sbuf)
1207 glfs_fd_t *glfd = NULL;
1209 START_PROFILE(syscall_fstat);
1211 glfd = vfs_gluster_fetch_glfd(handle, fsp);
1213 END_PROFILE(syscall_fstat);
1214 DBG_ERR("Failed to fetch gluster fd\n");
1218 ret = glfs_fstat(glfd, &st);
1220 smb_stat_ex_from_stat(sbuf, &st);
1223 DEBUG(0, ("glfs_fstat(%d) failed: %s\n",
1224 fsp->fh->fd, strerror(errno)));
1226 END_PROFILE(syscall_fstat);
1231 static int vfs_gluster_lstat(struct vfs_handle_struct *handle,
1232 struct smb_filename *smb_fname)
1237 START_PROFILE(syscall_lstat);
1238 ret = glfs_lstat(handle->data, smb_fname->base_name, &st);
1240 smb_stat_ex_from_stat(&smb_fname->st, &st);
1242 if (ret < 0 && errno != ENOENT) {
1243 DEBUG(0, ("glfs_lstat(%s) failed: %s\n",
1244 smb_fname->base_name, strerror(errno)));
1246 END_PROFILE(syscall_lstat);
1251 static uint64_t vfs_gluster_get_alloc_size(struct vfs_handle_struct *handle,
1253 const SMB_STRUCT_STAT *sbuf)
1257 START_PROFILE(syscall_get_alloc_size);
1258 ret = sbuf->st_ex_blocks * 512;
1259 END_PROFILE(syscall_get_alloc_size);
1264 static int vfs_gluster_unlinkat(struct vfs_handle_struct *handle,
1265 struct files_struct *dirfsp,
1266 const struct smb_filename *smb_fname,
1271 START_PROFILE(syscall_unlinkat);
1272 SMB_ASSERT(dirfsp == dirfsp->conn->cwd_fsp);
1273 if (flags & AT_REMOVEDIR) {
1274 ret = glfs_rmdir(handle->data, smb_fname->base_name);
1276 ret = glfs_unlink(handle->data, smb_fname->base_name);
1278 END_PROFILE(syscall_unlinkat);
1283 static int vfs_gluster_chmod(struct vfs_handle_struct *handle,
1284 const struct smb_filename *smb_fname,
1289 START_PROFILE(syscall_chmod);
1290 ret = glfs_chmod(handle->data, smb_fname->base_name, mode);
1291 END_PROFILE(syscall_chmod);
1296 static int vfs_gluster_fchmod(struct vfs_handle_struct *handle,
1297 files_struct *fsp, mode_t mode)
1300 glfs_fd_t *glfd = NULL;
1302 START_PROFILE(syscall_fchmod);
1304 glfd = vfs_gluster_fetch_glfd(handle, fsp);
1306 END_PROFILE(syscall_fchmod);
1307 DBG_ERR("Failed to fetch gluster fd\n");
1311 ret = glfs_fchmod(glfd, mode);
1312 END_PROFILE(syscall_fchmod);
1317 static int vfs_gluster_fchown(struct vfs_handle_struct *handle,
1318 files_struct *fsp, uid_t uid, gid_t gid)
1321 glfs_fd_t *glfd = NULL;
1323 START_PROFILE(syscall_fchown);
1325 glfd = vfs_gluster_fetch_glfd(handle, fsp);
1327 END_PROFILE(syscall_fchown);
1328 DBG_ERR("Failed to fetch gluster fd\n");
1332 ret = glfs_fchown(glfd, uid, gid);
1333 END_PROFILE(syscall_fchown);
1338 static int vfs_gluster_lchown(struct vfs_handle_struct *handle,
1339 const struct smb_filename *smb_fname,
1345 START_PROFILE(syscall_lchown);
1346 ret = glfs_lchown(handle->data, smb_fname->base_name, uid, gid);
1347 END_PROFILE(syscall_lchown);
1352 static int vfs_gluster_chdir(struct vfs_handle_struct *handle,
1353 const struct smb_filename *smb_fname)
1357 START_PROFILE(syscall_chdir);
1358 ret = glfs_chdir(handle->data, smb_fname->base_name);
1359 END_PROFILE(syscall_chdir);
1364 static struct smb_filename *vfs_gluster_getwd(struct vfs_handle_struct *handle,
1369 struct smb_filename *smb_fname = NULL;
1371 START_PROFILE(syscall_getwd);
1373 cwd = SMB_CALLOC_ARRAY(char, PATH_MAX);
1375 END_PROFILE(syscall_getwd);
1379 ret = glfs_getcwd(handle->data, cwd, PATH_MAX - 1);
1380 END_PROFILE(syscall_getwd);
1386 smb_fname = synthetic_smb_fname(ctx,
1395 static int vfs_gluster_ntimes(struct vfs_handle_struct *handle,
1396 const struct smb_filename *smb_fname,
1397 struct smb_file_time *ft)
1400 struct timespec times[2];
1402 START_PROFILE(syscall_ntimes);
1404 if (is_omit_timespec(&ft->atime)) {
1405 times[0].tv_sec = smb_fname->st.st_ex_atime.tv_sec;
1406 times[0].tv_nsec = smb_fname->st.st_ex_atime.tv_nsec;
1408 times[0].tv_sec = ft->atime.tv_sec;
1409 times[0].tv_nsec = ft->atime.tv_nsec;
1412 if (is_omit_timespec(&ft->mtime)) {
1413 times[1].tv_sec = smb_fname->st.st_ex_mtime.tv_sec;
1414 times[1].tv_nsec = smb_fname->st.st_ex_mtime.tv_nsec;
1416 times[1].tv_sec = ft->mtime.tv_sec;
1417 times[1].tv_nsec = ft->mtime.tv_nsec;
1420 if ((timespec_compare(×[0],
1421 &smb_fname->st.st_ex_atime) == 0) &&
1422 (timespec_compare(×[1],
1423 &smb_fname->st.st_ex_mtime) == 0)) {
1424 END_PROFILE(syscall_ntimes);
1428 ret = glfs_utimens(handle->data, smb_fname->base_name, times);
1429 END_PROFILE(syscall_ntimes);
1434 static int vfs_gluster_ftruncate(struct vfs_handle_struct *handle,
1435 files_struct *fsp, off_t offset)
1438 glfs_fd_t *glfd = NULL;
1440 START_PROFILE(syscall_ftruncate);
1442 glfd = vfs_gluster_fetch_glfd(handle, fsp);
1444 END_PROFILE(syscall_ftruncate);
1445 DBG_ERR("Failed to fetch gluster fd\n");
1449 #ifdef HAVE_GFAPI_VER_7_6
1450 ret = glfs_ftruncate(glfd, offset, NULL, NULL);
1452 ret = glfs_ftruncate(glfd, offset);
1454 END_PROFILE(syscall_ftruncate);
1459 static int vfs_gluster_fallocate(struct vfs_handle_struct *handle,
1460 struct files_struct *fsp,
1462 off_t offset, off_t len)
1465 #ifdef HAVE_GFAPI_VER_6
1466 glfs_fd_t *glfd = NULL;
1467 int keep_size, punch_hole;
1469 START_PROFILE(syscall_fallocate);
1471 glfd = vfs_gluster_fetch_glfd(handle, fsp);
1473 END_PROFILE(syscall_fallocate);
1474 DBG_ERR("Failed to fetch gluster fd\n");
1478 keep_size = mode & VFS_FALLOCATE_FL_KEEP_SIZE;
1479 punch_hole = mode & VFS_FALLOCATE_FL_PUNCH_HOLE;
1481 mode &= ~(VFS_FALLOCATE_FL_KEEP_SIZE|VFS_FALLOCATE_FL_PUNCH_HOLE);
1483 END_PROFILE(syscall_fallocate);
1489 ret = glfs_discard(glfd, offset, len);
1491 DBG_DEBUG("glfs_discard failed: %s\n",
1496 ret = glfs_fallocate(glfd, keep_size, offset, len);
1497 END_PROFILE(syscall_fallocate);
1505 static struct smb_filename *vfs_gluster_realpath(struct vfs_handle_struct *handle,
1507 const struct smb_filename *smb_fname)
1509 char *result = NULL;
1510 struct smb_filename *result_fname = NULL;
1511 char *resolved_path = NULL;
1513 START_PROFILE(syscall_realpath);
1515 resolved_path = SMB_MALLOC_ARRAY(char, PATH_MAX+1);
1516 if (resolved_path == NULL) {
1517 END_PROFILE(syscall_realpath);
1522 result = glfs_realpath(handle->data,
1523 smb_fname->base_name,
1525 if (result != NULL) {
1526 result_fname = synthetic_smb_fname(ctx, result, NULL, NULL, 0);
1529 SAFE_FREE(resolved_path);
1530 END_PROFILE(syscall_realpath);
1532 return result_fname;
1535 static bool vfs_gluster_lock(struct vfs_handle_struct *handle,
1536 files_struct *fsp, int op, off_t offset,
1537 off_t count, int type)
1539 struct flock flock = { 0, };
1541 glfs_fd_t *glfd = NULL;
1544 START_PROFILE(syscall_fcntl_lock);
1546 glfd = vfs_gluster_fetch_glfd(handle, fsp);
1548 DBG_ERR("Failed to fetch gluster fd\n");
1553 flock.l_type = type;
1554 flock.l_whence = SEEK_SET;
1555 flock.l_start = offset;
1556 flock.l_len = count;
1559 ret = glfs_posix_lock(glfd, op, &flock);
1561 if (op == F_GETLK) {
1562 /* lock query, true if someone else has locked */
1564 (flock.l_type != F_UNLCK) &&
1565 (flock.l_pid != 0) && (flock.l_pid != getpid())) {
1581 END_PROFILE(syscall_fcntl_lock);
1586 static int vfs_gluster_kernel_flock(struct vfs_handle_struct *handle,
1587 files_struct *fsp, uint32_t share_access,
1588 uint32_t access_mask)
1594 static int vfs_gluster_fcntl(vfs_handle_struct *handle,
1595 files_struct *fsp, int cmd, va_list cmd_arg)
1598 * SMB_VFS_FCNTL() is currently only called by vfs_set_blocking() to
1599 * clear O_NONBLOCK, etc for LOCK_MAND and FIFOs. Ignore it.
1601 if (cmd == F_GETFL) {
1603 } else if (cmd == F_SETFL) {
1604 va_list dup_cmd_arg;
1607 va_copy(dup_cmd_arg, cmd_arg);
1608 opt = va_arg(dup_cmd_arg, int);
1609 va_end(dup_cmd_arg);
1613 DBG_ERR("unexpected fcntl SETFL(%d)\n", opt);
1616 DBG_ERR("unexpected fcntl: %d\n", cmd);
1622 static int vfs_gluster_linux_setlease(struct vfs_handle_struct *handle,
1623 files_struct *fsp, int leasetype)
1629 static bool vfs_gluster_getlock(struct vfs_handle_struct *handle,
1630 files_struct *fsp, off_t *poffset,
1631 off_t *pcount, int *ptype, pid_t *ppid)
1633 struct flock flock = { 0, };
1635 glfs_fd_t *glfd = NULL;
1637 START_PROFILE(syscall_fcntl_getlock);
1639 glfd = vfs_gluster_fetch_glfd(handle, fsp);
1641 END_PROFILE(syscall_fcntl_getlock);
1642 DBG_ERR("Failed to fetch gluster fd\n");
1646 flock.l_type = *ptype;
1647 flock.l_whence = SEEK_SET;
1648 flock.l_start = *poffset;
1649 flock.l_len = *pcount;
1652 ret = glfs_posix_lock(glfd, F_GETLK, &flock);
1655 END_PROFILE(syscall_fcntl_getlock);
1659 *ptype = flock.l_type;
1660 *poffset = flock.l_start;
1661 *pcount = flock.l_len;
1662 *ppid = flock.l_pid;
1663 END_PROFILE(syscall_fcntl_getlock);
1668 static int vfs_gluster_symlinkat(struct vfs_handle_struct *handle,
1669 const char *link_target,
1670 struct files_struct *dirfsp,
1671 const struct smb_filename *new_smb_fname)
1675 START_PROFILE(syscall_symlinkat);
1676 SMB_ASSERT(dirfsp == dirfsp->conn->cwd_fsp);
1677 ret = glfs_symlink(handle->data,
1679 new_smb_fname->base_name);
1680 END_PROFILE(syscall_symlinkat);
1685 static int vfs_gluster_readlinkat(struct vfs_handle_struct *handle,
1686 files_struct *dirfsp,
1687 const struct smb_filename *smb_fname,
1693 START_PROFILE(syscall_readlinkat);
1694 SMB_ASSERT(dirfsp == dirfsp->conn->cwd_fsp);
1695 ret = glfs_readlink(handle->data, smb_fname->base_name, buf, bufsiz);
1696 END_PROFILE(syscall_readlinkat);
1701 static int vfs_gluster_linkat(struct vfs_handle_struct *handle,
1702 files_struct *srcfsp,
1703 const struct smb_filename *old_smb_fname,
1704 files_struct *dstfsp,
1705 const struct smb_filename *new_smb_fname,
1710 START_PROFILE(syscall_linkat);
1712 SMB_ASSERT(srcfsp == srcfsp->conn->cwd_fsp);
1713 SMB_ASSERT(dstfsp == dstfsp->conn->cwd_fsp);
1715 ret = glfs_link(handle->data,
1716 old_smb_fname->base_name,
1717 new_smb_fname->base_name);
1718 END_PROFILE(syscall_linkat);
1723 static int vfs_gluster_mknodat(struct vfs_handle_struct *handle,
1724 files_struct *dirfsp,
1725 const struct smb_filename *smb_fname,
1731 START_PROFILE(syscall_mknodat);
1732 SMB_ASSERT(dirfsp == dirfsp->conn->cwd_fsp);
1733 ret = glfs_mknod(handle->data, smb_fname->base_name, mode, dev);
1734 END_PROFILE(syscall_mknodat);
1739 static int vfs_gluster_chflags(struct vfs_handle_struct *handle,
1740 const struct smb_filename *smb_fname,
1747 static int vfs_gluster_get_real_filename(struct vfs_handle_struct *handle,
1748 const char *path, const char *name,
1749 TALLOC_CTX *mem_ctx, char **found_name)
1752 char key_buf[GLUSTER_NAME_MAX + 64];
1753 char val_buf[GLUSTER_NAME_MAX + 1];
1755 if (strlen(name) >= GLUSTER_NAME_MAX) {
1756 errno = ENAMETOOLONG;
1760 snprintf(key_buf, GLUSTER_NAME_MAX + 64,
1761 "glusterfs.get_real_filename:%s", name);
1763 ret = glfs_getxattr(handle->data, path, key_buf, val_buf,
1764 GLUSTER_NAME_MAX + 1);
1766 if (errno == ENOATTR) {
1772 *found_name = talloc_strdup(mem_ctx, val_buf);
1773 if (found_name[0] == NULL) {
1780 static const char *vfs_gluster_connectpath(struct vfs_handle_struct *handle,
1781 const struct smb_filename *smb_fname)
1783 return handle->conn->connectpath;
1788 static ssize_t vfs_gluster_getxattr(struct vfs_handle_struct *handle,
1789 const struct smb_filename *smb_fname,
1794 return glfs_getxattr(handle->data, smb_fname->base_name,
1798 static ssize_t vfs_gluster_fgetxattr(struct vfs_handle_struct *handle,
1799 files_struct *fsp, const char *name,
1800 void *value, size_t size)
1802 glfs_fd_t *glfd = vfs_gluster_fetch_glfd(handle, fsp);
1804 DBG_ERR("Failed to fetch gluster fd\n");
1808 return glfs_fgetxattr(glfd, name, value, size);
1811 static ssize_t vfs_gluster_listxattr(struct vfs_handle_struct *handle,
1812 const struct smb_filename *smb_fname,
1816 return glfs_listxattr(handle->data, smb_fname->base_name, list, size);
1819 static ssize_t vfs_gluster_flistxattr(struct vfs_handle_struct *handle,
1820 files_struct *fsp, char *list,
1823 glfs_fd_t *glfd = vfs_gluster_fetch_glfd(handle, fsp);
1825 DBG_ERR("Failed to fetch gluster fd\n");
1829 return glfs_flistxattr(glfd, list, size);
1832 static int vfs_gluster_removexattr(struct vfs_handle_struct *handle,
1833 const struct smb_filename *smb_fname,
1836 return glfs_removexattr(handle->data, smb_fname->base_name, name);
1839 static int vfs_gluster_fremovexattr(struct vfs_handle_struct *handle,
1840 files_struct *fsp, const char *name)
1842 glfs_fd_t *glfd = vfs_gluster_fetch_glfd(handle, fsp);
1844 DBG_ERR("Failed to fetch gluster fd\n");
1848 return glfs_fremovexattr(glfd, name);
1851 static int vfs_gluster_setxattr(struct vfs_handle_struct *handle,
1852 const struct smb_filename *smb_fname,
1854 const void *value, size_t size, int flags)
1856 return glfs_setxattr(handle->data, smb_fname->base_name, name, value, size, flags);
1859 static int vfs_gluster_fsetxattr(struct vfs_handle_struct *handle,
1860 files_struct *fsp, const char *name,
1861 const void *value, size_t size, int flags)
1863 glfs_fd_t *glfd = vfs_gluster_fetch_glfd(handle, fsp);
1865 DBG_ERR("Failed to fetch gluster fd\n");
1869 return glfs_fsetxattr(glfd, name, value, size, flags);
1872 /* AIO Operations */
1874 static bool vfs_gluster_aio_force(struct vfs_handle_struct *handle,
1880 static NTSTATUS vfs_gluster_create_dfs_pathat(struct vfs_handle_struct *handle,
1881 struct files_struct *dirfsp,
1882 const struct smb_filename *smb_fname,
1883 const struct referral *reflist,
1884 size_t referral_count)
1886 TALLOC_CTX *frame = talloc_stackframe();
1887 NTSTATUS status = NT_STATUS_NO_MEMORY;
1889 char *msdfs_link = NULL;
1891 SMB_ASSERT(dirfsp == dirfsp->conn->cwd_fsp);
1893 /* Form the msdfs_link contents */
1894 msdfs_link = msdfs_link_string(frame,
1897 if (msdfs_link == NULL) {
1901 ret = glfs_symlink(handle->data,
1903 smb_fname->base_name);
1905 status = NT_STATUS_OK;
1907 status = map_nt_error_from_unix(errno);
1917 * Read and return the contents of a DFS redirect given a
1918 * pathname. A caller can pass in NULL for ppreflist and
1919 * preferral_count but still determine if this was a
1920 * DFS redirect point by getting NT_STATUS_OK back
1921 * without incurring the overhead of reading and parsing
1922 * the referral contents.
1925 static NTSTATUS vfs_gluster_read_dfs_pathat(struct vfs_handle_struct *handle,
1926 TALLOC_CTX *mem_ctx,
1927 struct files_struct *dirfsp,
1928 const struct smb_filename *smb_fname,
1929 struct referral **ppreflist,
1930 size_t *preferral_count)
1932 NTSTATUS status = NT_STATUS_NO_MEMORY;
1934 char *link_target = NULL;
1937 #if defined(HAVE_BROKEN_READLINK)
1938 char link_target_buf[PATH_MAX];
1940 char link_target_buf[7];
1943 SMB_ASSERT(dirfsp == dirfsp->conn->cwd_fsp);
1945 if (ppreflist == NULL && preferral_count == NULL) {
1947 * We're only checking if this is a DFS
1948 * redirect. We don't need to return data.
1950 bufsize = sizeof(link_target_buf);
1951 link_target = link_target_buf;
1954 link_target = talloc_array(mem_ctx, char, bufsize);
1960 referral_len = glfs_readlink(handle->data,
1961 smb_fname->base_name,
1964 if (referral_len < 0) {
1965 if (errno == EINVAL) {
1966 DBG_INFO("%s is not a link.\n", smb_fname->base_name);
1967 status = NT_STATUS_OBJECT_TYPE_MISMATCH;
1969 status = map_nt_error_from_unix(errno);
1970 DBG_ERR("Error reading "
1971 "msdfs link %s: %s\n",
1972 smb_fname->base_name,
1977 link_target[referral_len] = '\0';
1979 DBG_INFO("%s -> %s\n",
1980 smb_fname->base_name,
1983 if (!strnequal(link_target, "msdfs:", 6)) {
1984 status = NT_STATUS_OBJECT_TYPE_MISMATCH;
1988 if (ppreflist == NULL && preferral_count == NULL) {
1989 /* Early return for checking if this is a DFS link. */
1990 return NT_STATUS_OK;
1993 ok = parse_msdfs_symlink(mem_ctx,
1994 lp_msdfs_shuffle_referrals(SNUM(handle->conn)),
2000 status = NT_STATUS_OK;
2002 status = NT_STATUS_NO_MEMORY;
2007 if (link_target != link_target_buf) {
2008 TALLOC_FREE(link_target);
2013 static struct vfs_fn_pointers glusterfs_fns = {
2015 /* Disk Operations */
2017 .connect_fn = vfs_gluster_connect,
2018 .disconnect_fn = vfs_gluster_disconnect,
2019 .disk_free_fn = vfs_gluster_disk_free,
2020 .get_quota_fn = vfs_gluster_get_quota,
2021 .set_quota_fn = vfs_gluster_set_quota,
2022 .statvfs_fn = vfs_gluster_statvfs,
2023 .fs_capabilities_fn = vfs_gluster_fs_capabilities,
2025 .get_dfs_referrals_fn = NULL,
2027 /* Directory Operations */
2029 .fdopendir_fn = vfs_gluster_fdopendir,
2030 .readdir_fn = vfs_gluster_readdir,
2031 .seekdir_fn = vfs_gluster_seekdir,
2032 .telldir_fn = vfs_gluster_telldir,
2033 .rewind_dir_fn = vfs_gluster_rewinddir,
2034 .mkdirat_fn = vfs_gluster_mkdirat,
2035 .closedir_fn = vfs_gluster_closedir,
2037 /* File Operations */
2039 .open_fn = vfs_gluster_open,
2040 .create_file_fn = NULL,
2041 .close_fn = vfs_gluster_close,
2042 .pread_fn = vfs_gluster_pread,
2043 .pread_send_fn = vfs_gluster_pread_send,
2044 .pread_recv_fn = vfs_gluster_pread_recv,
2045 .pwrite_fn = vfs_gluster_pwrite,
2046 .pwrite_send_fn = vfs_gluster_pwrite_send,
2047 .pwrite_recv_fn = vfs_gluster_pwrite_recv,
2048 .lseek_fn = vfs_gluster_lseek,
2049 .sendfile_fn = vfs_gluster_sendfile,
2050 .recvfile_fn = vfs_gluster_recvfile,
2051 .renameat_fn = vfs_gluster_renameat,
2052 .fsync_send_fn = vfs_gluster_fsync_send,
2053 .fsync_recv_fn = vfs_gluster_fsync_recv,
2055 .stat_fn = vfs_gluster_stat,
2056 .fstat_fn = vfs_gluster_fstat,
2057 .lstat_fn = vfs_gluster_lstat,
2058 .get_alloc_size_fn = vfs_gluster_get_alloc_size,
2059 .unlinkat_fn = vfs_gluster_unlinkat,
2061 .chmod_fn = vfs_gluster_chmod,
2062 .fchmod_fn = vfs_gluster_fchmod,
2063 .fchown_fn = vfs_gluster_fchown,
2064 .lchown_fn = vfs_gluster_lchown,
2065 .chdir_fn = vfs_gluster_chdir,
2066 .getwd_fn = vfs_gluster_getwd,
2067 .ntimes_fn = vfs_gluster_ntimes,
2068 .ftruncate_fn = vfs_gluster_ftruncate,
2069 .fallocate_fn = vfs_gluster_fallocate,
2070 .lock_fn = vfs_gluster_lock,
2071 .kernel_flock_fn = vfs_gluster_kernel_flock,
2072 .fcntl_fn = vfs_gluster_fcntl,
2073 .linux_setlease_fn = vfs_gluster_linux_setlease,
2074 .getlock_fn = vfs_gluster_getlock,
2075 .symlinkat_fn = vfs_gluster_symlinkat,
2076 .readlinkat_fn = vfs_gluster_readlinkat,
2077 .linkat_fn = vfs_gluster_linkat,
2078 .mknodat_fn = vfs_gluster_mknodat,
2079 .realpath_fn = vfs_gluster_realpath,
2080 .chflags_fn = vfs_gluster_chflags,
2081 .file_id_create_fn = NULL,
2082 .streaminfo_fn = NULL,
2083 .get_real_filename_fn = vfs_gluster_get_real_filename,
2084 .connectpath_fn = vfs_gluster_connectpath,
2085 .create_dfs_pathat_fn = vfs_gluster_create_dfs_pathat,
2086 .read_dfs_pathat_fn = vfs_gluster_read_dfs_pathat,
2088 .brl_lock_windows_fn = NULL,
2089 .brl_unlock_windows_fn = NULL,
2090 .strict_lock_check_fn = NULL,
2091 .translate_name_fn = NULL,
2094 /* NT ACL Operations */
2095 .fget_nt_acl_fn = NULL,
2096 .get_nt_acl_fn = NULL,
2097 .fset_nt_acl_fn = NULL,
2098 .audit_file_fn = NULL,
2100 /* Posix ACL Operations */
2101 .sys_acl_get_file_fn = posixacl_xattr_acl_get_file,
2102 .sys_acl_get_fd_fn = posixacl_xattr_acl_get_fd,
2103 .sys_acl_blob_get_file_fn = posix_sys_acl_blob_get_file,
2104 .sys_acl_blob_get_fd_fn = posix_sys_acl_blob_get_fd,
2105 .sys_acl_set_file_fn = posixacl_xattr_acl_set_file,
2106 .sys_acl_set_fd_fn = posixacl_xattr_acl_set_fd,
2107 .sys_acl_delete_def_file_fn = posixacl_xattr_acl_delete_def_file,
2110 .getxattr_fn = vfs_gluster_getxattr,
2111 .getxattrat_send_fn = vfs_not_implemented_getxattrat_send,
2112 .getxattrat_recv_fn = vfs_not_implemented_getxattrat_recv,
2113 .fgetxattr_fn = vfs_gluster_fgetxattr,
2114 .listxattr_fn = vfs_gluster_listxattr,
2115 .flistxattr_fn = vfs_gluster_flistxattr,
2116 .removexattr_fn = vfs_gluster_removexattr,
2117 .fremovexattr_fn = vfs_gluster_fremovexattr,
2118 .setxattr_fn = vfs_gluster_setxattr,
2119 .fsetxattr_fn = vfs_gluster_fsetxattr,
2121 /* AIO Operations */
2122 .aio_force_fn = vfs_gluster_aio_force,
2124 /* Durable handle Operations */
2125 .durable_cookie_fn = NULL,
2126 .durable_disconnect_fn = NULL,
2127 .durable_reconnect_fn = NULL,
2131 NTSTATUS vfs_glusterfs_init(TALLOC_CTX *ctx)
2133 return smb_register_vfs(SMB_VFS_INTERFACE_VERSION,
2134 "glusterfs", &glusterfs_fns);