]> git.proxmox.com Git - ceph.git/blob - ceph/src/rgw/rgw_frontend.cc
bump version to 18.2.2-pve1
[ceph.git] / ceph / src / rgw / rgw_frontend.cc
1 // -*- mode:C++; tab-width:8; c-basic-offset:2; indent-tabs-mode:t -*-
2 // vim: ts=8 sw=2 smarttab ft=cpp
3
4 #include <signal.h>
5
6 #include "rgw_frontend.h"
7 #include "include/str_list.h"
8
9 #include "include/ceph_assert.h"
10
11
12 #define dout_context g_ceph_context
13 #define dout_subsys ceph_subsys_rgw
14
15 using namespace std;
16
17 int RGWFrontendConfig::parse_config(const string& config,
18 std::multimap<string, string>& config_map)
19 {
20 for (auto& entry : get_str_vec(config, " ")) {
21 string key;
22 string val;
23
24 if (framework.empty()) {
25 framework = entry;
26 dout(0) << "framework: " << framework << dendl;
27 continue;
28 }
29
30 ssize_t pos = entry.find('=');
31 if (pos < 0) {
32 dout(0) << "framework conf key: " << entry << dendl;
33 config_map.emplace(std::move(entry), "");
34 continue;
35 }
36
37 int ret = parse_key_value(entry, key, val);
38 if (ret < 0) {
39 cerr << "ERROR: can't parse " << entry << std::endl;
40 return ret;
41 }
42
43 dout(0) << "framework conf key: " << key << ", val: " << val << dendl;
44 config_map.emplace(std::move(key), std::move(val));
45 }
46
47 return 0;
48 }
49
50 void RGWFrontendConfig::set_default_config(RGWFrontendConfig& def_conf)
51 {
52 const auto& def_conf_map = def_conf.get_config_map();
53
54 for (auto& entry : def_conf_map) {
55 if (config_map.find(entry.first) == config_map.end()) {
56 config_map.emplace(entry.first, entry.second);
57 }
58 }
59 }
60
61 std::optional<string> RGWFrontendConfig::get_val(const std::string& key)
62 {
63 auto iter = config_map.find(key);
64 if (iter == config_map.end()) {
65 return std::nullopt;
66 }
67
68 return iter->second;
69 }
70
71 bool RGWFrontendConfig::get_val(const string& key, const string& def_val,
72 string *out)
73 {
74 auto iter = config_map.find(key);
75 if (iter == config_map.end()) {
76 *out = def_val;
77 return false;
78 }
79
80 *out = iter->second;
81 return true;
82 }
83
84 bool RGWFrontendConfig::get_val(const string& key, int def_val, int *out)
85 {
86 string str;
87 bool found = get_val(key, "", &str);
88 if (!found) {
89 *out = def_val;
90 return false;
91 }
92 string err;
93 *out = strict_strtol(str.c_str(), 10, &err);
94 if (!err.empty()) {
95 cerr << "error parsing int: " << str << ": " << err << std::endl;
96 return -EINVAL;
97 }
98 return 0;
99 }
100
101 void RGWProcessFrontend::stop()
102 {
103 pprocess->close_fd();
104 thread->kill(SIGUSR1);
105 }