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, with is 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
;
289 * Unless we have an async implementation of getxattrat turn this off.
291 lp_do_parameter(SNUM(handle
->conn
), "smbd async dosmode", "false");
297 static void cephwrap_disconnect(struct vfs_handle_struct
*handle
)
299 int ret
= cephmount_cache_remove(handle
->data
);
301 DBG_ERR("failed to remove ceph mount from cache: %s\n",
306 DBG_DEBUG("mount cache entry still in use\n");
310 ret
= ceph_unmount(handle
->data
);
312 DBG_ERR("[CEPH] failed to unmount: %s\n", strerror(-ret
));
315 ret
= ceph_release(handle
->data
);
317 DBG_ERR("[CEPH] failed to release: %s\n", strerror(-ret
));
322 /* Disk operations */
324 static uint64_t cephwrap_disk_free(struct vfs_handle_struct
*handle
,
325 const struct smb_filename
*smb_fname
,
330 struct statvfs statvfs_buf
;
333 if (!(ret
= ceph_statfs(handle
->data
, smb_fname
->base_name
,
336 * Provide all the correct values.
338 *bsize
= statvfs_buf
.f_bsize
;
339 *dfree
= statvfs_buf
.f_bavail
;
340 *dsize
= statvfs_buf
.f_blocks
;
341 DBG_DEBUG("[CEPH] bsize: %llu, dfree: %llu, dsize: %llu\n",
342 llu(*bsize
), llu(*dfree
), llu(*dsize
));
345 DBG_DEBUG("[CEPH] ceph_statfs returned %d\n", ret
);
350 static int cephwrap_get_quota(struct vfs_handle_struct
*handle
,
351 const struct smb_filename
*smb_fname
,
352 enum SMB_QUOTA_TYPE qtype
,
356 /* libcephfs: Ceph does not implement this */
358 /* was ifdef HAVE_SYS_QUOTAS */
361 ret
= ceph_get_quota(handle
->conn
->connectpath
, qtype
, id
, qt
);
375 static int cephwrap_set_quota(struct vfs_handle_struct
*handle
, enum SMB_QUOTA_TYPE qtype
, unid_t id
, SMB_DISK_QUOTA
*qt
)
377 /* libcephfs: Ceph does not implement this */
379 /* was ifdef HAVE_SYS_QUOTAS */
382 ret
= ceph_set_quota(handle
->conn
->connectpath
, qtype
, id
, qt
);
390 WRAP_RETURN(-ENOSYS
);
394 static int cephwrap_statvfs(struct vfs_handle_struct
*handle
,
395 const struct smb_filename
*smb_fname
,
396 struct vfs_statvfs_struct
*statbuf
)
398 struct statvfs statvfs_buf
;
401 ret
= ceph_statfs(handle
->data
, smb_fname
->base_name
, &statvfs_buf
);
406 statbuf
->OptimalTransferSize
= statvfs_buf
.f_frsize
;
407 statbuf
->BlockSize
= statvfs_buf
.f_bsize
;
408 statbuf
->TotalBlocks
= statvfs_buf
.f_blocks
;
409 statbuf
->BlocksAvail
= statvfs_buf
.f_bfree
;
410 statbuf
->UserBlocksAvail
= statvfs_buf
.f_bavail
;
411 statbuf
->TotalFileNodes
= statvfs_buf
.f_files
;
412 statbuf
->FreeFileNodes
= statvfs_buf
.f_ffree
;
413 statbuf
->FsIdentifier
= statvfs_buf
.f_fsid
;
414 DBG_DEBUG("[CEPH] f_bsize: %ld, f_blocks: %ld, f_bfree: %ld, f_bavail: %ld\n",
415 (long int)statvfs_buf
.f_bsize
, (long int)statvfs_buf
.f_blocks
,
416 (long int)statvfs_buf
.f_bfree
, (long int)statvfs_buf
.f_bavail
);
421 static uint32_t cephwrap_fs_capabilities(struct vfs_handle_struct
*handle
,
422 enum timestamp_set_resolution
*p_ts_res
)
424 uint32_t caps
= FILE_CASE_SENSITIVE_SEARCH
| FILE_CASE_PRESERVED_NAMES
;
426 *p_ts_res
= TIMESTAMP_SET_NT_OR_BETTER
;
431 /* Directory operations */
433 static DIR *cephwrap_fdopendir(struct vfs_handle_struct
*handle
,
434 struct files_struct
*fsp
,
439 struct ceph_dir_result
*result
;
440 DBG_DEBUG("[CEPH] fdopendir(%p, %p)\n", handle
, fsp
);
442 ret
= ceph_opendir(handle
->data
, fsp
->fsp_name
->base_name
, &result
);
445 errno
= -ret
; /* We return result which is NULL in this case */
448 DBG_DEBUG("[CEPH] fdopendir(...) = %d\n", ret
);
449 return (DIR *) result
;
452 static struct dirent
*cephwrap_readdir(struct vfs_handle_struct
*handle
,
453 struct files_struct
*dirfsp
,
456 struct dirent
*result
;
458 DBG_DEBUG("[CEPH] readdir(%p, %p)\n", handle
, dirp
);
459 result
= ceph_readdir(handle
->data
, (struct ceph_dir_result
*) dirp
);
460 DBG_DEBUG("[CEPH] readdir(...) = %p\n", result
);
465 static void cephwrap_rewinddir(struct vfs_handle_struct
*handle
, DIR *dirp
)
467 DBG_DEBUG("[CEPH] rewinddir(%p, %p)\n", handle
, dirp
);
468 ceph_rewinddir(handle
->data
, (struct ceph_dir_result
*) dirp
);
471 static int cephwrap_mkdirat(struct vfs_handle_struct
*handle
,
472 files_struct
*dirfsp
,
473 const struct smb_filename
*smb_fname
,
476 struct smb_filename
*full_fname
= NULL
;
479 full_fname
= full_path_from_dirfsp_atname(talloc_tos(),
482 if (full_fname
== NULL
) {
486 DBG_DEBUG("[CEPH] mkdir(%p, %s)\n",
487 handle
, smb_fname_str_dbg(full_fname
));
489 result
= ceph_mkdir(handle
->data
, full_fname
->base_name
, mode
);
491 TALLOC_FREE(full_fname
);
493 return WRAP_RETURN(result
);
496 static int cephwrap_closedir(struct vfs_handle_struct
*handle
, DIR *dirp
)
500 DBG_DEBUG("[CEPH] closedir(%p, %p)\n", handle
, dirp
);
501 result
= ceph_closedir(handle
->data
, (struct ceph_dir_result
*) dirp
);
502 DBG_DEBUG("[CEPH] closedir(...) = %d\n", result
);
506 /* File operations */
508 static int cephwrap_openat(struct vfs_handle_struct
*handle
,
509 const struct files_struct
*dirfsp
,
510 const struct smb_filename
*smb_fname
,
512 const struct vfs_open_how
*how
)
514 int flags
= how
->flags
;
515 mode_t mode
= how
->mode
;
516 struct smb_filename
*name
= NULL
;
517 bool have_opath
= false;
518 bool became_root
= false;
519 int result
= -ENOENT
;
521 if (how
->resolve
!= 0) {
527 * ceph doesn't have openat().
529 if (fsp_get_pathref_fd(dirfsp
) != AT_FDCWD
) {
530 name
= full_path_from_dirfsp_atname(talloc_tos(),
539 DBG_DEBUG("[CEPH] openat(%p, %s, %p, %d, %d)\n", handle
,
540 smb_fname_str_dbg(smb_fname
), fsp
, flags
, mode
);
542 if (smb_fname
->stream_name
) {
548 if (fsp
->fsp_flags
.is_pathref
) {
553 if (fsp
->fsp_flags
.is_pathref
&& !have_opath
) {
558 result
= ceph_open(handle
->data
, smb_fname
->base_name
, flags
, mode
);
566 fsp
->fsp_flags
.have_proc_fds
= false;
567 DBG_DEBUG("[CEPH] open(...) = %d\n", result
);
571 static int cephwrap_close(struct vfs_handle_struct
*handle
, files_struct
*fsp
)
575 DBG_DEBUG("[CEPH] close(%p, %p)\n", handle
, fsp
);
576 result
= ceph_close(handle
->data
, fsp_get_pathref_fd(fsp
));
577 DBG_DEBUG("[CEPH] close(...) = %d\n", result
);
582 static ssize_t
cephwrap_pread(struct vfs_handle_struct
*handle
, files_struct
*fsp
, void *data
,
583 size_t n
, off_t offset
)
587 DBG_DEBUG("[CEPH] pread(%p, %p, %p, %llu, %llu)\n", handle
, fsp
, data
, llu(n
), llu(offset
));
589 result
= ceph_read(handle
->data
, fsp_get_io_fd(fsp
), data
, n
, offset
);
590 DBG_DEBUG("[CEPH] pread(...) = %llu\n", llu(result
));
594 struct cephwrap_pread_state
{
596 struct vfs_aio_state vfs_aio_state
;
600 * Fake up an async ceph read by calling the synchronous API.
602 static struct tevent_req
*cephwrap_pread_send(struct vfs_handle_struct
*handle
,
604 struct tevent_context
*ev
,
605 struct files_struct
*fsp
,
607 size_t n
, off_t offset
)
609 struct tevent_req
*req
= NULL
;
610 struct cephwrap_pread_state
*state
= NULL
;
613 DBG_DEBUG("[CEPH] %s\n", __func__
);
614 req
= tevent_req_create(mem_ctx
, &state
, struct cephwrap_pread_state
);
619 ret
= ceph_read(handle
->data
, fsp_get_io_fd(fsp
), data
, n
, offset
);
621 /* ceph returns -errno on error. */
622 tevent_req_error(req
, -ret
);
623 return tevent_req_post(req
, ev
);
626 state
->bytes_read
= ret
;
627 tevent_req_done(req
);
628 /* Return and schedule the completion of the call. */
629 return tevent_req_post(req
, ev
);
632 static ssize_t
cephwrap_pread_recv(struct tevent_req
*req
,
633 struct vfs_aio_state
*vfs_aio_state
)
635 struct cephwrap_pread_state
*state
=
636 tevent_req_data(req
, struct cephwrap_pread_state
);
638 DBG_DEBUG("[CEPH] %s\n", __func__
);
639 if (tevent_req_is_unix_error(req
, &vfs_aio_state
->error
)) {
642 *vfs_aio_state
= state
->vfs_aio_state
;
643 return state
->bytes_read
;
646 static ssize_t
cephwrap_pwrite(struct vfs_handle_struct
*handle
, files_struct
*fsp
, const void *data
,
647 size_t n
, off_t offset
)
651 DBG_DEBUG("[CEPH] pwrite(%p, %p, %p, %llu, %llu)\n", handle
, fsp
, data
, llu(n
), llu(offset
));
652 result
= ceph_write(handle
->data
, fsp_get_io_fd(fsp
), data
, n
, offset
);
653 DBG_DEBUG("[CEPH] pwrite(...) = %llu\n", llu(result
));
657 struct cephwrap_pwrite_state
{
658 ssize_t bytes_written
;
659 struct vfs_aio_state vfs_aio_state
;
663 * Fake up an async ceph write by calling the synchronous API.
665 static struct tevent_req
*cephwrap_pwrite_send(struct vfs_handle_struct
*handle
,
667 struct tevent_context
*ev
,
668 struct files_struct
*fsp
,
670 size_t n
, off_t offset
)
672 struct tevent_req
*req
= NULL
;
673 struct cephwrap_pwrite_state
*state
= NULL
;
676 DBG_DEBUG("[CEPH] %s\n", __func__
);
677 req
= tevent_req_create(mem_ctx
, &state
, struct cephwrap_pwrite_state
);
682 ret
= ceph_write(handle
->data
, fsp_get_io_fd(fsp
), data
, n
, offset
);
684 /* ceph returns -errno on error. */
685 tevent_req_error(req
, -ret
);
686 return tevent_req_post(req
, ev
);
689 state
->bytes_written
= ret
;
690 tevent_req_done(req
);
691 /* Return and schedule the completion of the call. */
692 return tevent_req_post(req
, ev
);
695 static ssize_t
cephwrap_pwrite_recv(struct tevent_req
*req
,
696 struct vfs_aio_state
*vfs_aio_state
)
698 struct cephwrap_pwrite_state
*state
=
699 tevent_req_data(req
, struct cephwrap_pwrite_state
);
701 DBG_DEBUG("[CEPH] %s\n", __func__
);
702 if (tevent_req_is_unix_error(req
, &vfs_aio_state
->error
)) {
705 *vfs_aio_state
= state
->vfs_aio_state
;
706 return state
->bytes_written
;
709 static off_t
cephwrap_lseek(struct vfs_handle_struct
*handle
, files_struct
*fsp
, off_t offset
, int whence
)
713 DBG_DEBUG("[CEPH] cephwrap_lseek\n");
714 result
= ceph_lseek(handle
->data
, fsp_get_io_fd(fsp
), offset
, whence
);
718 static ssize_t
cephwrap_sendfile(struct vfs_handle_struct
*handle
, int tofd
, files_struct
*fromfsp
, const DATA_BLOB
*hdr
,
719 off_t offset
, size_t n
)
722 * We cannot support sendfile because libcephfs is in user space.
724 DBG_DEBUG("[CEPH] cephwrap_sendfile\n");
729 static ssize_t
cephwrap_recvfile(struct vfs_handle_struct
*handle
,
736 * We cannot support recvfile because libcephfs is in user space.
738 DBG_DEBUG("[CEPH] cephwrap_recvfile\n");
743 static int cephwrap_renameat(struct vfs_handle_struct
*handle
,
744 files_struct
*srcfsp
,
745 const struct smb_filename
*smb_fname_src
,
746 files_struct
*dstfsp
,
747 const struct smb_filename
*smb_fname_dst
)
749 struct smb_filename
*full_fname_src
= NULL
;
750 struct smb_filename
*full_fname_dst
= NULL
;
753 DBG_DEBUG("[CEPH] cephwrap_renameat\n");
754 if (smb_fname_src
->stream_name
|| smb_fname_dst
->stream_name
) {
759 full_fname_src
= full_path_from_dirfsp_atname(talloc_tos(),
762 if (full_fname_src
== NULL
) {
766 full_fname_dst
= full_path_from_dirfsp_atname(talloc_tos(),
769 if (full_fname_dst
== NULL
) {
770 TALLOC_FREE(full_fname_src
);
775 result
= ceph_rename(handle
->data
,
776 full_fname_src
->base_name
,
777 full_fname_dst
->base_name
);
779 TALLOC_FREE(full_fname_src
);
780 TALLOC_FREE(full_fname_dst
);
786 * Fake up an async ceph fsync by calling the synchronous API.
789 static struct tevent_req
*cephwrap_fsync_send(struct vfs_handle_struct
*handle
,
791 struct tevent_context
*ev
,
794 struct tevent_req
*req
= NULL
;
795 struct vfs_aio_state
*state
= NULL
;
798 DBG_DEBUG("[CEPH] cephwrap_fsync_send\n");
800 req
= tevent_req_create(mem_ctx
, &state
, struct vfs_aio_state
);
805 /* Make sync call. */
806 ret
= ceph_fsync(handle
->data
, fsp_get_io_fd(fsp
), false);
809 /* ceph_fsync returns -errno on error. */
810 tevent_req_error(req
, -ret
);
811 return tevent_req_post(req
, ev
);
814 /* Mark it as done. */
815 tevent_req_done(req
);
816 /* Return and schedule the completion of the call. */
817 return tevent_req_post(req
, ev
);
820 static int cephwrap_fsync_recv(struct tevent_req
*req
,
821 struct vfs_aio_state
*vfs_aio_state
)
823 struct vfs_aio_state
*state
=
824 tevent_req_data(req
, struct vfs_aio_state
);
826 DBG_DEBUG("[CEPH] cephwrap_fsync_recv\n");
828 if (tevent_req_is_unix_error(req
, &vfs_aio_state
->error
)) {
831 *vfs_aio_state
= *state
;
835 #define SAMBA_STATX_ATTR_MASK (CEPH_STATX_BASIC_STATS|CEPH_STATX_BTIME)
837 static void init_stat_ex_from_ceph_statx(struct stat_ex
*dst
, const struct ceph_statx
*stx
)
839 DBG_DEBUG("[CEPH]\tstx = {dev = %llx, ino = %llu, mode = 0x%x, "
840 "nlink = %llu, uid = %d, gid = %d, rdev = %llx, size = %llu, "
841 "blksize = %llu, blocks = %llu, atime = %llu, mtime = %llu, "
842 "ctime = %llu, btime = %llu}\n",
843 llu(stx
->stx_dev
), llu(stx
->stx_ino
), stx
->stx_mode
,
844 llu(stx
->stx_nlink
), stx
->stx_uid
, stx
->stx_gid
,
845 llu(stx
->stx_rdev
), llu(stx
->stx_size
), llu(stx
->stx_blksize
),
846 llu(stx
->stx_blocks
), llu(stx
->stx_atime
.tv_sec
),
847 llu(stx
->stx_mtime
.tv_sec
), llu(stx
->stx_ctime
.tv_sec
),
848 llu(stx
->stx_btime
.tv_sec
));
850 if ((stx
->stx_mask
& SAMBA_STATX_ATTR_MASK
) != SAMBA_STATX_ATTR_MASK
) {
851 DBG_WARNING("%s: stx->stx_mask is incorrect (wanted %x, got %x)\n",
852 __func__
, SAMBA_STATX_ATTR_MASK
, stx
->stx_mask
);
855 dst
->st_ex_dev
= stx
->stx_dev
;
856 dst
->st_ex_rdev
= stx
->stx_rdev
;
857 dst
->st_ex_ino
= stx
->stx_ino
;
858 dst
->st_ex_mode
= stx
->stx_mode
;
859 dst
->st_ex_uid
= stx
->stx_uid
;
860 dst
->st_ex_gid
= stx
->stx_gid
;
861 dst
->st_ex_size
= stx
->stx_size
;
862 dst
->st_ex_nlink
= stx
->stx_nlink
;
863 dst
->st_ex_atime
= stx
->stx_atime
;
864 dst
->st_ex_btime
= stx
->stx_btime
;
865 dst
->st_ex_ctime
= stx
->stx_ctime
;
866 dst
->st_ex_mtime
= stx
->stx_mtime
;
867 dst
->st_ex_blksize
= stx
->stx_blksize
;
868 dst
->st_ex_blocks
= stx
->stx_blocks
;
871 static int cephwrap_stat(struct vfs_handle_struct
*handle
,
872 struct smb_filename
*smb_fname
)
875 struct ceph_statx stx
;
877 DBG_DEBUG("[CEPH] stat(%p, %s)\n", handle
, smb_fname_str_dbg(smb_fname
));
879 if (smb_fname
->stream_name
) {
884 result
= ceph_statx(handle
->data
, smb_fname
->base_name
, &stx
,
885 SAMBA_STATX_ATTR_MASK
, 0);
886 DBG_DEBUG("[CEPH] statx(...) = %d\n", result
);
891 init_stat_ex_from_ceph_statx(&smb_fname
->st
, &stx
);
892 DBG_DEBUG("[CEPH] mode = 0x%x\n", smb_fname
->st
.st_ex_mode
);
896 static int cephwrap_fstat(struct vfs_handle_struct
*handle
, files_struct
*fsp
, SMB_STRUCT_STAT
*sbuf
)
899 struct ceph_statx stx
;
900 int fd
= fsp_get_pathref_fd(fsp
);
902 DBG_DEBUG("[CEPH] fstat(%p, %d)\n", handle
, fd
);
903 result
= ceph_fstatx(handle
->data
, fd
, &stx
,
904 SAMBA_STATX_ATTR_MASK
, 0);
905 DBG_DEBUG("[CEPH] fstat(...) = %d\n", result
);
910 init_stat_ex_from_ceph_statx(sbuf
, &stx
);
911 DBG_DEBUG("[CEPH] mode = 0x%x\n", sbuf
->st_ex_mode
);
915 static int cephwrap_lstat(struct vfs_handle_struct
*handle
,
916 struct smb_filename
*smb_fname
)
919 struct ceph_statx stx
;
921 DBG_DEBUG("[CEPH] lstat(%p, %s)\n", handle
, smb_fname_str_dbg(smb_fname
));
923 if (smb_fname
->stream_name
) {
928 result
= ceph_statx(handle
->data
, smb_fname
->base_name
, &stx
,
929 SAMBA_STATX_ATTR_MASK
, AT_SYMLINK_NOFOLLOW
);
930 DBG_DEBUG("[CEPH] lstat(...) = %d\n", result
);
935 init_stat_ex_from_ceph_statx(&smb_fname
->st
, &stx
);
939 static int cephwrap_fntimes(struct vfs_handle_struct
*handle
,
941 struct smb_file_time
*ft
)
943 struct ceph_statx stx
= { 0 };
947 if (!is_omit_timespec(&ft
->atime
)) {
948 stx
.stx_atime
= ft
->atime
;
949 mask
|= CEPH_SETATTR_ATIME
;
951 if (!is_omit_timespec(&ft
->mtime
)) {
952 stx
.stx_mtime
= ft
->mtime
;
953 mask
|= CEPH_SETATTR_MTIME
;
955 if (!is_omit_timespec(&ft
->create_time
)) {
956 stx
.stx_btime
= ft
->create_time
;
957 mask
|= CEPH_SETATTR_BTIME
;
964 if (!fsp
->fsp_flags
.is_pathref
) {
966 * We can use an io_fd to set xattrs.
968 result
= ceph_fsetattrx(handle
->data
,
974 * This is no longer a handle based call.
976 result
= ceph_setattrx(handle
->data
,
977 fsp
->fsp_name
->base_name
,
983 DBG_DEBUG("[CEPH] ntimes(%p, %s, {%ld, %ld, %ld, %ld}) = %d\n",
984 handle
, fsp_str_dbg(fsp
), ft
->mtime
.tv_sec
, ft
->atime
.tv_sec
,
985 ft
->ctime
.tv_sec
, ft
->create_time
.tv_sec
, result
);
990 static int cephwrap_unlinkat(struct vfs_handle_struct
*handle
,
991 struct files_struct
*dirfsp
,
992 const struct smb_filename
*smb_fname
,
995 struct smb_filename
*full_fname
= NULL
;
998 DBG_DEBUG("[CEPH] unlink(%p, %s)\n",
1000 smb_fname_str_dbg(smb_fname
));
1002 if (smb_fname
->stream_name
) {
1007 full_fname
= full_path_from_dirfsp_atname(talloc_tos(),
1010 if (full_fname
== NULL
) {
1014 if (flags
& AT_REMOVEDIR
) {
1015 result
= ceph_rmdir(handle
->data
, full_fname
->base_name
);
1017 result
= ceph_unlink(handle
->data
, full_fname
->base_name
);
1019 TALLOC_FREE(full_fname
);
1020 DBG_DEBUG("[CEPH] unlink(...) = %d\n", result
);
1021 WRAP_RETURN(result
);
1024 static int cephwrap_fchmod(struct vfs_handle_struct
*handle
, files_struct
*fsp
, mode_t mode
)
1028 DBG_DEBUG("[CEPH] fchmod(%p, %p, %d)\n", handle
, fsp
, mode
);
1029 if (!fsp
->fsp_flags
.is_pathref
) {
1031 * We can use an io_fd to change permissions.
1033 result
= ceph_fchmod(handle
->data
, fsp_get_io_fd(fsp
), mode
);
1036 * This is no longer a handle based call.
1038 result
= ceph_chmod(handle
->data
,
1039 fsp
->fsp_name
->base_name
,
1042 DBG_DEBUG("[CEPH] fchmod(...) = %d\n", result
);
1043 WRAP_RETURN(result
);
1046 static int cephwrap_fchown(struct vfs_handle_struct
*handle
, files_struct
*fsp
, uid_t uid
, gid_t gid
)
1050 DBG_DEBUG("[CEPH] fchown(%p, %p, %d, %d)\n", handle
, fsp
, uid
, gid
);
1051 if (!fsp
->fsp_flags
.is_pathref
) {
1053 * We can use an io_fd to change ownership.
1055 result
= ceph_fchown(handle
->data
,
1061 * This is no longer a handle based call.
1063 result
= ceph_chown(handle
->data
,
1064 fsp
->fsp_name
->base_name
,
1069 DBG_DEBUG("[CEPH] fchown(...) = %d\n", result
);
1070 WRAP_RETURN(result
);
1073 static int cephwrap_lchown(struct vfs_handle_struct
*handle
,
1074 const struct smb_filename
*smb_fname
,
1079 DBG_DEBUG("[CEPH] lchown(%p, %s, %d, %d)\n", handle
, smb_fname
->base_name
, uid
, gid
);
1080 result
= ceph_lchown(handle
->data
, smb_fname
->base_name
, uid
, gid
);
1081 DBG_DEBUG("[CEPH] lchown(...) = %d\n", result
);
1082 WRAP_RETURN(result
);
1085 static int cephwrap_chdir(struct vfs_handle_struct
*handle
,
1086 const struct smb_filename
*smb_fname
)
1089 DBG_DEBUG("[CEPH] chdir(%p, %s)\n", handle
, smb_fname
->base_name
);
1090 result
= ceph_chdir(handle
->data
, smb_fname
->base_name
);
1091 DBG_DEBUG("[CEPH] chdir(...) = %d\n", result
);
1092 WRAP_RETURN(result
);
1095 static struct smb_filename
*cephwrap_getwd(struct vfs_handle_struct
*handle
,
1098 const char *cwd
= ceph_getcwd(handle
->data
);
1099 DBG_DEBUG("[CEPH] getwd(%p) = %s\n", handle
, cwd
);
1100 return synthetic_smb_fname(ctx
,
1108 static int strict_allocate_ftruncate(struct vfs_handle_struct
*handle
, files_struct
*fsp
, off_t len
)
1110 off_t space_to_write
;
1113 SMB_STRUCT_STAT
*pst
;
1115 status
= vfs_stat_fsp(fsp
);
1116 if (!NT_STATUS_IS_OK(status
)) {
1119 pst
= &fsp
->fsp_name
->st
;
1122 if (S_ISFIFO(pst
->st_ex_mode
))
1126 if (pst
->st_ex_size
== len
)
1129 /* Shrink - just ftruncate. */
1130 if (pst
->st_ex_size
> len
) {
1131 result
= ceph_ftruncate(handle
->data
, fsp_get_io_fd(fsp
), len
);
1132 WRAP_RETURN(result
);
1135 space_to_write
= len
- pst
->st_ex_size
;
1136 result
= ceph_fallocate(handle
->data
, fsp_get_io_fd(fsp
), 0, pst
->st_ex_size
,
1138 WRAP_RETURN(result
);
1141 static int cephwrap_ftruncate(struct vfs_handle_struct
*handle
, files_struct
*fsp
, off_t len
)
1145 DBG_DEBUG("[CEPH] ftruncate(%p, %p, %llu\n", handle
, fsp
, llu(len
));
1147 if (lp_strict_allocate(SNUM(fsp
->conn
))) {
1148 return strict_allocate_ftruncate(handle
, fsp
, len
);
1151 result
= ceph_ftruncate(handle
->data
, fsp_get_io_fd(fsp
), len
);
1152 WRAP_RETURN(result
);
1155 static int cephwrap_fallocate(struct vfs_handle_struct
*handle
,
1156 struct files_struct
*fsp
,
1163 DBG_DEBUG("[CEPH] fallocate(%p, %p, %u, %llu, %llu\n",
1164 handle
, fsp
, mode
, llu(offset
), llu(len
));
1165 /* unsupported mode flags are rejected by libcephfs */
1166 result
= ceph_fallocate(handle
->data
, fsp_get_io_fd(fsp
), mode
, offset
, len
);
1167 DBG_DEBUG("[CEPH] fallocate(...) = %d\n", result
);
1168 WRAP_RETURN(result
);
1171 static bool cephwrap_lock(struct vfs_handle_struct
*handle
, files_struct
*fsp
, int op
, off_t offset
, off_t count
, int type
)
1173 DBG_DEBUG("[CEPH] lock\n");
1177 static int cephwrap_filesystem_sharemode(struct vfs_handle_struct
*handle
,
1179 uint32_t share_access
,
1180 uint32_t access_mask
)
1182 DBG_ERR("[CEPH] filesystem sharemodes unsupported! Consider setting "
1183 "\"kernel share modes = no\"\n");
1189 static int cephwrap_fcntl(vfs_handle_struct
*handle
,
1190 files_struct
*fsp
, int cmd
, va_list cmd_arg
)
1193 * SMB_VFS_FCNTL() is currently only called by vfs_set_blocking() to
1194 * clear O_NONBLOCK, etc for LOCK_MAND and FIFOs. Ignore it.
1196 if (cmd
== F_GETFL
) {
1198 } else if (cmd
== F_SETFL
) {
1199 va_list dup_cmd_arg
;
1202 va_copy(dup_cmd_arg
, cmd_arg
);
1203 opt
= va_arg(dup_cmd_arg
, int);
1204 va_end(dup_cmd_arg
);
1208 DBG_ERR("unexpected fcntl SETFL(%d)\n", opt
);
1211 DBG_ERR("unexpected fcntl: %d\n", cmd
);
1217 static bool cephwrap_getlock(struct vfs_handle_struct
*handle
, files_struct
*fsp
, off_t
*poffset
, off_t
*pcount
, int *ptype
, pid_t
*ppid
)
1219 DBG_DEBUG("[CEPH] getlock returning false and errno=0\n");
1226 * We cannot let this fall through to the default, because the file might only
1227 * be accessible from libcephfs (which is a user-space client) but the fd might
1228 * be for some file the kernel knows about.
1230 static int cephwrap_linux_setlease(struct vfs_handle_struct
*handle
, files_struct
*fsp
,
1235 DBG_DEBUG("[CEPH] linux_setlease\n");
1240 static int cephwrap_symlinkat(struct vfs_handle_struct
*handle
,
1241 const struct smb_filename
*link_target
,
1242 struct files_struct
*dirfsp
,
1243 const struct smb_filename
*new_smb_fname
)
1245 struct smb_filename
*full_fname
= NULL
;
1248 full_fname
= full_path_from_dirfsp_atname(talloc_tos(),
1251 if (full_fname
== NULL
) {
1255 DBG_DEBUG("[CEPH] symlink(%p, %s, %s)\n", handle
,
1256 link_target
->base_name
,
1257 full_fname
->base_name
);
1259 result
= ceph_symlink(handle
->data
,
1260 link_target
->base_name
,
1261 full_fname
->base_name
);
1262 TALLOC_FREE(full_fname
);
1263 DBG_DEBUG("[CEPH] symlink(...) = %d\n", result
);
1264 WRAP_RETURN(result
);
1267 static int cephwrap_readlinkat(struct vfs_handle_struct
*handle
,
1268 const struct files_struct
*dirfsp
,
1269 const struct smb_filename
*smb_fname
,
1273 struct smb_filename
*full_fname
= NULL
;
1276 full_fname
= full_path_from_dirfsp_atname(talloc_tos(),
1279 if (full_fname
== NULL
) {
1283 DBG_DEBUG("[CEPH] readlink(%p, %s, %p, %llu)\n", handle
,
1284 full_fname
->base_name
, buf
, llu(bufsiz
));
1286 result
= ceph_readlink(handle
->data
, full_fname
->base_name
, buf
, bufsiz
);
1287 TALLOC_FREE(full_fname
);
1288 DBG_DEBUG("[CEPH] readlink(...) = %d\n", result
);
1289 WRAP_RETURN(result
);
1292 static int cephwrap_linkat(struct vfs_handle_struct
*handle
,
1293 files_struct
*srcfsp
,
1294 const struct smb_filename
*old_smb_fname
,
1295 files_struct
*dstfsp
,
1296 const struct smb_filename
*new_smb_fname
,
1299 struct smb_filename
*full_fname_old
= NULL
;
1300 struct smb_filename
*full_fname_new
= NULL
;
1303 full_fname_old
= full_path_from_dirfsp_atname(talloc_tos(),
1306 if (full_fname_old
== NULL
) {
1309 full_fname_new
= full_path_from_dirfsp_atname(talloc_tos(),
1312 if (full_fname_new
== NULL
) {
1313 TALLOC_FREE(full_fname_old
);
1317 DBG_DEBUG("[CEPH] link(%p, %s, %s)\n", handle
,
1318 full_fname_old
->base_name
,
1319 full_fname_new
->base_name
);
1321 result
= ceph_link(handle
->data
,
1322 full_fname_old
->base_name
,
1323 full_fname_new
->base_name
);
1324 DBG_DEBUG("[CEPH] link(...) = %d\n", result
);
1325 TALLOC_FREE(full_fname_old
);
1326 TALLOC_FREE(full_fname_new
);
1327 WRAP_RETURN(result
);
1330 static int cephwrap_mknodat(struct vfs_handle_struct
*handle
,
1331 files_struct
*dirfsp
,
1332 const struct smb_filename
*smb_fname
,
1336 struct smb_filename
*full_fname
= NULL
;
1339 full_fname
= full_path_from_dirfsp_atname(talloc_tos(),
1342 if (full_fname
== NULL
) {
1346 DBG_DEBUG("[CEPH] mknodat(%p, %s)\n", handle
, full_fname
->base_name
);
1347 result
= ceph_mknod(handle
->data
, full_fname
->base_name
, mode
, dev
);
1348 DBG_DEBUG("[CEPH] mknodat(...) = %d\n", result
);
1350 TALLOC_FREE(full_fname
);
1352 WRAP_RETURN(result
);
1356 * This is a simple version of real-path ... a better version is needed to
1357 * ask libcephfs about symbolic links.
1359 static struct smb_filename
*cephwrap_realpath(struct vfs_handle_struct
*handle
,
1361 const struct smb_filename
*smb_fname
)
1363 char *result
= NULL
;
1364 const char *path
= smb_fname
->base_name
;
1365 size_t len
= strlen(path
);
1366 struct smb_filename
*result_fname
= NULL
;
1369 if (len
&& (path
[0] == '/')) {
1370 r
= asprintf(&result
, "%s", path
);
1371 } else if ((len
>= 2) && (path
[0] == '.') && (path
[1] == '/')) {
1373 r
= asprintf(&result
, "%s",
1374 handle
->conn
->cwd_fsp
->fsp_name
->base_name
);
1376 r
= asprintf(&result
, "%s/%s",
1377 handle
->conn
->cwd_fsp
->fsp_name
->base_name
, &path
[2]);
1380 r
= asprintf(&result
, "%s/%s",
1381 handle
->conn
->cwd_fsp
->fsp_name
->base_name
, path
);
1388 DBG_DEBUG("[CEPH] realpath(%p, %s) = %s\n", handle
, path
, result
);
1389 result_fname
= synthetic_smb_fname(ctx
,
1396 return result_fname
;
1400 static int cephwrap_fchflags(struct vfs_handle_struct
*handle
,
1401 struct files_struct
*fsp
,
1408 static NTSTATUS
cephwrap_get_real_filename_at(
1409 struct vfs_handle_struct
*handle
,
1410 struct files_struct
*dirfsp
,
1412 TALLOC_CTX
*mem_ctx
,
1416 * Don't fall back to get_real_filename so callers can differentiate
1417 * between a full directory scan and an actual case-insensitive stat.
1419 return NT_STATUS_NOT_SUPPORTED
;
1422 static const char *cephwrap_connectpath(
1423 struct vfs_handle_struct
*handle
,
1424 const struct files_struct
*dirfsp
,
1425 const struct smb_filename
*smb_fname
)
1427 return handle
->conn
->connectpath
;
1430 /****************************************************************
1431 Extended attribute operations.
1432 *****************************************************************/
1434 static ssize_t
cephwrap_fgetxattr(struct vfs_handle_struct
*handle
, struct files_struct
*fsp
, const char *name
, void *value
, size_t size
)
1437 DBG_DEBUG("[CEPH] fgetxattr(%p, %p, %s, %p, %llu)\n", handle
, fsp
, name
, value
, llu(size
));
1438 ret
= ceph_fgetxattr(handle
->data
, fsp_get_io_fd(fsp
), name
, value
, size
);
1439 DBG_DEBUG("[CEPH] fgetxattr(...) = %d\n", ret
);
1443 return (ssize_t
)ret
;
1446 static ssize_t
cephwrap_flistxattr(struct vfs_handle_struct
*handle
, struct files_struct
*fsp
, char *list
, size_t size
)
1449 DBG_DEBUG("[CEPH] flistxattr(%p, %p, %p, %llu)\n",
1450 handle
, fsp
, list
, llu(size
));
1451 if (!fsp
->fsp_flags
.is_pathref
) {
1453 * We can use an io_fd to list xattrs.
1455 ret
= ceph_flistxattr(handle
->data
,
1461 * This is no longer a handle based call.
1463 ret
= ceph_listxattr(handle
->data
,
1464 fsp
->fsp_name
->base_name
,
1468 DBG_DEBUG("[CEPH] flistxattr(...) = %d\n", ret
);
1472 return (ssize_t
)ret
;
1475 static int cephwrap_fremovexattr(struct vfs_handle_struct
*handle
, struct files_struct
*fsp
, const char *name
)
1478 DBG_DEBUG("[CEPH] fremovexattr(%p, %p, %s)\n", handle
, fsp
, name
);
1479 if (!fsp
->fsp_flags
.is_pathref
) {
1481 * We can use an io_fd to remove xattrs.
1483 ret
= ceph_fremovexattr(handle
->data
, fsp_get_io_fd(fsp
), name
);
1486 * This is no longer a handle based call.
1488 ret
= ceph_removexattr(handle
->data
,
1489 fsp
->fsp_name
->base_name
,
1492 DBG_DEBUG("[CEPH] fremovexattr(...) = %d\n", ret
);
1496 static int cephwrap_fsetxattr(struct vfs_handle_struct
*handle
, struct files_struct
*fsp
, const char *name
, const void *value
, size_t size
, int flags
)
1499 DBG_DEBUG("[CEPH] fsetxattr(%p, %p, %s, %p, %llu, %d)\n", handle
, fsp
, name
, value
, llu(size
), flags
);
1500 if (!fsp
->fsp_flags
.is_pathref
) {
1502 * We can use an io_fd to set xattrs.
1504 ret
= ceph_fsetxattr(handle
->data
,
1512 * This is no longer a handle based call.
1514 ret
= ceph_setxattr(handle
->data
,
1515 fsp
->fsp_name
->base_name
,
1521 DBG_DEBUG("[CEPH] fsetxattr(...) = %d\n", ret
);
1525 static bool cephwrap_aio_force(struct vfs_handle_struct
*handle
, struct files_struct
*fsp
)
1529 * We do not support AIO yet.
1532 DBG_DEBUG("[CEPH] cephwrap_aio_force(%p, %p) = false (errno = ENOTSUP)\n", handle
, fsp
);
1537 static NTSTATUS
cephwrap_create_dfs_pathat(struct vfs_handle_struct
*handle
,
1538 struct files_struct
*dirfsp
,
1539 const struct smb_filename
*smb_fname
,
1540 const struct referral
*reflist
,
1541 size_t referral_count
)
1543 TALLOC_CTX
*frame
= talloc_stackframe();
1544 NTSTATUS status
= NT_STATUS_NO_MEMORY
;
1546 char *msdfs_link
= NULL
;
1547 struct smb_filename
*full_fname
= NULL
;
1549 full_fname
= full_path_from_dirfsp_atname(talloc_tos(),
1552 if (full_fname
== NULL
) {
1556 /* Form the msdfs_link contents */
1557 msdfs_link
= msdfs_link_string(frame
,
1560 if (msdfs_link
== NULL
) {
1564 ret
= ceph_symlink(handle
->data
,
1566 full_fname
->base_name
);
1568 status
= NT_STATUS_OK
;
1570 status
= map_nt_error_from_unix(-ret
);
1575 DBG_DEBUG("[CEPH] create_dfs_pathat(%s) = %s\n",
1576 full_fname
!= NULL
? full_fname
->base_name
: "",
1584 * Read and return the contents of a DFS redirect given a
1585 * pathname. A caller can pass in NULL for ppreflist and
1586 * preferral_count but still determine if this was a
1587 * DFS redirect point by getting NT_STATUS_OK back
1588 * without incurring the overhead of reading and parsing
1589 * the referral contents.
1592 static NTSTATUS
cephwrap_read_dfs_pathat(struct vfs_handle_struct
*handle
,
1593 TALLOC_CTX
*mem_ctx
,
1594 struct files_struct
*dirfsp
,
1595 struct smb_filename
*smb_fname
,
1596 struct referral
**ppreflist
,
1597 size_t *preferral_count
)
1599 NTSTATUS status
= NT_STATUS_NO_MEMORY
;
1601 char *link_target
= NULL
;
1604 #if defined(HAVE_BROKEN_READLINK)
1605 char link_target_buf
[PATH_MAX
];
1607 char link_target_buf
[7];
1609 struct ceph_statx stx
;
1610 struct smb_filename
*full_fname
= NULL
;
1613 if (is_named_stream(smb_fname
)) {
1614 status
= NT_STATUS_OBJECT_NAME_NOT_FOUND
;
1618 if (ppreflist
== NULL
&& preferral_count
== NULL
) {
1620 * We're only checking if this is a DFS
1621 * redirect. We don't need to return data.
1623 bufsize
= sizeof(link_target_buf
);
1624 link_target
= link_target_buf
;
1627 link_target
= talloc_array(mem_ctx
, char, bufsize
);
1633 full_fname
= full_path_from_dirfsp_atname(talloc_tos(),
1636 if (full_fname
== NULL
) {
1637 status
= NT_STATUS_NO_MEMORY
;
1641 ret
= ceph_statx(handle
->data
,
1642 full_fname
->base_name
,
1644 SAMBA_STATX_ATTR_MASK
,
1645 AT_SYMLINK_NOFOLLOW
);
1647 status
= map_nt_error_from_unix(-ret
);
1651 referral_len
= ceph_readlink(handle
->data
,
1652 full_fname
->base_name
,
1655 if (referral_len
< 0) {
1656 /* ceph errors are -errno. */
1657 if (-referral_len
== EINVAL
) {
1658 DBG_INFO("%s is not a link.\n",
1659 full_fname
->base_name
);
1660 status
= NT_STATUS_OBJECT_TYPE_MISMATCH
;
1662 status
= map_nt_error_from_unix(-referral_len
);
1663 DBG_ERR("Error reading "
1664 "msdfs link %s: %s\n",
1665 full_fname
->base_name
,
1670 link_target
[referral_len
] = '\0';
1672 DBG_INFO("%s -> %s\n",
1673 full_fname
->base_name
,
1676 if (!strnequal(link_target
, "msdfs:", 6)) {
1677 status
= NT_STATUS_OBJECT_TYPE_MISMATCH
;
1681 if (ppreflist
== NULL
&& preferral_count
== NULL
) {
1682 /* Early return for checking if this is a DFS link. */
1683 TALLOC_FREE(full_fname
);
1684 init_stat_ex_from_ceph_statx(&smb_fname
->st
, &stx
);
1685 return NT_STATUS_OK
;
1688 ok
= parse_msdfs_symlink(mem_ctx
,
1689 lp_msdfs_shuffle_referrals(SNUM(handle
->conn
)),
1695 init_stat_ex_from_ceph_statx(&smb_fname
->st
, &stx
);
1696 status
= NT_STATUS_OK
;
1698 status
= NT_STATUS_NO_MEMORY
;
1703 if (link_target
!= link_target_buf
) {
1704 TALLOC_FREE(link_target
);
1706 TALLOC_FREE(full_fname
);
1710 static struct vfs_fn_pointers ceph_fns
= {
1711 /* Disk operations */
1713 .connect_fn
= cephwrap_connect
,
1714 .disconnect_fn
= cephwrap_disconnect
,
1715 .disk_free_fn
= cephwrap_disk_free
,
1716 .get_quota_fn
= cephwrap_get_quota
,
1717 .set_quota_fn
= cephwrap_set_quota
,
1718 .statvfs_fn
= cephwrap_statvfs
,
1719 .fs_capabilities_fn
= cephwrap_fs_capabilities
,
1721 /* Directory operations */
1723 .fdopendir_fn
= cephwrap_fdopendir
,
1724 .readdir_fn
= cephwrap_readdir
,
1725 .rewind_dir_fn
= cephwrap_rewinddir
,
1726 .mkdirat_fn
= cephwrap_mkdirat
,
1727 .closedir_fn
= cephwrap_closedir
,
1729 /* File operations */
1731 .create_dfs_pathat_fn
= cephwrap_create_dfs_pathat
,
1732 .read_dfs_pathat_fn
= cephwrap_read_dfs_pathat
,
1733 .openat_fn
= cephwrap_openat
,
1734 .close_fn
= cephwrap_close
,
1735 .pread_fn
= cephwrap_pread
,
1736 .pread_send_fn
= cephwrap_pread_send
,
1737 .pread_recv_fn
= cephwrap_pread_recv
,
1738 .pwrite_fn
= cephwrap_pwrite
,
1739 .pwrite_send_fn
= cephwrap_pwrite_send
,
1740 .pwrite_recv_fn
= cephwrap_pwrite_recv
,
1741 .lseek_fn
= cephwrap_lseek
,
1742 .sendfile_fn
= cephwrap_sendfile
,
1743 .recvfile_fn
= cephwrap_recvfile
,
1744 .renameat_fn
= cephwrap_renameat
,
1745 .fsync_send_fn
= cephwrap_fsync_send
,
1746 .fsync_recv_fn
= cephwrap_fsync_recv
,
1747 .stat_fn
= cephwrap_stat
,
1748 .fstat_fn
= cephwrap_fstat
,
1749 .lstat_fn
= cephwrap_lstat
,
1750 .unlinkat_fn
= cephwrap_unlinkat
,
1751 .fchmod_fn
= cephwrap_fchmod
,
1752 .fchown_fn
= cephwrap_fchown
,
1753 .lchown_fn
= cephwrap_lchown
,
1754 .chdir_fn
= cephwrap_chdir
,
1755 .getwd_fn
= cephwrap_getwd
,
1756 .fntimes_fn
= cephwrap_fntimes
,
1757 .ftruncate_fn
= cephwrap_ftruncate
,
1758 .fallocate_fn
= cephwrap_fallocate
,
1759 .lock_fn
= cephwrap_lock
,
1760 .filesystem_sharemode_fn
= cephwrap_filesystem_sharemode
,
1761 .fcntl_fn
= cephwrap_fcntl
,
1762 .linux_setlease_fn
= cephwrap_linux_setlease
,
1763 .getlock_fn
= cephwrap_getlock
,
1764 .symlinkat_fn
= cephwrap_symlinkat
,
1765 .readlinkat_fn
= cephwrap_readlinkat
,
1766 .linkat_fn
= cephwrap_linkat
,
1767 .mknodat_fn
= cephwrap_mknodat
,
1768 .realpath_fn
= cephwrap_realpath
,
1769 .fchflags_fn
= cephwrap_fchflags
,
1770 .get_real_filename_at_fn
= cephwrap_get_real_filename_at
,
1771 .connectpath_fn
= cephwrap_connectpath
,
1773 /* EA operations. */
1774 .getxattrat_send_fn
= vfs_not_implemented_getxattrat_send
,
1775 .getxattrat_recv_fn
= vfs_not_implemented_getxattrat_recv
,
1776 .fgetxattr_fn
= cephwrap_fgetxattr
,
1777 .flistxattr_fn
= cephwrap_flistxattr
,
1778 .fremovexattr_fn
= cephwrap_fremovexattr
,
1779 .fsetxattr_fn
= cephwrap_fsetxattr
,
1781 /* Posix ACL Operations */
1782 .sys_acl_get_fd_fn
= posixacl_xattr_acl_get_fd
,
1783 .sys_acl_blob_get_fd_fn
= posix_sys_acl_blob_get_fd
,
1784 .sys_acl_set_fd_fn
= posixacl_xattr_acl_set_fd
,
1785 .sys_acl_delete_def_fd_fn
= posixacl_xattr_acl_delete_def_fd
,
1787 /* aio operations */
1788 .aio_force_fn
= cephwrap_aio_force
,
1792 NTSTATUS
vfs_ceph_init(TALLOC_CTX
*ctx
)
1794 return smb_register_vfs(SMB_VFS_INTERFACE_VERSION
,