[PATCH] PM: use kobject_name() to access kobject names
[linux-2.6/openmoko-kernel/knife-kernel.git] / fs / afs / main.c
blobf2704ba5385735f598f4378a7591d05042ac7214
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>
20 #include "cache.h"
21 #include "cell.h"
22 #include "server.h"
23 #include "fsclient.h"
24 #include "cmservice.h"
25 #include "kafstimod.h"
26 #include "kafsasyncd.h"
27 #include "internal.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 = {
59 .name = "afs",
60 .version = 0,
61 .ops = &afs_cache_ops,
63 #endif
65 /*****************************************************************************/
67 * initialise the AFS client FS module
69 static int __init afs_init(void)
71 int loop, ret;
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();
82 if (ret < 0)
83 return ret;
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);
89 if (ret < 0)
90 goto error;
91 #endif
93 #ifdef CONFIG_KEYS_TURNED_OFF
94 ret = afs_key_register();
95 if (ret < 0)
96 goto error_cache;
97 #endif
99 /* initialise the cell DB */
100 ret = afs_cell_init(rootcell);
101 if (ret < 0)
102 goto error_keys;
104 /* start the timeout daemon */
105 ret = afs_kafstimod_start();
106 if (ret < 0)
107 goto error_keys;
109 /* start the async operation daemon */
110 ret = afs_kafsasyncd_start();
111 if (ret < 0)
112 goto error_kafstimod;
114 /* create the RxRPC transport */
115 ret = rxrpc_create_transport(7001, &afs_transport);
116 if (ret < 0)
117 goto error_kafsasyncd;
119 afs_transport->peer_ops = &afs_peer_ops;
121 /* register the filesystems */
122 ret = afs_fs_init();
123 if (ret < 0)
124 goto error_transport;
126 return ret;
128 error_transport:
129 rxrpc_put_transport(afs_transport);
130 error_kafsasyncd:
131 afs_kafsasyncd_stop();
132 error_kafstimod:
133 afs_kafstimod_stop();
134 error_keys:
135 #ifdef CONFIG_KEYS_TURNED_OFF
136 afs_key_unregister();
137 error_cache:
138 #endif
139 #ifdef AFS_CACHING_SUPPORT
140 cachefs_unregister_netfs(&afs_cache_netfs);
141 error:
142 #endif
143 afs_cell_purge();
144 afs_proc_cleanup();
145 printk(KERN_ERR "kAFS: failed to register: %d\n", ret);
146 return 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");
161 afs_fs_exit();
162 rxrpc_put_transport(afs_transport);
163 afs_kafstimod_stop();
164 afs_kafsasyncd_stop();
165 afs_cell_purge();
166 #ifdef CONFIG_KEYS_TURNED_OFF
167 afs_key_unregister();
168 #endif
169 #ifdef AFS_CACHING_SUPPORT
170 cachefs_unregister_netfs(&afs_cache_netfs);
171 #endif
172 afs_proc_cleanup();
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;
188 int ret;
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);
194 if (ret < 0)
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);
204 peer->user = server;
205 server->peer = peer;
206 spin_unlock(&afs_server_peer_lock);
208 afs_put_server(server);
210 return 0;
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;
222 _enter("%p",peer);
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);
231 server = peer->user;
232 if (server) {
233 peer->user = NULL;
234 server->peer = NULL;
236 spin_unlock(&afs_server_peer_lock);
238 _leave("");
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
247 #if 0
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"
254 " andl %0,%%edi \n"
255 " addl %1,%%edi \n"
256 " movl %%esp,%%ecx \n"
257 " subl %%edi,%%ecx \n"
258 " shrl $2,%%ecx \n"
259 " movl $0xedededed,%%eax \n"
260 " rep stosl \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"
273 " andl %0,%%edi \n"
274 " addl %1,%%edi \n"
275 " movl %%esp,%%ecx \n"
276 " subl %%edi,%%ecx \n"
277 " shrl $2,%%ecx \n"
278 " movl $0xdadadada,%%eax \n"
279 " rep stosl \n"
281 : "i"(~(THREAD_SIZE - 1)), "i"(sizeof(struct thread_info))
282 : "eax", "ecx", "edi", "memory", "cc"
285 #endif