aboutsummaryrefslogtreecommitdiffstats
path: root/fs/afs/callback.c
diff options
context:
space:
mode:
Diffstat (limited to 'fs/afs/callback.c')
-rw-r--r--fs/afs/callback.c469
1 files changed, 373 insertions, 96 deletions
diff --git a/fs/afs/callback.c b/fs/afs/callback.c
index 26a48fea42f4..611215547142 100644
--- a/fs/afs/callback.c
+++ b/fs/afs/callback.c
@@ -1,5 +1,5 @@
1/* 1/*
2 * Copyright (c) 2002 Red Hat, Inc. All rights reserved. 2 * Copyright (c) 2002, 2007 Red Hat, Inc. All rights reserved.
3 * 3 *
4 * This software may be freely redistributed under the terms of the 4 * This software may be freely redistributed under the terms of the
5 * GNU General Public License. 5 * GNU General Public License.
@@ -16,83 +16,182 @@
16#include <linux/kernel.h> 16#include <linux/kernel.h>
17#include <linux/module.h> 17#include <linux/module.h>
18#include <linux/init.h> 18#include <linux/init.h>
19#include "server.h" 19#include <linux/circ_buf.h>
20#include "vnode.h"
21#include "internal.h" 20#include "internal.h"
22#include "cmservice.h" 21
22unsigned afs_vnode_update_timeout = 10;
23
24#define afs_breakring_space(server) \
25 CIRC_SPACE((server)->cb_break_head, (server)->cb_break_tail, \
26 ARRAY_SIZE((server)->cb_break))
27
28//static void afs_callback_updater(struct work_struct *);
29
30static struct workqueue_struct *afs_callback_update_worker;
23 31
24/* 32/*
25 * allow the fileserver to request callback state (re-)initialisation 33 * allow the fileserver to request callback state (re-)initialisation
26 */ 34 */
27int SRXAFSCM_InitCallBackState(struct afs_server *server) 35void afs_init_callback_state(struct afs_server *server)
28{ 36{
29 struct list_head callbacks; 37 struct afs_vnode *vnode;
30 38
31 _enter("%p", server); 39 _enter("{%p}", server);
32 40
33 INIT_LIST_HEAD(&callbacks);
34
35 /* transfer the callback list from the server to a temp holding area */
36 spin_lock(&server->cb_lock); 41 spin_lock(&server->cb_lock);
37 42
38 list_add(&callbacks, &server->cb_promises); 43 /* kill all the promises on record from this server */
39 list_del_init(&server->cb_promises); 44 while (!RB_EMPTY_ROOT(&server->cb_promises)) {
45 vnode = rb_entry(server->cb_promises.rb_node,
46 struct afs_vnode, cb_promise);
47 printk("\nUNPROMISE on %p\n", vnode);
48 rb_erase(&vnode->cb_promise, &server->cb_promises);
49 vnode->cb_promised = false;
50 }
40 51
41 /* munch our way through the list, grabbing the inode, dropping all the 52 spin_unlock(&server->cb_lock);
42 * locks and regetting them in the right order 53 _leave("");
43 */ 54}
44 while (!list_empty(&callbacks)) {
45 struct afs_vnode *vnode;
46 struct inode *inode;
47 55
48 vnode = list_entry(callbacks.next, struct afs_vnode, cb_link); 56/*
49 list_del_init(&vnode->cb_link); 57 * handle the data invalidation side of a callback being broken
58 */
59void afs_broken_callback_work(struct work_struct *work)
60{
61 struct afs_vnode *vnode =
62 container_of(work, struct afs_vnode, cb_broken_work);
50 63
51 /* try and grab the inode - may fail */ 64 _enter("");
52 inode = igrab(AFS_VNODE_TO_I(vnode));
53 if (inode) {
54 int release = 0;
55 65
56 spin_unlock(&server->cb_lock); 66 if (test_bit(AFS_VNODE_DELETED, &vnode->flags))
57 spin_lock(&vnode->lock); 67 return;
58 68
59 if (vnode->cb_server == server) { 69 /* we're only interested in dealing with a broken callback on *this*
60 vnode->cb_server = NULL; 70 * vnode and only if no-one else has dealt with it yet */
61 afs_kafstimod_del_timer(&vnode->cb_timeout); 71 if (!mutex_trylock(&vnode->cb_broken_lock))
62 spin_lock(&afs_cb_hash_lock); 72 return; /* someone else is dealing with it */
63 list_del_init(&vnode->cb_hash_link);
64 spin_unlock(&afs_cb_hash_lock);
65 release = 1;
66 }
67 73
68 spin_unlock(&vnode->lock); 74 if (test_bit(AFS_VNODE_CB_BROKEN, &vnode->flags)) {
75 if (afs_vnode_fetch_status(vnode) < 0)
76 goto out;
69 77
70 iput(inode); 78 if (test_bit(AFS_VNODE_DELETED, &vnode->flags))
71 afs_put_server(server); 79 goto out;
72 80
73 spin_lock(&server->cb_lock); 81 /* if the vnode's data version number changed then its contents
82 * are different */
83 if (test_and_clear_bit(AFS_VNODE_ZAP_DATA, &vnode->flags)) {
84 _debug("zap data");
85 invalidate_remote_inode(&vnode->vfs_inode);
74 } 86 }
75 } 87 }
76 88
77 spin_unlock(&server->cb_lock); 89out:
90 mutex_unlock(&vnode->cb_broken_lock);
78 91
79 _leave(" = 0"); 92 /* avoid the potential race whereby the mutex_trylock() in this
80 return 0; 93 * function happens again between the clear_bit() and the
94 * mutex_unlock() */
95 if (test_bit(AFS_VNODE_CB_BROKEN, &vnode->flags)) {
96 _debug("requeue");
97 queue_work(afs_callback_update_worker, &vnode->cb_broken_work);
98 }
99 _leave("");
100}
101
102/*
103 * actually break a callback
104 */
105static void afs_break_callback(struct afs_server *server,
106 struct afs_vnode *vnode)
107{
108 _enter("");
109
110 set_bit(AFS_VNODE_CB_BROKEN, &vnode->flags);
111
112 if (vnode->cb_promised) {
113 spin_lock(&vnode->lock);
114
115 _debug("break callback");
116
117 spin_lock(&server->cb_lock);
118 if (vnode->cb_promised) {
119 rb_erase(&vnode->cb_promise, &server->cb_promises);
120 vnode->cb_promised = false;
121 }
122 spin_unlock(&server->cb_lock);
123
124 queue_work(afs_callback_update_worker, &vnode->cb_broken_work);
125 spin_unlock(&vnode->lock);
126 }
127}
128
129/*
130 * allow the fileserver to explicitly break one callback
131 * - happens when
132 * - the backing file is changed
133 * - a lock is released
134 */
135static void afs_break_one_callback(struct afs_server *server,
136 struct afs_fid *fid)
137{
138 struct afs_vnode *vnode;
139 struct rb_node *p;
140
141 _debug("find");
142 spin_lock(&server->fs_lock);
143 p = server->fs_vnodes.rb_node;
144 while (p) {
145 vnode = rb_entry(p, struct afs_vnode, server_rb);
146 if (fid->vid < vnode->fid.vid)
147 p = p->rb_left;
148 else if (fid->vid > vnode->fid.vid)
149 p = p->rb_right;
150 else if (fid->vnode < vnode->fid.vnode)
151 p = p->rb_left;
152 else if (fid->vnode > vnode->fid.vnode)
153 p = p->rb_right;
154 else if (fid->unique < vnode->fid.unique)
155 p = p->rb_left;
156 else if (fid->unique > vnode->fid.unique)
157 p = p->rb_right;
158 else
159 goto found;
160 }
161
162 /* not found so we just ignore it (it may have moved to another
163 * server) */
164not_available:
165 _debug("not avail");
166 spin_unlock(&server->fs_lock);
167 _leave("");
168 return;
169
170found:
171 _debug("found");
172 ASSERTCMP(server, ==, vnode->server);
173
174 if (!igrab(AFS_VNODE_TO_I(vnode)))
175 goto not_available;
176 spin_unlock(&server->fs_lock);
177
178 afs_break_callback(server, vnode);
179 iput(&vnode->vfs_inode);
180 _leave("");
81} 181}
82 182
83/* 183/*
84 * allow the fileserver to break callback promises 184 * allow the fileserver to break callback promises
85 */ 185 */
86int SRXAFSCM_CallBack(struct afs_server *server, size_t count, 186void afs_break_callbacks(struct afs_server *server, size_t count,
87 struct afs_callback callbacks[]) 187 struct afs_callback callbacks[])
88{ 188{
89 _enter("%p,%u,", server, count); 189 _enter("%p,%zu,", server, count);
90 190
91 for (; count > 0; callbacks++, count--) { 191 ASSERT(server != NULL);
92 struct afs_vnode *vnode = NULL; 192 ASSERTCMP(count, <=, AFSCBMAX);
93 struct inode *inode = NULL;
94 int valid = 0;
95 193
194 for (; count > 0; callbacks++, count--) {
96 _debug("- Fid { vl=%08x n=%u u=%u } CB { v=%u x=%u t=%u }", 195 _debug("- Fid { vl=%08x n=%u u=%u } CB { v=%u x=%u t=%u }",
97 callbacks->fid.vid, 196 callbacks->fid.vid,
98 callbacks->fid.vnode, 197 callbacks->fid.vnode,
@@ -101,66 +200,244 @@ int SRXAFSCM_CallBack(struct afs_server *server, size_t count,
101 callbacks->expiry, 200 callbacks->expiry,
102 callbacks->type 201 callbacks->type
103 ); 202 );
203 afs_break_one_callback(server, &callbacks->fid);
204 }
205
206 _leave("");
207 return;
208}
104 209
105 /* find the inode for this fid */ 210/*
106 spin_lock(&afs_cb_hash_lock); 211 * record the callback for breaking
212 * - the caller must hold server->cb_lock
213 */
214static void afs_do_give_up_callback(struct afs_server *server,
215 struct afs_vnode *vnode)
216{
217 struct afs_callback *cb;
107 218
108 list_for_each_entry(vnode, 219 _enter("%p,%p", server, vnode);
109 &afs_cb_hash(server, &callbacks->fid),
110 cb_hash_link) {
111 if (memcmp(&vnode->fid, &callbacks->fid,
112 sizeof(struct afs_fid)) != 0)
113 continue;
114 220
115 /* right vnode, but is it same server? */ 221 cb = &server->cb_break[server->cb_break_head];
116 if (vnode->cb_server != server) 222 cb->fid = vnode->fid;
117 break; /* no */ 223 cb->version = vnode->cb_version;
224 cb->expiry = vnode->cb_expiry;
225 cb->type = vnode->cb_type;
226 smp_wmb();
227 server->cb_break_head =
228 (server->cb_break_head + 1) &
229 (ARRAY_SIZE(server->cb_break) - 1);
118 230
119 /* try and nail the inode down */ 231 /* defer the breaking of callbacks to try and collect as many as
120 inode = igrab(AFS_VNODE_TO_I(vnode)); 232 * possible to ship in one operation */
121 break; 233 switch (atomic_inc_return(&server->cb_break_n)) {
234 case 1 ... AFSCBMAX - 1:
235 queue_delayed_work(afs_callback_update_worker,
236 &server->cb_break_work, HZ * 2);
237 break;
238 case AFSCBMAX:
239 afs_flush_callback_breaks(server);
240 break;
241 default:
242 break;
243 }
244
245 ASSERT(server->cb_promises.rb_node != NULL);
246 rb_erase(&vnode->cb_promise, &server->cb_promises);
247 vnode->cb_promised = false;
248 _leave("");
249}
250
251/*
252 * give up the callback registered for a vnode on the file server when the
253 * inode is being cleared
254 */
255void afs_give_up_callback(struct afs_vnode *vnode)
256{
257 struct afs_server *server = vnode->server;
258
259 DECLARE_WAITQUEUE(myself, current);
260
261 _enter("%d", vnode->cb_promised);
262
263 _debug("GIVE UP INODE %p", &vnode->vfs_inode);
264
265 if (!vnode->cb_promised) {
266 _leave(" [not promised]");
267 return;
268 }
269
270 ASSERT(server != NULL);
271
272 spin_lock(&server->cb_lock);
273 if (vnode->cb_promised && afs_breakring_space(server) == 0) {
274 add_wait_queue(&server->cb_break_waitq, &myself);
275 for (;;) {
276 set_current_state(TASK_UNINTERRUPTIBLE);
277 if (!vnode->cb_promised ||
278 afs_breakring_space(server) != 0)
279 break;
280 spin_unlock(&server->cb_lock);
281 schedule();
282 spin_lock(&server->cb_lock);
122 } 283 }
284 remove_wait_queue(&server->cb_break_waitq, &myself);
285 __set_current_state(TASK_RUNNING);
286 }
287
288 /* of course, it's always possible for the server to break this vnode's
289 * callback first... */
290 if (vnode->cb_promised)
291 afs_do_give_up_callback(server, vnode);
292
293 spin_unlock(&server->cb_lock);
294 _leave("");
295}
296
297/*
298 * dispatch a deferred give up callbacks operation
299 */
300void afs_dispatch_give_up_callbacks(struct work_struct *work)
301{
302 struct afs_server *server =
303 container_of(work, struct afs_server, cb_break_work.work);
304
305 _enter("");
306
307 /* tell the fileserver to discard the callback promises it has
308 * - in the event of ENOMEM or some other error, we just forget that we
309 * had callbacks entirely, and the server will call us later to break
310 * them
311 */
312 afs_fs_give_up_callbacks(server, &afs_async_call);
313}
314
315/*
316 * flush the outstanding callback breaks on a server
317 */
318void afs_flush_callback_breaks(struct afs_server *server)
319{
320 cancel_delayed_work(&server->cb_break_work);
321 queue_delayed_work(afs_callback_update_worker,
322 &server->cb_break_work, 0);
323}
324
325#if 0
326/*
327 * update a bunch of callbacks
328 */
329static void afs_callback_updater(struct work_struct *work)
330{
331 struct afs_server *server;
332 struct afs_vnode *vnode, *xvnode;
333 time_t now;
334 long timeout;
335 int ret;
336
337 server = container_of(work, struct afs_server, updater);
338
339 _enter("");
123 340
124 spin_unlock(&afs_cb_hash_lock); 341 now = get_seconds();
125 342
126 if (inode) { 343 /* find the first vnode to update */
127 /* we've found the record for this vnode */ 344 spin_lock(&server->cb_lock);
128 spin_lock(&vnode->lock); 345 for (;;) {
129 if (vnode->cb_server == server) { 346 if (RB_EMPTY_ROOT(&server->cb_promises)) {
130 /* the callback _is_ on the calling server */ 347 spin_unlock(&server->cb_lock);
131 vnode->cb_server = NULL; 348 _leave(" [nothing]");
132 valid = 1; 349 return;
133
134 afs_kafstimod_del_timer(&vnode->cb_timeout);
135 vnode->flags |= AFS_VNODE_CHANGED;
136
137 spin_lock(&server->cb_lock);
138 list_del_init(&vnode->cb_link);
139 spin_unlock(&server->cb_lock);
140
141 spin_lock(&afs_cb_hash_lock);
142 list_del_init(&vnode->cb_hash_link);
143 spin_unlock(&afs_cb_hash_lock);
144 }
145 spin_unlock(&vnode->lock);
146
147 if (valid) {
148 invalidate_remote_inode(inode);
149 afs_put_server(server);
150 }
151 iput(inode);
152 } 350 }
351
352 vnode = rb_entry(rb_first(&server->cb_promises),
353 struct afs_vnode, cb_promise);
354 if (atomic_read(&vnode->usage) > 0)
355 break;
356 rb_erase(&vnode->cb_promise, &server->cb_promises);
357 vnode->cb_promised = false;
358 }
359
360 timeout = vnode->update_at - now;
361 if (timeout > 0) {
362 queue_delayed_work(afs_vnode_update_worker,
363 &afs_vnode_update, timeout * HZ);
364 spin_unlock(&server->cb_lock);
365 _leave(" [nothing]");
366 return;
367 }
368
369 list_del_init(&vnode->update);
370 atomic_inc(&vnode->usage);
371 spin_unlock(&server->cb_lock);
372
373 /* we can now perform the update */
374 _debug("update %s", vnode->vldb.name);
375 vnode->state = AFS_VL_UPDATING;
376 vnode->upd_rej_cnt = 0;
377 vnode->upd_busy_cnt = 0;
378
379 ret = afs_vnode_update_record(vl, &vldb);
380 switch (ret) {
381 case 0:
382 afs_vnode_apply_update(vl, &vldb);
383 vnode->state = AFS_VL_UPDATING;
384 break;
385 case -ENOMEDIUM:
386 vnode->state = AFS_VL_VOLUME_DELETED;
387 break;
388 default:
389 vnode->state = AFS_VL_UNCERTAIN;
390 break;
391 }
392
393 /* and then reschedule */
394 _debug("reschedule");
395 vnode->update_at = get_seconds() + afs_vnode_update_timeout;
396
397 spin_lock(&server->cb_lock);
398
399 if (!list_empty(&server->cb_promises)) {
400 /* next update in 10 minutes, but wait at least 1 second more
401 * than the newest record already queued so that we don't spam
402 * the VL server suddenly with lots of requests
403 */
404 xvnode = list_entry(server->cb_promises.prev,
405 struct afs_vnode, update);
406 if (vnode->update_at <= xvnode->update_at)
407 vnode->update_at = xvnode->update_at + 1;
408 xvnode = list_entry(server->cb_promises.next,
409 struct afs_vnode, update);
410 timeout = xvnode->update_at - now;
411 if (timeout < 0)
412 timeout = 0;
413 } else {
414 timeout = afs_vnode_update_timeout;
153 } 415 }
154 416
155 _leave(" = 0"); 417 list_add_tail(&vnode->update, &server->cb_promises);
156 return 0; 418
419 _debug("timeout %ld", timeout);
420 queue_delayed_work(afs_vnode_update_worker,
421 &afs_vnode_update, timeout * HZ);
422 spin_unlock(&server->cb_lock);
423 afs_put_vnode(vl);
424}
425#endif
426
427/*
428 * initialise the callback update process
429 */
430int __init afs_callback_update_init(void)
431{
432 afs_callback_update_worker =
433 create_singlethread_workqueue("kafs_callbackd");
434 return afs_callback_update_worker ? 0 : -ENOMEM;
157} 435}
158 436
159/* 437/*
160 * allow the fileserver to see if the cache manager is still alive 438 * shut down the callback update process
161 */ 439 */
162int SRXAFSCM_Probe(struct afs_server *server) 440void __exit afs_callback_update_kill(void)
163{ 441{
164 _debug("SRXAFSCM_Probe(%p)\n", server); 442 destroy_workqueue(afs_callback_update_worker);
165 return 0;
166} 443}