Linux Audio

Check our new training course

Loading...
v3.15
  1/*
  2 * Copyright (c) 2002, 2007 Red Hat, Inc. All rights reserved.
  3 *
  4 * This software may be freely redistributed under the terms of the
  5 * GNU General Public License.
  6 *
  7 * You should have received a copy of the GNU General Public License
  8 * along with this program; if not, write to the Free Software
  9 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
 10 *
 11 * Authors: David Woodhouse <dwmw2@infradead.org>
 12 *          David Howells <dhowells@redhat.com>
 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#if 0
 24unsigned afs_vnode_update_timeout = 10;
 25#endif  /*  0  */
 26
 27#define afs_breakring_space(server) \
 28	CIRC_SPACE((server)->cb_break_head, (server)->cb_break_tail,	\
 29		   ARRAY_SIZE((server)->cb_break))
 30
 31//static void afs_callback_updater(struct work_struct *);
 32
 33static struct workqueue_struct *afs_callback_update_worker;
 34
 35/*
 36 * allow the fileserver to request callback state (re-)initialisation
 37 */
 38void afs_init_callback_state(struct afs_server *server)
 
 39{
 40	struct afs_vnode *vnode;
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 41
 42	_enter("{%p}", server);
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 43
 44	spin_lock(&server->cb_lock);
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 45
 46	/* kill all the promises on record from this server */
 47	while (!RB_EMPTY_ROOT(&server->cb_promises)) {
 48		vnode = rb_entry(server->cb_promises.rb_node,
 49				 struct afs_vnode, cb_promise);
 50		_debug("UNPROMISE { vid=%x:%u uq=%u}",
 51		       vnode->fid.vid, vnode->fid.vnode, vnode->fid.unique);
 52		rb_erase(&vnode->cb_promise, &server->cb_promises);
 53		vnode->cb_promised = false;
 
 
 
 
 
 54	}
 55
 56	spin_unlock(&server->cb_lock);
 57	_leave("");
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 58}
 59
 60/*
 61 * handle the data invalidation side of a callback being broken
 62 */
 63void afs_broken_callback_work(struct work_struct *work)
 64{
 65	struct afs_vnode *vnode =
 66		container_of(work, struct afs_vnode, cb_broken_work);
 67
 68	_enter("");
 
 
 69
 70	if (test_bit(AFS_VNODE_DELETED, &vnode->flags))
 71		return;
 
 
 
 
 
 72
 73	/* we're only interested in dealing with a broken callback on *this*
 74	 * vnode and only if no-one else has dealt with it yet */
 75	if (!mutex_trylock(&vnode->validate_lock))
 76		return; /* someone else is dealing with it */
 77
 78	if (test_bit(AFS_VNODE_CB_BROKEN, &vnode->flags)) {
 79		if (S_ISDIR(vnode->vfs_inode.i_mode))
 80			afs_clear_permits(vnode);
 81
 82		if (afs_vnode_fetch_status(vnode, NULL, NULL) < 0)
 83			goto out;
 84
 85		if (test_bit(AFS_VNODE_DELETED, &vnode->flags))
 86			goto out;
 87
 88		/* if the vnode's data version number changed then its contents
 89		 * are different */
 90		if (test_and_clear_bit(AFS_VNODE_ZAP_DATA, &vnode->flags))
 91			afs_zap_data(vnode);
 92	}
 
 93
 94out:
 95	mutex_unlock(&vnode->validate_lock);
 96
 97	/* avoid the potential race whereby the mutex_trylock() in this
 98	 * function happens again between the clear_bit() and the
 99	 * mutex_unlock() */
100	if (test_bit(AFS_VNODE_CB_BROKEN, &vnode->flags)) {
101		_debug("requeue");
102		queue_work(afs_callback_update_worker, &vnode->cb_broken_work);
103	}
104	_leave("");
105}
106
107/*
108 * actually break a callback
109 */
110static void afs_break_callback(struct afs_server *server,
111			       struct afs_vnode *vnode)
112{
113	_enter("");
114
115	set_bit(AFS_VNODE_CB_BROKEN, &vnode->flags);
116
117	if (vnode->cb_promised) {
118		spin_lock(&vnode->lock);
119
120		_debug("break callback");
121
122		spin_lock(&server->cb_lock);
123		if (vnode->cb_promised) {
124			rb_erase(&vnode->cb_promise, &server->cb_promises);
125			vnode->cb_promised = false;
126		}
127		spin_unlock(&server->cb_lock);
128
129		queue_work(afs_callback_update_worker, &vnode->cb_broken_work);
130		if (list_empty(&vnode->granted_locks) &&
131		    !list_empty(&vnode->pending_locks))
132			afs_lock_may_be_available(vnode);
133		spin_unlock(&vnode->lock);
 
 
 
134	}
135}
136
 
 
 
 
 
 
 
