blob: 2d3e5d4fb9f781b7b360fea9bf3c2896b0771504 [file] [log] [blame]
David Howellsec268152007-04-26 15:49:28 -07001/* AFS client file system
Linus Torvalds1da177e2005-04-16 15:20:36 -07002 *
3 * Copyright (C) 2002 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>
Linus Torvalds1da177e2005-04-16 15:20:36 -070015#include <linux/completion.h>
Alexey Dobriyane8edc6e2007-05-21 01:22:52 +040016#include <linux/sched.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070017#include "internal.h"
18
Linus Torvalds1da177e2005-04-16 15:20:36 -070019MODULE_DESCRIPTION("AFS Client File System");
20MODULE_AUTHOR("Red Hat, Inc.");
21MODULE_LICENSE("GPL");
22
David Howells08e0e7c2007-04-26 15:55:03 -070023unsigned afs_debug;
24module_param_named(debug, afs_debug, uint, S_IWUSR | S_IRUGO);
Paul Bolle424b00e2008-04-16 11:08:22 +010025MODULE_PARM_DESC(debug, "AFS debugging mask");
David Howells08e0e7c2007-04-26 15:55:03 -070026
Linus Torvalds1da177e2005-04-16 15:20:36 -070027static char *rootcell;
28
29module_param(rootcell, charp, 0);
30MODULE_PARM_DESC(rootcell, "root AFS cell name and VL server IP addr list");
31
Linus Torvalds1da177e2005-04-16 15:20:36 -070032#ifdef AFS_CACHING_SUPPORT
33static struct cachefs_netfs_operations afs_cache_ops = {
34 .get_page_cookie = afs_cache_get_page_cookie,
35};
36
37struct cachefs_netfs afs_cache_netfs = {
38 .name = "afs",
39 .version = 0,
40 .ops = &afs_cache_ops,
41};
42#endif
43
David Howellsb908fe62007-04-26 15:58:17 -070044struct afs_uuid afs_uuid;
45
46/*
47 * get a client UUID
48 */
49static int __init afs_get_client_UUID(void)
50{
51 struct timespec ts;
52 u64 uuidtime;
53 u16 clockseq;
54 int ret;
55
56 /* read the MAC address of one of the external interfaces and construct
57 * a UUID from it */
David Howellsec9c9482007-05-03 03:29:41 -070058 ret = afs_get_MAC_address(afs_uuid.node, sizeof(afs_uuid.node));
David Howellsb908fe62007-04-26 15:58:17 -070059 if (ret < 0)
60 return ret;
61
62 getnstimeofday(&ts);
63 uuidtime = (u64) ts.tv_sec * 1000 * 1000 * 10;
64 uuidtime += ts.tv_nsec / 100;
65 uuidtime += AFS_UUID_TO_UNIX_TIME;
66 afs_uuid.time_low = uuidtime;
67 afs_uuid.time_mid = uuidtime >> 32;
68 afs_uuid.time_hi_and_version = (uuidtime >> 48) & AFS_UUID_TIMEHI_MASK;
69 afs_uuid.time_hi_and_version = AFS_UUID_VERSION_TIME;
70
71 get_random_bytes(&clockseq, 2);
72 afs_uuid.clock_seq_low = clockseq;
73 afs_uuid.clock_seq_hi_and_reserved =
74 (clockseq >> 8) & AFS_UUID_CLOCKHI_MASK;
75 afs_uuid.clock_seq_hi_and_reserved = AFS_UUID_VARIANT_STD;
76
77 _debug("AFS UUID: %08x-%04x-%04x-%02x%02x-%02x%02x%02x%02x%02x%02x",
78 afs_uuid.time_low,
79 afs_uuid.time_mid,
80 afs_uuid.time_hi_and_version,
81 afs_uuid.clock_seq_hi_and_reserved,
82 afs_uuid.clock_seq_low,
83 afs_uuid.node[0], afs_uuid.node[1], afs_uuid.node[2],
84 afs_uuid.node[3], afs_uuid.node[4], afs_uuid.node[5]);
85
86 return 0;
87}
88
Linus Torvalds1da177e2005-04-16 15:20:36 -070089/*
90 * initialise the AFS client FS module
91 */
92static int __init afs_init(void)
93{
David Howells08e0e7c2007-04-26 15:55:03 -070094 int ret;
Linus Torvalds1da177e2005-04-16 15:20:36 -070095
96 printk(KERN_INFO "kAFS: Red Hat AFS client v0.1 registering.\n");
97
David Howellsb908fe62007-04-26 15:58:17 -070098 ret = afs_get_client_UUID();
99 if (ret < 0)
100 return ret;
101
Linus Torvalds1da177e2005-04-16 15:20:36 -0700102 /* register the /proc stuff */
103 ret = afs_proc_init();
104 if (ret < 0)
105 return ret;
106
107#ifdef AFS_CACHING_SUPPORT
108 /* we want to be able to cache */
109 ret = cachefs_register_netfs(&afs_cache_netfs,
110 &afs_cache_cell_index_def);
111 if (ret < 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700112 goto error_cache;
113#endif
114
115 /* initialise the cell DB */
116 ret = afs_cell_init(rootcell);
117 if (ret < 0)
David Howellsec268152007-04-26 15:49:28 -0700118 goto error_cell_init;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700119
David Howells08e0e7c2007-04-26 15:55:03 -0700120 /* initialise the VL update process */
121 ret = afs_vlocation_update_init();
Linus Torvalds1da177e2005-04-16 15:20:36 -0700122 if (ret < 0)
David Howells08e0e7c2007-04-26 15:55:03 -0700123 goto error_vl_update_init;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700124
David Howells08e0e7c2007-04-26 15:55:03 -0700125 /* initialise the callback update process */
126 ret = afs_callback_update_init();
Linus Torvalds1da177e2005-04-16 15:20:36 -0700127
128 /* create the RxRPC transport */
David Howells08e0e7c2007-04-26 15:55:03 -0700129 ret = afs_open_socket();
Linus Torvalds1da177e2005-04-16 15:20:36 -0700130 if (ret < 0)
David Howells08e0e7c2007-04-26 15:55:03 -0700131 goto error_open_socket;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700132
133 /* register the filesystems */
134 ret = afs_fs_init();
135 if (ret < 0)
David Howellsec268152007-04-26 15:49:28 -0700136 goto error_fs;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700137
138 return ret;
139
David Howellsec268152007-04-26 15:49:28 -0700140error_fs:
David Howells08e0e7c2007-04-26 15:55:03 -0700141 afs_close_socket();
142error_open_socket:
143error_vl_update_init:
David Howellsec268152007-04-26 15:49:28 -0700144error_cell_init:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700145#ifdef AFS_CACHING_SUPPORT
146 cachefs_unregister_netfs(&afs_cache_netfs);
David Howellsec268152007-04-26 15:49:28 -0700147error_cache:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700148#endif
David Howells08e0e7c2007-04-26 15:55:03 -0700149 afs_callback_update_kill();
150 afs_vlocation_purge();
Linus Torvalds1da177e2005-04-16 15:20:36 -0700151 afs_cell_purge();
152 afs_proc_cleanup();
David Howells416351f2007-05-09 02:33:45 -0700153 rcu_barrier();
Linus Torvalds1da177e2005-04-16 15:20:36 -0700154 printk(KERN_ERR "kAFS: failed to register: %d\n", ret);
155 return ret;
David Howellsec268152007-04-26 15:49:28 -0700156}
Linus Torvalds1da177e2005-04-16 15:20:36 -0700157
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 */
David Howellsec268152007-04-26 15:49:28 -0700162
Linus Torvalds1da177e2005-04-16 15:20:36 -0700163/*
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();
David Howellse8d6c552007-07-15 23:40:12 -0700171 afs_kill_lock_manager();
David Howells08e0e7c2007-04-26 15:55:03 -0700172 afs_close_socket();
173 afs_purge_servers();
174 afs_callback_update_kill();
175 afs_vlocation_purge();
176 flush_scheduled_work();
Linus Torvalds1da177e2005-04-16 15:20:36 -0700177 afs_cell_purge();
Linus Torvalds1da177e2005-04-16 15:20:36 -0700178#ifdef AFS_CACHING_SUPPORT
179 cachefs_unregister_netfs(&afs_cache_netfs);
180#endif
181 afs_proc_cleanup();
David Howells416351f2007-05-09 02:33:45 -0700182 rcu_barrier();
David Howellsec268152007-04-26 15:49:28 -0700183}
Linus Torvalds1da177e2005-04-16 15:20:36 -0700184
185module_exit(afs_exit);