]>
Commit | Line | Data |
---|---|---|
2874c5fd | 1 | // SPDX-License-Identifier: GPL-2.0-or-later |
ec26815a | 2 | /* AFS client file system |
1da177e4 | 3 | * |
9b3f26c9 | 4 | * Copyright (C) 2002,5 Red Hat, Inc. All Rights Reserved. |
1da177e4 | 5 | * Written by David Howells (dhowells@redhat.com) |
1da177e4 LT |
6 | */ |
7 | ||
8 | #include <linux/module.h> | |
9 | #include <linux/moduleparam.h> | |
10 | #include <linux/init.h> | |
1da177e4 | 11 | #include <linux/completion.h> |
e8edc6e0 | 12 | #include <linux/sched.h> |
e0661dfc | 13 | #include <linux/random.h> |
5b86d4ff | 14 | #include <linux/proc_fs.h> |
8e8d7f13 | 15 | #define CREATE_TRACE_POINTS |
1da177e4 LT |
16 | #include "internal.h" |
17 | ||
1da177e4 LT |
18 | MODULE_DESCRIPTION("AFS Client File System"); |
19 | MODULE_AUTHOR("Red Hat, Inc."); | |
20 | MODULE_LICENSE("GPL"); | |
21 | ||
08e0e7c8 DH |
22 | unsigned afs_debug; |
23 | module_param_named(debug, afs_debug, uint, S_IWUSR | S_IRUGO); | |
424b00e2 | 24 | MODULE_PARM_DESC(debug, "AFS debugging mask"); |
08e0e7c8 | 25 | |
1da177e4 LT |
26 | static char *rootcell; |
27 | ||
28 | module_param(rootcell, charp, 0); | |
29 | MODULE_PARM_DESC(rootcell, "root AFS cell name and VL server IP addr list"); | |
30 | ||
0ad53eee | 31 | struct workqueue_struct *afs_wq; |
5b86d4ff | 32 | static struct proc_dir_entry *afs_proc_symlink; |
f044c884 | 33 | |
6f8880d8 DH |
34 | #if defined(CONFIG_ALPHA) |
35 | const char afs_init_sysname[] = "alpha_linux26"; | |
36 | #elif defined(CONFIG_X86_64) | |
37 | const char afs_init_sysname[] = "amd64_linux26"; | |
38 | #elif defined(CONFIG_ARM) | |
39 | const char afs_init_sysname[] = "arm_linux26"; | |
40 | #elif defined(CONFIG_ARM64) | |
41 | const char afs_init_sysname[] = "aarch64_linux26"; | |
42 | #elif defined(CONFIG_X86_32) | |
43 | const char afs_init_sysname[] = "i386_linux26"; | |
44 | #elif defined(CONFIG_IA64) | |
45 | const char afs_init_sysname[] = "ia64_linux26"; | |
46 | #elif defined(CONFIG_PPC64) | |
47 | const char afs_init_sysname[] = "ppc64_linux26"; | |
48 | #elif defined(CONFIG_PPC32) | |
49 | const char afs_init_sysname[] = "ppc_linux26"; | |
50 | #elif defined(CONFIG_S390) | |
51 | #ifdef CONFIG_64BIT | |
52 | const char afs_init_sysname[] = "s390x_linux26"; | |
53 | #else | |
54 | const char afs_init_sysname[] = "s390_linux26"; | |
55 | #endif | |
56 | #elif defined(CONFIG_SPARC64) | |
57 | const char afs_init_sysname[] = "sparc64_linux26"; | |
58 | #elif defined(CONFIG_SPARC32) | |
59 | const char afs_init_sysname[] = "sparc_linux26"; | |
60 | #else | |
61 | const char afs_init_sysname[] = "unknown_linux26"; | |
62 | #endif | |
63 | ||
f044c884 DH |
64 | /* |
65 | * Initialise an AFS network namespace record. | |
66 | */ | |
5b86d4ff | 67 | static int __net_init afs_net_init(struct net *net_ns) |
f044c884 | 68 | { |
6f8880d8 | 69 | struct afs_sysnames *sysnames; |
5b86d4ff | 70 | struct afs_net *net = afs_net(net_ns); |
f044c884 DH |
71 | int ret; |
72 | ||
5b86d4ff | 73 | net->net = net_ns; |
f044c884 DH |
74 | net->live = true; |
75 | generate_random_uuid((unsigned char *)&net->uuid); | |
76 | ||
77 | INIT_WORK(&net->charge_preallocation_work, afs_charge_preallocation); | |
78 | mutex_init(&net->socket_mutex); | |
989782dc DH |
79 | |
80 | net->cells = RB_ROOT; | |
81 | seqlock_init(&net->cells_lock); | |
82 | INIT_WORK(&net->cells_manager, afs_manage_cells); | |
83 | timer_setup(&net->cells_timer, afs_cells_timer, 0); | |
84 | ||
0da0b7fd | 85 | mutex_init(&net->proc_cells_lock); |
6b3944e4 | 86 | INIT_HLIST_HEAD(&net->proc_cells); |
989782dc | 87 | |
d2ddc776 DH |
88 | seqlock_init(&net->fs_lock); |
89 | net->fs_servers = RB_ROOT; | |
90 | INIT_LIST_HEAD(&net->fs_updates); | |
91 | INIT_HLIST_HEAD(&net->fs_proc); | |
92 | ||
93 | INIT_HLIST_HEAD(&net->fs_addresses4); | |
94 | INIT_HLIST_HEAD(&net->fs_addresses6); | |
95 | seqlock_init(&net->fs_addr_lock); | |
96 | ||
97 | INIT_WORK(&net->fs_manager, afs_manage_servers); | |
98 | timer_setup(&net->fs_timer, afs_servers_timer, 0); | |
f044c884 | 99 | |
6f8880d8 DH |
100 | ret = -ENOMEM; |
101 | sysnames = kzalloc(sizeof(*sysnames), GFP_KERNEL); | |
102 | if (!sysnames) | |
103 | goto error_sysnames; | |
104 | sysnames->subs[0] = (char *)&afs_init_sysname; | |
105 | sysnames->nr = 1; | |
106 | refcount_set(&sysnames->usage, 1); | |
107 | net->sysnames = sysnames; | |
108 | rwlock_init(&net->sysnames_lock); | |
109 | ||
f044c884 DH |
110 | /* Register the /proc stuff */ |
111 | ret = afs_proc_init(net); | |
112 | if (ret < 0) | |
113 | goto error_proc; | |
114 | ||
115 | /* Initialise the cell DB */ | |
116 | ret = afs_cell_init(net, rootcell); | |
117 | if (ret < 0) | |
118 | goto error_cell_init; | |
119 | ||
120 | /* Create the RxRPC transport */ | |
121 | ret = afs_open_socket(net); | |
122 | if (ret < 0) | |
123 | goto error_open_socket; | |
124 | ||
125 | return 0; | |
126 | ||
127 | error_open_socket: | |
989782dc | 128 | net->live = false; |
f044c884 | 129 | afs_cell_purge(net); |
d2ddc776 | 130 | afs_purge_servers(net); |
f044c884 | 131 | error_cell_init: |
989782dc | 132 | net->live = false; |
f044c884 DH |
133 | afs_proc_cleanup(net); |
134 | error_proc: | |
6f8880d8 DH |
135 | afs_put_sysnames(net->sysnames); |
136 | error_sysnames: | |
989782dc | 137 | net->live = false; |
f044c884 DH |
138 | return ret; |
139 | } | |
140 | ||
141 | /* | |
142 | * Clean up and destroy an AFS network namespace record. | |
143 | */ | |
5b86d4ff | 144 | static void __net_exit afs_net_exit(struct net *net_ns) |
f044c884 | 145 | { |
5b86d4ff DH |
146 | struct afs_net *net = afs_net(net_ns); |
147 | ||
f044c884 | 148 | net->live = false; |
f044c884 | 149 | afs_cell_purge(net); |
d2ddc776 | 150 | afs_purge_servers(net); |
e3b2ffe0 | 151 | afs_close_socket(net); |
f044c884 | 152 | afs_proc_cleanup(net); |
6f8880d8 | 153 | afs_put_sysnames(net->sysnames); |
f044c884 | 154 | } |
b908fe6b | 155 | |
5b86d4ff DH |
156 | static struct pernet_operations afs_net_ops = { |
157 | .init = afs_net_init, | |
158 | .exit = afs_net_exit, | |
159 | .id = &afs_net_id, | |
160 | .size = sizeof(struct afs_net), | |
161 | }; | |
162 | ||
1da177e4 LT |
163 | /* |
164 | * initialise the AFS client FS module | |
165 | */ | |
166 | static int __init afs_init(void) | |
167 | { | |
f044c884 | 168 | int ret = -ENOMEM; |
1da177e4 LT |
169 | |
170 | printk(KERN_INFO "kAFS: Red Hat AFS client v0.1 registering.\n"); | |
171 | ||
0ad53eee TH |
172 | afs_wq = alloc_workqueue("afs", 0, 0); |
173 | if (!afs_wq) | |
f044c884 DH |
174 | goto error_afs_wq; |
175 | afs_async_calls = alloc_workqueue("kafsd", WQ_MEM_RECLAIM, 0); | |
176 | if (!afs_async_calls) | |
177 | goto error_async; | |
f044c884 DH |
178 | afs_lock_manager = alloc_workqueue("kafs_lockd", WQ_MEM_RECLAIM, 0); |
179 | if (!afs_lock_manager) | |
180 | goto error_lockmgr; | |
1da177e4 | 181 | |
9b3f26c9 | 182 | #ifdef CONFIG_AFS_FSCACHE |
1da177e4 | 183 | /* we want to be able to cache */ |
9b3f26c9 | 184 | ret = fscache_register_netfs(&afs_cache_netfs); |
1da177e4 LT |
185 | if (ret < 0) |
186 | goto error_cache; | |
187 | #endif | |
188 | ||
5b86d4ff | 189 | ret = register_pernet_subsys(&afs_net_ops); |
df44f9f4 | 190 | if (ret < 0) |
f044c884 | 191 | goto error_net; |
1da177e4 LT |
192 | |
193 | /* register the filesystems */ | |
194 | ret = afs_fs_init(); | |
195 | if (ret < 0) | |
ec26815a | 196 | goto error_fs; |
1da177e4 | 197 | |
5b86d4ff DH |
198 | afs_proc_symlink = proc_symlink("fs/afs", NULL, "../self/net/afs"); |
199 | if (IS_ERR(afs_proc_symlink)) { | |
200 | ret = PTR_ERR(afs_proc_symlink); | |
201 | goto error_proc; | |
202 | } | |
203 | ||
1da177e4 LT |
204 | return ret; |
205 | ||
5b86d4ff DH |
206 | error_proc: |
207 | afs_fs_exit(); | |
ec26815a | 208 | error_fs: |
5b86d4ff | 209 | unregister_pernet_subsys(&afs_net_ops); |
f044c884 | 210 | error_net: |
9b3f26c9 DH |
211 | #ifdef CONFIG_AFS_FSCACHE |
212 | fscache_unregister_netfs(&afs_cache_netfs); | |
ec26815a | 213 | error_cache: |
1da177e4 | 214 | #endif |
f044c884 DH |
215 | destroy_workqueue(afs_lock_manager); |
216 | error_lockmgr: | |
f044c884 DH |
217 | destroy_workqueue(afs_async_calls); |
218 | error_async: | |
0ad53eee | 219 | destroy_workqueue(afs_wq); |
f044c884 | 220 | error_afs_wq: |
416351f2 | 221 | rcu_barrier(); |
1da177e4 LT |
222 | printk(KERN_ERR "kAFS: failed to register: %d\n", ret); |
223 | return ret; | |
ec26815a | 224 | } |
1da177e4 LT |
225 | |
226 | /* XXX late_initcall is kludgy, but the only alternative seems to create | |
227 | * a transport upon the first mount, which is worse. Or is it? | |
228 | */ | |
229 | late_initcall(afs_init); /* must be called after net/ to create socket */ | |
ec26815a | 230 | |
1da177e4 LT |
231 | /* |
232 | * clean up on module removal | |
233 | */ | |
234 | static void __exit afs_exit(void) | |
235 | { | |
236 | printk(KERN_INFO "kAFS: Red Hat AFS client v0.1 unregistering.\n"); | |
237 | ||
5b86d4ff | 238 | proc_remove(afs_proc_symlink); |
1da177e4 | 239 | afs_fs_exit(); |
5b86d4ff | 240 | unregister_pernet_subsys(&afs_net_ops); |
9b3f26c9 DH |
241 | #ifdef CONFIG_AFS_FSCACHE |
242 | fscache_unregister_netfs(&afs_cache_netfs); | |
1da177e4 | 243 | #endif |
f044c884 | 244 | destroy_workqueue(afs_lock_manager); |
f044c884 DH |
245 | destroy_workqueue(afs_async_calls); |
246 | destroy_workqueue(afs_wq); | |
be080a6f | 247 | afs_clean_up_permit_cache(); |
416351f2 | 248 | rcu_barrier(); |
ec26815a | 249 | } |
1da177e4 LT |
250 | |
251 | module_exit(afs_exit); |