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 struct gpfs_fsp_extension
{
61 static inline unsigned int gpfs_acl_flags(gpfs_acl_t
*gacl
)
63 if (gacl
->acl_level
== GPFS_ACL_LEVEL_V4FLAGS
) {
64 return gacl
->v4Level1
.acl_flags
;
69 static inline gpfs_ace_v4_t
*gpfs_ace_ptr(gpfs_acl_t
*gacl
, unsigned int i
)
71 if (gacl
->acl_level
== GPFS_ACL_LEVEL_V4FLAGS
) {
72 return &gacl
->v4Level1
.ace_v4
[i
];
74 return &gacl
->ace_v4
[i
];
77 static bool set_gpfs_sharemode(files_struct
*fsp
, uint32_t access_mask
,
78 uint32_t share_access
)
80 unsigned int allow
= GPFS_SHARE_NONE
;
81 unsigned int deny
= GPFS_DENY_NONE
;
84 if ((fsp
== NULL
) || (fsp
->fh
== NULL
) || (fsp
->fh
->fd
< 0)) {
85 /* No real file, don't disturb */
89 allow
|= (access_mask
& (FILE_WRITE_DATA
|FILE_APPEND_DATA
|
90 DELETE_ACCESS
)) ? GPFS_SHARE_WRITE
: 0;
91 allow
|= (access_mask
& (FILE_READ_DATA
|FILE_EXECUTE
)) ?
94 if (allow
== GPFS_SHARE_NONE
) {
95 DEBUG(10, ("special case am=no_access:%x\n",access_mask
));
98 deny
|= (share_access
& FILE_SHARE_WRITE
) ?
100 deny
|= (share_access
& (FILE_SHARE_READ
)) ?
103 DEBUG(10, ("am=%x, allow=%d, sa=%x, deny=%d\n",
104 access_mask
, allow
, share_access
, deny
));
106 result
= gpfswrap_set_share(fsp
->fh
->fd
, allow
, deny
);
108 if (errno
== ENOSYS
) {
109 DEBUG(5, ("VFS module vfs_gpfs loaded, but gpfs "
110 "set_share function support not available. "
111 "Allowing access\n"));
114 DEBUG(10, ("gpfs_set_share failed: %s\n",
119 return (result
== 0);
122 static int vfs_gpfs_kernel_flock(vfs_handle_struct
*handle
, files_struct
*fsp
,
123 uint32_t share_mode
, uint32_t access_mask
)
126 struct gpfs_config_data
*config
;
129 SMB_VFS_HANDLE_GET_DATA(handle
, config
,
130 struct gpfs_config_data
,
133 if(!config
->sharemodes
) {
138 * A named stream fsp will have the basefile open in the fsp
139 * fd, so lacking a distinct fd for the stream we have to skip
140 * kernel_flock and set_gpfs_sharemode for stream.
142 if (!is_ntfs_default_stream_smb_fname(fsp
->fsp_name
)) {
143 DEBUG(2,("%s: kernel_flock on stream\n", fsp_str_dbg(fsp
)));
147 START_PROFILE(syscall_kernel_flock
);
149 kernel_flock(fsp
->fh
->fd
, share_mode
, access_mask
);
151 if (!set_gpfs_sharemode(fsp
, access_mask
, fsp
->share_access
)) {
155 END_PROFILE(syscall_kernel_flock
);
160 static int vfs_gpfs_close(vfs_handle_struct
*handle
, files_struct
*fsp
)
163 struct gpfs_config_data
*config
;
165 SMB_VFS_HANDLE_GET_DATA(handle
, config
,
166 struct gpfs_config_data
,
169 if (config
->sharemodes
&& (fsp
->fh
!= NULL
) && (fsp
->fh
->fd
!= -1)) {
170 set_gpfs_sharemode(fsp
, 0, 0);
173 return SMB_VFS_NEXT_CLOSE(handle
, fsp
);
176 static int set_gpfs_lease(int fd
, int leasetype
)
178 int gpfs_type
= GPFS_LEASE_NONE
;
180 if (leasetype
== F_RDLCK
) {
181 gpfs_type
= GPFS_LEASE_READ
;
183 if (leasetype
== F_WRLCK
) {
184 gpfs_type
= GPFS_LEASE_WRITE
;
187 /* we unconditionally set CAP_LEASE, rather than looking for
188 -1/EACCES as there is a bug in some versions of
189 libgpfs_gpl.so which results in a leaked fd on /dev/ss0
190 each time we try this with the wrong capabilities set
192 linux_set_lease_capability();
193 return gpfswrap_set_lease(fd
, gpfs_type
);
196 static int vfs_gpfs_setlease(vfs_handle_struct
*handle
, files_struct
*fsp
,
199 struct gpfs_config_data
*config
;
202 SMB_VFS_HANDLE_GET_DATA(handle
, config
,
203 struct gpfs_config_data
,
206 START_PROFILE(syscall_linux_setlease
);
208 if (linux_set_lease_sighandler(fsp
->fh
->fd
) == -1) {
213 if (config
->leases
) {
215 * Ensure the lease owner is root to allow
216 * correct delivery of lease-break signals.
219 ret
= set_gpfs_lease(fsp
->fh
->fd
,leasetype
);
224 END_PROFILE(syscall_linux_setlease
);
229 static int vfs_gpfs_get_real_filename(struct vfs_handle_struct
*handle
,
237 char real_pathname
[PATH_MAX
+1];
240 struct gpfs_config_data
*config
;
242 SMB_VFS_HANDLE_GET_DATA(handle
, config
,
243 struct gpfs_config_data
,
246 if (!config
->getrealfilename
) {
247 return SMB_VFS_NEXT_GET_REAL_FILENAME(handle
, path
, name
,
248 mem_ctx
, found_name
);
251 mangled
= mangle_is_mangled(name
, handle
->conn
->params
);
253 return SMB_VFS_NEXT_GET_REAL_FILENAME(handle
, path
, name
,
254 mem_ctx
, found_name
);
257 full_path
= talloc_asprintf(talloc_tos(), "%s/%s", path
, name
);
258 if (full_path
== NULL
) {
263 buflen
= sizeof(real_pathname
) - 1;
265 result
= gpfswrap_get_realfilename_path(full_path
, real_pathname
,
268 TALLOC_FREE(full_path
);
270 if ((result
== -1) && (errno
== ENOSYS
)) {
271 return SMB_VFS_NEXT_GET_REAL_FILENAME(
272 handle
, path
, name
, mem_ctx
, found_name
);
276 DEBUG(10, ("smbd_gpfs_get_realfilename_path returned %s\n",
282 * GPFS does not necessarily null-terminate the returned path
283 * but instead returns the buffer length in buflen.
286 if (buflen
< sizeof(real_pathname
)) {
287 real_pathname
[buflen
] = '\0';
289 real_pathname
[sizeof(real_pathname
)-1] = '\0';
292 DEBUG(10, ("smbd_gpfs_get_realfilename_path: %s/%s -> %s\n",
293 path
, name
, real_pathname
));
295 name
= strrchr_m(real_pathname
, '/');
301 *found_name
= talloc_strdup(mem_ctx
, name
+1);
302 if (*found_name
== NULL
) {
310 static void sd2gpfs_control(uint16_t control
, struct gpfs_acl
*gacl
)
312 unsigned int gpfs_aclflags
= 0;
313 control
&= SEC_DESC_DACL_PROTECTED
| SEC_DESC_SACL_PROTECTED
|
314 SEC_DESC_DACL_AUTO_INHERITED
| SEC_DESC_SACL_AUTO_INHERITED
|
315 SEC_DESC_DACL_DEFAULTED
| SEC_DESC_SACL_DEFAULTED
|
316 SEC_DESC_DACL_PRESENT
| SEC_DESC_SACL_PRESENT
;
317 gpfs_aclflags
= control
<< 8;
318 if (!(control
& SEC_DESC_DACL_PRESENT
))
319 gpfs_aclflags
|= ACL4_FLAG_NULL_DACL
;
320 if (!(control
& SEC_DESC_SACL_PRESENT
))
321 gpfs_aclflags
|= ACL4_FLAG_NULL_SACL
;
322 gacl
->acl_level
= GPFS_ACL_LEVEL_V4FLAGS
;
323 gacl
->v4Level1
.acl_flags
= 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
= 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
,
443 struct SMB4ACL_T
**ppacl
)
446 struct gpfs_acl
*gacl
= NULL
;
447 DEBUG(10, ("gpfs_get_nfs4_acl invoked for %s\n", fname
));
450 gacl
= (struct gpfs_acl
*) vfs_gpfs_getacl(talloc_tos(), fname
,
453 DEBUG(9, ("gpfs_getacl failed for %s with %s\n",
454 fname
, strerror(errno
)));
455 if (errno
== ENODATA
) {
457 * GPFS returns ENODATA for snapshot
458 * directories. Retry with POSIX ACLs check.
466 if (gacl
->acl_type
!= GPFS_ACL_TYPE_NFS4
) {
467 DEBUG(10, ("Got non-nfsv4 acl\n"));
468 /* Retry with POSIX ACLs check */
473 *ppacl
= smb_create_smb4acl(mem_ctx
);
475 if (gacl
->acl_level
== GPFS_ACL_LEVEL_V4FLAGS
) {
476 uint16_t control
= gpfs2sd_control(gpfs_acl_flags(gacl
));
477 smbacl4_set_controlflags(*ppacl
, control
);
480 DEBUG(10, ("len: %d, level: %d, version: %d, nace: %d, control: %x\n",
481 gacl
->acl_len
, gacl
->acl_level
, gacl
->acl_version
,
482 gacl
->acl_nace
, gpfs_acl_flags(gacl
)));
484 for (i
=0; i
<gacl
->acl_nace
; i
++) {
485 struct gpfs_ace_v4
*gace
= gpfs_ace_ptr(gacl
, i
);
486 SMB_ACE4PROP_T smbace
= { 0 };
487 DEBUG(10, ("type: %d, iflags: %x, flags: %x, mask: %x, "
488 "who: %d\n", gace
->aceType
, gace
->aceIFlags
,
489 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 struct 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 struct 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
,
634 struct SMB4ACL_T
*smbacl
,
637 struct gpfs_acl
*gacl
;
638 gpfs_aclLen_t gacl_len
;
639 struct SMB4ACE_T
*smbace
;
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
= 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
= 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
,
727 struct SMB4ACL_T
*smbacl
)
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 struct SMB4ACL_T
*pacl
= NULL
;
1304 bool haveAllowEntry
[SMB_ACE4_WHO_EVERYONE
+ 1] = {False
, False
, False
, False
};
1306 files_struct fake_fsp
= { 0 }; /* TODO: rationalize parametrization */
1307 struct SMB4ACE_T
*smbace
;
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
++) {
1352 SMB_ACE4PROP_T ace
= { 0 };
1354 if (haveAllowEntry
[i
]==True
)
1357 ace
.aceType
= SMB_ACE4_ACCESS_ALLOWED_ACE_TYPE
;
1358 ace
.flags
|= SMB_ACE4_ID_SPECIAL
;
1359 ace
.who
.special_id
= i
;
1361 if (i
==SMB_ACE4_WHO_GROUP
) /* not sure it's necessary... */
1362 ace
.aceFlags
|= SMB_ACE4_IDENTIFIER_GROUP
;
1364 ace
.aceMask
= gpfsacl_mask_filter(ace
.aceType
, ace
.aceMask
,
1365 mode
>> ((SMB_ACE4_WHO_EVERYONE
- i
) * 3));
1367 /* don't add unnecessary aces */
1371 /* we add it to the END - as windows expects allow aces */
1372 smb_add_ace4(pacl
, &ace
);
1373 DEBUG(10, ("Added ALLOW ace for %s, mode=%o, id=%d, aceMask=%x\n",
1374 path
, mode
, i
, ace
.aceMask
));
1377 /* don't add complementary DENY ACEs here */
1378 fake_fsp
.fsp_name
= synthetic_smb_fname(
1379 frame
, path
, NULL
, NULL
);
1380 if (fake_fsp
.fsp_name
== NULL
) {
1386 if (gpfsacl_process_smbacl(handle
, &fake_fsp
, pacl
) == False
) {
1392 return 0; /* ok for [f]chmod */
1395 static int vfs_gpfs_chmod(vfs_handle_struct
*handle
, const char *path
, mode_t mode
)
1397 struct smb_filename
*smb_fname_cpath
;
1400 smb_fname_cpath
= synthetic_smb_fname(talloc_tos(), path
, NULL
, NULL
);
1401 if (smb_fname_cpath
== NULL
) {
1406 if (SMB_VFS_NEXT_STAT(handle
, smb_fname_cpath
) != 0) {
1410 /* avoid chmod() if possible, to preserve acls */
1411 if ((smb_fname_cpath
->st
.st_ex_mode
& ~S_IFMT
) == mode
) {
1415 rc
= gpfsacl_emu_chmod(handle
, path
, mode
);
1417 return SMB_VFS_NEXT_CHMOD(handle
, path
, mode
);
1421 static int vfs_gpfs_fchmod(vfs_handle_struct
*handle
, files_struct
*fsp
, mode_t mode
)
1426 if (SMB_VFS_NEXT_FSTAT(handle
, fsp
, &st
) != 0) {
1430 /* avoid chmod() if possible, to preserve acls */
1431 if ((st
.st_ex_mode
& ~S_IFMT
) == mode
) {
1435 rc
= gpfsacl_emu_chmod(handle
, fsp
->fsp_name
->base_name
,
1438 return SMB_VFS_NEXT_FCHMOD(handle
, fsp
, mode
);
1442 static int gpfs_set_xattr(struct vfs_handle_struct
*handle
, const char *path
,
1443 const char *name
, const void *value
, size_t size
, int flags
){
1444 struct xattr_DOSATTRIB dosattrib
;
1445 enum ndr_err_code ndr_err
;
1447 unsigned int dosmode
=0;
1448 struct gpfs_winattr attrs
;
1450 struct gpfs_config_data
*config
;
1452 SMB_VFS_HANDLE_GET_DATA(handle
, config
,
1453 struct gpfs_config_data
,
1456 if (!config
->winattr
) {
1457 DEBUG(10, ("gpfs_set_xattr:name is %s -> next\n",name
));
1458 return SMB_VFS_NEXT_SETXATTR(handle
,path
,name
,value
,size
,flags
);
1461 DEBUG(10, ("gpfs_set_xattr: %s \n",path
));
1463 /* Only handle DOS Attributes */
1464 if (strcmp(name
,SAMBA_XATTR_DOS_ATTRIB
) != 0){
1465 DEBUG(5, ("gpfs_set_xattr:name is %s\n",name
));
1466 return SMB_VFS_NEXT_SETXATTR(handle
,path
,name
,value
,size
,flags
);
1469 blob
.data
= discard_const_p(uint8_t, value
);
1472 ndr_err
= ndr_pull_struct_blob(&blob
, talloc_tos(), &dosattrib
,
1473 (ndr_pull_flags_fn_t
)ndr_pull_xattr_DOSATTRIB
);
1475 if (!NDR_ERR_CODE_IS_SUCCESS(ndr_err
)) {
1476 DEBUG(1, ("gpfs_set_xattr: bad ndr decode "
1477 "from EA on file %s: Error = %s\n",
1478 path
, ndr_errstr(ndr_err
)));
1482 if (dosattrib
.version
!= 3) {
1483 DEBUG(1, ("gpfs_set_xattr: expected dosattrib version 3, got "
1484 "%d\n", (int)dosattrib
.version
));
1487 if (!(dosattrib
.info
.info3
.valid_flags
& XATTR_DOSINFO_ATTRIB
)) {
1488 DEBUG(10, ("gpfs_set_xattr: XATTR_DOSINFO_ATTRIB not "
1489 "valid, ignoring\n"));
1493 dosmode
= dosattrib
.info
.info3
.attrib
;
1496 /*Just map RD_ONLY, ARCHIVE, SYSTEM HIDDEN and SPARSE. Ignore the others*/
1497 if (dosmode
& FILE_ATTRIBUTE_ARCHIVE
){
1498 attrs
.winAttrs
|= GPFS_WINATTR_ARCHIVE
;
1500 if (dosmode
& FILE_ATTRIBUTE_HIDDEN
){
1501 attrs
.winAttrs
|= GPFS_WINATTR_HIDDEN
;
1503 if (dosmode
& FILE_ATTRIBUTE_SYSTEM
){
1504 attrs
.winAttrs
|= GPFS_WINATTR_SYSTEM
;
1506 if (dosmode
& FILE_ATTRIBUTE_READONLY
){
1507 attrs
.winAttrs
|= GPFS_WINATTR_READONLY
;
1509 if (dosmode
& FILE_ATTRIBUTE_SPARSE
) {
1510 attrs
.winAttrs
|= GPFS_WINATTR_SPARSE_FILE
;
1514 ret
= gpfswrap_set_winattrs_path(discard_const_p(char, path
),
1515 GPFS_WINATTR_SET_ATTRS
, &attrs
);
1517 if (errno
== ENOSYS
) {
1518 return SMB_VFS_NEXT_SETXATTR(handle
, path
, name
, value
,
1522 DEBUG(1, ("gpfs_set_xattr:Set GPFS attributes failed %d\n",ret
));
1526 DEBUG(10, ("gpfs_set_xattr:Set attributes: 0x%x\n",attrs
.winAttrs
));
1530 static ssize_t
gpfs_get_xattr(struct vfs_handle_struct
*handle
, const char *path
,
1531 const char *name
, void *value
, size_t size
){
1532 char *attrstr
= value
;
1533 unsigned int dosmode
= 0;
1534 struct gpfs_winattr attrs
;
1536 struct gpfs_config_data
*config
;
1538 SMB_VFS_HANDLE_GET_DATA(handle
, config
,
1539 struct gpfs_config_data
,
1542 if (!config
->winattr
) {
1543 DEBUG(10, ("gpfs_get_xattr:name is %s -> next\n",name
));
1544 return SMB_VFS_NEXT_GETXATTR(handle
,path
,name
,value
,size
);
1547 DEBUG(10, ("gpfs_get_xattr: %s \n",path
));
1549 /* Only handle DOS Attributes */
1550 if (strcmp(name
,SAMBA_XATTR_DOS_ATTRIB
) != 0){
1551 DEBUG(5, ("gpfs_get_xattr:name is %s\n",name
));
1552 return SMB_VFS_NEXT_GETXATTR(handle
,path
,name
,value
,size
);
1555 ret
= gpfswrap_get_winattrs_path(discard_const_p(char, path
), &attrs
);
1559 if (errno
== ENOSYS
) {
1560 return SMB_VFS_NEXT_GETXATTR(handle
, path
, name
, value
,
1564 if (errno
!= EPERM
&& errno
!= EACCES
) {
1569 DEBUG(dbg_lvl
, ("gpfs_get_xattr: Get GPFS attributes failed: "
1570 "%d (%s)\n", ret
, strerror(errno
)));
1574 DEBUG(10, ("gpfs_get_xattr:Got attributes: 0x%x\n",attrs
.winAttrs
));
1576 /*Just map RD_ONLY, ARCHIVE, SYSTEM, HIDDEN and SPARSE. Ignore the others*/
1577 if (attrs
.winAttrs
& GPFS_WINATTR_ARCHIVE
){
1578 dosmode
|= FILE_ATTRIBUTE_ARCHIVE
;
1580 if (attrs
.winAttrs
& GPFS_WINATTR_HIDDEN
){
1581 dosmode
|= FILE_ATTRIBUTE_HIDDEN
;
1583 if (attrs
.winAttrs
& GPFS_WINATTR_SYSTEM
){
1584 dosmode
|= FILE_ATTRIBUTE_SYSTEM
;
1586 if (attrs
.winAttrs
& GPFS_WINATTR_READONLY
){
1587 dosmode
|= FILE_ATTRIBUTE_READONLY
;
1589 if (attrs
.winAttrs
& GPFS_WINATTR_SPARSE_FILE
) {
1590 dosmode
|= FILE_ATTRIBUTE_SPARSE
;
1593 snprintf(attrstr
, size
, "0x%2.2x",
1594 (unsigned int)(dosmode
& SAMBA_ATTRIBUTES_MASK
));
1595 DEBUG(10, ("gpfs_get_xattr: returning %s\n",attrstr
));
1599 #if defined(HAVE_FSTATAT)
1600 static int stat_with_capability(struct vfs_handle_struct
*handle
,
1601 struct smb_filename
*smb_fname
, int flag
)
1606 const char *rel_name
= NULL
;
1610 b
= parent_dirname(talloc_tos(), smb_fname
->base_name
,
1611 &dir_name
, &rel_name
);
1617 fd
= open(dir_name
, O_RDONLY
, 0);
1618 TALLOC_FREE(dir_name
);
1623 set_effective_capability(DAC_OVERRIDE_CAPABILITY
);
1624 ret
= fstatat(fd
, rel_name
, &st
, flag
);
1625 drop_effective_capability(DAC_OVERRIDE_CAPABILITY
);
1630 init_stat_ex_from_stat(
1631 &smb_fname
->st
, &st
,
1632 lp_fake_directory_create_times(SNUM(handle
->conn
)));
1639 static int vfs_gpfs_stat(struct vfs_handle_struct
*handle
,
1640 struct smb_filename
*smb_fname
)
1642 struct gpfs_winattr attrs
;
1646 struct gpfs_config_data
*config
;
1648 SMB_VFS_HANDLE_GET_DATA(handle
, config
,
1649 struct gpfs_config_data
,
1652 ret
= SMB_VFS_NEXT_STAT(handle
, smb_fname
);
1653 #if defined(HAVE_FSTATAT)
1654 if (ret
== -1 && errno
== EACCES
) {
1655 DEBUG(10, ("Trying stat with capability for %s\n",
1656 smb_fname
->base_name
));
1657 ret
= stat_with_capability(handle
, smb_fname
, 0);
1664 if (!config
->winattr
) {
1668 status
= get_full_smb_filename(talloc_tos(), smb_fname
, &fname
);
1669 if (!NT_STATUS_IS_OK(status
)) {
1670 errno
= map_errno_from_nt_status(status
);
1673 ret
= gpfswrap_get_winattrs_path(discard_const_p(char, fname
), &attrs
);
1676 smb_fname
->st
.st_ex_calculated_birthtime
= false;
1677 smb_fname
->st
.st_ex_btime
.tv_sec
= attrs
.creationTime
.tv_sec
;
1678 smb_fname
->st
.st_ex_btime
.tv_nsec
= attrs
.creationTime
.tv_nsec
;
1683 static int vfs_gpfs_fstat(struct vfs_handle_struct
*handle
,
1684 struct files_struct
*fsp
, SMB_STRUCT_STAT
*sbuf
)
1686 struct gpfs_winattr attrs
;
1688 struct gpfs_config_data
*config
;
1690 SMB_VFS_HANDLE_GET_DATA(handle
, config
,
1691 struct gpfs_config_data
,
1694 ret
= SMB_VFS_NEXT_FSTAT(handle
, fsp
, sbuf
);
1698 if ((fsp
->fh
== NULL
) || (fsp
->fh
->fd
== -1)) {
1701 if (!config
->winattr
) {
1705 ret
= gpfswrap_get_winattrs(fsp
->fh
->fd
, &attrs
);
1707 sbuf
->st_ex_calculated_birthtime
= false;
1708 sbuf
->st_ex_btime
.tv_sec
= attrs
.creationTime
.tv_sec
;
1709 sbuf
->st_ex_btime
.tv_nsec
= attrs
.creationTime
.tv_nsec
;
1714 static int vfs_gpfs_lstat(struct vfs_handle_struct
*handle
,
1715 struct smb_filename
*smb_fname
)
1717 struct gpfs_winattr attrs
;
1721 struct gpfs_config_data
*config
;
1723 SMB_VFS_HANDLE_GET_DATA(handle
, config
,
1724 struct gpfs_config_data
,
1727 ret
= SMB_VFS_NEXT_LSTAT(handle
, smb_fname
);
1728 #if defined(HAVE_FSTATAT)
1729 if (ret
== -1 && errno
== EACCES
) {
1730 DEBUG(10, ("Trying lstat with capability for %s\n",
1731 smb_fname
->base_name
));
1732 ret
= stat_with_capability(handle
, smb_fname
,
1733 AT_SYMLINK_NOFOLLOW
);
1740 if (!config
->winattr
) {
1744 status
= get_full_smb_filename(talloc_tos(), smb_fname
, &path
);
1745 if (!NT_STATUS_IS_OK(status
)) {
1746 errno
= map_errno_from_nt_status(status
);
1749 ret
= gpfswrap_get_winattrs_path(discard_const_p(char, path
), &attrs
);
1752 smb_fname
->st
.st_ex_calculated_birthtime
= false;
1753 smb_fname
->st
.st_ex_btime
.tv_sec
= attrs
.creationTime
.tv_sec
;
1754 smb_fname
->st
.st_ex_btime
.tv_nsec
= attrs
.creationTime
.tv_nsec
;
1759 static void timespec_to_gpfs_time(struct timespec ts
, gpfs_timestruc_t
*gt
,
1760 int idx
, int *flags
)
1762 if (!null_timespec(ts
)) {
1764 gt
[idx
].tv_sec
= ts
.tv_sec
;
1765 gt
[idx
].tv_nsec
= ts
.tv_nsec
;
1766 DEBUG(10, ("Setting GPFS time %d, flags 0x%x\n", idx
, *flags
));
1770 static int smbd_gpfs_set_times_path(char *path
, struct smb_file_time
*ft
)
1772 gpfs_timestruc_t gpfs_times
[4];
1776 ZERO_ARRAY(gpfs_times
);
1777 timespec_to_gpfs_time(ft
->atime
, gpfs_times
, 0, &flags
);
1778 timespec_to_gpfs_time(ft
->mtime
, gpfs_times
, 1, &flags
);
1779 /* No good mapping from LastChangeTime to ctime, not storing */
1780 timespec_to_gpfs_time(ft
->create_time
, gpfs_times
, 3, &flags
);
1783 DEBUG(10, ("nothing to do, return to avoid EINVAL\n"));
1787 rc
= gpfswrap_set_times_path(path
, flags
, gpfs_times
);
1789 if (rc
!= 0 && errno
!= ENOSYS
) {
1790 DEBUG(1,("gpfs_set_times() returned with error %s\n",
1797 static int vfs_gpfs_ntimes(struct vfs_handle_struct
*handle
,
1798 const struct smb_filename
*smb_fname
,
1799 struct smb_file_time
*ft
)
1802 struct gpfs_winattr attrs
;
1806 struct gpfs_config_data
*config
;
1808 SMB_VFS_HANDLE_GET_DATA(handle
, config
,
1809 struct gpfs_config_data
,
1812 status
= get_full_smb_filename(talloc_tos(), smb_fname
, &path
);
1813 if (!NT_STATUS_IS_OK(status
)) {
1814 errno
= map_errno_from_nt_status(status
);
1818 /* Try to use gpfs_set_times if it is enabled and available */
1819 if (config
->settimes
) {
1820 ret
= smbd_gpfs_set_times_path(path
, ft
);
1822 if (ret
== 0 || (ret
== -1 && errno
!= ENOSYS
)) {
1827 DEBUG(10,("gpfs_set_times() not available or disabled, "
1828 "use ntimes and winattr\n"));
1830 ret
= SMB_VFS_NEXT_NTIMES(handle
, smb_fname
, ft
);
1832 /* don't complain if access was denied */
1833 if (errno
!= EPERM
&& errno
!= EACCES
) {
1834 DEBUG(1,("vfs_gpfs_ntimes: SMB_VFS_NEXT_NTIMES failed:"
1835 "%s", strerror(errno
)));
1840 if(null_timespec(ft
->create_time
)){
1841 DEBUG(10,("vfs_gpfs_ntimes:Create Time is NULL\n"));
1845 if (!config
->winattr
) {
1850 attrs
.creationTime
.tv_sec
= ft
->create_time
.tv_sec
;
1851 attrs
.creationTime
.tv_nsec
= ft
->create_time
.tv_nsec
;
1853 ret
= gpfswrap_set_winattrs_path(discard_const_p(char, path
),
1854 GPFS_WINATTR_SET_CREATION_TIME
,
1856 if(ret
== -1 && errno
!= ENOSYS
){
1857 DEBUG(1,("vfs_gpfs_ntimes: set GPFS ntimes failed %d\n",ret
));
1864 static int vfs_gpfs_fallocate(struct vfs_handle_struct
*handle
,
1865 struct files_struct
*fsp
, uint32_t mode
,
1866 off_t offset
, off_t len
)
1869 struct gpfs_config_data
*config
;
1871 SMB_VFS_HANDLE_GET_DATA(handle
, config
,
1872 struct gpfs_config_data
,
1875 if (!config
->prealloc
) {
1876 /* you should better not run fallocate() on GPFS at all */
1882 DEBUG(10, ("unmapped fallocate flags: %lx\n",
1883 (unsigned long)mode
));
1888 ret
= gpfswrap_prealloc(fsp
->fh
->fd
, offset
, len
);
1890 if (ret
== -1 && errno
!= ENOSYS
) {
1891 DEBUG(0, ("GPFS prealloc failed: %s\n", strerror(errno
)));
1892 } else if (ret
== -1 && errno
== ENOSYS
) {
1893 DEBUG(10, ("GPFS prealloc not supported.\n"));
1895 DEBUG(10, ("GPFS prealloc succeeded.\n"));
1901 static int vfs_gpfs_ftruncate(vfs_handle_struct
*handle
, files_struct
*fsp
,
1905 struct gpfs_config_data
*config
;
1907 SMB_VFS_HANDLE_GET_DATA(handle
, config
,
1908 struct gpfs_config_data
,
1911 if (!config
->ftruncate
) {
1912 return SMB_VFS_NEXT_FTRUNCATE(handle
, fsp
, len
);
1915 result
= gpfswrap_ftruncate(fsp
->fh
->fd
, len
);
1916 if ((result
== -1) && (errno
== ENOSYS
)) {
1917 return SMB_VFS_NEXT_FTRUNCATE(handle
, fsp
, len
);
1922 static bool vfs_gpfs_is_offline(struct vfs_handle_struct
*handle
,
1923 const struct smb_filename
*fname
,
1924 SMB_STRUCT_STAT
*sbuf
)
1926 struct gpfs_winattr attrs
;
1929 struct gpfs_config_data
*config
;
1932 SMB_VFS_HANDLE_GET_DATA(handle
, config
,
1933 struct gpfs_config_data
,
1936 if (!config
->winattr
) {
1937 return SMB_VFS_NEXT_IS_OFFLINE(handle
, fname
, sbuf
);
1940 status
= get_full_smb_filename(talloc_tos(), fname
, &path
);
1941 if (!NT_STATUS_IS_OK(status
)) {
1942 errno
= map_errno_from_nt_status(status
);
1946 ret
= gpfswrap_get_winattrs_path(path
, &attrs
);
1952 if ((attrs
.winAttrs
& GPFS_WINATTR_OFFLINE
) != 0) {
1953 DEBUG(10, ("%s is offline\n", path
));
1957 DEBUG(10, ("%s is online\n", path
));
1959 return SMB_VFS_NEXT_IS_OFFLINE(handle
, fname
, sbuf
);
1962 static bool vfs_gpfs_fsp_is_offline(struct vfs_handle_struct
*handle
,
1963 struct files_struct
*fsp
)
1965 struct gpfs_fsp_extension
*ext
;
1967 ext
= VFS_FETCH_FSP_EXTENSION(handle
, fsp
);
1970 * Something bad happened, always ask.
1972 return vfs_gpfs_is_offline(handle
, fsp
->fsp_name
,
1973 &fsp
->fsp_name
->st
);
1978 * As long as it's offline, ask.
1980 ext
->offline
= vfs_gpfs_is_offline(handle
, fsp
->fsp_name
,
1981 &fsp
->fsp_name
->st
);
1984 return ext
->offline
;
1987 static bool vfs_gpfs_aio_force(struct vfs_handle_struct
*handle
,
1988 struct files_struct
*fsp
)
1990 return vfs_gpfs_fsp_is_offline(handle
, fsp
);
1993 static ssize_t
vfs_gpfs_sendfile(vfs_handle_struct
*handle
, int tofd
,
1994 files_struct
*fsp
, const DATA_BLOB
*hdr
,
1995 off_t offset
, size_t n
)
1997 if (vfs_gpfs_fsp_is_offline(handle
, fsp
)) {
2001 return SMB_VFS_NEXT_SENDFILE(handle
, tofd
, fsp
, hdr
, offset
, n
);
2004 static int vfs_gpfs_connect(struct vfs_handle_struct
*handle
,
2005 const char *service
, const char *user
)
2007 struct gpfs_config_data
*config
;
2010 gpfswrap_lib_init(0);
2012 config
= talloc_zero(handle
->conn
, struct gpfs_config_data
);
2014 DEBUG(0, ("talloc_zero() failed\n"));
2019 ret
= SMB_VFS_NEXT_CONNECT(handle
, service
, user
);
2021 TALLOC_FREE(config
);
2025 config
->sharemodes
= lp_parm_bool(SNUM(handle
->conn
), "gpfs",
2026 "sharemodes", true);
2028 config
->leases
= lp_parm_bool(SNUM(handle
->conn
), "gpfs",
2031 config
->hsm
= lp_parm_bool(SNUM(handle
->conn
), "gpfs",
2034 config
->syncio
= lp_parm_bool(SNUM(handle
->conn
), "gpfs",
2037 config
->winattr
= lp_parm_bool(SNUM(handle
->conn
), "gpfs",
2040 config
->ftruncate
= lp_parm_bool(SNUM(handle
->conn
), "gpfs",
2043 config
->getrealfilename
= lp_parm_bool(SNUM(handle
->conn
), "gpfs",
2044 "getrealfilename", true);
2046 config
->dfreequota
= lp_parm_bool(SNUM(handle
->conn
), "gpfs",
2047 "dfreequota", false);
2049 config
->prealloc
= lp_parm_bool(SNUM(handle
->conn
), "gpfs",
2052 config
->acl
= lp_parm_bool(SNUM(handle
->conn
), "gpfs", "acl", true);
2054 config
->settimes
= lp_parm_bool(SNUM(handle
->conn
), "gpfs",
2056 config
->recalls
= lp_parm_bool(SNUM(handle
->conn
), "gpfs",
2059 SMB_VFS_HANDLE_SET_DATA(handle
, config
,
2060 NULL
, struct gpfs_config_data
,
2063 if (config
->leases
) {
2065 * GPFS lease code is based on kernel oplock code
2066 * so make sure it is turned on
2068 if (!lp_kernel_oplocks(SNUM(handle
->conn
))) {
2069 DEBUG(5, ("Enabling kernel oplocks for "
2070 "gpfs:leases to work\n"));
2071 lp_do_parameter(SNUM(handle
->conn
), "kernel oplocks",
2076 * as the kernel does not properly support Level II oplocks
2077 * and GPFS leases code is based on kernel infrastructure, we
2078 * need to turn off Level II oplocks if gpfs:leases is enabled
2080 if (lp_level2_oplocks(SNUM(handle
->conn
))) {
2081 DEBUG(5, ("gpfs:leases are enabled, disabling "
2082 "Level II oplocks\n"));
2083 lp_do_parameter(SNUM(handle
->conn
), "level2 oplocks",
2091 static int get_gpfs_quota(const char *pathname
, int type
, int id
,
2092 struct gpfs_quotaInfo
*qi
)
2096 ret
= gpfswrap_quotactl(discard_const_p(char, pathname
),
2097 GPFS_QCMD(Q_GETQUOTA
, type
), id
, qi
);
2100 if (errno
== GPFS_E_NO_QUOTA_INST
) {
2101 DEBUG(10, ("Quotas disabled on GPFS filesystem.\n"));
2102 } else if (errno
!= ENOSYS
) {
2103 DEBUG(0, ("Get quota failed, type %d, id, %d, "
2104 "errno %d.\n", type
, id
, errno
));
2110 DEBUG(10, ("quota type %d, id %d, blk u:%lld h:%lld s:%lld gt:%u\n",
2111 type
, id
, qi
->blockUsage
, qi
->blockHardLimit
,
2112 qi
->blockSoftLimit
, qi
->blockGraceTime
));
2117 static void vfs_gpfs_disk_free_quota(struct gpfs_quotaInfo qi
, time_t cur_time
,
2118 uint64_t *dfree
, uint64_t *dsize
)
2120 uint64_t usage
, limit
;
2123 * The quota reporting is done in units of 1024 byte blocks, but
2124 * sys_fsusage uses units of 512 byte blocks, adjust the block number
2125 * accordingly. Also filter possibly negative usage counts from gpfs.
2127 usage
= qi
.blockUsage
< 0 ? 0 : (uint64_t)qi
.blockUsage
* 2;
2128 limit
= (uint64_t)qi
.blockHardLimit
* 2;
2131 * When the grace time for the exceeded soft block quota has been
2132 * exceeded, the soft block quota becomes an additional hard limit.
2134 if (qi
.blockSoftLimit
&&
2135 qi
.blockGraceTime
&& cur_time
> qi
.blockGraceTime
) {
2136 /* report disk as full */
2138 *dsize
= MIN(*dsize
, usage
);
2141 if (!qi
.blockHardLimit
)
2144 if (usage
>= limit
) {
2145 /* report disk as full */
2147 *dsize
= MIN(*dsize
, usage
);
2150 /* limit has not been reached, determine "free space" */
2151 *dfree
= MIN(*dfree
, limit
- usage
);
2152 *dsize
= MIN(*dsize
, limit
);
2156 static uint64_t vfs_gpfs_disk_free(vfs_handle_struct
*handle
, const char *path
,
2158 uint64_t *dfree
, uint64_t *dsize
)
2160 struct security_unix_token
*utok
;
2161 struct gpfs_quotaInfo qi_user
= { 0 }, qi_group
= { 0 };
2162 struct gpfs_config_data
*config
;
2166 SMB_VFS_HANDLE_GET_DATA(handle
, config
, struct gpfs_config_data
,
2167 return (uint64_t)-1);
2168 if (!config
->dfreequota
) {
2169 return SMB_VFS_NEXT_DISK_FREE(handle
, path
,
2170 bsize
, dfree
, dsize
);
2173 err
= sys_fsusage(path
, dfree
, dsize
);
2175 DEBUG (0, ("Could not get fs usage, errno %d\n", errno
));
2176 return SMB_VFS_NEXT_DISK_FREE(handle
, path
,
2177 bsize
, dfree
, dsize
);
2180 /* sys_fsusage returns units of 512 bytes */
2183 DEBUG(10, ("fs dfree %llu, dsize %llu\n",
2184 (unsigned long long)*dfree
, (unsigned long long)*dsize
));
2186 utok
= handle
->conn
->session_info
->unix_token
;
2188 err
= get_gpfs_quota(path
, GPFS_USRQUOTA
, utok
->uid
, &qi_user
);
2190 return SMB_VFS_NEXT_DISK_FREE(handle
, path
,
2191 bsize
, dfree
, dsize
);
2194 err
= get_gpfs_quota(path
, GPFS_GRPQUOTA
, utok
->gid
, &qi_group
);
2196 return SMB_VFS_NEXT_DISK_FREE(handle
, path
,
2197 bsize
, dfree
, dsize
);
2200 cur_time
= time(NULL
);
2202 /* Adjust free space and size according to quota limits. */
2203 vfs_gpfs_disk_free_quota(qi_user
, cur_time
, dfree
, dsize
);
2204 vfs_gpfs_disk_free_quota(qi_group
, cur_time
, dfree
, dsize
);
2206 disk_norm(bsize
, dfree
, dsize
);
2210 static uint32_t vfs_gpfs_capabilities(struct vfs_handle_struct
*handle
,
2211 enum timestamp_set_resolution
*p_ts_res
)
2213 struct gpfs_config_data
*config
;
2216 next
= SMB_VFS_NEXT_FS_CAPABILITIES(handle
, p_ts_res
);
2218 SMB_VFS_HANDLE_GET_DATA(handle
, config
,
2219 struct gpfs_config_data
,
2223 next
|= FILE_SUPPORTS_REMOTE_STORAGE
;
2228 static int vfs_gpfs_open(struct vfs_handle_struct
*handle
,
2229 struct smb_filename
*smb_fname
, files_struct
*fsp
,
2230 int flags
, mode_t mode
)
2232 struct gpfs_config_data
*config
;
2234 struct gpfs_fsp_extension
*ext
;
2236 SMB_VFS_HANDLE_GET_DATA(handle
, config
,
2237 struct gpfs_config_data
,
2240 if (config
->hsm
&& !config
->recalls
&&
2241 vfs_gpfs_fsp_is_offline(handle
, fsp
)) {
2242 DEBUG(10, ("Refusing access to offline file %s\n",
2248 if (config
->syncio
) {
2252 ext
= VFS_ADD_FSP_EXTENSION(handle
, fsp
, struct gpfs_fsp_extension
,
2260 * Assume the file is offline until gpfs tells us it's online.
2262 *ext
= (struct gpfs_fsp_extension
) { .offline
= true };
2264 ret
= SMB_VFS_NEXT_OPEN(handle
, smb_fname
, fsp
, flags
, mode
);
2266 VFS_REMOVE_FSP_EXTENSION(handle
, fsp
);
2271 static ssize_t
vfs_gpfs_pread(vfs_handle_struct
*handle
, files_struct
*fsp
,
2272 void *data
, size_t n
, off_t offset
)
2277 was_offline
= vfs_gpfs_fsp_is_offline(handle
, fsp
);
2279 ret
= SMB_VFS_NEXT_PREAD(handle
, fsp
, data
, n
, offset
);
2281 if ((ret
!= -1) && was_offline
) {
2282 notify_fname(handle
->conn
, NOTIFY_ACTION_MODIFIED
,
2283 FILE_NOTIFY_CHANGE_ATTRIBUTES
,
2284 fsp
->fsp_name
->base_name
);
2290 struct vfs_gpfs_pread_state
{
2291 struct files_struct
*fsp
;
2297 static void vfs_gpfs_pread_done(struct tevent_req
*subreq
);
2299 static struct tevent_req
*vfs_gpfs_pread_send(struct vfs_handle_struct
*handle
,
2300 TALLOC_CTX
*mem_ctx
,
2301 struct tevent_context
*ev
,
2302 struct files_struct
*fsp
,
2303 void *data
, size_t n
,
2306 struct tevent_req
*req
, *subreq
;
2307 struct vfs_gpfs_pread_state
*state
;
2309 req
= tevent_req_create(mem_ctx
, &state
, struct vfs_gpfs_pread_state
);
2313 state
->was_offline
= vfs_gpfs_fsp_is_offline(handle
, fsp
);
2315 subreq
= SMB_VFS_NEXT_PREAD_SEND(state
, ev
, handle
, fsp
, data
,
2317 if (tevent_req_nomem(subreq
, req
)) {
2318 return tevent_req_post(req
, ev
);
2320 tevent_req_set_callback(subreq
, vfs_gpfs_pread_done
, req
);
2324 static void vfs_gpfs_pread_done(struct tevent_req
*subreq
)
2326 struct tevent_req
*req
= tevent_req_callback_data(
2327 subreq
, struct tevent_req
);
2328 struct vfs_gpfs_pread_state
*state
= tevent_req_data(
2329 req
, struct vfs_gpfs_pread_state
);
2331 state
->ret
= SMB_VFS_PREAD_RECV(subreq
, &state
->err
);
2332 TALLOC_FREE(subreq
);
2333 tevent_req_done(req
);
2336 static ssize_t
vfs_gpfs_pread_recv(struct tevent_req
*req
, int *err
)
2338 struct vfs_gpfs_pread_state
*state
= tevent_req_data(
2339 req
, struct vfs_gpfs_pread_state
);
2340 struct files_struct
*fsp
= state
->fsp
;
2342 if (tevent_req_is_unix_error(req
, err
)) {
2347 if ((state
->ret
!= -1) && state
->was_offline
) {
2348 DEBUG(10, ("sending notify\n"));
2349 notify_fname(fsp
->conn
, NOTIFY_ACTION_MODIFIED
,
2350 FILE_NOTIFY_CHANGE_ATTRIBUTES
,
2351 fsp
->fsp_name
->base_name
);
2357 static ssize_t
vfs_gpfs_pwrite(vfs_handle_struct
*handle
, files_struct
*fsp
,
2358 const void *data
, size_t n
, off_t offset
)
2363 was_offline
= vfs_gpfs_fsp_is_offline(handle
, fsp
);
2365 ret
= SMB_VFS_NEXT_PWRITE(handle
, fsp
, data
, n
, offset
);
2367 if ((ret
!= -1) && was_offline
) {
2368 notify_fname(handle
->conn
, NOTIFY_ACTION_MODIFIED
,
2369 FILE_NOTIFY_CHANGE_ATTRIBUTES
,
2370 fsp
->fsp_name
->base_name
);
2376 struct vfs_gpfs_pwrite_state
{
2377 struct files_struct
*fsp
;
2383 static void vfs_gpfs_pwrite_done(struct tevent_req
*subreq
);
2385 static struct tevent_req
*vfs_gpfs_pwrite_send(
2386 struct vfs_handle_struct
*handle
,
2387 TALLOC_CTX
*mem_ctx
,
2388 struct tevent_context
*ev
,
2389 struct files_struct
*fsp
,
2390 const void *data
, size_t n
,
2393 struct tevent_req
*req
, *subreq
;
2394 struct vfs_gpfs_pwrite_state
*state
;
2396 req
= tevent_req_create(mem_ctx
, &state
, struct vfs_gpfs_pwrite_state
);
2400 state
->was_offline
= vfs_gpfs_fsp_is_offline(handle
, fsp
);
2402 subreq
= SMB_VFS_NEXT_PWRITE_SEND(state
, ev
, handle
, fsp
, data
,
2404 if (tevent_req_nomem(subreq
, req
)) {
2405 return tevent_req_post(req
, ev
);
2407 tevent_req_set_callback(subreq
, vfs_gpfs_pwrite_done
, req
);
2411 static void vfs_gpfs_pwrite_done(struct tevent_req
*subreq
)
2413 struct tevent_req
*req
= tevent_req_callback_data(
2414 subreq
, struct tevent_req
);
2415 struct vfs_gpfs_pwrite_state
*state
= tevent_req_data(
2416 req
, struct vfs_gpfs_pwrite_state
);
2418 state
->ret
= SMB_VFS_PWRITE_RECV(subreq
, &state
->err
);
2419 TALLOC_FREE(subreq
);
2420 tevent_req_done(req
);
2423 static ssize_t
vfs_gpfs_pwrite_recv(struct tevent_req
*req
, int *err
)
2425 struct vfs_gpfs_pwrite_state
*state
= tevent_req_data(
2426 req
, struct vfs_gpfs_pwrite_state
);
2427 struct files_struct
*fsp
= state
->fsp
;
2429 if (tevent_req_is_unix_error(req
, err
)) {
2434 if ((state
->ret
!= -1) && state
->was_offline
) {
2435 DEBUG(10, ("sending notify\n"));
2436 notify_fname(fsp
->conn
, NOTIFY_ACTION_MODIFIED
,
2437 FILE_NOTIFY_CHANGE_ATTRIBUTES
,
2438 fsp
->fsp_name
->base_name
);
2445 static struct vfs_fn_pointers vfs_gpfs_fns
= {
2446 .connect_fn
= vfs_gpfs_connect
,
2447 .disk_free_fn
= vfs_gpfs_disk_free
,
2448 .fs_capabilities_fn
= vfs_gpfs_capabilities
,
2449 .kernel_flock_fn
= vfs_gpfs_kernel_flock
,
2450 .linux_setlease_fn
= vfs_gpfs_setlease
,
2451 .get_real_filename_fn
= vfs_gpfs_get_real_filename
,
2452 .fget_nt_acl_fn
= gpfsacl_fget_nt_acl
,
2453 .get_nt_acl_fn
= gpfsacl_get_nt_acl
,
2454 .fset_nt_acl_fn
= gpfsacl_fset_nt_acl
,
2455 .sys_acl_get_file_fn
= gpfsacl_sys_acl_get_file
,
2456 .sys_acl_get_fd_fn
= gpfsacl_sys_acl_get_fd
,
2457 .sys_acl_blob_get_file_fn
= gpfsacl_sys_acl_blob_get_file
,
2458 .sys_acl_blob_get_fd_fn
= gpfsacl_sys_acl_blob_get_fd
,
2459 .sys_acl_set_file_fn
= gpfsacl_sys_acl_set_file
,
2460 .sys_acl_set_fd_fn
= gpfsacl_sys_acl_set_fd
,
2461 .sys_acl_delete_def_file_fn
= gpfsacl_sys_acl_delete_def_file
,
2462 .chmod_fn
= vfs_gpfs_chmod
,
2463 .fchmod_fn
= vfs_gpfs_fchmod
,
2464 .close_fn
= vfs_gpfs_close
,
2465 .setxattr_fn
= gpfs_set_xattr
,
2466 .getxattr_fn
= gpfs_get_xattr
,
2467 .stat_fn
= vfs_gpfs_stat
,
2468 .fstat_fn
= vfs_gpfs_fstat
,
2469 .lstat_fn
= vfs_gpfs_lstat
,
2470 .ntimes_fn
= vfs_gpfs_ntimes
,
2471 .is_offline_fn
= vfs_gpfs_is_offline
,
2472 .aio_force_fn
= vfs_gpfs_aio_force
,
2473 .sendfile_fn
= vfs_gpfs_sendfile
,
2474 .fallocate_fn
= vfs_gpfs_fallocate
,
2475 .open_fn
= vfs_gpfs_open
,
2476 .pread_fn
= vfs_gpfs_pread
,
2477 .pread_send_fn
= vfs_gpfs_pread_send
,
2478 .pread_recv_fn
= vfs_gpfs_pread_recv
,
2479 .pwrite_fn
= vfs_gpfs_pwrite
,
2480 .pwrite_send_fn
= vfs_gpfs_pwrite_send
,
2481 .pwrite_recv_fn
= vfs_gpfs_pwrite_recv
,
2482 .ftruncate_fn
= vfs_gpfs_ftruncate
2485 NTSTATUS
vfs_gpfs_init(void);
2486 NTSTATUS
vfs_gpfs_init(void)
2490 ret
= gpfswrap_init();
2492 DEBUG(1, ("Could not initialize GPFS library wrapper\n"));
2495 return smb_register_vfs(SMB_VFS_INTERFACE_VERSION
, "gpfs",