1 // -*- mode:C++; tab-width:8; c-basic-offset:2; indent-tabs-mode:t -*-
2 // vim: ts=8 sw=2 smarttab
6 #include "MDSUtility.h"
7 #include "RoleSelector.h"
11 #include "mds/mdstypes.h"
12 #include "mds/LogEvent.h"
13 #include "mds/events/EMetaBlob.h"
15 #include "include/rados/librados.hpp"
16 #include "common/ceph_json.h"
18 using ::ceph::bufferlist
;
19 class MetaTool
: public MDSUtility
24 inode_meta_t(snapid_t f
= CEPH_NOSNAP
, char t
= char(255), InodeStore
* i
= NULL
):
27 snapid_t
get_snapid() const {
30 InodeStore
* get_meta() const {
36 int get_type() const {
39 void decode_json(JSONObj
*obj
);
40 void encode(::ceph::bufferlist
& bl
, uint64_t features
);
49 meta_op(bool debug
= false, std::string out
= "", std::string in
= "", bool confirm
= false):
71 static std::string
op_type_name(op_type
& t
) {
96 name
= "unknow op type";
100 static std::string
ino_type_name(ino_type
& t
) {
110 name
= "unknow file type";
116 sub_op(meta_op
* mop
):
122 std::cout
<< detail() << std::endl
;
124 std::string
detail() {
125 std::stringstream ds
;
126 ds
<< " [sub_op]" << op_type_name(sub_op_t
) << "|"
127 << ino_type_name(sub_ino_t
) << "|"
131 << trace_level
<< "|"
135 bool get_c_ancestor(inode_backpointer_t
& bp
) {
138 auto item
= _mop
->ancestors
.find(ino_c
);
139 if (item
!= _mop
->ancestors
.end()) {
145 bool get_ancestor(inode_backpointer_t
& bp
) {
148 auto item
= _mop
->ancestors
.find(ino
);
149 if (item
!= _mop
->ancestors
.end()) {
160 unsigned trace_level
;
166 std::map
<inodeno_t
, inode_backpointer_t
> ancestors
;
167 std::map
<inodeno_t
, inode_meta_t
* > inodes
;
168 std::map
<inodeno_t
, std::string
> okeys
;
175 return sub_ops
.empty();
177 void push_op(sub_op
* sop
) {
179 std::cout
<< "<<====" << sop
->detail() << std::endl
;
183 return sub_ops
.top();
186 sub_op
* sop
= sub_ops
.top();
188 std::cout
<< "====>>" << sop
->detail() << std::endl
;;
192 std::string
outfile() {
195 std::string
infile() {
205 stack
<sub_op
*> sub_ops
;
211 MDSRoleSelector role_selector
;
215 librados::Rados rados
;
216 librados::IoCtx io_meta
;
217 std::vector
<librados::IoCtx
*> io_data_v
;
218 librados::IoCtx output
;
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;
226 // 0 : continue to find
227 // 1 : stop to find it
228 int show_child(std::string_view key
,
229 std::string_view dname
,
233 const std::set
<snapid_t
> *snaps
,
235 inodeno_t sp_ino
= 0,
239 int process(std::string
& mode
, std::string
& ino
, std::string out
, std::string in
, bool confirm
);
240 int show_meta_info(std::string
& ino
, std::string
& out
);
241 int list_meta_info(std::string
& ino
, std::string
& out
);
242 int amend_meta_info(std::string
& ino
, std::string
& in
, bool confirm
);
243 int show_fnode(std::string
& ino
, std::string
& out
);
244 int amend_fnode(std::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
);
253 int _file_meta(meta_op
&op
, librados::IoCtx
& io
);
254 int _show_meta(inode_meta_t
& i
, const std::string
& fn
);
255 int _amend_meta(std::string
&k
, inode_meta_t
& i
, const std::string
& fn
, meta_op
& op
);
256 int _show_fn(inode_meta_t
& i
, const std::string
& fn
);
257 int _amend_fn(const std::string
& fn
, bool confirm
);
259 MetaTool(bool debug
=false):
263 int main(std::string
& mode
,
264 std::string
& rank_str
,
272 #endif // METATOOL_H__