]>
Commit | Line | Data |
---|---|---|
7c673cae FG |
1 | // -*- mode:C++; tab-width:8; c-basic-offset:2; indent-tabs-mode:t -*- |
2 | // vim: ts=8 sw=2 smarttab | |
3 | /* | |
4 | * Ceph - scalable distributed file system | |
5 | * | |
6 | * Copyright (C) 2004-2006 Sage Weil <sage@newdream.net> | |
7 | * | |
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. | |
12 | * | |
13 | */ | |
14 | ||
15 | ||
16 | ||
17 | #ifndef CEPH_CDIR_H | |
18 | #define CEPH_CDIR_H | |
19 | ||
7c673cae | 20 | #include <iosfwd> |
7c673cae | 21 | #include <list> |
7c673cae | 22 | #include <map> |
94b18763 | 23 | #include <set> |
7c673cae | 24 | #include <string> |
94b18763 | 25 | #include <boost/utility/string_view.hpp> |
7c673cae | 26 | |
94b18763 FG |
27 | #include "common/DecayCounter.h" |
28 | #include "common/bloom_filter.hpp" | |
29 | #include "common/config.h" | |
30 | #include "include/buffer_fwd.h" | |
31 | #include "include/counter.h" | |
32 | #include "include/types.h" | |
7c673cae FG |
33 | |
34 | #include "CInode.h" | |
94b18763 | 35 | #include "MDSCacheObject.h" |
7c673cae FG |
36 | |
37 | class CDentry; | |
38 | class MDCache; | |
39 | ||
40 | struct ObjectOperation; | |
41 | ||
42 | ostream& operator<<(ostream& out, const class CDir& dir); | |
43 | class CDir : public MDSCacheObject, public Counter<CDir> { | |
44 | friend ostream& operator<<(ostream& out, const class CDir& dir); | |
45 | ||
46 | public: | |
181888fb | 47 | MEMPOOL_CLASS_HELPERS(); |
7c673cae FG |
48 | // -- pins -- |
49 | static const int PIN_DNWAITER = 1; | |
50 | static const int PIN_INOWAITER = 2; | |
51 | static const int PIN_CHILD = 3; | |
52 | static const int PIN_FROZEN = 4; | |
53 | static const int PIN_SUBTREE = 5; | |
54 | static const int PIN_IMPORTING = 7; | |
55 | static const int PIN_IMPORTBOUND = 9; | |
56 | static const int PIN_EXPORTBOUND = 10; | |
57 | static const int PIN_STICKY = 11; | |
58 | static const int PIN_SUBTREETEMP = 12; // used by MDCache::trim_non_auth() | |
59 | const char *pin_name(int p) const override { | |
60 | switch (p) { | |
61 | case PIN_DNWAITER: return "dnwaiter"; | |
62 | case PIN_INOWAITER: return "inowaiter"; | |
63 | case PIN_CHILD: return "child"; | |
64 | case PIN_FROZEN: return "frozen"; | |
65 | case PIN_SUBTREE: return "subtree"; | |
66 | case PIN_IMPORTING: return "importing"; | |
67 | case PIN_IMPORTBOUND: return "importbound"; | |
68 | case PIN_EXPORTBOUND: return "exportbound"; | |
69 | case PIN_STICKY: return "sticky"; | |
70 | case PIN_SUBTREETEMP: return "subtreetemp"; | |
71 | default: return generic_pin_name(p); | |
72 | } | |
73 | } | |
74 | ||
75 | // -- state -- | |
76 | static const unsigned STATE_COMPLETE = (1<< 1); // the complete contents are in cache | |
77 | static const unsigned STATE_FROZENTREE = (1<< 2); // root of tree (bounded by exports) | |
78 | static const unsigned STATE_FREEZINGTREE = (1<< 3); // in process of freezing | |
79 | static const unsigned STATE_FROZENDIR = (1<< 4); | |
80 | static const unsigned STATE_FREEZINGDIR = (1<< 5); | |
81 | static const unsigned STATE_COMMITTING = (1<< 6); // mid-commit | |
82 | static const unsigned STATE_FETCHING = (1<< 7); // currenting fetching | |
83 | static const unsigned STATE_CREATING = (1<< 8); | |
84 | static const unsigned STATE_IMPORTBOUND = (1<<10); | |
85 | static const unsigned STATE_EXPORTBOUND = (1<<11); | |
86 | static const unsigned STATE_EXPORTING = (1<<12); | |
87 | static const unsigned STATE_IMPORTING = (1<<13); | |
88 | static const unsigned STATE_FRAGMENTING = (1<<14); | |
89 | static const unsigned STATE_STICKY = (1<<15); // sticky pin due to inode stickydirs | |
90 | static const unsigned STATE_DNPINNEDFRAG = (1<<16); // dir is refragmenting | |
91 | static const unsigned STATE_ASSIMRSTAT = (1<<17); // assimilating inode->frag rstats | |
92 | static const unsigned STATE_DIRTYDFT = (1<<18); // dirty dirfragtree | |
93 | static const unsigned STATE_BADFRAG = (1<<19); // bad dirfrag | |
94 | static const unsigned STATE_AUXSUBTREE = (1<<20); // no subtree merge | |
95 | ||
96 | // common states | |
97 | static const unsigned STATE_CLEAN = 0; | |
7c673cae FG |
98 | |
99 | // these state bits are preserved by an import/export | |
100 | // ...except if the directory is hashed, in which case none of them are! | |
101 | static const unsigned MASK_STATE_EXPORTED = | |
102 | (STATE_COMPLETE|STATE_DIRTY|STATE_DIRTYDFT|STATE_BADFRAG); | |
103 | static const unsigned MASK_STATE_IMPORT_KEPT = | |
104 | ( | |
105 | STATE_IMPORTING | |
106 | |STATE_IMPORTBOUND|STATE_EXPORTBOUND | |
107 | |STATE_FROZENTREE | |
108 | |STATE_STICKY); | |
109 | static const unsigned MASK_STATE_EXPORT_KEPT = | |
110 | (STATE_EXPORTING | |
111 | |STATE_IMPORTBOUND|STATE_EXPORTBOUND | |
112 | |STATE_FROZENTREE | |
113 | |STATE_FROZENDIR | |
114 | |STATE_STICKY); | |
115 | static const unsigned MASK_STATE_FRAGMENT_KEPT = | |
116 | (STATE_DIRTY| | |
117 | STATE_EXPORTBOUND | | |
118 | STATE_IMPORTBOUND | | |
119 | STATE_AUXSUBTREE | | |
120 | STATE_REJOINUNDEF); | |
121 | ||
122 | // -- rep spec -- | |
123 | static const int REP_NONE = 0; | |
124 | static const int REP_ALL = 1; | |
125 | static const int REP_LIST = 2; | |
126 | ||
127 | ||
128 | static const unsigned EXPORT_NONCE = 1; | |
129 | ||
130 | ||
131 | // -- wait masks -- | |
132 | static const uint64_t WAIT_DENTRY = (1<<0); // wait for item to be in cache | |
133 | static const uint64_t WAIT_COMPLETE = (1<<1); // wait for complete dir contents | |
134 | static const uint64_t WAIT_FROZEN = (1<<2); // auth pins removed | |
135 | static const uint64_t WAIT_CREATED = (1<<3); // new dirfrag is logged | |
136 | ||
137 | static const int WAIT_DNLOCK_OFFSET = 4; | |
138 | ||
139 | static const uint64_t WAIT_ANY_MASK = (uint64_t)(-1); | |
140 | static const uint64_t WAIT_ATFREEZEROOT = (WAIT_UNFREEZE); | |
141 | static const uint64_t WAIT_ATSUBTREEROOT = (WAIT_SINGLEAUTH); | |
142 | ||
143 | ||
144 | ||
145 | ||
146 | public: | |
147 | // context | |
148 | MDCache *cache; | |
149 | ||
150 | CInode *inode; // my inode | |
151 | frag_t frag; // my frag | |
152 | ||
153 | bool is_lt(const MDSCacheObject *r) const override { | |
154 | return dirfrag() < (static_cast<const CDir*>(r))->dirfrag(); | |
155 | } | |
156 | ||
157 | fnode_t fnode; | |
158 | snapid_t first; | |
94b18763 | 159 | mempool::mds_co::compact_map<snapid_t,old_rstat_t> dirty_old_rstat; // [value.first,key] |
7c673cae FG |
160 | |
161 | // my inodes with dirty rstat data | |
162 | elist<CInode*> dirty_rstat_inodes; | |
163 | ||
164 | void resync_accounted_fragstat(); | |
165 | void resync_accounted_rstat(); | |
166 | void assimilate_dirty_rstat_inodes(); | |
167 | void assimilate_dirty_rstat_inodes_finish(MutationRef& mut, EMetaBlob *blob); | |
168 | ||
169 | protected: | |
170 | version_t projected_version; | |
94b18763 | 171 | mempool::mds_co::list<fnode_t> projected_fnode; |
7c673cae FG |
172 | |
173 | public: | |
b32b8144 | 174 | elist<CDentry*> dirty_dentries; |
7c673cae FG |
175 | elist<CDir*>::item item_dirty, item_new; |
176 | ||
7c673cae FG |
177 | public: |
178 | version_t get_version() const { return fnode.version; } | |
179 | void set_version(version_t v) { | |
180 | assert(projected_fnode.empty()); | |
181 | projected_version = fnode.version = v; | |
182 | } | |
183 | version_t get_projected_version() const { return projected_version; } | |
184 | ||
185 | const fnode_t *get_projected_fnode() const { | |
186 | if (projected_fnode.empty()) | |
187 | return &fnode; | |
188 | else | |
94b18763 | 189 | return &projected_fnode.back(); |
7c673cae FG |
190 | } |
191 | ||
192 | fnode_t *get_projected_fnode() { | |
193 | if (projected_fnode.empty()) | |
194 | return &fnode; | |
195 | else | |
94b18763 | 196 | return &projected_fnode.back(); |
7c673cae FG |
197 | } |
198 | fnode_t *project_fnode(); | |
199 | ||
200 | void pop_and_dirty_projected_fnode(LogSegment *ls); | |
201 | bool is_projected() const { return !projected_fnode.empty(); } | |
202 | version_t pre_dirty(version_t min=0); | |
203 | void _mark_dirty(LogSegment *ls); | |
204 | void _set_dirty_flag() { | |
205 | if (!state_test(STATE_DIRTY)) { | |
206 | state_set(STATE_DIRTY); | |
207 | get(PIN_DIRTY); | |
208 | } | |
209 | } | |
210 | void mark_dirty(version_t pv, LogSegment *ls); | |
211 | void mark_clean(); | |
212 | ||
213 | bool is_new() { return item_new.is_on_list(); } | |
214 | void mark_new(LogSegment *ls); | |
215 | ||
216 | bool is_bad() { return state_test(STATE_BADFRAG); } | |
217 | private: | |
218 | void log_mark_dirty(); | |
219 | ||
220 | public: | |
94b18763 FG |
221 | typedef mempool::mds_co::map<dentry_key_t, CDentry*> dentry_key_map; |
222 | typedef mempool::mds_co::set<dentry_key_t> dentry_key_set; | |
7c673cae FG |
223 | |
224 | class scrub_info_t { | |
225 | public: | |
226 | /// inodes we contain with dirty scrub stamps | |
94b18763 | 227 | dentry_key_map dirty_scrub_stamps; // TODO: make use of this! |
7c673cae FG |
228 | struct scrub_stamps { |
229 | version_t version; | |
230 | utime_t time; | |
231 | scrub_stamps() : version(0) {} | |
232 | void operator=(const scrub_stamps &o) { | |
233 | version = o.version; | |
234 | time = o.time; | |
235 | } | |
236 | }; | |
237 | ||
238 | scrub_stamps recursive_start; // when we last started a recursive scrub | |
239 | scrub_stamps last_recursive; // when we last finished a recursive scrub | |
240 | scrub_stamps last_local; // when we last did a local scrub | |
241 | ||
242 | bool directory_scrubbing; /// safety check | |
243 | bool need_scrub_local; | |
244 | bool last_scrub_dirty; /// is scrub info dirty or is it flushed to fnode? | |
245 | bool pending_scrub_error; | |
246 | ||
247 | /// these are lists of children in each stage of scrubbing | |
94b18763 FG |
248 | dentry_key_set directories_to_scrub; |
249 | dentry_key_set directories_scrubbing; | |
250 | dentry_key_set directories_scrubbed; | |
251 | dentry_key_set others_to_scrub; | |
252 | dentry_key_set others_scrubbing; | |
253 | dentry_key_set others_scrubbed; | |
7c673cae FG |
254 | |
255 | ScrubHeaderRefConst header; | |
256 | ||
257 | scrub_info_t() : | |
258 | directory_scrubbing(false), | |
259 | need_scrub_local(false), | |
260 | last_scrub_dirty(false), | |
261 | pending_scrub_error(false) {} | |
262 | }; | |
263 | /** | |
264 | * Call to start this CDir on a new scrub. | |
265 | * @pre It is not currently scrubbing | |
266 | * @pre The CDir is marked complete. | |
267 | * @post It has set up its internal scrubbing state. | |
268 | */ | |
269 | void scrub_initialize(const ScrubHeaderRefConst& header); | |
270 | /** | |
271 | * Get the next dentry to scrub. Gives you a CDentry* and its meaning. This | |
272 | * function will give you all directory-representing dentries before any | |
273 | * others. | |
274 | * 0: success, you should scrub this CDentry right now | |
275 | * EAGAIN: is currently fetching the next CDentry into memory for you. | |
276 | * It will activate your callback when done; try again when it does! | |
277 | * ENOENT: there are no remaining dentries to scrub | |
278 | * <0: There was an unexpected error | |
279 | * | |
280 | * @param cb An MDSInternalContext which will be activated only if | |
281 | * we return EAGAIN via rcode, or else ignored | |
282 | * @param dnout CDentry * which you should next scrub, or NULL | |
283 | * @returns a value as described above | |
284 | */ | |
285 | int scrub_dentry_next(MDSInternalContext *cb, CDentry **dnout); | |
286 | /** | |
287 | * Get the currently scrubbing dentries. When returned, the passed-in | |
288 | * list will be filled with all CDentry * which have been returned | |
289 | * from scrub_dentry_next() but not sent back via scrub_dentry_finished(). | |
290 | */ | |
94b18763 | 291 | void scrub_dentries_scrubbing(std::list<CDentry*> *out_dentries); |
7c673cae FG |
292 | /** |
293 | * Report to the CDir that a CDentry has been scrubbed. Call this | |
294 | * for every CDentry returned from scrub_dentry_next(). | |
295 | * @param dn The CDentry which has been scrubbed. | |
296 | */ | |
297 | void scrub_dentry_finished(CDentry *dn); | |
298 | /** | |
299 | * Call this once all CDentries have been scrubbed, according to | |
300 | * scrub_dentry_next's listing. It finalizes the scrub statistics. | |
301 | */ | |
302 | void scrub_finished(); | |
303 | /** | |
304 | * Tell the CDir to do a local scrub of itself. | |
305 | * @pre The CDir is_complete(). | |
306 | * @returns true if the rstats and directory contents match, false otherwise. | |
307 | */ | |
308 | bool scrub_local(); | |
309 | private: | |
310 | /** | |
311 | * Create a scrub_info_t struct for the scrub_infop pointer. | |
312 | */ | |
313 | void scrub_info_create() const; | |
314 | /** | |
315 | * Delete the scrub_infop if it's not got any useful data. | |
316 | */ | |
317 | void scrub_maybe_delete_info(); | |
318 | /** | |
319 | * Check the given set (presumably one of those in scrub_info_t) for the | |
320 | * next key to scrub and look it up (or fail!). | |
321 | */ | |
94b18763 | 322 | int _next_dentry_on_set(dentry_key_set &dns, bool missing_okay, |
7c673cae FG |
323 | MDSInternalContext *cb, CDentry **dnout); |
324 | ||
325 | ||
326 | protected: | |
94b18763 | 327 | std::unique_ptr<scrub_info_t> scrub_infop; // FIXME not in mempool |
7c673cae FG |
328 | |
329 | // contents of this directory | |
94b18763 | 330 | dentry_key_map items; // non-null AND null |
7c673cae FG |
331 | unsigned num_head_items; |
332 | unsigned num_head_null; | |
333 | unsigned num_snap_items; | |
334 | unsigned num_snap_null; | |
335 | ||
336 | int num_dirty; | |
337 | ||
338 | // state | |
339 | version_t committing_version; | |
340 | version_t committed_version; | |
341 | ||
94b18763 | 342 | mempool::mds_co::compact_set<mempool::mds_co::string> stale_items; |
7c673cae FG |
343 | |
344 | // lock nesting, freeze | |
345 | static int num_frozen_trees; | |
346 | static int num_freezing_trees; | |
347 | ||
348 | int dir_auth_pins; | |
349 | int request_pins; | |
350 | ||
351 | // cache control (defined for authority; hints for replicas) | |
352 | __s32 dir_rep; | |
94b18763 | 353 | mempool::mds_co::compact_set<__s32> dir_rep_by; // if dir_rep == REP_LIST |
7c673cae FG |
354 | |
355 | // popularity | |
356 | dirfrag_load_vec_t pop_me; | |
357 | dirfrag_load_vec_t pop_nested; | |
358 | dirfrag_load_vec_t pop_auth_subtree; | |
359 | dirfrag_load_vec_t pop_auth_subtree_nested; | |
360 | ||
361 | utime_t last_popularity_sample; | |
362 | ||
363 | load_spread_t pop_spread; | |
364 | ||
28e407b8 AA |
365 | elist<CInode*> pop_lru_subdirs; |
366 | ||
7c673cae FG |
367 | // and to provide density |
368 | int num_dentries_nested; | |
369 | int num_dentries_auth_subtree; | |
370 | int num_dentries_auth_subtree_nested; | |
371 | ||
372 | ||
373 | // friends | |
374 | friend class Migrator; | |
375 | friend class CInode; | |
376 | friend class MDCache; | |
377 | friend class MDiscover; | |
378 | friend class MDBalancer; | |
379 | ||
380 | friend class CDirDiscover; | |
381 | friend class CDirExport; | |
382 | friend class C_IO_Dir_TMAP_Fetched; | |
383 | friend class C_IO_Dir_OMAP_Fetched; | |
384 | friend class C_IO_Dir_OMAP_FetchedMore; | |
385 | friend class C_IO_Dir_Committed; | |
386 | ||
94b18763 | 387 | std::unique_ptr<bloom_filter> bloom; // XXX not part of mempool::mds_co |
7c673cae FG |
388 | /* If you set up the bloom filter, you must keep it accurate! |
389 | * It's deleted when you mark_complete() and is deliberately not serialized.*/ | |
390 | ||
391 | public: | |
392 | CDir(CInode *in, frag_t fg, MDCache *mdcache, bool auth); | |
393 | ||
394 | const scrub_info_t *scrub_info() const { | |
395 | if (!scrub_infop) { | |
396 | scrub_info_create(); | |
397 | } | |
398 | return scrub_infop.get(); | |
399 | } | |
400 | ||
401 | ||
402 | // -- accessors -- | |
403 | inodeno_t ino() const { return inode->ino(); } // deprecate me? | |
404 | frag_t get_frag() const { return frag; } | |
405 | dirfrag_t dirfrag() const { return dirfrag_t(inode->ino(), frag); } | |
406 | ||
407 | CInode *get_inode() { return inode; } | |
408 | const CInode *get_inode() const { return inode; } | |
409 | CDir *get_parent_dir() { return inode->get_parent_dir(); } | |
410 | ||
94b18763 FG |
411 | dentry_key_map::iterator begin() { return items.begin(); } |
412 | dentry_key_map::iterator end() { return items.end(); } | |
413 | dentry_key_map::iterator lower_bound(dentry_key_t key) { return items.lower_bound(key); } | |
7c673cae FG |
414 | |
415 | unsigned get_num_head_items() const { return num_head_items; } | |
416 | unsigned get_num_head_null() const { return num_head_null; } | |
417 | unsigned get_num_snap_items() const { return num_snap_items; } | |
418 | unsigned get_num_snap_null() const { return num_snap_null; } | |
419 | unsigned get_num_any() const { return num_head_items + num_head_null + num_snap_items + num_snap_null; } | |
420 | ||
421 | bool check_rstats(bool scrub=false); | |
422 | ||
423 | void inc_num_dirty() { num_dirty++; } | |
424 | void dec_num_dirty() { | |
425 | assert(num_dirty > 0); | |
426 | num_dirty--; | |
427 | } | |
428 | int get_num_dirty() const { | |
429 | return num_dirty; | |
430 | } | |
431 | ||
432 | int64_t get_frag_size() const { | |
433 | return get_projected_fnode()->fragstat.size(); | |
434 | } | |
435 | ||
436 | // -- dentries and inodes -- | |
437 | public: | |
94b18763 FG |
438 | CDentry* lookup_exact_snap(boost::string_view dname, snapid_t last); |
439 | CDentry* lookup(boost::string_view n, snapid_t snap=CEPH_NOSNAP); | |
7c673cae | 440 | CDentry* lookup(const char *n, snapid_t snap=CEPH_NOSNAP) { |
94b18763 | 441 | return lookup(boost::string_view(n), snap); |
7c673cae FG |
442 | } |
443 | ||
94b18763 | 444 | CDentry* add_null_dentry(boost::string_view dname, |
7c673cae | 445 | snapid_t first=2, snapid_t last=CEPH_NOSNAP); |
94b18763 | 446 | CDentry* add_primary_dentry(boost::string_view dname, CInode *in, |
7c673cae | 447 | snapid_t first=2, snapid_t last=CEPH_NOSNAP); |
94b18763 | 448 | CDentry* add_remote_dentry(boost::string_view dname, inodeno_t ino, unsigned char d_type, |
7c673cae FG |
449 | snapid_t first=2, snapid_t last=CEPH_NOSNAP); |
450 | void remove_dentry( CDentry *dn ); // delete dentry | |
451 | void link_remote_inode( CDentry *dn, inodeno_t ino, unsigned char d_type); | |
452 | void link_remote_inode( CDentry *dn, CInode *in ); | |
453 | void link_primary_inode( CDentry *dn, CInode *in ); | |
31f18b77 | 454 | void unlink_inode(CDentry *dn, bool adjust_lru=true); |
7c673cae FG |
455 | void try_remove_unlinked_dn(CDentry *dn); |
456 | ||
457 | void add_to_bloom(CDentry *dn); | |
94b18763 | 458 | bool is_in_bloom(boost::string_view name); |
7c673cae FG |
459 | bool has_bloom() { return (bloom ? true : false); } |
460 | void remove_bloom() { | |
461 | bloom.reset(); | |
462 | } | |
463 | private: | |
464 | void link_inode_work( CDentry *dn, CInode *in ); | |
465 | void unlink_inode_work( CDentry *dn ); | |
466 | void remove_null_dentries(); | |
467 | void purge_stale_snap_data(const std::set<snapid_t>& snaps); | |
468 | public: | |
7c673cae FG |
469 | void try_remove_dentries_for_stray(); |
470 | bool try_trim_snap_dentry(CDentry *dn, const std::set<snapid_t>& snaps); | |
471 | ||
472 | ||
473 | public: | |
94b18763 FG |
474 | void split(int bits, std::list<CDir*>& subs, list<MDSInternalContextBase*>& waiters, bool replay); |
475 | void merge(std::list<CDir*>& subs, std::list<MDSInternalContextBase*>& waiters, bool replay); | |
7c673cae FG |
476 | |
477 | bool should_split() const { | |
478 | return (int)get_frag_size() > g_conf->mds_bal_split_size; | |
479 | } | |
480 | bool should_split_fast() const; | |
481 | bool should_merge() const { | |
482 | return (int)get_frag_size() < g_conf->mds_bal_merge_size; | |
483 | } | |
484 | ||
485 | private: | |
486 | void prepare_new_fragment(bool replay); | |
31f18b77 | 487 | void prepare_old_fragment(map<string_snap_t, std::list<MDSInternalContextBase*> >& dentry_waiters, bool replay); |
7c673cae | 488 | void steal_dentry(CDentry *dn); // from another dir. used by merge/split. |
94b18763 | 489 | void finish_old_fragment(std::list<MDSInternalContextBase*>& waiters, bool replay); |
7c673cae FG |
490 | void init_fragment_pins(); |
491 | ||
492 | ||
493 | // -- authority -- | |
494 | /* | |
495 | * normal: <parent,unknown> !subtree_root | |
496 | * delegation: <mds,unknown> subtree_root | |
497 | * ambiguous: <mds1,mds2> subtree_root | |
498 | * <parent,mds2> subtree_root | |
499 | */ | |
500 | mds_authority_t dir_auth; | |
501 | ||
502 | std::string get_path() const; | |
503 | ||
504 | public: | |
505 | mds_authority_t authority() const override; | |
506 | mds_authority_t get_dir_auth() const { return dir_auth; } | |
507 | void set_dir_auth(mds_authority_t a); | |
508 | void set_dir_auth(mds_rank_t a) { set_dir_auth(mds_authority_t(a, CDIR_AUTH_UNKNOWN)); } | |
509 | bool is_ambiguous_dir_auth() const { | |
510 | return dir_auth.second != CDIR_AUTH_UNKNOWN; | |
511 | } | |
512 | bool is_full_dir_auth() const { | |
513 | return is_auth() && !is_ambiguous_dir_auth(); | |
514 | } | |
515 | bool is_full_dir_nonauth() const { | |
516 | return !is_auth() && !is_ambiguous_dir_auth(); | |
517 | } | |
518 | ||
519 | bool is_subtree_root() const { | |
520 | return dir_auth != CDIR_AUTH_DEFAULT; | |
521 | } | |
522 | ||
523 | bool contains(CDir *x); // true if we are x or an ancestor of x | |
524 | ||
525 | ||
526 | // for giving to clients | |
527 | void get_dist_spec(std::set<mds_rank_t>& ls, mds_rank_t auth) { | |
528 | if (is_rep()) { | |
529 | list_replicas(ls); | |
530 | if (!ls.empty()) | |
531 | ls.insert(auth); | |
532 | } | |
533 | } | |
534 | void encode_dirstat(bufferlist& bl, mds_rank_t whoami) { | |
535 | /* | |
536 | * note: encoding matches struct ceph_client_reply_dirfrag | |
537 | */ | |
538 | frag_t frag = get_frag(); | |
539 | mds_rank_t auth; | |
540 | std::set<mds_rank_t> dist; | |
541 | ||
542 | auth = dir_auth.first; | |
543 | if (is_auth()) | |
544 | get_dist_spec(dist, whoami); | |
545 | ||
546 | ::encode(frag, bl); | |
547 | ::encode(auth, bl); | |
548 | ::encode(dist, bl); | |
549 | } | |
550 | ||
551 | void _encode_base(bufferlist& bl) { | |
552 | ::encode(first, bl); | |
553 | ::encode(fnode, bl); | |
554 | ::encode(dir_rep, bl); | |
555 | ::encode(dir_rep_by, bl); | |
556 | } | |
557 | void _decode_base(bufferlist::iterator& p) { | |
558 | ::decode(first, p); | |
559 | ::decode(fnode, p); | |
560 | ::decode(dir_rep, p); | |
561 | ::decode(dir_rep_by, p); | |
562 | } | |
563 | void encode_replica(mds_rank_t who, bufferlist& bl) { | |
564 | __u32 nonce = add_replica(who); | |
565 | ::encode(nonce, bl); | |
566 | _encode_base(bl); | |
567 | } | |
568 | void decode_replica(bufferlist::iterator& p) { | |
569 | __u32 nonce; | |
570 | ::decode(nonce, p); | |
571 | replica_nonce = nonce; | |
572 | _decode_base(p); | |
573 | } | |
574 | ||
575 | ||
576 | ||
577 | // -- state -- | |
578 | bool is_complete() { return state & STATE_COMPLETE; } | |
579 | bool is_exporting() { return state & STATE_EXPORTING; } | |
580 | bool is_importing() { return state & STATE_IMPORTING; } | |
581 | bool is_dirty_dft() { return state & STATE_DIRTYDFT; } | |
582 | ||
583 | int get_dir_rep() const { return dir_rep; } | |
584 | bool is_rep() const { | |
585 | if (dir_rep == REP_NONE) return false; | |
586 | return true; | |
587 | } | |
588 | ||
589 | // -- fetch -- | |
590 | object_t get_ondisk_object() { | |
591 | return file_object_t(ino(), frag); | |
592 | } | |
593 | void fetch(MDSInternalContextBase *c, bool ignore_authpinnability=false); | |
94b18763 | 594 | void fetch(MDSInternalContextBase *c, boost::string_view want_dn, bool ignore_authpinnability=false); |
7c673cae FG |
595 | void fetch(MDSInternalContextBase *c, const std::set<dentry_key_t>& keys); |
596 | protected: | |
94b18763 | 597 | mempool::mds_co::compact_set<mempool::mds_co::string> wanted_items; |
7c673cae FG |
598 | |
599 | void _omap_fetch(MDSInternalContextBase *fin, const std::set<dentry_key_t>& keys); | |
600 | void _omap_fetch_more( | |
601 | bufferlist& hdrbl, std::map<std::string, bufferlist>& omap, | |
602 | MDSInternalContextBase *fin); | |
603 | CDentry *_load_dentry( | |
94b18763 FG |
604 | boost::string_view key, |
605 | boost::string_view dname, | |
7c673cae FG |
606 | snapid_t last, |
607 | bufferlist &bl, | |
608 | int pos, | |
609 | const std::set<snapid_t> *snaps, | |
28e407b8 | 610 | bool *force_dirty); |
7c673cae FG |
611 | |
612 | /** | |
613 | * Mark this fragment as BADFRAG (common part of go_bad and go_bad_dentry) | |
614 | */ | |
615 | void _go_bad(); | |
616 | ||
617 | /** | |
618 | * Go bad due to a damaged dentry (register with damagetable and go BADFRAG) | |
619 | */ | |
94b18763 | 620 | void go_bad_dentry(snapid_t last, boost::string_view dname); |
7c673cae FG |
621 | |
622 | /** | |
623 | * Go bad due to a damaged header (register with damagetable and go BADFRAG) | |
624 | */ | |
625 | void go_bad(bool complete); | |
626 | ||
627 | void _omap_fetched(bufferlist& hdrbl, std::map<std::string, bufferlist>& omap, | |
628 | bool complete, int r); | |
629 | ||
630 | // -- commit -- | |
94b18763 | 631 | mempool::mds_co::compact_map<version_t, mempool::mds_co::list<MDSInternalContextBase*> > waiting_for_commit; |
7c673cae FG |
632 | void _commit(version_t want, int op_prio); |
633 | void _omap_commit(int op_prio); | |
634 | void _encode_dentry(CDentry *dn, bufferlist& bl, const std::set<snapid_t> *snaps); | |
635 | void _committed(int r, version_t v); | |
636 | public: | |
637 | #if 0 // unused? | |
638 | void wait_for_commit(Context *c, version_t v=0); | |
639 | #endif | |
640 | void commit_to(version_t want); | |
641 | void commit(version_t want, MDSInternalContextBase *c, | |
642 | bool ignore_authpinnability=false, int op_prio=-1); | |
643 | ||
644 | // -- dirtyness -- | |
645 | version_t get_committing_version() const { return committing_version; } | |
646 | version_t get_committed_version() const { return committed_version; } | |
647 | void set_committed_version(version_t v) { committed_version = v; } | |
648 | ||
649 | void mark_complete(); | |
650 | ||
651 | ||
652 | // -- reference counting -- | |
653 | void first_get() override; | |
654 | void last_put() override; | |
655 | ||
656 | void request_pin_get() { | |
657 | if (request_pins == 0) get(PIN_REQUEST); | |
658 | request_pins++; | |
659 | } | |
660 | void request_pin_put() { | |
661 | request_pins--; | |
662 | if (request_pins == 0) put(PIN_REQUEST); | |
663 | } | |
664 | ||
665 | // -- waiters -- | |
666 | protected: | |
94b18763 | 667 | mempool::mds_co::compact_map< string_snap_t, mempool::mds_co::list<MDSInternalContextBase*> > waiting_on_dentry; // FIXME string_snap_t not in mempool |
7c673cae FG |
668 | |
669 | public: | |
94b18763 | 670 | bool is_waiting_for_dentry(boost::string_view dname, snapid_t snap) { |
7c673cae FG |
671 | return waiting_on_dentry.count(string_snap_t(dname, snap)); |
672 | } | |
94b18763 FG |
673 | void add_dentry_waiter(boost::string_view dentry, snapid_t snap, MDSInternalContextBase *c); |
674 | void take_dentry_waiting(boost::string_view dentry, snapid_t first, snapid_t last, std::list<MDSInternalContextBase*>& ls); | |
7c673cae FG |
675 | void take_sub_waiting(std::list<MDSInternalContextBase*>& ls); // dentry or ino |
676 | ||
677 | void add_waiter(uint64_t mask, MDSInternalContextBase *c) override; | |
678 | void take_waiting(uint64_t mask, std::list<MDSInternalContextBase*>& ls) override; // may include dentry waiters | |
679 | void finish_waiting(uint64_t mask, int result = 0); // ditto | |
680 | ||
681 | ||
682 | // -- import/export -- | |
683 | void encode_export(bufferlist& bl); | |
684 | void finish_export(utime_t now); | |
685 | void abort_export() { | |
686 | put(PIN_TEMPEXPORTING); | |
687 | } | |
688 | void decode_import(bufferlist::iterator& blp, utime_t now, LogSegment *ls); | |
689 | ||
690 | // -- auth pins -- | |
691 | bool can_auth_pin() const override { return is_auth() && !(is_frozen() || is_freezing()); } | |
692 | int get_cum_auth_pins() const { return auth_pins + nested_auth_pins; } | |
693 | int get_auth_pins() const { return auth_pins; } | |
694 | int get_nested_auth_pins() const { return nested_auth_pins; } | |
695 | int get_dir_auth_pins() const { return dir_auth_pins; } | |
696 | void auth_pin(void *who) override; | |
697 | void auth_unpin(void *who) override; | |
698 | ||
699 | void adjust_nested_auth_pins(int inc, int dirinc, void *by); | |
700 | void verify_fragstat(); | |
701 | ||
702 | // -- freezing -- | |
703 | bool freeze_tree(); | |
704 | void _freeze_tree(); | |
705 | void unfreeze_tree(); | |
706 | ||
707 | bool freeze_dir(); | |
708 | void _freeze_dir(); | |
709 | void unfreeze_dir(); | |
710 | ||
711 | void maybe_finish_freeze(); | |
712 | ||
713 | bool is_freezing() const override { return is_freezing_tree() || is_freezing_dir(); } | |
714 | bool is_freezing_tree() const; | |
715 | bool is_freezing_tree_root() const { return state & STATE_FREEZINGTREE; } | |
716 | bool is_freezing_dir() const { return state & STATE_FREEZINGDIR; } | |
717 | ||
718 | bool is_frozen() const override { return is_frozen_dir() || is_frozen_tree(); } | |
719 | bool is_frozen_tree() const; | |
720 | bool is_frozen_tree_root() const { return state & STATE_FROZENTREE; } | |
721 | bool is_frozen_dir() const { return state & STATE_FROZENDIR; } | |
722 | ||
723 | bool is_freezeable(bool freezing=false) const { | |
724 | // no nested auth pins. | |
725 | if ((auth_pins-freezing) > 0 || nested_auth_pins > 0) | |
726 | return false; | |
727 | ||
728 | // inode must not be frozen. | |
729 | if (!is_subtree_root() && inode->is_frozen()) | |
730 | return false; | |
731 | ||
732 | return true; | |
733 | } | |
734 | bool is_freezeable_dir(bool freezing=false) const { | |
735 | if ((auth_pins-freezing) > 0 || dir_auth_pins > 0) | |
736 | return false; | |
737 | ||
738 | // if not subtree root, inode must not be frozen (tree--frozen_dir is okay). | |
739 | if (!is_subtree_root() && inode->is_frozen() && !inode->is_frozen_dir()) | |
740 | return false; | |
741 | ||
742 | return true; | |
743 | } | |
744 | ||
745 | CDir *get_frozen_tree_root(); | |
746 | ||
747 | ||
748 | ostream& print_db_line_prefix(ostream& out) override; | |
749 | void print(ostream& out) override; | |
750 | void dump(Formatter *f) const; | |
28e407b8 | 751 | void dump_load(Formatter *f, utime_t now, const DecayRate& rate); |
7c673cae FG |
752 | }; |
753 | ||
754 | #endif |