]> git.proxmox.com Git - ceph.git/blame - ceph/src/mds/StrayManager.h
update sources to ceph Nautilus 14.2.1
[ceph.git] / ceph / src / mds / StrayManager.h
CommitLineData
7c673cae
FG
1// vim: ts=8 sw=2 smarttab
2/*
3 * Ceph - scalable distributed file system
4 *
5 * Copyright (C) 2015 Red Hat
6 *
7 * This is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU Lesser General Public
9 * License version 2.1, as published by the Free Software
10 * Foundation. See file COPYING.
11 *
12 */
13
14#ifndef STRAY_MANAGER_H
15#define STRAY_MANAGER_H
16
17#include "include/elist.h"
18#include <list>
19#include "mds/PurgeQueue.h"
20
21class MDSRank;
22class PerfCounters;
23class CInode;
24class CDentry;
25
26class StrayManager
27{
28 protected:
29 // Has passed through eval_stray and still has refs
30 elist<CDentry*> delayed_eval_stray;
31
32 // strays that have been trimmed from cache
33 std::set<std::string> trimmed_strays;
34
35 // Global references for doing I/O
36 MDSRank *mds;
37 PerfCounters *logger;
38
39 bool started;
40
41 // Stray dentries for this rank (including those not in cache)
42 uint64_t num_strays;
43
44 // Stray dentries
45 uint64_t num_strays_delayed;
46
47 // Entries that have entered enqueue() but not been persistently
48 // recorded by PurgeQueue yet
49 uint64_t num_strays_enqueuing;
50
51 PurgeQueue &purge_queue;
52
53 void truncate(CDentry *dn);
54
55 /**
56 * Purge a dentry from a stray directory. This function
57 * is called once eval_stray is satisfied and StrayManager
58 * throttling is also satisfied. There is no going back
59 * at this stage!
60 */
61 void purge(CDentry *dn);
62
63 /**
64 * Completion handler for a Filer::purge on a stray inode.
65 */
d2e6a577 66 void _purge_stray_purged(CDentry *dn, bool only_head);
7c673cae
FG
67
68 void _purge_stray_logged(CDentry *dn, version_t pdv, LogSegment *ls);
69
70 /**
71 * Callback: we have logged the update to an inode's metadata
72 * reflecting it's newly-zeroed length.
73 */
74 void _truncate_stray_logged(CDentry *dn, LogSegment *ls);
75
76 friend class StrayManagerIOContext;
77 friend class StrayManagerLogContext;
78 friend class StrayManagerContext;
79
80 friend class C_StraysFetched;
81 friend class C_OpenSnapParents;
82 friend class C_PurgeStrayLogged;
83 friend class C_TruncateStrayLogged;
84 friend class C_IO_PurgeStrayPurged;
85
86
87 // Call this on a dentry that has been identified as
11fdf7f2 88 // eligible for purging. It will be passed on to PurgeQueue.
7c673cae
FG
89 void enqueue(CDentry *dn, bool trunc);
90
91 // Final part of enqueue() which we may have to retry
92 // after opening snap parents.
93 void _enqueue(CDentry *dn, bool trunc);
94
95
96 /**
97 * When hard links exist to an inode whose primary dentry
98 * is unlinked, the inode gets a stray primary dentry.
99 *
100 * We may later "reintegrate" the inode into a remaining
101 * non-stray dentry (one of what was previously a remote
102 * dentry) by issuing a rename from the stray to the other
103 * dentry.
104 */
105 void reintegrate_stray(CDentry *dn, CDentry *rlink);
106
107 /**
108 * Evaluate a stray dentry for purging or reintegration.
109 *
110 * purging: If the inode has no linkage, and no more references, then
111 * we may decide to purge it.
112 *
113 * reintegration: If the inode still has linkage, then it means someone else
114 * (a hard link) is still referring to it, and we should
115 * think about reintegrating that inode into the remote dentry.
116 *
117 * @returns true if the dentry will be purged (caller should never
118 * take more refs after this happens), else false.
119 */
11fdf7f2 120 bool _eval_stray(CDentry *dn);
7c673cae 121
31f18b77
FG
122 void _eval_stray_remote(CDentry *stray_dn, CDentry *remote_dn);
123
7c673cae
FG
124 // My public interface is for consumption by MDCache
125 public:
126 explicit StrayManager(MDSRank *mds, PurgeQueue &purge_queue_);
127 void set_logger(PerfCounters *l) {logger = l;}
128 void activate();
129
11fdf7f2 130 bool eval_stray(CDentry *dn);
7c673cae
FG
131
132 void set_num_strays(uint64_t num);
133 uint64_t get_num_strays() const { return num_strays; }
134
135 /**
11fdf7f2
TL
136 * Queue dentry for later evaluation. (evaluate it while not in the
137 * middle of another metadata operation)
138 */
139 void queue_delayed(CDentry *dn);
140
141 /**
142 * Eval strays in the delayed_eval_stray list
7c673cae
FG
143 */
144 void advance_delayed();
145
146 /**
31f18b77
FG
147 * Remote dentry potentially points to a stray. When it is touched,
148 * call in here to evaluate it for migration (move a stray residing
149 * on another MDS to this MDS) or reintegration (move a stray dentry's
150 * inode into a non-stray hardlink dentry and clean up the stray).
7c673cae
FG
151 *
152 * @param stray_dn a stray dentry whose inode has been referenced
153 * by a remote dentry
154 * @param remote_dn (optional) which remote dentry was touched
155 * in an operation that led us here: this is used
156 * as a hint for which remote to reintegrate into
157 * if there are multiple remotes.
158 */
31f18b77 159 void eval_remote(CDentry *remote_dn);
7c673cae
FG
160
161 /**
162 * Given a dentry within one of my stray directories,
163 * send it off to a stray directory in another MDS.
164 *
165 * This is for use:
166 * * Case A: when shutting down a rank, we migrate strays
167 * away from ourselves rather than waiting for purge
168 * * Case B: when a client request has a trace that refers to
169 * a stray inode on another MDS, we migrate that inode from
170 * there to here, in order that we can later re-integrate it
171 * here.
172 *
173 * In case B, the receiver should be calling into eval_stray
174 * on completion of mv (i.e. inode put), resulting in a subsequent
175 * reintegration.
176 */
177 void migrate_stray(CDentry *dn, mds_rank_t dest);
178
179 /**
180 * Update stats to reflect a newly created stray dentry. Needed
181 * because stats on strays live here, but creation happens
182 * in Server or MDCache. For our purposes "creation" includes
183 * loading a stray from a dirfrag and migrating a stray from
184 * another MDS, in addition to creations per-se.
185 */
186 void notify_stray_created();
187
188 /**
189 * Update stats to reflect a removed stray dentry. Needed because
190 * stats on strays live here, but removal happens in Server or
191 * MDCache. Also includes migration (rename) of strays from
192 * this MDS to another MDS.
193 */
194 void notify_stray_removed();
195};
196
197#endif // STRAY_MANAGER_H