blob: 66d54d348c55f2c232bd362f1b432ab242d4256b [file] [log] [blame]
David Howellsec268152007-04-26 15:49:28 -07001/* AFS client file system
Linus Torvalds1da177e2005-04-16 15:20:36 -07002 *
David Howells9b3f26c2009-04-03 16:42:41 +01003 * Copyright (C) 2002,5 Red Hat, Inc. All Rights Reserved.
Linus Torvalds1da177e2005-04-16 15:20:36 -07004 * 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
David Howellsb908fe62007-04-26 15:58:17 -070032struct afs_uuid afs_uuid;
33
34/*
35 * get a client UUID
36 */
37static int __init afs_get_client_UUID(void)
38{
39 struct timespec ts;
40 u64 uuidtime;
41 u16 clockseq;
42 int ret;
43
44 /* read the MAC address of one of the external interfaces and construct
45 * a UUID from it */
David Howellsec9c9482007-05-03 03:29:41 -070046 ret = afs_get_MAC_address(afs_uuid.node, sizeof(afs_uuid.node));
David Howellsb908fe62007-04-26 15:58:17 -070047 if (ret < 0)
48 return ret;
49
50 getnstimeofday(&ts);
51 uuidtime = (u64) ts.tv_sec * 1000 * 1000 * 10;
52 uuidtime += ts.tv_nsec / 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
Linus Torvalds1da177e2005-04-16 15:20:36 -070077/*
78 * initialise the AFS client FS module
79 */
80static int __init afs_init(void)
81{
David Howells08e0e7c2007-04-26 15:55:03 -070082 int ret;
Linus Torvalds1da177e2005-04-16 15:20:36 -070083
84 printk(KERN_INFO "kAFS: Red Hat AFS client v0.1 registering.\n");
85
David Howellsb908fe62007-04-26 15:58:17 -070086 ret = afs_get_client_UUID();
87 if (ret < 0)
88 return ret;
89
Linus Torvalds1da177e2005-04-16 15:20:36 -070090 /* register the /proc stuff */
91 ret = afs_proc_init();
92 if (ret < 0)
93 return ret;
94
David Howells9b3f26c2009-04-03 16:42:41 +010095#ifdef CONFIG_AFS_FSCACHE
Linus Torvalds1da177e2005-04-16 15:20:36 -070096 /* we want to be able to cache */
David Howells9b3f26c2009-04-03 16:42:41 +010097 ret = fscache_register_netfs(&afs_cache_netfs);
Linus Torvalds1da177e2005-04-16 15:20:36 -070098 if (ret < 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -070099 goto error_cache;
100#endif
101
102 /* initialise the cell DB */
103 ret = afs_cell_init(rootcell);
104 if (ret < 0)
David Howellsec268152007-04-26 15:49:28 -0700105 goto error_cell_init;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700106
David Howells08e0e7c2007-04-26 15:55:03 -0700107 /* initialise the VL update process */
108 ret = afs_vlocation_update_init();
Linus Torvalds1da177e2005-04-16 15:20:36 -0700109 if (ret < 0)
David Howells08e0e7c2007-04-26 15:55:03 -0700110 goto error_vl_update_init;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700111
David Howells08e0e7c2007-04-26 15:55:03 -0700112 /* initialise the callback update process */
113 ret = afs_callback_update_init();
Linus Torvalds1da177e2005-04-16 15:20:36 -0700114
115 /* create the RxRPC transport */
David Howells08e0e7c2007-04-26 15:55:03 -0700116 ret = afs_open_socket();
Linus Torvalds1da177e2005-04-16 15:20:36 -0700117 if (ret < 0)
David Howells08e0e7c2007-04-26 15:55:03 -0700118 goto error_open_socket;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700119
120 /* register the filesystems */
121 ret = afs_fs_init();
122 if (ret < 0)
David Howellsec268152007-04-26 15:49:28 -0700123 goto error_fs;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700124
125 return ret;
126
David Howellsec268152007-04-26 15:49:28 -0700127error_fs:
David Howells08e0e7c2007-04-26 15:55:03 -0700128 afs_close_socket();
129error_open_socket:
130error_vl_update_init:
David Howellsec268152007-04-26 15:49:28 -0700131error_cell_init:
David Howells9b3f26c2009-04-03 16:42:41 +0100132#ifdef CONFIG_AFS_FSCACHE
133 fscache_unregister_netfs(&afs_cache_netfs);
David Howellsec268152007-04-26 15:49:28 -0700134error_cache:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700135#endif
David Howells08e0e7c2007-04-26 15:55:03 -0700136 afs_callback_update_kill();
137 afs_vlocation_purge();
Linus Torvalds1da177e2005-04-16 15:20:36 -0700138 afs_cell_purge();
139 afs_proc_cleanup();
David Howells416351f2007-05-09 02:33:45 -0700140 rcu_barrier();
Linus Torvalds1da177e2005-04-16 15:20:36 -0700141 printk(KERN_ERR "kAFS: failed to register: %d\n", ret);
142 return ret;
David Howellsec268152007-04-26 15:49:28 -0700143}
Linus Torvalds1da177e2005-04-16 15:20:36 -0700144
145/* XXX late_initcall is kludgy, but the only alternative seems to create
146 * a transport upon the first mount, which is worse. Or is it?
147 */
148late_initcall(afs_init); /* must be called after net/ to create socket */
David Howellsec268152007-04-26 15:49:28 -0700149
Linus Torvalds1da177e2005-04-16 15:20:36 -0700150/*
151 * clean up on module removal
152 */
153static void __exit afs_exit(void)
154{
155 printk(KERN_INFO "kAFS: Red Hat AFS client v0.1 unregistering.\n");
156
157 afs_fs_exit();
David Howellse8d6c552007-07-15 23:40:12 -0700158 afs_kill_lock_manager();
David Howells08e0e7c2007-04-26 15:55:03 -0700159 afs_close_socket();
160 afs_purge_servers();
161 afs_callback_update_kill();
162 afs_vlocation_purge();
163 flush_scheduled_work();
Linus Torvalds1da177e2005-04-16 15:20:36 -0700164 afs_cell_purge();
David Howells9b3f26c2009-04-03 16:42:41 +0100165#ifdef CONFIG_AFS_FSCACHE
166 fscache_unregister_netfs(&afs_cache_netfs);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700167#endif
168 afs_proc_cleanup();
David Howells416351f2007-05-09 02:33:45 -0700169 rcu_barrier();
David Howellsec268152007-04-26 15:49:28 -0700170}
Linus Torvalds1da177e2005-04-16 15:20:36 -0700171
172module_exit(afs_exit);