Line data Source code
1 : /*
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>
8 :
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.
13 :
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.
18 :
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/>.
21 : */
22 :
23 : /*
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.
26 : *
27 : * Add the following smb.conf parameter to each share that will be hosted on
28 : * Ceph:
29 : *
30 : * vfs objects = [any others you need go here] ceph
31 : */
32 :
33 : #include "includes.h"
34 : #include "smbd/smbd.h"
35 : #include "system/filesys.h"
36 : #include <dirent.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"
42 :
43 : #undef DBGC_CLASS
44 : #define DBGC_CLASS DBGC_VFS
45 :
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)
49 : #endif
50 :
51 : /*
52 : * Use %llu whenever we have a 64bit unsigned int, and cast to (long long unsigned)
53 : */
54 : #define llu(_var) ((long long unsigned)_var)
55 :
56 : /*
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
59 : */
60 : #define WRAP_RETURN(_res) \
61 : errno = 0; \
62 : if (_res < 0) { \
63 : errno = -_res; \
64 : return -1; \
65 : } \
66 : return _res \
67 :
68 : /*
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
72 : * to the same cephfs.
73 : *
74 : * Individual mounts are IDed by a 'cookie' value that is a string built
75 : * from identifying parameters found in smb.conf.
76 : */
77 :
78 : static struct cephmount_cached {
79 : char *cookie;
80 : uint32_t count;
81 : struct ceph_mount_info *mount;
82 : struct cephmount_cached *next, *prev;
83 : } *cephmount_cached;
84 :
85 0 : static int cephmount_cache_add(const char *cookie,
86 : struct ceph_mount_info *mount)
87 : {
88 0 : struct cephmount_cached *entry = NULL;
89 :
90 0 : entry = talloc_zero(NULL, struct cephmount_cached);
91 0 : if (entry == NULL) {
92 0 : errno = ENOMEM;
93 0 : return -1;
94 : }
95 :
96 0 : entry->cookie = talloc_strdup(entry, cookie);
97 0 : if (entry->cookie == NULL) {
98 0 : talloc_free(entry);
99 0 : errno = ENOMEM;
100 0 : return -1;
101 : }
102 :
103 0 : entry->mount = mount;
104 0 : entry->count = 1;
105 :
106 0 : DBG_DEBUG("adding mount cache entry for %s\n", entry->cookie);
107 0 : DLIST_ADD(cephmount_cached, entry);
108 0 : return 0;
109 : }
110 :
111 0 : static struct ceph_mount_info *cephmount_cache_update(const char *cookie)
112 : {
113 0 : struct cephmount_cached *entry = NULL;
114 :
115 0 : for (entry = cephmount_cached; entry; entry = entry->next) {
116 0 : if (strcmp(entry->cookie, cookie) == 0) {
117 0 : entry->count++;
118 0 : DBG_DEBUG("updated mount cache: count is [%"
119 : PRIu32 "]\n", entry->count);
120 0 : return entry->mount;
121 : }
122 : }
123 :
124 0 : errno = ENOENT;
125 0 : return NULL;
126 : }
127 :
128 0 : static int cephmount_cache_remove(struct ceph_mount_info *mount)
129 : {
130 0 : struct cephmount_cached *entry = NULL;
131 :
132 0 : for (entry = cephmount_cached; entry; entry = entry->next) {
133 0 : if (entry->mount == mount) {
134 0 : if (--entry->count) {
135 0 : DBG_DEBUG("updated mount cache: count is [%"
136 : PRIu32 "]\n", entry->count);
137 0 : return entry->count;
138 : }
139 :
140 0 : DBG_DEBUG("removing mount cache entry for %s\n",
141 : entry->cookie);
142 0 : DLIST_REMOVE(cephmount_cached, entry);
143 0 : talloc_free(entry);
144 0 : return 0;
145 : }
146 : }
147 0 : errno = ENOENT;
148 0 : return -1;
149 : }
150 :
151 0 : static char *cephmount_get_cookie(TALLOC_CTX * mem_ctx, const int snum)
152 : {
153 : const char *conf_file =
154 0 : lp_parm_const_string(snum, "ceph", "config_file", ".");
155 0 : const char *user_id = lp_parm_const_string(snum, "ceph", "user_id", "");
156 : const char *fsname =
157 0 : lp_parm_const_string(snum, "ceph", "filesystem", "");
158 0 : return talloc_asprintf(mem_ctx, "(%s/%s/%s)", conf_file, user_id,
159 : fsname);
160 : }
161 :
162 0 : static int cephmount_select_fs(struct ceph_mount_info *mnt, const char *fsname)
163 : {
164 : /*
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.
169 : */
170 : #if defined(HAVE_CEPH_SELECT_FILESYSTEM)
171 0 : DBG_DEBUG("[CEPH] calling: ceph_select_filesystem with %s\n", fsname);
172 0 : return ceph_select_filesystem(mnt, fsname);
173 : #else
174 : DBG_ERR("[CEPH] ceph_select_filesystem not available\n");
175 : return -ENOTSUP;
176 : #endif
177 : }
178 :
179 0 : static struct ceph_mount_info *cephmount_mount_fs(const int snum)
180 : {
181 : int ret;
182 : char buf[256];
183 0 : 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 0 : lp_parm_const_string(snum, "ceph", "config_file", NULL);
187 : const char *user_id =
188 0 : lp_parm_const_string(snum, "ceph", "user_id", NULL);
189 : const char *fsname =
190 0 : lp_parm_const_string(snum, "ceph", "filesystem", NULL);
191 :
192 0 : DBG_DEBUG("[CEPH] calling: ceph_create\n");
193 0 : ret = ceph_create(&mnt, user_id);
194 0 : if (ret) {
195 0 : errno = -ret;
196 0 : return NULL;
197 : }
198 :
199 0 : DBG_DEBUG("[CEPH] calling: ceph_conf_read_file with %s\n",
200 : (conf_file == NULL ? "default path" : conf_file));
201 0 : ret = ceph_conf_read_file(mnt, conf_file);
202 0 : if (ret) {
203 0 : goto err_cm_release;
204 : }
205 :
206 0 : DBG_DEBUG("[CEPH] calling: ceph_conf_get\n");
207 0 : ret = ceph_conf_get(mnt, "log file", buf, sizeof(buf));
208 0 : if (ret < 0) {
209 0 : goto err_cm_release;
210 : }
211 :
212 : /* libcephfs disables POSIX ACL support by default, enable it... */
213 0 : ret = ceph_conf_set(mnt, "client_acl_type", "posix_acl");
214 0 : if (ret < 0) {
215 0 : goto err_cm_release;
216 : }
217 : /* tell libcephfs to perform local permission checks */
218 0 : ret = ceph_conf_set(mnt, "fuse_default_permissions", "false");
219 0 : if (ret < 0) {
220 0 : goto err_cm_release;
221 : }
222 : /*
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.
226 : */
227 0 : if (fsname != NULL) {
228 0 : ret = cephmount_select_fs(mnt, fsname);
229 0 : if (ret < 0) {
230 0 : goto err_cm_release;
231 : }
232 : }
233 :
234 0 : DBG_DEBUG("[CEPH] calling: ceph_mount\n");
235 0 : ret = ceph_mount(mnt, NULL);
236 0 : if (ret >= 0) {
237 0 : goto cm_done;
238 : }
239 :
240 0 : err_cm_release:
241 0 : ceph_release(mnt);
242 0 : mnt = NULL;
243 0 : DBG_DEBUG("[CEPH] Error mounting fs: %s\n", strerror(-ret));
244 0 : cm_done:
245 : /*
246 : * Handle the error correctly. Ceph returns -errno.
247 : */
248 0 : if (ret) {
249 0 : errno = -ret;
250 : }
251 0 : return mnt;
252 : }
253 :
254 : /* Check for NULL pointer parameters in cephwrap_* functions */
255 :
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
258 : this possibility. */
259 :
260 0 : static int cephwrap_connect(struct vfs_handle_struct *handle,
261 : const char *service, const char *user)
262 : {
263 0 : int ret = 0;
264 0 : struct ceph_mount_info *cmount = NULL;
265 0 : int snum = SNUM(handle->conn);
266 0 : char *cookie = cephmount_get_cookie(handle, snum);
267 0 : if (cookie == NULL) {
268 0 : return -1;
269 : }
270 :
271 0 : cmount = cephmount_cache_update(cookie);
272 0 : if (cmount != NULL) {
273 0 : goto connect_ok;
274 : }
275 :
276 0 : cmount = cephmount_mount_fs(snum);
277 0 : if (cmount == NULL) {
278 0 : ret = -1;
279 0 : goto connect_fail;
280 : }
281 0 : ret = cephmount_cache_add(cookie, cmount);
282 0 : if (ret) {
283 0 : goto connect_fail;
284 : }
285 :
286 0 : connect_ok:
287 0 : handle->data = cmount;
288 0 : DBG_WARNING("Connection established with the server: %s\n", cookie);
289 : /*
290 : * Unless we have an async implementation of getxattrat turn this off.
291 : */
292 0 : lp_do_parameter(SNUM(handle->conn), "smbd async dosmode", "false");
293 0 : connect_fail:
294 0 : talloc_free(cookie);
295 0 : return ret;
296 : }
297 :
298 0 : static void cephwrap_disconnect(struct vfs_handle_struct *handle)
299 : {
300 0 : int ret = cephmount_cache_remove(handle->data);
301 0 : if (ret < 0) {
302 0 : DBG_ERR("failed to remove ceph mount from cache: %s\n",
303 : strerror(errno));
304 0 : return;
305 : }
306 0 : if (ret > 0) {
307 0 : DBG_DEBUG("mount cache entry still in use\n");
308 0 : return;
309 : }
310 :
311 0 : ret = ceph_unmount(handle->data);
312 0 : if (ret < 0) {
313 0 : DBG_ERR("[CEPH] failed to unmount: %s\n", strerror(-ret));
314 : }
315 :
316 0 : ret = ceph_release(handle->data);
317 0 : if (ret < 0) {
318 0 : DBG_ERR("[CEPH] failed to release: %s\n", strerror(-ret));
319 : }
320 0 : handle->data = NULL;
321 : }
322 :
323 : /* Disk operations */
324 :
325 0 : static uint64_t cephwrap_disk_free(struct vfs_handle_struct *handle,
326 : const struct smb_filename *smb_fname,
327 : uint64_t *bsize,
328 : uint64_t *dfree,
329 : uint64_t *dsize)
330 : {
331 0 : struct statvfs statvfs_buf = { 0 };
332 : int ret;
333 :
334 0 : if (!(ret = ceph_statfs(handle->data, smb_fname->base_name,
335 : &statvfs_buf))) {
336 : /*
337 : * Provide all the correct values.
338 : */
339 0 : *bsize = statvfs_buf.f_bsize;
340 0 : *dfree = statvfs_buf.f_bavail;
341 0 : *dsize = statvfs_buf.f_blocks;
342 0 : DBG_DEBUG("[CEPH] bsize: %llu, dfree: %llu, dsize: %llu\n",
343 : llu(*bsize), llu(*dfree), llu(*dsize));
344 0 : return *dfree;
345 : } else {
346 0 : DBG_DEBUG("[CEPH] ceph_statfs returned %d\n", ret);
347 0 : WRAP_RETURN(ret);
348 : }
349 : }
350 :
351 0 : static int cephwrap_get_quota(struct vfs_handle_struct *handle,
352 : const struct smb_filename *smb_fname,
353 : enum SMB_QUOTA_TYPE qtype,
354 : unid_t id,
355 : SMB_DISK_QUOTA *qt)
356 : {
357 : /* libcephfs: Ceph does not implement this */
358 : #if 0
359 : /* was ifdef HAVE_SYS_QUOTAS */
360 : int ret;
361 :
362 : ret = ceph_get_quota(handle->conn->connectpath, qtype, id, qt);
363 :
364 : if (ret) {
365 : errno = -ret;
366 : ret = -1;
367 : }
368 :
369 : return ret;
370 : #else
371 0 : errno = ENOSYS;
372 0 : return -1;
373 : #endif
374 : }
375 :
376 0 : static int cephwrap_set_quota(struct vfs_handle_struct *handle, enum SMB_QUOTA_TYPE qtype, unid_t id, SMB_DISK_QUOTA *qt)
377 : {
378 : /* libcephfs: Ceph does not implement this */
379 : #if 0
380 : /* was ifdef HAVE_SYS_QUOTAS */
381 : int ret;
382 :
383 : ret = ceph_set_quota(handle->conn->connectpath, qtype, id, qt);
384 : if (ret) {
385 : errno = -ret;
386 : ret = -1;
387 : }
388 :
389 : return ret;
390 : #else
391 0 : WRAP_RETURN(-ENOSYS);
392 : #endif
393 : }
394 :
395 0 : static int cephwrap_statvfs(struct vfs_handle_struct *handle,
396 : const struct smb_filename *smb_fname,
397 : struct vfs_statvfs_struct *statbuf)
398 : {
399 0 : struct statvfs statvfs_buf = { 0 };
400 : int ret;
401 :
402 0 : ret = ceph_statfs(handle->data, smb_fname->base_name, &statvfs_buf);
403 0 : if (ret < 0) {
404 0 : WRAP_RETURN(ret);
405 : }
406 :
407 0 : statbuf->OptimalTransferSize = statvfs_buf.f_frsize;
408 0 : statbuf->BlockSize = statvfs_buf.f_bsize;
409 0 : statbuf->TotalBlocks = statvfs_buf.f_blocks;
410 0 : statbuf->BlocksAvail = statvfs_buf.f_bfree;
411 0 : statbuf->UserBlocksAvail = statvfs_buf.f_bavail;
412 0 : statbuf->TotalFileNodes = statvfs_buf.f_files;
413 0 : statbuf->FreeFileNodes = statvfs_buf.f_ffree;
414 0 : statbuf->FsIdentifier = statvfs_buf.f_fsid;
415 0 : 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);
418 :
419 0 : return ret;
420 : }
421 :
422 0 : static uint32_t cephwrap_fs_capabilities(struct vfs_handle_struct *handle,
423 : enum timestamp_set_resolution *p_ts_res)
424 : {
425 0 : uint32_t caps = FILE_CASE_SENSITIVE_SEARCH | FILE_CASE_PRESERVED_NAMES;
426 :
427 0 : *p_ts_res = TIMESTAMP_SET_NT_OR_BETTER;
428 :
429 0 : return caps;
430 : }
431 :
432 : /* Directory operations */
433 :
434 0 : static DIR *cephwrap_fdopendir(struct vfs_handle_struct *handle,
435 : struct files_struct *fsp,
436 : const char *mask,
437 : uint32_t attributes)
438 : {
439 0 : int ret = 0;
440 0 : struct ceph_dir_result *result = NULL;
441 :
442 : #ifdef HAVE_CEPH_FDOPENDIR
443 0 : int dirfd = fsp_get_io_fd(fsp);
444 0 : DBG_DEBUG("[CEPH] fdopendir(%p, %d)\n", handle, dirfd);
445 0 : ret = ceph_fdopendir(handle->data, dirfd, &result);
446 : #else
447 : DBG_DEBUG("[CEPH] fdopendir(%p, %p)\n", handle, fsp);
448 : ret = ceph_opendir(handle->data, fsp->fsp_name->base_name, &result);
449 : #endif
450 0 : if (ret < 0) {
451 0 : result = NULL;
452 0 : errno = -ret; /* We return result which is NULL in this case */
453 : }
454 :
455 0 : DBG_DEBUG("[CEPH] fdopendir(...) = %d\n", ret);
456 0 : return (DIR *) result;
457 : }
458 :
459 0 : static struct dirent *cephwrap_readdir(struct vfs_handle_struct *handle,
460 : struct files_struct *dirfsp,
461 : DIR *dirp)
462 : {
463 0 : struct dirent *result = NULL;
464 :
465 0 : DBG_DEBUG("[CEPH] readdir(%p, %p)\n", handle, dirp);
466 0 : result = ceph_readdir(handle->data, (struct ceph_dir_result *) dirp);
467 0 : DBG_DEBUG("[CEPH] readdir(...) = %p\n", result);
468 :
469 0 : return result;
470 : }
471 :
472 0 : static void cephwrap_rewinddir(struct vfs_handle_struct *handle, DIR *dirp)
473 : {
474 0 : DBG_DEBUG("[CEPH] rewinddir(%p, %p)\n", handle, dirp);
475 0 : ceph_rewinddir(handle->data, (struct ceph_dir_result *) dirp);
476 0 : }
477 :
478 0 : static int cephwrap_mkdirat(struct vfs_handle_struct *handle,
479 : files_struct *dirfsp,
480 : const struct smb_filename *smb_fname,
481 : mode_t mode)
482 : {
483 0 : int result = -1;
484 : #ifdef HAVE_CEPH_MKDIRAT
485 0 : int dirfd = fsp_get_pathref_fd(dirfsp);
486 :
487 0 : DBG_DEBUG("[CEPH] mkdirat(%p, %d, %s)\n",
488 : handle,
489 : dirfd,
490 : smb_fname->base_name);
491 :
492 0 : result = ceph_mkdirat(handle->data, dirfd, smb_fname->base_name, mode);
493 :
494 0 : DBG_DEBUG("[CEPH] mkdirat(...) = %d\n", result);
495 :
496 0 : WRAP_RETURN(result);
497 : #else
498 : struct smb_filename *full_fname = NULL;
499 :
500 : full_fname = full_path_from_dirfsp_atname(talloc_tos(),
501 : dirfsp,
502 : smb_fname);
503 : if (full_fname == NULL) {
504 : return -1;
505 : }
506 :
507 : DBG_DEBUG("[CEPH] mkdir(%p, %s)\n",
508 : handle, smb_fname_str_dbg(full_fname));
509 :
510 : result = ceph_mkdir(handle->data, full_fname->base_name, mode);
511 :
512 : TALLOC_FREE(full_fname);
513 :
514 : WRAP_RETURN(result);
515 : #endif
516 : }
517 :
518 0 : static int cephwrap_closedir(struct vfs_handle_struct *handle, DIR *dirp)
519 : {
520 : int result;
521 :
522 0 : DBG_DEBUG("[CEPH] closedir(%p, %p)\n", handle, dirp);
523 0 : result = ceph_closedir(handle->data, (struct ceph_dir_result *) dirp);
524 0 : DBG_DEBUG("[CEPH] closedir(...) = %d\n", result);
525 0 : WRAP_RETURN(result);
526 : }
527 :
528 : /* File operations */
529 :
530 0 : static int cephwrap_openat(struct vfs_handle_struct *handle,
531 : const struct files_struct *dirfsp,
532 : const struct smb_filename *smb_fname,
533 : files_struct *fsp,
534 : const struct vfs_open_how *how)
535 : {
536 0 : int flags = how->flags;
537 0 : mode_t mode = how->mode;
538 0 : struct smb_filename *name = NULL;
539 0 : bool have_opath = false;
540 0 : bool became_root = false;
541 0 : int result = -ENOENT;
542 : #ifdef HAVE_CEPH_OPENAT
543 0 : int dirfd = -1;
544 : #endif
545 :
546 0 : if (how->resolve != 0) {
547 0 : errno = ENOSYS;
548 0 : return -1;
549 : }
550 :
551 0 : if (smb_fname->stream_name) {
552 0 : goto out;
553 : }
554 :
555 : #ifdef O_PATH
556 0 : have_opath = true;
557 0 : if (fsp->fsp_flags.is_pathref) {
558 0 : flags |= O_PATH;
559 : }
560 : #endif
561 :
562 : #ifdef HAVE_CEPH_OPENAT
563 0 : dirfd = fsp_get_pathref_fd(dirfsp);
564 :
565 0 : DBG_DEBUG("[CEPH] openat(%p, %d, %p, %d, %d)\n",
566 : handle, dirfd, fsp, flags, mode);
567 :
568 0 : if (fsp->fsp_flags.is_pathref && !have_opath) {
569 0 : become_root();
570 0 : became_root = true;
571 : }
572 :
573 0 : result = ceph_openat(handle->data,
574 : dirfd,
575 0 : smb_fname->base_name,
576 : flags,
577 : mode);
578 :
579 : #else
580 : if (fsp_get_pathref_fd(dirfsp) != AT_FDCWD) {
581 : name = full_path_from_dirfsp_atname(talloc_tos(),
582 : dirfsp,
583 : smb_fname);
584 : if (name == NULL) {
585 : return -1;
586 : }
587 : smb_fname = name;
588 : }
589 :
590 : DBG_DEBUG("[CEPH] openat(%p, %s, %p, %d, %d)\n", handle,
591 : smb_fname_str_dbg(smb_fname), fsp, flags, mode);
592 :
593 : if (fsp->fsp_flags.is_pathref && !have_opath) {
594 : become_root();
595 : became_root = true;
596 : }
597 :
598 : result = ceph_open(handle->data, smb_fname->base_name, flags, mode);
599 : #endif
600 0 : if (became_root) {
601 0 : unbecome_root();
602 : }
603 0 : out:
604 0 : TALLOC_FREE(name);
605 0 : fsp->fsp_flags.have_proc_fds = false;
606 0 : DBG_DEBUG("[CEPH] open(...) = %d\n", result);
607 0 : WRAP_RETURN(result);
608 : }
609 :
610 0 : static int cephwrap_close(struct vfs_handle_struct *handle, files_struct *fsp)
611 : {
612 : int result;
613 :
614 0 : DBG_DEBUG("[CEPH] close(%p, %p)\n", handle, fsp);
615 0 : result = ceph_close(handle->data, fsp_get_pathref_fd(fsp));
616 0 : DBG_DEBUG("[CEPH] close(...) = %d\n", result);
617 :
618 0 : WRAP_RETURN(result);
619 : }
620 :
621 0 : static ssize_t cephwrap_pread(struct vfs_handle_struct *handle, files_struct *fsp, void *data,
622 : size_t n, off_t offset)
623 : {
624 : ssize_t result;
625 :
626 0 : DBG_DEBUG("[CEPH] pread(%p, %p, %p, %llu, %llu)\n", handle, fsp, data, llu(n), llu(offset));
627 :
628 0 : result = ceph_read(handle->data, fsp_get_io_fd(fsp), data, n, offset);
629 0 : DBG_DEBUG("[CEPH] pread(...) = %llu\n", llu(result));
630 0 : WRAP_RETURN(result);
631 : }
632 :
633 : struct cephwrap_pread_state {
634 : ssize_t bytes_read;
635 : struct vfs_aio_state vfs_aio_state;
636 : };
637 :
638 : /*
639 : * Fake up an async ceph read by calling the synchronous API.
640 : */
641 0 : static struct tevent_req *cephwrap_pread_send(struct vfs_handle_struct *handle,
642 : TALLOC_CTX *mem_ctx,
643 : struct tevent_context *ev,
644 : struct files_struct *fsp,
645 : void *data,
646 : size_t n, off_t offset)
647 : {
648 0 : struct tevent_req *req = NULL;
649 0 : struct cephwrap_pread_state *state = NULL;
650 0 : int ret = -1;
651 :
652 0 : DBG_DEBUG("[CEPH] %s\n", __func__);
653 0 : req = tevent_req_create(mem_ctx, &state, struct cephwrap_pread_state);
654 0 : if (req == NULL) {
655 0 : return NULL;
656 : }
657 :
658 0 : ret = ceph_read(handle->data, fsp_get_io_fd(fsp), data, n, offset);
659 0 : if (ret < 0) {
660 : /* ceph returns -errno on error. */
661 0 : tevent_req_error(req, -ret);
662 0 : return tevent_req_post(req, ev);
663 : }
664 :
665 0 : state->bytes_read = ret;
666 0 : tevent_req_done(req);
667 : /* Return and schedule the completion of the call. */
668 0 : return tevent_req_post(req, ev);
669 : }
670 :
671 0 : static ssize_t cephwrap_pread_recv(struct tevent_req *req,
672 : struct vfs_aio_state *vfs_aio_state)
673 : {
674 : struct cephwrap_pread_state *state =
675 0 : tevent_req_data(req, struct cephwrap_pread_state);
676 :
677 0 : DBG_DEBUG("[CEPH] %s\n", __func__);
678 0 : if (tevent_req_is_unix_error(req, &vfs_aio_state->error)) {
679 0 : return -1;
680 : }
681 0 : *vfs_aio_state = state->vfs_aio_state;
682 0 : return state->bytes_read;
683 : }
684 :
685 0 : static ssize_t cephwrap_pwrite(struct vfs_handle_struct *handle, files_struct *fsp, const void *data,
686 : size_t n, off_t offset)
687 : {
688 : ssize_t result;
689 :
690 0 : DBG_DEBUG("[CEPH] pwrite(%p, %p, %p, %llu, %llu)\n", handle, fsp, data, llu(n), llu(offset));
691 0 : result = ceph_write(handle->data, fsp_get_io_fd(fsp), data, n, offset);
692 0 : DBG_DEBUG("[CEPH] pwrite(...) = %llu\n", llu(result));
693 0 : WRAP_RETURN(result);
694 : }
695 :
696 : struct cephwrap_pwrite_state {
697 : ssize_t bytes_written;
698 : struct vfs_aio_state vfs_aio_state;
699 : };
700 :
701 : /*
702 : * Fake up an async ceph write by calling the synchronous API.
703 : */
704 0 : static struct tevent_req *cephwrap_pwrite_send(struct vfs_handle_struct *handle,
705 : TALLOC_CTX *mem_ctx,
706 : struct tevent_context *ev,
707 : struct files_struct *fsp,
708 : const void *data,
709 : size_t n, off_t offset)
710 : {
711 0 : struct tevent_req *req = NULL;
712 0 : struct cephwrap_pwrite_state *state = NULL;
713 0 : int ret = -1;
714 :
715 0 : DBG_DEBUG("[CEPH] %s\n", __func__);
716 0 : req = tevent_req_create(mem_ctx, &state, struct cephwrap_pwrite_state);
717 0 : if (req == NULL) {
718 0 : return NULL;
719 : }
720 :
721 0 : ret = ceph_write(handle->data, fsp_get_io_fd(fsp), data, n, offset);
722 0 : if (ret < 0) {
723 : /* ceph returns -errno on error. */
724 0 : tevent_req_error(req, -ret);
725 0 : return tevent_req_post(req, ev);
726 : }
727 :
728 0 : state->bytes_written = ret;
729 0 : tevent_req_done(req);
730 : /* Return and schedule the completion of the call. */
731 0 : return tevent_req_post(req, ev);
732 : }
733 :
734 0 : static ssize_t cephwrap_pwrite_recv(struct tevent_req *req,
735 : struct vfs_aio_state *vfs_aio_state)
736 : {
737 : struct cephwrap_pwrite_state *state =
738 0 : tevent_req_data(req, struct cephwrap_pwrite_state);
739 :
740 0 : DBG_DEBUG("[CEPH] %s\n", __func__);
741 0 : if (tevent_req_is_unix_error(req, &vfs_aio_state->error)) {
742 0 : return -1;
743 : }
744 0 : *vfs_aio_state = state->vfs_aio_state;
745 0 : return state->bytes_written;
746 : }
747 :
748 0 : static off_t cephwrap_lseek(struct vfs_handle_struct *handle, files_struct *fsp, off_t offset, int whence)
749 : {
750 0 : off_t result = 0;
751 :
752 0 : DBG_DEBUG("[CEPH] cephwrap_lseek\n");
753 0 : result = ceph_lseek(handle->data, fsp_get_io_fd(fsp), offset, whence);
754 0 : WRAP_RETURN(result);
755 : }
756 :
757 0 : 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)
759 : {
760 : /*
761 : * We cannot support sendfile because libcephfs is in user space.
762 : */
763 0 : DBG_DEBUG("[CEPH] cephwrap_sendfile\n");
764 0 : errno = ENOTSUP;
765 0 : return -1;
766 : }
767 :
768 0 : static ssize_t cephwrap_recvfile(struct vfs_handle_struct *handle,
769 : int fromfd,
770 : files_struct *tofsp,
771 : off_t offset,
772 : size_t n)
773 : {
774 : /*
775 : * We cannot support recvfile because libcephfs is in user space.
776 : */
777 0 : DBG_DEBUG("[CEPH] cephwrap_recvfile\n");
778 0 : errno=ENOTSUP;
779 0 : return -1;
780 : }
781 :
782 0 : 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)
787 : {
788 0 : struct smb_filename *full_fname_src = NULL;
789 0 : struct smb_filename *full_fname_dst = NULL;
790 0 : int result = -1;
791 :
792 0 : DBG_DEBUG("[CEPH] cephwrap_renameat\n");
793 0 : if (smb_fname_src->stream_name || smb_fname_dst->stream_name) {
794 0 : errno = ENOENT;
795 0 : return result;
796 : }
797 :
798 0 : full_fname_src = full_path_from_dirfsp_atname(talloc_tos(),
799 : srcfsp,
800 : smb_fname_src);
801 0 : if (full_fname_src == NULL) {
802 0 : errno = ENOMEM;
803 0 : return -1;
804 : }
805 0 : full_fname_dst = full_path_from_dirfsp_atname(talloc_tos(),
806 : dstfsp,
807 : smb_fname_dst);
808 0 : if (full_fname_dst == NULL) {
809 0 : TALLOC_FREE(full_fname_src);
810 0 : errno = ENOMEM;
811 0 : return -1;
812 : }
813 :
814 0 : result = ceph_rename(handle->data,
815 0 : full_fname_src->base_name,
816 0 : full_fname_dst->base_name);
817 :
818 0 : TALLOC_FREE(full_fname_src);
819 0 : TALLOC_FREE(full_fname_dst);
820 :
821 0 : WRAP_RETURN(result);
822 : }
823 :
824 : /*
825 : * Fake up an async ceph fsync by calling the synchronous API.
826 : */
827 :
828 0 : static struct tevent_req *cephwrap_fsync_send(struct vfs_handle_struct *handle,
829 : TALLOC_CTX *mem_ctx,
830 : struct tevent_context *ev,
831 : files_struct *fsp)
832 : {
833 0 : struct tevent_req *req = NULL;
834 0 : struct vfs_aio_state *state = NULL;
835 0 : int ret = -1;
836 :
837 0 : DBG_DEBUG("[CEPH] cephwrap_fsync_send\n");
838 :
839 0 : req = tevent_req_create(mem_ctx, &state, struct vfs_aio_state);
840 0 : if (req == NULL) {
841 0 : return NULL;
842 : }
843 :
844 : /* Make sync call. */
845 0 : ret = ceph_fsync(handle->data, fsp_get_io_fd(fsp), false);
846 :
847 0 : if (ret != 0) {
848 : /* ceph_fsync returns -errno on error. */
849 0 : tevent_req_error(req, -ret);
850 0 : return tevent_req_post(req, ev);
851 : }
852 :
853 : /* Mark it as done. */
854 0 : tevent_req_done(req);
855 : /* Return and schedule the completion of the call. */
856 0 : return tevent_req_post(req, ev);
857 : }
858 :
859 0 : static int cephwrap_fsync_recv(struct tevent_req *req,
860 : struct vfs_aio_state *vfs_aio_state)
861 : {
862 : struct vfs_aio_state *state =
863 0 : tevent_req_data(req, struct vfs_aio_state);
864 :
865 0 : DBG_DEBUG("[CEPH] cephwrap_fsync_recv\n");
866 :
867 0 : if (tevent_req_is_unix_error(req, &vfs_aio_state->error)) {
868 0 : return -1;
869 : }
870 0 : *vfs_aio_state = *state;
871 0 : return 0;
872 : }
873 :
874 : #define SAMBA_STATX_ATTR_MASK (CEPH_STATX_BASIC_STATS|CEPH_STATX_BTIME)
875 :
876 0 : static void init_stat_ex_from_ceph_statx(struct stat_ex *dst, const struct ceph_statx *stx)
877 : {
878 0 : 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));
888 :
889 0 : if ((stx->stx_mask & SAMBA_STATX_ATTR_MASK) != SAMBA_STATX_ATTR_MASK) {
890 0 : DBG_WARNING("%s: stx->stx_mask is incorrect (wanted %x, got %x)\n",
891 : __func__, SAMBA_STATX_ATTR_MASK, stx->stx_mask);
892 : }
893 :
894 0 : dst->st_ex_dev = stx->stx_dev;
895 0 : dst->st_ex_rdev = stx->stx_rdev;
896 0 : dst->st_ex_ino = stx->stx_ino;
897 0 : dst->st_ex_mode = stx->stx_mode;
898 0 : dst->st_ex_uid = stx->stx_uid;
899 0 : dst->st_ex_gid = stx->stx_gid;
900 0 : dst->st_ex_size = stx->stx_size;
901 0 : dst->st_ex_nlink = stx->stx_nlink;
902 0 : dst->st_ex_atime = stx->stx_atime;
903 0 : dst->st_ex_btime = stx->stx_btime;
904 0 : dst->st_ex_ctime = stx->stx_ctime;
905 0 : dst->st_ex_mtime = stx->stx_mtime;
906 0 : dst->st_ex_blksize = stx->stx_blksize;
907 0 : dst->st_ex_blocks = stx->stx_blocks;
908 0 : }
909 :
910 0 : static int cephwrap_stat(struct vfs_handle_struct *handle,
911 : struct smb_filename *smb_fname)
912 : {
913 0 : int result = -1;
914 0 : struct ceph_statx stx = { 0 };
915 :
916 0 : DBG_DEBUG("[CEPH] stat(%p, %s)\n", handle, smb_fname_str_dbg(smb_fname));
917 :
918 0 : if (smb_fname->stream_name) {
919 0 : errno = ENOENT;
920 0 : return result;
921 : }
922 :
923 0 : result = ceph_statx(handle->data, smb_fname->base_name, &stx,
924 : SAMBA_STATX_ATTR_MASK, 0);
925 0 : DBG_DEBUG("[CEPH] statx(...) = %d\n", result);
926 0 : if (result < 0) {
927 0 : WRAP_RETURN(result);
928 : }
929 :
930 0 : init_stat_ex_from_ceph_statx(&smb_fname->st, &stx);
931 0 : DBG_DEBUG("[CEPH] mode = 0x%x\n", smb_fname->st.st_ex_mode);
932 0 : return result;
933 : }
934 :
935 0 : static int cephwrap_fstat(struct vfs_handle_struct *handle, files_struct *fsp, SMB_STRUCT_STAT *sbuf)
936 : {
937 0 : int result = -1;
938 0 : struct ceph_statx stx = { 0 };
939 0 : int fd = fsp_get_pathref_fd(fsp);
940 :
941 0 : DBG_DEBUG("[CEPH] fstat(%p, %d)\n", handle, fd);
942 0 : result = ceph_fstatx(handle->data, fd, &stx,
943 : SAMBA_STATX_ATTR_MASK, 0);
944 0 : DBG_DEBUG("[CEPH] fstat(...) = %d\n", result);
945 0 : if (result < 0) {
946 0 : WRAP_RETURN(result);
947 : }
948 :
949 0 : init_stat_ex_from_ceph_statx(sbuf, &stx);
950 0 : DBG_DEBUG("[CEPH] mode = 0x%x\n", sbuf->st_ex_mode);
951 0 : return result;
952 : }
953 :
954 0 : 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,
958 : int flags)
959 : {
960 0 : int result = -1;
961 0 : struct ceph_statx stx = { 0 };
962 : #ifdef HAVE_CEPH_STATXAT
963 0 : int dirfd = fsp_get_pathref_fd(dirfsp);
964 :
965 0 : DBG_DEBUG("[CEPH] fstatat(%p, %d, %s)\n",
966 : handle, dirfd, smb_fname->base_name);
967 0 : result = ceph_statxat(handle->data, dirfd, smb_fname->base_name,
968 : &stx, SAMBA_STATX_ATTR_MASK, 0);
969 : #else
970 : struct smb_filename *full_fname = NULL;
971 :
972 : full_fname = full_path_from_dirfsp_atname(talloc_tos(),
973 : dirfsp,
974 : smb_fname);
975 : if (full_fname == NULL) {
976 : errno = ENOMEM;
977 : return -1;
978 : }
979 :
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);
984 :
985 : TALLOC_FREE(full_fname);
986 : #endif
987 :
988 0 : DBG_DEBUG("[CEPH] fstatat(...) = %d\n", result);
989 0 : if (result < 0) {
990 0 : WRAP_RETURN(result);
991 : }
992 :
993 0 : init_stat_ex_from_ceph_statx(sbuf, &stx);
994 0 : DBG_DEBUG("[CEPH] mode = 0x%x\n", sbuf->st_ex_mode);
995 :
996 0 : return 0;
997 : }
998 :
999 0 : static int cephwrap_lstat(struct vfs_handle_struct *handle,
1000 : struct smb_filename *smb_fname)
1001 : {
1002 0 : int result = -1;
1003 0 : struct ceph_statx stx = { 0 };
1004 :
1005 0 : DBG_DEBUG("[CEPH] lstat(%p, %s)\n", handle, smb_fname_str_dbg(smb_fname));
1006 :
1007 0 : if (smb_fname->stream_name) {
1008 0 : errno = ENOENT;
1009 0 : return result;
1010 : }
1011 :
1012 0 : result = ceph_statx(handle->data, smb_fname->base_name, &stx,
1013 : SAMBA_STATX_ATTR_MASK, AT_SYMLINK_NOFOLLOW);
1014 0 : DBG_DEBUG("[CEPH] lstat(...) = %d\n", result);
1015 0 : if (result < 0) {
1016 0 : WRAP_RETURN(result);
1017 : }
1018 :
1019 0 : init_stat_ex_from_ceph_statx(&smb_fname->st, &stx);
1020 0 : return result;
1021 : }
1022 :
1023 0 : static int cephwrap_fntimes(struct vfs_handle_struct *handle,
1024 : files_struct *fsp,
1025 : struct smb_file_time *ft)
1026 : {
1027 0 : struct ceph_statx stx = { 0 };
1028 : int result;
1029 0 : int mask = 0;
1030 :
1031 0 : if (!is_omit_timespec(&ft->atime)) {
1032 0 : stx.stx_atime = ft->atime;
1033 0 : mask |= CEPH_SETATTR_ATIME;
1034 : }
1035 0 : if (!is_omit_timespec(&ft->mtime)) {
1036 0 : stx.stx_mtime = ft->mtime;
1037 0 : mask |= CEPH_SETATTR_MTIME;
1038 : }
1039 0 : if (!is_omit_timespec(&ft->create_time)) {
1040 0 : stx.stx_btime = ft->create_time;
1041 0 : mask |= CEPH_SETATTR_BTIME;
1042 : }
1043 :
1044 0 : if (!mask) {
1045 0 : return 0;
1046 : }
1047 :
1048 0 : if (!fsp->fsp_flags.is_pathref) {
1049 : /*
1050 : * We can use an io_fd to set xattrs.
1051 : */
1052 0 : result = ceph_fsetattrx(handle->data,
1053 : fsp_get_io_fd(fsp),
1054 : &stx,
1055 : mask);
1056 : } else {
1057 : /*
1058 : * This is no longer a handle based call.
1059 : */
1060 0 : result = ceph_setattrx(handle->data,
1061 0 : fsp->fsp_name->base_name,
1062 : &stx,
1063 : mask,
1064 : 0);
1065 : }
1066 :
1067 0 : 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);
1070 :
1071 0 : return result;
1072 : }
1073 :
1074 0 : static int cephwrap_unlinkat(struct vfs_handle_struct *handle,
1075 : struct files_struct *dirfsp,
1076 : const struct smb_filename *smb_fname,
1077 : int flags)
1078 : {
1079 0 : int result = -1;
1080 : #ifdef HAVE_CEPH_UNLINKAT
1081 0 : int dirfd = fsp_get_pathref_fd(dirfsp);
1082 :
1083 0 : DBG_DEBUG("[CEPH] unlinkat(%p, %d, %s)\n",
1084 : handle,
1085 : dirfd,
1086 : smb_fname_str_dbg(smb_fname));
1087 :
1088 0 : if (smb_fname->stream_name) {
1089 0 : errno = ENOENT;
1090 0 : return result;
1091 : }
1092 :
1093 0 : result = ceph_unlinkat(handle->data,
1094 : dirfd,
1095 0 : smb_fname->base_name,
1096 : flags);
1097 0 : DBG_DEBUG("[CEPH] unlinkat(...) = %d\n", result);
1098 0 : WRAP_RETURN(result);
1099 : #else
1100 : struct smb_filename *full_fname = NULL;
1101 :
1102 : DBG_DEBUG("[CEPH] unlink(%p, %s)\n",
1103 : handle,
1104 : smb_fname_str_dbg(smb_fname));
1105 :
1106 : if (smb_fname->stream_name) {
1107 : errno = ENOENT;
1108 : return result;
1109 : }
1110 :
1111 : full_fname = full_path_from_dirfsp_atname(talloc_tos(),
1112 : dirfsp,
1113 : smb_fname);
1114 : if (full_fname == NULL) {
1115 : return -1;
1116 : }
1117 :
1118 : if (flags & AT_REMOVEDIR) {
1119 : result = ceph_rmdir(handle->data, full_fname->base_name);
1120 : } else {
1121 : result = ceph_unlink(handle->data, full_fname->base_name);
1122 : }
1123 : TALLOC_FREE(full_fname);
1124 : DBG_DEBUG("[CEPH] unlink(...) = %d\n", result);
1125 : WRAP_RETURN(result);
1126 : #endif
1127 : }
1128 :
1129 0 : static int cephwrap_fchmod(struct vfs_handle_struct *handle, files_struct *fsp, mode_t mode)
1130 : {
1131 : int result;
1132 :
1133 0 : DBG_DEBUG("[CEPH] fchmod(%p, %p, %d)\n", handle, fsp, mode);
1134 0 : if (!fsp->fsp_flags.is_pathref) {
1135 : /*
1136 : * We can use an io_fd to change permissions.
1137 : */
1138 0 : result = ceph_fchmod(handle->data, fsp_get_io_fd(fsp), mode);
1139 : } else {
1140 : /*
1141 : * This is no longer a handle based call.
1142 : */
1143 0 : result = ceph_chmod(handle->data,
1144 0 : fsp->fsp_name->base_name,
1145 : mode);
1146 : }
1147 0 : DBG_DEBUG("[CEPH] fchmod(...) = %d\n", result);
1148 0 : WRAP_RETURN(result);
1149 : }
1150 :
1151 0 : static int cephwrap_fchown(struct vfs_handle_struct *handle, files_struct *fsp, uid_t uid, gid_t gid)
1152 : {
1153 : int result;
1154 :
1155 0 : DBG_DEBUG("[CEPH] fchown(%p, %p, %d, %d)\n", handle, fsp, uid, gid);
1156 0 : if (!fsp->fsp_flags.is_pathref) {
1157 : /*
1158 : * We can use an io_fd to change ownership.
1159 : */
1160 0 : result = ceph_fchown(handle->data,
1161 : fsp_get_io_fd(fsp),
1162 : uid,
1163 : gid);
1164 : } else {
1165 : /*
1166 : * This is no longer a handle based call.
1167 : */
1168 0 : result = ceph_chown(handle->data,
1169 0 : fsp->fsp_name->base_name,
1170 : uid,
1171 : gid);
1172 : }
1173 :
1174 0 : DBG_DEBUG("[CEPH] fchown(...) = %d\n", result);
1175 0 : WRAP_RETURN(result);
1176 : }
1177 :
1178 0 : static int cephwrap_lchown(struct vfs_handle_struct *handle,
1179 : const struct smb_filename *smb_fname,
1180 : uid_t uid,
1181 : gid_t gid)
1182 : {
1183 : int result;
1184 0 : DBG_DEBUG("[CEPH] lchown(%p, %s, %d, %d)\n", handle, smb_fname->base_name, uid, gid);
1185 0 : result = ceph_lchown(handle->data, smb_fname->base_name, uid, gid);
1186 0 : DBG_DEBUG("[CEPH] lchown(...) = %d\n", result);
1187 0 : WRAP_RETURN(result);
1188 : }
1189 :
1190 0 : static int cephwrap_chdir(struct vfs_handle_struct *handle,
1191 : const struct smb_filename *smb_fname)
1192 : {
1193 0 : int result = -1;
1194 0 : DBG_DEBUG("[CEPH] chdir(%p, %s)\n", handle, smb_fname->base_name);
1195 0 : result = ceph_chdir(handle->data, smb_fname->base_name);
1196 0 : DBG_DEBUG("[CEPH] chdir(...) = %d\n", result);
1197 0 : WRAP_RETURN(result);
1198 : }
1199 :
1200 0 : static struct smb_filename *cephwrap_getwd(struct vfs_handle_struct *handle,
1201 : TALLOC_CTX *ctx)
1202 : {
1203 0 : const char *cwd = ceph_getcwd(handle->data);
1204 0 : DBG_DEBUG("[CEPH] getwd(%p) = %s\n", handle, cwd);
1205 0 : return synthetic_smb_fname(ctx,
1206 : cwd,
1207 : NULL,
1208 : NULL,
1209 : 0,
1210 : 0);
1211 : }
1212 :
1213 0 : static int strict_allocate_ftruncate(struct vfs_handle_struct *handle, files_struct *fsp, off_t len)
1214 : {
1215 : off_t space_to_write;
1216 : int result;
1217 : NTSTATUS status;
1218 : SMB_STRUCT_STAT *pst;
1219 :
1220 0 : status = vfs_stat_fsp(fsp);
1221 0 : if (!NT_STATUS_IS_OK(status)) {
1222 0 : return -1;
1223 : }
1224 0 : pst = &fsp->fsp_name->st;
1225 :
1226 : #ifdef S_ISFIFO
1227 0 : if (S_ISFIFO(pst->st_ex_mode))
1228 0 : return 0;
1229 : #endif
1230 :
1231 0 : if (pst->st_ex_size == len)
1232 0 : return 0;
1233 :
1234 : /* Shrink - just ftruncate. */
1235 0 : if (pst->st_ex_size > len) {
1236 0 : result = ceph_ftruncate(handle->data, fsp_get_io_fd(fsp), len);
1237 0 : WRAP_RETURN(result);
1238 : }
1239 :
1240 0 : space_to_write = len - pst->st_ex_size;
1241 0 : result = ceph_fallocate(handle->data, fsp_get_io_fd(fsp), 0, pst->st_ex_size,
1242 : space_to_write);
1243 0 : WRAP_RETURN(result);
1244 : }
1245 :
1246 0 : static int cephwrap_ftruncate(struct vfs_handle_struct *handle, files_struct *fsp, off_t len)
1247 : {
1248 0 : int result = -1;
1249 :
1250 0 : DBG_DEBUG("[CEPH] ftruncate(%p, %p, %llu\n", handle, fsp, llu(len));
1251 :
1252 0 : if (lp_strict_allocate(SNUM(fsp->conn))) {
1253 0 : return strict_allocate_ftruncate(handle, fsp, len);
1254 : }
1255 :
1256 0 : result = ceph_ftruncate(handle->data, fsp_get_io_fd(fsp), len);
1257 0 : WRAP_RETURN(result);
1258 : }
1259 :
1260 0 : static int cephwrap_fallocate(struct vfs_handle_struct *handle,
1261 : struct files_struct *fsp,
1262 : uint32_t mode,
1263 : off_t offset,
1264 : off_t len)
1265 : {
1266 : int result;
1267 :
1268 0 : 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 0 : result = ceph_fallocate(handle->data, fsp_get_io_fd(fsp), mode, offset, len);
1272 0 : DBG_DEBUG("[CEPH] fallocate(...) = %d\n", result);
1273 0 : WRAP_RETURN(result);
1274 : }
1275 :
1276 0 : static bool cephwrap_lock(struct vfs_handle_struct *handle, files_struct *fsp, int op, off_t offset, off_t count, int type)
1277 : {
1278 0 : DBG_DEBUG("[CEPH] lock\n");
1279 0 : return true;
1280 : }
1281 :
1282 0 : static int cephwrap_filesystem_sharemode(struct vfs_handle_struct *handle,
1283 : files_struct *fsp,
1284 : uint32_t share_access,
1285 : uint32_t access_mask)
1286 : {
1287 0 : DBG_ERR("[CEPH] filesystem sharemodes unsupported! Consider setting "
1288 : "\"kernel share modes = no\"\n");
1289 :
1290 0 : errno = ENOSYS;
1291 0 : return -1;
1292 : }
1293 :
1294 0 : static int cephwrap_fcntl(vfs_handle_struct *handle,
1295 : files_struct *fsp, int cmd, va_list cmd_arg)
1296 : {
1297 : /*
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.
1300 : */
1301 0 : if (cmd == F_GETFL) {
1302 0 : return 0;
1303 0 : } else if (cmd == F_SETFL) {
1304 : va_list dup_cmd_arg;
1305 : int opt;
1306 :
1307 0 : va_copy(dup_cmd_arg, cmd_arg);
1308 0 : opt = va_arg(dup_cmd_arg, int);
1309 0 : va_end(dup_cmd_arg);
1310 0 : if (opt == 0) {
1311 0 : return 0;
1312 : }
1313 0 : DBG_ERR("unexpected fcntl SETFL(%d)\n", opt);
1314 0 : goto err_out;
1315 : }
1316 0 : DBG_ERR("unexpected fcntl: %d\n", cmd);
1317 0 : err_out:
1318 0 : errno = EINVAL;
1319 0 : return -1;
1320 : }
1321 :
1322 0 : static bool cephwrap_getlock(struct vfs_handle_struct *handle, files_struct *fsp, off_t *poffset, off_t *pcount, int *ptype, pid_t *ppid)
1323 : {
1324 0 : DBG_DEBUG("[CEPH] getlock returning false and errno=0\n");
1325 :
1326 0 : errno = 0;
1327 0 : return false;
1328 : }
1329 :
1330 : /*
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.
1334 : */
1335 0 : static int cephwrap_linux_setlease(struct vfs_handle_struct *handle, files_struct *fsp,
1336 : int leasetype)
1337 : {
1338 0 : int result = -1;
1339 :
1340 0 : DBG_DEBUG("[CEPH] linux_setlease\n");
1341 0 : errno = ENOSYS;
1342 0 : return result;
1343 : }
1344 :
1345 0 : 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)
1349 : {
1350 0 : int result = -1;
1351 : #ifdef HAVE_CEPH_SYMLINKAT
1352 0 : int dirfd = fsp_get_pathref_fd(dirfsp);
1353 :
1354 0 : DBG_DEBUG("[CEPH] symlinkat(%p, %s, %d, %s)\n",
1355 : handle,
1356 : link_target->base_name,
1357 : dirfd,
1358 : new_smb_fname->base_name);
1359 :
1360 0 : result = ceph_symlinkat(handle->data,
1361 0 : link_target->base_name,
1362 : dirfd,
1363 0 : new_smb_fname->base_name);
1364 0 : DBG_DEBUG("[CEPH] symlinkat(...) = %d\n", result);
1365 0 : WRAP_RETURN(result);
1366 : #else
1367 : struct smb_filename *full_fname = NULL;
1368 :
1369 : full_fname = full_path_from_dirfsp_atname(talloc_tos(),
1370 : dirfsp,
1371 : new_smb_fname);
1372 : if (full_fname == NULL) {
1373 : return -1;
1374 : }
1375 :
1376 : DBG_DEBUG("[CEPH] symlink(%p, %s, %s)\n", handle,
1377 : link_target->base_name,
1378 : full_fname->base_name);
1379 :
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);
1386 : #endif
1387 : }
1388 :
1389 0 : static int cephwrap_readlinkat(struct vfs_handle_struct *handle,
1390 : const struct files_struct *dirfsp,
1391 : const struct smb_filename *smb_fname,
1392 : char *buf,
1393 : size_t bufsiz)
1394 : {
1395 0 : int result = -1;
1396 : #ifdef HAVE_CEPH_READLINKAT
1397 0 : int dirfd = fsp_get_pathref_fd(dirfsp);
1398 :
1399 0 : DBG_DEBUG("[CEPH] readlinkat(%p, %d, %s, %p, %llu)\n",
1400 : handle,
1401 : dirfd,
1402 : smb_fname->base_name,
1403 : buf,
1404 : llu(bufsiz));
1405 :
1406 0 : result = ceph_readlinkat(handle->data,
1407 : dirfd,
1408 0 : smb_fname->base_name,
1409 : buf,
1410 : bufsiz);
1411 :
1412 0 : DBG_DEBUG("[CEPH] readlinkat(...) = %d\n", result);
1413 0 : WRAP_RETURN(result);
1414 : #else
1415 : struct smb_filename *full_fname = NULL;
1416 :
1417 : full_fname = full_path_from_dirfsp_atname(talloc_tos(),
1418 : dirfsp,
1419 : smb_fname);
1420 : if (full_fname == NULL) {
1421 : return -1;
1422 : }
1423 :
1424 : DBG_DEBUG("[CEPH] readlink(%p, %s, %p, %llu)\n", handle,
1425 : full_fname->base_name, buf, llu(bufsiz));
1426 :
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);
1431 : #endif
1432 : }
1433 :
1434 0 : 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,
1439 : int flags)
1440 : {
1441 0 : struct smb_filename *full_fname_old = NULL;
1442 0 : struct smb_filename *full_fname_new = NULL;
1443 0 : int result = -1;
1444 :
1445 0 : full_fname_old = full_path_from_dirfsp_atname(talloc_tos(),
1446 : srcfsp,
1447 : old_smb_fname);
1448 0 : if (full_fname_old == NULL) {
1449 0 : return -1;
1450 : }
1451 0 : full_fname_new = full_path_from_dirfsp_atname(talloc_tos(),
1452 : dstfsp,
1453 : new_smb_fname);
1454 0 : if (full_fname_new == NULL) {
1455 0 : TALLOC_FREE(full_fname_old);
1456 0 : return -1;
1457 : }
1458 :
1459 0 : DBG_DEBUG("[CEPH] link(%p, %s, %s)\n", handle,
1460 : full_fname_old->base_name,
1461 : full_fname_new->base_name);
1462 :
1463 0 : result = ceph_link(handle->data,
1464 0 : full_fname_old->base_name,
1465 0 : full_fname_new->base_name);
1466 0 : DBG_DEBUG("[CEPH] link(...) = %d\n", result);
1467 0 : TALLOC_FREE(full_fname_old);
1468 0 : TALLOC_FREE(full_fname_new);
1469 0 : WRAP_RETURN(result);
1470 : }
1471 :
1472 0 : static int cephwrap_mknodat(struct vfs_handle_struct *handle,
1473 : files_struct *dirfsp,
1474 : const struct smb_filename *smb_fname,
1475 : mode_t mode,
1476 : SMB_DEV_T dev)
1477 : {
1478 0 : struct smb_filename *full_fname = NULL;
1479 0 : int result = -1;
1480 :
1481 0 : full_fname = full_path_from_dirfsp_atname(talloc_tos(),
1482 : dirfsp,
1483 : smb_fname);
1484 0 : if (full_fname == NULL) {
1485 0 : return -1;
1486 : }
1487 :
1488 0 : DBG_DEBUG("[CEPH] mknodat(%p, %s)\n", handle, full_fname->base_name);
1489 0 : result = ceph_mknod(handle->data, full_fname->base_name, mode, dev);
1490 0 : DBG_DEBUG("[CEPH] mknodat(...) = %d\n", result);
1491 :
1492 0 : TALLOC_FREE(full_fname);
1493 :
1494 0 : WRAP_RETURN(result);
1495 : }
1496 :
1497 : /*
1498 : * This is a simple version of real-path ... a better version is needed to
1499 : * ask libcephfs about symbolic links.
1500 : */
1501 0 : static struct smb_filename *cephwrap_realpath(struct vfs_handle_struct *handle,
1502 : TALLOC_CTX *ctx,
1503 : const struct smb_filename *smb_fname)
1504 : {
1505 0 : char *result = NULL;
1506 0 : const char *path = smb_fname->base_name;
1507 0 : size_t len = strlen(path);
1508 0 : struct smb_filename *result_fname = NULL;
1509 0 : int r = -1;
1510 :
1511 0 : if (len && (path[0] == '/')) {
1512 0 : r = asprintf(&result, "%s", path);
1513 0 : } else if ((len >= 2) && (path[0] == '.') && (path[1] == '/')) {
1514 0 : if (len == 2) {
1515 0 : r = asprintf(&result, "%s",
1516 0 : handle->conn->cwd_fsp->fsp_name->base_name);
1517 : } else {
1518 0 : r = asprintf(&result, "%s/%s",
1519 0 : handle->conn->cwd_fsp->fsp_name->base_name, &path[2]);
1520 : }
1521 : } else {
1522 0 : r = asprintf(&result, "%s/%s",
1523 0 : handle->conn->cwd_fsp->fsp_name->base_name, path);
1524 : }
1525 :
1526 0 : if (r < 0) {
1527 0 : return NULL;
1528 : }
1529 :
1530 0 : DBG_DEBUG("[CEPH] realpath(%p, %s) = %s\n", handle, path, result);
1531 0 : result_fname = synthetic_smb_fname(ctx,
1532 : result,
1533 : NULL,
1534 : NULL,
1535 : 0,
1536 : 0);
1537 0 : SAFE_FREE(result);
1538 0 : return result_fname;
1539 : }
1540 :
1541 :
1542 0 : static int cephwrap_fchflags(struct vfs_handle_struct *handle,
1543 : struct files_struct *fsp,
1544 : unsigned int flags)
1545 : {
1546 0 : errno = ENOSYS;
1547 0 : return -1;
1548 : }
1549 :
1550 0 : static NTSTATUS cephwrap_get_real_filename_at(
1551 : struct vfs_handle_struct *handle,
1552 : struct files_struct *dirfsp,
1553 : const char *name,
1554 : TALLOC_CTX *mem_ctx,
1555 : char **found_name)
1556 : {
1557 : /*
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.
1560 : */
1561 0 : return NT_STATUS_NOT_SUPPORTED;
1562 : }
1563 :
1564 0 : static const char *cephwrap_connectpath(
1565 : struct vfs_handle_struct *handle,
1566 : const struct files_struct *dirfsp,
1567 : const struct smb_filename *smb_fname)
1568 : {
1569 0 : return handle->conn->connectpath;
1570 : }
1571 :
1572 0 : static NTSTATUS cephwrap_fget_dos_attributes(struct vfs_handle_struct *handle,
1573 : struct files_struct *fsp,
1574 : uint32_t *dosmode)
1575 : {
1576 0 : struct timespec saved_btime = fsp->fsp_name->st.st_ex_btime;
1577 : NTSTATUS status;
1578 :
1579 0 : status = fget_ea_dos_attribute(fsp, dosmode);
1580 0 : if (!NT_STATUS_IS_OK(status)) {
1581 0 : return status;
1582 : }
1583 :
1584 : /*
1585 : * Restore previously stored btime from statx timestamps as it should be
1586 : * the only source of truth. create_time from dos attribute, if any, may
1587 : * have older values which isn't trustworthy to be looked at for other
1588 : * open file handle operations.
1589 : */
1590 0 : fsp->fsp_name->st.st_ex_btime = saved_btime;
1591 :
1592 0 : return NT_STATUS_OK;
1593 : }
1594 :
1595 : /****************************************************************
1596 : Extended attribute operations.
1597 : *****************************************************************/
1598 :
1599 0 : static ssize_t cephwrap_fgetxattr(struct vfs_handle_struct *handle,
1600 : struct files_struct *fsp,
1601 : const char *name,
1602 : void *value,
1603 : size_t size)
1604 : {
1605 : int ret;
1606 0 : DBG_DEBUG("[CEPH] fgetxattr(%p, %p, %s, %p, %llu)\n",
1607 : handle,
1608 : fsp,
1609 : name,
1610 : value,
1611 : llu(size));
1612 0 : if (!fsp->fsp_flags.is_pathref) {
1613 0 : ret = ceph_fgetxattr(handle->data,
1614 : fsp_get_io_fd(fsp),
1615 : name,
1616 : value,
1617 : size);
1618 : } else {
1619 0 : ret = ceph_getxattr(handle->data,
1620 0 : fsp->fsp_name->base_name,
1621 : name,
1622 : value,
1623 : size);
1624 : }
1625 0 : DBG_DEBUG("[CEPH] fgetxattr(...) = %d\n", ret);
1626 0 : if (ret < 0) {
1627 0 : WRAP_RETURN(ret);
1628 : }
1629 0 : return (ssize_t)ret;
1630 : }
1631 :
1632 0 : static ssize_t cephwrap_flistxattr(struct vfs_handle_struct *handle, struct files_struct *fsp, char *list, size_t size)
1633 : {
1634 : int ret;
1635 0 : DBG_DEBUG("[CEPH] flistxattr(%p, %p, %p, %llu)\n",
1636 : handle, fsp, list, llu(size));
1637 0 : if (!fsp->fsp_flags.is_pathref) {
1638 : /*
1639 : * We can use an io_fd to list xattrs.
1640 : */
1641 0 : ret = ceph_flistxattr(handle->data,
1642 : fsp_get_io_fd(fsp),
1643 : list,
1644 : size);
1645 : } else {
1646 : /*
1647 : * This is no longer a handle based call.
1648 : */
1649 0 : ret = ceph_listxattr(handle->data,
1650 0 : fsp->fsp_name->base_name,
1651 : list,
1652 : size);
1653 : }
1654 0 : DBG_DEBUG("[CEPH] flistxattr(...) = %d\n", ret);
1655 0 : if (ret < 0) {
1656 0 : WRAP_RETURN(ret);
1657 : }
1658 0 : return (ssize_t)ret;
1659 : }
1660 :
1661 0 : static int cephwrap_fremovexattr(struct vfs_handle_struct *handle, struct files_struct *fsp, const char *name)
1662 : {
1663 : int ret;
1664 0 : DBG_DEBUG("[CEPH] fremovexattr(%p, %p, %s)\n", handle, fsp, name);
1665 0 : if (!fsp->fsp_flags.is_pathref) {
1666 : /*
1667 : * We can use an io_fd to remove xattrs.
1668 : */
1669 0 : ret = ceph_fremovexattr(handle->data, fsp_get_io_fd(fsp), name);
1670 : } else {
1671 : /*
1672 : * This is no longer a handle based call.
1673 : */
1674 0 : ret = ceph_removexattr(handle->data,
1675 0 : fsp->fsp_name->base_name,
1676 : name);
1677 : }
1678 0 : DBG_DEBUG("[CEPH] fremovexattr(...) = %d\n", ret);
1679 0 : WRAP_RETURN(ret);
1680 : }
1681 :
1682 0 : static int cephwrap_fsetxattr(struct vfs_handle_struct *handle, struct files_struct *fsp, const char *name, const void *value, size_t size, int flags)
1683 : {
1684 : int ret;
1685 0 : DBG_DEBUG("[CEPH] fsetxattr(%p, %p, %s, %p, %llu, %d)\n", handle, fsp, name, value, llu(size), flags);
1686 0 : if (!fsp->fsp_flags.is_pathref) {
1687 : /*
1688 : * We can use an io_fd to set xattrs.
1689 : */
1690 0 : ret = ceph_fsetxattr(handle->data,
1691 : fsp_get_io_fd(fsp),
1692 : name,
1693 : value,
1694 : size,
1695 : flags);
1696 : } else {
1697 : /*
1698 : * This is no longer a handle based call.
1699 : */
1700 0 : ret = ceph_setxattr(handle->data,
1701 0 : fsp->fsp_name->base_name,
1702 : name,
1703 : value,
1704 : size,
1705 : flags);
1706 : }
1707 0 : DBG_DEBUG("[CEPH] fsetxattr(...) = %d\n", ret);
1708 0 : WRAP_RETURN(ret);
1709 : }
1710 :
1711 0 : static bool cephwrap_aio_force(struct vfs_handle_struct *handle, struct files_struct *fsp)
1712 : {
1713 :
1714 : /*
1715 : * We do not support AIO yet.
1716 : */
1717 :
1718 0 : DBG_DEBUG("[CEPH] cephwrap_aio_force(%p, %p) = false (errno = ENOTSUP)\n", handle, fsp);
1719 0 : errno = ENOTSUP;
1720 0 : return false;
1721 : }
1722 :
1723 0 : static NTSTATUS cephwrap_create_dfs_pathat(struct vfs_handle_struct *handle,
1724 : struct files_struct *dirfsp,
1725 : const struct smb_filename *smb_fname,
1726 : const struct referral *reflist,
1727 : size_t referral_count)
1728 : {
1729 0 : TALLOC_CTX *frame = talloc_stackframe();
1730 0 : NTSTATUS status = NT_STATUS_NO_MEMORY;
1731 : int ret;
1732 0 : char *msdfs_link = NULL;
1733 0 : struct smb_filename *full_fname = NULL;
1734 :
1735 0 : full_fname = full_path_from_dirfsp_atname(talloc_tos(),
1736 : dirfsp,
1737 : smb_fname);
1738 0 : if (full_fname == NULL) {
1739 0 : goto out;
1740 : }
1741 :
1742 : /* Form the msdfs_link contents */
1743 0 : msdfs_link = msdfs_link_string(frame,
1744 : reflist,
1745 : referral_count);
1746 0 : if (msdfs_link == NULL) {
1747 0 : goto out;
1748 : }
1749 :
1750 0 : ret = ceph_symlink(handle->data,
1751 : msdfs_link,
1752 0 : full_fname->base_name);
1753 0 : if (ret == 0) {
1754 0 : status = NT_STATUS_OK;
1755 : } else {
1756 0 : status = map_nt_error_from_unix(-ret);
1757 : }
1758 :
1759 0 : out:
1760 :
1761 0 : DBG_DEBUG("[CEPH] create_dfs_pathat(%s) = %s\n",
1762 : full_fname != NULL ? full_fname->base_name : "",
1763 : nt_errstr(status));
1764 :
1765 0 : TALLOC_FREE(frame);
1766 0 : return status;
1767 : }
1768 :
1769 : /*
1770 : * Read and return the contents of a DFS redirect given a
1771 : * pathname. A caller can pass in NULL for ppreflist and
1772 : * preferral_count but still determine if this was a
1773 : * DFS redirect point by getting NT_STATUS_OK back
1774 : * without incurring the overhead of reading and parsing
1775 : * the referral contents.
1776 : */
1777 :
1778 0 : static NTSTATUS cephwrap_read_dfs_pathat(struct vfs_handle_struct *handle,
1779 : TALLOC_CTX *mem_ctx,
1780 : struct files_struct *dirfsp,
1781 : struct smb_filename *smb_fname,
1782 : struct referral **ppreflist,
1783 : size_t *preferral_count)
1784 : {
1785 0 : NTSTATUS status = NT_STATUS_NO_MEMORY;
1786 : size_t bufsize;
1787 0 : char *link_target = NULL;
1788 : int referral_len;
1789 : bool ok;
1790 : #if defined(HAVE_BROKEN_READLINK)
1791 : char link_target_buf[PATH_MAX];
1792 : #else
1793 : char link_target_buf[7];
1794 : #endif
1795 0 : struct ceph_statx stx = { 0 };
1796 0 : struct smb_filename *full_fname = NULL;
1797 : int ret;
1798 :
1799 0 : if (is_named_stream(smb_fname)) {
1800 0 : status = NT_STATUS_OBJECT_NAME_NOT_FOUND;
1801 0 : goto err;
1802 : }
1803 :
1804 0 : if (ppreflist == NULL && preferral_count == NULL) {
1805 : /*
1806 : * We're only checking if this is a DFS
1807 : * redirect. We don't need to return data.
1808 : */
1809 0 : bufsize = sizeof(link_target_buf);
1810 0 : link_target = link_target_buf;
1811 : } else {
1812 0 : bufsize = PATH_MAX;
1813 0 : link_target = talloc_array(mem_ctx, char, bufsize);
1814 0 : if (!link_target) {
1815 0 : goto err;
1816 : }
1817 : }
1818 :
1819 0 : full_fname = full_path_from_dirfsp_atname(talloc_tos(),
1820 : dirfsp,
1821 : smb_fname);
1822 0 : if (full_fname == NULL) {
1823 0 : status = NT_STATUS_NO_MEMORY;
1824 0 : goto err;
1825 : }
1826 :
1827 0 : ret = ceph_statx(handle->data,
1828 0 : full_fname->base_name,
1829 : &stx,
1830 : SAMBA_STATX_ATTR_MASK,
1831 : AT_SYMLINK_NOFOLLOW);
1832 0 : if (ret < 0) {
1833 0 : status = map_nt_error_from_unix(-ret);
1834 0 : goto err;
1835 : }
1836 :
1837 0 : referral_len = ceph_readlink(handle->data,
1838 0 : full_fname->base_name,
1839 : link_target,
1840 0 : bufsize - 1);
1841 0 : if (referral_len < 0) {
1842 : /* ceph errors are -errno. */
1843 0 : if (-referral_len == EINVAL) {
1844 0 : DBG_INFO("%s is not a link.\n",
1845 : full_fname->base_name);
1846 0 : status = NT_STATUS_OBJECT_TYPE_MISMATCH;
1847 : } else {
1848 0 : status = map_nt_error_from_unix(-referral_len);
1849 0 : DBG_ERR("Error reading "
1850 : "msdfs link %s: %s\n",
1851 : full_fname->base_name,
1852 : strerror(errno));
1853 : }
1854 0 : goto err;
1855 : }
1856 0 : link_target[referral_len] = '\0';
1857 :
1858 0 : DBG_INFO("%s -> %s\n",
1859 : full_fname->base_name,
1860 : link_target);
1861 :
1862 0 : if (!strnequal(link_target, "msdfs:", 6)) {
1863 0 : status = NT_STATUS_OBJECT_TYPE_MISMATCH;
1864 0 : goto err;
1865 : }
1866 :
1867 0 : if (ppreflist == NULL && preferral_count == NULL) {
1868 : /* Early return for checking if this is a DFS link. */
1869 0 : TALLOC_FREE(full_fname);
1870 0 : init_stat_ex_from_ceph_statx(&smb_fname->st, &stx);
1871 0 : return NT_STATUS_OK;
1872 : }
1873 :
1874 0 : ok = parse_msdfs_symlink(mem_ctx,
1875 0 : lp_msdfs_shuffle_referrals(SNUM(handle->conn)),
1876 : link_target,
1877 : ppreflist,
1878 : preferral_count);
1879 :
1880 0 : if (ok) {
1881 0 : init_stat_ex_from_ceph_statx(&smb_fname->st, &stx);
1882 0 : status = NT_STATUS_OK;
1883 : } else {
1884 0 : status = NT_STATUS_NO_MEMORY;
1885 : }
1886 :
1887 0 : err:
1888 :
1889 0 : if (link_target != link_target_buf) {
1890 0 : TALLOC_FREE(link_target);
1891 : }
1892 0 : TALLOC_FREE(full_fname);
1893 0 : return status;
1894 : }
1895 :
1896 : static struct vfs_fn_pointers ceph_fns = {
1897 : /* Disk operations */
1898 :
1899 : .connect_fn = cephwrap_connect,
1900 : .disconnect_fn = cephwrap_disconnect,
1901 : .disk_free_fn = cephwrap_disk_free,
1902 : .get_quota_fn = cephwrap_get_quota,
1903 : .set_quota_fn = cephwrap_set_quota,
1904 : .statvfs_fn = cephwrap_statvfs,
1905 : .fs_capabilities_fn = cephwrap_fs_capabilities,
1906 :
1907 : /* Directory operations */
1908 :
1909 : .fdopendir_fn = cephwrap_fdopendir,
1910 : .readdir_fn = cephwrap_readdir,
1911 : .rewind_dir_fn = cephwrap_rewinddir,
1912 : .mkdirat_fn = cephwrap_mkdirat,
1913 : .closedir_fn = cephwrap_closedir,
1914 :
1915 : /* File operations */
1916 :
1917 : .create_dfs_pathat_fn = cephwrap_create_dfs_pathat,
1918 : .read_dfs_pathat_fn = cephwrap_read_dfs_pathat,
1919 : .openat_fn = cephwrap_openat,
1920 : .close_fn = cephwrap_close,
1921 : .pread_fn = cephwrap_pread,
1922 : .pread_send_fn = cephwrap_pread_send,
1923 : .pread_recv_fn = cephwrap_pread_recv,
1924 : .pwrite_fn = cephwrap_pwrite,
1925 : .pwrite_send_fn = cephwrap_pwrite_send,
1926 : .pwrite_recv_fn = cephwrap_pwrite_recv,
1927 : .lseek_fn = cephwrap_lseek,
1928 : .sendfile_fn = cephwrap_sendfile,
1929 : .recvfile_fn = cephwrap_recvfile,
1930 : .renameat_fn = cephwrap_renameat,
1931 : .fsync_send_fn = cephwrap_fsync_send,
1932 : .fsync_recv_fn = cephwrap_fsync_recv,
1933 : .stat_fn = cephwrap_stat,
1934 : .fstat_fn = cephwrap_fstat,
1935 : .lstat_fn = cephwrap_lstat,
1936 : .fstatat_fn = cephwrap_fstatat,
1937 : .unlinkat_fn = cephwrap_unlinkat,
1938 : .fchmod_fn = cephwrap_fchmod,
1939 : .fchown_fn = cephwrap_fchown,
1940 : .lchown_fn = cephwrap_lchown,
1941 : .chdir_fn = cephwrap_chdir,
1942 : .getwd_fn = cephwrap_getwd,
1943 : .fntimes_fn = cephwrap_fntimes,
1944 : .ftruncate_fn = cephwrap_ftruncate,
1945 : .fallocate_fn = cephwrap_fallocate,
1946 : .lock_fn = cephwrap_lock,
1947 : .filesystem_sharemode_fn = cephwrap_filesystem_sharemode,
1948 : .fcntl_fn = cephwrap_fcntl,
1949 : .linux_setlease_fn = cephwrap_linux_setlease,
1950 : .getlock_fn = cephwrap_getlock,
1951 : .symlinkat_fn = cephwrap_symlinkat,
1952 : .readlinkat_fn = cephwrap_readlinkat,
1953 : .linkat_fn = cephwrap_linkat,
1954 : .mknodat_fn = cephwrap_mknodat,
1955 : .realpath_fn = cephwrap_realpath,
1956 : .fchflags_fn = cephwrap_fchflags,
1957 : .get_real_filename_at_fn = cephwrap_get_real_filename_at,
1958 : .connectpath_fn = cephwrap_connectpath,
1959 : .fget_dos_attributes_fn = cephwrap_fget_dos_attributes,
1960 :
1961 : /* EA operations. */
1962 : .getxattrat_send_fn = vfs_not_implemented_getxattrat_send,
1963 : .getxattrat_recv_fn = vfs_not_implemented_getxattrat_recv,
1964 : .fgetxattr_fn = cephwrap_fgetxattr,
1965 : .flistxattr_fn = cephwrap_flistxattr,
1966 : .fremovexattr_fn = cephwrap_fremovexattr,
1967 : .fsetxattr_fn = cephwrap_fsetxattr,
1968 :
1969 : /* Posix ACL Operations */
1970 : .sys_acl_get_fd_fn = posixacl_xattr_acl_get_fd,
1971 : .sys_acl_blob_get_fd_fn = posix_sys_acl_blob_get_fd,
1972 : .sys_acl_set_fd_fn = posixacl_xattr_acl_set_fd,
1973 : .sys_acl_delete_def_fd_fn = posixacl_xattr_acl_delete_def_fd,
1974 :
1975 : /* aio operations */
1976 : .aio_force_fn = cephwrap_aio_force,
1977 : };
1978 :
1979 : static_decl_vfs;
1980 27 : NTSTATUS vfs_ceph_init(TALLOC_CTX *ctx)
1981 : {
1982 27 : return smb_register_vfs(SMB_VFS_INTERFACE_VERSION,
1983 : "ceph", &ceph_fns);
1984 : }
|