]> git.proxmox.com Git - ceph.git/blame - ceph/src/mds/inode_backtrace.h
import ceph 16.2.6
[ceph.git] / ceph / src / mds / inode_backtrace.h
CommitLineData
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
11fdf7f2 6#include <string_view>
94b18763 7
7c673cae
FG
8#include "mdstypes.h"
9
10namespace ceph {
11 class Formatter;
12}
13
14/** metadata backpointers **/
15
16/*
17 * - inode_backpointer_t is just the _pointer_ portion; it doesn't
18 * tell us who we point _from_.
19 *
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
22 * newer.
23 */
24struct inode_backpointer_t {
9f95a23c 25 inode_backpointer_t() {}
11fdf7f2 26 inode_backpointer_t(inodeno_t i, std::string_view d, version_t v) : dirino(i), dname(d), version(v) {}
7c673cae 27
f67539c2
TL
28 void encode(ceph::buffer::list& bl) const;
29 void decode(ceph::buffer::list::const_iterator &bl);
30 void decode_old(ceph::buffer::list::const_iterator &bl);
31 void dump(ceph::Formatter *f) const;
9f95a23c
TL
32 static void generate_test_instances(std::list<inode_backpointer_t*>& ls);
33
34 inodeno_t dirino; // containing directory ino
f67539c2 35 std::string dname; // linking dentry name
9f95a23c 36 version_t version = 0; // child's version at time of backpointer creation
7c673cae
FG
37};
38WRITE_CLASS_ENCODER(inode_backpointer_t)
39
40inline 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;
42}
43
f67539c2 44inline std::ostream& operator<<(std::ostream& out, const inode_backpointer_t& ib) {
7c673cae
FG
45 return out << "<" << ib.dirino << "/" << ib.dname << " v" << ib.version << ">";
46}
47
48/*
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).
52 */
53struct inode_backtrace_t {
9f95a23c 54 inode_backtrace_t() {}
7c673cae 55
f67539c2
TL
56 void encode(ceph::buffer::list& bl) const;
57 void decode(ceph::buffer::list::const_iterator &bl);
58 void dump(ceph::Formatter *f) const;
9f95a23c 59 static void generate_test_instances(std::list<inode_backtrace_t*>& ls);
7c673cae
FG
60
61 /**
62 * Compare two backtraces *for the same inode*.
63 * @pre The backtraces are for the same inode
64 *
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
70 *
71 * @returns 1 if we are newer than the other, 0 if equal, -1 if older
72 */
73 int compare(const inode_backtrace_t& other,
74 bool *equivalent, bool *divergent) const;
9f95a23c 75
f67539c2
TL
76 void clear() {
77 ancestors.clear();
78 old_pools.clear();
79 }
80
9f95a23c 81 inodeno_t ino; // my ino
f67539c2 82 std::vector<inode_backpointer_t> ancestors;
9f95a23c 83 int64_t pool = -1;
f67539c2 84 std::vector<int64_t> old_pools;
7c673cae
FG
85};
86WRITE_CLASS_ENCODER(inode_backtrace_t)
87
f67539c2 88inline std::ostream& operator<<(std::ostream& out, const inode_backtrace_t& it) {
7c673cae
FG
89 return out << "(" << it.pool << ")" << it.ino << ":" << it.ancestors << "//" << it.old_pools;
90}
91
92inline bool operator==(const inode_backtrace_t& l,
93 const inode_backtrace_t& r) {
94 return l.ino == r.ino &&
95 l.pool == r.pool &&
96 l.old_pools == r.old_pools &&
97 l.ancestors == r.ancestors;
98}
99
100#endif