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/init.h>
14 #include <linux/sched.h>
15 #include <linux/completion.h>
16 #include <rxrpc/rxrpc.h>
17 #include <rxrpc/transport.h>
18 #include <rxrpc/call.h>
19 #include <rxrpc/peer.h>
24 #include "cmservice.h"
25 #include "kafstimod.h"
26 #include "kafsasyncd.h"
29 struct rxrpc_transport *afs_transport;
31 static int afs_init(void);
32 static void afs_exit(void);
33 static int afs_adding_peer(struct rxrpc_peer *peer);
34 static void afs_discarding_peer(struct rxrpc_peer *peer);
36 /* XXX late_initcall is kludgy, but the only alternative seems to create
37 * a transport upon the first mount, which is worse. Or is it?
39 /* module_init(afs_init); */
40 late_initcall(afs_init); /* must be called after net/ to create socket */
42 module_exit(afs_exit);
44 MODULE_DESCRIPTION("AFS Client File System");
45 MODULE_AUTHOR("Red Hat, Inc.");
46 MODULE_LICENSE("GPL");
48 static char *rootcell;
50 MODULE_PARM(rootcell, "s");
51 MODULE_PARM_DESC(rootcell, "root AFS cell name and VL server IP addr list");
54 static struct rxrpc_peer_ops afs_peer_ops = {
55 .adding = afs_adding_peer,
56 .discarding = afs_discarding_peer,
59 struct list_head afs_cb_hash_tbl[AFS_CB_HASH_COUNT];
60 spinlock_t afs_cb_hash_lock = SPIN_LOCK_UNLOCKED;
62 #ifdef AFS_CACHING_SUPPORT
63 static struct cachefs_netfs_operations afs_cache_ops = {
64 .get_page_cookie = afs_cache_get_page_cookie,
67 struct cachefs_netfs afs_cache_netfs = {
70 .ops = &afs_cache_ops,
74 /*****************************************************************************/
76 * initialise the AFS client FS module
78 static int afs_init(void)
82 printk(KERN_INFO "kAFS: Red Hat AFS client v0.1 registering.\n");
84 /* initialise the callback hash table */
85 spin_lock_init(&afs_cb_hash_lock);
86 for (loop = AFS_CB_HASH_COUNT - 1; loop >= 0; loop--)
87 INIT_LIST_HEAD(&afs_cb_hash_tbl[loop]);
89 /* register the /proc stuff */
90 ret = afs_proc_init();
94 #ifdef AFS_CACHING_SUPPORT
95 /* we want to be able to cache */
96 ret = cachefs_register_netfs(&afs_cache_netfs,
97 &afs_cache_cell_index_def);
103 ret = afs_key_register();
108 /* initialise the cell DB */
109 ret = afs_cell_init(rootcell);
113 /* start the timeout daemon */
114 ret = afs_kafstimod_start();
118 /* start the async operation daemon */
119 ret = afs_kafsasyncd_start();
121 goto error_kafstimod;
123 /* create the RxRPC transport */
124 ret = rxrpc_create_transport(7001, &afs_transport);
126 goto error_kafsasyncd;
128 afs_transport->peer_ops = &afs_peer_ops;
130 /* register the filesystems */
133 goto error_transport;
138 rxrpc_put_transport(afs_transport);
140 afs_kafsasyncd_stop();
142 afs_kafstimod_stop();
145 afs_key_unregister();
148 #ifdef AFS_CACHING_SUPPORT
149 cachefs_unregister_netfs(&afs_cache_netfs);
154 printk(KERN_ERR "kAFS: failed to register: %d\n", ret);
156 } /* end afs_init() */
158 /*****************************************************************************/
160 * clean up on module removal
162 static void __exit afs_exit(void)
164 printk(KERN_INFO "kAFS: Red Hat AFS client v0.1 unregistering.\n");
167 rxrpc_put_transport(afs_transport);
168 afs_kafstimod_stop();
169 afs_kafsasyncd_stop();
172 afs_key_unregister();
174 #ifdef AFS_CACHING_SUPPORT
175 cachefs_unregister_netfs(&afs_cache_netfs);
179 } /* end afs_exit() */
181 /*****************************************************************************/
183 * notification that new peer record is being added
184 * - called from krxsecd
185 * - return an error to induce an abort
186 * - mustn't sleep (caller holds an rwlock)
188 static int afs_adding_peer(struct rxrpc_peer *peer)
190 struct afs_server *server;
193 _debug("kAFS: Adding new peer %08x\n", ntohl(peer->addr.s_addr));
195 /* determine which server the peer resides in (if any) */
196 ret = afs_server_find_by_peer(peer, &server);
198 return ret; /* none that we recognise, so abort */
200 _debug("Server %p{u=%d}\n", server, atomic_read(&server->usage));
202 _debug("Cell %p{u=%d}\n",
203 server->cell, atomic_read(&server->cell->usage));
205 /* cross-point the structs under a global lock */
206 spin_lock(&afs_server_peer_lock);
209 spin_unlock(&afs_server_peer_lock);
211 afs_put_server(server);
214 } /* end afs_adding_peer() */
216 /*****************************************************************************/
218 * notification that a peer record is being discarded
219 * - called from krxiod or krxsecd
221 static void afs_discarding_peer(struct rxrpc_peer *peer)
223 struct afs_server *server;
227 _debug("Discarding peer %08x (rtt=%lu.%lumS)\n",
228 ntohl(peer->addr.s_addr),
229 (long) (peer->rtt / 1000),
230 (long) (peer->rtt % 1000));
232 /* uncross-point the structs under a global lock */
233 spin_lock(&afs_server_peer_lock);
239 spin_unlock(&afs_server_peer_lock);
243 } /* end afs_discarding_peer() */
245 /*****************************************************************************/
247 * clear the dead space between task_struct and kernel stack
248 * - called by supplying -finstrument-functions to gcc
251 void __cyg_profile_func_enter (void *this_fn, void *call_site)
252 __attribute__((no_instrument_function));
254 void __cyg_profile_func_enter (void *this_fn, void *call_site)
256 asm volatile(" movl %%esp,%%edi \n"
259 " movl %%esp,%%ecx \n"
260 " subl %%edi,%%ecx \n"
262 " movl $0xedededed,%%eax \n"
265 : "i"(~(THREAD_SIZE - 1)), "i"(sizeof(struct thread_info))
266 : "eax", "ecx", "edi", "memory", "cc"
270 void __cyg_profile_func_exit(void *this_fn, void *call_site)
271 __attribute__((no_instrument_function));
273 void __cyg_profile_func_exit(void *this_fn, void *call_site)
275 asm volatile(" movl %%esp,%%edi \n"
278 " movl %%esp,%%ecx \n"
279 " subl %%edi,%%ecx \n"
281 " movl $0xdadadada,%%eax \n"
284 : "i"(~(THREAD_SIZE - 1)), "i"(sizeof(struct thread_info))
285 : "eax", "ecx", "edi", "memory", "cc"