Skip to content

Commit

Permalink
common: move ConfigValues out of md_config_t
Browse files Browse the repository at this point in the history
by moving ConfigValues out of md_config_t, we are able to point
md_config_t to a new ConfigValues instance at runtime, without
destroying the old one.

also remove ConfigReader, because all md_config_obs_t will be updated
with ConfigProxy now. as md_config_t is not able to offer the *data*
anymore.

Signed-off-by: Kefu Chai <[email protected]>
  • Loading branch information
tchaikov committed Jul 10, 2018
1 parent 4718b7c commit f528475
Show file tree
Hide file tree
Showing 143 changed files with 1,034 additions and 992 deletions.
6 changes: 3 additions & 3 deletions doc/dev/config.rst
Original file line number Diff line number Diff line change
Expand Up @@ -79,10 +79,10 @@ and not done in new code. Do not ever alter g_conf.
Changing configuration values
====================================================

Configuration values can be changed by calling g_conf->set_val. After changing
the configuration, you should call g_conf->apply_changes to re-run all the
Configuration values can be changed by calling ``g_conf()->set_val``. After changing
the configuration, you should call ``g_conf()->apply_changes`` to re-run all the
affected configuration observers. For convenience, you can call
g_conf->set_val_or_die to make a configuration change which you think should
``g_conf()->set_val_or_die`` to make a configuration change which you think should
never fail.

