efb6989190f494fa0139344242b944efdd43b252
[samba.git] / source3 / modules / vfs_glusterfs.c
1 /*
2    Unix SMB/CIFS implementation.
3
4    Wrap GlusterFS GFAPI calls in vfs functions.
5
6    Copyright (c) 2013 Anand Avati <avati@redhat.com>
7
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.
12
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.
17
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/>.
20 */
21
22 /**
23  * @file   vfs_glusterfs.c
24  * @author Anand Avati <avati@redhat.com>
25  * @date   May 2013
26  * @brief  Samba VFS module for glusterfs
27  *
28  * @todo
29  *   - sendfile/recvfile support
30  *
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.
35  *
36  */
37
38 #include "includes.h"
39 #include "smbd/smbd.h"
40 #include <stdio.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"
49
50 #define DEFAULT_VOLFILE_SERVER "localhost"
51 #define GLUSTER_NAME_MAX 255
52
53 /**
54  * Helper to convert struct stat to struct stat_ex.
55  */
56 static void smb_stat_ex_from_stat(struct stat_ex *dst, const struct stat *src)
57 {
58         ZERO_STRUCTP(dst);
59
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;
76 #ifdef STAT_HAVE_NSEC
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;
81 #endif
82         dst->st_ex_itime = dst->st_ex_btime;
83         dst->st_ex_iflags |= ST_EX_IFLAG_CALCULATED_ITIME;
84 }
85
86 /* pre-opened glfs_t */
87
88 static struct glfs_preopened {
89         char *volume;
90         char *connectpath;
91         glfs_t *fs;
92         int ref;
93         struct glfs_preopened *next, *prev;
94 } *glfs_preopened;
95
96
97 static int glfs_set_preopened(const char *volume, const char *connectpath, glfs_t *fs)
98 {
99         struct glfs_preopened *entry = NULL;
100
101         entry = talloc_zero(NULL, struct glfs_preopened);
102         if (!entry) {
103                 errno = ENOMEM;
104                 return -1;
105         }
106
107         entry->volume = talloc_strdup(entry, volume);
108         if (!entry->volume) {
109                 talloc_free(entry);
110                 errno = ENOMEM;
111                 return -1;
112         }
113
114         entry->connectpath = talloc_strdup(entry, connectpath);
115         if (entry->connectpath == NULL) {
116                 talloc_free(entry);
117                 errno = ENOMEM;
118                 return -1;
119         }
120
121         entry->fs = fs;
122         entry->ref = 1;
123
124         DLIST_ADD(glfs_preopened, entry);
125
126         return 0;
127 }
128
129 static glfs_t *glfs_find_preopened(const char *volume, const char *connectpath)
130 {
131         struct glfs_preopened *entry = NULL;
132
133         for (entry = glfs_preopened; entry; entry = entry->next) {
134                 if (strcmp(entry->volume, volume) == 0 &&
135                     strcmp(entry->connectpath, connectpath) == 0)
136                 {
137                         entry->ref++;
138                         return entry->fs;
139                 }
140         }
141
142         return NULL;
143 }
144
145 static void glfs_clear_preopened(glfs_t *fs)
146 {
147         struct glfs_preopened *entry = NULL;
148
149         for (entry = glfs_preopened; entry; entry = entry->next) {
150                 if (entry->fs == fs) {
151                         if (--entry->ref)
152                                 return;
153
154                         DLIST_REMOVE(glfs_preopened, entry);
155
156                         glfs_fini(entry->fs);
157                         talloc_free(entry);
158                 }
159         }
160 }
161
162 static int vfs_gluster_set_volfile_servers(glfs_t *fs,
163                                            const char *volfile_servers)
164 {
165         char *server = NULL;
166         size_t server_count = 0;
167         size_t server_success = 0;
168         int   ret = -1;
169         TALLOC_CTX *frame = talloc_stackframe();
170
171         DBG_INFO("servers list %s\n", volfile_servers);
172
173         while (next_token_talloc(frame, &volfile_servers, &server, " \t")) {
174                 char *transport = NULL;
175                 char *host = NULL;
176                 int   port = 0;
177
178                 server_count++;
179                 DBG_INFO("server %zu %s\n", server_count, server);
180
181                 /* Determine the transport type */
182                 if (strncmp(server, "unix+", 5) == 0) {
183                         port = 0;
184                         transport = talloc_strdup(frame, "unix");
185                         if (!transport) {
186                                 errno = ENOMEM;
187                                 goto out;
188                         }
189                         host = talloc_strdup(frame, server + 5);
190                         if (!host) {
191                                 errno = ENOMEM;
192                                 goto out;
193                         }
194                 } else {
195                         char *p = NULL;
196                         char *port_index = NULL;
197
198                         if (strncmp(server, "tcp+", 4) == 0) {
199                                 server += 4;
200                         }
201
202                         /* IPv6 is enclosed in []
203                          * ':' before ']' is part of IPv6
204                          * ':' after  ']' indicates port
205                          */
206                         p = server;
207                         if (server[0] == '[') {
208                                 server++;
209                                 p = index(server, ']');
210                                 if (p == NULL) {
211                                         /* Malformed IPv6 */
212                                         continue;
213                                 }
214                                 p[0] = '\0';
215                                 p++;
216                         }
217
218                         port_index = index(p, ':');
219
220                         if (port_index == NULL) {
221                                 port = 0;
222                         } else {
223                                 port = atoi(port_index + 1);
224                                 port_index[0] = '\0';
225                         }
226                         transport = talloc_strdup(frame, "tcp");
227                         if (!transport) {
228                                 errno = ENOMEM;
229                                 goto out;
230                         }
231                         host = talloc_strdup(frame, server);
232                         if (!host) {
233                                 errno = ENOMEM;
234                                 goto out;
235                         }
236                 }
237
238                 DBG_INFO("Calling set volfile server with params "
239                          "transport=%s, host=%s, port=%d\n", transport,
240                           host, port);
241
242                 ret = glfs_set_volfile_server(fs, transport, host, port);
243                 if (ret < 0) {
244                         DBG_WARNING("Failed to set volfile_server "
245                                     "transport=%s, host=%s, port=%d (%s)\n",
246                                     transport, host, port, strerror(errno));
247                 } else {
248                         server_success++;
249                 }
250         }
251
252 out:
253         if (server_count == 0) {
254                 ret = -1;
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);
258                 ret = 0;
259         }
260
261         TALLOC_FREE(frame);
262         return ret;
263 }
264
265 /* Disk Operations */
266
267 static int vfs_gluster_connect(struct vfs_handle_struct *handle,
268                                const char *service,
269                                const char *user)
270 {
271         const struct loadparm_substitution *lp_sub =
272                 loadparm_s3_global_substitution();
273         const char *volfile_servers;
274         const char *volume;
275         char *logfile;
276         int loglevel;
277         glfs_t *fs = NULL;
278         TALLOC_CTX *tmp_ctx;
279         int ret = 0;
280
281         tmp_ctx = talloc_new(NULL);
282         if (tmp_ctx == NULL) {
283                 ret = -1;
284                 goto done;
285         }
286         logfile = lp_parm_substituted_string(tmp_ctx,
287                                              lp_sub,
288                                              SNUM(handle->conn),
289                                              "glusterfs",
290                                              "logfile",
291                                              NULL);
292
293         loglevel = lp_parm_int(SNUM(handle->conn), "glusterfs", "loglevel", -1);
294
295         volfile_servers = lp_parm_substituted_string(tmp_ctx,
296                                                      lp_sub,
297                                                      SNUM(handle->conn),
298                                                      "glusterfs",
299                                                      "volfile_server",
300                                                      NULL);
301         if (volfile_servers == NULL) {
302                 volfile_servers = DEFAULT_VOLFILE_SERVER;
303         }
304
305         volume = lp_parm_const_string(SNUM(handle->conn), "glusterfs", "volume",
306                                       NULL);
307         if (volume == NULL) {
308                 volume = service;
309         }
310
311         fs = glfs_find_preopened(volume, handle->conn->connectpath);
312         if (fs) {
313                 goto done;
314         }
315
316         fs = glfs_new(volume);
317         if (fs == NULL) {
318                 ret = -1;
319                 goto done;
320         }
321
322         ret = vfs_gluster_set_volfile_servers(fs, volfile_servers);
323         if (ret < 0) {
324                 DBG_ERR("Failed to set volfile_servers from list %s\n",
325                         volfile_servers);
326                 goto done;
327         }
328
329         ret = glfs_set_xlator_option(fs, "*-md-cache", "cache-posix-acl",
330                                      "true");
331         if (ret < 0) {
332                 DEBUG(0, ("%s: Failed to set xlator options\n", volume));
333                 goto done;
334         }
335
336
337         ret = glfs_set_xlator_option(fs, "*-snapview-client",
338                                      "snapdir-entry-path",
339                                      handle->conn->connectpath);
340         if (ret < 0) {
341                 DEBUG(0, ("%s: Failed to set xlator option:"
342                           " snapdir-entry-path\n", volume));
343                 goto done;
344         }
345
346         ret = glfs_set_logging(fs, logfile, loglevel);
347         if (ret < 0) {
348                 DEBUG(0, ("%s: Failed to set logfile %s loglevel %d\n",
349                           volume, logfile, loglevel));
350                 goto done;
351         }
352
353         ret = glfs_init(fs);
354         if (ret < 0) {
355                 DEBUG(0, ("%s: Failed to initialize volume (%s)\n",
356                           volume, strerror(errno)));
357                 goto done;
358         }
359
360         ret = glfs_set_preopened(volume, handle->conn->connectpath, fs);
361         if (ret < 0) {
362                 DEBUG(0, ("%s: Failed to register volume (%s)\n",
363                           volume, strerror(errno)));
364                 goto done;
365         }
366
367         /*
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
371          * locally mounted:
372          * https://bugzilla.samba.org/show_bug.cgi?id=13091
373          */
374         lp_do_parameter(SNUM(handle->conn), "shadow:mountpoint", "/");
375
376         /*
377          * Unless we have an async implementation of getxattrat turn this off.
378          */
379         lp_do_parameter(SNUM(handle->conn), "smbd async dosmode", "false");
380
381 done:
382         if (ret < 0) {
383                 if (fs)
384                         glfs_fini(fs);
385         } else {
386                 DBG_ERR("%s: Initialized volume from servers %s\n",
387                         volume, volfile_servers);
388                 handle->data = fs;
389         }
390         talloc_free(tmp_ctx);
391         return ret;
392 }
393
394 static void vfs_gluster_disconnect(struct vfs_handle_struct *handle)
395 {
396         glfs_t *fs = NULL;
397
398         fs = handle->data;
399
400         glfs_clear_preopened(fs);
401 }
402
403 static uint64_t vfs_gluster_disk_free(struct vfs_handle_struct *handle,
404                                 const struct smb_filename *smb_fname,
405                                 uint64_t *bsize_p,
406                                 uint64_t *dfree_p,
407                                 uint64_t *dsize_p)
408 {
409         struct statvfs statvfs = { 0, };
410         int ret;
411
412         ret = glfs_statvfs(handle->data, smb_fname->base_name, &statvfs);
413         if (ret < 0) {
414                 return -1;
415         }
416
417         if (bsize_p != NULL) {
418                 *bsize_p = (uint64_t)statvfs.f_bsize; /* Block size */
419         }
420         if (dfree_p != NULL) {
421                 *dfree_p = (uint64_t)statvfs.f_bavail; /* Available Block units */
422         }
423         if (dsize_p != NULL) {
424                 *dsize_p = (uint64_t)statvfs.f_blocks; /* Total Block units */
425         }
426
427         return (uint64_t)statvfs.f_bavail;
428 }
429
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,
433                                 unid_t id,
434                                 SMB_DISK_QUOTA *qt)
435 {
436         errno = ENOSYS;
437         return -1;
438 }
439
440 static int
441 vfs_gluster_set_quota(struct vfs_handle_struct *handle,
442                       enum SMB_QUOTA_TYPE qtype, unid_t id, SMB_DISK_QUOTA *qt)
443 {
444         errno = ENOSYS;
445         return -1;
446 }
447
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)
451 {
452         struct statvfs statvfs = { 0, };
453         int ret;
454
455         ret = glfs_statvfs(handle->data, smb_fname->base_name, &statvfs);
456         if (ret < 0) {
457                 DEBUG(0, ("glfs_statvfs(%s) failed: %s\n",
458                           smb_fname->base_name, strerror(errno)));
459                 return -1;
460         }
461
462         ZERO_STRUCTP(vfs_statvfs);
463
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;
474
475         return ret;
476 }
477
478 static uint32_t vfs_gluster_fs_capabilities(struct vfs_handle_struct *handle,
479                                             enum timestamp_set_resolution *p_ts_res)
480 {
481         uint32_t caps = FILE_CASE_SENSITIVE_SEARCH | FILE_CASE_PRESERVED_NAMES;
482
483 #ifdef HAVE_GFAPI_VER_6
484         caps |= FILE_SUPPORTS_SPARSE_FILES;
485 #endif
486
487 #ifdef STAT_HAVE_NSEC
488         *p_ts_res = TIMESTAMP_SET_NT_OR_BETTER;
489 #endif
490
491         return caps;
492 }
493
494 static glfs_fd_t *vfs_gluster_fetch_glfd(struct vfs_handle_struct *handle,
495                                          files_struct *fsp)
496 {
497         glfs_fd_t **glfd = (glfs_fd_t **)VFS_FETCH_FSP_EXTENSION(handle, fsp);
498         if (glfd == NULL) {
499                 DBG_INFO("Failed to fetch fsp extension\n");
500                 return NULL;
501         }
502         if (*glfd == NULL) {
503                 DBG_INFO("Empty glfs_fd_t pointer\n");
504                 return NULL;
505         }
506
507         return *glfd;
508 }
509
510 static DIR *vfs_gluster_fdopendir(struct vfs_handle_struct *handle,
511                                   files_struct *fsp, const char *mask,
512                                   uint32_t attributes)
513 {
514         glfs_fd_t *glfd = vfs_gluster_fetch_glfd(handle, fsp);
515         if (glfd == NULL) {
516                 DBG_ERR("Failed to fetch gluster fd\n");
517                 return NULL;
518         }
519
520         return (DIR *)glfd;
521 }
522
523 static int vfs_gluster_closedir(struct vfs_handle_struct *handle, DIR *dirp)
524 {
525         int ret;
526
527         START_PROFILE(syscall_closedir);
528         ret = glfs_closedir((void *)dirp);
529         END_PROFILE(syscall_closedir);
530
531         return ret;
532 }
533
534 static struct dirent *vfs_gluster_readdir(struct vfs_handle_struct *handle,
535                                           DIR *dirp, SMB_STRUCT_STAT *sbuf)
536 {
537         static char direntbuf[512];
538         int ret;
539         struct stat stat;
540         struct dirent *dirent = 0;
541
542         START_PROFILE(syscall_readdir);
543         if (sbuf != NULL) {
544                 ret = glfs_readdirplus_r((void *)dirp, &stat, (void *)direntbuf,
545                                          &dirent);
546         } else {
547                 ret = glfs_readdir_r((void *)dirp, (void *)direntbuf, &dirent);
548         }
549
550         if ((ret < 0) || (dirent == NULL)) {
551                 END_PROFILE(syscall_readdir);
552                 return NULL;
553         }
554
555         if (sbuf != NULL) {
556                 SET_STAT_INVALID(*sbuf);
557                 if (!S_ISLNK(stat.st_mode)) {
558                         smb_stat_ex_from_stat(sbuf, &stat);
559                 }
560         }
561
562         END_PROFILE(syscall_readdir);
563         return dirent;
564 }
565
566 static long vfs_gluster_telldir(struct vfs_handle_struct *handle, DIR *dirp)
567 {
568         long ret;
569
570         START_PROFILE(syscall_telldir);
571         ret = glfs_telldir((void *)dirp);
572         END_PROFILE(syscall_telldir);
573
574         return ret;
575 }
576
577 static void vfs_gluster_seekdir(struct vfs_handle_struct *handle, DIR *dirp,
578                                 long offset)
579 {
580         START_PROFILE(syscall_seekdir);
581         glfs_seekdir((void *)dirp, offset);
582         END_PROFILE(syscall_seekdir);
583 }
584
585 static void vfs_gluster_rewinddir(struct vfs_handle_struct *handle, DIR *dirp)
586 {
587         START_PROFILE(syscall_rewinddir);
588         glfs_seekdir((void *)dirp, 0);
589         END_PROFILE(syscall_rewinddir);
590 }
591
592 static int vfs_gluster_mkdirat(struct vfs_handle_struct *handle,
593                         struct files_struct *dirfsp,
594                         const struct smb_filename *smb_fname,
595                         mode_t mode)
596 {
597         int ret;
598
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);
603
604         return ret;
605 }
606
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)
610 {
611         glfs_fd_t *glfd;
612         glfs_fd_t **p_tmp;
613
614         START_PROFILE(syscall_open);
615
616         p_tmp = VFS_ADD_FSP_EXTENSION(handle, fsp, glfs_fd_t *, NULL);
617         if (p_tmp == NULL) {
618                 END_PROFILE(syscall_open);
619                 errno = ENOMEM;
620                 return -1;
621         }
622
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,
627                                   mode);
628         } else {
629                 glfd = glfs_open(handle->data, smb_fname->base_name, flags);
630         }
631
632         if (glfd == NULL) {
633                 END_PROFILE(syscall_open);
634                 /* no extension destroy_fn, so no need to save errno */
635                 VFS_REMOVE_FSP_EXTENSION(handle, fsp);
636                 return -1;
637         }
638
639         *p_tmp = glfd;
640
641         END_PROFILE(syscall_open);
642         /* An arbitrary value for error reporting, so you know its us. */
643         return 13371337;
644 }
645
646 static int vfs_gluster_close(struct vfs_handle_struct *handle,
647                              files_struct *fsp)
648 {
649         int ret;
650         glfs_fd_t *glfd = NULL;
651
652         START_PROFILE(syscall_close);
653
654         glfd = vfs_gluster_fetch_glfd(handle, fsp);
655         if (glfd == NULL) {
656                 END_PROFILE(syscall_close);
657                 DBG_ERR("Failed to fetch gluster fd\n");
658                 return -1;
659         }
660
661         VFS_REMOVE_FSP_EXTENSION(handle, fsp);
662
663         ret = glfs_close(glfd);
664         END_PROFILE(syscall_close);
665
666         return ret;
667 }
668
669 static ssize_t vfs_gluster_pread(struct vfs_handle_struct *handle,
670                                  files_struct *fsp, void *data, size_t n,
671                                  off_t offset)
672 {
673         ssize_t ret;
674         glfs_fd_t *glfd = NULL;
675
676         START_PROFILE_BYTES(syscall_pread, n);
677
678         glfd = vfs_gluster_fetch_glfd(handle, fsp);
679         if (glfd == NULL) {
680                 END_PROFILE_BYTES(syscall_pread);
681                 DBG_ERR("Failed to fetch gluster fd\n");
682                 return -1;
683         }
684
685 #ifdef HAVE_GFAPI_VER_7_6
686         ret = glfs_pread(glfd, data, n, offset, 0, NULL);
687 #else
688         ret = glfs_pread(glfd, data, n, offset, 0);
689 #endif
690         END_PROFILE_BYTES(syscall_pread);
691
692         return ret;
693 }
694
695 struct vfs_gluster_pread_state {
696         ssize_t ret;
697         glfs_fd_t *fd;
698         void *buf;
699         size_t count;
700         off_t offset;
701
702         struct vfs_aio_state vfs_aio_state;
703         SMBPROFILE_BYTES_ASYNC_STATE(profile_bytes);
704 };
705
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);
709
710 static struct tevent_req *vfs_gluster_pread_send(struct vfs_handle_struct
711                                                   *handle, TALLOC_CTX *mem_ctx,
712                                                   struct tevent_context *ev,
713                                                   files_struct *fsp,
714                                                   void *data, size_t n,
715                                                   off_t offset)
716 {
717         struct vfs_gluster_pread_state *state;
718         struct tevent_req *req, *subreq;
719
720         glfs_fd_t *glfd = vfs_gluster_fetch_glfd(handle, fsp);
721         if (glfd == NULL) {
722                 DBG_ERR("Failed to fetch gluster fd\n");
723                 return NULL;
724         }
725
726         req = tevent_req_create(mem_ctx, &state, struct vfs_gluster_pread_state);
727         if (req == NULL) {
728                 return NULL;
729         }
730
731         state->ret = -1;
732         state->fd = glfd;
733         state->buf = data;
734         state->count = n;
735         state->offset = offset;
736
737         SMBPROFILE_BYTES_ASYNC_START(syscall_asys_pread, profile_p,
738                                      state->profile_bytes, n);
739         SMBPROFILE_BYTES_ASYNC_SET_IDLE(state->profile_bytes);
740
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);
746         }
747         tevent_req_set_callback(subreq, vfs_gluster_pread_done, req);
748
749         talloc_set_destructor(state, vfs_gluster_pread_state_destructor);
750
751         return req;
752 }
753
754 static void vfs_gluster_pread_do(void *private_data)
755 {
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;
760
761         SMBPROFILE_BYTES_ASYNC_SET_BUSY(state->profile_bytes);
762
763         PROFILE_TIMESTAMP(&start_time);
764
765         do {
766 #ifdef HAVE_GFAPI_VER_7_6
767                 state->ret = glfs_pread(state->fd, state->buf, state->count,
768                                         state->offset, 0, NULL);
769 #else
770                 state->ret = glfs_pread(state->fd, state->buf, state->count,
771                                         state->offset, 0);
772 #endif
773         } while ((state->ret == -1) && (errno == EINTR));
774
775         if (state->ret == -1) {
776                 state->vfs_aio_state.error = errno;
777         }
778
779         PROFILE_TIMESTAMP(&end_time);
780
781         state->vfs_aio_state.duration = nsec_time_diff(&end_time, &start_time);
782
783         SMBPROFILE_BYTES_ASYNC_SET_IDLE(state->profile_bytes);
784 }
785
786 static int vfs_gluster_pread_state_destructor(struct vfs_gluster_pread_state *state)
787 {
788         return -1;
789 }
790
791 static void vfs_gluster_pread_done(struct tevent_req *subreq)
792 {
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);
797         int ret;
798
799         ret = pthreadpool_tevent_job_recv(subreq);
800         TALLOC_FREE(subreq);
801         SMBPROFILE_BYTES_ASYNC_END(state->profile_bytes);
802         talloc_set_destructor(state, NULL);
803         if (ret != 0) {
804                 if (ret != EAGAIN) {
805                         tevent_req_error(req, ret);
806                         return;
807                 }
808                 /*
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.
813                  */
814                 vfs_gluster_pread_do(state);
815         }
816
817         tevent_req_done(req);
818 }
819
820 static ssize_t vfs_gluster_pread_recv(struct tevent_req *req,
821                                       struct vfs_aio_state *vfs_aio_state)
822 {
823         struct vfs_gluster_pread_state *state = tevent_req_data(
824                 req, struct vfs_gluster_pread_state);
825
826         if (tevent_req_is_unix_error(req, &vfs_aio_state->error)) {
827                 return -1;
828         }
829
830         *vfs_aio_state = state->vfs_aio_state;
831         return state->ret;
832 }
833
834 struct vfs_gluster_pwrite_state {
835         ssize_t ret;
836         glfs_fd_t *fd;
837         const void *buf;
838         size_t count;
839         off_t offset;
840
841         struct vfs_aio_state vfs_aio_state;
842         SMBPROFILE_BYTES_ASYNC_STATE(profile_bytes);
843 };
844
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);
848
849 static struct tevent_req *vfs_gluster_pwrite_send(struct vfs_handle_struct
850                                                   *handle, TALLOC_CTX *mem_ctx,
851                                                   struct tevent_context *ev,
852                                                   files_struct *fsp,
853                                                   const void *data, size_t n,
854                                                   off_t offset)
855 {
856         struct tevent_req *req, *subreq;
857         struct vfs_gluster_pwrite_state *state;
858
859         glfs_fd_t *glfd = vfs_gluster_fetch_glfd(handle, fsp);
860         if (glfd == NULL) {
861                 DBG_ERR("Failed to fetch gluster fd\n");
862                 return NULL;
863         }
864
865         req = tevent_req_create(mem_ctx, &state, struct vfs_gluster_pwrite_state);
866         if (req == NULL) {
867                 return NULL;
868         }
869
870         state->ret = -1;
871         state->fd = glfd;
872         state->buf = data;
873         state->count = n;
874         state->offset = offset;
875
876         SMBPROFILE_BYTES_ASYNC_START(syscall_asys_pwrite, profile_p,
877                                      state->profile_bytes, n);
878         SMBPROFILE_BYTES_ASYNC_SET_IDLE(state->profile_bytes);
879
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);
885         }
886         tevent_req_set_callback(subreq, vfs_gluster_pwrite_done, req);
887
888         talloc_set_destructor(state, vfs_gluster_pwrite_state_destructor);
889
890         return req;
891 }
892
893 static void vfs_gluster_pwrite_do(void *private_data)
894 {
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;
899
900         SMBPROFILE_BYTES_ASYNC_SET_BUSY(state->profile_bytes);
901
902         PROFILE_TIMESTAMP(&start_time);
903
904         do {
905 #ifdef HAVE_GFAPI_VER_7_6
906                 state->ret = glfs_pwrite(state->fd, state->buf, state->count,
907                                          state->offset, 0, NULL, NULL);
908 #else
909                 state->ret = glfs_pwrite(state->fd, state->buf, state->count,
910                                          state->offset, 0);
911 #endif
912         } while ((state->ret == -1) && (errno == EINTR));
913
914         if (state->ret == -1) {
915                 state->vfs_aio_state.error = errno;
916         }
917
918         PROFILE_TIMESTAMP(&end_time);
919
920         state->vfs_aio_state.duration = nsec_time_diff(&end_time, &start_time);
921
922         SMBPROFILE_BYTES_ASYNC_SET_IDLE(state->profile_bytes);
923 }
924
925 static int vfs_gluster_pwrite_state_destructor(struct vfs_gluster_pwrite_state *state)
926 {
927         return -1;
928 }
929
930 static void vfs_gluster_pwrite_done(struct tevent_req *subreq)
931 {
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);
936         int ret;
937
938         ret = pthreadpool_tevent_job_recv(subreq);
939         TALLOC_FREE(subreq);
940         SMBPROFILE_BYTES_ASYNC_END(state->profile_bytes);
941         talloc_set_destructor(state, NULL);
942         if (ret != 0) {
943                 if (ret != EAGAIN) {
944                         tevent_req_error(req, ret);
945                         return;
946                 }
947                 /*
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.
952                  */
953                 vfs_gluster_pwrite_do(state);
954         }
955
956         tevent_req_done(req);
957 }
958
959 static ssize_t vfs_gluster_pwrite_recv(struct tevent_req *req,
960                                        struct vfs_aio_state *vfs_aio_state)
961 {
962         struct vfs_gluster_pwrite_state *state = tevent_req_data(
963                 req, struct vfs_gluster_pwrite_state);
964
965         if (tevent_req_is_unix_error(req, &vfs_aio_state->error)) {
966                 return -1;
967         }
968
969         *vfs_aio_state = state->vfs_aio_state;
970
971         return state->ret;
972 }
973
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)
977 {
978         ssize_t ret;
979         glfs_fd_t *glfd = NULL;
980
981         START_PROFILE_BYTES(syscall_pwrite, n);
982
983         glfd = vfs_gluster_fetch_glfd(handle, fsp);
984         if (glfd == NULL) {
985                 END_PROFILE_BYTES(syscall_pwrite);
986                 DBG_ERR("Failed to fetch gluster fd\n");
987                 return -1;
988         }
989
990 #ifdef HAVE_GFAPI_VER_7_6
991         ret = glfs_pwrite(glfd, data, n, offset, 0, NULL, NULL);
992 #else
993         ret = glfs_pwrite(glfd, data, n, offset, 0);
994 #endif
995         END_PROFILE_BYTES(syscall_pwrite);
996
997         return ret;
998 }
999
1000 static off_t vfs_gluster_lseek(struct vfs_handle_struct *handle,
1001                                files_struct *fsp, off_t offset, int whence)
1002 {
1003         off_t ret = 0;
1004         glfs_fd_t *glfd = NULL;
1005
1006         START_PROFILE(syscall_lseek);
1007
1008         glfd = vfs_gluster_fetch_glfd(handle, fsp);
1009         if (glfd == NULL) {
1010                 END_PROFILE(syscall_lseek);
1011                 DBG_ERR("Failed to fetch gluster fd\n");
1012                 return -1;
1013         }
1014
1015         ret = glfs_lseek(glfd, offset, whence);
1016         END_PROFILE(syscall_lseek);
1017
1018         return ret;
1019 }
1020
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)
1025 {
1026         errno = ENOTSUP;
1027         return -1;
1028 }
1029
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)
1033 {
1034         errno = ENOTSUP;
1035         return -1;
1036 }
1037
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)
1043 {
1044         int ret;
1045
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);
1050
1051         return ret;
1052 }
1053
1054 struct vfs_gluster_fsync_state {
1055         ssize_t ret;
1056         glfs_fd_t *fd;
1057
1058         struct vfs_aio_state vfs_aio_state;
1059         SMBPROFILE_BYTES_ASYNC_STATE(profile_bytes);
1060 };
1061
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);
1065
1066 static struct tevent_req *vfs_gluster_fsync_send(struct vfs_handle_struct
1067                                                  *handle, TALLOC_CTX *mem_ctx,
1068                                                  struct tevent_context *ev,
1069                                                  files_struct *fsp)
1070 {
1071         struct tevent_req *req, *subreq;
1072         struct vfs_gluster_fsync_state *state;
1073
1074         glfs_fd_t *glfd = vfs_gluster_fetch_glfd(handle, fsp);
1075         if (glfd == NULL) {
1076                 DBG_ERR("Failed to fetch gluster fd\n");
1077                 return NULL;
1078         }
1079
1080         req = tevent_req_create(mem_ctx, &state, struct vfs_gluster_fsync_state);
1081         if (req == NULL) {
1082                 return NULL;
1083         }
1084
1085         state->ret = -1;
1086         state->fd = glfd;
1087
1088         SMBPROFILE_BYTES_ASYNC_START(syscall_asys_fsync, profile_p,
1089                                      state->profile_bytes, 0);
1090         SMBPROFILE_BYTES_ASYNC_SET_IDLE(state->profile_bytes);
1091
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);
1096         }
1097         tevent_req_set_callback(subreq, vfs_gluster_fsync_done, req);
1098
1099         talloc_set_destructor(state, vfs_gluster_fsync_state_destructor);
1100
1101         return req;
1102 }
1103
1104 static void vfs_gluster_fsync_do(void *private_data)
1105 {
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;
1110
1111         SMBPROFILE_BYTES_ASYNC_SET_BUSY(state->profile_bytes);
1112
1113         PROFILE_TIMESTAMP(&start_time);
1114
1115         do {
1116 #ifdef HAVE_GFAPI_VER_7_6
1117                 state->ret = glfs_fsync(state->fd, NULL, NULL);
1118 #else
1119                 state->ret = glfs_fsync(state->fd);
1120 #endif
1121         } while ((state->ret == -1) && (errno == EINTR));
1122
1123         if (state->ret == -1) {
1124                 state->vfs_aio_state.error = errno;
1125         }
1126
1127         PROFILE_TIMESTAMP(&end_time);
1128
1129         state->vfs_aio_state.duration = nsec_time_diff(&end_time, &start_time);
1130
1131         SMBPROFILE_BYTES_ASYNC_SET_IDLE(state->profile_bytes);
1132 }
1133
1134 static int vfs_gluster_fsync_state_destructor(struct vfs_gluster_fsync_state *state)
1135 {
1136         return -1;
1137 }
1138
1139 static void vfs_gluster_fsync_done(struct tevent_req *subreq)
1140 {
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);
1145         int ret;
1146
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);
1151         if (ret != 0) {
1152                 if (ret != EAGAIN) {
1153                         tevent_req_error(req, ret);
1154                         return;
1155                 }
1156                 /*
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.
1161                  */
1162                 vfs_gluster_fsync_do(state);
1163         }
1164
1165         tevent_req_done(req);
1166 }
1167
1168 static int vfs_gluster_fsync_recv(struct tevent_req *req,
1169                                   struct vfs_aio_state *vfs_aio_state)
1170 {
1171         struct vfs_gluster_fsync_state *state = tevent_req_data(
1172                 req, struct vfs_gluster_fsync_state);
1173
1174         if (tevent_req_is_unix_error(req, &vfs_aio_state->error)) {
1175                 return -1;
1176         }
1177
1178         *vfs_aio_state = state->vfs_aio_state;
1179         return state->ret;
1180 }
1181
1182 static int vfs_gluster_stat(struct vfs_handle_struct *handle,
1183                             struct smb_filename *smb_fname)
1184 {
1185         struct stat st;
1186         int ret;
1187
1188         START_PROFILE(syscall_stat);
1189         ret = glfs_stat(handle->data, smb_fname->base_name, &st);
1190         if (ret == 0) {
1191                 smb_stat_ex_from_stat(&smb_fname->st, &st);
1192         }
1193         if (ret < 0 && errno != ENOENT) {
1194                 DEBUG(0, ("glfs_stat(%s) failed: %s\n",
1195                           smb_fname->base_name, strerror(errno)));
1196         }
1197         END_PROFILE(syscall_stat);
1198
1199         return ret;
1200 }
1201
1202 static int vfs_gluster_fstat(struct vfs_handle_struct *handle,
1203                              files_struct *fsp, SMB_STRUCT_STAT *sbuf)
1204 {
1205         struct stat st;
1206         int ret;
1207         glfs_fd_t *glfd = NULL;
1208
1209         START_PROFILE(syscall_fstat);
1210
1211         glfd = vfs_gluster_fetch_glfd(handle, fsp);
1212         if (glfd == NULL) {
1213                 END_PROFILE(syscall_fstat);
1214                 DBG_ERR("Failed to fetch gluster fd\n");
1215                 return -1;
1216         }
1217
1218         ret = glfs_fstat(glfd, &st);
1219         if (ret == 0) {
1220                 smb_stat_ex_from_stat(sbuf, &st);
1221         }
1222         if (ret < 0) {
1223                 DEBUG(0, ("glfs_fstat(%d) failed: %s\n",
1224                           fsp->fh->fd, strerror(errno)));
1225         }
1226         END_PROFILE(syscall_fstat);
1227
1228         return ret;
1229 }
1230
1231 static int vfs_gluster_lstat(struct vfs_handle_struct *handle,
1232                              struct smb_filename *smb_fname)
1233 {
1234         struct stat st;
1235         int ret;
1236
1237         START_PROFILE(syscall_lstat);
1238         ret = glfs_lstat(handle->data, smb_fname->base_name, &st);
1239         if (ret == 0) {
1240                 smb_stat_ex_from_stat(&smb_fname->st, &st);
1241         }
1242         if (ret < 0 && errno != ENOENT) {
1243                 DEBUG(0, ("glfs_lstat(%s) failed: %s\n",
1244                           smb_fname->base_name, strerror(errno)));
1245         }
1246         END_PROFILE(syscall_lstat);
1247
1248         return ret;
1249 }
1250
1251 static uint64_t vfs_gluster_get_alloc_size(struct vfs_handle_struct *handle,
1252                                            files_struct *fsp,
1253                                            const SMB_STRUCT_STAT *sbuf)
1254 {
1255         uint64_t ret;
1256
1257         START_PROFILE(syscall_get_alloc_size);
1258         ret = sbuf->st_ex_blocks * 512;
1259         END_PROFILE(syscall_get_alloc_size);
1260
1261         return ret;
1262 }
1263
1264 static int vfs_gluster_unlinkat(struct vfs_handle_struct *handle,
1265                         struct files_struct *dirfsp,
1266                         const struct smb_filename *smb_fname,
1267                         int flags)
1268 {
1269         int ret;
1270
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);
1275         } else {
1276                 ret = glfs_unlink(handle->data, smb_fname->base_name);
1277         }
1278         END_PROFILE(syscall_unlinkat);
1279
1280         return ret;
1281 }
1282
1283 static int vfs_gluster_chmod(struct vfs_handle_struct *handle,
1284                                 const struct smb_filename *smb_fname,
1285                                 mode_t mode)
1286 {
1287         int ret;
1288
1289         START_PROFILE(syscall_chmod);
1290         ret = glfs_chmod(handle->data, smb_fname->base_name, mode);
1291         END_PROFILE(syscall_chmod);
1292
1293         return ret;
1294 }
1295
1296 static int vfs_gluster_fchmod(struct vfs_handle_struct *handle,
1297                               files_struct *fsp, mode_t mode)
1298 {
1299         int ret;
1300         glfs_fd_t *glfd = NULL;
1301
1302         START_PROFILE(syscall_fchmod);
1303
1304         glfd = vfs_gluster_fetch_glfd(handle, fsp);
1305         if (glfd == NULL) {
1306                 END_PROFILE(syscall_fchmod);
1307                 DBG_ERR("Failed to fetch gluster fd\n");
1308                 return -1;
1309         }
1310
1311         ret = glfs_fchmod(glfd, mode);
1312         END_PROFILE(syscall_fchmod);
1313
1314         return ret;
1315 }
1316
1317 static int vfs_gluster_fchown(struct vfs_handle_struct *handle,
1318                               files_struct *fsp, uid_t uid, gid_t gid)
1319 {
1320         int ret;
1321         glfs_fd_t *glfd = NULL;
1322
1323         START_PROFILE(syscall_fchown);
1324
1325         glfd = vfs_gluster_fetch_glfd(handle, fsp);
1326         if (glfd == NULL) {
1327                 END_PROFILE(syscall_fchown);
1328                 DBG_ERR("Failed to fetch gluster fd\n");
1329                 return -1;
1330         }
1331
1332         ret = glfs_fchown(glfd, uid, gid);
1333         END_PROFILE(syscall_fchown);
1334
1335         return ret;
1336 }
1337
1338 static int vfs_gluster_lchown(struct vfs_handle_struct *handle,
1339                         const struct smb_filename *smb_fname,
1340                         uid_t uid,
1341                         gid_t gid)
1342 {
1343         int ret;
1344
1345         START_PROFILE(syscall_lchown);
1346         ret = glfs_lchown(handle->data, smb_fname->base_name, uid, gid);
1347         END_PROFILE(syscall_lchown);
1348
1349         return ret;
1350 }
1351
1352 static int vfs_gluster_chdir(struct vfs_handle_struct *handle,
1353                         const struct smb_filename *smb_fname)
1354 {
1355         int ret;
1356
1357         START_PROFILE(syscall_chdir);
1358         ret = glfs_chdir(handle->data, smb_fname->base_name);
1359         END_PROFILE(syscall_chdir);
1360
1361         return ret;
1362 }
1363
1364 static struct smb_filename *vfs_gluster_getwd(struct vfs_handle_struct *handle,
1365                                 TALLOC_CTX *ctx)
1366 {
1367         char *cwd;
1368         char *ret;
1369         struct smb_filename *smb_fname = NULL;
1370
1371         START_PROFILE(syscall_getwd);
1372
1373         cwd = SMB_CALLOC_ARRAY(char, PATH_MAX);
1374         if (cwd == NULL) {
1375                 END_PROFILE(syscall_getwd);
1376                 return NULL;
1377         }
1378
1379         ret = glfs_getcwd(handle->data, cwd, PATH_MAX - 1);
1380         END_PROFILE(syscall_getwd);
1381
1382         if (ret == NULL) {
1383                 SAFE_FREE(cwd);
1384                 return NULL;
1385         }
1386         smb_fname = synthetic_smb_fname(ctx,
1387                                         ret,
1388                                         NULL,
1389                                         NULL,
1390                                         0);
1391         SAFE_FREE(cwd);
1392         return smb_fname;
1393 }
1394
1395 static int vfs_gluster_ntimes(struct vfs_handle_struct *handle,
1396                               const struct smb_filename *smb_fname,
1397                               struct smb_file_time *ft)
1398 {
1399         int ret = -1;
1400         struct timespec times[2];
1401
1402         START_PROFILE(syscall_ntimes);
1403
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;
1407         } else {
1408                 times[0].tv_sec = ft->atime.tv_sec;
1409                 times[0].tv_nsec = ft->atime.tv_nsec;
1410         }
1411
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;
1415         } else {
1416                 times[1].tv_sec = ft->mtime.tv_sec;
1417                 times[1].tv_nsec = ft->mtime.tv_nsec;
1418         }
1419
1420         if ((timespec_compare(&times[0],
1421                               &smb_fname->st.st_ex_atime) == 0) &&
1422             (timespec_compare(&times[1],
1423                               &smb_fname->st.st_ex_mtime) == 0)) {
1424                 END_PROFILE(syscall_ntimes);
1425                 return 0;
1426         }
1427
1428         ret = glfs_utimens(handle->data, smb_fname->base_name, times);
1429         END_PROFILE(syscall_ntimes);
1430
1431         return ret;
1432 }
1433
1434 static int vfs_gluster_ftruncate(struct vfs_handle_struct *handle,
1435                                  files_struct *fsp, off_t offset)
1436 {
1437         int ret;
1438         glfs_fd_t *glfd = NULL;
1439
1440         START_PROFILE(syscall_ftruncate);
1441
1442         glfd = vfs_gluster_fetch_glfd(handle, fsp);
1443         if (glfd == NULL) {
1444                 END_PROFILE(syscall_ftruncate);
1445                 DBG_ERR("Failed to fetch gluster fd\n");
1446                 return -1;
1447         }
1448
1449 #ifdef HAVE_GFAPI_VER_7_6
1450         ret = glfs_ftruncate(glfd, offset, NULL, NULL);
1451 #else
1452         ret = glfs_ftruncate(glfd, offset);
1453 #endif
1454         END_PROFILE(syscall_ftruncate);
1455
1456         return ret;
1457 }
1458
1459 static int vfs_gluster_fallocate(struct vfs_handle_struct *handle,
1460                                  struct files_struct *fsp,
1461                                  uint32_t mode,
1462                                  off_t offset, off_t len)
1463 {
1464         int ret;
1465 #ifdef HAVE_GFAPI_VER_6
1466         glfs_fd_t *glfd = NULL;
1467         int keep_size, punch_hole;
1468
1469         START_PROFILE(syscall_fallocate);
1470
1471         glfd = vfs_gluster_fetch_glfd(handle, fsp);
1472         if (glfd == NULL) {
1473                 END_PROFILE(syscall_fallocate);
1474                 DBG_ERR("Failed to fetch gluster fd\n");
1475                 return -1;
1476         }
1477
1478         keep_size = mode & VFS_FALLOCATE_FL_KEEP_SIZE;
1479         punch_hole = mode & VFS_FALLOCATE_FL_PUNCH_HOLE;
1480
1481         mode &= ~(VFS_FALLOCATE_FL_KEEP_SIZE|VFS_FALLOCATE_FL_PUNCH_HOLE);
1482         if (mode != 0) {
1483                 END_PROFILE(syscall_fallocate);
1484                 errno = ENOTSUP;
1485                 return -1;
1486         }
1487
1488         if (punch_hole) {
1489                 ret = glfs_discard(glfd, offset, len);
1490                 if (ret != 0) {
1491                         DBG_DEBUG("glfs_discard failed: %s\n",
1492                                   strerror(errno));
1493                 }
1494         }
1495
1496         ret = glfs_fallocate(glfd, keep_size, offset, len);
1497         END_PROFILE(syscall_fallocate);
1498 #else
1499         errno = ENOTSUP;
1500         ret = -1;
1501 #endif
1502         return ret;
1503 }
1504
1505 static struct smb_filename *vfs_gluster_realpath(struct vfs_handle_struct *handle,
1506                                 TALLOC_CTX *ctx,
1507                                 const struct smb_filename *smb_fname)
1508 {
1509         char *result = NULL;
1510         struct smb_filename *result_fname = NULL;
1511         char *resolved_path = NULL;
1512
1513         START_PROFILE(syscall_realpath);
1514
1515         resolved_path = SMB_MALLOC_ARRAY(char, PATH_MAX+1);
1516         if (resolved_path == NULL) {
1517                 END_PROFILE(syscall_realpath);
1518                 errno = ENOMEM;
1519                 return NULL;
1520         }
1521
1522         result = glfs_realpath(handle->data,
1523                         smb_fname->base_name,
1524                         resolved_path);
1525         if (result != NULL) {
1526                 result_fname = synthetic_smb_fname(ctx, result, NULL, NULL, 0);
1527         }
1528
1529         SAFE_FREE(resolved_path);
1530         END_PROFILE(syscall_realpath);
1531
1532         return result_fname;
1533 }
1534
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)
1538 {
1539         struct flock flock = { 0, };
1540         int ret;
1541         glfs_fd_t *glfd = NULL;
1542         bool ok = false;
1543
1544         START_PROFILE(syscall_fcntl_lock);
1545
1546         glfd = vfs_gluster_fetch_glfd(handle, fsp);
1547         if (glfd == NULL) {
1548                 DBG_ERR("Failed to fetch gluster fd\n");
1549                 ok = false;
1550                 goto out;
1551         }
1552
1553         flock.l_type = type;
1554         flock.l_whence = SEEK_SET;
1555         flock.l_start = offset;
1556         flock.l_len = count;
1557         flock.l_pid = 0;
1558
1559         ret = glfs_posix_lock(glfd, op, &flock);
1560
1561         if (op == F_GETLK) {
1562                 /* lock query, true if someone else has locked */
1563                 if ((ret != -1) &&
1564                     (flock.l_type != F_UNLCK) &&
1565                     (flock.l_pid != 0) && (flock.l_pid != getpid())) {
1566                         ok = true;
1567                         goto out;
1568                 }
1569                 /* not me */
1570                 ok = false;
1571                 goto out;
1572         }
1573
1574         if (ret == -1) {
1575                 ok = false;
1576                 goto out;
1577         }
1578
1579         ok = true;
1580 out:
1581         END_PROFILE(syscall_fcntl_lock);
1582
1583         return ok;
1584 }
1585
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)
1589 {
1590         errno = ENOSYS;
1591         return -1;
1592 }
1593
1594 static int vfs_gluster_fcntl(vfs_handle_struct *handle,
1595                              files_struct *fsp, int cmd, va_list cmd_arg)
1596 {
1597         /*
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.
1600          */
1601         if (cmd == F_GETFL) {
1602                 return 0;
1603         } else if (cmd == F_SETFL) {
1604                 va_list dup_cmd_arg;
1605                 int opt;
1606
1607                 va_copy(dup_cmd_arg, cmd_arg);
1608                 opt = va_arg(dup_cmd_arg, int);
1609                 va_end(dup_cmd_arg);
1610                 if (opt == 0) {
1611                         return 0;
1612                 }
1613                 DBG_ERR("unexpected fcntl SETFL(%d)\n", opt);
1614                 goto err_out;
1615         }
1616         DBG_ERR("unexpected fcntl: %d\n", cmd);
1617 err_out:
1618         errno = EINVAL;
1619         return -1;
1620 }
1621
1622 static int vfs_gluster_linux_setlease(struct vfs_handle_struct *handle,
1623                                       files_struct *fsp, int leasetype)
1624 {
1625         errno = ENOSYS;
1626         return -1;
1627 }
1628
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)
1632 {
1633         struct flock flock = { 0, };
1634         int ret;
1635         glfs_fd_t *glfd = NULL;
1636
1637         START_PROFILE(syscall_fcntl_getlock);
1638
1639         glfd = vfs_gluster_fetch_glfd(handle, fsp);
1640         if (glfd == NULL) {
1641                 END_PROFILE(syscall_fcntl_getlock);
1642                 DBG_ERR("Failed to fetch gluster fd\n");
1643                 return false;
1644         }
1645
1646         flock.l_type = *ptype;
1647         flock.l_whence = SEEK_SET;
1648         flock.l_start = *poffset;
1649         flock.l_len = *pcount;
1650         flock.l_pid = 0;
1651
1652         ret = glfs_posix_lock(glfd, F_GETLK, &flock);
1653
1654         if (ret == -1) {
1655                 END_PROFILE(syscall_fcntl_getlock);
1656                 return false;
1657         }
1658
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);
1664
1665         return true;
1666 }
1667
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)
1672 {
1673         int ret;
1674
1675         START_PROFILE(syscall_symlinkat);
1676         SMB_ASSERT(dirfsp == dirfsp->conn->cwd_fsp);
1677         ret = glfs_symlink(handle->data,
1678                         link_target,
1679                         new_smb_fname->base_name);
1680         END_PROFILE(syscall_symlinkat);
1681
1682         return ret;
1683 }
1684
1685 static int vfs_gluster_readlinkat(struct vfs_handle_struct *handle,
1686                                 files_struct *dirfsp,
1687                                 const struct smb_filename *smb_fname,
1688                                 char *buf,
1689                                 size_t bufsiz)
1690 {
1691         int ret;
1692
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);
1697
1698         return ret;
1699 }
1700
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,
1706                                 int flags)
1707 {
1708         int ret;
1709
1710         START_PROFILE(syscall_linkat);
1711
1712         SMB_ASSERT(srcfsp == srcfsp->conn->cwd_fsp);
1713         SMB_ASSERT(dstfsp == dstfsp->conn->cwd_fsp);
1714
1715         ret = glfs_link(handle->data,
1716                         old_smb_fname->base_name,
1717                         new_smb_fname->base_name);
1718         END_PROFILE(syscall_linkat);
1719
1720         return ret;
1721 }
1722
1723 static int vfs_gluster_mknodat(struct vfs_handle_struct *handle,
1724                                 files_struct *dirfsp,
1725                                 const struct smb_filename *smb_fname,
1726                                 mode_t mode,
1727                                 SMB_DEV_T dev)
1728 {
1729         int ret;
1730
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);
1735
1736         return ret;
1737 }
1738
1739 static int vfs_gluster_chflags(struct vfs_handle_struct *handle,
1740                                 const struct smb_filename *smb_fname,
1741                                 unsigned int flags)
1742 {
1743         errno = ENOSYS;
1744         return -1;
1745 }
1746
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)
1750 {
1751         int ret;
1752         char key_buf[GLUSTER_NAME_MAX + 64];
1753         char val_buf[GLUSTER_NAME_MAX + 1];
1754
1755         if (strlen(name) >= GLUSTER_NAME_MAX) {
1756                 errno = ENAMETOOLONG;
1757                 return -1;
1758         }
1759
1760         snprintf(key_buf, GLUSTER_NAME_MAX + 64,
1761                  "glusterfs.get_real_filename:%s", name);
1762
1763         ret = glfs_getxattr(handle->data, path, key_buf, val_buf,
1764                             GLUSTER_NAME_MAX + 1);
1765         if (ret == -1) {
1766                 if (errno == ENOATTR) {
1767                         errno = ENOENT;
1768                 }
1769                 return -1;
1770         }
1771
1772         *found_name = talloc_strdup(mem_ctx, val_buf);
1773         if (found_name[0] == NULL) {
1774                 errno = ENOMEM;
1775                 return -1;
1776         }
1777         return 0;
1778 }
1779
1780 static const char *vfs_gluster_connectpath(struct vfs_handle_struct *handle,
1781                                 const struct smb_filename *smb_fname)
1782 {
1783         return handle->conn->connectpath;
1784 }
1785
1786 /* EA Operations */
1787
1788 static ssize_t vfs_gluster_getxattr(struct vfs_handle_struct *handle,
1789                                 const struct smb_filename *smb_fname,
1790                                 const char *name,
1791                                 void *value,
1792                                 size_t size)
1793 {
1794         return glfs_getxattr(handle->data, smb_fname->base_name,
1795                              name, value, size);
1796 }
1797
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)
1801 {
1802         glfs_fd_t *glfd = vfs_gluster_fetch_glfd(handle, fsp);
1803         if (glfd == NULL) {
1804                 DBG_ERR("Failed to fetch gluster fd\n");
1805                 return -1;
1806         }
1807
1808         return glfs_fgetxattr(glfd, name, value, size);
1809 }
1810
1811 static ssize_t vfs_gluster_listxattr(struct vfs_handle_struct *handle,
1812                                 const struct smb_filename *smb_fname,
1813                                 char *list,
1814                                 size_t size)
1815 {
1816         return glfs_listxattr(handle->data, smb_fname->base_name, list, size);
1817 }
1818
1819 static ssize_t vfs_gluster_flistxattr(struct vfs_handle_struct *handle,
1820                                       files_struct *fsp, char *list,
1821                                       size_t size)
1822 {
1823         glfs_fd_t *glfd = vfs_gluster_fetch_glfd(handle, fsp);
1824         if (glfd == NULL) {
1825                 DBG_ERR("Failed to fetch gluster fd\n");
1826                 return -1;
1827         }
1828
1829         return glfs_flistxattr(glfd, list, size);
1830 }
1831
1832 static int vfs_gluster_removexattr(struct vfs_handle_struct *handle,
1833                                 const struct smb_filename *smb_fname,
1834                                 const char *name)
1835 {
1836         return glfs_removexattr(handle->data, smb_fname->base_name, name);
1837 }
1838
1839 static int vfs_gluster_fremovexattr(struct vfs_handle_struct *handle,
1840                                     files_struct *fsp, const char *name)
1841 {
1842         glfs_fd_t *glfd = vfs_gluster_fetch_glfd(handle, fsp);
1843         if (glfd == NULL) {
1844                 DBG_ERR("Failed to fetch gluster fd\n");
1845                 return -1;
1846         }
1847
1848         return glfs_fremovexattr(glfd, name);
1849 }
1850
1851 static int vfs_gluster_setxattr(struct vfs_handle_struct *handle,
1852                                 const struct smb_filename *smb_fname,
1853                                 const char *name,
1854                                 const void *value, size_t size, int flags)
1855 {
1856         return glfs_setxattr(handle->data, smb_fname->base_name, name, value, size, flags);
1857 }
1858
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)
1862 {
1863         glfs_fd_t *glfd = vfs_gluster_fetch_glfd(handle, fsp);
1864         if (glfd == NULL) {
1865                 DBG_ERR("Failed to fetch gluster fd\n");
1866                 return -1;
1867         }
1868
1869         return glfs_fsetxattr(glfd, name, value, size, flags);
1870 }
1871
1872 /* AIO Operations */
1873
1874 static bool vfs_gluster_aio_force(struct vfs_handle_struct *handle,
1875                                   files_struct *fsp)
1876 {
1877         return false;
1878 }
1879
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)
1885 {
1886         TALLOC_CTX *frame = talloc_stackframe();
1887         NTSTATUS status = NT_STATUS_NO_MEMORY;
1888         int ret;
1889         char *msdfs_link = NULL;
1890
1891         SMB_ASSERT(dirfsp == dirfsp->conn->cwd_fsp);
1892
1893         /* Form the msdfs_link contents */
1894         msdfs_link = msdfs_link_string(frame,
1895                                         reflist,
1896                                         referral_count);
1897         if (msdfs_link == NULL) {
1898                 goto out;
1899         }
1900
1901         ret = glfs_symlink(handle->data,
1902                         msdfs_link,
1903                         smb_fname->base_name);
1904         if (ret == 0) {
1905                 status = NT_STATUS_OK;
1906         } else {
1907                 status = map_nt_error_from_unix(errno);
1908         }
1909
1910   out:
1911
1912         TALLOC_FREE(frame);
1913         return status;
1914 }
1915
1916 /*
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.
1923  */
1924
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)
1931 {
1932         NTSTATUS status = NT_STATUS_NO_MEMORY;
1933         size_t bufsize;
1934         char *link_target = NULL;
1935         int referral_len;
1936         bool ok;
1937 #if defined(HAVE_BROKEN_READLINK)
1938         char link_target_buf[PATH_MAX];
1939 #else
1940         char link_target_buf[7];
1941 #endif
1942
1943         SMB_ASSERT(dirfsp == dirfsp->conn->cwd_fsp);
1944
1945         if (ppreflist == NULL && preferral_count == NULL) {
1946                 /*
1947                  * We're only checking if this is a DFS
1948                  * redirect. We don't need to return data.
1949                  */
1950                 bufsize = sizeof(link_target_buf);
1951                 link_target = link_target_buf;
1952         } else {
1953                 bufsize = PATH_MAX;
1954                 link_target = talloc_array(mem_ctx, char, bufsize);
1955                 if (!link_target) {
1956                         goto err;
1957                 }
1958         }
1959
1960         referral_len = glfs_readlink(handle->data,
1961                                 smb_fname->base_name,
1962                                 link_target,
1963                                 bufsize - 1);
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;
1968                 } else {
1969                         status = map_nt_error_from_unix(errno);
1970                         DBG_ERR("Error reading "
1971                                 "msdfs link %s: %s\n",
1972                                 smb_fname->base_name,
1973                                 strerror(errno));
1974                 }
1975                 goto err;
1976         }
1977         link_target[referral_len] = '\0';
1978
1979         DBG_INFO("%s -> %s\n",
1980                         smb_fname->base_name,
1981                         link_target);
1982
1983         if (!strnequal(link_target, "msdfs:", 6)) {
1984                 status = NT_STATUS_OBJECT_TYPE_MISMATCH;
1985                 goto err;
1986         }
1987
1988         if (ppreflist == NULL && preferral_count == NULL) {
1989                 /* Early return for checking if this is a DFS link. */
1990                 return NT_STATUS_OK;
1991         }
1992
1993         ok = parse_msdfs_symlink(mem_ctx,
1994                         lp_msdfs_shuffle_referrals(SNUM(handle->conn)),
1995                         link_target,
1996                         ppreflist,
1997                         preferral_count);
1998
1999         if (ok) {
2000                 status = NT_STATUS_OK;
2001         } else {
2002                 status = NT_STATUS_NO_MEMORY;
2003         }
2004
2005   err:
2006
2007         if (link_target != link_target_buf) {
2008                 TALLOC_FREE(link_target);
2009         }
2010         return status;
2011 }
2012
2013 static struct vfs_fn_pointers glusterfs_fns = {
2014
2015         /* Disk Operations */
2016
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,
2024
2025         .get_dfs_referrals_fn = NULL,
2026
2027         /* Directory Operations */
2028
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,
2036
2037         /* File Operations */
2038
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,
2054
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,
2060
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,
2087
2088         .brl_lock_windows_fn = NULL,
2089         .brl_unlock_windows_fn = NULL,
2090         .strict_lock_check_fn = NULL,
2091         .translate_name_fn = NULL,
2092         .fsctl_fn = NULL,
2093
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,
2099
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,
2108
2109         /* EA Operations */
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,
2120
2121         /* AIO Operations */
2122         .aio_force_fn = vfs_gluster_aio_force,
2123
2124         /* Durable handle Operations */
2125         .durable_cookie_fn = NULL,
2126         .durable_disconnect_fn = NULL,
2127         .durable_reconnect_fn = NULL,
2128 };
2129
2130 static_decl_vfs;
2131 NTSTATUS vfs_glusterfs_init(TALLOC_CTX *ctx)
2132 {
2133         return smb_register_vfs(SMB_VFS_INTERFACE_VERSION,
2134                                 "glusterfs", &glusterfs_fns);
2135 }