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_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
= {
71 .ops
= &afs_cache_ops
,
75 /*****************************************************************************/
77 * initialise the AFS client FS module
79 static int afs_init(void)
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();
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
);
104 ret
= afs_key_register();
109 /* initialise the cell DB */
110 ret
= afs_cell_init(rootcell
);
114 /* start the timeout daemon */
115 ret
= afs_kafstimod_start();
119 /* start the async operation daemon */
120 ret
= afs_kafsasyncd_start();
122 goto error_kafstimod
;
124 /* create the RxRPC transport */
125 ret
= rxrpc_create_transport(7001, &afs_transport
);
127 goto error_kafsasyncd
;
129 afs_transport
->peer_ops
= &afs_peer_ops
;
131 /* register the filesystems */
134 goto error_transport
;
139 rxrpc_put_transport(afs_transport
);
141 afs_kafsasyncd_stop();
143 afs_kafstimod_stop();
146 afs_key_unregister();
149 #ifdef AFS_CACHING_SUPPORT
150 cachefs_unregister_netfs(&afs_cache_netfs
);
155 printk(KERN_ERR
"kAFS: failed to register: %d\n", 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");
168 rxrpc_put_transport(afs_transport
);
169 afs_kafstimod_stop();
170 afs_kafsasyncd_stop();
173 afs_key_unregister();
175 #ifdef AFS_CACHING_SUPPORT
176 cachefs_unregister_netfs(&afs_cache_netfs
);
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
;
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
);
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
);
210 spin_unlock(&afs_server_peer_lock
);
212 afs_put_server(server
);
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
;
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
);
240 spin_unlock(&afs_server_peer_lock
);
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
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"
260 " movl %%esp,%%ecx \n"
261 " subl %%edi,%%ecx \n"
263 " movl $0xedededed,%%eax \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"
279 " movl %%esp,%%ecx \n"
280 " subl %%edi,%%ecx \n"
282 " movl $0xdadadada,%%eax \n"
285 : "i"(~(THREAD_SIZE
- 1)), "i"(sizeof(struct thread_info
))
286 : "eax", "ecx", "edi", "memory", "cc"