]>
git.proxmox.com Git - ceph.git/blob - ceph/src/mds/inode_backtrace.cc
1 // -*- mode:C++; tab-width:8; c-basic-offset:2; indent-tabs-mode:t -*-
2 // vim: ts=8 sw=2 smarttab
4 #include "inode_backtrace.h"
6 #include "common/Formatter.h"
8 /* inode_backpointer_t */
10 void inode_backpointer_t::encode(bufferlist
& bl
) const
12 ENCODE_START(2, 2, bl
);
15 ::encode(version
, bl
);
19 void inode_backpointer_t::decode(bufferlist::iterator
& bl
)
21 DECODE_START_LEGACY_COMPAT_LEN(2, 2, 2, bl
);
24 ::decode(version
, bl
);
28 void inode_backpointer_t::decode_old(bufferlist::iterator
& bl
)
32 ::decode(version
, bl
);
35 void inode_backpointer_t::dump(Formatter
*f
) const
37 f
->dump_unsigned("dirino", dirino
);
38 f
->dump_string("dname", dname
);
39 f
->dump_unsigned("version", version
);
42 void inode_backpointer_t::generate_test_instances(list
<inode_backpointer_t
*>& ls
)
44 ls
.push_back(new inode_backpointer_t
);
45 ls
.push_back(new inode_backpointer_t
);
46 ls
.back()->dirino
= 1;
47 ls
.back()->dname
= "foo";
48 ls
.back()->version
= 123;
56 void inode_backtrace_t::encode(bufferlist
& bl
) const
58 ENCODE_START(5, 4, bl
);
60 ::encode(ancestors
, bl
);
62 ::encode(old_pools
, bl
);
66 void inode_backtrace_t::decode(bufferlist::iterator
& bl
)
68 DECODE_START_LEGACY_COMPAT_LEN(5, 4, 4, bl
);
70 return; // sorry, the old data was crap
73 ::decode(ancestors
, bl
);
78 ancestors
.push_back(inode_backpointer_t());
79 ancestors
.back().decode_old(bl
);
84 ::decode(old_pools
, bl
);
89 void inode_backtrace_t::dump(Formatter
*f
) const
91 f
->dump_unsigned("ino", ino
);
92 f
->open_array_section("ancestors");
93 for (vector
<inode_backpointer_t
>::const_iterator p
= ancestors
.begin(); p
!= ancestors
.end(); ++p
) {
94 f
->open_object_section("backpointer");
99 f
->dump_int("pool", pool
);
100 f
->open_array_section("old_pools");
101 for (set
<int64_t>::iterator p
= old_pools
.begin(); p
!= old_pools
.end(); ++p
) {
102 f
->dump_int("old_pool", *p
);
107 void inode_backtrace_t::generate_test_instances(list
<inode_backtrace_t
*>& ls
)
109 ls
.push_back(new inode_backtrace_t
);
110 ls
.push_back(new inode_backtrace_t
);
112 ls
.back()->ancestors
.push_back(inode_backpointer_t());
113 ls
.back()->ancestors
.back().dirino
= 123;
114 ls
.back()->ancestors
.back().dname
= "bar";
115 ls
.back()->ancestors
.back().version
= 456;
117 ls
.back()->old_pools
.insert(10);
118 ls
.back()->old_pools
.insert(7);
121 int inode_backtrace_t::compare(const inode_backtrace_t
& other
,
122 bool *equivalent
, bool *divergent
) const
124 int min_size
= MIN(ancestors
.size(),other
.ancestors
.size());
130 if (ancestors
[0].version
> other
.ancestors
[0].version
)
132 else if (ancestors
[0].version
< other
.ancestors
[0].version
)
134 if (ancestors
[0].dirino
!= other
.ancestors
[0].dirino
||
135 ancestors
[0].dname
!= other
.ancestors
[0].dname
)
137 for (int i
= 1; i
< min_size
; ++i
) {
140 * we already know the dentries and versions are
141 * incompatible; no point checking farther
145 if (ancestors
[i
].dirino
!= other
.ancestors
[i
].dirino
||
146 ancestors
[i
].dname
!= other
.ancestors
[i
].dname
) {
149 } else if (ancestors
[i
].version
> other
.ancestors
[i
].version
) {
153 } else if (ancestors
[i
].version
< other
.ancestors
[i
].version
) {