blob: f1f71ff7d5c673ccccffd02f965224ea51456934 [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>
Linus Torvalds1da177e2005-04-16 15:20:36 -070016#include "internal.h"
17
Linus Torvalds1da177e2005-04-16 15:20:36 -070018MODULE_DESCRIPTION("AFS Client File System");
19MODULE_AUTHOR("Red Hat, Inc.");
20MODULE_LICENSE("GPL");
21
David Howells08e0e7c2007-04-26 15:55:03 -070022unsigned afs_debug;
23module_param_named(debug, afs_debug, uint, S_IWUSR | S_IRUGO);
24MODULE_PARM_DESC(afs_debug, "AFS debugging mask");
25
Linus Torvalds1da177e2005-04-16 15:20:36 -070026static char *rootcell;
27
28module_param(rootcell, charp, 0);
29MODULE_PARM_DESC(rootcell, "root AFS cell name and VL server IP addr list");
30
Linus Torvalds1da177e2005-04-16 15:20:36 -070031#ifdef AFS_CACHING_SUPPORT
32static struct cachefs_netfs_operations afs_cache_ops = {
33 .get_page_cookie = afs_cache_get_page_cookie,
34};
35
36struct cachefs_netfs afs_cache_netfs = {
37 .name = "afs",
38 .version = 0,
39 .ops = &afs_cache_ops,
40};
41#endif
42
David Howellsb908fe62007-04-26 15:58:17 -070043struct afs_uuid afs_uuid;
44
45/*
46 * get a client UUID
47 */
48static int __init afs_get_client_UUID(void)
49{
50 struct timespec ts;
51 u64 uuidtime;
52 u16 clockseq;
53 int ret;
54
55 /* read the MAC address of one of the external interfaces and construct
56 * a UUID from it */
David Howellsec9c9482007-05-03 03:29:41 -070057 ret = afs_get_MAC_address(afs_uuid.node, sizeof(afs_uuid.node));
David Howellsb908fe62007-04-26 15:58:17 -070058 if (ret < 0)
59 return ret;
60
61 getnstimeofday(&ts);
62 uuidtime = (u64) ts.tv_sec * 1000 * 1000 * 10;
63 uuidtime += ts.tv_nsec / 100;
64 uuidtime += AFS_UUID_TO_UNIX_TIME;
65 afs_uuid.time_low = uuidtime;
66 afs_uuid.time_mid = uuidtime >> 32;
67 afs_uuid.time_hi_and_version = (uuidtime >> 48) & AFS_UUID_TIMEHI_MASK;
68 afs_uuid.time_hi_and_version = AFS_UUID_VERSION_TIME;
69
70 get_random_bytes(&clockseq, 2);
71 afs_uuid.clock_seq_low = clockseq;
72 afs_uuid.clock_seq_hi_and_reserved =
73 (clockseq >> 8) & AFS_UUID_CLOCKHI_MASK;
74 afs_uuid.clock_seq_hi_and_reserved = AFS_UUID_VARIANT_STD;
75
76 _debug("AFS UUID: %08x-%04x-%04x-%02x%02x-%02x%02x%02x%02x%02x%02x",
77 afs_uuid.time_low,
78 afs_uuid.time_mid,
79 afs_uuid.time_hi_and_version,
80 afs_uuid.clock_seq_hi_and_reserved,
81 afs_uuid.clock_seq_low,
82 afs_uuid.node[0], afs_uuid.node[1], afs_uuid.node[2],
83 afs_uuid.node[3], afs_uuid.node[4], afs_uuid.node[5]);
84
85 return 0;
86}
87
Linus Torvalds1da177e2005-04-16 15:20:36 -070088/*
89 * initialise the AFS client FS module
90 */
91static int __init afs_init(void)
92{
David Howells08e0e7c2007-04-26 15:55:03 -070093 int ret;
Linus Torvalds1da177e2005-04-16 15:20:36 -070094
95 printk(KERN_INFO "kAFS: Red Hat AFS client v0.1 registering.\n");
96
David Howellsb908fe62007-04-26 15:58:17 -070097 ret = afs_get_client_UUID();
98 if (ret < 0)
99 return ret;
100
Linus Torvalds1da177e2005-04-16 15:20:36 -0700101 /* register the /proc stuff */
102 ret = afs_proc_init();
103 if (ret < 0)
104 return ret;
105
106#ifdef AFS_CACHING_SUPPORT
107 /* we want to be able to cache */
108 ret = cachefs_register_netfs(&afs_cache_netfs,
109 &afs_cache_cell_index_def);
110 if (ret < 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700111 goto error_cache;
112#endif
113
114 /* initialise the cell DB */
115 ret = afs_cell_init(rootcell);
116 if (ret < 0)
David Howellsec268152007-04-26 15:49:28 -0700117 goto error_cell_init;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700118
David Howells08e0e7c2007-04-26 15:55:03 -0700119 /* initialise the VL update process */
120 ret = afs_vlocation_update_init();
Linus Torvalds1da177e2005-04-16 15:20:36 -0700121 if (ret < 0)
David Howells08e0e7c2007-04-26 15:55:03 -0700122 goto error_vl_update_init;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700123
David Howells08e0e7c2007-04-26 15:55:03 -0700124 /* initialise the callback update process */
125 ret = afs_callback_update_init();
Linus Torvalds1da177e2005-04-16 15:20:36 -0700126
127 /* create the RxRPC transport */
David Howells08e0e7c2007-04-26 15:55:03 -0700128 ret = afs_open_socket();
Linus Torvalds1da177e2005-04-16 15:20:36 -0700129 if (ret < 0)
David Howells08e0e7c2007-04-26 15:55:03 -0700130 goto error_open_socket;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700131
132 /* register the filesystems */
133 ret = afs_fs_init();
134 if (ret < 0)
David Howellsec268152007-04-26 15:49:28 -0700135 goto error_fs;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700136
137 return ret;
138
David Howellsec268152007-04-26 15:49:28 -0700139error_fs:
David Howells08e0e7c2007-04-26 15:55:03 -0700140 afs_close_socket();
141error_open_socket:
142error_vl_update_init:
David Howellsec268152007-04-26 15:49:28 -0700143error_cell_init:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700144#ifdef AFS_CACHING_SUPPORT
145 cachefs_unregister_netfs(&afs_cache_netfs);
David Howellsec268152007-04-26 15:49:28 -0700146error_cache:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700147#endif
David Howells08e0e7c2007-04-26 15:55:03 -0700148 afs_callback_update_kill();
149 afs_vlocation_purge();
Linus Torvalds1da177e2005-04-16 15:20:36 -0700150 afs_cell_purge();
151 afs_proc_cleanup();
David Howells416351f2007-05-09 02:33:45 -0700152 rcu_barrier();
Linus Torvalds1da177e2005-04-16 15:20:36 -0700153 printk(KERN_ERR "kAFS: failed to register: %d\n", ret);
154 return ret;
David Howellsec268152007-04-26 15:49:28 -0700155}
Linus Torvalds1da177e2005-04-16 15:20:36 -0700156
157/* XXX late_initcall is kludgy, but the only alternative seems to create
158 * a transport upon the first mount, which is worse. Or is it?
159 */
160late_initcall(afs_init); /* must be called after net/ to create socket */
David Howellsec268152007-04-26 15:49:28 -0700161
Linus Torvalds1da177e2005-04-16 15:20:36 -0700162/*
163 * clean up on module removal
164 */
165static void __exit afs_exit(void)
166{
167 printk(KERN_INFO "kAFS: Red Hat AFS client v0.1 unregistering.\n");
168
169 afs_fs_exit();
David Howells08e0e7c2007-04-26 15:55:03 -0700170 afs_close_socket();
171 afs_purge_servers();
172 afs_callback_update_kill();
173 afs_vlocation_purge();
174 flush_scheduled_work();
Linus Torvalds1da177e2005-04-16 15:20:36 -0700175 afs_cell_purge();
Linus Torvalds1da177e2005-04-16 15:20:36 -0700176#ifdef AFS_CACHING_SUPPORT
177 cachefs_unregister_netfs(&afs_cache_netfs);
178#endif
179 afs_proc_cleanup();
David Howells416351f2007-05-09 02:33:45 -0700180 rcu_barrier();
David Howellsec268152007-04-26 15:49:28 -0700181}
Linus Torvalds1da177e2005-04-16 15:20:36 -0700182
183module_exit(afs_exit);