blob: 0cf1b021ad543238fd8787fdf826d81b25d87630 [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
Linus Torvalds1da177e2005-04-16 15:20:36 -070043/*
44 * initialise the AFS client FS module
45 */
46static int __init afs_init(void)
47{
David Howells08e0e7c2007-04-26 15:55:03 -070048 int ret;
Linus Torvalds1da177e2005-04-16 15:20:36 -070049
50 printk(KERN_INFO "kAFS: Red Hat AFS client v0.1 registering.\n");
51
Linus Torvalds1da177e2005-04-16 15:20:36 -070052 /* 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 Torvalds1da177e2005-04-16 15:20:36 -070062 goto error_cache;
63#endif
64
65 /* initialise the cell DB */
66 ret = afs_cell_init(rootcell);
67 if (ret < 0)
David Howellsec268152007-04-26 15:49:28 -070068 goto error_cell_init;
Linus Torvalds1da177e2005-04-16 15:20:36 -070069
David Howells08e0e7c2007-04-26 15:55:03 -070070 /* initialise the VL update process */
71 ret = afs_vlocation_update_init();
Linus Torvalds1da177e2005-04-16 15:20:36 -070072 if (ret < 0)
David Howells08e0e7c2007-04-26 15:55:03 -070073 goto error_vl_update_init;
Linus Torvalds1da177e2005-04-16 15:20:36 -070074
David Howells08e0e7c2007-04-26 15:55:03 -070075 /* initialise the callback update process */
76 ret = afs_callback_update_init();
Linus Torvalds1da177e2005-04-16 15:20:36 -070077
78 /* create the RxRPC transport */
David Howells08e0e7c2007-04-26 15:55:03 -070079 ret = afs_open_socket();
Linus Torvalds1da177e2005-04-16 15:20:36 -070080 if (ret < 0)
David Howells08e0e7c2007-04-26 15:55:03 -070081 goto error_open_socket;
Linus Torvalds1da177e2005-04-16 15:20:36 -070082
83 /* register the filesystems */
84 ret = afs_fs_init();
85 if (ret < 0)
David Howellsec268152007-04-26 15:49:28 -070086 goto error_fs;
Linus Torvalds1da177e2005-04-16 15:20:36 -070087
88 return ret;
89
David Howellsec268152007-04-26 15:49:28 -070090error_fs:
David Howells08e0e7c2007-04-26 15:55:03 -070091 afs_close_socket();
92error_open_socket:
93error_vl_update_init:
David Howellsec268152007-04-26 15:49:28 -070094error_cell_init:
Linus Torvalds1da177e2005-04-16 15:20:36 -070095#ifdef AFS_CACHING_SUPPORT
96 cachefs_unregister_netfs(&afs_cache_netfs);
David Howellsec268152007-04-26 15:49:28 -070097error_cache:
Linus Torvalds1da177e2005-04-16 15:20:36 -070098#endif
David Howells08e0e7c2007-04-26 15:55:03 -070099 afs_callback_update_kill();
100 afs_vlocation_purge();
Linus Torvalds1da177e2005-04-16 15:20:36 -0700101 afs_cell_purge();
102 afs_proc_cleanup();
103 printk(KERN_ERR "kAFS: failed to register: %d\n", ret);
104 return ret;
David Howellsec268152007-04-26 15:49:28 -0700105}
Linus Torvalds1da177e2005-04-16 15:20:36 -0700106
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 */
110late_initcall(afs_init); /* must be called after net/ to create socket */
David Howellsec268152007-04-26 15:49:28 -0700111
Linus Torvalds1da177e2005-04-16 15:20:36 -0700112/*
113 * clean up on module removal
114 */
115static 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 Howells08e0e7c2007-04-26 15:55:03 -0700120 afs_close_socket();
121 afs_purge_servers();
122 afs_callback_update_kill();
123 afs_vlocation_purge();
124 flush_scheduled_work();
Linus Torvalds1da177e2005-04-16 15:20:36 -0700125 afs_cell_purge();
Linus Torvalds1da177e2005-04-16 15:20:36 -0700126#ifdef AFS_CACHING_SUPPORT
127 cachefs_unregister_netfs(&afs_cache_netfs);
128#endif
129 afs_proc_cleanup();
David Howellsec268152007-04-26 15:49:28 -0700130}
Linus Torvalds1da177e2005-04-16 15:20:36 -0700131
132module_exit(afs_exit);