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> |
David Howells | 8e8d7f1 | 2017-01-05 10:38:34 +0000 | [diff] [blame] | 18 | #define CREATE_TRACE_POINTS |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 19 | #include "internal.h" |
| 20 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 21 | MODULE_DESCRIPTION("AFS Client File System"); |
| 22 | MODULE_AUTHOR("Red Hat, Inc."); |
| 23 | MODULE_LICENSE("GPL"); |
| 24 | |
David Howells | 08e0e7c | 2007-04-26 15:55:03 -0700 | [diff] [blame] | 25 | unsigned afs_debug; |
| 26 | module_param_named(debug, afs_debug, uint, S_IWUSR | S_IRUGO); |
Paul Bolle | 424b00e | 2008-04-16 11:08:22 +0100 | [diff] [blame] | 27 | MODULE_PARM_DESC(debug, "AFS debugging mask"); |
David Howells | 08e0e7c | 2007-04-26 15:55:03 -0700 | [diff] [blame] | 28 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 29 | static char *rootcell; |
| 30 | |
| 31 | module_param(rootcell, charp, 0); |
| 32 | MODULE_PARM_DESC(rootcell, "root AFS cell name and VL server IP addr list"); |
| 33 | |
Christoph Hellwig | 41bb26f | 2017-05-28 08:56:46 +0300 | [diff] [blame] | 34 | struct afs_uuid afs_uuid; |
Tejun Heo | 0ad53ee | 2011-01-14 15:56:37 +0000 | [diff] [blame] | 35 | struct workqueue_struct *afs_wq; |
David Howells | b908fe6 | 2007-04-26 15:58:17 -0700 | [diff] [blame] | 36 | |
| 37 | /* |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 38 | * initialise the AFS client FS module |
| 39 | */ |
| 40 | static int __init afs_init(void) |
| 41 | { |
David Howells | 08e0e7c | 2007-04-26 15:55:03 -0700 | [diff] [blame] | 42 | int ret; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 43 | |
| 44 | printk(KERN_INFO "kAFS: Red Hat AFS client v0.1 registering.\n"); |
| 45 | |
Arnd Bergmann | b4db2b3 | 2017-02-10 16:34:07 +0000 | [diff] [blame] | 46 | generate_random_uuid((unsigned char *)&afs_uuid); |
David Howells | b908fe6 | 2007-04-26 15:58:17 -0700 | [diff] [blame] | 47 | |
Tejun Heo | 0ad53ee | 2011-01-14 15:56:37 +0000 | [diff] [blame] | 48 | /* create workqueue */ |
| 49 | ret = -ENOMEM; |
| 50 | afs_wq = alloc_workqueue("afs", 0, 0); |
| 51 | if (!afs_wq) |
| 52 | return ret; |
| 53 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 54 | /* register the /proc stuff */ |
| 55 | ret = afs_proc_init(); |
| 56 | if (ret < 0) |
Tejun Heo | 0ad53ee | 2011-01-14 15:56:37 +0000 | [diff] [blame] | 57 | goto error_proc; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 58 | |
David Howells | 9b3f26c | 2009-04-03 16:42:41 +0100 | [diff] [blame] | 59 | #ifdef CONFIG_AFS_FSCACHE |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 60 | /* we want to be able to cache */ |
David Howells | 9b3f26c | 2009-04-03 16:42:41 +0100 | [diff] [blame] | 61 | ret = fscache_register_netfs(&afs_cache_netfs); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 62 | if (ret < 0) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 63 | goto error_cache; |
| 64 | #endif |
| 65 | |
| 66 | /* initialise the cell DB */ |
| 67 | ret = afs_cell_init(rootcell); |
| 68 | if (ret < 0) |
David Howells | ec26815 | 2007-04-26 15:49:28 -0700 | [diff] [blame] | 69 | goto error_cell_init; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 70 | |
David Howells | 08e0e7c | 2007-04-26 15:55:03 -0700 | [diff] [blame] | 71 | /* initialise the VL update process */ |
| 72 | ret = afs_vlocation_update_init(); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 73 | if (ret < 0) |
David Howells | 08e0e7c | 2007-04-26 15:55:03 -0700 | [diff] [blame] | 74 | goto error_vl_update_init; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 75 | |
David Howells | 08e0e7c | 2007-04-26 15:55:03 -0700 | [diff] [blame] | 76 | /* initialise the callback update process */ |
| 77 | ret = afs_callback_update_init(); |
David Howells | df44f9f | 2010-08-06 17:26:48 +0100 | [diff] [blame] | 78 | if (ret < 0) |
| 79 | goto error_callback_update_init; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 80 | |
| 81 | /* create the RxRPC transport */ |
David Howells | 08e0e7c | 2007-04-26 15:55:03 -0700 | [diff] [blame] | 82 | ret = afs_open_socket(); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 83 | if (ret < 0) |
David Howells | 08e0e7c | 2007-04-26 15:55:03 -0700 | [diff] [blame] | 84 | goto error_open_socket; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 85 | |
| 86 | /* register the filesystems */ |
| 87 | ret = afs_fs_init(); |
| 88 | if (ret < 0) |
David Howells | ec26815 | 2007-04-26 15:49:28 -0700 | [diff] [blame] | 89 | goto error_fs; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 90 | |
| 91 | return ret; |
| 92 | |
David Howells | ec26815 | 2007-04-26 15:49:28 -0700 | [diff] [blame] | 93 | error_fs: |
David Howells | 08e0e7c | 2007-04-26 15:55:03 -0700 | [diff] [blame] | 94 | afs_close_socket(); |
| 95 | error_open_socket: |
David Howells | df44f9f | 2010-08-06 17:26:48 +0100 | [diff] [blame] | 96 | afs_callback_update_kill(); |
| 97 | error_callback_update_init: |
| 98 | afs_vlocation_purge(); |
David Howells | 08e0e7c | 2007-04-26 15:55:03 -0700 | [diff] [blame] | 99 | error_vl_update_init: |
David Howells | df44f9f | 2010-08-06 17:26:48 +0100 | [diff] [blame] | 100 | afs_cell_purge(); |
David Howells | ec26815 | 2007-04-26 15:49:28 -0700 | [diff] [blame] | 101 | error_cell_init: |
David Howells | 9b3f26c | 2009-04-03 16:42:41 +0100 | [diff] [blame] | 102 | #ifdef CONFIG_AFS_FSCACHE |
| 103 | fscache_unregister_netfs(&afs_cache_netfs); |
David Howells | ec26815 | 2007-04-26 15:49:28 -0700 | [diff] [blame] | 104 | error_cache: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 105 | #endif |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 106 | afs_proc_cleanup(); |
Tejun Heo | 0ad53ee | 2011-01-14 15:56:37 +0000 | [diff] [blame] | 107 | error_proc: |
| 108 | destroy_workqueue(afs_wq); |
David Howells | 416351f | 2007-05-09 02:33:45 -0700 | [diff] [blame] | 109 | rcu_barrier(); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 110 | printk(KERN_ERR "kAFS: failed to register: %d\n", ret); |
| 111 | return ret; |
David Howells | ec26815 | 2007-04-26 15:49:28 -0700 | [diff] [blame] | 112 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 113 | |
| 114 | /* XXX late_initcall is kludgy, but the only alternative seems to create |
| 115 | * a transport upon the first mount, which is worse. Or is it? |
| 116 | */ |
| 117 | late_initcall(afs_init); /* must be called after net/ to create socket */ |
David Howells | ec26815 | 2007-04-26 15:49:28 -0700 | [diff] [blame] | 118 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 119 | /* |
| 120 | * clean up on module removal |
| 121 | */ |
| 122 | static void __exit afs_exit(void) |
| 123 | { |
| 124 | printk(KERN_INFO "kAFS: Red Hat AFS client v0.1 unregistering.\n"); |
| 125 | |
| 126 | afs_fs_exit(); |
David Howells | e8d6c55 | 2007-07-15 23:40:12 -0700 | [diff] [blame] | 127 | afs_kill_lock_manager(); |
David Howells | 08e0e7c | 2007-04-26 15:55:03 -0700 | [diff] [blame] | 128 | afs_close_socket(); |
| 129 | afs_purge_servers(); |
| 130 | afs_callback_update_kill(); |
| 131 | afs_vlocation_purge(); |
Tejun Heo | 0ad53ee | 2011-01-14 15:56:37 +0000 | [diff] [blame] | 132 | destroy_workqueue(afs_wq); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 133 | afs_cell_purge(); |
David Howells | 9b3f26c | 2009-04-03 16:42:41 +0100 | [diff] [blame] | 134 | #ifdef CONFIG_AFS_FSCACHE |
| 135 | fscache_unregister_netfs(&afs_cache_netfs); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 136 | #endif |
| 137 | afs_proc_cleanup(); |
David Howells | 416351f | 2007-05-09 02:33:45 -0700 | [diff] [blame] | 138 | rcu_barrier(); |
David Howells | ec26815 | 2007-04-26 15:49:28 -0700 | [diff] [blame] | 139 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 140 | |
| 141 | module_exit(afs_exit); |