s3:vfs_gpfs remove a trailing space
[Samba/gebeck_regimport.git] / source3 / modules / vfs_gpfs.c
blob2d8ac5cd66c020f50ff92f7bfa7f12bcaf798872
1 /*
2 Unix SMB/CIFS implementation.
3 Wrap gpfs calls in vfs functions.
5 Copyright (C) Christian Ambach <cambach1@de.ibm.com> 2006
7 Major code contributions by Chetan Shringarpure <chetan.sh@in.ibm.com>
8 and Gomati Mohanan <gomati.mohanan@in.ibm.com>
10 This program is free software; you can redistribute it and/or modify
11 it under the terms of the GNU General Public License as published by
12 the Free Software Foundation; either version 3 of the License, or
13 (at your option) any later version.
15 This program is distributed in the hope that it will be useful,
16 but WITHOUT ANY WARRANTY; without even the implied warranty of
17 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 GNU General Public License for more details.
20 You should have received a copy of the GNU General Public License
21 along with this program. If not, see <http://www.gnu.org/licenses/>.
24 #include "includes.h"
25 #include "smbd/smbd.h"
26 #include "librpc/gen_ndr/ndr_xattr.h"
27 #include "include/smbprofile.h"
29 #undef DBGC_CLASS
30 #define DBGC_CLASS DBGC_VFS
32 #include <gpfs_gpl.h>
33 #include "nfs4_acls.h"
34 #include "vfs_gpfs.h"
35 #include "system/filesys.h"
36 #include "auth.h"
37 #include "lib/util/tevent_unix.h"
39 struct gpfs_config_data {
40 bool sharemodes;
41 bool leases;
42 bool hsm;
43 bool syncio;
44 bool winattr;
45 bool ftruncate;
46 bool getrealfilename;
47 bool dfreequota;
48 bool prealloc;
49 bool acl;
53 static int vfs_gpfs_kernel_flock(vfs_handle_struct *handle, files_struct *fsp,
54 uint32 share_mode, uint32 access_mask)
57 struct gpfs_config_data *config;
58 int ret = 0;
60 SMB_VFS_HANDLE_GET_DATA(handle, config,
61 struct gpfs_config_data,
62 return -1);
64 if(!config->sharemodes) {
65 return 0;
68 START_PROFILE(syscall_kernel_flock);
70 kernel_flock(fsp->fh->fd, share_mode, access_mask);
72 if (!set_gpfs_sharemode(fsp, access_mask, fsp->share_access)) {
73 ret = -1;
76 END_PROFILE(syscall_kernel_flock);
78 return ret;
81 static int vfs_gpfs_close(vfs_handle_struct *handle, files_struct *fsp)
84 struct gpfs_config_data *config;
86 SMB_VFS_HANDLE_GET_DATA(handle, config,
87 struct gpfs_config_data,
88 return -1);
90 if (config->sharemodes && (fsp->fh != NULL) && (fsp->fh->fd != -1)) {
91 set_gpfs_sharemode(fsp, 0, 0);
94 return SMB_VFS_NEXT_CLOSE(handle, fsp);
97 static int vfs_gpfs_setlease(vfs_handle_struct *handle, files_struct *fsp,
98 int leasetype)
100 struct gpfs_config_data *config;
101 int ret=0;
103 SMB_VFS_HANDLE_GET_DATA(handle, config,
104 struct gpfs_config_data,
105 return -1);
107 if (linux_set_lease_sighandler(fsp->fh->fd) == -1)
108 return -1;
110 START_PROFILE(syscall_linux_setlease);
112 if (config->leases) {
113 ret = set_gpfs_lease(fsp->fh->fd,leasetype);
116 END_PROFILE(syscall_linux_setlease);
118 return ret;
121 static int vfs_gpfs_get_real_filename(struct vfs_handle_struct *handle,
122 const char *path,
123 const char *name,
124 TALLOC_CTX *mem_ctx,
125 char **found_name)
127 int result;
128 char *full_path;
129 char real_pathname[PATH_MAX+1];
130 int buflen;
131 bool mangled;
132 struct gpfs_config_data *config;
134 SMB_VFS_HANDLE_GET_DATA(handle, config,
135 struct gpfs_config_data,
136 return -1);
138 if (!config->getrealfilename) {
139 return SMB_VFS_NEXT_GET_REAL_FILENAME(handle, path, name,
140 mem_ctx, found_name);
143 mangled = mangle_is_mangled(name, handle->conn->params);
144 if (mangled) {
145 return SMB_VFS_NEXT_GET_REAL_FILENAME(handle, path, name,
146 mem_ctx, found_name);
149 full_path = talloc_asprintf(talloc_tos(), "%s/%s", path, name);
150 if (full_path == NULL) {
151 errno = ENOMEM;
152 return -1;
155 buflen = sizeof(real_pathname) - 1;
157 result = smbd_gpfs_get_realfilename_path(full_path, real_pathname,
158 &buflen);
160 TALLOC_FREE(full_path);
162 if ((result == -1) && (errno == ENOSYS)) {
163 return SMB_VFS_NEXT_GET_REAL_FILENAME(
164 handle, path, name, mem_ctx, found_name);
167 if (result == -1) {
168 DEBUG(10, ("smbd_gpfs_get_realfilename_path returned %s\n",
169 strerror(errno)));
170 return -1;
174 * GPFS does not necessarily null-terminate the returned path
175 * but instead returns the buffer length in buflen.
178 if (buflen < sizeof(real_pathname)) {
179 real_pathname[buflen] = '\0';
180 } else {
181 real_pathname[sizeof(real_pathname)-1] = '\0';
184 DEBUG(10, ("smbd_gpfs_get_realfilename_path: %s/%s -> %s\n",
185 path, name, real_pathname));
187 name = strrchr_m(real_pathname, '/');
188 if (name == NULL) {
189 errno = ENOENT;
190 return -1;
193 *found_name = talloc_strdup(mem_ctx, name+1);
194 if (*found_name == NULL) {
195 errno = ENOMEM;
196 return -1;
199 return 0;
202 static void gpfs_dumpacl(int level, struct gpfs_acl *gacl)
204 gpfs_aclCount_t i;
205 if (gacl==NULL)
207 DEBUG(0, ("gpfs acl is NULL\n"));
208 return;
211 DEBUG(level, ("gpfs acl: nace: %d, type:%d, version:%d, level:%d, len:%d\n",
212 gacl->acl_nace, gacl->acl_type, gacl->acl_version, gacl->acl_level, gacl->acl_len));
213 for(i=0; i<gacl->acl_nace; i++)
215 struct gpfs_ace_v4 *gace = gacl->ace_v4 + i;
216 DEBUG(level, ("\tace[%d]: type:%d, flags:0x%x, mask:0x%x, iflags:0x%x, who:%u\n",
217 i, gace->aceType, gace->aceFlags, gace->aceMask,
218 gace->aceIFlags, gace->aceWho));
222 static struct gpfs_acl *gpfs_getacl_alloc(const char *fname, gpfs_aclType_t type)
224 struct gpfs_acl *acl;
225 size_t len = 200;
226 int ret;
227 TALLOC_CTX *mem_ctx = talloc_tos();
229 acl = (struct gpfs_acl *)TALLOC_SIZE(mem_ctx, len);
230 if (acl == NULL) {
231 errno = ENOMEM;
232 return NULL;
235 acl->acl_len = len;
236 acl->acl_level = 0;
237 acl->acl_version = 0;
238 acl->acl_type = type;
240 ret = smbd_gpfs_getacl((char *)fname, GPFS_GETACL_STRUCT, acl);
241 if ((ret != 0) && (errno == ENOSPC)) {
242 struct gpfs_acl *new_acl = (struct gpfs_acl *)TALLOC_SIZE(
243 mem_ctx, acl->acl_len + sizeof(struct gpfs_acl));
244 if (new_acl == NULL) {
245 errno = ENOMEM;
246 return NULL;
249 new_acl->acl_len = acl->acl_len;
250 new_acl->acl_level = acl->acl_level;
251 new_acl->acl_version = acl->acl_version;
252 new_acl->acl_type = acl->acl_type;
253 acl = new_acl;
255 ret = smbd_gpfs_getacl((char *)fname, GPFS_GETACL_STRUCT, acl);
257 if (ret != 0)
259 DEBUG(8, ("smbd_gpfs_getacl failed with %s\n",strerror(errno)));
260 return NULL;
263 return acl;
266 /* Tries to get nfs4 acls and returns SMB ACL allocated.
267 * On failure returns 1 if it got non-NFSv4 ACL to prompt
268 * retry with POSIX ACL checks.
269 * On failure returns -1 if there is system (GPFS) error, check errno.
270 * Returns 0 on success
272 static int gpfs_get_nfs4_acl(const char *fname, SMB4ACL_T **ppacl)
274 gpfs_aclCount_t i;
275 struct gpfs_acl *gacl = NULL;
276 DEBUG(10, ("gpfs_get_nfs4_acl invoked for %s\n", fname));
278 /* First get the real acl length */
279 gacl = gpfs_getacl_alloc(fname, 0);
280 if (gacl == NULL) {
281 DEBUG(9, ("gpfs_getacl failed for %s with %s\n",
282 fname, strerror(errno)));
283 return -1;
286 if (gacl->acl_type != GPFS_ACL_TYPE_NFS4) {
287 DEBUG(10, ("Got non-nfsv4 acl\n"));
288 /* Retry with POSIX ACLs check */
289 return 1;
292 *ppacl = smb_create_smb4acl();
294 DEBUG(10, ("len: %d, level: %d, version: %d, nace: %d\n",
295 gacl->acl_len, gacl->acl_level, gacl->acl_version,
296 gacl->acl_nace));
298 for (i=0; i<gacl->acl_nace; i++) {
299 struct gpfs_ace_v4 *gace = &gacl->ace_v4[i];
300 SMB_ACE4PROP_T smbace;
301 DEBUG(10, ("type: %d, iflags: %x, flags: %x, mask: %x, "
302 "who: %d\n", gace->aceType, gace->aceIFlags,
303 gace->aceFlags, gace->aceMask, gace->aceWho));
305 ZERO_STRUCT(smbace);
306 if (gace->aceIFlags & ACE4_IFLAG_SPECIAL_ID) {
307 smbace.flags |= SMB_ACE4_ID_SPECIAL;
308 switch (gace->aceWho) {
309 case ACE4_SPECIAL_OWNER:
310 smbace.who.special_id = SMB_ACE4_WHO_OWNER;
311 break;
312 case ACE4_SPECIAL_GROUP:
313 smbace.who.special_id = SMB_ACE4_WHO_GROUP;
314 break;
315 case ACE4_SPECIAL_EVERYONE:
316 smbace.who.special_id = SMB_ACE4_WHO_EVERYONE;
317 break;
318 default:
319 DEBUG(8, ("invalid special gpfs id %d "
320 "ignored\n", gace->aceWho));
321 continue; /* don't add it */
323 } else {
324 if (gace->aceFlags & ACE4_FLAG_GROUP_ID)
325 smbace.who.gid = gace->aceWho;
326 else
327 smbace.who.uid = gace->aceWho;
330 /* remove redundent deny entries */
331 if (i > 0 && gace->aceType == SMB_ACE4_ACCESS_DENIED_ACE_TYPE) {
332 struct gpfs_ace_v4 *prev = &gacl->ace_v4[i-1];
333 if (prev->aceType == SMB_ACE4_ACCESS_ALLOWED_ACE_TYPE &&
334 prev->aceFlags == gace->aceFlags &&
335 prev->aceIFlags == gace->aceIFlags &&
336 (gace->aceMask & prev->aceMask) == 0 &&
337 gace->aceWho == prev->aceWho) {
338 /* its redundent - skip it */
339 continue;
343 smbace.aceType = gace->aceType;
344 smbace.aceFlags = gace->aceFlags;
345 smbace.aceMask = gace->aceMask;
346 smb_add_ace4(*ppacl, &smbace);
349 return 0;
352 static NTSTATUS gpfsacl_fget_nt_acl(vfs_handle_struct *handle,
353 files_struct *fsp, uint32 security_info,
354 TALLOC_CTX *mem_ctx,
355 struct security_descriptor **ppdesc)
357 SMB4ACL_T *pacl = NULL;
358 int result;
359 struct gpfs_config_data *config;
361 *ppdesc = NULL;
363 SMB_VFS_HANDLE_GET_DATA(handle, config,
364 struct gpfs_config_data,
365 return NT_STATUS_INTERNAL_ERROR);
367 if (!config->acl) {
368 return SMB_VFS_NEXT_FGET_NT_ACL(handle, fsp, security_info, ppdesc);
371 result = gpfs_get_nfs4_acl(fsp->fsp_name->base_name, &pacl);
373 if (result == 0)
374 return smb_fget_nt_acl_nfs4(fsp, security_info, mem_ctx, ppdesc, pacl);
376 if (result > 0) {
377 DEBUG(10, ("retrying with posix acl...\n"));
378 return posix_fget_nt_acl(fsp, security_info, mem_ctx, ppdesc);
381 /* GPFS ACL was not read, something wrong happened, error code is set in errno */
382 return map_nt_error_from_unix(errno);
385 static NTSTATUS gpfsacl_get_nt_acl(vfs_handle_struct *handle,
386 const char *name,
387 uint32 security_info,
388 TALLOC_CTX *mem_ctx, struct security_descriptor **ppdesc)
390 SMB4ACL_T *pacl = NULL;
391 int result;
392 struct gpfs_config_data *config;
394 *ppdesc = NULL;
396 SMB_VFS_HANDLE_GET_DATA(handle, config,
397 struct gpfs_config_data,
398 return NT_STATUS_INTERNAL_ERROR);
400 if (!config->acl) {
401 return SMB_VFS_NEXT_GET_NT_ACL(handle, name, security_info, ppdesc);
404 result = gpfs_get_nfs4_acl(name, &pacl);
406 if (result == 0)
407 return smb_get_nt_acl_nfs4(handle->conn, name, security_info,
408 mem_ctx, ppdesc, pacl);
410 if (result > 0) {
411 DEBUG(10, ("retrying with posix acl...\n"));
412 return posix_get_nt_acl(handle->conn, name, security_info,
413 mem_ctx, ppdesc);
416 /* GPFS ACL was not read, something wrong happened, error code is set in errno */
417 return map_nt_error_from_unix(errno);
420 static bool gpfsacl_process_smbacl(files_struct *fsp, SMB4ACL_T *smbacl)
422 int ret;
423 gpfs_aclLen_t gacl_len;
424 SMB4ACE_T *smbace;
425 struct gpfs_acl *gacl;
426 TALLOC_CTX *mem_ctx = talloc_tos();
428 gacl_len = offsetof(gpfs_acl_t, ace_v4) + smb_get_naces(smbacl) *
429 sizeof(gpfs_ace_v4_t);
431 gacl = (struct gpfs_acl *)TALLOC_SIZE(mem_ctx, gacl_len);
432 if (gacl == NULL) {
433 DEBUG(0, ("talloc failed\n"));
434 errno = ENOMEM;
435 return False;
438 gacl->acl_len = gacl_len;
439 gacl->acl_level = 0;
440 gacl->acl_version = GPFS_ACL_VERSION_NFS4;
441 gacl->acl_type = GPFS_ACL_TYPE_NFS4;
442 gacl->acl_nace = 0; /* change later... */
444 for (smbace=smb_first_ace4(smbacl); smbace!=NULL; smbace = smb_next_ace4(smbace)) {
445 struct gpfs_ace_v4 *gace = &gacl->ace_v4[gacl->acl_nace];
446 SMB_ACE4PROP_T *aceprop = smb_get_ace4(smbace);
448 gace->aceType = aceprop->aceType;
449 gace->aceFlags = aceprop->aceFlags;
450 gace->aceMask = aceprop->aceMask;
453 * GPFS can't distinguish between WRITE and APPEND on
454 * files, so one being set without the other is an
455 * error. Sorry for the many ()'s :-)
458 if (!fsp->is_directory
460 ((((gace->aceMask & ACE4_MASK_WRITE) == 0)
461 && ((gace->aceMask & ACE4_MASK_APPEND) != 0))
463 (((gace->aceMask & ACE4_MASK_WRITE) != 0)
464 && ((gace->aceMask & ACE4_MASK_APPEND) == 0)))
466 lp_parm_bool(fsp->conn->params->service, "gpfs",
467 "merge_writeappend", True)) {
468 DEBUG(2, ("vfs_gpfs.c: file [%s]: ACE contains "
469 "WRITE^APPEND, setting WRITE|APPEND\n",
470 fsp_str_dbg(fsp)));
471 gace->aceMask |= ACE4_MASK_WRITE|ACE4_MASK_APPEND;
474 gace->aceIFlags = (aceprop->flags&SMB_ACE4_ID_SPECIAL) ? ACE4_IFLAG_SPECIAL_ID : 0;
476 if (aceprop->flags&SMB_ACE4_ID_SPECIAL)
478 switch(aceprop->who.special_id)
480 case SMB_ACE4_WHO_EVERYONE:
481 gace->aceWho = ACE4_SPECIAL_EVERYONE;
482 break;
483 case SMB_ACE4_WHO_OWNER:
484 gace->aceWho = ACE4_SPECIAL_OWNER;
485 break;
486 case SMB_ACE4_WHO_GROUP:
487 gace->aceWho = ACE4_SPECIAL_GROUP;
488 break;
489 default:
490 DEBUG(8, ("unsupported special_id %d\n", aceprop->who.special_id));
491 continue; /* don't add it !!! */
493 } else {
494 /* just only for the type safety... */
495 if (aceprop->aceFlags&SMB_ACE4_IDENTIFIER_GROUP)
496 gace->aceWho = aceprop->who.gid;
497 else
498 gace->aceWho = aceprop->who.uid;
501 gacl->acl_nace++;
504 ret = smbd_gpfs_putacl(fsp->fsp_name->base_name,
505 GPFS_PUTACL_STRUCT | GPFS_ACL_SAMBA, gacl);
506 if (ret != 0) {
507 DEBUG(8, ("gpfs_putacl failed with %s\n", strerror(errno)));
508 gpfs_dumpacl(8, gacl);
509 return False;
512 DEBUG(10, ("gpfs_putacl succeeded\n"));
513 return True;
516 static NTSTATUS gpfsacl_set_nt_acl_internal(files_struct *fsp, uint32 security_info_sent, const struct security_descriptor *psd)
518 struct gpfs_acl *acl;
519 NTSTATUS result = NT_STATUS_ACCESS_DENIED;
521 acl = gpfs_getacl_alloc(fsp->fsp_name->base_name, 0);
522 if (acl == NULL)
523 return result;
525 if (acl->acl_version&GPFS_ACL_VERSION_NFS4)
527 if (lp_parm_bool(fsp->conn->params->service, "gpfs",
528 "refuse_dacl_protected", false)
529 && (psd->type&SEC_DESC_DACL_PROTECTED)) {
530 DEBUG(2, ("Rejecting unsupported ACL with DACL_PROTECTED bit set\n"));
531 return NT_STATUS_NOT_SUPPORTED;
534 result = smb_set_nt_acl_nfs4(
535 fsp, security_info_sent, psd,
536 gpfsacl_process_smbacl);
537 } else { /* assume POSIX ACL - by default... */
538 result = set_nt_acl(fsp, security_info_sent, psd);
541 return result;
544 static NTSTATUS gpfsacl_fset_nt_acl(vfs_handle_struct *handle, files_struct *fsp, uint32 security_info_sent, const struct security_descriptor *psd)
546 struct gpfs_config_data *config;
548 SMB_VFS_HANDLE_GET_DATA(handle, config,
549 struct gpfs_config_data,
550 return NT_STATUS_INTERNAL_ERROR);
552 if (!config->acl) {
553 return SMB_VFS_NEXT_FSET_NT_ACL(handle, fsp, security_info_sent, psd);
556 return gpfsacl_set_nt_acl_internal(fsp, security_info_sent, psd);
559 static SMB_ACL_T gpfs2smb_acl(const struct gpfs_acl *pacl, TALLOC_CTX *mem_ctx)
561 SMB_ACL_T result;
562 gpfs_aclCount_t i;
564 result = sys_acl_init(mem_ctx);
565 if (result == NULL) {
566 errno = ENOMEM;
567 return NULL;
570 result->count = pacl->acl_nace;
572 for (i=0; i<pacl->acl_nace; i++) {
573 struct smb_acl_entry *ace = &result->acl[i];
574 const struct gpfs_ace_v1 *g_ace = &pacl->ace_v1[i];
576 DEBUG(10, ("Converting type %d id %lu perm %x\n",
577 (int)g_ace->ace_type, (unsigned long)g_ace->ace_who,
578 (int)g_ace->ace_perm));
580 switch (g_ace->ace_type) {
581 case GPFS_ACL_USER:
582 ace->a_type = SMB_ACL_USER;
583 ace->info.user.uid = (uid_t)g_ace->ace_who;
584 break;
585 case GPFS_ACL_USER_OBJ:
586 ace->a_type = SMB_ACL_USER_OBJ;
587 break;
588 case GPFS_ACL_GROUP:
589 ace->a_type = SMB_ACL_GROUP;
590 ace->info.group.gid = (gid_t)g_ace->ace_who;
591 break;
592 case GPFS_ACL_GROUP_OBJ:
593 ace->a_type = SMB_ACL_GROUP_OBJ;
594 break;
595 case GPFS_ACL_OTHER:
596 ace->a_type = SMB_ACL_OTHER;
597 break;
598 case GPFS_ACL_MASK:
599 ace->a_type = SMB_ACL_MASK;
600 break;
601 default:
602 DEBUG(10, ("Got invalid ace_type: %d\n",
603 g_ace->ace_type));
604 errno = EINVAL;
605 TALLOC_FREE(result);
606 return NULL;
609 ace->a_perm = 0;
610 ace->a_perm |= (g_ace->ace_perm & ACL_PERM_READ) ?
611 SMB_ACL_READ : 0;
612 ace->a_perm |= (g_ace->ace_perm & ACL_PERM_WRITE) ?
613 SMB_ACL_WRITE : 0;
614 ace->a_perm |= (g_ace->ace_perm & ACL_PERM_EXECUTE) ?
615 SMB_ACL_EXECUTE : 0;
617 DEBUGADD(10, ("Converted to %d perm %x\n",
618 ace->a_type, ace->a_perm));
621 return result;
624 static SMB_ACL_T gpfsacl_get_posix_acl(const char *path, gpfs_aclType_t type,
625 TALLOC_CTX *mem_ctx)
627 struct gpfs_acl *pacl;
628 SMB_ACL_T result = NULL;
630 pacl = gpfs_getacl_alloc(path, type);
632 if (pacl == NULL) {
633 DEBUG(10, ("gpfs_getacl failed for %s with %s\n",
634 path, strerror(errno)));
635 if (errno == 0) {
636 errno = EINVAL;
638 goto done;
641 if (pacl->acl_version != GPFS_ACL_VERSION_POSIX) {
642 DEBUG(10, ("Got acl version %d, expected %d\n",
643 pacl->acl_version, GPFS_ACL_VERSION_POSIX));
644 errno = EINVAL;
645 goto done;
648 DEBUG(10, ("len: %d, level: %d, version: %d, nace: %d\n",
649 pacl->acl_len, pacl->acl_level, pacl->acl_version,
650 pacl->acl_nace));
652 result = gpfs2smb_acl(pacl, mem_ctx);
653 if (result != NULL) {
654 errno = 0;
657 done:
659 if (errno != 0) {
660 TALLOC_FREE(result);
662 return result;
665 static SMB_ACL_T gpfsacl_sys_acl_get_file(vfs_handle_struct *handle,
666 const char *path_p,
667 SMB_ACL_TYPE_T type,
668 TALLOC_CTX *mem_ctx)
670 gpfs_aclType_t gpfs_type;
671 struct gpfs_config_data *config;
673 SMB_VFS_HANDLE_GET_DATA(handle, config,
674 struct gpfs_config_data,
675 return NULL);
677 if (!config->acl) {
678 return SMB_VFS_NEXT_SYS_ACL_GET_FILE(handle, path_p,
679 type, mem_ctx);
682 switch(type) {
683 case SMB_ACL_TYPE_ACCESS:
684 gpfs_type = GPFS_ACL_TYPE_ACCESS;
685 break;
686 case SMB_ACL_TYPE_DEFAULT:
687 gpfs_type = GPFS_ACL_TYPE_DEFAULT;
688 break;
689 default:
690 DEBUG(0, ("Got invalid type: %d\n", type));
691 smb_panic("exiting");
694 return gpfsacl_get_posix_acl(path_p, gpfs_type, mem_ctx);
697 static SMB_ACL_T gpfsacl_sys_acl_get_fd(vfs_handle_struct *handle,
698 files_struct *fsp,
699 TALLOC_CTX *mem_ctx)
701 struct gpfs_config_data *config;
703 SMB_VFS_HANDLE_GET_DATA(handle, config,
704 struct gpfs_config_data,
705 return NULL);
707 if (!config->acl) {
708 return SMB_VFS_NEXT_SYS_ACL_GET_FD(handle, fsp, mem_ctx);
711 return gpfsacl_get_posix_acl(fsp->fsp_name->base_name,
712 GPFS_ACL_TYPE_ACCESS, mem_ctx);
715 static int gpfsacl_sys_acl_blob_get_file(vfs_handle_struct *handle, const char *path_p,
716 TALLOC_CTX *mem_ctx,
717 char **blob_description,
718 DATA_BLOB *blob)
720 struct gpfs_config_data *config;
722 SMB_VFS_HANDLE_GET_DATA(handle, config,
723 struct gpfs_config_data,
724 return NULL);
726 if (!config->acl) {
727 return SMB_VFS_NEXT_SYS_ACL_BLOB_GET_FILE(handle, path_p, mem_ctx, blob_description, blob);
730 result = gpfs_get_nfs4_acl(name, &pacl);
731 if (result == 0) {
732 /* We don't have a way to linearlise the NFS4 ACL
733 * right now, and it is much closer to the NT ACL
734 * anyway */
735 errno = EINVAL;
736 return -1;
739 return posix_sys_acl_blob_get_file(handle, path_p, mem_ctx,
740 blob_description, blob);
743 static int gpfsacl_sys_acl_blob_get_fd(vfs_handle_struct *handle, files_struct *fsp,
744 TALLOC_CTX *mem_ctx,
745 char **blob_description,
746 DATA_BLOB *blob)
748 struct gpfs_config_data *config;
750 SMB_VFS_HANDLE_GET_DATA(handle, config,
751 struct gpfs_config_data,
752 return NULL);
754 if (!config->acl) {
755 return SMB_VFS_NEXT_SYS_ACL_BLOB_GET_FD(handle, fsp, mem_ctx, blob_description, blob);
758 result = gpfs_get_nfs4_acl(fsp->fsp_name->base_name, &pacl);
759 if (result == 0) {
760 /* We don't have a way to linearlise the NFS4 ACL
761 * right now, and it is much closer to the NT ACL
762 * anyway */
763 errno = EINVAL;
764 return -1;
767 return posix_sys_acl_blob_get_fd(handle, fsp, mem_ctx,
768 blob_description, blob);
771 static struct gpfs_acl *smb2gpfs_acl(const SMB_ACL_T pacl,
772 SMB_ACL_TYPE_T type)
774 gpfs_aclLen_t len;
775 struct gpfs_acl *result;
776 int i;
778 DEBUG(10, ("smb2gpfs_acl: Got ACL with %d entries\n", pacl->count));
780 len = offsetof(gpfs_acl_t, ace_v1) + (pacl->count) *
781 sizeof(gpfs_ace_v1_t);
783 result = (struct gpfs_acl *)SMB_MALLOC(len);
784 if (result == NULL) {
785 errno = ENOMEM;
786 return result;
789 result->acl_len = len;
790 result->acl_level = 0;
791 result->acl_version = GPFS_ACL_VERSION_POSIX;
792 result->acl_type = (type == SMB_ACL_TYPE_DEFAULT) ?
793 GPFS_ACL_TYPE_DEFAULT : GPFS_ACL_TYPE_ACCESS;
794 result->acl_nace = pacl->count;
796 for (i=0; i<pacl->count; i++) {
797 const struct smb_acl_entry *ace = &pacl->acl[i];
798 struct gpfs_ace_v1 *g_ace = &result->ace_v1[i];
800 DEBUG(10, ("Converting type %d perm %x\n",
801 (int)ace->a_type, (int)ace->a_perm));
803 g_ace->ace_perm = 0;
805 switch(ace->a_type) {
806 case SMB_ACL_USER:
807 g_ace->ace_type = GPFS_ACL_USER;
808 g_ace->ace_who = (gpfs_uid_t)ace->info.user.uid;
809 break;
810 case SMB_ACL_USER_OBJ:
811 g_ace->ace_type = GPFS_ACL_USER_OBJ;
812 g_ace->ace_perm |= ACL_PERM_CONTROL;
813 g_ace->ace_who = 0;
814 break;
815 case SMB_ACL_GROUP:
816 g_ace->ace_type = GPFS_ACL_GROUP;
817 g_ace->ace_who = (gpfs_uid_t)ace->info.group.gid;
818 break;
819 case SMB_ACL_GROUP_OBJ:
820 g_ace->ace_type = GPFS_ACL_GROUP_OBJ;
821 g_ace->ace_who = 0;
822 break;
823 case SMB_ACL_MASK:
824 g_ace->ace_type = GPFS_ACL_MASK;
825 g_ace->ace_perm = 0x8f;
826 g_ace->ace_who = 0;
827 break;
828 case SMB_ACL_OTHER:
829 g_ace->ace_type = GPFS_ACL_OTHER;
830 g_ace->ace_who = 0;
831 break;
832 default:
833 DEBUG(10, ("Got invalid ace_type: %d\n", ace->a_type));
834 errno = EINVAL;
835 SAFE_FREE(result);
836 return NULL;
839 g_ace->ace_perm |= (ace->a_perm & SMB_ACL_READ) ?
840 ACL_PERM_READ : 0;
841 g_ace->ace_perm |= (ace->a_perm & SMB_ACL_WRITE) ?
842 ACL_PERM_WRITE : 0;
843 g_ace->ace_perm |= (ace->a_perm & SMB_ACL_EXECUTE) ?
844 ACL_PERM_EXECUTE : 0;
846 DEBUGADD(10, ("Converted to %d id %d perm %x\n",
847 g_ace->ace_type, g_ace->ace_who, g_ace->ace_perm));
850 return result;
853 static int gpfsacl_sys_acl_set_file(vfs_handle_struct *handle,
854 const char *name,
855 SMB_ACL_TYPE_T type,
856 SMB_ACL_T theacl)
858 struct gpfs_acl *gpfs_acl;
859 int result;
860 struct gpfs_config_data *config;
862 SMB_VFS_HANDLE_GET_DATA(handle, config,
863 struct gpfs_config_data,
864 return -1);
866 if (!config->acl) {
867 return SMB_VFS_NEXT_SYS_ACL_SET_FILE(handle, name, type, theacl);
870 gpfs_acl = smb2gpfs_acl(theacl, type);
871 if (gpfs_acl == NULL) {
872 return -1;
875 result = smbd_gpfs_putacl((char *)name, GPFS_PUTACL_STRUCT | GPFS_ACL_SAMBA, gpfs_acl);
877 SAFE_FREE(gpfs_acl);
878 return result;
881 static int gpfsacl_sys_acl_set_fd(vfs_handle_struct *handle,
882 files_struct *fsp,
883 SMB_ACL_T theacl)
885 struct gpfs_config_data *config;
887 SMB_VFS_HANDLE_GET_DATA(handle, config,
888 struct gpfs_config_data,
889 return -1);
891 if (!config->acl) {
892 return SMB_VFS_NEXT_SYS_ACL_SET_FD(handle, fsp, theacl);
895 return gpfsacl_sys_acl_set_file(handle, fsp->fsp_name->base_name,
896 SMB_ACL_TYPE_ACCESS, theacl);
899 static int gpfsacl_sys_acl_delete_def_file(vfs_handle_struct *handle,
900 const char *path)
902 struct gpfs_config_data *config;
904 SMB_VFS_HANDLE_GET_DATA(handle, config,
905 struct gpfs_config_data,
906 return -1);
908 if (!config->acl) {
909 return SMB_VFS_NEXT_SYS_ACL_DELETE_DEF_FILE(handle, path);
912 errno = ENOTSUP;
913 return -1;
917 * Assumed: mode bits are shiftable and standard
918 * Output: the new aceMask field for an smb nfs4 ace
920 static uint32 gpfsacl_mask_filter(uint32 aceType, uint32 aceMask, uint32 rwx)
922 const uint32 posix_nfs4map[3] = {
923 SMB_ACE4_EXECUTE, /* execute */
924 SMB_ACE4_WRITE_DATA | SMB_ACE4_APPEND_DATA, /* write; GPFS specific */
925 SMB_ACE4_READ_DATA /* read */
927 int i;
928 uint32_t posix_mask = 0x01;
929 uint32_t posix_bit;
930 uint32_t nfs4_bits;
932 for(i=0; i<3; i++) {
933 nfs4_bits = posix_nfs4map[i];
934 posix_bit = rwx & posix_mask;
936 if (aceType==SMB_ACE4_ACCESS_ALLOWED_ACE_TYPE) {
937 if (posix_bit)
938 aceMask |= nfs4_bits;
939 else
940 aceMask &= ~nfs4_bits;
941 } else {
942 /* add deny bits when suitable */
943 if (!posix_bit)
944 aceMask |= nfs4_bits;
945 else
946 aceMask &= ~nfs4_bits;
947 } /* other ace types are unexpected */
949 posix_mask <<= 1;
952 return aceMask;
955 static int gpfsacl_emu_chmod(const char *path, mode_t mode)
957 SMB4ACL_T *pacl = NULL;
958 int result;
959 bool haveAllowEntry[SMB_ACE4_WHO_EVERYONE + 1] = {False, False, False, False};
960 int i;
961 files_struct fake_fsp; /* TODO: rationalize parametrization */
962 SMB4ACE_T *smbace;
963 NTSTATUS status;
965 DEBUG(10, ("gpfsacl_emu_chmod invoked for %s mode %o\n", path, mode));
967 result = gpfs_get_nfs4_acl(path, &pacl);
968 if (result)
969 return result;
971 if (mode & ~(S_IRWXU | S_IRWXG | S_IRWXO)) {
972 DEBUG(2, ("WARNING: cutting extra mode bits %o on %s\n", mode, path));
975 for (smbace=smb_first_ace4(pacl); smbace!=NULL; smbace = smb_next_ace4(smbace)) {
976 SMB_ACE4PROP_T *ace = smb_get_ace4(smbace);
977 uint32_t specid = ace->who.special_id;
979 if (ace->flags&SMB_ACE4_ID_SPECIAL &&
980 ace->aceType<=SMB_ACE4_ACCESS_DENIED_ACE_TYPE &&
981 specid <= SMB_ACE4_WHO_EVERYONE) {
983 uint32_t newMask;
985 if (ace->aceType==SMB_ACE4_ACCESS_ALLOWED_ACE_TYPE)
986 haveAllowEntry[specid] = True;
988 /* mode >> 6 for @owner, mode >> 3 for @group,
989 * mode >> 0 for @everyone */
990 newMask = gpfsacl_mask_filter(ace->aceType, ace->aceMask,
991 mode >> ((SMB_ACE4_WHO_EVERYONE - specid) * 3));
992 if (ace->aceMask!=newMask) {
993 DEBUG(10, ("ace changed for %s (%o -> %o) id=%d\n",
994 path, ace->aceMask, newMask, specid));
996 ace->aceMask = newMask;
1000 /* make sure we have at least ALLOW entries
1001 * for all the 3 special ids (@EVERYONE, @OWNER, @GROUP)
1002 * - if necessary
1004 for(i = SMB_ACE4_WHO_OWNER; i<=SMB_ACE4_WHO_EVERYONE; i++) {
1005 SMB_ACE4PROP_T ace;
1007 if (haveAllowEntry[i]==True)
1008 continue;
1010 ZERO_STRUCT(ace);
1011 ace.aceType = SMB_ACE4_ACCESS_ALLOWED_ACE_TYPE;
1012 ace.flags |= SMB_ACE4_ID_SPECIAL;
1013 ace.who.special_id = i;
1015 if (i==SMB_ACE4_WHO_GROUP) /* not sure it's necessary... */
1016 ace.aceFlags |= SMB_ACE4_IDENTIFIER_GROUP;
1018 ace.aceMask = gpfsacl_mask_filter(ace.aceType, ace.aceMask,
1019 mode >> ((SMB_ACE4_WHO_EVERYONE - i) * 3));
1021 /* don't add unnecessary aces */
1022 if (!ace.aceMask)
1023 continue;
1025 /* we add it to the END - as windows expects allow aces */
1026 smb_add_ace4(pacl, &ace);
1027 DEBUG(10, ("Added ALLOW ace for %s, mode=%o, id=%d, aceMask=%x\n",
1028 path, mode, i, ace.aceMask));
1031 /* don't add complementary DENY ACEs here */
1032 ZERO_STRUCT(fake_fsp);
1033 status = create_synthetic_smb_fname(talloc_tos(), path, NULL, NULL,
1034 &fake_fsp.fsp_name);
1035 if (!NT_STATUS_IS_OK(status)) {
1036 errno = map_errno_from_nt_status(status);
1037 return -1;
1039 /* put the acl */
1040 if (gpfsacl_process_smbacl(&fake_fsp, pacl) == False) {
1041 TALLOC_FREE(fake_fsp.fsp_name);
1042 return -1;
1045 TALLOC_FREE(fake_fsp.fsp_name);
1046 return 0; /* ok for [f]chmod */
1049 static int vfs_gpfs_chmod(vfs_handle_struct *handle, const char *path, mode_t mode)
1051 struct smb_filename *smb_fname_cpath;
1052 int rc;
1053 NTSTATUS status;
1055 status = create_synthetic_smb_fname(
1056 talloc_tos(), path, NULL, NULL, &smb_fname_cpath);
1058 if (SMB_VFS_NEXT_STAT(handle, smb_fname_cpath) != 0) {
1059 return -1;
1062 /* avoid chmod() if possible, to preserve acls */
1063 if ((smb_fname_cpath->st.st_ex_mode & ~S_IFMT) == mode) {
1064 return 0;
1067 rc = gpfsacl_emu_chmod(path, mode);
1068 if (rc == 1)
1069 return SMB_VFS_NEXT_CHMOD(handle, path, mode);
1070 return rc;
1073 static int vfs_gpfs_fchmod(vfs_handle_struct *handle, files_struct *fsp, mode_t mode)
1075 SMB_STRUCT_STAT st;
1076 int rc;
1078 if (SMB_VFS_NEXT_FSTAT(handle, fsp, &st) != 0) {
1079 return -1;
1082 /* avoid chmod() if possible, to preserve acls */
1083 if ((st.st_ex_mode & ~S_IFMT) == mode) {
1084 return 0;
1087 rc = gpfsacl_emu_chmod(fsp->fsp_name->base_name, mode);
1088 if (rc == 1)
1089 return SMB_VFS_NEXT_FCHMOD(handle, fsp, mode);
1090 return rc;
1093 static int gpfs_set_xattr(struct vfs_handle_struct *handle, const char *path,
1094 const char *name, const void *value, size_t size, int flags){
1095 struct xattr_DOSATTRIB dosattrib;
1096 enum ndr_err_code ndr_err;
1097 DATA_BLOB blob;
1098 const char *attrstr = value;
1099 unsigned int dosmode=0;
1100 struct gpfs_winattr attrs;
1101 int ret = 0;
1102 struct gpfs_config_data *config;
1104 SMB_VFS_HANDLE_GET_DATA(handle, config,
1105 struct gpfs_config_data,
1106 return -1);
1108 if (!config->winattr) {
1109 DEBUG(10, ("gpfs_set_xattr:name is %s -> next\n",name));
1110 return SMB_VFS_NEXT_SETXATTR(handle,path,name,value,size,flags);
1113 DEBUG(10, ("gpfs_set_xattr: %s \n",path));
1115 /* Only handle DOS Attributes */
1116 if (strcmp(name,SAMBA_XATTR_DOS_ATTRIB) != 0){
1117 DEBUG(5, ("gpfs_set_xattr:name is %s\n",name));
1118 return SMB_VFS_NEXT_SETXATTR(handle,path,name,value,size,flags);
1121 blob.data = (uint8_t *)attrstr;
1122 blob.length = size;
1124 ndr_err = ndr_pull_struct_blob(&blob, talloc_tos(), &dosattrib,
1125 (ndr_pull_flags_fn_t)ndr_pull_xattr_DOSATTRIB);
1127 if (!NDR_ERR_CODE_IS_SUCCESS(ndr_err)) {
1128 DEBUG(1, ("gpfs_set_xattr: bad ndr decode "
1129 "from EA on file %s: Error = %s\n",
1130 path, ndr_errstr(ndr_err)));
1131 return false;
1134 if (dosattrib.version != 3) {
1135 DEBUG(1, ("gpfs_set_xattr: expected dosattrib version 3, got "
1136 "%d\n", (int)dosattrib.version));
1137 return false;
1139 if (!(dosattrib.info.info3.valid_flags & XATTR_DOSINFO_ATTRIB)) {
1140 DEBUG(10, ("gpfs_set_xattr: XATTR_DOSINFO_ATTRIB not "
1141 "valid, ignoring\n"));
1142 return true;
1145 dosmode = dosattrib.info.info3.attrib;
1147 attrs.winAttrs = 0;
1148 /*Just map RD_ONLY, ARCHIVE, SYSTEM HIDDEN and SPARSE. Ignore the others*/
1149 if (dosmode & FILE_ATTRIBUTE_ARCHIVE){
1150 attrs.winAttrs |= GPFS_WINATTR_ARCHIVE;
1152 if (dosmode & FILE_ATTRIBUTE_HIDDEN){
1153 attrs.winAttrs |= GPFS_WINATTR_HIDDEN;
1155 if (dosmode & FILE_ATTRIBUTE_SYSTEM){
1156 attrs.winAttrs |= GPFS_WINATTR_SYSTEM;
1158 if (dosmode & FILE_ATTRIBUTE_READONLY){
1159 attrs.winAttrs |= GPFS_WINATTR_READONLY;
1161 if (dosmode & FILE_ATTRIBUTE_SPARSE) {
1162 attrs.winAttrs |= GPFS_WINATTR_SPARSE_FILE;
1166 ret = set_gpfs_winattrs(discard_const_p(char, path),
1167 GPFS_WINATTR_SET_ATTRS, &attrs);
1168 if ( ret == -1){
1169 if (errno == ENOSYS) {
1170 return SMB_VFS_NEXT_SETXATTR(handle, path, name, value,
1171 size, flags);
1174 DEBUG(1, ("gpfs_set_xattr:Set GPFS attributes failed %d\n",ret));
1175 return -1;
1178 DEBUG(10, ("gpfs_set_xattr:Set attributes: 0x%x\n",attrs.winAttrs));
1179 return 0;
1182 static ssize_t gpfs_get_xattr(struct vfs_handle_struct *handle, const char *path,
1183 const char *name, void *value, size_t size){
1184 char *attrstr = value;
1185 unsigned int dosmode = 0;
1186 struct gpfs_winattr attrs;
1187 int ret = 0;
1188 struct gpfs_config_data *config;
1190 SMB_VFS_HANDLE_GET_DATA(handle, config,
1191 struct gpfs_config_data,
1192 return -1);
1194 if (!config->winattr) {
1195 DEBUG(10, ("gpfs_get_xattr:name is %s -> next\n",name));
1196 return SMB_VFS_NEXT_GETXATTR(handle,path,name,value,size);
1199 DEBUG(10, ("gpfs_get_xattr: %s \n",path));
1201 /* Only handle DOS Attributes */
1202 if (strcmp(name,SAMBA_XATTR_DOS_ATTRIB) != 0){
1203 DEBUG(5, ("gpfs_get_xattr:name is %s\n",name));
1204 return SMB_VFS_NEXT_GETXATTR(handle,path,name,value,size);
1207 ret = get_gpfs_winattrs(discard_const_p(char, path), &attrs);
1208 if ( ret == -1){
1209 if (errno == ENOSYS) {
1210 return SMB_VFS_NEXT_GETXATTR(handle, path, name, value,
1211 size);
1214 DEBUG(1, ("gpfs_get_xattr: Get GPFS attributes failed: "
1215 "%d (%s)\n", ret, strerror(errno)));
1216 return -1;
1219 DEBUG(10, ("gpfs_get_xattr:Got attributes: 0x%x\n",attrs.winAttrs));
1221 /*Just map RD_ONLY, ARCHIVE, SYSTEM, HIDDEN and SPARSE. Ignore the others*/
1222 if (attrs.winAttrs & GPFS_WINATTR_ARCHIVE){
1223 dosmode |= FILE_ATTRIBUTE_ARCHIVE;
1225 if (attrs.winAttrs & GPFS_WINATTR_HIDDEN){
1226 dosmode |= FILE_ATTRIBUTE_HIDDEN;
1228 if (attrs.winAttrs & GPFS_WINATTR_SYSTEM){
1229 dosmode |= FILE_ATTRIBUTE_SYSTEM;
1231 if (attrs.winAttrs & GPFS_WINATTR_READONLY){
1232 dosmode |= FILE_ATTRIBUTE_READONLY;
1234 if (attrs.winAttrs & GPFS_WINATTR_SPARSE_FILE) {
1235 dosmode |= FILE_ATTRIBUTE_SPARSE;
1238 snprintf(attrstr, size, "0x%2.2x",
1239 (unsigned int)(dosmode & SAMBA_ATTRIBUTES_MASK));
1240 DEBUG(10, ("gpfs_get_xattr: returning %s\n",attrstr));
1241 return 4;
1244 static int vfs_gpfs_stat(struct vfs_handle_struct *handle,
1245 struct smb_filename *smb_fname)
1247 struct gpfs_winattr attrs;
1248 char *fname = NULL;
1249 NTSTATUS status;
1250 int ret;
1251 struct gpfs_config_data *config;
1253 SMB_VFS_HANDLE_GET_DATA(handle, config,
1254 struct gpfs_config_data,
1255 return -1);
1257 ret = SMB_VFS_NEXT_STAT(handle, smb_fname);
1258 if (ret == -1) {
1259 return -1;
1262 if (!config->winattr) {
1263 return 0;
1266 status = get_full_smb_filename(talloc_tos(), smb_fname, &fname);
1267 if (!NT_STATUS_IS_OK(status)) {
1268 errno = map_errno_from_nt_status(status);
1269 return -1;
1271 ret = get_gpfs_winattrs(discard_const_p(char, fname), &attrs);
1272 TALLOC_FREE(fname);
1273 if (ret == 0) {
1274 smb_fname->st.st_ex_calculated_birthtime = false;
1275 smb_fname->st.st_ex_btime.tv_sec = attrs.creationTime.tv_sec;
1276 smb_fname->st.st_ex_btime.tv_nsec = attrs.creationTime.tv_nsec;
1277 smb_fname->st.vfs_private = attrs.winAttrs;
1279 return 0;
1282 static int vfs_gpfs_fstat(struct vfs_handle_struct *handle,
1283 struct files_struct *fsp, SMB_STRUCT_STAT *sbuf)
1285 struct gpfs_winattr attrs;
1286 int ret;
1287 struct gpfs_config_data *config;
1289 SMB_VFS_HANDLE_GET_DATA(handle, config,
1290 struct gpfs_config_data,
1291 return -1);
1293 ret = SMB_VFS_NEXT_FSTAT(handle, fsp, sbuf);
1294 if (ret == -1) {
1295 return -1;
1297 if ((fsp->fh == NULL) || (fsp->fh->fd == -1)) {
1298 return 0;
1300 if (!config->winattr) {
1301 return 0;
1304 ret = smbd_fget_gpfs_winattrs(fsp->fh->fd, &attrs);
1305 if (ret == 0) {
1306 sbuf->st_ex_calculated_birthtime = false;
1307 sbuf->st_ex_btime.tv_sec = attrs.creationTime.tv_sec;
1308 sbuf->st_ex_btime.tv_nsec = attrs.creationTime.tv_nsec;
1310 return 0;
1313 static int vfs_gpfs_lstat(struct vfs_handle_struct *handle,
1314 struct smb_filename *smb_fname)
1316 struct gpfs_winattr attrs;
1317 char *path = NULL;
1318 NTSTATUS status;
1319 int ret;
1320 struct gpfs_config_data *config;
1322 SMB_VFS_HANDLE_GET_DATA(handle, config,
1323 struct gpfs_config_data,
1324 return -1);
1326 ret = SMB_VFS_NEXT_LSTAT(handle, smb_fname);
1327 if (ret == -1) {
1328 return -1;
1330 if (!config->winattr) {
1331 return 0;
1334 status = get_full_smb_filename(talloc_tos(), smb_fname, &path);
1335 if (!NT_STATUS_IS_OK(status)) {
1336 errno = map_errno_from_nt_status(status);
1337 return -1;
1339 ret = get_gpfs_winattrs(discard_const_p(char, path), &attrs);
1340 TALLOC_FREE(path);
1341 if (ret == 0) {
1342 smb_fname->st.st_ex_calculated_birthtime = false;
1343 smb_fname->st.st_ex_btime.tv_sec = attrs.creationTime.tv_sec;
1344 smb_fname->st.st_ex_btime.tv_nsec = attrs.creationTime.tv_nsec;
1345 smb_fname->st.vfs_private = attrs.winAttrs;
1347 return 0;
1350 static int vfs_gpfs_ntimes(struct vfs_handle_struct *handle,
1351 const struct smb_filename *smb_fname,
1352 struct smb_file_time *ft)
1355 struct gpfs_winattr attrs;
1356 int ret;
1357 char *path = NULL;
1358 NTSTATUS status;
1359 struct gpfs_config_data *config;
1361 SMB_VFS_HANDLE_GET_DATA(handle, config,
1362 struct gpfs_config_data,
1363 return -1);
1365 ret = SMB_VFS_NEXT_NTIMES(handle, smb_fname, ft);
1366 if(ret == -1){
1367 /* don't complain if access was denied */
1368 if (errno != EPERM && errno != EACCES) {
1369 DEBUG(1,("vfs_gpfs_ntimes: SMB_VFS_NEXT_NTIMES failed:"
1370 "%s", strerror(errno)));
1372 return -1;
1375 if(null_timespec(ft->create_time)){
1376 DEBUG(10,("vfs_gpfs_ntimes:Create Time is NULL\n"));
1377 return 0;
1380 if (!config->winattr) {
1381 return 0;
1384 status = get_full_smb_filename(talloc_tos(), smb_fname, &path);
1385 if (!NT_STATUS_IS_OK(status)) {
1386 errno = map_errno_from_nt_status(status);
1387 return -1;
1390 attrs.winAttrs = 0;
1391 attrs.creationTime.tv_sec = ft->create_time.tv_sec;
1392 attrs.creationTime.tv_nsec = ft->create_time.tv_nsec;
1394 ret = set_gpfs_winattrs(discard_const_p(char, path),
1395 GPFS_WINATTR_SET_CREATION_TIME, &attrs);
1396 if(ret == -1 && errno != ENOSYS){
1397 DEBUG(1,("vfs_gpfs_ntimes: set GPFS ntimes failed %d\n",ret));
1398 return -1;
1400 return 0;
1404 static int vfs_gpfs_fallocate(struct vfs_handle_struct *handle,
1405 struct files_struct *fsp, enum vfs_fallocate_mode mode,
1406 off_t offset, off_t len)
1408 int ret;
1409 struct gpfs_config_data *config;
1411 SMB_VFS_HANDLE_GET_DATA(handle, config,
1412 struct gpfs_config_data,
1413 return -1);
1415 if (!config->prealloc) {
1416 /* you should better not run fallocate() on GPFS at all */
1417 errno = ENOTSUP;
1418 return -1;
1421 if (mode == VFS_FALLOCATE_KEEP_SIZE) {
1422 DEBUG(10, ("Unsupported VFS_FALLOCATE_KEEP_SIZE\n"));
1423 errno = ENOTSUP;
1424 return -1;
1427 ret = smbd_gpfs_prealloc(fsp->fh->fd, offset, len);
1429 if (ret == -1 && errno != ENOSYS) {
1430 DEBUG(0, ("GPFS prealloc failed: %s\n", strerror(errno)));
1431 } else if (ret == -1 && errno == ENOSYS) {
1432 DEBUG(10, ("GPFS prealloc not supported.\n"));
1433 } else {
1434 DEBUG(10, ("GPFS prealloc succeeded.\n"));
1437 return ret;
1440 static int vfs_gpfs_ftruncate(vfs_handle_struct *handle, files_struct *fsp,
1441 off_t len)
1443 int result;
1444 struct gpfs_config_data *config;
1446 SMB_VFS_HANDLE_GET_DATA(handle, config,
1447 struct gpfs_config_data,
1448 return -1);
1450 if (!config->ftruncate) {
1451 return SMB_VFS_NEXT_FTRUNCATE(handle, fsp, len);
1454 result = smbd_gpfs_ftruncate(fsp->fh->fd, len);
1455 if ((result == -1) && (errno == ENOSYS)) {
1456 return SMB_VFS_NEXT_FTRUNCATE(handle, fsp, len);
1458 return result;
1461 static bool vfs_gpfs_is_offline(struct vfs_handle_struct *handle,
1462 const struct smb_filename *fname,
1463 SMB_STRUCT_STAT *sbuf)
1465 struct gpfs_winattr attrs;
1466 char *path = NULL;
1467 NTSTATUS status;
1468 struct gpfs_config_data *config;
1470 SMB_VFS_HANDLE_GET_DATA(handle, config,
1471 struct gpfs_config_data,
1472 return -1);
1474 if (!config->winattr) {
1475 return SMB_VFS_NEXT_IS_OFFLINE(handle, fname, sbuf);
1478 status = get_full_smb_filename(talloc_tos(), fname, &path);
1479 if (!NT_STATUS_IS_OK(status)) {
1480 errno = map_errno_from_nt_status(status);
1481 return -1;
1484 if (VALID_STAT(*sbuf)) {
1485 attrs.winAttrs = sbuf->vfs_private;
1486 } else {
1487 int ret;
1488 ret = get_gpfs_winattrs(path, &attrs);
1490 if (ret == -1) {
1491 TALLOC_FREE(path);
1492 return false;
1495 if ((attrs.winAttrs & GPFS_WINATTR_OFFLINE) != 0) {
1496 DEBUG(10, ("%s is offline\n", path));
1497 TALLOC_FREE(path);
1498 return true;
1500 DEBUG(10, ("%s is online\n", path));
1501 TALLOC_FREE(path);
1502 return SMB_VFS_NEXT_IS_OFFLINE(handle, fname, sbuf);
1505 static bool vfs_gpfs_aio_force(struct vfs_handle_struct *handle,
1506 struct files_struct *fsp)
1508 return vfs_gpfs_is_offline(handle, fsp->fsp_name, &fsp->fsp_name->st);
1511 static ssize_t vfs_gpfs_sendfile(vfs_handle_struct *handle, int tofd,
1512 files_struct *fsp, const DATA_BLOB *hdr,
1513 off_t offset, size_t n)
1515 if ((fsp->fsp_name->st.vfs_private & GPFS_WINATTR_OFFLINE) != 0) {
1516 errno = ENOSYS;
1517 return -1;
1519 return SMB_VFS_NEXT_SENDFILE(handle, tofd, fsp, hdr, offset, n);
1522 static int vfs_gpfs_connect(struct vfs_handle_struct *handle,
1523 const char *service, const char *user)
1525 struct gpfs_config_data *config;
1526 int ret;
1528 smbd_gpfs_lib_init();
1530 ret = SMB_VFS_NEXT_CONNECT(handle, service, user);
1532 if (ret < 0) {
1533 return ret;
1536 config = talloc_zero(handle->conn, struct gpfs_config_data);
1537 if (!config) {
1538 SMB_VFS_NEXT_DISCONNECT(handle);
1539 DEBUG(0, ("talloc_zero() failed\n"));
1540 return -1;
1543 config->sharemodes = lp_parm_bool(SNUM(handle->conn), "gpfs",
1544 "sharemodes", true);
1546 config->leases = lp_parm_bool(SNUM(handle->conn), "gpfs",
1547 "leases", true);
1549 config->hsm = lp_parm_bool(SNUM(handle->conn), "gpfs",
1550 "hsm", false);
1552 config->syncio = lp_parm_bool(SNUM(handle->conn), "gpfs",
1553 "syncio", false);
1555 config->winattr = lp_parm_bool(SNUM(handle->conn), "gpfs",
1556 "winattr", false);
1558 config->ftruncate = lp_parm_bool(SNUM(handle->conn), "gpfs",
1559 "ftruncate", true);
1561 config->getrealfilename = lp_parm_bool(SNUM(handle->conn), "gpfs",
1562 "getrealfilename", true);
1564 config->dfreequota = lp_parm_bool(SNUM(handle->conn), "gpfs",
1565 "dfreequota", false);
1567 config->prealloc = lp_parm_bool(SNUM(handle->conn), "gpfs",
1568 "prealloc", true);
1570 config->acl = lp_parm_bool(SNUM(handle->conn), "gpfs", "acl", true);
1572 SMB_VFS_HANDLE_SET_DATA(handle, config,
1573 NULL, struct gpfs_config_data,
1574 return -1);
1576 if (config->leases) {
1578 * GPFS lease code is based on kernel oplock code
1579 * so make sure it is turned on
1581 if (!lp_kernel_oplocks(SNUM(handle->conn))) {
1582 DEBUG(5, ("Enabling kernel oplocks for "
1583 "gpfs:leases to work\n"));
1584 lp_do_parameter(SNUM(handle->conn), "kernel oplocks",
1585 "true");
1589 * as the kernel does not properly support Level II oplocks
1590 * and GPFS leases code is based on kernel infrastructure, we
1591 * need to turn off Level II oplocks if gpfs:leases is enabled
1593 if (lp_level2_oplocks(SNUM(handle->conn))) {
1594 DEBUG(5, ("gpfs:leases are enabled, disabling "
1595 "Level II oplocks\n"));
1596 lp_do_parameter(SNUM(handle->conn), "level2 oplocks",
1597 "false");
1601 return 0;
1604 static int vfs_gpfs_get_quotas(const char *path, uid_t uid, gid_t gid,
1605 int *fset_id,
1606 struct gpfs_quotaInfo *qi_user,
1607 struct gpfs_quotaInfo *qi_group,
1608 struct gpfs_quotaInfo *qi_fset)
1610 int err;
1611 char *dir_path;
1612 bool b;
1615 * We want to always use the directory to get the fileset id,
1616 * because files might have a share mode. We also do not want
1617 * to get the parent directory when there is already a
1618 * directory to avoid stepping in a different fileset. The
1619 * path passed here is currently either "." or a filename, so
1620 * this is ok. The proper solution would be having a way to
1621 * query the fileset id without opening the file.
1623 b = parent_dirname(talloc_tos(), path, &dir_path, NULL);
1624 if (!b) {
1625 errno = ENOMEM;
1626 return -1;
1629 DEBUG(10, ("path %s, directory %s\n", path, dir_path));
1631 err = get_gpfs_fset_id(dir_path, fset_id);
1632 if (err) {
1633 DEBUG(0, ("Get fset id failed path %s, dir %s, errno %d.\n",
1634 path, dir_path, errno));
1635 return err;
1638 err = get_gpfs_quota(path, GPFS_USRQUOTA, uid, qi_user);
1639 if (err) {
1640 return err;
1643 err = get_gpfs_quota(path, GPFS_GRPQUOTA, gid, qi_group);
1644 if (err) {
1645 return err;
1648 err = get_gpfs_quota(path, GPFS_FILESETQUOTA, *fset_id, qi_fset);
1649 if (err) {
1650 return err;
1653 return 0;
1656 static void vfs_gpfs_disk_free_quota(struct gpfs_quotaInfo qi, time_t cur_time,
1657 uint64_t *dfree, uint64_t *dsize)
1659 uint64_t usage, limit;
1662 * The quota reporting is done in units of 1024 byte blocks, but
1663 * sys_fsusage uses units of 512 byte blocks, adjust the block number
1664 * accordingly. Also filter possibly negative usage counts from gpfs.
1666 usage = qi.blockUsage < 0 ? 0 : (uint64_t)qi.blockUsage * 2;
1667 limit = (uint64_t)qi.blockHardLimit * 2;
1670 * When the grace time for the exceeded soft block quota has been
1671 * exceeded, the soft block quota becomes an additional hard limit.
1673 if (qi.blockSoftLimit &&
1674 qi.blockGraceTime && cur_time > qi.blockGraceTime) {
1675 /* report disk as full */
1676 *dfree = 0;
1677 *dsize = MIN(*dsize, usage);
1680 if (!qi.blockHardLimit)
1681 return;
1683 if (usage >= limit) {
1684 /* report disk as full */
1685 *dfree = 0;
1686 *dsize = MIN(*dsize, usage);
1688 } else {
1689 /* limit has not been reached, determine "free space" */
1690 *dfree = MIN(*dfree, limit - usage);
1691 *dsize = MIN(*dsize, limit);
1695 static uint64_t vfs_gpfs_disk_free(vfs_handle_struct *handle, const char *path,
1696 bool small_query, uint64_t *bsize,
1697 uint64_t *dfree, uint64_t *dsize)
1699 struct security_unix_token *utok;
1700 struct gpfs_quotaInfo qi_user, qi_group, qi_fset;
1701 struct gpfs_config_data *config;
1702 int err, fset_id;
1703 time_t cur_time;
1705 SMB_VFS_HANDLE_GET_DATA(handle, config, struct gpfs_config_data,
1706 return (uint64_t)-1);
1707 if (!config->dfreequota) {
1708 return SMB_VFS_NEXT_DISK_FREE(handle, path, small_query,
1709 bsize, dfree, dsize);
1712 err = sys_fsusage(path, dfree, dsize);
1713 if (err) {
1714 DEBUG (0, ("Could not get fs usage, errno %d\n", errno));
1715 return SMB_VFS_NEXT_DISK_FREE(handle, path, small_query,
1716 bsize, dfree, dsize);
1719 /* sys_fsusage returns units of 512 bytes */
1720 *bsize = 512;
1722 DEBUG(10, ("fs dfree %llu, dsize %llu\n",
1723 (unsigned long long)*dfree, (unsigned long long)*dsize));
1725 utok = handle->conn->session_info->unix_token;
1726 err = vfs_gpfs_get_quotas(path, utok->uid, utok->gid, &fset_id,
1727 &qi_user, &qi_group, &qi_fset);
1728 if (err) {
1729 return SMB_VFS_NEXT_DISK_FREE(handle, path, small_query,
1730 bsize, dfree, dsize);
1733 cur_time = time(NULL);
1735 /* Adjust free space and size according to quota limits. */
1736 vfs_gpfs_disk_free_quota(qi_user, cur_time, dfree, dsize);
1737 vfs_gpfs_disk_free_quota(qi_group, cur_time, dfree, dsize);
1739 /* Id 0 indicates the default quota, not an actual quota */
1740 if (fset_id != 0) {
1741 vfs_gpfs_disk_free_quota(qi_fset, cur_time, dfree, dsize);
1744 disk_norm(small_query, bsize, dfree, dsize);
1745 return *dfree;
1748 static uint32_t vfs_gpfs_capabilities(struct vfs_handle_struct *handle,
1749 enum timestamp_set_resolution *p_ts_res)
1751 struct gpfs_config_data *config;
1752 uint32_t next;
1754 next = SMB_VFS_NEXT_FS_CAPABILITIES(handle, p_ts_res);
1756 SMB_VFS_HANDLE_GET_DATA(handle, config,
1757 struct gpfs_config_data,
1758 return next);
1760 if (config->hsm) {
1761 next |= FILE_SUPPORTS_REMOTE_STORAGE;
1763 return next;
1766 static int vfs_gpfs_open(struct vfs_handle_struct *handle,
1767 struct smb_filename *smb_fname, files_struct *fsp,
1768 int flags, mode_t mode)
1770 struct gpfs_config_data *config;
1772 SMB_VFS_HANDLE_GET_DATA(handle, config,
1773 struct gpfs_config_data,
1774 return -1);
1776 if (config->syncio) {
1777 flags |= O_SYNC;
1779 return SMB_VFS_NEXT_OPEN(handle, smb_fname, fsp, flags, mode);
1782 static ssize_t vfs_gpfs_pread(vfs_handle_struct *handle, files_struct *fsp,
1783 void *data, size_t n, off_t offset)
1785 ssize_t ret;
1787 ret = SMB_VFS_NEXT_PREAD(handle, fsp, data, n, offset);
1789 DEBUG(10, ("vfs_private = %x\n",
1790 (unsigned int)fsp->fsp_name->st.vfs_private));
1792 if ((ret != -1) &&
1793 ((fsp->fsp_name->st.vfs_private & GPFS_WINATTR_OFFLINE) != 0)) {
1794 fsp->fsp_name->st.vfs_private &= ~GPFS_WINATTR_OFFLINE;
1795 notify_fname(handle->conn, NOTIFY_ACTION_MODIFIED,
1796 FILE_NOTIFY_CHANGE_ATTRIBUTES,
1797 fsp->fsp_name->base_name);
1800 return ret;
1803 struct vfs_gpfs_pread_state {
1804 struct files_struct *fsp;
1805 ssize_t ret;
1806 int err;
1809 static void vfs_gpfs_pread_done(struct tevent_req *subreq);
1811 static struct tevent_req *vfs_gpfs_pread_send(struct vfs_handle_struct *handle,
1812 TALLOC_CTX *mem_ctx,
1813 struct tevent_context *ev,
1814 struct files_struct *fsp,
1815 void *data, size_t n,
1816 off_t offset)
1818 struct tevent_req *req, *subreq;
1819 struct vfs_gpfs_pread_state *state;
1821 req = tevent_req_create(mem_ctx, &state, struct vfs_gpfs_pread_state);
1822 if (req == NULL) {
1823 return NULL;
1825 state->fsp = fsp;
1826 subreq = SMB_VFS_NEXT_PREAD_SEND(state, ev, handle, fsp, data,
1827 n, offset);
1828 if (tevent_req_nomem(subreq, req)) {
1829 return tevent_req_post(req, ev);
1831 tevent_req_set_callback(subreq, vfs_gpfs_pread_done, req);
1832 return req;
1835 static void vfs_gpfs_pread_done(struct tevent_req *subreq)
1837 struct tevent_req *req = tevent_req_callback_data(
1838 subreq, struct tevent_req);
1839 struct vfs_gpfs_pread_state *state = tevent_req_data(
1840 req, struct vfs_gpfs_pread_state);
1842 state->ret = SMB_VFS_PREAD_RECV(subreq, &state->err);
1843 TALLOC_FREE(subreq);
1844 tevent_req_done(req);
1847 static ssize_t vfs_gpfs_pread_recv(struct tevent_req *req, int *err)
1849 struct vfs_gpfs_pread_state *state = tevent_req_data(
1850 req, struct vfs_gpfs_pread_state);
1851 struct files_struct *fsp = state->fsp;
1853 if (tevent_req_is_unix_error(req, err)) {
1854 return -1;
1856 *err = state->err;
1858 DEBUG(10, ("vfs_private = %x\n",
1859 (unsigned int)fsp->fsp_name->st.vfs_private));
1861 if ((state->ret != -1) &&
1862 ((fsp->fsp_name->st.vfs_private & GPFS_WINATTR_OFFLINE) != 0)) {
1863 fsp->fsp_name->st.vfs_private &= ~GPFS_WINATTR_OFFLINE;
1864 DEBUG(10, ("sending notify\n"));
1865 notify_fname(fsp->conn, NOTIFY_ACTION_MODIFIED,
1866 FILE_NOTIFY_CHANGE_ATTRIBUTES,
1867 fsp->fsp_name->base_name);
1870 return state->ret;
1873 static ssize_t vfs_gpfs_pwrite(vfs_handle_struct *handle, files_struct *fsp,
1874 const void *data, size_t n, off_t offset)
1876 ssize_t ret;
1878 ret = SMB_VFS_NEXT_PWRITE(handle, fsp, data, n, offset);
1880 DEBUG(10, ("vfs_private = %x\n",
1881 (unsigned int)fsp->fsp_name->st.vfs_private));
1883 if ((ret != -1) &&
1884 ((fsp->fsp_name->st.vfs_private & GPFS_WINATTR_OFFLINE) != 0)) {
1885 fsp->fsp_name->st.vfs_private &= ~GPFS_WINATTR_OFFLINE;
1886 notify_fname(handle->conn, NOTIFY_ACTION_MODIFIED,
1887 FILE_NOTIFY_CHANGE_ATTRIBUTES,
1888 fsp->fsp_name->base_name);
1891 return ret;
1894 struct vfs_gpfs_pwrite_state {
1895 struct files_struct *fsp;
1896 ssize_t ret;
1897 int err;
1900 static void vfs_gpfs_pwrite_done(struct tevent_req *subreq);
1902 static struct tevent_req *vfs_gpfs_pwrite_send(
1903 struct vfs_handle_struct *handle,
1904 TALLOC_CTX *mem_ctx,
1905 struct tevent_context *ev,
1906 struct files_struct *fsp,
1907 const void *data, size_t n,
1908 off_t offset)
1910 struct tevent_req *req, *subreq;
1911 struct vfs_gpfs_pwrite_state *state;
1913 req = tevent_req_create(mem_ctx, &state, struct vfs_gpfs_pwrite_state);
1914 if (req == NULL) {
1915 return NULL;
1917 state->fsp = fsp;
1918 subreq = SMB_VFS_NEXT_PWRITE_SEND(state, ev, handle, fsp, data,
1919 n, offset);
1920 if (tevent_req_nomem(subreq, req)) {
1921 return tevent_req_post(req, ev);
1923 tevent_req_set_callback(subreq, vfs_gpfs_pwrite_done, req);
1924 return req;
1927 static void vfs_gpfs_pwrite_done(struct tevent_req *subreq)
1929 struct tevent_req *req = tevent_req_callback_data(
1930 subreq, struct tevent_req);
1931 struct vfs_gpfs_pwrite_state *state = tevent_req_data(
1932 req, struct vfs_gpfs_pwrite_state);
1934 state->ret = SMB_VFS_PWRITE_RECV(subreq, &state->err);
1935 TALLOC_FREE(subreq);
1936 tevent_req_done(req);
1939 static ssize_t vfs_gpfs_pwrite_recv(struct tevent_req *req, int *err)
1941 struct vfs_gpfs_pwrite_state *state = tevent_req_data(
1942 req, struct vfs_gpfs_pwrite_state);
1943 struct files_struct *fsp = state->fsp;
1945 if (tevent_req_is_unix_error(req, err)) {
1946 return -1;
1948 *err = state->err;
1950 DEBUG(10, ("vfs_private = %x\n",
1951 (unsigned int)fsp->fsp_name->st.vfs_private));
1953 if ((state->ret != -1) &&
1954 ((fsp->fsp_name->st.vfs_private & GPFS_WINATTR_OFFLINE) != 0)) {
1955 fsp->fsp_name->st.vfs_private &= ~GPFS_WINATTR_OFFLINE;
1956 DEBUG(10, ("sending notify\n"));
1957 notify_fname(fsp->conn, NOTIFY_ACTION_MODIFIED,
1958 FILE_NOTIFY_CHANGE_ATTRIBUTES,
1959 fsp->fsp_name->base_name);
1962 return state->ret;
1966 static struct vfs_fn_pointers vfs_gpfs_fns = {
1967 .connect_fn = vfs_gpfs_connect,
1968 .disk_free_fn = vfs_gpfs_disk_free,
1969 .fs_capabilities_fn = vfs_gpfs_capabilities,
1970 .kernel_flock_fn = vfs_gpfs_kernel_flock,
1971 .linux_setlease_fn = vfs_gpfs_setlease,
1972 .get_real_filename_fn = vfs_gpfs_get_real_filename,
1973 .fget_nt_acl_fn = gpfsacl_fget_nt_acl,
1974 .get_nt_acl_fn = gpfsacl_get_nt_acl,
1975 .fset_nt_acl_fn = gpfsacl_fset_nt_acl,
1976 .sys_acl_get_file_fn = gpfsacl_sys_acl_get_file,
1977 .sys_acl_get_fd_fn = gpfsacl_sys_acl_get_fd,
1978 .sys_acl_blob_get_file_fn = gpfsacl_sys_acl_blob_get_file,
1979 .sys_acl_blob_get_fd_fn = gpfsacl_sys_acl_blob_get_fd,
1980 .sys_acl_set_file_fn = gpfsacl_sys_acl_set_file,
1981 .sys_acl_set_fd_fn = gpfsacl_sys_acl_set_fd,
1982 .sys_acl_delete_def_file_fn = gpfsacl_sys_acl_delete_def_file,
1983 .chmod_fn = vfs_gpfs_chmod,
1984 .fchmod_fn = vfs_gpfs_fchmod,
1985 .close_fn = vfs_gpfs_close,
1986 .setxattr_fn = gpfs_set_xattr,
1987 .getxattr_fn = gpfs_get_xattr,
1988 .stat_fn = vfs_gpfs_stat,
1989 .fstat_fn = vfs_gpfs_fstat,
1990 .lstat_fn = vfs_gpfs_lstat,
1991 .ntimes_fn = vfs_gpfs_ntimes,
1992 .is_offline_fn = vfs_gpfs_is_offline,
1993 .aio_force_fn = vfs_gpfs_aio_force,
1994 .sendfile_fn = vfs_gpfs_sendfile,
1995 .fallocate_fn = vfs_gpfs_fallocate,
1996 .open_fn = vfs_gpfs_open,
1997 .pread_fn = vfs_gpfs_pread,
1998 .pread_send_fn = vfs_gpfs_pread_send,
1999 .pread_recv_fn = vfs_gpfs_pread_recv,
2000 .pwrite_fn = vfs_gpfs_pwrite,
2001 .pwrite_send_fn = vfs_gpfs_pwrite_send,
2002 .pwrite_recv_fn = vfs_gpfs_pwrite_recv,
2003 .ftruncate_fn = vfs_gpfs_ftruncate
2006 NTSTATUS vfs_gpfs_init(void);
2007 NTSTATUS vfs_gpfs_init(void)
2009 init_gpfs();
2011 return smb_register_vfs(SMB_VFS_INTERFACE_VERSION, "gpfs",
2012 &vfs_gpfs_fns);