Merge remote-tracking branch 'y2038/y2038'
[deliverable/linux.git] / fs / afs / main.c
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 <linux/ktime.h>
19 #include "internal.h"
20
21 MODULE_DESCRIPTION("AFS Client File System");
22 MODULE_AUTHOR("Red Hat, Inc.");
23 MODULE_LICENSE("GPL");
24
25 unsigned afs_debug;
26 module_param_named(debug, afs_debug, uint, S_IWUSR | S_IRUGO);
27 MODULE_PARM_DESC(debug, "AFS debugging mask");
28
29 static char *rootcell;
30
31 module_param(rootcell, charp, 0);
32 MODULE_PARM_DESC(rootcell, "root AFS cell name and VL server IP addr list");
33
34 struct afs_uuid afs_uuid;
35 struct workqueue_struct *afs_wq;
36
37 /*
38 * get a client UUID
39 */
40 static int __init afs_get_client_UUID(void)
41 {
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 uuidtime = ktime_divns(ktime_get_real(), 100);
53 uuidtime += AFS_UUID_TO_UNIX_TIME;
54 afs_uuid.time_low = uuidtime;
55 afs_uuid.time_mid = uuidtime >> 32;
56 afs_uuid.time_hi_and_version = (uuidtime >> 48) & AFS_UUID_TIMEHI_MASK;
57 afs_uuid.time_hi_and_version |= AFS_UUID_VERSION_TIME;
58
59 get_random_bytes(&clockseq, 2);
60 afs_uuid.clock_seq_low = clockseq;
61 afs_uuid.clock_seq_hi_and_reserved =
62 (clockseq >> 8) & AFS_UUID_CLOCKHI_MASK;
63 afs_uuid.clock_seq_hi_and_reserved |= AFS_UUID_VARIANT_STD;
64
65 _debug("AFS UUID: %08x-%04x-%04x-%02x%02x-%02x%02x%02x%02x%02x%02x",
66 afs_uuid.time_low,
67 afs_uuid.time_mid,
68 afs_uuid.time_hi_and_version,
69 afs_uuid.clock_seq_hi_and_reserved,
70 afs_uuid.clock_seq_low,
71 afs_uuid.node[0], afs_uuid.node[1], afs_uuid.node[2],
72 afs_uuid.node[3], afs_uuid.node[4], afs_uuid.node[5]);
73
74 return 0;
75 }
76
77 /*
78 * initialise the AFS client FS module
79 */
80 static int __init afs_init(void)
81 {
82 int ret;
83
84 printk(KERN_INFO "kAFS: Red Hat AFS client v0.1 registering.\n");
85
86 ret = afs_get_client_UUID();
87 if (ret < 0)
88 return ret;
89
90 /* create workqueue */
91 ret = -ENOMEM;
92 afs_wq = alloc_workqueue("afs", 0, 0);
93 if (!afs_wq)
94 return ret;
95
96 /* register the /proc stuff */
97 ret = afs_proc_init();
98 if (ret < 0)
99 goto error_proc;
100
101 #ifdef CONFIG_AFS_FSCACHE
102 /* we want to be able to cache */
103 ret = fscache_register_netfs(&afs_cache_netfs);
104 if (ret < 0)
105 goto error_cache;
106 #endif
107
108 /* initialise the cell DB */
109 ret = afs_cell_init(rootcell);
110 if (ret < 0)
111 goto error_cell_init;
112
113 /* initialise the VL update process */
114 ret = afs_vlocation_update_init();
115 if (ret < 0)
116 goto error_vl_update_init;
117
118 /* initialise the callback update process */
119 ret = afs_callback_update_init();
120 if (ret < 0)
121 goto error_callback_update_init;
122
123 /* create the RxRPC transport */
124 ret = afs_open_socket();
125 if (ret < 0)
126 goto error_open_socket;
127
128 /* register the filesystems */
129 ret = afs_fs_init();
130 if (ret < 0)
131 goto error_fs;
132
133 return ret;
134
135 error_fs:
136 afs_close_socket();
137 error_open_socket:
138 afs_callback_update_kill();
139 error_callback_update_init:
140 afs_vlocation_purge();
141 error_vl_update_init:
142 afs_cell_purge();
143 error_cell_init:
144 #ifdef CONFIG_AFS_FSCACHE
145 fscache_unregister_netfs(&afs_cache_netfs);
146 error_cache:
147 #endif
148 afs_proc_cleanup();
149 error_proc:
150 destroy_workqueue(afs_wq);
151 rcu_barrier();
152 printk(KERN_ERR "kAFS: failed to register: %d\n", ret);
153 return ret;
154 }
155
156 /* XXX late_initcall is kludgy, but the only alternative seems to create
157 * a transport upon the first mount, which is worse. Or is it?
158 */
159 late_initcall(afs_init); /* must be called after net/ to create socket */
160
161 /*
162 * clean up on module removal
163 */
164 static void __exit afs_exit(void)
165 {
166 printk(KERN_INFO "kAFS: Red Hat AFS client v0.1 unregistering.\n");
167
168 afs_fs_exit();
169 afs_kill_lock_manager();
170 afs_close_socket();
171 afs_purge_servers();
172 afs_callback_update_kill();
173 afs_vlocation_purge();
174 destroy_workqueue(afs_wq);
175 afs_cell_purge();
176 #ifdef CONFIG_AFS_FSCACHE
177 fscache_unregister_netfs(&afs_cache_netfs);
178 #endif
179 afs_proc_cleanup();
180 rcu_barrier();
181 }
182
183 module_exit(afs_exit);
This page took 0.03646 seconds and 5 git commands to generate.