]>
Commit | Line | Data |
---|---|---|
f67539c2 TL |
1 | // -*- mode:C++; tab-width:8; c-basic-offset:2; indent-tabs-mode:t -*- |
2 | // vim: ts=8 sw=2 smarttab | |
3 | #ifndef METATOOL_H__ | |
4 | #define METATOOL_H__ | |
5 | ||
6 | #include "MDSUtility.h" | |
7 | #include "RoleSelector.h" | |
8 | #include <vector> | |
9 | #include <stack> | |
10 | using std::stack; | |
11 | #include "mds/mdstypes.h" | |
12 | #include "mds/LogEvent.h" | |
13 | #include "mds/events/EMetaBlob.h" | |
14 | ||
15 | #include "include/rados/librados.hpp" | |
16 | #include "common/ceph_json.h" | |
17 | ||
18 | using ::ceph::bufferlist; | |
19 | class MetaTool : public MDSUtility | |
20 | { | |
21 | public: | |
22 | class inode_meta_t { | |
23 | public: | |
24 | inode_meta_t(snapid_t f = CEPH_NOSNAP, char t = char(255), InodeStore* i = NULL): | |
25 | _f(f),_t(t),_i(i) { | |
26 | }; | |
27 | snapid_t get_snapid() const { | |
28 | return _f; | |
29 | } | |
30 | InodeStore* get_meta() const { | |
31 | if (_t == 'I') | |
32 | return _i; | |
33 | else | |
34 | return NULL; | |
35 | } | |
36 | int get_type() const { | |
37 | return _t; | |
38 | } | |
39 | void decode_json(JSONObj *obj); | |
40 | void encode(::ceph::bufferlist& bl, uint64_t features); | |
41 | private: | |
42 | snapid_t _f; | |
43 | char _t; | |
44 | InodeStore* _i; | |
45 | }; | |
46 | private: | |
47 | class meta_op { | |
48 | public: | |
49 | meta_op(bool debug = false, string out = "", string in = "", bool confirm = false): | |
50 | _debug(debug), | |
51 | _out(out), | |
52 | _in(in), | |
53 | _confirm(confirm) | |
54 | {} | |
55 | void release(); | |
56 | typedef enum { | |
57 | OP_LIST = 0, | |
58 | OP_LTRACE, | |
59 | OP_SHOW, | |
60 | OP_AMEND, | |
61 | OP_SHOW_FN, | |
62 | OP_AMEND_FN, | |
63 | OP_NO | |
64 | } op_type; | |
65 | ||
66 | typedef enum { | |
67 | INO_DIR = 0, | |
68 | INO_F | |
69 | } ino_type; | |
70 | ||
71 | static string op_type_name(op_type& t) { | |
72 | string name; | |
73 | switch (t) { | |
74 | case OP_LIST: | |
75 | name = "list dir"; | |
76 | break; | |
77 | case OP_LTRACE: | |
78 | name = "load trace"; | |
79 | break; | |
80 | case OP_SHOW: | |
81 | name = "show info"; | |
82 | break; | |
83 | case OP_AMEND: | |
84 | name = "amend info"; | |
85 | break; | |
86 | case OP_SHOW_FN: | |
87 | name = "show fnode"; | |
88 | break; | |
89 | case OP_AMEND_FN: | |
90 | name = "amend fnode"; | |
91 | break; | |
92 | case OP_NO: | |
93 | name = "noop"; | |
94 | break; | |
95 | default: | |
96 | name = "unknow op type"; | |
97 | } | |
98 | return name; | |
99 | } | |
100 | static string ino_type_name(ino_type& t) { | |
101 | string name; | |
102 | switch (t) { | |
103 | case INO_DIR: | |
104 | name = "dir"; | |
105 | break; | |
106 | case INO_F: | |
107 | name = "file"; | |
108 | break; | |
109 | default: | |
110 | name = "unknow file type"; | |
111 | } | |
112 | return name; | |
113 | } | |
114 | class sub_op { | |
115 | public: | |
116 | sub_op(meta_op* mop): | |
117 | trace_level(0), | |
118 | _proc(false), | |
119 | _mop(mop) | |
120 | {} | |
121 | void print() { | |
122 | std::cout << detail() << std::endl; | |
123 | } | |
124 | string detail() { | |
125 | std::stringstream ds; | |
126 | ds << " [sub_op]" << op_type_name(sub_op_t) << "|" | |
127 | << ino_type_name(sub_ino_t) << "|" | |
128 | << ino << "|" | |
129 | << frag << "|" | |
130 | << ino_c << "|" | |
131 | << trace_level << "|" | |
132 | << name; | |
133 | return ds.str(); | |
134 | } | |
135 | bool get_c_ancestor(inode_backpointer_t& bp) { | |
136 | if (!_mop || !ino_c) | |
137 | return false; | |
138 | auto item = _mop->ancestors.find(ino_c); | |
139 | if (item != _mop->ancestors.end()) { | |
140 | bp = item->second; | |
141 | return true; | |
142 | } else | |
143 | return false; | |
144 | } | |
145 | bool get_ancestor(inode_backpointer_t& bp) { | |
146 | if (!_mop || !ino) | |
147 | return false; | |
148 | auto item = _mop->ancestors.find(ino); | |
149 | if (item != _mop->ancestors.end()) { | |
150 | bp = item->second; | |
151 | return true; | |
152 | } else | |
153 | return false; | |
154 | } | |
155 | op_type sub_op_t; | |
156 | ino_type sub_ino_t; | |
157 | inodeno_t ino; | |
158 | frag_t frag; | |
159 | inodeno_t ino_c; | |
160 | unsigned trace_level; | |
161 | std::string name; | |
162 | bool _proc; | |
163 | meta_op* _mop; | |
164 | }; | |
165 | ||
166 | std::map<inodeno_t, inode_backpointer_t > ancestors; | |
167 | std::map<inodeno_t, inode_meta_t* > inodes; | |
168 | std::map<inodeno_t, string > okeys; | |
169 | ||
170 | void clear_sops() { | |
171 | while(!no_sops()) | |
172 | pop_op(); | |
173 | } | |
174 | bool no_sops() { | |
175 | return sub_ops.empty(); | |
176 | } | |
177 | void push_op(sub_op* sop) { | |
178 | if (_debug) | |
179 | std::cout << "<<====" << sop->detail() << std::endl; | |
180 | sub_ops.push(sop); | |
181 | } | |
182 | sub_op* top_op() { | |
183 | return sub_ops.top(); | |
184 | } | |
185 | void pop_op() { | |
186 | sub_op* sop = sub_ops.top(); | |
187 | if (_debug) | |
188 | std::cout << "====>>" << sop->detail() << std::endl;; | |
189 | delete sop; | |
190 | sub_ops.pop(); | |
191 | } | |
192 | string outfile() { | |
193 | return _out; | |
194 | } | |
195 | string infile() { | |
196 | return _in; | |
197 | } | |
198 | bool is_debug() { | |
199 | return _debug; | |
200 | } | |
201 | bool confirm_chg() { | |
202 | return _confirm; | |
203 | } | |
204 | private: | |
205 | stack<sub_op*> sub_ops; | |
206 | bool _debug; | |
207 | string _out; | |
208 | string _in; | |
209 | bool _confirm; | |
210 | }; | |
211 | MDSRoleSelector role_selector; | |
212 | mds_rank_t rank; | |
213 | ||
214 | // I/O handles | |
215 | librados::Rados rados; | |
216 | librados::IoCtx io_meta; | |
217 | std::vector<librados::IoCtx*> io_data_v; | |
218 | librados::IoCtx output; | |
219 | bool _debug; | |
220 | uint64_t features; | |
221 | ||
222 | std::string obj_name(inodeno_t ino, frag_t fg = frag_t(), const char *suffix = NULL) const; | |
223 | std::string obj_name(inodeno_t ino, uint64_t offset, const char *suffix = NULL) const; | |
224 | std::string obj_name(const char* ino, uint64_t offset, const char *suffix = NULL) const; | |
225 | ||
226 | // 0 : continue to find | |
227 | // 1 : stop to find it | |
228 | int show_child(std::string_view key, | |
229 | std::string_view dname, | |
230 | const snapid_t last, | |
231 | bufferlist &bl, | |
232 | const int pos, | |
233 | const std::set<snapid_t> *snaps, | |
234 | bool *force_dirty, | |
235 | inodeno_t sp_ino = 0, | |
236 | meta_op* op = NULL | |
237 | ); | |
238 | ||
239 | int process(string& mode, string& ino, string out, string in, bool confirm); | |
240 | int show_meta_info(string& ino, string& out); | |
241 | int list_meta_info(string& ino, string& out); | |
242 | int amend_meta_info(string& ino, string& in, bool confirm); | |
243 | int show_fnode(string& ino, string& out); | |
244 | int amend_fnode(string& in, bool confirm); | |
245 | int op_process(meta_op &op); | |
246 | int list_meta(meta_op &op); | |
247 | int file_meta(meta_op &op); | |
248 | int show_meta(meta_op &op); | |
249 | int amend_meta(meta_op &op); | |
250 | int show_fn(meta_op &op); | |
251 | int amend_fn(meta_op &op); | |
252 | public: | |
253 | int _file_meta(meta_op &op, librados::IoCtx& io); | |
254 | int _show_meta(inode_meta_t& i, const string& fn); | |
255 | int _amend_meta(string &k, inode_meta_t& i, const string& fn, meta_op& op); | |
256 | int _show_fn(inode_meta_t& i, const string& fn); | |
257 | int _amend_fn(const string& fn, bool confirm); | |
258 | void usage(); | |
259 | MetaTool(bool debug=false): | |
260 | _debug(debug) {} | |
261 | ~MetaTool() {} | |
262 | ||
263 | int main(string& mode, | |
264 | string& rank_str, | |
265 | string& minfo, | |
266 | string&ino, | |
267 | string& out, | |
268 | string& in, | |
269 | bool confirm = false | |
270 | ); | |
271 | }; | |
272 | #endif // METATOOL_H__ |