main.c 3.2 KB
Newer Older
D
David Howells 已提交
1
/* AFS client file system
L
Linus Torvalds 已提交
2
 *
D
David Howells 已提交
3
 * Copyright (C) 2002,5 Red Hat, Inc. All Rights Reserved.
L
Linus Torvalds 已提交
4 5 6 7 8 9 10 11 12 13 14 15
 * Written by David Howells (dhowells@redhat.com)
 *
 * This program is free software; you can redistribute it and/or
 * modify it under the terms of the GNU General Public License
 * as published by the Free Software Foundation; either version
 * 2 of the License, or (at your option) any later version.
 */

#include <linux/module.h>
#include <linux/moduleparam.h>
#include <linux/init.h>
#include <linux/completion.h>
A
Alexey Dobriyan 已提交
16
#include <linux/sched.h>
D
David Howells 已提交
17
#include <linux/random.h>
D
David Howells 已提交
18
#define CREATE_TRACE_POINTS
L
Linus Torvalds 已提交
19 20 21 22 23 24
#include "internal.h"

MODULE_DESCRIPTION("AFS Client File System");
MODULE_AUTHOR("Red Hat, Inc.");
MODULE_LICENSE("GPL");

25 26
unsigned afs_debug;
module_param_named(debug, afs_debug, uint, S_IWUSR | S_IRUGO);
27
MODULE_PARM_DESC(debug, "AFS debugging mask");
28

L
Linus Torvalds 已提交
29 30 31 32 33
static char *rootcell;

module_param(rootcell, charp, 0);
MODULE_PARM_DESC(rootcell, "root AFS cell name and VL server IP addr list");

34
struct uuid_v1 afs_uuid;
35
struct workqueue_struct *afs_wq;
36

L
Linus Torvalds 已提交
37 38 39 40 41
/*
 * initialise the AFS client FS module
 */
static int __init afs_init(void)
{
42
	int ret;
L
Linus Torvalds 已提交
43 44 45

	printk(KERN_INFO "kAFS: Red Hat AFS client v0.1 registering.\n");

46
	generate_random_uuid((unsigned char *)&afs_uuid);
47

48 49 50 51 52 53
	/* create workqueue */
	ret = -ENOMEM;
	afs_wq = alloc_workqueue("afs", 0, 0);
	if (!afs_wq)
		return ret;

L
Linus Torvalds 已提交
54 55 56
	/* register the /proc stuff */
	ret = afs_proc_init();
	if (ret < 0)
57
		goto error_proc;
L
Linus Torvalds 已提交
58

D
David Howells 已提交
59
#ifdef CONFIG_AFS_FSCACHE
L
Linus Torvalds 已提交
60
	/* we want to be able to cache */
D
David Howells 已提交
61
	ret = fscache_register_netfs(&afs_cache_netfs);
L
Linus Torvalds 已提交
62 63 64 65 66 67 68
	if (ret < 0)
		goto error_cache;
#endif

	/* initialise the cell DB */
	ret = afs_cell_init(rootcell);
	if (ret < 0)
D
David Howells 已提交
69
		goto error_cell_init;
L
Linus Torvalds 已提交
70

71 72
	/* initialise the VL update process */
	ret = afs_vlocation_update_init();
L
Linus Torvalds 已提交
73
	if (ret < 0)
74
		goto error_vl_update_init;
L
Linus Torvalds 已提交
75

76 77
	/* initialise the callback update process */
	ret = afs_callback_update_init();
78 79
	if (ret < 0)
		goto error_callback_update_init;
L
Linus Torvalds 已提交
80 81

	/* create the RxRPC transport */
82
	ret = afs_open_socket();
L
Linus Torvalds 已提交
83
	if (ret < 0)
84
		goto error_open_socket;
L
Linus Torvalds 已提交
85 86 87 88

	/* register the filesystems */
	ret = afs_fs_init();
	if (ret < 0)
D
David Howells 已提交
89
		goto error_fs;
L
Linus Torvalds 已提交
90 91 92

	return ret;

D
David Howells 已提交
93
error_fs:
94 95
	afs_close_socket();
error_open_socket:
96 97 98
	afs_callback_update_kill();
error_callback_update_init:
	afs_vlocation_purge();
99
error_vl_update_init:
100
	afs_cell_purge();
D
David Howells 已提交
101
error_cell_init:
D
David Howells 已提交
102 103
#ifdef CONFIG_AFS_FSCACHE
	fscache_unregister_netfs(&afs_cache_netfs);
D
David Howells 已提交
104
error_cache:
L
Linus Torvalds 已提交
105 106
#endif
	afs_proc_cleanup();
107 108
error_proc:
	destroy_workqueue(afs_wq);
D
David Howells 已提交
109
	rcu_barrier();
L
Linus Torvalds 已提交
110 111
	printk(KERN_ERR "kAFS: failed to register: %d\n", ret);
	return ret;
D
David Howells 已提交
112
}
L
Linus Torvalds 已提交
113 114 115 116 117

/* XXX late_initcall is kludgy, but the only alternative seems to create
 * a transport upon the first mount, which is worse. Or is it?
 */
late_initcall(afs_init);	/* must be called after net/ to create socket */
D
David Howells 已提交
118

L
Linus Torvalds 已提交
119 120 121 122 123 124 125 126
/*
 * clean up on module removal
 */
static void __exit afs_exit(void)
{
	printk(KERN_INFO "kAFS: Red Hat AFS client v0.1 unregistering.\n");

	afs_fs_exit();
D
David Howells 已提交
127
	afs_kill_lock_manager();
128 129 130 131
	afs_close_socket();
	afs_purge_servers();
	afs_callback_update_kill();
	afs_vlocation_purge();
132
	destroy_workqueue(afs_wq);
L
Linus Torvalds 已提交
133
	afs_cell_purge();
D
David Howells 已提交
134 135
#ifdef CONFIG_AFS_FSCACHE
	fscache_unregister_netfs(&afs_cache_netfs);
L
Linus Torvalds 已提交
136 137
#endif
	afs_proc_cleanup();
D
David Howells 已提交
138
	rcu_barrier();
D
David Howells 已提交
139
}
L
Linus Torvalds 已提交
140 141

module_exit(afs_exit);