summaryrefslogtreecommitdiff
path: root/fs/afs/callback.c
blob: 26a48fea42f47a1812a860f3a4a7e8f9a0a7e3cc (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
/*
 * Copyright (c) 2002 Red Hat, Inc. All rights reserved.
 *
 * This software may be freely redistributed under the terms of the
 * GNU General Public License.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
 *
 * Authors: David Woodhouse <dwmw2@cambridge.redhat.com>
 *          David Howells <dhowells@redhat.com>
 *
 */

#include <linux/kernel.h>
#include <linux/module.h>
#include <linux/init.h>
#include "server.h"
#include "vnode.h"
#include "internal.h"
#include "cmservice.h"

/*
 * allow the fileserver to request callback state (re-)initialisation
 */
int SRXAFSCM_InitCallBackState(struct afs_server *server)
{
	struct list_head callbacks;

	_enter("%p", server);

	INIT_LIST_HEAD(&callbacks);

	/* transfer the callback list from the server to a temp holding area */
	spin_lock(&server->cb_lock);

	list_add(&callbacks, &server->cb_promises);
	list_del_init(&server->cb_promises);

	/* munch our way through the list, grabbing the inode, dropping all the
	 * locks and regetting them in the right order
	 */
	while (!list_empty(&callbacks)) {
		struct afs_vnode *vnode;
		struct inode *inode;

		vnode = list_entry(callbacks.next, struct afs_vnode, cb_link);
		list_del_init(&vnode->cb_link);

		/* try and grab the inode - may fail */
		inode = igrab(AFS_VNODE_TO_I(vnode));
		if (inode) {
			int release = 0;

			spin_unlock(&server->cb_lock);
			spin_lock(&vnode->lock);

			if (vnode->cb_server == server) {
				vnode->cb_server = NULL;
				afs_kafstimod_del_timer(&vnode->cb_timeout);
				spin_lock(&afs_cb_hash_lock);
				list_del_init(&vnode->cb_hash_link);
				spin_unlock(&afs_cb_hash_lock);
				release = 1;
			}

			spin_unlock(&vnode->lock);

			iput(inode);
			afs_put_server(server);

			spin_lock(&server->cb_lock);
		}
	}

	spin_unlock(&server->cb_lock);

	_leave(" = 0");
	return 0;
}

/*
 * allow the fileserver to break callback promises
 */
int SRXAFSCM_CallBack(struct afs_server *server, size_t count,
		      struct afs_callback callbacks[])
{
	_enter("%p,%u,", server, count);

	for (; count > 0; callbacks++, count--) {
		struct afs_vnode *vnode = NULL;
		struct inode *inode = NULL;
		int valid = 0;

		_debug("- Fid { vl=%08x n=%u u=%u }  CB { v=%u x=%u t=%u }",
		       callbacks->fid.vid,
		       callbacks->fid.vnode,
		       callbacks->fid.unique,
		       callbacks->version,
		       callbacks->expiry,
		       callbacks->type
		       );

		/* find the inode for this fid */
		spin_lock(&afs_cb_hash_lock);

		list_for_each_entry(vnode,
				    &afs_cb_hash(server, &callbacks->fid),
				    cb_hash_link) {
			if (memcmp(&vnode->fid, &callbacks->fid,
				   sizeof(struct afs_fid)) != 0)
				continue;

			/* right vnode, but is it same server? */
			if (vnode->cb_server != server)
				break; /* no */

			/* try and nail the inode down */
			inode = igrab(AFS_VNODE_TO_I(vnode));
			break;
		}

		spin_unlock(&afs_cb_hash_lock);

		if (inode) {
			/* we've found the record for this vnode */
			spin_lock(&vnode->lock);
			if (vnode->cb_server == server) {
				/* the callback _is_ on the calling server */
				vnode->cb_server = NULL;
				valid = 1;

				afs_kafstimod_del_timer(&vnode->cb_timeout);
				vnode->flags |= AFS_VNODE_CHANGED;

				spin_lock(&server->cb_lock);
				list_del_init(&vnode->cb_link);
				spin_unlock(&server->cb_lock);

				spin_lock(&afs_cb_hash_lock);
				list_del_init(&vnode->cb_hash_link);
				spin_unlock(&afs_cb_hash_lock);
			}
			spin_unlock(&vnode->lock);

			if (valid) {
				invalidate_remote_inode(inode);
				afs_put_server(server);
			}
			iput(inode);
		}
	}

	_leave(" = 0");
	return 0;
}

/*
 * allow the fileserver to see if the cache manager is still alive
 */
int SRXAFSCM_Probe(struct afs_server *server)
{
	_debug("SRXAFSCM_Probe(%p)\n", server);
	return 0;
}