1 // -*- mode:C++; tab-width:8; c-basic-offset:2; indent-tabs-mode:t -*-
2 // vim: ts=8 sw=2 smarttab
4 * Ceph - scalable distributed file system
6 * Copyright (C) 2004-2006 Sage Weil <sage@newdream.net>
8 * This is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU Lesser General Public
10 * License version 2.1, as published by the Free Software
11 * Foundation. See file COPYING.
16 #ifndef DAMAGE_TABLE_H_
17 #define DAMAGE_TABLE_H_
19 #include <string_view>
22 #include "include/random.h"
26 typedef uint64_t damage_entry_id_t
;
32 DAMAGE_ENTRY_BACKTRACE
34 } damage_entry_type_t
;
42 // path is optional, advisory. Used to give the admin an idea of what
43 // part of his tree the damage affects.
48 id
= ceph::util::generate_random_number
<damage_entry_id_t
>(0, 0xffffffff);
49 reported_at
= ceph_clock_now();
52 virtual damage_entry_type_t
get_type() const = 0;
54 virtual ~DamageEntry();
56 virtual void dump(Formatter
*f
) const = 0;
60 typedef std::shared_ptr
<DamageEntry
> DamageEntryRef
;
69 bool operator<(const DirFragIdent
&rhs
) const
72 return frag
< rhs
.frag
;
78 DirFragIdent(inodeno_t ino_
, frag_t frag_
)
79 : ino(ino_
), frag(frag_
)
89 bool operator<(const DentryIdent
&rhs
) const
91 if (dname
== rhs
.dname
) {
92 return snap_id
< rhs
.snap_id
;
94 return dname
< rhs
.dname
;
98 DentryIdent(std::string_view dname_
, snapid_t snap_id_
)
99 : dname(dname_
), snap_id(snap_id_
)
104 * Registry of in-RADOS metadata damage identified
105 * during forward scrub or during normal fetches.
107 * Used to indicate damage to the administrator, and
108 * to cache known-bad paths so that we don't hit them
111 * Callers notifying damage must check return code; if
112 * an fatal condition is indicated then they should mark the MDS
115 * An artificial limit on the number of damage entries
116 * is imposed to avoid this structure growing indefinitely. If
117 * a notification causes the limit to be exceeded, the fatal
118 * condition will be indicated in the return code and the MDS
119 * rank should be marked damaged.
121 * Protected by MDS::mds_lock
127 // Map of all dirfrags reported damaged
128 std::map
<DirFragIdent
, DamageEntryRef
> dirfrags
;
130 // Store dentries in a map per dirfrag, so that we can
131 // readily look up all the bad dentries in a particular
133 std::map
<DirFragIdent
, std::map
<DentryIdent
, DamageEntryRef
> > dentries
;
135 // Map of all inodes which could not be resolved remotely
136 // (i.e. have probably/possibly missing backtraces)
137 std::map
<inodeno_t
, DamageEntryRef
> remotes
;
139 // All damage, by ID. This is a secondary index
140 // to the dirfrag, dentry, remote maps. It exists
141 // to enable external tools to unambiguously operate
142 // on particular entries.
143 std::map
<damage_entry_id_t
, DamageEntryRef
> by_id
;
145 // I need to know my MDS rank so that I can check if
146 // metadata items are part of my mydir.
147 const mds_rank_t rank
;
149 bool oversized() const;
154 * Return true if no damage entries exist
158 return by_id
.empty();
162 * Indicate that a dirfrag cannot be loaded.
164 * @return true if fatal
166 bool notify_dirfrag(inodeno_t ino
, frag_t frag
, std::string_view path
);
169 * Indicate that a particular dentry cannot be loaded.
171 * @return true if fatal
174 inodeno_t ino
, frag_t frag
,
175 snapid_t snap_id
, std::string_view dname
, std::string_view path
);
178 * Indicate that a particular Inode could not be loaded by number
180 bool notify_remote_damaged(
181 inodeno_t ino
, std::string_view path
);
183 bool is_dentry_damaged(
184 const CDir
*dir_frag
,
185 std::string_view dname
,
186 const snapid_t snap_id
) const;
188 bool is_dirfrag_damaged(
189 const CDir
*dir_frag
) const;
191 bool is_remote_damaged(
192 const inodeno_t ino
) const;
195 explicit DamageTable(const mds_rank_t rank_
)
198 ceph_assert(rank_
!= MDS_RANK_NONE
);
201 void dump(Formatter
*f
) const;
203 void erase(damage_entry_id_t damage_id
);
206 #endif // DAMAGE_TABLE_H_