blob: 691c0000e9eae14c0d0dfd08b2969fa663252ed0 [file] [log] [blame]
Thomas Gleixner09c434b2019-05-19 13:08:20 +01001// SPDX-License-Identifier: GPL-2.0-only
Linus Torvalds1da177e2005-04-16 15:20:36 -07002/*
3 * linux/net/sunrpc/sunrpc_syms.c
4 *
5 * Symbols exported by the sunrpc module.
6 *
7 * Copyright (C) 1997 Olaf Kirch <okir@monad.swb.de>
8 */
9
Linus Torvalds1da177e2005-04-16 15:20:36 -070010#include <linux/module.h>
11
12#include <linux/types.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070013#include <linux/uio.h>
14#include <linux/unistd.h>
15#include <linux/init.h>
16
17#include <linux/sunrpc/sched.h>
18#include <linux/sunrpc/clnt.h>
19#include <linux/sunrpc/svc.h>
20#include <linux/sunrpc/svcsock.h>
21#include <linux/sunrpc/auth.h>
22#include <linux/workqueue.h>
23#include <linux/sunrpc/rpc_pipe_fs.h>
\"Talpey, Thomas\49c36fc2007-09-10 13:47:31 -040024#include <linux/sunrpc/xprtsock.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070025
NeilBrownf45db2b2020-05-22 12:01:32 +100026#include "sunrpc.h"
Olga Kornievskaia74678742021-06-08 15:59:10 -040027#include "sysfs.h"
Pavel Emelyanov2f72c9b2010-09-27 14:01:27 +040028#include "netns.h"
29
Alexey Dobriyanc7d03a02016-11-17 04:58:21 +030030unsigned int sunrpc_net_id;
Stanislav Kinsburskya1db4102012-01-19 21:42:37 +040031EXPORT_SYMBOL_GPL(sunrpc_net_id);
Pavel Emelyanov2f72c9b2010-09-27 14:01:27 +040032
33static __net_init int sunrpc_init_net(struct net *net)
34{
Pavel Emelyanov4f42d0d2010-09-27 14:01:58 +040035 int err;
Stanislav Kinsbursky70abc492012-01-12 22:07:51 +040036 struct sunrpc_net *sn = net_generic(net, sunrpc_net_id);
Pavel Emelyanov4f42d0d2010-09-27 14:01:58 +040037
38 err = rpc_proc_init(net);
39 if (err)
40 goto err_proc;
41
Pavel Emelyanov90d51b02010-09-27 14:02:29 +040042 err = ip_map_cache_create(net);
43 if (err)
44 goto err_ipmap;
45
Stanislav Kinsbursky73393232012-01-19 21:42:29 +040046 err = unix_gid_cache_create(net);
47 if (err)
48 goto err_unixgid;
49
Jeff Layton4b9a4452013-11-14 07:25:17 -050050 err = rpc_pipefs_init_net(net);
51 if (err)
52 goto err_pipefs;
53
Stanislav Kinsbursky70abc492012-01-12 22:07:51 +040054 INIT_LIST_HEAD(&sn->all_clients);
55 spin_lock_init(&sn->rpc_client_lock);
Stanislav Kinsbursky1d96e802012-02-16 17:42:12 +040056 spin_lock_init(&sn->rpcb_clnt_lock);
Pavel Emelyanov2f72c9b2010-09-27 14:01:27 +040057 return 0;
Pavel Emelyanov4f42d0d2010-09-27 14:01:58 +040058
Jeff Layton4b9a4452013-11-14 07:25:17 -050059err_pipefs:
60 unix_gid_cache_destroy(net);
Stanislav Kinsbursky73393232012-01-19 21:42:29 +040061err_unixgid:
62 ip_map_cache_destroy(net);
Pavel Emelyanov90d51b02010-09-27 14:02:29 +040063err_ipmap:
64 rpc_proc_exit(net);
Pavel Emelyanov4f42d0d2010-09-27 14:01:58 +040065err_proc:
66 return err;
Pavel Emelyanov2f72c9b2010-09-27 14:01:27 +040067}
68
69static __net_exit void sunrpc_exit_net(struct net *net)
70{
Vasily Averin4112be72017-11-12 11:48:43 +030071 struct sunrpc_net *sn = net_generic(net, sunrpc_net_id);
72
Jeff Layton4b9a4452013-11-14 07:25:17 -050073 rpc_pipefs_exit_net(net);
Stanislav Kinsbursky73393232012-01-19 21:42:29 +040074 unix_gid_cache_destroy(net);
Pavel Emelyanov90d51b02010-09-27 14:02:29 +040075 ip_map_cache_destroy(net);
Pavel Emelyanov4f42d0d2010-09-27 14:01:58 +040076 rpc_proc_exit(net);
Vasily Averin4112be72017-11-12 11:48:43 +030077 WARN_ON_ONCE(!list_empty(&sn->all_clients));
Pavel Emelyanov2f72c9b2010-09-27 14:01:27 +040078}
79
80static struct pernet_operations sunrpc_net_ops = {
81 .init = sunrpc_init_net,
82 .exit = sunrpc_exit_net,
83 .id = &sunrpc_net_id,
84 .size = sizeof(struct sunrpc_net),
85};
86
Linus Torvalds1da177e2005-04-16 15:20:36 -070087static int __init
88init_sunrpc(void)
89{
Stanislav Kinsburskyadae0fe2012-04-05 21:04:37 +040090 int err = rpc_init_mempool();
Linus Torvalds1da177e2005-04-16 15:20:36 -070091 if (err)
92 goto out;
Trond Myklebust5d8d9a42010-07-31 14:29:07 -040093 err = rpcauth_init_module();
94 if (err)
Stanislav Kinsburskyadae0fe2012-04-05 21:04:37 +040095 goto out2;
Pavel Emelyanov2f72c9b2010-09-27 14:01:27 +040096
97 cache_initialize();
98
99 err = register_pernet_subsys(&sunrpc_net_ops);
100 if (err)
Stanislav Kinsburskyadae0fe2012-04-05 21:04:37 +0400101 goto out3;
102
103 err = register_rpc_pipefs();
104 if (err)
Pavel Emelyanov2f72c9b2010-09-27 14:01:27 +0400105 goto out4;
Jeff Laytonb4b9d2c2014-11-26 14:44:43 -0500106
Olga Kornievskaia74678742021-06-08 15:59:10 -0400107 err = rpc_sysfs_init();
108 if (err)
109 goto out5;
110
Jeff Laytonf9c72d12015-03-31 12:03:28 -0400111 sunrpc_debugfs_init();
Jeff Laytonf895b252014-11-17 16:58:04 -0500112#if IS_ENABLED(CONFIG_SUNRPC_DEBUG)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700113 rpc_register_sysctl();
114#endif
Tom Tucker360d87382007-12-30 21:07:17 -0600115 svc_init_xprt_sock(); /* svc sock transport */
116 init_socket_xprt(); /* clnt sock transport */
Trond Myklebust5d8d9a42010-07-31 14:29:07 -0400117 return 0;
Pavel Emelyanov2f72c9b2010-09-27 14:01:27 +0400118
Olga Kornievskaia74678742021-06-08 15:59:10 -0400119out5:
120 unregister_rpc_pipefs();
Pavel Emelyanov2f72c9b2010-09-27 14:01:27 +0400121out4:
Stanislav Kinsburskyadae0fe2012-04-05 21:04:37 +0400122 unregister_pernet_subsys(&sunrpc_net_ops);
Trond Myklebust5d8d9a42010-07-31 14:29:07 -0400123out3:
Stanislav Kinsburskyadae0fe2012-04-05 21:04:37 +0400124 rpcauth_remove_module();
Trond Myklebust5d8d9a42010-07-31 14:29:07 -0400125out2:
Stanislav Kinsburskyadae0fe2012-04-05 21:04:37 +0400126 rpc_destroy_mempool();
Linus Torvalds1da177e2005-04-16 15:20:36 -0700127out:
128 return err;
129}
130
131static void __exit
132cleanup_sunrpc(void)
133{
Olga Kornievskaia74678742021-06-08 15:59:10 -0400134 rpc_sysfs_exit();
Kinglong Meec929ea02017-01-20 16:48:39 +0800135 rpc_cleanup_clids();
Olga Kornievskaia572caba2021-06-08 15:59:13 -0400136 xprt_cleanup_ids();
Olga Kornievskaia5b926872021-06-08 15:59:14 -0400137 xprt_multipath_cleanup_ids();
Trond Myklebustf5c21872007-06-25 17:11:20 -0400138 rpcauth_remove_module();
Chuck Lever282b32e2006-12-05 16:35:51 -0500139 cleanup_socket_xprt();
Tom Tucker360d87382007-12-30 21:07:17 -0600140 svc_cleanup_xprt_sock();
Jeff Laytonb4b9d2c2014-11-26 14:44:43 -0500141 sunrpc_debugfs_exit();
Linus Torvalds1da177e2005-04-16 15:20:36 -0700142 unregister_rpc_pipefs();
143 rpc_destroy_mempool();
Pavel Emelyanov2f72c9b2010-09-27 14:01:27 +0400144 unregister_pernet_subsys(&sunrpc_net_ops);
NeilBrownf45db2b2020-05-22 12:01:32 +1000145 auth_domain_cleanup();
Jeff Laytonf895b252014-11-17 16:58:04 -0500146#if IS_ENABLED(CONFIG_SUNRPC_DEBUG)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700147 rpc_unregister_sysctl();
148#endif
Jesper Dangaard Brouer75de8742009-06-26 10:45:58 +0000149 rcu_barrier(); /* Wait for completion of call_rcu()'s */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700150}
151MODULE_LICENSE("GPL");
Trond Myklebust405d8f82009-08-21 08:17:56 -0400152fs_initcall(init_sunrpc); /* Ensure we're initialised before nfs */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700153module_exit(cleanup_sunrpc);