smb: client: get rid of smb311_posix_query_path_info()
[linux-2.6-block.git] / fs / afs / main.c
CommitLineData
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
18MODULE_DESCRIPTION("AFS Client File System");
19MODULE_AUTHOR("Red Hat, Inc.");
20MODULE_LICENSE("GPL");
21
08e0e7c8
DH
22unsigned afs_debug;
23module_param_named(debug, afs_debug, uint, S_IWUSR | S_IRUGO);
424b00e2 24MODULE_PARM_DESC(debug, "AFS debugging mask");
08e0e7c8 25
1da177e4
LT
26static char *rootcell;
27
28module_param(rootcell, charp, 0);
29MODULE_PARM_DESC(rootcell, "root AFS cell name and VL server IP addr list");
30
0ad53eee 31struct workqueue_struct *afs_wq;
5b86d4ff 32static struct proc_dir_entry *afs_proc_symlink;
f044c884 33
6f8880d8
DH
34#if defined(CONFIG_ALPHA)
35const char afs_init_sysname[] = "alpha_linux26";
36#elif defined(CONFIG_X86_64)
37const char afs_init_sysname[] = "amd64_linux26";
38#elif defined(CONFIG_ARM)
39const char afs_init_sysname[] = "arm_linux26";
40#elif defined(CONFIG_ARM64)
41const char afs_init_sysname[] = "aarch64_linux26";
42#elif defined(CONFIG_X86_32)
43const char afs_init_sysname[] = "i386_linux26";
6f8880d8
DH
44#elif defined(CONFIG_PPC64)
45const char afs_init_sysname[] = "ppc64_linux26";
46#elif defined(CONFIG_PPC32)
47const char afs_init_sysname[] = "ppc_linux26";
48#elif defined(CONFIG_S390)
49#ifdef CONFIG_64BIT
50const char afs_init_sysname[] = "s390x_linux26";
51#else
52const char afs_init_sysname[] = "s390_linux26";
53#endif
54#elif defined(CONFIG_SPARC64)
55const char afs_init_sysname[] = "sparc64_linux26";
56#elif defined(CONFIG_SPARC32)
57const char afs_init_sysname[] = "sparc_linux26";
58#else
59const char afs_init_sysname[] = "unknown_linux26";
60#endif
61
f044c884
DH
62/*
63 * Initialise an AFS network namespace record.
64 */
5b86d4ff 65static int __net_init afs_net_init(struct net *net_ns)
f044c884 66{
6f8880d8 67 struct afs_sysnames *sysnames;
5b86d4ff 68 struct afs_net *net = afs_net(net_ns);
f044c884
DH
69 int ret;
70
5b86d4ff 71 net->net = net_ns;
f044c884
DH
72 net->live = true;
73 generate_random_uuid((unsigned char *)&net->uuid);
74
75 INIT_WORK(&net->charge_preallocation_work, afs_charge_preallocation);
76 mutex_init(&net->socket_mutex);
989782dc
DH
77
78 net->cells = RB_ROOT;
92e3cc91 79 init_rwsem(&net->cells_lock);
989782dc
DH
80 INIT_WORK(&net->cells_manager, afs_manage_cells);
81 timer_setup(&net->cells_timer, afs_cells_timer, 0);
82
8a070a96 83 mutex_init(&net->cells_alias_lock);
0da0b7fd 84 mutex_init(&net->proc_cells_lock);
6b3944e4 85 INIT_HLIST_HEAD(&net->proc_cells);
989782dc 86
d2ddc776
DH
87 seqlock_init(&net->fs_lock);
88 net->fs_servers = RB_ROOT;
f6cbb368
DH
89 INIT_LIST_HEAD(&net->fs_probe_fast);
90 INIT_LIST_HEAD(&net->fs_probe_slow);
d2ddc776
DH
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);
f6cbb368
DH
99 INIT_WORK(&net->fs_prober, afs_fs_probe_dispatcher);
100 timer_setup(&net->fs_probe_timer, afs_fs_probe_timer, 0);
5481fc6e 101 atomic_set(&net->servers_outstanding, 1);
f044c884 102
6f8880d8
DH
103 ret = -ENOMEM;
104 sysnames = kzalloc(sizeof(*sysnames), GFP_KERNEL);
105 if (!sysnames)
106 goto error_sysnames;
107 sysnames->subs[0] = (char *)&afs_init_sysname;
108 sysnames->nr = 1;
109 refcount_set(&sysnames->usage, 1);
110 net->sysnames = sysnames;
111 rwlock_init(&net->sysnames_lock);
112
f044c884
DH
113 /* Register the /proc stuff */
114 ret = afs_proc_init(net);
115 if (ret < 0)
116 goto error_proc;
117
118 /* Initialise the cell DB */
119 ret = afs_cell_init(net, rootcell);
120 if (ret < 0)
121 goto error_cell_init;
122
123 /* Create the RxRPC transport */
124 ret = afs_open_socket(net);
125 if (ret < 0)
126 goto error_open_socket;
127
128 return 0;
129
130error_open_socket:
989782dc 131 net->live = false;
5481fc6e 132 afs_fs_probe_cleanup(net);
f044c884 133 afs_cell_purge(net);
d2ddc776 134 afs_purge_servers(net);
f044c884 135error_cell_init:
989782dc 136 net->live = false;
f044c884
DH
137 afs_proc_cleanup(net);
138error_proc:
6f8880d8
DH
139 afs_put_sysnames(net->sysnames);
140error_sysnames:
989782dc 141 net->live = false;
f044c884
DH
142 return ret;
143}
144
145/*
146 * Clean up and destroy an AFS network namespace record.
147 */
5b86d4ff 148static void __net_exit afs_net_exit(struct net *net_ns)
f044c884 149{
5b86d4ff
DH
150 struct afs_net *net = afs_net(net_ns);
151
f044c884 152 net->live = false;
5481fc6e 153 afs_fs_probe_cleanup(net);
f044c884 154 afs_cell_purge(net);
d2ddc776 155 afs_purge_servers(net);
e3b2ffe0 156 afs_close_socket(net);
f044c884 157 afs_proc_cleanup(net);
6f8880d8 158 afs_put_sysnames(net->sysnames);
f94f70d3 159 kfree_rcu(rcu_access_pointer(net->address_prefs), rcu);
f044c884 160}
b908fe6b 161
5b86d4ff
DH
162static struct pernet_operations afs_net_ops = {
163 .init = afs_net_init,
164 .exit = afs_net_exit,
165 .id = &afs_net_id,
166 .size = sizeof(struct afs_net),
167};
168
1da177e4
LT
169/*
170 * initialise the AFS client FS module
171 */
172static int __init afs_init(void)
173{
f044c884 174 int ret = -ENOMEM;
1da177e4
LT
175
176 printk(KERN_INFO "kAFS: Red Hat AFS client v0.1 registering.\n");
177
0ad53eee
TH
178 afs_wq = alloc_workqueue("afs", 0, 0);
179 if (!afs_wq)
f044c884
DH
180 goto error_afs_wq;
181 afs_async_calls = alloc_workqueue("kafsd", WQ_MEM_RECLAIM, 0);
182 if (!afs_async_calls)
183 goto error_async;
f044c884
DH
184 afs_lock_manager = alloc_workqueue("kafs_lockd", WQ_MEM_RECLAIM, 0);
185 if (!afs_lock_manager)
186 goto error_lockmgr;
1da177e4 187
5399d522 188 ret = register_pernet_device(&afs_net_ops);
df44f9f4 189 if (ret < 0)
f044c884 190 goto error_net;
1da177e4
LT
191
192 /* register the filesystems */
193 ret = afs_fs_init();
194 if (ret < 0)
ec26815a 195 goto error_fs;
1da177e4 196
5b86d4ff 197 afs_proc_symlink = proc_symlink("fs/afs", NULL, "../self/net/afs");
a33d6266
DC
198 if (!afs_proc_symlink) {
199 ret = -ENOMEM;
5b86d4ff
DH
200 goto error_proc;
201 }
202
1da177e4
LT
203 return ret;
204
5b86d4ff
DH
205error_proc:
206 afs_fs_exit();
ec26815a 207error_fs:
5399d522 208 unregister_pernet_device(&afs_net_ops);
f044c884 209error_net:
f044c884
DH
210 destroy_workqueue(afs_lock_manager);
211error_lockmgr:
f044c884
DH
212 destroy_workqueue(afs_async_calls);
213error_async:
0ad53eee 214 destroy_workqueue(afs_wq);
f044c884 215error_afs_wq:
416351f2 216 rcu_barrier();
1da177e4
LT
217 printk(KERN_ERR "kAFS: failed to register: %d\n", ret);
218 return ret;
ec26815a 219}
1da177e4
LT
220
221/* XXX late_initcall is kludgy, but the only alternative seems to create
222 * a transport upon the first mount, which is worse. Or is it?
223 */
224late_initcall(afs_init); /* must be called after net/ to create socket */
ec26815a 225
1da177e4
LT
226/*
227 * clean up on module removal
228 */
229static void __exit afs_exit(void)
230{
231 printk(KERN_INFO "kAFS: Red Hat AFS client v0.1 unregistering.\n");
232
5b86d4ff 233 proc_remove(afs_proc_symlink);
1da177e4 234 afs_fs_exit();
5399d522 235 unregister_pernet_device(&afs_net_ops);
f044c884 236 destroy_workqueue(afs_lock_manager);
f044c884
DH
237 destroy_workqueue(afs_async_calls);
238 destroy_workqueue(afs_wq);
be080a6f 239 afs_clean_up_permit_cache();
416351f2 240 rcu_barrier();
ec26815a 241}
1da177e4
LT
242
243module_exit(afs_exit);