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>
25 #include "cmservice.h"
26 #include "kafstimod.h"
27 #include "kafsasyncd.h"
30 struct rxrpc_transport *afs_transport;
32 static int afs_adding_peer(struct rxrpc_peer *peer);
33 static void afs_discarding_peer(struct rxrpc_peer *peer);
36 MODULE_DESCRIPTION("AFS Client File System");
37 MODULE_AUTHOR("Red Hat, Inc.");
38 MODULE_LICENSE("GPL");
40 static char *rootcell;
42 module_param(rootcell, charp, 0);
43 MODULE_PARM_DESC(rootcell, "root AFS cell name and VL server IP addr list");
46 static struct rxrpc_peer_ops afs_peer_ops = {
47 .adding = afs_adding_peer,
48 .discarding = afs_discarding_peer,
51 struct list_head afs_cb_hash_tbl[AFS_CB_HASH_COUNT];
52 DEFINE_SPINLOCK(afs_cb_hash_lock);
54 #ifdef AFS_CACHING_SUPPORT
55 static struct cachefs_netfs_operations afs_cache_ops = {
56 .get_page_cookie = afs_cache_get_page_cookie,
59 struct cachefs_netfs afs_cache_netfs = {
62 .ops = &afs_cache_ops,
66 /*****************************************************************************/
68 * initialise the AFS client FS module
70 static int __init afs_init(void)
74 printk(KERN_INFO "kAFS: Red Hat AFS client v0.1 registering.\n");
76 /* initialise the callback hash table */
77 spin_lock_init(&afs_cb_hash_lock);
78 for (loop = AFS_CB_HASH_COUNT - 1; loop >= 0; loop--)
79 INIT_LIST_HEAD(&afs_cb_hash_tbl[loop]);
81 /* register the /proc stuff */
82 ret = afs_proc_init();
86 #ifdef AFS_CACHING_SUPPORT
87 /* we want to be able to cache */
88 ret = cachefs_register_netfs(&afs_cache_netfs,
89 &afs_cache_cell_index_def);
94 #ifdef CONFIG_KEYS_TURNED_OFF
95 ret = afs_key_register();
100 /* initialise the cell DB */
101 ret = afs_cell_init(rootcell);
105 /* start the timeout daemon */
106 ret = afs_kafstimod_start();
110 /* start the async operation daemon */
111 ret = afs_kafsasyncd_start();
113 goto error_kafstimod;
115 /* create the RxRPC transport */
116 ret = rxrpc_create_transport(7001, &afs_transport);
118 goto error_kafsasyncd;
120 afs_transport->peer_ops = &afs_peer_ops;
122 /* register the filesystems */
125 goto error_transport;
130 rxrpc_put_transport(afs_transport);
132 afs_kafsasyncd_stop();
134 afs_kafstimod_stop();
136 #ifdef CONFIG_KEYS_TURNED_OFF
137 afs_key_unregister();
140 #ifdef AFS_CACHING_SUPPORT
141 cachefs_unregister_netfs(&afs_cache_netfs);
146 printk(KERN_ERR "kAFS: failed to register: %d\n", ret);
148 } /* end afs_init() */
150 /* XXX late_initcall is kludgy, but the only alternative seems to create
151 * a transport upon the first mount, which is worse. Or is it?
153 late_initcall(afs_init); /* must be called after net/ to create socket */
154 /*****************************************************************************/
156 * clean up on module removal
158 static void __exit afs_exit(void)
160 printk(KERN_INFO "kAFS: Red Hat AFS client v0.1 unregistering.\n");
163 rxrpc_put_transport(afs_transport);
164 afs_kafstimod_stop();
165 afs_kafsasyncd_stop();
167 #ifdef CONFIG_KEYS_TURNED_OFF
168 afs_key_unregister();
170 #ifdef AFS_CACHING_SUPPORT
171 cachefs_unregister_netfs(&afs_cache_netfs);
175 } /* end afs_exit() */
177 module_exit(afs_exit);
179 /*****************************************************************************/
181 * notification that new peer record is being added
182 * - called from krxsecd
183 * - return an error to induce an abort
184 * - mustn't sleep (caller holds an rwlock)
186 static int afs_adding_peer(struct rxrpc_peer *peer)
188 struct afs_server *server;
191 _debug("kAFS: Adding new peer %08x\n", ntohl(peer->addr.s_addr));
193 /* determine which server the peer resides in (if any) */
194 ret = afs_server_find_by_peer(peer, &server);
196 return ret; /* none that we recognise, so abort */
198 _debug("Server %p{u=%d}\n", server, atomic_read(&server->usage));
200 _debug("Cell %p{u=%d}\n",
201 server->cell, atomic_read(&server->cell->usage));
203 /* cross-point the structs under a global lock */
204 spin_lock(&afs_server_peer_lock);
207 spin_unlock(&afs_server_peer_lock);
209 afs_put_server(server);
212 } /* end afs_adding_peer() */
214 /*****************************************************************************/
216 * notification that a peer record is being discarded
217 * - called from krxiod or krxsecd
219 static void afs_discarding_peer(struct rxrpc_peer *peer)
221 struct afs_server *server;
225 _debug("Discarding peer %08x (rtt=%lu.%lumS)\n",
226 ntohl(peer->addr.s_addr),
227 (long) (peer->rtt / 1000),
228 (long) (peer->rtt % 1000));
230 /* uncross-point the structs under a global lock */
231 spin_lock(&afs_server_peer_lock);
237 spin_unlock(&afs_server_peer_lock);
241 } /* end afs_discarding_peer() */
243 /*****************************************************************************/
245 * clear the dead space between task_struct and kernel stack
246 * - called by supplying -finstrument-functions to gcc
249 void __cyg_profile_func_enter (void *this_fn, void *call_site)
250 __attribute__((no_instrument_function));
252 void __cyg_profile_func_enter (void *this_fn, void *call_site)
254 asm volatile(" movl %%esp,%%edi \n"
257 " movl %%esp,%%ecx \n"
258 " subl %%edi,%%ecx \n"
260 " movl $0xedededed,%%eax \n"
263 : "i"(~(THREAD_SIZE - 1)), "i"(sizeof(struct thread_info))
264 : "eax", "ecx", "edi", "memory", "cc"
268 void __cyg_profile_func_exit(void *this_fn, void *call_site)
269 __attribute__((no_instrument_function));
271 void __cyg_profile_func_exit(void *this_fn, void *call_site)
273 asm volatile(" movl %%esp,%%edi \n"
276 " movl %%esp,%%ecx \n"
277 " subl %%edi,%%ecx \n"
279 " movl $0xdadadada,%%eax \n"
282 : "i"(~(THREAD_SIZE - 1)), "i"(sizeof(struct thread_info))
283 : "eax", "ecx", "edi", "memory", "cc"