diff --git a/src/ceph_fuse.cc b/src/ceph_fuse.cc index 4416e9d3c58..d536365c3fb 100644 --- a/src/ceph_fuse.cc +++ b/src/ceph_fuse.cc @@ -16,7 +16,6 @@ #include #include #include -using namespace std; #include "common/config.h" #include "common/errno.h" @@ -52,7 +51,7 @@ static void fuse_usage() "-h", }; struct fuse_args args = FUSE_ARGS_INIT(2, (char**)argv); - if (fuse_parse_cmdline(&args, NULL, NULL, NULL) == -1) { + if (fuse_parse_cmdline(&args, nullptr, nullptr, nullptr) == -1) { derr << "fuse_parse_cmdline failed." << dendl; } assert(args.allocated); @@ -85,13 +84,16 @@ int main(int argc, const char **argv, const char *envp[]) { auto cct = global_init(&def_args, args, CEPH_ENTITY_TYPE_CLIENT, CODE_ENVIRONMENT_DAEMON, CINIT_FLAG_UNPRIVILEGED_DAEMON_DEFAULTS); - for (std::vector::iterator i = args.begin(); i != args.end(); ) { + + auto i = args.begin(); + auto end = args.end(); + for (; i != end;) { if (ceph_argparse_double_dash(args, i)) { break; - } else if (ceph_argparse_flag(args, i, "--localize-reads", (char*)NULL)) { + } else if (ceph_argparse_flag(args, i, "--localize-reads", (char*)nullptr)) { cerr << "setting CEPH_OSD_FLAG_LOCALIZE_READS" << std::endl; filer_flags |= CEPH_OSD_FLAG_LOCALIZE_READS; - } else if (ceph_argparse_flag(args, i, "-h", "--help", (char*)NULL)) { + } else if (ceph_argparse_flag(args, i, "-h", "--help", (char*)nullptr)) { usage(); } else { ++i; @@ -105,7 +107,7 @@ int main(int argc, const char **argv, const char *envp[]) { // FUSE will chdir("/"); be ready. g_ceph_context->_conf->set_val("chdir", "/"); - g_ceph_context->_conf->apply_changes(NULL); + g_ceph_context->_conf->apply_changes(nullptr); // check for 32-bit arch #ifndef __LP64__ @@ -116,7 +118,8 @@ int main(int argc, const char **argv, const char *envp[]) { #endif Preforker forker; - if (g_conf->daemonize) { + auto daemonize = g_conf->get_val("daemonize"); + if (daemonize) { global_init_prefork(g_ceph_context); int r; string err; @@ -148,7 +151,7 @@ int main(int argc, const char **argv, const char *envp[]) { public: CephFuse *cfuse; Client *client; - RemountTest() : cfuse(NULL), client(NULL) {} + RemountTest() : cfuse(nullptr), client(nullptr) {} void init(CephFuse *cf, Client *cl) { cfuse = cf; client = cl; @@ -158,8 +161,10 @@ int main(int argc, const char **argv, const char *envp[]) { #if defined(__linux__) int ver = get_linux_version(); assert(ver != 0); - bool can_invalidate_dentries = g_conf->client_try_dentry_invalidate && - ver < KERNEL_VERSION(3, 18, 0); + auto client_try_dentry_invalidate = g_conf->get_val( + "client_try_dentry_invalidate"); + bool can_invalidate_dentries = + client_try_dentry_invalidate && ver < KERNEL_VERSION(3, 18, 0); int tr = client->test_dentry_handling(can_invalidate_dentries); if (tr != 0) { cerr << "ceph-fuse[" << getpid() @@ -193,12 +198,12 @@ int main(int argc, const char **argv, const char *envp[]) { // get monmap - Messenger *messenger = NULL; + Messenger *messenger = nullptr; StandaloneClient *client; CephFuse *cfuse; UserPerm perms; int tester_r = 0; - void *tester_rp = NULL; + void *tester_rp = nullptr; MonClient *mc = new MonClient(g_ceph_context); int r = mc->build_initial_monmap(); @@ -245,15 +250,21 @@ int main(int argc, const char **argv, const char *envp[]) { client->update_metadata("mount_point", cfuse->get_mount_point()); perms = client->pick_my_perms(); - // start up fuse - // use my argc, argv (make sure you pass a mount point!) - r = client->mount(g_conf->client_mountpoint.c_str(), perms, - g_ceph_context->_conf->fuse_require_active_mds); - if (r < 0) { - if (r == CEPH_FUSE_NO_MDS_UP) - cerr << "ceph-fuse[" << getpid() << "]: probably no MDS server is up?" << std::endl; - cerr << "ceph-fuse[" << getpid() << "]: ceph mount failed with " << cpp_strerror(-r) << std::endl; - goto out_shutdown; + { + // start up fuse + // use my argc, argv (make sure you pass a mount point!) + auto client_mountpoint = g_conf->get_val( + "client_mountpoint"); + auto mountpoint = client_mountpoint.c_str(); + auto fuse_require_active_mds = g_conf->get_val( + "fuse_require_active_mds"); + r = client->mount(mountpoint, perms, fuse_require_active_mds); + if (r < 0) { + if (r == CEPH_FUSE_NO_MDS_UP) + cerr << "ceph-fuse[" << getpid() << "]: probably no MDS server is up?" << std::endl; + cerr << "ceph-fuse[" << getpid() << "]: ceph mount failed with " << cpp_strerror(-r) << std::endl; + goto out_shutdown; + } } r = cfuse->start(); @@ -270,8 +281,7 @@ int main(int argc, const char **argv, const char *envp[]) { tester_r = static_cast(reinterpret_cast(tester_rp)); cerr << "ceph-fuse[" << getpid() << "]: fuse finished with error " << r << " and tester_r " << tester_r <unmount(); cfuse->finalize(); @@ -286,13 +296,16 @@ int main(int argc, const char **argv, const char *envp[]) { messenger->wait(); out_messenger_start_failed: delete cfuse; + cfuse = nullptr; delete client; + client = nullptr; delete messenger; + messenger = nullptr; out_mc_start_failed: free(newargv); delete mc; + mc = nullptr; //cout << "child done" << std::endl; return forker.signal_exit(r); } } - diff --git a/src/client/Client.cc b/src/client/Client.cc index 678184787a2..6d322df651b 100644 --- a/src/client/Client.cc +++ b/src/client/Client.cc @@ -10233,7 +10233,9 @@ int Client::ll_lookup(Inode *parent, const char *name, struct stat *attr, return -ENOTCONN; int r = 0; - if (!cct->_conf->fuse_default_permissions) { + auto fuse_default_permissions = cct->_conf->get_val( + "fuse_default_permissions"); + if (!fuse_default_permissions) { r = may_lookup(parent, perms); if (r < 0) return r; @@ -10274,7 +10276,9 @@ int Client::ll_lookupx(Inode *parent, const char *name, Inode **out, return -ENOTCONN; int r = 0; - if (!cct->_conf->fuse_default_permissions) { + auto fuse_default_permissions = cct->_conf->get_val( + "fuse_default_permissions"); + if (!fuse_default_permissions) { r = may_lookup(parent, perms); if (r < 0) return r; @@ -10518,7 +10522,9 @@ int Client::_ll_setattrx(Inode *in, struct ceph_statx *stx, int mask, tout(cct) << stx->stx_btime << std::endl; tout(cct) << mask << std::endl; - if (!cct->_conf->fuse_default_permissions) { + auto fuse_default_permissions = cct->_conf->get_val( + "fuse_default_permissions"); + if (!fuse_default_permissions) { int res = may_setattr(in, stx, mask, perms); if (res < 0) return res; @@ -10839,7 +10845,9 @@ int Client::ll_getxattr(Inode *in, const char *name, void *value, tout(cct) << vino.ino.val << std::endl; tout(cct) << name << std::endl; - if (!cct->_conf->fuse_default_permissions) { + auto fuse_default_permissions = cct->_conf->get_val( + "fuse_default_permissions"); + if (!fuse_default_permissions) { int r = xattr_permission(in, name, MAY_READ, perms); if (r < 0) return r; @@ -11094,7 +11102,9 @@ int Client::ll_setxattr(Inode *in, const char *name, const void *value, tout(cct) << vino.ino.val << std::endl; tout(cct) << name << std::endl; - if (!cct->_conf->fuse_default_permissions) { + auto fuse_default_permissions = cct->_conf->get_val( + "fuse_default_permissions"); + if (!fuse_default_permissions) { int r = xattr_permission(in, name, MAY_WRITE, perms); if (r < 0) return r; @@ -11158,7 +11168,9 @@ int Client::ll_removexattr(Inode *in, const char *name, const UserPerm& perms) tout(cct) << vino.ino.val << std::endl; tout(cct) << name << std::endl; - if (!cct->_conf->fuse_default_permissions) { + auto fuse_default_permissions = cct->_conf->get_val( + "fuse_default_permissions"); + if (!fuse_default_permissions) { int r = xattr_permission(in, name, MAY_WRITE, perms); if (r < 0) return r; @@ -11481,7 +11493,9 @@ int Client::ll_mknod(Inode *parent, const char *name, mode_t mode, tout(cct) << mode << std::endl; tout(cct) << rdev << std::endl; - if (!cct->_conf->fuse_default_permissions) { + auto fuse_default_permissions = cct->_conf->get_val( + "fuse_default_permissions"); + if (!fuse_default_permissions) { int r = may_create(parent, perms); if (r < 0) return r; @@ -11520,7 +11534,9 @@ int Client::ll_mknodx(Inode *parent, const char *name, mode_t mode, tout(cct) << mode << std::endl; tout(cct) << rdev << std::endl; - if (!cct->_conf->fuse_default_permissions) { + auto fuse_default_permissions = cct->_conf->get_val( + "fuse_default_permissions"); + if (!fuse_default_permissions) { int r = may_create(parent, perms); if (r < 0) return r; @@ -11705,7 +11721,9 @@ int Client::ll_mkdir(Inode *parent, const char *name, mode_t mode, tout(cct) << name << std::endl; tout(cct) << mode << std::endl; - if (!cct->_conf->fuse_default_permissions) { + auto fuse_default_permissions = cct->_conf->get_val( + "fuse_default_permissions"); + if (!fuse_default_permissions) { int r = may_create(parent, perm); if (r < 0) return r; @@ -11741,7 +11759,9 @@ int Client::ll_mkdirx(Inode *parent, const char *name, mode_t mode, Inode **out, tout(cct) << name << std::endl; tout(cct) << mode << std::endl; - if (!cct->_conf->fuse_default_permissions) { + auto fuse_default_permissions = cct->_conf->get_val( + "fuse_default_permissions"); + if (!fuse_default_permissions) { int r = may_create(parent, perms); if (r < 0) return r; @@ -11826,7 +11846,9 @@ int Client::ll_symlink(Inode *parent, const char *name, const char *value, tout(cct) << name << std::endl; tout(cct) << value << std::endl; - if (!cct->_conf->fuse_default_permissions) { + auto fuse_default_permissions = cct->_conf->get_val( + "fuse_default_permissions"); + if (!fuse_default_permissions) { int r = may_create(parent, perms); if (r < 0) return r; @@ -11863,7 +11885,9 @@ int Client::ll_symlinkx(Inode *parent, const char *name, const char *value, tout(cct) << name << std::endl; tout(cct) << value << std::endl; - if (!cct->_conf->fuse_default_permissions) { + auto fuse_default_permissions = cct->_conf->get_val( + "fuse_default_permissions"); + if (!fuse_default_permissions) { int r = may_create(parent, perms); if (r < 0) return r; @@ -11942,7 +11966,9 @@ int Client::ll_unlink(Inode *in, const char *name, const UserPerm& perm) tout(cct) << vino.ino.val << std::endl; tout(cct) << name << std::endl; - if (!cct->_conf->fuse_default_permissions) { + auto fuse_default_permissions = cct->_conf->get_val( + "fuse_default_permissions"); + if (!fuse_default_permissions) { int r = may_delete(in, name, perm); if (r < 0) return r; @@ -12012,7 +12038,9 @@ int Client::ll_rmdir(Inode *in, const char *name, const UserPerm& perms) tout(cct) << vino.ino.val << std::endl; tout(cct) << name << std::endl; - if (!cct->_conf->fuse_default_permissions) { + auto fuse_default_permissions = cct->_conf->get_val( + "fuse_default_permissions"); + if (!fuse_default_permissions) { int r = may_delete(in, name, perms); if (r < 0) return r; @@ -12134,7 +12162,9 @@ int Client::ll_rename(Inode *parent, const char *name, Inode *newparent, tout(cct) << vnewparent.ino.val << std::endl; tout(cct) << newname << std::endl; - if (!cct->_conf->fuse_default_permissions) { + auto fuse_default_permissions = cct->_conf->get_val( + "fuse_default_permissions"); + if (!fuse_default_permissions) { int r = may_delete(parent, name, perm); if (r < 0) return r; @@ -12211,7 +12241,9 @@ int Client::ll_link(Inode *in, Inode *newparent, const char *newname, int r = 0; InodeRef target; - if (!cct->_conf->fuse_default_permissions) { + auto fuse_default_permissions = cct->_conf->get_val( + "fuse_default_permissions"); + if (!fuse_default_permissions) { if (S_ISDIR(in->mode)) return -EPERM; @@ -12337,7 +12369,9 @@ int Client::ll_opendir(Inode *in, int flags, dir_result_t** dirpp, tout(cct) << "ll_opendir" << std::endl; tout(cct) << vino.ino.val << std::endl; - if (!cct->_conf->fuse_default_permissions) { + auto fuse_default_permissions = cct->_conf->get_val( + "fuse_default_permissions"); + if (!fuse_default_permissions) { int r = may_open(in, flags, perms); if (r < 0) return r; @@ -12395,7 +12429,9 @@ int Client::ll_open(Inode *in, int flags, Fh **fhp, const UserPerm& perms) tout(cct) << ceph_flags_sys2wire(flags) << std::endl; int r; - if (!cct->_conf->fuse_default_permissions) { + auto fuse_default_permissions = cct->_conf->get_val( + "fuse_default_permissions"); + if (!fuse_default_permissions) { r = may_open(in, flags, perms); if (r < 0) goto out; @@ -12438,7 +12474,9 @@ int Client::_ll_create(Inode *parent, const char *name, mode_t mode, return -EEXIST; if (r == -ENOENT && (flags & O_CREAT)) { - if (!cct->_conf->fuse_default_permissions) { + auto fuse_default_permissions = cct->_conf->get_val( + "fuse_default_permissions"); + if (!fuse_default_permissions) { r = may_create(parent, perms); if (r < 0) goto out; @@ -12456,7 +12494,9 @@ int Client::_ll_create(Inode *parent, const char *name, mode_t mode, ldout(cct, 20) << "_ll_create created = " << created << dendl; if (!created) { - if (!cct->_conf->fuse_default_permissions) { + auto fuse_default_permissions = cct->_conf->get_val( + "fuse_default_permissions"); + if (!fuse_default_permissions) { r = may_open(in->get(), flags, perms); if (r < 0) { if (*fhp) { diff --git a/src/client/fuse_ll.cc b/src/client/fuse_ll.cc index d3c54837bea..c40652f2186 100644 --- a/src/client/fuse_ll.cc +++ b/src/client/fuse_ll.cc @@ -400,9 +400,12 @@ static void fuse_ll_mkdir(fuse_req_t req, fuse_ino_t parent, const char *name, UserPerm perm(ctx->uid, ctx->gid); GET_GROUPS(perm, req); #ifdef HAVE_SYS_SYNCFS + auto fuse_multithreaded = cfuse->client->cct->_conf->get_val( + "fuse_multithreaded"); + auto fuse_syncfs_on_mksnap = cfuse->client->cct->_conf->get_val( + "fuse_syncfs_on_mksnap"); if (cfuse->fino_snap(parent) == CEPH_SNAPDIR && - cfuse->client->cct->_conf->fuse_multithreaded && - cfuse->client->cct->_conf->fuse_syncfs_on_mksnap) { + fuse_multithreaded && fuse_syncfs_on_mksnap) { int err = 0; int fd = ::open(cfuse->mountpoint, O_RDONLY | O_DIRECTORY); if (fd < 0) { @@ -562,9 +565,13 @@ static void fuse_ll_open(fuse_req_t req, fuse_ino_t ino, if (r == 0) { fi->fh = (uint64_t)fh; #if FUSE_VERSION >= FUSE_MAKE_VERSION(2, 8) - if (cfuse->client->cct->_conf->fuse_disable_pagecache) + auto fuse_disable_pagecache = cfuse->client->cct->_conf->get_val( + "fuse_disable_pagecache"); + auto fuse_use_invalidate_cb = cfuse->client->cct->_conf->get_val( + "fuse_use_invalidate_cb"); + if (fuse_disable_pagecache) fi->direct_io = 1; - else if (cfuse->client->cct->_conf->fuse_use_invalidate_cb) + else if (fuse_use_invalidate_cb) fi->keep_cache = 1; #endif fuse_reply_open(req, fi); @@ -771,9 +778,13 @@ static void fuse_ll_create(fuse_req_t req, fuse_ino_t parent, const char *name, fi->fh = (uint64_t)fh; fe.ino = cfuse->make_fake_ino(fe.attr.st_ino, fe.attr.st_dev); #if FUSE_VERSION >= FUSE_MAKE_VERSION(2, 8) - if (cfuse->client->cct->_conf->fuse_disable_pagecache) + auto fuse_disable_pagecache = cfuse->client->cct->_conf->get_val( + "fuse_disable_pagecache"); + auto fuse_use_invalidate_cb = cfuse->client->cct->_conf->get_val( + "fuse_use_invalidate_cb"); + if (fuse_disable_pagecache) fi->direct_io = 1; - else if (cfuse->client->cct->_conf->fuse_use_invalidate_cb) + else if (fuse_use_invalidate_cb) fi->keep_cache = 1; #endif fuse_reply_create(req, &fe, fi); @@ -822,8 +833,9 @@ static void fuse_ll_setlk(fuse_req_t req, fuse_ino_t ino, Fh *fh = reinterpret_cast(fi->fh); // must use multithread if operation may block - if (!cfuse->client->cct->_conf->fuse_multithreaded && - sleep && lock->l_type != F_UNLCK) { + auto fuse_multithreaded = cfuse->client->cct->_conf->get_val( + "fuse_multithreaded"); + if (!fuse_multithreaded && sleep && lock->l_type != F_UNLCK) { fuse_reply_err(req, EDEADLK); return; } @@ -857,8 +869,9 @@ static void fuse_ll_flock(fuse_req_t req, fuse_ino_t ino, Fh *fh = (Fh*)fi->fh; // must use multithread if operation may block - if (!cfuse->client->cct->_conf->fuse_multithreaded && - !(cmd & (LOCK_NB | LOCK_UN))) { + auto fuse_multithreaded = cfuse->client->cct->_conf->get_val( + "fuse_multithreaded"); + if (!fuse_multithreaded && !(cmd & (LOCK_NB | LOCK_UN))) { fuse_reply_err(req, EDEADLK); return; } @@ -924,8 +937,9 @@ static void do_init(void *data, fuse_conn_info *conn) Client *client = cfuse->client; #if !defined(__APPLE__) - if (!client->cct->_conf->fuse_default_permissions && - client->ll_handle_umask()) { + auto fuse_default_permissions = client->cct->_conf->get_val( + "fuse_default_permissions"); + if (!fuse_default_permissions && client->ll_handle_umask()) { // apply umask in userspace if posix acl is enabled if(conn->capable & FUSE_CAP_DONT_MASK) conn->want |= FUSE_CAP_DONT_MASK; @@ -1058,25 +1072,36 @@ int CephFuse::Handle::init(int argc, const char *argv[]) newargv[newargc++] = argv[0]; newargv[newargc++] = "-f"; // stay in foreground - if (client->cct->_conf->fuse_allow_other) { + auto fuse_allow_other = client->cct->_conf->get_val( + "fuse_allow_other"); + auto fuse_default_permissions = client->cct->_conf->get_val( + "fuse_default_permissions"); + auto fuse_big_writes = client->cct->_conf->get_val( + "fuse_big_writes"); + auto fuse_atomic_o_trunc = client->cct->_conf->get_val( + "fuse_atomic_o_trunc"); + auto fuse_debug = client->cct->_conf->get_val( + "fuse_debug"); + + if (fuse_allow_other) { newargv[newargc++] = "-o"; newargv[newargc++] = "allow_other"; } - if (client->cct->_conf->fuse_default_permissions) { + if (fuse_default_permissions) { newargv[newargc++] = "-o"; newargv[newargc++] = "default_permissions"; } #if defined(__linux__) - if (client->cct->_conf->fuse_big_writes) { + if (fuse_big_writes) { newargv[newargc++] = "-o"; newargv[newargc++] = "big_writes"; } - if (client->cct->_conf->fuse_atomic_o_trunc) { + if (fuse_atomic_o_trunc) { newargv[newargc++] = "-o"; newargv[newargc++] = "atomic_o_trunc"; } #endif - if (client->cct->_conf->fuse_debug) + if (fuse_debug) newargv[newargc++] = "-d"; for (int argctr = 1; argctr < argc; argctr++) @@ -1124,7 +1149,8 @@ int CephFuse::Handle::start() struct client_callback_args args = { handle: this, - ino_cb: client->cct->_conf->fuse_use_invalidate_cb ? ino_invalidate_cb : NULL, + ino_cb: client->cct->_conf->get_val("fuse_use_invalidate_cb") ? + ino_invalidate_cb : NULL, dentry_cb: dentry_invalidate_cb, switch_intr_cb: switch_interrupt_cb, #if defined(__linux__) @@ -1142,7 +1168,9 @@ int CephFuse::Handle::start() int CephFuse::Handle::loop() { - if (client->cct->_conf->fuse_multithreaded) { + auto fuse_multithreaded = client->cct->_conf->get_val( + "fuse_multithreaded"); + if (fuse_multithreaded) { return fuse_session_loop_mt(se); } else { return fuse_session_loop(se); diff --git a/src/common/legacy_config_opts.h b/src/common/legacy_config_opts.h index f880ef81827..20238371599 100644 --- a/src/common/legacy_config_opts.h +++ b/src/common/legacy_config_opts.h @@ -350,7 +350,6 @@ OPTION(client_readahead_max_bytes, OPT_LONGLONG) // default unlimited OPTION(client_readahead_max_periods, OPT_LONGLONG) // as multiple of file layout period (object size * num stripes) OPTION(client_reconnect_stale, OPT_BOOL) // automatically reconnect stale session OPTION(client_snapdir, OPT_STR) -OPTION(client_mountpoint, OPT_STR) OPTION(client_mount_uid, OPT_INT) OPTION(client_mount_gid, OPT_INT) OPTION(client_notify_timeout, OPT_INT) // in seconds @@ -374,18 +373,6 @@ OPTION(client_acl_type, OPT_STR) OPTION(client_permissions, OPT_BOOL) OPTION(client_dirsize_rbytes, OPT_BOOL) -// note: the max amount of "in flight" dirty data is roughly (max - target) -OPTION(fuse_use_invalidate_cb, OPT_BOOL) // use fuse 2.8+ invalidate callback to keep page cache consistent -OPTION(fuse_disable_pagecache, OPT_BOOL) -OPTION(fuse_allow_other, OPT_BOOL) -OPTION(fuse_default_permissions, OPT_BOOL) -OPTION(fuse_big_writes, OPT_BOOL) -OPTION(fuse_atomic_o_trunc, OPT_BOOL) -OPTION(fuse_debug, OPT_BOOL) -OPTION(fuse_multithreaded, OPT_BOOL) -OPTION(fuse_require_active_mds, OPT_BOOL) // if ceph_fuse requires active mds server -OPTION(fuse_syncfs_on_mksnap, OPT_BOOL) - OPTION(client_try_dentry_invalidate, OPT_BOOL) // the client should try to use dentry invaldation instead of remounting, on kernels it believes that will work for OPTION(client_die_on_failed_remount, OPT_BOOL) OPTION(client_check_pool_perm, OPT_BOOL) diff --git a/src/common/options.cc b/src/common/options.cc index dd407d109ce..5eb6e83af84 100644 --- a/src/common/options.cc +++ b/src/common/options.cc @@ -6517,9 +6517,10 @@ std::vector