]>
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
6 #include <boost/utility/string_view.hpp>
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 inodeno_t dirino
; // containing directory ino
26 string dname
; // linking dentry name
27 version_t version
; // child's version at time of backpointer creation
29 inode_backpointer_t() : version(0) {}
30 inode_backpointer_t(inodeno_t i
, boost::string_view d
, version_t v
) : dirino(i
), dname(d
), version(v
) {}
32 void encode(bufferlist
& bl
) const;
33 void decode(bufferlist::iterator
&bl
);
34 void decode_old(bufferlist::iterator
&bl
);
35 void dump(Formatter
*f
) const;
36 static void generate_test_instances(list
<inode_backpointer_t
*>& ls
);
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 inodeno_t ino
; // my ino
55 vector
<inode_backpointer_t
> ancestors
;
57 // we use a set for old_pools to avoid duplicate entries, e.g. setlayout 0, 1, 0
58 set
<int64_t> old_pools
;
60 inode_backtrace_t() : pool(-1) {}
62 void encode(bufferlist
& bl
) const;
63 void decode(bufferlist::iterator
&bl
);
64 void dump(Formatter
*f
) const;
65 static void generate_test_instances(list
<inode_backtrace_t
*>& ls
);
68 * Compare two backtraces *for the same inode*.
69 * @pre The backtraces are for the same inode
71 * @param other The backtrace to compare ourselves with
72 * @param equivalent A bool pointer which will be set to true if
73 * the other backtrace is equivalent to our own (has the same dentries)
74 * @param divergent A bool pointer which will be set to true if
75 * the backtraces have differing entries without versions supporting them
77 * @returns 1 if we are newer than the other, 0 if equal, -1 if older
79 int compare(const inode_backtrace_t
& other
,
80 bool *equivalent
, bool *divergent
) const;
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
;