1 /* 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,
66 * initialise the AFS client FS module
68 static int __init afs_init(void)
72 printk(KERN_INFO "kAFS: Red Hat AFS client v0.1 registering.\n");
74 /* initialise the callback hash table */
75 spin_lock_init(&afs_cb_hash_lock);
76 for (loop = AFS_CB_HASH_COUNT - 1; loop >= 0; loop--)
77 INIT_LIST_HEAD(&afs_cb_hash_tbl[loop]);
79 /* register the /proc stuff */
80 ret = afs_proc_init();
84 #ifdef AFS_CACHING_SUPPORT
85 /* we want to be able to cache */
86 ret = cachefs_register_netfs(&afs_cache_netfs,
87 &afs_cache_cell_index_def);
92 /* initialise the cell DB */
93 ret = afs_cell_init(rootcell);
97 /* start the timeout daemon */
98 ret = afs_kafstimod_start();
100 goto error_kafstimod;
102 /* start the async operation daemon */
103 ret = afs_kafsasyncd_start();
105 goto error_kafsasyncd;
107 /* create the RxRPC transport */
108 ret = rxrpc_create_transport(7001, &afs_transport);
110 goto error_transport;
112 afs_transport->peer_ops = &afs_peer_ops;
114 /* register the filesystems */
122 rxrpc_put_transport(afs_transport);
124 afs_kafsasyncd_stop();
126 afs_kafstimod_stop();
129 #ifdef AFS_CACHING_SUPPORT
130 cachefs_unregister_netfs(&afs_cache_netfs);
135 printk(KERN_ERR "kAFS: failed to register: %d\n", ret);
139 /* XXX late_initcall is kludgy, but the only alternative seems to create
140 * a transport upon the first mount, which is worse. Or is it?
142 late_initcall(afs_init); /* must be called after net/ to create socket */
145 * clean up on module removal
147 static void __exit afs_exit(void)
149 printk(KERN_INFO "kAFS: Red Hat AFS client v0.1 unregistering.\n");
152 rxrpc_put_transport(afs_transport);
153 afs_kafstimod_stop();
154 afs_kafsasyncd_stop();
156 #ifdef AFS_CACHING_SUPPORT
157 cachefs_unregister_netfs(&afs_cache_netfs);
162 module_exit(afs_exit);
165 * notification that new peer record is being added
166 * - called from krxsecd
167 * - return an error to induce an abort
168 * - mustn't sleep (caller holds an rwlock)
170 static int afs_adding_peer(struct rxrpc_peer *peer)
172 struct afs_server *server;
175 _debug("kAFS: Adding new peer %08x\n", ntohl(peer->addr.s_addr));
177 /* determine which server the peer resides in (if any) */
178 ret = afs_server_find_by_peer(peer, &server);
180 return ret; /* none that we recognise, so abort */
182 _debug("Server %p{u=%d}\n", server, atomic_read(&server->usage));
184 _debug("Cell %p{u=%d}\n",
185 server->cell, atomic_read(&server->cell->usage));
187 /* cross-point the structs under a global lock */
188 spin_lock(&afs_server_peer_lock);
191 spin_unlock(&afs_server_peer_lock);
193 afs_put_server(server);
199 * notification that a peer record is being discarded
200 * - called from krxiod or krxsecd
202 static void afs_discarding_peer(struct rxrpc_peer *peer)
204 struct afs_server *server;
208 _debug("Discarding peer %08x (rtt=%lu.%lumS)\n",
209 ntohl(peer->addr.s_addr),
210 (long) (peer->rtt / 1000),
211 (long) (peer->rtt % 1000));
213 /* uncross-point the structs under a global lock */
214 spin_lock(&afs_server_peer_lock);
220 spin_unlock(&afs_server_peer_lock);