1 // -*- mode:C++; tab-width:8; c-basic-offset:2; indent-tabs-mode:t -*-
2 // vim: ts=8 sw=2 smarttab
4 * Ceph - scalable distributed file system
6 * Copyright (C) 2004-2006 Sage Weil <sage@newdream.net>
8 * This is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU Lesser General Public
10 * License version 2.1, as published by the Free Software
11 * Foundation. See file COPYING.
15 #ifndef CEPH_MON_TYPES_H
16 #define CEPH_MON_TYPES_H
18 #include "include/utime.h"
19 #include "include/util.h"
20 #include "common/Formatter.h"
21 #include "common/bit_str.h"
22 #include "include/Context.h"
23 #include "mon/MonOpRequest.h"
25 #define PAXOS_PGMAP 0 // before osd, for pg kick to behave
26 #define PAXOS_MDSMAP 1
27 #define PAXOS_OSDMAP 2
29 #define PAXOS_MONMAP 4
34 inline const char *get_paxos_name(int p
) {
36 case PAXOS_MDSMAP
: return "mdsmap";
37 case PAXOS_MONMAP
: return "monmap";
38 case PAXOS_OSDMAP
: return "osdmap";
39 case PAXOS_PGMAP
: return "pgmap";
40 case PAXOS_LOG
: return "logm";
41 case PAXOS_AUTH
: return "auth";
42 case PAXOS_MGR
: return "mgr";
43 default: ceph_abort(); return 0;
47 #define CEPH_MON_ONDISK_MAGIC "ceph mon volume v012"
52 * If we ever decide to support multiple backends for the monitor store,
53 * we should then create an abstract class 'MonitorStoreStats' of sorts
54 * and inherit it on LevelDBStoreStats. I'm sure you'll figure something
57 struct LevelDBStoreStats
{
71 void dump(Formatter
*f
) const {
73 f
->dump_int("bytes_total", bytes_total
);
74 f
->dump_int("bytes_sst", bytes_sst
);
75 f
->dump_int("bytes_log", bytes_log
);
76 f
->dump_int("bytes_misc", bytes_misc
);
77 f
->dump_stream("last_updated") << last_update
;
80 void encode(bufferlist
&bl
) const {
81 ENCODE_START(1, 1, bl
);
82 ::encode(bytes_total
, bl
);
83 ::encode(bytes_sst
, bl
);
84 ::encode(bytes_log
, bl
);
85 ::encode(bytes_misc
, bl
);
86 ::encode(last_update
, bl
);
90 void decode(bufferlist::iterator
&p
) {
92 ::decode(bytes_total
, p
);
93 ::decode(bytes_sst
, p
);
94 ::decode(bytes_log
, p
);
95 ::decode(bytes_misc
, p
);
96 ::decode(last_update
, p
);
100 static void generate_test_instances(list
<LevelDBStoreStats
*>& ls
) {
101 ls
.push_back(new LevelDBStoreStats
);
102 ls
.push_back(new LevelDBStoreStats
);
103 ls
.back()->bytes_total
= 1024*1024;
104 ls
.back()->bytes_sst
= 512*1024;
105 ls
.back()->bytes_log
= 256*1024;
106 ls
.back()->bytes_misc
= 256*1024;
107 ls
.back()->last_update
= utime_t();
110 WRITE_CLASS_ENCODER(LevelDBStoreStats
)
115 ceph_data_stats_t fs_stats
;
118 LevelDBStoreStats store_stats
;
120 void dump(Formatter
*f
) const {
122 f
->dump_int("kb_total", (fs_stats
.byte_total
/1024));
123 f
->dump_int("kb_used", (fs_stats
.byte_used
/1024));
124 f
->dump_int("kb_avail", (fs_stats
.byte_avail
/1024));
125 f
->dump_int("avail_percent", fs_stats
.avail_percent
);
126 f
->dump_stream("last_updated") << last_update
;
127 f
->open_object_section("store_stats");
132 void encode(bufferlist
&bl
) const {
133 ENCODE_START(3, 1, bl
);
134 ::encode(fs_stats
.byte_total
, bl
);
135 ::encode(fs_stats
.byte_used
, bl
);
136 ::encode(fs_stats
.byte_avail
, bl
);
137 ::encode(fs_stats
.avail_percent
, bl
);
138 ::encode(last_update
, bl
);
139 ::encode(store_stats
, bl
);
142 void decode(bufferlist::iterator
&p
) {
144 // we moved from having fields in kb to fields in byte
146 ::decode(fs_stats
.byte_total
, p
);
147 ::decode(fs_stats
.byte_used
, p
);
148 ::decode(fs_stats
.byte_avail
, p
);
152 fs_stats
.byte_total
= t
*1024;
154 fs_stats
.byte_used
= t
*1024;
156 fs_stats
.byte_avail
= t
*1024;
158 ::decode(fs_stats
.avail_percent
, p
);
159 ::decode(last_update
, p
);
161 ::decode(store_stats
, p
);
166 WRITE_CLASS_ENCODER(DataStats
)
169 map
<string
,uint32_t> prefix_crc
; ///< prefix -> crc
170 map
<string
,uint64_t> prefix_keys
; ///< prefix -> key count
172 bool operator!=(const ScrubResult
& other
) {
173 return prefix_crc
!= other
.prefix_crc
|| prefix_keys
!= other
.prefix_keys
;
176 void encode(bufferlist
& bl
) const {
177 ENCODE_START(1, 1, bl
);
178 ::encode(prefix_crc
, bl
);
179 ::encode(prefix_keys
, bl
);
182 void decode(bufferlist::iterator
& p
) {
184 ::decode(prefix_crc
, p
);
185 ::decode(prefix_keys
, p
);
188 void dump(Formatter
*f
) const {
189 f
->open_object_section("crc");
190 for (map
<string
,uint32_t>::const_iterator p
= prefix_crc
.begin(); p
!= prefix_crc
.end(); ++p
)
191 f
->dump_unsigned(p
->first
.c_str(), p
->second
);
193 f
->open_object_section("keys");
194 for (map
<string
,uint64_t>::const_iterator p
= prefix_keys
.begin(); p
!= prefix_keys
.end(); ++p
)
195 f
->dump_unsigned(p
->first
.c_str(), p
->second
);
198 static void generate_test_instances(list
<ScrubResult
*>& ls
) {
199 ls
.push_back(new ScrubResult
);
200 ls
.push_back(new ScrubResult
);
201 ls
.back()->prefix_crc
["foo"] = 123;
202 ls
.back()->prefix_keys
["bar"] = 456;
205 WRITE_CLASS_ENCODER(ScrubResult
)
207 static inline ostream
& operator<<(ostream
& out
, const ScrubResult
& r
) {
208 return out
<< "ScrubResult(keys " << r
.prefix_keys
<< " crc " << r
.prefix_crc
<< ")";
211 /// for information like os, kernel, hostname, memory info, cpu model.
212 typedef map
<string
, string
> Metadata
;
214 struct C_MonOp
: public Context
218 explicit C_MonOp(MonOpRequestRef o
) :
221 void finish(int r
) override
{
222 if (op
&& r
== -ECANCELED
) {
223 op
->mark_event("callback canceled");
224 } else if (op
&& r
== -EAGAIN
) {
225 op
->mark_event("callback retry");
226 } else if (op
&& r
== 0) {
227 op
->mark_event("callback finished");
232 void mark_op_event(const string
&event
) {
234 op
->mark_event_string(event
);
237 virtual void _finish(int r
) = 0;
244 * Get a feature's name based on its value.
246 * @param b raw feature value
249 * Consumers should not assume this interface will never change.
251 * As the number of features increase, so may the internal representation
252 * of the raw features. When this happens, this interface will change
253 * accordingly. So should consumers of this interface.
255 static inline const char *get_feature_name(uint64_t b
);
261 inline const char *ceph_mon_feature_name(uint64_t b
)
263 return ceph::features::mon::get_feature_name(b
);
266 class mon_feature_t
{
268 static const int HEAD_VERSION
= 1;
269 static const int COMPAT_VERSION
= 1;
271 // mon-specific features
277 mon_feature_t(const uint64_t f
) : features(f
) { }
283 mon_feature_t(const mon_feature_t
&o
) :
284 features(o
.features
) { }
286 mon_feature_t
& operator&=(const mon_feature_t other
) {
287 features
&= other
.features
;
292 * Obtain raw features
295 * Consumers should not assume this interface will never change.
297 * As the number of features increase, so may the internal representation
298 * of the raw features. When this happens, this interface will change
299 * accordingly. So should consumers of this interface.
301 uint64_t get_raw() const {
306 friend mon_feature_t
operator&(const mon_feature_t a
,
307 const mon_feature_t b
) {
308 return mon_feature_t(a
.features
& b
.features
);
311 mon_feature_t
& operator|=(const mon_feature_t other
) {
312 features
|= other
.features
;
317 friend mon_feature_t
operator|(const mon_feature_t a
,
318 const mon_feature_t b
) {
319 return mon_feature_t(a
.features
| b
.features
);
323 friend mon_feature_t
operator^(const mon_feature_t a
,
324 const mon_feature_t b
) {
325 return mon_feature_t(a
.features
^ b
.features
);
328 mon_feature_t
& operator^=(const mon_feature_t other
) {
329 features
^= other
.features
;
333 bool operator==(const mon_feature_t other
) const {
334 return (features
== other
.features
);
337 bool operator!=(const mon_feature_t other
) const {
338 return (features
!= other
.features
);
342 return features
== 0;
346 * Set difference of our features in respect to @p other
348 * Returns all the elements in our features that are not in @p other
350 * @returns all the features not in @p other
352 mon_feature_t
diff(const mon_feature_t other
) const {
353 return mon_feature_t((features
^ other
.features
) & features
);
357 * Set intersection of our features and @p other
359 * Returns all the elements common to both our features and the
360 * features of @p other
362 * @returns the features common to @p other and us
364 mon_feature_t
intersection(const mon_feature_t other
) const {
365 return mon_feature_t((features
& other
.features
));
369 * Checks whether we have all the features in @p other
371 * Returns true if we have all the features in @p other
373 * @returns true if we contain all the features in @p other
374 * @returns false if we do not contain some of the features in @p other
376 bool contains_all(const mon_feature_t other
) const {
377 mon_feature_t d
= intersection(other
);
382 * Checks whether we contain any of the features in @p other.
384 * @returns true if we contain any of the features in @p other
385 * @returns false if we don't contain any of the features in @p other
387 bool contains_any(const mon_feature_t other
) const {
388 mon_feature_t d
= intersection(other
);
392 void set_feature(const mon_feature_t f
) {
393 features
|= f
.features
;
396 void unset_feature(const mon_feature_t f
) {
397 features
&= ~(f
.features
);
400 void print(ostream
& out
) const {
402 print_bit_str(features
, out
, ceph::features::mon::get_feature_name
);
406 void print_with_value(ostream
& out
) const {
408 print_bit_str(features
, out
, ceph::features::mon::get_feature_name
, true);
412 void dump(Formatter
*f
, const char *sec_name
= NULL
) const {
413 f
->open_array_section((sec_name
? sec_name
: "features"));
414 dump_bit_str(features
, f
, ceph::features::mon::get_feature_name
);
418 void dump_with_value(Formatter
*f
, const char *sec_name
= NULL
) const {
419 f
->open_array_section((sec_name
? sec_name
: "features"));
420 dump_bit_str(features
, f
, ceph::features::mon::get_feature_name
, true);
424 void encode(bufferlist
& bl
) const {
425 ENCODE_START(HEAD_VERSION
, COMPAT_VERSION
, bl
);
426 ::encode(features
, bl
);
429 void decode(bufferlist::iterator
& p
) {
430 DECODE_START(COMPAT_VERSION
, p
);
431 ::decode(features
, p
);
435 WRITE_CLASS_ENCODER(mon_feature_t
)
440 constexpr mon_feature_t
FEATURE_KRAKEN( (1ULL << 0));
441 constexpr mon_feature_t
FEATURE_LUMINOUS( (1ULL << 1));
443 constexpr mon_feature_t
FEATURE_RESERVED( (1ULL << 63));
444 constexpr mon_feature_t
FEATURE_NONE( (0ULL));
447 * All the features this monitor supports
449 * If there's a feature above, it should be OR'ed to this list.
451 constexpr mon_feature_t
get_supported() {
459 * All the features that, once set, cannot be removed.
461 * Features should only be added to this list if you want to make
462 * sure downgrades are not possible after a quorum supporting all
463 * these features has been formed.
465 * Any feature in this list will be automatically set on the monmap's
466 * features once all the monitors in the quorum support it.
468 constexpr mon_feature_t
get_persistent() {
476 static inline mon_feature_t
get_feature_by_name(std::string n
);
481 static inline const char *ceph::features::mon::get_feature_name(uint64_t b
) {
484 if (f
== FEATURE_KRAKEN
) {
486 } else if (f
== FEATURE_LUMINOUS
) {
488 } else if (f
== FEATURE_RESERVED
) {
495 mon_feature_t
ceph::features::mon::get_feature_by_name(std::string n
) {
498 return FEATURE_KRAKEN
;
499 } else if (n
== "luminous") {
500 return FEATURE_LUMINOUS
;
501 } else if (n
== "reserved") {
502 return FEATURE_RESERVED
;
507 static inline ostream
& operator<<(ostream
& out
, const mon_feature_t
& f
) {
508 out
<< "mon_feature_t(";