s3: VFS: Remove SMB_VFS_CHMOD_ACL().
[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
49 #define DEFAULT_VOLFILE_SERVER "localhost"
50
51 static int read_fd = -1;
52 static int write_fd = -1;
53 static struct tevent_fd *aio_read_event = NULL;
54
55 /**
56  * Helper to convert struct stat to struct stat_ex.
57  */
58 static void smb_stat_ex_from_stat(struct stat_ex *dst, const struct stat *src)
59 {
60         ZERO_STRUCTP(dst);
61
62         dst->st_ex_dev = src->st_dev;
63         dst->st_ex_ino = src->st_ino;
64         dst->st_ex_mode = src->st_mode;
65         dst->st_ex_nlink = src->st_nlink;
66         dst->st_ex_uid = src->st_uid;
67         dst->st_ex_gid = src->st_gid;
68         dst->st_ex_rdev = src->st_rdev;
69         dst->st_ex_size = src->st_size;
70         dst->st_ex_atime.tv_sec = src->st_atime;
71         dst->st_ex_mtime.tv_sec = src->st_mtime;
72         dst->st_ex_ctime.tv_sec = src->st_ctime;
73         dst->st_ex_btime.tv_sec = src->st_mtime;
74         dst->st_ex_blksize = src->st_blksize;
75         dst->st_ex_blocks = src->st_blocks;
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 }
83
84 /* pre-opened glfs_t */
85
86 static struct glfs_preopened {
87         char *volume;
88         char *connectpath;
89         glfs_t *fs;
90         int ref;
91         struct glfs_preopened *next, *prev;
92 } *glfs_preopened;
93
94
95 static int glfs_set_preopened(const char *volume, const char *connectpath, glfs_t *fs)
96 {
97         struct glfs_preopened *entry = NULL;
98
99         entry = talloc_zero(NULL, struct glfs_preopened);
100         if (!entry) {
101                 errno = ENOMEM;
102                 return -1;
103         }
104
105         entry->volume = talloc_strdup(entry, volume);
106         if (!entry->volume) {
107                 talloc_free(entry);
108                 errno = ENOMEM;
109                 return -1;
110         }
111
112         entry->connectpath = talloc_strdup(entry, connectpath);
113         if (entry->connectpath == NULL) {
114                 talloc_free(entry);
115                 errno = ENOMEM;
116                 return -1;
117         }
118
119         entry->fs = fs;
120         entry->ref = 1;
121
122         DLIST_ADD(glfs_preopened, entry);
123
124         return 0;
125 }
126
127 static glfs_t *glfs_find_preopened(const char *volume, const char *connectpath)
128 {
129         struct glfs_preopened *entry = NULL;
130
131         for (entry = glfs_preopened; entry; entry = entry->next) {
132                 if (strcmp(entry->volume, volume) == 0 &&
133                     strcmp(entry->connectpath, connectpath) == 0)
134                 {
135                         entry->ref++;
136                         return entry->fs;
137                 }
138         }
139
140         return NULL;
141 }
142
143 static void glfs_clear_preopened(glfs_t *fs)
144 {
145         struct glfs_preopened *entry = NULL;
146
147         for (entry = glfs_preopened; entry; entry = entry->next) {
148                 if (entry->fs == fs) {
149                         if (--entry->ref)
150                                 return;
151
152                         DLIST_REMOVE(glfs_preopened, entry);
153
154                         glfs_fini(entry->fs);
155                         talloc_free(entry);
156                 }
157         }
158 }
159
160 static int vfs_gluster_set_volfile_servers(glfs_t *fs,
161                                            const char *volfile_servers)
162 {
163         char *server = NULL;
164         int   server_count = 0;
165         int   server_success = 0;
166         int   ret = -1;
167         TALLOC_CTX *frame = talloc_stackframe();
168
169         DBG_INFO("servers list %s\n", volfile_servers);
170
171         while (next_token_talloc(frame, &volfile_servers, &server, " \t")) {
172                 char *transport = NULL;
173                 char *host = NULL;
174                 int   port = 0;
175
176                 server_count++;
177                 DBG_INFO("server %d %s\n", server_count, server);
178
179                 /* Determine the transport type */
180                 if (strncmp(server, "unix+", 5) == 0) {
181                         port = 0;
182                         transport = talloc_strdup(frame, "unix");
183                         if (!transport) {
184                                 errno = ENOMEM;
185                                 goto out;
186                         }
187                         host = talloc_strdup(frame, server + 5);
188                         if (!host) {
189                                 errno = ENOMEM;
190                                 goto out;
191                         }
192                 } else {
193                         char *p = NULL;
194                         char *port_index = NULL;
195
196                         if (strncmp(server, "tcp+", 4) == 0) {
197                                 server += 4;
198                         }
199
200                         /* IPv6 is enclosed in []
201                          * ':' before ']' is part of IPv6
202                          * ':' after  ']' indicates port
203                          */
204                         p = server;
205                         if (server[0] == '[') {
206                                 server++;
207                                 p = index(server, ']');
208                                 if (p == NULL) {
209                                         /* Malformed IPv6 */
210                                         continue;
211                                 }
212                                 p[0] = '\0';
213                                 p++;
214                         }
215
216                         port_index = index(p, ':');
217
218                         if (port_index == NULL) {
219                                 port = 0;
220                         } else {
221                                 port = atoi(port_index + 1);
222                                 port_index[0] = '\0';
223                         }
224                         transport = talloc_strdup(frame, "tcp");
225                         if (!transport) {
226                                 errno = ENOMEM;
227                                 goto out;
228                         }
229                         host = talloc_strdup(frame, server);
230                         if (!host) {
231                                 errno = ENOMEM;
232                                 goto out;
233                         }
234                 }
235
236                 DBG_INFO("Calling set volfile server with params "
237                          "transport=%s, host=%s, port=%d\n", transport,
238                           host, port);
239
240                 ret = glfs_set_volfile_server(fs, transport, host, port);
241                 if (ret < 0) {
242                         DBG_WARNING("Failed to set volfile_server "
243                                     "transport=%s, host=%s, port=%d (%s)\n",
244                                     transport, host, port, strerror(errno));
245                 } else {
246                         server_success++;
247                 }
248         }
249
250 out:
251         if (server_count == 0) {
252                 ret = -1;
253         } else if (server_success < server_count) {
254                 DBG_WARNING("Failed to set %d out of %d servers parsed\n",
255                             server_count - server_success, server_count);
256                 ret = 0;
257         }
258
259         TALLOC_FREE(frame);
260         return ret;
261 }
262
263 /* Disk Operations */
264
265 static int vfs_gluster_connect(struct vfs_handle_struct *handle,
266                                const char *service,
267                                const char *user)
268 {
269         const char *volfile_servers;
270         const char *volume;
271         char *logfile;
272         int loglevel;
273         glfs_t *fs = NULL;
274         TALLOC_CTX *tmp_ctx;
275         int ret = 0;
276
277         tmp_ctx = talloc_new(NULL);
278         if (tmp_ctx == NULL) {
279                 ret = -1;
280                 goto done;
281         }
282         logfile = lp_parm_talloc_string(tmp_ctx, SNUM(handle->conn), "glusterfs",
283                                        "logfile", NULL);
284
285         loglevel = lp_parm_int(SNUM(handle->conn), "glusterfs", "loglevel", -1);
286
287         volfile_servers = lp_parm_talloc_string(tmp_ctx, SNUM(handle->conn),
288                                                "glusterfs", "volfile_server",
289                                                NULL);
290         if (volfile_servers == NULL) {
291                 volfile_servers = DEFAULT_VOLFILE_SERVER;
292         }
293
294         volume = lp_parm_const_string(SNUM(handle->conn), "glusterfs", "volume",
295                                       NULL);
296         if (volume == NULL) {
297                 volume = service;
298         }
299
300         fs = glfs_find_preopened(volume, handle->conn->connectpath);
301         if (fs) {
302                 goto done;
303         }
304
305         fs = glfs_new(volume);
306         if (fs == NULL) {
307                 ret = -1;
308                 goto done;
309         }
310
311         ret = vfs_gluster_set_volfile_servers(fs, volfile_servers);
312         if (ret < 0) {
313                 DBG_ERR("Failed to set volfile_servers from list %s\n",
314                         volfile_servers);
315                 goto done;
316         }
317
318         ret = glfs_set_xlator_option(fs, "*-md-cache", "cache-posix-acl",
319                                      "true");
320         if (ret < 0) {
321                 DEBUG(0, ("%s: Failed to set xlator options\n", volume));
322                 goto done;
323         }
324
325
326         ret = glfs_set_xlator_option(fs, "*-snapview-client",
327                                      "snapdir-entry-path",
328                                      handle->conn->connectpath);
329         if (ret < 0) {
330                 DEBUG(0, ("%s: Failed to set xlator option:"
331                           " snapdir-entry-path\n", volume));
332                 goto done;
333         }
334
335         ret = glfs_set_logging(fs, logfile, loglevel);
336         if (ret < 0) {
337                 DEBUG(0, ("%s: Failed to set logfile %s loglevel %d\n",
338                           volume, logfile, loglevel));
339                 goto done;
340         }
341
342         ret = glfs_init(fs);
343         if (ret < 0) {
344                 DEBUG(0, ("%s: Failed to initialize volume (%s)\n",
345                           volume, strerror(errno)));
346                 goto done;
347         }
348
349         ret = glfs_set_preopened(volume, handle->conn->connectpath, fs);
350         if (ret < 0) {
351                 DEBUG(0, ("%s: Failed to register volume (%s)\n",
352                           volume, strerror(errno)));
353                 goto done;
354         }
355
356         /*
357          * The shadow_copy2 module will fail to export subdirectories
358          * of a gluster volume unless we specify the mount point,
359          * because the detection fails if the file system is not
360          * locally mounted:
361          * https://bugzilla.samba.org/show_bug.cgi?id=13091
362          */
363         lp_do_parameter(SNUM(handle->conn), "shadow:mountpoint", "/");
364
365 done:
366         if (ret < 0) {
367                 if (fs)
368                         glfs_fini(fs);
369         } else {
370                 DBG_ERR("%s: Initialized volume from servers %s\n",
371                         volume, volfile_servers);
372                 handle->data = fs;
373         }
374         talloc_free(tmp_ctx);
375         return ret;
376 }
377
378 static void vfs_gluster_disconnect(struct vfs_handle_struct *handle)
379 {
380         glfs_t *fs = NULL;
381
382         fs = handle->data;
383
384         glfs_clear_preopened(fs);
385 }
386
387 static uint64_t vfs_gluster_disk_free(struct vfs_handle_struct *handle,
388                                 const struct smb_filename *smb_fname,
389                                 uint64_t *bsize_p,
390                                 uint64_t *dfree_p,
391                                 uint64_t *dsize_p)
392 {
393         struct statvfs statvfs = { 0, };
394         int ret;
395
396         ret = glfs_statvfs(handle->data, smb_fname->base_name, &statvfs);
397         if (ret < 0) {
398                 return -1;
399         }
400
401         if (bsize_p != NULL) {
402                 *bsize_p = (uint64_t)statvfs.f_bsize; /* Block size */
403         }
404         if (dfree_p != NULL) {
405                 *dfree_p = (uint64_t)statvfs.f_bavail; /* Available Block units */
406         }
407         if (dsize_p != NULL) {
408                 *dsize_p = (uint64_t)statvfs.f_blocks; /* Total Block units */
409         }
410
411         return (uint64_t)statvfs.f_bavail;
412 }
413
414 static int vfs_gluster_get_quota(struct vfs_handle_struct *handle,
415                                 const struct smb_filename *smb_fname,
416                                 enum SMB_QUOTA_TYPE qtype,
417                                 unid_t id,
418                                 SMB_DISK_QUOTA *qt)
419 {
420         errno = ENOSYS;
421         return -1;
422 }
423
424 static int
425 vfs_gluster_set_quota(struct vfs_handle_struct *handle,
426                       enum SMB_QUOTA_TYPE qtype, unid_t id, SMB_DISK_QUOTA *qt)
427 {
428         errno = ENOSYS;
429         return -1;
430 }
431
432 static int vfs_gluster_statvfs(struct vfs_handle_struct *handle,
433                                 const struct smb_filename *smb_fname,
434                                 struct vfs_statvfs_struct *vfs_statvfs)
435 {
436         struct statvfs statvfs = { 0, };
437         int ret;
438
439         ret = glfs_statvfs(handle->data, smb_fname->base_name, &statvfs);
440         if (ret < 0) {
441                 DEBUG(0, ("glfs_statvfs(%s) failed: %s\n",
442                           smb_fname->base_name, strerror(errno)));
443                 return -1;
444         }
445
446         ZERO_STRUCTP(vfs_statvfs);
447
448         vfs_statvfs->OptimalTransferSize = statvfs.f_frsize;
449         vfs_statvfs->BlockSize = statvfs.f_bsize;
450         vfs_statvfs->TotalBlocks = statvfs.f_blocks;
451         vfs_statvfs->BlocksAvail = statvfs.f_bfree;
452         vfs_statvfs->UserBlocksAvail = statvfs.f_bavail;
453         vfs_statvfs->TotalFileNodes = statvfs.f_files;
454         vfs_statvfs->FreeFileNodes = statvfs.f_ffree;
455         vfs_statvfs->FsIdentifier = statvfs.f_fsid;
456         vfs_statvfs->FsCapabilities =
457             FILE_CASE_SENSITIVE_SEARCH | FILE_CASE_PRESERVED_NAMES;
458
459         return ret;
460 }
461
462 static uint32_t vfs_gluster_fs_capabilities(struct vfs_handle_struct *handle,
463                                             enum timestamp_set_resolution *p_ts_res)
464 {
465         uint32_t caps = FILE_CASE_SENSITIVE_SEARCH | FILE_CASE_PRESERVED_NAMES;
466
467 #ifdef HAVE_GFAPI_VER_6
468         caps |= FILE_SUPPORTS_SPARSE_FILES;
469 #endif
470
471 #ifdef STAT_HAVE_NSEC
472         *p_ts_res = TIMESTAMP_SET_NT_OR_BETTER;
473 #endif
474
475         return caps;
476 }
477
478 static DIR *vfs_gluster_opendir(struct vfs_handle_struct *handle,
479                                 const struct smb_filename *smb_fname,
480                                 const char *mask,
481                                 uint32_t attributes)
482 {
483         glfs_fd_t *fd;
484
485         fd = glfs_opendir(handle->data, smb_fname->base_name);
486         if (fd == NULL) {
487                 DEBUG(0, ("glfs_opendir(%s) failed: %s\n",
488                           smb_fname->base_name, strerror(errno)));
489         }
490
491         return (DIR *) fd;
492 }
493
494 static DIR *vfs_gluster_fdopendir(struct vfs_handle_struct *handle,
495                                   files_struct *fsp, const char *mask,
496                                   uint32_t attributes)
497 {
498         return (DIR *) *(glfs_fd_t **)VFS_FETCH_FSP_EXTENSION(handle, fsp);
499 }
500
501 static int vfs_gluster_closedir(struct vfs_handle_struct *handle, DIR *dirp)
502 {
503         return glfs_closedir((void *)dirp);
504 }
505
506 static struct dirent *vfs_gluster_readdir(struct vfs_handle_struct *handle,
507                                           DIR *dirp, SMB_STRUCT_STAT *sbuf)
508 {
509         static char direntbuf[512];
510         int ret;
511         struct stat stat;
512         struct dirent *dirent = 0;
513
514         if (sbuf != NULL) {
515                 ret = glfs_readdirplus_r((void *)dirp, &stat, (void *)direntbuf,
516                                          &dirent);
517         } else {
518                 ret = glfs_readdir_r((void *)dirp, (void *)direntbuf, &dirent);
519         }
520
521         if ((ret < 0) || (dirent == NULL)) {
522                 return NULL;
523         }
524
525         if (sbuf != NULL) {
526                 smb_stat_ex_from_stat(sbuf, &stat);
527         }
528
529         return dirent;
530 }
531
532 static long vfs_gluster_telldir(struct vfs_handle_struct *handle, DIR *dirp)
533 {
534         return glfs_telldir((void *)dirp);
535 }
536
537 static void vfs_gluster_seekdir(struct vfs_handle_struct *handle, DIR *dirp,
538                                 long offset)
539 {
540         glfs_seekdir((void *)dirp, offset);
541 }
542
543 static void vfs_gluster_rewinddir(struct vfs_handle_struct *handle, DIR *dirp)
544 {
545         glfs_seekdir((void *)dirp, 0);
546 }
547
548 static int vfs_gluster_mkdir(struct vfs_handle_struct *handle,
549                              const struct smb_filename *smb_fname,
550                              mode_t mode)
551 {
552         return glfs_mkdir(handle->data, smb_fname->base_name, mode);
553 }
554
555 static int vfs_gluster_rmdir(struct vfs_handle_struct *handle,
556                         const struct smb_filename *smb_fname)
557 {
558         return glfs_rmdir(handle->data, smb_fname->base_name);
559 }
560
561 static int vfs_gluster_open(struct vfs_handle_struct *handle,
562                             struct smb_filename *smb_fname, files_struct *fsp,
563                             int flags, mode_t mode)
564 {
565         glfs_fd_t *glfd;
566         glfs_fd_t **p_tmp;
567
568         if (flags & O_DIRECTORY) {
569                 glfd = glfs_opendir(handle->data, smb_fname->base_name);
570         } else if (flags & O_CREAT) {
571                 glfd = glfs_creat(handle->data, smb_fname->base_name, flags,
572                                   mode);
573         } else {
574                 glfd = glfs_open(handle->data, smb_fname->base_name, flags);
575         }
576
577         if (glfd == NULL) {
578                 return -1;
579         }
580         p_tmp = VFS_ADD_FSP_EXTENSION(handle, fsp, glfs_fd_t *, NULL);
581         *p_tmp = glfd;
582         /* An arbitrary value for error reporting, so you know its us. */
583         return 13371337;
584 }
585
586 static int vfs_gluster_close(struct vfs_handle_struct *handle,
587                              files_struct *fsp)
588 {
589         glfs_fd_t *glfd;
590         glfd = *(glfs_fd_t **)VFS_FETCH_FSP_EXTENSION(handle, fsp);
591         VFS_REMOVE_FSP_EXTENSION(handle, fsp);
592         return glfs_close(glfd);
593 }
594
595 static ssize_t vfs_gluster_pread(struct vfs_handle_struct *handle,
596                                  files_struct *fsp, void *data, size_t n,
597                                  off_t offset)
598 {
599         return glfs_pread(*(glfs_fd_t **)VFS_FETCH_FSP_EXTENSION(handle, fsp), data, n, offset, 0);
600 }
601
602 struct glusterfs_aio_state;
603
604 struct glusterfs_aio_wrapper {
605         struct glusterfs_aio_state *state;
606 };
607
608 struct glusterfs_aio_state {
609         ssize_t ret;
610         struct tevent_req *req;
611         bool cancelled;
612         struct vfs_aio_state vfs_aio_state;
613         struct timespec start;
614 };
615
616 static int aio_wrapper_destructor(struct glusterfs_aio_wrapper *wrap)
617 {
618         if (wrap->state != NULL) {
619                 wrap->state->cancelled = true;
620         }
621
622         return 0;
623 }
624
625 /*
626  * This function is the callback that will be called on glusterfs
627  * threads once the async IO submitted is complete. To notify
628  * Samba of the completion we use a pipe based queue.
629  */
630 static void aio_glusterfs_done(glfs_fd_t *fd, ssize_t ret, void *data)
631 {
632         struct glusterfs_aio_state *state = NULL;
633         int sts = 0;
634         struct timespec end;
635
636         state = (struct glusterfs_aio_state *)data;
637
638         PROFILE_TIMESTAMP(&end);
639
640         if (ret < 0) {
641                 state->ret = -1;
642                 state->vfs_aio_state.error = errno;
643         } else {
644                 state->ret = ret;
645         }
646         state->vfs_aio_state.duration = nsec_time_diff(&end, &state->start);
647
648         /*
649          * Write the state pointer to glusterfs_aio_state to the
650          * pipe, so we can call tevent_req_done() from the main thread,
651          * because tevent_req_done() is not designed to be executed in
652          * the multithread environment, so tevent_req_done() must be
653          * executed from the smbd main thread.
654          *
655          * write(2) on pipes with sizes under _POSIX_PIPE_BUF
656          * in size is atomic, without this, the use op pipes in this
657          * code would not work.
658          *
659          * sys_write is a thin enough wrapper around write(2)
660          * that we can trust it here.
661          */
662
663         sts = sys_write(write_fd, &state, sizeof(struct glusterfs_aio_state *));
664         if (sts < 0) {
665                 DEBUG(0,("\nWrite to pipe failed (%s)", strerror(errno)));
666         }
667
668         return;
669 }
670
671 /*
672  * Read each req off the pipe and process it.
673  */
674 static void aio_tevent_fd_done(struct tevent_context *event_ctx,
675                                 struct tevent_fd *fde,
676                                 uint16_t flags, void *data)
677 {
678         struct tevent_req *req = NULL;
679         struct glusterfs_aio_state *state = NULL;
680         int sts = 0;
681
682         /*
683          * read(2) on pipes is atomic if the needed data is available
684          * in the pipe, per SUS and POSIX.  Because we always write
685          * to the pipe in sizeof(struct tevent_req *) chunks, we can
686          * always read in those chunks, atomically.
687          *
688          * sys_read is a thin enough wrapper around read(2) that we
689          * can trust it here.
690          */
691
692         sts = sys_read(read_fd, &state, sizeof(struct glusterfs_aio_state *));
693
694         if (sts < 0) {
695                 DEBUG(0,("\nRead from pipe failed (%s)", strerror(errno)));
696         }
697
698         /* if we've cancelled the op, there is no req, so just clean up. */
699         if (state->cancelled == true) {
700                 TALLOC_FREE(state);
701                 return;
702         }
703
704         req = state->req;
705
706         if (req) {
707                 tevent_req_done(req);
708         }
709         return;
710 }
711
712 static bool init_gluster_aio(struct vfs_handle_struct *handle)
713 {
714         int fds[2];
715         int ret = -1;
716
717         if (read_fd != -1) {
718                 /*
719                  * Already initialized.
720                  */
721                 return true;
722         }
723
724         ret = pipe(fds);
725         if (ret == -1) {
726                 goto fail;
727         }
728
729         read_fd = fds[0];
730         write_fd = fds[1];
731
732         aio_read_event = tevent_add_fd(handle->conn->sconn->ev_ctx,
733                                         NULL,
734                                         read_fd,
735                                         TEVENT_FD_READ,
736                                         aio_tevent_fd_done,
737                                         NULL);
738         if (aio_read_event == NULL) {
739                 goto fail;
740         }
741
742         return true;
743 fail:
744         TALLOC_FREE(aio_read_event);
745         if (read_fd != -1) {
746                 close(read_fd);
747                 close(write_fd);
748                 read_fd = -1;
749                 write_fd = -1;
750         }
751         return false;
752 }
753
754 static struct glusterfs_aio_state *aio_state_create(TALLOC_CTX *mem_ctx)
755 {
756         struct tevent_req *req = NULL;
757         struct glusterfs_aio_state *state = NULL;
758         struct glusterfs_aio_wrapper *wrapper = NULL;
759
760         req = tevent_req_create(mem_ctx, &wrapper, struct glusterfs_aio_wrapper);
761
762         if (req == NULL) {
763                 return NULL;
764         }
765
766         state = talloc_zero(NULL, struct glusterfs_aio_state);
767
768         if (state == NULL) {
769                 TALLOC_FREE(req);
770                 return NULL;
771         }
772
773         talloc_set_destructor(wrapper, aio_wrapper_destructor);
774         state->cancelled = false;
775         state->req = req;
776
777         wrapper->state = state;
778
779         return state;
780 }
781
782 static struct tevent_req *vfs_gluster_pread_send(struct vfs_handle_struct
783                                                   *handle, TALLOC_CTX *mem_ctx,
784                                                   struct tevent_context *ev,
785                                                   files_struct *fsp,
786                                                   void *data, size_t n,
787                                                   off_t offset)
788 {
789         struct glusterfs_aio_state *state = NULL;
790         struct tevent_req *req = NULL;
791         int ret = 0;
792
793         state = aio_state_create(mem_ctx);
794
795         if (state == NULL) {
796                 return NULL;
797         }
798
799         req = state->req;
800
801         if (!init_gluster_aio(handle)) {
802                 tevent_req_error(req, EIO);
803                 return tevent_req_post(req, ev);
804         }
805
806         PROFILE_TIMESTAMP(&state->start);
807         ret = glfs_pread_async(*(glfs_fd_t **)VFS_FETCH_FSP_EXTENSION(handle,
808                                 fsp), data, n, offset, 0, aio_glusterfs_done,
809                                 state);
810         if (ret < 0) {
811                 tevent_req_error(req, -ret);
812                 return tevent_req_post(req, ev);
813         }
814
815         return req;
816 }
817
818 static struct tevent_req *vfs_gluster_pwrite_send(struct vfs_handle_struct
819                                                   *handle, TALLOC_CTX *mem_ctx,
820                                                   struct tevent_context *ev,
821                                                   files_struct *fsp,
822                                                   const void *data, size_t n,
823                                                   off_t offset)
824 {
825         struct glusterfs_aio_state *state = NULL;
826         struct tevent_req *req = NULL;
827         int ret = 0;
828
829         state = aio_state_create(mem_ctx);
830
831         if (state == NULL) {
832                 return NULL;
833         }
834
835         req = state->req;
836
837         if (!init_gluster_aio(handle)) {
838                 tevent_req_error(req, EIO);
839                 return tevent_req_post(req, ev);
840         }
841
842         PROFILE_TIMESTAMP(&state->start);
843         ret = glfs_pwrite_async(*(glfs_fd_t **)VFS_FETCH_FSP_EXTENSION(handle,
844                                 fsp), data, n, offset, 0, aio_glusterfs_done,
845                                 state);
846         if (ret < 0) {
847                 tevent_req_error(req, -ret);
848                 return tevent_req_post(req, ev);
849         }
850
851         return req;
852 }
853
854 static ssize_t vfs_gluster_recv(struct tevent_req *req,
855                                 struct vfs_aio_state *vfs_aio_state)
856 {
857         struct glusterfs_aio_wrapper *wrapper = NULL;
858         int ret = 0;
859
860         wrapper = tevent_req_data(req, struct glusterfs_aio_wrapper);
861
862         if (wrapper == NULL) {
863                 return -1;
864         }
865
866         if (wrapper->state == NULL) {
867                 return -1;
868         }
869
870         if (tevent_req_is_unix_error(req, &vfs_aio_state->error)) {
871                 return -1;
872         }
873
874         *vfs_aio_state = wrapper->state->vfs_aio_state;
875         ret = wrapper->state->ret;
876
877         /* Clean up the state, it is in a NULL context. */
878
879         TALLOC_FREE(wrapper->state);
880
881         return ret;
882 }
883
884 static ssize_t vfs_gluster_pwrite(struct vfs_handle_struct *handle,
885                                   files_struct *fsp, const void *data,
886                                   size_t n, off_t offset)
887 {
888         return glfs_pwrite(*(glfs_fd_t **)VFS_FETCH_FSP_EXTENSION(handle, fsp), data, n, offset, 0);
889 }
890
891 static off_t vfs_gluster_lseek(struct vfs_handle_struct *handle,
892                                files_struct *fsp, off_t offset, int whence)
893 {
894         return glfs_lseek(*(glfs_fd_t **)VFS_FETCH_FSP_EXTENSION(handle, fsp), offset, whence);
895 }
896
897 static ssize_t vfs_gluster_sendfile(struct vfs_handle_struct *handle, int tofd,
898                                     files_struct *fromfsp,
899                                     const DATA_BLOB *hdr,
900                                     off_t offset, size_t n)
901 {
902         errno = ENOTSUP;
903         return -1;
904 }
905
906 static ssize_t vfs_gluster_recvfile(struct vfs_handle_struct *handle,
907                                     int fromfd, files_struct *tofsp,
908                                     off_t offset, size_t n)
909 {
910         errno = ENOTSUP;
911         return -1;
912 }
913
914 static int vfs_gluster_rename(struct vfs_handle_struct *handle,
915                               const struct smb_filename *smb_fname_src,
916                               const struct smb_filename *smb_fname_dst)
917 {
918         return glfs_rename(handle->data, smb_fname_src->base_name,
919                            smb_fname_dst->base_name);
920 }
921
922 static struct tevent_req *vfs_gluster_fsync_send(struct vfs_handle_struct
923                                                  *handle, TALLOC_CTX *mem_ctx,
924                                                  struct tevent_context *ev,
925                                                  files_struct *fsp)
926 {
927         struct tevent_req *req = NULL;
928         struct glusterfs_aio_state *state = NULL;
929         int ret = 0;
930
931         state = aio_state_create(mem_ctx);
932
933         if (state == NULL) {
934                 return NULL;
935         }
936
937         req = state->req;
938
939         if (!init_gluster_aio(handle)) {
940                 tevent_req_error(req, EIO);
941                 return tevent_req_post(req, ev);
942         }
943
944         PROFILE_TIMESTAMP(&state->start);
945         ret = glfs_fsync_async(*(glfs_fd_t **)VFS_FETCH_FSP_EXTENSION(handle,
946                                 fsp), aio_glusterfs_done, state);
947         if (ret < 0) {
948                 tevent_req_error(req, -ret);
949                 return tevent_req_post(req, ev);
950         }
951         return req;
952 }
953
954 static int vfs_gluster_fsync_recv(struct tevent_req *req,
955                                   struct vfs_aio_state *vfs_aio_state)
956 {
957         /*
958          * Use implicit conversion ssize_t->int
959          */
960         return vfs_gluster_recv(req, vfs_aio_state);
961 }
962
963 static int vfs_gluster_stat(struct vfs_handle_struct *handle,
964                             struct smb_filename *smb_fname)
965 {
966         struct stat st;
967         int ret;
968
969         ret = glfs_stat(handle->data, smb_fname->base_name, &st);
970         if (ret == 0) {
971                 smb_stat_ex_from_stat(&smb_fname->st, &st);
972         }
973         if (ret < 0 && errno != ENOENT) {
974                 DEBUG(0, ("glfs_stat(%s) failed: %s\n",
975                           smb_fname->base_name, strerror(errno)));
976         }
977         return ret;
978 }
979
980 static int vfs_gluster_fstat(struct vfs_handle_struct *handle,
981                              files_struct *fsp, SMB_STRUCT_STAT *sbuf)
982 {
983         struct stat st;
984         int ret;
985
986         ret = glfs_fstat(*(glfs_fd_t **)VFS_FETCH_FSP_EXTENSION(handle, fsp), &st);
987         if (ret == 0) {
988                 smb_stat_ex_from_stat(sbuf, &st);
989         }
990         if (ret < 0) {
991                 DEBUG(0, ("glfs_fstat(%d) failed: %s\n",
992                           fsp->fh->fd, strerror(errno)));
993         }
994         return ret;
995 }
996
997 static int vfs_gluster_lstat(struct vfs_handle_struct *handle,
998                              struct smb_filename *smb_fname)
999 {
1000         struct stat st;
1001         int ret;
1002
1003         ret = glfs_lstat(handle->data, smb_fname->base_name, &st);
1004         if (ret == 0) {
1005                 smb_stat_ex_from_stat(&smb_fname->st, &st);
1006         }
1007         if (ret < 0 && errno != ENOENT) {
1008                 DEBUG(0, ("glfs_lstat(%s) failed: %s\n",
1009                           smb_fname->base_name, strerror(errno)));
1010         }
1011         return ret;
1012 }
1013
1014 static uint64_t vfs_gluster_get_alloc_size(struct vfs_handle_struct *handle,
1015                                            files_struct *fsp,
1016                                            const SMB_STRUCT_STAT *sbuf)
1017 {
1018         return sbuf->st_ex_blocks * 512;
1019 }
1020
1021 static int vfs_gluster_unlink(struct vfs_handle_struct *handle,
1022                               const struct smb_filename *smb_fname)
1023 {
1024         return glfs_unlink(handle->data, smb_fname->base_name);
1025 }
1026
1027 static int vfs_gluster_chmod(struct vfs_handle_struct *handle,
1028                                 const struct smb_filename *smb_fname,
1029                                 mode_t mode)
1030 {
1031         return glfs_chmod(handle->data, smb_fname->base_name, mode);
1032 }
1033
1034 static int vfs_gluster_fchmod(struct vfs_handle_struct *handle,
1035                               files_struct *fsp, mode_t mode)
1036 {
1037         return glfs_fchmod(*(glfs_fd_t **)VFS_FETCH_FSP_EXTENSION(handle, fsp), mode);
1038 }
1039
1040 static int vfs_gluster_chown(struct vfs_handle_struct *handle,
1041                         const struct smb_filename *smb_fname,
1042                         uid_t uid,
1043                         gid_t gid)
1044 {
1045         return glfs_chown(handle->data, smb_fname->base_name, uid, gid);
1046 }
1047
1048 static int vfs_gluster_fchown(struct vfs_handle_struct *handle,
1049                               files_struct *fsp, uid_t uid, gid_t gid)
1050 {
1051         return glfs_fchown(*(glfs_fd_t **)VFS_FETCH_FSP_EXTENSION(handle, fsp), uid, gid);
1052 }
1053
1054 static int vfs_gluster_lchown(struct vfs_handle_struct *handle,
1055                         const struct smb_filename *smb_fname,
1056                         uid_t uid,
1057                         gid_t gid)
1058 {
1059         return glfs_lchown(handle->data, smb_fname->base_name, uid, gid);
1060 }
1061
1062 static int vfs_gluster_chdir(struct vfs_handle_struct *handle,
1063                         const struct smb_filename *smb_fname)
1064 {
1065         return glfs_chdir(handle->data, smb_fname->base_name);
1066 }
1067
1068 static struct smb_filename *vfs_gluster_getwd(struct vfs_handle_struct *handle,
1069                                 TALLOC_CTX *ctx)
1070 {
1071         char *cwd;
1072         char *ret;
1073         struct smb_filename *smb_fname = NULL;
1074
1075         cwd = SMB_CALLOC_ARRAY(char, PATH_MAX);
1076         if (cwd == NULL) {
1077                 return NULL;
1078         }
1079
1080         ret = glfs_getcwd(handle->data, cwd, PATH_MAX - 1);
1081         if (ret == NULL) {
1082                 SAFE_FREE(cwd);
1083                 return NULL;
1084         }
1085         smb_fname = synthetic_smb_fname(ctx,
1086                                         ret,
1087                                         NULL,
1088                                         NULL,
1089                                         0);
1090         SAFE_FREE(cwd);
1091         return smb_fname;
1092 }
1093
1094 static int vfs_gluster_ntimes(struct vfs_handle_struct *handle,
1095                               const struct smb_filename *smb_fname,
1096                               struct smb_file_time *ft)
1097 {
1098         struct timespec times[2];
1099
1100         if (null_timespec(ft->atime)) {
1101                 times[0].tv_sec = smb_fname->st.st_ex_atime.tv_sec;
1102                 times[0].tv_nsec = smb_fname->st.st_ex_atime.tv_nsec;
1103         } else {
1104                 times[0].tv_sec = ft->atime.tv_sec;
1105                 times[0].tv_nsec = ft->atime.tv_nsec;
1106         }
1107
1108         if (null_timespec(ft->mtime)) {
1109                 times[1].tv_sec = smb_fname->st.st_ex_mtime.tv_sec;
1110                 times[1].tv_nsec = smb_fname->st.st_ex_mtime.tv_nsec;
1111         } else {
1112                 times[1].tv_sec = ft->mtime.tv_sec;
1113                 times[1].tv_nsec = ft->mtime.tv_nsec;
1114         }
1115
1116         if ((timespec_compare(&times[0],
1117                               &smb_fname->st.st_ex_atime) == 0) &&
1118             (timespec_compare(&times[1],
1119                               &smb_fname->st.st_ex_mtime) == 0)) {
1120                 return 0;
1121         }
1122
1123         return glfs_utimens(handle->data, smb_fname->base_name, times);
1124 }
1125
1126 static int vfs_gluster_ftruncate(struct vfs_handle_struct *handle,
1127                                  files_struct *fsp, off_t offset)
1128 {
1129         return glfs_ftruncate(*(glfs_fd_t **)VFS_FETCH_FSP_EXTENSION(handle, fsp), offset);
1130 }
1131
1132 static int vfs_gluster_fallocate(struct vfs_handle_struct *handle,
1133                                  struct files_struct *fsp,
1134                                  uint32_t mode,
1135                                  off_t offset, off_t len)
1136 {
1137 #ifdef HAVE_GFAPI_VER_6
1138         int keep_size, punch_hole;
1139
1140         keep_size = mode & VFS_FALLOCATE_FL_KEEP_SIZE;
1141         punch_hole = mode & VFS_FALLOCATE_FL_PUNCH_HOLE;
1142
1143         mode &= ~(VFS_FALLOCATE_FL_KEEP_SIZE|VFS_FALLOCATE_FL_PUNCH_HOLE);
1144         if (mode != 0) {
1145                 errno = ENOTSUP;
1146                 return -1;
1147         }
1148
1149         if (punch_hole) {
1150                 return glfs_discard(*(glfs_fd_t **)
1151                                     VFS_FETCH_FSP_EXTENSION(handle, fsp),
1152                                     offset, len);
1153         }
1154
1155         return glfs_fallocate(*(glfs_fd_t **)
1156                               VFS_FETCH_FSP_EXTENSION(handle, fsp),
1157                               keep_size, offset, len);
1158 #else
1159         errno = ENOTSUP;
1160         return -1;
1161 #endif
1162 }
1163
1164 static struct smb_filename *vfs_gluster_realpath(struct vfs_handle_struct *handle,
1165                                 TALLOC_CTX *ctx,
1166                                 const struct smb_filename *smb_fname)
1167 {
1168         char *result = NULL;
1169         struct smb_filename *result_fname = NULL;
1170         char *resolved_path = SMB_MALLOC_ARRAY(char, PATH_MAX+1);
1171
1172         if (resolved_path == NULL) {
1173                 errno = ENOMEM;
1174                 return NULL;
1175         }
1176
1177         result = glfs_realpath(handle->data,
1178                         smb_fname->base_name,
1179                         resolved_path);
1180         if (result != NULL) {
1181                 result_fname = synthetic_smb_fname(ctx, result, NULL, NULL, 0);
1182         }
1183
1184         SAFE_FREE(resolved_path);
1185         return result_fname;
1186 }
1187
1188 static bool vfs_gluster_lock(struct vfs_handle_struct *handle,
1189                              files_struct *fsp, int op, off_t offset,
1190                              off_t count, int type)
1191 {
1192         struct flock flock = { 0, };
1193         int ret;
1194
1195         flock.l_type = type;
1196         flock.l_whence = SEEK_SET;
1197         flock.l_start = offset;
1198         flock.l_len = count;
1199         flock.l_pid = 0;
1200
1201         ret = glfs_posix_lock(*(glfs_fd_t **)VFS_FETCH_FSP_EXTENSION(handle, fsp), op, &flock);
1202
1203         if (op == F_GETLK) {
1204                 /* lock query, true if someone else has locked */
1205                 if ((ret != -1) &&
1206                     (flock.l_type != F_UNLCK) &&
1207                     (flock.l_pid != 0) && (flock.l_pid != getpid()))
1208                         return true;
1209                 /* not me */
1210                 return false;
1211         }
1212
1213         if (ret == -1) {
1214                 return false;
1215         }
1216
1217         return true;
1218 }
1219
1220 static int vfs_gluster_kernel_flock(struct vfs_handle_struct *handle,
1221                                     files_struct *fsp, uint32_t share_mode,
1222                                     uint32_t access_mask)
1223 {
1224         errno = ENOSYS;
1225         return -1;
1226 }
1227
1228 static int vfs_gluster_linux_setlease(struct vfs_handle_struct *handle,
1229                                       files_struct *fsp, int leasetype)
1230 {
1231         errno = ENOSYS;
1232         return -1;
1233 }
1234
1235 static bool vfs_gluster_getlock(struct vfs_handle_struct *handle,
1236                                 files_struct *fsp, off_t *poffset,
1237                                 off_t *pcount, int *ptype, pid_t *ppid)
1238 {
1239         struct flock flock = { 0, };
1240         int ret;
1241
1242         flock.l_type = *ptype;
1243         flock.l_whence = SEEK_SET;
1244         flock.l_start = *poffset;
1245         flock.l_len = *pcount;
1246         flock.l_pid = 0;
1247
1248         ret = glfs_posix_lock(*(glfs_fd_t **)VFS_FETCH_FSP_EXTENSION(handle, fsp), F_GETLK, &flock);
1249
1250         if (ret == -1) {
1251                 return false;
1252         }
1253
1254         *ptype = flock.l_type;
1255         *poffset = flock.l_start;
1256         *pcount = flock.l_len;
1257         *ppid = flock.l_pid;
1258
1259         return true;
1260 }
1261
1262 static int vfs_gluster_symlink(struct vfs_handle_struct *handle,
1263                                 const char *link_target,
1264                                 const struct smb_filename *new_smb_fname)
1265 {
1266         return glfs_symlink(handle->data,
1267                         link_target,
1268                         new_smb_fname->base_name);
1269 }
1270
1271 static int vfs_gluster_readlink(struct vfs_handle_struct *handle,
1272                                 const struct smb_filename *smb_fname,
1273                                 char *buf,
1274                                 size_t bufsiz)
1275 {
1276         return glfs_readlink(handle->data, smb_fname->base_name, buf, bufsiz);
1277 }
1278
1279 static int vfs_gluster_link(struct vfs_handle_struct *handle,
1280                                 const struct smb_filename *old_smb_fname,
1281                                 const struct smb_filename *new_smb_fname)
1282 {
1283         return glfs_link(handle->data,
1284                         old_smb_fname->base_name,
1285                         new_smb_fname->base_name);
1286 }
1287
1288 static int vfs_gluster_mknod(struct vfs_handle_struct *handle,
1289                                 const struct smb_filename *smb_fname,
1290                                 mode_t mode,
1291                                 SMB_DEV_T dev)
1292 {
1293         return glfs_mknod(handle->data, smb_fname->base_name, mode, dev);
1294 }
1295
1296 static int vfs_gluster_chflags(struct vfs_handle_struct *handle,
1297                                 const struct smb_filename *smb_fname,
1298                                 unsigned int flags)
1299 {
1300         errno = ENOSYS;
1301         return -1;
1302 }
1303
1304 static int vfs_gluster_get_real_filename(struct vfs_handle_struct *handle,
1305                                          const char *path, const char *name,
1306                                          TALLOC_CTX *mem_ctx, char **found_name)
1307 {
1308         int ret;
1309         char key_buf[NAME_MAX + 64];
1310         char val_buf[NAME_MAX + 1];
1311
1312         if (strlen(name) >= NAME_MAX) {
1313                 errno = ENAMETOOLONG;
1314                 return -1;
1315         }
1316
1317         snprintf(key_buf, NAME_MAX + 64,
1318                  "glusterfs.get_real_filename:%s", name);
1319
1320         ret = glfs_getxattr(handle->data, path, key_buf, val_buf, NAME_MAX + 1);
1321         if (ret == -1) {
1322                 if (errno == ENODATA) {
1323                         errno = EOPNOTSUPP;
1324                 }
1325                 return -1;
1326         }
1327
1328         *found_name = talloc_strdup(mem_ctx, val_buf);
1329         if (found_name[0] == NULL) {
1330                 errno = ENOMEM;
1331                 return -1;
1332         }
1333         return 0;
1334 }
1335
1336 static const char *vfs_gluster_connectpath(struct vfs_handle_struct *handle,
1337                                 const struct smb_filename *smb_fname)
1338 {
1339         return handle->conn->connectpath;
1340 }
1341
1342 /* EA Operations */
1343
1344 static ssize_t vfs_gluster_getxattr(struct vfs_handle_struct *handle,
1345                                 const struct smb_filename *smb_fname,
1346                                 const char *name,
1347                                 void *value,
1348                                 size_t size)
1349 {
1350         return glfs_getxattr(handle->data, smb_fname->base_name,
1351                         name, value, size);
1352 }
1353
1354 static ssize_t vfs_gluster_fgetxattr(struct vfs_handle_struct *handle,
1355                                      files_struct *fsp, const char *name,
1356                                      void *value, size_t size)
1357 {
1358         return glfs_fgetxattr(*(glfs_fd_t **)VFS_FETCH_FSP_EXTENSION(handle, fsp), name, value, size);
1359 }
1360
1361 static ssize_t vfs_gluster_listxattr(struct vfs_handle_struct *handle,
1362                                 const struct smb_filename *smb_fname,
1363                                 char *list,
1364                                 size_t size)
1365 {
1366         return glfs_listxattr(handle->data, smb_fname->base_name, list, size);
1367 }
1368
1369 static ssize_t vfs_gluster_flistxattr(struct vfs_handle_struct *handle,
1370                                       files_struct *fsp, char *list,
1371                                       size_t size)
1372 {
1373         return glfs_flistxattr(*(glfs_fd_t **)VFS_FETCH_FSP_EXTENSION(handle, fsp), list, size);
1374 }
1375
1376 static int vfs_gluster_removexattr(struct vfs_handle_struct *handle,
1377                                 const struct smb_filename *smb_fname,
1378                                 const char *name)
1379 {
1380         return glfs_removexattr(handle->data, smb_fname->base_name, name);
1381 }
1382
1383 static int vfs_gluster_fremovexattr(struct vfs_handle_struct *handle,
1384                                     files_struct *fsp, const char *name)
1385 {
1386         return glfs_fremovexattr(*(glfs_fd_t **)VFS_FETCH_FSP_EXTENSION(handle, fsp), name);
1387 }
1388
1389 static int vfs_gluster_setxattr(struct vfs_handle_struct *handle,
1390                                 const struct smb_filename *smb_fname,
1391                                 const char *name,
1392                                 const void *value, size_t size, int flags)
1393 {
1394         return glfs_setxattr(handle->data, smb_fname->base_name, name, value, size, flags);
1395 }
1396
1397 static int vfs_gluster_fsetxattr(struct vfs_handle_struct *handle,
1398                                  files_struct *fsp, const char *name,
1399                                  const void *value, size_t size, int flags)
1400 {
1401         return glfs_fsetxattr(*(glfs_fd_t **)VFS_FETCH_FSP_EXTENSION(handle, fsp), name, value, size,
1402                               flags);
1403 }
1404
1405 /* AIO Operations */
1406
1407 static bool vfs_gluster_aio_force(struct vfs_handle_struct *handle,
1408                                   files_struct *fsp)
1409 {
1410         return false;
1411 }
1412
1413 static struct vfs_fn_pointers glusterfs_fns = {
1414
1415         /* Disk Operations */
1416
1417         .connect_fn = vfs_gluster_connect,
1418         .disconnect_fn = vfs_gluster_disconnect,
1419         .disk_free_fn = vfs_gluster_disk_free,
1420         .get_quota_fn = vfs_gluster_get_quota,
1421         .set_quota_fn = vfs_gluster_set_quota,
1422         .statvfs_fn = vfs_gluster_statvfs,
1423         .fs_capabilities_fn = vfs_gluster_fs_capabilities,
1424
1425         .get_dfs_referrals_fn = NULL,
1426
1427         /* Directory Operations */
1428
1429         .opendir_fn = vfs_gluster_opendir,
1430         .fdopendir_fn = vfs_gluster_fdopendir,
1431         .readdir_fn = vfs_gluster_readdir,
1432         .seekdir_fn = vfs_gluster_seekdir,
1433         .telldir_fn = vfs_gluster_telldir,
1434         .rewind_dir_fn = vfs_gluster_rewinddir,
1435         .mkdir_fn = vfs_gluster_mkdir,
1436         .rmdir_fn = vfs_gluster_rmdir,
1437         .closedir_fn = vfs_gluster_closedir,
1438
1439         /* File Operations */
1440
1441         .open_fn = vfs_gluster_open,
1442         .create_file_fn = NULL,
1443         .close_fn = vfs_gluster_close,
1444         .pread_fn = vfs_gluster_pread,
1445         .pread_send_fn = vfs_gluster_pread_send,
1446         .pread_recv_fn = vfs_gluster_recv,
1447         .pwrite_fn = vfs_gluster_pwrite,
1448         .pwrite_send_fn = vfs_gluster_pwrite_send,
1449         .pwrite_recv_fn = vfs_gluster_recv,
1450         .lseek_fn = vfs_gluster_lseek,
1451         .sendfile_fn = vfs_gluster_sendfile,
1452         .recvfile_fn = vfs_gluster_recvfile,
1453         .rename_fn = vfs_gluster_rename,
1454         .fsync_send_fn = vfs_gluster_fsync_send,
1455         .fsync_recv_fn = vfs_gluster_fsync_recv,
1456
1457         .stat_fn = vfs_gluster_stat,
1458         .fstat_fn = vfs_gluster_fstat,
1459         .lstat_fn = vfs_gluster_lstat,
1460         .get_alloc_size_fn = vfs_gluster_get_alloc_size,
1461         .unlink_fn = vfs_gluster_unlink,
1462
1463         .chmod_fn = vfs_gluster_chmod,
1464         .fchmod_fn = vfs_gluster_fchmod,
1465         .chown_fn = vfs_gluster_chown,
1466         .fchown_fn = vfs_gluster_fchown,
1467         .lchown_fn = vfs_gluster_lchown,
1468         .chdir_fn = vfs_gluster_chdir,
1469         .getwd_fn = vfs_gluster_getwd,
1470         .ntimes_fn = vfs_gluster_ntimes,
1471         .ftruncate_fn = vfs_gluster_ftruncate,
1472         .fallocate_fn = vfs_gluster_fallocate,
1473         .lock_fn = vfs_gluster_lock,
1474         .kernel_flock_fn = vfs_gluster_kernel_flock,
1475         .linux_setlease_fn = vfs_gluster_linux_setlease,
1476         .getlock_fn = vfs_gluster_getlock,
1477         .symlink_fn = vfs_gluster_symlink,
1478         .readlink_fn = vfs_gluster_readlink,
1479         .link_fn = vfs_gluster_link,
1480         .mknod_fn = vfs_gluster_mknod,
1481         .realpath_fn = vfs_gluster_realpath,
1482         .chflags_fn = vfs_gluster_chflags,
1483         .file_id_create_fn = NULL,
1484         .streaminfo_fn = NULL,
1485         .get_real_filename_fn = vfs_gluster_get_real_filename,
1486         .connectpath_fn = vfs_gluster_connectpath,
1487
1488         .brl_lock_windows_fn = NULL,
1489         .brl_unlock_windows_fn = NULL,
1490         .brl_cancel_windows_fn = NULL,
1491         .strict_lock_check_fn = NULL,
1492         .translate_name_fn = NULL,
1493         .fsctl_fn = NULL,
1494
1495         /* NT ACL Operations */
1496         .fget_nt_acl_fn = NULL,
1497         .get_nt_acl_fn = NULL,
1498         .fset_nt_acl_fn = NULL,
1499         .audit_file_fn = NULL,
1500
1501         /* Posix ACL Operations */
1502         .fchmod_acl_fn = NULL,  /* passthrough to default */
1503         .sys_acl_get_file_fn = posixacl_xattr_acl_get_file,
1504         .sys_acl_get_fd_fn = posixacl_xattr_acl_get_fd,
1505         .sys_acl_blob_get_file_fn = posix_sys_acl_blob_get_file,
1506         .sys_acl_blob_get_fd_fn = posix_sys_acl_blob_get_fd,
1507         .sys_acl_set_file_fn = posixacl_xattr_acl_set_file,
1508         .sys_acl_set_fd_fn = posixacl_xattr_acl_set_fd,
1509         .sys_acl_delete_def_file_fn = posixacl_xattr_acl_delete_def_file,
1510
1511         /* EA Operations */
1512         .getxattr_fn = vfs_gluster_getxattr,
1513         .fgetxattr_fn = vfs_gluster_fgetxattr,
1514         .listxattr_fn = vfs_gluster_listxattr,
1515         .flistxattr_fn = vfs_gluster_flistxattr,
1516         .removexattr_fn = vfs_gluster_removexattr,
1517         .fremovexattr_fn = vfs_gluster_fremovexattr,
1518         .setxattr_fn = vfs_gluster_setxattr,
1519         .fsetxattr_fn = vfs_gluster_fsetxattr,
1520
1521         /* AIO Operations */
1522         .aio_force_fn = vfs_gluster_aio_force,
1523
1524         /* Durable handle Operations */
1525         .durable_cookie_fn = NULL,
1526         .durable_disconnect_fn = NULL,
1527         .durable_reconnect_fn = NULL,
1528 };
1529
1530 static_decl_vfs;
1531 NTSTATUS vfs_glusterfs_init(TALLOC_CTX *ctx)
1532 {
1533         return smb_register_vfs(SMB_VFS_INTERFACE_VERSION,
1534                                 "glusterfs", &glusterfs_fns);
1535 }