]>
Commit | Line | Data |
---|---|---|
7c673cae FG |
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/Cond.h" | |
18 | #include "common/Mutex.h" | |
19 | #include "common/RWLock.h" | |
20 | #include "common/Timer.h" | |
21 | #include "include/rados/librados.h" | |
22 | #include "include/rados/librados.hpp" | |
23 | #include "mon/MonClient.h" | |
24 | #include "mgr/MgrClient.h" | |
25 | #include "msg/Dispatcher.h" | |
26 | ||
27 | #include "IoCtxImpl.h" | |
28 | ||
29 | struct AuthAuthorizer; | |
30 | class CephContext; | |
31 | struct Connection; | |
32 | struct md_config_t; | |
33 | class Message; | |
34 | class MLog; | |
35 | class Messenger; | |
36 | class AioCompletionImpl; | |
37 | ||
38 | class librados::RadosClient : public Dispatcher | |
39 | { | |
40 | std::unique_ptr<CephContext, | |
41 | std::function<void(CephContext*)> > cct_deleter; | |
42 | ||
43 | public: | |
44 | using Dispatcher::cct; | |
45 | md_config_t *conf; | |
46 | private: | |
47 | enum { | |
48 | DISCONNECTED, | |
49 | CONNECTING, | |
50 | CONNECTED, | |
51 | } state; | |
52 | ||
53 | MonClient monclient; | |
54 | MgrClient mgrclient; | |
55 | Messenger *messenger; | |
56 | ||
57 | uint64_t instance_id; | |
58 | ||
59 | bool _dispatch(Message *m); | |
60 | bool ms_dispatch(Message *m) override; | |
61 | ||
62 | bool ms_get_authorizer(int dest_type, AuthAuthorizer **authorizer, bool force_new) override; | |
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 | Mutex lock; | |
71 | Cond cond; | |
72 | SafeTimer timer; | |
73 | int refcnt; | |
74 | ||
75 | version_t log_last_version; | |
76 | rados_log_callback_t log_cb; | |
31f18b77 | 77 | rados_log_callback2_t log_cb2; |
7c673cae FG |
78 | void *log_cb_arg; |
79 | string log_watch; | |
80 | ||
81 | int wait_for_osdmap(); | |
82 | ||
83 | public: | |
84 | Finisher finisher; | |
85 | ||
86 | explicit RadosClient(CephContext *cct_); | |
87 | ~RadosClient() override; | |
88 | int ping_monitor(string mon_id, string *result); | |
89 | int connect(); | |
90 | void shutdown(); | |
91 | ||
92 | int watch_flush(); | |
93 | int async_watch_flush(AioCompletionImpl *c); | |
94 | ||
95 | uint64_t get_instance_id(); | |
96 | ||
97 | int wait_for_latest_osdmap(); | |
98 | ||
99 | int create_ioctx(const char *name, IoCtxImpl **io); | |
100 | int create_ioctx(int64_t, IoCtxImpl **io); | |
101 | ||
102 | int get_fsid(std::string *s); | |
103 | int64_t lookup_pool(const char *name); | |
104 | bool pool_requires_alignment(int64_t pool_id); | |
105 | int pool_requires_alignment2(int64_t pool_id, bool *requires); | |
106 | uint64_t pool_required_alignment(int64_t pool_id); | |
107 | int pool_required_alignment2(int64_t pool_id, uint64_t *alignment); | |
108 | int pool_get_auid(uint64_t pool_id, unsigned long long *auid); | |
109 | int pool_get_name(uint64_t pool_id, std::string *auid); | |
110 | ||
111 | int pool_list(std::list<std::pair<int64_t, string> >& ls); | |
112 | int get_pool_stats(std::list<string>& ls, map<string,::pool_stat_t>& result); | |
113 | int get_fs_stats(ceph_statfs& result); | |
114 | bool get_pool_is_selfmanaged_snaps_mode(const std::string& pool); | |
115 | ||
116 | /* | |
117 | -1 was set as the default value and monitor will pickup the right crush rule with below order: | |
118 | a) osd pool default crush replicated ruleset | |
119 | b) the first ruleset in crush ruleset | |
120 | c) error out if no value find | |
121 | */ | |
122 | int pool_create(string& name, unsigned long long auid=0, int16_t crush_rule=-1); | |
123 | int pool_create_async(string& name, PoolAsyncCompletionImpl *c, unsigned long long auid=0, | |
124 | int16_t crush_rule=-1); | |
125 | int pool_get_base_tier(int64_t pool_id, int64_t* base_tier); | |
126 | int pool_delete(const char *name); | |
127 | ||
128 | int pool_delete_async(const char *name, PoolAsyncCompletionImpl *c); | |
129 | ||
130 | int blacklist_add(const string& client_address, uint32_t expire_seconds); | |
131 | ||
132 | int mon_command(const vector<string>& cmd, const bufferlist &inbl, | |
133 | bufferlist *outbl, string *outs); | |
134 | int mon_command(int rank, | |
135 | const vector<string>& cmd, const bufferlist &inbl, | |
136 | bufferlist *outbl, string *outs); | |
137 | int mon_command(string name, | |
138 | const vector<string>& cmd, const bufferlist &inbl, | |
139 | bufferlist *outbl, string *outs); | |
140 | int mgr_command(const vector<string>& cmd, const bufferlist &inbl, | |
141 | bufferlist *outbl, string *outs); | |
142 | int osd_command(int osd, vector<string>& cmd, const bufferlist& inbl, | |
143 | bufferlist *poutbl, string *prs); | |
144 | int pg_command(pg_t pgid, vector<string>& cmd, const bufferlist& inbl, | |
145 | bufferlist *poutbl, string *prs); | |
146 | ||
147 | void handle_log(MLog *m); | |
31f18b77 FG |
148 | int monitor_log(const string& level, rados_log_callback_t cb, |
149 | rados_log_callback2_t cb2, void *arg); | |
7c673cae FG |
150 | |
151 | void get(); | |
152 | bool put(); | |
153 | void blacklist_self(bool set); | |
154 | }; | |
155 | ||
156 | #endif |