2 Unix SMB/CIFS implementation.
3 Wrap disk only vfs functions to sidestep dodgy compilers.
4 Copyright (C) Tim Potter 1998
5 Copyright (C) Jeremy Allison 2007
6 Copyright (C) Brian Chrisman 2011 <bchrisman@gmail.com>
7 Copyright (C) Richard Sharpe 2011 <realrichardsharpe@gmail.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 * This VFS only works with the libcephfs.so user-space client. It is not needed
25 * if you are using the kernel client or the FUSE client.
27 * Add the following smb.conf parameter to each share that will be hosted on
30 * vfs objects = [any others you need go here] ceph
34 #include "smbd/smbd.h"
35 #include "system/filesys.h"
37 #include <sys/statvfs.h>
38 #include "cephfs/libcephfs.h"
39 #include "smbprofile.h"
40 #include "modules/posixacl_xattr.h"
41 #include "lib/util/tevent_unix.h"
44 #define DBGC_CLASS DBGC_VFS
46 #ifndef LIBCEPHFS_VERSION
47 #define LIBCEPHFS_VERSION(maj, min, extra) ((maj << 16) + (min << 8) + extra)
48 #define LIBCEPHFS_VERSION_CODE LIBCEPHFS_VERSION(0, 0, 0)
52 * Use %llu whenever we have a 64bit unsigned int, and cast to (long long unsigned)
54 #define llu(_var) ((long long unsigned)_var)
57 * Note, libcephfs's return code model is to return -errno! So we have to
58 * convert to what Samba expects, which is to set errno to -return and return -1
60 #define WRAP_RETURN(_res) \
69 * Track unique connections, as virtual mounts, to cephfs file systems.
70 * Individual mounts will be set on the handle->data attribute, but
71 * the mounts themselves will be shared so as not to spawn extra mounts
74 * Individual mounts are IDed by a 'cookie' value that is a string built
75 * from identifying parameters found in smb.conf.
78 static struct cephmount_cached
{
81 struct ceph_mount_info
*mount
;
82 struct cephmount_cached
*next
, *prev
;
85 static int cephmount_cache_add(const char *cookie
,
86 struct ceph_mount_info
*mount
)
88 struct cephmount_cached
*entry
= NULL
;
90 entry
= talloc_zero(NULL
, struct cephmount_cached
);
96 entry
->cookie
= talloc_strdup(entry
, cookie
);
97 if (entry
->cookie
== NULL
) {
103 entry
->mount
= mount
;
106 DBG_DEBUG("adding mount cache entry for %s\n", entry
->cookie
);
107 DLIST_ADD(cephmount_cached
, entry
);
111 static struct ceph_mount_info
*cephmount_cache_update(const char *cookie
)
113 struct cephmount_cached
*entry
= NULL
;
115 for (entry
= cephmount_cached
; entry
; entry
= entry
->next
) {
116 if (strcmp(entry
->cookie
, cookie
) == 0) {
118 DBG_DEBUG("updated mount cache: count is [%"
119 PRIu32
"]\n", entry
->count
);
128 static int cephmount_cache_remove(struct ceph_mount_info
*mount
)
130 struct cephmount_cached
*entry
= NULL
;
132 for (entry
= cephmount_cached
; entry
; entry
= entry
->next
) {
133 if (entry
->mount
== mount
) {
134 if (--entry
->count
) {
135 DBG_DEBUG("updated mount cache: count is [%"
136 PRIu32
"]\n", entry
->count
);
140 DBG_DEBUG("removing mount cache entry for %s\n",
142 DLIST_REMOVE(cephmount_cached
, entry
);
151 static char *cephmount_get_cookie(TALLOC_CTX
* mem_ctx
, const int snum
)
153 const char *conf_file
=
154 lp_parm_const_string(snum
, "ceph", "config_file", ".");
155 const char *user_id
= lp_parm_const_string(snum
, "ceph", "user_id", "");
157 lp_parm_const_string(snum
, "ceph", "filesystem", "");
158 return talloc_asprintf(mem_ctx
, "(%s/%s/%s)", conf_file
, user_id
,
162 static int cephmount_select_fs(struct ceph_mount_info
*mnt
, const char *fsname
)
165 * ceph_select_filesystem was added in ceph 'nautilus' (v14).
166 * Earlier versions of libcephfs will lack that API function.
167 * At the time of this writing (Feb 2023) all versions of ceph
168 * supported by ceph upstream have this function.
170 #if defined(HAVE_CEPH_SELECT_FILESYSTEM)
171 DBG_DEBUG("[CEPH] calling: ceph_select_filesystem with %s\n", fsname
);
172 return ceph_select_filesystem(mnt
, fsname
);
174 DBG_ERR("[CEPH] ceph_select_filesystem not available\n");
179 static struct ceph_mount_info
*cephmount_mount_fs(const int snum
)
183 struct ceph_mount_info
*mnt
= NULL
;
184 /* if config_file and/or user_id are NULL, ceph will use defaults */
185 const char *conf_file
=
186 lp_parm_const_string(snum
, "ceph", "config_file", NULL
);
187 const char *user_id
=
188 lp_parm_const_string(snum
, "ceph", "user_id", NULL
);
190 lp_parm_const_string(snum
, "ceph", "filesystem", NULL
);
192 DBG_DEBUG("[CEPH] calling: ceph_create\n");
193 ret
= ceph_create(&mnt
, user_id
);
199 DBG_DEBUG("[CEPH] calling: ceph_conf_read_file with %s\n",
200 (conf_file
== NULL
? "default path" : conf_file
));
201 ret
= ceph_conf_read_file(mnt
, conf_file
);
206 DBG_DEBUG("[CEPH] calling: ceph_conf_get\n");
207 ret
= ceph_conf_get(mnt
, "log file", buf
, sizeof(buf
));
212 /* libcephfs disables POSIX ACL support by default, enable it... */
213 ret
= ceph_conf_set(mnt
, "client_acl_type", "posix_acl");
217 /* tell libcephfs to perform local permission checks */
218 ret
= ceph_conf_set(mnt
, "fuse_default_permissions", "false");
223 * select a cephfs file system to use:
224 * In ceph, multiple file system support has been stable since 'pacific'.
225 * Permit different shares to access different file systems.
227 if (fsname
!= NULL
) {
228 ret
= cephmount_select_fs(mnt
, fsname
);
234 DBG_DEBUG("[CEPH] calling: ceph_mount\n");
235 ret
= ceph_mount(mnt
, NULL
);
243 DBG_DEBUG("[CEPH] Error mounting fs: %s\n", strerror(-ret
));
246 * Handle the error correctly. Ceph returns -errno.
254 /* Check for NULL pointer parameters in cephwrap_* functions */
256 /* We don't want to have NULL function pointers lying around. Someone
257 is sure to try and execute them. These stubs are used to prevent
260 static int cephwrap_connect(struct vfs_handle_struct
*handle
,
261 const char *service
, const char *user
)
264 struct ceph_mount_info
*cmount
= NULL
;
265 int snum
= SNUM(handle
->conn
);
266 char *cookie
= cephmount_get_cookie(handle
, snum
);
267 if (cookie
== NULL
) {
271 cmount
= cephmount_cache_update(cookie
);
272 if (cmount
!= NULL
) {
276 cmount
= cephmount_mount_fs(snum
);
277 if (cmount
== NULL
) {
281 ret
= cephmount_cache_add(cookie
, cmount
);
287 handle
->data
= cmount
;
288 DBG_WARNING("Connection established with the server: %s\n", cookie
);
290 * Unless we have an async implementation of getxattrat turn this off.
292 lp_do_parameter(SNUM(handle
->conn
), "smbd async dosmode", "false");
298 static void cephwrap_disconnect(struct vfs_handle_struct
*handle
)
300 int ret
= cephmount_cache_remove(handle
->data
);
302 DBG_ERR("failed to remove ceph mount from cache: %s\n",
307 DBG_DEBUG("mount cache entry still in use\n");
311 ret
= ceph_unmount(handle
->data
);
313 DBG_ERR("[CEPH] failed to unmount: %s\n", strerror(-ret
));
316 ret
= ceph_release(handle
->data
);
318 DBG_ERR("[CEPH] failed to release: %s\n", strerror(-ret
));
323 /* Disk operations */
325 static uint64_t cephwrap_disk_free(struct vfs_handle_struct
*handle
,
326 const struct smb_filename
*smb_fname
,
331 struct statvfs statvfs_buf
= { 0 };
334 if (!(ret
= ceph_statfs(handle
->data
, smb_fname
->base_name
,
337 * Provide all the correct values.
339 *bsize
= statvfs_buf
.f_bsize
;
340 *dfree
= statvfs_buf
.f_bavail
;
341 *dsize
= statvfs_buf
.f_blocks
;
342 DBG_DEBUG("[CEPH] bsize: %llu, dfree: %llu, dsize: %llu\n",
343 llu(*bsize
), llu(*dfree
), llu(*dsize
));
346 DBG_DEBUG("[CEPH] ceph_statfs returned %d\n", ret
);
351 static int cephwrap_get_quota(struct vfs_handle_struct
*handle
,
352 const struct smb_filename
*smb_fname
,
353 enum SMB_QUOTA_TYPE qtype
,
357 /* libcephfs: Ceph does not implement this */
359 /* was ifdef HAVE_SYS_QUOTAS */
362 ret
= ceph_get_quota(handle
->conn
->connectpath
, qtype
, id
, qt
);
376 static int cephwrap_set_quota(struct vfs_handle_struct
*handle
, enum SMB_QUOTA_TYPE qtype
, unid_t id
, SMB_DISK_QUOTA
*qt
)
378 /* libcephfs: Ceph does not implement this */
380 /* was ifdef HAVE_SYS_QUOTAS */
383 ret
= ceph_set_quota(handle
->conn
->connectpath
, qtype
, id
, qt
);
391 WRAP_RETURN(-ENOSYS
);
395 static int cephwrap_statvfs(struct vfs_handle_struct
*handle
,
396 const struct smb_filename
*smb_fname
,
397 struct vfs_statvfs_struct
*statbuf
)
399 struct statvfs statvfs_buf
= { 0 };
402 ret
= ceph_statfs(handle
->data
, smb_fname
->base_name
, &statvfs_buf
);
407 statbuf
->OptimalTransferSize
= statvfs_buf
.f_frsize
;
408 statbuf
->BlockSize
= statvfs_buf
.f_bsize
;
409 statbuf
->TotalBlocks
= statvfs_buf
.f_blocks
;
410 statbuf
->BlocksAvail
= statvfs_buf
.f_bfree
;
411 statbuf
->UserBlocksAvail
= statvfs_buf
.f_bavail
;
412 statbuf
->TotalFileNodes
= statvfs_buf
.f_files
;
413 statbuf
->FreeFileNodes
= statvfs_buf
.f_ffree
;
414 statbuf
->FsIdentifier
= statvfs_buf
.f_fsid
;
415 DBG_DEBUG("[CEPH] f_bsize: %ld, f_blocks: %ld, f_bfree: %ld, f_bavail: %ld\n",
416 (long int)statvfs_buf
.f_bsize
, (long int)statvfs_buf
.f_blocks
,
417 (long int)statvfs_buf
.f_bfree
, (long int)statvfs_buf
.f_bavail
);
422 static uint32_t cephwrap_fs_capabilities(struct vfs_handle_struct
*handle
,
423 enum timestamp_set_resolution
*p_ts_res
)
425 uint32_t caps
= FILE_CASE_SENSITIVE_SEARCH
| FILE_CASE_PRESERVED_NAMES
;
427 *p_ts_res
= TIMESTAMP_SET_NT_OR_BETTER
;
432 /* Directory operations */
434 static DIR *cephwrap_fdopendir(struct vfs_handle_struct
*handle
,
435 struct files_struct
*fsp
,
440 struct ceph_dir_result
*result
= NULL
;
442 #ifdef HAVE_CEPH_FDOPENDIR
443 int dirfd
= fsp_get_io_fd(fsp
);
444 DBG_DEBUG("[CEPH] fdopendir(%p, %d)\n", handle
, dirfd
);
445 ret
= ceph_fdopendir(handle
->data
, dirfd
, &result
);
447 DBG_DEBUG("[CEPH] fdopendir(%p, %p)\n", handle
, fsp
);
448 ret
= ceph_opendir(handle
->data
, fsp
->fsp_name
->base_name
, &result
);
452 errno
= -ret
; /* We return result which is NULL in this case */
455 DBG_DEBUG("[CEPH] fdopendir(...) = %d\n", ret
);
456 return (DIR *) result
;
459 static struct dirent
*cephwrap_readdir(struct vfs_handle_struct
*handle
,
460 struct files_struct
*dirfsp
,
463 struct dirent
*result
= NULL
;
465 DBG_DEBUG("[CEPH] readdir(%p, %p)\n", handle
, dirp
);
466 result
= ceph_readdir(handle
->data
, (struct ceph_dir_result
*) dirp
);
467 DBG_DEBUG("[CEPH] readdir(...) = %p\n", result
);
472 static void cephwrap_rewinddir(struct vfs_handle_struct
*handle
, DIR *dirp
)
474 DBG_DEBUG("[CEPH] rewinddir(%p, %p)\n", handle
, dirp
);
475 ceph_rewinddir(handle
->data
, (struct ceph_dir_result
*) dirp
);
478 static int cephwrap_mkdirat(struct vfs_handle_struct
*handle
,
479 files_struct
*dirfsp
,
480 const struct smb_filename
*smb_fname
,
484 #ifdef HAVE_CEPH_MKDIRAT
485 int dirfd
= fsp_get_pathref_fd(dirfsp
);
487 DBG_DEBUG("[CEPH] mkdirat(%p, %d, %s)\n",
490 smb_fname
->base_name
);
492 result
= ceph_mkdirat(handle
->data
, dirfd
, smb_fname
->base_name
, mode
);
494 DBG_DEBUG("[CEPH] mkdirat(...) = %d\n", result
);
498 struct smb_filename
*full_fname
= NULL
;
500 full_fname
= full_path_from_dirfsp_atname(talloc_tos(),
503 if (full_fname
== NULL
) {
507 DBG_DEBUG("[CEPH] mkdir(%p, %s)\n",
508 handle
, smb_fname_str_dbg(full_fname
));
510 result
= ceph_mkdir(handle
->data
, full_fname
->base_name
, mode
);
512 TALLOC_FREE(full_fname
);
518 static int cephwrap_closedir(struct vfs_handle_struct
*handle
, DIR *dirp
)
522 DBG_DEBUG("[CEPH] closedir(%p, %p)\n", handle
, dirp
);
523 result
= ceph_closedir(handle
->data
, (struct ceph_dir_result
*) dirp
);
524 DBG_DEBUG("[CEPH] closedir(...) = %d\n", result
);
528 /* File operations */
530 static int cephwrap_openat(struct vfs_handle_struct
*handle
,
531 const struct files_struct
*dirfsp
,
532 const struct smb_filename
*smb_fname
,
534 const struct vfs_open_how
*how
)
536 int flags
= how
->flags
;
537 mode_t mode
= how
->mode
;
538 struct smb_filename
*name
= NULL
;
539 bool have_opath
= false;
540 bool became_root
= false;
541 int result
= -ENOENT
;
542 #ifdef HAVE_CEPH_OPENAT
546 if (how
->resolve
!= 0) {
551 if (smb_fname
->stream_name
) {
557 if (fsp
->fsp_flags
.is_pathref
) {
562 #ifdef HAVE_CEPH_OPENAT
563 dirfd
= fsp_get_pathref_fd(dirfsp
);
565 DBG_DEBUG("[CEPH] openat(%p, %d, %p, %d, %d)\n",
566 handle
, dirfd
, fsp
, flags
, mode
);
568 if (fsp
->fsp_flags
.is_pathref
&& !have_opath
) {
573 result
= ceph_openat(handle
->data
,
575 smb_fname
->base_name
,
580 if (fsp_get_pathref_fd(dirfsp
) != AT_FDCWD
) {
581 name
= full_path_from_dirfsp_atname(talloc_tos(),
590 DBG_DEBUG("[CEPH] openat(%p, %s, %p, %d, %d)\n", handle
,
591 smb_fname_str_dbg(smb_fname
), fsp
, flags
, mode
);
593 if (fsp
->fsp_flags
.is_pathref
&& !have_opath
) {
598 result
= ceph_open(handle
->data
, smb_fname
->base_name
, flags
, mode
);
605 fsp
->fsp_flags
.have_proc_fds
= false;
606 DBG_DEBUG("[CEPH] open(...) = %d\n", result
);
610 static int cephwrap_close(struct vfs_handle_struct
*handle
, files_struct
*fsp
)
614 DBG_DEBUG("[CEPH] close(%p, %p)\n", handle
, fsp
);
615 result
= ceph_close(handle
->data
, fsp_get_pathref_fd(fsp
));
616 DBG_DEBUG("[CEPH] close(...) = %d\n", result
);
621 static ssize_t
cephwrap_pread(struct vfs_handle_struct
*handle
, files_struct
*fsp
, void *data
,
622 size_t n
, off_t offset
)
626 DBG_DEBUG("[CEPH] pread(%p, %p, %p, %llu, %llu)\n", handle
, fsp
, data
, llu(n
), llu(offset
));
628 result
= ceph_read(handle
->data
, fsp_get_io_fd(fsp
), data
, n
, offset
);
629 DBG_DEBUG("[CEPH] pread(...) = %llu\n", llu(result
));
633 struct cephwrap_pread_state
{
635 struct vfs_aio_state vfs_aio_state
;
639 * Fake up an async ceph read by calling the synchronous API.
641 static struct tevent_req
*cephwrap_pread_send(struct vfs_handle_struct
*handle
,
643 struct tevent_context
*ev
,
644 struct files_struct
*fsp
,
646 size_t n
, off_t offset
)
648 struct tevent_req
*req
= NULL
;
649 struct cephwrap_pread_state
*state
= NULL
;
652 DBG_DEBUG("[CEPH] %s\n", __func__
);
653 req
= tevent_req_create(mem_ctx
, &state
, struct cephwrap_pread_state
);
658 ret
= ceph_read(handle
->data
, fsp_get_io_fd(fsp
), data
, n
, offset
);
660 /* ceph returns -errno on error. */
661 tevent_req_error(req
, -ret
);
662 return tevent_req_post(req
, ev
);
665 state
->bytes_read
= ret
;
666 tevent_req_done(req
);
667 /* Return and schedule the completion of the call. */
668 return tevent_req_post(req
, ev
);
671 static ssize_t
cephwrap_pread_recv(struct tevent_req
*req
,
672 struct vfs_aio_state
*vfs_aio_state
)
674 struct cephwrap_pread_state
*state
=
675 tevent_req_data(req
, struct cephwrap_pread_state
);
677 DBG_DEBUG("[CEPH] %s\n", __func__
);
678 if (tevent_req_is_unix_error(req
, &vfs_aio_state
->error
)) {
681 *vfs_aio_state
= state
->vfs_aio_state
;
682 return state
->bytes_read
;
685 static ssize_t
cephwrap_pwrite(struct vfs_handle_struct
*handle
, files_struct
*fsp
, const void *data
,
686 size_t n
, off_t offset
)
690 DBG_DEBUG("[CEPH] pwrite(%p, %p, %p, %llu, %llu)\n", handle
, fsp
, data
, llu(n
), llu(offset
));
691 result
= ceph_write(handle
->data
, fsp_get_io_fd(fsp
), data
, n
, offset
);
692 DBG_DEBUG("[CEPH] pwrite(...) = %llu\n", llu(result
));
696 struct cephwrap_pwrite_state
{
697 ssize_t bytes_written
;
698 struct vfs_aio_state vfs_aio_state
;
702 * Fake up an async ceph write by calling the synchronous API.
704 static struct tevent_req
*cephwrap_pwrite_send(struct vfs_handle_struct
*handle
,
706 struct tevent_context
*ev
,
707 struct files_struct
*fsp
,
709 size_t n
, off_t offset
)
711 struct tevent_req
*req
= NULL
;
712 struct cephwrap_pwrite_state
*state
= NULL
;
715 DBG_DEBUG("[CEPH] %s\n", __func__
);
716 req
= tevent_req_create(mem_ctx
, &state
, struct cephwrap_pwrite_state
);
721 ret
= ceph_write(handle
->data
, fsp_get_io_fd(fsp
), data
, n
, offset
);
723 /* ceph returns -errno on error. */
724 tevent_req_error(req
, -ret
);
725 return tevent_req_post(req
, ev
);
728 state
->bytes_written
= ret
;
729 tevent_req_done(req
);
730 /* Return and schedule the completion of the call. */
731 return tevent_req_post(req
, ev
);
734 static ssize_t
cephwrap_pwrite_recv(struct tevent_req
*req
,
735 struct vfs_aio_state
*vfs_aio_state
)
737 struct cephwrap_pwrite_state
*state
=
738 tevent_req_data(req
, struct cephwrap_pwrite_state
);
740 DBG_DEBUG("[CEPH] %s\n", __func__
);
741 if (tevent_req_is_unix_error(req
, &vfs_aio_state
->error
)) {
744 *vfs_aio_state
= state
->vfs_aio_state
;
745 return state
->bytes_written
;
748 static off_t
cephwrap_lseek(struct vfs_handle_struct
*handle
, files_struct
*fsp
, off_t offset
, int whence
)
752 DBG_DEBUG("[CEPH] cephwrap_lseek\n");
753 result
= ceph_lseek(handle
->data
, fsp_get_io_fd(fsp
), offset
, whence
);
757 static ssize_t
cephwrap_sendfile(struct vfs_handle_struct
*handle
, int tofd
, files_struct
*fromfsp
, const DATA_BLOB
*hdr
,
758 off_t offset
, size_t n
)
761 * We cannot support sendfile because libcephfs is in user space.
763 DBG_DEBUG("[CEPH] cephwrap_sendfile\n");
768 static ssize_t
cephwrap_recvfile(struct vfs_handle_struct
*handle
,
775 * We cannot support recvfile because libcephfs is in user space.
777 DBG_DEBUG("[CEPH] cephwrap_recvfile\n");
782 static int cephwrap_renameat(struct vfs_handle_struct
*handle
,
783 files_struct
*srcfsp
,
784 const struct smb_filename
*smb_fname_src
,
785 files_struct
*dstfsp
,
786 const struct smb_filename
*smb_fname_dst
)
788 struct smb_filename
*full_fname_src
= NULL
;
789 struct smb_filename
*full_fname_dst
= NULL
;
792 DBG_DEBUG("[CEPH] cephwrap_renameat\n");
793 if (smb_fname_src
->stream_name
|| smb_fname_dst
->stream_name
) {
798 full_fname_src
= full_path_from_dirfsp_atname(talloc_tos(),
801 if (full_fname_src
== NULL
) {
805 full_fname_dst
= full_path_from_dirfsp_atname(talloc_tos(),
808 if (full_fname_dst
== NULL
) {
809 TALLOC_FREE(full_fname_src
);
814 result
= ceph_rename(handle
->data
,
815 full_fname_src
->base_name
,
816 full_fname_dst
->base_name
);
818 TALLOC_FREE(full_fname_src
);
819 TALLOC_FREE(full_fname_dst
);
825 * Fake up an async ceph fsync by calling the synchronous API.
828 static struct tevent_req
*cephwrap_fsync_send(struct vfs_handle_struct
*handle
,
830 struct tevent_context
*ev
,
833 struct tevent_req
*req
= NULL
;
834 struct vfs_aio_state
*state
= NULL
;
837 DBG_DEBUG("[CEPH] cephwrap_fsync_send\n");
839 req
= tevent_req_create(mem_ctx
, &state
, struct vfs_aio_state
);
844 /* Make sync call. */
845 ret
= ceph_fsync(handle
->data
, fsp_get_io_fd(fsp
), false);
848 /* ceph_fsync returns -errno on error. */
849 tevent_req_error(req
, -ret
);
850 return tevent_req_post(req
, ev
);
853 /* Mark it as done. */
854 tevent_req_done(req
);
855 /* Return and schedule the completion of the call. */
856 return tevent_req_post(req
, ev
);
859 static int cephwrap_fsync_recv(struct tevent_req
*req
,
860 struct vfs_aio_state
*vfs_aio_state
)
862 struct vfs_aio_state
*state
=
863 tevent_req_data(req
, struct vfs_aio_state
);
865 DBG_DEBUG("[CEPH] cephwrap_fsync_recv\n");
867 if (tevent_req_is_unix_error(req
, &vfs_aio_state
->error
)) {
870 *vfs_aio_state
= *state
;
874 #define SAMBA_STATX_ATTR_MASK (CEPH_STATX_BASIC_STATS|CEPH_STATX_BTIME)
876 static void init_stat_ex_from_ceph_statx(struct stat_ex
*dst
, const struct ceph_statx
*stx
)
878 DBG_DEBUG("[CEPH]\tstx = {dev = %llx, ino = %llu, mode = 0x%x, "
879 "nlink = %llu, uid = %d, gid = %d, rdev = %llx, size = %llu, "
880 "blksize = %llu, blocks = %llu, atime = %llu, mtime = %llu, "
881 "ctime = %llu, btime = %llu}\n",
882 llu(stx
->stx_dev
), llu(stx
->stx_ino
), stx
->stx_mode
,
883 llu(stx
->stx_nlink
), stx
->stx_uid
, stx
->stx_gid
,
884 llu(stx
->stx_rdev
), llu(stx
->stx_size
), llu(stx
->stx_blksize
),
885 llu(stx
->stx_blocks
), llu(stx
->stx_atime
.tv_sec
),
886 llu(stx
->stx_mtime
.tv_sec
), llu(stx
->stx_ctime
.tv_sec
),
887 llu(stx
->stx_btime
.tv_sec
));
889 if ((stx
->stx_mask
& SAMBA_STATX_ATTR_MASK
) != SAMBA_STATX_ATTR_MASK
) {
890 DBG_WARNING("%s: stx->stx_mask is incorrect (wanted %x, got %x)\n",
891 __func__
, SAMBA_STATX_ATTR_MASK
, stx
->stx_mask
);
894 dst
->st_ex_dev
= stx
->stx_dev
;
895 dst
->st_ex_rdev
= stx
->stx_rdev
;
896 dst
->st_ex_ino
= stx
->stx_ino
;
897 dst
->st_ex_mode
= stx
->stx_mode
;
898 dst
->st_ex_uid
= stx
->stx_uid
;
899 dst
->st_ex_gid
= stx
->stx_gid
;
900 dst
->st_ex_size
= stx
->stx_size
;
901 dst
->st_ex_nlink
= stx
->stx_nlink
;
902 dst
->st_ex_atime
= stx
->stx_atime
;
903 dst
->st_ex_btime
= stx
->stx_btime
;
904 dst
->st_ex_ctime
= stx
->stx_ctime
;
905 dst
->st_ex_mtime
= stx
->stx_mtime
;
906 dst
->st_ex_blksize
= stx
->stx_blksize
;
907 dst
->st_ex_blocks
= stx
->stx_blocks
;
910 static int cephwrap_stat(struct vfs_handle_struct
*handle
,
911 struct smb_filename
*smb_fname
)
914 struct ceph_statx stx
= { 0 };
916 DBG_DEBUG("[CEPH] stat(%p, %s)\n", handle
, smb_fname_str_dbg(smb_fname
));
918 if (smb_fname
->stream_name
) {
923 result
= ceph_statx(handle
->data
, smb_fname
->base_name
, &stx
,
924 SAMBA_STATX_ATTR_MASK
, 0);
925 DBG_DEBUG("[CEPH] statx(...) = %d\n", result
);
930 init_stat_ex_from_ceph_statx(&smb_fname
->st
, &stx
);
931 DBG_DEBUG("[CEPH] mode = 0x%x\n", smb_fname
->st
.st_ex_mode
);
935 static int cephwrap_fstat(struct vfs_handle_struct
*handle
, files_struct
*fsp
, SMB_STRUCT_STAT
*sbuf
)
938 struct ceph_statx stx
= { 0 };
939 int fd
= fsp_get_pathref_fd(fsp
);
941 DBG_DEBUG("[CEPH] fstat(%p, %d)\n", handle
, fd
);
942 result
= ceph_fstatx(handle
->data
, fd
, &stx
,
943 SAMBA_STATX_ATTR_MASK
, 0);
944 DBG_DEBUG("[CEPH] fstat(...) = %d\n", result
);
949 init_stat_ex_from_ceph_statx(sbuf
, &stx
);
950 DBG_DEBUG("[CEPH] mode = 0x%x\n", sbuf
->st_ex_mode
);
954 static int cephwrap_fstatat(struct vfs_handle_struct
*handle
,
955 const struct files_struct
*dirfsp
,
956 const struct smb_filename
*smb_fname
,
957 SMB_STRUCT_STAT
*sbuf
,
961 struct ceph_statx stx
= { 0 };
962 #ifdef HAVE_CEPH_STATXAT
963 int dirfd
= fsp_get_pathref_fd(dirfsp
);
965 DBG_DEBUG("[CEPH] fstatat(%p, %d, %s)\n",
966 handle
, dirfd
, smb_fname
->base_name
);
967 result
= ceph_statxat(handle
->data
, dirfd
, smb_fname
->base_name
,
968 &stx
, SAMBA_STATX_ATTR_MASK
, 0);
970 struct smb_filename
*full_fname
= NULL
;
972 full_fname
= full_path_from_dirfsp_atname(talloc_tos(),
975 if (full_fname
== NULL
) {
980 DBG_DEBUG("[CEPH] fstatat(%p, %s)\n",
981 handle
, smb_fname_str_dbg(full_fname
));
982 result
= ceph_statx(handle
->data
, full_fname
->base_name
,
983 &stx
, SAMBA_STATX_ATTR_MASK
, 0);
985 TALLOC_FREE(full_fname
);
988 DBG_DEBUG("[CEPH] fstatat(...) = %d\n", result
);
993 init_stat_ex_from_ceph_statx(sbuf
, &stx
);
994 DBG_DEBUG("[CEPH] mode = 0x%x\n", sbuf
->st_ex_mode
);
999 static int cephwrap_lstat(struct vfs_handle_struct
*handle
,
1000 struct smb_filename
*smb_fname
)
1003 struct ceph_statx stx
= { 0 };
1005 DBG_DEBUG("[CEPH] lstat(%p, %s)\n", handle
, smb_fname_str_dbg(smb_fname
));
1007 if (smb_fname
->stream_name
) {
1012 result
= ceph_statx(handle
->data
, smb_fname
->base_name
, &stx
,
1013 SAMBA_STATX_ATTR_MASK
, AT_SYMLINK_NOFOLLOW
);
1014 DBG_DEBUG("[CEPH] lstat(...) = %d\n", result
);
1016 WRAP_RETURN(result
);
1019 init_stat_ex_from_ceph_statx(&smb_fname
->st
, &stx
);
1023 static int cephwrap_fntimes(struct vfs_handle_struct
*handle
,
1025 struct smb_file_time
*ft
)
1027 struct ceph_statx stx
= { 0 };
1031 if (!is_omit_timespec(&ft
->atime
)) {
1032 stx
.stx_atime
= ft
->atime
;
1033 mask
|= CEPH_SETATTR_ATIME
;
1035 if (!is_omit_timespec(&ft
->mtime
)) {
1036 stx
.stx_mtime
= ft
->mtime
;
1037 mask
|= CEPH_SETATTR_MTIME
;
1039 if (!is_omit_timespec(&ft
->create_time
)) {
1040 stx
.stx_btime
= ft
->create_time
;
1041 mask
|= CEPH_SETATTR_BTIME
;
1048 if (!fsp
->fsp_flags
.is_pathref
) {
1050 * We can use an io_fd to set xattrs.
1052 result
= ceph_fsetattrx(handle
->data
,
1058 * This is no longer a handle based call.
1060 result
= ceph_setattrx(handle
->data
,
1061 fsp
->fsp_name
->base_name
,
1067 DBG_DEBUG("[CEPH] ntimes(%p, %s, {%ld, %ld, %ld, %ld}) = %d\n",
1068 handle
, fsp_str_dbg(fsp
), ft
->mtime
.tv_sec
, ft
->atime
.tv_sec
,
1069 ft
->ctime
.tv_sec
, ft
->create_time
.tv_sec
, result
);
1074 static int cephwrap_unlinkat(struct vfs_handle_struct
*handle
,
1075 struct files_struct
*dirfsp
,
1076 const struct smb_filename
*smb_fname
,
1080 #ifdef HAVE_CEPH_UNLINKAT
1081 int dirfd
= fsp_get_pathref_fd(dirfsp
);
1083 DBG_DEBUG("[CEPH] unlinkat(%p, %d, %s)\n",
1086 smb_fname_str_dbg(smb_fname
));
1088 if (smb_fname
->stream_name
) {
1093 result
= ceph_unlinkat(handle
->data
,
1095 smb_fname
->base_name
,
1097 DBG_DEBUG("[CEPH] unlinkat(...) = %d\n", result
);
1098 WRAP_RETURN(result
);
1100 struct smb_filename
*full_fname
= NULL
;
1102 DBG_DEBUG("[CEPH] unlink(%p, %s)\n",
1104 smb_fname_str_dbg(smb_fname
));
1106 if (smb_fname
->stream_name
) {
1111 full_fname
= full_path_from_dirfsp_atname(talloc_tos(),
1114 if (full_fname
== NULL
) {
1118 if (flags
& AT_REMOVEDIR
) {
1119 result
= ceph_rmdir(handle
->data
, full_fname
->base_name
);
1121 result
= ceph_unlink(handle
->data
, full_fname
->base_name
);
1123 TALLOC_FREE(full_fname
);
1124 DBG_DEBUG("[CEPH] unlink(...) = %d\n", result
);
1125 WRAP_RETURN(result
);
1129 static int cephwrap_fchmod(struct vfs_handle_struct
*handle
, files_struct
*fsp
, mode_t mode
)
1133 DBG_DEBUG("[CEPH] fchmod(%p, %p, %d)\n", handle
, fsp
, mode
);
1134 if (!fsp
->fsp_flags
.is_pathref
) {
1136 * We can use an io_fd to change permissions.
1138 result
= ceph_fchmod(handle
->data
, fsp_get_io_fd(fsp
), mode
);
1141 * This is no longer a handle based call.
1143 result
= ceph_chmod(handle
->data
,
1144 fsp
->fsp_name
->base_name
,
1147 DBG_DEBUG("[CEPH] fchmod(...) = %d\n", result
);
1148 WRAP_RETURN(result
);
1151 static int cephwrap_fchown(struct vfs_handle_struct
*handle
, files_struct
*fsp
, uid_t uid
, gid_t gid
)
1155 DBG_DEBUG("[CEPH] fchown(%p, %p, %d, %d)\n", handle
, fsp
, uid
, gid
);
1156 if (!fsp
->fsp_flags
.is_pathref
) {
1158 * We can use an io_fd to change ownership.
1160 result
= ceph_fchown(handle
->data
,
1166 * This is no longer a handle based call.
1168 result
= ceph_chown(handle
->data
,
1169 fsp
->fsp_name
->base_name
,
1174 DBG_DEBUG("[CEPH] fchown(...) = %d\n", result
);
1175 WRAP_RETURN(result
);
1178 static int cephwrap_lchown(struct vfs_handle_struct
*handle
,
1179 const struct smb_filename
*smb_fname
,
1184 DBG_DEBUG("[CEPH] lchown(%p, %s, %d, %d)\n", handle
, smb_fname
->base_name
, uid
, gid
);
1185 result
= ceph_lchown(handle
->data
, smb_fname
->base_name
, uid
, gid
);
1186 DBG_DEBUG("[CEPH] lchown(...) = %d\n", result
);
1187 WRAP_RETURN(result
);
1190 static int cephwrap_chdir(struct vfs_handle_struct
*handle
,
1191 const struct smb_filename
*smb_fname
)
1194 DBG_DEBUG("[CEPH] chdir(%p, %s)\n", handle
, smb_fname
->base_name
);
1195 result
= ceph_chdir(handle
->data
, smb_fname
->base_name
);
1196 DBG_DEBUG("[CEPH] chdir(...) = %d\n", result
);
1197 WRAP_RETURN(result
);
1200 static struct smb_filename
*cephwrap_getwd(struct vfs_handle_struct
*handle
,
1203 const char *cwd
= ceph_getcwd(handle
->data
);
1204 DBG_DEBUG("[CEPH] getwd(%p) = %s\n", handle
, cwd
);
1205 return synthetic_smb_fname(ctx
,
1213 static int strict_allocate_ftruncate(struct vfs_handle_struct
*handle
, files_struct
*fsp
, off_t len
)
1215 off_t space_to_write
;
1218 SMB_STRUCT_STAT
*pst
;
1220 status
= vfs_stat_fsp(fsp
);
1221 if (!NT_STATUS_IS_OK(status
)) {
1224 pst
= &fsp
->fsp_name
->st
;
1227 if (S_ISFIFO(pst
->st_ex_mode
))
1231 if (pst
->st_ex_size
== len
)
1234 /* Shrink - just ftruncate. */
1235 if (pst
->st_ex_size
> len
) {
1236 result
= ceph_ftruncate(handle
->data
, fsp_get_io_fd(fsp
), len
);
1237 WRAP_RETURN(result
);
1240 space_to_write
= len
- pst
->st_ex_size
;
1241 result
= ceph_fallocate(handle
->data
, fsp_get_io_fd(fsp
), 0, pst
->st_ex_size
,
1243 WRAP_RETURN(result
);
1246 static int cephwrap_ftruncate(struct vfs_handle_struct
*handle
, files_struct
*fsp
, off_t len
)
1250 DBG_DEBUG("[CEPH] ftruncate(%p, %p, %llu\n", handle
, fsp
, llu(len
));
1252 if (lp_strict_allocate(SNUM(fsp
->conn
))) {
1253 return strict_allocate_ftruncate(handle
, fsp
, len
);
1256 result
= ceph_ftruncate(handle
->data
, fsp_get_io_fd(fsp
), len
);
1257 WRAP_RETURN(result
);
1260 static int cephwrap_fallocate(struct vfs_handle_struct
*handle
,
1261 struct files_struct
*fsp
,
1268 DBG_DEBUG("[CEPH] fallocate(%p, %p, %u, %llu, %llu\n",
1269 handle
, fsp
, mode
, llu(offset
), llu(len
));
1270 /* unsupported mode flags are rejected by libcephfs */
1271 result
= ceph_fallocate(handle
->data
, fsp_get_io_fd(fsp
), mode
, offset
, len
);
1272 DBG_DEBUG("[CEPH] fallocate(...) = %d\n", result
);
1273 WRAP_RETURN(result
);
1276 static bool cephwrap_lock(struct vfs_handle_struct
*handle
, files_struct
*fsp
, int op
, off_t offset
, off_t count
, int type
)
1278 DBG_DEBUG("[CEPH] lock\n");
1282 static int cephwrap_filesystem_sharemode(struct vfs_handle_struct
*handle
,
1284 uint32_t share_access
,
1285 uint32_t access_mask
)
1287 DBG_ERR("[CEPH] filesystem sharemodes unsupported! Consider setting "
1288 "\"kernel share modes = no\"\n");
1294 static int cephwrap_fcntl(vfs_handle_struct
*handle
,
1295 files_struct
*fsp
, int cmd
, va_list cmd_arg
)
1298 * SMB_VFS_FCNTL() is currently only called by vfs_set_blocking() to
1299 * clear O_NONBLOCK, etc for LOCK_MAND and FIFOs. Ignore it.
1301 if (cmd
== F_GETFL
) {
1303 } else if (cmd
== F_SETFL
) {
1304 va_list dup_cmd_arg
;
1307 va_copy(dup_cmd_arg
, cmd_arg
);
1308 opt
= va_arg(dup_cmd_arg
, int);
1309 va_end(dup_cmd_arg
);
1313 DBG_ERR("unexpected fcntl SETFL(%d)\n", opt
);
1316 DBG_ERR("unexpected fcntl: %d\n", cmd
);
1322 static bool cephwrap_getlock(struct vfs_handle_struct
*handle
, files_struct
*fsp
, off_t
*poffset
, off_t
*pcount
, int *ptype
, pid_t
*ppid
)
1324 DBG_DEBUG("[CEPH] getlock returning false and errno=0\n");
1331 * We cannot let this fall through to the default, because the file might only
1332 * be accessible from libcephfs (which is a user-space client) but the fd might
1333 * be for some file the kernel knows about.
1335 static int cephwrap_linux_setlease(struct vfs_handle_struct
*handle
, files_struct
*fsp
,
1340 DBG_DEBUG("[CEPH] linux_setlease\n");
1345 static int cephwrap_symlinkat(struct vfs_handle_struct
*handle
,
1346 const struct smb_filename
*link_target
,
1347 struct files_struct
*dirfsp
,
1348 const struct smb_filename
*new_smb_fname
)
1351 #ifdef HAVE_CEPH_SYMLINKAT
1352 int dirfd
= fsp_get_pathref_fd(dirfsp
);
1354 DBG_DEBUG("[CEPH] symlinkat(%p, %s, %d, %s)\n",
1356 link_target
->base_name
,
1358 new_smb_fname
->base_name
);
1360 result
= ceph_symlinkat(handle
->data
,
1361 link_target
->base_name
,
1363 new_smb_fname
->base_name
);
1364 DBG_DEBUG("[CEPH] symlinkat(...) = %d\n", result
);
1365 WRAP_RETURN(result
);
1367 struct smb_filename
*full_fname
= NULL
;
1369 full_fname
= full_path_from_dirfsp_atname(talloc_tos(),
1372 if (full_fname
== NULL
) {
1376 DBG_DEBUG("[CEPH] symlink(%p, %s, %s)\n", handle
,
1377 link_target
->base_name
,
1378 full_fname
->base_name
);
1380 result
= ceph_symlink(handle
->data
,
1381 link_target
->base_name
,
1382 full_fname
->base_name
);
1383 TALLOC_FREE(full_fname
);
1384 DBG_DEBUG("[CEPH] symlink(...) = %d\n", result
);
1385 WRAP_RETURN(result
);
1389 static int cephwrap_readlinkat(struct vfs_handle_struct
*handle
,
1390 const struct files_struct
*dirfsp
,
1391 const struct smb_filename
*smb_fname
,
1396 #ifdef HAVE_CEPH_READLINKAT
1397 int dirfd
= fsp_get_pathref_fd(dirfsp
);
1399 DBG_DEBUG("[CEPH] readlinkat(%p, %d, %s, %p, %llu)\n",
1402 smb_fname
->base_name
,
1406 result
= ceph_readlinkat(handle
->data
,
1408 smb_fname
->base_name
,
1412 DBG_DEBUG("[CEPH] readlinkat(...) = %d\n", result
);
1413 WRAP_RETURN(result
);
1415 struct smb_filename
*full_fname
= NULL
;
1417 full_fname
= full_path_from_dirfsp_atname(talloc_tos(),
1420 if (full_fname
== NULL
) {
1424 DBG_DEBUG("[CEPH] readlink(%p, %s, %p, %llu)\n", handle
,
1425 full_fname
->base_name
, buf
, llu(bufsiz
));
1427 result
= ceph_readlink(handle
->data
, full_fname
->base_name
, buf
, bufsiz
);
1428 TALLOC_FREE(full_fname
);
1429 DBG_DEBUG("[CEPH] readlink(...) = %d\n", result
);
1430 WRAP_RETURN(result
);
1434 static int cephwrap_linkat(struct vfs_handle_struct
*handle
,
1435 files_struct
*srcfsp
,
1436 const struct smb_filename
*old_smb_fname
,
1437 files_struct
*dstfsp
,
1438 const struct smb_filename
*new_smb_fname
,
1441 struct smb_filename
*full_fname_old
= NULL
;
1442 struct smb_filename
*full_fname_new
= NULL
;
1445 full_fname_old
= full_path_from_dirfsp_atname(talloc_tos(),
1448 if (full_fname_old
== NULL
) {
1451 full_fname_new
= full_path_from_dirfsp_atname(talloc_tos(),
1454 if (full_fname_new
== NULL
) {
1455 TALLOC_FREE(full_fname_old
);
1459 DBG_DEBUG("[CEPH] link(%p, %s, %s)\n", handle
,
1460 full_fname_old
->base_name
,
1461 full_fname_new
->base_name
);
1463 result
= ceph_link(handle
->data
,
1464 full_fname_old
->base_name
,
1465 full_fname_new
->base_name
);
1466 DBG_DEBUG("[CEPH] link(...) = %d\n", result
);
1467 TALLOC_FREE(full_fname_old
);
1468 TALLOC_FREE(full_fname_new
);
1469 WRAP_RETURN(result
);
1472 static int cephwrap_mknodat(struct vfs_handle_struct
*handle
,
1473 files_struct
*dirfsp
,
1474 const struct smb_filename
*smb_fname
,
1478 struct smb_filename
*full_fname
= NULL
;
1481 full_fname
= full_path_from_dirfsp_atname(talloc_tos(),
1484 if (full_fname
== NULL
) {
1488 DBG_DEBUG("[CEPH] mknodat(%p, %s)\n", handle
, full_fname
->base_name
);
1489 result
= ceph_mknod(handle
->data
, full_fname
->base_name
, mode
, dev
);
1490 DBG_DEBUG("[CEPH] mknodat(...) = %d\n", result
);
1492 TALLOC_FREE(full_fname
);
1494 WRAP_RETURN(result
);
1498 * This is a simple version of real-path ... a better version is needed to
1499 * ask libcephfs about symbolic links.
1501 static struct smb_filename
*cephwrap_realpath(struct vfs_handle_struct
*handle
,
1503 const struct smb_filename
*smb_fname
)
1505 char *result
= NULL
;
1506 const char *path
= smb_fname
->base_name
;
1507 size_t len
= strlen(path
);
1508 struct smb_filename
*result_fname
= NULL
;
1511 if (len
&& (path
[0] == '/')) {
1512 r
= asprintf(&result
, "%s", path
);
1513 } else if ((len
>= 2) && (path
[0] == '.') && (path
[1] == '/')) {
1515 r
= asprintf(&result
, "%s",
1516 handle
->conn
->cwd_fsp
->fsp_name
->base_name
);
1518 r
= asprintf(&result
, "%s/%s",
1519 handle
->conn
->cwd_fsp
->fsp_name
->base_name
, &path
[2]);
1522 r
= asprintf(&result
, "%s/%s",
1523 handle
->conn
->cwd_fsp
->fsp_name
->base_name
, path
);
1530 DBG_DEBUG("[CEPH] realpath(%p, %s) = %s\n", handle
, path
, result
);
1531 result_fname
= synthetic_smb_fname(ctx
,
1538 return result_fname
;
1542 static int cephwrap_fchflags(struct vfs_handle_struct
*handle
,
1543 struct files_struct
*fsp
,
1550 static NTSTATUS
cephwrap_get_real_filename_at(
1551 struct vfs_handle_struct
*handle
,
1552 struct files_struct
*dirfsp
,
1554 TALLOC_CTX
*mem_ctx
,
1558 * Don't fall back to get_real_filename so callers can differentiate
1559 * between a full directory scan and an actual case-insensitive stat.
1561 return NT_STATUS_NOT_SUPPORTED
;
1564 static const char *cephwrap_connectpath(
1565 struct vfs_handle_struct
*handle
,
1566 const struct files_struct
*dirfsp
,
1567 const struct smb_filename
*smb_fname
)
1569 return handle
->conn
->connectpath
;
1572 static NTSTATUS
cephwrap_fget_dos_attributes(struct vfs_handle_struct
*handle
,
1573 struct files_struct
*fsp
,
1576 struct timespec saved_btime
= fsp
->fsp_name
->st
.st_ex_btime
;
1579 status
= fget_ea_dos_attribute(fsp
, dosmode
);
1582 * Restore previously stored btime from statx timestamps as it should be
1583 * the only source of truth. create_time from dos attribute, if any, may
1584 * have older values which isn't trustworthy to be looked at for other
1585 * open file handle operations.
1587 fsp
->fsp_name
->st
.st_ex_btime
= saved_btime
;
1592 static NTSTATUS
cephwrap_fset_dos_attributes(struct vfs_handle_struct
*handle
,
1593 struct files_struct
*fsp
,
1596 struct timespec saved_btime
= fsp
->fsp_name
->st
.st_ex_btime
;
1599 status
= set_ea_dos_attribute(handle
->conn
, fsp
->fsp_name
, dosmode
);
1602 * Restore previously stored btime from statx timestamps. This is done
1603 * to ensure that we have the exact btime in fsp stat information while
1604 * the file handle is still open since the create_time stored as part of
1605 * dos attributes can loose its precision when converted back to btime.
1607 fsp
->fsp_name
->st
.st_ex_btime
= saved_btime
;
1612 /****************************************************************
1613 Extended attribute operations.
1614 *****************************************************************/
1616 static ssize_t
cephwrap_fgetxattr(struct vfs_handle_struct
*handle
,
1617 struct files_struct
*fsp
,
1623 DBG_DEBUG("[CEPH] fgetxattr(%p, %p, %s, %p, %llu)\n",
1629 if (!fsp
->fsp_flags
.is_pathref
) {
1630 ret
= ceph_fgetxattr(handle
->data
,
1636 ret
= ceph_getxattr(handle
->data
,
1637 fsp
->fsp_name
->base_name
,
1642 DBG_DEBUG("[CEPH] fgetxattr(...) = %d\n", ret
);
1646 return (ssize_t
)ret
;
1649 static ssize_t
cephwrap_flistxattr(struct vfs_handle_struct
*handle
, struct files_struct
*fsp
, char *list
, size_t size
)
1652 DBG_DEBUG("[CEPH] flistxattr(%p, %p, %p, %llu)\n",
1653 handle
, fsp
, list
, llu(size
));
1654 if (!fsp
->fsp_flags
.is_pathref
) {
1656 * We can use an io_fd to list xattrs.
1658 ret
= ceph_flistxattr(handle
->data
,
1664 * This is no longer a handle based call.
1666 ret
= ceph_listxattr(handle
->data
,
1667 fsp
->fsp_name
->base_name
,
1671 DBG_DEBUG("[CEPH] flistxattr(...) = %d\n", ret
);
1675 return (ssize_t
)ret
;
1678 static int cephwrap_fremovexattr(struct vfs_handle_struct
*handle
, struct files_struct
*fsp
, const char *name
)
1681 DBG_DEBUG("[CEPH] fremovexattr(%p, %p, %s)\n", handle
, fsp
, name
);
1682 if (!fsp
->fsp_flags
.is_pathref
) {
1684 * We can use an io_fd to remove xattrs.
1686 ret
= ceph_fremovexattr(handle
->data
, fsp_get_io_fd(fsp
), name
);
1689 * This is no longer a handle based call.
1691 ret
= ceph_removexattr(handle
->data
,
1692 fsp
->fsp_name
->base_name
,
1695 DBG_DEBUG("[CEPH] fremovexattr(...) = %d\n", ret
);
1699 static int cephwrap_fsetxattr(struct vfs_handle_struct
*handle
, struct files_struct
*fsp
, const char *name
, const void *value
, size_t size
, int flags
)
1702 DBG_DEBUG("[CEPH] fsetxattr(%p, %p, %s, %p, %llu, %d)\n", handle
, fsp
, name
, value
, llu(size
), flags
);
1703 if (!fsp
->fsp_flags
.is_pathref
) {
1705 * We can use an io_fd to set xattrs.
1707 ret
= ceph_fsetxattr(handle
->data
,
1715 * This is no longer a handle based call.
1717 ret
= ceph_setxattr(handle
->data
,
1718 fsp
->fsp_name
->base_name
,
1724 DBG_DEBUG("[CEPH] fsetxattr(...) = %d\n", ret
);
1728 static bool cephwrap_aio_force(struct vfs_handle_struct
*handle
, struct files_struct
*fsp
)
1732 * We do not support AIO yet.
1735 DBG_DEBUG("[CEPH] cephwrap_aio_force(%p, %p) = false (errno = ENOTSUP)\n", handle
, fsp
);
1740 static NTSTATUS
cephwrap_create_dfs_pathat(struct vfs_handle_struct
*handle
,
1741 struct files_struct
*dirfsp
,
1742 const struct smb_filename
*smb_fname
,
1743 const struct referral
*reflist
,
1744 size_t referral_count
)
1746 TALLOC_CTX
*frame
= talloc_stackframe();
1747 NTSTATUS status
= NT_STATUS_NO_MEMORY
;
1749 char *msdfs_link
= NULL
;
1750 struct smb_filename
*full_fname
= NULL
;
1752 full_fname
= full_path_from_dirfsp_atname(talloc_tos(),
1755 if (full_fname
== NULL
) {
1759 /* Form the msdfs_link contents */
1760 msdfs_link
= msdfs_link_string(frame
,
1763 if (msdfs_link
== NULL
) {
1767 ret
= ceph_symlink(handle
->data
,
1769 full_fname
->base_name
);
1771 status
= NT_STATUS_OK
;
1773 status
= map_nt_error_from_unix(-ret
);
1778 DBG_DEBUG("[CEPH] create_dfs_pathat(%s) = %s\n",
1779 full_fname
!= NULL
? full_fname
->base_name
: "",
1787 * Read and return the contents of a DFS redirect given a
1788 * pathname. A caller can pass in NULL for ppreflist and
1789 * preferral_count but still determine if this was a
1790 * DFS redirect point by getting NT_STATUS_OK back
1791 * without incurring the overhead of reading and parsing
1792 * the referral contents.
1795 static NTSTATUS
cephwrap_read_dfs_pathat(struct vfs_handle_struct
*handle
,
1796 TALLOC_CTX
*mem_ctx
,
1797 struct files_struct
*dirfsp
,
1798 struct smb_filename
*smb_fname
,
1799 struct referral
**ppreflist
,
1800 size_t *preferral_count
)
1802 NTSTATUS status
= NT_STATUS_NO_MEMORY
;
1804 char *link_target
= NULL
;
1807 #if defined(HAVE_BROKEN_READLINK)
1808 char link_target_buf
[PATH_MAX
];
1810 char link_target_buf
[7];
1812 struct ceph_statx stx
= { 0 };
1813 struct smb_filename
*full_fname
= NULL
;
1816 if (is_named_stream(smb_fname
)) {
1817 status
= NT_STATUS_OBJECT_NAME_NOT_FOUND
;
1821 if (ppreflist
== NULL
&& preferral_count
== NULL
) {
1823 * We're only checking if this is a DFS
1824 * redirect. We don't need to return data.
1826 bufsize
= sizeof(link_target_buf
);
1827 link_target
= link_target_buf
;
1830 link_target
= talloc_array(mem_ctx
, char, bufsize
);
1836 full_fname
= full_path_from_dirfsp_atname(talloc_tos(),
1839 if (full_fname
== NULL
) {
1840 status
= NT_STATUS_NO_MEMORY
;
1844 ret
= ceph_statx(handle
->data
,
1845 full_fname
->base_name
,
1847 SAMBA_STATX_ATTR_MASK
,
1848 AT_SYMLINK_NOFOLLOW
);
1850 status
= map_nt_error_from_unix(-ret
);
1854 referral_len
= ceph_readlink(handle
->data
,
1855 full_fname
->base_name
,
1858 if (referral_len
< 0) {
1859 /* ceph errors are -errno. */
1860 if (-referral_len
== EINVAL
) {
1861 DBG_INFO("%s is not a link.\n",
1862 full_fname
->base_name
);
1863 status
= NT_STATUS_OBJECT_TYPE_MISMATCH
;
1865 status
= map_nt_error_from_unix(-referral_len
);
1866 DBG_ERR("Error reading "
1867 "msdfs link %s: %s\n",
1868 full_fname
->base_name
,
1873 link_target
[referral_len
] = '\0';
1875 DBG_INFO("%s -> %s\n",
1876 full_fname
->base_name
,
1879 if (!strnequal(link_target
, "msdfs:", 6)) {
1880 status
= NT_STATUS_OBJECT_TYPE_MISMATCH
;
1884 if (ppreflist
== NULL
&& preferral_count
== NULL
) {
1885 /* Early return for checking if this is a DFS link. */
1886 TALLOC_FREE(full_fname
);
1887 init_stat_ex_from_ceph_statx(&smb_fname
->st
, &stx
);
1888 return NT_STATUS_OK
;
1891 ok
= parse_msdfs_symlink(mem_ctx
,
1892 lp_msdfs_shuffle_referrals(SNUM(handle
->conn
)),
1898 init_stat_ex_from_ceph_statx(&smb_fname
->st
, &stx
);
1899 status
= NT_STATUS_OK
;
1901 status
= NT_STATUS_NO_MEMORY
;
1906 if (link_target
!= link_target_buf
) {
1907 TALLOC_FREE(link_target
);
1909 TALLOC_FREE(full_fname
);
1913 static struct vfs_fn_pointers ceph_fns
= {
1914 /* Disk operations */
1916 .connect_fn
= cephwrap_connect
,
1917 .disconnect_fn
= cephwrap_disconnect
,
1918 .disk_free_fn
= cephwrap_disk_free
,
1919 .get_quota_fn
= cephwrap_get_quota
,
1920 .set_quota_fn
= cephwrap_set_quota
,
1921 .statvfs_fn
= cephwrap_statvfs
,
1922 .fs_capabilities_fn
= cephwrap_fs_capabilities
,
1924 /* Directory operations */
1926 .fdopendir_fn
= cephwrap_fdopendir
,
1927 .readdir_fn
= cephwrap_readdir
,
1928 .rewind_dir_fn
= cephwrap_rewinddir
,
1929 .mkdirat_fn
= cephwrap_mkdirat
,
1930 .closedir_fn
= cephwrap_closedir
,
1932 /* File operations */
1934 .create_dfs_pathat_fn
= cephwrap_create_dfs_pathat
,
1935 .read_dfs_pathat_fn
= cephwrap_read_dfs_pathat
,
1936 .openat_fn
= cephwrap_openat
,
1937 .close_fn
= cephwrap_close
,
1938 .pread_fn
= cephwrap_pread
,
1939 .pread_send_fn
= cephwrap_pread_send
,
1940 .pread_recv_fn
= cephwrap_pread_recv
,
1941 .pwrite_fn
= cephwrap_pwrite
,
1942 .pwrite_send_fn
= cephwrap_pwrite_send
,
1943 .pwrite_recv_fn
= cephwrap_pwrite_recv
,
1944 .lseek_fn
= cephwrap_lseek
,
1945 .sendfile_fn
= cephwrap_sendfile
,
1946 .recvfile_fn
= cephwrap_recvfile
,
1947 .renameat_fn
= cephwrap_renameat
,
1948 .fsync_send_fn
= cephwrap_fsync_send
,
1949 .fsync_recv_fn
= cephwrap_fsync_recv
,
1950 .stat_fn
= cephwrap_stat
,
1951 .fstat_fn
= cephwrap_fstat
,
1952 .lstat_fn
= cephwrap_lstat
,
1953 .fstatat_fn
= cephwrap_fstatat
,
1954 .unlinkat_fn
= cephwrap_unlinkat
,
1955 .fchmod_fn
= cephwrap_fchmod
,
1956 .fchown_fn
= cephwrap_fchown
,
1957 .lchown_fn
= cephwrap_lchown
,
1958 .chdir_fn
= cephwrap_chdir
,
1959 .getwd_fn
= cephwrap_getwd
,
1960 .fntimes_fn
= cephwrap_fntimes
,
1961 .ftruncate_fn
= cephwrap_ftruncate
,
1962 .fallocate_fn
= cephwrap_fallocate
,
1963 .lock_fn
= cephwrap_lock
,
1964 .filesystem_sharemode_fn
= cephwrap_filesystem_sharemode
,
1965 .fcntl_fn
= cephwrap_fcntl
,
1966 .linux_setlease_fn
= cephwrap_linux_setlease
,
1967 .getlock_fn
= cephwrap_getlock
,
1968 .symlinkat_fn
= cephwrap_symlinkat
,
1969 .readlinkat_fn
= cephwrap_readlinkat
,
1970 .linkat_fn
= cephwrap_linkat
,
1971 .mknodat_fn
= cephwrap_mknodat
,
1972 .realpath_fn
= cephwrap_realpath
,
1973 .fchflags_fn
= cephwrap_fchflags
,
1974 .get_real_filename_at_fn
= cephwrap_get_real_filename_at
,
1975 .connectpath_fn
= cephwrap_connectpath
,
1976 .fget_dos_attributes_fn
= cephwrap_fget_dos_attributes
,
1977 .fset_dos_attributes_fn
= cephwrap_fset_dos_attributes
,
1979 /* EA operations. */
1980 .getxattrat_send_fn
= vfs_not_implemented_getxattrat_send
,
1981 .getxattrat_recv_fn
= vfs_not_implemented_getxattrat_recv
,
1982 .fgetxattr_fn
= cephwrap_fgetxattr
,
1983 .flistxattr_fn
= cephwrap_flistxattr
,
1984 .fremovexattr_fn
= cephwrap_fremovexattr
,
1985 .fsetxattr_fn
= cephwrap_fsetxattr
,
1987 /* Posix ACL Operations */
1988 .sys_acl_get_fd_fn
= posixacl_xattr_acl_get_fd
,
1989 .sys_acl_blob_get_fd_fn
= posix_sys_acl_blob_get_fd
,
1990 .sys_acl_set_fd_fn
= posixacl_xattr_acl_set_fd
,
1991 .sys_acl_delete_def_fd_fn
= posixacl_xattr_acl_delete_def_fd
,
1993 /* aio operations */
1994 .aio_force_fn
= cephwrap_aio_force
,
1998 NTSTATUS
vfs_ceph_init(TALLOC_CTX
*ctx
)
2000 return smb_register_vfs(SMB_VFS_INTERFACE_VERSION
,