vfs_glusterfs: Samba VFS module for glusterfs
[samba.git] / source3 / modules / vfs_glusterfs.c
1 /*
2    Unix SMB/CIFS implementation.
3
4    Wrap GlusterFS GFAPI calls in vfs functions.
5
6    Copyright (c) 2013 Anand Avati <avati@redhat.com>
7
8    This program is free software; you can redistribute it and/or modify
9    it under the terms of the GNU General Public License as published by
10    the Free Software Foundation; either version 3 of the License, or
11    (at your option) any later version.
12
13    This program is distributed in the hope that it will be useful,
14    but WITHOUT ANY WARRANTY; without even the implied warranty of
15    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16    GNU General Public License for more details.
17
18    You should have received a copy of the GNU General Public License
19    along with this program.  If not, see <http://www.gnu.org/licenses/>.
20 */
21
22 #include "includes.h"
23 #include "smbd/smbd.h"
24 #include <stdio.h>
25 #include "api/glfs.h"
26 #include "lib/util/dlinklist.h"
27
28 #define DEFAULT_VOLFILE_SERVER "localhost"
29
30 /*
31   TODO
32   ----
33   Short term:
34   - AIO support
35   - sendfile/recvfile support
36 */
37
38 /* Helpers to provide 'integer' fds */
39
40 /* This is global. gfapi's FD operations do not
41    require filesystem context.
42 */
43
44 static glfs_fd_t **glfd_fd;
45 static int glfd_fd_size;
46 static int glfd_fd_used;
47
48 static int glfd_fd_store(glfs_fd_t *glfd)
49 {
50         int i;
51         void *tmp;
52
53         if (glfd_fd_size == glfd_fd_used) {
54                 if (glfd_fd_size >= INT_MAX - 1) {
55                         errno = ENOMEM;
56                         return -1;
57                 }
58
59                 tmp = talloc_realloc(glfd_fd, glfd_fd, glfs_fd_t *,
60                                      glfd_fd_size + 1);
61                 if (tmp == NULL) {
62                         errno = ENOMEM;
63                         return -1;
64                 }
65
66                 glfd_fd = tmp;
67                 glfd_fd[glfd_fd_size] = 0;
68                 glfd_fd_size++;
69         }
70
71         for (i = 0; i < glfd_fd_size; i++) {
72                 if (glfd_fd[i] == NULL) {
73                         break;
74                 }
75         }
76         glfd_fd_used++;
77         glfd_fd[i] = glfd;
78         return i;
79 }
80
81 static glfs_fd_t *glfd_fd_get(int i)
82 {
83         if (i < 0 || i >= glfd_fd_size) {
84                 return NULL;
85         }
86         return glfd_fd[i];
87 }
88
89 static glfs_fd_t *glfd_fd_clear(int i)
90 {
91         glfs_fd_t *glfd = NULL;
92
93         if (i < 0 || i >= glfd_fd_size) {
94                 return NULL;
95         }
96
97         glfd = glfd_fd[i];
98
99         glfd_fd[i] = 0;
100         glfd_fd_used--;
101         return glfd;
102 }
103
104 /* Helper to convert stat to stat_ex */
105
106 static void smb_stat_ex_from_stat(struct stat_ex *dst, const struct stat *src)
107 {
108         ZERO_STRUCTP(dst);
109
110         dst->st_ex_dev = src->st_dev;
111         dst->st_ex_ino = src->st_ino;
112         dst->st_ex_mode = src->st_mode;
113         dst->st_ex_nlink = src->st_nlink;
114         dst->st_ex_uid = src->st_uid;
115         dst->st_ex_gid = src->st_gid;
116         dst->st_ex_rdev = src->st_rdev;
117         dst->st_ex_size = src->st_size;
118         dst->st_ex_atime.tv_sec = src->st_atime;
119 #ifdef STAT_HAVE_NSEC
120         dst->st_ex_atime.tv_nsec = src->st_atime_nsec;
121 #endif
122         dst->st_ex_mtime.tv_sec = src->st_mtime;
123 #ifdef STAT_HAVE_NSEC
124         dst->st_ex_mtime.tv_nsec = src->st_mtime_nsec;
125 #endif
126         dst->st_ex_ctime.tv_sec = src->st_ctime;
127 #ifdef STAT_HAVE_NSEC
128         dst->st_ex_ctime.tv_nsec = src->st_ctime_nsec;
129 #endif
130         dst->st_ex_btime.tv_sec = src->st_mtime;
131 #ifdef STAT_HAVE_NSEC
132         dst->st_ex_btime.tv_nsec = src->st_mtime_nsec;
133 #endif
134         dst->st_ex_blksize = src->st_blksize;
135         dst->st_ex_blocks = src->st_blocks;
136 }
137
138 /* pre-opened glfs_t */
139
140 static struct glfs_preopened {
141         char *volume;
142         glfs_t *fs;
143         int ref;
144         struct glfs_preopened *next, *prev;
145 } *glfs_preopened;
146
147
148 int glfs_set_preopened(const char *volume, glfs_t *fs)
149 {
150         struct glfs_preopened *entry = NULL;
151
152         entry = talloc_zero(NULL, struct glfs_preopened);
153         if (!entry) {
154                 errno = ENOMEM;
155                 return -1;
156         }
157
158         entry->volume = talloc_strdup(entry, volume);
159         if (!entry->volume) {
160                 talloc_free(entry);
161                 errno = ENOMEM;
162                 return -1;
163         }
164
165         entry->fs = fs;
166         entry->ref = 1;
167
168         DLIST_ADD(glfs_preopened, entry);
169
170         return 0;
171 }
172
173 static glfs_t *glfs_find_preopened(const char *volume)
174 {
175         struct glfs_preopened *entry = NULL;
176
177         for (entry = glfs_preopened; entry; entry = entry->next) {
178                 if (strcmp(entry->volume, volume) == 0) {
179                         entry->ref++;
180                         return entry->fs;
181                 }
182         }
183
184         return NULL;
185 }
186
187 static void glfs_clear_preopened(glfs_t *fs)
188 {
189         struct glfs_preopened *entry = NULL;
190
191         for (entry = glfs_preopened; entry; entry = entry->next) {
192                 if (entry->fs == fs) {
193                         if (--entry->ref)
194                                 return;
195
196                         DLIST_REMOVE(glfs_preopened, entry);
197
198                         glfs_fini(entry->fs);
199                         talloc_free(entry);
200                 }
201         }
202 }
203
204 /* Disk Operations */
205
206 static int vfs_gluster_connect(struct vfs_handle_struct *handle,
207                                const char *service,
208                                const char *user)
209 {
210         const char *volfile_server;
211         const char *volume;
212         const char *logfile;
213         int loglevel;
214         glfs_t *fs;
215         int ret;
216
217         logfile = lp_parm_const_string(SNUM(handle->conn), "glusterfs",
218                                        "logfile", NULL);
219
220         loglevel = lp_parm_int(SNUM(handle->conn), "glusterfs", "loglevel", -1);
221
222         volfile_server = lp_parm_const_string(SNUM(handle->conn), "glusterfs",
223                                                "volfile_server", NULL);
224         if (volfile_server == NULL) {
225                 volfile_server = DEFAULT_VOLFILE_SERVER;
226         }
227
228         volume = lp_parm_const_string(SNUM(handle->conn), "glusterfs", "volume",
229                                       NULL);
230         if (volume == NULL) {
231                 volume = service;
232         }
233
234         fs = glfs_find_preopened(volume);
235         if (fs) {
236                 goto found;
237         }
238
239         fs = glfs_new(volume);
240         if (fs == NULL) {
241                 return -1;
242         }
243
244         ret = glfs_set_volfile_server(fs, "tcp", volfile_server, 0);
245         if (ret < 0) {
246                 DEBUG(0, ("Failed to set volfile_server %s\n", volfile_server));
247                 glfs_fini(fs);
248                 return -1;
249         }
250
251         ret = glfs_set_xlator_option(fs, "*-md-cache", "cache-posix-acl",
252                                      "true");
253         if (ret < 0) {
254                 DEBUG(0, ("%s: Failed to set xlator options\n", volume));
255                 glfs_fini(fs);
256                 return -1;
257         }
258
259         ret = glfs_set_logging(fs, logfile, loglevel);
260         if (ret < 0) {
261                 DEBUG(0, ("%s: Failed to set logfile %s loglevel %d\n",
262                           volume, logfile, loglevel));
263                 glfs_fini(fs);
264                 return -1;
265         }
266
267         ret = glfs_init(fs);
268         if (ret < 0) {
269                 DEBUG(0, ("%s: Failed to initialize volume (%s)\n",
270                           volume, strerror(errno)));
271                 glfs_fini(fs);
272                 return -1;
273         }
274
275         ret = glfs_set_preopened(volume, fs);
276         if (ret < 0) {
277                 DEBUG(0, ("%s: Failed to register volume (%s)\n",
278                           volume, strerror(errno)));
279                 glfs_fini(fs);
280                 return -1;
281         }
282 found:
283         DEBUG(0, ("%s: Initialized volume from server %s\n",
284                   volume, volfile_server));
285         handle->data = fs;
286         return 0;
287 }
288
289 static void vfs_gluster_disconnect(struct vfs_handle_struct *handle)
290 {
291         glfs_t *fs = NULL;
292
293         fs = handle->data;
294
295         glfs_clear_preopened(fs);
296 }
297
298 static uint64_t vfs_gluster_disk_free(struct vfs_handle_struct *handle,
299                                       const char *path, bool small_query,
300                                       uint64_t *bsize_p, uint64_t *dfree_p,
301                                       uint64_t *dsize_p)
302 {
303         struct statvfs statvfs = { 0, };
304         uint64_t dfree = 0;
305         int ret;
306
307         ret = glfs_statvfs(handle->data, path, &statvfs);
308         if (ret < 0) {
309                 return -1;
310         }
311
312         dfree = statvfs.f_bsize * statvfs.f_bavail;
313
314         if (bsize_p != NULL) {
315                 *bsize_p = statvfs.f_bsize;
316         }
317         if (dfree_p != NULL) {
318                 *dfree_p = dfree;
319         }
320         if (dsize_p != NULL) {
321                 *dsize_p = statvfs.f_bsize * statvfs.f_blocks;
322         }
323
324         return dfree;
325 }
326
327 static int vfs_gluster_get_quota(struct vfs_handle_struct *handle,
328                                  enum SMB_QUOTA_TYPE qtype, unid_t id,
329                                  SMB_DISK_QUOTA *qt)
330 {
331         errno = ENOSYS;
332         return -1;
333 }
334
335 static int
336 vfs_gluster_set_quota(struct vfs_handle_struct *handle,
337                       enum SMB_QUOTA_TYPE qtype, unid_t id, SMB_DISK_QUOTA *qt)
338 {
339         errno = ENOSYS;
340         return -1;
341 }
342
343 static int vfs_gluster_statvfs(struct vfs_handle_struct *handle,
344                                const char *path,
345                                struct vfs_statvfs_struct *vfs_statvfs)
346 {
347         struct statvfs statvfs = { 0, };
348         int ret;
349
350         ret = glfs_statvfs(handle->data, path, &statvfs);
351         if (ret < 0) {
352                 DEBUG(0, ("glfs_statvfs(%s) failed: %s\n",
353                           path, strerror(errno)));
354                 return -1;
355         }
356
357         ZERO_STRUCTP(vfs_statvfs);
358
359         vfs_statvfs->OptimalTransferSize = statvfs.f_frsize;
360         vfs_statvfs->BlockSize = statvfs.f_bsize;
361         vfs_statvfs->TotalBlocks = statvfs.f_blocks;
362         vfs_statvfs->BlocksAvail = statvfs.f_bfree;
363         vfs_statvfs->UserBlocksAvail = statvfs.f_bavail;
364         vfs_statvfs->TotalFileNodes = statvfs.f_files;
365         vfs_statvfs->FreeFileNodes = statvfs.f_ffree;
366         vfs_statvfs->FsIdentifier = statvfs.f_fsid;
367         vfs_statvfs->FsCapabilities =
368             FILE_CASE_SENSITIVE_SEARCH | FILE_CASE_PRESERVED_NAMES;
369
370         return ret;
371 }
372
373 static uint32_t vfs_gluster_fs_capabilities(struct vfs_handle_struct *handle,
374                                             enum timestamp_set_resolution *p_ts_res)
375 {
376         uint32_t caps = FILE_CASE_SENSITIVE_SEARCH | FILE_CASE_PRESERVED_NAMES;
377
378 #ifdef STAT_HAVE_NSEC
379         *p_ts_res = TIMESTAMP_SET_NT_OR_BETTER;
380 #endif
381
382         return caps;
383 }
384
385 static DIR *vfs_gluster_opendir(struct vfs_handle_struct *handle,
386                                 const char *path, const char *mask,
387                                 uint32 attributes)
388 {
389         glfs_fd_t *fd;
390
391         fd = glfs_opendir(handle->data, path);
392         if (fd == NULL) {
393                 DEBUG(0, ("glfs_opendir(%s) failed: %s\n",
394                           path, strerror(errno)));
395         }
396
397         return (DIR *) fd;
398 }
399
400 static DIR *vfs_gluster_fdopendir(struct vfs_handle_struct *handle,
401                                   files_struct *fsp, const char *mask,
402                                   uint32 attributes)
403 {
404         return (DIR *) glfd_fd_get(fsp->fh->fd);
405 }
406
407 static int vfs_gluster_closedir(struct vfs_handle_struct *handle, DIR *dirp)
408 {
409         return glfs_closedir((void *)dirp);
410 }
411
412 static struct dirent *vfs_gluster_readdir(struct vfs_handle_struct *handle,
413                                           DIR *dirp, SMB_STRUCT_STAT *sbuf)
414 {
415         static char direntbuf[512];
416         int ret;
417         struct stat stat;
418         struct dirent *dirent = 0;
419
420         if (sbuf != NULL) {
421                 ret = glfs_readdirplus_r((void *)dirp, &stat, (void *)direntbuf,
422                                          &dirent);
423         } else {
424                 ret = glfs_readdir_r((void *)dirp, (void *)direntbuf, &dirent);
425         }
426
427         if ((ret < 0) || (dirent == NULL)) {
428                 return NULL;
429         }
430
431         if (sbuf != NULL) {
432                 smb_stat_ex_from_stat(sbuf, &stat);
433         }
434
435         return dirent;
436 }
437
438 static long vfs_gluster_telldir(struct vfs_handle_struct *handle, DIR *dirp)
439 {
440         return glfs_telldir((void *)dirp);
441 }
442
443 static void vfs_gluster_seekdir(struct vfs_handle_struct *handle, DIR *dirp,
444                                 long offset)
445 {
446         glfs_seekdir((void *)dirp, offset);
447 }
448
449 static void vfs_gluster_rewinddir(struct vfs_handle_struct *handle, DIR *dirp)
450 {
451         glfs_seekdir((void *)dirp, 0);
452 }
453
454 static void vfs_gluster_init_search_op(struct vfs_handle_struct *handle,
455                                        DIR *dirp)
456 {
457         return;
458 }
459
460 static int vfs_gluster_mkdir(struct vfs_handle_struct *handle, const char *path,
461                              mode_t mode)
462 {
463         return glfs_mkdir(handle->data, path, mode);
464 }
465
466 static int vfs_gluster_rmdir(struct vfs_handle_struct *handle, const char *path)
467 {
468         return glfs_rmdir(handle->data, path);
469 }
470
471 static int vfs_gluster_open(struct vfs_handle_struct *handle,
472                             struct smb_filename *smb_fname, files_struct *fsp,
473                             int flags, mode_t mode)
474 {
475         glfs_fd_t *glfd;
476
477         if (flags & O_DIRECTORY) {
478                 glfd = glfs_opendir(handle->data, smb_fname->base_name);
479         } else if (flags & O_CREAT) {
480                 glfd = glfs_creat(handle->data, smb_fname->base_name, flags,
481                                   mode);
482         } else {
483                 glfd = glfs_open(handle->data, smb_fname->base_name, flags);
484         }
485
486         if (glfd == NULL) {
487                 DEBUG(0, ("glfs_{open[dir],creat}(%s) failed: %s\n",
488                           smb_fname->base_name, strerror(errno)));
489                 return -1;
490         }
491
492         return glfd_fd_store(glfd);
493 }
494
495 static int vfs_gluster_close(struct vfs_handle_struct *handle,
496                              files_struct *fsp)
497 {
498         return glfs_close(glfd_fd_clear(fsp->fh->fd));
499 }
500
501 static ssize_t vfs_gluster_read(struct vfs_handle_struct *handle,
502                                 files_struct *fsp, void *data, size_t n)
503 {
504         return glfs_read(glfd_fd_get(fsp->fh->fd), data, n, 0);
505 }
506
507 static ssize_t vfs_gluster_pread(struct vfs_handle_struct *handle,
508                                  files_struct *fsp, void *data, size_t n,
509                                  off_t offset)
510 {
511         return glfs_pread(glfd_fd_get(fsp->fh->fd), data, n, offset, 0);
512 }
513
514 static struct tevent_req *vfs_gluster_pread_send(struct vfs_handle_struct
515                                                  *handle, TALLOC_CTX *mem_ctx,
516                                                  struct tevent_context *ev,
517                                                  files_struct *fsp, void *data,
518                                                  size_t n, off_t offset)
519 {
520         errno = ENOTSUP;
521         return NULL;
522 }
523
524 static ssize_t vfs_gluster_pread_recv(struct tevent_req *req, int *err)
525 {
526         errno = ENOTSUP;
527         return -1;
528 }
529
530 static ssize_t vfs_gluster_write(struct vfs_handle_struct *handle,
531                                  files_struct *fsp, const void *data, size_t n)
532 {
533         return glfs_write(glfd_fd_get(fsp->fh->fd), data, n, 0);
534 }
535
536 static ssize_t vfs_gluster_pwrite(struct vfs_handle_struct *handle,
537                                   files_struct *fsp, const void *data,
538                                   size_t n, off_t offset)
539 {
540         return glfs_pwrite(glfd_fd_get(fsp->fh->fd), data, n, offset, 0);
541 }
542
543 static struct tevent_req *vfs_gluster_pwrite_send(struct vfs_handle_struct
544                                                   *handle, TALLOC_CTX *mem_ctx,
545                                                   struct tevent_context *ev,
546                                                   files_struct *fsp,
547                                                   const void *data, size_t n,
548                                                   off_t offset)
549 {
550         errno = ENOTSUP;
551         return NULL;
552 }
553
554 static ssize_t vfs_gluster_pwrite_recv(struct tevent_req *req, int *err)
555 {
556         errno = ENOTSUP;
557         return -1;
558 }
559
560 static off_t vfs_gluster_lseek(struct vfs_handle_struct *handle,
561                                files_struct *fsp, off_t offset, int whence)
562 {
563         return glfs_lseek(glfd_fd_get(fsp->fh->fd), offset, whence);
564 }
565
566 static ssize_t vfs_gluster_sendfile(struct vfs_handle_struct *handle, int tofd,
567                                     files_struct *fromfsp,
568                                     const DATA_BLOB *hdr,
569                                     off_t offset, size_t n)
570 {
571         errno = ENOTSUP;
572         return -1;
573 }
574
575 static ssize_t vfs_gluster_recvfile(struct vfs_handle_struct *handle,
576                                     int fromfd, files_struct *tofsp,
577                                     off_t offset, size_t n)
578 {
579         errno = ENOTSUP;
580         return -1;
581 }
582
583 static int vfs_gluster_rename(struct vfs_handle_struct *handle,
584                               const struct smb_filename *smb_fname_src,
585                               const struct smb_filename *smb_fname_dst)
586 {
587         return glfs_rename(handle->data, smb_fname_src->base_name,
588                            smb_fname_dst->base_name);
589 }
590
591 static int vfs_gluster_fsync(struct vfs_handle_struct *handle,
592                              files_struct *fsp)
593 {
594         return glfs_fsync(glfd_fd_get(fsp->fh->fd));
595 }
596
597 static struct tevent_req *vfs_gluster_fsync_send(struct vfs_handle_struct
598                                                  *handle, TALLOC_CTX *mem_ctx,
599                                                  struct tevent_context *ev,
600                                                  files_struct *fsp)
601 {
602         errno = ENOTSUP;
603         return NULL;
604 }
605
606 static int vfs_gluster_fsync_recv(struct tevent_req *req, int *err)
607 {
608         errno = ENOTSUP;
609         return -1;
610 }
611
612 static int vfs_gluster_stat(struct vfs_handle_struct *handle,
613                             struct smb_filename *smb_fname)
614 {
615         struct stat st;
616         int ret;
617
618         ret = glfs_stat(handle->data, smb_fname->base_name, &st);
619         if (ret == 0) {
620                 smb_stat_ex_from_stat(&smb_fname->st, &st);
621         }
622         if (ret < 0 && errno != ENOENT) {
623                 DEBUG(0, ("glfs_stat(%s) failed: %s\n",
624                           smb_fname->base_name, strerror(errno)));
625         }
626         return ret;
627 }
628
629 static int vfs_gluster_fstat(struct vfs_handle_struct *handle,
630                              files_struct *fsp, SMB_STRUCT_STAT *sbuf)
631 {
632         struct stat st;
633         int ret;
634
635         ret = glfs_fstat(glfd_fd_get(fsp->fh->fd), &st);
636         if (ret == 0) {
637                 smb_stat_ex_from_stat(sbuf, &st);
638         }
639         if (ret < 0) {
640                 DEBUG(0, ("glfs_fstat(%d) failed: %s\n",
641                           fsp->fh->fd, strerror(errno)));
642         }
643         return ret;
644 }
645
646 static int vfs_gluster_lstat(struct vfs_handle_struct *handle,
647                              struct smb_filename *smb_fname)
648 {
649         struct stat st;
650         int ret;
651
652         ret = glfs_lstat(handle->data, smb_fname->base_name, &st);
653         if (ret == 0) {
654                 smb_stat_ex_from_stat(&smb_fname->st, &st);
655         }
656         if (ret < 0 && errno != ENOENT) {
657                 DEBUG(0, ("glfs_lstat(%s) failed: %s\n",
658                           smb_fname->base_name, strerror(errno)));
659         }
660         return ret;
661 }
662
663 static uint64_t vfs_gluster_get_alloc_size(struct vfs_handle_struct *handle,
664                                            files_struct *fsp,
665                                            const SMB_STRUCT_STAT *sbuf)
666 {
667         return sbuf->st_ex_blocks * 512;
668 }
669
670 static int vfs_gluster_unlink(struct vfs_handle_struct *handle,
671                               const struct smb_filename *smb_fname)
672 {
673         return glfs_unlink(handle->data, smb_fname->base_name);
674 }
675
676 static int vfs_gluster_chmod(struct vfs_handle_struct *handle,
677                              const char *path, mode_t mode)
678 {
679         return glfs_chmod(handle->data, path, mode);
680 }
681
682 static int vfs_gluster_fchmod(struct vfs_handle_struct *handle,
683                               files_struct *fsp, mode_t mode)
684 {
685         return glfs_fchmod(glfd_fd_get(fsp->fh->fd), mode);
686 }
687
688 static int vfs_gluster_chown(struct vfs_handle_struct *handle,
689                              const char *path, uid_t uid, gid_t gid)
690 {
691         return glfs_chown(handle->data, path, uid, gid);
692 }
693
694 static int vfs_gluster_fchown(struct vfs_handle_struct *handle,
695                               files_struct *fsp, uid_t uid, gid_t gid)
696 {
697         return glfs_fchown(glfd_fd_get(fsp->fh->fd), uid, gid);
698 }
699
700 static int vfs_gluster_lchown(struct vfs_handle_struct *handle,
701                               const char *path, uid_t uid, gid_t gid)
702 {
703         return glfs_lchown(handle->data, path, uid, gid);
704 }
705
706 static int vfs_gluster_chdir(struct vfs_handle_struct *handle, const char *path)
707 {
708         return glfs_chdir(handle->data, path);
709 }
710
711 static char *vfs_gluster_getwd(struct vfs_handle_struct *handle)
712 {
713         char *cwd;
714         char *ret;
715
716         cwd = calloc(1, PATH_MAX + 1);
717         if (cwd == NULL) {
718                 return NULL;
719         }
720
721         ret = glfs_getcwd(handle->data, cwd, PATH_MAX);
722         if (ret == 0) {
723                 free(cwd);
724         }
725         return ret;
726 }
727
728 static int vfs_gluster_ntimes(struct vfs_handle_struct *handle,
729                               const struct smb_filename *smb_fname,
730                               struct smb_file_time *ft)
731 {
732         struct timespec times[2];
733
734         times[0].tv_sec = ft->atime.tv_sec;
735         times[0].tv_nsec = ft->atime.tv_nsec;
736         times[1].tv_sec = ft->mtime.tv_sec;
737         times[1].tv_nsec = ft->mtime.tv_nsec;
738
739         return glfs_utimens(handle->data, smb_fname->base_name, times);
740 }
741
742 static int vfs_gluster_ftruncate(struct vfs_handle_struct *handle,
743                                  files_struct *fsp, off_t offset)
744 {
745         return glfs_ftruncate(glfd_fd_get(fsp->fh->fd), offset);
746 }
747
748 static int vfs_gluster_fallocate(struct vfs_handle_struct *handle,
749                                  struct files_struct *fsp,
750                                  enum vfs_fallocate_mode mode,
751                                  off_t offset, off_t len)
752 {
753         errno = ENOTSUP;
754         return -1;
755 }
756
757 static char *vfs_gluster_realpath(struct vfs_handle_struct *handle,
758                                   const char *path)
759 {
760         return glfs_realpath(handle->data, path, 0);
761 }
762
763 static bool vfs_gluster_lock(struct vfs_handle_struct *handle,
764                              files_struct *fsp, int op, off_t offset,
765                              off_t count, int type)
766 {
767         struct flock flock = { 0, };
768         int ret;
769
770         flock.l_type = type;
771         flock.l_whence = SEEK_SET;
772         flock.l_start = offset;
773         flock.l_len = count;
774         flock.l_pid = 0;
775
776         ret = glfs_posix_lock(glfd_fd_get(fsp->fh->fd), op, &flock);
777
778         if (op == F_GETLK) {
779                 /* lock query, true if someone else has locked */
780                 if ((ret != -1) &&
781                     (flock.l_type != F_UNLCK) &&
782                     (flock.l_pid != 0) && (flock.l_pid != getpid()))
783                         return true;
784                 /* not me */
785                 return false;
786         }
787
788         if (ret == -1) {
789                 return false;
790         }
791
792         return true;
793 }
794
795 static int vfs_gluster_kernel_flock(struct vfs_handle_struct *handle,
796                                     files_struct *fsp, uint32 share_mode,
797                                     uint32_t access_mask)
798 {
799         errno = ENOSYS;
800         return -1;
801 }
802
803 static int vfs_gluster_linux_setlease(struct vfs_handle_struct *handle,
804                                       files_struct *fsp, int leasetype)
805 {
806         errno = ENOSYS;
807         return -1;
808 }
809
810 static bool vfs_gluster_getlock(struct vfs_handle_struct *handle,
811                                 files_struct *fsp, off_t *poffset,
812                                 off_t *pcount, int *ptype, pid_t *ppid)
813 {
814         struct flock flock = { 0, };
815         int ret;
816
817         flock.l_type = *ptype;
818         flock.l_whence = SEEK_SET;
819         flock.l_start = *poffset;
820         flock.l_len = *pcount;
821         flock.l_pid = 0;
822
823         ret = glfs_posix_lock(glfd_fd_get(fsp->fh->fd), F_GETLK, &flock);
824
825         if (ret == -1) {
826                 return false;
827         }
828
829         *ptype = flock.l_type;
830         *poffset = flock.l_start;
831         *pcount = flock.l_len;
832         *ppid = flock.l_pid;
833
834         return true;
835 }
836
837 static int vfs_gluster_symlink(struct vfs_handle_struct *handle,
838                                const char *oldpath, const char *newpath)
839 {
840         return glfs_symlink(handle->data, oldpath, newpath);
841 }
842
843 static int vfs_gluster_readlink(struct vfs_handle_struct *handle,
844                                 const char *path, char *buf, size_t bufsiz)
845 {
846         return glfs_readlink(handle->data, path, buf, bufsiz);
847 }
848
849 static int vfs_gluster_link(struct vfs_handle_struct *handle,
850                             const char *oldpath, const char *newpath)
851 {
852         return glfs_link(handle->data, oldpath, newpath);
853 }
854
855 static int vfs_gluster_mknod(struct vfs_handle_struct *handle, const char *path,
856                              mode_t mode, SMB_DEV_T dev)
857 {
858         return glfs_mknod(handle->data, path, mode, dev);
859 }
860
861 static NTSTATUS vfs_gluster_notify_watch(struct vfs_handle_struct *handle,
862                                          struct sys_notify_context *ctx,
863                                          const char *path, uint32_t *filter,
864                                          uint32_t *subdir_filter,
865                                          void (*callback) (struct sys_notify_context *ctx,
866                                                            void *private_data,
867                                                            struct notify_event *ev),
868                                          void *private_data, void *handle_p)
869 {
870         return NT_STATUS_NOT_IMPLEMENTED;
871 }
872
873 static int vfs_gluster_chflags(struct vfs_handle_struct *handle,
874                                const char *path, unsigned int flags)
875 {
876         errno = ENOSYS;
877         return -1;
878 }
879
880 static int vfs_gluster_get_real_filename(struct vfs_handle_struct *handle,
881                                          const char *path, const char *name,
882                                          TALLOC_CTX *mem_ctx, char **found_name)
883 {
884         int ret;
885         char key_buf[NAME_MAX + 64];
886         char val_buf[NAME_MAX + 1];
887
888         if (strlen(name) >= NAME_MAX) {
889                 errno = ENAMETOOLONG;
890                 return -1;
891         }
892
893         snprintf(key_buf, NAME_MAX + 64,
894                  "user.glusterfs.get_real_filename:%s", name);
895
896         ret = glfs_getxattr(handle->data, path, key_buf, val_buf, NAME_MAX + 1);
897         if (ret == -1 && errno == ENODATA) {
898                 errno = EOPNOTSUPP;
899                 return -1;
900         }
901
902         *found_name = talloc_strdup(mem_ctx, val_buf);
903         if (found_name[0] == NULL) {
904                 errno = ENOMEM;
905                 return -1;
906         }
907         return 0;
908 }
909
910 static const char *vfs_gluster_connectpath(struct vfs_handle_struct *handle,
911                                            const char *filename)
912 {
913         return handle->conn->connectpath;
914 }
915
916 /* EA Operations */
917
918 static ssize_t vfs_gluster_getxattr(struct vfs_handle_struct *handle,
919                                     const char *path, const char *name,
920                                     void *value, size_t size)
921 {
922         return glfs_getxattr(handle->data, path, name, value, size);
923 }
924
925 static ssize_t vfs_gluster_fgetxattr(struct vfs_handle_struct *handle,
926                                      files_struct *fsp, const char *name,
927                                      void *value, size_t size)
928 {
929         return glfs_fgetxattr(glfd_fd_get(fsp->fh->fd), name, value, size);
930 }
931
932 static ssize_t vfs_gluster_listxattr(struct vfs_handle_struct *handle,
933                                      const char *path, char *list, size_t size)
934 {
935         return glfs_listxattr(handle->data, path, list, size);
936 }
937
938 static ssize_t vfs_gluster_flistxattr(struct vfs_handle_struct *handle,
939                                       files_struct *fsp, char *list,
940                                       size_t size)
941 {
942         return glfs_flistxattr(glfd_fd_get(fsp->fh->fd), list, size);
943 }
944
945 static int vfs_gluster_removexattr(struct vfs_handle_struct *handle,
946                                    const char *path, const char *name)
947 {
948         return glfs_removexattr(handle->data, path, name);
949 }
950
951 static int vfs_gluster_fremovexattr(struct vfs_handle_struct *handle,
952                                     files_struct *fsp, const char *name)
953 {
954         return glfs_fremovexattr(glfd_fd_get(fsp->fh->fd), name);
955 }
956
957 static int vfs_gluster_setxattr(struct vfs_handle_struct *handle,
958                                 const char *path, const char *name,
959                                 const void *value, size_t size, int flags)
960 {
961         return glfs_setxattr(handle->data, path, name, value, size, flags);
962 }
963
964 static int vfs_gluster_fsetxattr(struct vfs_handle_struct *handle,
965                                  files_struct *fsp, const char *name,
966                                  const void *value, size_t size, int flags)
967 {
968         return glfs_fsetxattr(glfd_fd_get(fsp->fh->fd), name, value, size,
969                               flags);
970 }
971
972 /* AIO Operations */
973
974 static bool vfs_gluster_aio_force(struct vfs_handle_struct *handle,
975                                   files_struct *fsp)
976 {
977         return false;
978 }
979
980 /* Offline Operations */
981
982 static bool vfs_gluster_is_offline(struct vfs_handle_struct *handle,
983                                    const struct smb_filename *fname,
984                                    SMB_STRUCT_STAT *sbuf)
985 {
986         return false;
987 }
988
989 static int vfs_gluster_set_offline(struct vfs_handle_struct *handle,
990                                    const struct smb_filename *fname)
991 {
992         errno = ENOTSUP;
993         return -1;
994 }
995
996 /* Posix ACL Operations */
997
998 #define GLUSTER_ACL_VERSION 2
999 #define GLUSTER_ACL_READ    0x04
1000 #define GLUSTER_ACL_WRITE   0x02
1001 #define GLUSTER_ACL_EXECUTE 0x01
1002
1003 #define GLUSTER_ACL_UNDEFINED_TAG  0x00
1004 #define GLUSTER_ACL_USER_OBJ       0x01
1005 #define GLUSTER_ACL_USER           0x02
1006 #define GLUSTER_ACL_GROUP_OBJ      0x04
1007 #define GLUSTER_ACL_GROUP          0x08
1008 #define GLUSTER_ACL_MASK           0x10
1009 #define GLUSTER_ACL_OTHER          0x20
1010
1011 #define GLUSTER_ACL_UNDEFINED_ID  (-1)
1012
1013 struct gluster_ace {
1014         uint16_t tag;
1015         uint16_t perm;
1016         uint32_t id;
1017 };
1018
1019 struct gluster_acl_header {
1020         uint32_t version;
1021         struct gluster_ace entries[];
1022 };
1023
1024 static SMB_ACL_T gluster_to_smb_acl(const char *buf, size_t xattr_size,
1025                                     TALLOC_CTX *mem_ctx)
1026 {
1027         int count;
1028         size_t size;
1029         struct gluster_ace *ace;
1030         struct smb_acl_entry *smb_ace;
1031         struct gluster_acl_header *hdr;
1032         struct smb_acl_t *result;
1033         int i;
1034         uint16_t tag;
1035         uint16_t perm;
1036         uint32_t id;
1037
1038         size = xattr_size;
1039
1040         if (size < sizeof(*hdr)) {
1041                 /* ACL should be at least as big as the header */
1042                 errno = EINVAL;
1043                 return NULL;
1044         }
1045
1046         size -= sizeof(*hdr);
1047
1048         if (size % sizeof(*ace)) {
1049                 /* Size of entries must strictly be a multiple of
1050                    size of an ACE
1051                 */
1052                 errno = EINVAL;
1053                 return NULL;
1054         }
1055
1056         count = size / sizeof(*ace);
1057
1058         hdr = (void *)buf;
1059
1060         if (ntohl(hdr->version) != GLUSTER_ACL_VERSION) {
1061                 DEBUG(0, ("Unknown gluster ACL version: %d\n",
1062                           ntohl(hdr->version)));
1063                 return NULL;
1064         }
1065
1066         result = sys_acl_init(mem_ctx);
1067         if (!result) {
1068                 errno = ENOMEM;
1069                 return NULL;
1070         }
1071
1072         result->acl = talloc_array(result, struct smb_acl_entry, count);
1073         if (!result->acl) {
1074                 errno = ENOMEM;
1075                 talloc_free(result);
1076                 return NULL;
1077         }
1078
1079         result->count = count;
1080
1081         smb_ace = result->acl;
1082         ace = hdr->entries;
1083
1084         for (i = 0; i < count; i++) {
1085                 tag = ntohs(ace->tag);
1086
1087                 switch(tag) {
1088                 case GLUSTER_ACL_USER:
1089                         smb_ace->a_type = SMB_ACL_USER;
1090                         break;
1091                 case GLUSTER_ACL_USER_OBJ:
1092                         smb_ace->a_type = SMB_ACL_USER_OBJ;
1093                         break;
1094                 case GLUSTER_ACL_GROUP:
1095                         smb_ace->a_type = SMB_ACL_GROUP;
1096                         break;
1097                 case GLUSTER_ACL_GROUP_OBJ:
1098                         smb_ace->a_type = SMB_ACL_GROUP_OBJ;
1099                         break;
1100                 case GLUSTER_ACL_OTHER:
1101                         smb_ace->a_type = SMB_ACL_OTHER;
1102                         break;
1103                 case GLUSTER_ACL_MASK:
1104                         smb_ace->a_type = SMB_ACL_MASK;
1105                         break;
1106                 default:
1107                         DEBUG(0, ("unknown tag type %d\n", (unsigned int) tag));
1108                         return NULL;
1109                 }
1110
1111                 id = ntohl(ace->id);
1112
1113                 switch(smb_ace->a_type) {
1114                 case SMB_ACL_USER:
1115                         smb_ace->info.user.uid = id;
1116                         break;
1117                 case SMB_ACL_GROUP:
1118                         smb_ace->info.group.gid = id;
1119                         break;
1120                 default:
1121                         break;
1122                 }
1123
1124                 perm = ntohs(ace->perm);
1125
1126                 smb_ace->a_perm = 0;
1127                 smb_ace->a_perm |=
1128                         ((perm & GLUSTER_ACL_READ) ? SMB_ACL_READ : 0);
1129                 smb_ace->a_perm |=
1130                         ((perm & GLUSTER_ACL_WRITE) ? SMB_ACL_WRITE : 0);
1131                 smb_ace->a_perm |=
1132                         ((perm & GLUSTER_ACL_EXECUTE) ? SMB_ACL_EXECUTE : 0);
1133
1134                 ace++;
1135                 smb_ace++;
1136         }
1137
1138         return result;
1139 }
1140
1141
1142 static ssize_t smb_to_gluster_acl(SMB_ACL_T theacl, char *buf, size_t len)
1143 {
1144         ssize_t size;
1145         struct gluster_ace *ace;
1146         struct smb_acl_entry *smb_ace;
1147         struct gluster_acl_header *hdr;
1148         int i;
1149         int count;
1150         uint16_t tag;
1151         uint16_t perm;
1152         uint32_t id;
1153
1154         count = theacl->count;
1155
1156         size = sizeof(*hdr) + (count * sizeof(*ace));
1157         if (!buf) {
1158                 return size;
1159         }
1160
1161         if (len < size) {
1162                 errno = ERANGE;
1163                 return -1;
1164         }
1165
1166         hdr = (void *)buf;
1167         ace = hdr->entries;
1168         smb_ace = theacl->acl;
1169
1170         hdr->version = htonl(GLUSTER_ACL_VERSION);
1171
1172         for (i = 0; i < count; i++) {
1173                 switch(smb_ace->a_type) {
1174                 case SMB_ACL_USER:
1175                         tag = GLUSTER_ACL_USER;
1176                         break;
1177                 case SMB_ACL_USER_OBJ:
1178                         tag = GLUSTER_ACL_USER_OBJ;
1179                         break;
1180                 case SMB_ACL_GROUP:
1181                         tag = GLUSTER_ACL_GROUP;
1182                         break;
1183                 case SMB_ACL_GROUP_OBJ:
1184                         tag = GLUSTER_ACL_GROUP_OBJ;
1185                         break;
1186                 case SMB_ACL_OTHER:
1187                         tag = GLUSTER_ACL_OTHER;
1188                         break;
1189                 case SMB_ACL_MASK:
1190                         tag = GLUSTER_ACL_MASK;
1191                         break;
1192                 default:
1193                         DEBUG(0, ("Unknown tag value %d\n",
1194                                   smb_ace->a_type));
1195                         errno = EINVAL;
1196                         return -1;
1197                 }
1198
1199                 ace->tag = ntohs(tag);
1200
1201                 switch(smb_ace->a_type) {
1202                 case SMB_ACL_USER:
1203                         id = smb_ace->info.user.uid;
1204                         break;
1205                 case SMB_ACL_GROUP:
1206                         id = smb_ace->info.group.gid;
1207                         break;
1208                 default:
1209                         id = GLUSTER_ACL_UNDEFINED_ID;
1210                         break;
1211                 }
1212
1213                 ace->id = ntohl(id);
1214
1215                 ace->perm = 0;
1216                 ace->perm |=
1217                         ((smb_ace->a_perm & SMB_ACL_READ) ? GLUSTER_ACL_READ : 0);
1218                 ace->perm |=
1219                         ((smb_ace->a_perm & SMB_ACL_WRITE) ? GLUSTER_ACL_WRITE : 0);
1220                 ace->perm |=
1221                         ((smb_ace->a_perm & SMB_ACL_EXECUTE) ? GLUSTER_ACL_EXECUTE : 0);
1222
1223                 ace++;
1224                 smb_ace++;
1225         }
1226
1227         return size;
1228 }
1229
1230
1231 static SMB_ACL_T vfs_gluster_sys_acl_get_file(struct vfs_handle_struct *handle,
1232                                               const char *path_p,
1233                                               SMB_ACL_TYPE_T type,
1234                                               TALLOC_CTX *mem_ctx)
1235 {
1236         struct smb_acl_t *result;
1237         char *buf;
1238         char *key;
1239         ssize_t ret;
1240
1241         switch (type) {
1242         case SMB_ACL_TYPE_ACCESS:
1243                 key = "system.posix_acl_access";
1244                 break;
1245         case SMB_ACL_TYPE_DEFAULT:
1246                 key = "system.posix_acl_default";
1247                 break;
1248         default:
1249                 errno = EINVAL;
1250                 return NULL;
1251         }
1252
1253         ret = glfs_getxattr(handle->data, path_p, key, 0, 0);
1254         if (ret <= 0) {
1255                 return NULL;
1256         }
1257
1258         buf = alloca(ret);
1259         ret = glfs_getxattr(handle->data, path_p, key, buf, ret);
1260         if (ret <= 0) {
1261                 return NULL;
1262         }
1263
1264         result = gluster_to_smb_acl(buf, ret, mem_ctx);
1265
1266         return result;
1267 }
1268
1269 static SMB_ACL_T vfs_gluster_sys_acl_get_fd(struct vfs_handle_struct *handle,
1270                                             struct files_struct *fsp,
1271                                             TALLOC_CTX *mem_ctx)
1272 {
1273         struct smb_acl_t *result;
1274         int ret;
1275         char *buf;
1276
1277         ret = glfs_fgetxattr(glfd_fd_get(fsp->fh->fd),
1278                              "system.posix_acl_access", 0, 0);
1279         if (ret <= 0) {
1280                 return NULL;
1281         }
1282
1283         buf = alloca(ret);
1284         ret = glfs_fgetxattr(glfd_fd_get(fsp->fh->fd),
1285                              "system.posix_acl_access", buf, ret);
1286         if (ret <= 0) {
1287                 return NULL;
1288         }
1289
1290         result = gluster_to_smb_acl(buf, ret, mem_ctx);
1291
1292         return result;
1293 }
1294
1295 static int vfs_gluster_sys_acl_set_file(struct vfs_handle_struct *handle,
1296                                         const char *name,
1297                                         SMB_ACL_TYPE_T acltype,
1298                                         SMB_ACL_T theacl)
1299 {
1300         int ret;
1301         char *key;
1302         char *buf;
1303         ssize_t size;
1304
1305         switch (acltype) {
1306         case SMB_ACL_TYPE_ACCESS:
1307                 key = "system.posix_acl_access";
1308                 break;
1309         case SMB_ACL_TYPE_DEFAULT:
1310                 key = "system.posix_acl_default";
1311                 break;
1312         default:
1313                 errno = EINVAL;
1314                 return -1;
1315         }
1316
1317         size = smb_to_gluster_acl(theacl, 0, 0);
1318         buf = alloca(size);
1319
1320         size = smb_to_gluster_acl(theacl, buf, size);
1321         if (size == -1) {
1322                 return -1;
1323         }
1324
1325         ret = glfs_setxattr(handle->data, name, key, buf, size, 0);
1326
1327         return ret;
1328 }
1329
1330 static int vfs_gluster_sys_acl_set_fd(struct vfs_handle_struct *handle,
1331                                       struct files_struct *fsp,
1332                                       SMB_ACL_T theacl)
1333 {
1334         int ret;
1335         char *key;
1336         char *buf;
1337         ssize_t size;
1338
1339         size = smb_to_gluster_acl(theacl, 0, 0);
1340         buf = alloca(size);
1341
1342         size = smb_to_gluster_acl(theacl, buf, size);
1343         if (size == -1) {
1344                 return -1;
1345         }
1346
1347         ret = glfs_fsetxattr(glfd_fd_get(fsp->fh->fd),
1348                              "system.posix_acl_access", buf, size, 0);
1349         return ret;
1350 }
1351
1352 static int vfs_gluster_sys_acl_delete_def_file(struct vfs_handle_struct *handle,
1353                                                const char *path)
1354 {
1355         return glfs_removexattr(handle->data, path, "system.posix_acl_default");
1356 }
1357
1358 static struct vfs_fn_pointers glusterfs_fns = {
1359
1360         /* Disk Operations */
1361
1362         .connect_fn = vfs_gluster_connect,
1363         .disconnect_fn = vfs_gluster_disconnect,
1364         .disk_free_fn = vfs_gluster_disk_free,
1365         .get_quota_fn = vfs_gluster_get_quota,
1366         .set_quota_fn = vfs_gluster_set_quota,
1367         .statvfs_fn = vfs_gluster_statvfs,
1368         .fs_capabilities_fn = vfs_gluster_fs_capabilities,
1369
1370         .get_dfs_referrals_fn = NULL,
1371
1372         /* Directory Operations */
1373
1374         .opendir_fn = vfs_gluster_opendir,
1375         .fdopendir_fn = vfs_gluster_fdopendir,
1376         .readdir_fn = vfs_gluster_readdir,
1377         .seekdir_fn = vfs_gluster_seekdir,
1378         .telldir_fn = vfs_gluster_telldir,
1379         .rewind_dir_fn = vfs_gluster_rewinddir,
1380         .mkdir_fn = vfs_gluster_mkdir,
1381         .rmdir_fn = vfs_gluster_rmdir,
1382         .closedir_fn = vfs_gluster_closedir,
1383         .init_search_op_fn = vfs_gluster_init_search_op,
1384
1385         /* File Operations */
1386
1387         .open_fn = vfs_gluster_open,
1388         .create_file_fn = NULL,
1389         .close_fn = vfs_gluster_close,
1390         .read_fn = vfs_gluster_read,
1391         .pread_fn = vfs_gluster_pread,
1392         .pread_send_fn = vfs_gluster_pread_send,
1393         .pread_recv_fn = vfs_gluster_pread_recv,
1394         .write_fn = vfs_gluster_write,
1395         .pwrite_fn = vfs_gluster_pwrite,
1396         .pwrite_send_fn = vfs_gluster_pwrite_send,
1397         .pwrite_recv_fn = vfs_gluster_pwrite_recv,
1398         .lseek_fn = vfs_gluster_lseek,
1399         .sendfile_fn = vfs_gluster_sendfile,
1400         .recvfile_fn = vfs_gluster_recvfile,
1401         .rename_fn = vfs_gluster_rename,
1402         .fsync_fn = vfs_gluster_fsync,
1403         .fsync_send_fn = vfs_gluster_fsync_send,
1404         .fsync_recv_fn = vfs_gluster_fsync_recv,
1405
1406         .stat_fn = vfs_gluster_stat,
1407         .fstat_fn = vfs_gluster_fstat,
1408         .lstat_fn = vfs_gluster_lstat,
1409         .get_alloc_size_fn = vfs_gluster_get_alloc_size,
1410         .unlink_fn = vfs_gluster_unlink,
1411
1412         .chmod_fn = vfs_gluster_chmod,
1413         .fchmod_fn = vfs_gluster_fchmod,
1414         .chown_fn = vfs_gluster_chown,
1415         .fchown_fn = vfs_gluster_fchown,
1416         .lchown_fn = vfs_gluster_lchown,
1417         .chdir_fn = vfs_gluster_chdir,
1418         .getwd_fn = vfs_gluster_getwd,
1419         .ntimes_fn = vfs_gluster_ntimes,
1420         .ftruncate_fn = vfs_gluster_ftruncate,
1421         .fallocate_fn = vfs_gluster_fallocate,
1422         .lock_fn = vfs_gluster_lock,
1423         .kernel_flock_fn = vfs_gluster_kernel_flock,
1424         .linux_setlease_fn = vfs_gluster_linux_setlease,
1425         .getlock_fn = vfs_gluster_getlock,
1426         .symlink_fn = vfs_gluster_symlink,
1427         .readlink_fn = vfs_gluster_readlink,
1428         .link_fn = vfs_gluster_link,
1429         .mknod_fn = vfs_gluster_mknod,
1430         .realpath_fn = vfs_gluster_realpath,
1431         .notify_watch_fn = vfs_gluster_notify_watch,
1432         .chflags_fn = vfs_gluster_chflags,
1433         .file_id_create_fn = NULL,
1434         .copy_chunk_send_fn = NULL,
1435         .copy_chunk_recv_fn = NULL,
1436         .streaminfo_fn = NULL,
1437         .get_real_filename_fn = vfs_gluster_get_real_filename,
1438         .connectpath_fn = vfs_gluster_connectpath,
1439
1440         .brl_lock_windows_fn = NULL,
1441         .brl_unlock_windows_fn = NULL,
1442         .brl_cancel_windows_fn = NULL,
1443         .strict_lock_fn = NULL,
1444         .strict_unlock_fn = NULL,
1445         .translate_name_fn = NULL,
1446         .fsctl_fn = NULL,
1447
1448         /* NT ACL Operations */
1449         .fget_nt_acl_fn = NULL,
1450         .get_nt_acl_fn = NULL,
1451         .fset_nt_acl_fn = NULL,
1452         .audit_file_fn = NULL,
1453
1454         /* Posix ACL Operations */
1455         .chmod_acl_fn = NULL,   /* passthrough to default */
1456         .fchmod_acl_fn = NULL,  /* passthrough to default */
1457         .sys_acl_get_file_fn = vfs_gluster_sys_acl_get_file,
1458         .sys_acl_get_fd_fn = vfs_gluster_sys_acl_get_fd,
1459         .sys_acl_blob_get_file_fn = posix_sys_acl_blob_get_file,
1460         .sys_acl_blob_get_fd_fn = posix_sys_acl_blob_get_fd,
1461         .sys_acl_set_file_fn = vfs_gluster_sys_acl_set_file,
1462         .sys_acl_set_fd_fn = vfs_gluster_sys_acl_set_fd,
1463         .sys_acl_delete_def_file_fn = vfs_gluster_sys_acl_delete_def_file,
1464
1465         /* EA Operations */
1466         .getxattr_fn = vfs_gluster_getxattr,
1467         .fgetxattr_fn = vfs_gluster_fgetxattr,
1468         .listxattr_fn = vfs_gluster_listxattr,
1469         .flistxattr_fn = vfs_gluster_flistxattr,
1470         .removexattr_fn = vfs_gluster_removexattr,
1471         .fremovexattr_fn = vfs_gluster_fremovexattr,
1472         .setxattr_fn = vfs_gluster_setxattr,
1473         .fsetxattr_fn = vfs_gluster_fsetxattr,
1474
1475         /* AIO Operations */
1476         .aio_force_fn = vfs_gluster_aio_force,
1477
1478         /* Offline Operations */
1479         .is_offline_fn = vfs_gluster_is_offline,
1480         .set_offline_fn = vfs_gluster_set_offline,
1481
1482         /* Durable handle Operations */
1483         .durable_cookie_fn = NULL,
1484         .durable_disconnect_fn = NULL,
1485         .durable_reconnect_fn = NULL,
1486 };
1487
1488 NTSTATUS vfs_glusterfs_init(void);
1489 NTSTATUS vfs_glusterfs_init(void)
1490 {
1491         return smb_register_vfs(SMB_VFS_INTERFACE_VERSION,
1492                                 "glusterfs", &glusterfs_fns);
1493 }