]>
git.proxmox.com Git - ceph.git/blob - ceph/src/mds/inode_backtrace.h
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
14 /** metadata backpointers **/
17 * - inode_backpointer_t is just the _pointer_ portion; it doesn't
18 * tell us who we point _from_.
20 * - it _does_ include a version of the source object, so we can look
21 * at two different pointers (from the same inode) and tell which is
24 struct inode_backpointer_t
{
25 inode_backpointer_t() {}
26 inode_backpointer_t(inodeno_t i
, std::string_view d
, version_t v
) : dirino(i
), dname(d
), version(v
) {}
28 void encode(bufferlist
& bl
) const;
29 void decode(bufferlist::const_iterator
&bl
);
30 void decode_old(bufferlist::const_iterator
&bl
);
31 void dump(Formatter
*f
) const;
32 static void generate_test_instances(std::list
<inode_backpointer_t
*>& ls
);
34 inodeno_t dirino
; // containing directory ino
35 string dname
; // linking dentry name
36 version_t version
= 0; // child's version at time of backpointer creation
38 WRITE_CLASS_ENCODER(inode_backpointer_t
)
40 inline bool operator==(const inode_backpointer_t
& l
, const inode_backpointer_t
& r
) {
41 return l
.dirino
== r
.dirino
&& l
.version
== r
.version
&& l
.dname
== r
.dname
;
44 inline ostream
& operator<<(ostream
& out
, const inode_backpointer_t
& ib
) {
45 return out
<< "<" << ib
.dirino
<< "/" << ib
.dname
<< " v" << ib
.version
<< ">";
49 * inode_backtrace_t is a complete ancestor backtraces for a given inode.
50 * we include who _we_ are, so that the backtrace can stand alone (as, say,
51 * an xattr on an object).
53 struct inode_backtrace_t
{
54 inode_backtrace_t() {}
56 void encode(bufferlist
& bl
) const;
57 void decode(bufferlist::const_iterator
&bl
);
58 void dump(Formatter
*f
) const;
59 static void generate_test_instances(std::list
<inode_backtrace_t
*>& ls
);
62 * Compare two backtraces *for the same inode*.
63 * @pre The backtraces are for the same inode
65 * @param other The backtrace to compare ourselves with
66 * @param equivalent A bool pointer which will be set to true if
67 * the other backtrace is equivalent to our own (has the same dentries)
68 * @param divergent A bool pointer which will be set to true if
69 * the backtraces have differing entries without versions supporting them
71 * @returns 1 if we are newer than the other, 0 if equal, -1 if older
73 int compare(const inode_backtrace_t
& other
,
74 bool *equivalent
, bool *divergent
) const;
76 inodeno_t ino
; // my ino
77 vector
<inode_backpointer_t
> ancestors
;
79 // we use a set for old_pools to avoid duplicate entries, e.g. setlayout 0, 1, 0
80 set
<int64_t> old_pools
;
82 WRITE_CLASS_ENCODER(inode_backtrace_t
)
84 inline ostream
& operator<<(ostream
& out
, const inode_backtrace_t
& it
) {
85 return out
<< "(" << it
.pool
<< ")" << it
.ino
<< ":" << it
.ancestors
<< "//" << it
.old_pools
;
88 inline bool operator==(const inode_backtrace_t
& l
,
89 const inode_backtrace_t
& r
) {
90 return l
.ino
== r
.ino
&&
92 l
.old_pools
== r
.old_pools
&&
93 l
.ancestors
== r
.ancestors
;