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_
20 #include "auth/Crypto.h"
24 typedef uint64_t damage_entry_id_t
;
30 DAMAGE_ENTRY_BACKTRACE
32 } damage_entry_type_t
;
40 // path is optional, advisory. Used to give the admin an idea of what
41 // part of his tree the damage affects.
46 id
= get_random(0, 0xffffffff);
47 reported_at
= ceph_clock_now();
50 virtual damage_entry_type_t
get_type() const = 0;
52 virtual ~DamageEntry();
54 virtual void dump(Formatter
*f
) const = 0;
58 typedef ceph::shared_ptr
<DamageEntry
> DamageEntryRef
;
67 bool operator<(const DirFragIdent
&rhs
) const
70 return frag
< rhs
.frag
;
76 DirFragIdent(inodeno_t ino_
, frag_t frag_
)
77 : ino(ino_
), frag(frag_
)
87 bool operator<(const DentryIdent
&rhs
) const
89 if (dname
== rhs
.dname
) {
90 return snap_id
< rhs
.snap_id
;
92 return dname
< rhs
.dname
;
96 DentryIdent(const std::string
&dname_
, snapid_t snap_id_
)
97 : dname(dname_
), snap_id(snap_id_
)
102 * Registry of in-RADOS metadata damage identified
103 * during forward scrub or during normal fetches.
105 * Used to indicate damage to the administrator, and
106 * to cache known-bad paths so that we don't hit them
109 * Callers notifying damage must check return code; if
110 * an fatal condition is indicated then they should mark the MDS
113 * An artificial limit on the number of damage entries
114 * is imposed to avoid this structure growing indefinitely. If
115 * a notification causes the limit to be exceeded, the fatal
116 * condition will be indicated in the return code and the MDS
117 * rank should be marked damaged.
119 * Protected by MDS::mds_lock
125 // Map of all dirfrags reported damaged
126 std::map
<DirFragIdent
, DamageEntryRef
> dirfrags
;
128 // Store dentries in a map per dirfrag, so that we can
129 // readily look up all the bad dentries in a particular
131 std::map
<DirFragIdent
, std::map
<DentryIdent
, DamageEntryRef
> > dentries
;
133 // Map of all inodes which could not be resolved remotely
134 // (i.e. have probably/possibly missing backtraces)
135 std::map
<inodeno_t
, DamageEntryRef
> remotes
;
137 // All damage, by ID. This is a secondary index
138 // to the dirfrag, dentry, remote maps. It exists
139 // to enable external tools to unambiguously operate
140 // on particular entries.
141 std::map
<damage_entry_id_t
, DamageEntryRef
> by_id
;
143 // I need to know my MDS rank so that I can check if
144 // metadata items are part of my mydir.
145 const mds_rank_t rank
;
147 bool oversized() const;
152 * Return true if no damage entries exist
156 return by_id
.empty();
160 * Indicate that a dirfrag cannot be loaded.
162 * @return true if fatal
164 bool notify_dirfrag(inodeno_t ino
, frag_t frag
, const std::string
&path
);
167 * Indicate that a particular dentry cannot be loaded.
169 * @return true if fatal
172 inodeno_t ino
, frag_t frag
,
173 snapid_t snap_id
, const std::string
&dname
, const std::string
&path
);
176 * Indicate that a particular Inode could not be loaded by number
178 bool notify_remote_damaged(
179 inodeno_t ino
, const std::string
&path
);
181 bool is_dentry_damaged(
182 const CDir
*dir_frag
,
183 const std::string
&dname
,
184 const snapid_t snap_id
) const;
186 bool is_dirfrag_damaged(
187 const CDir
*dir_frag
) const;
189 bool is_remote_damaged(
190 const inodeno_t ino
) const;
193 DamageTable(const mds_rank_t rank_
)
196 assert(rank_
!= MDS_RANK_NONE
);
199 void dump(Formatter
*f
) const;
201 void erase(damage_entry_id_t damage_id
);
204 #endif // DAMAGE_TABLE_H_