1 /* 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/completion.h>
16 #include <linux/sched.h>
17 #include <linux/random.h>
18 #include <linux/proc_fs.h>
19 #define CREATE_TRACE_POINTS
22 MODULE_DESCRIPTION("AFS Client File System");
23 MODULE_AUTHOR("Red Hat, Inc.");
24 MODULE_LICENSE("GPL");
27 module_param_named(debug
, afs_debug
, uint
, S_IWUSR
| S_IRUGO
);
28 MODULE_PARM_DESC(debug
, "AFS debugging mask");
30 static char *rootcell
;
32 module_param(rootcell
, charp
, 0);
33 MODULE_PARM_DESC(rootcell
, "root AFS cell name and VL server IP addr list");
35 struct workqueue_struct
*afs_wq
;
36 static struct proc_dir_entry
*afs_proc_symlink
;
38 #if defined(CONFIG_ALPHA)
39 const char afs_init_sysname
[] = "alpha_linux26";
40 #elif defined(CONFIG_X86_64)
41 const char afs_init_sysname
[] = "amd64_linux26";
42 #elif defined(CONFIG_ARM)
43 const char afs_init_sysname
[] = "arm_linux26";
44 #elif defined(CONFIG_ARM64)
45 const char afs_init_sysname
[] = "aarch64_linux26";
46 #elif defined(CONFIG_X86_32)
47 const char afs_init_sysname
[] = "i386_linux26";
48 #elif defined(CONFIG_IA64)
49 const char afs_init_sysname
[] = "ia64_linux26";
50 #elif defined(CONFIG_PPC64)
51 const char afs_init_sysname
[] = "ppc64_linux26";
52 #elif defined(CONFIG_PPC32)
53 const char afs_init_sysname
[] = "ppc_linux26";
54 #elif defined(CONFIG_S390)
56 const char afs_init_sysname
[] = "s390x_linux26";
58 const char afs_init_sysname
[] = "s390_linux26";
60 #elif defined(CONFIG_SPARC64)
61 const char afs_init_sysname
[] = "sparc64_linux26";
62 #elif defined(CONFIG_SPARC32)
63 const char afs_init_sysname
[] = "sparc_linux26";
65 const char afs_init_sysname
[] = "unknown_linux26";
69 * Initialise an AFS network namespace record.
71 static int __net_init
afs_net_init(struct net
*net_ns
)
73 struct afs_sysnames
*sysnames
;
74 struct afs_net
*net
= afs_net(net_ns
);
79 generate_random_uuid((unsigned char *)&net
->uuid
);
81 INIT_WORK(&net
->charge_preallocation_work
, afs_charge_preallocation
);
82 mutex_init(&net
->socket_mutex
);
85 seqlock_init(&net
->cells_lock
);
86 INIT_WORK(&net
->cells_manager
, afs_manage_cells
);
87 timer_setup(&net
->cells_timer
, afs_cells_timer
, 0);
89 mutex_init(&net
->proc_cells_lock
);
90 INIT_LIST_HEAD(&net
->proc_cells
);
92 seqlock_init(&net
->fs_lock
);
93 net
->fs_servers
= RB_ROOT
;
94 INIT_LIST_HEAD(&net
->fs_updates
);
95 INIT_HLIST_HEAD(&net
->fs_proc
);
97 INIT_HLIST_HEAD(&net
->fs_addresses4
);
98 INIT_HLIST_HEAD(&net
->fs_addresses6
);
99 seqlock_init(&net
->fs_addr_lock
);
101 INIT_WORK(&net
->fs_manager
, afs_manage_servers
);
102 timer_setup(&net
->fs_timer
, afs_servers_timer
, 0);
105 sysnames
= kzalloc(sizeof(*sysnames
), GFP_KERNEL
);
108 sysnames
->subs
[0] = (char *)&afs_init_sysname
;
110 refcount_set(&sysnames
->usage
, 1);
111 net
->sysnames
= sysnames
;
112 rwlock_init(&net
->sysnames_lock
);
114 /* Register the /proc stuff */
115 ret
= afs_proc_init(net
);
119 /* Initialise the cell DB */
120 ret
= afs_cell_init(net
, rootcell
);
122 goto error_cell_init
;
124 /* Create the RxRPC transport */
125 ret
= afs_open_socket(net
);
127 goto error_open_socket
;
134 afs_purge_servers(net
);
137 afs_proc_cleanup(net
);
139 afs_put_sysnames(net
->sysnames
);
146 * Clean up and destroy an AFS network namespace record.
148 static void __net_exit
afs_net_exit(struct net
*net_ns
)
150 struct afs_net
*net
= afs_net(net_ns
);
154 afs_purge_servers(net
);
155 afs_close_socket(net
);
156 afs_proc_cleanup(net
);
157 afs_put_sysnames(net
->sysnames
);
160 static struct pernet_operations afs_net_ops
= {
161 .init
= afs_net_init
,
162 .exit
= afs_net_exit
,
164 .size
= sizeof(struct afs_net
),
168 * initialise the AFS client FS module
170 static int __init
afs_init(void)
174 printk(KERN_INFO
"kAFS: Red Hat AFS client v0.1 registering.\n");
176 afs_wq
= alloc_workqueue("afs", 0, 0);
179 afs_async_calls
= alloc_workqueue("kafsd", WQ_MEM_RECLAIM
, 0);
180 if (!afs_async_calls
)
182 afs_lock_manager
= alloc_workqueue("kafs_lockd", WQ_MEM_RECLAIM
, 0);
183 if (!afs_lock_manager
)
186 #ifdef CONFIG_AFS_FSCACHE
187 /* we want to be able to cache */
188 ret
= fscache_register_netfs(&afs_cache_netfs
);
193 ret
= register_pernet_subsys(&afs_net_ops
);
197 /* register the filesystems */
202 afs_proc_symlink
= proc_symlink("fs/afs", NULL
, "../self/net/afs");
203 if (IS_ERR(afs_proc_symlink
)) {
204 ret
= PTR_ERR(afs_proc_symlink
);
213 unregister_pernet_subsys(&afs_net_ops
);
215 #ifdef CONFIG_AFS_FSCACHE
216 fscache_unregister_netfs(&afs_cache_netfs
);
219 destroy_workqueue(afs_lock_manager
);
221 destroy_workqueue(afs_async_calls
);
223 destroy_workqueue(afs_wq
);
226 printk(KERN_ERR
"kAFS: failed to register: %d\n", ret
);
230 /* XXX late_initcall is kludgy, but the only alternative seems to create
231 * a transport upon the first mount, which is worse. Or is it?
233 late_initcall(afs_init
); /* must be called after net/ to create socket */
236 * clean up on module removal
238 static void __exit
afs_exit(void)
240 printk(KERN_INFO
"kAFS: Red Hat AFS client v0.1 unregistering.\n");
242 proc_remove(afs_proc_symlink
);
244 unregister_pernet_subsys(&afs_net_ops
);
245 #ifdef CONFIG_AFS_FSCACHE
246 fscache_unregister_netfs(&afs_cache_netfs
);
248 destroy_workqueue(afs_lock_manager
);
249 destroy_workqueue(afs_async_calls
);
250 destroy_workqueue(afs_wq
);
251 afs_clean_up_permit_cache();
255 module_exit(afs_exit
);