sunrpc_syms.c 2.79 KB
Newer Older
1
// SPDX-License-Identifier: GPL-2.0-only
Linus Torvalds's avatar
Linus Torvalds committed
2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23
/*
 * linux/net/sunrpc/sunrpc_syms.c
 *
 * Symbols exported by the sunrpc module.
 *
 * Copyright (C) 1997 Olaf Kirch <okir@monad.swb.de>
 */

#include <linux/module.h>

#include <linux/types.h>
#include <linux/uio.h>
#include <linux/unistd.h>
#include <linux/init.h>

#include <linux/sunrpc/sched.h>
#include <linux/sunrpc/clnt.h>
#include <linux/sunrpc/svc.h>
#include <linux/sunrpc/svcsock.h>
#include <linux/sunrpc/auth.h>
#include <linux/workqueue.h>
#include <linux/sunrpc/rpc_pipe_fs.h>
24
#include <linux/sunrpc/xprtsock.h>
Linus Torvalds's avatar
Linus Torvalds committed
25

26 27
#include "netns.h"

28
unsigned int sunrpc_net_id;
29
EXPORT_SYMBOL_GPL(sunrpc_net_id);
30 31 32

static __net_init int sunrpc_init_net(struct net *net)
{
33
	int err;
34
	struct sunrpc_net *sn = net_generic(net, sunrpc_net_id);
35 36 37 38 39

	err = rpc_proc_init(net);
	if (err)
		goto err_proc;

40 41 42 43
	err = ip_map_cache_create(net);
	if (err)
		goto err_ipmap;

44 45 46 47
	err = unix_gid_cache_create(net);
	if (err)
		goto err_unixgid;

48 49 50 51
	err = rpc_pipefs_init_net(net);
	if (err)
		goto err_pipefs;

52 53
	INIT_LIST_HEAD(&sn->all_clients);
	spin_lock_init(&sn->rpc_client_lock);
54
	spin_lock_init(&sn->rpcb_clnt_lock);
55
	return 0;
56

57 58
err_pipefs:
	unix_gid_cache_destroy(net);
59 60
err_unixgid:
	ip_map_cache_destroy(net);
61 62
err_ipmap:
	rpc_proc_exit(net);
63 64
err_proc:
	return err;
65 66 67 68
}

static __net_exit void sunrpc_exit_net(struct net *net)
{
69 70
	struct sunrpc_net *sn = net_generic(net, sunrpc_net_id);

71
	rpc_pipefs_exit_net(net);
72
	unix_gid_cache_destroy(net);
73
	ip_map_cache_destroy(net);
74
	rpc_proc_exit(net);
75
	WARN_ON_ONCE(!list_empty(&sn->all_clients));
76 77 78 79 80 81 82 83 84
}

static struct pernet_operations sunrpc_net_ops = {
	.init = sunrpc_init_net,
	.exit = sunrpc_exit_net,
	.id = &sunrpc_net_id,
	.size = sizeof(struct sunrpc_net),
};

Linus Torvalds's avatar
Linus Torvalds committed
85 86 87
static int __init
init_sunrpc(void)
{
88
	int err = rpc_init_mempool();
Linus Torvalds's avatar
Linus Torvalds committed
89 90
	if (err)
		goto out;
91 92
	err = rpcauth_init_module();
	if (err)
93
		goto out2;
94 95 96 97

	cache_initialize();

	err = register_pernet_subsys(&sunrpc_net_ops);
98 99 100 101
	if (err)
		goto out3;

	err = register_rpc_pipefs();
102 103
	if (err)
		goto out4;
104

105
	sunrpc_debugfs_init();
106
#if IS_ENABLED(CONFIG_SUNRPC_DEBUG)
Linus Torvalds's avatar
Linus Torvalds committed
107 108
	rpc_register_sysctl();
#endif
109 110
	svc_init_xprt_sock();	/* svc sock transport */
	init_socket_xprt();	/* clnt sock transport */
111
	return 0;
112 113

out4:
114
	unregister_pernet_subsys(&sunrpc_net_ops);
115
out3:
116
	rpcauth_remove_module();
117
out2:
118
	rpc_destroy_mempool();
Linus Torvalds's avatar
Linus Torvalds committed
119 120 121 122 123 124 125
out:
	return err;
}

static void __exit
cleanup_sunrpc(void)
{
126
	rpc_cleanup_clids();
127
	rpcauth_remove_module();
128
	cleanup_socket_xprt();
129
	svc_cleanup_xprt_sock();
130
	sunrpc_debugfs_exit();
Linus Torvalds's avatar
Linus Torvalds committed
131 132
	unregister_rpc_pipefs();
	rpc_destroy_mempool();
133
	unregister_pernet_subsys(&sunrpc_net_ops);
134
#if IS_ENABLED(CONFIG_SUNRPC_DEBUG)
Linus Torvalds's avatar
Linus Torvalds committed
135 136
	rpc_unregister_sysctl();
#endif
137
	rcu_barrier(); /* Wait for completion of call_rcu()'s */
Linus Torvalds's avatar
Linus Torvalds committed
138 139
}
MODULE_LICENSE("GPL");
140
fs_initcall(init_sunrpc); /* Ensure we're initialised before nfs */
Linus Torvalds's avatar
Linus Torvalds committed
141
module_exit(cleanup_sunrpc);