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