2 * Unix SMB/CIFS implementation.
3 * Samba VFS module for GPFS filesystem
4 * Copyright (C) Christian Ambach <cambach1@de.ibm.com> 2006
5 * Copyright (C) Christof Schmitt 2015
6 * Major code contributions by Chetan Shringarpure <chetan.sh@in.ibm.com>
7 * and Gomati Mohanan <gomati.mohanan@in.ibm.com>
9 * This program is free software; you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License as published by
11 * the Free Software Foundation; either version 3 of the License, or
12 * (at your option) any later version.
14 * This program is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 * GNU General Public License for more details.
19 * You should have received a copy of the GNU General Public License
20 * along with this program; if not, see <http://www.gnu.org/licenses/>.
24 #include "smbd/smbd.h"
25 #include "librpc/gen_ndr/ndr_xattr.h"
26 #include "include/smbprofile.h"
27 #include "modules/non_posix_acls.h"
28 #include "libcli/security/security.h"
29 #include "nfs4_acls.h"
30 #include "system/filesys.h"
32 #include "lib/util/tevent_unix.h"
36 #define DBGC_CLASS DBGC_VFS
38 #ifndef GPFS_GETACL_NATIVE
39 #define GPFS_GETACL_NATIVE 0x00000004
42 struct gpfs_config_data
{
57 static inline unsigned int gpfs_acl_flags(gpfs_acl_t
*gacl
)
59 if (gacl
->acl_level
== 1) { /* GPFS_ACL_LEVEL_V4FLAGS */
60 /* gacl->v4Level1.acl_flags requires gpfs 3.5 */
61 return *(unsigned int *)&gacl
->ace_v4
;
66 static inline gpfs_ace_v4_t
*gpfs_ace_ptr(gpfs_acl_t
*gacl
, unsigned int i
)
68 if (gacl
->acl_level
== 1) { /* GPFS_ACL_LEVEL_V4FLAGS */
69 /* &gacl->v4Level1.ace_v4[i] requires gpfs 3.5 */
70 char *ptr
= (char *)&gacl
->ace_v4
[i
] + sizeof(unsigned int);
71 return (gpfs_ace_v4_t
*)ptr
;
73 return &gacl
->ace_v4
[i
];
76 static bool set_gpfs_sharemode(files_struct
*fsp
, uint32 access_mask
,
79 unsigned int allow
= GPFS_SHARE_NONE
;
80 unsigned int deny
= GPFS_DENY_NONE
;
83 if ((fsp
== NULL
) || (fsp
->fh
== NULL
) || (fsp
->fh
->fd
< 0)) {
84 /* No real file, don't disturb */
88 allow
|= (access_mask
& (FILE_WRITE_DATA
|FILE_APPEND_DATA
|
89 DELETE_ACCESS
)) ? GPFS_SHARE_WRITE
: 0;
90 allow
|= (access_mask
& (FILE_READ_DATA
|FILE_EXECUTE
)) ?
93 if (allow
== GPFS_SHARE_NONE
) {
94 DEBUG(10, ("special case am=no_access:%x\n",access_mask
));
97 deny
|= (share_access
& FILE_SHARE_WRITE
) ?
99 deny
|= (share_access
& (FILE_SHARE_READ
)) ?
102 DEBUG(10, ("am=%x, allow=%d, sa=%x, deny=%d\n",
103 access_mask
, allow
, share_access
, deny
));
105 result
= gpfswrap_set_share(fsp
->fh
->fd
, allow
, deny
);
107 if (errno
== ENOSYS
) {
108 DEBUG(5, ("VFS module vfs_gpfs loaded, but gpfs "
109 "set_share function support not available. "
110 "Allowing access\n"));
113 DEBUG(10, ("gpfs_set_share failed: %s\n",
118 return (result
== 0);
121 static int vfs_gpfs_kernel_flock(vfs_handle_struct
*handle
, files_struct
*fsp
,
122 uint32 share_mode
, uint32 access_mask
)
125 struct gpfs_config_data
*config
;
128 START_PROFILE(syscall_kernel_flock
);
130 SMB_VFS_HANDLE_GET_DATA(handle
, config
,
131 struct gpfs_config_data
,
134 if(!config
->sharemodes
) {
138 kernel_flock(fsp
->fh
->fd
, share_mode
, access_mask
);
140 if (!set_gpfs_sharemode(fsp
, access_mask
, fsp
->share_access
)) {
144 END_PROFILE(syscall_kernel_flock
);
149 static int vfs_gpfs_close(vfs_handle_struct
*handle
, files_struct
*fsp
)
152 struct gpfs_config_data
*config
;
154 SMB_VFS_HANDLE_GET_DATA(handle
, config
,
155 struct gpfs_config_data
,
158 if (config
->sharemodes
&& (fsp
->fh
!= NULL
) && (fsp
->fh
->fd
!= -1)) {
159 set_gpfs_sharemode(fsp
, 0, 0);
162 return SMB_VFS_NEXT_CLOSE(handle
, fsp
);
165 static int set_gpfs_lease(int fd
, int leasetype
)
167 int gpfs_type
= GPFS_LEASE_NONE
;
169 if (leasetype
== F_RDLCK
) {
170 gpfs_type
= GPFS_LEASE_READ
;
172 if (leasetype
== F_WRLCK
) {
173 gpfs_type
= GPFS_LEASE_WRITE
;
176 /* we unconditionally set CAP_LEASE, rather than looking for
177 -1/EACCES as there is a bug in some versions of
178 libgpfs_gpl.so which results in a leaked fd on /dev/ss0
179 each time we try this with the wrong capabilities set
181 linux_set_lease_capability();
182 return gpfswrap_set_lease(fd
, gpfs_type
);
185 static int vfs_gpfs_setlease(vfs_handle_struct
*handle
, files_struct
*fsp
,
188 struct gpfs_config_data
*config
;
191 START_PROFILE(syscall_linux_setlease
);
193 SMB_VFS_HANDLE_GET_DATA(handle
, config
,
194 struct gpfs_config_data
,
197 if (linux_set_lease_sighandler(fsp
->fh
->fd
) == -1)
200 if (config
->leases
) {
202 * Ensure the lease owner is root to allow
203 * correct delivery of lease-break signals.
206 ret
= set_gpfs_lease(fsp
->fh
->fd
,leasetype
);
210 END_PROFILE(syscall_linux_setlease
);
215 static int vfs_gpfs_get_real_filename(struct vfs_handle_struct
*handle
,
223 char real_pathname
[PATH_MAX
+1];
226 struct gpfs_config_data
*config
;
228 SMB_VFS_HANDLE_GET_DATA(handle
, config
,
229 struct gpfs_config_data
,
232 if (!config
->getrealfilename
) {
233 return SMB_VFS_NEXT_GET_REAL_FILENAME(handle
, path
, name
,
234 mem_ctx
, found_name
);
237 mangled
= mangle_is_mangled(name
, handle
->conn
->params
);
239 return SMB_VFS_NEXT_GET_REAL_FILENAME(handle
, path
, name
,
240 mem_ctx
, found_name
);
243 full_path
= talloc_asprintf(talloc_tos(), "%s/%s", path
, name
);
244 if (full_path
== NULL
) {
249 buflen
= sizeof(real_pathname
) - 1;
251 result
= gpfswrap_get_realfilename_path(full_path
, real_pathname
,
254 TALLOC_FREE(full_path
);
256 if ((result
== -1) && (errno
== ENOSYS
)) {
257 return SMB_VFS_NEXT_GET_REAL_FILENAME(
258 handle
, path
, name
, mem_ctx
, found_name
);
262 DEBUG(10, ("smbd_gpfs_get_realfilename_path returned %s\n",
268 * GPFS does not necessarily null-terminate the returned path
269 * but instead returns the buffer length in buflen.
272 if (buflen
< sizeof(real_pathname
)) {
273 real_pathname
[buflen
] = '\0';
275 real_pathname
[sizeof(real_pathname
)-1] = '\0';
278 DEBUG(10, ("smbd_gpfs_get_realfilename_path: %s/%s -> %s\n",
279 path
, name
, real_pathname
));
281 name
= strrchr_m(real_pathname
, '/');
287 *found_name
= talloc_strdup(mem_ctx
, name
+1);
288 if (*found_name
== NULL
) {
296 static void sd2gpfs_control(uint16_t control
, struct gpfs_acl
*gacl
)
298 unsigned int gpfs_aclflags
= 0;
299 control
&= SEC_DESC_DACL_PROTECTED
| SEC_DESC_SACL_PROTECTED
|
300 SEC_DESC_DACL_AUTO_INHERITED
| SEC_DESC_SACL_AUTO_INHERITED
|
301 SEC_DESC_DACL_DEFAULTED
| SEC_DESC_SACL_DEFAULTED
|
302 SEC_DESC_DACL_PRESENT
| SEC_DESC_SACL_PRESENT
;
303 gpfs_aclflags
= control
<< 8;
304 if (!(control
& SEC_DESC_DACL_PRESENT
))
305 gpfs_aclflags
|= 0x00800000; /* ACL4_FLAG_NULL_DACL; */
306 if (!(control
& SEC_DESC_SACL_PRESENT
))
307 gpfs_aclflags
|= 0x01000000; /* ACL4_FLAG_NULL_SACL; */
308 gacl
->acl_level
= 1; /* GPFS_ACL_LEVEL_V4FLAGS*/
309 /* gacl->v4Level1.acl_flags requires gpfs 3.5 */
310 *(unsigned int *)&gacl
->ace_v4
= gpfs_aclflags
;
313 static uint16_t gpfs2sd_control(unsigned int gpfs_aclflags
)
315 uint16_t control
= gpfs_aclflags
>> 8;
316 control
&= SEC_DESC_DACL_PROTECTED
| SEC_DESC_SACL_PROTECTED
|
317 SEC_DESC_DACL_AUTO_INHERITED
| SEC_DESC_SACL_AUTO_INHERITED
|
318 SEC_DESC_DACL_DEFAULTED
| SEC_DESC_SACL_DEFAULTED
|
319 SEC_DESC_DACL_PRESENT
| SEC_DESC_SACL_PRESENT
;
320 control
|= SEC_DESC_SELF_RELATIVE
;
324 static void gpfs_dumpacl(int level
, struct gpfs_acl
*gacl
)
329 DEBUG(0, ("gpfs acl is NULL\n"));
333 DEBUG(level
, ("len: %d, level: %d, version: %d, nace: %d, "
335 gacl
->acl_len
, gacl
->acl_level
, gacl
->acl_version
,
336 gacl
->acl_nace
, gpfs_acl_flags(gacl
)));
338 for(i
=0; i
<gacl
->acl_nace
; i
++)
340 struct gpfs_ace_v4
*gace
= gpfs_ace_ptr(gacl
, i
);
341 DEBUG(level
, ("\tace[%d]: type:%d, flags:0x%x, mask:0x%x, "
342 "iflags:0x%x, who:%u\n",
343 i
, gace
->aceType
, gace
->aceFlags
, gace
->aceMask
,
344 gace
->aceIFlags
, gace
->aceWho
));
349 * get the ACL from GPFS, allocated on the specified mem_ctx
350 * internally retries when initial buffer was too small
352 * caller needs to cast result to either
353 * raw = yes: struct gpfs_opaque_acl
354 * raw = no: struct gpfs_acl
357 static void *vfs_gpfs_getacl(TALLOC_CTX
*mem_ctx
,
360 const gpfs_aclType_t type
)
371 aclbuf
= talloc_zero_size(mem_ctx
, size
);
372 if (aclbuf
== NULL
) {
378 struct gpfs_opaque_acl
*buf
= (struct gpfs_opaque_acl
*) aclbuf
;
379 buf
->acl_type
= type
;
380 flags
= GPFS_GETACL_NATIVE
;
381 len
= (unsigned int *) &(buf
->acl_buffer_len
);
382 struct_size
= sizeof(struct gpfs_opaque_acl
);
384 struct gpfs_acl
*buf
= (struct gpfs_acl
*) aclbuf
;
385 buf
->acl_type
= type
;
386 buf
->acl_level
= 1; /* GPFS_ACL_LEVEL_V4FLAGS */
387 flags
= GPFS_GETACL_STRUCT
;
388 len
= &(buf
->acl_len
);
389 /* reserve space for control flags in gpfs 3.5 and beyond */
390 struct_size
= sizeof(struct gpfs_acl
) + sizeof(unsigned int);
393 /* set the length of the buffer as input value */
397 ret
= gpfswrap_getacl(discard_const_p(char, fname
), flags
, aclbuf
);
398 if ((ret
!= 0) && (errno
== ENOSPC
)) {
400 * get the size needed to accommodate the complete buffer
402 * the value returned only applies to the ACL blob in the
403 * struct so make sure to also have headroom for the first
404 * struct members by adding room for the complete struct
405 * (might be a few bytes too much then)
407 size
= *len
+ struct_size
;
409 DEBUG(10, ("Increasing ACL buffer size to %zu\n", size
));
414 DEBUG(5, ("smbd_gpfs_getacl failed with %s\n",
423 /* Tries to get nfs4 acls and returns SMB ACL allocated.
424 * On failure returns 1 if it got non-NFSv4 ACL to prompt
425 * retry with POSIX ACL checks.
426 * On failure returns -1 if there is system (GPFS) error, check errno.
427 * Returns 0 on success
429 static int gpfs_get_nfs4_acl(TALLOC_CTX
*mem_ctx
, const char *fname
, SMB4ACL_T
**ppacl
)
432 struct gpfs_acl
*gacl
= NULL
;
433 DEBUG(10, ("gpfs_get_nfs4_acl invoked for %s\n", fname
));
436 gacl
= (struct gpfs_acl
*) vfs_gpfs_getacl(talloc_tos(), fname
,
439 DEBUG(9, ("gpfs_getacl failed for %s with %s\n",
440 fname
, strerror(errno
)));
444 if (gacl
->acl_type
!= GPFS_ACL_TYPE_NFS4
) {
445 DEBUG(10, ("Got non-nfsv4 acl\n"));
446 /* Retry with POSIX ACLs check */
451 *ppacl
= smb_create_smb4acl(mem_ctx
);
453 if (gacl
->acl_level
== 1) { /* GPFS_ACL_LEVEL_V4FLAGS */
454 uint16_t control
= gpfs2sd_control(gpfs_acl_flags(gacl
));
455 smbacl4_set_controlflags(*ppacl
, control
);
458 DEBUG(10, ("len: %d, level: %d, version: %d, nace: %d, control: %x\n",
459 gacl
->acl_len
, gacl
->acl_level
, gacl
->acl_version
,
460 gacl
->acl_nace
, gpfs_acl_flags(gacl
)));
462 for (i
=0; i
<gacl
->acl_nace
; i
++) {
463 struct gpfs_ace_v4
*gace
= gpfs_ace_ptr(gacl
, i
);
464 SMB_ACE4PROP_T smbace
;
465 DEBUG(10, ("type: %d, iflags: %x, flags: %x, mask: %x, "
466 "who: %d\n", gace
->aceType
, gace
->aceIFlags
,
467 gace
->aceFlags
, gace
->aceMask
, gace
->aceWho
));
470 if (gace
->aceIFlags
& ACE4_IFLAG_SPECIAL_ID
) {
471 smbace
.flags
|= SMB_ACE4_ID_SPECIAL
;
472 switch (gace
->aceWho
) {
473 case ACE4_SPECIAL_OWNER
:
474 smbace
.who
.special_id
= SMB_ACE4_WHO_OWNER
;
476 case ACE4_SPECIAL_GROUP
:
477 smbace
.who
.special_id
= SMB_ACE4_WHO_GROUP
;
479 case ACE4_SPECIAL_EVERYONE
:
480 smbace
.who
.special_id
= SMB_ACE4_WHO_EVERYONE
;
483 DEBUG(8, ("invalid special gpfs id %d "
484 "ignored\n", gace
->aceWho
));
485 continue; /* don't add it */
488 if (gace
->aceFlags
& ACE4_FLAG_GROUP_ID
)
489 smbace
.who
.gid
= gace
->aceWho
;
491 smbace
.who
.uid
= gace
->aceWho
;
494 /* remove redundant deny entries */
495 if (i
> 0 && gace
->aceType
== SMB_ACE4_ACCESS_DENIED_ACE_TYPE
) {
496 struct gpfs_ace_v4
*prev
= gpfs_ace_ptr(gacl
, i
- 1);
497 if (prev
->aceType
== SMB_ACE4_ACCESS_ALLOWED_ACE_TYPE
&&
498 prev
->aceFlags
== gace
->aceFlags
&&
499 prev
->aceIFlags
== gace
->aceIFlags
&&
500 (gace
->aceMask
& prev
->aceMask
) == 0 &&
501 gace
->aceWho
== prev
->aceWho
) {
502 /* it's redundant - skip it */
507 smbace
.aceType
= gace
->aceType
;
508 smbace
.aceFlags
= gace
->aceFlags
;
509 smbace
.aceMask
= gace
->aceMask
;
510 smb_add_ace4(*ppacl
, &smbace
);
518 static NTSTATUS
gpfsacl_fget_nt_acl(vfs_handle_struct
*handle
,
519 files_struct
*fsp
, uint32 security_info
,
521 struct security_descriptor
**ppdesc
)
523 SMB4ACL_T
*pacl
= NULL
;
525 struct gpfs_config_data
*config
;
526 TALLOC_CTX
*frame
= talloc_stackframe();
531 SMB_VFS_HANDLE_GET_DATA(handle
, config
,
532 struct gpfs_config_data
,
533 return NT_STATUS_INTERNAL_ERROR
);
536 status
= SMB_VFS_NEXT_FGET_NT_ACL(handle
, fsp
, security_info
,
542 result
= gpfs_get_nfs4_acl(frame
, fsp
->fsp_name
->base_name
, &pacl
);
545 status
= smb_fget_nt_acl_nfs4(fsp
, security_info
, mem_ctx
,
552 DEBUG(10, ("retrying with posix acl...\n"));
553 status
= posix_fget_nt_acl(fsp
, security_info
,
561 /* GPFS ACL was not read, something wrong happened, error code is set in errno */
562 return map_nt_error_from_unix(errno
);
565 static NTSTATUS
gpfsacl_get_nt_acl(vfs_handle_struct
*handle
,
567 uint32 security_info
,
568 TALLOC_CTX
*mem_ctx
, struct security_descriptor
**ppdesc
)
570 SMB4ACL_T
*pacl
= NULL
;
572 struct gpfs_config_data
*config
;
573 TALLOC_CTX
*frame
= talloc_stackframe();
578 SMB_VFS_HANDLE_GET_DATA(handle
, config
,
579 struct gpfs_config_data
,
580 return NT_STATUS_INTERNAL_ERROR
);
583 status
= SMB_VFS_NEXT_GET_NT_ACL(handle
, name
, security_info
,
589 result
= gpfs_get_nfs4_acl(frame
, name
, &pacl
);
592 status
= smb_get_nt_acl_nfs4(handle
->conn
, name
, security_info
,
593 mem_ctx
, ppdesc
, pacl
);
599 DEBUG(10, ("retrying with posix acl...\n"));
600 status
= posix_get_nt_acl(handle
->conn
, name
, security_info
,
606 /* GPFS ACL was not read, something wrong happened, error code is set in errno */
608 return map_nt_error_from_unix(errno
);
611 static struct gpfs_acl
*vfs_gpfs_smbacl2gpfsacl(TALLOC_CTX
*mem_ctx
,
616 struct gpfs_acl
*gacl
;
617 gpfs_aclLen_t gacl_len
;
620 gacl_len
= offsetof(gpfs_acl_t
, ace_v4
) + sizeof(unsigned int)
621 + smb_get_naces(smbacl
) * sizeof(gpfs_ace_v4_t
);
623 gacl
= (struct gpfs_acl
*)TALLOC_SIZE(mem_ctx
, gacl_len
);
625 DEBUG(0, ("talloc failed\n"));
630 gacl
->acl_level
= 0; /* GPFS_ACL_LEVEL_BASE */
631 gacl
->acl_version
= GPFS_ACL_VERSION_NFS4
;
632 gacl
->acl_type
= GPFS_ACL_TYPE_NFS4
;
633 gacl
->acl_nace
= 0; /* change later... */
636 gacl
->acl_level
= 1; /* GPFS_ACL_LEVEL_V4FLAGS */
637 sd2gpfs_control(smbacl4_get_controlflags(smbacl
), gacl
);
640 for (smbace
=smb_first_ace4(smbacl
); smbace
!=NULL
; smbace
= smb_next_ace4(smbace
)) {
641 struct gpfs_ace_v4
*gace
= gpfs_ace_ptr(gacl
, gacl
->acl_nace
);
642 SMB_ACE4PROP_T
*aceprop
= smb_get_ace4(smbace
);
644 gace
->aceType
= aceprop
->aceType
;
645 gace
->aceFlags
= aceprop
->aceFlags
;
646 gace
->aceMask
= aceprop
->aceMask
;
649 * GPFS can't distinguish between WRITE and APPEND on
650 * files, so one being set without the other is an
651 * error. Sorry for the many ()'s :-)
654 if (!fsp
->is_directory
656 ((((gace
->aceMask
& ACE4_MASK_WRITE
) == 0)
657 && ((gace
->aceMask
& ACE4_MASK_APPEND
) != 0))
659 (((gace
->aceMask
& ACE4_MASK_WRITE
) != 0)
660 && ((gace
->aceMask
& ACE4_MASK_APPEND
) == 0)))
662 lp_parm_bool(fsp
->conn
->params
->service
, "gpfs",
663 "merge_writeappend", True
)) {
664 DEBUG(2, ("vfs_gpfs.c: file [%s]: ACE contains "
665 "WRITE^APPEND, setting WRITE|APPEND\n",
667 gace
->aceMask
|= ACE4_MASK_WRITE
|ACE4_MASK_APPEND
;
670 gace
->aceIFlags
= (aceprop
->flags
&SMB_ACE4_ID_SPECIAL
) ? ACE4_IFLAG_SPECIAL_ID
: 0;
672 if (aceprop
->flags
&SMB_ACE4_ID_SPECIAL
)
674 switch(aceprop
->who
.special_id
)
676 case SMB_ACE4_WHO_EVERYONE
:
677 gace
->aceWho
= ACE4_SPECIAL_EVERYONE
;
679 case SMB_ACE4_WHO_OWNER
:
680 gace
->aceWho
= ACE4_SPECIAL_OWNER
;
682 case SMB_ACE4_WHO_GROUP
:
683 gace
->aceWho
= ACE4_SPECIAL_GROUP
;
686 DEBUG(8, ("unsupported special_id %d\n", aceprop
->who
.special_id
));
687 continue; /* don't add it !!! */
690 /* just only for the type safety... */
691 if (aceprop
->aceFlags
&SMB_ACE4_IDENTIFIER_GROUP
)
692 gace
->aceWho
= aceprop
->who
.gid
;
694 gace
->aceWho
= aceprop
->who
.uid
;
699 gacl
->acl_len
= (char *)gpfs_ace_ptr(gacl
, gacl
->acl_nace
)
704 static bool gpfsacl_process_smbacl(vfs_handle_struct
*handle
,
709 struct gpfs_acl
*gacl
;
710 TALLOC_CTX
*mem_ctx
= talloc_tos();
712 gacl
= vfs_gpfs_smbacl2gpfsacl(mem_ctx
, fsp
, smbacl
, true);
713 if (gacl
== NULL
) { /* out of memory */
716 ret
= gpfswrap_putacl(fsp
->fsp_name
->base_name
,
717 GPFS_PUTACL_STRUCT
| GPFS_ACL_SAMBA
, gacl
);
719 if ((ret
!= 0) && (errno
== EINVAL
)) {
720 DEBUG(10, ("Retry without nfs41 control flags\n"));
722 gacl
= vfs_gpfs_smbacl2gpfsacl(mem_ctx
, fsp
, smbacl
, false);
723 if (gacl
== NULL
) { /* out of memory */
726 ret
= gpfswrap_putacl(fsp
->fsp_name
->base_name
,
727 GPFS_PUTACL_STRUCT
| GPFS_ACL_SAMBA
,
732 DEBUG(8, ("gpfs_putacl failed with %s\n", strerror(errno
)));
733 gpfs_dumpacl(8, gacl
);
737 DEBUG(10, ("gpfs_putacl succeeded\n"));
741 static NTSTATUS
gpfsacl_set_nt_acl_internal(vfs_handle_struct
*handle
, files_struct
*fsp
, uint32 security_info_sent
, const struct security_descriptor
*psd
)
743 struct gpfs_acl
*acl
;
744 NTSTATUS result
= NT_STATUS_ACCESS_DENIED
;
746 acl
= (struct gpfs_acl
*) vfs_gpfs_getacl(talloc_tos(),
747 fsp
->fsp_name
->base_name
,
750 return map_nt_error_from_unix(errno
);
753 if (acl
->acl_version
== GPFS_ACL_VERSION_NFS4
) {
754 if (lp_parm_bool(fsp
->conn
->params
->service
, "gpfs",
755 "refuse_dacl_protected", false)
756 && (psd
->type
&SEC_DESC_DACL_PROTECTED
)) {
757 DEBUG(2, ("Rejecting unsupported ACL with DACL_PROTECTED bit set\n"));
759 return NT_STATUS_NOT_SUPPORTED
;
762 result
= smb_set_nt_acl_nfs4(handle
,
763 fsp
, security_info_sent
, psd
,
764 gpfsacl_process_smbacl
);
765 } else { /* assume POSIX ACL - by default... */
766 result
= set_nt_acl(fsp
, security_info_sent
, psd
);
773 static NTSTATUS
gpfsacl_fset_nt_acl(vfs_handle_struct
*handle
, files_struct
*fsp
, uint32 security_info_sent
, const struct security_descriptor
*psd
)
775 struct gpfs_config_data
*config
;
777 SMB_VFS_HANDLE_GET_DATA(handle
, config
,
778 struct gpfs_config_data
,
779 return NT_STATUS_INTERNAL_ERROR
);
782 return SMB_VFS_NEXT_FSET_NT_ACL(handle
, fsp
, security_info_sent
, psd
);
785 return gpfsacl_set_nt_acl_internal(handle
, fsp
, security_info_sent
, psd
);
788 static SMB_ACL_T
gpfs2smb_acl(const struct gpfs_acl
*pacl
, TALLOC_CTX
*mem_ctx
)
793 result
= sys_acl_init(mem_ctx
);
794 if (result
== NULL
) {
799 result
->count
= pacl
->acl_nace
;
800 result
->acl
= talloc_realloc(result
, result
->acl
, struct smb_acl_entry
,
802 if (result
->acl
== NULL
) {
808 for (i
=0; i
<pacl
->acl_nace
; i
++) {
809 struct smb_acl_entry
*ace
= &result
->acl
[i
];
810 const struct gpfs_ace_v1
*g_ace
= &pacl
->ace_v1
[i
];
812 DEBUG(10, ("Converting type %d id %lu perm %x\n",
813 (int)g_ace
->ace_type
, (unsigned long)g_ace
->ace_who
,
814 (int)g_ace
->ace_perm
));
816 switch (g_ace
->ace_type
) {
818 ace
->a_type
= SMB_ACL_USER
;
819 ace
->info
.user
.uid
= (uid_t
)g_ace
->ace_who
;
821 case GPFS_ACL_USER_OBJ
:
822 ace
->a_type
= SMB_ACL_USER_OBJ
;
825 ace
->a_type
= SMB_ACL_GROUP
;
826 ace
->info
.group
.gid
= (gid_t
)g_ace
->ace_who
;
828 case GPFS_ACL_GROUP_OBJ
:
829 ace
->a_type
= SMB_ACL_GROUP_OBJ
;
832 ace
->a_type
= SMB_ACL_OTHER
;
835 ace
->a_type
= SMB_ACL_MASK
;
838 DEBUG(10, ("Got invalid ace_type: %d\n",
846 ace
->a_perm
|= (g_ace
->ace_perm
& ACL_PERM_READ
) ?
848 ace
->a_perm
|= (g_ace
->ace_perm
& ACL_PERM_WRITE
) ?
850 ace
->a_perm
|= (g_ace
->ace_perm
& ACL_PERM_EXECUTE
) ?
853 DEBUGADD(10, ("Converted to %d perm %x\n",
854 ace
->a_type
, ace
->a_perm
));
860 static SMB_ACL_T
gpfsacl_get_posix_acl(const char *path
, gpfs_aclType_t type
,
863 struct gpfs_acl
*pacl
;
864 SMB_ACL_T result
= NULL
;
866 pacl
= vfs_gpfs_getacl(talloc_tos(), path
, false, type
);
869 DEBUG(10, ("vfs_gpfs_getacl failed for %s with %s\n",
870 path
, strerror(errno
)));
877 if (pacl
->acl_version
!= GPFS_ACL_VERSION_POSIX
) {
878 DEBUG(10, ("Got acl version %d, expected %d\n",
879 pacl
->acl_version
, GPFS_ACL_VERSION_POSIX
));
884 DEBUG(10, ("len: %d, level: %d, version: %d, nace: %d\n",
885 pacl
->acl_len
, pacl
->acl_level
, pacl
->acl_version
,
888 result
= gpfs2smb_acl(pacl
, mem_ctx
);
889 if (result
!= NULL
) {
904 static SMB_ACL_T
gpfsacl_sys_acl_get_file(vfs_handle_struct
*handle
,
909 gpfs_aclType_t gpfs_type
;
910 struct gpfs_config_data
*config
;
912 SMB_VFS_HANDLE_GET_DATA(handle
, config
,
913 struct gpfs_config_data
,
917 return SMB_VFS_NEXT_SYS_ACL_GET_FILE(handle
, path_p
,
922 case SMB_ACL_TYPE_ACCESS
:
923 gpfs_type
= GPFS_ACL_TYPE_ACCESS
;
925 case SMB_ACL_TYPE_DEFAULT
:
926 gpfs_type
= GPFS_ACL_TYPE_DEFAULT
;
929 DEBUG(0, ("Got invalid type: %d\n", type
));
930 smb_panic("exiting");
933 return gpfsacl_get_posix_acl(path_p
, gpfs_type
, mem_ctx
);
936 static SMB_ACL_T
gpfsacl_sys_acl_get_fd(vfs_handle_struct
*handle
,
940 struct gpfs_config_data
*config
;
942 SMB_VFS_HANDLE_GET_DATA(handle
, config
,
943 struct gpfs_config_data
,
947 return SMB_VFS_NEXT_SYS_ACL_GET_FD(handle
, fsp
, mem_ctx
);
950 return gpfsacl_get_posix_acl(fsp
->fsp_name
->base_name
,
951 GPFS_ACL_TYPE_ACCESS
, mem_ctx
);
954 static int gpfsacl_sys_acl_blob_get_file(vfs_handle_struct
*handle
,
957 char **blob_description
,
960 struct gpfs_config_data
*config
;
961 struct gpfs_opaque_acl
*acl
= NULL
;
965 SMB_VFS_HANDLE_GET_DATA(handle
, config
,
966 struct gpfs_config_data
,
970 return SMB_VFS_NEXT_SYS_ACL_BLOB_GET_FILE(handle
, path_p
,
977 acl
= (struct gpfs_opaque_acl
*)
978 vfs_gpfs_getacl(mem_ctx
,
984 DEBUG(5, ("vfs_gpfs_getacl finished with errno %d: %s\n",
985 errno
, strerror(errno
)));
987 /* EINVAL means POSIX ACL, bail out on other cases */
988 if (errno
!= EINVAL
) {
997 * we only need the actual ACL blob here
998 * acl_version will always be NFS4 because we asked
1000 * acl_type is only used for POSIX ACLs
1002 aclblob
.data
= (uint8_t*) acl
->acl_var_data
;
1003 aclblob
.length
= acl
->acl_buffer_len
;
1005 *blob_description
= talloc_strdup(mem_ctx
, "gpfs_nfs4_acl");
1006 if (!*blob_description
) {
1012 result
= non_posix_sys_acl_blob_get_file_helper(handle
, path_p
,
1020 /* fall back to POSIX ACL */
1021 return posix_sys_acl_blob_get_file(handle
, path_p
, mem_ctx
,
1022 blob_description
, blob
);
1025 static int gpfsacl_sys_acl_blob_get_fd(vfs_handle_struct
*handle
,
1027 TALLOC_CTX
*mem_ctx
,
1028 char **blob_description
,
1031 struct gpfs_config_data
*config
;
1032 struct gpfs_opaque_acl
*acl
= NULL
;
1036 SMB_VFS_HANDLE_GET_DATA(handle
, config
,
1037 struct gpfs_config_data
,
1041 return SMB_VFS_NEXT_SYS_ACL_BLOB_GET_FD(handle
, fsp
, mem_ctx
,
1042 blob_description
, blob
);
1046 acl
= (struct gpfs_opaque_acl
*) vfs_gpfs_getacl(mem_ctx
,
1047 fsp
->fsp_name
->base_name
,
1049 GPFS_ACL_TYPE_NFS4
);
1052 DEBUG(5, ("vfs_gpfs_getacl finished with errno %d: %s\n",
1053 errno
, strerror(errno
)));
1055 /* EINVAL means POSIX ACL, bail out on other cases */
1056 if (errno
!= EINVAL
) {
1063 * file has NFSv4 ACL
1065 * we only need the actual ACL blob here
1066 * acl_version will always be NFS4 because we asked
1068 * acl_type is only used for POSIX ACLs
1070 aclblob
.data
= (uint8_t*) acl
->acl_var_data
;
1071 aclblob
.length
= acl
->acl_buffer_len
;
1073 *blob_description
= talloc_strdup(mem_ctx
, "gpfs_nfs4_acl");
1074 if (!*blob_description
) {
1080 result
= non_posix_sys_acl_blob_get_fd_helper(handle
, fsp
,
1088 /* fall back to POSIX ACL */
1089 return posix_sys_acl_blob_get_fd(handle
, fsp
, mem_ctx
,
1090 blob_description
, blob
);
1093 static struct gpfs_acl
*smb2gpfs_acl(const SMB_ACL_T pacl
,
1094 SMB_ACL_TYPE_T type
)
1097 struct gpfs_acl
*result
;
1100 DEBUG(10, ("smb2gpfs_acl: Got ACL with %d entries\n", pacl
->count
));
1102 len
= offsetof(gpfs_acl_t
, ace_v1
) + (pacl
->count
) *
1103 sizeof(gpfs_ace_v1_t
);
1105 result
= (struct gpfs_acl
*)SMB_MALLOC(len
);
1106 if (result
== NULL
) {
1111 result
->acl_len
= len
;
1112 result
->acl_level
= 0;
1113 result
->acl_version
= GPFS_ACL_VERSION_POSIX
;
1114 result
->acl_type
= (type
== SMB_ACL_TYPE_DEFAULT
) ?
1115 GPFS_ACL_TYPE_DEFAULT
: GPFS_ACL_TYPE_ACCESS
;
1116 result
->acl_nace
= pacl
->count
;
1118 for (i
=0; i
<pacl
->count
; i
++) {
1119 const struct smb_acl_entry
*ace
= &pacl
->acl
[i
];
1120 struct gpfs_ace_v1
*g_ace
= &result
->ace_v1
[i
];
1122 DEBUG(10, ("Converting type %d perm %x\n",
1123 (int)ace
->a_type
, (int)ace
->a_perm
));
1125 g_ace
->ace_perm
= 0;
1127 switch(ace
->a_type
) {
1129 g_ace
->ace_type
= GPFS_ACL_USER
;
1130 g_ace
->ace_who
= (gpfs_uid_t
)ace
->info
.user
.uid
;
1132 case SMB_ACL_USER_OBJ
:
1133 g_ace
->ace_type
= GPFS_ACL_USER_OBJ
;
1134 g_ace
->ace_perm
|= ACL_PERM_CONTROL
;
1138 g_ace
->ace_type
= GPFS_ACL_GROUP
;
1139 g_ace
->ace_who
= (gpfs_uid_t
)ace
->info
.group
.gid
;
1141 case SMB_ACL_GROUP_OBJ
:
1142 g_ace
->ace_type
= GPFS_ACL_GROUP_OBJ
;
1146 g_ace
->ace_type
= GPFS_ACL_MASK
;
1147 g_ace
->ace_perm
= 0x8f;
1151 g_ace
->ace_type
= GPFS_ACL_OTHER
;
1155 DEBUG(10, ("Got invalid ace_type: %d\n", ace
->a_type
));
1161 g_ace
->ace_perm
|= (ace
->a_perm
& SMB_ACL_READ
) ?
1163 g_ace
->ace_perm
|= (ace
->a_perm
& SMB_ACL_WRITE
) ?
1165 g_ace
->ace_perm
|= (ace
->a_perm
& SMB_ACL_EXECUTE
) ?
1166 ACL_PERM_EXECUTE
: 0;
1168 DEBUGADD(10, ("Converted to %d id %d perm %x\n",
1169 g_ace
->ace_type
, g_ace
->ace_who
, g_ace
->ace_perm
));
1175 static int gpfsacl_sys_acl_set_file(vfs_handle_struct
*handle
,
1177 SMB_ACL_TYPE_T type
,
1180 struct gpfs_acl
*gpfs_acl
;
1182 struct gpfs_config_data
*config
;
1184 SMB_VFS_HANDLE_GET_DATA(handle
, config
,
1185 struct gpfs_config_data
,
1189 return SMB_VFS_NEXT_SYS_ACL_SET_FILE(handle
, name
, type
, theacl
);
1192 gpfs_acl
= smb2gpfs_acl(theacl
, type
);
1193 if (gpfs_acl
== NULL
) {
1197 result
= gpfswrap_putacl(discard_const_p(char, name
),
1198 GPFS_PUTACL_STRUCT
|GPFS_ACL_SAMBA
, gpfs_acl
);
1200 SAFE_FREE(gpfs_acl
);
1204 static int gpfsacl_sys_acl_set_fd(vfs_handle_struct
*handle
,
1208 struct gpfs_config_data
*config
;
1210 SMB_VFS_HANDLE_GET_DATA(handle
, config
,
1211 struct gpfs_config_data
,
1215 return SMB_VFS_NEXT_SYS_ACL_SET_FD(handle
, fsp
, theacl
);
1218 return gpfsacl_sys_acl_set_file(handle
, fsp
->fsp_name
->base_name
,
1219 SMB_ACL_TYPE_ACCESS
, theacl
);
1222 static int gpfsacl_sys_acl_delete_def_file(vfs_handle_struct
*handle
,
1225 struct gpfs_config_data
*config
;
1227 SMB_VFS_HANDLE_GET_DATA(handle
, config
,
1228 struct gpfs_config_data
,
1232 return SMB_VFS_NEXT_SYS_ACL_DELETE_DEF_FILE(handle
, path
);
1240 * Assumed: mode bits are shiftable and standard
1241 * Output: the new aceMask field for an smb nfs4 ace
1243 static uint32
gpfsacl_mask_filter(uint32 aceType
, uint32 aceMask
, uint32 rwx
)
1245 const uint32 posix_nfs4map
[3] = {
1246 SMB_ACE4_EXECUTE
, /* execute */
1247 SMB_ACE4_WRITE_DATA
| SMB_ACE4_APPEND_DATA
, /* write; GPFS specific */
1248 SMB_ACE4_READ_DATA
/* read */
1251 uint32_t posix_mask
= 0x01;
1255 for(i
=0; i
<3; i
++) {
1256 nfs4_bits
= posix_nfs4map
[i
];
1257 posix_bit
= rwx
& posix_mask
;
1259 if (aceType
==SMB_ACE4_ACCESS_ALLOWED_ACE_TYPE
) {
1261 aceMask
|= nfs4_bits
;
1263 aceMask
&= ~nfs4_bits
;
1265 /* add deny bits when suitable */
1267 aceMask
|= nfs4_bits
;
1269 aceMask
&= ~nfs4_bits
;
1270 } /* other ace types are unexpected */
1278 static int gpfsacl_emu_chmod(vfs_handle_struct
*handle
,
1279 const char *path
, mode_t mode
)
1281 SMB4ACL_T
*pacl
= NULL
;
1283 bool haveAllowEntry
[SMB_ACE4_WHO_EVERYONE
+ 1] = {False
, False
, False
, False
};
1285 files_struct fake_fsp
; /* TODO: rationalize parametrization */
1287 TALLOC_CTX
*frame
= talloc_stackframe();
1289 DEBUG(10, ("gpfsacl_emu_chmod invoked for %s mode %o\n", path
, mode
));
1291 result
= gpfs_get_nfs4_acl(frame
, path
, &pacl
);
1297 if (mode
& ~(S_IRWXU
| S_IRWXG
| S_IRWXO
)) {
1298 DEBUG(2, ("WARNING: cutting extra mode bits %o on %s\n", mode
, path
));
1301 for (smbace
=smb_first_ace4(pacl
); smbace
!=NULL
; smbace
= smb_next_ace4(smbace
)) {
1302 SMB_ACE4PROP_T
*ace
= smb_get_ace4(smbace
);
1303 uint32_t specid
= ace
->who
.special_id
;
1305 if (ace
->flags
&SMB_ACE4_ID_SPECIAL
&&
1306 ace
->aceType
<=SMB_ACE4_ACCESS_DENIED_ACE_TYPE
&&
1307 specid
<= SMB_ACE4_WHO_EVERYONE
) {
1311 if (ace
->aceType
==SMB_ACE4_ACCESS_ALLOWED_ACE_TYPE
)
1312 haveAllowEntry
[specid
] = True
;
1314 /* mode >> 6 for @owner, mode >> 3 for @group,
1315 * mode >> 0 for @everyone */
1316 newMask
= gpfsacl_mask_filter(ace
->aceType
, ace
->aceMask
,
1317 mode
>> ((SMB_ACE4_WHO_EVERYONE
- specid
) * 3));
1318 if (ace
->aceMask
!=newMask
) {
1319 DEBUG(10, ("ace changed for %s (%o -> %o) id=%d\n",
1320 path
, ace
->aceMask
, newMask
, specid
));
1322 ace
->aceMask
= newMask
;
1326 /* make sure we have at least ALLOW entries
1327 * for all the 3 special ids (@EVERYONE, @OWNER, @GROUP)
1330 for(i
= SMB_ACE4_WHO_OWNER
; i
<=SMB_ACE4_WHO_EVERYONE
; i
++) {
1333 if (haveAllowEntry
[i
]==True
)
1337 ace
.aceType
= SMB_ACE4_ACCESS_ALLOWED_ACE_TYPE
;
1338 ace
.flags
|= SMB_ACE4_ID_SPECIAL
;
1339 ace
.who
.special_id
= i
;
1341 if (i
==SMB_ACE4_WHO_GROUP
) /* not sure it's necessary... */
1342 ace
.aceFlags
|= SMB_ACE4_IDENTIFIER_GROUP
;
1344 ace
.aceMask
= gpfsacl_mask_filter(ace
.aceType
, ace
.aceMask
,
1345 mode
>> ((SMB_ACE4_WHO_EVERYONE
- i
) * 3));
1347 /* don't add unnecessary aces */
1351 /* we add it to the END - as windows expects allow aces */
1352 smb_add_ace4(pacl
, &ace
);
1353 DEBUG(10, ("Added ALLOW ace for %s, mode=%o, id=%d, aceMask=%x\n",
1354 path
, mode
, i
, ace
.aceMask
));
1357 /* don't add complementary DENY ACEs here */
1358 ZERO_STRUCT(fake_fsp
);
1359 fake_fsp
.fsp_name
= synthetic_smb_fname(
1360 frame
, path
, NULL
, NULL
);
1361 if (fake_fsp
.fsp_name
== NULL
) {
1367 if (gpfsacl_process_smbacl(handle
, &fake_fsp
, pacl
) == False
) {
1373 return 0; /* ok for [f]chmod */
1376 static int vfs_gpfs_chmod(vfs_handle_struct
*handle
, const char *path
, mode_t mode
)
1378 struct smb_filename
*smb_fname_cpath
;
1381 smb_fname_cpath
= synthetic_smb_fname(talloc_tos(), path
, NULL
, NULL
);
1382 if (smb_fname_cpath
== NULL
) {
1387 if (SMB_VFS_NEXT_STAT(handle
, smb_fname_cpath
) != 0) {
1391 /* avoid chmod() if possible, to preserve acls */
1392 if ((smb_fname_cpath
->st
.st_ex_mode
& ~S_IFMT
) == mode
) {
1396 rc
= gpfsacl_emu_chmod(handle
, path
, mode
);
1398 return SMB_VFS_NEXT_CHMOD(handle
, path
, mode
);
1402 static int vfs_gpfs_fchmod(vfs_handle_struct
*handle
, files_struct
*fsp
, mode_t mode
)
1407 if (SMB_VFS_NEXT_FSTAT(handle
, fsp
, &st
) != 0) {
1411 /* avoid chmod() if possible, to preserve acls */
1412 if ((st
.st_ex_mode
& ~S_IFMT
) == mode
) {
1416 rc
= gpfsacl_emu_chmod(handle
, fsp
->fsp_name
->base_name
,
1419 return SMB_VFS_NEXT_FCHMOD(handle
, fsp
, mode
);
1423 static int gpfs_set_xattr(struct vfs_handle_struct
*handle
, const char *path
,
1424 const char *name
, const void *value
, size_t size
, int flags
){
1425 struct xattr_DOSATTRIB dosattrib
;
1426 enum ndr_err_code ndr_err
;
1428 unsigned int dosmode
=0;
1429 struct gpfs_winattr attrs
;
1431 struct gpfs_config_data
*config
;
1433 SMB_VFS_HANDLE_GET_DATA(handle
, config
,
1434 struct gpfs_config_data
,
1437 if (!config
->winattr
) {
1438 DEBUG(10, ("gpfs_set_xattr:name is %s -> next\n",name
));
1439 return SMB_VFS_NEXT_SETXATTR(handle
,path
,name
,value
,size
,flags
);
1442 DEBUG(10, ("gpfs_set_xattr: %s \n",path
));
1444 /* Only handle DOS Attributes */
1445 if (strcmp(name
,SAMBA_XATTR_DOS_ATTRIB
) != 0){
1446 DEBUG(5, ("gpfs_set_xattr:name is %s\n",name
));
1447 return SMB_VFS_NEXT_SETXATTR(handle
,path
,name
,value
,size
,flags
);
1450 blob
.data
= discard_const_p(uint8_t, value
);
1453 ndr_err
= ndr_pull_struct_blob(&blob
, talloc_tos(), &dosattrib
,
1454 (ndr_pull_flags_fn_t
)ndr_pull_xattr_DOSATTRIB
);
1456 if (!NDR_ERR_CODE_IS_SUCCESS(ndr_err
)) {
1457 DEBUG(1, ("gpfs_set_xattr: bad ndr decode "
1458 "from EA on file %s: Error = %s\n",
1459 path
, ndr_errstr(ndr_err
)));
1463 if (dosattrib
.version
!= 3) {
1464 DEBUG(1, ("gpfs_set_xattr: expected dosattrib version 3, got "
1465 "%d\n", (int)dosattrib
.version
));
1468 if (!(dosattrib
.info
.info3
.valid_flags
& XATTR_DOSINFO_ATTRIB
)) {
1469 DEBUG(10, ("gpfs_set_xattr: XATTR_DOSINFO_ATTRIB not "
1470 "valid, ignoring\n"));
1474 dosmode
= dosattrib
.info
.info3
.attrib
;
1477 /*Just map RD_ONLY, ARCHIVE, SYSTEM HIDDEN and SPARSE. Ignore the others*/
1478 if (dosmode
& FILE_ATTRIBUTE_ARCHIVE
){
1479 attrs
.winAttrs
|= GPFS_WINATTR_ARCHIVE
;
1481 if (dosmode
& FILE_ATTRIBUTE_HIDDEN
){
1482 attrs
.winAttrs
|= GPFS_WINATTR_HIDDEN
;
1484 if (dosmode
& FILE_ATTRIBUTE_SYSTEM
){
1485 attrs
.winAttrs
|= GPFS_WINATTR_SYSTEM
;
1487 if (dosmode
& FILE_ATTRIBUTE_READONLY
){
1488 attrs
.winAttrs
|= GPFS_WINATTR_READONLY
;
1490 if (dosmode
& FILE_ATTRIBUTE_SPARSE
) {
1491 attrs
.winAttrs
|= GPFS_WINATTR_SPARSE_FILE
;
1495 ret
= gpfswrap_set_winattrs_path(discard_const_p(char, path
),
1496 GPFS_WINATTR_SET_ATTRS
, &attrs
);
1498 if (errno
== ENOSYS
) {
1499 return SMB_VFS_NEXT_SETXATTR(handle
, path
, name
, value
,
1503 DEBUG(1, ("gpfs_set_xattr:Set GPFS attributes failed %d\n",ret
));
1507 DEBUG(10, ("gpfs_set_xattr:Set attributes: 0x%x\n",attrs
.winAttrs
));
1511 static ssize_t
gpfs_get_xattr(struct vfs_handle_struct
*handle
, const char *path
,
1512 const char *name
, void *value
, size_t size
){
1513 char *attrstr
= value
;
1514 unsigned int dosmode
= 0;
1515 struct gpfs_winattr attrs
;
1517 struct gpfs_config_data
*config
;
1519 SMB_VFS_HANDLE_GET_DATA(handle
, config
,
1520 struct gpfs_config_data
,
1523 if (!config
->winattr
) {
1524 DEBUG(10, ("gpfs_get_xattr:name is %s -> next\n",name
));
1525 return SMB_VFS_NEXT_GETXATTR(handle
,path
,name
,value
,size
);
1528 DEBUG(10, ("gpfs_get_xattr: %s \n",path
));
1530 /* Only handle DOS Attributes */
1531 if (strcmp(name
,SAMBA_XATTR_DOS_ATTRIB
) != 0){
1532 DEBUG(5, ("gpfs_get_xattr:name is %s\n",name
));
1533 return SMB_VFS_NEXT_GETXATTR(handle
,path
,name
,value
,size
);
1536 ret
= gpfswrap_get_winattrs_path(discard_const_p(char, path
), &attrs
);
1540 if (errno
== ENOSYS
) {
1541 return SMB_VFS_NEXT_GETXATTR(handle
, path
, name
, value
,
1545 if (errno
!= EPERM
&& errno
!= EACCES
) {
1550 DEBUG(dbg_lvl
, ("gpfs_get_xattr: Get GPFS attributes failed: "
1551 "%d (%s)\n", ret
, strerror(errno
)));
1555 DEBUG(10, ("gpfs_get_xattr:Got attributes: 0x%x\n",attrs
.winAttrs
));
1557 /*Just map RD_ONLY, ARCHIVE, SYSTEM, HIDDEN and SPARSE. Ignore the others*/
1558 if (attrs
.winAttrs
& GPFS_WINATTR_ARCHIVE
){
1559 dosmode
|= FILE_ATTRIBUTE_ARCHIVE
;
1561 if (attrs
.winAttrs
& GPFS_WINATTR_HIDDEN
){
1562 dosmode
|= FILE_ATTRIBUTE_HIDDEN
;
1564 if (attrs
.winAttrs
& GPFS_WINATTR_SYSTEM
){
1565 dosmode
|= FILE_ATTRIBUTE_SYSTEM
;
1567 if (attrs
.winAttrs
& GPFS_WINATTR_READONLY
){
1568 dosmode
|= FILE_ATTRIBUTE_READONLY
;
1570 if (attrs
.winAttrs
& GPFS_WINATTR_SPARSE_FILE
) {
1571 dosmode
|= FILE_ATTRIBUTE_SPARSE
;
1574 snprintf(attrstr
, size
, "0x%2.2x",
1575 (unsigned int)(dosmode
& SAMBA_ATTRIBUTES_MASK
));
1576 DEBUG(10, ("gpfs_get_xattr: returning %s\n",attrstr
));
1580 #if defined(HAVE_FSTATAT)
1581 static int stat_with_capability(struct vfs_handle_struct
*handle
,
1582 struct smb_filename
*smb_fname
, int flag
)
1587 const char *rel_name
= NULL
;
1591 b
= parent_dirname(talloc_tos(), smb_fname
->base_name
,
1592 &dir_name
, &rel_name
);
1598 fd
= open(dir_name
, O_RDONLY
, 0);
1599 TALLOC_FREE(dir_name
);
1604 set_effective_capability(DAC_OVERRIDE_CAPABILITY
);
1605 ret
= fstatat(fd
, rel_name
, &st
, flag
);
1606 drop_effective_capability(DAC_OVERRIDE_CAPABILITY
);
1611 init_stat_ex_from_stat(
1612 &smb_fname
->st
, &st
,
1613 lp_fake_directory_create_times(SNUM(handle
->conn
)));
1620 static int vfs_gpfs_stat(struct vfs_handle_struct
*handle
,
1621 struct smb_filename
*smb_fname
)
1623 struct gpfs_winattr attrs
;
1627 struct gpfs_config_data
*config
;
1629 SMB_VFS_HANDLE_GET_DATA(handle
, config
,
1630 struct gpfs_config_data
,
1633 ret
= SMB_VFS_NEXT_STAT(handle
, smb_fname
);
1634 #if defined(HAVE_FSTATAT)
1635 if (ret
== -1 && errno
== EACCES
) {
1636 DEBUG(10, ("Trying stat with capability for %s\n",
1637 smb_fname
->base_name
));
1638 ret
= stat_with_capability(handle
, smb_fname
, 0);
1645 if (!config
->winattr
) {
1649 status
= get_full_smb_filename(talloc_tos(), smb_fname
, &fname
);
1650 if (!NT_STATUS_IS_OK(status
)) {
1651 errno
= map_errno_from_nt_status(status
);
1654 ret
= gpfswrap_get_winattrs_path(discard_const_p(char, fname
), &attrs
);
1657 smb_fname
->st
.st_ex_calculated_birthtime
= false;
1658 smb_fname
->st
.st_ex_btime
.tv_sec
= attrs
.creationTime
.tv_sec
;
1659 smb_fname
->st
.st_ex_btime
.tv_nsec
= attrs
.creationTime
.tv_nsec
;
1664 static int vfs_gpfs_fstat(struct vfs_handle_struct
*handle
,
1665 struct files_struct
*fsp
, SMB_STRUCT_STAT
*sbuf
)
1667 struct gpfs_winattr attrs
;
1669 struct gpfs_config_data
*config
;
1671 SMB_VFS_HANDLE_GET_DATA(handle
, config
,
1672 struct gpfs_config_data
,
1675 ret
= SMB_VFS_NEXT_FSTAT(handle
, fsp
, sbuf
);
1679 if ((fsp
->fh
== NULL
) || (fsp
->fh
->fd
== -1)) {
1682 if (!config
->winattr
) {
1686 ret
= gpfswrap_get_winattrs(fsp
->fh
->fd
, &attrs
);
1688 sbuf
->st_ex_calculated_birthtime
= false;
1689 sbuf
->st_ex_btime
.tv_sec
= attrs
.creationTime
.tv_sec
;
1690 sbuf
->st_ex_btime
.tv_nsec
= attrs
.creationTime
.tv_nsec
;
1695 static int vfs_gpfs_lstat(struct vfs_handle_struct
*handle
,
1696 struct smb_filename
*smb_fname
)
1698 struct gpfs_winattr attrs
;
1702 struct gpfs_config_data
*config
;
1704 SMB_VFS_HANDLE_GET_DATA(handle
, config
,
1705 struct gpfs_config_data
,
1708 ret
= SMB_VFS_NEXT_LSTAT(handle
, smb_fname
);
1709 #if defined(HAVE_FSTATAT)
1710 if (ret
== -1 && errno
== EACCES
) {
1711 DEBUG(10, ("Trying lstat with capability for %s\n",
1712 smb_fname
->base_name
));
1713 ret
= stat_with_capability(handle
, smb_fname
,
1714 AT_SYMLINK_NOFOLLOW
);
1721 if (!config
->winattr
) {
1725 status
= get_full_smb_filename(talloc_tos(), smb_fname
, &path
);
1726 if (!NT_STATUS_IS_OK(status
)) {
1727 errno
= map_errno_from_nt_status(status
);
1730 ret
= gpfswrap_get_winattrs_path(discard_const_p(char, path
), &attrs
);
1733 smb_fname
->st
.st_ex_calculated_birthtime
= false;
1734 smb_fname
->st
.st_ex_btime
.tv_sec
= attrs
.creationTime
.tv_sec
;
1735 smb_fname
->st
.st_ex_btime
.tv_nsec
= attrs
.creationTime
.tv_nsec
;
1740 static void timespec_to_gpfs_time(struct timespec ts
, gpfs_timestruc_t
*gt
,
1741 int idx
, int *flags
)
1743 if (!null_timespec(ts
)) {
1745 gt
[idx
].tv_sec
= ts
.tv_sec
;
1746 gt
[idx
].tv_nsec
= ts
.tv_nsec
;
1747 DEBUG(10, ("Setting GPFS time %d, flags 0x%x\n", idx
, *flags
));
1751 static int smbd_gpfs_set_times_path(char *path
, struct smb_file_time
*ft
)
1753 gpfs_timestruc_t gpfs_times
[4];
1757 ZERO_ARRAY(gpfs_times
);
1758 timespec_to_gpfs_time(ft
->atime
, gpfs_times
, 0, &flags
);
1759 timespec_to_gpfs_time(ft
->mtime
, gpfs_times
, 1, &flags
);
1760 /* No good mapping from LastChangeTime to ctime, not storing */
1761 timespec_to_gpfs_time(ft
->create_time
, gpfs_times
, 3, &flags
);
1764 DEBUG(10, ("nothing to do, return to avoid EINVAL\n"));
1768 rc
= gpfswrap_set_times_path(path
, flags
, gpfs_times
);
1770 if (rc
!= 0 && errno
!= ENOSYS
) {
1771 DEBUG(1,("gpfs_set_times() returned with error %s\n",
1778 static int vfs_gpfs_ntimes(struct vfs_handle_struct
*handle
,
1779 const struct smb_filename
*smb_fname
,
1780 struct smb_file_time
*ft
)
1783 struct gpfs_winattr attrs
;
1787 struct gpfs_config_data
*config
;
1789 SMB_VFS_HANDLE_GET_DATA(handle
, config
,
1790 struct gpfs_config_data
,
1793 status
= get_full_smb_filename(talloc_tos(), smb_fname
, &path
);
1794 if (!NT_STATUS_IS_OK(status
)) {
1795 errno
= map_errno_from_nt_status(status
);
1799 /* Try to use gpfs_set_times if it is enabled and available */
1800 if (config
->settimes
) {
1801 ret
= smbd_gpfs_set_times_path(path
, ft
);
1803 if (ret
== 0 || (ret
== -1 && errno
!= ENOSYS
)) {
1808 DEBUG(10,("gpfs_set_times() not available or disabled, "
1809 "use ntimes and winattr\n"));
1811 ret
= SMB_VFS_NEXT_NTIMES(handle
, smb_fname
, ft
);
1813 /* don't complain if access was denied */
1814 if (errno
!= EPERM
&& errno
!= EACCES
) {
1815 DEBUG(1,("vfs_gpfs_ntimes: SMB_VFS_NEXT_NTIMES failed:"
1816 "%s", strerror(errno
)));
1821 if(null_timespec(ft
->create_time
)){
1822 DEBUG(10,("vfs_gpfs_ntimes:Create Time is NULL\n"));
1826 if (!config
->winattr
) {
1831 attrs
.creationTime
.tv_sec
= ft
->create_time
.tv_sec
;
1832 attrs
.creationTime
.tv_nsec
= ft
->create_time
.tv_nsec
;
1834 ret
= gpfswrap_set_winattrs_path(discard_const_p(char, path
),
1835 GPFS_WINATTR_SET_CREATION_TIME
,
1837 if(ret
== -1 && errno
!= ENOSYS
){
1838 DEBUG(1,("vfs_gpfs_ntimes: set GPFS ntimes failed %d\n",ret
));
1845 static int vfs_gpfs_fallocate(struct vfs_handle_struct
*handle
,
1846 struct files_struct
*fsp
, enum vfs_fallocate_mode mode
,
1847 off_t offset
, off_t len
)
1850 struct gpfs_config_data
*config
;
1852 SMB_VFS_HANDLE_GET_DATA(handle
, config
,
1853 struct gpfs_config_data
,
1856 if (!config
->prealloc
) {
1857 /* you should better not run fallocate() on GPFS at all */
1862 if (mode
== VFS_FALLOCATE_KEEP_SIZE
) {
1863 DEBUG(10, ("Unsupported VFS_FALLOCATE_KEEP_SIZE\n"));
1868 ret
= gpfswrap_prealloc(fsp
->fh
->fd
, offset
, len
);
1870 if (ret
== -1 && errno
!= ENOSYS
) {
1871 DEBUG(0, ("GPFS prealloc failed: %s\n", strerror(errno
)));
1872 } else if (ret
== -1 && errno
== ENOSYS
) {
1873 DEBUG(10, ("GPFS prealloc not supported.\n"));
1875 DEBUG(10, ("GPFS prealloc succeeded.\n"));
1881 static int vfs_gpfs_ftruncate(vfs_handle_struct
*handle
, files_struct
*fsp
,
1885 struct gpfs_config_data
*config
;
1887 SMB_VFS_HANDLE_GET_DATA(handle
, config
,
1888 struct gpfs_config_data
,
1891 if (!config
->ftruncate
) {
1892 return SMB_VFS_NEXT_FTRUNCATE(handle
, fsp
, len
);
1895 result
= gpfswrap_ftruncate(fsp
->fh
->fd
, len
);
1896 if ((result
== -1) && (errno
== ENOSYS
)) {
1897 return SMB_VFS_NEXT_FTRUNCATE(handle
, fsp
, len
);
1902 static bool vfs_gpfs_is_offline(struct vfs_handle_struct
*handle
,
1903 const struct smb_filename
*fname
,
1904 SMB_STRUCT_STAT
*sbuf
)
1906 struct gpfs_winattr attrs
;
1909 struct gpfs_config_data
*config
;
1912 SMB_VFS_HANDLE_GET_DATA(handle
, config
,
1913 struct gpfs_config_data
,
1916 if (!config
->winattr
) {
1917 return SMB_VFS_NEXT_IS_OFFLINE(handle
, fname
, sbuf
);
1920 status
= get_full_smb_filename(talloc_tos(), fname
, &path
);
1921 if (!NT_STATUS_IS_OK(status
)) {
1922 errno
= map_errno_from_nt_status(status
);
1926 ret
= gpfswrap_get_winattrs_path(path
, &attrs
);
1932 if ((attrs
.winAttrs
& GPFS_WINATTR_OFFLINE
) != 0) {
1933 DEBUG(10, ("%s is offline\n", path
));
1937 DEBUG(10, ("%s is online\n", path
));
1939 return SMB_VFS_NEXT_IS_OFFLINE(handle
, fname
, sbuf
);
1942 static bool vfs_gpfs_aio_force(struct vfs_handle_struct
*handle
,
1943 struct files_struct
*fsp
)
1945 return vfs_gpfs_is_offline(handle
, fsp
->fsp_name
, &fsp
->fsp_name
->st
);
1948 static ssize_t
vfs_gpfs_sendfile(vfs_handle_struct
*handle
, int tofd
,
1949 files_struct
*fsp
, const DATA_BLOB
*hdr
,
1950 off_t offset
, size_t n
)
1952 if (SMB_VFS_IS_OFFLINE(handle
->conn
, fsp
->fsp_name
, &fsp
->fsp_name
->st
))
1957 return SMB_VFS_NEXT_SENDFILE(handle
, tofd
, fsp
, hdr
, offset
, n
);
1960 static int vfs_gpfs_connect(struct vfs_handle_struct
*handle
,
1961 const char *service
, const char *user
)
1963 struct gpfs_config_data
*config
;
1966 gpfswrap_lib_init(0);
1968 config
= talloc_zero(handle
->conn
, struct gpfs_config_data
);
1970 DEBUG(0, ("talloc_zero() failed\n"));
1975 ret
= SMB_VFS_NEXT_CONNECT(handle
, service
, user
);
1977 TALLOC_FREE(config
);
1981 config
->sharemodes
= lp_parm_bool(SNUM(handle
->conn
), "gpfs",
1982 "sharemodes", true);
1984 config
->leases
= lp_parm_bool(SNUM(handle
->conn
), "gpfs",
1987 config
->hsm
= lp_parm_bool(SNUM(handle
->conn
), "gpfs",
1990 config
->syncio
= lp_parm_bool(SNUM(handle
->conn
), "gpfs",
1993 config
->winattr
= lp_parm_bool(SNUM(handle
->conn
), "gpfs",
1996 config
->ftruncate
= lp_parm_bool(SNUM(handle
->conn
), "gpfs",
1999 config
->getrealfilename
= lp_parm_bool(SNUM(handle
->conn
), "gpfs",
2000 "getrealfilename", true);
2002 config
->dfreequota
= lp_parm_bool(SNUM(handle
->conn
), "gpfs",
2003 "dfreequota", false);
2005 config
->prealloc
= lp_parm_bool(SNUM(handle
->conn
), "gpfs",
2008 config
->acl
= lp_parm_bool(SNUM(handle
->conn
), "gpfs", "acl", true);
2010 config
->settimes
= lp_parm_bool(SNUM(handle
->conn
), "gpfs",
2012 config
->recalls
= lp_parm_bool(SNUM(handle
->conn
), "gpfs",
2015 SMB_VFS_HANDLE_SET_DATA(handle
, config
,
2016 NULL
, struct gpfs_config_data
,
2019 if (config
->leases
) {
2021 * GPFS lease code is based on kernel oplock code
2022 * so make sure it is turned on
2024 if (!lp_kernel_oplocks(SNUM(handle
->conn
))) {
2025 DEBUG(5, ("Enabling kernel oplocks for "
2026 "gpfs:leases to work\n"));
2027 lp_do_parameter(SNUM(handle
->conn
), "kernel oplocks",
2032 * as the kernel does not properly support Level II oplocks
2033 * and GPFS leases code is based on kernel infrastructure, we
2034 * need to turn off Level II oplocks if gpfs:leases is enabled
2036 if (lp_level2_oplocks(SNUM(handle
->conn
))) {
2037 DEBUG(5, ("gpfs:leases are enabled, disabling "
2038 "Level II oplocks\n"));
2039 lp_do_parameter(SNUM(handle
->conn
), "level2 oplocks",
2047 static int get_gpfs_fset_id(const char *pathname
, int *fset_id
)
2049 int err
, fd
, errno_fcntl
;
2052 gpfsFcntlHeader_t hdr
;
2053 gpfsGetFilesetName_t fsn
;
2056 arg
.hdr
.totalLength
= sizeof(arg
);
2057 arg
.hdr
.fcntlVersion
= GPFS_FCNTL_CURRENT_VERSION
;
2058 arg
.hdr
.fcntlReserved
= 0;
2059 arg
.fsn
.structLen
= sizeof(arg
.fsn
);
2060 arg
.fsn
.structType
= GPFS_FCNTL_GET_FILESETNAME
;
2062 fd
= open(pathname
, O_RDONLY
);
2064 DEBUG(1, ("Could not open %s: %s\n",
2065 pathname
, strerror(errno
)));
2069 err
= gpfswrap_fcntl(fd
, &arg
);
2070 errno_fcntl
= errno
;
2074 errno
= errno_fcntl
;
2075 if (errno
!= ENOSYS
) {
2076 DEBUG(1, ("GPFS_FCNTL_GET_FILESETNAME for %s failed: "
2077 "%s\n", pathname
, strerror(errno
)));
2082 err
= gpfswrap_getfilesetid(discard_const_p(char, pathname
),
2083 arg
.fsn
.buffer
, fset_id
);
2084 if (err
&& errno
!= ENOSYS
) {
2085 DEBUG(1, ("gpfs_getfilesetid for %s failed: %s\n",
2086 pathname
, strerror(errno
)));
2091 static int get_gpfs_quota(const char *pathname
, int type
, int id
,
2092 struct gpfs_quotaInfo
*qi
)
2097 ret
= gpfswrap_quotactl(discard_const_p(char, pathname
),
2098 GPFS_QCMD(Q_GETQUOTA
, type
), id
, qi
);
2101 if (errno
== GPFS_E_NO_QUOTA_INST
) {
2102 DEBUG(10, ("Quotas disabled on GPFS filesystem.\n"));
2103 } else if (errno
!= ENOSYS
) {
2104 DEBUG(0, ("Get quota failed, type %d, id, %d, "
2105 "errno %d.\n", type
, id
, errno
));
2111 DEBUG(10, ("quota type %d, id %d, blk u:%lld h:%lld s:%lld gt:%u\n",
2112 type
, id
, qi
->blockUsage
, qi
->blockHardLimit
,
2113 qi
->blockSoftLimit
, qi
->blockGraceTime
));
2118 static int vfs_gpfs_get_quotas(const char *path
, uid_t uid
, gid_t gid
,
2120 struct gpfs_quotaInfo
*qi_user
,
2121 struct gpfs_quotaInfo
*qi_group
,
2122 struct gpfs_quotaInfo
*qi_fset
)
2129 * We want to always use the directory to get the fileset id,
2130 * because files might have a share mode. We also do not want
2131 * to get the parent directory when there is already a
2132 * directory to avoid stepping in a different fileset. The
2133 * path passed here is currently either "." or a filename, so
2134 * this is ok. The proper solution would be having a way to
2135 * query the fileset id without opening the file.
2137 b
= parent_dirname(talloc_tos(), path
, &dir_path
, NULL
);
2143 DEBUG(10, ("path %s, directory %s\n", path
, dir_path
));
2145 err
= get_gpfs_fset_id(dir_path
, fset_id
);
2147 DEBUG(0, ("Get fset id failed path %s, dir %s, errno %d.\n",
2148 path
, dir_path
, errno
));
2152 err
= get_gpfs_quota(path
, GPFS_USRQUOTA
, uid
, qi_user
);
2157 err
= get_gpfs_quota(path
, GPFS_GRPQUOTA
, gid
, qi_group
);
2162 err
= get_gpfs_quota(path
, GPFS_FILESETQUOTA
, *fset_id
, qi_fset
);
2170 static void vfs_gpfs_disk_free_quota(struct gpfs_quotaInfo qi
, time_t cur_time
,
2171 uint64_t *dfree
, uint64_t *dsize
)
2173 uint64_t usage
, limit
;
2176 * The quota reporting is done in units of 1024 byte blocks, but
2177 * sys_fsusage uses units of 512 byte blocks, adjust the block number
2178 * accordingly. Also filter possibly negative usage counts from gpfs.
2180 usage
= qi
.blockUsage
< 0 ? 0 : (uint64_t)qi
.blockUsage
* 2;
2181 limit
= (uint64_t)qi
.blockHardLimit
* 2;
2184 * When the grace time for the exceeded soft block quota has been
2185 * exceeded, the soft block quota becomes an additional hard limit.
2187 if (qi
.blockSoftLimit
&&
2188 qi
.blockGraceTime
&& cur_time
> qi
.blockGraceTime
) {
2189 /* report disk as full */
2191 *dsize
= MIN(*dsize
, usage
);
2194 if (!qi
.blockHardLimit
)
2197 if (usage
>= limit
) {
2198 /* report disk as full */
2200 *dsize
= MIN(*dsize
, usage
);
2203 /* limit has not been reached, determine "free space" */
2204 *dfree
= MIN(*dfree
, limit
- usage
);
2205 *dsize
= MIN(*dsize
, limit
);
2209 static uint64_t vfs_gpfs_disk_free(vfs_handle_struct
*handle
, const char *path
,
2211 uint64_t *dfree
, uint64_t *dsize
)
2213 struct security_unix_token
*utok
;
2214 struct gpfs_quotaInfo qi_user
, qi_group
, qi_fset
;
2215 struct gpfs_config_data
*config
;
2219 SMB_VFS_HANDLE_GET_DATA(handle
, config
, struct gpfs_config_data
,
2220 return (uint64_t)-1);
2221 if (!config
->dfreequota
) {
2222 return SMB_VFS_NEXT_DISK_FREE(handle
, path
,
2223 bsize
, dfree
, dsize
);
2226 err
= sys_fsusage(path
, dfree
, dsize
);
2228 DEBUG (0, ("Could not get fs usage, errno %d\n", errno
));
2229 return SMB_VFS_NEXT_DISK_FREE(handle
, path
,
2230 bsize
, dfree
, dsize
);
2233 /* sys_fsusage returns units of 512 bytes */
2236 DEBUG(10, ("fs dfree %llu, dsize %llu\n",
2237 (unsigned long long)*dfree
, (unsigned long long)*dsize
));
2239 utok
= handle
->conn
->session_info
->unix_token
;
2240 err
= vfs_gpfs_get_quotas(path
, utok
->uid
, utok
->gid
, &fset_id
,
2241 &qi_user
, &qi_group
, &qi_fset
);
2243 return SMB_VFS_NEXT_DISK_FREE(handle
, path
,
2244 bsize
, dfree
, dsize
);
2247 cur_time
= time(NULL
);
2249 /* Adjust free space and size according to quota limits. */
2250 vfs_gpfs_disk_free_quota(qi_user
, cur_time
, dfree
, dsize
);
2251 vfs_gpfs_disk_free_quota(qi_group
, cur_time
, dfree
, dsize
);
2253 /* Id 0 indicates the default quota, not an actual quota */
2255 vfs_gpfs_disk_free_quota(qi_fset
, cur_time
, dfree
, dsize
);
2258 disk_norm(bsize
, dfree
, dsize
);
2262 static uint32_t vfs_gpfs_capabilities(struct vfs_handle_struct
*handle
,
2263 enum timestamp_set_resolution
*p_ts_res
)
2265 struct gpfs_config_data
*config
;
2268 next
= SMB_VFS_NEXT_FS_CAPABILITIES(handle
, p_ts_res
);
2270 SMB_VFS_HANDLE_GET_DATA(handle
, config
,
2271 struct gpfs_config_data
,
2275 next
|= FILE_SUPPORTS_REMOTE_STORAGE
;
2280 static int vfs_gpfs_open(struct vfs_handle_struct
*handle
,
2281 struct smb_filename
*smb_fname
, files_struct
*fsp
,
2282 int flags
, mode_t mode
)
2284 struct gpfs_config_data
*config
;
2286 SMB_VFS_HANDLE_GET_DATA(handle
, config
,
2287 struct gpfs_config_data
,
2290 if (config
->hsm
&& !config
->recalls
) {
2291 if (SMB_VFS_IS_OFFLINE(handle
->conn
, smb_fname
, &smb_fname
->st
))
2293 DEBUG(10, ("Refusing access to offline file %s\n",
2300 if (config
->syncio
) {
2303 return SMB_VFS_NEXT_OPEN(handle
, smb_fname
, fsp
, flags
, mode
);
2306 static ssize_t
vfs_gpfs_pread(vfs_handle_struct
*handle
, files_struct
*fsp
,
2307 void *data
, size_t n
, off_t offset
)
2312 was_offline
= SMB_VFS_IS_OFFLINE(handle
->conn
, fsp
->fsp_name
,
2313 &fsp
->fsp_name
->st
);
2315 ret
= SMB_VFS_NEXT_PREAD(handle
, fsp
, data
, n
, offset
);
2317 if ((ret
!= -1) && was_offline
) {
2318 notify_fname(handle
->conn
, NOTIFY_ACTION_MODIFIED
,
2319 FILE_NOTIFY_CHANGE_ATTRIBUTES
,
2320 fsp
->fsp_name
->base_name
);
2326 struct vfs_gpfs_pread_state
{
2327 struct files_struct
*fsp
;
2333 static void vfs_gpfs_pread_done(struct tevent_req
*subreq
);
2335 static struct tevent_req
*vfs_gpfs_pread_send(struct vfs_handle_struct
*handle
,
2336 TALLOC_CTX
*mem_ctx
,
2337 struct tevent_context
*ev
,
2338 struct files_struct
*fsp
,
2339 void *data
, size_t n
,
2342 struct tevent_req
*req
, *subreq
;
2343 struct vfs_gpfs_pread_state
*state
;
2345 req
= tevent_req_create(mem_ctx
, &state
, struct vfs_gpfs_pread_state
);
2349 state
->was_offline
= SMB_VFS_IS_OFFLINE(handle
->conn
, fsp
->fsp_name
,
2350 &fsp
->fsp_name
->st
);
2352 subreq
= SMB_VFS_NEXT_PREAD_SEND(state
, ev
, handle
, fsp
, data
,
2354 if (tevent_req_nomem(subreq
, req
)) {
2355 return tevent_req_post(req
, ev
);
2357 tevent_req_set_callback(subreq
, vfs_gpfs_pread_done
, req
);
2361 static void vfs_gpfs_pread_done(struct tevent_req
*subreq
)
2363 struct tevent_req
*req
= tevent_req_callback_data(
2364 subreq
, struct tevent_req
);
2365 struct vfs_gpfs_pread_state
*state
= tevent_req_data(
2366 req
, struct vfs_gpfs_pread_state
);
2368 state
->ret
= SMB_VFS_PREAD_RECV(subreq
, &state
->err
);
2369 TALLOC_FREE(subreq
);
2370 tevent_req_done(req
);
2373 static ssize_t
vfs_gpfs_pread_recv(struct tevent_req
*req
, int *err
)
2375 struct vfs_gpfs_pread_state
*state
= tevent_req_data(
2376 req
, struct vfs_gpfs_pread_state
);
2377 struct files_struct
*fsp
= state
->fsp
;
2379 if (tevent_req_is_unix_error(req
, err
)) {
2384 if ((state
->ret
!= -1) && state
->was_offline
) {
2385 DEBUG(10, ("sending notify\n"));
2386 notify_fname(fsp
->conn
, NOTIFY_ACTION_MODIFIED
,
2387 FILE_NOTIFY_CHANGE_ATTRIBUTES
,
2388 fsp
->fsp_name
->base_name
);
2394 static ssize_t
vfs_gpfs_pwrite(vfs_handle_struct
*handle
, files_struct
*fsp
,
2395 const void *data
, size_t n
, off_t offset
)
2400 was_offline
= SMB_VFS_IS_OFFLINE(handle
->conn
, fsp
->fsp_name
,
2401 &fsp
->fsp_name
->st
);
2403 ret
= SMB_VFS_NEXT_PWRITE(handle
, fsp
, data
, n
, offset
);
2405 if ((ret
!= -1) && was_offline
) {
2406 notify_fname(handle
->conn
, NOTIFY_ACTION_MODIFIED
,
2407 FILE_NOTIFY_CHANGE_ATTRIBUTES
,
2408 fsp
->fsp_name
->base_name
);
2414 struct vfs_gpfs_pwrite_state
{
2415 struct files_struct
*fsp
;
2421 static void vfs_gpfs_pwrite_done(struct tevent_req
*subreq
);
2423 static struct tevent_req
*vfs_gpfs_pwrite_send(
2424 struct vfs_handle_struct
*handle
,
2425 TALLOC_CTX
*mem_ctx
,
2426 struct tevent_context
*ev
,
2427 struct files_struct
*fsp
,
2428 const void *data
, size_t n
,
2431 struct tevent_req
*req
, *subreq
;
2432 struct vfs_gpfs_pwrite_state
*state
;
2434 req
= tevent_req_create(mem_ctx
, &state
, struct vfs_gpfs_pwrite_state
);
2438 state
->was_offline
= SMB_VFS_IS_OFFLINE(handle
->conn
, fsp
->fsp_name
,
2439 &fsp
->fsp_name
->st
);
2441 subreq
= SMB_VFS_NEXT_PWRITE_SEND(state
, ev
, handle
, fsp
, data
,
2443 if (tevent_req_nomem(subreq
, req
)) {
2444 return tevent_req_post(req
, ev
);
2446 tevent_req_set_callback(subreq
, vfs_gpfs_pwrite_done
, req
);
2450 static void vfs_gpfs_pwrite_done(struct tevent_req
*subreq
)
2452 struct tevent_req
*req
= tevent_req_callback_data(
2453 subreq
, struct tevent_req
);
2454 struct vfs_gpfs_pwrite_state
*state
= tevent_req_data(
2455 req
, struct vfs_gpfs_pwrite_state
);
2457 state
->ret
= SMB_VFS_PWRITE_RECV(subreq
, &state
->err
);
2458 TALLOC_FREE(subreq
);
2459 tevent_req_done(req
);
2462 static ssize_t
vfs_gpfs_pwrite_recv(struct tevent_req
*req
, int *err
)
2464 struct vfs_gpfs_pwrite_state
*state
= tevent_req_data(
2465 req
, struct vfs_gpfs_pwrite_state
);
2466 struct files_struct
*fsp
= state
->fsp
;
2468 if (tevent_req_is_unix_error(req
, err
)) {
2473 if ((state
->ret
!= -1) && state
->was_offline
) {
2474 DEBUG(10, ("sending notify\n"));
2475 notify_fname(fsp
->conn
, NOTIFY_ACTION_MODIFIED
,
2476 FILE_NOTIFY_CHANGE_ATTRIBUTES
,
2477 fsp
->fsp_name
->base_name
);
2484 static struct vfs_fn_pointers vfs_gpfs_fns
= {
2485 .connect_fn
= vfs_gpfs_connect
,
2486 .disk_free_fn
= vfs_gpfs_disk_free
,
2487 .fs_capabilities_fn
= vfs_gpfs_capabilities
,
2488 .kernel_flock_fn
= vfs_gpfs_kernel_flock
,
2489 .linux_setlease_fn
= vfs_gpfs_setlease
,
2490 .get_real_filename_fn
= vfs_gpfs_get_real_filename
,
2491 .fget_nt_acl_fn
= gpfsacl_fget_nt_acl
,
2492 .get_nt_acl_fn
= gpfsacl_get_nt_acl
,
2493 .fset_nt_acl_fn
= gpfsacl_fset_nt_acl
,
2494 .sys_acl_get_file_fn
= gpfsacl_sys_acl_get_file
,
2495 .sys_acl_get_fd_fn
= gpfsacl_sys_acl_get_fd
,
2496 .sys_acl_blob_get_file_fn
= gpfsacl_sys_acl_blob_get_file
,
2497 .sys_acl_blob_get_fd_fn
= gpfsacl_sys_acl_blob_get_fd
,
2498 .sys_acl_set_file_fn
= gpfsacl_sys_acl_set_file
,
2499 .sys_acl_set_fd_fn
= gpfsacl_sys_acl_set_fd
,
2500 .sys_acl_delete_def_file_fn
= gpfsacl_sys_acl_delete_def_file
,
2501 .chmod_fn
= vfs_gpfs_chmod
,
2502 .fchmod_fn
= vfs_gpfs_fchmod
,
2503 .close_fn
= vfs_gpfs_close
,
2504 .setxattr_fn
= gpfs_set_xattr
,
2505 .getxattr_fn
= gpfs_get_xattr
,
2506 .stat_fn
= vfs_gpfs_stat
,
2507 .fstat_fn
= vfs_gpfs_fstat
,
2508 .lstat_fn
= vfs_gpfs_lstat
,
2509 .ntimes_fn
= vfs_gpfs_ntimes
,
2510 .is_offline_fn
= vfs_gpfs_is_offline
,
2511 .aio_force_fn
= vfs_gpfs_aio_force
,
2512 .sendfile_fn
= vfs_gpfs_sendfile
,
2513 .fallocate_fn
= vfs_gpfs_fallocate
,
2514 .open_fn
= vfs_gpfs_open
,
2515 .pread_fn
= vfs_gpfs_pread
,
2516 .pread_send_fn
= vfs_gpfs_pread_send
,
2517 .pread_recv_fn
= vfs_gpfs_pread_recv
,
2518 .pwrite_fn
= vfs_gpfs_pwrite
,
2519 .pwrite_send_fn
= vfs_gpfs_pwrite_send
,
2520 .pwrite_recv_fn
= vfs_gpfs_pwrite_recv
,
2521 .ftruncate_fn
= vfs_gpfs_ftruncate
2524 NTSTATUS
vfs_gpfs_init(void);
2525 NTSTATUS
vfs_gpfs_init(void)
2529 ret
= gpfswrap_init();
2531 DEBUG(1, ("Could not initialize GPFS library wrapper\n"));
2534 return smb_register_vfs(SMB_VFS_INTERFACE_VERSION
, "gpfs",