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