Merge branch 'master' of ctdb into 'master' of samba
[sfrench/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 #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         int ret;
305
306         ret = glfs_statvfs(handle->data, path, &statvfs);
307         if (ret < 0) {
308                 return -1;
309         }
310
311         if (bsize_p != NULL) {
312                 *bsize_p = (uint64_t)statvfs.f_bsize; /* Block size */
313         }
314         if (dfree_p != NULL) {
315                 *dfree_p = (uint64_t)statvfs.f_bavail; /* Available Block units */
316         }
317         if (dsize_p != NULL) {
318                 *dsize_p = (uint64_t)statvfs.f_blocks; /* Total Block units */
319         }
320
321         return (uint64_t)statvfs.f_bavail;
322 }
323
324 static int vfs_gluster_get_quota(struct vfs_handle_struct *handle,
325                                  enum SMB_QUOTA_TYPE qtype, unid_t id,
326                                  SMB_DISK_QUOTA *qt)
327 {
328         errno = ENOSYS;
329         return -1;
330 }
331
332 static int
333 vfs_gluster_set_quota(struct vfs_handle_struct *handle,
334                       enum SMB_QUOTA_TYPE qtype, unid_t id, SMB_DISK_QUOTA *qt)
335 {
336         errno = ENOSYS;
337         return -1;
338 }
339
340 static int vfs_gluster_statvfs(struct vfs_handle_struct *handle,
341                                const char *path,
342                                struct vfs_statvfs_struct *vfs_statvfs)
343 {
344         struct statvfs statvfs = { 0, };
345         int ret;
346
347         ret = glfs_statvfs(handle->data, path, &statvfs);
348         if (ret < 0) {
349                 DEBUG(0, ("glfs_statvfs(%s) failed: %s\n",
350                           path, strerror(errno)));
351                 return -1;
352         }
353
354         ZERO_STRUCTP(vfs_statvfs);
355
356         vfs_statvfs->OptimalTransferSize = statvfs.f_frsize;
357         vfs_statvfs->BlockSize = statvfs.f_bsize;
358         vfs_statvfs->TotalBlocks = statvfs.f_blocks;
359         vfs_statvfs->BlocksAvail = statvfs.f_bfree;
360         vfs_statvfs->UserBlocksAvail = statvfs.f_bavail;
361         vfs_statvfs->TotalFileNodes = statvfs.f_files;
362         vfs_statvfs->FreeFileNodes = statvfs.f_ffree;
363         vfs_statvfs->FsIdentifier = statvfs.f_fsid;
364         vfs_statvfs->FsCapabilities =
365             FILE_CASE_SENSITIVE_SEARCH | FILE_CASE_PRESERVED_NAMES;
366
367         return ret;
368 }
369
370 static uint32_t vfs_gluster_fs_capabilities(struct vfs_handle_struct *handle,
371                                             enum timestamp_set_resolution *p_ts_res)
372 {
373         uint32_t caps = FILE_CASE_SENSITIVE_SEARCH | FILE_CASE_PRESERVED_NAMES;
374
375 #ifdef STAT_HAVE_NSEC
376         *p_ts_res = TIMESTAMP_SET_NT_OR_BETTER;
377 #endif
378
379         return caps;
380 }
381
382 static DIR *vfs_gluster_opendir(struct vfs_handle_struct *handle,
383                                 const char *path, const char *mask,
384                                 uint32 attributes)
385 {
386         glfs_fd_t *fd;
387
388         fd = glfs_opendir(handle->data, path);
389         if (fd == NULL) {
390                 DEBUG(0, ("glfs_opendir(%s) failed: %s\n",
391                           path, strerror(errno)));
392         }
393
394         return (DIR *) fd;
395 }
396
397 static DIR *vfs_gluster_fdopendir(struct vfs_handle_struct *handle,
398                                   files_struct *fsp, const char *mask,
399                                   uint32 attributes)
400 {
401         return (DIR *) glfd_fd_get(fsp->fh->fd);
402 }
403
404 static int vfs_gluster_closedir(struct vfs_handle_struct *handle, DIR *dirp)
405 {
406         return glfs_closedir((void *)dirp);
407 }
408
409 static struct dirent *vfs_gluster_readdir(struct vfs_handle_struct *handle,
410                                           DIR *dirp, SMB_STRUCT_STAT *sbuf)
411 {
412         static char direntbuf[512];
413         int ret;
414         struct stat stat;
415         struct dirent *dirent = 0;
416
417         if (sbuf != NULL) {
418                 ret = glfs_readdirplus_r((void *)dirp, &stat, (void *)direntbuf,
419                                          &dirent);
420         } else {
421                 ret = glfs_readdir_r((void *)dirp, (void *)direntbuf, &dirent);
422         }
423
424         if ((ret < 0) || (dirent == NULL)) {
425                 return NULL;
426         }
427
428         if (sbuf != NULL) {
429                 smb_stat_ex_from_stat(sbuf, &stat);
430         }
431
432         return dirent;
433 }
434
435 static long vfs_gluster_telldir(struct vfs_handle_struct *handle, DIR *dirp)
436 {
437         return glfs_telldir((void *)dirp);
438 }
439
440 static void vfs_gluster_seekdir(struct vfs_handle_struct *handle, DIR *dirp,
441                                 long offset)
442 {
443         glfs_seekdir((void *)dirp, offset);
444 }
445
446 static void vfs_gluster_rewinddir(struct vfs_handle_struct *handle, DIR *dirp)
447 {
448         glfs_seekdir((void *)dirp, 0);
449 }
450
451 static void vfs_gluster_init_search_op(struct vfs_handle_struct *handle,
452                                        DIR *dirp)
453 {
454         return;
455 }
456
457 static int vfs_gluster_mkdir(struct vfs_handle_struct *handle, const char *path,
458                              mode_t mode)
459 {
460         return glfs_mkdir(handle->data, path, mode);
461 }
462
463 static int vfs_gluster_rmdir(struct vfs_handle_struct *handle, const char *path)
464 {
465         return glfs_rmdir(handle->data, path);
466 }
467
468 static int vfs_gluster_open(struct vfs_handle_struct *handle,
469                             struct smb_filename *smb_fname, files_struct *fsp,
470                             int flags, mode_t mode)
471 {
472         glfs_fd_t *glfd;
473
474         if (flags & O_DIRECTORY) {
475                 glfd = glfs_opendir(handle->data, smb_fname->base_name);
476         } else if (flags & O_CREAT) {
477                 glfd = glfs_creat(handle->data, smb_fname->base_name, flags,
478                                   mode);
479         } else {
480                 glfd = glfs_open(handle->data, smb_fname->base_name, flags);
481         }
482
483         if (glfd == NULL) {
484                 return -1;
485         }
486         return glfd_fd_store(glfd);
487 }
488
489 static int vfs_gluster_close(struct vfs_handle_struct *handle,
490                              files_struct *fsp)
491 {
492         return glfs_close(glfd_fd_clear(fsp->fh->fd));
493 }
494
495 static ssize_t vfs_gluster_read(struct vfs_handle_struct *handle,
496                                 files_struct *fsp, void *data, size_t n)
497 {
498         return glfs_read(glfd_fd_get(fsp->fh->fd), data, n, 0);
499 }
500
501 static ssize_t vfs_gluster_pread(struct vfs_handle_struct *handle,
502                                  files_struct *fsp, void *data, size_t n,
503                                  off_t offset)
504 {
505         return glfs_pread(glfd_fd_get(fsp->fh->fd), data, n, offset, 0);
506 }
507
508 static struct tevent_req *vfs_gluster_pread_send(struct vfs_handle_struct
509                                                  *handle, TALLOC_CTX *mem_ctx,
510                                                  struct tevent_context *ev,
511                                                  files_struct *fsp, void *data,
512                                                  size_t n, off_t offset)
513 {
514         errno = ENOTSUP;
515         return NULL;
516 }
517
518 static ssize_t vfs_gluster_pread_recv(struct tevent_req *req, int *err)
519 {
520         errno = ENOTSUP;
521         return -1;
522 }
523
524 static ssize_t vfs_gluster_write(struct vfs_handle_struct *handle,
525                                  files_struct *fsp, const void *data, size_t n)
526 {
527         return glfs_write(glfd_fd_get(fsp->fh->fd), data, n, 0);
528 }
529
530 static ssize_t vfs_gluster_pwrite(struct vfs_handle_struct *handle,
531                                   files_struct *fsp, const void *data,
532                                   size_t n, off_t offset)
533 {
534         return glfs_pwrite(glfd_fd_get(fsp->fh->fd), data, n, offset, 0);
535 }
536
537 static struct tevent_req *vfs_gluster_pwrite_send(struct vfs_handle_struct
538                                                   *handle, TALLOC_CTX *mem_ctx,
539                                                   struct tevent_context *ev,
540                                                   files_struct *fsp,
541                                                   const void *data, size_t n,
542                                                   off_t offset)
543 {
544         errno = ENOTSUP;
545         return NULL;
546 }
547
548 static ssize_t vfs_gluster_pwrite_recv(struct tevent_req *req, int *err)
549 {
550         errno = ENOTSUP;
551         return -1;
552 }
553
554 static off_t vfs_gluster_lseek(struct vfs_handle_struct *handle,
555                                files_struct *fsp, off_t offset, int whence)
556 {
557         return glfs_lseek(glfd_fd_get(fsp->fh->fd), offset, whence);
558 }
559
560 static ssize_t vfs_gluster_sendfile(struct vfs_handle_struct *handle, int tofd,
561                                     files_struct *fromfsp,
562                                     const DATA_BLOB *hdr,
563                                     off_t offset, size_t n)
564 {
565         errno = ENOTSUP;
566         return -1;
567 }
568
569 static ssize_t vfs_gluster_recvfile(struct vfs_handle_struct *handle,
570                                     int fromfd, files_struct *tofsp,
571                                     off_t offset, size_t n)
572 {
573         errno = ENOTSUP;
574         return -1;
575 }
576
577 static int vfs_gluster_rename(struct vfs_handle_struct *handle,
578                               const struct smb_filename *smb_fname_src,
579                               const struct smb_filename *smb_fname_dst)
580 {
581         return glfs_rename(handle->data, smb_fname_src->base_name,
582                            smb_fname_dst->base_name);
583 }
584
585 static int vfs_gluster_fsync(struct vfs_handle_struct *handle,
586                              files_struct *fsp)
587 {
588         return glfs_fsync(glfd_fd_get(fsp->fh->fd));
589 }
590
591 static struct tevent_req *vfs_gluster_fsync_send(struct vfs_handle_struct
592                                                  *handle, TALLOC_CTX *mem_ctx,
593                                                  struct tevent_context *ev,
594                                                  files_struct *fsp)
595 {
596         errno = ENOTSUP;
597         return NULL;
598 }
599
600 static int vfs_gluster_fsync_recv(struct tevent_req *req, int *err)
601 {
602         errno = ENOTSUP;
603         return -1;
604 }
605
606 static int vfs_gluster_stat(struct vfs_handle_struct *handle,
607                             struct smb_filename *smb_fname)
608 {
609         struct stat st;
610         int ret;
611
612         ret = glfs_stat(handle->data, smb_fname->base_name, &st);
613         if (ret == 0) {
614                 smb_stat_ex_from_stat(&smb_fname->st, &st);
615         }
616         if (ret < 0 && errno != ENOENT) {
617                 DEBUG(0, ("glfs_stat(%s) failed: %s\n",
618                           smb_fname->base_name, strerror(errno)));
619         }
620         return ret;
621 }
622
623 static int vfs_gluster_fstat(struct vfs_handle_struct *handle,
624                              files_struct *fsp, SMB_STRUCT_STAT *sbuf)
625 {
626         struct stat st;
627         int ret;
628
629         ret = glfs_fstat(glfd_fd_get(fsp->fh->fd), &st);
630         if (ret == 0) {
631                 smb_stat_ex_from_stat(sbuf, &st);
632         }
633         if (ret < 0) {
634                 DEBUG(0, ("glfs_fstat(%d) failed: %s\n",
635                           fsp->fh->fd, strerror(errno)));
636         }
637         return ret;
638 }
639
640 static int vfs_gluster_lstat(struct vfs_handle_struct *handle,
641                              struct smb_filename *smb_fname)
642 {
643         struct stat st;
644         int ret;
645
646         ret = glfs_lstat(handle->data, smb_fname->base_name, &st);
647         if (ret == 0) {
648                 smb_stat_ex_from_stat(&smb_fname->st, &st);
649         }
650         if (ret < 0 && errno != ENOENT) {
651                 DEBUG(0, ("glfs_lstat(%s) failed: %s\n",
652                           smb_fname->base_name, strerror(errno)));
653         }
654         return ret;
655 }
656
657 static uint64_t vfs_gluster_get_alloc_size(struct vfs_handle_struct *handle,
658                                            files_struct *fsp,
659                                            const SMB_STRUCT_STAT *sbuf)
660 {
661         return sbuf->st_ex_blocks * 512;
662 }
663
664 static int vfs_gluster_unlink(struct vfs_handle_struct *handle,
665                               const struct smb_filename *smb_fname)
666 {
667         return glfs_unlink(handle->data, smb_fname->base_name);
668 }
669
670 static int vfs_gluster_chmod(struct vfs_handle_struct *handle,
671                              const char *path, mode_t mode)
672 {
673         return glfs_chmod(handle->data, path, mode);
674 }
675
676 static int vfs_gluster_fchmod(struct vfs_handle_struct *handle,
677                               files_struct *fsp, mode_t mode)
678 {
679         return glfs_fchmod(glfd_fd_get(fsp->fh->fd), mode);
680 }
681
682 static int vfs_gluster_chown(struct vfs_handle_struct *handle,
683                              const char *path, uid_t uid, gid_t gid)
684 {
685         return glfs_chown(handle->data, path, uid, gid);
686 }
687
688 static int vfs_gluster_fchown(struct vfs_handle_struct *handle,
689                               files_struct *fsp, uid_t uid, gid_t gid)
690 {
691         return glfs_fchown(glfd_fd_get(fsp->fh->fd), uid, gid);
692 }
693
694 static int vfs_gluster_lchown(struct vfs_handle_struct *handle,
695                               const char *path, uid_t uid, gid_t gid)
696 {
697         return glfs_lchown(handle->data, path, uid, gid);
698 }
699
700 static int vfs_gluster_chdir(struct vfs_handle_struct *handle, const char *path)
701 {
702         return glfs_chdir(handle->data, path);
703 }
704
705 static char *vfs_gluster_getwd(struct vfs_handle_struct *handle)
706 {
707         char *cwd;
708         char *ret;
709
710         cwd = SMB_CALLOC_ARRAY(char, PATH_MAX);
711         if (cwd == NULL) {
712                 return NULL;
713         }
714
715         ret = glfs_getcwd(handle->data, cwd, PATH_MAX - 1);
716         if (ret == 0) {
717                 free(cwd);
718         }
719         return ret;
720 }
721
722 static int vfs_gluster_ntimes(struct vfs_handle_struct *handle,
723                               const struct smb_filename *smb_fname,
724                               struct smb_file_time *ft)
725 {
726         struct timespec times[2];
727
728         times[0].tv_sec = ft->atime.tv_sec;
729         times[0].tv_nsec = ft->atime.tv_nsec;
730         times[1].tv_sec = ft->mtime.tv_sec;
731         times[1].tv_nsec = ft->mtime.tv_nsec;
732
733         return glfs_utimens(handle->data, smb_fname->base_name, times);
734 }
735
736 static int vfs_gluster_ftruncate(struct vfs_handle_struct *handle,
737                                  files_struct *fsp, off_t offset)
738 {
739         return glfs_ftruncate(glfd_fd_get(fsp->fh->fd), offset);
740 }
741
742 static int vfs_gluster_fallocate(struct vfs_handle_struct *handle,
743                                  struct files_struct *fsp,
744                                  enum vfs_fallocate_mode mode,
745                                  off_t offset, off_t len)
746 {
747         errno = ENOTSUP;
748         return -1;
749 }
750
751 static char *vfs_gluster_realpath(struct vfs_handle_struct *handle,
752                                   const char *path)
753 {
754         return glfs_realpath(handle->data, path, 0);
755 }
756
757 static bool vfs_gluster_lock(struct vfs_handle_struct *handle,
758                              files_struct *fsp, int op, off_t offset,
759                              off_t count, int type)
760 {
761         struct flock flock = { 0, };
762         int ret;
763
764         flock.l_type = type;
765         flock.l_whence = SEEK_SET;
766         flock.l_start = offset;
767         flock.l_len = count;
768         flock.l_pid = 0;
769
770         ret = glfs_posix_lock(glfd_fd_get(fsp->fh->fd), op, &flock);
771
772         if (op == F_GETLK) {
773                 /* lock query, true if someone else has locked */
774                 if ((ret != -1) &&
775                     (flock.l_type != F_UNLCK) &&
776                     (flock.l_pid != 0) && (flock.l_pid != getpid()))
777                         return true;
778                 /* not me */
779                 return false;
780         }
781
782         if (ret == -1) {
783                 return false;
784         }
785
786         return true;
787 }
788
789 static int vfs_gluster_kernel_flock(struct vfs_handle_struct *handle,
790                                     files_struct *fsp, uint32 share_mode,
791                                     uint32_t access_mask)
792 {
793         errno = ENOSYS;
794         return -1;
795 }
796
797 static int vfs_gluster_linux_setlease(struct vfs_handle_struct *handle,
798                                       files_struct *fsp, int leasetype)
799 {
800         errno = ENOSYS;
801         return -1;
802 }
803
804 static bool vfs_gluster_getlock(struct vfs_handle_struct *handle,
805                                 files_struct *fsp, off_t *poffset,
806                                 off_t *pcount, int *ptype, pid_t *ppid)
807 {
808         struct flock flock = { 0, };
809         int ret;
810
811         flock.l_type = *ptype;
812         flock.l_whence = SEEK_SET;
813         flock.l_start = *poffset;
814         flock.l_len = *pcount;
815         flock.l_pid = 0;
816
817         ret = glfs_posix_lock(glfd_fd_get(fsp->fh->fd), F_GETLK, &flock);
818
819         if (ret == -1) {
820                 return false;
821         }
822
823         *ptype = flock.l_type;
824         *poffset = flock.l_start;
825         *pcount = flock.l_len;
826         *ppid = flock.l_pid;
827
828         return true;
829 }
830
831 static int vfs_gluster_symlink(struct vfs_handle_struct *handle,
832                                const char *oldpath, const char *newpath)
833 {
834         return glfs_symlink(handle->data, oldpath, newpath);
835 }
836
837 static int vfs_gluster_readlink(struct vfs_handle_struct *handle,
838                                 const char *path, char *buf, size_t bufsiz)
839 {
840         return glfs_readlink(handle->data, path, buf, bufsiz);
841 }
842
843 static int vfs_gluster_link(struct vfs_handle_struct *handle,
844                             const char *oldpath, const char *newpath)
845 {
846         return glfs_link(handle->data, oldpath, newpath);
847 }
848
849 static int vfs_gluster_mknod(struct vfs_handle_struct *handle, const char *path,
850                              mode_t mode, SMB_DEV_T dev)
851 {
852         return glfs_mknod(handle->data, path, mode, dev);
853 }
854
855 static NTSTATUS vfs_gluster_notify_watch(struct vfs_handle_struct *handle,
856                                          struct sys_notify_context *ctx,
857                                          const char *path, uint32_t *filter,
858                                          uint32_t *subdir_filter,
859                                          void (*callback) (struct sys_notify_context *ctx,
860                                                            void *private_data,
861                                                            struct notify_event *ev),
862                                          void *private_data, void *handle_p)
863 {
864         return NT_STATUS_NOT_IMPLEMENTED;
865 }
866
867 static int vfs_gluster_chflags(struct vfs_handle_struct *handle,
868                                const char *path, unsigned int flags)
869 {
870         errno = ENOSYS;
871         return -1;
872 }
873
874 static int vfs_gluster_get_real_filename(struct vfs_handle_struct *handle,
875                                          const char *path, const char *name,
876                                          TALLOC_CTX *mem_ctx, char **found_name)
877 {
878         int ret;
879         char key_buf[NAME_MAX + 64];
880         char val_buf[NAME_MAX + 1];
881
882         if (strlen(name) >= NAME_MAX) {
883                 errno = ENAMETOOLONG;
884                 return -1;
885         }
886
887         snprintf(key_buf, NAME_MAX + 64,
888                  "user.glusterfs.get_real_filename:%s", name);
889
890         ret = glfs_getxattr(handle->data, path, key_buf, val_buf, NAME_MAX + 1);
891         if (ret == -1) {
892                 if (errno == ENODATA) {
893                         errno = EOPNOTSUPP;
894                 }
895                 return -1;
896         }
897
898         *found_name = talloc_strdup(mem_ctx, val_buf);
899         if (found_name[0] == NULL) {
900                 errno = ENOMEM;
901                 return -1;
902         }
903         return 0;
904 }
905
906 static const char *vfs_gluster_connectpath(struct vfs_handle_struct *handle,
907                                            const char *filename)
908 {
909         return handle->conn->connectpath;
910 }
911
912 /* EA Operations */
913
914 static ssize_t vfs_gluster_getxattr(struct vfs_handle_struct *handle,
915                                     const char *path, const char *name,
916                                     void *value, size_t size)
917 {
918         return glfs_getxattr(handle->data, path, name, value, size);
919 }
920
921 static ssize_t vfs_gluster_fgetxattr(struct vfs_handle_struct *handle,
922                                      files_struct *fsp, const char *name,
923                                      void *value, size_t size)
924 {
925         return glfs_fgetxattr(glfd_fd_get(fsp->fh->fd), name, value, size);
926 }
927
928 static ssize_t vfs_gluster_listxattr(struct vfs_handle_struct *handle,
929                                      const char *path, char *list, size_t size)
930 {
931         return glfs_listxattr(handle->data, path, list, size);
932 }
933
934 static ssize_t vfs_gluster_flistxattr(struct vfs_handle_struct *handle,
935                                       files_struct *fsp, char *list,
936                                       size_t size)
937 {
938         return glfs_flistxattr(glfd_fd_get(fsp->fh->fd), list, size);
939 }
940
941 static int vfs_gluster_removexattr(struct vfs_handle_struct *handle,
942                                    const char *path, const char *name)
943 {
944         return glfs_removexattr(handle->data, path, name);
945 }
946
947 static int vfs_gluster_fremovexattr(struct vfs_handle_struct *handle,
948                                     files_struct *fsp, const char *name)
949 {
950         return glfs_fremovexattr(glfd_fd_get(fsp->fh->fd), name);
951 }
952
953 static int vfs_gluster_setxattr(struct vfs_handle_struct *handle,
954                                 const char *path, const char *name,
955                                 const void *value, size_t size, int flags)
956 {
957         return glfs_setxattr(handle->data, path, name, value, size, flags);
958 }
959
960 static int vfs_gluster_fsetxattr(struct vfs_handle_struct *handle,
961                                  files_struct *fsp, const char *name,
962                                  const void *value, size_t size, int flags)
963 {
964         return glfs_fsetxattr(glfd_fd_get(fsp->fh->fd), name, value, size,
965                               flags);
966 }
967
968 /* AIO Operations */
969
970 static bool vfs_gluster_aio_force(struct vfs_handle_struct *handle,
971                                   files_struct *fsp)
972 {
973         return false;
974 }
975
976 /* Offline Operations */
977
978 static bool vfs_gluster_is_offline(struct vfs_handle_struct *handle,
979                                    const struct smb_filename *fname,
980                                    SMB_STRUCT_STAT *sbuf)
981 {
982         return false;
983 }
984
985 static int vfs_gluster_set_offline(struct vfs_handle_struct *handle,
986                                    const struct smb_filename *fname)
987 {
988         errno = ENOTSUP;
989         return -1;
990 }
991
992 /*
993   Gluster ACL Format:
994
995   Size = 4 (header) + N * 8 (entry)
996
997   Offset  Size    Field (Little Endian)
998   -------------------------------------
999   0-3     4-byte  Version
1000
1001   4-5     2-byte  Entry-1 tag
1002   6-7     2-byte  Entry-1 perm
1003   8-11    4-byte  Entry-1 id
1004
1005   12-13   2-byte  Entry-2 tag
1006   14-15   2-byte  Entry-2 perm
1007   16-19   4-byte  Entry-2 id
1008
1009   ...
1010
1011  */
1012
1013 /* header version */
1014 #define GLUSTER_ACL_VERSION 2
1015
1016 /* perm bits */
1017 #define GLUSTER_ACL_READ    0x04
1018 #define GLUSTER_ACL_WRITE   0x02
1019 #define GLUSTER_ACL_EXECUTE 0x01
1020
1021 /* tag values */
1022 #define GLUSTER_ACL_UNDEFINED_TAG  0x00
1023 #define GLUSTER_ACL_USER_OBJ       0x01
1024 #define GLUSTER_ACL_USER           0x02
1025 #define GLUSTER_ACL_GROUP_OBJ      0x04
1026 #define GLUSTER_ACL_GROUP          0x08
1027 #define GLUSTER_ACL_MASK           0x10
1028 #define GLUSTER_ACL_OTHER          0x20
1029
1030 #define GLUSTER_ACL_UNDEFINED_ID  (-1)
1031
1032 #define GLUSTER_ACL_HEADER_SIZE    4
1033 #define GLUSTER_ACL_ENTRY_SIZE     8
1034
1035 static SMB_ACL_T gluster_to_smb_acl(const char *buf, size_t xattr_size,
1036                                     TALLOC_CTX *mem_ctx)
1037 {
1038         int count;
1039         size_t size;
1040         struct smb_acl_entry *smb_ace;
1041         struct smb_acl_t *result;
1042         int i;
1043         int offset;
1044         uint16_t tag;
1045         uint16_t perm;
1046         uint32_t id;
1047
1048         size = xattr_size;
1049
1050         if (size < GLUSTER_ACL_HEADER_SIZE) {
1051                 /* ACL should be at least as big as the header (4 bytes) */
1052                 errno = EINVAL;
1053                 return NULL;
1054         }
1055
1056         size -= GLUSTER_ACL_HEADER_SIZE; /* size of header = 4 bytes */
1057
1058         if (size % GLUSTER_ACL_ENTRY_SIZE) {
1059                 /* Size of entries must strictly be a multiple of
1060                    size of an ACE (8 bytes)
1061                 */
1062                 errno = EINVAL;
1063                 return NULL;
1064         }
1065
1066         count = size / GLUSTER_ACL_ENTRY_SIZE;
1067
1068         /* Version is the first 4 bytes of the ACL */
1069         if (IVAL(buf, 0) != GLUSTER_ACL_VERSION) {
1070                 DEBUG(0, ("Unknown gluster ACL version: %d\n",
1071                           IVAL(buf, 0)));
1072                 return NULL;
1073         }
1074         offset = GLUSTER_ACL_HEADER_SIZE;
1075
1076         result = sys_acl_init(mem_ctx);
1077         if (!result) {
1078                 errno = ENOMEM;
1079                 return NULL;
1080         }
1081
1082         result->acl = talloc_array(result, struct smb_acl_entry, count);
1083         if (!result->acl) {
1084                 errno = ENOMEM;
1085                 talloc_free(result);
1086                 return NULL;
1087         }
1088
1089         result->count = count;
1090
1091         smb_ace = result->acl;
1092
1093         for (i = 0; i < count; i++) {
1094                 /* TAG is the first 2 bytes of an entry */
1095                 tag = SVAL(buf, offset);
1096                 offset += 2;
1097
1098                 /* PERM is the next 2 bytes of an entry */
1099                 perm = SVAL(buf, offset);
1100                 offset += 2;
1101
1102                 /* ID is the last 4 bytes of an entry */
1103                 id = IVAL(buf, offset);
1104                 offset += 4;
1105
1106                 switch(tag) {
1107                 case GLUSTER_ACL_USER:
1108                         smb_ace->a_type = SMB_ACL_USER;
1109                         break;
1110                 case GLUSTER_ACL_USER_OBJ:
1111                         smb_ace->a_type = SMB_ACL_USER_OBJ;
1112                         break;
1113                 case GLUSTER_ACL_GROUP:
1114                         smb_ace->a_type = SMB_ACL_GROUP;
1115                         break;
1116                 case GLUSTER_ACL_GROUP_OBJ:
1117                         smb_ace->a_type = SMB_ACL_GROUP_OBJ;
1118                         break;
1119                 case GLUSTER_ACL_OTHER:
1120                         smb_ace->a_type = SMB_ACL_OTHER;
1121                         break;
1122                 case GLUSTER_ACL_MASK:
1123                         smb_ace->a_type = SMB_ACL_MASK;
1124                         break;
1125                 default:
1126                         DEBUG(0, ("unknown tag type %d\n", (unsigned int) tag));
1127                         return NULL;
1128                 }
1129
1130
1131                 switch(smb_ace->a_type) {
1132                 case SMB_ACL_USER:
1133                         smb_ace->info.user.uid = id;
1134                         break;
1135                 case SMB_ACL_GROUP:
1136                         smb_ace->info.group.gid = id;
1137                         break;
1138                 default:
1139                         break;
1140                 }
1141
1142                 smb_ace->a_perm = 0;
1143                 smb_ace->a_perm |=
1144                         ((perm & GLUSTER_ACL_READ) ? SMB_ACL_READ : 0);
1145                 smb_ace->a_perm |=
1146                         ((perm & GLUSTER_ACL_WRITE) ? SMB_ACL_WRITE : 0);
1147                 smb_ace->a_perm |=
1148                         ((perm & GLUSTER_ACL_EXECUTE) ? SMB_ACL_EXECUTE : 0);
1149
1150                 smb_ace++;
1151         }
1152
1153         return result;
1154 }
1155
1156
1157 static int gluster_ace_cmp(const void *left, const void *right)
1158 {
1159         int ret = 0;
1160         uint16_t tag_left, tag_right;
1161         uint32_t id_left, id_right;
1162
1163         /*
1164           Sorting precedence:
1165
1166            - Smaller TAG values must be earlier.
1167
1168            - Within same TAG, smaller identifiers must be earlier, E.g:
1169              UID 0 entry must be earlier than UID 200
1170              GID 17 entry must be earlier than GID 19
1171         */
1172
1173         /* TAG is the first element in the entry */
1174         tag_left = SVAL(left, 0);
1175         tag_right = SVAL(right, 0);
1176
1177         ret = (tag_left - tag_right);
1178         if (!ret) {
1179                 /* ID is the third element in the entry, after two short
1180                    integers (tag and perm), i.e at offset 4.
1181                 */
1182                 id_left = IVAL(left, 4);
1183                 id_right = IVAL(right, 4);
1184                 ret = id_left - id_right;
1185         }
1186
1187         return ret;
1188 }
1189
1190
1191 static ssize_t smb_to_gluster_acl(SMB_ACL_T theacl, char *buf, size_t len)
1192 {
1193         ssize_t size;
1194         struct smb_acl_entry *smb_ace;
1195         int i;
1196         int count;
1197         uint16_t tag;
1198         uint16_t perm;
1199         uint32_t id;
1200         int offset;
1201
1202         count = theacl->count;
1203
1204         size = GLUSTER_ACL_HEADER_SIZE + (count * GLUSTER_ACL_ENTRY_SIZE);
1205         if (!buf) {
1206                 return size;
1207         }
1208
1209         if (len < size) {
1210                 errno = ERANGE;
1211                 return -1;
1212         }
1213
1214         smb_ace = theacl->acl;
1215
1216         /* Version is the first 4 bytes of the ACL */
1217         SIVAL(buf, 0, GLUSTER_ACL_VERSION);
1218         offset = GLUSTER_ACL_HEADER_SIZE;
1219
1220         for (i = 0; i < count; i++) {
1221                 /* Calculate tag */
1222                 switch(smb_ace->a_type) {
1223                 case SMB_ACL_USER:
1224                         tag = GLUSTER_ACL_USER;
1225                         break;
1226                 case SMB_ACL_USER_OBJ:
1227                         tag = GLUSTER_ACL_USER_OBJ;
1228                         break;
1229                 case SMB_ACL_GROUP:
1230                         tag = GLUSTER_ACL_GROUP;
1231                         break;
1232                 case SMB_ACL_GROUP_OBJ:
1233                         tag = GLUSTER_ACL_GROUP_OBJ;
1234                         break;
1235                 case SMB_ACL_OTHER:
1236                         tag = GLUSTER_ACL_OTHER;
1237                         break;
1238                 case SMB_ACL_MASK:
1239                         tag = GLUSTER_ACL_MASK;
1240                         break;
1241                 default:
1242                         DEBUG(0, ("Unknown tag value %d\n",
1243                                   smb_ace->a_type));
1244                         errno = EINVAL;
1245                         return -1;
1246                 }
1247
1248
1249                 /* Calculate id */
1250                 switch(smb_ace->a_type) {
1251                 case SMB_ACL_USER:
1252                         id = smb_ace->info.user.uid;
1253                         break;
1254                 case SMB_ACL_GROUP:
1255                         id = smb_ace->info.group.gid;
1256                         break;
1257                 default:
1258                         id = GLUSTER_ACL_UNDEFINED_ID;
1259                         break;
1260                 }
1261
1262                 /* Calculate perm */
1263                 perm = 0;
1264
1265                 perm |=
1266                         ((smb_ace->a_perm & SMB_ACL_READ) ? GLUSTER_ACL_READ : 0);
1267                 perm |=
1268                         ((smb_ace->a_perm & SMB_ACL_WRITE) ? GLUSTER_ACL_WRITE : 0);
1269                 perm |=
1270                         ((smb_ace->a_perm & SMB_ACL_EXECUTE) ? GLUSTER_ACL_EXECUTE : 0);
1271
1272
1273                 /* TAG is the first 2 bytes of an entry */
1274                 SSVAL(buf, offset, tag);
1275                 offset += 2;
1276
1277                 /* PERM is the next 2 bytes of an entry */
1278                 SSVAL(buf, offset, perm);
1279                 offset += 2;
1280
1281                 /* ID is the last 4 bytes of an entry */
1282                 SIVAL(buf, offset, id);
1283                 offset += 4;
1284
1285                 smb_ace++;
1286         }
1287
1288         /* Skip the header, sort @count number of 8-byte entries */
1289         qsort(buf+GLUSTER_ACL_HEADER_SIZE, count, GLUSTER_ACL_ENTRY_SIZE,
1290               gluster_ace_cmp);
1291
1292         return size;
1293 }
1294
1295
1296 static SMB_ACL_T vfs_gluster_sys_acl_get_file(struct vfs_handle_struct *handle,
1297                                               const char *path_p,
1298                                               SMB_ACL_TYPE_T type,
1299                                               TALLOC_CTX *mem_ctx)
1300 {
1301         struct smb_acl_t *result;
1302         char *buf;
1303         const char *key;
1304         ssize_t ret;
1305
1306         switch (type) {
1307         case SMB_ACL_TYPE_ACCESS:
1308                 key = "system.posix_acl_access";
1309                 break;
1310         case SMB_ACL_TYPE_DEFAULT:
1311                 key = "system.posix_acl_default";
1312                 break;
1313         default:
1314                 errno = EINVAL;
1315                 return NULL;
1316         }
1317
1318         ret = glfs_getxattr(handle->data, path_p, key, 0, 0);
1319         if (ret <= 0) {
1320                 return NULL;
1321         }
1322
1323         buf = alloca(ret);
1324         ret = glfs_getxattr(handle->data, path_p, key, buf, ret);
1325         if (ret <= 0) {
1326                 return NULL;
1327         }
1328
1329         result = gluster_to_smb_acl(buf, ret, mem_ctx);
1330
1331         return result;
1332 }
1333
1334 static SMB_ACL_T vfs_gluster_sys_acl_get_fd(struct vfs_handle_struct *handle,
1335                                             struct files_struct *fsp,
1336                                             TALLOC_CTX *mem_ctx)
1337 {
1338         struct smb_acl_t *result;
1339         int ret;
1340         char *buf;
1341
1342         ret = glfs_fgetxattr(glfd_fd_get(fsp->fh->fd),
1343                              "system.posix_acl_access", 0, 0);
1344         if (ret <= 0) {
1345                 return NULL;
1346         }
1347
1348         buf = alloca(ret);
1349         ret = glfs_fgetxattr(glfd_fd_get(fsp->fh->fd),
1350                              "system.posix_acl_access", buf, ret);
1351         if (ret <= 0) {
1352                 return NULL;
1353         }
1354
1355         result = gluster_to_smb_acl(buf, ret, mem_ctx);
1356
1357         return result;
1358 }
1359
1360 static int vfs_gluster_sys_acl_set_file(struct vfs_handle_struct *handle,
1361                                         const char *name,
1362                                         SMB_ACL_TYPE_T acltype,
1363                                         SMB_ACL_T theacl)
1364 {
1365         int ret;
1366         const char *key;
1367         char *buf;
1368         ssize_t size;
1369
1370         switch (acltype) {
1371         case SMB_ACL_TYPE_ACCESS:
1372                 key = "system.posix_acl_access";
1373                 break;
1374         case SMB_ACL_TYPE_DEFAULT:
1375                 key = "system.posix_acl_default";
1376                 break;
1377         default:
1378                 errno = EINVAL;
1379                 return -1;
1380         }
1381
1382         size = smb_to_gluster_acl(theacl, 0, 0);
1383         buf = alloca(size);
1384
1385         size = smb_to_gluster_acl(theacl, buf, size);
1386         if (size == -1) {
1387                 return -1;
1388         }
1389
1390         ret = glfs_setxattr(handle->data, name, key, buf, size, 0);
1391
1392         return ret;
1393 }
1394
1395 static int vfs_gluster_sys_acl_set_fd(struct vfs_handle_struct *handle,
1396                                       struct files_struct *fsp,
1397                                       SMB_ACL_T theacl)
1398 {
1399         int ret;
1400         char *key;
1401         char *buf;
1402         ssize_t size;
1403
1404         size = smb_to_gluster_acl(theacl, 0, 0);
1405         buf = alloca(size);
1406
1407         size = smb_to_gluster_acl(theacl, buf, size);
1408         if (size == -1) {
1409                 return -1;
1410         }
1411
1412         ret = glfs_fsetxattr(glfd_fd_get(fsp->fh->fd),
1413                              "system.posix_acl_access", buf, size, 0);
1414         return ret;
1415 }
1416
1417 static int vfs_gluster_sys_acl_delete_def_file(struct vfs_handle_struct *handle,
1418                                                const char *path)
1419 {
1420         return glfs_removexattr(handle->data, path, "system.posix_acl_default");
1421 }
1422
1423 static struct vfs_fn_pointers glusterfs_fns = {
1424
1425         /* Disk Operations */
1426
1427         .connect_fn = vfs_gluster_connect,
1428         .disconnect_fn = vfs_gluster_disconnect,
1429         .disk_free_fn = vfs_gluster_disk_free,
1430         .get_quota_fn = vfs_gluster_get_quota,
1431         .set_quota_fn = vfs_gluster_set_quota,
1432         .statvfs_fn = vfs_gluster_statvfs,
1433         .fs_capabilities_fn = vfs_gluster_fs_capabilities,
1434
1435         .get_dfs_referrals_fn = NULL,
1436
1437         /* Directory Operations */
1438
1439         .opendir_fn = vfs_gluster_opendir,
1440         .fdopendir_fn = vfs_gluster_fdopendir,
1441         .readdir_fn = vfs_gluster_readdir,
1442         .seekdir_fn = vfs_gluster_seekdir,
1443         .telldir_fn = vfs_gluster_telldir,
1444         .rewind_dir_fn = vfs_gluster_rewinddir,
1445         .mkdir_fn = vfs_gluster_mkdir,
1446         .rmdir_fn = vfs_gluster_rmdir,
1447         .closedir_fn = vfs_gluster_closedir,
1448         .init_search_op_fn = vfs_gluster_init_search_op,
1449
1450         /* File Operations */
1451
1452         .open_fn = vfs_gluster_open,
1453         .create_file_fn = NULL,
1454         .close_fn = vfs_gluster_close,
1455         .read_fn = vfs_gluster_read,
1456         .pread_fn = vfs_gluster_pread,
1457         .pread_send_fn = vfs_gluster_pread_send,
1458         .pread_recv_fn = vfs_gluster_pread_recv,
1459         .write_fn = vfs_gluster_write,
1460         .pwrite_fn = vfs_gluster_pwrite,
1461         .pwrite_send_fn = vfs_gluster_pwrite_send,
1462         .pwrite_recv_fn = vfs_gluster_pwrite_recv,
1463         .lseek_fn = vfs_gluster_lseek,
1464         .sendfile_fn = vfs_gluster_sendfile,
1465         .recvfile_fn = vfs_gluster_recvfile,
1466         .rename_fn = vfs_gluster_rename,
1467         .fsync_fn = vfs_gluster_fsync,
1468         .fsync_send_fn = vfs_gluster_fsync_send,
1469         .fsync_recv_fn = vfs_gluster_fsync_recv,
1470
1471         .stat_fn = vfs_gluster_stat,
1472         .fstat_fn = vfs_gluster_fstat,
1473         .lstat_fn = vfs_gluster_lstat,
1474         .get_alloc_size_fn = vfs_gluster_get_alloc_size,
1475         .unlink_fn = vfs_gluster_unlink,
1476
1477         .chmod_fn = vfs_gluster_chmod,
1478         .fchmod_fn = vfs_gluster_fchmod,
1479         .chown_fn = vfs_gluster_chown,
1480         .fchown_fn = vfs_gluster_fchown,
1481         .lchown_fn = vfs_gluster_lchown,
1482         .chdir_fn = vfs_gluster_chdir,
1483         .getwd_fn = vfs_gluster_getwd,
1484         .ntimes_fn = vfs_gluster_ntimes,
1485         .ftruncate_fn = vfs_gluster_ftruncate,
1486         .fallocate_fn = vfs_gluster_fallocate,
1487         .lock_fn = vfs_gluster_lock,
1488         .kernel_flock_fn = vfs_gluster_kernel_flock,
1489         .linux_setlease_fn = vfs_gluster_linux_setlease,
1490         .getlock_fn = vfs_gluster_getlock,
1491         .symlink_fn = vfs_gluster_symlink,
1492         .readlink_fn = vfs_gluster_readlink,
1493         .link_fn = vfs_gluster_link,
1494         .mknod_fn = vfs_gluster_mknod,
1495         .realpath_fn = vfs_gluster_realpath,
1496         .notify_watch_fn = vfs_gluster_notify_watch,
1497         .chflags_fn = vfs_gluster_chflags,
1498         .file_id_create_fn = NULL,
1499         .copy_chunk_send_fn = NULL,
1500         .copy_chunk_recv_fn = NULL,
1501         .streaminfo_fn = NULL,
1502         .get_real_filename_fn = vfs_gluster_get_real_filename,
1503         .connectpath_fn = vfs_gluster_connectpath,
1504
1505         .brl_lock_windows_fn = NULL,
1506         .brl_unlock_windows_fn = NULL,
1507         .brl_cancel_windows_fn = NULL,
1508         .strict_lock_fn = NULL,
1509         .strict_unlock_fn = NULL,
1510         .translate_name_fn = NULL,
1511         .fsctl_fn = NULL,
1512
1513         /* NT ACL Operations */
1514         .fget_nt_acl_fn = NULL,
1515         .get_nt_acl_fn = NULL,
1516         .fset_nt_acl_fn = NULL,
1517         .audit_file_fn = NULL,
1518
1519         /* Posix ACL Operations */
1520         .chmod_acl_fn = NULL,   /* passthrough to default */
1521         .fchmod_acl_fn = NULL,  /* passthrough to default */
1522         .sys_acl_get_file_fn = vfs_gluster_sys_acl_get_file,
1523         .sys_acl_get_fd_fn = vfs_gluster_sys_acl_get_fd,
1524         .sys_acl_blob_get_file_fn = posix_sys_acl_blob_get_file,
1525         .sys_acl_blob_get_fd_fn = posix_sys_acl_blob_get_fd,
1526         .sys_acl_set_file_fn = vfs_gluster_sys_acl_set_file,
1527         .sys_acl_set_fd_fn = vfs_gluster_sys_acl_set_fd,
1528         .sys_acl_delete_def_file_fn = vfs_gluster_sys_acl_delete_def_file,
1529
1530         /* EA Operations */
1531         .getxattr_fn = vfs_gluster_getxattr,
1532         .fgetxattr_fn = vfs_gluster_fgetxattr,
1533         .listxattr_fn = vfs_gluster_listxattr,
1534         .flistxattr_fn = vfs_gluster_flistxattr,
1535         .removexattr_fn = vfs_gluster_removexattr,
1536         .fremovexattr_fn = vfs_gluster_fremovexattr,
1537         .setxattr_fn = vfs_gluster_setxattr,
1538         .fsetxattr_fn = vfs_gluster_fsetxattr,
1539
1540         /* AIO Operations */
1541         .aio_force_fn = vfs_gluster_aio_force,
1542
1543         /* Offline Operations */
1544         .is_offline_fn = vfs_gluster_is_offline,
1545         .set_offline_fn = vfs_gluster_set_offline,
1546
1547         /* Durable handle Operations */
1548         .durable_cookie_fn = NULL,
1549         .durable_disconnect_fn = NULL,
1550         .durable_reconnect_fn = NULL,
1551 };
1552
1553 NTSTATUS vfs_glusterfs_init(void);
1554 NTSTATUS vfs_glusterfs_init(void)
1555 {
1556         return smb_register_vfs(SMB_VFS_INTERFACE_VERSION,
1557                                 "glusterfs", &glusterfs_fns);
1558 }