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"
33 #include "lib/util/gpfswrap.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
== GPFS_ACL_LEVEL_V4FLAGS
) {
60 return gacl
->v4Level1
.acl_flags
;
65 static inline gpfs_ace_v4_t
*gpfs_ace_ptr(gpfs_acl_t
*gacl
, unsigned int i
)
67 if (gacl
->acl_level
== GPFS_ACL_LEVEL_V4FLAGS
) {
68 return &gacl
->v4Level1
.ace_v4
[i
];
70 return &gacl
->ace_v4
[i
];
73 static bool set_gpfs_sharemode(files_struct
*fsp
, uint32_t access_mask
,
74 uint32_t share_access
)
76 unsigned int allow
= GPFS_SHARE_NONE
;
77 unsigned int deny
= GPFS_DENY_NONE
;
80 if ((fsp
== NULL
) || (fsp
->fh
== NULL
) || (fsp
->fh
->fd
< 0)) {
81 /* No real file, don't disturb */
85 allow
|= (access_mask
& (FILE_WRITE_DATA
|FILE_APPEND_DATA
|
86 DELETE_ACCESS
)) ? GPFS_SHARE_WRITE
: 0;
87 allow
|= (access_mask
& (FILE_READ_DATA
|FILE_EXECUTE
)) ?
90 if (allow
== GPFS_SHARE_NONE
) {
91 DEBUG(10, ("special case am=no_access:%x\n",access_mask
));
94 deny
|= (share_access
& FILE_SHARE_WRITE
) ?
96 deny
|= (share_access
& (FILE_SHARE_READ
)) ?
99 DEBUG(10, ("am=%x, allow=%d, sa=%x, deny=%d\n",
100 access_mask
, allow
, share_access
, deny
));
102 result
= gpfswrap_set_share(fsp
->fh
->fd
, allow
, deny
);
104 if (errno
== ENOSYS
) {
105 DEBUG(5, ("VFS module vfs_gpfs loaded, but gpfs "
106 "set_share function support not available. "
107 "Allowing access\n"));
110 DEBUG(10, ("gpfs_set_share failed: %s\n",
115 return (result
== 0);
118 static int vfs_gpfs_kernel_flock(vfs_handle_struct
*handle
, files_struct
*fsp
,
119 uint32_t share_mode
, uint32_t access_mask
)
122 struct gpfs_config_data
*config
;
125 SMB_VFS_HANDLE_GET_DATA(handle
, config
,
126 struct gpfs_config_data
,
129 if(!config
->sharemodes
) {
134 * A named stream fsp will have the basefile open in the fsp
135 * fd, so lacking a distinct fd for the stream we have to skip
136 * kernel_flock and set_gpfs_sharemode for stream.
138 if (!is_ntfs_default_stream_smb_fname(fsp
->fsp_name
)) {
139 DEBUG(2,("%s: kernel_flock on stream\n", fsp_str_dbg(fsp
)));
143 START_PROFILE(syscall_kernel_flock
);
145 kernel_flock(fsp
->fh
->fd
, share_mode
, access_mask
);
147 if (!set_gpfs_sharemode(fsp
, access_mask
, fsp
->share_access
)) {
151 END_PROFILE(syscall_kernel_flock
);
156 static int vfs_gpfs_close(vfs_handle_struct
*handle
, files_struct
*fsp
)
159 struct gpfs_config_data
*config
;
161 SMB_VFS_HANDLE_GET_DATA(handle
, config
,
162 struct gpfs_config_data
,
165 if (config
->sharemodes
&& (fsp
->fh
!= NULL
) && (fsp
->fh
->fd
!= -1)) {
166 set_gpfs_sharemode(fsp
, 0, 0);
169 return SMB_VFS_NEXT_CLOSE(handle
, fsp
);
172 static int set_gpfs_lease(int fd
, int leasetype
)
174 int gpfs_type
= GPFS_LEASE_NONE
;
176 if (leasetype
== F_RDLCK
) {
177 gpfs_type
= GPFS_LEASE_READ
;
179 if (leasetype
== F_WRLCK
) {
180 gpfs_type
= GPFS_LEASE_WRITE
;
183 /* we unconditionally set CAP_LEASE, rather than looking for
184 -1/EACCES as there is a bug in some versions of
185 libgpfs_gpl.so which results in a leaked fd on /dev/ss0
186 each time we try this with the wrong capabilities set
188 linux_set_lease_capability();
189 return gpfswrap_set_lease(fd
, gpfs_type
);
192 static int vfs_gpfs_setlease(vfs_handle_struct
*handle
, files_struct
*fsp
,
195 struct gpfs_config_data
*config
;
198 SMB_VFS_HANDLE_GET_DATA(handle
, config
,
199 struct gpfs_config_data
,
202 START_PROFILE(syscall_linux_setlease
);
204 if (linux_set_lease_sighandler(fsp
->fh
->fd
) == -1) {
209 if (config
->leases
) {
211 * Ensure the lease owner is root to allow
212 * correct delivery of lease-break signals.
215 ret
= set_gpfs_lease(fsp
->fh
->fd
,leasetype
);
220 END_PROFILE(syscall_linux_setlease
);
225 static int vfs_gpfs_get_real_filename(struct vfs_handle_struct
*handle
,
233 char real_pathname
[PATH_MAX
+1];
236 struct gpfs_config_data
*config
;
238 SMB_VFS_HANDLE_GET_DATA(handle
, config
,
239 struct gpfs_config_data
,
242 if (!config
->getrealfilename
) {
243 return SMB_VFS_NEXT_GET_REAL_FILENAME(handle
, path
, name
,
244 mem_ctx
, found_name
);
247 mangled
= mangle_is_mangled(name
, handle
->conn
->params
);
249 return SMB_VFS_NEXT_GET_REAL_FILENAME(handle
, path
, name
,
250 mem_ctx
, found_name
);
253 full_path
= talloc_asprintf(talloc_tos(), "%s/%s", path
, name
);
254 if (full_path
== NULL
) {
259 buflen
= sizeof(real_pathname
) - 1;
261 result
= gpfswrap_get_realfilename_path(full_path
, real_pathname
,
264 TALLOC_FREE(full_path
);
266 if ((result
== -1) && (errno
== ENOSYS
)) {
267 return SMB_VFS_NEXT_GET_REAL_FILENAME(
268 handle
, path
, name
, mem_ctx
, found_name
);
272 DEBUG(10, ("smbd_gpfs_get_realfilename_path returned %s\n",
278 * GPFS does not necessarily null-terminate the returned path
279 * but instead returns the buffer length in buflen.
282 if (buflen
< sizeof(real_pathname
)) {
283 real_pathname
[buflen
] = '\0';
285 real_pathname
[sizeof(real_pathname
)-1] = '\0';
288 DEBUG(10, ("smbd_gpfs_get_realfilename_path: %s/%s -> %s\n",
289 path
, name
, real_pathname
));
291 name
= strrchr_m(real_pathname
, '/');
297 *found_name
= talloc_strdup(mem_ctx
, name
+1);
298 if (*found_name
== NULL
) {
306 static void sd2gpfs_control(uint16_t control
, struct gpfs_acl
*gacl
)
308 unsigned int gpfs_aclflags
= 0;
309 control
&= SEC_DESC_DACL_PROTECTED
| SEC_DESC_SACL_PROTECTED
|
310 SEC_DESC_DACL_AUTO_INHERITED
| SEC_DESC_SACL_AUTO_INHERITED
|
311 SEC_DESC_DACL_DEFAULTED
| SEC_DESC_SACL_DEFAULTED
|
312 SEC_DESC_DACL_PRESENT
| SEC_DESC_SACL_PRESENT
;
313 gpfs_aclflags
= control
<< 8;
314 if (!(control
& SEC_DESC_DACL_PRESENT
))
315 gpfs_aclflags
|= ACL4_FLAG_NULL_DACL
;
316 if (!(control
& SEC_DESC_SACL_PRESENT
))
317 gpfs_aclflags
|= ACL4_FLAG_NULL_SACL
;
318 gacl
->acl_level
= GPFS_ACL_LEVEL_V4FLAGS
;
319 gacl
->v4Level1
.acl_flags
= gpfs_aclflags
;
322 static uint16_t gpfs2sd_control(unsigned int gpfs_aclflags
)
324 uint16_t control
= gpfs_aclflags
>> 8;
325 control
&= SEC_DESC_DACL_PROTECTED
| SEC_DESC_SACL_PROTECTED
|
326 SEC_DESC_DACL_AUTO_INHERITED
| SEC_DESC_SACL_AUTO_INHERITED
|
327 SEC_DESC_DACL_DEFAULTED
| SEC_DESC_SACL_DEFAULTED
|
328 SEC_DESC_DACL_PRESENT
| SEC_DESC_SACL_PRESENT
;
329 control
|= SEC_DESC_SELF_RELATIVE
;
333 static void gpfs_dumpacl(int level
, struct gpfs_acl
*gacl
)
338 DEBUG(0, ("gpfs acl is NULL\n"));
342 DEBUG(level
, ("len: %d, level: %d, version: %d, nace: %d, "
344 gacl
->acl_len
, gacl
->acl_level
, gacl
->acl_version
,
345 gacl
->acl_nace
, gpfs_acl_flags(gacl
)));
347 for(i
=0; i
<gacl
->acl_nace
; i
++)
349 struct gpfs_ace_v4
*gace
= gpfs_ace_ptr(gacl
, i
);
350 DEBUG(level
, ("\tace[%d]: type:%d, flags:0x%x, mask:0x%x, "
351 "iflags:0x%x, who:%u\n",
352 i
, gace
->aceType
, gace
->aceFlags
, gace
->aceMask
,
353 gace
->aceIFlags
, gace
->aceWho
));
358 * get the ACL from GPFS, allocated on the specified mem_ctx
359 * internally retries when initial buffer was too small
361 * caller needs to cast result to either
362 * raw = yes: struct gpfs_opaque_acl
363 * raw = no: struct gpfs_acl
366 static void *vfs_gpfs_getacl(TALLOC_CTX
*mem_ctx
,
369 const gpfs_aclType_t type
)
380 aclbuf
= talloc_zero_size(mem_ctx
, size
);
381 if (aclbuf
== NULL
) {
387 struct gpfs_opaque_acl
*buf
= (struct gpfs_opaque_acl
*) aclbuf
;
388 buf
->acl_type
= type
;
389 flags
= GPFS_GETACL_NATIVE
;
390 len
= (unsigned int *) &(buf
->acl_buffer_len
);
391 struct_size
= sizeof(struct gpfs_opaque_acl
);
393 struct gpfs_acl
*buf
= (struct gpfs_acl
*) aclbuf
;
394 buf
->acl_type
= type
;
395 buf
->acl_level
= GPFS_ACL_LEVEL_V4FLAGS
;
396 flags
= GPFS_GETACL_STRUCT
;
397 len
= &(buf
->acl_len
);
398 /* reserve space for control flags in gpfs 3.5 and beyond */
399 struct_size
= sizeof(struct gpfs_acl
) + sizeof(unsigned int);
402 /* set the length of the buffer as input value */
406 ret
= gpfswrap_getacl(discard_const_p(char, fname
), flags
, aclbuf
);
407 if ((ret
!= 0) && (errno
== ENOSPC
)) {
409 * get the size needed to accommodate the complete buffer
411 * the value returned only applies to the ACL blob in the
412 * struct so make sure to also have headroom for the first
413 * struct members by adding room for the complete struct
414 * (might be a few bytes too much then)
416 size
= *len
+ struct_size
;
418 DEBUG(10, ("Increasing ACL buffer size to %zu\n", size
));
423 DEBUG(5, ("smbd_gpfs_getacl failed with %s\n",
432 /* Tries to get nfs4 acls and returns SMB ACL allocated.
433 * On failure returns 1 if it got non-NFSv4 ACL to prompt
434 * retry with POSIX ACL checks.
435 * On failure returns -1 if there is system (GPFS) error, check errno.
436 * Returns 0 on success
438 static int gpfs_get_nfs4_acl(TALLOC_CTX
*mem_ctx
, const char *fname
, SMB4ACL_T
**ppacl
)
441 struct gpfs_acl
*gacl
= NULL
;
442 DEBUG(10, ("gpfs_get_nfs4_acl invoked for %s\n", fname
));
445 gacl
= (struct gpfs_acl
*) vfs_gpfs_getacl(talloc_tos(), fname
,
448 DEBUG(9, ("gpfs_getacl failed for %s with %s\n",
449 fname
, strerror(errno
)));
450 if (errno
== ENODATA
) {
452 * GPFS returns ENODATA for snapshot
453 * directories. Retry with POSIX ACLs check.
461 if (gacl
->acl_type
!= GPFS_ACL_TYPE_NFS4
) {
462 DEBUG(10, ("Got non-nfsv4 acl\n"));
463 /* Retry with POSIX ACLs check */
468 *ppacl
= smb_create_smb4acl(mem_ctx
);
470 if (gacl
->acl_level
== GPFS_ACL_LEVEL_V4FLAGS
) {
471 uint16_t control
= gpfs2sd_control(gpfs_acl_flags(gacl
));
472 smbacl4_set_controlflags(*ppacl
, control
);
475 DEBUG(10, ("len: %d, level: %d, version: %d, nace: %d, control: %x\n",
476 gacl
->acl_len
, gacl
->acl_level
, gacl
->acl_version
,
477 gacl
->acl_nace
, gpfs_acl_flags(gacl
)));
479 for (i
=0; i
<gacl
->acl_nace
; i
++) {
480 struct gpfs_ace_v4
*gace
= gpfs_ace_ptr(gacl
, i
);
481 SMB_ACE4PROP_T smbace
= { 0 };
482 DEBUG(10, ("type: %d, iflags: %x, flags: %x, mask: %x, "
483 "who: %d\n", gace
->aceType
, gace
->aceIFlags
,
484 gace
->aceFlags
, gace
->aceMask
, gace
->aceWho
));
486 if (gace
->aceIFlags
& ACE4_IFLAG_SPECIAL_ID
) {
487 smbace
.flags
|= SMB_ACE4_ID_SPECIAL
;
488 switch (gace
->aceWho
) {
489 case ACE4_SPECIAL_OWNER
:
490 smbace
.who
.special_id
= SMB_ACE4_WHO_OWNER
;
492 case ACE4_SPECIAL_GROUP
:
493 smbace
.who
.special_id
= SMB_ACE4_WHO_GROUP
;
495 case ACE4_SPECIAL_EVERYONE
:
496 smbace
.who
.special_id
= SMB_ACE4_WHO_EVERYONE
;
499 DEBUG(8, ("invalid special gpfs id %d "
500 "ignored\n", gace
->aceWho
));
501 continue; /* don't add it */
504 if (gace
->aceFlags
& ACE4_FLAG_GROUP_ID
)
505 smbace
.who
.gid
= gace
->aceWho
;
507 smbace
.who
.uid
= gace
->aceWho
;
510 /* remove redundant deny entries */
511 if (i
> 0 && gace
->aceType
== SMB_ACE4_ACCESS_DENIED_ACE_TYPE
) {
512 struct gpfs_ace_v4
*prev
= gpfs_ace_ptr(gacl
, i
- 1);
513 if (prev
->aceType
== SMB_ACE4_ACCESS_ALLOWED_ACE_TYPE
&&
514 prev
->aceFlags
== gace
->aceFlags
&&
515 prev
->aceIFlags
== gace
->aceIFlags
&&
516 (gace
->aceMask
& prev
->aceMask
) == 0 &&
517 gace
->aceWho
== prev
->aceWho
) {
518 /* it's redundant - skip it */
523 smbace
.aceType
= gace
->aceType
;
524 smbace
.aceFlags
= gace
->aceFlags
;
525 smbace
.aceMask
= gace
->aceMask
;
526 smb_add_ace4(*ppacl
, &smbace
);
534 static NTSTATUS
gpfsacl_fget_nt_acl(vfs_handle_struct
*handle
,
535 files_struct
*fsp
, uint32_t security_info
,
537 struct security_descriptor
**ppdesc
)
539 SMB4ACL_T
*pacl
= NULL
;
541 struct gpfs_config_data
*config
;
542 TALLOC_CTX
*frame
= talloc_stackframe();
547 SMB_VFS_HANDLE_GET_DATA(handle
, config
,
548 struct gpfs_config_data
,
549 return NT_STATUS_INTERNAL_ERROR
);
552 status
= SMB_VFS_NEXT_FGET_NT_ACL(handle
, fsp
, security_info
,
558 result
= gpfs_get_nfs4_acl(frame
, fsp
->fsp_name
->base_name
, &pacl
);
561 status
= smb_fget_nt_acl_nfs4(fsp
, security_info
, mem_ctx
,
568 DEBUG(10, ("retrying with posix acl...\n"));
569 status
= posix_fget_nt_acl(fsp
, security_info
,
577 /* GPFS ACL was not read, something wrong happened, error code is set in errno */
578 return map_nt_error_from_unix(errno
);
581 static NTSTATUS
gpfsacl_get_nt_acl(vfs_handle_struct
*handle
,
583 uint32_t security_info
,
584 TALLOC_CTX
*mem_ctx
, struct security_descriptor
**ppdesc
)
586 SMB4ACL_T
*pacl
= NULL
;
588 struct gpfs_config_data
*config
;
589 TALLOC_CTX
*frame
= talloc_stackframe();
594 SMB_VFS_HANDLE_GET_DATA(handle
, config
,
595 struct gpfs_config_data
,
596 return NT_STATUS_INTERNAL_ERROR
);
599 status
= SMB_VFS_NEXT_GET_NT_ACL(handle
, name
, security_info
,
605 result
= gpfs_get_nfs4_acl(frame
, name
, &pacl
);
608 status
= smb_get_nt_acl_nfs4(handle
->conn
, name
, security_info
,
609 mem_ctx
, ppdesc
, pacl
);
615 DEBUG(10, ("retrying with posix acl...\n"));
616 status
= posix_get_nt_acl(handle
->conn
, name
, security_info
,
622 /* GPFS ACL was not read, something wrong happened, error code is set in errno */
624 return map_nt_error_from_unix(errno
);
627 static struct gpfs_acl
*vfs_gpfs_smbacl2gpfsacl(TALLOC_CTX
*mem_ctx
,
632 struct gpfs_acl
*gacl
;
633 gpfs_aclLen_t gacl_len
;
636 gacl_len
= offsetof(gpfs_acl_t
, ace_v4
) + sizeof(unsigned int)
637 + smb_get_naces(smbacl
) * sizeof(gpfs_ace_v4_t
);
639 gacl
= (struct gpfs_acl
*)TALLOC_SIZE(mem_ctx
, gacl_len
);
641 DEBUG(0, ("talloc failed\n"));
646 gacl
->acl_level
= GPFS_ACL_LEVEL_BASE
;
647 gacl
->acl_version
= GPFS_ACL_VERSION_NFS4
;
648 gacl
->acl_type
= GPFS_ACL_TYPE_NFS4
;
649 gacl
->acl_nace
= 0; /* change later... */
652 gacl
->acl_level
= GPFS_ACL_LEVEL_V4FLAGS
;
653 sd2gpfs_control(smbacl4_get_controlflags(smbacl
), gacl
);
656 for (smbace
=smb_first_ace4(smbacl
); smbace
!=NULL
; smbace
= smb_next_ace4(smbace
)) {
657 struct gpfs_ace_v4
*gace
= gpfs_ace_ptr(gacl
, gacl
->acl_nace
);
658 SMB_ACE4PROP_T
*aceprop
= smb_get_ace4(smbace
);
660 gace
->aceType
= aceprop
->aceType
;
661 gace
->aceFlags
= aceprop
->aceFlags
;
662 gace
->aceMask
= aceprop
->aceMask
;
665 * GPFS can't distinguish between WRITE and APPEND on
666 * files, so one being set without the other is an
667 * error. Sorry for the many ()'s :-)
670 if (!fsp
->is_directory
672 ((((gace
->aceMask
& ACE4_MASK_WRITE
) == 0)
673 && ((gace
->aceMask
& ACE4_MASK_APPEND
) != 0))
675 (((gace
->aceMask
& ACE4_MASK_WRITE
) != 0)
676 && ((gace
->aceMask
& ACE4_MASK_APPEND
) == 0)))
678 lp_parm_bool(fsp
->conn
->params
->service
, "gpfs",
679 "merge_writeappend", True
)) {
680 DEBUG(2, ("vfs_gpfs.c: file [%s]: ACE contains "
681 "WRITE^APPEND, setting WRITE|APPEND\n",
683 gace
->aceMask
|= ACE4_MASK_WRITE
|ACE4_MASK_APPEND
;
686 gace
->aceIFlags
= (aceprop
->flags
&SMB_ACE4_ID_SPECIAL
) ? ACE4_IFLAG_SPECIAL_ID
: 0;
688 if (aceprop
->flags
&SMB_ACE4_ID_SPECIAL
)
690 switch(aceprop
->who
.special_id
)
692 case SMB_ACE4_WHO_EVERYONE
:
693 gace
->aceWho
= ACE4_SPECIAL_EVERYONE
;
695 case SMB_ACE4_WHO_OWNER
:
696 gace
->aceWho
= ACE4_SPECIAL_OWNER
;
698 case SMB_ACE4_WHO_GROUP
:
699 gace
->aceWho
= ACE4_SPECIAL_GROUP
;
702 DEBUG(8, ("unsupported special_id %d\n", aceprop
->who
.special_id
));
703 continue; /* don't add it !!! */
706 /* just only for the type safety... */
707 if (aceprop
->aceFlags
&SMB_ACE4_IDENTIFIER_GROUP
)
708 gace
->aceWho
= aceprop
->who
.gid
;
710 gace
->aceWho
= aceprop
->who
.uid
;
715 gacl
->acl_len
= (char *)gpfs_ace_ptr(gacl
, gacl
->acl_nace
)
720 static bool gpfsacl_process_smbacl(vfs_handle_struct
*handle
,
725 struct gpfs_acl
*gacl
;
726 TALLOC_CTX
*mem_ctx
= talloc_tos();
728 gacl
= vfs_gpfs_smbacl2gpfsacl(mem_ctx
, fsp
, smbacl
, true);
729 if (gacl
== NULL
) { /* out of memory */
732 ret
= gpfswrap_putacl(fsp
->fsp_name
->base_name
,
733 GPFS_PUTACL_STRUCT
| GPFS_ACL_SAMBA
, gacl
);
735 if ((ret
!= 0) && (errno
== EINVAL
)) {
736 DEBUG(10, ("Retry without nfs41 control flags\n"));
738 gacl
= vfs_gpfs_smbacl2gpfsacl(mem_ctx
, fsp
, smbacl
, false);
739 if (gacl
== NULL
) { /* out of memory */
742 ret
= gpfswrap_putacl(fsp
->fsp_name
->base_name
,
743 GPFS_PUTACL_STRUCT
| GPFS_ACL_SAMBA
,
748 DEBUG(8, ("gpfs_putacl failed with %s\n", strerror(errno
)));
749 gpfs_dumpacl(8, gacl
);
753 DEBUG(10, ("gpfs_putacl succeeded\n"));
757 static NTSTATUS
gpfsacl_set_nt_acl_internal(vfs_handle_struct
*handle
, files_struct
*fsp
, uint32_t security_info_sent
, const struct security_descriptor
*psd
)
759 struct gpfs_acl
*acl
;
760 NTSTATUS result
= NT_STATUS_ACCESS_DENIED
;
762 acl
= (struct gpfs_acl
*) vfs_gpfs_getacl(talloc_tos(),
763 fsp
->fsp_name
->base_name
,
766 return map_nt_error_from_unix(errno
);
769 if (acl
->acl_version
== GPFS_ACL_VERSION_NFS4
) {
770 if (lp_parm_bool(fsp
->conn
->params
->service
, "gpfs",
771 "refuse_dacl_protected", false)
772 && (psd
->type
&SEC_DESC_DACL_PROTECTED
)) {
773 DEBUG(2, ("Rejecting unsupported ACL with DACL_PROTECTED bit set\n"));
775 return NT_STATUS_NOT_SUPPORTED
;
778 result
= smb_set_nt_acl_nfs4(handle
,
779 fsp
, security_info_sent
, psd
,
780 gpfsacl_process_smbacl
);
781 } else { /* assume POSIX ACL - by default... */
782 result
= set_nt_acl(fsp
, security_info_sent
, psd
);
789 static NTSTATUS
gpfsacl_fset_nt_acl(vfs_handle_struct
*handle
, files_struct
*fsp
, uint32_t security_info_sent
, const struct security_descriptor
*psd
)
791 struct gpfs_config_data
*config
;
793 SMB_VFS_HANDLE_GET_DATA(handle
, config
,
794 struct gpfs_config_data
,
795 return NT_STATUS_INTERNAL_ERROR
);
798 return SMB_VFS_NEXT_FSET_NT_ACL(handle
, fsp
, security_info_sent
, psd
);
801 return gpfsacl_set_nt_acl_internal(handle
, fsp
, security_info_sent
, psd
);
804 static SMB_ACL_T
gpfs2smb_acl(const struct gpfs_acl
*pacl
, TALLOC_CTX
*mem_ctx
)
809 result
= sys_acl_init(mem_ctx
);
810 if (result
== NULL
) {
815 result
->count
= pacl
->acl_nace
;
816 result
->acl
= talloc_realloc(result
, result
->acl
, struct smb_acl_entry
,
818 if (result
->acl
== NULL
) {
824 for (i
=0; i
<pacl
->acl_nace
; i
++) {
825 struct smb_acl_entry
*ace
= &result
->acl
[i
];
826 const struct gpfs_ace_v1
*g_ace
= &pacl
->ace_v1
[i
];
828 DEBUG(10, ("Converting type %d id %lu perm %x\n",
829 (int)g_ace
->ace_type
, (unsigned long)g_ace
->ace_who
,
830 (int)g_ace
->ace_perm
));
832 switch (g_ace
->ace_type
) {
834 ace
->a_type
= SMB_ACL_USER
;
835 ace
->info
.user
.uid
= (uid_t
)g_ace
->ace_who
;
837 case GPFS_ACL_USER_OBJ
:
838 ace
->a_type
= SMB_ACL_USER_OBJ
;
841 ace
->a_type
= SMB_ACL_GROUP
;
842 ace
->info
.group
.gid
= (gid_t
)g_ace
->ace_who
;
844 case GPFS_ACL_GROUP_OBJ
:
845 ace
->a_type
= SMB_ACL_GROUP_OBJ
;
848 ace
->a_type
= SMB_ACL_OTHER
;
851 ace
->a_type
= SMB_ACL_MASK
;
854 DEBUG(10, ("Got invalid ace_type: %d\n",
862 ace
->a_perm
|= (g_ace
->ace_perm
& ACL_PERM_READ
) ?
864 ace
->a_perm
|= (g_ace
->ace_perm
& ACL_PERM_WRITE
) ?
866 ace
->a_perm
|= (g_ace
->ace_perm
& ACL_PERM_EXECUTE
) ?
869 DEBUGADD(10, ("Converted to %d perm %x\n",
870 ace
->a_type
, ace
->a_perm
));
876 static SMB_ACL_T
gpfsacl_get_posix_acl(const char *path
, gpfs_aclType_t type
,
879 struct gpfs_acl
*pacl
;
880 SMB_ACL_T result
= NULL
;
882 pacl
= vfs_gpfs_getacl(talloc_tos(), path
, false, type
);
885 DEBUG(10, ("vfs_gpfs_getacl failed for %s with %s\n",
886 path
, strerror(errno
)));
893 if (pacl
->acl_version
!= GPFS_ACL_VERSION_POSIX
) {
894 DEBUG(10, ("Got acl version %d, expected %d\n",
895 pacl
->acl_version
, GPFS_ACL_VERSION_POSIX
));
900 DEBUG(10, ("len: %d, level: %d, version: %d, nace: %d\n",
901 pacl
->acl_len
, pacl
->acl_level
, pacl
->acl_version
,
904 result
= gpfs2smb_acl(pacl
, mem_ctx
);
905 if (result
!= NULL
) {
920 static SMB_ACL_T
gpfsacl_sys_acl_get_file(vfs_handle_struct
*handle
,
925 gpfs_aclType_t gpfs_type
;
926 struct gpfs_config_data
*config
;
928 SMB_VFS_HANDLE_GET_DATA(handle
, config
,
929 struct gpfs_config_data
,
933 return SMB_VFS_NEXT_SYS_ACL_GET_FILE(handle
, path_p
,
938 case SMB_ACL_TYPE_ACCESS
:
939 gpfs_type
= GPFS_ACL_TYPE_ACCESS
;
941 case SMB_ACL_TYPE_DEFAULT
:
942 gpfs_type
= GPFS_ACL_TYPE_DEFAULT
;
945 DEBUG(0, ("Got invalid type: %d\n", type
));
946 smb_panic("exiting");
949 return gpfsacl_get_posix_acl(path_p
, gpfs_type
, mem_ctx
);
952 static SMB_ACL_T
gpfsacl_sys_acl_get_fd(vfs_handle_struct
*handle
,
956 struct gpfs_config_data
*config
;
958 SMB_VFS_HANDLE_GET_DATA(handle
, config
,
959 struct gpfs_config_data
,
963 return SMB_VFS_NEXT_SYS_ACL_GET_FD(handle
, fsp
, mem_ctx
);
966 return gpfsacl_get_posix_acl(fsp
->fsp_name
->base_name
,
967 GPFS_ACL_TYPE_ACCESS
, mem_ctx
);
970 static int gpfsacl_sys_acl_blob_get_file(vfs_handle_struct
*handle
,
973 char **blob_description
,
976 struct gpfs_config_data
*config
;
977 struct gpfs_opaque_acl
*acl
= NULL
;
981 SMB_VFS_HANDLE_GET_DATA(handle
, config
,
982 struct gpfs_config_data
,
986 return SMB_VFS_NEXT_SYS_ACL_BLOB_GET_FILE(handle
, path_p
,
993 acl
= (struct gpfs_opaque_acl
*)
994 vfs_gpfs_getacl(mem_ctx
,
1000 DEBUG(5, ("vfs_gpfs_getacl finished with errno %d: %s\n",
1001 errno
, strerror(errno
)));
1003 /* EINVAL means POSIX ACL, bail out on other cases */
1004 if (errno
!= EINVAL
) {
1011 * file has NFSv4 ACL
1013 * we only need the actual ACL blob here
1014 * acl_version will always be NFS4 because we asked
1016 * acl_type is only used for POSIX ACLs
1018 aclblob
.data
= (uint8_t*) acl
->acl_var_data
;
1019 aclblob
.length
= acl
->acl_buffer_len
;
1021 *blob_description
= talloc_strdup(mem_ctx
, "gpfs_nfs4_acl");
1022 if (!*blob_description
) {
1028 result
= non_posix_sys_acl_blob_get_file_helper(handle
, path_p
,
1036 /* fall back to POSIX ACL */
1037 return posix_sys_acl_blob_get_file(handle
, path_p
, mem_ctx
,
1038 blob_description
, blob
);
1041 static int gpfsacl_sys_acl_blob_get_fd(vfs_handle_struct
*handle
,
1043 TALLOC_CTX
*mem_ctx
,
1044 char **blob_description
,
1047 struct gpfs_config_data
*config
;
1048 struct gpfs_opaque_acl
*acl
= NULL
;
1052 SMB_VFS_HANDLE_GET_DATA(handle
, config
,
1053 struct gpfs_config_data
,
1057 return SMB_VFS_NEXT_SYS_ACL_BLOB_GET_FD(handle
, fsp
, mem_ctx
,
1058 blob_description
, blob
);
1062 acl
= (struct gpfs_opaque_acl
*) vfs_gpfs_getacl(mem_ctx
,
1063 fsp
->fsp_name
->base_name
,
1065 GPFS_ACL_TYPE_NFS4
);
1068 DEBUG(5, ("vfs_gpfs_getacl finished with errno %d: %s\n",
1069 errno
, strerror(errno
)));
1071 /* EINVAL means POSIX ACL, bail out on other cases */
1072 if (errno
!= EINVAL
) {
1079 * file has NFSv4 ACL
1081 * we only need the actual ACL blob here
1082 * acl_version will always be NFS4 because we asked
1084 * acl_type is only used for POSIX ACLs
1086 aclblob
.data
= (uint8_t*) acl
->acl_var_data
;
1087 aclblob
.length
= acl
->acl_buffer_len
;
1089 *blob_description
= talloc_strdup(mem_ctx
, "gpfs_nfs4_acl");
1090 if (!*blob_description
) {
1096 result
= non_posix_sys_acl_blob_get_fd_helper(handle
, fsp
,
1104 /* fall back to POSIX ACL */
1105 return posix_sys_acl_blob_get_fd(handle
, fsp
, mem_ctx
,
1106 blob_description
, blob
);
1109 static struct gpfs_acl
*smb2gpfs_acl(const SMB_ACL_T pacl
,
1110 SMB_ACL_TYPE_T type
)
1113 struct gpfs_acl
*result
;
1116 DEBUG(10, ("smb2gpfs_acl: Got ACL with %d entries\n", pacl
->count
));
1118 len
= offsetof(gpfs_acl_t
, ace_v1
) + (pacl
->count
) *
1119 sizeof(gpfs_ace_v1_t
);
1121 result
= (struct gpfs_acl
*)SMB_MALLOC(len
);
1122 if (result
== NULL
) {
1127 result
->acl_len
= len
;
1128 result
->acl_level
= 0;
1129 result
->acl_version
= GPFS_ACL_VERSION_POSIX
;
1130 result
->acl_type
= (type
== SMB_ACL_TYPE_DEFAULT
) ?
1131 GPFS_ACL_TYPE_DEFAULT
: GPFS_ACL_TYPE_ACCESS
;
1132 result
->acl_nace
= pacl
->count
;
1134 for (i
=0; i
<pacl
->count
; i
++) {
1135 const struct smb_acl_entry
*ace
= &pacl
->acl
[i
];
1136 struct gpfs_ace_v1
*g_ace
= &result
->ace_v1
[i
];
1138 DEBUG(10, ("Converting type %d perm %x\n",
1139 (int)ace
->a_type
, (int)ace
->a_perm
));
1141 g_ace
->ace_perm
= 0;
1143 switch(ace
->a_type
) {
1145 g_ace
->ace_type
= GPFS_ACL_USER
;
1146 g_ace
->ace_who
= (gpfs_uid_t
)ace
->info
.user
.uid
;
1148 case SMB_ACL_USER_OBJ
:
1149 g_ace
->ace_type
= GPFS_ACL_USER_OBJ
;
1150 g_ace
->ace_perm
|= ACL_PERM_CONTROL
;
1154 g_ace
->ace_type
= GPFS_ACL_GROUP
;
1155 g_ace
->ace_who
= (gpfs_uid_t
)ace
->info
.group
.gid
;
1157 case SMB_ACL_GROUP_OBJ
:
1158 g_ace
->ace_type
= GPFS_ACL_GROUP_OBJ
;
1162 g_ace
->ace_type
= GPFS_ACL_MASK
;
1163 g_ace
->ace_perm
= 0x8f;
1167 g_ace
->ace_type
= GPFS_ACL_OTHER
;
1171 DEBUG(10, ("Got invalid ace_type: %d\n", ace
->a_type
));
1177 g_ace
->ace_perm
|= (ace
->a_perm
& SMB_ACL_READ
) ?
1179 g_ace
->ace_perm
|= (ace
->a_perm
& SMB_ACL_WRITE
) ?
1181 g_ace
->ace_perm
|= (ace
->a_perm
& SMB_ACL_EXECUTE
) ?
1182 ACL_PERM_EXECUTE
: 0;
1184 DEBUGADD(10, ("Converted to %d id %d perm %x\n",
1185 g_ace
->ace_type
, g_ace
->ace_who
, g_ace
->ace_perm
));
1191 static int gpfsacl_sys_acl_set_file(vfs_handle_struct
*handle
,
1193 SMB_ACL_TYPE_T type
,
1196 struct gpfs_acl
*gpfs_acl
;
1198 struct gpfs_config_data
*config
;
1200 SMB_VFS_HANDLE_GET_DATA(handle
, config
,
1201 struct gpfs_config_data
,
1205 return SMB_VFS_NEXT_SYS_ACL_SET_FILE(handle
, name
, type
, theacl
);
1208 gpfs_acl
= smb2gpfs_acl(theacl
, type
);
1209 if (gpfs_acl
== NULL
) {
1213 result
= gpfswrap_putacl(discard_const_p(char, name
),
1214 GPFS_PUTACL_STRUCT
|GPFS_ACL_SAMBA
, gpfs_acl
);
1216 SAFE_FREE(gpfs_acl
);
1220 static int gpfsacl_sys_acl_set_fd(vfs_handle_struct
*handle
,
1224 struct gpfs_config_data
*config
;
1226 SMB_VFS_HANDLE_GET_DATA(handle
, config
,
1227 struct gpfs_config_data
,
1231 return SMB_VFS_NEXT_SYS_ACL_SET_FD(handle
, fsp
, theacl
);
1234 return gpfsacl_sys_acl_set_file(handle
, fsp
->fsp_name
->base_name
,
1235 SMB_ACL_TYPE_ACCESS
, theacl
);
1238 static int gpfsacl_sys_acl_delete_def_file(vfs_handle_struct
*handle
,
1241 struct gpfs_config_data
*config
;
1243 SMB_VFS_HANDLE_GET_DATA(handle
, config
,
1244 struct gpfs_config_data
,
1248 return SMB_VFS_NEXT_SYS_ACL_DELETE_DEF_FILE(handle
, path
);
1256 * Assumed: mode bits are shiftable and standard
1257 * Output: the new aceMask field for an smb nfs4 ace
1259 static uint32_t gpfsacl_mask_filter(uint32_t aceType
, uint32_t aceMask
, uint32_t rwx
)
1261 const uint32_t posix_nfs4map
[3] = {
1262 SMB_ACE4_EXECUTE
, /* execute */
1263 SMB_ACE4_WRITE_DATA
| SMB_ACE4_APPEND_DATA
, /* write; GPFS specific */
1264 SMB_ACE4_READ_DATA
/* read */
1267 uint32_t posix_mask
= 0x01;
1271 for(i
=0; i
<3; i
++) {
1272 nfs4_bits
= posix_nfs4map
[i
];
1273 posix_bit
= rwx
& posix_mask
;
1275 if (aceType
==SMB_ACE4_ACCESS_ALLOWED_ACE_TYPE
) {
1277 aceMask
|= nfs4_bits
;
1279 aceMask
&= ~nfs4_bits
;
1281 /* add deny bits when suitable */
1283 aceMask
|= nfs4_bits
;
1285 aceMask
&= ~nfs4_bits
;
1286 } /* other ace types are unexpected */
1294 static int gpfsacl_emu_chmod(vfs_handle_struct
*handle
,
1295 const char *path
, mode_t mode
)
1297 SMB4ACL_T
*pacl
= NULL
;
1299 bool haveAllowEntry
[SMB_ACE4_WHO_EVERYONE
+ 1] = {False
, False
, False
, False
};
1301 files_struct fake_fsp
= { 0 }; /* TODO: rationalize parametrization */
1303 TALLOC_CTX
*frame
= talloc_stackframe();
1305 DEBUG(10, ("gpfsacl_emu_chmod invoked for %s mode %o\n", path
, mode
));
1307 result
= gpfs_get_nfs4_acl(frame
, path
, &pacl
);
1313 if (mode
& ~(S_IRWXU
| S_IRWXG
| S_IRWXO
)) {
1314 DEBUG(2, ("WARNING: cutting extra mode bits %o on %s\n", mode
, path
));
1317 for (smbace
=smb_first_ace4(pacl
); smbace
!=NULL
; smbace
= smb_next_ace4(smbace
)) {
1318 SMB_ACE4PROP_T
*ace
= smb_get_ace4(smbace
);
1319 uint32_t specid
= ace
->who
.special_id
;
1321 if (ace
->flags
&SMB_ACE4_ID_SPECIAL
&&
1322 ace
->aceType
<=SMB_ACE4_ACCESS_DENIED_ACE_TYPE
&&
1323 specid
<= SMB_ACE4_WHO_EVERYONE
) {
1327 if (ace
->aceType
==SMB_ACE4_ACCESS_ALLOWED_ACE_TYPE
)
1328 haveAllowEntry
[specid
] = True
;
1330 /* mode >> 6 for @owner, mode >> 3 for @group,
1331 * mode >> 0 for @everyone */
1332 newMask
= gpfsacl_mask_filter(ace
->aceType
, ace
->aceMask
,
1333 mode
>> ((SMB_ACE4_WHO_EVERYONE
- specid
) * 3));
1334 if (ace
->aceMask
!=newMask
) {
1335 DEBUG(10, ("ace changed for %s (%o -> %o) id=%d\n",
1336 path
, ace
->aceMask
, newMask
, specid
));
1338 ace
->aceMask
= newMask
;
1342 /* make sure we have at least ALLOW entries
1343 * for all the 3 special ids (@EVERYONE, @OWNER, @GROUP)
1346 for(i
= SMB_ACE4_WHO_OWNER
; i
<=SMB_ACE4_WHO_EVERYONE
; i
++) {
1347 SMB_ACE4PROP_T ace
= { 0 };
1349 if (haveAllowEntry
[i
]==True
)
1352 ace
.aceType
= SMB_ACE4_ACCESS_ALLOWED_ACE_TYPE
;
1353 ace
.flags
|= SMB_ACE4_ID_SPECIAL
;
1354 ace
.who
.special_id
= i
;
1356 if (i
==SMB_ACE4_WHO_GROUP
) /* not sure it's necessary... */
1357 ace
.aceFlags
|= SMB_ACE4_IDENTIFIER_GROUP
;
1359 ace
.aceMask
= gpfsacl_mask_filter(ace
.aceType
, ace
.aceMask
,
1360 mode
>> ((SMB_ACE4_WHO_EVERYONE
- i
) * 3));
1362 /* don't add unnecessary aces */
1366 /* we add it to the END - as windows expects allow aces */
1367 smb_add_ace4(pacl
, &ace
);
1368 DEBUG(10, ("Added ALLOW ace for %s, mode=%o, id=%d, aceMask=%x\n",
1369 path
, mode
, i
, ace
.aceMask
));
1372 /* don't add complementary DENY ACEs here */
1373 fake_fsp
.fsp_name
= synthetic_smb_fname(
1374 frame
, path
, NULL
, NULL
);
1375 if (fake_fsp
.fsp_name
== NULL
) {
1381 if (gpfsacl_process_smbacl(handle
, &fake_fsp
, pacl
) == False
) {
1387 return 0; /* ok for [f]chmod */
1390 static int vfs_gpfs_chmod(vfs_handle_struct
*handle
, const char *path
, mode_t mode
)
1392 struct smb_filename
*smb_fname_cpath
;
1395 smb_fname_cpath
= synthetic_smb_fname(talloc_tos(), path
, NULL
, NULL
);
1396 if (smb_fname_cpath
== NULL
) {
1401 if (SMB_VFS_NEXT_STAT(handle
, smb_fname_cpath
) != 0) {
1405 /* avoid chmod() if possible, to preserve acls */
1406 if ((smb_fname_cpath
->st
.st_ex_mode
& ~S_IFMT
) == mode
) {
1410 rc
= gpfsacl_emu_chmod(handle
, path
, mode
);
1412 return SMB_VFS_NEXT_CHMOD(handle
, path
, mode
);
1416 static int vfs_gpfs_fchmod(vfs_handle_struct
*handle
, files_struct
*fsp
, mode_t mode
)
1421 if (SMB_VFS_NEXT_FSTAT(handle
, fsp
, &st
) != 0) {
1425 /* avoid chmod() if possible, to preserve acls */
1426 if ((st
.st_ex_mode
& ~S_IFMT
) == mode
) {
1430 rc
= gpfsacl_emu_chmod(handle
, fsp
->fsp_name
->base_name
,
1433 return SMB_VFS_NEXT_FCHMOD(handle
, fsp
, mode
);
1437 static int gpfs_set_xattr(struct vfs_handle_struct
*handle
, const char *path
,
1438 const char *name
, const void *value
, size_t size
, int flags
){
1439 struct xattr_DOSATTRIB dosattrib
;
1440 enum ndr_err_code ndr_err
;
1442 unsigned int dosmode
=0;
1443 struct gpfs_winattr attrs
;
1445 struct gpfs_config_data
*config
;
1447 SMB_VFS_HANDLE_GET_DATA(handle
, config
,
1448 struct gpfs_config_data
,
1451 if (!config
->winattr
) {
1452 DEBUG(10, ("gpfs_set_xattr:name is %s -> next\n",name
));
1453 return SMB_VFS_NEXT_SETXATTR(handle
,path
,name
,value
,size
,flags
);
1456 DEBUG(10, ("gpfs_set_xattr: %s \n",path
));
1458 /* Only handle DOS Attributes */
1459 if (strcmp(name
,SAMBA_XATTR_DOS_ATTRIB
) != 0){
1460 DEBUG(5, ("gpfs_set_xattr:name is %s\n",name
));
1461 return SMB_VFS_NEXT_SETXATTR(handle
,path
,name
,value
,size
,flags
);
1464 blob
.data
= discard_const_p(uint8_t, value
);
1467 ndr_err
= ndr_pull_struct_blob(&blob
, talloc_tos(), &dosattrib
,
1468 (ndr_pull_flags_fn_t
)ndr_pull_xattr_DOSATTRIB
);
1470 if (!NDR_ERR_CODE_IS_SUCCESS(ndr_err
)) {
1471 DEBUG(1, ("gpfs_set_xattr: bad ndr decode "
1472 "from EA on file %s: Error = %s\n",
1473 path
, ndr_errstr(ndr_err
)));
1477 if (dosattrib
.version
!= 3) {
1478 DEBUG(1, ("gpfs_set_xattr: expected dosattrib version 3, got "
1479 "%d\n", (int)dosattrib
.version
));
1482 if (!(dosattrib
.info
.info3
.valid_flags
& XATTR_DOSINFO_ATTRIB
)) {
1483 DEBUG(10, ("gpfs_set_xattr: XATTR_DOSINFO_ATTRIB not "
1484 "valid, ignoring\n"));
1488 dosmode
= dosattrib
.info
.info3
.attrib
;
1491 /*Just map RD_ONLY, ARCHIVE, SYSTEM HIDDEN and SPARSE. Ignore the others*/
1492 if (dosmode
& FILE_ATTRIBUTE_ARCHIVE
){
1493 attrs
.winAttrs
|= GPFS_WINATTR_ARCHIVE
;
1495 if (dosmode
& FILE_ATTRIBUTE_HIDDEN
){
1496 attrs
.winAttrs
|= GPFS_WINATTR_HIDDEN
;
1498 if (dosmode
& FILE_ATTRIBUTE_SYSTEM
){
1499 attrs
.winAttrs
|= GPFS_WINATTR_SYSTEM
;
1501 if (dosmode
& FILE_ATTRIBUTE_READONLY
){
1502 attrs
.winAttrs
|= GPFS_WINATTR_READONLY
;
1504 if (dosmode
& FILE_ATTRIBUTE_SPARSE
) {
1505 attrs
.winAttrs
|= GPFS_WINATTR_SPARSE_FILE
;
1509 ret
= gpfswrap_set_winattrs_path(discard_const_p(char, path
),
1510 GPFS_WINATTR_SET_ATTRS
, &attrs
);
1512 if (errno
== ENOSYS
) {
1513 return SMB_VFS_NEXT_SETXATTR(handle
, path
, name
, value
,
1517 DEBUG(1, ("gpfs_set_xattr:Set GPFS attributes failed %d\n",ret
));
1521 DEBUG(10, ("gpfs_set_xattr:Set attributes: 0x%x\n",attrs
.winAttrs
));
1525 static ssize_t
gpfs_get_xattr(struct vfs_handle_struct
*handle
, const char *path
,
1526 const char *name
, void *value
, size_t size
){
1527 char *attrstr
= value
;
1528 unsigned int dosmode
= 0;
1529 struct gpfs_winattr attrs
;
1531 struct gpfs_config_data
*config
;
1533 SMB_VFS_HANDLE_GET_DATA(handle
, config
,
1534 struct gpfs_config_data
,
1537 if (!config
->winattr
) {
1538 DEBUG(10, ("gpfs_get_xattr:name is %s -> next\n",name
));
1539 return SMB_VFS_NEXT_GETXATTR(handle
,path
,name
,value
,size
);
1542 DEBUG(10, ("gpfs_get_xattr: %s \n",path
));
1544 /* Only handle DOS Attributes */
1545 if (strcmp(name
,SAMBA_XATTR_DOS_ATTRIB
) != 0){
1546 DEBUG(5, ("gpfs_get_xattr:name is %s\n",name
));
1547 return SMB_VFS_NEXT_GETXATTR(handle
,path
,name
,value
,size
);
1550 ret
= gpfswrap_get_winattrs_path(discard_const_p(char, path
), &attrs
);
1554 if (errno
== ENOSYS
) {
1555 return SMB_VFS_NEXT_GETXATTR(handle
, path
, name
, value
,
1559 if (errno
!= EPERM
&& errno
!= EACCES
) {
1564 DEBUG(dbg_lvl
, ("gpfs_get_xattr: Get GPFS attributes failed: "
1565 "%d (%s)\n", ret
, strerror(errno
)));
1569 DEBUG(10, ("gpfs_get_xattr:Got attributes: 0x%x\n",attrs
.winAttrs
));
1571 /*Just map RD_ONLY, ARCHIVE, SYSTEM, HIDDEN and SPARSE. Ignore the others*/
1572 if (attrs
.winAttrs
& GPFS_WINATTR_ARCHIVE
){
1573 dosmode
|= FILE_ATTRIBUTE_ARCHIVE
;
1575 if (attrs
.winAttrs
& GPFS_WINATTR_HIDDEN
){
1576 dosmode
|= FILE_ATTRIBUTE_HIDDEN
;
1578 if (attrs
.winAttrs
& GPFS_WINATTR_SYSTEM
){
1579 dosmode
|= FILE_ATTRIBUTE_SYSTEM
;
1581 if (attrs
.winAttrs
& GPFS_WINATTR_READONLY
){
1582 dosmode
|= FILE_ATTRIBUTE_READONLY
;
1584 if (attrs
.winAttrs
& GPFS_WINATTR_SPARSE_FILE
) {
1585 dosmode
|= FILE_ATTRIBUTE_SPARSE
;
1588 snprintf(attrstr
, size
, "0x%2.2x",
1589 (unsigned int)(dosmode
& SAMBA_ATTRIBUTES_MASK
));
1590 DEBUG(10, ("gpfs_get_xattr: returning %s\n",attrstr
));
1594 #if defined(HAVE_FSTATAT)
1595 static int stat_with_capability(struct vfs_handle_struct
*handle
,
1596 struct smb_filename
*smb_fname
, int flag
)
1601 const char *rel_name
= NULL
;
1605 b
= parent_dirname(talloc_tos(), smb_fname
->base_name
,
1606 &dir_name
, &rel_name
);
1612 fd
= open(dir_name
, O_RDONLY
, 0);
1613 TALLOC_FREE(dir_name
);
1618 set_effective_capability(DAC_OVERRIDE_CAPABILITY
);
1619 ret
= fstatat(fd
, rel_name
, &st
, flag
);
1620 drop_effective_capability(DAC_OVERRIDE_CAPABILITY
);
1625 init_stat_ex_from_stat(
1626 &smb_fname
->st
, &st
,
1627 lp_fake_directory_create_times(SNUM(handle
->conn
)));
1634 static int vfs_gpfs_stat(struct vfs_handle_struct
*handle
,
1635 struct smb_filename
*smb_fname
)
1637 struct gpfs_winattr attrs
;
1641 struct gpfs_config_data
*config
;
1643 SMB_VFS_HANDLE_GET_DATA(handle
, config
,
1644 struct gpfs_config_data
,
1647 ret
= SMB_VFS_NEXT_STAT(handle
, smb_fname
);
1648 #if defined(HAVE_FSTATAT)
1649 if (ret
== -1 && errno
== EACCES
) {
1650 DEBUG(10, ("Trying stat with capability for %s\n",
1651 smb_fname
->base_name
));
1652 ret
= stat_with_capability(handle
, smb_fname
, 0);
1659 if (!config
->winattr
) {
1663 status
= get_full_smb_filename(talloc_tos(), smb_fname
, &fname
);
1664 if (!NT_STATUS_IS_OK(status
)) {
1665 errno
= map_errno_from_nt_status(status
);
1668 ret
= gpfswrap_get_winattrs_path(discard_const_p(char, fname
), &attrs
);
1671 smb_fname
->st
.st_ex_calculated_birthtime
= false;
1672 smb_fname
->st
.st_ex_btime
.tv_sec
= attrs
.creationTime
.tv_sec
;
1673 smb_fname
->st
.st_ex_btime
.tv_nsec
= attrs
.creationTime
.tv_nsec
;
1678 static int vfs_gpfs_fstat(struct vfs_handle_struct
*handle
,
1679 struct files_struct
*fsp
, SMB_STRUCT_STAT
*sbuf
)
1681 struct gpfs_winattr attrs
;
1683 struct gpfs_config_data
*config
;
1685 SMB_VFS_HANDLE_GET_DATA(handle
, config
,
1686 struct gpfs_config_data
,
1689 ret
= SMB_VFS_NEXT_FSTAT(handle
, fsp
, sbuf
);
1693 if ((fsp
->fh
== NULL
) || (fsp
->fh
->fd
== -1)) {
1696 if (!config
->winattr
) {
1700 ret
= gpfswrap_get_winattrs(fsp
->fh
->fd
, &attrs
);
1702 sbuf
->st_ex_calculated_birthtime
= false;
1703 sbuf
->st_ex_btime
.tv_sec
= attrs
.creationTime
.tv_sec
;
1704 sbuf
->st_ex_btime
.tv_nsec
= attrs
.creationTime
.tv_nsec
;
1709 static int vfs_gpfs_lstat(struct vfs_handle_struct
*handle
,
1710 struct smb_filename
*smb_fname
)
1712 struct gpfs_winattr attrs
;
1716 struct gpfs_config_data
*config
;
1718 SMB_VFS_HANDLE_GET_DATA(handle
, config
,
1719 struct gpfs_config_data
,
1722 ret
= SMB_VFS_NEXT_LSTAT(handle
, smb_fname
);
1723 #if defined(HAVE_FSTATAT)
1724 if (ret
== -1 && errno
== EACCES
) {
1725 DEBUG(10, ("Trying lstat with capability for %s\n",
1726 smb_fname
->base_name
));
1727 ret
= stat_with_capability(handle
, smb_fname
,
1728 AT_SYMLINK_NOFOLLOW
);
1735 if (!config
->winattr
) {
1739 status
= get_full_smb_filename(talloc_tos(), smb_fname
, &path
);
1740 if (!NT_STATUS_IS_OK(status
)) {
1741 errno
= map_errno_from_nt_status(status
);
1744 ret
= gpfswrap_get_winattrs_path(discard_const_p(char, path
), &attrs
);
1747 smb_fname
->st
.st_ex_calculated_birthtime
= false;
1748 smb_fname
->st
.st_ex_btime
.tv_sec
= attrs
.creationTime
.tv_sec
;
1749 smb_fname
->st
.st_ex_btime
.tv_nsec
= attrs
.creationTime
.tv_nsec
;
1754 static void timespec_to_gpfs_time(struct timespec ts
, gpfs_timestruc_t
*gt
,
1755 int idx
, int *flags
)
1757 if (!null_timespec(ts
)) {
1759 gt
[idx
].tv_sec
= ts
.tv_sec
;
1760 gt
[idx
].tv_nsec
= ts
.tv_nsec
;
1761 DEBUG(10, ("Setting GPFS time %d, flags 0x%x\n", idx
, *flags
));
1765 static int smbd_gpfs_set_times_path(char *path
, struct smb_file_time
*ft
)
1767 gpfs_timestruc_t gpfs_times
[4];
1771 ZERO_ARRAY(gpfs_times
);
1772 timespec_to_gpfs_time(ft
->atime
, gpfs_times
, 0, &flags
);
1773 timespec_to_gpfs_time(ft
->mtime
, gpfs_times
, 1, &flags
);
1774 /* No good mapping from LastChangeTime to ctime, not storing */
1775 timespec_to_gpfs_time(ft
->create_time
, gpfs_times
, 3, &flags
);
1778 DEBUG(10, ("nothing to do, return to avoid EINVAL\n"));
1782 rc
= gpfswrap_set_times_path(path
, flags
, gpfs_times
);
1784 if (rc
!= 0 && errno
!= ENOSYS
) {
1785 DEBUG(1,("gpfs_set_times() returned with error %s\n",
1792 static int vfs_gpfs_ntimes(struct vfs_handle_struct
*handle
,
1793 const struct smb_filename
*smb_fname
,
1794 struct smb_file_time
*ft
)
1797 struct gpfs_winattr attrs
;
1801 struct gpfs_config_data
*config
;
1803 SMB_VFS_HANDLE_GET_DATA(handle
, config
,
1804 struct gpfs_config_data
,
1807 status
= get_full_smb_filename(talloc_tos(), smb_fname
, &path
);
1808 if (!NT_STATUS_IS_OK(status
)) {
1809 errno
= map_errno_from_nt_status(status
);
1813 /* Try to use gpfs_set_times if it is enabled and available */
1814 if (config
->settimes
) {
1815 ret
= smbd_gpfs_set_times_path(path
, ft
);
1817 if (ret
== 0 || (ret
== -1 && errno
!= ENOSYS
)) {
1822 DEBUG(10,("gpfs_set_times() not available or disabled, "
1823 "use ntimes and winattr\n"));
1825 ret
= SMB_VFS_NEXT_NTIMES(handle
, smb_fname
, ft
);
1827 /* don't complain if access was denied */
1828 if (errno
!= EPERM
&& errno
!= EACCES
) {
1829 DEBUG(1,("vfs_gpfs_ntimes: SMB_VFS_NEXT_NTIMES failed:"
1830 "%s", strerror(errno
)));
1835 if(null_timespec(ft
->create_time
)){
1836 DEBUG(10,("vfs_gpfs_ntimes:Create Time is NULL\n"));
1840 if (!config
->winattr
) {
1845 attrs
.creationTime
.tv_sec
= ft
->create_time
.tv_sec
;
1846 attrs
.creationTime
.tv_nsec
= ft
->create_time
.tv_nsec
;
1848 ret
= gpfswrap_set_winattrs_path(discard_const_p(char, path
),
1849 GPFS_WINATTR_SET_CREATION_TIME
,
1851 if(ret
== -1 && errno
!= ENOSYS
){
1852 DEBUG(1,("vfs_gpfs_ntimes: set GPFS ntimes failed %d\n",ret
));
1859 static int vfs_gpfs_fallocate(struct vfs_handle_struct
*handle
,
1860 struct files_struct
*fsp
, uint32_t mode
,
1861 off_t offset
, off_t len
)
1864 struct gpfs_config_data
*config
;
1866 SMB_VFS_HANDLE_GET_DATA(handle
, config
,
1867 struct gpfs_config_data
,
1870 if (!config
->prealloc
) {
1871 /* you should better not run fallocate() on GPFS at all */
1877 DEBUG(10, ("unmapped fallocate flags: %lx\n",
1878 (unsigned long)mode
));
1883 ret
= gpfswrap_prealloc(fsp
->fh
->fd
, offset
, len
);
1885 if (ret
== -1 && errno
!= ENOSYS
) {
1886 DEBUG(0, ("GPFS prealloc failed: %s\n", strerror(errno
)));
1887 } else if (ret
== -1 && errno
== ENOSYS
) {
1888 DEBUG(10, ("GPFS prealloc not supported.\n"));
1890 DEBUG(10, ("GPFS prealloc succeeded.\n"));
1896 static int vfs_gpfs_ftruncate(vfs_handle_struct
*handle
, files_struct
*fsp
,
1900 struct gpfs_config_data
*config
;
1902 SMB_VFS_HANDLE_GET_DATA(handle
, config
,
1903 struct gpfs_config_data
,
1906 if (!config
->ftruncate
) {
1907 return SMB_VFS_NEXT_FTRUNCATE(handle
, fsp
, len
);
1910 result
= gpfswrap_ftruncate(fsp
->fh
->fd
, len
);
1911 if ((result
== -1) && (errno
== ENOSYS
)) {
1912 return SMB_VFS_NEXT_FTRUNCATE(handle
, fsp
, len
);
1917 static bool vfs_gpfs_is_offline(struct vfs_handle_struct
*handle
,
1918 const struct smb_filename
*fname
,
1919 SMB_STRUCT_STAT
*sbuf
)
1921 struct gpfs_winattr attrs
;
1924 struct gpfs_config_data
*config
;
1927 SMB_VFS_HANDLE_GET_DATA(handle
, config
,
1928 struct gpfs_config_data
,
1931 if (!config
->winattr
) {
1932 return SMB_VFS_NEXT_IS_OFFLINE(handle
, fname
, sbuf
);
1935 status
= get_full_smb_filename(talloc_tos(), fname
, &path
);
1936 if (!NT_STATUS_IS_OK(status
)) {
1937 errno
= map_errno_from_nt_status(status
);
1941 ret
= gpfswrap_get_winattrs_path(path
, &attrs
);
1947 if ((attrs
.winAttrs
& GPFS_WINATTR_OFFLINE
) != 0) {
1948 DEBUG(10, ("%s is offline\n", path
));
1952 DEBUG(10, ("%s is online\n", path
));
1954 return SMB_VFS_NEXT_IS_OFFLINE(handle
, fname
, sbuf
);
1957 static bool vfs_gpfs_aio_force(struct vfs_handle_struct
*handle
,
1958 struct files_struct
*fsp
)
1960 return vfs_gpfs_is_offline(handle
, fsp
->fsp_name
, &fsp
->fsp_name
->st
);
1963 static ssize_t
vfs_gpfs_sendfile(vfs_handle_struct
*handle
, int tofd
,
1964 files_struct
*fsp
, const DATA_BLOB
*hdr
,
1965 off_t offset
, size_t n
)
1967 if (SMB_VFS_IS_OFFLINE(handle
->conn
, fsp
->fsp_name
, &fsp
->fsp_name
->st
))
1972 return SMB_VFS_NEXT_SENDFILE(handle
, tofd
, fsp
, hdr
, offset
, n
);
1975 static int vfs_gpfs_connect(struct vfs_handle_struct
*handle
,
1976 const char *service
, const char *user
)
1978 struct gpfs_config_data
*config
;
1981 gpfswrap_lib_init(0);
1983 config
= talloc_zero(handle
->conn
, struct gpfs_config_data
);
1985 DEBUG(0, ("talloc_zero() failed\n"));
1990 ret
= SMB_VFS_NEXT_CONNECT(handle
, service
, user
);
1992 TALLOC_FREE(config
);
1996 config
->sharemodes
= lp_parm_bool(SNUM(handle
->conn
), "gpfs",
1997 "sharemodes", true);
1999 config
->leases
= lp_parm_bool(SNUM(handle
->conn
), "gpfs",
2002 config
->hsm
= lp_parm_bool(SNUM(handle
->conn
), "gpfs",
2005 config
->syncio
= lp_parm_bool(SNUM(handle
->conn
), "gpfs",
2008 config
->winattr
= lp_parm_bool(SNUM(handle
->conn
), "gpfs",
2011 config
->ftruncate
= lp_parm_bool(SNUM(handle
->conn
), "gpfs",
2014 config
->getrealfilename
= lp_parm_bool(SNUM(handle
->conn
), "gpfs",
2015 "getrealfilename", true);
2017 config
->dfreequota
= lp_parm_bool(SNUM(handle
->conn
), "gpfs",
2018 "dfreequota", false);
2020 config
->prealloc
= lp_parm_bool(SNUM(handle
->conn
), "gpfs",
2023 config
->acl
= lp_parm_bool(SNUM(handle
->conn
), "gpfs", "acl", true);
2025 config
->settimes
= lp_parm_bool(SNUM(handle
->conn
), "gpfs",
2027 config
->recalls
= lp_parm_bool(SNUM(handle
->conn
), "gpfs",
2030 SMB_VFS_HANDLE_SET_DATA(handle
, config
,
2031 NULL
, struct gpfs_config_data
,
2034 if (config
->leases
) {
2036 * GPFS lease code is based on kernel oplock code
2037 * so make sure it is turned on
2039 if (!lp_kernel_oplocks(SNUM(handle
->conn
))) {
2040 DEBUG(5, ("Enabling kernel oplocks for "
2041 "gpfs:leases to work\n"));
2042 lp_do_parameter(SNUM(handle
->conn
), "kernel oplocks",
2047 * as the kernel does not properly support Level II oplocks
2048 * and GPFS leases code is based on kernel infrastructure, we
2049 * need to turn off Level II oplocks if gpfs:leases is enabled
2051 if (lp_level2_oplocks(SNUM(handle
->conn
))) {
2052 DEBUG(5, ("gpfs:leases are enabled, disabling "
2053 "Level II oplocks\n"));
2054 lp_do_parameter(SNUM(handle
->conn
), "level2 oplocks",
2062 static int get_gpfs_quota(const char *pathname
, int type
, int id
,
2063 struct gpfs_quotaInfo
*qi
)
2067 ret
= gpfswrap_quotactl(discard_const_p(char, pathname
),
2068 GPFS_QCMD(Q_GETQUOTA
, type
), id
, qi
);
2071 if (errno
== GPFS_E_NO_QUOTA_INST
) {
2072 DEBUG(10, ("Quotas disabled on GPFS filesystem.\n"));
2073 } else if (errno
!= ENOSYS
) {
2074 DEBUG(0, ("Get quota failed, type %d, id, %d, "
2075 "errno %d.\n", type
, id
, errno
));
2081 DEBUG(10, ("quota type %d, id %d, blk u:%lld h:%lld s:%lld gt:%u\n",
2082 type
, id
, qi
->blockUsage
, qi
->blockHardLimit
,
2083 qi
->blockSoftLimit
, qi
->blockGraceTime
));
2088 static void vfs_gpfs_disk_free_quota(struct gpfs_quotaInfo qi
, time_t cur_time
,
2089 uint64_t *dfree
, uint64_t *dsize
)
2091 uint64_t usage
, limit
;
2094 * The quota reporting is done in units of 1024 byte blocks, but
2095 * sys_fsusage uses units of 512 byte blocks, adjust the block number
2096 * accordingly. Also filter possibly negative usage counts from gpfs.
2098 usage
= qi
.blockUsage
< 0 ? 0 : (uint64_t)qi
.blockUsage
* 2;
2099 limit
= (uint64_t)qi
.blockHardLimit
* 2;
2102 * When the grace time for the exceeded soft block quota has been
2103 * exceeded, the soft block quota becomes an additional hard limit.
2105 if (qi
.blockSoftLimit
&&
2106 qi
.blockGraceTime
&& cur_time
> qi
.blockGraceTime
) {
2107 /* report disk as full */
2109 *dsize
= MIN(*dsize
, usage
);
2112 if (!qi
.blockHardLimit
)
2115 if (usage
>= limit
) {
2116 /* report disk as full */
2118 *dsize
= MIN(*dsize
, usage
);
2121 /* limit has not been reached, determine "free space" */
2122 *dfree
= MIN(*dfree
, limit
- usage
);
2123 *dsize
= MIN(*dsize
, limit
);
2127 static uint64_t vfs_gpfs_disk_free(vfs_handle_struct
*handle
, const char *path
,
2129 uint64_t *dfree
, uint64_t *dsize
)
2131 struct security_unix_token
*utok
;
2132 struct gpfs_quotaInfo qi_user
= { 0 }, qi_group
= { 0 };
2133 struct gpfs_config_data
*config
;
2137 SMB_VFS_HANDLE_GET_DATA(handle
, config
, struct gpfs_config_data
,
2138 return (uint64_t)-1);
2139 if (!config
->dfreequota
) {
2140 return SMB_VFS_NEXT_DISK_FREE(handle
, path
,
2141 bsize
, dfree
, dsize
);
2144 err
= sys_fsusage(path
, dfree
, dsize
);
2146 DEBUG (0, ("Could not get fs usage, errno %d\n", errno
));
2147 return SMB_VFS_NEXT_DISK_FREE(handle
, path
,
2148 bsize
, dfree
, dsize
);
2151 /* sys_fsusage returns units of 512 bytes */
2154 DEBUG(10, ("fs dfree %llu, dsize %llu\n",
2155 (unsigned long long)*dfree
, (unsigned long long)*dsize
));
2157 utok
= handle
->conn
->session_info
->unix_token
;
2159 err
= get_gpfs_quota(path
, GPFS_USRQUOTA
, utok
->uid
, &qi_user
);
2161 return SMB_VFS_NEXT_DISK_FREE(handle
, path
,
2162 bsize
, dfree
, dsize
);
2165 err
= get_gpfs_quota(path
, GPFS_GRPQUOTA
, utok
->gid
, &qi_group
);
2167 return SMB_VFS_NEXT_DISK_FREE(handle
, path
,
2168 bsize
, dfree
, dsize
);
2171 cur_time
= time(NULL
);
2173 /* Adjust free space and size according to quota limits. */
2174 vfs_gpfs_disk_free_quota(qi_user
, cur_time
, dfree
, dsize
);
2175 vfs_gpfs_disk_free_quota(qi_group
, cur_time
, dfree
, dsize
);
2177 disk_norm(bsize
, dfree
, dsize
);
2181 static uint32_t vfs_gpfs_capabilities(struct vfs_handle_struct
*handle
,
2182 enum timestamp_set_resolution
*p_ts_res
)
2184 struct gpfs_config_data
*config
;
2187 next
= SMB_VFS_NEXT_FS_CAPABILITIES(handle
, p_ts_res
);
2189 SMB_VFS_HANDLE_GET_DATA(handle
, config
,
2190 struct gpfs_config_data
,
2194 next
|= FILE_SUPPORTS_REMOTE_STORAGE
;
2199 static int vfs_gpfs_open(struct vfs_handle_struct
*handle
,
2200 struct smb_filename
*smb_fname
, files_struct
*fsp
,
2201 int flags
, mode_t mode
)
2203 struct gpfs_config_data
*config
;
2205 SMB_VFS_HANDLE_GET_DATA(handle
, config
,
2206 struct gpfs_config_data
,
2209 if (config
->hsm
&& !config
->recalls
) {
2210 if (SMB_VFS_IS_OFFLINE(handle
->conn
, smb_fname
, &smb_fname
->st
))
2212 DEBUG(10, ("Refusing access to offline file %s\n",
2219 if (config
->syncio
) {
2222 return SMB_VFS_NEXT_OPEN(handle
, smb_fname
, fsp
, flags
, mode
);
2225 static ssize_t
vfs_gpfs_pread(vfs_handle_struct
*handle
, files_struct
*fsp
,
2226 void *data
, size_t n
, off_t offset
)
2231 was_offline
= SMB_VFS_IS_OFFLINE(handle
->conn
, fsp
->fsp_name
,
2232 &fsp
->fsp_name
->st
);
2234 ret
= SMB_VFS_NEXT_PREAD(handle
, fsp
, data
, n
, offset
);
2236 if ((ret
!= -1) && was_offline
) {
2237 notify_fname(handle
->conn
, NOTIFY_ACTION_MODIFIED
,
2238 FILE_NOTIFY_CHANGE_ATTRIBUTES
,
2239 fsp
->fsp_name
->base_name
);
2245 struct vfs_gpfs_pread_state
{
2246 struct files_struct
*fsp
;
2252 static void vfs_gpfs_pread_done(struct tevent_req
*subreq
);
2254 static struct tevent_req
*vfs_gpfs_pread_send(struct vfs_handle_struct
*handle
,
2255 TALLOC_CTX
*mem_ctx
,
2256 struct tevent_context
*ev
,
2257 struct files_struct
*fsp
,
2258 void *data
, size_t n
,
2261 struct tevent_req
*req
, *subreq
;
2262 struct vfs_gpfs_pread_state
*state
;
2264 req
= tevent_req_create(mem_ctx
, &state
, struct vfs_gpfs_pread_state
);
2268 state
->was_offline
= SMB_VFS_IS_OFFLINE(handle
->conn
, fsp
->fsp_name
,
2269 &fsp
->fsp_name
->st
);
2271 subreq
= SMB_VFS_NEXT_PREAD_SEND(state
, ev
, handle
, fsp
, data
,
2273 if (tevent_req_nomem(subreq
, req
)) {
2274 return tevent_req_post(req
, ev
);
2276 tevent_req_set_callback(subreq
, vfs_gpfs_pread_done
, req
);
2280 static void vfs_gpfs_pread_done(struct tevent_req
*subreq
)
2282 struct tevent_req
*req
= tevent_req_callback_data(
2283 subreq
, struct tevent_req
);
2284 struct vfs_gpfs_pread_state
*state
= tevent_req_data(
2285 req
, struct vfs_gpfs_pread_state
);
2287 state
->ret
= SMB_VFS_PREAD_RECV(subreq
, &state
->err
);
2288 TALLOC_FREE(subreq
);
2289 tevent_req_done(req
);
2292 static ssize_t
vfs_gpfs_pread_recv(struct tevent_req
*req
, int *err
)
2294 struct vfs_gpfs_pread_state
*state
= tevent_req_data(
2295 req
, struct vfs_gpfs_pread_state
);
2296 struct files_struct
*fsp
= state
->fsp
;
2298 if (tevent_req_is_unix_error(req
, err
)) {
2303 if ((state
->ret
!= -1) && state
->was_offline
) {
2304 DEBUG(10, ("sending notify\n"));
2305 notify_fname(fsp
->conn
, NOTIFY_ACTION_MODIFIED
,
2306 FILE_NOTIFY_CHANGE_ATTRIBUTES
,
2307 fsp
->fsp_name
->base_name
);
2313 static ssize_t
vfs_gpfs_pwrite(vfs_handle_struct
*handle
, files_struct
*fsp
,
2314 const void *data
, size_t n
, off_t offset
)
2319 was_offline
= SMB_VFS_IS_OFFLINE(handle
->conn
, fsp
->fsp_name
,
2320 &fsp
->fsp_name
->st
);
2322 ret
= SMB_VFS_NEXT_PWRITE(handle
, fsp
, data
, n
, offset
);
2324 if ((ret
!= -1) && was_offline
) {
2325 notify_fname(handle
->conn
, NOTIFY_ACTION_MODIFIED
,
2326 FILE_NOTIFY_CHANGE_ATTRIBUTES
,
2327 fsp
->fsp_name
->base_name
);
2333 struct vfs_gpfs_pwrite_state
{
2334 struct files_struct
*fsp
;
2340 static void vfs_gpfs_pwrite_done(struct tevent_req
*subreq
);
2342 static struct tevent_req
*vfs_gpfs_pwrite_send(
2343 struct vfs_handle_struct
*handle
,
2344 TALLOC_CTX
*mem_ctx
,
2345 struct tevent_context
*ev
,
2346 struct files_struct
*fsp
,
2347 const void *data
, size_t n
,
2350 struct tevent_req
*req
, *subreq
;
2351 struct vfs_gpfs_pwrite_state
*state
;
2353 req
= tevent_req_create(mem_ctx
, &state
, struct vfs_gpfs_pwrite_state
);
2357 state
->was_offline
= SMB_VFS_IS_OFFLINE(handle
->conn
, fsp
->fsp_name
,
2358 &fsp
->fsp_name
->st
);
2360 subreq
= SMB_VFS_NEXT_PWRITE_SEND(state
, ev
, handle
, fsp
, data
,
2362 if (tevent_req_nomem(subreq
, req
)) {
2363 return tevent_req_post(req
, ev
);
2365 tevent_req_set_callback(subreq
, vfs_gpfs_pwrite_done
, req
);
2369 static void vfs_gpfs_pwrite_done(struct tevent_req
*subreq
)
2371 struct tevent_req
*req
= tevent_req_callback_data(
2372 subreq
, struct tevent_req
);
2373 struct vfs_gpfs_pwrite_state
*state
= tevent_req_data(
2374 req
, struct vfs_gpfs_pwrite_state
);
2376 state
->ret
= SMB_VFS_PWRITE_RECV(subreq
, &state
->err
);
2377 TALLOC_FREE(subreq
);
2378 tevent_req_done(req
);
2381 static ssize_t
vfs_gpfs_pwrite_recv(struct tevent_req
*req
, int *err
)
2383 struct vfs_gpfs_pwrite_state
*state
= tevent_req_data(
2384 req
, struct vfs_gpfs_pwrite_state
);
2385 struct files_struct
*fsp
= state
->fsp
;
2387 if (tevent_req_is_unix_error(req
, err
)) {
2392 if ((state
->ret
!= -1) && state
->was_offline
) {
2393 DEBUG(10, ("sending notify\n"));
2394 notify_fname(fsp
->conn
, NOTIFY_ACTION_MODIFIED
,
2395 FILE_NOTIFY_CHANGE_ATTRIBUTES
,
2396 fsp
->fsp_name
->base_name
);
2403 static struct vfs_fn_pointers vfs_gpfs_fns
= {
2404 .connect_fn
= vfs_gpfs_connect
,
2405 .disk_free_fn
= vfs_gpfs_disk_free
,
2406 .fs_capabilities_fn
= vfs_gpfs_capabilities
,
2407 .kernel_flock_fn
= vfs_gpfs_kernel_flock
,
2408 .linux_setlease_fn
= vfs_gpfs_setlease
,
2409 .get_real_filename_fn
= vfs_gpfs_get_real_filename
,
2410 .fget_nt_acl_fn
= gpfsacl_fget_nt_acl
,
2411 .get_nt_acl_fn
= gpfsacl_get_nt_acl
,
2412 .fset_nt_acl_fn
= gpfsacl_fset_nt_acl
,
2413 .sys_acl_get_file_fn
= gpfsacl_sys_acl_get_file
,
2414 .sys_acl_get_fd_fn
= gpfsacl_sys_acl_get_fd
,
2415 .sys_acl_blob_get_file_fn
= gpfsacl_sys_acl_blob_get_file
,
2416 .sys_acl_blob_get_fd_fn
= gpfsacl_sys_acl_blob_get_fd
,
2417 .sys_acl_set_file_fn
= gpfsacl_sys_acl_set_file
,
2418 .sys_acl_set_fd_fn
= gpfsacl_sys_acl_set_fd
,
2419 .sys_acl_delete_def_file_fn
= gpfsacl_sys_acl_delete_def_file
,
2420 .chmod_fn
= vfs_gpfs_chmod
,
2421 .fchmod_fn
= vfs_gpfs_fchmod
,
2422 .close_fn
= vfs_gpfs_close
,
2423 .setxattr_fn
= gpfs_set_xattr
,
2424 .getxattr_fn
= gpfs_get_xattr
,
2425 .stat_fn
= vfs_gpfs_stat
,
2426 .fstat_fn
= vfs_gpfs_fstat
,
2427 .lstat_fn
= vfs_gpfs_lstat
,
2428 .ntimes_fn
= vfs_gpfs_ntimes
,
2429 .is_offline_fn
= vfs_gpfs_is_offline
,
2430 .aio_force_fn
= vfs_gpfs_aio_force
,
2431 .sendfile_fn
= vfs_gpfs_sendfile
,
2432 .fallocate_fn
= vfs_gpfs_fallocate
,
2433 .open_fn
= vfs_gpfs_open
,
2434 .pread_fn
= vfs_gpfs_pread
,
2435 .pread_send_fn
= vfs_gpfs_pread_send
,
2436 .pread_recv_fn
= vfs_gpfs_pread_recv
,
2437 .pwrite_fn
= vfs_gpfs_pwrite
,
2438 .pwrite_send_fn
= vfs_gpfs_pwrite_send
,
2439 .pwrite_recv_fn
= vfs_gpfs_pwrite_recv
,
2440 .ftruncate_fn
= vfs_gpfs_ftruncate
2443 NTSTATUS
vfs_gpfs_init(void);
2444 NTSTATUS
vfs_gpfs_init(void)
2448 ret
= gpfswrap_init();
2450 DEBUG(1, ("Could not initialize GPFS library wrapper\n"));
2453 return smb_register_vfs(SMB_VFS_INTERFACE_VERSION
, "gpfs",