Merge to Fedora kernel-2.6.18-1.2224_FC5 patched with stable patch-2.6.18.1-vs2.0...
[linux-2.6.git] / fs / afs / main.c
1 /* main.c: AFS client file system
2  *
3  * Copyright (C) 2002,5 Red Hat, Inc. All Rights Reserved.
4  * Written by David Howells (dhowells@redhat.com)
5  *
6  * This program is free software; you can redistribute it and/or
7  * modify it under the terms of the GNU General Public License
8  * as published by the Free Software Foundation; either version
9  * 2 of the License, or (at your option) any later version.
10  */
11
12 #include <linux/module.h>
13 #include <linux/moduleparam.h>
14 #include <linux/init.h>
15 #include <linux/sched.h>
16 #include <linux/completion.h>
17 #include <linux/fscache.h>
18 #include <rxrpc/rxrpc.h>
19 #include <rxrpc/transport.h>
20 #include <rxrpc/call.h>
21 #include <rxrpc/peer.h>
22 #include "cell.h"
23 #include "server.h"
24 #include "fsclient.h"
25 #include "cmservice.h"
26 #include "kafstimod.h"
27 #include "kafsasyncd.h"
28 #include "internal.h"
29
30 struct rxrpc_transport *afs_transport;
31
32 static int afs_adding_peer(struct rxrpc_peer *peer);
33 static void afs_discarding_peer(struct rxrpc_peer *peer);
34
35
36 MODULE_DESCRIPTION("AFS Client File System");
37 MODULE_AUTHOR("Red Hat, Inc.");
38 MODULE_LICENSE("GPL");
39
40 static char *rootcell;
41
42 module_param(rootcell, charp, 0);
43 MODULE_PARM_DESC(rootcell, "root AFS cell name and VL server IP addr list");
44
45
46 static struct rxrpc_peer_ops afs_peer_ops = {
47         .adding         = afs_adding_peer,
48         .discarding     = afs_discarding_peer,
49 };
50
51 struct list_head afs_cb_hash_tbl[AFS_CB_HASH_COUNT];
52 DEFINE_SPINLOCK(afs_cb_hash_lock);
53
54 #ifdef CONFIG_AFS_FSCACHE
55 static struct fscache_netfs_operations afs_cache_ops = {
56 };
57
58 struct fscache_netfs afs_cache_netfs = {
59         .name                   = "afs",
60         .version                = 0,
61         .ops                    = &afs_cache_ops,
62 };
63 #endif
64
65 /*****************************************************************************/
66 /*
67  * initialise the AFS client FS module
68  */
69 static int __init afs_init(void)
70 {
71         int loop, ret;
72
73         printk(KERN_INFO "kAFS: Red Hat AFS client v0.1 registering.\n");
74
75         /* initialise the callback hash table */
76         spin_lock_init(&afs_cb_hash_lock);
77         for (loop = AFS_CB_HASH_COUNT - 1; loop >= 0; loop--)
78                 INIT_LIST_HEAD(&afs_cb_hash_tbl[loop]);
79
80         /* register the /proc stuff */
81         ret = afs_proc_init();
82         if (ret < 0)
83                 return ret;
84
85 #ifdef CONFIG_AFS_FSCACHE
86         /* we want to be able to cache */
87         ret = fscache_register_netfs(&afs_cache_netfs);
88         if (ret < 0)
89                 goto error;
90 #endif
91
92 #ifdef CONFIG_KEYS_TURNED_OFF
93         ret = afs_key_register();
94         if (ret < 0)
95                 goto error_cache;
96 #endif
97
98         /* initialise the cell DB */
99         ret = afs_cell_init(rootcell);
100         if (ret < 0)
101                 goto error_keys;
102
103         /* start the timeout daemon */
104         ret = afs_kafstimod_start();
105         if (ret < 0)
106                 goto error_keys;
107
108         /* start the async operation daemon */
109         ret = afs_kafsasyncd_start();
110         if (ret < 0)
111                 goto error_kafstimod;
112
113         /* create the RxRPC transport */
114         ret = rxrpc_create_transport(7001, &afs_transport);
115         if (ret < 0)
116                 goto error_kafsasyncd;
117
118         afs_transport->peer_ops = &afs_peer_ops;
119
120         /* register the filesystems */
121         ret = afs_fs_init();
122         if (ret < 0)
123                 goto error_transport;
124
125         return ret;
126
127  error_transport:
128         rxrpc_put_transport(afs_transport);
129  error_kafsasyncd:
130         afs_kafsasyncd_stop();
131  error_kafstimod:
132         afs_kafstimod_stop();
133  error_keys:
134 #ifdef CONFIG_KEYS_TURNED_OFF
135         afs_key_unregister();
136  error_cache:
137 #endif
138 #ifdef CONFIG_AFS_FSCACHE
139         fscache_unregister_netfs(&afs_cache_netfs);
140  error:
141 #endif
142         afs_cell_purge();
143         afs_proc_cleanup();
144         printk(KERN_ERR "kAFS: failed to register: %d\n", ret);
145         return ret;
146 } /* end afs_init() */
147
148 /* XXX late_initcall is kludgy, but the only alternative seems to create
149  * a transport upon the first mount, which is worse. Or is it?
150  */
151 late_initcall(afs_init);        /* must be called after net/ to create socket */
152 /*****************************************************************************/
153 /*
154  * clean up on module removal
155  */
156 static void __exit afs_exit(void)
157 {
158         printk(KERN_INFO "kAFS: Red Hat AFS client v0.1 unregistering.\n");
159
160         afs_fs_exit();
161         rxrpc_put_transport(afs_transport);
162         afs_kafstimod_stop();
163         afs_kafsasyncd_stop();
164         afs_cell_purge();
165 #ifdef CONFIG_KEYS_TURNED_OFF
166         afs_key_unregister();
167 #endif
168 #ifdef CONFIG_AFS_FSCACHE
169         fscache_unregister_netfs(&afs_cache_netfs);
170 #endif
171         afs_proc_cleanup();
172
173 } /* end afs_exit() */
174
175 module_exit(afs_exit);
176
177 /*****************************************************************************/
178 /*
179  * notification that new peer record is being added
180  * - called from krxsecd
181  * - return an error to induce an abort
182  * - mustn't sleep (caller holds an rwlock)
183  */
184 static int afs_adding_peer(struct rxrpc_peer *peer)
185 {
186         struct afs_server *server;
187         int ret;
188
189         _debug("kAFS: Adding new peer %08x\n", ntohl(peer->addr.s_addr));
190
191         /* determine which server the peer resides in (if any) */
192         ret = afs_server_find_by_peer(peer, &server);
193         if (ret < 0)
194                 return ret; /* none that we recognise, so abort */
195
196         _debug("Server %p{u=%d}\n", server, atomic_read(&server->usage));
197
198         _debug("Cell %p{u=%d}\n",
199                server->cell, atomic_read(&server->cell->usage));
200
201         /* cross-point the structs under a global lock */
202         spin_lock(&afs_server_peer_lock);
203         peer->user = server;
204         server->peer = peer;
205         spin_unlock(&afs_server_peer_lock);
206
207         afs_put_server(server);
208
209         return 0;
210 } /* end afs_adding_peer() */
211
212 /*****************************************************************************/
213 /*
214  * notification that a peer record is being discarded
215  * - called from krxiod or krxsecd
216  */
217 static void afs_discarding_peer(struct rxrpc_peer *peer)
218 {
219         struct afs_server *server;
220
221         _enter("%p",peer);
222
223         _debug("Discarding peer %08x (rtt=%lu.%lumS)\n",
224                ntohl(peer->addr.s_addr),
225                (long) (peer->rtt / 1000),
226                (long) (peer->rtt % 1000));
227
228         /* uncross-point the structs under a global lock */
229         spin_lock(&afs_server_peer_lock);
230         server = peer->user;
231         if (server) {
232                 peer->user = NULL;
233                 server->peer = NULL;
234         }
235         spin_unlock(&afs_server_peer_lock);
236
237         _leave("");
238
239 } /* end afs_discarding_peer() */
240
241 /*****************************************************************************/
242 /*
243  * clear the dead space between task_struct and kernel stack
244  * - called by supplying -finstrument-functions to gcc
245  */
246 #if 0
247 void __cyg_profile_func_enter (void *this_fn, void *call_site)
248 __attribute__((no_instrument_function));
249
250 void __cyg_profile_func_enter (void *this_fn, void *call_site)
251 {
252        asm volatile("  movl    %%esp,%%edi     \n"
253                     "  andl    %0,%%edi        \n"
254                     "  addl    %1,%%edi        \n"
255                     "  movl    %%esp,%%ecx     \n"
256                     "  subl    %%edi,%%ecx     \n"
257                     "  shrl    $2,%%ecx        \n"
258                     "  movl    $0xedededed,%%eax     \n"
259                     "  rep stosl               \n"
260                     :
261                     : "i"(~(THREAD_SIZE - 1)), "i"(sizeof(struct thread_info))
262                     : "eax", "ecx", "edi", "memory", "cc"
263                     );
264 }
265
266 void __cyg_profile_func_exit(void *this_fn, void *call_site)
267 __attribute__((no_instrument_function));
268
269 void __cyg_profile_func_exit(void *this_fn, void *call_site)
270 {
271        asm volatile("  movl    %%esp,%%edi     \n"
272                     "  andl    %0,%%edi        \n"
273                     "  addl    %1,%%edi        \n"
274                     "  movl    %%esp,%%ecx     \n"
275                     "  subl    %%edi,%%ecx     \n"
276                     "  shrl    $2,%%ecx        \n"
277                     "  movl    $0xdadadada,%%eax     \n"
278                     "  rep stosl               \n"
279                     :
280                     : "i"(~(THREAD_SIZE - 1)), "i"(sizeof(struct thread_info))
281                     : "eax", "ecx", "edi", "memory", "cc"
282                     );
283 }
284 #endif