1 // SPDX-License-Identifier: GPL-2.0-or-later
2 /* AFS client file system
4 * Copyright (C) 2002,5 Red Hat, Inc. All Rights Reserved.
5 * Written by David Howells (dhowells@redhat.com)
8 #include <linux/module.h>
9 #include <linux/moduleparam.h>
10 #include <linux/init.h>
11 #include <linux/completion.h>
12 #include <linux/sched.h>
13 #include <linux/random.h>
14 #include <linux/proc_fs.h>
15 #define CREATE_TRACE_POINTS
18 MODULE_DESCRIPTION("AFS Client File System");
19 MODULE_AUTHOR("Red Hat, Inc.");
20 MODULE_LICENSE("GPL");
23 module_param_named(debug
, afs_debug
, uint
, S_IWUSR
| S_IRUGO
);
24 MODULE_PARM_DESC(debug
, "AFS debugging mask");
26 static char *rootcell
;
28 module_param(rootcell
, charp
, 0);
29 MODULE_PARM_DESC(rootcell
, "root AFS cell name and VL server IP addr list");
31 struct workqueue_struct
*afs_wq
;
32 static struct proc_dir_entry
*afs_proc_symlink
;
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_PPC64)
45 const char afs_init_sysname
[] = "ppc64_linux26";
46 #elif defined(CONFIG_PPC32)
47 const char afs_init_sysname
[] = "ppc_linux26";
48 #elif defined(CONFIG_S390)
50 const char afs_init_sysname
[] = "s390x_linux26";
52 const char afs_init_sysname
[] = "s390_linux26";
54 #elif defined(CONFIG_SPARC64)
55 const char afs_init_sysname
[] = "sparc64_linux26";
56 #elif defined(CONFIG_SPARC32)
57 const char afs_init_sysname
[] = "sparc_linux26";
59 const char afs_init_sysname
[] = "unknown_linux26";
63 * Initialise an AFS network namespace record.
65 static int __net_init
afs_net_init(struct net
*net_ns
)
67 struct afs_sysnames
*sysnames
;
68 struct afs_net
*net
= afs_net(net_ns
);
73 generate_random_uuid((unsigned char *)&net
->uuid
);
75 INIT_WORK(&net
->charge_preallocation_work
, afs_charge_preallocation
);
76 mutex_init(&net
->socket_mutex
);
79 init_rwsem(&net
->cells_lock
);
80 INIT_WORK(&net
->cells_manager
, afs_manage_cells
);
81 timer_setup(&net
->cells_timer
, afs_cells_timer
, 0);
83 mutex_init(&net
->cells_alias_lock
);
84 mutex_init(&net
->proc_cells_lock
);
85 INIT_HLIST_HEAD(&net
->proc_cells
);
87 seqlock_init(&net
->fs_lock
);
88 net
->fs_servers
= RB_ROOT
;
89 INIT_LIST_HEAD(&net
->fs_probe_fast
);
90 INIT_LIST_HEAD(&net
->fs_probe_slow
);
91 INIT_HLIST_HEAD(&net
->fs_proc
);
93 INIT_HLIST_HEAD(&net
->fs_addresses
);
94 seqlock_init(&net
->fs_addr_lock
);
96 INIT_WORK(&net
->fs_manager
, afs_manage_servers
);
97 timer_setup(&net
->fs_timer
, afs_servers_timer
, 0);
98 INIT_WORK(&net
->fs_prober
, afs_fs_probe_dispatcher
);
99 timer_setup(&net
->fs_probe_timer
, afs_fs_probe_timer
, 0);
100 atomic_set(&net
->servers_outstanding
, 1);
103 sysnames
= kzalloc(sizeof(*sysnames
), GFP_KERNEL
);
106 sysnames
->subs
[0] = (char *)&afs_init_sysname
;
108 refcount_set(&sysnames
->usage
, 1);
109 net
->sysnames
= sysnames
;
110 rwlock_init(&net
->sysnames_lock
);
112 /* Register the /proc stuff */
113 ret
= afs_proc_init(net
);
117 /* Initialise the cell DB */
118 ret
= afs_cell_init(net
, rootcell
);
120 goto error_cell_init
;
122 /* Create the RxRPC transport */
123 ret
= afs_open_socket(net
);
125 goto error_open_socket
;
131 afs_fs_probe_cleanup(net
);
133 afs_purge_servers(net
);
136 afs_proc_cleanup(net
);
138 afs_put_sysnames(net
->sysnames
);
145 * Clean up and destroy an AFS network namespace record.
147 static void __net_exit
afs_net_exit(struct net
*net_ns
)
149 struct afs_net
*net
= afs_net(net_ns
);
152 afs_fs_probe_cleanup(net
);
154 afs_purge_servers(net
);
155 afs_close_socket(net
);
156 afs_proc_cleanup(net
);
157 afs_put_sysnames(net
->sysnames
);
158 kfree_rcu(rcu_access_pointer(net
->address_prefs
), rcu
);
161 static struct pernet_operations afs_net_ops
= {
162 .init
= afs_net_init
,
163 .exit
= afs_net_exit
,
165 .size
= sizeof(struct afs_net
),
169 * initialise the AFS client FS module
171 static int __init
afs_init(void)
175 printk(KERN_INFO
"kAFS: Red Hat AFS client v0.1 registering.\n");
177 afs_wq
= alloc_workqueue("afs", 0, 0);
180 afs_async_calls
= alloc_workqueue("kafsd", WQ_MEM_RECLAIM
, 0);
181 if (!afs_async_calls
)
183 afs_lock_manager
= alloc_workqueue("kafs_lockd", WQ_MEM_RECLAIM
, 0);
184 if (!afs_lock_manager
)
187 ret
= register_pernet_device(&afs_net_ops
);
191 /* register the filesystems */
196 afs_proc_symlink
= proc_symlink("fs/afs", NULL
, "../self/net/afs");
197 if (!afs_proc_symlink
) {
207 unregister_pernet_device(&afs_net_ops
);
209 destroy_workqueue(afs_lock_manager
);
211 destroy_workqueue(afs_async_calls
);
213 destroy_workqueue(afs_wq
);
216 printk(KERN_ERR
"kAFS: failed to register: %d\n", ret
);
220 /* XXX late_initcall is kludgy, but the only alternative seems to create
221 * a transport upon the first mount, which is worse. Or is it?
223 late_initcall(afs_init
); /* must be called after net/ to create socket */
226 * clean up on module removal
228 static void __exit
afs_exit(void)
230 printk(KERN_INFO
"kAFS: Red Hat AFS client v0.1 unregistering.\n");
232 proc_remove(afs_proc_symlink
);
234 unregister_pernet_device(&afs_net_ops
);
235 destroy_workqueue(afs_lock_manager
);
236 destroy_workqueue(afs_async_calls
);
237 destroy_workqueue(afs_wq
);
238 afs_clean_up_permit_cache();
242 module_exit(afs_exit
);