blob: f8188feb03adbaa44dc8eb431be0e9b77ce93177 [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 ([email protected])
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>
David Howellse0661df2016-08-30 16:05:14 +010017#include <linux/random.h>
David Howells8e8d7f12017-01-05 10:38:34 +000018#define CREATE_TRACE_POINTS
Linus Torvalds1da177e2005-04-16 15:20:36 -070019#include "internal.h"
20
Linus Torvalds1da177e2005-04-16 15:20:36 -070021MODULE_DESCRIPTION("AFS Client File System");
22MODULE_AUTHOR("Red Hat, Inc.");
23MODULE_LICENSE("GPL");
24
David Howells08e0e7c2007-04-26 15:55:03 -070025unsigned afs_debug;
26module_param_named(debug, afs_debug, uint, S_IWUSR | S_IRUGO);
Paul Bolle424b00e2008-04-16 11:08:22 +010027MODULE_PARM_DESC(debug, "AFS debugging mask");
David Howells08e0e7c2007-04-26 15:55:03 -070028
Linus Torvalds1da177e2005-04-16 15:20:36 -070029static char *rootcell;
30
31module_param(rootcell, charp, 0);
32MODULE_PARM_DESC(rootcell, "root AFS cell name and VL server IP addr list");
33
David Howellsb908fe62007-04-26 15:58:17 -070034struct afs_uuid afs_uuid;
Tejun Heo0ad53ee2011-01-14 15:56:37 +000035struct workqueue_struct *afs_wq;
David Howellsb908fe62007-04-26 15:58:17 -070036
37/*
38 * get a client UUID
39 */
40static int __init afs_get_client_UUID(void)
41{
42 struct timespec ts;
43 u64 uuidtime;
44 u16 clockseq;
45 int ret;
46
47 /* read the MAC address of one of the external interfaces and construct
48 * a UUID from it */
David Howellsec9c9482007-05-03 03:29:41 -070049 ret = afs_get_MAC_address(afs_uuid.node, sizeof(afs_uuid.node));
David Howellsb908fe62007-04-26 15:58:17 -070050 if (ret < 0)
51 return ret;
52
53 getnstimeofday(&ts);
54 uuidtime = (u64) ts.tv_sec * 1000 * 1000 * 10;
55 uuidtime += ts.tv_nsec / 100;
56 uuidtime += AFS_UUID_TO_UNIX_TIME;
57 afs_uuid.time_low = uuidtime;
58 afs_uuid.time_mid = uuidtime >> 32;
59 afs_uuid.time_hi_and_version = (uuidtime >> 48) & AFS_UUID_TIMEHI_MASK;
David Howells0ef13512014-07-29 17:53:23 +010060 afs_uuid.time_hi_and_version |= AFS_UUID_VERSION_TIME;
David Howellsb908fe62007-04-26 15:58:17 -070061
62 get_random_bytes(&clockseq, 2);
63 afs_uuid.clock_seq_low = clockseq;
64 afs_uuid.clock_seq_hi_and_reserved =
65 (clockseq >> 8) & AFS_UUID_CLOCKHI_MASK;
David Howells0ef13512014-07-29 17:53:23 +010066 afs_uuid.clock_seq_hi_and_reserved |= AFS_UUID_VARIANT_STD;
David Howellsb908fe62007-04-26 15:58:17 -070067
68 _debug("AFS UUID: %08x-%04x-%04x-%02x%02x-%02x%02x%02x%02x%02x%02x",
69 afs_uuid.time_low,
70 afs_uuid.time_mid,
71 afs_uuid.time_hi_and_version,
72 afs_uuid.clock_seq_hi_and_reserved,
73 afs_uuid.clock_seq_low,
74 afs_uuid.node[0], afs_uuid.node[1], afs_uuid.node[2],
75 afs_uuid.node[3], afs_uuid.node[4], afs_uuid.node[5]);
76
77 return 0;
78}
79
Linus Torvalds1da177e2005-04-16 15:20:36 -070080/*
81 * initialise the AFS client FS module
82 */
83static int __init afs_init(void)
84{
David Howells08e0e7c2007-04-26 15:55:03 -070085 int ret;
Linus Torvalds1da177e2005-04-16 15:20:36 -070086
87 printk(KERN_INFO "kAFS: Red Hat AFS client v0.1 registering.\n");
88
David Howellsb908fe62007-04-26 15:58:17 -070089 ret = afs_get_client_UUID();
90 if (ret < 0)
91 return ret;
92
Tejun Heo0ad53ee2011-01-14 15:56:37 +000093 /* create workqueue */
94 ret = -ENOMEM;
95 afs_wq = alloc_workqueue("afs", 0, 0);
96 if (!afs_wq)
97 return ret;
98
Linus Torvalds1da177e2005-04-16 15:20:36 -070099 /* register the /proc stuff */
100 ret = afs_proc_init();
101 if (ret < 0)
Tejun Heo0ad53ee2011-01-14 15:56:37 +0000102 goto error_proc;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700103
David Howells9b3f26c2009-04-03 16:42:41 +0100104#ifdef CONFIG_AFS_FSCACHE
Linus Torvalds1da177e2005-04-16 15:20:36 -0700105 /* we want to be able to cache */
David Howells9b3f26c2009-04-03 16:42:41 +0100106 ret = fscache_register_netfs(&afs_cache_netfs);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700107 if (ret < 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700108 goto error_cache;
109#endif
110
111 /* initialise the cell DB */
112 ret = afs_cell_init(rootcell);
113 if (ret < 0)
David Howellsec268152007-04-26 15:49:28 -0700114 goto error_cell_init;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700115
David Howells08e0e7c2007-04-26 15:55:03 -0700116 /* initialise the VL update process */
117 ret = afs_vlocation_update_init();
Linus Torvalds1da177e2005-04-16 15:20:36 -0700118 if (ret < 0)
David Howells08e0e7c2007-04-26 15:55:03 -0700119 goto error_vl_update_init;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700120
David Howells08e0e7c2007-04-26 15:55:03 -0700121 /* initialise the callback update process */
122 ret = afs_callback_update_init();
David Howellsdf44f9f2010-08-06 17:26:48 +0100123 if (ret < 0)
124 goto error_callback_update_init;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700125
126 /* create the RxRPC transport */
David Howells08e0e7c2007-04-26 15:55:03 -0700127 ret = afs_open_socket();
Linus Torvalds1da177e2005-04-16 15:20:36 -0700128 if (ret < 0)
David Howells08e0e7c2007-04-26 15:55:03 -0700129 goto error_open_socket;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700130
131 /* register the filesystems */
132 ret = afs_fs_init();
133 if (ret < 0)
David Howellsec268152007-04-26 15:49:28 -0700134 goto error_fs;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700135
136 return ret;
137
David Howellsec268152007-04-26 15:49:28 -0700138error_fs:
David Howells08e0e7c2007-04-26 15:55:03 -0700139 afs_close_socket();
140error_open_socket:
David Howellsdf44f9f2010-08-06 17:26:48 +0100141 afs_callback_update_kill();
142error_callback_update_init:
143 afs_vlocation_purge();
David Howells08e0e7c2007-04-26 15:55:03 -0700144error_vl_update_init:
David Howellsdf44f9f2010-08-06 17:26:48 +0100145 afs_cell_purge();
David Howellsec268152007-04-26 15:49:28 -0700146error_cell_init:
David Howells9b3f26c2009-04-03 16:42:41 +0100147#ifdef CONFIG_AFS_FSCACHE
148 fscache_unregister_netfs(&afs_cache_netfs);
David Howellsec268152007-04-26 15:49:28 -0700149error_cache:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700150#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -0700151 afs_proc_cleanup();
Tejun Heo0ad53ee2011-01-14 15:56:37 +0000152error_proc:
153 destroy_workqueue(afs_wq);
David Howells416351f2007-05-09 02:33:45 -0700154 rcu_barrier();
Linus Torvalds1da177e2005-04-16 15:20:36 -0700155 printk(KERN_ERR "kAFS: failed to register: %d\n", ret);
156 return ret;
David Howellsec268152007-04-26 15:49:28 -0700157}
Linus Torvalds1da177e2005-04-16 15:20:36 -0700158
159/* XXX late_initcall is kludgy, but the only alternative seems to create
160 * a transport upon the first mount, which is worse. Or is it?
161 */
162late_initcall(afs_init); /* must be called after net/ to create socket */
David Howellsec268152007-04-26 15:49:28 -0700163
Linus Torvalds1da177e2005-04-16 15:20:36 -0700164/*
165 * clean up on module removal
166 */
167static void __exit afs_exit(void)
168{
169 printk(KERN_INFO "kAFS: Red Hat AFS client v0.1 unregistering.\n");
170
171 afs_fs_exit();
David Howellse8d6c552007-07-15 23:40:12 -0700172 afs_kill_lock_manager();
David Howells08e0e7c2007-04-26 15:55:03 -0700173 afs_close_socket();
174 afs_purge_servers();
175 afs_callback_update_kill();
176 afs_vlocation_purge();
Tejun Heo0ad53ee2011-01-14 15:56:37 +0000177 destroy_workqueue(afs_wq);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700178 afs_cell_purge();
David Howells9b3f26c2009-04-03 16:42:41 +0100179#ifdef CONFIG_AFS_FSCACHE
180 fscache_unregister_netfs(&afs_cache_netfs);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700181#endif
182 afs_proc_cleanup();
David Howells416351f2007-05-09 02:33:45 -0700183 rcu_barrier();
David Howellsec268152007-04-26 15:49:28 -0700184}
Linus Torvalds1da177e2005-04-16 15:20:36 -0700185
186module_exit(afs_exit);