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