blob: 38e15b1f0eec708a1caca03a1af9f7e30d5dec02 [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 ([email protected])
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
Tejun Heo0ad53ee2011-01-14 15:56:37 +000034struct workqueue_struct *afs_wq;
David Howellsf044c882017-11-02 15:27:45 +000035struct afs_net __afs_net;
36
37/*
38 * Initialise an AFS network namespace record.
39 */
40static int __net_init afs_net_init(struct afs_net *net)
41{
42 int ret;
43
44 net->live = true;
45 generate_random_uuid((unsigned char *)&net->uuid);
46
47 INIT_WORK(&net->charge_preallocation_work, afs_charge_preallocation);
48 mutex_init(&net->socket_mutex);
49 INIT_LIST_HEAD(&net->cells);
50 rwlock_init(&net->cells_lock);
51 init_rwsem(&net->cells_sem);
52 init_waitqueue_head(&net->cells_freeable_wq);
53 init_rwsem(&net->proc_cells_sem);
54 INIT_LIST_HEAD(&net->proc_cells);
55 INIT_LIST_HEAD(&net->vl_updates);
56 INIT_LIST_HEAD(&net->vl_graveyard);
57 INIT_DELAYED_WORK(&net->vl_reaper, afs_vlocation_reaper);
58 INIT_DELAYED_WORK(&net->vl_updater, afs_vlocation_updater);
59 spin_lock_init(&net->vl_updates_lock);
60 spin_lock_init(&net->vl_graveyard_lock);
61 net->servers = RB_ROOT;
62 rwlock_init(&net->servers_lock);
63 INIT_LIST_HEAD(&net->server_graveyard);
64 spin_lock_init(&net->server_graveyard_lock);
David Howells59fa1c4a2017-11-02 15:27:45 +000065 INIT_WORK(&net->server_reaper, afs_reap_server);
66 timer_setup(&net->server_timer, afs_server_timer, 0);
David Howellsf044c882017-11-02 15:27:45 +000067
68 /* Register the /proc stuff */
69 ret = afs_proc_init(net);
70 if (ret < 0)
71 goto error_proc;
72
73 /* Initialise the cell DB */
74 ret = afs_cell_init(net, rootcell);
75 if (ret < 0)
76 goto error_cell_init;
77
78 /* Create the RxRPC transport */
79 ret = afs_open_socket(net);
80 if (ret < 0)
81 goto error_open_socket;
82
83 return 0;
84
85error_open_socket:
86 afs_vlocation_purge(net);
87 afs_cell_purge(net);
88error_cell_init:
89 afs_proc_cleanup(net);
90error_proc:
91 return ret;
92}
93
94/*
95 * Clean up and destroy an AFS network namespace record.
96 */
97static void __net_exit afs_net_exit(struct afs_net *net)
98{
99 net->live = false;
David Howellsf044c882017-11-02 15:27:45 +0000100 afs_purge_servers(net);
101 afs_vlocation_purge(net);
102 afs_cell_purge(net);
David Howellse3b2ffe2017-11-02 15:27:45 +0000103 afs_close_socket(net);
David Howellsf044c882017-11-02 15:27:45 +0000104 afs_proc_cleanup(net);
105}
David Howellsb908fe62007-04-26 15:58:17 -0700106
107/*
Linus Torvalds1da177e2005-04-16 15:20:36 -0700108 * initialise the AFS client FS module
109 */
110static int __init afs_init(void)
111{
David Howellsf044c882017-11-02 15:27:45 +0000112 int ret = -ENOMEM;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700113
114 printk(KERN_INFO "kAFS: Red Hat AFS client v0.1 registering.\n");
115
Tejun Heo0ad53ee2011-01-14 15:56:37 +0000116 afs_wq = alloc_workqueue("afs", 0, 0);
117 if (!afs_wq)
David Howellsf044c882017-11-02 15:27:45 +0000118 goto error_afs_wq;
119 afs_async_calls = alloc_workqueue("kafsd", WQ_MEM_RECLAIM, 0);
120 if (!afs_async_calls)
121 goto error_async;
122 afs_vlocation_update_worker =
123 alloc_workqueue("kafs_vlupdated", WQ_MEM_RECLAIM, 0);
124 if (!afs_vlocation_update_worker)
125 goto error_vl_up;
126 afs_callback_update_worker =
127 alloc_ordered_workqueue("kafs_callbackd", WQ_MEM_RECLAIM);
128 if (!afs_callback_update_worker)
129 goto error_callback;
130 afs_lock_manager = alloc_workqueue("kafs_lockd", WQ_MEM_RECLAIM, 0);
131 if (!afs_lock_manager)
132 goto error_lockmgr;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700133
David Howells9b3f26c2009-04-03 16:42:41 +0100134#ifdef CONFIG_AFS_FSCACHE
Linus Torvalds1da177e2005-04-16 15:20:36 -0700135 /* we want to be able to cache */
David Howells9b3f26c2009-04-03 16:42:41 +0100136 ret = fscache_register_netfs(&afs_cache_netfs);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700137 if (ret < 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700138 goto error_cache;
139#endif
140
David Howellsf044c882017-11-02 15:27:45 +0000141 ret = afs_net_init(&__afs_net);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700142 if (ret < 0)
David Howellsf044c882017-11-02 15:27:45 +0000143 goto error_net;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700144
145 /* register the filesystems */
146 ret = afs_fs_init();
147 if (ret < 0)
David Howellsec268152007-04-26 15:49:28 -0700148 goto error_fs;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700149
150 return ret;
151
David Howellsec268152007-04-26 15:49:28 -0700152error_fs:
David Howellsf044c882017-11-02 15:27:45 +0000153 afs_net_exit(&__afs_net);
154error_net:
David Howells9b3f26c2009-04-03 16:42:41 +0100155#ifdef CONFIG_AFS_FSCACHE
156 fscache_unregister_netfs(&afs_cache_netfs);
David Howellsec268152007-04-26 15:49:28 -0700157error_cache:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700158#endif
David Howellsf044c882017-11-02 15:27:45 +0000159 destroy_workqueue(afs_lock_manager);
160error_lockmgr:
161 destroy_workqueue(afs_callback_update_worker);
162error_callback:
163 destroy_workqueue(afs_vlocation_update_worker);
164error_vl_up:
165 destroy_workqueue(afs_async_calls);
166error_async:
Tejun Heo0ad53ee2011-01-14 15:56:37 +0000167 destroy_workqueue(afs_wq);
David Howellsf044c882017-11-02 15:27:45 +0000168error_afs_wq:
David Howells416351f2007-05-09 02:33:45 -0700169 rcu_barrier();
Linus Torvalds1da177e2005-04-16 15:20:36 -0700170 printk(KERN_ERR "kAFS: failed to register: %d\n", ret);
171 return ret;
David Howellsec268152007-04-26 15:49:28 -0700172}
Linus Torvalds1da177e2005-04-16 15:20:36 -0700173
174/* XXX late_initcall is kludgy, but the only alternative seems to create
175 * a transport upon the first mount, which is worse. Or is it?
176 */
177late_initcall(afs_init); /* must be called after net/ to create socket */
David Howellsec268152007-04-26 15:49:28 -0700178
Linus Torvalds1da177e2005-04-16 15:20:36 -0700179/*
180 * clean up on module removal
181 */
182static void __exit afs_exit(void)
183{
184 printk(KERN_INFO "kAFS: Red Hat AFS client v0.1 unregistering.\n");
185
186 afs_fs_exit();
David Howellsf044c882017-11-02 15:27:45 +0000187 afs_net_exit(&__afs_net);
David Howells9b3f26c2009-04-03 16:42:41 +0100188#ifdef CONFIG_AFS_FSCACHE
189 fscache_unregister_netfs(&afs_cache_netfs);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700190#endif
David Howellsf044c882017-11-02 15:27:45 +0000191 destroy_workqueue(afs_lock_manager);
192 destroy_workqueue(afs_callback_update_worker);
193 destroy_workqueue(afs_vlocation_update_worker);
194 destroy_workqueue(afs_async_calls);
195 destroy_workqueue(afs_wq);
David Howells416351f2007-05-09 02:33:45 -0700196 rcu_barrier();
David Howellsec268152007-04-26 15:49:28 -0700197}
Linus Torvalds1da177e2005-04-16 15:20:36 -0700198
199module_exit(afs_exit);