Linux Audio

Check our new training course

Loading...
v6.13.7
  1// SPDX-License-Identifier: GPL-2.0-or-later
  2/* AFS client file system
  3 *
  4 * Copyright (C) 2002,5 Red Hat, Inc. All Rights Reserved.
  5 * Written by David Howells (dhowells@redhat.com)
 
 
 
 
 
  6 */
  7
  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
 16#include "internal.h"
 17
 18MODULE_DESCRIPTION("AFS Client File System");
 19MODULE_AUTHOR("Red Hat, Inc.");
 20MODULE_LICENSE("GPL");
 21
 22unsigned afs_debug;
 23module_param_named(debug, afs_debug, uint, S_IWUSR | S_IRUGO);
 24MODULE_PARM_DESC(debug, "AFS debugging mask");
 25
 26static char *rootcell;
 27
 28module_param(rootcell, charp, 0);
 29MODULE_PARM_DESC(rootcell, "root AFS cell name and VL server IP addr list");
 30
 
 31struct workqueue_struct *afs_wq;
 32static struct proc_dir_entry *afs_proc_symlink;
 33
 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";
 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
 62/*
 63 * Initialise an AFS network namespace record.
 64 */
 65static int __net_init afs_net_init(struct net *net_ns)
 66{
 67	struct afs_sysnames *sysnames;
 68	struct afs_net *net = afs_net(net_ns);
 
 69	int ret;
 70
 71	net->net = net_ns;
 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);
 77
 78	net->cells = RB_ROOT;
 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);
 82
 83	mutex_init(&net->cells_alias_lock);
 84	mutex_init(&net->proc_cells_lock);
 85	INIT_HLIST_HEAD(&net->proc_cells);
 86
 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);
 92
 93	INIT_HLIST_HEAD(&net->fs_addresses);
 94	seqlock_init(&net->fs_addr_lock);
 95
 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);
