David Howells | ec26815 | 2007-04-26 15:49:28 -0700 | [diff] [blame] | 1 | /* AFS client file system |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2 | * |
David Howells | 9b3f26c | 2009-04-03 16:42:41 +0100 | [diff] [blame] | 3 | * Copyright (C) 2002,5 Red Hat, Inc. All Rights Reserved. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 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 Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 15 | #include <linux/completion.h> |
Alexey Dobriyan | e8edc6e | 2007-05-21 01:22:52 +0400 | [diff] [blame] | 16 | #include <linux/sched.h> |
David Howells | e0661df | 2016-08-30 16:05:14 +0100 | [diff] [blame] | 17 | #include <linux/random.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 18 | #include "internal.h" |
| 19 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 20 | MODULE_DESCRIPTION("AFS Client File System"); |
| 21 | MODULE_AUTHOR("Red Hat, Inc."); |
| 22 | MODULE_LICENSE("GPL"); |
| 23 | |
David Howells | 08e0e7c | 2007-04-26 15:55:03 -0700 | [diff] [blame] | 24 | unsigned afs_debug; |
| 25 | module_param_named(debug, afs_debug, uint, S_IWUSR | S_IRUGO); |
Paul Bolle | 424b00e | 2008-04-16 11:08:22 +0100 | [diff] [blame] | 26 | MODULE_PARM_DESC(debug, "AFS debugging mask"); |
David Howells | 08e0e7c | 2007-04-26 15:55:03 -0700 | [diff] [blame] | 27 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 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 | |
David Howells | b908fe6 | 2007-04-26 15:58:17 -0700 | [diff] [blame] | 33 | struct afs_uuid afs_uuid; |
Tejun Heo | 0ad53ee | 2011-01-14 15:56:37 +0000 | [diff] [blame] | 34 | struct workqueue_struct *afs_wq; |
David Howells | b908fe6 | 2007-04-26 15:58:17 -0700 | [diff] [blame] | 35 | |
| 36 | /* |
| 37 | * get a client UUID |
| 38 | */ |
| 39 | static int __init afs_get_client_UUID(void) |
| 40 | { |
| 41 | struct timespec ts; |
| 42 | u64 uuidtime; |
| 43 | u16 clockseq; |
| 44 | int ret; |
| 45 | |
| 46 | /* read the MAC address of one of the external interfaces and construct |
| 47 | * a UUID from it */ |
David Howells | ec9c948 | 2007-05-03 03:29:41 -0700 | [diff] [blame] | 48 | ret = afs_get_MAC_address(afs_uuid.node, sizeof(afs_uuid.node)); |
David Howells | b908fe6 | 2007-04-26 15:58:17 -0700 | [diff] [blame] | 49 | if (ret < 0) |
| 50 | return ret; |
| 51 | |
| 52 | getnstimeofday(&ts); |
| 53 | uuidtime = (u64) ts.tv_sec * 1000 * 1000 * 10; |
| 54 | uuidtime += ts.tv_nsec / 100; |
| 55 | uuidtime += AFS_UUID_TO_UNIX_TIME; |
| 56 | afs_uuid.time_low = uuidtime; |
| 57 | afs_uuid.time_mid = uuidtime >> 32; |
| 58 | afs_uuid.time_hi_and_version = (uuidtime >> 48) & AFS_UUID_TIMEHI_MASK; |
David Howells | 0ef1351 | 2014-07-29 17:53:23 +0100 | [diff] [blame] | 59 | afs_uuid.time_hi_and_version |= AFS_UUID_VERSION_TIME; |
David Howells | b908fe6 | 2007-04-26 15:58:17 -0700 | [diff] [blame] | 60 | |
| 61 | get_random_bytes(&clockseq, 2); |
| 62 | afs_uuid.clock_seq_low = clockseq; |
| 63 | afs_uuid.clock_seq_hi_and_reserved = |
| 64 | (clockseq >> 8) & AFS_UUID_CLOCKHI_MASK; |
David Howells | 0ef1351 | 2014-07-29 17:53:23 +0100 | [diff] [blame] | 65 | afs_uuid.clock_seq_hi_and_reserved |= AFS_UUID_VARIANT_STD; |
David Howells | b908fe6 | 2007-04-26 15:58:17 -0700 | [diff] [blame] | 66 | |
| 67 | _debug("AFS UUID: %08x-%04x-%04x-%02x%02x-%02x%02x%02x%02x%02x%02x", |
| 68 | afs_uuid.time_low, |
| 69 | afs_uuid.time_mid, |
| 70 | afs_uuid.time_hi_and_version, |
| 71 | afs_uuid.clock_seq_hi_and_reserved, |
| 72 | afs_uuid.clock_seq_low, |
| 73 | afs_uuid.node[0], afs_uuid.node[1], afs_uuid.node[2], |
| 74 | afs_uuid.node[3], afs_uuid.node[4], afs_uuid.node[5]); |
| 75 | |
| 76 | return 0; |
| 77 | } |
| 78 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 79 | /* |
| 80 | * initialise the AFS client FS module |
| 81 | */ |
| 82 | static int __init afs_init(void) |
| 83 | { |
David Howells | 08e0e7c | 2007-04-26 15:55:03 -0700 | [diff] [blame] | 84 | int ret; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 85 | |
| 86 | printk(KERN_INFO "kAFS: Red Hat AFS client v0.1 registering.\n"); |
| 87 | |
David Howells | b908fe6 | 2007-04-26 15:58:17 -0700 | [diff] [blame] | 88 | ret = afs_get_client_UUID(); |
| 89 | if (ret < 0) |
| 90 | return ret; |
| 91 | |
Tejun Heo | 0ad53ee | 2011-01-14 15:56:37 +0000 | [diff] [blame] | 92 | /* create workqueue */ |
| 93 | ret = -ENOMEM; |
| 94 | afs_wq = alloc_workqueue("afs", 0, 0); |
| 95 | if (!afs_wq) |
| 96 | return ret; |
| 97 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 98 | /* register the /proc stuff */ |
| 99 | ret = afs_proc_init(); |
| 100 | if (ret < 0) |
Tejun Heo | 0ad53ee | 2011-01-14 15:56:37 +0000 | [diff] [blame] | 101 | goto error_proc; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 102 | |
David Howells | 9b3f26c | 2009-04-03 16:42:41 +0100 | [diff] [blame] | 103 | #ifdef CONFIG_AFS_FSCACHE |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 104 | /* we want to be able to cache */ |
David Howells | 9b3f26c | 2009-04-03 16:42:41 +0100 | [diff] [blame] | 105 | ret = fscache_register_netfs(&afs_cache_netfs); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 106 | if (ret < 0) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 107 | goto error_cache; |
| 108 | #endif |
| 109 | |
| 110 | /* initialise the cell DB */ |
| 111 | ret = afs_cell_init(rootcell); |
| 112 | if (ret < 0) |
David Howells | ec26815 | 2007-04-26 15:49:28 -0700 | [diff] [blame] | 113 | goto error_cell_init; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 114 | |
David Howells | 08e0e7c | 2007-04-26 15:55:03 -0700 | [diff] [blame] | 115 | /* initialise the VL update process */ |
| 116 | ret = afs_vlocation_update_init(); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 117 | if (ret < 0) |
David Howells | 08e0e7c | 2007-04-26 15:55:03 -0700 | [diff] [blame] | 118 | goto error_vl_update_init; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 119 | |
David Howells | 08e0e7c | 2007-04-26 15:55:03 -0700 | [diff] [blame] | 120 | /* initialise the callback update process */ |
| 121 | ret = afs_callback_update_init(); |
David Howells | df44f9f | 2010-08-06 17:26:48 +0100 | [diff] [blame] | 122 | if (ret < 0) |
| 123 | goto error_callback_update_init; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 124 | |
| 125 | /* create the RxRPC transport */ |
David Howells | 08e0e7c | 2007-04-26 15:55:03 -0700 | [diff] [blame] | 126 | ret = afs_open_socket(); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 127 | if (ret < 0) |
David Howells | 08e0e7c | 2007-04-26 15:55:03 -0700 | [diff] [blame] | 128 | goto error_open_socket; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 129 | |
| 130 | /* register the filesystems */ |
| 131 | ret = afs_fs_init(); |
| 132 | if (ret < 0) |
David Howells | ec26815 | 2007-04-26 15:49:28 -0700 | [diff] [blame] | 133 | goto error_fs; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 134 | |
| 135 | return ret; |
| 136 | |
David Howells | ec26815 | 2007-04-26 15:49:28 -0700 | [diff] [blame] | 137 | error_fs: |
David Howells | 08e0e7c | 2007-04-26 15:55:03 -0700 | [diff] [blame] | 138 | afs_close_socket(); |
| 139 | error_open_socket: |
David Howells | df44f9f | 2010-08-06 17:26:48 +0100 | [diff] [blame] | 140 | afs_callback_update_kill(); |
| 141 | error_callback_update_init: |
| 142 | afs_vlocation_purge(); |
David Howells | 08e0e7c | 2007-04-26 15:55:03 -0700 | [diff] [blame] | 143 | error_vl_update_init: |
David Howells | df44f9f | 2010-08-06 17:26:48 +0100 | [diff] [blame] | 144 | afs_cell_purge(); |
David Howells | ec26815 | 2007-04-26 15:49:28 -0700 | [diff] [blame] | 145 | error_cell_init: |
David Howells | 9b3f26c | 2009-04-03 16:42:41 +0100 | [diff] [blame] | 146 | #ifdef CONFIG_AFS_FSCACHE |
| 147 | fscache_unregister_netfs(&afs_cache_netfs); |
David Howells | ec26815 | 2007-04-26 15:49:28 -0700 | [diff] [blame] | 148 | error_cache: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 149 | #endif |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 150 | afs_proc_cleanup(); |
Tejun Heo | 0ad53ee | 2011-01-14 15:56:37 +0000 | [diff] [blame] | 151 | error_proc: |
| 152 | destroy_workqueue(afs_wq); |
David Howells | 416351f | 2007-05-09 02:33:45 -0700 | [diff] [blame] | 153 | rcu_barrier(); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 154 | printk(KERN_ERR "kAFS: failed to register: %d\n", ret); |
| 155 | return ret; |
David Howells | ec26815 | 2007-04-26 15:49:28 -0700 | [diff] [blame] | 156 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 157 | |
| 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 | */ |
| 161 | late_initcall(afs_init); /* must be called after net/ to create socket */ |
David Howells | ec26815 | 2007-04-26 15:49:28 -0700 | [diff] [blame] | 162 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 163 | /* |
| 164 | * clean up on module removal |
| 165 | */ |
| 166 | static 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 Howells | e8d6c55 | 2007-07-15 23:40:12 -0700 | [diff] [blame] | 171 | afs_kill_lock_manager(); |
David Howells | 08e0e7c | 2007-04-26 15:55:03 -0700 | [diff] [blame] | 172 | afs_close_socket(); |
| 173 | afs_purge_servers(); |
| 174 | afs_callback_update_kill(); |
| 175 | afs_vlocation_purge(); |
Tejun Heo | 0ad53ee | 2011-01-14 15:56:37 +0000 | [diff] [blame] | 176 | destroy_workqueue(afs_wq); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 177 | afs_cell_purge(); |
David Howells | 9b3f26c | 2009-04-03 16:42:41 +0100 | [diff] [blame] | 178 | #ifdef CONFIG_AFS_FSCACHE |
| 179 | fscache_unregister_netfs(&afs_cache_netfs); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 180 | #endif |
| 181 | afs_proc_cleanup(); |
David Howells | 416351f | 2007-05-09 02:33:45 -0700 | [diff] [blame] | 182 | rcu_barrier(); |
David Howells | ec26815 | 2007-04-26 15:49:28 -0700 | [diff] [blame] | 183 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 184 | |
| 185 | module_exit(afs_exit); |