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 "include/stringify.h"
31 #include "messages/MMonMap.h"
32 #include "msg/Messenger.h"
33 #include "include/ceph_assert.h"
34 #include "mds/MDSMap.h"
36 #include "include/cephfs/libcephfs.h"
38 #define DEFAULT_UMASK 002
42 static mode_t
umask_cb(void *);
44 // Set things up this way so we don't start up threads until mount and
45 // kill them off when the last mount goes away, but are tolerant to
46 // multiple mounts of overlapping duration.
47 std::shared_ptr
<ceph::async::io_context_pool
> get_icp(CephContext
* cct
)
50 static std::weak_ptr
<ceph::async::io_context_pool
> icwp
;
53 std::unique_lock
l(m
);
55 auto icp
= icwp
.lock();
59 icp
= std::make_shared
<ceph::async::io_context_pool
>();
61 icp
->start(cct
->_conf
.get_val
<std::uint64_t>("client_asio_thread_count"));
66 struct ceph_mount_info
68 mode_t umask
= DEFAULT_UMASK
;
69 std::shared_ptr
<ceph::async::io_context_pool
> icp
;
71 explicit ceph_mount_info(CephContext
*cct_
)
94 catch (const std::exception
& e
) {
95 // we shouldn't get here, but if we do, we want to know about it.
96 lderr(cct
) << "ceph_mount_info::~ceph_mount_info: caught exception: "
108 if (!cct
->_log
->is_started()) {
114 MonClient
mc_bootstrap(cct
, icp
->get_io_context());
115 ret
= mc_bootstrap
.get_monmap_and_config();
120 common_init_finish(cct
);
123 monclient
= new MonClient(cct
, icp
->get_io_context());
124 ret
= -CEPHFS_ERROR_MON_MAP_BUILD
; //defined in libcephfs.h;
125 if (monclient
->build_initial_monmap() < 0)
129 messenger
= Messenger::create_client_messenger(cct
, "client");
132 ret
= -CEPHFS_ERROR_NEW_CLIENT
; //defined in libcephfs.h;
133 client
= new StandaloneClient(messenger
, monclient
, icp
->get_io_context());
137 ret
= -CEPHFS_ERROR_MESSENGER_START
; //defined in libcephfs.h;
138 if (messenger
->start() != 0)
141 ret
= client
->init();
146 ceph_client_callback_args args
= {};
148 args
.umask_cb
= umask_cb
;
149 client
->ll_register_callbacks(&args
);
152 default_perms
= Client::pick_my_perms(cct
);
161 int select_filesystem(const std::string
&fs_name_
)
171 const std::string
& get_filesystem(void)
176 int mount(const std::string
&mount_root
, const UserPerm
& perms
)
190 ret
= client
->mount(mount_root
, perms
, false, fs_name
);
210 client
->abort_conn();
227 messenger
->shutdown();
243 bool is_initialized() const
253 mode_t
set_umask(mode_t umask
)
259 std::string
getaddrs()
261 CachedStackStringStream cos
;
262 *cos
<< messenger
->get_myaddrs();
263 return std::string(cos
->strv());
266 int conf_read_file(const char *path_list
)
268 int ret
= cct
->_conf
.parse_config_files(path_list
, nullptr, 0);
271 cct
->_conf
.apply_changes(nullptr);
272 cct
->_conf
.complain_about_parse_error(cct
);
276 int conf_parse_argv(int argc
, const char **argv
)
278 auto args
= argv_to_vec(argc
, argv
);
279 int ret
= cct
->_conf
.parse_argv(args
);
282 cct
->_conf
.apply_changes(nullptr);
286 int conf_parse_env(const char *name
)
288 auto& conf
= cct
->_conf
;
289 conf
.parse_env(cct
->get_module_type(), name
);
290 conf
.apply_changes(nullptr);
294 int conf_set(const char *option
, const char *value
)
296 int ret
= cct
->_conf
.set_val(option
, value
);
299 cct
->_conf
.apply_changes(nullptr);
303 int conf_get(const char *option
, char *buf
, size_t len
)
306 return cct
->_conf
.get_val(option
, &tmp
, len
);
314 const char *get_cwd(const UserPerm
& perms
)
316 client
->getcwd(cwd
, perms
);
320 int chdir(const char *to
, const UserPerm
& perms
)
322 return client
->chdir(to
, cwd
, perms
);
325 CephContext
*get_ceph_context() const {
329 UserPerm default_perms
;
333 StandaloneClient
*client
;
334 MonClient
*monclient
;
335 Messenger
*messenger
;
341 static mode_t
umask_cb(void *handle
)
343 return ((struct ceph_mount_info
*)handle
)->umask
;
346 static void do_out_buffer(bufferlist
& outbl
, char **outbuf
, size_t *outbuflen
)
349 if (outbl
.length() > 0) {
350 *outbuf
= (char *)malloc(outbl
.length());
351 memcpy(*outbuf
, outbl
.c_str(), outbl
.length());
357 *outbuflen
= outbl
.length();
360 static void do_out_buffer(string
& outbl
, char **outbuf
, size_t *outbuflen
)
363 if (outbl
.length() > 0) {
364 *outbuf
= (char *)malloc(outbl
.length());
365 memcpy(*outbuf
, outbl
.c_str(), outbl
.length());
371 *outbuflen
= outbl
.length();
374 extern "C" UserPerm
*ceph_userperm_new(uid_t uid
, gid_t gid
, int ngids
,
377 return new (std::nothrow
) UserPerm(uid
, gid
, ngids
, gidlist
);
380 extern "C" void ceph_userperm_destroy(UserPerm
*perm
)
385 extern "C" const char *ceph_version(int *pmajor
, int *pminor
, int *ppatch
)
387 int major
, minor
, patch
;
388 const char *v
= ceph_version_to_str();
390 int n
= sscanf(v
, "%d.%d.%d", &major
, &minor
, &patch
);
392 *pmajor
= (n
>= 1) ? major
: 0;
394 *pminor
= (n
>= 2) ? minor
: 0;
396 *ppatch
= (n
>= 3) ? patch
: 0;
397 return PROJECT_VERSION
;
400 extern "C" int ceph_create_with_context(struct ceph_mount_info
**cmount
, CephContext
*cct
)
402 *cmount
= new struct ceph_mount_info(cct
);
406 extern "C" int ceph_create_from_rados(struct ceph_mount_info
**cmount
,
409 auto rados
= (librados::RadosClient
*) cluster
;
410 auto cct
= rados
->cct
;
411 return ceph_create_with_context(cmount
, cct
);
414 extern "C" int ceph_create(struct ceph_mount_info
**cmount
, const char * const id
)
416 CephInitParameters
iparams(CEPH_ENTITY_TYPE_CLIENT
);
418 iparams
.name
.set(CEPH_ENTITY_TYPE_CLIENT
, id
);
421 CephContext
*cct
= common_preinit(iparams
, CODE_ENVIRONMENT_LIBRARY
, 0);
422 cct
->_conf
.parse_env(cct
->get_module_type()); // environment variables coverride
423 cct
->_conf
.apply_changes(nullptr);
424 int ret
= ceph_create_with_context(cmount
, cct
);
430 extern "C" int ceph_unmount(struct ceph_mount_info
*cmount
)
432 return cmount
->unmount();
435 extern "C" int ceph_abort_conn(struct ceph_mount_info
*cmount
)
437 return cmount
->abort_conn();
440 extern "C" int ceph_release(struct ceph_mount_info
*cmount
)
442 if (cmount
->is_mounted())
449 extern "C" void ceph_shutdown(struct ceph_mount_info
*cmount
)
456 extern "C" uint64_t ceph_get_instance_id(struct ceph_mount_info
*cmount
)
458 if (cmount
->is_initialized())
459 return cmount
->get_client()->get_nodeid().v
;
463 extern "C" int ceph_getaddrs(struct ceph_mount_info
*cmount
, char** addrs
)
465 if (!cmount
->is_initialized())
467 auto s
= cmount
->getaddrs();
468 *addrs
= strdup(s
.c_str());
472 extern "C" int ceph_conf_read_file(struct ceph_mount_info
*cmount
, const char *path
)
474 return cmount
->conf_read_file(path
);
477 extern "C" mode_t
ceph_umask(struct ceph_mount_info
*cmount
, mode_t mode
)
479 return cmount
->set_umask(mode
);
482 extern "C" int ceph_conf_parse_argv(struct ceph_mount_info
*cmount
, int argc
,
485 return cmount
->conf_parse_argv(argc
, argv
);
488 extern "C" int ceph_conf_parse_env(struct ceph_mount_info
*cmount
, const char *name
)
490 return cmount
->conf_parse_env(name
);
493 extern "C" int ceph_conf_set(struct ceph_mount_info
*cmount
, const char *option
,
496 return cmount
->conf_set(option
, value
);
499 extern "C" int ceph_conf_get(struct ceph_mount_info
*cmount
, const char *option
,
500 char *buf
, size_t len
)
505 return cmount
->conf_get(option
, buf
, len
);
508 extern "C" int ceph_set_mount_timeout(struct ceph_mount_info
*cmount
, uint32_t timeout
) {
509 if (cmount
->is_mounted()) {
513 auto timeout_str
= stringify(timeout
);
514 return ceph_conf_set(cmount
, "client_mount_timeout", timeout_str
.c_str());
517 extern "C" int ceph_mds_command(struct ceph_mount_info
*cmount
,
518 const char *mds_spec
,
521 const char *inbuf
, size_t inbuflen
,
522 char **outbuf
, size_t *outbuflen
,
523 char **outsbuf
, size_t *outsbuflen
)
527 std::vector
<string
> cmdv
;
530 if (!cmount
->is_initialized()) {
535 for (size_t i
= 0; i
< cmdlen
; ++i
) {
536 cmdv
.push_back(cmd
[i
]);
538 inbl
.append(inbuf
, inbuflen
);
540 // Issue remote command
542 int r
= cmount
->get_client()->mds_command(
552 // Wait for completion
556 do_out_buffer(outbl
, outbuf
, outbuflen
);
557 do_out_buffer(outs
, outsbuf
, outsbuflen
);
563 extern "C" int ceph_init(struct ceph_mount_info
*cmount
)
565 return cmount
->init();
568 extern "C" int ceph_select_filesystem(struct ceph_mount_info
*cmount
,
571 if (fs_name
== nullptr) {
575 return cmount
->select_filesystem(fs_name
);
578 extern "C" int ceph_mount(struct ceph_mount_info
*cmount
, const char *root
)
580 std::string mount_root
;
583 return cmount
->mount(mount_root
, cmount
->default_perms
);
586 extern "C" int ceph_is_mounted(struct ceph_mount_info
*cmount
)
588 return cmount
->is_mounted() ? 1 : 0;
591 extern "C" struct UserPerm
*ceph_mount_perms(struct ceph_mount_info
*cmount
)
593 return &cmount
->default_perms
;
596 extern "C" int64_t ceph_get_fs_cid(struct ceph_mount_info
*cmount
)
598 if (!cmount
->is_mounted())
600 return cmount
->get_client()->get_fs_cid();
603 extern "C" int ceph_mount_perms_set(struct ceph_mount_info
*cmount
,
604 struct UserPerm
*perms
)
606 if (cmount
->is_mounted())
608 cmount
->default_perms
= *perms
;
612 extern "C" int ceph_statfs(struct ceph_mount_info
*cmount
, const char *path
,
613 struct statvfs
*stbuf
)
615 if (!cmount
->is_mounted())
617 return cmount
->get_client()->statfs(path
, stbuf
, cmount
->default_perms
);
620 extern "C" int ceph_get_local_osd(struct ceph_mount_info
*cmount
)
622 if (!cmount
->is_mounted())
624 return cmount
->get_client()->get_local_osd();
627 extern "C" const char* ceph_getcwd(struct ceph_mount_info
*cmount
)
629 return cmount
->get_cwd(cmount
->default_perms
);
632 extern "C" int ceph_chdir (struct ceph_mount_info
*cmount
, const char *s
)
634 if (!cmount
->is_mounted())
636 return cmount
->chdir(s
, cmount
->default_perms
);
639 extern "C" int ceph_opendir(struct ceph_mount_info
*cmount
,
640 const char *name
, struct ceph_dir_result
**dirpp
)
642 if (!cmount
->is_mounted())
644 return cmount
->get_client()->opendir(name
, (dir_result_t
**)dirpp
, cmount
->default_perms
);
647 extern "C" int ceph_fdopendir(struct ceph_mount_info
*cmount
, int dirfd
,
648 struct ceph_dir_result
**dirpp
)
650 if (!cmount
->is_mounted())
652 return cmount
->get_client()->fdopendir(dirfd
, (dir_result_t
**)dirpp
, cmount
->default_perms
);
655 extern "C" int ceph_closedir(struct ceph_mount_info
*cmount
, struct ceph_dir_result
*dirp
)
657 if (!cmount
->is_mounted())
659 return cmount
->get_client()->closedir(reinterpret_cast<dir_result_t
*>(dirp
));
662 extern "C" struct dirent
* ceph_readdir(struct ceph_mount_info
*cmount
, struct ceph_dir_result
*dirp
)
664 if (!cmount
->is_mounted()) {
665 /* Client::readdir also sets errno to signal errors. */
669 return cmount
->get_client()->readdir(reinterpret_cast<dir_result_t
*>(dirp
));
672 extern "C" int ceph_readdir_r(struct ceph_mount_info
*cmount
, struct ceph_dir_result
*dirp
, struct dirent
*de
)
674 if (!cmount
->is_mounted())
676 return cmount
->get_client()->readdir_r(reinterpret_cast<dir_result_t
*>(dirp
), de
);
679 extern "C" int ceph_readdirplus_r(struct ceph_mount_info
*cmount
, struct ceph_dir_result
*dirp
,
680 struct dirent
*de
, struct ceph_statx
*stx
, unsigned want
,
681 unsigned flags
, struct Inode
**out
)
683 if (!cmount
->is_mounted())
685 if (flags
& ~CEPH_REQ_FLAG_MASK
)
687 return cmount
->get_client()->readdirplus_r(reinterpret_cast<dir_result_t
*>(dirp
), de
, stx
, want
, flags
, out
);
690 extern "C" int ceph_getdents(struct ceph_mount_info
*cmount
, struct ceph_dir_result
*dirp
,
691 char *buf
, int buflen
)
693 if (!cmount
->is_mounted())
695 return cmount
->get_client()->getdents(reinterpret_cast<dir_result_t
*>(dirp
), buf
, buflen
);
698 extern "C" int ceph_getdnames(struct ceph_mount_info
*cmount
, struct ceph_dir_result
*dirp
,
699 char *buf
, int buflen
)
701 if (!cmount
->is_mounted())
703 return cmount
->get_client()->getdnames(reinterpret_cast<dir_result_t
*>(dirp
), buf
, buflen
);
706 extern "C" void ceph_rewinddir(struct ceph_mount_info
*cmount
, struct ceph_dir_result
*dirp
)
708 if (!cmount
->is_mounted())
710 cmount
->get_client()->rewinddir(reinterpret_cast<dir_result_t
*>(dirp
));
713 extern "C" int64_t ceph_telldir(struct ceph_mount_info
*cmount
, struct ceph_dir_result
*dirp
)
715 if (!cmount
->is_mounted())
717 return cmount
->get_client()->telldir(reinterpret_cast<dir_result_t
*>(dirp
));
720 extern "C" void ceph_seekdir(struct ceph_mount_info
*cmount
, struct ceph_dir_result
*dirp
, int64_t offset
)
722 if (!cmount
->is_mounted())
724 cmount
->get_client()->seekdir(reinterpret_cast<dir_result_t
*>(dirp
), offset
);
727 extern "C" int ceph_may_delete(struct ceph_mount_info
*cmount
, const char *path
)
729 if (!cmount
->is_mounted())
731 return cmount
->get_client()->may_delete(path
, cmount
->default_perms
);
734 extern "C" int ceph_link (struct ceph_mount_info
*cmount
, const char *existing
,
737 if (!cmount
->is_mounted())
739 return cmount
->get_client()->link(existing
, newname
, cmount
->default_perms
);
742 extern "C" int ceph_unlink(struct ceph_mount_info
*cmount
, const char *path
)
744 if (!cmount
->is_mounted())
746 return cmount
->get_client()->unlink(path
, cmount
->default_perms
);
749 extern "C" int ceph_unlinkat(struct ceph_mount_info
*cmount
, int dirfd
, const char *relpath
, int flags
)
751 if (!cmount
->is_mounted())
753 return cmount
->get_client()->unlinkat(dirfd
, relpath
, flags
, cmount
->default_perms
);
756 extern "C" int ceph_rename(struct ceph_mount_info
*cmount
, const char *from
,
759 if (!cmount
->is_mounted())
761 return cmount
->get_client()->rename(from
, to
, cmount
->default_perms
);
765 extern "C" int ceph_mkdir(struct ceph_mount_info
*cmount
, const char *path
, mode_t mode
)
767 if (!cmount
->is_mounted())
769 return cmount
->get_client()->mkdir(path
, mode
, cmount
->default_perms
);
772 extern "C" int ceph_mkdirat(struct ceph_mount_info
*cmount
, int dirfd
, const char *relpath
,
775 if (!cmount
->is_mounted())
777 return cmount
->get_client()->mkdirat(dirfd
, relpath
, mode
, cmount
->default_perms
);
780 extern "C" int ceph_mksnap(struct ceph_mount_info
*cmount
, const char *path
, const char *name
,
781 mode_t mode
, struct snap_metadata
*snap_metadata
, size_t nr_snap_metadata
)
783 if (!cmount
->is_mounted())
786 std::map
<std::string
, std::string
> metadata
;
787 while (i
< nr_snap_metadata
) {
788 metadata
.emplace(snap_metadata
[i
].key
, snap_metadata
[i
].value
);
791 return cmount
->get_client()->mksnap(path
, name
, cmount
->default_perms
, mode
, metadata
);
794 extern "C" int ceph_rmsnap(struct ceph_mount_info
*cmount
, const char *path
, const char *name
)
796 if (!cmount
->is_mounted())
798 return cmount
->get_client()->rmsnap(path
, name
, cmount
->default_perms
, true);
801 extern "C" int ceph_mkdirs(struct ceph_mount_info
*cmount
, const char *path
, mode_t mode
)
803 if (!cmount
->is_mounted())
805 return cmount
->get_client()->mkdirs(path
, mode
, cmount
->default_perms
);
808 extern "C" int ceph_rmdir(struct ceph_mount_info
*cmount
, const char *path
)
810 if (!cmount
->is_mounted())
812 return cmount
->get_client()->rmdir(path
, cmount
->default_perms
);
816 extern "C" int ceph_readlink(struct ceph_mount_info
*cmount
, const char *path
,
817 char *buf
, int64_t size
)
819 if (!cmount
->is_mounted())
821 return cmount
->get_client()->readlink(path
, buf
, size
, cmount
->default_perms
);
824 extern "C" int ceph_readlinkat(struct ceph_mount_info
*cmount
, int dirfd
,
825 const char *relpath
, char *buf
, int64_t size
)
827 if (!cmount
->is_mounted())
829 return cmount
->get_client()->readlinkat(dirfd
, relpath
, buf
, size
, cmount
->default_perms
);
832 extern "C" int ceph_symlink(struct ceph_mount_info
*cmount
, const char *existing
,
835 if (!cmount
->is_mounted())
837 return cmount
->get_client()->symlink(existing
, newname
, cmount
->default_perms
);
840 extern "C" int ceph_symlinkat(struct ceph_mount_info
*cmount
, const char *existing
, int dirfd
,
843 if (!cmount
->is_mounted())
845 return cmount
->get_client()->symlinkat(existing
, dirfd
, newname
, cmount
->default_perms
);
848 extern "C" int ceph_fstatx(struct ceph_mount_info
*cmount
, int fd
, struct ceph_statx
*stx
,
849 unsigned int want
, unsigned int flags
)
851 if (!cmount
->is_mounted())
853 if (flags
& ~CEPH_REQ_FLAG_MASK
)
855 return cmount
->get_client()->fstatx(fd
, stx
, cmount
->default_perms
,
859 extern "C" int ceph_statxat(struct ceph_mount_info
*cmount
, int dirfd
, const char *relpath
,
860 struct ceph_statx
*stx
, unsigned int want
, unsigned int flags
)
862 if (!cmount
->is_mounted())
864 if (flags
& ~CEPH_REQ_FLAG_MASK
)
866 return cmount
->get_client()->statxat(dirfd
, relpath
, stx
, cmount
->default_perms
,
870 extern "C" int ceph_statx(struct ceph_mount_info
*cmount
, const char *path
,
871 struct ceph_statx
*stx
, unsigned int want
, unsigned int flags
)
873 if (!cmount
->is_mounted())
875 if (flags
& ~CEPH_REQ_FLAG_MASK
)
877 return cmount
->get_client()->statx(path
, stx
, cmount
->default_perms
,
881 extern "C" int ceph_fsetattrx(struct ceph_mount_info
*cmount
, int fd
,
882 struct ceph_statx
*stx
, int mask
)
884 if (!cmount
->is_mounted())
886 return cmount
->get_client()->fsetattrx(fd
, stx
, mask
, cmount
->default_perms
);
889 extern "C" int ceph_setattrx(struct ceph_mount_info
*cmount
, const char *relpath
,
890 struct ceph_statx
*stx
, int mask
, int flags
)
892 if (!cmount
->is_mounted())
894 if (flags
& ~CEPH_REQ_FLAG_MASK
)
896 return cmount
->get_client()->setattrx(relpath
, stx
, mask
,
897 cmount
->default_perms
, flags
);
900 // *xattr() calls supporting samba/vfs
901 extern "C" int ceph_getxattr(struct ceph_mount_info
*cmount
, const char *path
, const char *name
, void *value
, size_t size
)
903 if (!cmount
->is_mounted())
906 return cmount
->get_client()->getxattr(path
, name
, value
, size
, cmount
->default_perms
);
909 extern "C" int ceph_lgetxattr(struct ceph_mount_info
*cmount
, const char *path
, const char *name
, void *value
, size_t size
)
911 if (!cmount
->is_mounted())
913 return cmount
->get_client()->lgetxattr(path
, name
, value
, size
, cmount
->default_perms
);
916 extern "C" int ceph_fgetxattr(struct ceph_mount_info
*cmount
, int fd
, const char *name
, void *value
, size_t size
)
918 if (!cmount
->is_mounted())
920 return cmount
->get_client()->fgetxattr(fd
, name
, value
, size
, cmount
->default_perms
);
924 extern "C" int ceph_listxattr(struct ceph_mount_info
*cmount
, const char *path
, char *list
, size_t size
)
926 if (!cmount
->is_mounted())
928 return cmount
->get_client()->listxattr(path
, list
, size
, cmount
->default_perms
);
931 extern "C" int ceph_llistxattr(struct ceph_mount_info
*cmount
, const char *path
, char *list
, size_t size
)
933 if (!cmount
->is_mounted())
935 return cmount
->get_client()->llistxattr(path
, list
, size
, cmount
->default_perms
);
938 extern "C" int ceph_flistxattr(struct ceph_mount_info
*cmount
, int fd
, char *list
, size_t size
)
940 if (!cmount
->is_mounted())
942 return cmount
->get_client()->flistxattr(fd
, list
, size
, cmount
->default_perms
);
945 extern "C" int ceph_removexattr(struct ceph_mount_info
*cmount
, const char *path
, const char *name
)
947 if (!cmount
->is_mounted())
949 return cmount
->get_client()->removexattr(path
, name
, cmount
->default_perms
);
952 extern "C" int ceph_lremovexattr(struct ceph_mount_info
*cmount
, const char *path
, const char *name
)
954 if (!cmount
->is_mounted())
956 return cmount
->get_client()->lremovexattr(path
, name
, cmount
->default_perms
);
959 extern "C" int ceph_fremovexattr(struct ceph_mount_info
*cmount
, int fd
, const char *name
)
961 if (!cmount
->is_mounted())
963 return cmount
->get_client()->fremovexattr(fd
, name
, cmount
->default_perms
);
966 extern "C" int ceph_setxattr(struct ceph_mount_info
*cmount
, const char *path
, const char *name
, const void *value
, size_t size
, int flags
)
968 if (!cmount
->is_mounted())
970 return cmount
->get_client()->setxattr(path
, name
, value
, size
, flags
, cmount
->default_perms
);
973 extern "C" int ceph_lsetxattr(struct ceph_mount_info
*cmount
, const char *path
, const char *name
, const void *value
, size_t size
, int flags
)
975 if (!cmount
->is_mounted())
977 return cmount
->get_client()->lsetxattr(path
, name
, value
, size
, flags
, cmount
->default_perms
);
980 extern "C" int ceph_fsetxattr(struct ceph_mount_info
*cmount
, int fd
, const char *name
, const void *value
, size_t size
, int flags
)
982 if (!cmount
->is_mounted())
984 return cmount
->get_client()->fsetxattr(fd
, name
, value
, size
, flags
, cmount
->default_perms
);
986 /* end xattr support */
988 extern "C" int ceph_stat(struct ceph_mount_info
*cmount
, const char *path
, struct stat
*stbuf
)
990 if (!cmount
->is_mounted())
992 return cmount
->get_client()->stat(path
, stbuf
, cmount
->default_perms
);
995 extern "C" int ceph_fstat(struct ceph_mount_info
*cmount
, int fd
, struct stat
*stbuf
)
997 if (!cmount
->is_mounted())
999 return cmount
->get_client()->fstat(fd
, stbuf
, cmount
->default_perms
);
1002 extern int ceph_lstat(struct ceph_mount_info
*cmount
, const char *path
, struct stat
*stbuf
)
1004 if (!cmount
->is_mounted())
1006 return cmount
->get_client()->lstat(path
, stbuf
, cmount
->default_perms
);
1009 extern "C" int ceph_chmod(struct ceph_mount_info
*cmount
, const char *path
, mode_t mode
)
1011 if (!cmount
->is_mounted())
1013 return cmount
->get_client()->chmod(path
, mode
, cmount
->default_perms
);
1015 extern "C" int ceph_lchmod(struct ceph_mount_info
*cmount
, const char *path
, mode_t mode
)
1017 if (!cmount
->is_mounted())
1019 return cmount
->get_client()->lchmod(path
, mode
, cmount
->default_perms
);
1021 extern "C" int ceph_fchmod(struct ceph_mount_info
*cmount
, int fd
, mode_t mode
)
1023 if (!cmount
->is_mounted())
1025 return cmount
->get_client()->fchmod(fd
, mode
, cmount
->default_perms
);
1028 extern "C" int ceph_chmodat(struct ceph_mount_info
*cmount
, int dirfd
, const char *relpath
,
1029 mode_t mode
, int flags
) {
1030 if (!cmount
->is_mounted())
1032 return cmount
->get_client()->chmodat(dirfd
, relpath
, mode
, flags
, cmount
->default_perms
);
1035 extern "C" int ceph_chown(struct ceph_mount_info
*cmount
, const char *path
,
1038 if (!cmount
->is_mounted())
1040 return cmount
->get_client()->chown(path
, uid
, gid
, cmount
->default_perms
);
1042 extern "C" int ceph_fchown(struct ceph_mount_info
*cmount
, int fd
,
1045 if (!cmount
->is_mounted())
1047 return cmount
->get_client()->fchown(fd
, uid
, gid
, cmount
->default_perms
);
1049 extern "C" int ceph_lchown(struct ceph_mount_info
*cmount
, const char *path
,
1052 if (!cmount
->is_mounted())
1054 return cmount
->get_client()->lchown(path
, uid
, gid
, cmount
->default_perms
);
1057 extern "C" int ceph_chownat(struct ceph_mount_info
*cmount
, int dirfd
, const char *relpath
,
1058 uid_t uid
, gid_t gid
, int flags
) {
1059 if (!cmount
->is_mounted())
1061 return cmount
->get_client()->chownat(dirfd
, relpath
, uid
, gid
, flags
, cmount
->default_perms
);
1064 extern "C" int ceph_utime(struct ceph_mount_info
*cmount
, const char *path
,
1065 struct utimbuf
*buf
)
1067 if (!cmount
->is_mounted())
1069 return cmount
->get_client()->utime(path
, buf
, cmount
->default_perms
);
1072 extern "C" int ceph_futime(struct ceph_mount_info
*cmount
, int fd
,
1073 struct utimbuf
*buf
)
1075 if (!cmount
->is_mounted())
1077 return cmount
->get_client()->futime(fd
, buf
, cmount
->default_perms
);
1080 extern "C" int ceph_utimes(struct ceph_mount_info
*cmount
, const char *path
,
1081 struct timeval times
[2])
1083 if (!cmount
->is_mounted())
1085 return cmount
->get_client()->utimes(path
, times
, cmount
->default_perms
);
1088 extern "C" int ceph_lutimes(struct ceph_mount_info
*cmount
, const char *path
,
1089 struct timeval times
[2])
1091 if (!cmount
->is_mounted())
1093 return cmount
->get_client()->lutimes(path
, times
, cmount
->default_perms
);
1096 extern "C" int ceph_futimes(struct ceph_mount_info
*cmount
, int fd
,
1097 struct timeval times
[2])
1099 if (!cmount
->is_mounted())
1101 return cmount
->get_client()->futimes(fd
, times
, cmount
->default_perms
);
1104 extern "C" int ceph_futimens(struct ceph_mount_info
*cmount
, int fd
,
1105 struct timespec times
[2])
1107 if (!cmount
->is_mounted())
1109 return cmount
->get_client()->futimens(fd
, times
, cmount
->default_perms
);
1112 extern "C" int ceph_utimensat(struct ceph_mount_info
*cmount
, int dirfd
, const char *relpath
,
1113 struct timespec times
[2], int flags
) {
1114 if (!cmount
->is_mounted())
1116 return cmount
->get_client()->utimensat(dirfd
, relpath
, times
, flags
, cmount
->default_perms
);
1119 extern "C" int ceph_flock(struct ceph_mount_info
*cmount
, int fd
, int operation
,
1122 if (!cmount
->is_mounted())
1124 return cmount
->get_client()->flock(fd
, operation
, owner
);
1127 extern "C" int ceph_truncate(struct ceph_mount_info
*cmount
, const char *path
,
1130 if (!cmount
->is_mounted())
1132 return cmount
->get_client()->truncate(path
, size
, cmount
->default_perms
);
1136 extern "C" int ceph_mknod(struct ceph_mount_info
*cmount
, const char *path
,
1137 mode_t mode
, dev_t rdev
)
1139 if (!cmount
->is_mounted())
1141 return cmount
->get_client()->mknod(path
, mode
, cmount
->default_perms
, rdev
);
1144 extern "C" int ceph_open(struct ceph_mount_info
*cmount
, const char *path
,
1145 int flags
, mode_t mode
)
1147 if (!cmount
->is_mounted())
1149 return cmount
->get_client()->open(path
, flags
, cmount
->default_perms
, mode
);
1152 extern "C" int ceph_openat(struct ceph_mount_info
*cmount
, int dirfd
, const char *relpath
,
1153 int flags
, mode_t mode
)
1155 if (!cmount
->is_mounted())
1157 return cmount
->get_client()->openat(dirfd
, relpath
, flags
, cmount
->default_perms
, mode
);
1160 extern "C" int ceph_open_layout(struct ceph_mount_info
*cmount
, const char *path
, int flags
,
1161 mode_t mode
, int stripe_unit
, int stripe_count
, int object_size
, const char *data_pool
)
1163 if (!cmount
->is_mounted())
1165 return cmount
->get_client()->open(path
, flags
, cmount
->default_perms
, mode
,
1166 stripe_unit
, stripe_count
,
1167 object_size
, data_pool
);
1170 extern "C" int ceph_close(struct ceph_mount_info
*cmount
, int fd
)
1172 if (!cmount
->is_mounted())
1174 return cmount
->get_client()->close(fd
);
1177 extern "C" int64_t ceph_lseek(struct ceph_mount_info
*cmount
, int fd
,
1178 int64_t offset
, int whence
)
1180 if (!cmount
->is_mounted())
1182 return cmount
->get_client()->lseek(fd
, offset
, whence
);
1185 extern "C" int ceph_read(struct ceph_mount_info
*cmount
, int fd
, char *buf
,
1186 int64_t size
, int64_t offset
)
1188 if (!cmount
->is_mounted())
1190 return cmount
->get_client()->read(fd
, buf
, size
, offset
);
1193 extern "C" int ceph_preadv(struct ceph_mount_info
*cmount
, int fd
,
1194 const struct iovec
*iov
, int iovcnt
, int64_t offset
)
1196 if (!cmount
->is_mounted())
1198 return cmount
->get_client()->preadv(fd
, iov
, iovcnt
, offset
);
1201 extern "C" int ceph_write(struct ceph_mount_info
*cmount
, int fd
, const char *buf
,
1202 int64_t size
, int64_t offset
)
1204 if (!cmount
->is_mounted())
1206 return cmount
->get_client()->write(fd
, buf
, size
, offset
);
1209 extern "C" int ceph_pwritev(struct ceph_mount_info
*cmount
, int fd
,
1210 const struct iovec
*iov
, int iovcnt
, int64_t offset
)
1212 if (!cmount
->is_mounted())
1214 return cmount
->get_client()->pwritev(fd
, iov
, iovcnt
, offset
);
1217 extern "C" int ceph_ftruncate(struct ceph_mount_info
*cmount
, int fd
, int64_t size
)
1219 if (!cmount
->is_mounted())
1221 return cmount
->get_client()->ftruncate(fd
, size
, cmount
->default_perms
);
1224 extern "C" int ceph_fsync(struct ceph_mount_info
*cmount
, int fd
, int syncdataonly
)
1226 if (!cmount
->is_mounted())
1228 return cmount
->get_client()->fsync(fd
, syncdataonly
);
1231 extern "C" int ceph_fallocate(struct ceph_mount_info
*cmount
, int fd
, int mode
,
1232 int64_t offset
, int64_t length
)
1234 if (!cmount
->is_mounted())
1236 return cmount
->get_client()->fallocate(fd
, mode
, offset
, length
);
1239 extern "C" int ceph_lazyio(class ceph_mount_info
*cmount
,
1242 return (cmount
->get_client()->lazyio(fd
, enable
));
1245 extern "C" int ceph_lazyio_propagate(class ceph_mount_info
*cmount
,
1246 int fd
, int64_t offset
, size_t count
)
1248 if (!cmount
->is_mounted())
1250 return (cmount
->get_client()->lazyio_propagate(fd
, offset
, count
));
1253 extern "C" int ceph_lazyio_synchronize(class ceph_mount_info
*cmount
,
1254 int fd
, int64_t offset
, size_t count
)
1256 if (!cmount
->is_mounted())
1258 return (cmount
->get_client()->lazyio_synchronize(fd
, offset
, count
));
1262 extern "C" int ceph_sync_fs(struct ceph_mount_info
*cmount
)
1264 if (!cmount
->is_mounted())
1266 return cmount
->get_client()->sync_fs();
1269 extern "C" int ceph_get_file_stripe_unit(struct ceph_mount_info
*cmount
, int fh
)
1274 if (!cmount
->is_mounted())
1276 r
= cmount
->get_client()->fdescribe_layout(fh
, &l
);
1279 return l
.stripe_unit
;
1282 extern "C" int ceph_get_path_stripe_unit(struct ceph_mount_info
*cmount
, const char *path
)
1287 if (!cmount
->is_mounted())
1289 r
= cmount
->get_client()->describe_layout(path
, &l
, cmount
->default_perms
);
1292 return l
.stripe_unit
;
1295 extern "C" int ceph_get_file_stripe_count(struct ceph_mount_info
*cmount
, int fh
)
1300 if (!cmount
->is_mounted())
1302 r
= cmount
->get_client()->fdescribe_layout(fh
, &l
);
1305 return l
.stripe_count
;
1308 extern "C" int ceph_get_path_stripe_count(struct ceph_mount_info
*cmount
, const char *path
)
1313 if (!cmount
->is_mounted())
1315 r
= cmount
->get_client()->describe_layout(path
, &l
, cmount
->default_perms
);
1318 return l
.stripe_count
;
1321 extern "C" int ceph_get_file_object_size(struct ceph_mount_info
*cmount
, int fh
)
1326 if (!cmount
->is_mounted())
1328 r
= cmount
->get_client()->fdescribe_layout(fh
, &l
);
1331 return l
.object_size
;
1334 extern "C" int ceph_get_path_object_size(struct ceph_mount_info
*cmount
, const char *path
)
1339 if (!cmount
->is_mounted())
1341 r
= cmount
->get_client()->describe_layout(path
, &l
, cmount
->default_perms
);
1344 return l
.object_size
;
1347 extern "C" int ceph_get_file_pool(struct ceph_mount_info
*cmount
, int fh
)
1352 if (!cmount
->is_mounted())
1354 r
= cmount
->get_client()->fdescribe_layout(fh
, &l
);
1360 extern "C" int ceph_get_path_pool(struct ceph_mount_info
*cmount
, const char *path
)
1365 if (!cmount
->is_mounted())
1367 r
= cmount
->get_client()->describe_layout(path
, &l
, cmount
->default_perms
);
1373 extern "C" int ceph_get_file_pool_name(struct ceph_mount_info
*cmount
, int fh
, char *buf
, size_t len
)
1378 if (!cmount
->is_mounted())
1380 r
= cmount
->get_client()->fdescribe_layout(fh
, &l
);
1383 string name
= cmount
->get_client()->get_pool_name(l
.pool_id
);
1385 return name
.length();
1386 if (name
.length() > len
)
1388 strncpy(buf
, name
.c_str(), len
);
1389 return name
.length();
1392 extern "C" int ceph_get_pool_name(struct ceph_mount_info
*cmount
, int pool
, char *buf
, size_t len
)
1394 if (!cmount
->is_mounted())
1396 string name
= cmount
->get_client()->get_pool_name(pool
);
1398 return name
.length();
1399 if (name
.length() > len
)
1401 strncpy(buf
, name
.c_str(), len
);
1402 return name
.length();
1405 extern "C" int ceph_get_path_pool_name(struct ceph_mount_info
*cmount
, const char *path
, char *buf
, size_t len
)
1410 if (!cmount
->is_mounted())
1412 r
= cmount
->get_client()->describe_layout(path
, &l
, cmount
->default_perms
);
1415 string name
= cmount
->get_client()->get_pool_name(l
.pool_id
);
1417 return name
.length();
1418 if (name
.length() > len
)
1420 strncpy(buf
, name
.c_str(), len
);
1421 return name
.length();
1424 extern "C" int ceph_get_default_data_pool_name(struct ceph_mount_info
*cmount
, char *buf
, size_t len
)
1426 if (!cmount
->is_mounted())
1428 int64_t pool_id
= cmount
->get_client()->get_default_pool_id();
1430 string name
= cmount
->get_client()->get_pool_name(pool_id
);
1432 return name
.length();
1433 if (name
.length() > len
)
1435 strncpy(buf
, name
.c_str(), len
);
1436 return name
.length();
1439 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
)
1444 if (!cmount
->is_mounted())
1446 r
= cmount
->get_client()->fdescribe_layout(fh
, &l
);
1450 *stripe_unit
= l
.stripe_unit
;
1452 *stripe_count
= l
.stripe_count
;
1454 *object_size
= l
.object_size
;
1456 *pg_pool
= l
.pool_id
;
1460 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
)
1465 if (!cmount
->is_mounted())
1467 r
= cmount
->get_client()->describe_layout(path
, &l
, cmount
->default_perms
);
1471 *stripe_unit
= l
.stripe_unit
;
1473 *stripe_count
= l
.stripe_count
;
1475 *object_size
= l
.object_size
;
1477 *pg_pool
= l
.pool_id
;
1481 extern "C" int ceph_get_file_replication(struct ceph_mount_info
*cmount
, int fh
)
1486 if (!cmount
->is_mounted())
1488 r
= cmount
->get_client()->fdescribe_layout(fh
, &l
);
1491 int rep
= cmount
->get_client()->get_pool_replication(l
.pool_id
);
1495 extern "C" int ceph_get_path_replication(struct ceph_mount_info
*cmount
, const char *path
)
1500 if (!cmount
->is_mounted())
1502 r
= cmount
->get_client()->describe_layout(path
, &l
, cmount
->default_perms
);
1505 int rep
= cmount
->get_client()->get_pool_replication(l
.pool_id
);
1509 extern "C" int ceph_set_default_file_stripe_unit(struct ceph_mount_info
*cmount
,
1512 // this option no longer exists
1516 extern "C" int ceph_set_default_file_stripe_count(struct ceph_mount_info
*cmount
,
1519 // this option no longer exists
1523 extern "C" int ceph_set_default_object_size(struct ceph_mount_info
*cmount
, int size
)
1525 // this option no longer exists
1529 extern "C" int ceph_set_default_file_replication(struct ceph_mount_info
*cmount
,
1532 // this option no longer exists
1536 extern "C" int ceph_set_default_preferred_pg(struct ceph_mount_info
*cmount
, int osd
)
1538 // this option no longer exists
1542 extern "C" int ceph_get_file_extent_osds(struct ceph_mount_info
*cmount
, int fh
,
1543 int64_t offset
, int64_t *length
, int *osds
, int nosds
)
1548 if (!cmount
->is_mounted())
1552 int ret
= cmount
->get_client()->get_file_extent_osds(fh
, offset
, length
, vosds
);
1557 return vosds
.size();
1559 if ((int)vosds
.size() > nosds
)
1562 for (int i
= 0; i
< (int)vosds
.size(); i
++)
1565 return vosds
.size();
1568 extern "C" int ceph_get_osd_crush_location(struct ceph_mount_info
*cmount
,
1569 int osd
, char *path
, size_t len
)
1571 if (!cmount
->is_mounted())
1577 vector
<pair
<string
, string
> > loc
;
1578 int ret
= cmount
->get_client()->get_osd_crush_location(osd
, loc
);
1584 vector
<pair
<string
, string
> >::iterator it
;
1585 for (it
= loc
.begin(); it
!= loc
.end(); ++it
) {
1586 string
& type
= it
->first
;
1587 string
& name
= it
->second
;
1588 needed
+= type
.size() + name
.size() + 2;
1589 if (needed
<= len
) {
1591 strcpy(path
+ cur
, type
.c_str());
1592 cur
+= type
.size() + 1;
1594 strcpy(path
+ cur
, name
.c_str());
1595 cur
+= name
.size() + 1;
1608 extern "C" int ceph_get_osd_addr(struct ceph_mount_info
*cmount
, int osd
,
1609 struct sockaddr_storage
*addr
)
1611 if (!cmount
->is_mounted())
1617 entity_addr_t address
;
1618 int ret
= cmount
->get_client()->get_osd_addr(osd
, address
);
1622 *addr
= address
.get_sockaddr_storage();
1627 extern "C" int ceph_get_file_stripe_address(struct ceph_mount_info
*cmount
, int fh
,
1628 int64_t offset
, struct sockaddr_storage
*addr
, int naddr
)
1630 vector
<entity_addr_t
> address
;
1637 if (!cmount
->is_mounted())
1640 r
= cmount
->get_client()->get_file_stripe_address(fh
, offset
, address
);
1644 for (i
= 0; i
< (unsigned)naddr
&& i
< address
.size(); i
++)
1645 addr
[i
] = address
[i
].get_sockaddr_storage();
1647 /* naddr == 0: drop through and return actual size */
1648 if (naddr
&& (address
.size() > (unsigned)naddr
))
1651 return address
.size();
1654 extern "C" int ceph_localize_reads(struct ceph_mount_info
*cmount
, int val
)
1656 if (!cmount
->is_mounted())
1659 cmount
->get_client()->clear_filer_flags(CEPH_OSD_FLAG_LOCALIZE_READS
);
1661 cmount
->get_client()->set_filer_flags(CEPH_OSD_FLAG_LOCALIZE_READS
);
1665 extern "C" CephContext
*ceph_get_mount_context(struct ceph_mount_info
*cmount
)
1667 return cmount
->get_ceph_context();
1670 extern "C" int ceph_debug_get_fd_caps(struct ceph_mount_info
*cmount
, int fd
)
1672 if (!cmount
->is_mounted())
1674 return cmount
->get_client()->get_caps_issued(fd
);
1677 extern "C" int ceph_debug_get_file_caps(struct ceph_mount_info
*cmount
, const char *path
)
1679 if (!cmount
->is_mounted())
1681 return cmount
->get_client()->get_caps_issued(path
, cmount
->default_perms
);
1684 extern "C" int ceph_get_stripe_unit_granularity(struct ceph_mount_info
*cmount
)
1686 if (!cmount
->is_mounted())
1688 return CEPH_MIN_STRIPE_UNIT
;
1691 extern "C" int ceph_get_pool_id(struct ceph_mount_info
*cmount
, const char *pool_name
)
1693 if (!cmount
->is_mounted())
1696 if (!pool_name
|| !pool_name
[0])
1699 /* negative range reserved for errors */
1700 int64_t pool_id
= cmount
->get_client()->get_pool_id(pool_name
);
1701 if (pool_id
> 0x7fffffff)
1704 /* get_pool_id error codes fit in int */
1705 return (int)pool_id
;
1708 extern "C" int ceph_get_pool_replication(struct ceph_mount_info
*cmount
,
1711 if (!cmount
->is_mounted())
1713 return cmount
->get_client()->get_pool_replication(pool_id
);
1715 /* Low-level exports */
1717 extern "C" int ceph_ll_lookup_root(struct ceph_mount_info
*cmount
,
1720 *parent
= cmount
->get_client()->get_root();
1726 extern "C" struct Inode
*ceph_ll_get_inode(class ceph_mount_info
*cmount
,
1729 return (cmount
->get_client())->ll_get_inode(vino
);
1733 extern "C" int ceph_ll_lookup_vino(
1734 struct ceph_mount_info
*cmount
,
1738 return (cmount
->get_client())->ll_lookup_vino(vino
, cmount
->default_perms
, inode
);
1742 * Populates the client cache with the requested inode, and its
1745 extern "C" int ceph_ll_lookup_inode(
1746 struct ceph_mount_info
*cmount
,
1747 struct inodeno_t ino
,
1750 return (cmount
->get_client())->ll_lookup_inode(ino
, cmount
->default_perms
, inode
);
1753 extern "C" int ceph_ll_lookup(struct ceph_mount_info
*cmount
,
1754 Inode
*parent
, const char *name
, Inode
**out
,
1755 struct ceph_statx
*stx
, unsigned want
,
1756 unsigned flags
, const UserPerm
*perms
)
1758 if (flags
& ~CEPH_REQ_FLAG_MASK
)
1760 return (cmount
->get_client())->ll_lookupx(parent
, name
, out
, stx
, want
,
1764 extern "C" int ceph_ll_put(class ceph_mount_info
*cmount
, Inode
*in
)
1766 return (cmount
->get_client()->ll_put(in
));
1769 extern "C" int ceph_ll_forget(class ceph_mount_info
*cmount
, Inode
*in
,
1772 return (cmount
->get_client()->ll_forget(in
, count
));
1775 extern "C" int ceph_ll_walk(struct ceph_mount_info
*cmount
, const char* name
, Inode
**i
,
1776 struct ceph_statx
*stx
, unsigned int want
, unsigned int flags
,
1777 const UserPerm
*perms
)
1779 if (flags
& ~CEPH_REQ_FLAG_MASK
)
1781 return(cmount
->get_client()->ll_walk(name
, i
, stx
, want
, flags
, *perms
));
1784 extern "C" int ceph_ll_getattr(class ceph_mount_info
*cmount
,
1785 Inode
*in
, struct ceph_statx
*stx
,
1786 unsigned int want
, unsigned int flags
,
1787 const UserPerm
*perms
)
1789 if (flags
& ~CEPH_REQ_FLAG_MASK
)
1791 return (cmount
->get_client()->ll_getattrx(in
, stx
, want
, flags
, *perms
));
1794 extern "C" int ceph_ll_setattr(class ceph_mount_info
*cmount
,
1795 Inode
*in
, struct ceph_statx
*stx
,
1796 int mask
, const UserPerm
*perms
)
1798 return (cmount
->get_client()->ll_setattrx(in
, stx
, mask
, *perms
));
1801 extern "C" int ceph_ll_open(class ceph_mount_info
*cmount
, Inode
*in
,
1802 int flags
, Fh
**fh
, const UserPerm
*perms
)
1804 return (cmount
->get_client()->ll_open(in
, flags
, fh
, *perms
));
1807 extern "C" int ceph_ll_read(class ceph_mount_info
*cmount
, Fh
* filehandle
,
1808 int64_t off
, uint64_t len
, char* buf
)
1813 r
= cmount
->get_client()->ll_read(filehandle
, off
, len
, &bl
);
1816 bl
.begin().copy(bl
.length(), buf
);
1822 extern "C" int ceph_ll_read_block(class ceph_mount_info
*cmount
,
1823 Inode
*in
, uint64_t blockid
,
1824 char* buf
, uint64_t offset
,
1826 struct ceph_file_layout
* layout
)
1829 int r
= (cmount
->get_client()->ll_read_block(in
, blockid
, buf
, offset
,
1831 l
.to_legacy(layout
);
1835 extern "C" int ceph_ll_write_block(class ceph_mount_info
*cmount
,
1836 Inode
*in
, uint64_t blockid
,
1837 char *buf
, uint64_t offset
,
1839 struct ceph_file_layout
*layout
,
1840 uint64_t snapseq
, uint32_t sync
)
1843 int r
= (cmount
->get_client()->ll_write_block(in
, blockid
, buf
, offset
,
1844 length
, &l
, snapseq
, sync
));
1845 l
.to_legacy(layout
);
1849 extern "C" int ceph_ll_commit_blocks(class ceph_mount_info
*cmount
,
1850 Inode
*in
, uint64_t offset
,
1853 return (cmount
->get_client()->ll_commit_blocks(in
, offset
, range
));
1856 extern "C" int ceph_ll_fsync(class ceph_mount_info
*cmount
,
1857 Fh
*fh
, int syncdataonly
)
1859 return (cmount
->get_client()->ll_fsync(fh
, syncdataonly
));
1862 extern "C" int ceph_ll_sync_inode(class ceph_mount_info
*cmount
,
1863 Inode
*in
, int syncdataonly
)
1865 return (cmount
->get_client()->ll_sync_inode(in
, syncdataonly
));
1868 extern "C" int ceph_ll_fallocate(class ceph_mount_info
*cmount
, Fh
*fh
,
1869 int mode
, int64_t offset
, int64_t length
)
1871 return cmount
->get_client()->ll_fallocate(fh
, mode
, offset
, length
);
1874 extern "C" off_t
ceph_ll_lseek(class ceph_mount_info
*cmount
,
1875 Fh
*fh
, off_t offset
, int whence
)
1877 return (cmount
->get_client()->ll_lseek(fh
, offset
, whence
));
1880 extern "C" int ceph_ll_write(class ceph_mount_info
*cmount
,
1881 Fh
*fh
, int64_t off
, uint64_t len
,
1884 return (cmount
->get_client()->ll_write(fh
, off
, len
, data
));
1887 extern "C" int64_t ceph_ll_readv(class ceph_mount_info
*cmount
,
1888 struct Fh
*fh
, const struct iovec
*iov
,
1889 int iovcnt
, int64_t off
)
1891 return (cmount
->get_client()->ll_readv(fh
, iov
, iovcnt
, off
));
1894 extern "C" int64_t ceph_ll_writev(class ceph_mount_info
*cmount
,
1895 struct Fh
*fh
, const struct iovec
*iov
,
1896 int iovcnt
, int64_t off
)
1898 return (cmount
->get_client()->ll_writev(fh
, iov
, iovcnt
, off
));
1901 extern "C" int ceph_ll_close(class ceph_mount_info
*cmount
, Fh
* fh
)
1903 return (cmount
->get_client()->ll_release(fh
));
1906 extern "C" int ceph_ll_create(class ceph_mount_info
*cmount
,
1907 Inode
*parent
, const char *name
, mode_t mode
,
1908 int oflags
, Inode
**outp
, Fh
**fhp
,
1909 struct ceph_statx
*stx
, unsigned want
,
1910 unsigned lflags
, const UserPerm
*perms
)
1912 if (lflags
& ~CEPH_REQ_FLAG_MASK
)
1914 return (cmount
->get_client())->ll_createx(parent
, name
, mode
, oflags
, outp
,
1915 fhp
, stx
, want
, lflags
, *perms
);
1918 extern "C" int ceph_ll_mknod(class ceph_mount_info
*cmount
, Inode
*parent
,
1919 const char *name
, mode_t mode
, dev_t rdev
,
1920 Inode
**out
, struct ceph_statx
*stx
,
1921 unsigned want
, unsigned flags
,
1922 const UserPerm
*perms
)
1924 if (flags
& ~CEPH_REQ_FLAG_MASK
)
1926 return (cmount
->get_client())->ll_mknodx(parent
, name
, mode
, rdev
,
1927 out
, stx
, want
, flags
, *perms
);
1930 extern "C" int ceph_ll_mkdir(class ceph_mount_info
*cmount
, Inode
*parent
,
1931 const char *name
, mode_t mode
, Inode
**out
,
1932 struct ceph_statx
*stx
, unsigned want
,
1933 unsigned flags
, const UserPerm
*perms
)
1935 if (flags
& ~CEPH_REQ_FLAG_MASK
)
1937 return cmount
->get_client()->ll_mkdirx(parent
, name
, mode
, out
, stx
, want
,
1941 extern "C" int ceph_ll_link(class ceph_mount_info
*cmount
,
1942 Inode
*in
, Inode
*newparent
,
1943 const char *name
, const UserPerm
*perms
)
1945 return cmount
->get_client()->ll_link(in
, newparent
, name
, *perms
);
1948 extern "C" int ceph_ll_opendir(class ceph_mount_info
*cmount
,
1950 struct ceph_dir_result
**dirpp
,
1951 const UserPerm
*perms
)
1953 return (cmount
->get_client()->ll_opendir(in
, O_RDONLY
, (dir_result_t
**) dirpp
,
1957 extern "C" int ceph_ll_releasedir(class ceph_mount_info
*cmount
,
1958 ceph_dir_result
*dir
)
1960 return cmount
->get_client()->ll_releasedir(reinterpret_cast<dir_result_t
*>(dir
));
1963 extern "C" int ceph_ll_rename(class ceph_mount_info
*cmount
,
1964 Inode
*parent
, const char *name
,
1965 Inode
*newparent
, const char *newname
,
1966 const UserPerm
*perms
)
1968 return cmount
->get_client()->ll_rename(parent
, name
, newparent
,
1972 extern "C" int ceph_ll_unlink(class ceph_mount_info
*cmount
, Inode
*in
,
1973 const char *name
, const UserPerm
*perms
)
1975 return cmount
->get_client()->ll_unlink(in
, name
, *perms
);
1978 extern "C" int ceph_ll_statfs(class ceph_mount_info
*cmount
,
1979 Inode
*in
, struct statvfs
*stbuf
)
1981 return (cmount
->get_client()->ll_statfs(in
, stbuf
, cmount
->default_perms
));
1984 extern "C" int ceph_ll_readlink(class ceph_mount_info
*cmount
, Inode
*in
,
1985 char *buf
, size_t bufsiz
,
1986 const UserPerm
*perms
)
1988 return cmount
->get_client()->ll_readlink(in
, buf
, bufsiz
, *perms
);
1991 extern "C" int ceph_ll_symlink(class ceph_mount_info
*cmount
,
1992 Inode
*in
, const char *name
,
1993 const char *value
, Inode
**out
,
1994 struct ceph_statx
*stx
, unsigned want
,
1995 unsigned flags
, const UserPerm
*perms
)
1997 if (flags
& ~CEPH_REQ_FLAG_MASK
)
1999 return (cmount
->get_client()->ll_symlinkx(in
, name
, value
, out
, stx
, want
,
2003 extern "C" int ceph_ll_rmdir(class ceph_mount_info
*cmount
,
2004 Inode
*in
, const char *name
,
2005 const UserPerm
*perms
)
2007 return cmount
->get_client()->ll_rmdir(in
, name
, *perms
);
2010 extern "C" int ceph_ll_getxattr(class ceph_mount_info
*cmount
,
2011 Inode
*in
, const char *name
, void *value
,
2012 size_t size
, const UserPerm
*perms
)
2014 return (cmount
->get_client()->ll_getxattr(in
, name
, value
, size
, *perms
));
2017 extern "C" int ceph_ll_listxattr(struct ceph_mount_info
*cmount
,
2018 Inode
*in
, char *list
,
2019 size_t buf_size
, size_t *list_size
,
2020 const UserPerm
*perms
)
2022 int res
= cmount
->get_client()->ll_listxattr(in
, list
, buf_size
, *perms
);
2024 *list_size
= (size_t)res
;
2030 extern "C" int ceph_ll_setxattr(class ceph_mount_info
*cmount
,
2031 Inode
*in
, const char *name
,
2032 const void *value
, size_t size
,
2033 int flags
, const UserPerm
*perms
)
2035 return (cmount
->get_client()->ll_setxattr(in
, name
, value
, size
, flags
, *perms
));
2038 extern "C" int ceph_ll_removexattr(class ceph_mount_info
*cmount
,
2039 Inode
*in
, const char *name
,
2040 const UserPerm
*perms
)
2042 return (cmount
->get_client()->ll_removexattr(in
, name
, *perms
));
2045 extern "C" int ceph_ll_getlk(struct ceph_mount_info
*cmount
,
2046 Fh
*fh
, struct flock
*fl
, uint64_t owner
)
2048 return (cmount
->get_client()->ll_getlk(fh
, fl
, owner
));
2051 extern "C" int ceph_ll_setlk(struct ceph_mount_info
*cmount
,
2052 Fh
*fh
, struct flock
*fl
, uint64_t owner
,
2055 return (cmount
->get_client()->ll_setlk(fh
, fl
, owner
, sleep
));
2058 extern "C" int ceph_ll_lazyio(class ceph_mount_info
*cmount
,
2061 return (cmount
->get_client()->ll_lazyio(fh
, enable
));
2064 extern "C" int ceph_ll_delegation(struct ceph_mount_info
*cmount
, Fh
*fh
,
2065 unsigned cmd
, ceph_deleg_cb_t cb
, void *priv
)
2067 return (cmount
->get_client()->ll_delegation(fh
, cmd
, cb
, priv
));
2070 extern "C" uint32_t ceph_ll_stripe_unit(class ceph_mount_info
*cmount
,
2073 return (cmount
->get_client()->ll_stripe_unit(in
));
2076 extern "C" uint32_t ceph_ll_file_layout(class ceph_mount_info
*cmount
,
2078 struct ceph_file_layout
*layout
)
2081 int r
= (cmount
->get_client()->ll_file_layout(in
, &l
));
2082 l
.to_legacy(layout
);
2086 uint64_t ceph_ll_snap_seq(class ceph_mount_info
*cmount
, Inode
*in
)
2088 return (cmount
->get_client()->ll_snap_seq(in
));
2091 extern "C" int ceph_ll_get_stripe_osd(class ceph_mount_info
*cmount
,
2092 Inode
*in
, uint64_t blockno
,
2093 struct ceph_file_layout
* layout
)
2096 int r
= (cmount
->get_client()->ll_get_stripe_osd(in
, blockno
, &l
));
2097 l
.to_legacy(layout
);
2101 extern "C" int ceph_ll_num_osds(class ceph_mount_info
*cmount
)
2103 return (cmount
->get_client()->ll_num_osds());
2106 extern "C" int ceph_ll_osdaddr(class ceph_mount_info
*cmount
,
2107 int osd
, uint32_t *addr
)
2109 return (cmount
->get_client()->ll_osdaddr(osd
, addr
));
2112 extern "C" uint64_t ceph_ll_get_internal_offset(class ceph_mount_info
*cmount
,
2116 return (cmount
->get_client()->ll_get_internal_offset(in
, blockno
));
2119 extern "C" void ceph_buffer_free(char *buf
)
2126 extern "C" uint32_t ceph_get_cap_return_timeout(class ceph_mount_info
*cmount
)
2128 if (!cmount
->is_mounted())
2130 return cmount
->get_client()->mdsmap
->get_session_autoclose().sec();
2133 extern "C" int ceph_set_deleg_timeout(class ceph_mount_info
*cmount
, uint32_t timeout
)
2135 if (!cmount
->is_mounted())
2137 return cmount
->get_client()->set_deleg_timeout(timeout
);
2140 extern "C" void ceph_set_session_timeout(class ceph_mount_info
*cmount
, unsigned timeout
)
2142 cmount
->get_client()->set_session_timeout(timeout
);
2145 extern "C" void ceph_set_uuid(class ceph_mount_info
*cmount
, const char *uuid
)
2147 cmount
->get_client()->set_uuid(std::string(uuid
));
2150 extern "C" int ceph_start_reclaim(class ceph_mount_info
*cmount
,
2151 const char *uuid
, unsigned flags
)
2153 if (!cmount
->is_initialized()) {
2154 int ret
= cmount
->init();
2158 return cmount
->get_client()->start_reclaim(std::string(uuid
), flags
,
2159 cmount
->get_filesystem());
2162 extern "C" void ceph_finish_reclaim(class ceph_mount_info
*cmount
)
2164 cmount
->get_client()->finish_reclaim();
2167 // This is deprecated, use ceph_ll_register_callbacks2 instead.
2168 extern "C" void ceph_ll_register_callbacks(class ceph_mount_info
*cmount
,
2169 struct ceph_client_callback_args
*args
)
2171 cmount
->get_client()->ll_register_callbacks(args
);
2174 extern "C" int ceph_ll_register_callbacks2(class ceph_mount_info
*cmount
,
2175 struct ceph_client_callback_args
*args
)
2177 return cmount
->get_client()->ll_register_callbacks2(args
);
2181 extern "C" int ceph_get_snap_info(struct ceph_mount_info
*cmount
,
2182 const char *path
, struct snap_info
*snap_info
) {
2183 Client::SnapInfo info
;
2184 int r
= cmount
->get_client()->get_snap_info(path
, cmount
->default_perms
, &info
);
2190 auto nr_metadata
= info
.metadata
.size();
2192 snap_info
->id
= info
.id
.val
;
2193 snap_info
->nr_snap_metadata
= nr_metadata
;
2195 snap_info
->snap_metadata
= (struct snap_metadata
*)calloc(nr_metadata
, sizeof(struct snap_metadata
));
2196 if (!snap_info
->snap_metadata
) {
2200 // fill with key, value pairs
2201 for (auto &[key
, value
] : info
.metadata
) {
2202 // len(key) + '\0' + len(value) + '\0'
2203 char *kvp
= (char *)malloc(key
.size() + value
.size() + 2);
2208 char *_value
= kvp
+ key
.size() + 1;
2210 memcpy(_key
, key
.c_str(), key
.size());
2211 _key
[key
.size()] = '\0';
2212 memcpy(_value
, value
.c_str(), value
.size());
2213 _value
[value
.size()] = '\0';
2215 snap_info
->snap_metadata
[i
].key
= _key
;
2216 snap_info
->snap_metadata
[i
].value
= _value
;
2221 if (nr_metadata
&& i
!= nr_metadata
) {
2222 ceph_free_snap_info_buffer(snap_info
);
2229 extern "C" void ceph_free_snap_info_buffer(struct snap_info
*snap_info
) {
2230 for (size_t i
= 0; i
< snap_info
->nr_snap_metadata
; ++i
) {
2231 free((void *)snap_info
->snap_metadata
[i
].key
); // malloc'd memory is key+value composite
2233 free(snap_info
->snap_metadata
);