summaryrefslogtreecommitdiffstats
path: root/src/mds/MDSMap.h
diff options
context:
space:
mode:
authorKefu Chai <kchai@redhat.com>2019-04-29 11:04:26 +0200
committerKefu Chai <kchai@redhat.com>2019-05-04 08:51:27 +0200
commitdf771861f1b9fbb1e1e5a60e4afddadff5b67c69 (patch)
tree3bd64904082e2f44e9609350288d2597df64c510 /src/mds/MDSMap.h
parentcommon/admin_socket: use ceph_release_to_str() for release name (diff)
downloadceph-df771861f1b9fbb1e1e5a60e4afddadff5b67c69.tar.xz
ceph-df771861f1b9fbb1e1e5a60e4afddadff5b67c69.zip
src/: define ceph_release_t and use it
we have following pains when it comes to ceph release related programming: * we use int, uint8_t, uint32_t, unsigned int for representing the ceph release, i.e., jewel, luminous, nautilus, in different places in our source tree. * we always need to add a comment aside of `uint8_t release` to help the folks to understand that it is CEPH_RELEASE_*. * also we keep forgetting that "os << release" actually prints the release as an ASCII. * and it's painful to remember that we have to translate the release number using `ceph_release_name()` before print it out in the human readable format. * we replicate the n+2 upgrade policy in multiple places in this change, `ceph_release_t` and some helper functions are intruduced to alleviate the pains above. * add a scoped enum for representing ceph releases, so the release is typed . which means that we can attach different function to it. and in future, we can even replace `ceph_release_t` with a class if we need to support more fancy features which cannot be implemented using free functions. * add `ostream<<()` operator for `ceph_release_t`, so we can simply send it to `ostream` * add `can_upgrade_from()` so we don't need to repeat ourselves. * move ceph_release_from_name() to ceph_release.{h,cc}, as currently, ceph_release.cc uses `ceph_release_name()` for implementing `ostream<<()`, and after this change, `ceph_release_from_name()` will return `ceph_release_t`, so if we keep `ceph_release_from_name()` where it was, these two headers will be included by each other, which is a no-go. * reimplement `ceph_release_from_name()` using a loop. before this change, `ceph_release_from_name()` was implemented using a manually unrolled if-else structure, which is more performant, but the downside is that, it replicates mapping between release number and its name. so after this change, a loop is used instead. as this function is not used in the critical path, so this change should not have visible impact on the performance. * always use ceph_release_t::unknown as the default value of the "release" member variables. before this change, sometimes, we use "0" and sometimes we use "1", after inspecting the code, i found that "0" is good enough to cover all the use cases. and since "0" is a magic number in this context, it is replaced using `ceph_release_t::unknown`. to facilidate the checking against `ceph_release_t::unknown`, `operator!()` is added. * ceph::to_string() and ceph::to_integer<>() are added to help to remove the asssumption of the underlying type of `ceph_release_t`, ideally, users of `ceph_release_t` should not use `static_cast<>` to cast it into integer types, instead, they should use `ceph::to_integer<>()` to do this job. if, in future, we want to use a `class` to represent `ceph_release_t`, we can get this done with minimum change, if `ceph::to_string()` and `ceph::to_string()` are used. we can not specialize them in `std` naming space. as it's claimed that it's undefined behavior to do so. see https://en.cppreference.com/w/cpp/language/extending_std . Signed-off-by: Kefu Chai <kchai@redhat.com>
Diffstat (limited to 'src/mds/MDSMap.h')
-rw-r--r--src/mds/MDSMap.h15
1 files changed, 8 insertions, 7 deletions
diff --git a/src/mds/MDSMap.h b/src/mds/MDSMap.h
index 0a9e50ab0e1..a4a562d5cb4 100644
--- a/src/mds/MDSMap.h
+++ b/src/mds/MDSMap.h
@@ -25,14 +25,15 @@
#include <errno.h>
#include "include/types.h"
-#include "common/Clock.h"
+#include "include/ceph_features.h"
#include "include/health.h"
+#include "include/CompatSet.h"
+#include "common/Clock.h"
+#include "common/Formatter.h"
+#include "common/ceph_releases.h"
#include "common/config.h"
-#include "include/CompatSet.h"
-#include "include/ceph_features.h"
-#include "common/Formatter.h"
#include "mds/mdstypes.h"
class CephContext;
@@ -172,7 +173,7 @@ protected:
__u32 session_autoclose = 300;
uint64_t max_file_size = 1ULL<<40; /* 1TB */
- int8_t min_compat_client = -1;
+ ceph_release_t min_compat_client{ceph_release_t::unknown};
std::vector<int64_t> data_pools; // file data pools available to clients (via an ioctl). first is the default.
int64_t cas_pool = -1; // where CAS objects go
@@ -235,8 +236,8 @@ public:
uint64_t get_max_filesize() const { return max_file_size; }
void set_max_filesize(uint64_t m) { max_file_size = m; }
- uint8_t get_min_compat_client() const { return min_compat_client; }
- void set_min_compat_client(uint8_t version) { min_compat_client = version; }
+ ceph_release_t get_min_compat_client() const { return min_compat_client; }
+ void set_min_compat_client(ceph_release_t version) { min_compat_client = version; }
int get_flags() const { return flags; }
bool test_flag(int f) const { return flags & f; }