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 | * |
| 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 Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 15 | #include <linux/completion.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 16 | #include "internal.h" |
| 17 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 18 | MODULE_DESCRIPTION("AFS Client File System"); |
| 19 | MODULE_AUTHOR("Red Hat, Inc."); |
| 20 | MODULE_LICENSE("GPL"); |
| 21 | |
David Howells | 08e0e7c | 2007-04-26 15:55:03 -0700 | [diff] [blame] | 22 | unsigned afs_debug; |
| 23 | module_param_named(debug, afs_debug, uint, S_IWUSR | S_IRUGO); |
| 24 | MODULE_PARM_DESC(afs_debug, "AFS debugging mask"); |
| 25 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 26 | static char *rootcell; |
| 27 | |
| 28 | module_param(rootcell, charp, 0); |
| 29 | MODULE_PARM_DESC(rootcell, "root AFS cell name and VL server IP addr list"); |
| 30 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 31 | #ifdef AFS_CACHING_SUPPORT |
| 32 | static struct cachefs_netfs_operations afs_cache_ops = { |
| 33 | .get_page_cookie = afs_cache_get_page_cookie, |
| 34 | }; |
| 35 | |
| 36 | struct cachefs_netfs afs_cache_netfs = { |
| 37 | .name = "afs", |
| 38 | .version = 0, |
| 39 | .ops = &afs_cache_ops, |
| 40 | }; |
| 41 | #endif |
| 42 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 43 | /* |
| 44 | * initialise the AFS client FS module |
| 45 | */ |
| 46 | static int __init afs_init(void) |
| 47 | { |
David Howells | 08e0e7c | 2007-04-26 15:55:03 -0700 | [diff] [blame] | 48 | int ret; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 49 | |
| 50 | printk(KERN_INFO "kAFS: Red Hat AFS client v0.1 registering.\n"); |
| 51 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 52 | /* register the /proc stuff */ |
| 53 | ret = afs_proc_init(); |
| 54 | if (ret < 0) |
| 55 | return ret; |
| 56 | |
| 57 | #ifdef AFS_CACHING_SUPPORT |
| 58 | /* we want to be able to cache */ |
| 59 | ret = cachefs_register_netfs(&afs_cache_netfs, |
| 60 | &afs_cache_cell_index_def); |
| 61 | if (ret < 0) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 62 | goto error_cache; |
| 63 | #endif |
| 64 | |
| 65 | /* initialise the cell DB */ |
| 66 | ret = afs_cell_init(rootcell); |
| 67 | if (ret < 0) |
David Howells | ec26815 | 2007-04-26 15:49:28 -0700 | [diff] [blame] | 68 | goto error_cell_init; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 69 | |
David Howells | 08e0e7c | 2007-04-26 15:55:03 -0700 | [diff] [blame] | 70 | /* initialise the VL update process */ |
| 71 | ret = afs_vlocation_update_init(); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 72 | if (ret < 0) |
David Howells | 08e0e7c | 2007-04-26 15:55:03 -0700 | [diff] [blame] | 73 | goto error_vl_update_init; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 74 | |
David Howells | 08e0e7c | 2007-04-26 15:55:03 -0700 | [diff] [blame] | 75 | /* initialise the callback update process */ |
| 76 | ret = afs_callback_update_init(); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 77 | |
| 78 | /* create the RxRPC transport */ |
David Howells | 08e0e7c | 2007-04-26 15:55:03 -0700 | [diff] [blame] | 79 | ret = afs_open_socket(); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 80 | if (ret < 0) |
David Howells | 08e0e7c | 2007-04-26 15:55:03 -0700 | [diff] [blame] | 81 | goto error_open_socket; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 82 | |
| 83 | /* register the filesystems */ |
| 84 | ret = afs_fs_init(); |
| 85 | if (ret < 0) |
David Howells | ec26815 | 2007-04-26 15:49:28 -0700 | [diff] [blame] | 86 | goto error_fs; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 87 | |
| 88 | return ret; |
| 89 | |
David Howells | ec26815 | 2007-04-26 15:49:28 -0700 | [diff] [blame] | 90 | error_fs: |
David Howells | 08e0e7c | 2007-04-26 15:55:03 -0700 | [diff] [blame] | 91 | afs_close_socket(); |
| 92 | error_open_socket: |
| 93 | error_vl_update_init: |
David Howells | ec26815 | 2007-04-26 15:49:28 -0700 | [diff] [blame] | 94 | error_cell_init: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 95 | #ifdef AFS_CACHING_SUPPORT |
| 96 | cachefs_unregister_netfs(&afs_cache_netfs); |
David Howells | ec26815 | 2007-04-26 15:49:28 -0700 | [diff] [blame] | 97 | error_cache: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 98 | #endif |
David Howells | 08e0e7c | 2007-04-26 15:55:03 -0700 | [diff] [blame] | 99 | afs_callback_update_kill(); |
| 100 | afs_vlocation_purge(); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 101 | afs_cell_purge(); |
| 102 | afs_proc_cleanup(); |
| 103 | printk(KERN_ERR "kAFS: failed to register: %d\n", ret); |
| 104 | return ret; |
David Howells | ec26815 | 2007-04-26 15:49:28 -0700 | [diff] [blame] | 105 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 106 | |
| 107 | /* XXX late_initcall is kludgy, but the only alternative seems to create |
| 108 | * a transport upon the first mount, which is worse. Or is it? |
| 109 | */ |
| 110 | late_initcall(afs_init); /* must be called after net/ to create socket */ |
David Howells | ec26815 | 2007-04-26 15:49:28 -0700 | [diff] [blame] | 111 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 112 | /* |
| 113 | * clean up on module removal |
| 114 | */ |
| 115 | static void __exit afs_exit(void) |
| 116 | { |
| 117 | printk(KERN_INFO "kAFS: Red Hat AFS client v0.1 unregistering.\n"); |
| 118 | |
| 119 | afs_fs_exit(); |
David Howells | 08e0e7c | 2007-04-26 15:55:03 -0700 | [diff] [blame] | 120 | afs_close_socket(); |
| 121 | afs_purge_servers(); |
| 122 | afs_callback_update_kill(); |
| 123 | afs_vlocation_purge(); |
| 124 | flush_scheduled_work(); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 125 | afs_cell_purge(); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 126 | #ifdef AFS_CACHING_SUPPORT |
| 127 | cachefs_unregister_netfs(&afs_cache_netfs); |
| 128 | #endif |
| 129 | afs_proc_cleanup(); |
David Howells | ec26815 | 2007-04-26 15:49:28 -0700 | [diff] [blame] | 130 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 131 | |
| 132 | module_exit(afs_exit); |