MOXA linux-2.6.x / linux-2.6.9-uc0 from sdlinux-moxaart.tgz
[linux-2.6.9-moxart.git] / fs / afs / main.c
blob955dbef62b693ceb48bf1eac439324c99a63e7e5
1 /* main.c: AFS client file system
3 * Copyright (C) 2002 Red Hat, Inc. All Rights Reserved.
4 * Written by David Howells (dhowells@redhat.com)
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.
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"
30 struct rxrpc_transport *afs_transport;
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);
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?
40 /* module_init(afs_init); */
41 late_initcall(afs_init); /* must be called after net/ to create socket */
43 module_exit(afs_exit);
45 MODULE_DESCRIPTION("AFS Client File System");
46 MODULE_AUTHOR("Red Hat, Inc.");
47 MODULE_LICENSE("GPL");
49 static char *rootcell;
51 module_param(rootcell, charp, 0);
52 MODULE_PARM_DESC(rootcell, "root AFS cell name and VL server IP addr list");
55 static struct rxrpc_peer_ops afs_peer_ops = {
56 .adding = afs_adding_peer,
57 .discarding = afs_discarding_peer,
60 struct list_head afs_cb_hash_tbl[AFS_CB_HASH_COUNT];
61 spinlock_t afs_cb_hash_lock = SPIN_LOCK_UNLOCKED;
63 #ifdef AFS_CACHING_SUPPORT
64 static struct cachefs_netfs_operations afs_cache_ops = {
65 .get_page_cookie = afs_cache_get_page_cookie,
68 struct cachefs_netfs afs_cache_netfs = {
69 .name = "afs",
70 .version = 0,
71 .ops = &afs_cache_ops,
73 #endif
75 /*****************************************************************************/
77 * initialise the AFS client FS module
79 static int afs_init(void)
81 int loop, ret;
83 printk(KERN_INFO "kAFS: Red Hat AFS client v0.1 registering.\n");
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]);
90 /* register the /proc stuff */
91 ret = afs_proc_init();
92 if (ret < 0)
93 return ret;
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
103 #ifdef CONFIG_KEYS
104 ret = afs_key_register();
105 if (ret < 0)
106 goto error_cache;
107 #endif
109 /* initialise the cell DB */
110 ret = afs_cell_init(rootcell);
111 if (ret < 0)
112 goto error_keys;
114 /* start the timeout daemon */
115 ret = afs_kafstimod_start();
116 if (ret < 0)
117 goto error_keys;
119 /* start the async operation daemon */
120 ret = afs_kafsasyncd_start();
121 if (ret < 0)
122 goto error_kafstimod;
124 /* create the RxRPC transport */
125 ret = rxrpc_create_transport(7001, &afs_transport);
126 if (ret < 0)
127 goto error_kafsasyncd;
129 afs_transport->peer_ops = &afs_peer_ops;
131 /* register the filesystems */
132 ret = afs_fs_init();
133 if (ret < 0)
134 goto error_transport;
136 return ret;
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() */
159 /*****************************************************************************/
161 * clean up on module removal
163 static void __exit afs_exit(void)
165 printk(KERN_INFO "kAFS: Red Hat AFS client v0.1 unregistering.\n");
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();
180 } /* end afs_exit() */
182 /*****************************************************************************/
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)
189 static int afs_adding_peer(struct rxrpc_peer *peer)
191 struct afs_server *server;
192 int ret;
194 _debug("kAFS: Adding new peer %08x\n", ntohl(peer->addr.s_addr));
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 */
201 _debug("Server %p{u=%d}\n", server, atomic_read(&server->usage));
203 _debug("Cell %p{u=%d}\n",
204 server->cell, atomic_read(&server->cell->usage));
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);
212 afs_put_server(server);
214 return 0;
215 } /* end afs_adding_peer() */
217 /*****************************************************************************/
219 * notification that a peer record is being discarded
220 * - called from krxiod or krxsecd
222 static void afs_discarding_peer(struct rxrpc_peer *peer)
224 struct afs_server *server;
226 _enter("%p",peer);
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));
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;
240 spin_unlock(&afs_server_peer_lock);
242 _leave("");
244 } /* end afs_discarding_peer() */
246 /*****************************************************************************/
248 * clear the dead space between task_struct and kernel stack
249 * - called by supplying -finstrument-functions to gcc
251 #if 0
252 void __cyg_profile_func_enter (void *this_fn, void *call_site)
253 __attribute__((no_instrument_function));
255 void __cyg_profile_func_enter (void *this_fn, void *call_site)
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"
266 : "i"(~(THREAD_SIZE - 1)), "i"(sizeof(struct thread_info))
267 : "eax", "ecx", "edi", "memory", "cc"
271 void __cyg_profile_func_exit(void *this_fn, void *call_site)
272 __attribute__((no_instrument_function));
274 void __cyg_profile_func_exit(void *this_fn, void *call_site)
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"
285 : "i"(~(THREAD_SIZE - 1)), "i"(sizeof(struct thread_info))
286 : "eax", "ecx", "edi", "memory", "cc"
289 #endif