1 // -*- mode:C++; tab-width:8; c-basic-offset:2; indent-tabs-mode:t -*-
2 // vim: ts=8 sw=2 smarttab
4 * Ceph - scalable distributed file system
6 * Copyright (C) 2009-2011 New Dream Network
8 * This is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU Lesser General Public
10 * License version 2.1, as published by the Free Software
11 * Foundation. See file COPYING.
20 #include "auth/Crypto.h"
21 #include "client/Client.h"
22 #include "librados/RadosClient.h"
23 #include "common/async/context_pool.h"
24 #include "common/ceph_argparse.h"
25 #include "common/common_init.h"
26 #include "common/config.h"
27 #include "common/version.h"
28 #include "mon/MonClient.h"
29 #include "include/str_list.h"
30 #include "messages/MMonMap.h"
31 #include "msg/Messenger.h"
32 #include "include/ceph_assert.h"
33 #include "mds/MDSMap.h"
35 #include "include/cephfs/libcephfs.h"
37 #define DEFAULT_UMASK 002
39 static mode_t
umask_cb(void *);
41 // Set things up this way so we don't start up threads until mount and
42 // kill them off when the last mount goes away, but are tolerant to
43 // multiple mounts of overlapping duration.
44 std::shared_ptr
<ceph::async::io_context_pool
> get_icp(CephContext
* cct
)
47 static std::weak_ptr
<ceph::async::io_context_pool
> icwp
;
50 std::unique_lock
l(m
);
52 auto icp
= icwp
.lock();
56 icp
= std::make_shared
<ceph::async::io_context_pool
>();
58 icp
->start(cct
->_conf
.get_val
<std::uint64_t>("client_asio_thread_count"));
63 struct ceph_mount_info
65 mode_t umask
= DEFAULT_UMASK
;
66 std::shared_ptr
<ceph::async::io_context_pool
> icp
;
68 explicit ceph_mount_info(CephContext
*cct_
)
91 catch (const std::exception
& e
) {
92 // we shouldn't get here, but if we do, we want to know about it.
93 lderr(cct
) << "ceph_mount_info::~ceph_mount_info: caught exception: "
105 if (!cct
->_log
->is_started()) {
111 MonClient
mc_bootstrap(cct
, icp
->get_io_context());
112 ret
= mc_bootstrap
.get_monmap_and_config();
117 common_init_finish(cct
);
120 monclient
= new MonClient(cct
, icp
->get_io_context());
121 ret
= -CEPHFS_ERROR_MON_MAP_BUILD
; //defined in libcephfs.h;
122 if (monclient
->build_initial_monmap() < 0)
126 messenger
= Messenger::create_client_messenger(cct
, "client");
129 ret
= -CEPHFS_ERROR_NEW_CLIENT
; //defined in libcephfs.h;
130 client
= new StandaloneClient(messenger
, monclient
, icp
->get_io_context());
134 ret
= -CEPHFS_ERROR_MESSENGER_START
; //defined in libcephfs.h;
135 if (messenger
->start() != 0)
138 ret
= client
->init();
143 ceph_client_callback_args args
= {};
145 args
.umask_cb
= umask_cb
;
146 client
->ll_register_callbacks(&args
);
149 default_perms
= Client::pick_my_perms(cct
);
158 int select_filesystem(const std::string
&fs_name_
)
168 const std::string
& get_filesystem(void)
173 int mount(const std::string
&mount_root
, const UserPerm
& perms
)
187 ret
= client
->mount(mount_root
, perms
, false, fs_name
);
207 client
->abort_conn();
224 messenger
->shutdown();
240 bool is_initialized() const
250 mode_t
set_umask(mode_t umask
)
256 std::string
getaddrs()
258 CachedStackStringStream cos
;
259 *cos
<< messenger
->get_myaddrs();
260 return std::string(cos
->strv());
263 int conf_read_file(const char *path_list
)
265 int ret
= cct
->_conf
.parse_config_files(path_list
, nullptr, 0);
268 cct
->_conf
.apply_changes(nullptr);
269 cct
->_conf
.complain_about_parse_error(cct
);
273 int conf_parse_argv(int argc
, const char **argv
)
276 vector
<const char*> args
;
277 argv_to_vec(argc
, argv
, args
);
278 ret
= cct
->_conf
.parse_argv(args
);
281 cct
->_conf
.apply_changes(nullptr);
285 int conf_parse_env(const char *name
)
287 auto& conf
= cct
->_conf
;
288 conf
.parse_env(cct
->get_module_type(), name
);
289 conf
.apply_changes(nullptr);
293 int conf_set(const char *option
, const char *value
)
295 int ret
= cct
->_conf
.set_val(option
, value
);
298 cct
->_conf
.apply_changes(nullptr);
302 int conf_get(const char *option
, char *buf
, size_t len
)
305 return cct
->_conf
.get_val(option
, &tmp
, len
);
313 const char *get_cwd(const UserPerm
& perms
)
315 client
->getcwd(cwd
, perms
);
319 int chdir(const char *to
, const UserPerm
& perms
)
321 return client
->chdir(to
, cwd
, perms
);
324 CephContext
*get_ceph_context() const {
328 UserPerm default_perms
;
332 StandaloneClient
*client
;
333 MonClient
*monclient
;
334 Messenger
*messenger
;
340 static mode_t
umask_cb(void *handle
)
342 return ((struct ceph_mount_info
*)handle
)->umask
;
345 static void do_out_buffer(bufferlist
& outbl
, char **outbuf
, size_t *outbuflen
)
348 if (outbl
.length() > 0) {
349 *outbuf
= (char *)malloc(outbl
.length());
350 memcpy(*outbuf
, outbl
.c_str(), outbl
.length());
356 *outbuflen
= outbl
.length();
359 static void do_out_buffer(string
& outbl
, char **outbuf
, size_t *outbuflen
)
362 if (outbl
.length() > 0) {
363 *outbuf
= (char *)malloc(outbl
.length());
364 memcpy(*outbuf
, outbl
.c_str(), outbl
.length());
370 *outbuflen
= outbl
.length();
373 extern "C" UserPerm
*ceph_userperm_new(uid_t uid
, gid_t gid
, int ngids
,
376 return new (std::nothrow
) UserPerm(uid
, gid
, ngids
, gidlist
);
379 extern "C" void ceph_userperm_destroy(UserPerm
*perm
)
384 extern "C" const char *ceph_version(int *pmajor
, int *pminor
, int *ppatch
)
386 int major
, minor
, patch
;
387 const char *v
= ceph_version_to_str();
389 int n
= sscanf(v
, "%d.%d.%d", &major
, &minor
, &patch
);
391 *pmajor
= (n
>= 1) ? major
: 0;
393 *pminor
= (n
>= 2) ? minor
: 0;
395 *ppatch
= (n
>= 3) ? patch
: 0;
396 return PROJECT_VERSION
;
399 extern "C" int ceph_create_with_context(struct ceph_mount_info
**cmount
, CephContext
*cct
)
401 *cmount
= new struct ceph_mount_info(cct
);
405 extern "C" int ceph_create_from_rados(struct ceph_mount_info
**cmount
,
408 auto rados
= (librados::RadosClient
*) cluster
;
409 auto cct
= rados
->cct
;
410 return ceph_create_with_context(cmount
, cct
);
413 extern "C" int ceph_create(struct ceph_mount_info
**cmount
, const char * const id
)
415 CephInitParameters
iparams(CEPH_ENTITY_TYPE_CLIENT
);
417 iparams
.name
.set(CEPH_ENTITY_TYPE_CLIENT
, id
);
420 CephContext
*cct
= common_preinit(iparams
, CODE_ENVIRONMENT_LIBRARY
, 0);
421 cct
->_conf
.parse_env(cct
->get_module_type()); // environment variables coverride
422 cct
->_conf
.apply_changes(nullptr);
423 int ret
= ceph_create_with_context(cmount
, cct
);
429 extern "C" int ceph_unmount(struct ceph_mount_info
*cmount
)
431 return cmount
->unmount();
434 extern "C" int ceph_abort_conn(struct ceph_mount_info
*cmount
)
436 return cmount
->abort_conn();
439 extern "C" int ceph_release(struct ceph_mount_info
*cmount
)
441 if (cmount
->is_mounted())
448 extern "C" void ceph_shutdown(struct ceph_mount_info
*cmount
)
455 extern "C" uint64_t ceph_get_instance_id(struct ceph_mount_info
*cmount
)
457 if (cmount
->is_initialized())
458 return cmount
->get_client()->get_nodeid().v
;
462 extern "C" int ceph_getaddrs(struct ceph_mount_info
*cmount
, char** addrs
)
464 if (!cmount
->is_initialized())
466 auto s
= cmount
->getaddrs();
467 *addrs
= strdup(s
.c_str());
471 extern "C" int ceph_conf_read_file(struct ceph_mount_info
*cmount
, const char *path
)
473 return cmount
->conf_read_file(path
);
476 extern "C" mode_t
ceph_umask(struct ceph_mount_info
*cmount
, mode_t mode
)
478 return cmount
->set_umask(mode
);
481 extern "C" int ceph_conf_parse_argv(struct ceph_mount_info
*cmount
, int argc
,
484 return cmount
->conf_parse_argv(argc
, argv
);
487 extern "C" int ceph_conf_parse_env(struct ceph_mount_info
*cmount
, const char *name
)
489 return cmount
->conf_parse_env(name
);
492 extern "C" int ceph_conf_set(struct ceph_mount_info
*cmount
, const char *option
,
495 return cmount
->conf_set(option
, value
);
498 extern "C" int ceph_conf_get(struct ceph_mount_info
*cmount
, const char *option
,
499 char *buf
, size_t len
)
504 return cmount
->conf_get(option
, buf
, len
);
507 extern "C" int ceph_mds_command(struct ceph_mount_info
*cmount
,
508 const char *mds_spec
,
511 const char *inbuf
, size_t inbuflen
,
512 char **outbuf
, size_t *outbuflen
,
513 char **outsbuf
, size_t *outsbuflen
)
517 std::vector
<string
> cmdv
;
520 if (!cmount
->is_initialized()) {
525 for (size_t i
= 0; i
< cmdlen
; ++i
) {
526 cmdv
.push_back(cmd
[i
]);
528 inbl
.append(inbuf
, inbuflen
);
530 // Issue remote command
532 int r
= cmount
->get_client()->mds_command(
542 // Wait for completion
546 do_out_buffer(outbl
, outbuf
, outbuflen
);
547 do_out_buffer(outs
, outsbuf
, outsbuflen
);
553 extern "C" int ceph_init(struct ceph_mount_info
*cmount
)
555 return cmount
->init();
558 extern "C" int ceph_select_filesystem(struct ceph_mount_info
*cmount
,
561 if (fs_name
== nullptr) {
565 return cmount
->select_filesystem(fs_name
);
568 extern "C" int ceph_mount(struct ceph_mount_info
*cmount
, const char *root
)
570 std::string mount_root
;
573 return cmount
->mount(mount_root
, cmount
->default_perms
);
576 extern "C" int ceph_is_mounted(struct ceph_mount_info
*cmount
)
578 return cmount
->is_mounted() ? 1 : 0;
581 extern "C" struct UserPerm
*ceph_mount_perms(struct ceph_mount_info
*cmount
)
583 return &cmount
->default_perms
;
586 extern "C" int64_t ceph_get_fs_cid(struct ceph_mount_info
*cmount
)
588 if (!cmount
->is_mounted())
590 return cmount
->get_client()->get_fs_cid();
593 extern "C" int ceph_mount_perms_set(struct ceph_mount_info
*cmount
,
594 struct UserPerm
*perms
)
596 if (cmount
->is_mounted())
598 cmount
->default_perms
= *perms
;
602 extern "C" int ceph_statfs(struct ceph_mount_info
*cmount
, const char *path
,
603 struct statvfs
*stbuf
)
605 if (!cmount
->is_mounted())
607 return cmount
->get_client()->statfs(path
, stbuf
, cmount
->default_perms
);
610 extern "C" int ceph_get_local_osd(struct ceph_mount_info
*cmount
)
612 if (!cmount
->is_mounted())
614 return cmount
->get_client()->get_local_osd();
617 extern "C" const char* ceph_getcwd(struct ceph_mount_info
*cmount
)
619 return cmount
->get_cwd(cmount
->default_perms
);
622 extern "C" int ceph_chdir (struct ceph_mount_info
*cmount
, const char *s
)
624 if (!cmount
->is_mounted())
626 return cmount
->chdir(s
, cmount
->default_perms
);
629 extern "C" int ceph_opendir(struct ceph_mount_info
*cmount
,
630 const char *name
, struct ceph_dir_result
**dirpp
)
632 if (!cmount
->is_mounted())
634 return cmount
->get_client()->opendir(name
, (dir_result_t
**)dirpp
, cmount
->default_perms
);
637 extern "C" int ceph_closedir(struct ceph_mount_info
*cmount
, struct ceph_dir_result
*dirp
)
639 if (!cmount
->is_mounted())
641 return cmount
->get_client()->closedir(reinterpret_cast<dir_result_t
*>(dirp
));
644 extern "C" struct dirent
* ceph_readdir(struct ceph_mount_info
*cmount
, struct ceph_dir_result
*dirp
)
646 if (!cmount
->is_mounted()) {
647 /* Client::readdir also sets errno to signal errors. */
651 return cmount
->get_client()->readdir(reinterpret_cast<dir_result_t
*>(dirp
));
654 extern "C" int ceph_readdir_r(struct ceph_mount_info
*cmount
, struct ceph_dir_result
*dirp
, struct dirent
*de
)
656 if (!cmount
->is_mounted())
658 return cmount
->get_client()->readdir_r(reinterpret_cast<dir_result_t
*>(dirp
), de
);
661 extern "C" int ceph_readdirplus_r(struct ceph_mount_info
*cmount
, struct ceph_dir_result
*dirp
,
662 struct dirent
*de
, struct ceph_statx
*stx
, unsigned want
,
663 unsigned flags
, struct Inode
**out
)
665 if (!cmount
->is_mounted())
667 if (flags
& ~CEPH_REQ_FLAG_MASK
)
669 return cmount
->get_client()->readdirplus_r(reinterpret_cast<dir_result_t
*>(dirp
), de
, stx
, want
, flags
, out
);
672 extern "C" int ceph_getdents(struct ceph_mount_info
*cmount
, struct ceph_dir_result
*dirp
,
673 char *buf
, int buflen
)
675 if (!cmount
->is_mounted())
677 return cmount
->get_client()->getdents(reinterpret_cast<dir_result_t
*>(dirp
), buf
, buflen
);
680 extern "C" int ceph_getdnames(struct ceph_mount_info
*cmount
, struct ceph_dir_result
*dirp
,
681 char *buf
, int buflen
)
683 if (!cmount
->is_mounted())
685 return cmount
->get_client()->getdnames(reinterpret_cast<dir_result_t
*>(dirp
), buf
, buflen
);
688 extern "C" void ceph_rewinddir(struct ceph_mount_info
*cmount
, struct ceph_dir_result
*dirp
)
690 if (!cmount
->is_mounted())
692 cmount
->get_client()->rewinddir(reinterpret_cast<dir_result_t
*>(dirp
));
695 extern "C" int64_t ceph_telldir(struct ceph_mount_info
*cmount
, struct ceph_dir_result
*dirp
)
697 if (!cmount
->is_mounted())
699 return cmount
->get_client()->telldir(reinterpret_cast<dir_result_t
*>(dirp
));
702 extern "C" void ceph_seekdir(struct ceph_mount_info
*cmount
, struct ceph_dir_result
*dirp
, int64_t offset
)
704 if (!cmount
->is_mounted())
706 cmount
->get_client()->seekdir(reinterpret_cast<dir_result_t
*>(dirp
), offset
);
709 extern "C" int ceph_may_delete(struct ceph_mount_info
*cmount
, const char *path
)
711 if (!cmount
->is_mounted())
713 return cmount
->get_client()->may_delete(path
, cmount
->default_perms
);
716 extern "C" int ceph_link (struct ceph_mount_info
*cmount
, const char *existing
,
719 if (!cmount
->is_mounted())
721 return cmount
->get_client()->link(existing
, newname
, cmount
->default_perms
);
724 extern "C" int ceph_unlink(struct ceph_mount_info
*cmount
, const char *path
)
726 if (!cmount
->is_mounted())
728 return cmount
->get_client()->unlink(path
, cmount
->default_perms
);
731 extern "C" int ceph_rename(struct ceph_mount_info
*cmount
, const char *from
,
734 if (!cmount
->is_mounted())
736 return cmount
->get_client()->rename(from
, to
, cmount
->default_perms
);
740 extern "C" int ceph_mkdir(struct ceph_mount_info
*cmount
, const char *path
, mode_t mode
)
742 if (!cmount
->is_mounted())
744 return cmount
->get_client()->mkdir(path
, mode
, cmount
->default_perms
);
747 extern "C" int ceph_mksnap(struct ceph_mount_info
*cmount
, const char *path
, const char *name
,
748 mode_t mode
, struct snap_metadata
*snap_metadata
, size_t nr_snap_metadata
)
750 if (!cmount
->is_mounted())
753 std::map
<std::string
, std::string
> metadata
;
754 while (i
< nr_snap_metadata
) {
755 metadata
.emplace(snap_metadata
[i
].key
, snap_metadata
[i
].value
);
758 return cmount
->get_client()->mksnap(path
, name
, cmount
->default_perms
, mode
, metadata
);
761 extern "C" int ceph_rmsnap(struct ceph_mount_info
*cmount
, const char *path
, const char *name
)
763 if (!cmount
->is_mounted())
765 return cmount
->get_client()->rmsnap(path
, name
, cmount
->default_perms
, true);
768 extern "C" int ceph_mkdirs(struct ceph_mount_info
*cmount
, const char *path
, mode_t mode
)
770 if (!cmount
->is_mounted())
772 return cmount
->get_client()->mkdirs(path
, mode
, cmount
->default_perms
);
775 extern "C" int ceph_rmdir(struct ceph_mount_info
*cmount
, const char *path
)
777 if (!cmount
->is_mounted())
779 return cmount
->get_client()->rmdir(path
, cmount
->default_perms
);
783 extern "C" int ceph_readlink(struct ceph_mount_info
*cmount
, const char *path
,
784 char *buf
, int64_t size
)
786 if (!cmount
->is_mounted())
788 return cmount
->get_client()->readlink(path
, buf
, size
, cmount
->default_perms
);
791 extern "C" int ceph_symlink(struct ceph_mount_info
*cmount
, const char *existing
,
794 if (!cmount
->is_mounted())
796 return cmount
->get_client()->symlink(existing
, newname
, cmount
->default_perms
);
799 extern "C" int ceph_fstatx(struct ceph_mount_info
*cmount
, int fd
, struct ceph_statx
*stx
,
800 unsigned int want
, unsigned int flags
)
802 if (!cmount
->is_mounted())
804 if (flags
& ~CEPH_REQ_FLAG_MASK
)
806 return cmount
->get_client()->fstatx(fd
, stx
, cmount
->default_perms
,
810 extern "C" int ceph_statx(struct ceph_mount_info
*cmount
, const char *path
,
811 struct ceph_statx
*stx
, unsigned int want
, unsigned int flags
)
813 if (!cmount
->is_mounted())
815 if (flags
& ~CEPH_REQ_FLAG_MASK
)
817 return cmount
->get_client()->statx(path
, stx
, cmount
->default_perms
,
821 extern "C" int ceph_fsetattrx(struct ceph_mount_info
*cmount
, int fd
,
822 struct ceph_statx
*stx
, int mask
)
824 if (!cmount
->is_mounted())
826 return cmount
->get_client()->fsetattrx(fd
, stx
, mask
, cmount
->default_perms
);
829 extern "C" int ceph_setattrx(struct ceph_mount_info
*cmount
, const char *relpath
,
830 struct ceph_statx
*stx
, int mask
, int flags
)
832 if (!cmount
->is_mounted())
834 if (flags
& ~CEPH_REQ_FLAG_MASK
)
836 return cmount
->get_client()->setattrx(relpath
, stx
, mask
,
837 cmount
->default_perms
, flags
);
840 // *xattr() calls supporting samba/vfs
841 extern "C" int ceph_getxattr(struct ceph_mount_info
*cmount
, const char *path
, const char *name
, void *value
, size_t size
)
843 if (!cmount
->is_mounted())
846 return cmount
->get_client()->getxattr(path
, name
, value
, size
, cmount
->default_perms
);
849 extern "C" int ceph_lgetxattr(struct ceph_mount_info
*cmount
, const char *path
, const char *name
, void *value
, size_t size
)
851 if (!cmount
->is_mounted())
853 return cmount
->get_client()->lgetxattr(path
, name
, value
, size
, cmount
->default_perms
);
856 extern "C" int ceph_fgetxattr(struct ceph_mount_info
*cmount
, int fd
, const char *name
, void *value
, size_t size
)
858 if (!cmount
->is_mounted())
860 return cmount
->get_client()->fgetxattr(fd
, name
, value
, size
, cmount
->default_perms
);
864 extern "C" int ceph_listxattr(struct ceph_mount_info
*cmount
, const char *path
, char *list
, size_t size
)
866 if (!cmount
->is_mounted())
868 return cmount
->get_client()->listxattr(path
, list
, size
, cmount
->default_perms
);
871 extern "C" int ceph_llistxattr(struct ceph_mount_info
*cmount
, const char *path
, char *list
, size_t size
)
873 if (!cmount
->is_mounted())
875 return cmount
->get_client()->llistxattr(path
, list
, size
, cmount
->default_perms
);
878 extern "C" int ceph_flistxattr(struct ceph_mount_info
*cmount
, int fd
, char *list
, size_t size
)
880 if (!cmount
->is_mounted())
882 return cmount
->get_client()->flistxattr(fd
, list
, size
, cmount
->default_perms
);
885 extern "C" int ceph_removexattr(struct ceph_mount_info
*cmount
, const char *path
, const char *name
)
887 if (!cmount
->is_mounted())
889 return cmount
->get_client()->removexattr(path
, name
, cmount
->default_perms
);
892 extern "C" int ceph_lremovexattr(struct ceph_mount_info
*cmount
, const char *path
, const char *name
)
894 if (!cmount
->is_mounted())
896 return cmount
->get_client()->lremovexattr(path
, name
, cmount
->default_perms
);
899 extern "C" int ceph_fremovexattr(struct ceph_mount_info
*cmount
, int fd
, const char *name
)
901 if (!cmount
->is_mounted())
903 return cmount
->get_client()->fremovexattr(fd
, name
, cmount
->default_perms
);
906 extern "C" int ceph_setxattr(struct ceph_mount_info
*cmount
, const char *path
, const char *name
, const void *value
, size_t size
, int flags
)
908 if (!cmount
->is_mounted())
910 return cmount
->get_client()->setxattr(path
, name
, value
, size
, flags
, cmount
->default_perms
);
913 extern "C" int ceph_lsetxattr(struct ceph_mount_info
*cmount
, const char *path
, const char *name
, const void *value
, size_t size
, int flags
)
915 if (!cmount
->is_mounted())
917 return cmount
->get_client()->lsetxattr(path
, name
, value
, size
, flags
, cmount
->default_perms
);
920 extern "C" int ceph_fsetxattr(struct ceph_mount_info
*cmount
, int fd
, const char *name
, const void *value
, size_t size
, int flags
)
922 if (!cmount
->is_mounted())
924 return cmount
->get_client()->fsetxattr(fd
, name
, value
, size
, flags
, cmount
->default_perms
);
926 /* end xattr support */
928 extern "C" int ceph_stat(struct ceph_mount_info
*cmount
, const char *path
, struct stat
*stbuf
)
930 if (!cmount
->is_mounted())
932 return cmount
->get_client()->stat(path
, stbuf
, cmount
->default_perms
);
935 extern "C" int ceph_fstat(struct ceph_mount_info
*cmount
, int fd
, struct stat
*stbuf
)
937 if (!cmount
->is_mounted())
939 return cmount
->get_client()->fstat(fd
, stbuf
, cmount
->default_perms
);
942 extern int ceph_lstat(struct ceph_mount_info
*cmount
, const char *path
, struct stat
*stbuf
)
944 if (!cmount
->is_mounted())
946 return cmount
->get_client()->lstat(path
, stbuf
, cmount
->default_perms
);
949 extern "C" int ceph_chmod(struct ceph_mount_info
*cmount
, const char *path
, mode_t mode
)
951 if (!cmount
->is_mounted())
953 return cmount
->get_client()->chmod(path
, mode
, cmount
->default_perms
);
955 extern "C" int ceph_lchmod(struct ceph_mount_info
*cmount
, const char *path
, mode_t mode
)
957 if (!cmount
->is_mounted())
959 return cmount
->get_client()->lchmod(path
, mode
, cmount
->default_perms
);
961 extern "C" int ceph_fchmod(struct ceph_mount_info
*cmount
, int fd
, mode_t mode
)
963 if (!cmount
->is_mounted())
965 return cmount
->get_client()->fchmod(fd
, mode
, cmount
->default_perms
);
967 extern "C" int ceph_chown(struct ceph_mount_info
*cmount
, const char *path
,
970 if (!cmount
->is_mounted())
972 return cmount
->get_client()->chown(path
, uid
, gid
, cmount
->default_perms
);
974 extern "C" int ceph_fchown(struct ceph_mount_info
*cmount
, int fd
,
977 if (!cmount
->is_mounted())
979 return cmount
->get_client()->fchown(fd
, uid
, gid
, cmount
->default_perms
);
981 extern "C" int ceph_lchown(struct ceph_mount_info
*cmount
, const char *path
,
984 if (!cmount
->is_mounted())
986 return cmount
->get_client()->lchown(path
, uid
, gid
, cmount
->default_perms
);
990 extern "C" int ceph_utime(struct ceph_mount_info
*cmount
, const char *path
,
993 if (!cmount
->is_mounted())
995 return cmount
->get_client()->utime(path
, buf
, cmount
->default_perms
);
998 extern "C" int ceph_futime(struct ceph_mount_info
*cmount
, int fd
,
1001 if (!cmount
->is_mounted())
1003 return cmount
->get_client()->futime(fd
, buf
, cmount
->default_perms
);
1006 extern "C" int ceph_utimes(struct ceph_mount_info
*cmount
, const char *path
,
1007 struct timeval times
[2])
1009 if (!cmount
->is_mounted())
1011 return cmount
->get_client()->utimes(path
, times
, cmount
->default_perms
);
1014 extern "C" int ceph_lutimes(struct ceph_mount_info
*cmount
, const char *path
,
1015 struct timeval times
[2])
1017 if (!cmount
->is_mounted())
1019 return cmount
->get_client()->lutimes(path
, times
, cmount
->default_perms
);
1022 extern "C" int ceph_futimes(struct ceph_mount_info
*cmount
, int fd
,
1023 struct timeval times
[2])
1025 if (!cmount
->is_mounted())
1027 return cmount
->get_client()->futimes(fd
, times
, cmount
->default_perms
);
1030 extern "C" int ceph_futimens(struct ceph_mount_info
*cmount
, int fd
,
1031 struct timespec times
[2])
1033 if (!cmount
->is_mounted())
1035 return cmount
->get_client()->futimens(fd
, times
, cmount
->default_perms
);
1038 extern "C" int ceph_flock(struct ceph_mount_info
*cmount
, int fd
, int operation
,
1041 if (!cmount
->is_mounted())
1043 return cmount
->get_client()->flock(fd
, operation
, owner
);
1046 extern "C" int ceph_truncate(struct ceph_mount_info
*cmount
, const char *path
,
1049 if (!cmount
->is_mounted())
1051 return cmount
->get_client()->truncate(path
, size
, cmount
->default_perms
);
1055 extern "C" int ceph_mknod(struct ceph_mount_info
*cmount
, const char *path
,
1056 mode_t mode
, dev_t rdev
)
1058 if (!cmount
->is_mounted())
1060 return cmount
->get_client()->mknod(path
, mode
, cmount
->default_perms
, rdev
);
1063 extern "C" int ceph_open(struct ceph_mount_info
*cmount
, const char *path
,
1064 int flags
, mode_t mode
)
1066 if (!cmount
->is_mounted())
1068 return cmount
->get_client()->open(path
, flags
, cmount
->default_perms
, mode
);
1071 extern "C" int ceph_open_layout(struct ceph_mount_info
*cmount
, const char *path
, int flags
,
1072 mode_t mode
, int stripe_unit
, int stripe_count
, int object_size
, const char *data_pool
)
1074 if (!cmount
->is_mounted())
1076 return cmount
->get_client()->open(path
, flags
, cmount
->default_perms
, mode
,
1077 stripe_unit
, stripe_count
,
1078 object_size
, data_pool
);
1081 extern "C" int ceph_close(struct ceph_mount_info
*cmount
, int fd
)
1083 if (!cmount
->is_mounted())
1085 return cmount
->get_client()->close(fd
);
1088 extern "C" int64_t ceph_lseek(struct ceph_mount_info
*cmount
, int fd
,
1089 int64_t offset
, int whence
)
1091 if (!cmount
->is_mounted())
1093 return cmount
->get_client()->lseek(fd
, offset
, whence
);
1096 extern "C" int ceph_read(struct ceph_mount_info
*cmount
, int fd
, char *buf
,
1097 int64_t size
, int64_t offset
)
1099 if (!cmount
->is_mounted())
1101 return cmount
->get_client()->read(fd
, buf
, size
, offset
);
1104 extern "C" int ceph_preadv(struct ceph_mount_info
*cmount
, int fd
,
1105 const struct iovec
*iov
, int iovcnt
, int64_t offset
)
1107 if (!cmount
->is_mounted())
1109 return cmount
->get_client()->preadv(fd
, iov
, iovcnt
, offset
);
1112 extern "C" int ceph_write(struct ceph_mount_info
*cmount
, int fd
, const char *buf
,
1113 int64_t size
, int64_t offset
)
1115 if (!cmount
->is_mounted())
1117 return cmount
->get_client()->write(fd
, buf
, size
, offset
);
1120 extern "C" int ceph_pwritev(struct ceph_mount_info
*cmount
, int fd
,
1121 const struct iovec
*iov
, int iovcnt
, int64_t offset
)
1123 if (!cmount
->is_mounted())
1125 return cmount
->get_client()->pwritev(fd
, iov
, iovcnt
, offset
);
1128 extern "C" int ceph_ftruncate(struct ceph_mount_info
*cmount
, int fd
, int64_t size
)
1130 if (!cmount
->is_mounted())
1132 return cmount
->get_client()->ftruncate(fd
, size
, cmount
->default_perms
);
1135 extern "C" int ceph_fsync(struct ceph_mount_info
*cmount
, int fd
, int syncdataonly
)
1137 if (!cmount
->is_mounted())
1139 return cmount
->get_client()->fsync(fd
, syncdataonly
);
1142 extern "C" int ceph_fallocate(struct ceph_mount_info
*cmount
, int fd
, int mode
,
1143 int64_t offset
, int64_t length
)
1145 if (!cmount
->is_mounted())
1147 return cmount
->get_client()->fallocate(fd
, mode
, offset
, length
);
1150 extern "C" int ceph_lazyio(class ceph_mount_info
*cmount
,
1153 return (cmount
->get_client()->lazyio(fd
, enable
));
1156 extern "C" int ceph_lazyio_propagate(class ceph_mount_info
*cmount
,
1157 int fd
, int64_t offset
, size_t count
)
1159 if (!cmount
->is_mounted())
1161 return (cmount
->get_client()->lazyio_propagate(fd
, offset
, count
));
1164 extern "C" int ceph_lazyio_synchronize(class ceph_mount_info
*cmount
,
1165 int fd
, int64_t offset
, size_t count
)
1167 if (!cmount
->is_mounted())
1169 return (cmount
->get_client()->lazyio_synchronize(fd
, offset
, count
));
1173 extern "C" int ceph_sync_fs(struct ceph_mount_info
*cmount
)
1175 if (!cmount
->is_mounted())
1177 return cmount
->get_client()->sync_fs();
1180 extern "C" int ceph_get_file_stripe_unit(struct ceph_mount_info
*cmount
, int fh
)
1185 if (!cmount
->is_mounted())
1187 r
= cmount
->get_client()->fdescribe_layout(fh
, &l
);
1190 return l
.stripe_unit
;
1193 extern "C" int ceph_get_path_stripe_unit(struct ceph_mount_info
*cmount
, const char *path
)
1198 if (!cmount
->is_mounted())
1200 r
= cmount
->get_client()->describe_layout(path
, &l
, cmount
->default_perms
);
1203 return l
.stripe_unit
;
1206 extern "C" int ceph_get_file_stripe_count(struct ceph_mount_info
*cmount
, int fh
)
1211 if (!cmount
->is_mounted())
1213 r
= cmount
->get_client()->fdescribe_layout(fh
, &l
);
1216 return l
.stripe_count
;
1219 extern "C" int ceph_get_path_stripe_count(struct ceph_mount_info
*cmount
, const char *path
)
1224 if (!cmount
->is_mounted())
1226 r
= cmount
->get_client()->describe_layout(path
, &l
, cmount
->default_perms
);
1229 return l
.stripe_count
;
1232 extern "C" int ceph_get_file_object_size(struct ceph_mount_info
*cmount
, int fh
)
1237 if (!cmount
->is_mounted())
1239 r
= cmount
->get_client()->fdescribe_layout(fh
, &l
);
1242 return l
.object_size
;
1245 extern "C" int ceph_get_path_object_size(struct ceph_mount_info
*cmount
, const char *path
)
1250 if (!cmount
->is_mounted())
1252 r
= cmount
->get_client()->describe_layout(path
, &l
, cmount
->default_perms
);
1255 return l
.object_size
;
1258 extern "C" int ceph_get_file_pool(struct ceph_mount_info
*cmount
, int fh
)
1263 if (!cmount
->is_mounted())
1265 r
= cmount
->get_client()->fdescribe_layout(fh
, &l
);
1271 extern "C" int ceph_get_path_pool(struct ceph_mount_info
*cmount
, const char *path
)
1276 if (!cmount
->is_mounted())
1278 r
= cmount
->get_client()->describe_layout(path
, &l
, cmount
->default_perms
);
1284 extern "C" int ceph_get_file_pool_name(struct ceph_mount_info
*cmount
, int fh
, char *buf
, size_t len
)
1289 if (!cmount
->is_mounted())
1291 r
= cmount
->get_client()->fdescribe_layout(fh
, &l
);
1294 string name
= cmount
->get_client()->get_pool_name(l
.pool_id
);
1296 return name
.length();
1297 if (name
.length() > len
)
1299 strncpy(buf
, name
.c_str(), len
);
1300 return name
.length();
1303 extern "C" int ceph_get_pool_name(struct ceph_mount_info
*cmount
, int pool
, char *buf
, size_t len
)
1305 if (!cmount
->is_mounted())
1307 string name
= cmount
->get_client()->get_pool_name(pool
);
1309 return name
.length();
1310 if (name
.length() > len
)
1312 strncpy(buf
, name
.c_str(), len
);
1313 return name
.length();
1316 extern "C" int ceph_get_path_pool_name(struct ceph_mount_info
*cmount
, const char *path
, char *buf
, size_t len
)
1321 if (!cmount
->is_mounted())
1323 r
= cmount
->get_client()->describe_layout(path
, &l
, cmount
->default_perms
);
1326 string name
= cmount
->get_client()->get_pool_name(l
.pool_id
);
1328 return name
.length();
1329 if (name
.length() > len
)
1331 strncpy(buf
, name
.c_str(), len
);
1332 return name
.length();
1335 extern "C" int ceph_get_default_data_pool_name(struct ceph_mount_info
*cmount
, char *buf
, size_t len
)
1337 if (!cmount
->is_mounted())
1339 int64_t pool_id
= cmount
->get_client()->get_default_pool_id();
1341 string name
= cmount
->get_client()->get_pool_name(pool_id
);
1343 return name
.length();
1344 if (name
.length() > len
)
1346 strncpy(buf
, name
.c_str(), len
);
1347 return name
.length();
1350 extern "C" int ceph_get_file_layout(struct ceph_mount_info
*cmount
, int fh
, int *stripe_unit
, int *stripe_count
, int *object_size
, int *pg_pool
)
1355 if (!cmount
->is_mounted())
1357 r
= cmount
->get_client()->fdescribe_layout(fh
, &l
);
1361 *stripe_unit
= l
.stripe_unit
;
1363 *stripe_count
= l
.stripe_count
;
1365 *object_size
= l
.object_size
;
1367 *pg_pool
= l
.pool_id
;
1371 extern "C" int ceph_get_path_layout(struct ceph_mount_info
*cmount
, const char *path
, int *stripe_unit
, int *stripe_count
, int *object_size
, int *pg_pool
)
1376 if (!cmount
->is_mounted())
1378 r
= cmount
->get_client()->describe_layout(path
, &l
, cmount
->default_perms
);
1382 *stripe_unit
= l
.stripe_unit
;
1384 *stripe_count
= l
.stripe_count
;
1386 *object_size
= l
.object_size
;
1388 *pg_pool
= l
.pool_id
;
1392 extern "C" int ceph_get_file_replication(struct ceph_mount_info
*cmount
, int fh
)
1397 if (!cmount
->is_mounted())
1399 r
= cmount
->get_client()->fdescribe_layout(fh
, &l
);
1402 int rep
= cmount
->get_client()->get_pool_replication(l
.pool_id
);
1406 extern "C" int ceph_get_path_replication(struct ceph_mount_info
*cmount
, const char *path
)
1411 if (!cmount
->is_mounted())
1413 r
= cmount
->get_client()->describe_layout(path
, &l
, cmount
->default_perms
);
1416 int rep
= cmount
->get_client()->get_pool_replication(l
.pool_id
);
1420 extern "C" int ceph_set_default_file_stripe_unit(struct ceph_mount_info
*cmount
,
1423 // this option no longer exists
1427 extern "C" int ceph_set_default_file_stripe_count(struct ceph_mount_info
*cmount
,
1430 // this option no longer exists
1434 extern "C" int ceph_set_default_object_size(struct ceph_mount_info
*cmount
, int size
)
1436 // this option no longer exists
1440 extern "C" int ceph_set_default_file_replication(struct ceph_mount_info
*cmount
,
1443 // this option no longer exists
1447 extern "C" int ceph_set_default_preferred_pg(struct ceph_mount_info
*cmount
, int osd
)
1449 // this option no longer exists
1453 extern "C" int ceph_get_file_extent_osds(struct ceph_mount_info
*cmount
, int fh
,
1454 int64_t offset
, int64_t *length
, int *osds
, int nosds
)
1459 if (!cmount
->is_mounted())
1463 int ret
= cmount
->get_client()->get_file_extent_osds(fh
, offset
, length
, vosds
);
1468 return vosds
.size();
1470 if ((int)vosds
.size() > nosds
)
1473 for (int i
= 0; i
< (int)vosds
.size(); i
++)
1476 return vosds
.size();
1479 extern "C" int ceph_get_osd_crush_location(struct ceph_mount_info
*cmount
,
1480 int osd
, char *path
, size_t len
)
1482 if (!cmount
->is_mounted())
1488 vector
<pair
<string
, string
> > loc
;
1489 int ret
= cmount
->get_client()->get_osd_crush_location(osd
, loc
);
1495 vector
<pair
<string
, string
> >::iterator it
;
1496 for (it
= loc
.begin(); it
!= loc
.end(); ++it
) {
1497 string
& type
= it
->first
;
1498 string
& name
= it
->second
;
1499 needed
+= type
.size() + name
.size() + 2;
1500 if (needed
<= len
) {
1502 strcpy(path
+ cur
, type
.c_str());
1503 cur
+= type
.size() + 1;
1505 strcpy(path
+ cur
, name
.c_str());
1506 cur
+= name
.size() + 1;
1519 extern "C" int ceph_get_osd_addr(struct ceph_mount_info
*cmount
, int osd
,
1520 struct sockaddr_storage
*addr
)
1522 if (!cmount
->is_mounted())
1528 entity_addr_t address
;
1529 int ret
= cmount
->get_client()->get_osd_addr(osd
, address
);
1533 *addr
= address
.get_sockaddr_storage();
1538 extern "C" int ceph_get_file_stripe_address(struct ceph_mount_info
*cmount
, int fh
,
1539 int64_t offset
, struct sockaddr_storage
*addr
, int naddr
)
1541 vector
<entity_addr_t
> address
;
1548 if (!cmount
->is_mounted())
1551 r
= cmount
->get_client()->get_file_stripe_address(fh
, offset
, address
);
1555 for (i
= 0; i
< (unsigned)naddr
&& i
< address
.size(); i
++)
1556 addr
[i
] = address
[i
].get_sockaddr_storage();
1558 /* naddr == 0: drop through and return actual size */
1559 if (naddr
&& (address
.size() > (unsigned)naddr
))
1562 return address
.size();
1565 extern "C" int ceph_localize_reads(struct ceph_mount_info
*cmount
, int val
)
1567 if (!cmount
->is_mounted())
1570 cmount
->get_client()->clear_filer_flags(CEPH_OSD_FLAG_LOCALIZE_READS
);
1572 cmount
->get_client()->set_filer_flags(CEPH_OSD_FLAG_LOCALIZE_READS
);
1576 extern "C" CephContext
*ceph_get_mount_context(struct ceph_mount_info
*cmount
)
1578 return cmount
->get_ceph_context();
1581 extern "C" int ceph_debug_get_fd_caps(struct ceph_mount_info
*cmount
, int fd
)
1583 if (!cmount
->is_mounted())
1585 return cmount
->get_client()->get_caps_issued(fd
);
1588 extern "C" int ceph_debug_get_file_caps(struct ceph_mount_info
*cmount
, const char *path
)
1590 if (!cmount
->is_mounted())
1592 return cmount
->get_client()->get_caps_issued(path
, cmount
->default_perms
);
1595 extern "C" int ceph_get_stripe_unit_granularity(struct ceph_mount_info
*cmount
)
1597 if (!cmount
->is_mounted())
1599 return CEPH_MIN_STRIPE_UNIT
;
1602 extern "C" int ceph_get_pool_id(struct ceph_mount_info
*cmount
, const char *pool_name
)
1604 if (!cmount
->is_mounted())
1607 if (!pool_name
|| !pool_name
[0])
1610 /* negative range reserved for errors */
1611 int64_t pool_id
= cmount
->get_client()->get_pool_id(pool_name
);
1612 if (pool_id
> 0x7fffffff)
1615 /* get_pool_id error codes fit in int */
1616 return (int)pool_id
;
1619 extern "C" int ceph_get_pool_replication(struct ceph_mount_info
*cmount
,
1622 if (!cmount
->is_mounted())
1624 return cmount
->get_client()->get_pool_replication(pool_id
);
1626 /* Low-level exports */
1628 extern "C" int ceph_ll_lookup_root(struct ceph_mount_info
*cmount
,
1631 *parent
= cmount
->get_client()->get_root();
1637 extern "C" struct Inode
*ceph_ll_get_inode(class ceph_mount_info
*cmount
,
1640 return (cmount
->get_client())->ll_get_inode(vino
);
1644 extern "C" int ceph_ll_lookup_vino(
1645 struct ceph_mount_info
*cmount
,
1649 return (cmount
->get_client())->ll_lookup_vino(vino
, cmount
->default_perms
, inode
);
1653 * Populates the client cache with the requested inode, and its
1656 extern "C" int ceph_ll_lookup_inode(
1657 struct ceph_mount_info
*cmount
,
1658 struct inodeno_t ino
,
1661 return (cmount
->get_client())->ll_lookup_inode(ino
, cmount
->default_perms
, inode
);
1664 extern "C" int ceph_ll_lookup(struct ceph_mount_info
*cmount
,
1665 Inode
*parent
, const char *name
, Inode
**out
,
1666 struct ceph_statx
*stx
, unsigned want
,
1667 unsigned flags
, const UserPerm
*perms
)
1669 if (flags
& ~CEPH_REQ_FLAG_MASK
)
1671 return (cmount
->get_client())->ll_lookupx(parent
, name
, out
, stx
, want
,
1675 extern "C" int ceph_ll_put(class ceph_mount_info
*cmount
, Inode
*in
)
1677 return (cmount
->get_client()->ll_put(in
));
1680 extern "C" int ceph_ll_forget(class ceph_mount_info
*cmount
, Inode
*in
,
1683 return (cmount
->get_client()->ll_forget(in
, count
));
1686 extern "C" int ceph_ll_walk(struct ceph_mount_info
*cmount
, const char* name
, Inode
**i
,
1687 struct ceph_statx
*stx
, unsigned int want
, unsigned int flags
,
1688 const UserPerm
*perms
)
1690 if (flags
& ~CEPH_REQ_FLAG_MASK
)
1692 return(cmount
->get_client()->ll_walk(name
, i
, stx
, want
, flags
, *perms
));
1695 extern "C" int ceph_ll_getattr(class ceph_mount_info
*cmount
,
1696 Inode
*in
, struct ceph_statx
*stx
,
1697 unsigned int want
, unsigned int flags
,
1698 const UserPerm
*perms
)
1700 if (flags
& ~CEPH_REQ_FLAG_MASK
)
1702 return (cmount
->get_client()->ll_getattrx(in
, stx
, want
, flags
, *perms
));
1705 extern "C" int ceph_ll_setattr(class ceph_mount_info
*cmount
,
1706 Inode
*in
, struct ceph_statx
*stx
,
1707 int mask
, const UserPerm
*perms
)
1709 return (cmount
->get_client()->ll_setattrx(in
, stx
, mask
, *perms
));
1712 extern "C" int ceph_ll_open(class ceph_mount_info
*cmount
, Inode
*in
,
1713 int flags
, Fh
**fh
, const UserPerm
*perms
)
1715 return (cmount
->get_client()->ll_open(in
, flags
, fh
, *perms
));
1718 extern "C" int ceph_ll_read(class ceph_mount_info
*cmount
, Fh
* filehandle
,
1719 int64_t off
, uint64_t len
, char* buf
)
1724 r
= cmount
->get_client()->ll_read(filehandle
, off
, len
, &bl
);
1727 bl
.begin().copy(bl
.length(), buf
);
1733 extern "C" int ceph_ll_read_block(class ceph_mount_info
*cmount
,
1734 Inode
*in
, uint64_t blockid
,
1735 char* buf
, uint64_t offset
,
1737 struct ceph_file_layout
* layout
)
1740 int r
= (cmount
->get_client()->ll_read_block(in
, blockid
, buf
, offset
,
1742 l
.to_legacy(layout
);
1746 extern "C" int ceph_ll_write_block(class ceph_mount_info
*cmount
,
1747 Inode
*in
, uint64_t blockid
,
1748 char *buf
, uint64_t offset
,
1750 struct ceph_file_layout
*layout
,
1751 uint64_t snapseq
, uint32_t sync
)
1754 int r
= (cmount
->get_client()->ll_write_block(in
, blockid
, buf
, offset
,
1755 length
, &l
, snapseq
, sync
));
1756 l
.to_legacy(layout
);
1760 extern "C" int ceph_ll_commit_blocks(class ceph_mount_info
*cmount
,
1761 Inode
*in
, uint64_t offset
,
1764 return (cmount
->get_client()->ll_commit_blocks(in
, offset
, range
));
1767 extern "C" int ceph_ll_fsync(class ceph_mount_info
*cmount
,
1768 Fh
*fh
, int syncdataonly
)
1770 return (cmount
->get_client()->ll_fsync(fh
, syncdataonly
));
1773 extern "C" int ceph_ll_sync_inode(class ceph_mount_info
*cmount
,
1774 Inode
*in
, int syncdataonly
)
1776 return (cmount
->get_client()->ll_sync_inode(in
, syncdataonly
));
1779 extern "C" int ceph_ll_fallocate(class ceph_mount_info
*cmount
, Fh
*fh
,
1780 int mode
, int64_t offset
, int64_t length
)
1782 return cmount
->get_client()->ll_fallocate(fh
, mode
, offset
, length
);
1785 extern "C" off_t
ceph_ll_lseek(class ceph_mount_info
*cmount
,
1786 Fh
*fh
, off_t offset
, int whence
)
1788 return (cmount
->get_client()->ll_lseek(fh
, offset
, whence
));
1791 extern "C" int ceph_ll_write(class ceph_mount_info
*cmount
,
1792 Fh
*fh
, int64_t off
, uint64_t len
,
1795 return (cmount
->get_client()->ll_write(fh
, off
, len
, data
));
1798 extern "C" int64_t ceph_ll_readv(class ceph_mount_info
*cmount
,
1799 struct Fh
*fh
, const struct iovec
*iov
,
1800 int iovcnt
, int64_t off
)
1802 return (cmount
->get_client()->ll_readv(fh
, iov
, iovcnt
, off
));
1805 extern "C" int64_t ceph_ll_writev(class ceph_mount_info
*cmount
,
1806 struct Fh
*fh
, const struct iovec
*iov
,
1807 int iovcnt
, int64_t off
)
1809 return (cmount
->get_client()->ll_writev(fh
, iov
, iovcnt
, off
));
1812 extern "C" int ceph_ll_close(class ceph_mount_info
*cmount
, Fh
* fh
)
1814 return (cmount
->get_client()->ll_release(fh
));
1817 extern "C" int ceph_ll_create(class ceph_mount_info
*cmount
,
1818 Inode
*parent
, const char *name
, mode_t mode
,
1819 int oflags
, Inode
**outp
, Fh
**fhp
,
1820 struct ceph_statx
*stx
, unsigned want
,
1821 unsigned lflags
, const UserPerm
*perms
)
1823 if (lflags
& ~CEPH_REQ_FLAG_MASK
)
1825 return (cmount
->get_client())->ll_createx(parent
, name
, mode
, oflags
, outp
,
1826 fhp
, stx
, want
, lflags
, *perms
);
1829 extern "C" int ceph_ll_mknod(class ceph_mount_info
*cmount
, Inode
*parent
,
1830 const char *name
, mode_t mode
, dev_t rdev
,
1831 Inode
**out
, struct ceph_statx
*stx
,
1832 unsigned want
, unsigned flags
,
1833 const UserPerm
*perms
)
1835 if (flags
& ~CEPH_REQ_FLAG_MASK
)
1837 return (cmount
->get_client())->ll_mknodx(parent
, name
, mode
, rdev
,
1838 out
, stx
, want
, flags
, *perms
);
1841 extern "C" int ceph_ll_mkdir(class ceph_mount_info
*cmount
, Inode
*parent
,
1842 const char *name
, mode_t mode
, Inode
**out
,
1843 struct ceph_statx
*stx
, unsigned want
,
1844 unsigned flags
, const UserPerm
*perms
)
1846 if (flags
& ~CEPH_REQ_FLAG_MASK
)
1848 return cmount
->get_client()->ll_mkdirx(parent
, name
, mode
, out
, stx
, want
,
1852 extern "C" int ceph_ll_link(class ceph_mount_info
*cmount
,
1853 Inode
*in
, Inode
*newparent
,
1854 const char *name
, const UserPerm
*perms
)
1856 return cmount
->get_client()->ll_link(in
, newparent
, name
, *perms
);
1859 extern "C" int ceph_ll_opendir(class ceph_mount_info
*cmount
,
1861 struct ceph_dir_result
**dirpp
,
1862 const UserPerm
*perms
)
1864 return (cmount
->get_client()->ll_opendir(in
, O_RDONLY
, (dir_result_t
**) dirpp
,
1868 extern "C" int ceph_ll_releasedir(class ceph_mount_info
*cmount
,
1869 ceph_dir_result
*dir
)
1871 return cmount
->get_client()->ll_releasedir(reinterpret_cast<dir_result_t
*>(dir
));
1874 extern "C" int ceph_ll_rename(class ceph_mount_info
*cmount
,
1875 Inode
*parent
, const char *name
,
1876 Inode
*newparent
, const char *newname
,
1877 const UserPerm
*perms
)
1879 return cmount
->get_client()->ll_rename(parent
, name
, newparent
,
1883 extern "C" int ceph_ll_unlink(class ceph_mount_info
*cmount
, Inode
*in
,
1884 const char *name
, const UserPerm
*perms
)
1886 return cmount
->get_client()->ll_unlink(in
, name
, *perms
);
1889 extern "C" int ceph_ll_statfs(class ceph_mount_info
*cmount
,
1890 Inode
*in
, struct statvfs
*stbuf
)
1892 return (cmount
->get_client()->ll_statfs(in
, stbuf
, cmount
->default_perms
));
1895 extern "C" int ceph_ll_readlink(class ceph_mount_info
*cmount
, Inode
*in
,
1896 char *buf
, size_t bufsiz
,
1897 const UserPerm
*perms
)
1899 return cmount
->get_client()->ll_readlink(in
, buf
, bufsiz
, *perms
);
1902 extern "C" int ceph_ll_symlink(class ceph_mount_info
*cmount
,
1903 Inode
*in
, const char *name
,
1904 const char *value
, Inode
**out
,
1905 struct ceph_statx
*stx
, unsigned want
,
1906 unsigned flags
, const UserPerm
*perms
)
1908 if (flags
& ~CEPH_REQ_FLAG_MASK
)
1910 return (cmount
->get_client()->ll_symlinkx(in
, name
, value
, out
, stx
, want
,
1914 extern "C" int ceph_ll_rmdir(class ceph_mount_info
*cmount
,
1915 Inode
*in
, const char *name
,
1916 const UserPerm
*perms
)
1918 return cmount
->get_client()->ll_rmdir(in
, name
, *perms
);
1921 extern "C" int ceph_ll_getxattr(class ceph_mount_info
*cmount
,
1922 Inode
*in
, const char *name
, void *value
,
1923 size_t size
, const UserPerm
*perms
)
1925 return (cmount
->get_client()->ll_getxattr(in
, name
, value
, size
, *perms
));
1928 extern "C" int ceph_ll_listxattr(struct ceph_mount_info
*cmount
,
1929 Inode
*in
, char *list
,
1930 size_t buf_size
, size_t *list_size
,
1931 const UserPerm
*perms
)
1933 int res
= cmount
->get_client()->ll_listxattr(in
, list
, buf_size
, *perms
);
1935 *list_size
= (size_t)res
;
1941 extern "C" int ceph_ll_setxattr(class ceph_mount_info
*cmount
,
1942 Inode
*in
, const char *name
,
1943 const void *value
, size_t size
,
1944 int flags
, const UserPerm
*perms
)
1946 return (cmount
->get_client()->ll_setxattr(in
, name
, value
, size
, flags
, *perms
));
1949 extern "C" int ceph_ll_removexattr(class ceph_mount_info
*cmount
,
1950 Inode
*in
, const char *name
,
1951 const UserPerm
*perms
)
1953 return (cmount
->get_client()->ll_removexattr(in
, name
, *perms
));
1956 extern "C" int ceph_ll_getlk(struct ceph_mount_info
*cmount
,
1957 Fh
*fh
, struct flock
*fl
, uint64_t owner
)
1959 return (cmount
->get_client()->ll_getlk(fh
, fl
, owner
));
1962 extern "C" int ceph_ll_setlk(struct ceph_mount_info
*cmount
,
1963 Fh
*fh
, struct flock
*fl
, uint64_t owner
,
1966 return (cmount
->get_client()->ll_setlk(fh
, fl
, owner
, sleep
));
1969 extern "C" int ceph_ll_lazyio(class ceph_mount_info
*cmount
,
1972 return (cmount
->get_client()->ll_lazyio(fh
, enable
));
1975 extern "C" int ceph_ll_delegation(struct ceph_mount_info
*cmount
, Fh
*fh
,
1976 unsigned cmd
, ceph_deleg_cb_t cb
, void *priv
)
1978 return (cmount
->get_client()->ll_delegation(fh
, cmd
, cb
, priv
));
1981 extern "C" uint32_t ceph_ll_stripe_unit(class ceph_mount_info
*cmount
,
1984 return (cmount
->get_client()->ll_stripe_unit(in
));
1987 extern "C" uint32_t ceph_ll_file_layout(class ceph_mount_info
*cmount
,
1989 struct ceph_file_layout
*layout
)
1992 int r
= (cmount
->get_client()->ll_file_layout(in
, &l
));
1993 l
.to_legacy(layout
);
1997 uint64_t ceph_ll_snap_seq(class ceph_mount_info
*cmount
, Inode
*in
)
1999 return (cmount
->get_client()->ll_snap_seq(in
));
2002 extern "C" int ceph_ll_get_stripe_osd(class ceph_mount_info
*cmount
,
2003 Inode
*in
, uint64_t blockno
,
2004 struct ceph_file_layout
* layout
)
2007 int r
= (cmount
->get_client()->ll_get_stripe_osd(in
, blockno
, &l
));
2008 l
.to_legacy(layout
);
2012 extern "C" int ceph_ll_num_osds(class ceph_mount_info
*cmount
)
2014 return (cmount
->get_client()->ll_num_osds());
2017 extern "C" int ceph_ll_osdaddr(class ceph_mount_info
*cmount
,
2018 int osd
, uint32_t *addr
)
2020 return (cmount
->get_client()->ll_osdaddr(osd
, addr
));
2023 extern "C" uint64_t ceph_ll_get_internal_offset(class ceph_mount_info
*cmount
,
2027 return (cmount
->get_client()->ll_get_internal_offset(in
, blockno
));
2030 extern "C" void ceph_buffer_free(char *buf
)
2037 extern "C" uint32_t ceph_get_cap_return_timeout(class ceph_mount_info
*cmount
)
2039 if (!cmount
->is_mounted())
2041 return cmount
->get_client()->mdsmap
->get_session_autoclose().sec();
2044 extern "C" int ceph_set_deleg_timeout(class ceph_mount_info
*cmount
, uint32_t timeout
)
2046 if (!cmount
->is_mounted())
2048 return cmount
->get_client()->set_deleg_timeout(timeout
);
2051 extern "C" void ceph_set_session_timeout(class ceph_mount_info
*cmount
, unsigned timeout
)
2053 cmount
->get_client()->set_session_timeout(timeout
);
2056 extern "C" void ceph_set_uuid(class ceph_mount_info
*cmount
, const char *uuid
)
2058 cmount
->get_client()->set_uuid(std::string(uuid
));
2061 extern "C" int ceph_start_reclaim(class ceph_mount_info
*cmount
,
2062 const char *uuid
, unsigned flags
)
2064 if (!cmount
->is_initialized()) {
2065 int ret
= cmount
->init();
2069 return cmount
->get_client()->start_reclaim(std::string(uuid
), flags
,
2070 cmount
->get_filesystem());
2073 extern "C" void ceph_finish_reclaim(class ceph_mount_info
*cmount
)
2075 cmount
->get_client()->finish_reclaim();
2078 extern "C" void ceph_ll_register_callbacks(class ceph_mount_info
*cmount
,
2079 struct ceph_client_callback_args
*args
)
2081 cmount
->get_client()->ll_register_callbacks(args
);
2086 extern "C" int ceph_get_snap_info(struct ceph_mount_info
*cmount
,
2087 const char *path
, struct snap_info
*snap_info
) {
2088 Client::SnapInfo info
;
2089 int r
= cmount
->get_client()->get_snap_info(path
, cmount
->default_perms
, &info
);
2095 auto nr_metadata
= info
.metadata
.size();
2097 snap_info
->id
= info
.id
.val
;
2098 snap_info
->nr_snap_metadata
= nr_metadata
;
2100 snap_info
->snap_metadata
= (struct snap_metadata
*)calloc(nr_metadata
, sizeof(struct snap_metadata
));
2101 if (!snap_info
->snap_metadata
) {
2105 // fill with key, value pairs
2106 for (auto &[key
, value
] : info
.metadata
) {
2107 // len(key) + '\0' + len(value) + '\0'
2108 char *kvp
= (char *)malloc(key
.size() + value
.size() + 2);
2113 char *_value
= kvp
+ key
.size() + 1;
2115 memcpy(_key
, key
.c_str(), key
.size());
2116 _key
[key
.size()] = '\0';
2117 memcpy(_value
, value
.c_str(), value
.size());
2118 _value
[value
.size()] = '\0';
2120 snap_info
->snap_metadata
[i
].key
= _key
;
2121 snap_info
->snap_metadata
[i
].value
= _value
;
2126 if (nr_metadata
&& i
!= nr_metadata
) {
2127 ceph_free_snap_info_buffer(snap_info
);
2134 extern "C" void ceph_free_snap_info_buffer(struct snap_info
*snap_info
) {
2135 for (size_t i
= 0; i
< snap_info
->nr_snap_metadata
; ++i
) {
2136 free((void *)snap_info
->snap_metadata
[i
].key
); // malloc'd memory is key+value composite
2138 free(snap_info
->snap_metadata
);