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) 2014 John Spray <john.spray@inktank.com>
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.
14 #ifndef CLUSTER_STATE_H_
15 #define CLUSTER_STATE_H_
17 #include "mds/FSMap.h"
18 #include "mon/MgrMap.h"
19 #include "common/ceph_mutex.h"
21 #include "osdc/Objecter.h"
22 #include "mon/MonClient.h"
23 #include "mon/PGMap.h"
24 #include "mgr/ServiceMap.h"
32 * Cluster-scope state (things like cluster maps) as opposed
33 * to daemon-level state (things like perf counters and smart)
41 ServiceMap servicemap
;
42 mutable ceph::mutex lock
= ceph::make_mutex("ClusterState");
46 std::map
<int64_t,unsigned> existing_pools
; ///< pools that exist, and pg_num, as of PGMap epoch
48 PGMap::Incremental pending_inc
;
50 bufferlist health_json
;
51 bufferlist mon_status_json
;
53 class ClusterSocketHook
*asok_hook
;
57 void load_digest(MMgrDigest
*m
);
58 void ingest_pgstats(ceph::ref_t
<MPGStats
> stats
);
60 void update_delta_stats();
62 ClusterState(MonClient
*monc_
, Objecter
*objecter_
, const MgrMap
& mgrmap
);
64 void set_objecter(Objecter
*objecter_
);
65 void set_fsmap(FSMap
const &new_fsmap
);
66 void set_mgr_map(MgrMap
const &new_mgrmap
);
67 void set_service_map(ServiceMap
const &new_service_map
);
69 void notify_osdmap(const OSDMap
&osd_map
);
71 bool have_fsmap() const {
72 std::lock_guard
l(lock
);
73 return fsmap
.get_epoch() > 0;
76 template<typename Callback
, typename
...Args
>
77 auto with_servicemap(Callback
&& cb
, Args
&&...args
) const
79 std::lock_guard
l(lock
);
80 return std::forward
<Callback
>(cb
)(servicemap
, std::forward
<Args
>(args
)...);
83 template<typename Callback
, typename
...Args
>
84 auto with_fsmap(Callback
&& cb
, Args
&&...args
) const
86 std::lock_guard
l(lock
);
87 return std::forward
<Callback
>(cb
)(fsmap
, std::forward
<Args
>(args
)...);
90 template<typename Callback
, typename
...Args
>
91 auto with_mgrmap(Callback
&& cb
, Args
&&...args
) const
93 std::lock_guard
l(lock
);
94 return std::forward
<Callback
>(cb
)(mgr_map
, std::forward
<Args
>(args
)...);
97 template<typename Callback
, typename
...Args
>
98 auto with_pgmap(Callback
&& cb
, Args
&&...args
) const ->
99 decltype(cb(pg_map
, std::forward
<Args
>(args
)...))
101 std::lock_guard
l(lock
);
102 return std::forward
<Callback
>(cb
)(pg_map
, std::forward
<Args
>(args
)...);
105 template<typename Callback
, typename
...Args
>
106 auto with_mutable_pgmap(Callback
&& cb
, Args
&&...args
) ->
107 decltype(cb(pg_map
, std::forward
<Args
>(args
)...))
109 std::lock_guard
l(lock
);
110 return std::forward
<Callback
>(cb
)(pg_map
, std::forward
<Args
>(args
)...);
113 template<typename
... Args
>
114 auto with_monmap(Args
&&... args
) const
116 std::lock_guard
l(lock
);
117 ceph_assert(monc
!= nullptr);
118 return monc
->with_monmap(std::forward
<Args
>(args
)...);
121 template<typename
... Args
>
122 auto with_osdmap(Args
&&... args
) const ->
123 decltype(objecter
->with_osdmap(std::forward
<Args
>(args
)...))
125 ceph_assert(objecter
!= nullptr);
126 return objecter
->with_osdmap(std::forward
<Args
>(args
)...);
129 // call cb(osdmap, pg_map, ...args) with the appropriate locks
130 template <typename Callback
, typename
...Args
>
131 auto with_osdmap_and_pgmap(Callback
&& cb
, Args
&& ...args
) const {
132 ceph_assert(objecter
!= nullptr);
133 std::lock_guard
l(lock
);
134 return objecter
->with_osdmap(
135 std::forward
<Callback
>(cb
),
137 std::forward
<Args
>(args
)...);
140 template<typename Callback
, typename
...Args
>
141 auto with_health(Callback
&& cb
, Args
&&...args
) const
143 std::lock_guard
l(lock
);
144 return std::forward
<Callback
>(cb
)(health_json
, std::forward
<Args
>(args
)...);
147 template<typename Callback
, typename
...Args
>
148 auto with_mon_status(Callback
&& cb
, Args
&&...args
) const
150 std::lock_guard
l(lock
);
151 return std::forward
<Callback
>(cb
)(mon_status_json
, std::forward
<Args
>(args
)...);
156 bool asok_command(std::string_view admin_command
,
157 const cmdmap_t
& cmdmap
,