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
;
41 id
= ceph::util::generate_random_number
<damage_entry_id_t
>(0, 0xffffffff);
42 reported_at
= ceph_clock_now();
45 virtual ~DamageEntry();
47 virtual damage_entry_type_t
get_type() const = 0;
48 virtual void dump(Formatter
*f
) const = 0;
53 // path is optional, advisory. Used to give the admin an idea of what
54 // part of his tree the damage affects.
58 typedef std::shared_ptr
<DamageEntry
> DamageEntryRef
;
63 DirFragIdent(inodeno_t ino_
, frag_t frag_
)
64 : ino(ino_
), frag(frag_
)
67 bool operator<(const DirFragIdent
&rhs
) const
70 return frag
< rhs
.frag
;
83 DentryIdent(std::string_view dname_
, snapid_t snap_id_
)
84 : dname(dname_
), snap_id(snap_id_
)
87 bool operator<(const DentryIdent
&rhs
) const
89 if (dname
== rhs
.dname
) {
90 return snap_id
< rhs
.snap_id
;
92 return dname
< rhs
.dname
;
101 * Registry of in-RADOS metadata damage identified
102 * during forward scrub or during normal fetches.
104 * Used to indicate damage to the administrator, and
105 * to cache known-bad paths so that we don't hit them
108 * Callers notifying damage must check return code; if
109 * an fatal condition is indicated then they should mark the MDS
112 * An artificial limit on the number of damage entries
113 * is imposed to avoid this structure growing indefinitely. If
114 * a notification causes the limit to be exceeded, the fatal
115 * condition will be indicated in the return code and the MDS
116 * rank should be marked damaged.
118 * Protected by MDS::mds_lock
123 explicit DamageTable(const mds_rank_t rank_
)
126 ceph_assert(rank_
!= MDS_RANK_NONE
);
130 * Return true if no damage entries exist
134 return by_id
.empty();
138 * Indicate that a dirfrag cannot be loaded.
140 * @return true if fatal
142 bool notify_dirfrag(inodeno_t ino
, frag_t frag
, std::string_view path
);
145 * Indicate that a particular dentry cannot be loaded.
147 * @return true if fatal
150 inodeno_t ino
, frag_t frag
,
151 snapid_t snap_id
, std::string_view dname
, std::string_view path
);
154 * Indicate that a particular Inode could not be loaded by number
156 bool notify_remote_damaged(inodeno_t ino
, std::string_view path
);
158 bool is_dentry_damaged(
159 const CDir
*dir_frag
,
160 std::string_view dname
,
161 const snapid_t snap_id
) const;
163 bool is_dirfrag_damaged(const CDir
*dir_frag
) const;
165 bool is_remote_damaged(const inodeno_t ino
) const;
167 void dump(Formatter
*f
) const;
169 void erase(damage_entry_id_t damage_id
);
172 // I need to know my MDS rank so that I can check if
173 // metadata items are part of my mydir.
174 const mds_rank_t rank
;
176 bool oversized() const;
178 // Map of all dirfrags reported damaged
179 std::map
<DirFragIdent
, DamageEntryRef
> dirfrags
;
181 // Store dentries in a map per dirfrag, so that we can
182 // readily look up all the bad dentries in a particular
184 std::map
<DirFragIdent
, std::map
<DentryIdent
, DamageEntryRef
> > dentries
;
186 // Map of all inodes which could not be resolved remotely
187 // (i.e. have probably/possibly missing backtraces)
188 std::map
<inodeno_t
, DamageEntryRef
> remotes
;
190 // All damage, by ID. This is a secondary index
191 // to the dirfrag, dentry, remote maps. It exists
192 // to enable external tools to unambiguously operate
193 // on particular entries.
194 std::map
<damage_entry_id_t
, DamageEntryRef
> by_id
;
196 #endif // DAMAGE_TABLE_H_