137/*
138 * allow the fileserver to explicitly break one callback
139 * - happens when
140 *   - the backing file is changed
141 *   - a lock is released
142 */
143static void afs_break_one_callback(struct afs_server *server,
144				   struct afs_fid *fid)
145{
 
 
 
146	struct afs_vnode *vnode;
147	struct rb_node *p;
148
149	_debug("find");
150	spin_lock(&server->fs_lock);
151	p = server->fs_vnodes.rb_node;
152	while (p) {
153		vnode = rb_entry(p, struct afs_vnode, server_rb);
154		if (fid->vid < vnode->fid.vid)
155			p = p->rb_left;
156		else if (fid->vid > vnode->fid.vid)
157			p = p->rb_right;
158		else if (fid->vnode < vnode->fid.vnode)
159			p = p->rb_left;
160		else if (fid->vnode > vnode->fid.vnode)
161			p = p->rb_right;
162		else if (fid->unique < vnode->fid.unique)
163			p = p->rb_left;
164		else if (fid->unique > vnode->fid.unique)
165			p = p->rb_right;
166		else
167			goto found;
168	}
169
170	/* not found so we just ignore it (it may have moved to another
171	 * server) */
172not_available:
173	_debug("not avail");
174	spin_unlock(&server->fs_lock);
175	_leave("");
176	return;
177
178found:
179	_debug("found");
180	ASSERTCMP(server, ==, vnode->server);
181
182	if (!igrab(AFS_VNODE_TO_I(vnode)))
183		goto not_available;
184	spin_unlock(&server->fs_lock);
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
185
186	afs_break_callback(server, vnode);
187	iput(&vnode->vfs_inode);
188	_leave("");
189}
190
191/*
192 * allow the fileserver to break callback promises
193 */
194void afs_break_callbacks(struct afs_server *server, size_t count,
195			 struct afs_callback callbacks[])
196{
197	_enter("%p,%zu,", server, count);
198
199	ASSERT(server != NULL);
200	ASSERTCMP(count, <=, AFSCBMAX);
 
201
202	for (; count > 0; callbacks++, count--) {
203		_debug("- Fid { vl=%08x n=%u u=%u }  CB { v=%u x=%u t=%u }",
204		       callbacks->fid.vid,
205		       callbacks->fid.vnode,
206		       callbacks->fid.unique,
207		       callbacks->version,
208		       callbacks->expiry,
209		       callbacks->type
210		       );
211		afs_break_one_callback(server, &callbacks->fid);
212	}
213
214	_leave("");
215	return;
216}
217
218/*
219 * record the callback for breaking
220 * - the caller must hold server->cb_lock
221 */
222static void afs_do_give_up_callback(struct afs_server *server,
223				    struct afs_vnode *vnode)
224{
225	struct afs_callback *cb;
226
227	_enter("%p,%p", server, vnode);
228
229	cb = &server->cb_break[server->cb_break_head];
230	cb->fid		= vnode->fid;
231	cb->version	= vnode->cb_version;
232	cb->expiry	= vnode->cb_expiry;
233	cb->type	= vnode->cb_type;
234	smp_wmb();
235	server->cb_break_head =
236		(server->cb_break_head + 1) &
237		(ARRAY_SIZE(server->cb_break) - 1);
238
239	/* defer the breaking of callbacks to try and collect as many as
240	 * possible to ship in one operation */
241	switch (atomic_inc_return(&server->cb_break_n)) {
242	case 1 ... AFSCBMAX - 1:
243		queue_delayed_work(afs_callback_update_worker,
244				   &server->cb_break_work, HZ * 2);
245		break;
246	case AFSCBMAX:
247		afs_flush_callback_breaks(server);
248		break;
249	default:
250		break;
251	}
252
253	ASSERT(server->cb_promises.rb_node != NULL);
254	rb_erase(&vnode->cb_promise, &server->cb_promises);
255	vnode->cb_promised = false;
256	_leave("");
257}
258
259/*
260 * discard the callback on a deleted item
261 */
262void afs_discard_callback_on_delete(struct afs_vnode *vnode)
263{
264	struct afs_server *server = vnode->server;
265
266	_enter("%d", vnode->cb_promised);
267
268	if (!vnode->cb_promised) {
269		_leave(" [not promised]");
270		return;
271	}
272
273	ASSERT(server != NULL);
274
275	spin_lock(&server->cb_lock);
276	if (vnode->cb_promised) {
277		ASSERT(server->cb_promises.rb_node != NULL);
278		rb_erase(&vnode->cb_promise, &server->cb_promises);
279		vnode->cb_promised = false;
280	}
281	spin_unlock(&server->cb_lock);
282	_leave("");
283}
284
285/*
286 * give up the callback registered for a vnode on the file server when the
287 * inode is being cleared
288 */
289void afs_give_up_callback(struct afs_vnode *vnode)
290{
291	struct afs_server *server = vnode->server;
292
293	DECLARE_WAITQUEUE(myself, current);
294
295	_enter("%d", vnode->cb_promised);
296
297	_debug("GIVE UP INODE %p", &vnode->vfs_inode);
298
299	if (!vnode->cb_promised) {
300		_leave(" [not promised]");
301		return;
302	}
303
304	ASSERT(server != NULL);
305
306	spin_lock(&server->cb_lock);
307	if (vnode->cb_promised && afs_breakring_space(server) == 0) {
308		add_wait_queue(&server->cb_break_waitq, &myself);
309		for (;;) {
310			set_current_state(TASK_UNINTERRUPTIBLE);
311			if (!vnode->cb_promised ||
312			    afs_breakring_space(server) != 0)
313				break;
314			spin_unlock(&server->cb_lock);
315			schedule();
316			spin_lock(&server->cb_lock);
317		}
318		remove_wait_queue(&server->cb_break_waitq, &myself);
319		__set_current_state(TASK_RUNNING);
320	}
321
322	/* of course, it's always possible for the server to break this vnode's
323	 * callback first... */
324	if (vnode->cb_promised)
325		afs_do_give_up_callback(server, vnode);
326
327	spin_unlock(&server->cb_lock);
328	_leave("");
329}
330
331/*
332 * dispatch a deferred give up callbacks operation
333 */
334void afs_dispatch_give_up_callbacks(struct work_struct *work)
335{
336	struct afs_server *server =
337		container_of(work, struct afs_server, cb_break_work.work);
338
339	_enter("");
340
341	/* tell the fileserver to discard the callback promises it has
342	 * - in the event of ENOMEM or some other error, we just forget that we
343	 *   had callbacks entirely, and the server will call us later to break
344	 *   them
345	 */
346	afs_fs_give_up_callbacks(server, &afs_async_call);
347}
348
349/*
350 * flush the outstanding callback breaks on a server
351 */
352void afs_flush_callback_breaks(struct afs_server *server)
353{
354	mod_delayed_work(afs_callback_update_worker, &server->cb_break_work, 0);
355}
356
357#if 0
358/*
359 * update a bunch of callbacks
360 */
361static void afs_callback_updater(struct work_struct *work)
362{
363	struct afs_server *server;
364	struct afs_vnode *vnode, *xvnode;
365	time_t now;
366	long timeout;
367	int ret;
368
369	server = container_of(work, struct afs_server, updater);
370
371	_enter("");
372
373	now = get_seconds();
374
375	/* find the first vnode to update */
376	spin_lock(&server->cb_lock);
377	for (;;) {
378		if (RB_EMPTY_ROOT(&server->cb_promises)) {
379			spin_unlock(&server->cb_lock);
380			_leave(" [nothing]");
381			return;
382		}
383
384		vnode = rb_entry(rb_first(&server->cb_promises),
385				 struct afs_vnode, cb_promise);
386		if (atomic_read(&vnode->usage) > 0)
387			break;
388		rb_erase(&vnode->cb_promise, &server->cb_promises);
389		vnode->cb_promised = false;
390	}
391
392	timeout = vnode->update_at - now;
393	if (timeout > 0) {
394		queue_delayed_work(afs_vnode_update_worker,
395				   &afs_vnode_update, timeout * HZ);
396		spin_unlock(&server->cb_lock);
397		_leave(" [nothing]");
398		return;
399	}
400
401	list_del_init(&vnode->update);
402	atomic_inc(&vnode->usage);
403	spin_unlock(&server->cb_lock);
404
405	/* we can now perform the update */
406	_debug("update %s", vnode->vldb.name);
407	vnode->state = AFS_VL_UPDATING;
408	vnode->upd_rej_cnt = 0;
409	vnode->upd_busy_cnt = 0;
410
411	ret = afs_vnode_update_record(vl, &vldb);
412	switch (ret) {
413	case 0:
414		afs_vnode_apply_update(vl, &vldb);
415		vnode->state = AFS_VL_UPDATING;
416		break;
417	case -ENOMEDIUM:
418		vnode->state = AFS_VL_VOLUME_DELETED;
419		break;
420	default:
421		vnode->state = AFS_VL_UNCERTAIN;
422		break;
423	}
424
425	/* and then reschedule */
426	_debug("reschedule");
427	vnode->update_at = get_seconds() + afs_vnode_update_timeout;
428
429	spin_lock(&server->cb_lock);
430
431	if (!list_empty(&server->cb_promises)) {
432		/* next update in 10 minutes, but wait at least 1 second more
433		 * than the newest record already queued so that we don't spam
434		 * the VL server suddenly with lots of requests
435		 */
436		xvnode = list_entry(server->cb_promises.prev,
437				    struct afs_vnode, update);
438		if (vnode->update_at <= xvnode->update_at)
439			vnode->update_at = xvnode->update_at + 1;
440		xvnode = list_entry(server->cb_promises.next,
441				    struct afs_vnode, update);
442		timeout = xvnode->update_at - now;
443		if (timeout < 0)
444			timeout = 0;
445	} else {
446		timeout = afs_vnode_update_timeout;
447	}
448
449	list_add_tail(&vnode->update, &server->cb_promises);
450
451	_debug("timeout %ld", timeout);
452	queue_delayed_work(afs_vnode_update_worker,
453			   &afs_vnode_update, timeout * HZ);
454	spin_unlock(&server->cb_lock);
455	afs_put_vnode(vl);
456}
457#endif
458
459/*
460 * initialise the callback update process
461 */
462int __init afs_callback_update_init(void)
463{
464	afs_callback_update_worker =
465		create_singlethread_workqueue("kafs_callbackd");
466	return afs_callback_update_worker ? 0 : -ENOMEM;
467}
468
469/*
470 * shut down the callback update process
471 */
472void afs_callback_update_kill(void)
473{
474	destroy_workqueue(afs_callback_update_worker);
475}
v5.4
  1/*
  2 * Copyright (c) 2002, 2007 Red Hat, Inc. All rights reserved.
  3 *
  4 * This software may be freely redistributed under the terms of the
  5 * GNU General Public License.
  6 *
  7 * You should have received a copy of the GNU General Public License
  8 * along with this program; if not, write to the Free Software
  9 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
 10 *
 11 * Authors: David Woodhouse <dwmw2@infradead.org>
 12 *          David Howells <dhowells@redhat.com>
 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 * Create volume and callback interests on a server.
 25 */
 26static struct afs_cb_interest *afs_create_interest(struct afs_server *server,
 27						   struct afs_vnode *vnode)
 28{
 29	struct afs_vol_interest *new_vi, *vi;
 30	struct afs_cb_interest *new;
 31	struct hlist_node **pp;
 32
 33	new_vi = kzalloc(sizeof(struct afs_vol_interest), GFP_KERNEL);
 34	if (!new_vi)
 35		return NULL;
 36
 37	new = kzalloc(sizeof(struct afs_cb_interest), GFP_KERNEL);
 38	if (!new) {
 39		kfree(new_vi);
 40		return NULL;
 41	}
 42
 43	new_vi->usage = 1;
 44	new_vi->vid = vnode->volume->vid;
 45	INIT_HLIST_NODE(&new_vi->srv_link);
 46	INIT_HLIST_HEAD(&new_vi->cb_interests);
 47
 48	refcount_set(&new->usage, 1);
 49	new->sb = vnode->vfs_inode.i_sb;
 50	new->vid = vnode->volume->vid;
 51	new->server = afs_get_server(server, afs_server_trace_get_new_cbi);
 52	INIT_HLIST_NODE(&new->cb_vlink);
 53
 54	write_lock(&server->cb_break_lock);
 55
 56	for (pp = &server->cb_volumes.first; *pp; pp = &(*pp)->next) {
 57		vi = hlist_entry(*pp, struct afs_vol_interest, srv_link);
 58		if (vi->vid < new_vi->vid)
 59			continue;
 60		if (vi->vid > new_vi->vid)
 61			break;
 62		vi->usage++;
 63		goto found_vi;
 64	}
 65
 66	new_vi->srv_link.pprev = pp;
 67	new_vi->srv_link.next = *pp;
 68	if (*pp)
 69		(*pp)->pprev = &new_vi->srv_link.next;
 70	*pp = &new_vi->srv_link;
 71	vi = new_vi;
 72	new_vi = NULL;
 73found_vi:
 74
 75	new->vol_interest = vi;
 76	hlist_add_head(&new->cb_vlink, &vi->cb_interests);
 77
 78	write_unlock(&server->cb_break_lock);
 79	kfree(new_vi);
 80	return new;
 81}
 82
 83/*
 84 * Set up an interest-in-callbacks record for a volume on a server and
 85 * register it with the server.
 86 * - Called with vnode->io_lock held.
 87 */
 88int afs_register_server_cb_interest(struct afs_vnode *vnode,
 89				    struct afs_server_list *slist,
 90				    unsigned int index)
 91{
 92	struct afs_server_entry *entry = &slist->servers[index];
 93	struct afs_cb_interest *cbi, *vcbi, *new, *old;
 94	struct afs_server *server = entry->server;
 95
 96again:
 97	vcbi = rcu_dereference_protected(vnode->cb_interest,
 98					 lockdep_is_held(&vnode->io_lock));
 99	if (vcbi && likely(vcbi == entry->cb_interest))
100		return 0;
101
102	read_lock(&slist->lock);
103	cbi = afs_get_cb_interest(entry->cb_interest);
104	read_unlock(&slist->lock);
105
106	if (vcbi) {
107		if (vcbi == cbi) {
108			afs_put_cb_interest(afs_v2net(vnode), cbi);
109			return 0;
110		}
111
112		/* Use a new interest in the server list for the same server
113		 * rather than an old one that's still attached to a vnode.
114		 */
115		if (cbi && vcbi->server == cbi->server) {
116			write_seqlock(&vnode->cb_lock);
117			old = rcu_dereference_protected(vnode->cb_interest,
118							lockdep_is_held(&vnode->cb_lock.lock));
119			rcu_assign_pointer(vnode->cb_interest, cbi);
120			write_sequnlock(&vnode->cb_lock);
121			afs_put_cb_interest(afs_v2net(vnode), old);
122			return 0;
123		}
124
125		/* Re-use the one attached to the vnode. */
126		if (!cbi && vcbi->server == server) {
127			write_lock(&slist->lock);
128			if (entry->cb_interest) {
129				write_unlock(&slist->lock);
130				afs_put_cb_interest(afs_v2net(vnode), cbi);
131				goto again;
132			}
133
134			entry->cb_interest = cbi;
135			write_unlock(&slist->lock);
136			return 0;
137		}
138	}
139
140	if (!cbi) {
141		new = afs_create_interest(server, vnode);
142		if (!new)
143			return -ENOMEM;
144
145		write_lock(&slist->lock);
146		if (!entry->cb_interest) {
147			entry->cb_interest = afs_get_cb_interest(new);
148			cbi = new;
149			new = NULL;
150		} else {
151			cbi = afs_get_cb_interest(entry->cb_interest);
152		}
153		write_unlock(&slist->lock);
154		afs_put_cb_interest(afs_v2net(vnode), new);
155	}
156
157	ASSERT(cbi);
158
159	/* Change the server the vnode is using.  This entails scrubbing any
160	 * interest the vnode had in the previous server it was using.
161	 */
162	write_seqlock(&vnode->cb_lock);
163
164	old = rcu_dereference_protected(vnode->cb_interest,
165					lockdep_is_held(&vnode->cb_lock.lock));
166	rcu_assign_pointer(vnode->cb_interest, cbi);
167	vnode->cb_s_break = cbi->server->cb_s_break;
168	vnode->cb_v_break = vnode->volume->cb_v_break;
169	clear_bit(AFS_VNODE_CB_PROMISED, &vnode->flags);
170
171	write_sequnlock(&vnode->cb_lock);
172	afs_put_cb_interest(afs_v2net(vnode), old);
173	return 0;
174}
175
176/*
177 * Remove an interest on a server.
178 */
179void afs_put_cb_interest(struct afs_net *net, struct afs_cb_interest *cbi)
180{
181	struct afs_vol_interest *vi;
 
182
183	if (cbi && refcount_dec_and_test(&cbi->usage)) {
184		if (!hlist_unhashed(&cbi->cb_vlink)) {
185			write_lock(&cbi->server->cb_break_lock);
186
187			hlist_del_init(&cbi->cb_vlink);
188			vi = cbi->vol_interest;
189			cbi->vol_interest = NULL;
190			if (--vi->usage == 0)
191				hlist_del(&vi->srv_link);
192			else
193				vi = NULL;
194
195			write_unlock(&cbi->server->cb_break_lock);
196			if (vi)
197				kfree_rcu(vi, rcu);
198			afs_put_server(net, cbi->server, afs_server_trace_put_cbi);
199		}
200		kfree_rcu(cbi, rcu);
 
 
 
 
 
 
 
 
 
 
 
 
 
201	}
202}
203
204/*
205 * allow the fileserver to request callback state (re-)initialisation
206 */
207void afs_init_callback_state(struct afs_server *server)
208{
209	server->cb_s_break++;
 
 
 
 
 
210}
211
212/*
213 * actually break a callback
214 */
215void __afs_break_callback(struct afs_vnode *vnode, enum afs_cb_break_reason reason)
 
