]> git.proxmox.com Git - ceph.git/blob - ceph/src/rgw/rgw_frontend.cc
import 15.2.0 Octopus source
[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 int RGWFrontendConfig::parse_config(const string& config,
16 std::multimap<string, string>& config_map)
17 {
18 for (auto& entry : get_str_vec(config, " ")) {
19 string key;
20 string val;
21
22 if (framework.empty()) {
23 framework = entry;
24 dout(0) << "framework: " << framework << dendl;
25 continue;
26 }
27
28 ssize_t pos = entry.find('=');
29 if (pos < 0) {
30 dout(0) << "framework conf key: " << entry << dendl;
31 config_map.emplace(std::move(entry), "");
32 continue;
33 }
34
35 int ret = parse_key_value(entry, key, val);
36 if (ret < 0) {
37 cerr << "ERROR: can't parse " << entry << std::endl;
38 return ret;
39 }
40
41 dout(0) << "framework conf key: " << key << ", val: " << val << dendl;
42 config_map.emplace(std::move(key), std::move(val));
43 }
44
45 return 0;
46 }
47
48 void RGWFrontendConfig::set_default_config(RGWFrontendConfig& def_conf)
49 {
50 const auto& def_conf_map = def_conf.get_config_map();
51
52 for (auto& entry : def_conf_map) {
53 if (config_map.find(entry.first) == config_map.end()) {
54 config_map.emplace(entry.first, entry.second);
55 }
56 }
57 }
58
59 std::optional<string> RGWFrontendConfig::get_val(const std::string& key)
60 {
61 auto iter = config_map.find(key);
62 if (iter == config_map.end()) {
63 return std::nullopt;
64 }
65
66 return iter->second;
67 }
68
69 bool RGWFrontendConfig::get_val(const string& key, const string& def_val,
70 string *out)
71 {
72 auto iter = config_map.find(key);
73 if (iter == config_map.end()) {
74 *out = def_val;
75 return false;
76 }
77
78 *out = iter->second;
79 return true;
80 }
81
82 bool RGWFrontendConfig::get_val(const string& key, int def_val, int *out)
83 {
84 string str;
85 bool found = get_val(key, "", &str);
86 if (!found) {
87 *out = def_val;
88 return false;
89 }
90 string err;
91 *out = strict_strtol(str.c_str(), 10, &err);
92 if (!err.empty()) {
93 cerr << "error parsing int: " << str << ": " << err << std::endl;
94 return -EINVAL;
95 }
96 return 0;
97 }
98
99 void RGWProcessFrontend::stop()
100 {
101 pprocess->close_fd();
102 thread->kill(SIGUSR1);
103 }