1 /* main.c: AFS client file system
3 * Copyright (C) 2002,5 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 <linux/fscache.h>
18 #include <rxrpc/rxrpc.h>
19 #include <rxrpc/transport.h>
20 #include <rxrpc/call.h>
21 #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 CONFIG_AFS_FSCACHE
55 static struct fscache_netfs_operations afs_cache_ops = {
58 struct fscache_netfs afs_cache_netfs = {
61 .ops = &afs_cache_ops,
65 /*****************************************************************************/
67 * initialise the AFS client FS module
69 static int __init afs_init(void)
73 printk(KERN_INFO "kAFS: Red Hat AFS client v0.1 registering.\n");
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]);
80 /* register the /proc stuff */
81 ret = afs_proc_init();
85 #ifdef CONFIG_AFS_FSCACHE
86 /* we want to be able to cache */
87 ret = fscache_register_netfs(&afs_cache_netfs);
92 #ifdef CONFIG_KEYS_TURNED_OFF
93 ret = afs_key_register();
98 /* initialise the cell DB */
99 ret = afs_cell_init(rootcell);
103 /* start the timeout daemon */
104 ret = afs_kafstimod_start();
108 /* start the async operation daemon */
109 ret = afs_kafsasyncd_start();
111 goto error_kafstimod;
113 /* create the RxRPC transport */
114 ret = rxrpc_create_transport(7001, &afs_transport);
116 goto error_kafsasyncd;
118 afs_transport->peer_ops = &afs_peer_ops;
120 /* register the filesystems */
123 goto error_transport;
128 rxrpc_put_transport(afs_transport);
130 afs_kafsasyncd_stop();
132 afs_kafstimod_stop();
134 #ifdef CONFIG_KEYS_TURNED_OFF
135 afs_key_unregister();
138 #ifdef CONFIG_AFS_FSCACHE
139 fscache_unregister_netfs(&afs_cache_netfs);
144 printk(KERN_ERR "kAFS: failed to register: %d\n", ret);
146 } /* end afs_init() */
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?
151 late_initcall(afs_init); /* must be called after net/ to create socket */
152 /*****************************************************************************/
154 * clean up on module removal
156 static void __exit afs_exit(void)
158 printk(KERN_INFO "kAFS: Red Hat AFS client v0.1 unregistering.\n");
161 rxrpc_put_transport(afs_transport);
162 afs_kafstimod_stop();
163 afs_kafsasyncd_stop();
165 #ifdef CONFIG_KEYS_TURNED_OFF
166 afs_key_unregister();
168 #ifdef CONFIG_AFS_FSCACHE
169 fscache_unregister_netfs(&afs_cache_netfs);
173 } /* end afs_exit() */
175 module_exit(afs_exit);
177 /*****************************************************************************/
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)
184 static int afs_adding_peer(struct rxrpc_peer *peer)
186 struct afs_server *server;
189 _debug("kAFS: Adding new peer %08x\n", ntohl(peer->addr.s_addr));
191 /* determine which server the peer resides in (if any) */
192 ret = afs_server_find_by_peer(peer, &server);
194 return ret; /* none that we recognise, so abort */
196 _debug("Server %p{u=%d}\n", server, atomic_read(&server->usage));
198 _debug("Cell %p{u=%d}\n",
199 server->cell, atomic_read(&server->cell->usage));
201 /* cross-point the structs under a global lock */
202 spin_lock(&afs_server_peer_lock);
205 spin_unlock(&afs_server_peer_lock);
207 afs_put_server(server);
210 } /* end afs_adding_peer() */
212 /*****************************************************************************/
214 * notification that a peer record is being discarded
215 * - called from krxiod or krxsecd
217 static void afs_discarding_peer(struct rxrpc_peer *peer)
219 struct afs_server *server;
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));
228 /* uncross-point the structs under a global lock */
229 spin_lock(&afs_server_peer_lock);
235 spin_unlock(&afs_server_peer_lock);
239 } /* end afs_discarding_peer() */
241 /*****************************************************************************/
243 * clear the dead space between task_struct and kernel stack
244 * - called by supplying -finstrument-functions to gcc
247 void __cyg_profile_func_enter (void *this_fn, void *call_site)
248 __attribute__((no_instrument_function));
250 void __cyg_profile_func_enter (void *this_fn, void *call_site)
252 asm volatile(" movl %%esp,%%edi \n"
255 " movl %%esp,%%ecx \n"
256 " subl %%edi,%%ecx \n"
258 " movl $0xedededed,%%eax \n"
261 : "i"(~(THREAD_SIZE - 1)), "i"(sizeof(struct thread_info))
262 : "eax", "ecx", "edi", "memory", "cc"
266 void __cyg_profile_func_exit(void *this_fn, void *call_site)
267 __attribute__((no_instrument_function));
269 void __cyg_profile_func_exit(void *this_fn, void *call_site)
271 asm volatile(" movl %%esp,%%edi \n"
274 " movl %%esp,%%ecx \n"
275 " subl %%edi,%%ecx \n"
277 " movl $0xdadadada,%%eax \n"
280 : "i"(~(THREAD_SIZE - 1)), "i"(sizeof(struct thread_info))
281 : "eax", "ecx", "edi", "memory", "cc"