101
102	ret = -ENOMEM;
103	sysnames = kzalloc(sizeof(*sysnames), GFP_KERNEL);
104	if (!sysnames)
105		goto error_sysnames;
106	sysnames->subs[0] = (char *)&afs_init_sysname;
107	sysnames->nr = 1;
108	refcount_set(&sysnames->usage, 1);
109	net->sysnames = sysnames;
110	rwlock_init(&net->sysnames_lock);
111
112	/* Register the /proc stuff */
113	ret = afs_proc_init(net);
114	if (ret < 0)
115		goto error_proc;
116
117	/* Initialise the cell DB */
118	ret = afs_cell_init(net, rootcell);
119	if (ret < 0)
120		goto error_cell_init;
121
122	/* Create the RxRPC transport */
123	ret = afs_open_socket(net);
124	if (ret < 0)
125		goto error_open_socket;
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
126
127	return 0;
128
129error_open_socket:
130	net->live = false;
131	afs_fs_probe_cleanup(net);
132	afs_cell_purge(net);
133	afs_purge_servers(net);
134error_cell_init:
135	net->live = false;
136	afs_proc_cleanup(net);
137error_proc:
138	afs_put_sysnames(net->sysnames);
139error_sysnames:
140	net->live = false;
141	return ret;
142}
143
144/*
145 * Clean up and destroy an AFS network namespace record.
146 */
147static void __net_exit afs_net_exit(struct net *net_ns)
148{
149	struct afs_net *net = afs_net(net_ns);
150
151	net->live = false;
152	afs_fs_probe_cleanup(net);
153	afs_cell_purge(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);
159}
160
161static struct pernet_operations afs_net_ops = {
162	.init	= afs_net_init,
163	.exit	= afs_net_exit,
164	.id	= &afs_net_id,
165	.size	= sizeof(struct afs_net),
166};
167
168/*
169 * initialise the AFS client FS module
170 */
171static int __init afs_init(void)
172{
173	int ret = -ENOMEM;
174
175	printk(KERN_INFO "kAFS: Red Hat AFS client v0.1 registering.\n");
176
 
 
 
 
 
 
177	afs_wq = alloc_workqueue("afs", 0, 0);
178	if (!afs_wq)
179		goto error_afs_wq;
180	afs_async_calls = alloc_workqueue("kafsd", WQ_MEM_RECLAIM, 0);
181	if (!afs_async_calls)
182		goto error_async;
183	afs_lock_manager = alloc_workqueue("kafs_lockd", WQ_MEM_RECLAIM, 0);
184	if (!afs_lock_manager)
185		goto error_lockmgr;
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
186
187	ret = register_pernet_device(&afs_net_ops);
 
188	if (ret < 0)
189		goto error_net;
190
191	/* register the filesystems */
192	ret = afs_fs_init();
193	if (ret < 0)
194		goto error_fs;
195
196	afs_proc_symlink = proc_symlink("fs/afs", NULL, "../self/net/afs");
197	if (!afs_proc_symlink) {
198		ret = -ENOMEM;
199		goto error_proc;
200	}
201
202	return ret;
203
204error_proc:
205	afs_fs_exit();
206error_fs:
207	unregister_pernet_device(&afs_net_ops);
208error_net:
209	destroy_workqueue(afs_lock_manager);
210error_lockmgr:
211	destroy_workqueue(afs_async_calls);
212error_async:
 
 
 
 
 
 
 
 
213	destroy_workqueue(afs_wq);
214error_afs_wq:
215	rcu_barrier();
216	printk(KERN_ERR "kAFS: failed to register: %d\n", ret);
217	return ret;
218}
219
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?
222 */
223late_initcall(afs_init);	/* must be called after net/ to create socket */
224
225/*
226 * clean up on module removal
227 */
228static void __exit afs_exit(void)
229{
230	printk(KERN_INFO "kAFS: Red Hat AFS client v0.1 unregistering.\n");
231
232	proc_remove(afs_proc_symlink);
233	afs_fs_exit();
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();
 
 
 
 
239	rcu_barrier();
240}
241
242module_exit(afs_exit);
v4.10.11
 
  1/* AFS client file system
  2 *
  3 * Copyright (C) 2002,5 Red Hat, Inc. All Rights Reserved.
  4 * Written by David Howells (dhowells@redhat.com)
  5 *
  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.
 10 */
 11
 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 "internal.h"
 19
 20MODULE_DESCRIPTION("AFS Client File System");
 21MODULE_AUTHOR("Red Hat, Inc.");
 22MODULE_LICENSE("GPL");
 23
 24unsigned afs_debug;
 25module_param_named(debug, afs_debug, uint, S_IWUSR | S_IRUGO);
 26MODULE_PARM_DESC(debug, "AFS debugging mask");
 27
 28static char *rootcell;
 29
 30module_param(rootcell, charp, 0);
 31MODULE_PARM_DESC(rootcell, "root AFS cell name and VL server IP addr list");
 32
 33struct afs_uuid afs_uuid;
 34struct workqueue_struct *afs_wq;
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 35
 36/*
 37 * get a client UUID
 38 */
 39static int __init afs_get_client_UUID(void)
 40{
 41	struct timespec ts;
 42	u64 uuidtime;
 43	u16 clockseq;
 44	int ret;
 45
 46	/* read the MAC address of one of the external interfaces and construct
 47	 * a UUID from it */
 48	ret = afs_get_MAC_address(afs_uuid.node, sizeof(afs_uuid.node));
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 49	if (ret < 0)
 50		return ret;
 
 
 
 
 
 51
 52	getnstimeofday(&ts);
 53	uuidtime = (u64) ts.tv_sec * 1000 * 1000 * 10;
 54	uuidtime += ts.tv_nsec / 100;
 55	uuidtime += AFS_UUID_TO_UNIX_TIME;
 56	afs_uuid.time_low = uuidtime;
 57	afs_uuid.time_mid = uuidtime >> 32;
 58	afs_uuid.time_hi_and_version = (uuidtime >> 48) & AFS_UUID_TIMEHI_MASK;
 59	afs_uuid.time_hi_and_version |= AFS_UUID_VERSION_TIME;
 60
 61	get_random_bytes(&clockseq, 2);
 62	afs_uuid.clock_seq_low = clockseq;
 63	afs_uuid.clock_seq_hi_and_reserved =
 64		(clockseq >> 8) & AFS_UUID_CLOCKHI_MASK;
 65	afs_uuid.clock_seq_hi_and_reserved |= AFS_UUID_VARIANT_STD;
 66
 67	_debug("AFS UUID: %08x-%04x-%04x-%02x%02x-%02x%02x%02x%02x%02x%02x",
 68	       afs_uuid.time_low,
 69	       afs_uuid.time_mid,
 70	       afs_uuid.time_hi_and_version,
 71	       afs_uuid.clock_seq_hi_and_reserved,
 72	       afs_uuid.clock_seq_low,
 73	       afs_uuid.node[0], afs_uuid.node[1], afs_uuid.node[2],
 74	       afs_uuid.node[3], afs_uuid.node[4], afs_uuid.node[5]);
 75
 76	return 0;
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 77}
 78
 79/*
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 80 * initialise the AFS client FS module
 81 */
 82static int __init afs_init(void)
 83{
 84	int ret;
 85
 86	printk(KERN_INFO "kAFS: Red Hat AFS client v0.1 registering.\n");
 87
 88	ret = afs_get_client_UUID();
 89	if (ret < 0)
 90		return ret;
 91
 92	/* create workqueue */
 93	ret = -ENOMEM;
 94	afs_wq = alloc_workqueue("afs", 0, 0);
 95	if (!afs_wq)
 96		return ret;
 97
 98	/* register the /proc stuff */
 99	ret = afs_proc_init();
100	if (ret < 0)
101		goto error_proc;
102
103#ifdef CONFIG_AFS_FSCACHE
104	/* we want to be able to cache */
105	ret = fscache_register_netfs(&afs_cache_netfs);
106	if (ret < 0)
107		goto error_cache;
108#endif
109
110	/* initialise the cell DB */
111	ret = afs_cell_init(rootcell);
112	if (ret < 0)
113		goto error_cell_init;
114
115	/* initialise the VL update process */
116	ret = afs_vlocation_update_init();
117	if (ret < 0)
118		goto error_vl_update_init;
119
120	/* initialise the callback update process */
121	ret = afs_callback_update_init();
122	if (ret < 0)
123		goto error_callback_update_init;
124
125	/* create the RxRPC transport */
126	ret = afs_open_socket();
127	if (ret < 0)
128		goto error_open_socket;
129
130	/* register the filesystems */
131	ret = afs_fs_init();
132	if (ret < 0)
133		goto error_fs;
134
 
 
 
 
 
 
135	return ret;
136
 
 
137error_fs:
138	afs_close_socket();
139error_open_socket:
140	afs_callback_update_kill();
141error_callback_update_init:
142	afs_vlocation_purge();
143error_vl_update_init:
144	afs_cell_purge();
145error_cell_init:
146#ifdef CONFIG_AFS_FSCACHE
147	fscache_unregister_netfs(&afs_cache_netfs);
148error_cache:
149#endif
150	afs_proc_cleanup();
151error_proc:
152	destroy_workqueue(afs_wq);
 
153	rcu_barrier();
154	printk(KERN_ERR "kAFS: failed to register: %d\n", ret);
155	return ret;
156}
157
158/* XXX late_initcall is kludgy, but the only alternative seems to create
159 * a transport upon the first mount, which is worse. Or is it?
160 */
161late_initcall(afs_init);	/* must be called after net/ to create socket */
162
163/*
164 * clean up on module removal
165 */
166static void __exit afs_exit(void)
167{
168	printk(KERN_INFO "kAFS: Red Hat AFS client v0.1 unregistering.\n");
169
 
170	afs_fs_exit();
171	afs_kill_lock_manager();
172	afs_close_socket();
173	afs_purge_servers();
174	afs_callback_update_kill();
175	afs_vlocation_purge();
176	destroy_workqueue(afs_wq);
177	afs_cell_purge();
178#ifdef CONFIG_AFS_FSCACHE
179	fscache_unregister_netfs(&afs_cache_netfs);
180#endif
181	afs_proc_cleanup();
182	rcu_barrier();
183}
184
185module_exit(afs_exit);