]>
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
12 /** metadata backpointers **/
15 * - inode_backpointer_t is just the _pointer_ portion; it doesn't
16 * tell us who we point _from_.
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
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
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
) {}
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
);
36 WRITE_CLASS_ENCODER(inode_backpointer_t
)
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
;
42 inline ostream
& operator<<(ostream
& out
, const inode_backpointer_t
& ib
) {
43 return out
<< "<" << ib
.dirino
<< "/" << ib
.dname
<< " v" << ib
.version
<< ">";
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).
51 struct inode_backtrace_t
{
52 inodeno_t ino
; // my ino
53 vector
<inode_backpointer_t
> ancestors
;
55 // we use a set for old_pools to avoid duplicate entries, e.g. setlayout 0, 1, 0
56 set
<int64_t> old_pools
;
58 inode_backtrace_t() : pool(-1) {}
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
);
66 * Compare two backtraces *for the same inode*.
67 * @pre The backtraces are for the same inode
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
75 * @returns 1 if we are newer than the other, 0 if equal, -1 if older
77 int compare(const inode_backtrace_t
& other
,
78 bool *equivalent
, bool *divergent
) const;
80 WRITE_CLASS_ENCODER(inode_backtrace_t
)
82 inline ostream
& operator<<(ostream
& out
, const inode_backtrace_t
& it
) {
83 return out
<< "(" << it
.pool
<< ")" << it
.ino
<< ":" << it
.ancestors
<< "//" << it
.old_pools
;
86 inline bool operator==(const inode_backtrace_t
& l
,
87 const inode_backtrace_t
& r
) {
88 return l
.ino
== r
.ino
&&
90 l
.old_pools
== r
.old_pools
&&
91 l
.ancestors
== r
.ancestors
;