g_conf.id = strdup("admin");
}
+int md_config_t::set_val(const char *key, const char *val)
+{
+ if (!key)
+ return -EINVAL;
+ if (!val)
+ return -EINVAL;
+ for (int i = 0; i<num_config_options; ++i) {
+ config_option *opt = &config_optionsp[i];
+ if (strcmp(opt->conf_name, key))
+ continue;
+
+ switch (opt->type) {
+ case OPT_NONE:
+ return -ENOSYS;
+ case OPT_INT:
+ *(int*)opt->val_ptr = atoi(val);
+ return 0;
+ case OPT_LONGLONG:
+ *(long long*)opt->val_ptr = atoll(val);
+ return 0;
+ case OPT_STR: {
+ char *p = (char*)opt->val_ptr;
+ free(p);
+ opt->val_ptr = strdup(val);
+ return 0;
+ }
+ case OPT_FLOAT:
+ *(float*)opt->val_ptr = atof(val);
+ return 0;
+ case OPT_DOUBLE:
+ *(double*)opt->val_ptr = atof(val);
+ return 0;
+ case OPT_BOOL:
+ *(bool*)opt->val_ptr = !!atoi(val);
+ return 0;
+ case OPT_U32:
+ *(int*)opt->val_ptr = atoi(val);
+ return 0;
+ case OPT_ADDR: {
+ entity_addr_t *addr = (entity_addr_t*)opt->val_ptr;
+ if (!addr->parse(val)) {
+ return -EINVAL;
+ }
+ return 0;
+ }
+ }
+ }
+ // couldn't find a configuration option with key 'key'
+ return -ENOENT;
+}
+
+int md_config_t::get_val(const char *key, char **buf, int len)
+{
+ if (!key)
+ return -EINVAL;
+ for (int i = 0; i<num_config_options; ++i) {
+ const config_option *opt = &config_optionsp[i];
+ if (strcmp(opt->conf_name, key))
+ continue;
+
+ ostringstream oss;
+ switch (opt->type) {
+ case OPT_NONE:
+ return -ENOSYS;
+ case OPT_INT:
+ oss << *(int*)opt->val_ptr;
+ break;
+ case OPT_LONGLONG:
+ oss << *(long long*)opt->val_ptr;
+ break;
+ case OPT_STR:
+ if (opt->val_ptr)
+ oss << (char*)opt->val_ptr;
+ break;
+ case OPT_FLOAT:
+ oss << *(float*)opt->val_ptr;
+ break;
+ case OPT_DOUBLE:
+ oss << *(double*)opt->val_ptr;
+ break;
+ case OPT_BOOL:
+ oss << *(bool*)opt->val_ptr;
+ break;
+ case OPT_U32:
+ oss << *(uint32_t*)opt->val_ptr;
+ break;
+ case OPT_ADDR: {
+ oss << *(entity_addr_t*)opt->val_ptr;
+ break;
+ }
+ }
+ string str(oss.str());
+ int l = strlen(oss.str().c_str()) + 1;
+ if (len == -1) {
+ *buf = (char*)malloc(l);
+ strcpy(*buf, oss.str().c_str());
+ return 0;
+ }
+ snprintf(*buf, len, "%s", oss.str().c_str());
+ return (l > len) ? -ENAMETOOLONG : 0;
+ }
+ // couldn't find a configuration option with key 'key'
+ return -ENOENT;
+}
+
md_config_t::~md_config_t()
{
int len = sizeof(config_optionsp)/sizeof(config_option);
struct md_config_t {
md_config_t();
~md_config_t();
+ int get_val(const char *key, char **buf, int len);
+ int set_val(const char *key, const char *val);
ConfFile *cf;
}
}
-static void sighup_handler(int signum)
+void sighup_handler(int signum)
{
// All this does is set a few bits telling us to re-open our logfiles and
// restart our central logging service.
void install_sighandler(int signum, signal_handler_t handler, int flags);
+// handles SIGHUP
+void sighup_handler(int signum);
+
// Install the standard Ceph signal handlers
void install_standard_sighandlers(void);
/* config */
int rados_conf_parse_argv(rados_t cluster, int argc, const char **argv);
int rados_conf_read_file(rados_t cluster, const char *path);
+
+/* 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);
-const char *rados_conf_get(rados_t cluster, const char *option);
+
+/* Returns a configuration value as a string.
+ * If len is positive, that is the maximum number of bytes we'll write into the
+ * buffer. If len == -1, we'll call malloc() and set *buf.
+ * Returns 0 on success, error code otherwise. Returns ENAMETOOLONG if the
+ * buffer is too short. */
+int rados_conf_get(rados_t cluster, const char *option, char **buf, int len);
/* pools */
int rados_pool_open(rados_t cluster, const char *name, rados_pool_t *pool);
extern "C" int rados_conf_set(rados_t cluster, const char *option, const char *value)
{
- return 0;
+ int ret = g_conf.set_val(option, value);
+ if (ret == 0) {
+ // Simulate SIGHUP after a configuration change.
+ sighup_handler(SIGHUP);
+ }
+ return ret;
}
-extern "C" const char *rados_conf_get(rados_t cluster, const char *option)
+extern "C" int rados_conf_get(rados_t cluster, const char *option, char **buf, int len)
{
- return 0;
+ return g_conf.get_val(option, buf, len);
}
-
-extern "C" int rados_pool_lookup(rados_t cluster, const char *name)
+extern "C" int rados_lookup_pool(rados_t cluster, const char *name)
{
RadosClient *radosp = (RadosClient *)cluster;
return radosp->lookup_pool(name);