1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16#include <linux/kernel.h>
17#include <linux/module.h>
18#include <linux/init.h>
19#include <linux/circ_buf.h>
20#include <linux/sched.h>
21#include "internal.h"
22
23
24
25
26
27
28
29void afs_invalidate_mmap_work(struct work_struct *work)
30{
31 struct afs_vnode *vnode = container_of(work, struct afs_vnode, cb_work);
32
33 unmap_mapping_pages(vnode->vfs_inode.i_mapping, 0, 0, false);
34}
35
36void afs_server_init_callback_work(struct work_struct *work)
37{
38 struct afs_server *server = container_of(work, struct afs_server, initcb_work);
39 struct afs_vnode *vnode;
40 struct afs_cell *cell = server->cell;
41
42 down_read(&cell->fs_open_mmaps_lock);
43
44 list_for_each_entry(vnode, &cell->fs_open_mmaps, cb_mmap_link) {
45 if (vnode->cb_server == server) {
46 clear_bit(AFS_VNODE_CB_PROMISED, &vnode->flags);
47 queue_work(system_unbound_wq, &vnode->cb_work);
48 }
49 }
50
51 up_read(&cell->fs_open_mmaps_lock);
52}
53
54
55
56
57
58void afs_init_callback_state(struct afs_server *server)
59{
60 rcu_read_lock();
61 do {
62 server->cb_s_break++;
63 atomic_inc(&server->cell->fs_s_break);
64 if (!list_empty(&server->cell->fs_open_mmaps))
65 queue_work(system_unbound_wq, &server->initcb_work);
66
67 } while ((server = rcu_dereference(server->uuid_next)));
68 rcu_read_unlock();
69}
70
71
72
73
74void __afs_break_callback(struct afs_vnode *vnode, enum afs_cb_break_reason reason)
75{
76 _enter("");
77
78 clear_bit(AFS_VNODE_NEW_CONTENT, &vnode->flags);
79 if (test_and_clear_bit(AFS_VNODE_CB_PROMISED, &vnode->flags)) {
80 vnode->cb_break++;
81 vnode->cb_v_break = vnode->volume->cb_v_break;
82 afs_clear_permits(vnode);
83
84 if (vnode->lock_state == AFS_VNODE_LOCK_WAITING_FOR_CB)
85 afs_lock_may_be_available(vnode);
86
87 if (reason != afs_cb_break_for_deleted &&
88 vnode->status.type == AFS_FTYPE_FILE &&
89 atomic_read(&vnode->cb_nr_mmap))
90 queue_work(system_unbound_wq, &vnode->cb_work);
91
92 trace_afs_cb_break(&vnode->fid, vnode->cb_break, reason, true);
93 } else {
94 trace_afs_cb_break(&vnode->fid, vnode->cb_break, reason, false);
95 }
96}
97
98void afs_break_callback(struct afs_vnode *vnode, enum afs_cb_break_reason reason)
99{
100 write_seqlock(&vnode->cb_lock);
101 __afs_break_callback(vnode, reason);
102 write_sequnlock(&vnode->cb_lock);
103}
104
105
106
107
108static struct afs_volume *afs_lookup_volume_rcu(struct afs_cell *cell,
109 afs_volid_t vid)
110{
111 struct afs_volume *volume = NULL;
112 struct rb_node *p;
113 int seq = 0;
114
115 do {
116
117
118
119
120 read_seqbegin_or_lock(&cell->volume_lock, &seq);
121
122 p = rcu_dereference_raw(cell->volumes.rb_node);
123 while (p) {
124 volume = rb_entry(p, struct afs_volume, cell_node);
125
126 if (volume->vid < vid)
127 p = rcu_dereference_raw(p->rb_left);
128 else if (volume->vid > vid)
129 p = rcu_dereference_raw(p->rb_right);
130 else
131 break;
132 volume = NULL;
133 }
134
135 } while (need_seqretry(&cell->volume_lock, seq));
136
137 done_seqretry(&cell->volume_lock, seq);
138 return volume;
139}
140
141
142
143
144
145
146
147static void afs_break_one_callback(struct afs_volume *volume,
148 struct afs_fid *fid)
149{
150 struct super_block *sb;
151 struct afs_vnode *vnode;
152 struct inode *inode;
153
154 if (fid->vnode == 0 && fid->unique == 0) {
155
156 write_lock(&volume->cb_v_break_lock);
157 volume->cb_v_break++;
158 trace_afs_cb_break(fid, volume->cb_v_break,
159 afs_cb_break_for_volume_callback, false);
160 write_unlock(&volume->cb_v_break_lock);
161 return;
162 }
163
164
165
166
167
168 sb = rcu_dereference(volume->sb);
169 if (!sb)
170 return;
171
172 inode = find_inode_rcu(sb, fid->vnode, afs_ilookup5_test_by_fid, fid);
173 if (inode) {
174 vnode = AFS_FS_I(inode);
175 afs_break_callback(vnode, afs_cb_break_for_callback);
176 } else {
177 trace_afs_cb_miss(fid, afs_cb_break_for_callback);
178 }
179}
180
181static void afs_break_some_callbacks(struct afs_server *server,
182 struct afs_callback_break *cbb,
183 size_t *_count)
184{
185 struct afs_callback_break *residue = cbb;
186 struct afs_volume *volume;
187 afs_volid_t vid = cbb->fid.vid;
188 size_t i;
189
190 volume = afs_lookup_volume_rcu(server->cell, vid);
191
192
193
194
195
196 for (i = *_count; i > 0; cbb++, i--) {
197 if (cbb->fid.vid == vid) {
198 _debug("- Fid { vl=%08llx n=%llu u=%u }",
199 cbb->fid.vid,
200 cbb->fid.vnode,
201 cbb->fid.unique);
202 --*_count;
203 if (volume)
204 afs_break_one_callback(volume, &cbb->fid);
205 } else {
206 *residue++ = *cbb;
207 }
208 }
209}
210
211
212
213
214void afs_break_callbacks(struct afs_server *server, size_t count,
215 struct afs_callback_break *callbacks)
216{
217 _enter("%p,%zu,", server, count);
218
219 ASSERT(server != NULL);
220
221 rcu_read_lock();
222
223 while (count > 0)
224 afs_break_some_callbacks(server, callbacks, &count);
225
226 rcu_read_unlock();
227 return;
228}
229