]> git.proxmox.com Git - ceph.git/blob - ceph/src/mgr/Mgr.h
import 15.2.0 Octopus source
[ceph.git] / ceph / src / mgr / Mgr.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) 2014 John Spray <john.spray@inktank.com>
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 #ifndef CEPH_MGR_H_
15 #define CEPH_MGR_H_
16
17 // Python.h comes first because otherwise it clobbers ceph's assert
18 #include <Python.h>
19
20 #include "mds/FSMap.h"
21 #include "messages/MFSMap.h"
22 #include "msg/Messenger.h"
23 #include "auth/Auth.h"
24 #include "common/Finisher.h"
25 #include "mon/MgrMap.h"
26
27 #include "DaemonServer.h"
28 #include "PyModuleRegistry.h"
29
30 #include "DaemonState.h"
31 #include "ClusterState.h"
32
33 class MCommand;
34 class MMgrDigest;
35 class MLog;
36 class MServiceMap;
37 class Objecter;
38 class Client;
39
40 class Mgr : public AdminSocketHook {
41 protected:
42 MonClient *monc;
43 Objecter *objecter;
44 Client *client;
45 Messenger *client_messenger;
46
47 mutable ceph::mutex lock = ceph::make_mutex("Mgr::lock");
48 Finisher finisher;
49
50 // Track receipt of initial data during startup
51 ceph::condition_variable fs_map_cond;
52 bool digest_received;
53 ceph::condition_variable digest_cond;
54
55 PyModuleRegistry *py_module_registry;
56 DaemonStateIndex daemon_state;
57 ClusterState cluster_state;
58
59 DaemonServer server;
60
61 LogChannelRef clog;
62 LogChannelRef audit_clog;
63
64 void load_all_metadata();
65 std::map<std::string, std::string> load_store();
66 void init();
67
68 bool initialized;
69 bool initializing;
70
71 public:
72 Mgr(MonClient *monc_, const MgrMap& mgrmap,
73 PyModuleRegistry *py_module_registry_,
74 Messenger *clientm_, Objecter *objecter_,
75 Client *client_, LogChannelRef clog_, LogChannelRef audit_clog_);
76 ~Mgr();
77
78 bool is_initialized() const {return initialized;}
79 entity_addrvec_t get_server_addrs() const {
80 return server.get_myaddrs();
81 }
82
83 void handle_mgr_digest(ceph::ref_t<MMgrDigest> m);
84 void handle_fs_map(ceph::ref_t<MFSMap> m);
85 void handle_osd_map();
86 void handle_log(ceph::ref_t<MLog> m);
87 void handle_service_map(ceph::ref_t<MServiceMap> m);
88 void handle_mon_map();
89
90 bool got_mgr_map(const MgrMap& m);
91
92 bool ms_dispatch2(const ceph::ref_t<Message>& m);
93
94 void background_init(Context *completion);
95 void shutdown();
96
97 void handle_signal(int signum);
98
99 std::map<std::string, std::string> get_services() const;
100
101 int call(
102 std::string_view command,
103 const cmdmap_t& cmdmap,
104 Formatter *f,
105 std::ostream& errss,
106 ceph::buffer::list& out) override;
107 };
108
109 /**
110 * Context for completion of metadata mon commands: take
111 * the result and stash it in DaemonStateIndex
112 */
113 class MetadataUpdate : public Context
114 {
115
116 private:
117 DaemonStateIndex &daemon_state;
118 DaemonKey key;
119
120 std::map<std::string, std::string> defaults;
121
122 public:
123 bufferlist outbl;
124 std::string outs;
125
126 MetadataUpdate(DaemonStateIndex &daemon_state_, const DaemonKey &key_)
127 : daemon_state(daemon_state_), key(key_)
128 {
129 daemon_state.notify_updating(key);
130 }
131
132 void set_default(const std::string &k, const std::string &v)
133 {
134 defaults[k] = v;
135 }
136
137 void finish(int r) override;
138 };
139
140
141 #endif