s3: VFS: Change SMB_VFS_DISK_FREE to use const struct smb_filename * instead of const...
[metze/samba-autobuild/.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 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 done:
356         if (ret < 0) {
357                 if (fs)
358                         glfs_fini(fs);
359         } else {
360                 DBG_ERR("%s: Initialized volume from servers %s\n",
361                         volume, volfile_servers);
362                 handle->data = fs;
363         }
364         talloc_free(tmp_ctx);
365         return ret;
366 }
367
368 static void vfs_gluster_disconnect(struct vfs_handle_struct *handle)
369 {
370         glfs_t *fs = NULL;
371
372         fs = handle->data;
373
374         glfs_clear_preopened(fs);
375 }
376
377 static uint64_t vfs_gluster_disk_free(struct vfs_handle_struct *handle,
378                                 const struct smb_filename *smb_fname,
379                                 uint64_t *bsize_p,
380                                 uint64_t *dfree_p,
381                                 uint64_t *dsize_p)
382 {
383         struct statvfs statvfs = { 0, };
384         int ret;
385
386         ret = glfs_statvfs(handle->data, smb_fname->base_name, &statvfs);
387         if (ret < 0) {
388                 return -1;
389         }
390
391         if (bsize_p != NULL) {
392                 *bsize_p = (uint64_t)statvfs.f_bsize; /* Block size */
393         }
394         if (dfree_p != NULL) {
395                 *dfree_p = (uint64_t)statvfs.f_bavail; /* Available Block units */
396         }
397         if (dsize_p != NULL) {
398                 *dsize_p = (uint64_t)statvfs.f_blocks; /* Total Block units */
399         }
400
401         return (uint64_t)statvfs.f_bavail;
402 }
403
404 static int vfs_gluster_get_quota(struct vfs_handle_struct *handle,
405                                  const char *path,
406                                  enum SMB_QUOTA_TYPE qtype, unid_t id,
407                                  SMB_DISK_QUOTA *qt)
408 {
409         errno = ENOSYS;
410         return -1;
411 }
412
413 static int
414 vfs_gluster_set_quota(struct vfs_handle_struct *handle,
415                       enum SMB_QUOTA_TYPE qtype, unid_t id, SMB_DISK_QUOTA *qt)
416 {
417         errno = ENOSYS;
418         return -1;
419 }
420
421 static int vfs_gluster_statvfs(struct vfs_handle_struct *handle,
422                                const char *path,
423                                struct vfs_statvfs_struct *vfs_statvfs)
424 {
425         struct statvfs statvfs = { 0, };
426         int ret;
427
428         ret = glfs_statvfs(handle->data, path, &statvfs);
429         if (ret < 0) {
430                 DEBUG(0, ("glfs_statvfs(%s) failed: %s\n",
431                           path, strerror(errno)));
432                 return -1;
433         }
434
435         ZERO_STRUCTP(vfs_statvfs);
436
437         vfs_statvfs->OptimalTransferSize = statvfs.f_frsize;
438         vfs_statvfs->BlockSize = statvfs.f_bsize;
439         vfs_statvfs->TotalBlocks = statvfs.f_blocks;
440         vfs_statvfs->BlocksAvail = statvfs.f_bfree;
441         vfs_statvfs->UserBlocksAvail = statvfs.f_bavail;
442         vfs_statvfs->TotalFileNodes = statvfs.f_files;
443         vfs_statvfs->FreeFileNodes = statvfs.f_ffree;
444         vfs_statvfs->FsIdentifier = statvfs.f_fsid;
445         vfs_statvfs->FsCapabilities =
446             FILE_CASE_SENSITIVE_SEARCH | FILE_CASE_PRESERVED_NAMES;
447
448         return ret;
449 }
450
451 static uint32_t vfs_gluster_fs_capabilities(struct vfs_handle_struct *handle,
452                                             enum timestamp_set_resolution *p_ts_res)
453 {
454         uint32_t caps = FILE_CASE_SENSITIVE_SEARCH | FILE_CASE_PRESERVED_NAMES;
455
456 #ifdef STAT_HAVE_NSEC
457         *p_ts_res = TIMESTAMP_SET_NT_OR_BETTER;
458 #endif
459
460         return caps;
461 }
462
463 static DIR *vfs_gluster_opendir(struct vfs_handle_struct *handle,
464                                 const struct smb_filename *smb_fname,
465                                 const char *mask,
466                                 uint32_t attributes)
467 {
468         glfs_fd_t *fd;
469
470         fd = glfs_opendir(handle->data, smb_fname->base_name);
471         if (fd == NULL) {
472                 DEBUG(0, ("glfs_opendir(%s) failed: %s\n",
473                           smb_fname->base_name, strerror(errno)));
474         }
475
476         return (DIR *) fd;
477 }
478
479 static DIR *vfs_gluster_fdopendir(struct vfs_handle_struct *handle,
480                                   files_struct *fsp, const char *mask,
481                                   uint32_t attributes)
482 {
483         return (DIR *) *(glfs_fd_t **)VFS_FETCH_FSP_EXTENSION(handle, fsp);
484 }
485
486 static int vfs_gluster_closedir(struct vfs_handle_struct *handle, DIR *dirp)
487 {
488         return glfs_closedir((void *)dirp);
489 }
490
491 static struct dirent *vfs_gluster_readdir(struct vfs_handle_struct *handle,
492                                           DIR *dirp, SMB_STRUCT_STAT *sbuf)
493 {
494         static char direntbuf[512];
495         int ret;
496         struct stat stat;
497         struct dirent *dirent = 0;
498
499         if (sbuf != NULL) {
500                 ret = glfs_readdirplus_r((void *)dirp, &stat, (void *)direntbuf,
501                                          &dirent);
502         } else {
503                 ret = glfs_readdir_r((void *)dirp, (void *)direntbuf, &dirent);
504         }
505
506         if ((ret < 0) || (dirent == NULL)) {
507                 return NULL;
508         }
509
510         if (sbuf != NULL) {
511                 smb_stat_ex_from_stat(sbuf, &stat);
512         }
513
514         return dirent;
515 }
516
517 static long vfs_gluster_telldir(struct vfs_handle_struct *handle, DIR *dirp)
518 {
519         return glfs_telldir((void *)dirp);
520 }
521
522 static void vfs_gluster_seekdir(struct vfs_handle_struct *handle, DIR *dirp,
523                                 long offset)
524 {
525         glfs_seekdir((void *)dirp, offset);
526 }
527
528 static void vfs_gluster_rewinddir(struct vfs_handle_struct *handle, DIR *dirp)
529 {
530         glfs_seekdir((void *)dirp, 0);
531 }
532
533 static void vfs_gluster_init_search_op(struct vfs_handle_struct *handle,
534                                        DIR *dirp)
535 {
536         return;
537 }
538
539 static int vfs_gluster_mkdir(struct vfs_handle_struct *handle,
540                              const struct smb_filename *smb_fname,
541                              mode_t mode)
542 {
543         return glfs_mkdir(handle->data, smb_fname->base_name, mode);
544 }
545
546 static int vfs_gluster_rmdir(struct vfs_handle_struct *handle,
547                         const struct smb_filename *smb_fname)
548 {
549         return glfs_rmdir(handle->data, smb_fname->base_name);
550 }
551
552 static int vfs_gluster_open(struct vfs_handle_struct *handle,
553                             struct smb_filename *smb_fname, files_struct *fsp,
554                             int flags, mode_t mode)
555 {
556         glfs_fd_t *glfd;
557         glfs_fd_t **p_tmp;
558
559         if (flags & O_DIRECTORY) {
560                 glfd = glfs_opendir(handle->data, smb_fname->base_name);
561         } else if (flags & O_CREAT) {
562                 glfd = glfs_creat(handle->data, smb_fname->base_name, flags,
563                                   mode);
564         } else {
565                 glfd = glfs_open(handle->data, smb_fname->base_name, flags);
566         }
567
568         if (glfd == NULL) {
569                 return -1;
570         }
571         p_tmp = (glfs_fd_t **)VFS_ADD_FSP_EXTENSION(handle, fsp,
572                                                           glfs_fd_t *, NULL);
573         *p_tmp = glfd;
574         /* An arbitrary value for error reporting, so you know its us. */
575         return 13371337;
576 }
577
578 static int vfs_gluster_close(struct vfs_handle_struct *handle,
579                              files_struct *fsp)
580 {
581         glfs_fd_t *glfd;
582         glfd = *(glfs_fd_t **)VFS_FETCH_FSP_EXTENSION(handle, fsp);
583         VFS_REMOVE_FSP_EXTENSION(handle, fsp);
584         return glfs_close(glfd);
585 }
586
587 static ssize_t vfs_gluster_read(struct vfs_handle_struct *handle,
588                                 files_struct *fsp, void *data, size_t n)
589 {
590         return glfs_read(*(glfs_fd_t **)VFS_FETCH_FSP_EXTENSION(handle, fsp), data, n, 0);
591 }
592
593 static ssize_t vfs_gluster_pread(struct vfs_handle_struct *handle,
594                                  files_struct *fsp, void *data, size_t n,
595                                  off_t offset)
596 {
597         return glfs_pread(*(glfs_fd_t **)VFS_FETCH_FSP_EXTENSION(handle, fsp), data, n, offset, 0);
598 }
599
600 struct glusterfs_aio_state;
601
602 struct glusterfs_aio_wrapper {
603         struct glusterfs_aio_state *state;
604 };
605
606 struct glusterfs_aio_state {
607         ssize_t ret;
608         struct tevent_req *req;
609         bool cancelled;
610         struct vfs_aio_state vfs_aio_state;
611         struct timespec start;
612 };
613
614 static int aio_wrapper_destructor(struct glusterfs_aio_wrapper *wrap)
615 {
616         if (wrap->state != NULL) {
617                 wrap->state->cancelled = true;
618         }
619
620         return 0;
621 }
622
623 /*
624  * This function is the callback that will be called on glusterfs
625  * threads once the async IO submitted is complete. To notify
626  * Samba of the completion we use a pipe based queue.
627  */
628 static void aio_glusterfs_done(glfs_fd_t *fd, ssize_t ret, void *data)
629 {
630         struct glusterfs_aio_state *state = NULL;
631         int sts = 0;
632         struct timespec end;
633
634         state = (struct glusterfs_aio_state *)data;
635
636         PROFILE_TIMESTAMP(&end);
637
638         if (ret < 0) {
639                 state->ret = -1;
640                 state->vfs_aio_state.error = errno;
641         } else {
642                 state->ret = ret;
643         }
644         state->vfs_aio_state.duration = nsec_time_diff(&end, &state->start);
645
646         /*
647          * Write the state pointer to glusterfs_aio_state to the
648          * pipe, so we can call tevent_req_done() from the main thread,
649          * because tevent_req_done() is not designed to be executed in
650          * the multithread environment, so tevent_req_done() must be
651          * executed from the smbd main thread.
652          *
653          * write(2) on pipes with sizes under _POSIX_PIPE_BUF
654          * in size is atomic, without this, the use op pipes in this
655          * code would not work.
656          *
657          * sys_write is a thin enough wrapper around write(2)
658          * that we can trust it here.
659          */
660
661         sts = sys_write(write_fd, &state, sizeof(struct glusterfs_aio_state *));
662         if (sts < 0) {
663                 DEBUG(0,("\nWrite to pipe failed (%s)", strerror(errno)));
664         }
665
666         return;
667 }
668
669 /*
670  * Read each req off the pipe and process it.
671  */
672 static void aio_tevent_fd_done(struct tevent_context *event_ctx,
673                                 struct tevent_fd *fde,
674                                 uint16_t flags, void *data)
675 {
676         struct tevent_req *req = NULL;
677         struct glusterfs_aio_state *state = NULL;
678         int sts = 0;
679
680         /*
681          * read(2) on pipes is atomic if the needed data is available
682          * in the pipe, per SUS and POSIX.  Because we always write
683          * to the pipe in sizeof(struct tevent_req *) chunks, we can
684          * always read in those chunks, atomically.
685          *
686          * sys_read is a thin enough wrapper around read(2) that we
687          * can trust it here.
688          */
689
690         sts = sys_read(read_fd, &state, sizeof(struct glusterfs_aio_state *));
691
692         if (sts < 0) {
693                 DEBUG(0,("\nRead from pipe failed (%s)", strerror(errno)));
694         }
695
696         /* if we've cancelled the op, there is no req, so just clean up. */
697         if (state->cancelled == true) {
698                 TALLOC_FREE(state);
699                 return;
700         }
701
702         req = state->req;
703
704         if (req) {
705                 tevent_req_done(req);
706         }
707         return;
708 }
709
710 static bool init_gluster_aio(struct vfs_handle_struct *handle)
711 {
712         int fds[2];
713         int ret = -1;
714
715         if (read_fd != -1) {
716                 /*
717                  * Already initialized.
718                  */
719                 return true;
720         }
721
722         ret = pipe(fds);
723         if (ret == -1) {
724                 goto fail;
725         }
726
727         read_fd = fds[0];
728         write_fd = fds[1];
729
730         aio_read_event = tevent_add_fd(handle->conn->sconn->ev_ctx,
731                                         NULL,
732                                         read_fd,
733                                         TEVENT_FD_READ,
734                                         aio_tevent_fd_done,
735                                         NULL);
736         if (aio_read_event == NULL) {
737                 goto fail;
738         }
739
740         return true;
741 fail:
742         TALLOC_FREE(aio_read_event);
743         if (read_fd != -1) {
744                 close(read_fd);
745                 close(write_fd);
746                 read_fd = -1;
747                 write_fd = -1;
748         }
749         return false;
750 }
751
752 static struct glusterfs_aio_state *aio_state_create(TALLOC_CTX *mem_ctx)
753 {
754         struct tevent_req *req = NULL;
755         struct glusterfs_aio_state *state = NULL;
756         struct glusterfs_aio_wrapper *wrapper = NULL;
757
758         req = tevent_req_create(mem_ctx, &wrapper, struct glusterfs_aio_wrapper);
759
760         if (req == NULL) {
761                 return NULL;
762         }
763
764         state = talloc_zero(NULL, struct glusterfs_aio_state);
765
766         if (state == NULL) {
767                 TALLOC_FREE(req);
768                 return NULL;
769         }
770
771         talloc_set_destructor(wrapper, aio_wrapper_destructor);
772         state->cancelled = false;
773         state->req = req;
774
775         wrapper->state = state;
776
777         return state;
778 }
779
780 static struct tevent_req *vfs_gluster_pread_send(struct vfs_handle_struct
781                                                   *handle, TALLOC_CTX *mem_ctx,
782                                                   struct tevent_context *ev,
783                                                   files_struct *fsp,
784                                                   void *data, size_t n,
785                                                   off_t offset)
786 {
787         struct glusterfs_aio_state *state = NULL;
788         struct tevent_req *req = NULL;
789         int ret = 0;
790
791         state = aio_state_create(mem_ctx);
792
793         if (state == NULL) {
794                 return NULL;
795         }
796
797         req = state->req;
798
799         if (!init_gluster_aio(handle)) {
800                 tevent_req_error(req, EIO);
801                 return tevent_req_post(req, ev);
802         }
803
804         PROFILE_TIMESTAMP(&state->start);
805         ret = glfs_pread_async(*(glfs_fd_t **)VFS_FETCH_FSP_EXTENSION(handle,
806                                 fsp), data, n, offset, 0, aio_glusterfs_done,
807                                 state);
808         if (ret < 0) {
809                 tevent_req_error(req, -ret);
810                 return tevent_req_post(req, ev);
811         }
812
813         return req;
814 }
815
816 static struct tevent_req *vfs_gluster_pwrite_send(struct vfs_handle_struct
817                                                   *handle, TALLOC_CTX *mem_ctx,
818                                                   struct tevent_context *ev,
819                                                   files_struct *fsp,
820                                                   const void *data, size_t n,
821                                                   off_t offset)
822 {
823         struct glusterfs_aio_state *state = NULL;
824         struct tevent_req *req = NULL;
825         int ret = 0;
826
827         state = aio_state_create(mem_ctx);
828
829         if (state == NULL) {
830                 return NULL;
831         }
832
833         req = state->req;
834
835         if (!init_gluster_aio(handle)) {
836                 tevent_req_error(req, EIO);
837                 return tevent_req_post(req, ev);
838         }
839
840         PROFILE_TIMESTAMP(&state->start);
841         ret = glfs_pwrite_async(*(glfs_fd_t **)VFS_FETCH_FSP_EXTENSION(handle,
842                                 fsp), data, n, offset, 0, aio_glusterfs_done,
843                                 state);
844         if (ret < 0) {
845                 tevent_req_error(req, -ret);
846                 return tevent_req_post(req, ev);
847         }
848
849         return req;
850 }
851
852 static ssize_t vfs_gluster_recv(struct tevent_req *req,
853                                 struct vfs_aio_state *vfs_aio_state)
854 {
855         struct glusterfs_aio_wrapper *wrapper = NULL;
856         int ret = 0;
857
858         wrapper = tevent_req_data(req, struct glusterfs_aio_wrapper);
859
860         if (wrapper == NULL) {
861                 return -1;
862         }
863
864         if (wrapper->state == NULL) {
865                 return -1;
866         }
867
868         if (tevent_req_is_unix_error(req, &vfs_aio_state->error)) {
869                 return -1;
870         }
871
872         *vfs_aio_state = wrapper->state->vfs_aio_state;
873         ret = wrapper->state->ret;
874
875         /* Clean up the state, it is in a NULL context. */
876
877         TALLOC_FREE(wrapper->state);
878
879         return ret;
880 }
881
882 static ssize_t vfs_gluster_write(struct vfs_handle_struct *handle,
883                                  files_struct *fsp, const void *data, size_t n)
884 {
885         return glfs_write(*(glfs_fd_t **)VFS_FETCH_FSP_EXTENSION(handle, fsp), data, n, 0);
886 }
887
888 static ssize_t vfs_gluster_pwrite(struct vfs_handle_struct *handle,
889                                   files_struct *fsp, const void *data,
890                                   size_t n, off_t offset)
891 {
892         return glfs_pwrite(*(glfs_fd_t **)VFS_FETCH_FSP_EXTENSION(handle, fsp), data, n, offset, 0);
893 }
894
895 static off_t vfs_gluster_lseek(struct vfs_handle_struct *handle,
896                                files_struct *fsp, off_t offset, int whence)
897 {
898         return glfs_lseek(*(glfs_fd_t **)VFS_FETCH_FSP_EXTENSION(handle, fsp), offset, whence);
899 }
900
901 static ssize_t vfs_gluster_sendfile(struct vfs_handle_struct *handle, int tofd,
902                                     files_struct *fromfsp,
903                                     const DATA_BLOB *hdr,
904                                     off_t offset, size_t n)
905 {
906         errno = ENOTSUP;
907         return -1;
908 }
909
910 static ssize_t vfs_gluster_recvfile(struct vfs_handle_struct *handle,
911                                     int fromfd, files_struct *tofsp,
912                                     off_t offset, size_t n)
913 {
914         errno = ENOTSUP;
915         return -1;
916 }
917
918 static int vfs_gluster_rename(struct vfs_handle_struct *handle,
919                               const struct smb_filename *smb_fname_src,
920                               const struct smb_filename *smb_fname_dst)
921 {
922         return glfs_rename(handle->data, smb_fname_src->base_name,
923                            smb_fname_dst->base_name);
924 }
925
926 static int vfs_gluster_fsync(struct vfs_handle_struct *handle,
927                              files_struct *fsp)
928 {
929         return glfs_fsync(*(glfs_fd_t **)VFS_FETCH_FSP_EXTENSION(handle, fsp));
930 }
931
932 static struct tevent_req *vfs_gluster_fsync_send(struct vfs_handle_struct
933                                                  *handle, TALLOC_CTX *mem_ctx,
934                                                  struct tevent_context *ev,
935                                                  files_struct *fsp)
936 {
937         struct tevent_req *req = NULL;
938         struct glusterfs_aio_state *state = NULL;
939         int ret = 0;
940
941         state = aio_state_create(mem_ctx);
942
943         if (state == NULL) {
944                 return NULL;
945         }
946
947         req = state->req;
948
949         if (!init_gluster_aio(handle)) {
950                 tevent_req_error(req, EIO);
951                 return tevent_req_post(req, ev);
952         }
953
954         PROFILE_TIMESTAMP(&state->start);
955         ret = glfs_fsync_async(*(glfs_fd_t **)VFS_FETCH_FSP_EXTENSION(handle,
956                                 fsp), aio_glusterfs_done, req);
957         if (ret < 0) {
958                 tevent_req_error(req, -ret);
959                 return tevent_req_post(req, ev);
960         }
961         return req;
962 }
963
964 static int vfs_gluster_fsync_recv(struct tevent_req *req,
965                                   struct vfs_aio_state *vfs_aio_state)
966 {
967         /*
968          * Use implicit conversion ssize_t->int
969          */
970         return vfs_gluster_recv(req, vfs_aio_state);
971 }
972
973 static int vfs_gluster_stat(struct vfs_handle_struct *handle,
974                             struct smb_filename *smb_fname)
975 {
976         struct stat st;
977         int ret;
978
979         ret = glfs_stat(handle->data, smb_fname->base_name, &st);
980         if (ret == 0) {
981                 smb_stat_ex_from_stat(&smb_fname->st, &st);
982         }
983         if (ret < 0 && errno != ENOENT) {
984                 DEBUG(0, ("glfs_stat(%s) failed: %s\n",
985                           smb_fname->base_name, strerror(errno)));
986         }
987         return ret;
988 }
989
990 static int vfs_gluster_fstat(struct vfs_handle_struct *handle,
991                              files_struct *fsp, SMB_STRUCT_STAT *sbuf)
992 {
993         struct stat st;
994         int ret;
995
996         ret = glfs_fstat(*(glfs_fd_t **)VFS_FETCH_FSP_EXTENSION(handle, fsp), &st);
997         if (ret == 0) {
998                 smb_stat_ex_from_stat(sbuf, &st);
999         }
1000         if (ret < 0) {
1001                 DEBUG(0, ("glfs_fstat(%d) failed: %s\n",
1002                           fsp->fh->fd, strerror(errno)));
1003         }
1004         return ret;
1005 }
1006
1007 static int vfs_gluster_lstat(struct vfs_handle_struct *handle,
1008                              struct smb_filename *smb_fname)
1009 {
1010         struct stat st;
1011         int ret;
1012
1013         ret = glfs_lstat(handle->data, smb_fname->base_name, &st);
1014         if (ret == 0) {
1015                 smb_stat_ex_from_stat(&smb_fname->st, &st);
1016         }
1017         if (ret < 0 && errno != ENOENT) {
1018                 DEBUG(0, ("glfs_lstat(%s) failed: %s\n",
1019                           smb_fname->base_name, strerror(errno)));
1020         }
1021         return ret;
1022 }
1023
1024 static uint64_t vfs_gluster_get_alloc_size(struct vfs_handle_struct *handle,
1025                                            files_struct *fsp,
1026                                            const SMB_STRUCT_STAT *sbuf)
1027 {
1028         return sbuf->st_ex_blocks * 512;
1029 }
1030
1031 static int vfs_gluster_unlink(struct vfs_handle_struct *handle,
1032                               const struct smb_filename *smb_fname)
1033 {
1034         return glfs_unlink(handle->data, smb_fname->base_name);
1035 }
1036
1037 static int vfs_gluster_chmod(struct vfs_handle_struct *handle,
1038                                 const struct smb_filename *smb_fname,
1039                                 mode_t mode)
1040 {
1041         return glfs_chmod(handle->data, smb_fname->base_name, mode);
1042 }
1043
1044 static int vfs_gluster_fchmod(struct vfs_handle_struct *handle,
1045                               files_struct *fsp, mode_t mode)
1046 {
1047         return glfs_fchmod(*(glfs_fd_t **)VFS_FETCH_FSP_EXTENSION(handle, fsp), mode);
1048 }
1049
1050 static int vfs_gluster_chown(struct vfs_handle_struct *handle,
1051                         const struct smb_filename *smb_fname,
1052                         uid_t uid,
1053                         gid_t gid)
1054 {
1055         return glfs_chown(handle->data, smb_fname->base_name, uid, gid);
1056 }
1057
1058 static int vfs_gluster_fchown(struct vfs_handle_struct *handle,
1059                               files_struct *fsp, uid_t uid, gid_t gid)
1060 {
1061         return glfs_fchown(*(glfs_fd_t **)VFS_FETCH_FSP_EXTENSION(handle, fsp), uid, gid);
1062 }
1063
1064 static int vfs_gluster_lchown(struct vfs_handle_struct *handle,
1065                         const struct smb_filename *smb_fname,
1066                         uid_t uid,
1067                         gid_t gid)
1068 {
1069         return glfs_lchown(handle->data, smb_fname->base_name, uid, gid);
1070 }
1071
1072 static int vfs_gluster_chdir(struct vfs_handle_struct *handle, const char *path)
1073 {
1074         return glfs_chdir(handle->data, path);
1075 }
1076
1077 static char *vfs_gluster_getwd(struct vfs_handle_struct *handle)
1078 {
1079         char *cwd;
1080         char *ret;
1081
1082         cwd = SMB_CALLOC_ARRAY(char, PATH_MAX);
1083         if (cwd == NULL) {
1084                 return NULL;
1085         }
1086
1087         ret = glfs_getcwd(handle->data, cwd, PATH_MAX - 1);
1088         if (ret == 0) {
1089                 free(cwd);
1090         }
1091         return ret;
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         /* TODO: add support using glfs_fallocate() and glfs_zerofill() */
1138         errno = ENOTSUP;
1139         return -1;
1140 }
1141
1142 static char *vfs_gluster_realpath(struct vfs_handle_struct *handle,
1143                                   const char *path)
1144 {
1145         char *result = NULL;
1146         char *resolved_path = SMB_MALLOC_ARRAY(char, PATH_MAX+1);
1147
1148         if (resolved_path == NULL) {
1149                 errno = ENOMEM;
1150                 return NULL;
1151         }
1152
1153         result = glfs_realpath(handle->data, path, resolved_path);
1154         if (result == NULL) {
1155                 SAFE_FREE(resolved_path);
1156         }
1157
1158         return result;
1159 }
1160
1161 static bool vfs_gluster_lock(struct vfs_handle_struct *handle,
1162                              files_struct *fsp, int op, off_t offset,
1163                              off_t count, int type)
1164 {
1165         struct flock flock = { 0, };
1166         int ret;
1167
1168         flock.l_type = type;
1169         flock.l_whence = SEEK_SET;
1170         flock.l_start = offset;
1171         flock.l_len = count;
1172         flock.l_pid = 0;
1173
1174         ret = glfs_posix_lock(*(glfs_fd_t **)VFS_FETCH_FSP_EXTENSION(handle, fsp), op, &flock);
1175
1176         if (op == F_GETLK) {
1177                 /* lock query, true if someone else has locked */
1178                 if ((ret != -1) &&
1179                     (flock.l_type != F_UNLCK) &&
1180                     (flock.l_pid != 0) && (flock.l_pid != getpid()))
1181                         return true;
1182                 /* not me */
1183                 return false;
1184         }
1185
1186         if (ret == -1) {
1187                 return false;
1188         }
1189
1190         return true;
1191 }
1192
1193 static int vfs_gluster_kernel_flock(struct vfs_handle_struct *handle,
1194                                     files_struct *fsp, uint32_t share_mode,
1195                                     uint32_t access_mask)
1196 {
1197         errno = ENOSYS;
1198         return -1;
1199 }
1200
1201 static int vfs_gluster_linux_setlease(struct vfs_handle_struct *handle,
1202                                       files_struct *fsp, int leasetype)
1203 {
1204         errno = ENOSYS;
1205         return -1;
1206 }
1207
1208 static bool vfs_gluster_getlock(struct vfs_handle_struct *handle,
1209                                 files_struct *fsp, off_t *poffset,
1210                                 off_t *pcount, int *ptype, pid_t *ppid)
1211 {
1212         struct flock flock = { 0, };
1213         int ret;
1214
1215         flock.l_type = *ptype;
1216         flock.l_whence = SEEK_SET;
1217         flock.l_start = *poffset;
1218         flock.l_len = *pcount;
1219         flock.l_pid = 0;
1220
1221         ret = glfs_posix_lock(*(glfs_fd_t **)VFS_FETCH_FSP_EXTENSION(handle, fsp), F_GETLK, &flock);
1222
1223         if (ret == -1) {
1224                 return false;
1225         }
1226
1227         *ptype = flock.l_type;
1228         *poffset = flock.l_start;
1229         *pcount = flock.l_len;
1230         *ppid = flock.l_pid;
1231
1232         return true;
1233 }
1234
1235 static int vfs_gluster_symlink(struct vfs_handle_struct *handle,
1236                                const char *oldpath, const char *newpath)
1237 {
1238         return glfs_symlink(handle->data, oldpath, newpath);
1239 }
1240
1241 static int vfs_gluster_readlink(struct vfs_handle_struct *handle,
1242                                 const char *path, char *buf, size_t bufsiz)
1243 {
1244         return glfs_readlink(handle->data, path, buf, bufsiz);
1245 }
1246
1247 static int vfs_gluster_link(struct vfs_handle_struct *handle,
1248                             const char *oldpath, const char *newpath)
1249 {
1250         return glfs_link(handle->data, oldpath, newpath);
1251 }
1252
1253 static int vfs_gluster_mknod(struct vfs_handle_struct *handle,
1254                                 const struct smb_filename *smb_fname,
1255                                 mode_t mode,
1256                                 SMB_DEV_T dev)
1257 {
1258         return glfs_mknod(handle->data, smb_fname->base_name, mode, dev);
1259 }
1260
1261 static int vfs_gluster_chflags(struct vfs_handle_struct *handle,
1262                                 const struct smb_filename *smb_fname,
1263                                 unsigned int flags)
1264 {
1265         errno = ENOSYS;
1266         return -1;
1267 }
1268
1269 static int vfs_gluster_get_real_filename(struct vfs_handle_struct *handle,
1270                                          const char *path, const char *name,
1271                                          TALLOC_CTX *mem_ctx, char **found_name)
1272 {
1273         int ret;
1274         char key_buf[NAME_MAX + 64];
1275         char val_buf[NAME_MAX + 1];
1276
1277         if (strlen(name) >= NAME_MAX) {
1278                 errno = ENAMETOOLONG;
1279                 return -1;
1280         }
1281
1282         snprintf(key_buf, NAME_MAX + 64,
1283                  "glusterfs.get_real_filename:%s", name);
1284
1285         ret = glfs_getxattr(handle->data, path, key_buf, val_buf, NAME_MAX + 1);
1286         if (ret == -1) {
1287                 if (errno == ENODATA) {
1288                         errno = EOPNOTSUPP;
1289                 }
1290                 return -1;
1291         }
1292
1293         *found_name = talloc_strdup(mem_ctx, val_buf);
1294         if (found_name[0] == NULL) {
1295                 errno = ENOMEM;
1296                 return -1;
1297         }
1298         return 0;
1299 }
1300
1301 static const char *vfs_gluster_connectpath(struct vfs_handle_struct *handle,
1302                                            const char *filename)
1303 {
1304         return handle->conn->connectpath;
1305 }
1306
1307 /* EA Operations */
1308
1309 static ssize_t vfs_gluster_getxattr(struct vfs_handle_struct *handle,
1310                                 const struct smb_filename *smb_fname,
1311                                 const char *name,
1312                                 void *value,
1313                                 size_t size)
1314 {
1315         return glfs_getxattr(handle->data, smb_fname->base_name,
1316                         name, value, size);
1317 }
1318
1319 static ssize_t vfs_gluster_fgetxattr(struct vfs_handle_struct *handle,
1320                                      files_struct *fsp, const char *name,
1321                                      void *value, size_t size)
1322 {
1323         return glfs_fgetxattr(*(glfs_fd_t **)VFS_FETCH_FSP_EXTENSION(handle, fsp), name, value, size);
1324 }
1325
1326 static ssize_t vfs_gluster_listxattr(struct vfs_handle_struct *handle,
1327                                 const struct smb_filename *smb_fname,
1328                                 char *list,
1329                                 size_t size)
1330 {
1331         return glfs_listxattr(handle->data, smb_fname->base_name, list, size);
1332 }
1333
1334 static ssize_t vfs_gluster_flistxattr(struct vfs_handle_struct *handle,
1335                                       files_struct *fsp, char *list,
1336                                       size_t size)
1337 {
1338         return glfs_flistxattr(*(glfs_fd_t **)VFS_FETCH_FSP_EXTENSION(handle, fsp), list, size);
1339 }
1340
1341 static int vfs_gluster_removexattr(struct vfs_handle_struct *handle,
1342                                 const struct smb_filename *smb_fname,
1343                                 const char *name)
1344 {
1345         return glfs_removexattr(handle->data, smb_fname->base_name, name);
1346 }
1347
1348 static int vfs_gluster_fremovexattr(struct vfs_handle_struct *handle,
1349                                     files_struct *fsp, const char *name)
1350 {
1351         return glfs_fremovexattr(*(glfs_fd_t **)VFS_FETCH_FSP_EXTENSION(handle, fsp), name);
1352 }
1353
1354 static int vfs_gluster_setxattr(struct vfs_handle_struct *handle,
1355                                 const struct smb_filename *smb_fname,
1356                                 const char *name,
1357                                 const void *value, size_t size, int flags)
1358 {
1359         return glfs_setxattr(handle->data, smb_fname->base_name, name, value, size, flags);
1360 }
1361
1362 static int vfs_gluster_fsetxattr(struct vfs_handle_struct *handle,
1363                                  files_struct *fsp, const char *name,
1364                                  const void *value, size_t size, int flags)
1365 {
1366         return glfs_fsetxattr(*(glfs_fd_t **)VFS_FETCH_FSP_EXTENSION(handle, fsp), name, value, size,
1367                               flags);
1368 }
1369
1370 /* AIO Operations */
1371
1372 static bool vfs_gluster_aio_force(struct vfs_handle_struct *handle,
1373                                   files_struct *fsp)
1374 {
1375         return false;
1376 }
1377
1378 static struct vfs_fn_pointers glusterfs_fns = {
1379
1380         /* Disk Operations */
1381
1382         .connect_fn = vfs_gluster_connect,
1383         .disconnect_fn = vfs_gluster_disconnect,
1384         .disk_free_fn = vfs_gluster_disk_free,
1385         .get_quota_fn = vfs_gluster_get_quota,
1386         .set_quota_fn = vfs_gluster_set_quota,
1387         .statvfs_fn = vfs_gluster_statvfs,
1388         .fs_capabilities_fn = vfs_gluster_fs_capabilities,
1389
1390         .get_dfs_referrals_fn = NULL,
1391
1392         /* Directory Operations */
1393
1394         .opendir_fn = vfs_gluster_opendir,
1395         .fdopendir_fn = vfs_gluster_fdopendir,
1396         .readdir_fn = vfs_gluster_readdir,
1397         .seekdir_fn = vfs_gluster_seekdir,
1398         .telldir_fn = vfs_gluster_telldir,
1399         .rewind_dir_fn = vfs_gluster_rewinddir,
1400         .mkdir_fn = vfs_gluster_mkdir,
1401         .rmdir_fn = vfs_gluster_rmdir,
1402         .closedir_fn = vfs_gluster_closedir,
1403         .init_search_op_fn = vfs_gluster_init_search_op,
1404
1405         /* File Operations */
1406
1407         .open_fn = vfs_gluster_open,
1408         .create_file_fn = NULL,
1409         .close_fn = vfs_gluster_close,
1410         .read_fn = vfs_gluster_read,
1411         .pread_fn = vfs_gluster_pread,
1412         .pread_send_fn = vfs_gluster_pread_send,
1413         .pread_recv_fn = vfs_gluster_recv,
1414         .write_fn = vfs_gluster_write,
1415         .pwrite_fn = vfs_gluster_pwrite,
1416         .pwrite_send_fn = vfs_gluster_pwrite_send,
1417         .pwrite_recv_fn = vfs_gluster_recv,
1418         .lseek_fn = vfs_gluster_lseek,
1419         .sendfile_fn = vfs_gluster_sendfile,
1420         .recvfile_fn = vfs_gluster_recvfile,
1421         .rename_fn = vfs_gluster_rename,
1422         .fsync_fn = vfs_gluster_fsync,
1423         .fsync_send_fn = vfs_gluster_fsync_send,
1424         .fsync_recv_fn = vfs_gluster_fsync_recv,
1425
1426         .stat_fn = vfs_gluster_stat,
1427         .fstat_fn = vfs_gluster_fstat,
1428         .lstat_fn = vfs_gluster_lstat,
1429         .get_alloc_size_fn = vfs_gluster_get_alloc_size,
1430         .unlink_fn = vfs_gluster_unlink,
1431
1432         .chmod_fn = vfs_gluster_chmod,
1433         .fchmod_fn = vfs_gluster_fchmod,
1434         .chown_fn = vfs_gluster_chown,
1435         .fchown_fn = vfs_gluster_fchown,
1436         .lchown_fn = vfs_gluster_lchown,
1437         .chdir_fn = vfs_gluster_chdir,
1438         .getwd_fn = vfs_gluster_getwd,
1439         .ntimes_fn = vfs_gluster_ntimes,
1440         .ftruncate_fn = vfs_gluster_ftruncate,
1441         .fallocate_fn = vfs_gluster_fallocate,
1442         .lock_fn = vfs_gluster_lock,
1443         .kernel_flock_fn = vfs_gluster_kernel_flock,
1444         .linux_setlease_fn = vfs_gluster_linux_setlease,
1445         .getlock_fn = vfs_gluster_getlock,
1446         .symlink_fn = vfs_gluster_symlink,
1447         .readlink_fn = vfs_gluster_readlink,
1448         .link_fn = vfs_gluster_link,
1449         .mknod_fn = vfs_gluster_mknod,
1450         .realpath_fn = vfs_gluster_realpath,
1451         .chflags_fn = vfs_gluster_chflags,
1452         .file_id_create_fn = NULL,
1453         .copy_chunk_send_fn = NULL,
1454         .copy_chunk_recv_fn = NULL,
1455         .streaminfo_fn = NULL,
1456         .get_real_filename_fn = vfs_gluster_get_real_filename,
1457         .connectpath_fn = vfs_gluster_connectpath,
1458
1459         .brl_lock_windows_fn = NULL,
1460         .brl_unlock_windows_fn = NULL,
1461         .brl_cancel_windows_fn = NULL,
1462         .strict_lock_fn = NULL,
1463         .strict_unlock_fn = NULL,
1464         .translate_name_fn = NULL,
1465         .fsctl_fn = NULL,
1466
1467         /* NT ACL Operations */
1468         .fget_nt_acl_fn = NULL,
1469         .get_nt_acl_fn = NULL,
1470         .fset_nt_acl_fn = NULL,
1471         .audit_file_fn = NULL,
1472
1473         /* Posix ACL Operations */
1474         .chmod_acl_fn = NULL,   /* passthrough to default */
1475         .fchmod_acl_fn = NULL,  /* passthrough to default */
1476         .sys_acl_get_file_fn = posixacl_xattr_acl_get_file,
1477         .sys_acl_get_fd_fn = posixacl_xattr_acl_get_fd,
1478         .sys_acl_blob_get_file_fn = posix_sys_acl_blob_get_file,
1479         .sys_acl_blob_get_fd_fn = posix_sys_acl_blob_get_fd,
1480         .sys_acl_set_file_fn = posixacl_xattr_acl_set_file,
1481         .sys_acl_set_fd_fn = posixacl_xattr_acl_set_fd,
1482         .sys_acl_delete_def_file_fn = posixacl_xattr_acl_delete_def_file,
1483
1484         /* EA Operations */
1485         .getxattr_fn = vfs_gluster_getxattr,
1486         .fgetxattr_fn = vfs_gluster_fgetxattr,
1487         .listxattr_fn = vfs_gluster_listxattr,
1488         .flistxattr_fn = vfs_gluster_flistxattr,
1489         .removexattr_fn = vfs_gluster_removexattr,
1490         .fremovexattr_fn = vfs_gluster_fremovexattr,
1491         .setxattr_fn = vfs_gluster_setxattr,
1492         .fsetxattr_fn = vfs_gluster_fsetxattr,
1493
1494         /* AIO Operations */
1495         .aio_force_fn = vfs_gluster_aio_force,
1496
1497         /* Durable handle Operations */
1498         .durable_cookie_fn = NULL,
1499         .durable_disconnect_fn = NULL,
1500         .durable_reconnect_fn = NULL,
1501 };
1502
1503 NTSTATUS vfs_glusterfs_init(TALLOC_CTX *);
1504 NTSTATUS vfs_glusterfs_init(TALLOC_CTX *ctx)
1505 {
1506         return smb_register_vfs(SMB_VFS_INTERFACE_VERSION,
1507                                 "glusterfs", &glusterfs_fns);
1508 }