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
== 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_t access_mask
,
77 uint32_t share_access
)
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_t share_mode
, uint32_t access_mask
)
125 struct gpfs_config_data
*config
;
128 SMB_VFS_HANDLE_GET_DATA(handle
, config
,
129 struct gpfs_config_data
,
132 if(!config
->sharemodes
) {
137 * A named stream fsp will have the basefile open in the fsp
138 * fd, so lacking a distinct fd for the stream we have to skip
139 * kernel_flock and set_gpfs_sharemode for stream.
141 if (!is_ntfs_default_stream_smb_fname(fsp
->fsp_name
)) {
142 DEBUG(2,("%s: kernel_flock on stream\n", fsp_str_dbg(fsp
)));
146 START_PROFILE(syscall_kernel_flock
);
148 kernel_flock(fsp
->fh
->fd
, share_mode
, access_mask
);
150 if (!set_gpfs_sharemode(fsp
, access_mask
, fsp
->share_access
)) {
154 END_PROFILE(syscall_kernel_flock
);
159 static int vfs_gpfs_close(vfs_handle_struct
*handle
, files_struct
*fsp
)
162 struct gpfs_config_data
*config
;
164 SMB_VFS_HANDLE_GET_DATA(handle
, config
,
165 struct gpfs_config_data
,
168 if (config
->sharemodes
&& (fsp
->fh
!= NULL
) && (fsp
->fh
->fd
!= -1)) {
169 set_gpfs_sharemode(fsp
, 0, 0);
172 return SMB_VFS_NEXT_CLOSE(handle
, fsp
);
175 static int set_gpfs_lease(int fd
, int leasetype
)
177 int gpfs_type
= GPFS_LEASE_NONE
;
179 if (leasetype
== F_RDLCK
) {
180 gpfs_type
= GPFS_LEASE_READ
;
182 if (leasetype
== F_WRLCK
) {
183 gpfs_type
= GPFS_LEASE_WRITE
;
186 /* we unconditionally set CAP_LEASE, rather than looking for
187 -1/EACCES as there is a bug in some versions of
188 libgpfs_gpl.so which results in a leaked fd on /dev/ss0
189 each time we try this with the wrong capabilities set
191 linux_set_lease_capability();
192 return gpfswrap_set_lease(fd
, gpfs_type
);
195 static int vfs_gpfs_setlease(vfs_handle_struct
*handle
, files_struct
*fsp
,
198 struct gpfs_config_data
*config
;
201 SMB_VFS_HANDLE_GET_DATA(handle
, config
,
202 struct gpfs_config_data
,
205 START_PROFILE(syscall_linux_setlease
);
207 if (linux_set_lease_sighandler(fsp
->fh
->fd
) == -1) {
212 if (config
->leases
) {
214 * Ensure the lease owner is root to allow
215 * correct delivery of lease-break signals.
218 ret
= set_gpfs_lease(fsp
->fh
->fd
,leasetype
);
222 END_PROFILE(syscall_linux_setlease
);
228 static int vfs_gpfs_get_real_filename(struct vfs_handle_struct
*handle
,
236 char real_pathname
[PATH_MAX
+1];
239 struct gpfs_config_data
*config
;
241 SMB_VFS_HANDLE_GET_DATA(handle
, config
,
242 struct gpfs_config_data
,
245 if (!config
->getrealfilename
) {
246 return SMB_VFS_NEXT_GET_REAL_FILENAME(handle
, path
, name
,
247 mem_ctx
, found_name
);
250 mangled
= mangle_is_mangled(name
, handle
->conn
->params
);
252 return SMB_VFS_NEXT_GET_REAL_FILENAME(handle
, path
, name
,
253 mem_ctx
, found_name
);
256 full_path
= talloc_asprintf(talloc_tos(), "%s/%s", path
, name
);
257 if (full_path
== NULL
) {
262 buflen
= sizeof(real_pathname
) - 1;
264 result
= gpfswrap_get_realfilename_path(full_path
, real_pathname
,
267 TALLOC_FREE(full_path
);
269 if ((result
== -1) && (errno
== ENOSYS
)) {
270 return SMB_VFS_NEXT_GET_REAL_FILENAME(
271 handle
, path
, name
, mem_ctx
, found_name
);
275 DEBUG(10, ("smbd_gpfs_get_realfilename_path returned %s\n",
281 * GPFS does not necessarily null-terminate the returned path
282 * but instead returns the buffer length in buflen.
285 if (buflen
< sizeof(real_pathname
)) {
286 real_pathname
[buflen
] = '\0';
288 real_pathname
[sizeof(real_pathname
)-1] = '\0';
291 DEBUG(10, ("smbd_gpfs_get_realfilename_path: %s/%s -> %s\n",
292 path
, name
, real_pathname
));
294 name
= strrchr_m(real_pathname
, '/');
300 *found_name
= talloc_strdup(mem_ctx
, name
+1);
301 if (*found_name
== NULL
) {
309 static void sd2gpfs_control(uint16_t control
, struct gpfs_acl
*gacl
)
311 unsigned int gpfs_aclflags
= 0;
312 control
&= SEC_DESC_DACL_PROTECTED
| SEC_DESC_SACL_PROTECTED
|
313 SEC_DESC_DACL_AUTO_INHERITED
| SEC_DESC_SACL_AUTO_INHERITED
|
314 SEC_DESC_DACL_DEFAULTED
| SEC_DESC_SACL_DEFAULTED
|
315 SEC_DESC_DACL_PRESENT
| SEC_DESC_SACL_PRESENT
;
316 gpfs_aclflags
= control
<< 8;
317 if (!(control
& SEC_DESC_DACL_PRESENT
))
318 gpfs_aclflags
|= 0x00800000; /* ACL4_FLAG_NULL_DACL; */
319 if (!(control
& SEC_DESC_SACL_PRESENT
))
320 gpfs_aclflags
|= 0x01000000; /* ACL4_FLAG_NULL_SACL; */
321 gacl
->acl_level
= 1; /* GPFS_ACL_LEVEL_V4FLAGS*/
322 /* gacl->v4Level1.acl_flags requires gpfs 3.5 */
323 *(unsigned int *)&gacl
->ace_v4
= gpfs_aclflags
;
326 static uint16_t gpfs2sd_control(unsigned int gpfs_aclflags
)
328 uint16_t control
= gpfs_aclflags
>> 8;
329 control
&= SEC_DESC_DACL_PROTECTED
| SEC_DESC_SACL_PROTECTED
|
330 SEC_DESC_DACL_AUTO_INHERITED
| SEC_DESC_SACL_AUTO_INHERITED
|
331 SEC_DESC_DACL_DEFAULTED
| SEC_DESC_SACL_DEFAULTED
|
332 SEC_DESC_DACL_PRESENT
| SEC_DESC_SACL_PRESENT
;
333 control
|= SEC_DESC_SELF_RELATIVE
;
337 static void gpfs_dumpacl(int level
, struct gpfs_acl
*gacl
)
342 DEBUG(0, ("gpfs acl is NULL\n"));
346 DEBUG(level
, ("len: %d, level: %d, version: %d, nace: %d, "
348 gacl
->acl_len
, gacl
->acl_level
, gacl
->acl_version
,
349 gacl
->acl_nace
, gpfs_acl_flags(gacl
)));
351 for(i
=0; i
<gacl
->acl_nace
; i
++)
353 struct gpfs_ace_v4
*gace
= gpfs_ace_ptr(gacl
, i
);
354 DEBUG(level
, ("\tace[%d]: type:%d, flags:0x%x, mask:0x%x, "
355 "iflags:0x%x, who:%u\n",
356 i
, gace
->aceType
, gace
->aceFlags
, gace
->aceMask
,
357 gace
->aceIFlags
, gace
->aceWho
));
362 * get the ACL from GPFS, allocated on the specified mem_ctx
363 * internally retries when initial buffer was too small
365 * caller needs to cast result to either
366 * raw = yes: struct gpfs_opaque_acl
367 * raw = no: struct gpfs_acl
370 static void *vfs_gpfs_getacl(TALLOC_CTX
*mem_ctx
,
373 const gpfs_aclType_t type
)
384 aclbuf
= talloc_zero_size(mem_ctx
, size
);
385 if (aclbuf
== NULL
) {
391 struct gpfs_opaque_acl
*buf
= (struct gpfs_opaque_acl
*) aclbuf
;
392 buf
->acl_type
= type
;
393 flags
= GPFS_GETACL_NATIVE
;
394 len
= (unsigned int *) &(buf
->acl_buffer_len
);
395 struct_size
= sizeof(struct gpfs_opaque_acl
);
397 struct gpfs_acl
*buf
= (struct gpfs_acl
*) aclbuf
;
398 buf
->acl_type
= type
;
399 buf
->acl_level
= 1; /* GPFS_ACL_LEVEL_V4FLAGS */
400 flags
= GPFS_GETACL_STRUCT
;
401 len
= &(buf
->acl_len
);
402 /* reserve space for control flags in gpfs 3.5 and beyond */
403 struct_size
= sizeof(struct gpfs_acl
) + sizeof(unsigned int);
406 /* set the length of the buffer as input value */
410 ret
= gpfswrap_getacl(discard_const_p(char, fname
), flags
, aclbuf
);
411 if ((ret
!= 0) && (errno
== ENOSPC
)) {
413 * get the size needed to accommodate the complete buffer
415 * the value returned only applies to the ACL blob in the
416 * struct so make sure to also have headroom for the first
417 * struct members by adding room for the complete struct
418 * (might be a few bytes too much then)
420 size
= *len
+ struct_size
;
422 DEBUG(10, ("Increasing ACL buffer size to %zu\n", size
));
427 DEBUG(5, ("smbd_gpfs_getacl failed with %s\n",
436 /* Tries to get nfs4 acls and returns SMB ACL allocated.
437 * On failure returns 1 if it got non-NFSv4 ACL to prompt
438 * retry with POSIX ACL checks.
439 * On failure returns -1 if there is system (GPFS) error, check errno.
440 * Returns 0 on success
442 static int gpfs_get_nfs4_acl(TALLOC_CTX
*mem_ctx
, const char *fname
, SMB4ACL_T
**ppacl
)
445 struct gpfs_acl
*gacl
= NULL
;
446 DEBUG(10, ("gpfs_get_nfs4_acl invoked for %s\n", fname
));
449 gacl
= (struct gpfs_acl
*) vfs_gpfs_getacl(talloc_tos(), fname
,
452 DEBUG(9, ("gpfs_getacl failed for %s with %s\n",
453 fname
, strerror(errno
)));
454 if (errno
== ENODATA
) {
456 * GPFS returns ENODATA for snapshot
457 * directories. Retry with POSIX ACLs check.
465 if (gacl
->acl_type
!= GPFS_ACL_TYPE_NFS4
) {
466 DEBUG(10, ("Got non-nfsv4 acl\n"));
467 /* Retry with POSIX ACLs check */
472 *ppacl
= smb_create_smb4acl(mem_ctx
);
474 if (gacl
->acl_level
== 1) { /* GPFS_ACL_LEVEL_V4FLAGS */
475 uint16_t control
= gpfs2sd_control(gpfs_acl_flags(gacl
));
476 smbacl4_set_controlflags(*ppacl
, control
);
479 DEBUG(10, ("len: %d, level: %d, version: %d, nace: %d, control: %x\n",
480 gacl
->acl_len
, gacl
->acl_level
, gacl
->acl_version
,
481 gacl
->acl_nace
, gpfs_acl_flags(gacl
)));
483 for (i
=0; i
<gacl
->acl_nace
; i
++) {
484 struct gpfs_ace_v4
*gace
= gpfs_ace_ptr(gacl
, i
);
485 SMB_ACE4PROP_T smbace
;
486 DEBUG(10, ("type: %d, iflags: %x, flags: %x, mask: %x, "
487 "who: %d\n", gace
->aceType
, gace
->aceIFlags
,
488 gace
->aceFlags
, gace
->aceMask
, gace
->aceWho
));
491 if (gace
->aceIFlags
& ACE4_IFLAG_SPECIAL_ID
) {
492 smbace
.flags
|= SMB_ACE4_ID_SPECIAL
;
493 switch (gace
->aceWho
) {
494 case ACE4_SPECIAL_OWNER
:
495 smbace
.who
.special_id
= SMB_ACE4_WHO_OWNER
;
497 case ACE4_SPECIAL_GROUP
:
498 smbace
.who
.special_id
= SMB_ACE4_WHO_GROUP
;
500 case ACE4_SPECIAL_EVERYONE
:
501 smbace
.who
.special_id
= SMB_ACE4_WHO_EVERYONE
;
504 DEBUG(8, ("invalid special gpfs id %d "
505 "ignored\n", gace
->aceWho
));
506 continue; /* don't add it */
509 if (gace
->aceFlags
& ACE4_FLAG_GROUP_ID
)
510 smbace
.who
.gid
= gace
->aceWho
;
512 smbace
.who
.uid
= gace
->aceWho
;
515 /* remove redundant deny entries */
516 if (i
> 0 && gace
->aceType
== SMB_ACE4_ACCESS_DENIED_ACE_TYPE
) {
517 struct gpfs_ace_v4
*prev
= gpfs_ace_ptr(gacl
, i
- 1);
518 if (prev
->aceType
== SMB_ACE4_ACCESS_ALLOWED_ACE_TYPE
&&
519 prev
->aceFlags
== gace
->aceFlags
&&
520 prev
->aceIFlags
== gace
->aceIFlags
&&
521 (gace
->aceMask
& prev
->aceMask
) == 0 &&
522 gace
->aceWho
== prev
->aceWho
) {
523 /* it's redundant - skip it */
528 smbace
.aceType
= gace
->aceType
;
529 smbace
.aceFlags
= gace
->aceFlags
;
530 smbace
.aceMask
= gace
->aceMask
;
531 smb_add_ace4(*ppacl
, &smbace
);
539 static NTSTATUS
gpfsacl_fget_nt_acl(vfs_handle_struct
*handle
,
540 files_struct
*fsp
, uint32_t security_info
,
542 struct security_descriptor
**ppdesc
)
544 SMB4ACL_T
*pacl
= NULL
;
546 struct gpfs_config_data
*config
;
547 TALLOC_CTX
*frame
= talloc_stackframe();
552 SMB_VFS_HANDLE_GET_DATA(handle
, config
,
553 struct gpfs_config_data
,
554 return NT_STATUS_INTERNAL_ERROR
);
557 status
= SMB_VFS_NEXT_FGET_NT_ACL(handle
, fsp
, security_info
,
563 result
= gpfs_get_nfs4_acl(frame
, fsp
->fsp_name
->base_name
, &pacl
);
566 status
= smb_fget_nt_acl_nfs4(fsp
, security_info
, mem_ctx
,
573 DEBUG(10, ("retrying with posix acl...\n"));
574 status
= posix_fget_nt_acl(fsp
, security_info
,
582 /* GPFS ACL was not read, something wrong happened, error code is set in errno */
583 return map_nt_error_from_unix(errno
);
586 static NTSTATUS
gpfsacl_get_nt_acl(vfs_handle_struct
*handle
,
588 uint32_t security_info
,
589 TALLOC_CTX
*mem_ctx
, struct security_descriptor
**ppdesc
)
591 SMB4ACL_T
*pacl
= NULL
;
593 struct gpfs_config_data
*config
;
594 TALLOC_CTX
*frame
= talloc_stackframe();
599 SMB_VFS_HANDLE_GET_DATA(handle
, config
,
600 struct gpfs_config_data
,
601 return NT_STATUS_INTERNAL_ERROR
);
604 status
= SMB_VFS_NEXT_GET_NT_ACL(handle
, name
, security_info
,
610 result
= gpfs_get_nfs4_acl(frame
, name
, &pacl
);
613 status
= smb_get_nt_acl_nfs4(handle
->conn
, name
, security_info
,
614 mem_ctx
, ppdesc
, pacl
);
620 DEBUG(10, ("retrying with posix acl...\n"));
621 status
= posix_get_nt_acl(handle
->conn
, name
, security_info
,
627 /* GPFS ACL was not read, something wrong happened, error code is set in errno */
629 return map_nt_error_from_unix(errno
);
632 static struct gpfs_acl
*vfs_gpfs_smbacl2gpfsacl(TALLOC_CTX
*mem_ctx
,
637 struct gpfs_acl
*gacl
;
638 gpfs_aclLen_t gacl_len
;
641 gacl_len
= offsetof(gpfs_acl_t
, ace_v4
) + sizeof(unsigned int)
642 + smb_get_naces(smbacl
) * sizeof(gpfs_ace_v4_t
);
644 gacl
= (struct gpfs_acl
*)TALLOC_SIZE(mem_ctx
, gacl_len
);
646 DEBUG(0, ("talloc failed\n"));
651 gacl
->acl_level
= 0; /* GPFS_ACL_LEVEL_BASE */
652 gacl
->acl_version
= GPFS_ACL_VERSION_NFS4
;
653 gacl
->acl_type
= GPFS_ACL_TYPE_NFS4
;
654 gacl
->acl_nace
= 0; /* change later... */
657 gacl
->acl_level
= 1; /* GPFS_ACL_LEVEL_V4FLAGS */
658 sd2gpfs_control(smbacl4_get_controlflags(smbacl
), gacl
);
661 for (smbace
=smb_first_ace4(smbacl
); smbace
!=NULL
; smbace
= smb_next_ace4(smbace
)) {
662 struct gpfs_ace_v4
*gace
= gpfs_ace_ptr(gacl
, gacl
->acl_nace
);
663 SMB_ACE4PROP_T
*aceprop
= smb_get_ace4(smbace
);
665 gace
->aceType
= aceprop
->aceType
;
666 gace
->aceFlags
= aceprop
->aceFlags
;
667 gace
->aceMask
= aceprop
->aceMask
;
670 * GPFS can't distinguish between WRITE and APPEND on
671 * files, so one being set without the other is an
672 * error. Sorry for the many ()'s :-)
675 if (!fsp
->is_directory
677 ((((gace
->aceMask
& ACE4_MASK_WRITE
) == 0)
678 && ((gace
->aceMask
& ACE4_MASK_APPEND
) != 0))
680 (((gace
->aceMask
& ACE4_MASK_WRITE
) != 0)
681 && ((gace
->aceMask
& ACE4_MASK_APPEND
) == 0)))
683 lp_parm_bool(fsp
->conn
->params
->service
, "gpfs",
684 "merge_writeappend", True
)) {
685 DEBUG(2, ("vfs_gpfs.c: file [%s]: ACE contains "
686 "WRITE^APPEND, setting WRITE|APPEND\n",
688 gace
->aceMask
|= ACE4_MASK_WRITE
|ACE4_MASK_APPEND
;
691 gace
->aceIFlags
= (aceprop
->flags
&SMB_ACE4_ID_SPECIAL
) ? ACE4_IFLAG_SPECIAL_ID
: 0;
693 if (aceprop
->flags
&SMB_ACE4_ID_SPECIAL
)
695 switch(aceprop
->who
.special_id
)
697 case SMB_ACE4_WHO_EVERYONE
:
698 gace
->aceWho
= ACE4_SPECIAL_EVERYONE
;
700 case SMB_ACE4_WHO_OWNER
:
701 gace
->aceWho
= ACE4_SPECIAL_OWNER
;
703 case SMB_ACE4_WHO_GROUP
:
704 gace
->aceWho
= ACE4_SPECIAL_GROUP
;
707 DEBUG(8, ("unsupported special_id %d\n", aceprop
->who
.special_id
));
708 continue; /* don't add it !!! */
711 /* just only for the type safety... */
712 if (aceprop
->aceFlags
&SMB_ACE4_IDENTIFIER_GROUP
)
713 gace
->aceWho
= aceprop
->who
.gid
;
715 gace
->aceWho
= aceprop
->who
.uid
;
720 gacl
->acl_len
= (char *)gpfs_ace_ptr(gacl
, gacl
->acl_nace
)
725 static bool gpfsacl_process_smbacl(vfs_handle_struct
*handle
,
730 struct gpfs_acl
*gacl
;
731 TALLOC_CTX
*mem_ctx
= talloc_tos();
733 gacl
= vfs_gpfs_smbacl2gpfsacl(mem_ctx
, fsp
, smbacl
, true);
734 if (gacl
== NULL
) { /* out of memory */
737 ret
= gpfswrap_putacl(fsp
->fsp_name
->base_name
,
738 GPFS_PUTACL_STRUCT
| GPFS_ACL_SAMBA
, gacl
);
740 if ((ret
!= 0) && (errno
== EINVAL
)) {
741 DEBUG(10, ("Retry without nfs41 control flags\n"));
743 gacl
= vfs_gpfs_smbacl2gpfsacl(mem_ctx
, fsp
, smbacl
, false);
744 if (gacl
== NULL
) { /* out of memory */
747 ret
= gpfswrap_putacl(fsp
->fsp_name
->base_name
,
748 GPFS_PUTACL_STRUCT
| GPFS_ACL_SAMBA
,
753 DEBUG(8, ("gpfs_putacl failed with %s\n", strerror(errno
)));
754 gpfs_dumpacl(8, gacl
);
758 DEBUG(10, ("gpfs_putacl succeeded\n"));
762 static NTSTATUS
gpfsacl_set_nt_acl_internal(vfs_handle_struct
*handle
, files_struct
*fsp
, uint32_t security_info_sent
, const struct security_descriptor
*psd
)
764 struct gpfs_acl
*acl
;
765 NTSTATUS result
= NT_STATUS_ACCESS_DENIED
;
767 acl
= (struct gpfs_acl
*) vfs_gpfs_getacl(talloc_tos(),
768 fsp
->fsp_name
->base_name
,
771 return map_nt_error_from_unix(errno
);
774 if (acl
->acl_version
== GPFS_ACL_VERSION_NFS4
) {
775 if (lp_parm_bool(fsp
->conn
->params
->service
, "gpfs",
776 "refuse_dacl_protected", false)
777 && (psd
->type
&SEC_DESC_DACL_PROTECTED
)) {
778 DEBUG(2, ("Rejecting unsupported ACL with DACL_PROTECTED bit set\n"));
780 return NT_STATUS_NOT_SUPPORTED
;
783 result
= smb_set_nt_acl_nfs4(handle
,
784 fsp
, security_info_sent
, psd
,
785 gpfsacl_process_smbacl
);
786 } else { /* assume POSIX ACL - by default... */
787 result
= set_nt_acl(fsp
, security_info_sent
, psd
);
794 static NTSTATUS
gpfsacl_fset_nt_acl(vfs_handle_struct
*handle
, files_struct
*fsp
, uint32_t security_info_sent
, const struct security_descriptor
*psd
)
796 struct gpfs_config_data
*config
;
798 SMB_VFS_HANDLE_GET_DATA(handle
, config
,
799 struct gpfs_config_data
,
800 return NT_STATUS_INTERNAL_ERROR
);
803 return SMB_VFS_NEXT_FSET_NT_ACL(handle
, fsp
, security_info_sent
, psd
);
806 return gpfsacl_set_nt_acl_internal(handle
, fsp
, security_info_sent
, psd
);
809 static SMB_ACL_T
gpfs2smb_acl(const struct gpfs_acl
*pacl
, TALLOC_CTX
*mem_ctx
)
814 result
= sys_acl_init(mem_ctx
);
815 if (result
== NULL
) {
820 result
->count
= pacl
->acl_nace
;
821 result
->acl
= talloc_realloc(result
, result
->acl
, struct smb_acl_entry
,
823 if (result
->acl
== NULL
) {
829 for (i
=0; i
<pacl
->acl_nace
; i
++) {
830 struct smb_acl_entry
*ace
= &result
->acl
[i
];
831 const struct gpfs_ace_v1
*g_ace
= &pacl
->ace_v1
[i
];
833 DEBUG(10, ("Converting type %d id %lu perm %x\n",
834 (int)g_ace
->ace_type
, (unsigned long)g_ace
->ace_who
,
835 (int)g_ace
->ace_perm
));
837 switch (g_ace
->ace_type
) {
839 ace
->a_type
= SMB_ACL_USER
;
840 ace
->info
.user
.uid
= (uid_t
)g_ace
->ace_who
;
842 case GPFS_ACL_USER_OBJ
:
843 ace
->a_type
= SMB_ACL_USER_OBJ
;
846 ace
->a_type
= SMB_ACL_GROUP
;
847 ace
->info
.group
.gid
= (gid_t
)g_ace
->ace_who
;
849 case GPFS_ACL_GROUP_OBJ
:
850 ace
->a_type
= SMB_ACL_GROUP_OBJ
;
853 ace
->a_type
= SMB_ACL_OTHER
;
856 ace
->a_type
= SMB_ACL_MASK
;
859 DEBUG(10, ("Got invalid ace_type: %d\n",
867 ace
->a_perm
|= (g_ace
->ace_perm
& ACL_PERM_READ
) ?
869 ace
->a_perm
|= (g_ace
->ace_perm
& ACL_PERM_WRITE
) ?
871 ace
->a_perm
|= (g_ace
->ace_perm
& ACL_PERM_EXECUTE
) ?
874 DEBUGADD(10, ("Converted to %d perm %x\n",
875 ace
->a_type
, ace
->a_perm
));
881 static SMB_ACL_T
gpfsacl_get_posix_acl(const char *path
, gpfs_aclType_t type
,
884 struct gpfs_acl
*pacl
;
885 SMB_ACL_T result
= NULL
;
887 pacl
= vfs_gpfs_getacl(talloc_tos(), path
, false, type
);
890 DEBUG(10, ("vfs_gpfs_getacl failed for %s with %s\n",
891 path
, strerror(errno
)));
898 if (pacl
->acl_version
!= GPFS_ACL_VERSION_POSIX
) {
899 DEBUG(10, ("Got acl version %d, expected %d\n",
900 pacl
->acl_version
, GPFS_ACL_VERSION_POSIX
));
905 DEBUG(10, ("len: %d, level: %d, version: %d, nace: %d\n",
906 pacl
->acl_len
, pacl
->acl_level
, pacl
->acl_version
,
909 result
= gpfs2smb_acl(pacl
, mem_ctx
);
910 if (result
!= NULL
) {
925 static SMB_ACL_T
gpfsacl_sys_acl_get_file(vfs_handle_struct
*handle
,
930 gpfs_aclType_t gpfs_type
;
931 struct gpfs_config_data
*config
;
933 SMB_VFS_HANDLE_GET_DATA(handle
, config
,
934 struct gpfs_config_data
,
938 return SMB_VFS_NEXT_SYS_ACL_GET_FILE(handle
, path_p
,
943 case SMB_ACL_TYPE_ACCESS
:
944 gpfs_type
= GPFS_ACL_TYPE_ACCESS
;
946 case SMB_ACL_TYPE_DEFAULT
:
947 gpfs_type
= GPFS_ACL_TYPE_DEFAULT
;
950 DEBUG(0, ("Got invalid type: %d\n", type
));
951 smb_panic("exiting");
954 return gpfsacl_get_posix_acl(path_p
, gpfs_type
, mem_ctx
);
957 static SMB_ACL_T
gpfsacl_sys_acl_get_fd(vfs_handle_struct
*handle
,
961 struct gpfs_config_data
*config
;
963 SMB_VFS_HANDLE_GET_DATA(handle
, config
,
964 struct gpfs_config_data
,
968 return SMB_VFS_NEXT_SYS_ACL_GET_FD(handle
, fsp
, mem_ctx
);
971 return gpfsacl_get_posix_acl(fsp
->fsp_name
->base_name
,
972 GPFS_ACL_TYPE_ACCESS
, mem_ctx
);
975 static int gpfsacl_sys_acl_blob_get_file(vfs_handle_struct
*handle
,
978 char **blob_description
,
981 struct gpfs_config_data
*config
;
982 struct gpfs_opaque_acl
*acl
= NULL
;
986 SMB_VFS_HANDLE_GET_DATA(handle
, config
,
987 struct gpfs_config_data
,
991 return SMB_VFS_NEXT_SYS_ACL_BLOB_GET_FILE(handle
, path_p
,
998 acl
= (struct gpfs_opaque_acl
*)
999 vfs_gpfs_getacl(mem_ctx
,
1002 GPFS_ACL_TYPE_NFS4
);
1005 DEBUG(5, ("vfs_gpfs_getacl finished with errno %d: %s\n",
1006 errno
, strerror(errno
)));
1008 /* EINVAL means POSIX ACL, bail out on other cases */
1009 if (errno
!= EINVAL
) {
1016 * file has NFSv4 ACL
1018 * we only need the actual ACL blob here
1019 * acl_version will always be NFS4 because we asked
1021 * acl_type is only used for POSIX ACLs
1023 aclblob
.data
= (uint8_t*) acl
->acl_var_data
;
1024 aclblob
.length
= acl
->acl_buffer_len
;
1026 *blob_description
= talloc_strdup(mem_ctx
, "gpfs_nfs4_acl");
1027 if (!*blob_description
) {
1033 result
= non_posix_sys_acl_blob_get_file_helper(handle
, path_p
,
1041 /* fall back to POSIX ACL */
1042 return posix_sys_acl_blob_get_file(handle
, path_p
, mem_ctx
,
1043 blob_description
, blob
);
1046 static int gpfsacl_sys_acl_blob_get_fd(vfs_handle_struct
*handle
,
1048 TALLOC_CTX
*mem_ctx
,
1049 char **blob_description
,
1052 struct gpfs_config_data
*config
;
1053 struct gpfs_opaque_acl
*acl
= NULL
;
1057 SMB_VFS_HANDLE_GET_DATA(handle
, config
,
1058 struct gpfs_config_data
,
1062 return SMB_VFS_NEXT_SYS_ACL_BLOB_GET_FD(handle
, fsp
, mem_ctx
,
1063 blob_description
, blob
);
1067 acl
= (struct gpfs_opaque_acl
*) vfs_gpfs_getacl(mem_ctx
,
1068 fsp
->fsp_name
->base_name
,
1070 GPFS_ACL_TYPE_NFS4
);
1073 DEBUG(5, ("vfs_gpfs_getacl finished with errno %d: %s\n",
1074 errno
, strerror(errno
)));
1076 /* EINVAL means POSIX ACL, bail out on other cases */
1077 if (errno
!= EINVAL
) {
1084 * file has NFSv4 ACL
1086 * we only need the actual ACL blob here
1087 * acl_version will always be NFS4 because we asked
1089 * acl_type is only used for POSIX ACLs
1091 aclblob
.data
= (uint8_t*) acl
->acl_var_data
;
1092 aclblob
.length
= acl
->acl_buffer_len
;
1094 *blob_description
= talloc_strdup(mem_ctx
, "gpfs_nfs4_acl");
1095 if (!*blob_description
) {
1101 result
= non_posix_sys_acl_blob_get_fd_helper(handle
, fsp
,
1109 /* fall back to POSIX ACL */
1110 return posix_sys_acl_blob_get_fd(handle
, fsp
, mem_ctx
,
1111 blob_description
, blob
);
1114 static struct gpfs_acl
*smb2gpfs_acl(const SMB_ACL_T pacl
,
1115 SMB_ACL_TYPE_T type
)
1118 struct gpfs_acl
*result
;
1121 DEBUG(10, ("smb2gpfs_acl: Got ACL with %d entries\n", pacl
->count
));
1123 len
= offsetof(gpfs_acl_t
, ace_v1
) + (pacl
->count
) *
1124 sizeof(gpfs_ace_v1_t
);
1126 result
= (struct gpfs_acl
*)SMB_MALLOC(len
);
1127 if (result
== NULL
) {
1132 result
->acl_len
= len
;
1133 result
->acl_level
= 0;
1134 result
->acl_version
= GPFS_ACL_VERSION_POSIX
;
1135 result
->acl_type
= (type
== SMB_ACL_TYPE_DEFAULT
) ?
1136 GPFS_ACL_TYPE_DEFAULT
: GPFS_ACL_TYPE_ACCESS
;
1137 result
->acl_nace
= pacl
->count
;
1139 for (i
=0; i
<pacl
->count
; i
++) {
1140 const struct smb_acl_entry
*ace
= &pacl
->acl
[i
];
1141 struct gpfs_ace_v1
*g_ace
= &result
->ace_v1
[i
];
1143 DEBUG(10, ("Converting type %d perm %x\n",
1144 (int)ace
->a_type
, (int)ace
->a_perm
));
1146 g_ace
->ace_perm
= 0;
1148 switch(ace
->a_type
) {
1150 g_ace
->ace_type
= GPFS_ACL_USER
;
1151 g_ace
->ace_who
= (gpfs_uid_t
)ace
->info
.user
.uid
;
1153 case SMB_ACL_USER_OBJ
:
1154 g_ace
->ace_type
= GPFS_ACL_USER_OBJ
;
1155 g_ace
->ace_perm
|= ACL_PERM_CONTROL
;
1159 g_ace
->ace_type
= GPFS_ACL_GROUP
;
1160 g_ace
->ace_who
= (gpfs_uid_t
)ace
->info
.group
.gid
;
1162 case SMB_ACL_GROUP_OBJ
:
1163 g_ace
->ace_type
= GPFS_ACL_GROUP_OBJ
;
1167 g_ace
->ace_type
= GPFS_ACL_MASK
;
1168 g_ace
->ace_perm
= 0x8f;
1172 g_ace
->ace_type
= GPFS_ACL_OTHER
;
1176 DEBUG(10, ("Got invalid ace_type: %d\n", ace
->a_type
));
1182 g_ace
->ace_perm
|= (ace
->a_perm
& SMB_ACL_READ
) ?
1184 g_ace
->ace_perm
|= (ace
->a_perm
& SMB_ACL_WRITE
) ?
1186 g_ace
->ace_perm
|= (ace
->a_perm
& SMB_ACL_EXECUTE
) ?
1187 ACL_PERM_EXECUTE
: 0;
1189 DEBUGADD(10, ("Converted to %d id %d perm %x\n",
1190 g_ace
->ace_type
, g_ace
->ace_who
, g_ace
->ace_perm
));
1196 static int gpfsacl_sys_acl_set_file(vfs_handle_struct
*handle
,
1198 SMB_ACL_TYPE_T type
,
1201 struct gpfs_acl
*gpfs_acl
;
1203 struct gpfs_config_data
*config
;
1205 SMB_VFS_HANDLE_GET_DATA(handle
, config
,
1206 struct gpfs_config_data
,
1210 return SMB_VFS_NEXT_SYS_ACL_SET_FILE(handle
, name
, type
, theacl
);
1213 gpfs_acl
= smb2gpfs_acl(theacl
, type
);
1214 if (gpfs_acl
== NULL
) {
1218 result
= gpfswrap_putacl(discard_const_p(char, name
),
1219 GPFS_PUTACL_STRUCT
|GPFS_ACL_SAMBA
, gpfs_acl
);
1221 SAFE_FREE(gpfs_acl
);
1225 static int gpfsacl_sys_acl_set_fd(vfs_handle_struct
*handle
,
1229 struct gpfs_config_data
*config
;
1231 SMB_VFS_HANDLE_GET_DATA(handle
, config
,
1232 struct gpfs_config_data
,
1236 return SMB_VFS_NEXT_SYS_ACL_SET_FD(handle
, fsp
, theacl
);
1239 return gpfsacl_sys_acl_set_file(handle
, fsp
->fsp_name
->base_name
,
1240 SMB_ACL_TYPE_ACCESS
, theacl
);
1243 static int gpfsacl_sys_acl_delete_def_file(vfs_handle_struct
*handle
,
1246 struct gpfs_config_data
*config
;
1248 SMB_VFS_HANDLE_GET_DATA(handle
, config
,
1249 struct gpfs_config_data
,
1253 return SMB_VFS_NEXT_SYS_ACL_DELETE_DEF_FILE(handle
, path
);
1261 * Assumed: mode bits are shiftable and standard
1262 * Output: the new aceMask field for an smb nfs4 ace
1264 static uint32_t gpfsacl_mask_filter(uint32_t aceType
, uint32_t aceMask
, uint32_t rwx
)
1266 const uint32_t posix_nfs4map
[3] = {
1267 SMB_ACE4_EXECUTE
, /* execute */
1268 SMB_ACE4_WRITE_DATA
| SMB_ACE4_APPEND_DATA
, /* write; GPFS specific */
1269 SMB_ACE4_READ_DATA
/* read */
1272 uint32_t posix_mask
= 0x01;
1276 for(i
=0; i
<3; i
++) {
1277 nfs4_bits
= posix_nfs4map
[i
];
1278 posix_bit
= rwx
& posix_mask
;
1280 if (aceType
==SMB_ACE4_ACCESS_ALLOWED_ACE_TYPE
) {
1282 aceMask
|= nfs4_bits
;
1284 aceMask
&= ~nfs4_bits
;
1286 /* add deny bits when suitable */
1288 aceMask
|= nfs4_bits
;
1290 aceMask
&= ~nfs4_bits
;
1291 } /* other ace types are unexpected */
1299 static int gpfsacl_emu_chmod(vfs_handle_struct
*handle
,
1300 const char *path
, mode_t mode
)
1302 SMB4ACL_T
*pacl
= NULL
;
1304 bool haveAllowEntry
[SMB_ACE4_WHO_EVERYONE
+ 1] = {False
, False
, False
, False
};
1306 files_struct fake_fsp
; /* TODO: rationalize parametrization */
1308 TALLOC_CTX
*frame
= talloc_stackframe();
1310 DEBUG(10, ("gpfsacl_emu_chmod invoked for %s mode %o\n", path
, mode
));
1312 result
= gpfs_get_nfs4_acl(frame
, path
, &pacl
);
1318 if (mode
& ~(S_IRWXU
| S_IRWXG
| S_IRWXO
)) {
1319 DEBUG(2, ("WARNING: cutting extra mode bits %o on %s\n", mode
, path
));
1322 for (smbace
=smb_first_ace4(pacl
); smbace
!=NULL
; smbace
= smb_next_ace4(smbace
)) {
1323 SMB_ACE4PROP_T
*ace
= smb_get_ace4(smbace
);
1324 uint32_t specid
= ace
->who
.special_id
;
1326 if (ace
->flags
&SMB_ACE4_ID_SPECIAL
&&
1327 ace
->aceType
<=SMB_ACE4_ACCESS_DENIED_ACE_TYPE
&&
1328 specid
<= SMB_ACE4_WHO_EVERYONE
) {
1332 if (ace
->aceType
==SMB_ACE4_ACCESS_ALLOWED_ACE_TYPE
)
1333 haveAllowEntry
[specid
] = True
;
1335 /* mode >> 6 for @owner, mode >> 3 for @group,
1336 * mode >> 0 for @everyone */
1337 newMask
= gpfsacl_mask_filter(ace
->aceType
, ace
->aceMask
,
1338 mode
>> ((SMB_ACE4_WHO_EVERYONE
- specid
) * 3));
1339 if (ace
->aceMask
!=newMask
) {
1340 DEBUG(10, ("ace changed for %s (%o -> %o) id=%d\n",
1341 path
, ace
->aceMask
, newMask
, specid
));
1343 ace
->aceMask
= newMask
;
1347 /* make sure we have at least ALLOW entries
1348 * for all the 3 special ids (@EVERYONE, @OWNER, @GROUP)
1351 for(i
= SMB_ACE4_WHO_OWNER
; i
<=SMB_ACE4_WHO_EVERYONE
; i
++) {
1354 if (haveAllowEntry
[i
]==True
)
1358 ace
.aceType
= SMB_ACE4_ACCESS_ALLOWED_ACE_TYPE
;
1359 ace
.flags
|= SMB_ACE4_ID_SPECIAL
;
1360 ace
.who
.special_id
= i
;
1362 if (i
==SMB_ACE4_WHO_GROUP
) /* not sure it's necessary... */
1363 ace
.aceFlags
|= SMB_ACE4_IDENTIFIER_GROUP
;
1365 ace
.aceMask
= gpfsacl_mask_filter(ace
.aceType
, ace
.aceMask
,
1366 mode
>> ((SMB_ACE4_WHO_EVERYONE
- i
) * 3));
1368 /* don't add unnecessary aces */
1372 /* we add it to the END - as windows expects allow aces */
1373 smb_add_ace4(pacl
, &ace
);
1374 DEBUG(10, ("Added ALLOW ace for %s, mode=%o, id=%d, aceMask=%x\n",
1375 path
, mode
, i
, ace
.aceMask
));
1378 /* don't add complementary DENY ACEs here */
1379 ZERO_STRUCT(fake_fsp
);
1380 fake_fsp
.fsp_name
= synthetic_smb_fname(
1381 frame
, path
, NULL
, NULL
);
1382 if (fake_fsp
.fsp_name
== NULL
) {
1388 if (gpfsacl_process_smbacl(handle
, &fake_fsp
, pacl
) == False
) {
1394 return 0; /* ok for [f]chmod */
1397 static int vfs_gpfs_chmod(vfs_handle_struct
*handle
, const char *path
, mode_t mode
)
1399 struct smb_filename
*smb_fname_cpath
;
1402 smb_fname_cpath
= synthetic_smb_fname(talloc_tos(), path
, NULL
, NULL
);
1403 if (smb_fname_cpath
== NULL
) {
1408 if (SMB_VFS_NEXT_STAT(handle
, smb_fname_cpath
) != 0) {
1412 /* avoid chmod() if possible, to preserve acls */
1413 if ((smb_fname_cpath
->st
.st_ex_mode
& ~S_IFMT
) == mode
) {
1417 rc
= gpfsacl_emu_chmod(handle
, path
, mode
);
1419 return SMB_VFS_NEXT_CHMOD(handle
, path
, mode
);
1423 static int vfs_gpfs_fchmod(vfs_handle_struct
*handle
, files_struct
*fsp
, mode_t mode
)
1428 if (SMB_VFS_NEXT_FSTAT(handle
, fsp
, &st
) != 0) {
1432 /* avoid chmod() if possible, to preserve acls */
1433 if ((st
.st_ex_mode
& ~S_IFMT
) == mode
) {
1437 rc
= gpfsacl_emu_chmod(handle
, fsp
->fsp_name
->base_name
,
1440 return SMB_VFS_NEXT_FCHMOD(handle
, fsp
, mode
);
1444 static int gpfs_set_xattr(struct vfs_handle_struct
*handle
, const char *path
,
1445 const char *name
, const void *value
, size_t size
, int flags
){
1446 struct xattr_DOSATTRIB dosattrib
;
1447 enum ndr_err_code ndr_err
;
1449 unsigned int dosmode
=0;
1450 struct gpfs_winattr attrs
;
1452 struct gpfs_config_data
*config
;
1454 SMB_VFS_HANDLE_GET_DATA(handle
, config
,
1455 struct gpfs_config_data
,
1458 if (!config
->winattr
) {
1459 DEBUG(10, ("gpfs_set_xattr:name is %s -> next\n",name
));
1460 return SMB_VFS_NEXT_SETXATTR(handle
,path
,name
,value
,size
,flags
);
1463 DEBUG(10, ("gpfs_set_xattr: %s \n",path
));
1465 /* Only handle DOS Attributes */
1466 if (strcmp(name
,SAMBA_XATTR_DOS_ATTRIB
) != 0){
1467 DEBUG(5, ("gpfs_set_xattr:name is %s\n",name
));
1468 return SMB_VFS_NEXT_SETXATTR(handle
,path
,name
,value
,size
,flags
);
1471 blob
.data
= discard_const_p(uint8_t, value
);
1474 ndr_err
= ndr_pull_struct_blob(&blob
, talloc_tos(), &dosattrib
,
1475 (ndr_pull_flags_fn_t
)ndr_pull_xattr_DOSATTRIB
);
1477 if (!NDR_ERR_CODE_IS_SUCCESS(ndr_err
)) {
1478 DEBUG(1, ("gpfs_set_xattr: bad ndr decode "
1479 "from EA on file %s: Error = %s\n",
1480 path
, ndr_errstr(ndr_err
)));
1484 if (dosattrib
.version
!= 3) {
1485 DEBUG(1, ("gpfs_set_xattr: expected dosattrib version 3, got "
1486 "%d\n", (int)dosattrib
.version
));
1489 if (!(dosattrib
.info
.info3
.valid_flags
& XATTR_DOSINFO_ATTRIB
)) {
1490 DEBUG(10, ("gpfs_set_xattr: XATTR_DOSINFO_ATTRIB not "
1491 "valid, ignoring\n"));
1495 dosmode
= dosattrib
.info
.info3
.attrib
;
1498 /*Just map RD_ONLY, ARCHIVE, SYSTEM HIDDEN and SPARSE. Ignore the others*/
1499 if (dosmode
& FILE_ATTRIBUTE_ARCHIVE
){
1500 attrs
.winAttrs
|= GPFS_WINATTR_ARCHIVE
;
1502 if (dosmode
& FILE_ATTRIBUTE_HIDDEN
){
1503 attrs
.winAttrs
|= GPFS_WINATTR_HIDDEN
;
1505 if (dosmode
& FILE_ATTRIBUTE_SYSTEM
){
1506 attrs
.winAttrs
|= GPFS_WINATTR_SYSTEM
;
1508 if (dosmode
& FILE_ATTRIBUTE_READONLY
){
1509 attrs
.winAttrs
|= GPFS_WINATTR_READONLY
;
1511 if (dosmode
& FILE_ATTRIBUTE_SPARSE
) {
1512 attrs
.winAttrs
|= GPFS_WINATTR_SPARSE_FILE
;
1516 ret
= gpfswrap_set_winattrs_path(discard_const_p(char, path
),
1517 GPFS_WINATTR_SET_ATTRS
, &attrs
);
1519 if (errno
== ENOSYS
) {
1520 return SMB_VFS_NEXT_SETXATTR(handle
, path
, name
, value
,
1524 DEBUG(1, ("gpfs_set_xattr:Set GPFS attributes failed %d\n",ret
));
1528 DEBUG(10, ("gpfs_set_xattr:Set attributes: 0x%x\n",attrs
.winAttrs
));
1532 static ssize_t
gpfs_get_xattr(struct vfs_handle_struct
*handle
, const char *path
,
1533 const char *name
, void *value
, size_t size
){
1534 char *attrstr
= value
;
1535 unsigned int dosmode
= 0;
1536 struct gpfs_winattr attrs
;
1538 struct gpfs_config_data
*config
;
1540 SMB_VFS_HANDLE_GET_DATA(handle
, config
,
1541 struct gpfs_config_data
,
1544 if (!config
->winattr
) {
1545 DEBUG(10, ("gpfs_get_xattr:name is %s -> next\n",name
));
1546 return SMB_VFS_NEXT_GETXATTR(handle
,path
,name
,value
,size
);
1549 DEBUG(10, ("gpfs_get_xattr: %s \n",path
));
1551 /* Only handle DOS Attributes */
1552 if (strcmp(name
,SAMBA_XATTR_DOS_ATTRIB
) != 0){
1553 DEBUG(5, ("gpfs_get_xattr:name is %s\n",name
));
1554 return SMB_VFS_NEXT_GETXATTR(handle
,path
,name
,value
,size
);
1557 ret
= gpfswrap_get_winattrs_path(discard_const_p(char, path
), &attrs
);
1561 if (errno
== ENOSYS
) {
1562 return SMB_VFS_NEXT_GETXATTR(handle
, path
, name
, value
,
1566 if (errno
!= EPERM
&& errno
!= EACCES
) {
1571 DEBUG(dbg_lvl
, ("gpfs_get_xattr: Get GPFS attributes failed: "
1572 "%d (%s)\n", ret
, strerror(errno
)));
1576 DEBUG(10, ("gpfs_get_xattr:Got attributes: 0x%x\n",attrs
.winAttrs
));
1578 /*Just map RD_ONLY, ARCHIVE, SYSTEM, HIDDEN and SPARSE. Ignore the others*/
1579 if (attrs
.winAttrs
& GPFS_WINATTR_ARCHIVE
){
1580 dosmode
|= FILE_ATTRIBUTE_ARCHIVE
;
1582 if (attrs
.winAttrs
& GPFS_WINATTR_HIDDEN
){
1583 dosmode
|= FILE_ATTRIBUTE_HIDDEN
;
1585 if (attrs
.winAttrs
& GPFS_WINATTR_SYSTEM
){
1586 dosmode
|= FILE_ATTRIBUTE_SYSTEM
;
1588 if (attrs
.winAttrs
& GPFS_WINATTR_READONLY
){
1589 dosmode
|= FILE_ATTRIBUTE_READONLY
;
1591 if (attrs
.winAttrs
& GPFS_WINATTR_SPARSE_FILE
) {
1592 dosmode
|= FILE_ATTRIBUTE_SPARSE
;
1595 snprintf(attrstr
, size
, "0x%2.2x",
1596 (unsigned int)(dosmode
& SAMBA_ATTRIBUTES_MASK
));
1597 DEBUG(10, ("gpfs_get_xattr: returning %s\n",attrstr
));
1601 #if defined(HAVE_FSTATAT)
1602 static int stat_with_capability(struct vfs_handle_struct
*handle
,
1603 struct smb_filename
*smb_fname
, int flag
)
1608 const char *rel_name
= NULL
;
1612 b
= parent_dirname(talloc_tos(), smb_fname
->base_name
,
1613 &dir_name
, &rel_name
);
1619 fd
= open(dir_name
, O_RDONLY
, 0);
1620 TALLOC_FREE(dir_name
);
1625 set_effective_capability(DAC_OVERRIDE_CAPABILITY
);
1626 ret
= fstatat(fd
, rel_name
, &st
, flag
);
1627 drop_effective_capability(DAC_OVERRIDE_CAPABILITY
);
1632 init_stat_ex_from_stat(
1633 &smb_fname
->st
, &st
,
1634 lp_fake_directory_create_times(SNUM(handle
->conn
)));
1641 static int vfs_gpfs_stat(struct vfs_handle_struct
*handle
,
1642 struct smb_filename
*smb_fname
)
1644 struct gpfs_winattr attrs
;
1648 struct gpfs_config_data
*config
;
1650 SMB_VFS_HANDLE_GET_DATA(handle
, config
,
1651 struct gpfs_config_data
,
1654 ret
= SMB_VFS_NEXT_STAT(handle
, smb_fname
);
1655 #if defined(HAVE_FSTATAT)
1656 if (ret
== -1 && errno
== EACCES
) {
1657 DEBUG(10, ("Trying stat with capability for %s\n",
1658 smb_fname
->base_name
));
1659 ret
= stat_with_capability(handle
, smb_fname
, 0);
1666 if (!config
->winattr
) {
1670 status
= get_full_smb_filename(talloc_tos(), smb_fname
, &fname
);
1671 if (!NT_STATUS_IS_OK(status
)) {
1672 errno
= map_errno_from_nt_status(status
);
1675 ret
= gpfswrap_get_winattrs_path(discard_const_p(char, fname
), &attrs
);
1678 smb_fname
->st
.st_ex_calculated_birthtime
= false;
1679 smb_fname
->st
.st_ex_btime
.tv_sec
= attrs
.creationTime
.tv_sec
;
1680 smb_fname
->st
.st_ex_btime
.tv_nsec
= attrs
.creationTime
.tv_nsec
;
1685 static int vfs_gpfs_fstat(struct vfs_handle_struct
*handle
,
1686 struct files_struct
*fsp
, SMB_STRUCT_STAT
*sbuf
)
1688 struct gpfs_winattr attrs
;
1690 struct gpfs_config_data
*config
;
1692 SMB_VFS_HANDLE_GET_DATA(handle
, config
,
1693 struct gpfs_config_data
,
1696 ret
= SMB_VFS_NEXT_FSTAT(handle
, fsp
, sbuf
);
1700 if ((fsp
->fh
== NULL
) || (fsp
->fh
->fd
== -1)) {
1703 if (!config
->winattr
) {
1707 ret
= gpfswrap_get_winattrs(fsp
->fh
->fd
, &attrs
);
1709 sbuf
->st_ex_calculated_birthtime
= false;
1710 sbuf
->st_ex_btime
.tv_sec
= attrs
.creationTime
.tv_sec
;
1711 sbuf
->st_ex_btime
.tv_nsec
= attrs
.creationTime
.tv_nsec
;
1716 static int vfs_gpfs_lstat(struct vfs_handle_struct
*handle
,
1717 struct smb_filename
*smb_fname
)
1719 struct gpfs_winattr attrs
;
1723 struct gpfs_config_data
*config
;
1725 SMB_VFS_HANDLE_GET_DATA(handle
, config
,
1726 struct gpfs_config_data
,
1729 ret
= SMB_VFS_NEXT_LSTAT(handle
, smb_fname
);
1730 #if defined(HAVE_FSTATAT)
1731 if (ret
== -1 && errno
== EACCES
) {
1732 DEBUG(10, ("Trying lstat with capability for %s\n",
1733 smb_fname
->base_name
));
1734 ret
= stat_with_capability(handle
, smb_fname
,
1735 AT_SYMLINK_NOFOLLOW
);
1742 if (!config
->winattr
) {
1746 status
= get_full_smb_filename(talloc_tos(), smb_fname
, &path
);
1747 if (!NT_STATUS_IS_OK(status
)) {
1748 errno
= map_errno_from_nt_status(status
);
1751 ret
= gpfswrap_get_winattrs_path(discard_const_p(char, path
), &attrs
);
1754 smb_fname
->st
.st_ex_calculated_birthtime
= false;
1755 smb_fname
->st
.st_ex_btime
.tv_sec
= attrs
.creationTime
.tv_sec
;
1756 smb_fname
->st
.st_ex_btime
.tv_nsec
= attrs
.creationTime
.tv_nsec
;
1761 static void timespec_to_gpfs_time(struct timespec ts
, gpfs_timestruc_t
*gt
,
1762 int idx
, int *flags
)
1764 if (!null_timespec(ts
)) {
1766 gt
[idx
].tv_sec
= ts
.tv_sec
;
1767 gt
[idx
].tv_nsec
= ts
.tv_nsec
;
1768 DEBUG(10, ("Setting GPFS time %d, flags 0x%x\n", idx
, *flags
));
1772 static int smbd_gpfs_set_times_path(char *path
, struct smb_file_time
*ft
)
1774 gpfs_timestruc_t gpfs_times
[4];
1778 ZERO_ARRAY(gpfs_times
);
1779 timespec_to_gpfs_time(ft
->atime
, gpfs_times
, 0, &flags
);
1780 timespec_to_gpfs_time(ft
->mtime
, gpfs_times
, 1, &flags
);
1781 /* No good mapping from LastChangeTime to ctime, not storing */
1782 timespec_to_gpfs_time(ft
->create_time
, gpfs_times
, 3, &flags
);
1785 DEBUG(10, ("nothing to do, return to avoid EINVAL\n"));
1789 rc
= gpfswrap_set_times_path(path
, flags
, gpfs_times
);
1791 if (rc
!= 0 && errno
!= ENOSYS
) {
1792 DEBUG(1,("gpfs_set_times() returned with error %s\n",
1799 static int vfs_gpfs_ntimes(struct vfs_handle_struct
*handle
,
1800 const struct smb_filename
*smb_fname
,
1801 struct smb_file_time
*ft
)
1804 struct gpfs_winattr attrs
;
1808 struct gpfs_config_data
*config
;
1810 SMB_VFS_HANDLE_GET_DATA(handle
, config
,
1811 struct gpfs_config_data
,
1814 status
= get_full_smb_filename(talloc_tos(), smb_fname
, &path
);
1815 if (!NT_STATUS_IS_OK(status
)) {
1816 errno
= map_errno_from_nt_status(status
);
1820 /* Try to use gpfs_set_times if it is enabled and available */
1821 if (config
->settimes
) {
1822 ret
= smbd_gpfs_set_times_path(path
, ft
);
1824 if (ret
== 0 || (ret
== -1 && errno
!= ENOSYS
)) {
1829 DEBUG(10,("gpfs_set_times() not available or disabled, "
1830 "use ntimes and winattr\n"));
1832 ret
= SMB_VFS_NEXT_NTIMES(handle
, smb_fname
, ft
);
1834 /* don't complain if access was denied */
1835 if (errno
!= EPERM
&& errno
!= EACCES
) {
1836 DEBUG(1,("vfs_gpfs_ntimes: SMB_VFS_NEXT_NTIMES failed:"
1837 "%s", strerror(errno
)));
1842 if(null_timespec(ft
->create_time
)){
1843 DEBUG(10,("vfs_gpfs_ntimes:Create Time is NULL\n"));
1847 if (!config
->winattr
) {
1852 attrs
.creationTime
.tv_sec
= ft
->create_time
.tv_sec
;
1853 attrs
.creationTime
.tv_nsec
= ft
->create_time
.tv_nsec
;
1855 ret
= gpfswrap_set_winattrs_path(discard_const_p(char, path
),
1856 GPFS_WINATTR_SET_CREATION_TIME
,
1858 if(ret
== -1 && errno
!= ENOSYS
){
1859 DEBUG(1,("vfs_gpfs_ntimes: set GPFS ntimes failed %d\n",ret
));
1866 static int vfs_gpfs_fallocate(struct vfs_handle_struct
*handle
,
1867 struct files_struct
*fsp
, uint32_t mode
,
1868 off_t offset
, off_t len
)
1871 struct gpfs_config_data
*config
;
1873 SMB_VFS_HANDLE_GET_DATA(handle
, config
,
1874 struct gpfs_config_data
,
1877 if (!config
->prealloc
) {
1878 /* you should better not run fallocate() on GPFS at all */
1884 DEBUG(10, ("unmapped fallocate flags: %lx\n",
1885 (unsigned long)mode
));
1890 ret
= gpfswrap_prealloc(fsp
->fh
->fd
, offset
, len
);
1892 if (ret
== -1 && errno
!= ENOSYS
) {
1893 DEBUG(0, ("GPFS prealloc failed: %s\n", strerror(errno
)));
1894 } else if (ret
== -1 && errno
== ENOSYS
) {
1895 DEBUG(10, ("GPFS prealloc not supported.\n"));
1897 DEBUG(10, ("GPFS prealloc succeeded.\n"));
1903 static int vfs_gpfs_ftruncate(vfs_handle_struct
*handle
, files_struct
*fsp
,
1907 struct gpfs_config_data
*config
;
1909 SMB_VFS_HANDLE_GET_DATA(handle
, config
,
1910 struct gpfs_config_data
,
1913 if (!config
->ftruncate
) {
1914 return SMB_VFS_NEXT_FTRUNCATE(handle
, fsp
, len
);
1917 result
= gpfswrap_ftruncate(fsp
->fh
->fd
, len
);
1918 if ((result
== -1) && (errno
== ENOSYS
)) {
1919 return SMB_VFS_NEXT_FTRUNCATE(handle
, fsp
, len
);
1924 static bool vfs_gpfs_is_offline(struct vfs_handle_struct
*handle
,
1925 const struct smb_filename
*fname
,
1926 SMB_STRUCT_STAT
*sbuf
)
1928 struct gpfs_winattr attrs
;
1931 struct gpfs_config_data
*config
;
1934 SMB_VFS_HANDLE_GET_DATA(handle
, config
,
1935 struct gpfs_config_data
,
1938 if (!config
->winattr
) {
1939 return SMB_VFS_NEXT_IS_OFFLINE(handle
, fname
, sbuf
);
1942 status
= get_full_smb_filename(talloc_tos(), fname
, &path
);
1943 if (!NT_STATUS_IS_OK(status
)) {
1944 errno
= map_errno_from_nt_status(status
);
1948 ret
= gpfswrap_get_winattrs_path(path
, &attrs
);
1954 if ((attrs
.winAttrs
& GPFS_WINATTR_OFFLINE
) != 0) {
1955 DEBUG(10, ("%s is offline\n", path
));
1959 DEBUG(10, ("%s is online\n", path
));
1961 return SMB_VFS_NEXT_IS_OFFLINE(handle
, fname
, sbuf
);
1964 static bool vfs_gpfs_aio_force(struct vfs_handle_struct
*handle
,
1965 struct files_struct
*fsp
)
1967 return vfs_gpfs_is_offline(handle
, fsp
->fsp_name
, &fsp
->fsp_name
->st
);
1970 static ssize_t
vfs_gpfs_sendfile(vfs_handle_struct
*handle
, int tofd
,
1971 files_struct
*fsp
, const DATA_BLOB
*hdr
,
1972 off_t offset
, size_t n
)
1974 if (SMB_VFS_IS_OFFLINE(handle
->conn
, fsp
->fsp_name
, &fsp
->fsp_name
->st
))
1979 return SMB_VFS_NEXT_SENDFILE(handle
, tofd
, fsp
, hdr
, offset
, n
);
1982 static int vfs_gpfs_connect(struct vfs_handle_struct
*handle
,
1983 const char *service
, const char *user
)
1985 struct gpfs_config_data
*config
;
1988 gpfswrap_lib_init(0);
1990 config
= talloc_zero(handle
->conn
, struct gpfs_config_data
);
1992 DEBUG(0, ("talloc_zero() failed\n"));
1997 ret
= SMB_VFS_NEXT_CONNECT(handle
, service
, user
);
1999 TALLOC_FREE(config
);
2003 config
->sharemodes
= lp_parm_bool(SNUM(handle
->conn
), "gpfs",
2004 "sharemodes", true);
2006 config
->leases
= lp_parm_bool(SNUM(handle
->conn
), "gpfs",
2009 config
->hsm
= lp_parm_bool(SNUM(handle
->conn
), "gpfs",
2012 config
->syncio
= lp_parm_bool(SNUM(handle
->conn
), "gpfs",
2015 config
->winattr
= lp_parm_bool(SNUM(handle
->conn
), "gpfs",
2018 config
->ftruncate
= lp_parm_bool(SNUM(handle
->conn
), "gpfs",
2021 config
->getrealfilename
= lp_parm_bool(SNUM(handle
->conn
), "gpfs",
2022 "getrealfilename", true);
2024 config
->dfreequota
= lp_parm_bool(SNUM(handle
->conn
), "gpfs",
2025 "dfreequota", false);
2027 config
->prealloc
= lp_parm_bool(SNUM(handle
->conn
), "gpfs",
2030 config
->acl
= lp_parm_bool(SNUM(handle
->conn
), "gpfs", "acl", true);
2032 config
->settimes
= lp_parm_bool(SNUM(handle
->conn
), "gpfs",
2034 config
->recalls
= lp_parm_bool(SNUM(handle
->conn
), "gpfs",
2037 SMB_VFS_HANDLE_SET_DATA(handle
, config
,
2038 NULL
, struct gpfs_config_data
,
2041 if (config
->leases
) {
2043 * GPFS lease code is based on kernel oplock code
2044 * so make sure it is turned on
2046 if (!lp_kernel_oplocks(SNUM(handle
->conn
))) {
2047 DEBUG(5, ("Enabling kernel oplocks for "
2048 "gpfs:leases to work\n"));
2049 lp_do_parameter(SNUM(handle
->conn
), "kernel oplocks",
2054 * as the kernel does not properly support Level II oplocks
2055 * and GPFS leases code is based on kernel infrastructure, we
2056 * need to turn off Level II oplocks if gpfs:leases is enabled
2058 if (lp_level2_oplocks(SNUM(handle
->conn
))) {
2059 DEBUG(5, ("gpfs:leases are enabled, disabling "
2060 "Level II oplocks\n"));
2061 lp_do_parameter(SNUM(handle
->conn
), "level2 oplocks",
2069 static int get_gpfs_quota(const char *pathname
, int type
, int id
,
2070 struct gpfs_quotaInfo
*qi
)
2075 ret
= gpfswrap_quotactl(discard_const_p(char, pathname
),
2076 GPFS_QCMD(Q_GETQUOTA
, type
), id
, qi
);
2079 if (errno
== GPFS_E_NO_QUOTA_INST
) {
2080 DEBUG(10, ("Quotas disabled on GPFS filesystem.\n"));
2081 } else if (errno
!= ENOSYS
) {
2082 DEBUG(0, ("Get quota failed, type %d, id, %d, "
2083 "errno %d.\n", type
, id
, errno
));
2089 DEBUG(10, ("quota type %d, id %d, blk u:%lld h:%lld s:%lld gt:%u\n",
2090 type
, id
, qi
->blockUsage
, qi
->blockHardLimit
,
2091 qi
->blockSoftLimit
, qi
->blockGraceTime
));
2096 static void vfs_gpfs_disk_free_quota(struct gpfs_quotaInfo qi
, time_t cur_time
,
2097 uint64_t *dfree
, uint64_t *dsize
)
2099 uint64_t usage
, limit
;
2102 * The quota reporting is done in units of 1024 byte blocks, but
2103 * sys_fsusage uses units of 512 byte blocks, adjust the block number
2104 * accordingly. Also filter possibly negative usage counts from gpfs.
2106 usage
= qi
.blockUsage
< 0 ? 0 : (uint64_t)qi
.blockUsage
* 2;
2107 limit
= (uint64_t)qi
.blockHardLimit
* 2;
2110 * When the grace time for the exceeded soft block quota has been
2111 * exceeded, the soft block quota becomes an additional hard limit.
2113 if (qi
.blockSoftLimit
&&
2114 qi
.blockGraceTime
&& cur_time
> qi
.blockGraceTime
) {
2115 /* report disk as full */
2117 *dsize
= MIN(*dsize
, usage
);
2120 if (!qi
.blockHardLimit
)
2123 if (usage
>= limit
) {
2124 /* report disk as full */
2126 *dsize
= MIN(*dsize
, usage
);
2129 /* limit has not been reached, determine "free space" */
2130 *dfree
= MIN(*dfree
, limit
- usage
);
2131 *dsize
= MIN(*dsize
, limit
);
2135 static uint64_t vfs_gpfs_disk_free(vfs_handle_struct
*handle
, const char *path
,
2137 uint64_t *dfree
, uint64_t *dsize
)
2139 struct security_unix_token
*utok
;
2140 struct gpfs_quotaInfo qi_user
, qi_group
;
2141 struct gpfs_config_data
*config
;
2145 SMB_VFS_HANDLE_GET_DATA(handle
, config
, struct gpfs_config_data
,
2146 return (uint64_t)-1);
2147 if (!config
->dfreequota
) {
2148 return SMB_VFS_NEXT_DISK_FREE(handle
, path
,
2149 bsize
, dfree
, dsize
);
2152 err
= sys_fsusage(path
, dfree
, dsize
);
2154 DEBUG (0, ("Could not get fs usage, errno %d\n", errno
));
2155 return SMB_VFS_NEXT_DISK_FREE(handle
, path
,
2156 bsize
, dfree
, dsize
);
2159 /* sys_fsusage returns units of 512 bytes */
2162 DEBUG(10, ("fs dfree %llu, dsize %llu\n",
2163 (unsigned long long)*dfree
, (unsigned long long)*dsize
));
2165 utok
= handle
->conn
->session_info
->unix_token
;
2167 err
= get_gpfs_quota(path
, GPFS_USRQUOTA
, utok
->uid
, &qi_user
);
2169 return SMB_VFS_NEXT_DISK_FREE(handle
, path
,
2170 bsize
, dfree
, dsize
);
2173 err
= get_gpfs_quota(path
, GPFS_GRPQUOTA
, utok
->gid
, &qi_group
);
2175 return SMB_VFS_NEXT_DISK_FREE(handle
, path
,
2176 bsize
, dfree
, dsize
);
2179 cur_time
= time(NULL
);
2181 /* Adjust free space and size according to quota limits. */
2182 vfs_gpfs_disk_free_quota(qi_user
, cur_time
, dfree
, dsize
);
2183 vfs_gpfs_disk_free_quota(qi_group
, cur_time
, dfree
, dsize
);
2185 disk_norm(bsize
, dfree
, dsize
);
2189 static uint32_t vfs_gpfs_capabilities(struct vfs_handle_struct
*handle
,
2190 enum timestamp_set_resolution
*p_ts_res
)
2192 struct gpfs_config_data
*config
;
2195 next
= SMB_VFS_NEXT_FS_CAPABILITIES(handle
, p_ts_res
);
2197 SMB_VFS_HANDLE_GET_DATA(handle
, config
,
2198 struct gpfs_config_data
,
2202 next
|= FILE_SUPPORTS_REMOTE_STORAGE
;
2207 static int vfs_gpfs_open(struct vfs_handle_struct
*handle
,
2208 struct smb_filename
*smb_fname
, files_struct
*fsp
,
2209 int flags
, mode_t mode
)
2211 struct gpfs_config_data
*config
;
2213 SMB_VFS_HANDLE_GET_DATA(handle
, config
,
2214 struct gpfs_config_data
,
2217 if (config
->hsm
&& !config
->recalls
) {
2218 if (SMB_VFS_IS_OFFLINE(handle
->conn
, smb_fname
, &smb_fname
->st
))
2220 DEBUG(10, ("Refusing access to offline file %s\n",
2227 if (config
->syncio
) {
2230 return SMB_VFS_NEXT_OPEN(handle
, smb_fname
, fsp
, flags
, mode
);
2233 static ssize_t
vfs_gpfs_pread(vfs_handle_struct
*handle
, files_struct
*fsp
,
2234 void *data
, size_t n
, off_t offset
)
2239 was_offline
= SMB_VFS_IS_OFFLINE(handle
->conn
, fsp
->fsp_name
,
2240 &fsp
->fsp_name
->st
);
2242 ret
= SMB_VFS_NEXT_PREAD(handle
, fsp
, data
, n
, offset
);
2244 if ((ret
!= -1) && was_offline
) {
2245 notify_fname(handle
->conn
, NOTIFY_ACTION_MODIFIED
,
2246 FILE_NOTIFY_CHANGE_ATTRIBUTES
,
2247 fsp
->fsp_name
->base_name
);
2253 struct vfs_gpfs_pread_state
{
2254 struct files_struct
*fsp
;
2260 static void vfs_gpfs_pread_done(struct tevent_req
*subreq
);
2262 static struct tevent_req
*vfs_gpfs_pread_send(struct vfs_handle_struct
*handle
,
2263 TALLOC_CTX
*mem_ctx
,
2264 struct tevent_context
*ev
,
2265 struct files_struct
*fsp
,
2266 void *data
, size_t n
,
2269 struct tevent_req
*req
, *subreq
;
2270 struct vfs_gpfs_pread_state
*state
;
2272 req
= tevent_req_create(mem_ctx
, &state
, struct vfs_gpfs_pread_state
);
2276 state
->was_offline
= SMB_VFS_IS_OFFLINE(handle
->conn
, fsp
->fsp_name
,
2277 &fsp
->fsp_name
->st
);
2279 subreq
= SMB_VFS_NEXT_PREAD_SEND(state
, ev
, handle
, fsp
, data
,
2281 if (tevent_req_nomem(subreq
, req
)) {
2282 return tevent_req_post(req
, ev
);
2284 tevent_req_set_callback(subreq
, vfs_gpfs_pread_done
, req
);
2288 static void vfs_gpfs_pread_done(struct tevent_req
*subreq
)
2290 struct tevent_req
*req
= tevent_req_callback_data(
2291 subreq
, struct tevent_req
);
2292 struct vfs_gpfs_pread_state
*state
= tevent_req_data(
2293 req
, struct vfs_gpfs_pread_state
);
2295 state
->ret
= SMB_VFS_PREAD_RECV(subreq
, &state
->err
);
2296 TALLOC_FREE(subreq
);
2297 tevent_req_done(req
);
2300 static ssize_t
vfs_gpfs_pread_recv(struct tevent_req
*req
, int *err
)
2302 struct vfs_gpfs_pread_state
*state
= tevent_req_data(
2303 req
, struct vfs_gpfs_pread_state
);
2304 struct files_struct
*fsp
= state
->fsp
;
2306 if (tevent_req_is_unix_error(req
, err
)) {
2311 if ((state
->ret
!= -1) && state
->was_offline
) {
2312 DEBUG(10, ("sending notify\n"));
2313 notify_fname(fsp
->conn
, NOTIFY_ACTION_MODIFIED
,
2314 FILE_NOTIFY_CHANGE_ATTRIBUTES
,
2315 fsp
->fsp_name
->base_name
);
2321 static ssize_t
vfs_gpfs_pwrite(vfs_handle_struct
*handle
, files_struct
*fsp
,
2322 const void *data
, size_t n
, off_t offset
)
2327 was_offline
= SMB_VFS_IS_OFFLINE(handle
->conn
, fsp
->fsp_name
,
2328 &fsp
->fsp_name
->st
);
2330 ret
= SMB_VFS_NEXT_PWRITE(handle
, fsp
, data
, n
, offset
);
2332 if ((ret
!= -1) && was_offline
) {
2333 notify_fname(handle
->conn
, NOTIFY_ACTION_MODIFIED
,
2334 FILE_NOTIFY_CHANGE_ATTRIBUTES
,
2335 fsp
->fsp_name
->base_name
);
2341 struct vfs_gpfs_pwrite_state
{
2342 struct files_struct
*fsp
;
2348 static void vfs_gpfs_pwrite_done(struct tevent_req
*subreq
);
2350 static struct tevent_req
*vfs_gpfs_pwrite_send(
2351 struct vfs_handle_struct
*handle
,
2352 TALLOC_CTX
*mem_ctx
,
2353 struct tevent_context
*ev
,
2354 struct files_struct
*fsp
,
2355 const void *data
, size_t n
,
2358 struct tevent_req
*req
, *subreq
;
2359 struct vfs_gpfs_pwrite_state
*state
;
2361 req
= tevent_req_create(mem_ctx
, &state
, struct vfs_gpfs_pwrite_state
);
2365 state
->was_offline
= SMB_VFS_IS_OFFLINE(handle
->conn
, fsp
->fsp_name
,
2366 &fsp
->fsp_name
->st
);
2368 subreq
= SMB_VFS_NEXT_PWRITE_SEND(state
, ev
, handle
, fsp
, data
,
2370 if (tevent_req_nomem(subreq
, req
)) {
2371 return tevent_req_post(req
, ev
);
2373 tevent_req_set_callback(subreq
, vfs_gpfs_pwrite_done
, req
);
2377 static void vfs_gpfs_pwrite_done(struct tevent_req
*subreq
)
2379 struct tevent_req
*req
= tevent_req_callback_data(
2380 subreq
, struct tevent_req
);
2381 struct vfs_gpfs_pwrite_state
*state
= tevent_req_data(
2382 req
, struct vfs_gpfs_pwrite_state
);
2384 state
->ret
= SMB_VFS_PWRITE_RECV(subreq
, &state
->err
);
2385 TALLOC_FREE(subreq
);
2386 tevent_req_done(req
);
2389 static ssize_t
vfs_gpfs_pwrite_recv(struct tevent_req
*req
, int *err
)
2391 struct vfs_gpfs_pwrite_state
*state
= tevent_req_data(
2392 req
, struct vfs_gpfs_pwrite_state
);
2393 struct files_struct
*fsp
= state
->fsp
;
2395 if (tevent_req_is_unix_error(req
, err
)) {
2400 if ((state
->ret
!= -1) && state
->was_offline
) {
2401 DEBUG(10, ("sending notify\n"));
2402 notify_fname(fsp
->conn
, NOTIFY_ACTION_MODIFIED
,
2403 FILE_NOTIFY_CHANGE_ATTRIBUTES
,
2404 fsp
->fsp_name
->base_name
);
2411 static struct vfs_fn_pointers vfs_gpfs_fns
= {
2412 .connect_fn
= vfs_gpfs_connect
,
2413 .disk_free_fn
= vfs_gpfs_disk_free
,
2414 .fs_capabilities_fn
= vfs_gpfs_capabilities
,
2415 .kernel_flock_fn
= vfs_gpfs_kernel_flock
,
2416 .linux_setlease_fn
= vfs_gpfs_setlease
,
2417 .get_real_filename_fn
= vfs_gpfs_get_real_filename
,
2418 .fget_nt_acl_fn
= gpfsacl_fget_nt_acl
,
2419 .get_nt_acl_fn
= gpfsacl_get_nt_acl
,
2420 .fset_nt_acl_fn
= gpfsacl_fset_nt_acl
,
2421 .sys_acl_get_file_fn
= gpfsacl_sys_acl_get_file
,
2422 .sys_acl_get_fd_fn
= gpfsacl_sys_acl_get_fd
,
2423 .sys_acl_blob_get_file_fn
= gpfsacl_sys_acl_blob_get_file
,
2424 .sys_acl_blob_get_fd_fn
= gpfsacl_sys_acl_blob_get_fd
,
2425 .sys_acl_set_file_fn
= gpfsacl_sys_acl_set_file
,
2426 .sys_acl_set_fd_fn
= gpfsacl_sys_acl_set_fd
,
2427 .sys_acl_delete_def_file_fn
= gpfsacl_sys_acl_delete_def_file
,
2428 .chmod_fn
= vfs_gpfs_chmod
,
2429 .fchmod_fn
= vfs_gpfs_fchmod
,
2430 .close_fn
= vfs_gpfs_close
,
2431 .setxattr_fn
= gpfs_set_xattr
,
2432 .getxattr_fn
= gpfs_get_xattr
,
2433 .stat_fn
= vfs_gpfs_stat
,
2434 .fstat_fn
= vfs_gpfs_fstat
,
2435 .lstat_fn
= vfs_gpfs_lstat
,
2436 .ntimes_fn
= vfs_gpfs_ntimes
,
2437 .is_offline_fn
= vfs_gpfs_is_offline
,
2438 .aio_force_fn
= vfs_gpfs_aio_force
,
2439 .sendfile_fn
= vfs_gpfs_sendfile
,
2440 .fallocate_fn
= vfs_gpfs_fallocate
,
2441 .open_fn
= vfs_gpfs_open
,
2442 .pread_fn
= vfs_gpfs_pread
,
2443 .pread_send_fn
= vfs_gpfs_pread_send
,
2444 .pread_recv_fn
= vfs_gpfs_pread_recv
,
2445 .pwrite_fn
= vfs_gpfs_pwrite
,
2446 .pwrite_send_fn
= vfs_gpfs_pwrite_send
,
2447 .pwrite_recv_fn
= vfs_gpfs_pwrite_recv
,
2448 .ftruncate_fn
= vfs_gpfs_ftruncate
2451 NTSTATUS
vfs_gpfs_init(void);
2452 NTSTATUS
vfs_gpfs_init(void)
2456 ret
= gpfswrap_init();
2458 DEBUG(1, ("Could not initialize GPFS library wrapper\n"));
2461 return smb_register_vfs(SMB_VFS_INTERFACE_VERSION
, "gpfs",