| 1 | // SPDX-License-Identifier: GPL-2.0-only | 
|---|---|
| 2 | /* | 
| 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 | |
| 10 | #include <linux/module.h> | 
| 11 | |
| 12 | #include <linux/types.h> | 
| 13 | #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> | 
| 24 | #include <linux/sunrpc/xprtsock.h> | 
| 25 | |
| 26 | #include "sunrpc.h" | 
| 27 | #include "sysfs.h" | 
| 28 | #include "netns.h" | 
| 29 | |
| 30 | unsigned int sunrpc_net_id; | 
| 31 | EXPORT_SYMBOL_GPL(sunrpc_net_id); | 
| 32 | |
| 33 | static __net_init int sunrpc_init_net(struct net *net) | 
| 34 | { | 
| 35 | int err; | 
| 36 | struct sunrpc_net *sn = net_generic(net, id: sunrpc_net_id); | 
| 37 | |
| 38 | err = rpc_proc_init(net); | 
| 39 | if (err) | 
| 40 | goto err_proc; | 
| 41 | |
| 42 | err = ip_map_cache_create(net); | 
| 43 | if (err) | 
| 44 | goto err_ipmap; | 
| 45 | |
| 46 | err = unix_gid_cache_create(net); | 
| 47 | if (err) | 
| 48 | goto err_unixgid; | 
| 49 | |
| 50 | err = rpc_pipefs_init_net(net); | 
| 51 | if (err) | 
| 52 | goto err_pipefs; | 
| 53 | |
| 54 | INIT_LIST_HEAD(list: &sn->all_clients); | 
| 55 | spin_lock_init(&sn->rpc_client_lock); | 
| 56 | spin_lock_init(&sn->rpcb_clnt_lock); | 
| 57 | return 0; | 
| 58 | |
| 59 | err_pipefs: | 
| 60 | unix_gid_cache_destroy(net); | 
| 61 | err_unixgid: | 
| 62 | ip_map_cache_destroy(net); | 
| 63 | err_ipmap: | 
| 64 | rpc_proc_exit(net); | 
| 65 | err_proc: | 
| 66 | return err; | 
| 67 | } | 
| 68 | |
| 69 | static __net_exit void sunrpc_exit_net(struct net *net) | 
| 70 | { | 
| 71 | struct sunrpc_net *sn = net_generic(net, id: sunrpc_net_id); | 
| 72 | |
| 73 | rpc_pipefs_exit_net(net); | 
| 74 | unix_gid_cache_destroy(net); | 
| 75 | ip_map_cache_destroy(net); | 
| 76 | rpc_proc_exit(net); | 
| 77 | WARN_ON_ONCE(!list_empty(&sn->all_clients)); | 
| 78 | } | 
| 79 | |
| 80 | static 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 | |
| 87 | static int __init | 
| 88 | init_sunrpc(void) | 
| 89 | { | 
| 90 | int err = rpc_init_mempool(); | 
| 91 | if (err) | 
| 92 | goto out; | 
| 93 | err = rpcauth_init_module(); | 
| 94 | if (err) | 
| 95 | goto out2; | 
| 96 | |
| 97 | cache_initialize(); | 
| 98 | |
| 99 | err = register_pernet_subsys(&sunrpc_net_ops); | 
| 100 | if (err) | 
| 101 | goto out3; | 
| 102 | |
| 103 | err = register_rpc_pipefs(); | 
| 104 | if (err) | 
| 105 | goto out4; | 
| 106 | |
| 107 | err = rpc_sysfs_init(); | 
| 108 | if (err) | 
| 109 | goto out5; | 
| 110 | |
| 111 | sunrpc_debugfs_init(); | 
| 112 | #if IS_ENABLED(CONFIG_SUNRPC_DEBUG) | 
| 113 | rpc_register_sysctl(); | 
| 114 | #endif | 
| 115 | svc_init_xprt_sock(); /* svc sock transport */ | 
| 116 | init_socket_xprt(); /* clnt sock transport */ | 
| 117 | return 0; | 
| 118 | |
| 119 | out5: | 
| 120 | unregister_rpc_pipefs(); | 
| 121 | out4: | 
| 122 | unregister_pernet_subsys(&sunrpc_net_ops); | 
| 123 | out3: | 
| 124 | rpcauth_remove_module(); | 
| 125 | out2: | 
| 126 | rpc_destroy_mempool(); | 
| 127 | out: | 
| 128 | return err; | 
| 129 | } | 
| 130 | |
| 131 | static void __exit | 
| 132 | cleanup_sunrpc(void) | 
| 133 | { | 
| 134 | rpc_sysfs_exit(); | 
| 135 | rpc_cleanup_clids(); | 
| 136 | xprt_cleanup_ids(); | 
| 137 | xprt_multipath_cleanup_ids(); | 
| 138 | rpcauth_remove_module(); | 
| 139 | cleanup_socket_xprt(); | 
| 140 | svc_cleanup_xprt_sock(); | 
| 141 | sunrpc_debugfs_exit(); | 
| 142 | unregister_rpc_pipefs(); | 
| 143 | rpc_destroy_mempool(); | 
| 144 | unregister_pernet_subsys(&sunrpc_net_ops); | 
| 145 | auth_domain_cleanup(); | 
| 146 | #if IS_ENABLED(CONFIG_SUNRPC_DEBUG) | 
| 147 | rpc_unregister_sysctl(); | 
| 148 | #endif | 
| 149 | rcu_barrier(); /* Wait for completion of call_rcu()'s */ | 
| 150 | } | 
| 151 | MODULE_DESCRIPTION( "Sun RPC core"); | 
| 152 | MODULE_LICENSE( "GPL"); | 
| 153 | fs_initcall(init_sunrpc); /* Ensure we're initialised before nfs */ | 
| 154 | module_exit(cleanup_sunrpc); | 
| 155 | 
