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/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_adding_peer(struct rxrpc_peer
*peer
);
32 static void afs_discarding_peer(struct rxrpc_peer
*peer
);
35 MODULE_DESCRIPTION("AFS Client File System");
36 MODULE_AUTHOR("Red Hat, Inc.");
37 MODULE_LICENSE("GPL");
39 static char *rootcell
;
41 module_param(rootcell
, charp
, 0);
42 MODULE_PARM_DESC(rootcell
, "root AFS cell name and VL server IP addr list");
45 static struct rxrpc_peer_ops afs_peer_ops
= {
46 .adding
= afs_adding_peer
,
47 .discarding
= afs_discarding_peer
,
50 struct list_head afs_cb_hash_tbl
[AFS_CB_HASH_COUNT
];
51 DEFINE_SPINLOCK(afs_cb_hash_lock
);
53 #ifdef AFS_CACHING_SUPPORT
54 static struct cachefs_netfs_operations afs_cache_ops
= {
55 .get_page_cookie
= afs_cache_get_page_cookie
,
58 struct cachefs_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 AFS_CACHING_SUPPORT
86 /* we want to be able to cache */
87 ret
= cachefs_register_netfs(&afs_cache_netfs
,
88 &afs_cache_cell_index_def
);
93 #ifdef CONFIG_KEYS_TURNED_OFF
94 ret
= afs_key_register();
99 /* initialise the cell DB */
100 ret
= afs_cell_init(rootcell
);
104 /* start the timeout daemon */
105 ret
= afs_kafstimod_start();
109 /* start the async operation daemon */
110 ret
= afs_kafsasyncd_start();
112 goto error_kafstimod
;
114 /* create the RxRPC transport */
115 ret
= rxrpc_create_transport(7001, &afs_transport
);
117 goto error_kafsasyncd
;
119 afs_transport
->peer_ops
= &afs_peer_ops
;
121 /* register the filesystems */
124 goto error_transport
;
129 rxrpc_put_transport(afs_transport
);
131 afs_kafsasyncd_stop();
133 afs_kafstimod_stop();
135 #ifdef CONFIG_KEYS_TURNED_OFF
136 afs_key_unregister();
139 #ifdef AFS_CACHING_SUPPORT
140 cachefs_unregister_netfs(&afs_cache_netfs
);
145 printk(KERN_ERR
"kAFS: failed to register: %d\n", ret
);
147 } /* end afs_init() */
149 /* XXX late_initcall is kludgy, but the only alternative seems to create
150 * a transport upon the first mount, which is worse. Or is it?
152 late_initcall(afs_init
); /* must be called after net/ to create socket */
153 /*****************************************************************************/
155 * clean up on module removal
157 static void __exit
afs_exit(void)
159 printk(KERN_INFO
"kAFS: Red Hat AFS client v0.1 unregistering.\n");
162 rxrpc_put_transport(afs_transport
);
163 afs_kafstimod_stop();
164 afs_kafsasyncd_stop();
166 #ifdef CONFIG_KEYS_TURNED_OFF
167 afs_key_unregister();
169 #ifdef AFS_CACHING_SUPPORT
170 cachefs_unregister_netfs(&afs_cache_netfs
);
174 } /* end afs_exit() */
176 module_exit(afs_exit
);
178 /*****************************************************************************/
180 * notification that new peer record is being added
181 * - called from krxsecd
182 * - return an error to induce an abort
183 * - mustn't sleep (caller holds an rwlock)
185 static int afs_adding_peer(struct rxrpc_peer
*peer
)
187 struct afs_server
*server
;
190 _debug("kAFS: Adding new peer %08x\n", ntohl(peer
->addr
.s_addr
));
192 /* determine which server the peer resides in (if any) */
193 ret
= afs_server_find_by_peer(peer
, &server
);
195 return ret
; /* none that we recognise, so abort */
197 _debug("Server %p{u=%d}\n", server
, atomic_read(&server
->usage
));
199 _debug("Cell %p{u=%d}\n",
200 server
->cell
, atomic_read(&server
->cell
->usage
));
202 /* cross-point the structs under a global lock */
203 spin_lock(&afs_server_peer_lock
);
206 spin_unlock(&afs_server_peer_lock
);
208 afs_put_server(server
);
211 } /* end afs_adding_peer() */
213 /*****************************************************************************/
215 * notification that a peer record is being discarded
216 * - called from krxiod or krxsecd
218 static void afs_discarding_peer(struct rxrpc_peer
*peer
)
220 struct afs_server
*server
;
224 _debug("Discarding peer %08x (rtt=%lu.%lumS)\n",
225 ntohl(peer
->addr
.s_addr
),
226 (long) (peer
->rtt
/ 1000),
227 (long) (peer
->rtt
% 1000));
229 /* uncross-point the structs under a global lock */
230 spin_lock(&afs_server_peer_lock
);
236 spin_unlock(&afs_server_peer_lock
);
240 } /* end afs_discarding_peer() */
242 /*****************************************************************************/
244 * clear the dead space between task_struct and kernel stack
245 * - called by supplying -finstrument-functions to gcc
248 void __cyg_profile_func_enter (void *this_fn
, void *call_site
)
249 __attribute__((no_instrument_function
));
251 void __cyg_profile_func_enter (void *this_fn
, void *call_site
)
253 asm volatile(" movl %%esp,%%edi \n"
256 " movl %%esp,%%ecx \n"
257 " subl %%edi,%%ecx \n"
259 " movl $0xedededed,%%eax \n"
262 : "i"(~(THREAD_SIZE
- 1)), "i"(sizeof(struct thread_info
))
263 : "eax", "ecx", "edi", "memory", "cc"
267 void __cyg_profile_func_exit(void *this_fn
, void *call_site
)
268 __attribute__((no_instrument_function
));
270 void __cyg_profile_func_exit(void *this_fn
, void *call_site
)
272 asm volatile(" movl %%esp,%%edi \n"
275 " movl %%esp,%%ecx \n"
276 " subl %%edi,%%ecx \n"
278 " movl $0xdadadada,%%eax \n"
281 : "i"(~(THREAD_SIZE
- 1)), "i"(sizeof(struct thread_info
))
282 : "eax", "ecx", "edi", "memory", "cc"