]>
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 | #ifndef CEPH_INODE_BACKTRACE_H | |
4 | #define CEPH_INODE_BACKTRACE_H | |
5 | ||
6 | #include "mdstypes.h" | |
7 | ||
8 | namespace ceph { | |
9 | class Formatter; | |
10 | } | |
11 | ||
12 | /** metadata backpointers **/ | |
13 | ||
14 | /* | |
15 | * - inode_backpointer_t is just the _pointer_ portion; it doesn't | |
16 | * tell us who we point _from_. | |
17 | * | |
18 | * - it _does_ include a version of the source object, so we can look | |
19 | * at two different pointers (from the same inode) and tell which is | |
20 | * newer. | |
21 | */ | |
22 | struct inode_backpointer_t { | |
23 | inodeno_t dirino; // containing directory ino | |
24 | string dname; // linking dentry name | |
25 | version_t version; // child's version at time of backpointer creation | |
26 | ||
27 | inode_backpointer_t() : version(0) {} | |
28 | inode_backpointer_t(inodeno_t i, const string &d, version_t v) : dirino(i), dname(d), version(v) {} | |
29 | ||
30 | void encode(bufferlist& bl) const; | |
31 | void decode(bufferlist::iterator &bl); | |
32 | void decode_old(bufferlist::iterator &bl); | |
33 | void dump(Formatter *f) const; | |
34 | static void generate_test_instances(list<inode_backpointer_t*>& ls); | |
35 | }; | |
36 | WRITE_CLASS_ENCODER(inode_backpointer_t) | |
37 | ||
38 | inline bool operator==(const inode_backpointer_t& l, const inode_backpointer_t& r) { | |
39 | return l.dirino == r.dirino && l.version == r.version && l.dname == r.dname; | |
40 | } | |
41 | ||
42 | inline ostream& operator<<(ostream& out, const inode_backpointer_t& ib) { | |
43 | return out << "<" << ib.dirino << "/" << ib.dname << " v" << ib.version << ">"; | |
44 | } | |
45 | ||
46 | /* | |
47 | * inode_backtrace_t is a complete ancestor backtraces for a given inode. | |
48 | * we include who _we_ are, so that the backtrace can stand alone (as, say, | |
49 | * an xattr on an object). | |
50 | */ | |
51 | struct inode_backtrace_t { | |
52 | inodeno_t ino; // my ino | |
53 | vector<inode_backpointer_t> ancestors; | |
54 | int64_t pool; | |
55 | // we use a set for old_pools to avoid duplicate entries, e.g. setlayout 0, 1, 0 | |
56 | set<int64_t> old_pools; | |
57 | ||
58 | inode_backtrace_t() : pool(-1) {} | |
59 | ||
60 | void encode(bufferlist& bl) const; | |
61 | void decode(bufferlist::iterator &bl); | |
62 | void dump(Formatter *f) const; | |
63 | static void generate_test_instances(list<inode_backtrace_t*>& ls); | |
64 | ||
65 | /** | |
66 | * Compare two backtraces *for the same inode*. | |
67 | * @pre The backtraces are for the same inode | |
68 | * | |
69 | * @param other The backtrace to compare ourselves with | |
70 | * @param equivalent A bool pointer which will be set to true if | |
71 | * the other backtrace is equivalent to our own (has the same dentries) | |
72 | * @param divergent A bool pointer which will be set to true if | |
73 | * the backtraces have differing entries without versions supporting them | |
74 | * | |
75 | * @returns 1 if we are newer than the other, 0 if equal, -1 if older | |
76 | */ | |
77 | int compare(const inode_backtrace_t& other, | |
78 | bool *equivalent, bool *divergent) const; | |
79 | }; | |
80 | WRITE_CLASS_ENCODER(inode_backtrace_t) | |
81 | ||
82 | inline ostream& operator<<(ostream& out, const inode_backtrace_t& it) { | |
83 | return out << "(" << it.pool << ")" << it.ino << ":" << it.ancestors << "//" << it.old_pools; | |
84 | } | |
85 | ||
86 | inline bool operator==(const inode_backtrace_t& l, | |
87 | const inode_backtrace_t& r) { | |
88 | return l.ino == r.ino && | |
89 | l.pool == r.pool && | |
90 | l.old_pools == r.old_pools && | |
91 | l.ancestors == r.ancestors; | |
92 | } | |
93 | ||
94 | #endif | |
95 |