From 923c60c58811722ba936721d6a67a0e09ffcf0ce Mon Sep 17 00:00:00 2001 From: Sage Weil Date: Mon, 12 Sep 2011 10:56:37 -0700 Subject: [PATCH] librados: add conf_parse_env() With optional env var name, defaults to CEPH_ARGS. Parse it for librados and librbd api gtests. Signed-off-by: Sage Weil --- src/common/ceph_argparse.cc | 9 ++++++--- src/common/ceph_argparse.h | 2 +- src/common/config.cc | 3 +-- src/include/rados/librados.h | 2 ++ src/include/rados/librados.hpp | 1 + src/librados.cc | 18 ++++++++++++++++++ src/test/rados-api/test.cc | 2 ++ 7 files changed, 31 insertions(+), 6 deletions(-) diff --git a/src/common/ceph_argparse.cc b/src/common/ceph_argparse.cc index b4dbfd70c962e..641586de11c5c 100644 --- a/src/common/ceph_argparse.cc +++ b/src/common/ceph_argparse.cc @@ -45,10 +45,13 @@ #undef generic_dout #undef dendl -void env_to_vec(std::vector& args) +void env_to_vec(std::vector& args, const char *name) { - char *p = getenv("CEPH_ARGS"); - if (!p) return; + if (!name) + name = "CEPH_ARGS"; + char *p = getenv(name); + if (!p) + return; static char buf[1000]; int len = MIN(strlen(p), sizeof(buf)-1); // bleh. diff --git a/src/common/ceph_argparse.h b/src/common/ceph_argparse.h index 50168be41251a..bcad8e65b7ac4 100644 --- a/src/common/ceph_argparse.h +++ b/src/common/ceph_argparse.h @@ -43,7 +43,7 @@ public: }; /////////////////////// Functions /////////////////////// -extern void env_to_vec(std::vector& args); +extern void env_to_vec(std::vector& args, const char *name=NULL); extern void argv_to_vec(int argc, const char **argv, std::vector& args); extern void vec_to_argv(std::vector& args, diff --git a/src/common/config.cc b/src/common/config.cc index 94170c5779b61..22dc4e17697a6 100644 --- a/src/common/config.cc +++ b/src/common/config.cc @@ -587,8 +587,7 @@ parse_config_files_impl(const std::list &conf_files, return 0; } -void md_config_t:: -parse_env() +void md_config_t::parse_env() { Mutex::Locker l(lock); if (internal_safe_to_start_threads) diff --git a/src/include/rados/librados.h b/src/include/rados/librados.h index c86b3953addef..98702883c0763 100644 --- a/src/include/rados/librados.h +++ b/src/include/rados/librados.h @@ -85,6 +85,8 @@ int rados_conf_read_file(rados_t cluster, const char *path); /* Parse argv */ int rados_conf_parse_argv(rados_t cluster, int argc, const char **argv); +int rados_conf_parse_env(rados_t cluster, const char *var); + /* Sets a configuration value from a string. * Returns 0 on success, error code otherwise. */ int rados_conf_set(rados_t cluster, const char *option, const char *value); diff --git a/src/include/rados/librados.hpp b/src/include/rados/librados.hpp index bd41f16036496..c5c448a470fd8 100644 --- a/src/include/rados/librados.hpp +++ b/src/include/rados/librados.hpp @@ -345,6 +345,7 @@ namespace librados void shutdown(); int conf_read_file(const char * const path) const; int conf_parse_argv(int argc, const char ** argv) const; + int conf_parse_env(const char *env) const; int conf_set(const char *option, const char *value); int conf_get(const char *option, std::string &val); diff --git a/src/librados.cc b/src/librados.cc index c2d6d0b3e00f9..14fa2b1fb01ac 100644 --- a/src/librados.cc +++ b/src/librados.cc @@ -3151,6 +3151,11 @@ int librados::Rados::conf_parse_argv(int argc, const char ** argv) const return rados_conf_parse_argv((rados_t)client, argc, argv); } +int librados::Rados::conf_parse_env(const char *name) const +{ + return rados_conf_parse_env((rados_t)client, name); +} + int librados::Rados::conf_set(const char *option, const char *value) { return rados_conf_set((rados_t)client, option, value); @@ -3420,6 +3425,19 @@ extern "C" int rados_conf_parse_argv(rados_t cluster, int argc, const char **arg return 0; } +extern "C" int rados_conf_parse_env(rados_t cluster, const char *env) +{ + librados::RadosClient *client = (librados::RadosClient *)cluster; + md_config_t *conf = client->cct->_conf; + vector args; + env_to_vec(args, env); + int ret = conf->parse_argv(args); + if (ret) + return ret; + conf->apply_changes(NULL); + return 0; +} + extern "C" int rados_conf_set(rados_t cluster, const char *option, const char *value) { librados::RadosClient *client = (librados::RadosClient *)cluster; diff --git a/src/test/rados-api/test.cc b/src/test/rados-api/test.cc index ba9c5f2082edc..dd0c4f0f1f434 100644 --- a/src/test/rados-api/test.cc +++ b/src/test/rados-api/test.cc @@ -38,6 +38,7 @@ std::string create_one_pool(const std::string &pool_name, rados_t *cluster) oss << "rados_conf_read_file failed with error " << ret; return oss.str(); } + rados_conf_parse_env(*cluster, NULL); ret = rados_connect(*cluster); if (ret) { rados_shutdown(*cluster); @@ -71,6 +72,7 @@ std::string create_one_pool_pp(const std::string &pool_name, Rados &cluster) oss << "cluster.conf_read_file failed with error " << ret; return oss.str(); } + cluster.conf_parse_env(NULL); ret = cluster.connect(); if (ret) { cluster.shutdown(); -- 2.39.5