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