Injectargs, parse_argv, and parse_env are three other functions which modify
Expand Down
12 changes: 6 additions & 6 deletions src/ceph_fuse.cc
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@ int main(int argc, const char **argv, const char *envp[]) {
#endif

Preforker forker;
auto daemonize = g_conf->get_val<bool>("daemonize");
auto daemonize = g_conf().get_val<bool>("daemonize");
if (daemonize) {
global_init_prefork(g_ceph_context);
int r;
Expand All @@ -156,7 +156,7 @@ int main(int argc, const char **argv, const char *envp[]) {
}

{
g_ceph_context->_conf->finalize_reexpand_meta();
g_ceph_context->_conf.finalize_reexpand_meta();
common_init_finish(g_ceph_context);

init_async_signal_handler();
Expand All @@ -177,12 +177,12 @@ int main(int argc, const char **argv, const char *envp[]) {
#if defined(__linux__)
int ver = get_linux_version();
assert(ver != 0);
bool client_try_dentry_invalidate = g_conf->get_val<bool>(
bool client_try_dentry_invalidate = g_conf().get_val<bool>(
"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);
bool client_die_on_failed_dentry_invalidate = g_conf->get_val<bool>(
bool client_die_on_failed_dentry_invalidate = g_conf().get_val<bool>(
"client_die_on_failed_dentry_invalidate");
if (tr != 0 && client_die_on_failed_dentry_invalidate) {
cerr << "ceph-fuse[" << getpid()
Expand Down Expand Up @@ -270,10 +270,10 @@ int main(int argc, const char **argv, const char *envp[]) {
{
// start up fuse
// use my argc, argv (make sure you pass a mount point!)
auto client_mountpoint = g_conf->get_val<std::string>(
auto client_mountpoint = g_conf().get_val<std::string>(
"client_mountpoint");
auto mountpoint = client_mountpoint.c_str();
auto fuse_require_active_mds = g_conf->get_val<bool>(
auto fuse_require_active_mds = g_conf().get_val<bool>(
"fuse_require_active_mds");
r = client->mount(mountpoint, perms, fuse_require_active_mds);
if (r < 0) {
Expand Down
24 changes: 12 additions & 12 deletions src/ceph_mds.cc
Original file line number Diff line number Diff line change
Expand Up @@ -119,9 +119,9 @@ int main(int argc, const char **argv)
dout(0) << "requesting standby_replay for mds." << r << dendl;
char rb[32];
snprintf(rb, sizeof(rb), "%d", r);
g_conf->set_val("mds_standby_for_rank", rb);
g_conf->set_val("mds_standby_replay", "true");
g_conf->apply_changes(NULL);
g_conf().set_val("mds_standby_for_rank", rb);
g_conf().set_val("mds_standby_replay", "true");
g_conf().apply_changes(nullptr);
}
else {
derr << "Error: can't understand argument: " << *i << "\n" << dendl;
Expand All @@ -135,14 +135,14 @@ int main(int argc, const char **argv)
pick_addresses(g_ceph_context, CEPH_PICK_ADDRESS_PUBLIC, &addrs);

// Normal startup
if (g_conf->name.has_default_id()) {
if (g_conf()->name.has_default_id()) {
derr << "must specify '-i name' with the ceph-mds instance name" << dendl;
exit(1);
}

if (g_conf->name.get_id().empty() ||
(g_conf->name.get_id()[0] >= '0' && g_conf->name.get_id()[0] <= '9')) {
derr << "MDS id '" << g_conf->name << "' is invalid. "
if (g_conf()->name.get_id().empty() ||
(g_conf()->name.get_id()[0] >= '0' && g_conf()->name.get_id()[0] <= '9')) {
derr << "MDS id '" << g_conf()->name << "' is invalid. "
"MDS names may not start with a numeric digit." << dendl;
exit(1);
}
Expand All @@ -167,15 +167,15 @@ int main(int argc, const char **argv)

auto nonce = ceph::util::generate_random_number<uint64_t>();

std::string public_msgr_type = g_conf->ms_public_type.empty() ? g_conf->get_val<std::string>("ms_type") : g_conf->ms_public_type;
std::string public_msgr_type = g_conf()->ms_public_type.empty() ? g_conf().get_val<std::string>("ms_type") : g_conf()->ms_public_type;
Messenger *msgr = Messenger::create(g_ceph_context, public_msgr_type,
entity_name_t::MDS(-1), "mds",
nonce, Messenger::HAS_MANY_CONNECTIONS);
if (!msgr)
forker.exit(1);
msgr->set_cluster_protocol(CEPH_MDS_PROTOCOL);

cout << "starting " << g_conf->name << " at " << msgr->get_myaddrs()
cout << "starting " << g_conf()->name << " at " << msgr->get_myaddrs()
<< std::endl;
uint64_t required =
CEPH_FEATURE_OSDREPLYMUX;
Expand Down Expand Up @@ -206,13 +206,13 @@ int main(int argc, const char **argv)
msgr->start();

// start mds
mds = new MDSDaemon(g_conf->name.get_id().c_str(), msgr, &mc);
mds = new MDSDaemon(g_conf()->name.get_id().c_str(), msgr, &mc);

// in case we have to respawn...
mds->orig_argc = argc;
mds->orig_argv = argv;

if (g_conf->daemonize) {
if (g_conf()->daemonize) {
global_init_postfork_finish(g_ceph_context);
forker.daemonize();
}
Expand All @@ -226,7 +226,7 @@ int main(int argc, const char **argv)
register_async_signal_handler_oneshot(SIGINT, handle_mds_signal);
register_async_signal_handler_oneshot(SIGTERM, handle_mds_signal);

if (g_conf->inject_early_sigterm)
if (g_conf()->inject_early_sigterm)
kill(getpid(), SIGTERM);

msgr->wait();
Expand Down
4 changes: 2 additions & 2 deletions src/ceph_mon.cc
Original file line number Diff line number Diff line change
Expand Up @@ -118,9 +118,9 @@ int check_mon_data_exists()
/** Check whether **mon data** is empty.
*
* Being empty means mkfs has not been run and there's no monitor setup
* at **g_conf->mon_data**.
* at **g_conf()->mon_data**.
*
* If the directory g_conf->mon_data is not empty we will return -ENOTEMPTY.
* If the directory g_conf()->mon_data is not empty we will return -ENOTEMPTY.
* Otherwise we will return 0. Any other negative returns will represent
* a failure to be handled by the caller.
*
Expand Down
4 changes: 2 additions & 2 deletions src/client/Client.cc
Original file line number Diff line number Diff line change
Expand Up @@ -5963,7 +5963,7 @@ void Client::tick()
if (cct->_conf->client_debug_inject_tick_delay > 0) {
sleep(cct->_conf->client_debug_inject_tick_delay);
assert(0 == cct->_conf.set_val("client_debug_inject_tick_delay", "0"));
cct->_conf.apply_changes(NULL);
cct->_conf.apply_changes(nullptr);
}

ldout(cct, 21) << "tick" << dendl;
Expand Down Expand Up @@ -13949,7 +13949,7 @@ const char** Client::get_tracked_conf_keys() const
return keys;
}

void Client::handle_conf_change(const md_config_t *conf,
void Client::handle_conf_change(const ConfigProxy& conf,
const std::set <std::string> &changed)
{
Mutex::Locker lock(client_lock);
Expand Down
2 changes: 1 addition & 1 deletion src/client/Client.h
Original file line number Diff line number Diff line change
Expand Up @@ -1250,7 +1250,7 @@ class Client : public Dispatcher, public md_config_obs_t {
int test_dentry_handling(bool can_invalidate);

const char** get_tracked_conf_keys() const override;
void handle_conf_change(const md_config_t *conf,
void handle_conf_change(const ConfigProxy& conf,
const std::set <std::string> &changed) override;
uint32_t get_deleg_timeout() { return deleg_timeout; }
int set_deleg_timeout(uint32_t timeout);
Expand Down
36 changes: 18 additions & 18 deletions src/client/fuse_ll.cc
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@ static int getgroups(fuse_req_t req, gid_t **sgids)

static void get_fuse_groups(UserPerm& perms, fuse_req_t req)
{
if (g_conf->get_val<bool>("fuse_set_user_groups")) {
if (g_conf().get_val<bool>("fuse_set_user_groups")) {
gid_t *gids = NULL;
int count = getgroups(req, &gids);

Expand Down Expand Up @@ -411,9 +411,9 @@ static void fuse_ll_mkdir(fuse_req_t req, fuse_ino_t parent, const char *name,
UserPerm perm(ctx->uid, ctx->gid);
get_fuse_groups(perm, req);
#ifdef HAVE_SYS_SYNCFS
auto fuse_multithreaded = cfuse->client->cct->_conf->get_val<bool>(
auto fuse_multithreaded = cfuse->client->cct->_conf.get_val<bool>(
"fuse_multithreaded");
auto fuse_syncfs_on_mksnap = cfuse->client->cct->_conf->get_val<bool>(
auto fuse_syncfs_on_mksnap = cfuse->client->cct->_conf.get_val<bool>(
"fuse_syncfs_on_mksnap");
if (cfuse->fino_snap(parent) == CEPH_SNAPDIR &&
fuse_multithreaded && fuse_syncfs_on_mksnap) {
Expand Down Expand Up @@ -576,9 +576,9 @@ 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)
auto fuse_disable_pagecache = cfuse->client->cct->_conf->get_val<bool>(
auto fuse_disable_pagecache = cfuse->client->cct->_conf.get_val<bool>(
"fuse_disable_pagecache");
auto fuse_use_invalidate_cb = cfuse->client->cct->_conf->get_val<bool>(
auto fuse_use_invalidate_cb = cfuse->client->cct->_conf.get_val<bool>(
"fuse_use_invalidate_cb");
if (fuse_disable_pagecache)
fi->direct_io = 1;
Expand Down Expand Up @@ -797,9 +797,9 @@ 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)
auto fuse_disable_pagecache = cfuse->client->cct->_conf->get_val<bool>(
auto fuse_disable_pagecache = cfuse->client->cct->_conf.get_val<bool>(
"fuse_disable_pagecache");
auto fuse_use_invalidate_cb = cfuse->client->cct->_conf->get_val<bool>(
auto fuse_use_invalidate_cb = cfuse->client->cct->_conf.get_val<bool>(
"fuse_use_invalidate_cb");
if (fuse_disable_pagecache)
fi->direct_io = 1;
Expand Down Expand Up @@ -852,7 +852,7 @@ static void fuse_ll_setlk(fuse_req_t req, fuse_ino_t ino,
Fh *fh = reinterpret_cast<Fh*>(fi->fh);

// must use multithread if operation may block
auto fuse_multithreaded = cfuse->client->cct->_conf->get_val<bool>(
auto fuse_multithreaded = cfuse->client->cct->_conf.get_val<bool>(
"fuse_multithreaded");
if (!fuse_multithreaded && sleep && lock->l_type != F_UNLCK) {
fuse_reply_err(req, EDEADLK);
Expand Down Expand Up @@ -888,7 +888,7 @@ 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
auto fuse_multithreaded = cfuse->client->cct->_conf->get_val<bool>(
auto fuse_multithreaded = cfuse->client->cct->_conf.get_val<bool>(
"fuse_multithreaded");
if (!fuse_multithreaded && !(cmd & (LOCK_NB | LOCK_UN))) {
fuse_reply_err(req, EDEADLK);
Expand Down Expand Up @@ -956,7 +956,7 @@ static void do_init(void *data, fuse_conn_info *conn)
Client *client = cfuse->client;

#if !defined(__APPLE__)
auto fuse_default_permissions = client->cct->_conf->get_val<bool>(
auto fuse_default_permissions = client->cct->_conf.get_val<bool>(
"fuse_default_permissions");
if (!fuse_default_permissions && client->ll_handle_umask()) {
// apply umask in userspace if posix acl is enabled
Expand Down Expand Up @@ -1093,17 +1093,17 @@ int CephFuse::Handle::init(int argc, const char *argv[])
newargv[newargc++] = argv[0];
newargv[newargc++] = "-f"; // stay in foreground

auto fuse_allow_other = client->cct->_conf->get_val<bool>(
auto fuse_allow_other = client->cct->_conf.get_val<bool>(
"fuse_allow_other");
auto fuse_default_permissions = client->cct->_conf->get_val<bool>(
auto fuse_default_permissions = client->cct->_conf.get_val<bool>(
"fuse_default_permissions");
auto fuse_big_writes = client->cct->_conf->get_val<bool>(
auto fuse_big_writes = client->cct->_conf.get_val<bool>(
"fuse_big_writes");
auto fuse_atomic_o_trunc = client->cct->_conf->get_val<bool>(
auto fuse_atomic_o_trunc = client->cct->_conf.get_val<bool>(
"fuse_atomic_o_trunc");
auto fuse_debug = client->cct->_conf->get_val<bool>(
auto fuse_debug = client->cct->_conf.get_val<bool>(
"fuse_debug");
auto fuse_max_write = client->cct->_conf->get_val<uint64_t>(
auto fuse_max_write = client->cct->_conf.get_val<uint64_t>(
"fuse_max_write");

if (fuse_allow_other) {
Expand Down Expand Up @@ -1179,7 +1179,7 @@ int CephFuse::Handle::start()

struct client_callback_args args = {
handle: this,
ino_cb: client->cct->_conf->get_val<bool>("fuse_use_invalidate_cb") ?
ino_cb: client->cct->_conf.get_val<bool>("fuse_use_invalidate_cb") ?
ino_invalidate_cb : NULL,
dentry_cb: dentry_invalidate_cb,
switch_intr_cb: switch_interrupt_cb,
Expand All @@ -1197,7 +1197,7 @@ int CephFuse::Handle::start()

int CephFuse::Handle::loop()
{
auto fuse_multithreaded = client->cct->_conf->get_val<bool>(
auto fuse_multithreaded = client->cct->_conf.get_val<bool>(
"fuse_multithreaded");
if (fuse_multithreaded) {
return fuse_session_loop_mt(se);
Expand Down
4 changes: 2 additions & 2 deletions src/common/TracepointProvider.cc
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,9 @@ TracepointProvider::~TracepointProvider() {
}

void TracepointProvider::handle_conf_change(
const md_config_t *conf, const std::set<std::string> &changed) {
const ConfigProxy& conf, const std::set<std::string> &changed) {
if (changed.count(m_config_keys[0])) {
verify_config(ConfigProxy{conf});
verify_config(conf);
}
}

Expand Down
4 changes: 2 additions & 2 deletions src/common/TracepointProvider.h
Original file line number Diff line number Diff line change
Expand Up @@ -65,8 +65,8 @@ class TracepointProvider : public md_config_obs_t {
const char** get_tracked_conf_keys() const override {
return m_config_keys;
}
void handle_conf_change(const md_config_t *conf,
const std::set <std::string> &changed) override;
void handle_conf_change(const ConfigProxy& conf,
const std::set <std::string> &changed) override;

private:
CephContext *m_cct;
Expand Down
4 changes: 2 additions & 2 deletions src/common/WorkQueue.cc
Original file line number Diff line number Diff line change
Expand Up @@ -62,12 +62,12 @@ ThreadPool::~ThreadPool()
delete[] _conf_keys;
}

void ThreadPool::handle_conf_change(const md_config_t *conf,
void ThreadPool::handle_conf_change(const ConfigProxy& conf,
const std::set <std::string> &changed)
{
if (changed.count(_thread_num_option)) {
char *buf;
int r = conf->get_val(_thread_num_option.c_str(), &buf, -1);
int r = conf.get_val(_thread_num_option.c_str(), &buf, -1);
assert(r >= 0);
int v = atoi(buf);
free(buf);
Expand Down
2 changes: 1 addition & 1 deletion src/common/WorkQueue.h
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ class ThreadPool : public md_config_obs_t {
const char **get_tracked_conf_keys() const override {
return _conf_keys;
}
void handle_conf_change(const md_config_t *conf,
void handle_conf_change(const ConfigProxy& conf,
const std::set <std::string> &changed) override;

public:
Expand Down
14 changes: 6 additions & 8 deletions src/common/ceph_context.cc
Original file line number Diff line number Diff line change
Expand Up @@ -61,12 +61,12 @@ class LockdepObs : public md_config_obs_t {
return KEYS;
}

void handle_conf_change(const md_config_t *conf,
void handle_conf_change(const ConfigProxy& conf,
const std::set <std::string> &changed) override {
if (conf->values.lockdep && !m_registered) {
if (conf->lockdep && !m_registered) {
lockdep_register_ceph_context(m_cct);
m_registered = true;
} else if (!conf->values.lockdep && m_registered) {
} else if (!conf->lockdep && m_registered) {
lockdep_unregister_ceph_context(m_cct);
m_registered = false;
}
Expand Down Expand Up @@ -104,7 +104,7 @@ class MempoolObs : public md_config_obs_t,
return KEYS;
}

void handle_conf_change(const md_config_t *conf,
void handle_conf_change(const ConfigProxy& conf,
const std::set <std::string> &changed) override {
if (changed.count("mempool_debug")) {
mempool::set_debug_mode(cct->_conf->mempool_debug);
Expand Down Expand Up @@ -224,9 +224,8 @@ class LogObs : public md_config_obs_t {
return KEYS;
}

void handle_conf_change(const md_config_t *mconf,
void handle_conf_change(const ConfigProxy& conf,
const std::set <std::string> &changed) override {
ConfigReader conf{mconf};
// stderr
if (changed.count("log_to_stderr") || changed.count("err_to_stderr")) {
int l = conf->log_to_stderr ? 99 : (conf->err_to_stderr ? -1 : -2);
Expand Down Expand Up @@ -306,11 +305,10 @@ class CephContextObs : public md_config_obs_t {
return KEYS;
}

void handle_conf_change(const md_config_t *mconf,
void handle_conf_change(const ConfigProxy& conf,
const std::set <std::string> &changed) override {
if (changed.count(
"enable_experimental_unrecoverable_data_corrupting_features")) {
ConfigReader conf{mconf};
std::lock_guard<ceph::spinlock> lg(cct->_feature_lock);
get_str_set(
conf->enable_experimental_unrecoverable_data_corrupting_features,
Expand Down
4 changes: 2 additions & 2 deletions src/common/common_init.h
Original file line number Diff line number Diff line change
Expand Up @@ -54,8 +54,8 @@ enum common_init_flags_t {
* the user asked for.
*
* This is usually done by something like this:
* cct->_conf->parse_env();
* cct->_conf->apply_changes();
* cct->_conf.parse_env();
* cct->_conf.apply_changes();
*
* Your library may also supply functions to read a configuration file.
*/
Expand Down
Loading

0 comments on commit f528475

Please sign in to comment.