blob: 9944770849da20613af2c315d3f682f068d5f6c7 [file] [log] [blame]
David Howellsec268152007-04-26 15:49:28 -07001/* AFS client file system
Linus Torvalds1da177e2005-04-16 15:20:36 -07002 *
David Howells9b3f26c2009-04-03 16:42:41 +01003 * Copyright (C) 2002,5 Red Hat, Inc. All Rights Reserved.
Linus Torvalds1da177e2005-04-16 15:20:36 -07004 * 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>
Alexey Dobriyane8edc6e2007-05-21 01:22:52 +040016#include <linux/sched.h>
David Howellse0661df2016-08-30 16:05:14 +010017#include <linux/random.h>
David Howells8e8d7f12017-01-05 10:38:34 +000018#define CREATE_TRACE_POINTS
Linus Torvalds1da177e2005-04-16 15:20:36 -070019#include "internal.h"
20
Linus Torvalds1da177e2005-04-16 15:20:36 -070021MODULE_DESCRIPTION("AFS Client File System");
22MODULE_AUTHOR("Red Hat, Inc.");
23MODULE_LICENSE("GPL");
24
David Howells08e0e7c2007-04-26 15:55:03 -070025unsigned afs_debug;
26module_param_named(debug, afs_debug, uint, S_IWUSR | S_IRUGO);
Paul Bolle424b00e2008-04-16 11:08:22 +010027MODULE_PARM_DESC(debug, "AFS debugging mask");
David Howells08e0e7c2007-04-26 15:55:03 -070028
Linus Torvalds1da177e2005-04-16 15:20:36 -070029static char *rootcell;
30
31module_param(rootcell, charp, 0);
32MODULE_PARM_DESC(rootcell, "root AFS cell name and VL server IP addr list");
33
Christoph Hellwig41bb26f2017-05-28 08:56:46 +030034struct afs_uuid afs_uuid;
Tejun Heo0ad53ee2011-01-14 15:56:37 +000035struct workqueue_struct *afs_wq;
David Howellsb908fe62007-04-26 15:58:17 -070036
37/*
Linus Torvalds1da177e2005-04-16 15:20:36 -070038 * initialise the AFS client FS module
39 */
40static int __init afs_init(void)
41{
David Howells08e0e7c2007-04-26 15:55:03 -070042 int ret;
Linus Torvalds1da177e2005-04-16 15:20:36 -070043
44 printk(KERN_INFO "kAFS: Red Hat AFS client v0.1 registering.\n");
45
Arnd Bergmannb4db2b32017-02-10 16:34:07 +000046 generate_random_uuid((unsigned char *)&afs_uuid);
David Howellsb908fe62007-04-26 15:58:17 -070047
Tejun Heo0ad53ee2011-01-14 15:56:37 +000048 /* create workqueue */
49 ret = -ENOMEM;
50 afs_wq = alloc_workqueue("afs", 0, 0);
51 if (!afs_wq)
52 return ret;
53
Linus Torvalds1da177e2005-04-16 15:20:36 -070054 /* register the /proc stuff */
55 ret = afs_proc_init();
56 if (ret < 0)
Tejun Heo0ad53ee2011-01-14 15:56:37 +000057 goto error_proc;
Linus Torvalds1da177e2005-04-16 15:20:36 -070058
David Howells9b3f26c2009-04-03 16:42:41 +010059#ifdef CONFIG_AFS_FSCACHE
Linus Torvalds1da177e2005-04-16 15:20:36 -070060 /* we want to be able to cache */
David Howells9b3f26c2009-04-03 16:42:41 +010061 ret = fscache_register_netfs(&afs_cache_netfs);
Linus Torvalds1da177e2005-04-16 15:20:36 -070062 if (ret < 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -070063 goto error_cache;
64#endif
65
66 /* initialise the cell DB */
67 ret = afs_cell_init(rootcell);
68 if (ret < 0)
David Howellsec268152007-04-26 15:49:28 -070069 goto error_cell_init;
Linus Torvalds1da177e2005-04-16 15:20:36 -070070
David Howells08e0e7c2007-04-26 15:55:03 -070071 /* initialise the VL update process */
72 ret = afs_vlocation_update_init();
Linus Torvalds1da177e2005-04-16 15:20:36 -070073 if (ret < 0)
David Howells08e0e7c2007-04-26 15:55:03 -070074 goto error_vl_update_init;
Linus Torvalds1da177e2005-04-16 15:20:36 -070075
David Howells08e0e7c2007-04-26 15:55:03 -070076 /* initialise the callback update process */
77 ret = afs_callback_update_init();
David Howellsdf44f9f2010-08-06 17:26:48 +010078 if (ret < 0)
79 goto error_callback_update_init;
Linus Torvalds1da177e2005-04-16 15:20:36 -070080
81 /* create the RxRPC transport */
David Howells08e0e7c2007-04-26 15:55:03 -070082 ret = afs_open_socket();
Linus Torvalds1da177e2005-04-16 15:20:36 -070083 if (ret < 0)
David Howells08e0e7c2007-04-26 15:55:03 -070084 goto error_open_socket;
Linus Torvalds1da177e2005-04-16 15:20:36 -070085
86 /* register the filesystems */
87 ret = afs_fs_init();
88 if (ret < 0)
David Howellsec268152007-04-26 15:49:28 -070089 goto error_fs;
Linus Torvalds1da177e2005-04-16 15:20:36 -070090
91 return ret;
92
David Howellsec268152007-04-26 15:49:28 -070093error_fs:
David Howells08e0e7c2007-04-26 15:55:03 -070094 afs_close_socket();
95error_open_socket:
David Howellsdf44f9f2010-08-06 17:26:48 +010096 afs_callback_update_kill();
97error_callback_update_init:
98 afs_vlocation_purge();
David Howells08e0e7c2007-04-26 15:55:03 -070099error_vl_update_init:
David Howellsdf44f9f2010-08-06 17:26:48 +0100100 afs_cell_purge();
David Howellsec268152007-04-26 15:49:28 -0700101error_cell_init:
David Howells9b3f26c2009-04-03 16:42:41 +0100102#ifdef CONFIG_AFS_FSCACHE
103 fscache_unregister_netfs(&afs_cache_netfs);
David Howellsec268152007-04-26 15:49:28 -0700104error_cache:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700105#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -0700106 afs_proc_cleanup();
Tejun Heo0ad53ee2011-01-14 15:56:37 +0000107error_proc:
108 destroy_workqueue(afs_wq);
David Howells416351f2007-05-09 02:33:45 -0700109 rcu_barrier();
Linus Torvalds1da177e2005-04-16 15:20:36 -0700110 printk(KERN_ERR "kAFS: failed to register: %d\n", ret);
111 return ret;
David Howellsec268152007-04-26 15:49:28 -0700112}
Linus Torvalds1da177e2005-04-16 15:20:36 -0700113
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 */
117late_initcall(afs_init); /* must be called after net/ to create socket */
David Howellsec268152007-04-26 15:49:28 -0700118
Linus Torvalds1da177e2005-04-16 15:20:36 -0700119/*
120 * clean up on module removal
121 */
122static 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 Howellse8d6c552007-07-15 23:40:12 -0700127 afs_kill_lock_manager();
David Howells08e0e7c2007-04-26 15:55:03 -0700128 afs_close_socket();
129 afs_purge_servers();
130 afs_callback_update_kill();
131 afs_vlocation_purge();
Tejun Heo0ad53ee2011-01-14 15:56:37 +0000132 destroy_workqueue(afs_wq);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700133 afs_cell_purge();
David Howells9b3f26c2009-04-03 16:42:41 +0100134#ifdef CONFIG_AFS_FSCACHE
135 fscache_unregister_netfs(&afs_cache_netfs);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700136#endif
137 afs_proc_cleanup();
David Howells416351f2007-05-09 02:33:45 -0700138 rcu_barrier();
David Howellsec268152007-04-26 15:49:28 -0700139}
Linus Torvalds1da177e2005-04-16 15:20:36 -0700140
141module_exit(afs_exit);