]>
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 | #ifndef CEPH_MDS_SNAPREALM_H | |
16 | #define CEPH_MDS_SNAPREALM_H | |
17 | ||
11fdf7f2 | 18 | #include <string_view> |
94b18763 | 19 | |
7c673cae FG |
20 | #include "mdstypes.h" |
21 | #include "snap.h" | |
22 | #include "include/xlist.h" | |
23 | #include "include/elist.h" | |
24 | #include "common/snap_types.h" | |
11fdf7f2 | 25 | #include "MDSContext.h" |
7c673cae FG |
26 | |
27 | struct SnapRealm { | |
7c673cae | 28 | public: |
11fdf7f2 | 29 | SnapRealm(MDCache *c, CInode *in); |
7c673cae | 30 | |
11fdf7f2 | 31 | bool exists(std::string_view name) const { |
7c673cae FG |
32 | for (map<snapid_t,SnapInfo>::const_iterator p = srnode.snaps.begin(); |
33 | p != srnode.snaps.end(); | |
34 | ++p) { | |
35 | if (p->second.name == name) | |
36 | return true; | |
37 | } | |
38 | return false; | |
39 | } | |
40 | ||
11fdf7f2 TL |
41 | bool _open_parents(MDSContext *retryorfinish, snapid_t first=1, snapid_t last=CEPH_NOSNAP); |
42 | bool open_parents(MDSContext *retryorfinish); | |
7c673cae | 43 | void _remove_missing_parent(snapid_t snapid, inodeno_t parent, int err); |
11fdf7f2 | 44 | bool have_past_parents_open(snapid_t first=1, snapid_t last=CEPH_NOSNAP) const; |
7c673cae FG |
45 | void add_open_past_parent(SnapRealm *parent, snapid_t last); |
46 | void remove_open_past_parent(inodeno_t ino, snapid_t last); | |
47 | void close_parents(); | |
48 | ||
49 | void prune_past_parents(); | |
11fdf7f2 TL |
50 | bool has_past_parents() const { |
51 | return !srnode.past_parent_snaps.empty() || | |
52 | !srnode.past_parents.empty(); | |
53 | } | |
7c673cae | 54 | |
11fdf7f2 TL |
55 | void build_snap_set() const; |
56 | void get_snap_info(map<snapid_t, const SnapInfo*>& infomap, snapid_t first=0, snapid_t last=CEPH_NOSNAP); | |
7c673cae | 57 | |
11fdf7f2 TL |
58 | const bufferlist& get_snap_trace() const; |
59 | void build_snap_trace() const; | |
7c673cae | 60 | |
11fdf7f2 TL |
61 | std::string_view get_snapname(snapid_t snapid, inodeno_t atino); |
62 | snapid_t resolve_snapname(std::string_view name, inodeno_t atino, snapid_t first=0, snapid_t last=CEPH_NOSNAP); | |
7c673cae FG |
63 | |
64 | const set<snapid_t>& get_snaps() const; | |
65 | const SnapContext& get_snap_context() const; | |
66 | void invalidate_cached_snaps() { | |
67 | cached_seq = 0; | |
68 | } | |
69 | snapid_t get_last_created() { | |
70 | check_cache(); | |
71 | return cached_last_created; | |
72 | } | |
73 | snapid_t get_last_destroyed() { | |
74 | check_cache(); | |
75 | return cached_last_destroyed; | |
76 | } | |
77 | snapid_t get_newest_snap() { | |
78 | check_cache(); | |
79 | if (cached_snaps.empty()) | |
80 | return 0; | |
81 | else | |
82 | return *cached_snaps.rbegin(); | |
83 | } | |
84 | snapid_t get_newest_seq() { | |
85 | check_cache(); | |
86 | return cached_seq; | |
87 | } | |
88 | ||
89 | snapid_t get_snap_following(snapid_t follows) { | |
90 | check_cache(); | |
91 | const set<snapid_t>& s = get_snaps(); | |
92 | set<snapid_t>::const_iterator p = s.upper_bound(follows); | |
93 | if (p != s.end()) | |
94 | return *p; | |
95 | return CEPH_NOSNAP; | |
96 | } | |
97 | ||
98 | bool has_snaps_in_range(snapid_t first, snapid_t last) { | |
99 | check_cache(); | |
100 | const set<snapid_t>& s = get_snaps(); | |
101 | set<snapid_t>::const_iterator p = s.lower_bound(first); | |
102 | return (p != s.end() && *p <= last); | |
103 | } | |
104 | ||
105 | void adjust_parent(); | |
106 | ||
107 | void split_at(SnapRealm *child); | |
11fdf7f2 | 108 | void merge_to(SnapRealm *newparent); |
7c673cae FG |
109 | |
110 | void add_cap(client_t client, Capability *cap) { | |
111 | auto client_caps_entry = client_caps.find(client); | |
112 | if (client_caps_entry == client_caps.end()) | |
113 | client_caps_entry = client_caps.emplace(client, | |
114 | new xlist<Capability*>).first; | |
115 | client_caps_entry->second->push_back(&cap->item_snaprealm_caps); | |
116 | } | |
117 | void remove_cap(client_t client, Capability *cap) { | |
118 | cap->item_snaprealm_caps.remove_myself(); | |
eafe8130 TL |
119 | auto found = client_caps.find(client); |
120 | if (found != client_caps.end() && found->second->empty()) { | |
121 | delete found->second; | |
122 | client_caps.erase(found); | |
7c673cae FG |
123 | } |
124 | } | |
9f95a23c TL |
125 | |
126 | // realm state | |
127 | sr_t srnode; | |
128 | ||
129 | // in-memory state | |
130 | MDCache *mdcache; | |
131 | CInode *inode; | |
132 | ||
133 | bool past_parents_dirty = false; | |
134 | ||
135 | SnapRealm *parent = nullptr; | |
136 | set<SnapRealm*> open_children; // active children that are currently open | |
137 | set<SnapRealm*> open_past_children; // past children who has pinned me | |
138 | ||
139 | elist<CInode*> inodes_with_caps = 0; // for efficient realm splits | |
140 | map<client_t, xlist<Capability*>* > client_caps; // to identify clients who need snap notifications | |
141 | ||
142 | protected: | |
143 | void check_cache() const; | |
144 | ||
145 | private: | |
146 | mutable bool open = false; // set to true once all past_parents are opened | |
147 | bool global; | |
148 | ||
149 | map<inodeno_t, pair<SnapRealm*, set<snapid_t> > > open_past_parents; // these are explicitly pinned. | |
150 | unsigned num_open_past_parents = 0; | |
151 | ||
152 | // cache | |
153 | mutable snapid_t cached_seq; // max seq over self and all past+present parents. | |
154 | mutable snapid_t cached_last_created; // max last_created over all past+present parents | |
155 | mutable snapid_t cached_last_destroyed; | |
156 | mutable set<snapid_t> cached_snaps; | |
157 | mutable SnapContext cached_snap_context; | |
158 | mutable bufferlist cached_snap_trace; | |
7c673cae FG |
159 | }; |
160 | ||
161 | ostream& operator<<(ostream& out, const SnapRealm &realm); | |
7c673cae | 162 | #endif |