]> git.proxmox.com Git - ceph.git/blob - ceph/src/librados/RadosClient.h
import 15.2.0 Octopus source
[ceph.git] / ceph / src / librados / RadosClient.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) 2004-2012 Sage Weil <sage@newdream.net>
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_LIBRADOS_RADOSCLIENT_H
15 #define CEPH_LIBRADOS_RADOSCLIENT_H
16
17 #include "common/config_fwd.h"
18 #include "common/Cond.h"
19 #include "common/Timer.h"
20 #include "common/ceph_mutex.h"
21 #include "common/ceph_time.h"
22 #include "include/common_fwd.h"
23 #include "include/rados/librados.h"
24 #include "include/rados/librados.hpp"
25 #include "mon/MonClient.h"
26 #include "mgr/MgrClient.h"
27 #include "msg/Dispatcher.h"
28
29 #include "IoCtxImpl.h"
30
31 struct AuthAuthorizer;
32 struct Context;
33 struct Connection;
34 class Message;
35 class MLog;
36 class Messenger;
37 class AioCompletionImpl;
38
39 class librados::RadosClient : public Dispatcher
40 {
41 std::unique_ptr<CephContext,
42 std::function<void(CephContext*)> > cct_deleter;
43
44 public:
45 using Dispatcher::cct;
46 const ConfigProxy& conf;
47 private:
48 enum {
49 DISCONNECTED,
50 CONNECTING,
51 CONNECTED,
52 } state;
53
54 MonClient monclient;
55 MgrClient mgrclient;
56 Messenger *messenger;
57
58 uint64_t instance_id;
59
60 bool _dispatch(Message *m);
61 bool ms_dispatch(Message *m) override;
62
63 void ms_handle_connect(Connection *con) override;
64 bool ms_handle_reset(Connection *con) override;
65 void ms_handle_remote_reset(Connection *con) override;
66 bool ms_handle_refused(Connection *con) override;
67
68 Objecter *objecter;
69
70 ceph::mutex lock = ceph::make_mutex("librados::RadosClient::lock");
71 ceph::condition_variable cond;
72 SafeTimer timer;
73 int refcnt;
74
75 version_t log_last_version;
76 rados_log_callback_t log_cb;
77 rados_log_callback2_t log_cb2;
78 void *log_cb_arg;
79 string log_watch;
80
81 bool service_daemon = false;
82 string daemon_name, service_name;
83 map<string,string> daemon_metadata;
84
85 int wait_for_osdmap();
86
87 public:
88 Finisher finisher;
89
90 explicit RadosClient(CephContext *cct_);
91 ~RadosClient() override;
92 int ping_monitor(string mon_id, string *result);
93 int connect();
94 void shutdown();
95
96 int watch_flush();
97 int async_watch_flush(AioCompletionImpl *c);
98
99 uint64_t get_instance_id();
100
101 int get_min_compatible_osd(int8_t* require_osd_release);
102 int get_min_compatible_client(int8_t* min_compat_client,
103 int8_t* require_min_compat_client);
104
105 int wait_for_latest_osdmap();
106
107 int create_ioctx(const char *name, IoCtxImpl **io);
108 int create_ioctx(int64_t, IoCtxImpl **io);
109
110 int get_fsid(std::string *s);
111 int64_t lookup_pool(const char *name);
112 bool pool_requires_alignment(int64_t pool_id);
113 int pool_requires_alignment2(int64_t pool_id, bool *requires);
114 uint64_t pool_required_alignment(int64_t pool_id);
115 int pool_required_alignment2(int64_t pool_id, uint64_t *alignment);
116 int pool_get_name(uint64_t pool_id, std::string *name,
117 bool wait_latest_map = false);
118
119 int pool_list(std::list<std::pair<int64_t, string> >& ls);
120 int get_pool_stats(std::list<string>& ls, map<string,::pool_stat_t> *result,
121 bool *per_pool);
122 int get_fs_stats(ceph_statfs& result);
123 bool get_pool_is_selfmanaged_snaps_mode(const std::string& pool);
124
125 /*
126 -1 was set as the default value and monitor will pickup the right crush rule with below order:
127 a) osd pool default crush replicated ruleset
128 b) the first ruleset in crush ruleset
129 c) error out if no value find
130 */
131 int pool_create(string& name, int16_t crush_rule=-1);
132 int pool_create_async(string& name, PoolAsyncCompletionImpl *c,
133 int16_t crush_rule=-1);
134 int pool_get_base_tier(int64_t pool_id, int64_t* base_tier);
135 int pool_delete(const char *name);
136
137 int pool_delete_async(const char *name, PoolAsyncCompletionImpl *c);
138
139 int blacklist_add(const string& client_address, uint32_t expire_seconds);
140
141 int mon_command(const vector<string>& cmd, const bufferlist &inbl,
142 bufferlist *outbl, string *outs);
143 void mon_command_async(const vector<string>& cmd, const bufferlist &inbl,
144 bufferlist *outbl, string *outs, Context *on_finish);
145 int mon_command(int rank,
146 const vector<string>& cmd, const bufferlist &inbl,
147 bufferlist *outbl, string *outs);
148 int mon_command(string name,
149 const vector<string>& cmd, const bufferlist &inbl,
150 bufferlist *outbl, string *outs);
151 int mgr_command(const vector<string>& cmd, const bufferlist &inbl,
152 bufferlist *outbl, string *outs);
153 int mgr_command(
154 const string& name,
155 const vector<string>& cmd, const bufferlist &inbl,
156 bufferlist *outbl, string *outs);
157 int osd_command(int osd, vector<string>& cmd, const bufferlist& inbl,
158 bufferlist *poutbl, string *prs);
159 int pg_command(pg_t pgid, vector<string>& cmd, const bufferlist& inbl,
160 bufferlist *poutbl, string *prs);
161
162 void handle_log(MLog *m);
163 int monitor_log(const string& level, rados_log_callback_t cb,
164 rados_log_callback2_t cb2, void *arg);
165
166 void get();
167 bool put();
168 void blacklist_self(bool set);
169
170 std::string get_addrs() const;
171
172 int service_daemon_register(
173 const std::string& service, ///< service name (e.g., 'rgw')
174 const std::string& name, ///< daemon name (e.g., 'gwfoo')
175 const std::map<std::string,std::string>& metadata); ///< static metadata about daemon
176 int service_daemon_update_status(
177 std::map<std::string,std::string>&& status);
178
179 mon_feature_t get_required_monitor_features() const;
180
181 int get_inconsistent_pgs(int64_t pool_id, std::vector<std::string>* pgs);
182 };
183
184 #endif