From 19fcec84d8d7d21e796c7624e521b60d28ee21ed Mon Sep 17 00:00:00 2001 From: Daniel Baumann Date: Sun, 7 Apr 2024 20:45:59 +0200 Subject: Adding upstream version 16.2.11+ds. Signed-off-by: Daniel Baumann --- src/mgr/ClusterState.h | 163 +++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 163 insertions(+) create mode 100644 src/mgr/ClusterState.h (limited to 'src/mgr/ClusterState.h') diff --git a/src/mgr/ClusterState.h b/src/mgr/ClusterState.h new file mode 100644 index 000000000..eeff1f76b --- /dev/null +++ b/src/mgr/ClusterState.h @@ -0,0 +1,163 @@ +// -*- mode:C++; tab-width:8; c-basic-offset:2; indent-tabs-mode:t -*- +// vim: ts=8 sw=2 smarttab +/* + * Ceph - scalable distributed file system + * + * Copyright (C) 2014 John Spray + * + * This is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License version 2.1, as published by the Free Software + * Foundation. See file COPYING. + */ + +#ifndef CLUSTER_STATE_H_ +#define CLUSTER_STATE_H_ + +#include "mds/FSMap.h" +#include "mon/MgrMap.h" +#include "common/ceph_mutex.h" + +#include "osdc/Objecter.h" +#include "mon/MonClient.h" +#include "mon/PGMap.h" +#include "mgr/ServiceMap.h" + +class MMgrDigest; +class MMonMgrReport; +class MPGStats; + + +/** + * Cluster-scope state (things like cluster maps) as opposed + * to daemon-level state (things like perf counters and smart) + */ +class ClusterState +{ +protected: + MonClient *monc; + Objecter *objecter; + FSMap fsmap; + ServiceMap servicemap; + mutable ceph::mutex lock = ceph::make_mutex("ClusterState"); + + MgrMap mgr_map; + + map existing_pools; ///< pools that exist, and pg_num, as of PGMap epoch + PGMap pg_map; + PGMap::Incremental pending_inc; + + bufferlist health_json; + bufferlist mon_status_json; + + class ClusterSocketHook *asok_hook; + +public: + + void load_digest(MMgrDigest *m); + void ingest_pgstats(ceph::ref_t stats); + + void update_delta_stats(); + + ClusterState(MonClient *monc_, Objecter *objecter_, const MgrMap& mgrmap); + + void set_objecter(Objecter *objecter_); + void set_fsmap(FSMap const &new_fsmap); + void set_mgr_map(MgrMap const &new_mgrmap); + void set_service_map(ServiceMap const &new_service_map); + + void notify_osdmap(const OSDMap &osd_map); + + bool have_fsmap() const { + std::lock_guard l(lock); + return fsmap.get_epoch() > 0; + } + + template + auto with_servicemap(Callback&& cb, Args&&...args) const + { + std::lock_guard l(lock); + return std::forward(cb)(servicemap, std::forward(args)...); + } + + template + auto with_fsmap(Callback&& cb, Args&&...args) const + { + std::lock_guard l(lock); + return std::forward(cb)(fsmap, std::forward(args)...); + } + + template + auto with_mgrmap(Callback&& cb, Args&&...args) const + { + std::lock_guard l(lock); + return std::forward(cb)(mgr_map, std::forward(args)...); + } + + template + auto with_pgmap(Callback&& cb, Args&&...args) const -> + decltype(cb(pg_map, std::forward(args)...)) + { + std::lock_guard l(lock); + return std::forward(cb)(pg_map, std::forward(args)...); + } + + template + auto with_mutable_pgmap(Callback&& cb, Args&&...args) -> + decltype(cb(pg_map, std::forward(args)...)) + { + std::lock_guard l(lock); + return std::forward(cb)(pg_map, std::forward(args)...); + } + + template + auto with_monmap(Args &&... args) const + { + std::lock_guard l(lock); + ceph_assert(monc != nullptr); + return monc->with_monmap(std::forward(args)...); + } + + template + auto with_osdmap(Args &&... args) const -> + decltype(objecter->with_osdmap(std::forward(args)...)) + { + ceph_assert(objecter != nullptr); + return objecter->with_osdmap(std::forward(args)...); + } + + // call cb(osdmap, pg_map, ...args) with the appropriate locks + template + auto with_osdmap_and_pgmap(Callback&& cb, Args&& ...args) const { + ceph_assert(objecter != nullptr); + std::lock_guard l(lock); + return objecter->with_osdmap( + std::forward(cb), + pg_map, + std::forward(args)...); + } + + template + auto with_health(Callback&& cb, Args&&...args) const + { + std::lock_guard l(lock); + return std::forward(cb)(health_json, std::forward(args)...); + } + + template + auto with_mon_status(Callback&& cb, Args&&...args) const + { + std::lock_guard l(lock); + return std::forward(cb)(mon_status_json, std::forward(args)...); + } + + void final_init(); + void shutdown(); + bool asok_command(std::string_view admin_command, + const cmdmap_t& cmdmap, + Formatter *f, + ostream& ss); +}; + +#endif + -- cgit v1.2.3