]> git.proxmox.com Git - ceph.git/blob - ceph/src/mon/ConfigMap.h
update source to Ceph Pacific 16.2.2
[ceph.git] / ceph / src / mon / ConfigMap.h
1 // -*- mode:C++; tab-width:8; c-basic-offset:2; indent-tabs-mode:t -*-
2 // vim: ts=8 sw=2 smarttab
3
4 #pragma once
5
6 #include <map>
7 #include <ostream>
8 #include <string>
9
10 #include "include/utime.h"
11 #include "common/options.h"
12 #include "common/entity_name.h"
13
14 class CrushWrapper;
15
16 // the precedence is thus:
17 //
18 // global
19 // crush location (coarse to fine, ordered by type id)
20 // daemon type (e.g., osd)
21 // device class (osd only)
22 // crush location (coarse to fine, ordered by type id)
23 // daemon name (e.g., mds.foo)
24 //
25 // Note that this means that if we have
26 //
27 // config/host:foo/a = 1
28 // config/osd/rack:foo/a = 2
29 //
30 // then we get a = 2. The osd-level config wins, even though rack
31 // is less precise than host, because the crush limiters are only
32 // resolved within a section (global, per-daemon, per-instance).
33
34 struct OptionMask {
35 std::string location_type, location_value; ///< matches crush_location
36 std::string device_class; ///< matches device class
37
38 bool empty() const {
39 return location_type.size() == 0
40 && location_value.size() == 0
41 && device_class.size() == 0;
42 }
43
44 std::string to_str() const {
45 std::string r;
46 if (location_type.size()) {
47 r += location_type + ":" + location_value;
48 }
49 if (device_class.size()) {
50 if (r.size()) {
51 r += "/";
52 }
53 r += "class:" + device_class;
54 }
55 return r;
56 }
57 void dump(ceph::Formatter *f) const;
58 };
59
60 struct MaskedOption {
61 std::string raw_value; ///< raw, unparsed, unvalidated value
62 const Option *opt; ///< the option
63 OptionMask mask;
64 std::unique_ptr<const Option> unknown_opt; ///< if fabricated for an unknown option
65
66 MaskedOption(const Option *o, bool fab=false) : opt(o) {
67 if (fab) {
68 unknown_opt.reset(o);
69 }
70 }
71 MaskedOption(MaskedOption&& o) {
72 raw_value = std::move(o.raw_value);
73 opt = o.opt;
74 mask = std::move(o.mask);
75 unknown_opt = std::move(o.unknown_opt);
76 }
77 const MaskedOption& operator=(const MaskedOption& o) = delete;
78 const MaskedOption& operator=(MaskedOption&& o) = delete;
79
80 /// return a precision metric (smaller is more precise)
81 int get_precision(const CrushWrapper *crush);
82
83 friend std::ostream& operator<<(std::ostream& out, const MaskedOption& o);
84
85 void dump(ceph::Formatter *f) const;
86 };
87
88 struct Section {
89 std::multimap<std::string,MaskedOption> options;
90
91 void clear() {
92 options.clear();
93 }
94 void dump(ceph::Formatter *f) const;
95 std::string get_minimal_conf() const;
96 };
97
98 struct ConfigMap {
99 Section global;
100 std::map<std::string,Section, std::less<>> by_type;
101 std::map<std::string,Section, std::less<>> by_id;
102 std::list<std::unique_ptr<Option>> stray_options;
103
104 Section *find_section(const std::string& name) {
105 if (name == "global") {
106 return &global;
107 }
108 auto i = by_type.find(name);
109 if (i != by_type.end()) {
110 return &i->second;
111 }
112 i = by_id.find(name);
113 if (i != by_id.end()) {
114 return &i->second;
115 }
116 return nullptr;
117 }
118 void clear() {
119 global.clear();
120 by_type.clear();
121 by_id.clear();
122 stray_options.clear();
123 }
124 void dump(ceph::Formatter *f) const;
125 std::map<std::string,std::string,std::less<>> generate_entity_map(
126 const EntityName& name,
127 const std::map<std::string,std::string>& crush_location,
128 const CrushWrapper *crush,
129 const std::string& device_class,
130 std::map<std::string,std::pair<std::string,const MaskedOption*>> *src=0);
131
132 void parse_key(
133 const std::string& key,
134 std::string *name,
135 std::string *who);
136 static bool parse_mask(
137 const std::string& in,
138 std::string *section,
139 OptionMask *mask);
140 };
141
142
143 struct ConfigChangeSet {
144 version_t version;
145 utime_t stamp;
146 std::string name;
147
148 // key -> (old value, new value)
149 std::map<std::string,std::pair<boost::optional<std::string>,boost::optional<std::string>>> diff;
150
151 void dump(ceph::Formatter *f) const;
152 void print(std::ostream& out) const;
153 };