Fix some bugs when testing opensds ansible
[stor4nfv.git] / src / 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/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 struct Context;
31 class CephContext;
32 struct Connection;
33 struct md_config_t;
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   md_config_t *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   bool ms_get_authorizer(int dest_type, AuthAuthorizer **authorizer, bool force_new) override;
64   void ms_handle_connect(Connection *con) override;
65   bool ms_handle_reset(Connection *con) override;
66   void ms_handle_remote_reset(Connection *con) override;
67   bool ms_handle_refused(Connection *con) override;
68
69   Objecter *objecter;
70
71   Mutex lock;
72   Cond cond;
73   SafeTimer timer;
74   int refcnt;
75
76   version_t log_last_version;
77   rados_log_callback_t log_cb;
78   rados_log_callback2_t log_cb2;
79   void *log_cb_arg;
80   string log_watch;
81
82   bool service_daemon = false;
83   string daemon_name, service_name;
84   map<string,string> daemon_metadata;
85
86   int wait_for_osdmap();
87
88 public:
89   Finisher finisher;
90
91   explicit RadosClient(CephContext *cct_);
92   ~RadosClient() override;
93   int ping_monitor(string mon_id, string *result);
94   int connect();
95   void shutdown();
96
97   int watch_flush();
98   int async_watch_flush(AioCompletionImpl *c);
99
100   uint64_t get_instance_id();
101
102   int wait_for_latest_osdmap();
103
104   int create_ioctx(const char *name, IoCtxImpl **io);
105   int create_ioctx(int64_t, IoCtxImpl **io);
106
107   int get_fsid(std::string *s);
108   int64_t lookup_pool(const char *name);
109   bool pool_requires_alignment(int64_t pool_id);
110   int pool_requires_alignment2(int64_t pool_id, bool *requires);
111   uint64_t pool_required_alignment(int64_t pool_id);
112   int pool_required_alignment2(int64_t pool_id, uint64_t *alignment);
113   int pool_get_auid(uint64_t pool_id, unsigned long long *auid);
114   int pool_get_name(uint64_t pool_id, std::string *auid);
115
116   int pool_list(std::list<std::pair<int64_t, string> >& ls);
117   int get_pool_stats(std::list<string>& ls, map<string,::pool_stat_t>& result);
118   int get_fs_stats(ceph_statfs& result);
119   bool get_pool_is_selfmanaged_snaps_mode(const std::string& pool);
120
121   /*
122   -1 was set as the default value and monitor will pickup the right crush rule with below order:
123     a) osd pool default crush replicated ruleset
124     b) the first ruleset in crush ruleset
125     c) error out if no value find
126   */
127   int pool_create(string& name, unsigned long long auid=0, int16_t crush_rule=-1);
128   int pool_create_async(string& name, PoolAsyncCompletionImpl *c, unsigned long long auid=0,
129                         int16_t crush_rule=-1);
130   int pool_get_base_tier(int64_t pool_id, int64_t* base_tier);
131   int pool_delete(const char *name);
132
133   int pool_delete_async(const char *name, PoolAsyncCompletionImpl *c);
134
135   int blacklist_add(const string& client_address, uint32_t expire_seconds);
136
137   int mon_command(const vector<string>& cmd, const bufferlist &inbl,
138                   bufferlist *outbl, string *outs);
139   void mon_command_async(const vector<string>& cmd, const bufferlist &inbl,
140                          bufferlist *outbl, string *outs, Context *on_finish);
141   int mon_command(int rank,
142                   const vector<string>& cmd, const bufferlist &inbl,
143                   bufferlist *outbl, string *outs);
144   int mon_command(string name,
145                   const vector<string>& cmd, const bufferlist &inbl,
146                   bufferlist *outbl, string *outs);
147   int mgr_command(const vector<string>& cmd, const bufferlist &inbl,
148                   bufferlist *outbl, string *outs);
149   int osd_command(int osd, vector<string>& cmd, const bufferlist& inbl,
150                   bufferlist *poutbl, string *prs);
151   int pg_command(pg_t pgid, vector<string>& cmd, const bufferlist& inbl,
152                  bufferlist *poutbl, string *prs);
153
154   void handle_log(MLog *m);
155   int monitor_log(const string& level, rados_log_callback_t cb,
156                   rados_log_callback2_t cb2, void *arg);
157
158   void get();
159   bool put();
160   void blacklist_self(bool set);
161
162   int service_daemon_register(
163     const std::string& service,  ///< service name (e.g., 'rgw')
164     const std::string& name,     ///< daemon name (e.g., 'gwfoo')
165     const std::map<std::string,std::string>& metadata); ///< static metadata about daemon
166   int service_daemon_update_status(
167     const std::map<std::string,std::string>& status);
168
169   mon_feature_t get_required_monitor_features() const;
170 };
171
172 #endif