]> git.proxmox.com Git - ceph.git/blob - ceph/src/common/subsys_types.h
update sources to ceph Nautilus 14.2.1
[ceph.git] / ceph / src / common / subsys_types.h
1 // -*- mode:C++; tab-width:8; c-basic-offset:2; indent-tabs-mode:t -*-
2 // vim: ts=8 sw=2 smarttab
3 /*
4 * Ceph - scalable distributed file system
5 *
6 * Copyright (C) 2018 Red Hat Inc.
7 *
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.
12 *
13 */
14
15 #ifndef CEPH_SUBSYS_TYPES_H
16 #define CEPH_SUBSYS_TYPES_H
17
18 #include <algorithm>
19 #include <array>
20
21 enum ceph_subsys_id_t {
22 ceph_subsys_, // default
23 #define SUBSYS(name, log, gather) \
24 ceph_subsys_##name,
25 #define DEFAULT_SUBSYS(log, gather)
26 #include "common/subsys.h"
27 #undef SUBSYS
28 #undef DEFAULT_SUBSYS
29 ceph_subsys_max
30 };
31
32 constexpr static std::size_t ceph_subsys_get_num() {
33 return static_cast<std::size_t>(ceph_subsys_max);
34 }
35
36 struct ceph_subsys_item_t {
37 const char* name;
38 uint8_t log_level;
39 uint8_t gather_level;
40 };
41
42 constexpr static std::array<ceph_subsys_item_t, ceph_subsys_get_num()>
43 ceph_subsys_get_as_array() {
44 #define SUBSYS(name, log, gather) \
45 ceph_subsys_item_t{ #name, log, gather },
46 #define DEFAULT_SUBSYS(log, gather) \
47 ceph_subsys_item_t{ "none", log, gather },
48
49 return {
50 #include "common/subsys.h"
51 };
52 #undef SUBSYS
53 #undef DEFAULT_SUBSYS
54 }
55
56 constexpr static std::uint8_t
57 ceph_subsys_get_max_default_level(const std::size_t subidx) {
58 const auto item = ceph_subsys_get_as_array()[subidx];
59 return std::max(item.log_level, item.gather_level);
60 }
61
62 // Compile time-capable version of std::strlen. Resorting to own
63 // implementation only because C++17 doesn't mandate constexpr
64 // on the standard one.
65 constexpr static std::size_t strlen_ct(const char* const s) {
66 std::size_t l = 0;
67 while (s[l] != '\0') {
68 ++l;
69 }
70 return l;
71 }
72
73 constexpr static std::size_t ceph_subsys_max_name_length() {
74 return std::max({
75 #define SUBSYS(name, log, gather) \
76 strlen_ct(#name),
77 #define DEFAULT_SUBSYS(log, gather) \
78 strlen_ct("none"),
79 #include "common/subsys.h"
80 #undef SUBSYS
81 #undef DEFAULT_SUBSYS
82 });
83 }
84
85 #endif // CEPH_SUBSYS_TYPES_H
86