216{
217	_enter("");
218
219	clear_bit(AFS_VNODE_NEW_CONTENT, &vnode->flags);
220	if (test_and_clear_bit(AFS_VNODE_CB_PROMISED, &vnode->flags)) {
221		vnode->cb_break++;
222		afs_clear_permits(vnode);
223
224		if (vnode->lock_state == AFS_VNODE_LOCK_WAITING_FOR_CB)
 
 
 
 
 
 
 
 
 
 
 
225			afs_lock_may_be_available(vnode);
226
227		trace_afs_cb_break(&vnode->fid, vnode->cb_break, reason, true);
228	} else {
229		trace_afs_cb_break(&vnode->fid, vnode->cb_break, reason, false);
230	}
231}
232
233void afs_break_callback(struct afs_vnode *vnode, enum afs_cb_break_reason reason)
234{
235	write_seqlock(&vnode->cb_lock);
236	__afs_break_callback(vnode, reason);
237	write_sequnlock(&vnode->cb_lock);
238}
239
240/*
241 * allow the fileserver to explicitly break one callback
242 * - happens when
243 *   - the backing file is changed
244 *   - a lock is released
245 */
246static void afs_break_one_callback(struct afs_server *server,
247				   struct afs_fid *fid)
248{
249	struct afs_vol_interest *vi;
250	struct afs_cb_interest *cbi;
251	struct afs_iget_data data;
252	struct afs_vnode *vnode;
253	struct inode *inode;
254
255	read_lock(&server->cb_break_lock);
256	hlist_for_each_entry(vi, &server->cb_volumes, srv_link) {
257		if (vi->vid < fid->vid)
258			continue;
259		if (vi->vid > fid->vid) {
260			vi = NULL;
261			break;
262		}
263		//atomic_inc(&vi->usage);
264		break;
 
 
 
 
 
 
 
 
 
265	}
266
267	/* TODO: Find all matching volumes if we couldn't match the server and
268	 * break them anyway.
269	 */
270	if (!vi)
271		goto out;
 
 
272
273	/* Step through all interested superblocks.  There may be more than one
274	 * because of cell aliasing.
275	 */
276	hlist_for_each_entry(cbi, &vi->cb_interests, cb_vlink) {
277		if (fid->vnode == 0 && fid->unique == 0) {
278			/* The callback break applies to an entire volume. */
279			struct afs_super_info *as = AFS_FS_S(cbi->sb);
280			struct afs_volume *volume = as->volume;
281
282			write_lock(&volume->cb_v_break_lock);
283			volume->cb_v_break++;
284			trace_afs_cb_break(fid, volume->cb_v_break,
285					   afs_cb_break_for_volume_callback, false);
286			write_unlock(&volume->cb_v_break_lock);
287		} else {
288			data.volume = NULL;
289			data.fid = *fid;
290			inode = ilookup5_nowait(cbi->sb, fid->vnode,
291						afs_iget5_test, &data);
292			if (inode) {
293				vnode = AFS_FS_I(inode);
294				afs_break_callback(vnode, afs_cb_break_for_callback);
295				iput(inode);
296			} else {
297				trace_afs_cb_miss(fid, afs_cb_break_for_callback);
298			}
299		}
300	}
301
302out:
303	read_unlock(&server->cb_break_lock);
 
304}
305
306/*
307 * allow the fileserver to break callback promises
308 */
309void afs_break_callbacks(struct afs_server *server, size_t count,
310			 struct afs_callback_break *callbacks)
311{
312	_enter("%p,%zu,", server, count);
313
314	ASSERT(server != NULL);
315
316	/* TODO: Sort the callback break list by volume ID */
317
318	for (; count > 0; callbacks++, count--) {
319		_debug("- Fid { vl=%08llx n=%llu u=%u }",
320		       callbacks->fid.vid,
321		       callbacks->fid.vnode,
322		       callbacks->fid.unique);
 
 
 
 
323		afs_break_one_callback(server, &callbacks->fid);
324	}
325
326	_leave("");
327	return;
328}
329
330/*
331 * Clear the callback interests in a server list.
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
332 */
333void afs_clear_callback_interests(struct afs_net *net, struct afs_server_list *slist)
334{
335	int i;
 
 
336
337	for (i = 0; i < slist->nr_servers; i++) {
338		afs_put_cb_interest(net, slist->servers[i].cb_interest);
339		slist->servers[i].cb_interest = NULL;
340	}
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
341}