]>
Commit | Line | Data |
---|---|---|
7c673cae FG |
1 | #ifndef CEPH_CLIENT_DENTRY_H |
2 | #define CEPH_CLIENT_DENTRY_H | |
3 | ||
4 | #include "include/lru.h" | |
5 | #include "include/xlist.h" | |
6 | ||
7 | #include "mds/mdstypes.h" | |
11fdf7f2 | 8 | #include "Inode.h" |
7c673cae | 9 | #include "InodeRef.h" |
11fdf7f2 | 10 | #include "Dir.h" |
7c673cae FG |
11 | |
12 | class Dentry : public LRUObject { | |
11fdf7f2 TL |
13 | public: |
14 | explicit Dentry(Dir *_dir, const std::string &_name) : | |
15 | dir(_dir), name(_name), inode_xlist_link(this) | |
16 | { | |
17 | auto r = dir->dentries.insert(make_pair(name, this)); | |
18 | ceph_assert(r.second); | |
19 | dir->num_null_dentries++; | |
20 | } | |
21 | ~Dentry() { | |
22 | ceph_assert(ref == 0); | |
23 | ceph_assert(dir == nullptr); | |
24 | } | |
7c673cae FG |
25 | |
26 | /* | |
27 | * ref==1 -> cached, unused | |
28 | * ref >1 -> pinned in lru | |
29 | */ | |
30 | void get() { | |
11fdf7f2 | 31 | ceph_assert(ref > 0); |
7c673cae FG |
32 | if (++ref == 2) |
33 | lru_pin(); | |
34 | //cout << "dentry.get on " << this << " " << name << " now " << ref << std::endl; | |
35 | } | |
36 | void put() { | |
11fdf7f2 | 37 | ceph_assert(ref > 0); |
7c673cae FG |
38 | if (--ref == 1) |
39 | lru_unpin(); | |
40 | //cout << "dentry.put on " << this << " " << name << " now " << ref << std::endl; | |
41 | if (ref == 0) | |
42 | delete this; | |
43 | } | |
11fdf7f2 TL |
44 | void link(InodeRef in) { |
45 | inode = in; | |
46 | inode->dentries.push_back(&inode_xlist_link); | |
47 | if (inode->is_dir()) { | |
48 | if (inode->dir) | |
49 | get(); // dir -> dn pin | |
50 | if (inode->ll_ref) | |
51 | get(); // ll_ref -> dn pin | |
52 | } | |
53 | dir->num_null_dentries--; | |
54 | } | |
55 | void unlink(void) { | |
56 | if (inode->is_dir()) { | |
57 | if (inode->dir) | |
58 | put(); // dir -> dn pin | |
59 | if (inode->ll_ref) | |
60 | put(); // ll_ref -> dn pin | |
61 | } | |
62 | ceph_assert(inode_xlist_link.get_list() == &inode->dentries); | |
63 | inode_xlist_link.remove_myself(); | |
64 | inode.reset(); | |
65 | dir->num_null_dentries++; | |
66 | } | |
f91f0fd5 TL |
67 | void mark_primary() { |
68 | if (inode && inode->dentries.front() != this) | |
69 | inode->dentries.push_front(&inode_xlist_link); | |
70 | } | |
11fdf7f2 TL |
71 | void detach(void) { |
72 | ceph_assert(!inode); | |
73 | auto p = dir->dentries.find(name); | |
74 | ceph_assert(p != dir->dentries.end()); | |
75 | dir->dentries.erase(p); | |
76 | dir->num_null_dentries--; | |
77 | dir = nullptr; | |
78 | } | |
7c673cae FG |
79 | |
80 | void dump(Formatter *f) const; | |
11fdf7f2 TL |
81 | friend std::ostream &operator<<(std::ostream &oss, const Dentry &Dentry); |
82 | ||
83 | Dir *dir; | |
20effc67 | 84 | const std::string name; |
11fdf7f2 TL |
85 | InodeRef inode; |
86 | int ref = 1; // 1 if there's a dir beneath me. | |
87 | int64_t offset = 0; | |
88 | mds_rank_t lease_mds = -1; | |
89 | utime_t lease_ttl; | |
90 | uint64_t lease_gen = 0; | |
91 | ceph_seq_t lease_seq = 0; | |
92 | int cap_shared_gen = 0; | |
f67539c2 | 93 | std::string alternate_name; |
aee94f69 | 94 | bool is_renaming = false; |
7c673cae | 95 | |
7c673cae | 96 | private: |
11fdf7f2 | 97 | xlist<Dentry *>::item inode_xlist_link; |
7c673cae FG |
98 | }; |
99 | ||
7c673cae | 100 | #endif |