David Howells | 24c8dbb | 2006-08-22 20:06:10 -0400 | [diff] [blame] | 1 | /* client.c: NFS client sharing and management code |
| 2 | * |
| 3 | * Copyright (C) 2006 Red Hat, Inc. All Rights Reserved. |
| 4 | * 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 | |
David Howells | 24c8dbb | 2006-08-22 20:06:10 -0400 | [diff] [blame] | 13 | #include <linux/module.h> |
| 14 | #include <linux/init.h> |
Alexey Dobriyan | e8edc6e | 2007-05-21 01:22:52 +0400 | [diff] [blame] | 15 | #include <linux/sched.h> |
David Howells | 24c8dbb | 2006-08-22 20:06:10 -0400 | [diff] [blame] | 16 | #include <linux/time.h> |
| 17 | #include <linux/kernel.h> |
| 18 | #include <linux/mm.h> |
| 19 | #include <linux/string.h> |
| 20 | #include <linux/stat.h> |
| 21 | #include <linux/errno.h> |
| 22 | #include <linux/unistd.h> |
| 23 | #include <linux/sunrpc/clnt.h> |
| 24 | #include <linux/sunrpc/stats.h> |
| 25 | #include <linux/sunrpc/metrics.h> |
\"Talpey, Thomas\ | 0896a725 | 2007-09-10 13:48:23 -0400 | [diff] [blame] | 26 | #include <linux/sunrpc/xprtsock.h> |
\"Talpey, Thomas\ | 2cf7ff7 | 2007-09-10 13:49:41 -0400 | [diff] [blame] | 27 | #include <linux/sunrpc/xprtrdma.h> |
David Howells | 24c8dbb | 2006-08-22 20:06:10 -0400 | [diff] [blame] | 28 | #include <linux/nfs_fs.h> |
| 29 | #include <linux/nfs_mount.h> |
| 30 | #include <linux/nfs4_mount.h> |
| 31 | #include <linux/lockd/bind.h> |
David Howells | 24c8dbb | 2006-08-22 20:06:10 -0400 | [diff] [blame] | 32 | #include <linux/seq_file.h> |
| 33 | #include <linux/mount.h> |
| 34 | #include <linux/nfs_idmap.h> |
| 35 | #include <linux/vfs.h> |
| 36 | #include <linux/inet.h> |
Trond Myklebust | 3b0d3f9 | 2008-01-03 13:28:58 -0500 | [diff] [blame] | 37 | #include <linux/in6.h> |
Tejun Heo | 5a0e3ad | 2010-03-24 17:04:11 +0900 | [diff] [blame] | 38 | #include <linux/slab.h> |
Al Viro | 4040153 | 2012-02-13 03:58:52 +0000 | [diff] [blame] | 39 | #include <linux/idr.h> |
Trond Myklebust | 3b0d3f9 | 2008-01-03 13:28:58 -0500 | [diff] [blame] | 40 | #include <net/ipv6.h> |
David Howells | 24c8dbb | 2006-08-22 20:06:10 -0400 | [diff] [blame] | 41 | #include <linux/nfs_xdr.h> |
Andy Adamson | 0b5b7ae | 2009-04-01 09:23:15 -0400 | [diff] [blame] | 42 | #include <linux/sunrpc/bc_xprt.h> |
Stanislav Kinsbursky | 6b13168 | 2012-01-23 17:26:05 +0000 | [diff] [blame] | 43 | #include <linux/nsproxy.h> |
| 44 | #include <linux/pid_namespace.h> |
David Howells | 24c8dbb | 2006-08-22 20:06:10 -0400 | [diff] [blame] | 45 | |
David Howells | 24c8dbb | 2006-08-22 20:06:10 -0400 | [diff] [blame] | 46 | |
| 47 | #include "nfs4_fs.h" |
| 48 | #include "callback.h" |
| 49 | #include "delegation.h" |
| 50 | #include "iostat.h" |
| 51 | #include "internal.h" |
David Howells | 1472728 | 2009-04-03 16:42:42 +0100 | [diff] [blame] | 52 | #include "fscache.h" |
Ricardo Labiaga | 85e174b | 2010-10-20 00:17:58 -0400 | [diff] [blame] | 53 | #include "pnfs.h" |
Stanislav Kinsbursky | 6b13168 | 2012-01-23 17:26:05 +0000 | [diff] [blame] | 54 | #include "netns.h" |
David Howells | 24c8dbb | 2006-08-22 20:06:10 -0400 | [diff] [blame] | 55 | |
| 56 | #define NFSDBG_FACILITY NFSDBG_CLIENT |
| 57 | |
David Howells | 24c8dbb | 2006-08-22 20:06:10 -0400 | [diff] [blame] | 58 | static DECLARE_WAIT_QUEUE_HEAD(nfs_client_active_wq); |
Andy Adamson | f4eecd5 | 2011-01-06 02:04:30 +0000 | [diff] [blame] | 59 | #ifdef CONFIG_NFS_V4 |
Andy Adamson | f4eecd5 | 2011-01-06 02:04:30 +0000 | [diff] [blame] | 60 | |
| 61 | /* |
| 62 | * Get a unique NFSv4.0 callback identifier which will be used |
| 63 | * by the V4.0 callback service to lookup the nfs_client struct |
| 64 | */ |
| 65 | static int nfs_get_cb_ident_idr(struct nfs_client *clp, int minorversion) |
| 66 | { |
| 67 | int ret = 0; |
Chuck Lever | 73ea666 | 2012-05-21 22:44:50 -0400 | [diff] [blame] | 68 | struct nfs_net *nn = net_generic(clp->cl_net, nfs_net_id); |
Andy Adamson | f4eecd5 | 2011-01-06 02:04:30 +0000 | [diff] [blame] | 69 | |
| 70 | if (clp->rpc_ops->version != 4 || minorversion != 0) |
| 71 | return ret; |
| 72 | retry: |
Stanislav Kinsbursky | 28cd1b3 | 2012-01-23 17:26:22 +0000 | [diff] [blame] | 73 | if (!idr_pre_get(&nn->cb_ident_idr, GFP_KERNEL)) |
Andy Adamson | f4eecd5 | 2011-01-06 02:04:30 +0000 | [diff] [blame] | 74 | return -ENOMEM; |
Stanislav Kinsbursky | dc03085 | 2012-01-23 17:26:31 +0000 | [diff] [blame] | 75 | spin_lock(&nn->nfs_client_lock); |
Stanislav Kinsbursky | 28cd1b3 | 2012-01-23 17:26:22 +0000 | [diff] [blame] | 76 | ret = idr_get_new(&nn->cb_ident_idr, clp, &clp->cl_cb_ident); |
Stanislav Kinsbursky | dc03085 | 2012-01-23 17:26:31 +0000 | [diff] [blame] | 77 | spin_unlock(&nn->nfs_client_lock); |
Andy Adamson | f4eecd5 | 2011-01-06 02:04:30 +0000 | [diff] [blame] | 78 | if (ret == -EAGAIN) |
| 79 | goto retry; |
| 80 | return ret; |
| 81 | } |
| 82 | #endif /* CONFIG_NFS_V4 */ |
David Howells | 24c8dbb | 2006-08-22 20:06:10 -0400 | [diff] [blame] | 83 | |
| 84 | /* |
David Howells | 5006a76 | 2006-08-22 20:06:12 -0400 | [diff] [blame] | 85 | * RPC cruft for NFS |
| 86 | */ |
Trond Myklebust | a613fa1 | 2012-01-20 13:53:56 -0500 | [diff] [blame] | 87 | static const struct rpc_version *nfs_version[5] = { |
Bryan Schumaker | 2ba6800 | 2012-05-10 16:47:19 -0400 | [diff] [blame] | 88 | #ifdef CONFIG_NFS_V2 |
David Howells | 5006a76 | 2006-08-22 20:06:12 -0400 | [diff] [blame] | 89 | [2] = &nfs_version2, |
Bryan Schumaker | 2ba6800 | 2012-05-10 16:47:19 -0400 | [diff] [blame] | 90 | #endif |
David Howells | 5006a76 | 2006-08-22 20:06:12 -0400 | [diff] [blame] | 91 | #ifdef CONFIG_NFS_V3 |
| 92 | [3] = &nfs_version3, |
| 93 | #endif |
| 94 | #ifdef CONFIG_NFS_V4 |
| 95 | [4] = &nfs_version4, |
| 96 | #endif |
| 97 | }; |
| 98 | |
Trond Myklebust | a613fa1 | 2012-01-20 13:53:56 -0500 | [diff] [blame] | 99 | const struct rpc_program nfs_program = { |
David Howells | 5006a76 | 2006-08-22 20:06:12 -0400 | [diff] [blame] | 100 | .name = "nfs", |
| 101 | .number = NFS_PROGRAM, |
| 102 | .nrvers = ARRAY_SIZE(nfs_version), |
| 103 | .version = nfs_version, |
| 104 | .stats = &nfs_rpcstat, |
Jim Rees | fe0a9b7 | 2011-07-30 20:52:42 -0400 | [diff] [blame] | 105 | .pipe_dir_name = NFS_PIPE_DIRNAME, |
David Howells | 5006a76 | 2006-08-22 20:06:12 -0400 | [diff] [blame] | 106 | }; |
| 107 | |
| 108 | struct rpc_stat nfs_rpcstat = { |
| 109 | .program = &nfs_program |
| 110 | }; |
| 111 | |
| 112 | |
| 113 | #ifdef CONFIG_NFS_V3_ACL |
| 114 | static struct rpc_stat nfsacl_rpcstat = { &nfsacl_program }; |
Trond Myklebust | a613fa1 | 2012-01-20 13:53:56 -0500 | [diff] [blame] | 115 | static const struct rpc_version *nfsacl_version[] = { |
David Howells | 5006a76 | 2006-08-22 20:06:12 -0400 | [diff] [blame] | 116 | [3] = &nfsacl_version3, |
| 117 | }; |
| 118 | |
Trond Myklebust | a613fa1 | 2012-01-20 13:53:56 -0500 | [diff] [blame] | 119 | const struct rpc_program nfsacl_program = { |
David Howells | 5006a76 | 2006-08-22 20:06:12 -0400 | [diff] [blame] | 120 | .name = "nfsacl", |
| 121 | .number = NFS_ACL_PROGRAM, |
| 122 | .nrvers = ARRAY_SIZE(nfsacl_version), |
| 123 | .version = nfsacl_version, |
| 124 | .stats = &nfsacl_rpcstat, |
| 125 | }; |
| 126 | #endif /* CONFIG_NFS_V3_ACL */ |
| 127 | |
| 128 | /* |
David Howells | 24c8dbb | 2006-08-22 20:06:10 -0400 | [diff] [blame] | 129 | * Allocate a shared client record |
| 130 | * |
| 131 | * Since these are allocated/deallocated very rarely, we don't |
| 132 | * bother putting them in a slab cache... |
| 133 | */ |
Bryan Schumaker | 6663ee7 | 2012-06-20 15:53:46 -0400 | [diff] [blame] | 134 | struct nfs_client *nfs_alloc_client(const struct nfs_client_initdata *cl_init) |
David Howells | 24c8dbb | 2006-08-22 20:06:10 -0400 | [diff] [blame] | 135 | { |
| 136 | struct nfs_client *clp; |
Trond Myklebust | 7c67db3 | 2008-04-07 20:50:11 -0400 | [diff] [blame] | 137 | struct rpc_cred *cred; |
Chuck Lever | a21bdd9 | 2009-06-17 18:02:10 -0700 | [diff] [blame] | 138 | int err = -ENOMEM; |
David Howells | 24c8dbb | 2006-08-22 20:06:10 -0400 | [diff] [blame] | 139 | |
| 140 | if ((clp = kzalloc(sizeof(*clp), GFP_KERNEL)) == NULL) |
| 141 | goto error_0; |
| 142 | |
Trond Myklebust | 40c55319 | 2007-12-14 14:56:07 -0500 | [diff] [blame] | 143 | clp->rpc_ops = cl_init->rpc_ops; |
| 144 | |
David Howells | 24c8dbb | 2006-08-22 20:06:10 -0400 | [diff] [blame] | 145 | atomic_set(&clp->cl_count, 1); |
| 146 | clp->cl_cons_state = NFS_CS_INITING; |
| 147 | |
Chuck Lever | 6e4cffd | 2007-12-10 14:58:15 -0500 | [diff] [blame] | 148 | memcpy(&clp->cl_addr, cl_init->addr, cl_init->addrlen); |
| 149 | clp->cl_addrlen = cl_init->addrlen; |
David Howells | 24c8dbb | 2006-08-22 20:06:10 -0400 | [diff] [blame] | 150 | |
Trond Myklebust | 3a49802 | 2007-12-14 14:56:04 -0500 | [diff] [blame] | 151 | if (cl_init->hostname) { |
Chuck Lever | a21bdd9 | 2009-06-17 18:02:10 -0700 | [diff] [blame] | 152 | err = -ENOMEM; |
Trond Myklebust | 3a49802 | 2007-12-14 14:56:04 -0500 | [diff] [blame] | 153 | clp->cl_hostname = kstrdup(cl_init->hostname, GFP_KERNEL); |
David Howells | 24c8dbb | 2006-08-22 20:06:10 -0400 | [diff] [blame] | 154 | if (!clp->cl_hostname) |
Benny Halevy | 7146851 | 2009-04-01 09:22:56 -0400 | [diff] [blame] | 155 | goto error_cleanup; |
David Howells | 24c8dbb | 2006-08-22 20:06:10 -0400 | [diff] [blame] | 156 | } |
| 157 | |
| 158 | INIT_LIST_HEAD(&clp->cl_superblocks); |
| 159 | clp->cl_rpcclient = ERR_PTR(-EINVAL); |
| 160 | |
Trond Myklebust | 59dca3b | 2008-01-03 16:29:06 -0500 | [diff] [blame] | 161 | clp->cl_proto = cl_init->proto; |
Chuck Lever | 73ea666 | 2012-05-21 22:44:50 -0400 | [diff] [blame] | 162 | clp->cl_net = get_net(cl_init->net); |
Trond Myklebust | 59dca3b | 2008-01-03 16:29:06 -0500 | [diff] [blame] | 163 | |
Trond Myklebust | 68c9715 | 2012-01-03 13:22:46 -0500 | [diff] [blame] | 164 | cred = rpc_lookup_machine_cred("*"); |
Trond Myklebust | 7c67db3 | 2008-04-07 20:50:11 -0400 | [diff] [blame] | 165 | if (!IS_ERR(cred)) |
| 166 | clp->cl_machine_cred = cred; |
David Howells | 1472728 | 2009-04-03 16:42:42 +0100 | [diff] [blame] | 167 | nfs_fscache_get_client_cookie(clp); |
| 168 | |
David Howells | 24c8dbb | 2006-08-22 20:06:10 -0400 | [diff] [blame] | 169 | return clp; |
| 170 | |
Benny Halevy | 7146851 | 2009-04-01 09:22:56 -0400 | [diff] [blame] | 171 | error_cleanup: |
David Howells | 24c8dbb | 2006-08-22 20:06:10 -0400 | [diff] [blame] | 172 | kfree(clp); |
| 173 | error_0: |
Chuck Lever | a21bdd9 | 2009-06-17 18:02:10 -0700 | [diff] [blame] | 174 | return ERR_PTR(err); |
David Howells | 24c8dbb | 2006-08-22 20:06:10 -0400 | [diff] [blame] | 175 | } |
| 176 | |
Trond Myklebust | 5dd3177 | 2006-08-24 01:03:05 -0400 | [diff] [blame] | 177 | #ifdef CONFIG_NFS_V4 |
Andy Adamson | 557134a | 2009-04-01 09:21:53 -0400 | [diff] [blame] | 178 | #ifdef CONFIG_NFS_V4_1 |
Andy Adamson | ea00528 | 2011-01-06 02:04:29 +0000 | [diff] [blame] | 179 | static void nfs4_shutdown_session(struct nfs_client *clp) |
| 180 | { |
Trond Myklebust | 7df529a | 2012-02-26 17:34:22 -0500 | [diff] [blame] | 181 | if (nfs4_has_session(clp)) { |
Andy Adamson | 557134a | 2009-04-01 09:21:53 -0400 | [diff] [blame] | 182 | nfs4_destroy_session(clp->cl_session); |
Trond Myklebust | 6624553 | 2012-05-25 17:18:09 -0400 | [diff] [blame] | 183 | nfs4_destroy_clientid(clp); |
Trond Myklebust | 7df529a | 2012-02-26 17:34:22 -0500 | [diff] [blame] | 184 | } |
| 185 | |
Andy Adamson | 557134a | 2009-04-01 09:21:53 -0400 | [diff] [blame] | 186 | } |
Andy Adamson | ea00528 | 2011-01-06 02:04:29 +0000 | [diff] [blame] | 187 | #else /* CONFIG_NFS_V4_1 */ |
| 188 | static void nfs4_shutdown_session(struct nfs_client *clp) |
| 189 | { |
| 190 | } |
| 191 | #endif /* CONFIG_NFS_V4_1 */ |
Andy Adamson | 557134a | 2009-04-01 09:21:53 -0400 | [diff] [blame] | 192 | |
Bryan Schumaker | 6663ee7 | 2012-06-20 15:53:46 -0400 | [diff] [blame] | 193 | struct nfs_client *nfs4_alloc_client(const struct nfs_client_initdata *cl_init) |
| 194 | { |
| 195 | int err; |
| 196 | struct nfs_client *clp = nfs_alloc_client(cl_init); |
| 197 | if (IS_ERR(clp)) |
| 198 | return clp; |
| 199 | |
| 200 | err = nfs_get_cb_ident_idr(clp, cl_init->minorversion); |
| 201 | if (err) |
| 202 | goto error; |
| 203 | |
| 204 | spin_lock_init(&clp->cl_lock); |
| 205 | INIT_DELAYED_WORK(&clp->cl_renewd, nfs4_renew_state); |
| 206 | rpc_init_wait_queue(&clp->cl_rpcwaitq, "NFS client"); |
| 207 | clp->cl_state = 1 << NFS4CLNT_LEASE_EXPIRED; |
| 208 | clp->cl_minorversion = cl_init->minorversion; |
| 209 | clp->cl_mvops = nfs_v4_minor_ops[cl_init->minorversion]; |
| 210 | return clp; |
| 211 | |
| 212 | error: |
| 213 | kfree(clp); |
| 214 | return ERR_PTR(err); |
| 215 | } |
| 216 | |
Andy Adamson | 557134a | 2009-04-01 09:21:53 -0400 | [diff] [blame] | 217 | /* |
Alexandros Batsakis | 888ef2e | 2010-02-05 03:45:03 -0800 | [diff] [blame] | 218 | * Destroy the NFS4 callback service |
| 219 | */ |
| 220 | static void nfs4_destroy_callback(struct nfs_client *clp) |
| 221 | { |
| 222 | if (__test_and_clear_bit(NFS_CS_CALLBACK, &clp->cl_res_state)) |
Trond Myklebust | 97dc135 | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 223 | nfs_callback_down(clp->cl_mvops->minor_version); |
Alexandros Batsakis | 888ef2e | 2010-02-05 03:45:03 -0800 | [diff] [blame] | 224 | } |
| 225 | |
| 226 | static void nfs4_shutdown_client(struct nfs_client *clp) |
| 227 | { |
| 228 | if (__test_and_clear_bit(NFS_CS_RENEWD, &clp->cl_res_state)) |
| 229 | nfs4_kill_renewd(clp); |
Andy Adamson | ea00528 | 2011-01-06 02:04:29 +0000 | [diff] [blame] | 230 | nfs4_shutdown_session(clp); |
Alexandros Batsakis | 888ef2e | 2010-02-05 03:45:03 -0800 | [diff] [blame] | 231 | nfs4_destroy_callback(clp); |
| 232 | if (__test_and_clear_bit(NFS_CS_IDMAP, &clp->cl_res_state)) |
| 233 | nfs_idmap_delete(clp); |
| 234 | |
| 235 | rpc_destroy_wait_queue(&clp->cl_rpcwaitq); |
Chuck Lever | acdeb69 | 2012-05-21 22:46:16 -0400 | [diff] [blame] | 236 | kfree(clp->cl_serverowner); |
Chuck Lever | 79d4e1f | 2012-05-21 22:44:31 -0400 | [diff] [blame] | 237 | kfree(clp->cl_serverscope); |
Chuck Lever | 5915554 | 2012-05-21 22:44:41 -0400 | [diff] [blame] | 238 | kfree(clp->cl_implid); |
Alexandros Batsakis | 888ef2e | 2010-02-05 03:45:03 -0800 | [diff] [blame] | 239 | } |
Andy Adamson | f4eecd5 | 2011-01-06 02:04:30 +0000 | [diff] [blame] | 240 | |
Bryan Schumaker | cdb7ece | 2012-06-20 15:53:45 -0400 | [diff] [blame] | 241 | void nfs4_free_client(struct nfs_client *clp) |
| 242 | { |
| 243 | nfs4_shutdown_client(clp); |
| 244 | nfs_free_client(clp); |
| 245 | } |
| 246 | |
Andy Adamson | f4eecd5 | 2011-01-06 02:04:30 +0000 | [diff] [blame] | 247 | /* idr_remove_all is not needed as all id's are removed by nfs_put_client */ |
Stanislav Kinsbursky | 28cd1b3 | 2012-01-23 17:26:22 +0000 | [diff] [blame] | 248 | void nfs_cleanup_cb_ident_idr(struct net *net) |
Andy Adamson | f4eecd5 | 2011-01-06 02:04:30 +0000 | [diff] [blame] | 249 | { |
Stanislav Kinsbursky | 28cd1b3 | 2012-01-23 17:26:22 +0000 | [diff] [blame] | 250 | struct nfs_net *nn = net_generic(net, nfs_net_id); |
| 251 | |
| 252 | idr_destroy(&nn->cb_ident_idr); |
Andy Adamson | f4eecd5 | 2011-01-06 02:04:30 +0000 | [diff] [blame] | 253 | } |
| 254 | |
| 255 | /* nfs_client_lock held */ |
| 256 | static void nfs_cb_idr_remove_locked(struct nfs_client *clp) |
| 257 | { |
Chuck Lever | 73ea666 | 2012-05-21 22:44:50 -0400 | [diff] [blame] | 258 | struct nfs_net *nn = net_generic(clp->cl_net, nfs_net_id); |
Stanislav Kinsbursky | 28cd1b3 | 2012-01-23 17:26:22 +0000 | [diff] [blame] | 259 | |
Andy Adamson | f4eecd5 | 2011-01-06 02:04:30 +0000 | [diff] [blame] | 260 | if (clp->cl_cb_ident) |
Stanislav Kinsbursky | 28cd1b3 | 2012-01-23 17:26:22 +0000 | [diff] [blame] | 261 | idr_remove(&nn->cb_ident_idr, clp->cl_cb_ident); |
Andy Adamson | f4eecd5 | 2011-01-06 02:04:30 +0000 | [diff] [blame] | 262 | } |
| 263 | |
Fred Isaman | f7e8917 | 2011-01-06 11:36:32 +0000 | [diff] [blame] | 264 | static void pnfs_init_server(struct nfs_server *server) |
| 265 | { |
| 266 | rpc_init_wait_queue(&server->roc_rpcwaitq, "pNFS ROC"); |
| 267 | } |
| 268 | |
Alexandros Batsakis | 888ef2e | 2010-02-05 03:45:03 -0800 | [diff] [blame] | 269 | #else |
Stanislav Kinsbursky | 28cd1b3 | 2012-01-23 17:26:22 +0000 | [diff] [blame] | 270 | void nfs_cleanup_cb_ident_idr(struct net *net) |
Andy Adamson | f4eecd5 | 2011-01-06 02:04:30 +0000 | [diff] [blame] | 271 | { |
| 272 | } |
| 273 | |
| 274 | static void nfs_cb_idr_remove_locked(struct nfs_client *clp) |
| 275 | { |
| 276 | } |
Fred Isaman | f7e8917 | 2011-01-06 11:36:32 +0000 | [diff] [blame] | 277 | |
| 278 | static void pnfs_init_server(struct nfs_server *server) |
| 279 | { |
| 280 | } |
| 281 | |
Alexandros Batsakis | 888ef2e | 2010-02-05 03:45:03 -0800 | [diff] [blame] | 282 | #endif /* CONFIG_NFS_V4 */ |
| 283 | |
| 284 | /* |
David Howells | 24c8dbb | 2006-08-22 20:06:10 -0400 | [diff] [blame] | 285 | * Destroy a shared client record |
| 286 | */ |
Bryan Schumaker | cdb7ece | 2012-06-20 15:53:45 -0400 | [diff] [blame] | 287 | void nfs_free_client(struct nfs_client *clp) |
David Howells | 24c8dbb | 2006-08-22 20:06:10 -0400 | [diff] [blame] | 288 | { |
Trond Myklebust | 40c55319 | 2007-12-14 14:56:07 -0500 | [diff] [blame] | 289 | dprintk("--> nfs_free_client(%u)\n", clp->rpc_ops->version); |
David Howells | 24c8dbb | 2006-08-22 20:06:10 -0400 | [diff] [blame] | 290 | |
David Howells | 1472728 | 2009-04-03 16:42:42 +0100 | [diff] [blame] | 291 | nfs_fscache_release_client_cookie(clp); |
| 292 | |
David Howells | 24c8dbb | 2006-08-22 20:06:10 -0400 | [diff] [blame] | 293 | /* -EIO all pending I/O */ |
| 294 | if (!IS_ERR(clp->cl_rpcclient)) |
| 295 | rpc_shutdown_client(clp->cl_rpcclient); |
| 296 | |
Trond Myklebust | 7c67db3 | 2008-04-07 20:50:11 -0400 | [diff] [blame] | 297 | if (clp->cl_machine_cred != NULL) |
| 298 | put_rpccred(clp->cl_machine_cred); |
| 299 | |
Chuck Lever | 73ea666 | 2012-05-21 22:44:50 -0400 | [diff] [blame] | 300 | put_net(clp->cl_net); |
David Howells | 24c8dbb | 2006-08-22 20:06:10 -0400 | [diff] [blame] | 301 | kfree(clp->cl_hostname); |
| 302 | kfree(clp); |
| 303 | |
| 304 | dprintk("<-- nfs_free_client()\n"); |
| 305 | } |
| 306 | |
| 307 | /* |
| 308 | * Release a reference to a shared client record |
| 309 | */ |
| 310 | void nfs_put_client(struct nfs_client *clp) |
| 311 | { |
Stanislav Kinsbursky | dc03085 | 2012-01-23 17:26:31 +0000 | [diff] [blame] | 312 | struct nfs_net *nn; |
| 313 | |
David Howells | 27ba851 | 2006-07-30 14:40:56 -0400 | [diff] [blame] | 314 | if (!clp) |
| 315 | return; |
| 316 | |
David Howells | 24c8dbb | 2006-08-22 20:06:10 -0400 | [diff] [blame] | 317 | dprintk("--> nfs_put_client({%d})\n", atomic_read(&clp->cl_count)); |
Chuck Lever | 73ea666 | 2012-05-21 22:44:50 -0400 | [diff] [blame] | 318 | nn = net_generic(clp->cl_net, nfs_net_id); |
David Howells | 24c8dbb | 2006-08-22 20:06:10 -0400 | [diff] [blame] | 319 | |
Stanislav Kinsbursky | dc03085 | 2012-01-23 17:26:31 +0000 | [diff] [blame] | 320 | if (atomic_dec_and_lock(&clp->cl_count, &nn->nfs_client_lock)) { |
David Howells | 24c8dbb | 2006-08-22 20:06:10 -0400 | [diff] [blame] | 321 | list_del(&clp->cl_share_link); |
Andy Adamson | f4eecd5 | 2011-01-06 02:04:30 +0000 | [diff] [blame] | 322 | nfs_cb_idr_remove_locked(clp); |
Stanislav Kinsbursky | dc03085 | 2012-01-23 17:26:31 +0000 | [diff] [blame] | 323 | spin_unlock(&nn->nfs_client_lock); |
David Howells | 24c8dbb | 2006-08-22 20:06:10 -0400 | [diff] [blame] | 324 | |
| 325 | BUG_ON(!list_empty(&clp->cl_superblocks)); |
| 326 | |
Bryan Schumaker | cdb7ece | 2012-06-20 15:53:45 -0400 | [diff] [blame] | 327 | clp->rpc_ops->free_client(clp); |
David Howells | 24c8dbb | 2006-08-22 20:06:10 -0400 | [diff] [blame] | 328 | } |
| 329 | } |
Andy Adamson | 16b374c | 2010-10-20 00:18:04 -0400 | [diff] [blame] | 330 | EXPORT_SYMBOL_GPL(nfs_put_client); |
David Howells | 24c8dbb | 2006-08-22 20:06:10 -0400 | [diff] [blame] | 331 | |
Trond Myklebust | 9082a5c | 2008-12-23 15:21:53 -0500 | [diff] [blame] | 332 | #if defined(CONFIG_IPV6) || defined(CONFIG_IPV6_MODULE) |
Trond Myklebust | 9f4c899 | 2009-03-12 14:51:32 -0400 | [diff] [blame] | 333 | /* |
| 334 | * Test if two ip6 socket addresses refer to the same socket by |
| 335 | * comparing relevant fields. The padding bytes specifically, are not |
| 336 | * compared. sin6_flowinfo is not compared because it only affects QoS |
| 337 | * and sin6_scope_id is only compared if the address is "link local" |
| 338 | * because "link local" addresses need only be unique to a specific |
| 339 | * link. Conversely, ordinary unicast addresses might have different |
| 340 | * sin6_scope_id. |
| 341 | * |
| 342 | * The caller should ensure both socket addresses are AF_INET6. |
| 343 | */ |
Chuck Lever | 3c8c45d | 2009-03-18 20:48:14 -0400 | [diff] [blame] | 344 | static int nfs_sockaddr_match_ipaddr6(const struct sockaddr *sa1, |
| 345 | const struct sockaddr *sa2) |
Trond Myklebust | 9f4c899 | 2009-03-12 14:51:32 -0400 | [diff] [blame] | 346 | { |
Chuck Lever | 3c8c45d | 2009-03-18 20:48:14 -0400 | [diff] [blame] | 347 | const struct sockaddr_in6 *sin1 = (const struct sockaddr_in6 *)sa1; |
| 348 | const struct sockaddr_in6 *sin2 = (const struct sockaddr_in6 *)sa2; |
Trond Myklebust | 9f4c899 | 2009-03-12 14:51:32 -0400 | [diff] [blame] | 349 | |
Mi Jinlong | b9dd3ab | 2011-10-12 15:09:34 +0800 | [diff] [blame] | 350 | if (!ipv6_addr_equal(&sin1->sin6_addr, &sin2->sin6_addr)) |
Trond Myklebust | 9f4c899 | 2009-03-12 14:51:32 -0400 | [diff] [blame] | 351 | return 0; |
Mi Jinlong | b9dd3ab | 2011-10-12 15:09:34 +0800 | [diff] [blame] | 352 | else if (ipv6_addr_type(&sin1->sin6_addr) & IPV6_ADDR_LINKLOCAL) |
| 353 | return sin1->sin6_scope_id == sin2->sin6_scope_id; |
Trond Myklebust | 3b0d3f9 | 2008-01-03 13:28:58 -0500 | [diff] [blame] | 354 | |
Mi Jinlong | b9dd3ab | 2011-10-12 15:09:34 +0800 | [diff] [blame] | 355 | return 1; |
Trond Myklebust | 3b0d3f9 | 2008-01-03 13:28:58 -0500 | [diff] [blame] | 356 | } |
Chuck Lever | 3c8c45d | 2009-03-18 20:48:14 -0400 | [diff] [blame] | 357 | #else /* !defined(CONFIG_IPV6) && !defined(CONFIG_IPV6_MODULE) */ |
| 358 | static int nfs_sockaddr_match_ipaddr6(const struct sockaddr *sa1, |
| 359 | const struct sockaddr *sa2) |
Trond Myklebust | 9f4c899 | 2009-03-12 14:51:32 -0400 | [diff] [blame] | 360 | { |
| 361 | return 0; |
| 362 | } |
Trond Myklebust | 9082a5c | 2008-12-23 15:21:53 -0500 | [diff] [blame] | 363 | #endif |
Trond Myklebust | 3b0d3f9 | 2008-01-03 13:28:58 -0500 | [diff] [blame] | 364 | |
David Howells | 24c8dbb | 2006-08-22 20:06:10 -0400 | [diff] [blame] | 365 | /* |
Ian Dall | d7371c4 | 2009-03-10 20:33:22 -0400 | [diff] [blame] | 366 | * Test if two ip4 socket addresses refer to the same socket, by |
| 367 | * comparing relevant fields. The padding bytes specifically, are |
| 368 | * not compared. |
| 369 | * |
| 370 | * The caller should ensure both socket addresses are AF_INET. |
| 371 | */ |
Chuck Lever | 3c8c45d | 2009-03-18 20:48:14 -0400 | [diff] [blame] | 372 | static int nfs_sockaddr_match_ipaddr4(const struct sockaddr *sa1, |
| 373 | const struct sockaddr *sa2) |
| 374 | { |
| 375 | const struct sockaddr_in *sin1 = (const struct sockaddr_in *)sa1; |
| 376 | const struct sockaddr_in *sin2 = (const struct sockaddr_in *)sa2; |
| 377 | |
| 378 | return sin1->sin_addr.s_addr == sin2->sin_addr.s_addr; |
| 379 | } |
| 380 | |
| 381 | static int nfs_sockaddr_cmp_ip6(const struct sockaddr *sa1, |
| 382 | const struct sockaddr *sa2) |
| 383 | { |
| 384 | const struct sockaddr_in6 *sin1 = (const struct sockaddr_in6 *)sa1; |
| 385 | const struct sockaddr_in6 *sin2 = (const struct sockaddr_in6 *)sa2; |
| 386 | |
| 387 | return nfs_sockaddr_match_ipaddr6(sa1, sa2) && |
| 388 | (sin1->sin6_port == sin2->sin6_port); |
| 389 | } |
| 390 | |
Trond Myklebust | 9f4c899 | 2009-03-12 14:51:32 -0400 | [diff] [blame] | 391 | static int nfs_sockaddr_cmp_ip4(const struct sockaddr *sa1, |
| 392 | const struct sockaddr *sa2) |
Ian Dall | d7371c4 | 2009-03-10 20:33:22 -0400 | [diff] [blame] | 393 | { |
Chuck Lever | 3c8c45d | 2009-03-18 20:48:14 -0400 | [diff] [blame] | 394 | const struct sockaddr_in *sin1 = (const struct sockaddr_in *)sa1; |
| 395 | const struct sockaddr_in *sin2 = (const struct sockaddr_in *)sa2; |
Trond Myklebust | 9f4c899 | 2009-03-12 14:51:32 -0400 | [diff] [blame] | 396 | |
Chuck Lever | 3c8c45d | 2009-03-18 20:48:14 -0400 | [diff] [blame] | 397 | return nfs_sockaddr_match_ipaddr4(sa1, sa2) && |
| 398 | (sin1->sin_port == sin2->sin_port); |
Ian Dall | d7371c4 | 2009-03-10 20:33:22 -0400 | [diff] [blame] | 399 | } |
| 400 | |
Bryan Schumaker | 4b7c8dd | 2012-03-12 11:28:24 -0400 | [diff] [blame] | 401 | #if defined(CONFIG_NFS_V4_1) |
Ian Dall | d7371c4 | 2009-03-10 20:33:22 -0400 | [diff] [blame] | 402 | /* |
Ian Dall | d7371c4 | 2009-03-10 20:33:22 -0400 | [diff] [blame] | 403 | * Test if two socket addresses represent the same actual socket, |
Chuck Lever | 3c8c45d | 2009-03-18 20:48:14 -0400 | [diff] [blame] | 404 | * by comparing (only) relevant fields, excluding the port number. |
| 405 | */ |
Bryan Schumaker | fcf1039 | 2012-07-16 16:39:18 -0400 | [diff] [blame^] | 406 | int nfs_sockaddr_match_ipaddr(const struct sockaddr *sa1, |
| 407 | const struct sockaddr *sa2) |
Chuck Lever | 3c8c45d | 2009-03-18 20:48:14 -0400 | [diff] [blame] | 408 | { |
| 409 | if (sa1->sa_family != sa2->sa_family) |
| 410 | return 0; |
| 411 | |
| 412 | switch (sa1->sa_family) { |
| 413 | case AF_INET: |
| 414 | return nfs_sockaddr_match_ipaddr4(sa1, sa2); |
| 415 | case AF_INET6: |
| 416 | return nfs_sockaddr_match_ipaddr6(sa1, sa2); |
| 417 | } |
| 418 | return 0; |
| 419 | } |
Bryan Schumaker | 4b7c8dd | 2012-03-12 11:28:24 -0400 | [diff] [blame] | 420 | #endif /* CONFIG_NFS_V4_1 */ |
Chuck Lever | 3c8c45d | 2009-03-18 20:48:14 -0400 | [diff] [blame] | 421 | |
| 422 | /* |
| 423 | * Test if two socket addresses represent the same actual socket, |
| 424 | * by comparing (only) relevant fields, including the port number. |
Ian Dall | d7371c4 | 2009-03-10 20:33:22 -0400 | [diff] [blame] | 425 | */ |
| 426 | static int nfs_sockaddr_cmp(const struct sockaddr *sa1, |
| 427 | const struct sockaddr *sa2) |
| 428 | { |
| 429 | if (sa1->sa_family != sa2->sa_family) |
| 430 | return 0; |
| 431 | |
| 432 | switch (sa1->sa_family) { |
| 433 | case AF_INET: |
Trond Myklebust | 9f4c899 | 2009-03-12 14:51:32 -0400 | [diff] [blame] | 434 | return nfs_sockaddr_cmp_ip4(sa1, sa2); |
Ian Dall | d7371c4 | 2009-03-10 20:33:22 -0400 | [diff] [blame] | 435 | case AF_INET6: |
Trond Myklebust | 9f4c899 | 2009-03-12 14:51:32 -0400 | [diff] [blame] | 436 | return nfs_sockaddr_cmp_ip6(sa1, sa2); |
Ian Dall | d7371c4 | 2009-03-10 20:33:22 -0400 | [diff] [blame] | 437 | } |
| 438 | return 0; |
| 439 | } |
| 440 | |
Trond Myklebust | 3fbd67a | 2008-01-26 01:06:40 -0500 | [diff] [blame] | 441 | /* |
Trond Myklebust | c81468a | 2007-12-14 14:56:05 -0500 | [diff] [blame] | 442 | * Find an nfs_client on the list that matches the initialisation data |
| 443 | * that is supplied. |
| 444 | */ |
| 445 | static struct nfs_client *nfs_match_client(const struct nfs_client_initdata *data) |
David Howells | 24c8dbb | 2006-08-22 20:06:10 -0400 | [diff] [blame] | 446 | { |
| 447 | struct nfs_client *clp; |
Ian Dall | d7371c4 | 2009-03-10 20:33:22 -0400 | [diff] [blame] | 448 | const struct sockaddr *sap = data->addr; |
Stanislav Kinsbursky | 6b13168 | 2012-01-23 17:26:05 +0000 | [diff] [blame] | 449 | struct nfs_net *nn = net_generic(data->net, nfs_net_id); |
David Howells | 24c8dbb | 2006-08-22 20:06:10 -0400 | [diff] [blame] | 450 | |
Stanislav Kinsbursky | 6b13168 | 2012-01-23 17:26:05 +0000 | [diff] [blame] | 451 | list_for_each_entry(clp, &nn->nfs_client_list, cl_share_link) { |
Ian Dall | d7371c4 | 2009-03-10 20:33:22 -0400 | [diff] [blame] | 452 | const struct sockaddr *clap = (struct sockaddr *)&clp->cl_addr; |
Trond Myklebust | 13bbc06 | 2006-10-19 23:28:40 -0700 | [diff] [blame] | 453 | /* Don't match clients that failed to initialise properly */ |
| 454 | if (clp->cl_cons_state < 0) |
| 455 | continue; |
| 456 | |
David Howells | 24c8dbb | 2006-08-22 20:06:10 -0400 | [diff] [blame] | 457 | /* Different NFS versions cannot share the same nfs_client */ |
Trond Myklebust | 40c55319 | 2007-12-14 14:56:07 -0500 | [diff] [blame] | 458 | if (clp->rpc_ops != data->rpc_ops) |
David Howells | 24c8dbb | 2006-08-22 20:06:10 -0400 | [diff] [blame] | 459 | continue; |
| 460 | |
Trond Myklebust | 59dca3b | 2008-01-03 16:29:06 -0500 | [diff] [blame] | 461 | if (clp->cl_proto != data->proto) |
| 462 | continue; |
Benny Halevy | 5aae4a9 | 2009-04-01 09:21:50 -0400 | [diff] [blame] | 463 | /* Match nfsv4 minorversion */ |
| 464 | if (clp->cl_minorversion != data->minorversion) |
| 465 | continue; |
Trond Myklebust | c81468a | 2007-12-14 14:56:05 -0500 | [diff] [blame] | 466 | /* Match the full socket address */ |
Ian Dall | d7371c4 | 2009-03-10 20:33:22 -0400 | [diff] [blame] | 467 | if (!nfs_sockaddr_cmp(sap, clap)) |
David Howells | 24c8dbb | 2006-08-22 20:06:10 -0400 | [diff] [blame] | 468 | continue; |
| 469 | |
Trond Myklebust | c81468a | 2007-12-14 14:56:05 -0500 | [diff] [blame] | 470 | atomic_inc(&clp->cl_count); |
| 471 | return clp; |
David Howells | 24c8dbb | 2006-08-22 20:06:10 -0400 | [diff] [blame] | 472 | } |
David Howells | 24c8dbb | 2006-08-22 20:06:10 -0400 | [diff] [blame] | 473 | return NULL; |
David Howells | 24c8dbb | 2006-08-22 20:06:10 -0400 | [diff] [blame] | 474 | } |
| 475 | |
Trond Myklebust | 4697bd5 | 2012-05-23 13:24:36 -0400 | [diff] [blame] | 476 | static bool nfs_client_init_is_complete(const struct nfs_client *clp) |
| 477 | { |
| 478 | return clp->cl_cons_state != NFS_CS_INITING; |
| 479 | } |
| 480 | |
| 481 | int nfs_wait_client_init_complete(const struct nfs_client *clp) |
| 482 | { |
| 483 | return wait_event_killable(nfs_client_active_wq, |
| 484 | nfs_client_init_is_complete(clp)); |
| 485 | } |
| 486 | |
David Howells | 24c8dbb | 2006-08-22 20:06:10 -0400 | [diff] [blame] | 487 | /* |
Chuck Lever | f411703 | 2012-05-21 22:45:50 -0400 | [diff] [blame] | 488 | * Found an existing client. Make sure it's ready before returning. |
| 489 | */ |
| 490 | static struct nfs_client * |
| 491 | nfs_found_client(const struct nfs_client_initdata *cl_init, |
| 492 | struct nfs_client *clp) |
| 493 | { |
| 494 | int error; |
| 495 | |
Trond Myklebust | 4697bd5 | 2012-05-23 13:24:36 -0400 | [diff] [blame] | 496 | error = nfs_wait_client_init_complete(clp); |
Chuck Lever | f411703 | 2012-05-21 22:45:50 -0400 | [diff] [blame] | 497 | if (error < 0) { |
| 498 | nfs_put_client(clp); |
| 499 | return ERR_PTR(-ERESTARTSYS); |
| 500 | } |
| 501 | |
| 502 | if (clp->cl_cons_state < NFS_CS_READY) { |
| 503 | error = clp->cl_cons_state; |
| 504 | nfs_put_client(clp); |
| 505 | return ERR_PTR(error); |
| 506 | } |
| 507 | |
Trond Myklebust | 54ac471 | 2012-05-23 13:26:10 -0400 | [diff] [blame] | 508 | smp_rmb(); |
| 509 | |
Chuck Lever | f411703 | 2012-05-21 22:45:50 -0400 | [diff] [blame] | 510 | dprintk("<-- %s found nfs_client %p for %s\n", |
| 511 | __func__, clp, cl_init->hostname ?: ""); |
| 512 | return clp; |
| 513 | } |
| 514 | |
| 515 | /* |
David Howells | 24c8dbb | 2006-08-22 20:06:10 -0400 | [diff] [blame] | 516 | * Look up a client by IP address and protocol version |
| 517 | * - creates a new record if one doesn't yet exist |
| 518 | */ |
Bryan Schumaker | fcf1039 | 2012-07-16 16:39:18 -0400 | [diff] [blame^] | 519 | struct nfs_client * |
Andy Adamson | 45a52a0 | 2011-03-01 01:34:08 +0000 | [diff] [blame] | 520 | nfs_get_client(const struct nfs_client_initdata *cl_init, |
| 521 | const struct rpc_timeout *timeparms, |
| 522 | const char *ip_addr, |
Chuck Lever | 4bf590e | 2012-05-21 22:46:07 -0400 | [diff] [blame] | 523 | rpc_authflavor_t authflavour) |
David Howells | 24c8dbb | 2006-08-22 20:06:10 -0400 | [diff] [blame] | 524 | { |
| 525 | struct nfs_client *clp, *new = NULL; |
Stanislav Kinsbursky | 6b13168 | 2012-01-23 17:26:05 +0000 | [diff] [blame] | 526 | struct nfs_net *nn = net_generic(cl_init->net, nfs_net_id); |
David Howells | 24c8dbb | 2006-08-22 20:06:10 -0400 | [diff] [blame] | 527 | |
Chuck Lever | d7422c4 | 2007-12-10 14:58:51 -0500 | [diff] [blame] | 528 | dprintk("--> nfs_get_client(%s,v%u)\n", |
| 529 | cl_init->hostname ?: "", cl_init->rpc_ops->version); |
David Howells | 24c8dbb | 2006-08-22 20:06:10 -0400 | [diff] [blame] | 530 | |
| 531 | /* see if the client already exists */ |
| 532 | do { |
Stanislav Kinsbursky | dc03085 | 2012-01-23 17:26:31 +0000 | [diff] [blame] | 533 | spin_lock(&nn->nfs_client_lock); |
David Howells | 24c8dbb | 2006-08-22 20:06:10 -0400 | [diff] [blame] | 534 | |
Trond Myklebust | c81468a | 2007-12-14 14:56:05 -0500 | [diff] [blame] | 535 | clp = nfs_match_client(cl_init); |
Chuck Lever | f411703 | 2012-05-21 22:45:50 -0400 | [diff] [blame] | 536 | if (clp) { |
| 537 | spin_unlock(&nn->nfs_client_lock); |
| 538 | if (new) |
Bryan Schumaker | cdb7ece | 2012-06-20 15:53:45 -0400 | [diff] [blame] | 539 | new->rpc_ops->free_client(new); |
Chuck Lever | f411703 | 2012-05-21 22:45:50 -0400 | [diff] [blame] | 540 | return nfs_found_client(cl_init, clp); |
| 541 | } |
Chuck Lever | 8cab4c3 | 2012-05-21 22:45:59 -0400 | [diff] [blame] | 542 | if (new) { |
| 543 | list_add(&new->cl_share_link, &nn->nfs_client_list); |
| 544 | spin_unlock(&nn->nfs_client_lock); |
Chuck Lever | 4bf590e | 2012-05-21 22:46:07 -0400 | [diff] [blame] | 545 | new->cl_flags = cl_init->init_flags; |
Chuck Lever | 8cab4c3 | 2012-05-21 22:45:59 -0400 | [diff] [blame] | 546 | return cl_init->rpc_ops->init_client(new, |
| 547 | timeparms, ip_addr, |
Chuck Lever | 4bf590e | 2012-05-21 22:46:07 -0400 | [diff] [blame] | 548 | authflavour); |
Chuck Lever | 8cab4c3 | 2012-05-21 22:45:59 -0400 | [diff] [blame] | 549 | } |
David Howells | 24c8dbb | 2006-08-22 20:06:10 -0400 | [diff] [blame] | 550 | |
Stanislav Kinsbursky | dc03085 | 2012-01-23 17:26:31 +0000 | [diff] [blame] | 551 | spin_unlock(&nn->nfs_client_lock); |
David Howells | 24c8dbb | 2006-08-22 20:06:10 -0400 | [diff] [blame] | 552 | |
Bryan Schumaker | 6663ee7 | 2012-06-20 15:53:46 -0400 | [diff] [blame] | 553 | new = cl_init->rpc_ops->alloc_client(cl_init); |
Chuck Lever | a21bdd9 | 2009-06-17 18:02:10 -0700 | [diff] [blame] | 554 | } while (!IS_ERR(new)); |
David Howells | 24c8dbb | 2006-08-22 20:06:10 -0400 | [diff] [blame] | 555 | |
Chuck Lever | f411703 | 2012-05-21 22:45:50 -0400 | [diff] [blame] | 556 | dprintk("<-- nfs_get_client() Failed to find %s (%ld)\n", |
| 557 | cl_init->hostname ?: "", PTR_ERR(new)); |
Chuck Lever | a21bdd9 | 2009-06-17 18:02:10 -0700 | [diff] [blame] | 558 | return new; |
David Howells | 24c8dbb | 2006-08-22 20:06:10 -0400 | [diff] [blame] | 559 | } |
| 560 | |
| 561 | /* |
| 562 | * Mark a server as ready or failed |
| 563 | */ |
Andy Adamson | 76db6d9 | 2009-04-01 09:22:38 -0400 | [diff] [blame] | 564 | void nfs_mark_client_ready(struct nfs_client *clp, int state) |
David Howells | 24c8dbb | 2006-08-22 20:06:10 -0400 | [diff] [blame] | 565 | { |
Trond Myklebust | 54ac471 | 2012-05-23 13:26:10 -0400 | [diff] [blame] | 566 | smp_wmb(); |
David Howells | 24c8dbb | 2006-08-22 20:06:10 -0400 | [diff] [blame] | 567 | clp->cl_cons_state = state; |
| 568 | wake_up_all(&nfs_client_active_wq); |
| 569 | } |
David Howells | 5006a76 | 2006-08-22 20:06:12 -0400 | [diff] [blame] | 570 | |
| 571 | /* |
| 572 | * Initialise the timeout values for a connection |
| 573 | */ |
Bryan Schumaker | fcf1039 | 2012-07-16 16:39:18 -0400 | [diff] [blame^] | 574 | void nfs_init_timeout_values(struct rpc_timeout *to, int proto, |
David Howells | 5006a76 | 2006-08-22 20:06:12 -0400 | [diff] [blame] | 575 | unsigned int timeo, unsigned int retrans) |
| 576 | { |
| 577 | to->to_initval = timeo * HZ / 10; |
| 578 | to->to_retries = retrans; |
David Howells | 5006a76 | 2006-08-22 20:06:12 -0400 | [diff] [blame] | 579 | |
| 580 | switch (proto) { |
\"Talpey, Thomas\ | 0896a725 | 2007-09-10 13:48:23 -0400 | [diff] [blame] | 581 | case XPRT_TRANSPORT_TCP: |
\"Talpey, Thomas\ | 2cf7ff7 | 2007-09-10 13:49:41 -0400 | [diff] [blame] | 582 | case XPRT_TRANSPORT_RDMA: |
Trond Myklebust | 259875e | 2008-07-02 14:43:47 -0400 | [diff] [blame] | 583 | if (to->to_retries == 0) |
| 584 | to->to_retries = NFS_DEF_TCP_RETRANS; |
Trond Myklebust | 7a3e3e1 | 2007-12-20 16:03:57 -0500 | [diff] [blame] | 585 | if (to->to_initval == 0) |
Trond Myklebust | 259875e | 2008-07-02 14:43:47 -0400 | [diff] [blame] | 586 | to->to_initval = NFS_DEF_TCP_TIMEO * HZ / 10; |
David Howells | 5006a76 | 2006-08-22 20:06:12 -0400 | [diff] [blame] | 587 | if (to->to_initval > NFS_MAX_TCP_TIMEOUT) |
| 588 | to->to_initval = NFS_MAX_TCP_TIMEOUT; |
| 589 | to->to_increment = to->to_initval; |
| 590 | to->to_maxval = to->to_initval + (to->to_increment * to->to_retries); |
Trond Myklebust | 7a3e3e1 | 2007-12-20 16:03:57 -0500 | [diff] [blame] | 591 | if (to->to_maxval > NFS_MAX_TCP_TIMEOUT) |
| 592 | to->to_maxval = NFS_MAX_TCP_TIMEOUT; |
| 593 | if (to->to_maxval < to->to_initval) |
| 594 | to->to_maxval = to->to_initval; |
David Howells | 5006a76 | 2006-08-22 20:06:12 -0400 | [diff] [blame] | 595 | to->to_exponential = 0; |
| 596 | break; |
\"Talpey, Thomas\ | 0896a725 | 2007-09-10 13:48:23 -0400 | [diff] [blame] | 597 | case XPRT_TRANSPORT_UDP: |
Trond Myklebust | 259875e | 2008-07-02 14:43:47 -0400 | [diff] [blame] | 598 | if (to->to_retries == 0) |
| 599 | to->to_retries = NFS_DEF_UDP_RETRANS; |
David Howells | 5006a76 | 2006-08-22 20:06:12 -0400 | [diff] [blame] | 600 | if (!to->to_initval) |
Trond Myklebust | 259875e | 2008-07-02 14:43:47 -0400 | [diff] [blame] | 601 | to->to_initval = NFS_DEF_UDP_TIMEO * HZ / 10; |
David Howells | 5006a76 | 2006-08-22 20:06:12 -0400 | [diff] [blame] | 602 | if (to->to_initval > NFS_MAX_UDP_TIMEOUT) |
| 603 | to->to_initval = NFS_MAX_UDP_TIMEOUT; |
| 604 | to->to_maxval = NFS_MAX_UDP_TIMEOUT; |
| 605 | to->to_exponential = 1; |
| 606 | break; |
Trond Myklebust | 259875e | 2008-07-02 14:43:47 -0400 | [diff] [blame] | 607 | default: |
| 608 | BUG(); |
David Howells | 5006a76 | 2006-08-22 20:06:12 -0400 | [diff] [blame] | 609 | } |
| 610 | } |
| 611 | |
| 612 | /* |
| 613 | * Create an RPC client handle |
| 614 | */ |
Bryan Schumaker | 428360d | 2012-07-16 16:39:17 -0400 | [diff] [blame] | 615 | int nfs_create_rpc_client(struct nfs_client *clp, |
| 616 | const struct rpc_timeout *timeparms, |
| 617 | rpc_authflavor_t flavor) |
David Howells | 5006a76 | 2006-08-22 20:06:12 -0400 | [diff] [blame] | 618 | { |
David Howells | 5006a76 | 2006-08-22 20:06:12 -0400 | [diff] [blame] | 619 | struct rpc_clnt *clnt = NULL; |
Chuck Lever | 41877d2 | 2006-08-22 20:06:20 -0400 | [diff] [blame] | 620 | struct rpc_create_args args = { |
Chuck Lever | 73ea666 | 2012-05-21 22:44:50 -0400 | [diff] [blame] | 621 | .net = clp->cl_net, |
Trond Myklebust | 59dca3b | 2008-01-03 16:29:06 -0500 | [diff] [blame] | 622 | .protocol = clp->cl_proto, |
Chuck Lever | 41877d2 | 2006-08-22 20:06:20 -0400 | [diff] [blame] | 623 | .address = (struct sockaddr *)&clp->cl_addr, |
Chuck Lever | 6e4cffd | 2007-12-10 14:58:15 -0500 | [diff] [blame] | 624 | .addrsize = clp->cl_addrlen, |
Trond Myklebust | 3317023 | 2007-12-20 16:03:59 -0500 | [diff] [blame] | 625 | .timeout = timeparms, |
Chuck Lever | 41877d2 | 2006-08-22 20:06:20 -0400 | [diff] [blame] | 626 | .servername = clp->cl_hostname, |
| 627 | .program = &nfs_program, |
| 628 | .version = clp->rpc_ops->version, |
| 629 | .authflavor = flavor, |
| 630 | }; |
David Howells | 5006a76 | 2006-08-22 20:06:12 -0400 | [diff] [blame] | 631 | |
Chuck Lever | 4bf590e | 2012-05-21 22:46:07 -0400 | [diff] [blame] | 632 | if (test_bit(NFS_CS_DISCRTRY, &clp->cl_flags)) |
Chuck Lever | 4a01b8a | 2008-12-23 15:21:35 -0500 | [diff] [blame] | 633 | args.flags |= RPC_CLNT_CREATE_DISCRTRY; |
Chuck Lever | 4bf590e | 2012-05-21 22:46:07 -0400 | [diff] [blame] | 634 | if (test_bit(NFS_CS_NORESVPORT, &clp->cl_flags)) |
Chuck Lever | 4a01b8a | 2008-12-23 15:21:35 -0500 | [diff] [blame] | 635 | args.flags |= RPC_CLNT_CREATE_NONPRIVPORT; |
| 636 | |
David Howells | 5006a76 | 2006-08-22 20:06:12 -0400 | [diff] [blame] | 637 | if (!IS_ERR(clp->cl_rpcclient)) |
| 638 | return 0; |
| 639 | |
Chuck Lever | 41877d2 | 2006-08-22 20:06:20 -0400 | [diff] [blame] | 640 | clnt = rpc_create(&args); |
David Howells | 5006a76 | 2006-08-22 20:06:12 -0400 | [diff] [blame] | 641 | if (IS_ERR(clnt)) { |
| 642 | dprintk("%s: cannot create RPC client. Error = %ld\n", |
Harvey Harrison | 3110ff8 | 2008-05-02 13:42:44 -0700 | [diff] [blame] | 643 | __func__, PTR_ERR(clnt)); |
David Howells | 5006a76 | 2006-08-22 20:06:12 -0400 | [diff] [blame] | 644 | return PTR_ERR(clnt); |
| 645 | } |
| 646 | |
David Howells | 5006a76 | 2006-08-22 20:06:12 -0400 | [diff] [blame] | 647 | clp->cl_rpcclient = clnt; |
| 648 | return 0; |
| 649 | } |
David Howells | 54ceac4 | 2006-08-22 20:06:13 -0400 | [diff] [blame] | 650 | |
| 651 | /* |
| 652 | * Version 2 or 3 client destruction |
| 653 | */ |
| 654 | static void nfs_destroy_server(struct nfs_server *server) |
| 655 | { |
Suresh Jayaraman | 5eebde2 | 2010-09-23 08:55:58 -0400 | [diff] [blame] | 656 | if (!(server->flags & NFS_MOUNT_LOCAL_FLOCK) || |
| 657 | !(server->flags & NFS_MOUNT_LOCAL_FCNTL)) |
Chuck Lever | 9289e7f | 2008-01-11 17:09:52 -0500 | [diff] [blame] | 658 | nlmclnt_done(server->nlm_host); |
David Howells | 54ceac4 | 2006-08-22 20:06:13 -0400 | [diff] [blame] | 659 | } |
| 660 | |
| 661 | /* |
| 662 | * Version 2 or 3 lockd setup |
| 663 | */ |
| 664 | static int nfs_start_lockd(struct nfs_server *server) |
| 665 | { |
Chuck Lever | 9289e7f | 2008-01-11 17:09:52 -0500 | [diff] [blame] | 666 | struct nlm_host *host; |
| 667 | struct nfs_client *clp = server->nfs_client; |
Chuck Lever | 883bb16 | 2008-01-15 16:04:20 -0500 | [diff] [blame] | 668 | struct nlmclnt_initdata nlm_init = { |
| 669 | .hostname = clp->cl_hostname, |
| 670 | .address = (struct sockaddr *)&clp->cl_addr, |
| 671 | .addrlen = clp->cl_addrlen, |
Chuck Lever | 883bb16 | 2008-01-15 16:04:20 -0500 | [diff] [blame] | 672 | .nfs_version = clp->rpc_ops->version, |
Chuck Lever | 0cb2659 | 2008-12-23 15:21:38 -0500 | [diff] [blame] | 673 | .noresvport = server->flags & NFS_MOUNT_NORESVPORT ? |
| 674 | 1 : 0, |
Chuck Lever | 73ea666 | 2012-05-21 22:44:50 -0400 | [diff] [blame] | 675 | .net = clp->cl_net, |
Chuck Lever | 883bb16 | 2008-01-15 16:04:20 -0500 | [diff] [blame] | 676 | }; |
David Howells | 54ceac4 | 2006-08-22 20:06:13 -0400 | [diff] [blame] | 677 | |
Chuck Lever | 883bb16 | 2008-01-15 16:04:20 -0500 | [diff] [blame] | 678 | if (nlm_init.nfs_version > 3) |
Chuck Lever | 9289e7f | 2008-01-11 17:09:52 -0500 | [diff] [blame] | 679 | return 0; |
Suresh Jayaraman | 5eebde2 | 2010-09-23 08:55:58 -0400 | [diff] [blame] | 680 | if ((server->flags & NFS_MOUNT_LOCAL_FLOCK) && |
| 681 | (server->flags & NFS_MOUNT_LOCAL_FCNTL)) |
Chuck Lever | 9289e7f | 2008-01-11 17:09:52 -0500 | [diff] [blame] | 682 | return 0; |
| 683 | |
Trond Myklebust | 8a6e5de | 2009-09-23 14:36:37 -0400 | [diff] [blame] | 684 | switch (clp->cl_proto) { |
| 685 | default: |
| 686 | nlm_init.protocol = IPPROTO_TCP; |
| 687 | break; |
| 688 | case XPRT_TRANSPORT_UDP: |
| 689 | nlm_init.protocol = IPPROTO_UDP; |
| 690 | } |
| 691 | |
Chuck Lever | 883bb16 | 2008-01-15 16:04:20 -0500 | [diff] [blame] | 692 | host = nlmclnt_init(&nlm_init); |
Chuck Lever | 9289e7f | 2008-01-11 17:09:52 -0500 | [diff] [blame] | 693 | if (IS_ERR(host)) |
| 694 | return PTR_ERR(host); |
| 695 | |
| 696 | server->nlm_host = host; |
| 697 | server->destroy = nfs_destroy_server; |
| 698 | return 0; |
David Howells | 54ceac4 | 2006-08-22 20:06:13 -0400 | [diff] [blame] | 699 | } |
| 700 | |
| 701 | /* |
| 702 | * Initialise an NFSv3 ACL client connection |
| 703 | */ |
| 704 | #ifdef CONFIG_NFS_V3_ACL |
| 705 | static void nfs_init_server_aclclient(struct nfs_server *server) |
| 706 | { |
Trond Myklebust | 40c55319 | 2007-12-14 14:56:07 -0500 | [diff] [blame] | 707 | if (server->nfs_client->rpc_ops->version != 3) |
David Howells | 54ceac4 | 2006-08-22 20:06:13 -0400 | [diff] [blame] | 708 | goto out_noacl; |
| 709 | if (server->flags & NFS_MOUNT_NOACL) |
| 710 | goto out_noacl; |
| 711 | |
| 712 | server->client_acl = rpc_bind_new_program(server->client, &nfsacl_program, 3); |
| 713 | if (IS_ERR(server->client_acl)) |
| 714 | goto out_noacl; |
| 715 | |
| 716 | /* No errors! Assume that Sun nfsacls are supported */ |
| 717 | server->caps |= NFS_CAP_ACLS; |
| 718 | return; |
| 719 | |
| 720 | out_noacl: |
| 721 | server->caps &= ~NFS_CAP_ACLS; |
| 722 | } |
| 723 | #else |
| 724 | static inline void nfs_init_server_aclclient(struct nfs_server *server) |
| 725 | { |
| 726 | server->flags &= ~NFS_MOUNT_NOACL; |
| 727 | server->caps &= ~NFS_CAP_ACLS; |
| 728 | } |
| 729 | #endif |
| 730 | |
| 731 | /* |
| 732 | * Create a general RPC client |
| 733 | */ |
Bryan Schumaker | fcf1039 | 2012-07-16 16:39:18 -0400 | [diff] [blame^] | 734 | int nfs_init_server_rpcclient(struct nfs_server *server, |
Trond Myklebust | 3317023 | 2007-12-20 16:03:59 -0500 | [diff] [blame] | 735 | const struct rpc_timeout *timeo, |
| 736 | rpc_authflavor_t pseudoflavour) |
David Howells | 54ceac4 | 2006-08-22 20:06:13 -0400 | [diff] [blame] | 737 | { |
| 738 | struct nfs_client *clp = server->nfs_client; |
| 739 | |
| 740 | server->client = rpc_clone_client(clp->cl_rpcclient); |
| 741 | if (IS_ERR(server->client)) { |
Harvey Harrison | 3110ff8 | 2008-05-02 13:42:44 -0700 | [diff] [blame] | 742 | dprintk("%s: couldn't create rpc_client!\n", __func__); |
David Howells | 54ceac4 | 2006-08-22 20:06:13 -0400 | [diff] [blame] | 743 | return PTR_ERR(server->client); |
| 744 | } |
| 745 | |
Trond Myklebust | 3317023 | 2007-12-20 16:03:59 -0500 | [diff] [blame] | 746 | memcpy(&server->client->cl_timeout_default, |
| 747 | timeo, |
| 748 | sizeof(server->client->cl_timeout_default)); |
| 749 | server->client->cl_timeout = &server->client->cl_timeout_default; |
| 750 | |
David Howells | 54ceac4 | 2006-08-22 20:06:13 -0400 | [diff] [blame] | 751 | if (pseudoflavour != clp->cl_rpcclient->cl_auth->au_flavor) { |
| 752 | struct rpc_auth *auth; |
| 753 | |
| 754 | auth = rpcauth_create(pseudoflavour, server->client); |
| 755 | if (IS_ERR(auth)) { |
Harvey Harrison | 3110ff8 | 2008-05-02 13:42:44 -0700 | [diff] [blame] | 756 | dprintk("%s: couldn't create credcache!\n", __func__); |
David Howells | 54ceac4 | 2006-08-22 20:06:13 -0400 | [diff] [blame] | 757 | return PTR_ERR(auth); |
| 758 | } |
| 759 | } |
| 760 | server->client->cl_softrtry = 0; |
| 761 | if (server->flags & NFS_MOUNT_SOFT) |
| 762 | server->client->cl_softrtry = 1; |
| 763 | |
David Howells | 54ceac4 | 2006-08-22 20:06:13 -0400 | [diff] [blame] | 764 | return 0; |
| 765 | } |
| 766 | |
Chuck Lever | 8cab4c3 | 2012-05-21 22:45:59 -0400 | [diff] [blame] | 767 | /** |
| 768 | * nfs_init_client - Initialise an NFS2 or NFS3 client |
| 769 | * |
| 770 | * @clp: nfs_client to initialise |
| 771 | * @timeparms: timeout parameters for underlying RPC transport |
| 772 | * @ip_addr: IP presentation address (not used) |
| 773 | * @authflavor: authentication flavor for underlying RPC transport |
Chuck Lever | 8cab4c3 | 2012-05-21 22:45:59 -0400 | [diff] [blame] | 774 | * |
| 775 | * Returns pointer to an NFS client, or an ERR_PTR value. |
David Howells | 54ceac4 | 2006-08-22 20:06:13 -0400 | [diff] [blame] | 776 | */ |
Chuck Lever | 8cab4c3 | 2012-05-21 22:45:59 -0400 | [diff] [blame] | 777 | struct nfs_client *nfs_init_client(struct nfs_client *clp, |
| 778 | const struct rpc_timeout *timeparms, |
Chuck Lever | 4bf590e | 2012-05-21 22:46:07 -0400 | [diff] [blame] | 779 | const char *ip_addr, rpc_authflavor_t authflavour) |
David Howells | 54ceac4 | 2006-08-22 20:06:13 -0400 | [diff] [blame] | 780 | { |
David Howells | 54ceac4 | 2006-08-22 20:06:13 -0400 | [diff] [blame] | 781 | int error; |
| 782 | |
| 783 | if (clp->cl_cons_state == NFS_CS_READY) { |
| 784 | /* the client is already initialised */ |
| 785 | dprintk("<-- nfs_init_client() = 0 [already %p]\n", clp); |
Chuck Lever | 8cab4c3 | 2012-05-21 22:45:59 -0400 | [diff] [blame] | 786 | return clp; |
David Howells | 54ceac4 | 2006-08-22 20:06:13 -0400 | [diff] [blame] | 787 | } |
| 788 | |
David Howells | 54ceac4 | 2006-08-22 20:06:13 -0400 | [diff] [blame] | 789 | /* |
| 790 | * Create a client RPC handle for doing FSSTAT with UNIX auth only |
| 791 | * - RFC 2623, sec 2.3.2 |
| 792 | */ |
Chuck Lever | 4bf590e | 2012-05-21 22:46:07 -0400 | [diff] [blame] | 793 | error = nfs_create_rpc_client(clp, timeparms, RPC_AUTH_UNIX); |
David Howells | 54ceac4 | 2006-08-22 20:06:13 -0400 | [diff] [blame] | 794 | if (error < 0) |
| 795 | goto error; |
| 796 | nfs_mark_client_ready(clp, NFS_CS_READY); |
Chuck Lever | 8cab4c3 | 2012-05-21 22:45:59 -0400 | [diff] [blame] | 797 | return clp; |
David Howells | 54ceac4 | 2006-08-22 20:06:13 -0400 | [diff] [blame] | 798 | |
| 799 | error: |
| 800 | nfs_mark_client_ready(clp, error); |
Chuck Lever | 8cab4c3 | 2012-05-21 22:45:59 -0400 | [diff] [blame] | 801 | nfs_put_client(clp); |
David Howells | 54ceac4 | 2006-08-22 20:06:13 -0400 | [diff] [blame] | 802 | dprintk("<-- nfs_init_client() = xerror %d\n", error); |
Chuck Lever | 8cab4c3 | 2012-05-21 22:45:59 -0400 | [diff] [blame] | 803 | return ERR_PTR(error); |
David Howells | 54ceac4 | 2006-08-22 20:06:13 -0400 | [diff] [blame] | 804 | } |
| 805 | |
| 806 | /* |
| 807 | * Create a version 2 or 3 client |
| 808 | */ |
\"Talpey, Thomas\ | 2283f8d | 2007-09-10 13:43:56 -0400 | [diff] [blame] | 809 | static int nfs_init_server(struct nfs_server *server, |
| 810 | const struct nfs_parsed_mount_data *data) |
David Howells | 54ceac4 | 2006-08-22 20:06:13 -0400 | [diff] [blame] | 811 | { |
Trond Myklebust | 3a49802 | 2007-12-14 14:56:04 -0500 | [diff] [blame] | 812 | struct nfs_client_initdata cl_init = { |
| 813 | .hostname = data->nfs_server.hostname, |
Chuck Lever | d7422c4 | 2007-12-10 14:58:51 -0500 | [diff] [blame] | 814 | .addr = (const struct sockaddr *)&data->nfs_server.address, |
Chuck Lever | 4c56801 | 2007-12-10 14:59:28 -0500 | [diff] [blame] | 815 | .addrlen = data->nfs_server.addrlen, |
Bryan Schumaker | 2ba6800 | 2012-05-10 16:47:19 -0400 | [diff] [blame] | 816 | .rpc_ops = NULL, |
Trond Myklebust | 59dca3b | 2008-01-03 16:29:06 -0500 | [diff] [blame] | 817 | .proto = data->nfs_server.protocol, |
Stanislav Kinsbursky | e50a7a1 | 2012-01-10 16:12:46 +0400 | [diff] [blame] | 818 | .net = data->net, |
Trond Myklebust | 3a49802 | 2007-12-14 14:56:04 -0500 | [diff] [blame] | 819 | }; |
Trond Myklebust | 3317023 | 2007-12-20 16:03:59 -0500 | [diff] [blame] | 820 | struct rpc_timeout timeparms; |
David Howells | 54ceac4 | 2006-08-22 20:06:13 -0400 | [diff] [blame] | 821 | struct nfs_client *clp; |
Trond Myklebust | 3a49802 | 2007-12-14 14:56:04 -0500 | [diff] [blame] | 822 | int error; |
David Howells | 54ceac4 | 2006-08-22 20:06:13 -0400 | [diff] [blame] | 823 | |
| 824 | dprintk("--> nfs_init_server()\n"); |
| 825 | |
Bryan Schumaker | 2ba6800 | 2012-05-10 16:47:19 -0400 | [diff] [blame] | 826 | switch (data->version) { |
| 827 | #ifdef CONFIG_NFS_V2 |
| 828 | case 2: |
| 829 | cl_init.rpc_ops = &nfs_v2_clientops; |
| 830 | break; |
David Howells | 54ceac4 | 2006-08-22 20:06:13 -0400 | [diff] [blame] | 831 | #endif |
Bryan Schumaker | 2ba6800 | 2012-05-10 16:47:19 -0400 | [diff] [blame] | 832 | #ifdef CONFIG_NFS_V3 |
| 833 | case 3: |
| 834 | cl_init.rpc_ops = &nfs_v3_clientops; |
| 835 | break; |
| 836 | #endif |
| 837 | default: |
| 838 | return -EPROTONOSUPPORT; |
| 839 | } |
David Howells | 54ceac4 | 2006-08-22 20:06:13 -0400 | [diff] [blame] | 840 | |
Andy Adamson | 45a52a0 | 2011-03-01 01:34:08 +0000 | [diff] [blame] | 841 | nfs_init_timeout_values(&timeparms, data->nfs_server.protocol, |
| 842 | data->timeo, data->retrans); |
Chuck Lever | 4bf590e | 2012-05-21 22:46:07 -0400 | [diff] [blame] | 843 | if (data->flags & NFS_MOUNT_NORESVPORT) |
| 844 | set_bit(NFS_CS_NORESVPORT, &cl_init.init_flags); |
Andy Adamson | 45a52a0 | 2011-03-01 01:34:08 +0000 | [diff] [blame] | 845 | |
David Howells | 54ceac4 | 2006-08-22 20:06:13 -0400 | [diff] [blame] | 846 | /* Allocate or find a client reference we can use */ |
Chuck Lever | 4bf590e | 2012-05-21 22:46:07 -0400 | [diff] [blame] | 847 | clp = nfs_get_client(&cl_init, &timeparms, NULL, RPC_AUTH_UNIX); |
David Howells | 54ceac4 | 2006-08-22 20:06:13 -0400 | [diff] [blame] | 848 | if (IS_ERR(clp)) { |
| 849 | dprintk("<-- nfs_init_server() = error %ld\n", PTR_ERR(clp)); |
| 850 | return PTR_ERR(clp); |
| 851 | } |
| 852 | |
David Howells | 54ceac4 | 2006-08-22 20:06:13 -0400 | [diff] [blame] | 853 | server->nfs_client = clp; |
| 854 | |
| 855 | /* Initialise the client representation from the mount data */ |
Trond Myklebust | ff3525a | 2008-08-15 16:59:14 -0400 | [diff] [blame] | 856 | server->flags = data->flags; |
David Howells | b797cac | 2009-04-03 16:42:48 +0100 | [diff] [blame] | 857 | server->options = data->options; |
Trond Myklebust | 62ab460 | 2009-08-09 15:06:19 -0400 | [diff] [blame] | 858 | server->caps |= NFS_CAP_HARDLINKS|NFS_CAP_SYMLINKS|NFS_CAP_FILEID| |
| 859 | NFS_CAP_MODE|NFS_CAP_NLINK|NFS_CAP_OWNER|NFS_CAP_OWNER_GROUP| |
Trond Myklebust | 3a1556e | 2012-04-27 13:48:18 -0400 | [diff] [blame] | 860 | NFS_CAP_ATIME|NFS_CAP_CTIME|NFS_CAP_MTIME|NFS_CAP_CHANGE_ATTR; |
David Howells | 54ceac4 | 2006-08-22 20:06:13 -0400 | [diff] [blame] | 861 | |
| 862 | if (data->rsize) |
| 863 | server->rsize = nfs_block_size(data->rsize, NULL); |
| 864 | if (data->wsize) |
| 865 | server->wsize = nfs_block_size(data->wsize, NULL); |
| 866 | |
| 867 | server->acregmin = data->acregmin * HZ; |
| 868 | server->acregmax = data->acregmax * HZ; |
| 869 | server->acdirmin = data->acdirmin * HZ; |
| 870 | server->acdirmax = data->acdirmax * HZ; |
| 871 | |
| 872 | /* Start lockd here, before we might error out */ |
| 873 | error = nfs_start_lockd(server); |
| 874 | if (error < 0) |
| 875 | goto error; |
| 876 | |
Chuck Lever | f22d6d7 | 2008-03-14 14:10:22 -0400 | [diff] [blame] | 877 | server->port = data->nfs_server.port; |
| 878 | |
Trond Myklebust | 3317023 | 2007-12-20 16:03:59 -0500 | [diff] [blame] | 879 | error = nfs_init_server_rpcclient(server, &timeparms, data->auth_flavors[0]); |
David Howells | 54ceac4 | 2006-08-22 20:06:13 -0400 | [diff] [blame] | 880 | if (error < 0) |
| 881 | goto error; |
| 882 | |
Chuck Lever | 3f8400d | 2008-03-14 14:10:30 -0400 | [diff] [blame] | 883 | /* Preserve the values of mount_server-related mount options */ |
| 884 | if (data->mount_server.addrlen) { |
| 885 | memcpy(&server->mountd_address, &data->mount_server.address, |
| 886 | data->mount_server.addrlen); |
| 887 | server->mountd_addrlen = data->mount_server.addrlen; |
| 888 | } |
| 889 | server->mountd_version = data->mount_server.version; |
| 890 | server->mountd_port = data->mount_server.port; |
| 891 | server->mountd_protocol = data->mount_server.protocol; |
| 892 | |
David Howells | 54ceac4 | 2006-08-22 20:06:13 -0400 | [diff] [blame] | 893 | server->namelen = data->namlen; |
| 894 | /* Create a client RPC handle for the NFSv3 ACL management interface */ |
| 895 | nfs_init_server_aclclient(server); |
David Howells | 54ceac4 | 2006-08-22 20:06:13 -0400 | [diff] [blame] | 896 | dprintk("<-- nfs_init_server() = 0 [new %p]\n", clp); |
| 897 | return 0; |
| 898 | |
| 899 | error: |
| 900 | server->nfs_client = NULL; |
| 901 | nfs_put_client(clp); |
| 902 | dprintk("<-- nfs_init_server() = xerror %d\n", error); |
| 903 | return error; |
| 904 | } |
| 905 | |
| 906 | /* |
| 907 | * Load up the server record from information gained in an fsinfo record |
| 908 | */ |
Benny Halevy | 738fd0f3 | 2011-07-30 20:52:36 -0400 | [diff] [blame] | 909 | static void nfs_server_set_fsinfo(struct nfs_server *server, |
| 910 | struct nfs_fh *mntfh, |
| 911 | struct nfs_fsinfo *fsinfo) |
David Howells | 54ceac4 | 2006-08-22 20:06:13 -0400 | [diff] [blame] | 912 | { |
| 913 | unsigned long max_rpc_payload; |
| 914 | |
| 915 | /* Work out a lot of parameters */ |
| 916 | if (server->rsize == 0) |
| 917 | server->rsize = nfs_block_size(fsinfo->rtpref, NULL); |
| 918 | if (server->wsize == 0) |
| 919 | server->wsize = nfs_block_size(fsinfo->wtpref, NULL); |
| 920 | |
| 921 | if (fsinfo->rtmax >= 512 && server->rsize > fsinfo->rtmax) |
| 922 | server->rsize = nfs_block_size(fsinfo->rtmax, NULL); |
| 923 | if (fsinfo->wtmax >= 512 && server->wsize > fsinfo->wtmax) |
| 924 | server->wsize = nfs_block_size(fsinfo->wtmax, NULL); |
| 925 | |
| 926 | max_rpc_payload = nfs_block_size(rpc_max_payload(server->client), NULL); |
| 927 | if (server->rsize > max_rpc_payload) |
| 928 | server->rsize = max_rpc_payload; |
| 929 | if (server->rsize > NFS_MAX_FILE_IO_SIZE) |
| 930 | server->rsize = NFS_MAX_FILE_IO_SIZE; |
| 931 | server->rpages = (server->rsize + PAGE_CACHE_SIZE - 1) >> PAGE_CACHE_SHIFT; |
Peter Zijlstra | e0bf68d | 2007-10-16 23:25:46 -0700 | [diff] [blame] | 932 | |
Jens Axboe | d993831 | 2009-06-12 14:45:52 +0200 | [diff] [blame] | 933 | server->backing_dev_info.name = "nfs"; |
David Howells | 54ceac4 | 2006-08-22 20:06:13 -0400 | [diff] [blame] | 934 | server->backing_dev_info.ra_pages = server->rpages * NFS_MAX_READAHEAD; |
| 935 | |
| 936 | if (server->wsize > max_rpc_payload) |
| 937 | server->wsize = max_rpc_payload; |
| 938 | if (server->wsize > NFS_MAX_FILE_IO_SIZE) |
| 939 | server->wsize = NFS_MAX_FILE_IO_SIZE; |
| 940 | server->wpages = (server->wsize + PAGE_CACHE_SIZE - 1) >> PAGE_CACHE_SHIFT; |
Fred Isaman | dae100c | 2011-07-30 20:52:37 -0400 | [diff] [blame] | 941 | server->pnfs_blksize = fsinfo->blksize; |
Ricardo Labiaga | 85e174b | 2010-10-20 00:17:58 -0400 | [diff] [blame] | 942 | |
David Howells | 54ceac4 | 2006-08-22 20:06:13 -0400 | [diff] [blame] | 943 | server->wtmult = nfs_block_bits(fsinfo->wtmult, NULL); |
| 944 | |
| 945 | server->dtsize = nfs_block_size(fsinfo->dtpref, NULL); |
Bryan Schumaker | 56e4ebf | 2010-10-20 15:44:37 -0400 | [diff] [blame] | 946 | if (server->dtsize > PAGE_CACHE_SIZE * NFS_MAX_READDIR_PAGES) |
| 947 | server->dtsize = PAGE_CACHE_SIZE * NFS_MAX_READDIR_PAGES; |
David Howells | 54ceac4 | 2006-08-22 20:06:13 -0400 | [diff] [blame] | 948 | if (server->dtsize > server->rsize) |
| 949 | server->dtsize = server->rsize; |
| 950 | |
| 951 | if (server->flags & NFS_MOUNT_NOAC) { |
| 952 | server->acregmin = server->acregmax = 0; |
| 953 | server->acdirmin = server->acdirmax = 0; |
| 954 | } |
| 955 | |
| 956 | server->maxfilesize = fsinfo->maxfilesize; |
| 957 | |
Ricardo Labiaga | 6b96724 | 2010-10-12 16:30:05 -0700 | [diff] [blame] | 958 | server->time_delta = fsinfo->time_delta; |
| 959 | |
David Howells | 54ceac4 | 2006-08-22 20:06:13 -0400 | [diff] [blame] | 960 | /* We're airborne Set socket buffersize */ |
| 961 | rpc_setbufsize(server->client, server->wsize + 100, server->rsize + 100); |
| 962 | } |
| 963 | |
| 964 | /* |
| 965 | * Probe filesystem information, including the FSID on v2/v3 |
| 966 | */ |
Bryan Schumaker | fcf1039 | 2012-07-16 16:39:18 -0400 | [diff] [blame^] | 967 | int nfs_probe_fsinfo(struct nfs_server *server, struct nfs_fh *mntfh, struct nfs_fattr *fattr) |
David Howells | 54ceac4 | 2006-08-22 20:06:13 -0400 | [diff] [blame] | 968 | { |
| 969 | struct nfs_fsinfo fsinfo; |
| 970 | struct nfs_client *clp = server->nfs_client; |
| 971 | int error; |
| 972 | |
| 973 | dprintk("--> nfs_probe_fsinfo()\n"); |
| 974 | |
| 975 | if (clp->rpc_ops->set_capabilities != NULL) { |
| 976 | error = clp->rpc_ops->set_capabilities(server, mntfh); |
| 977 | if (error < 0) |
| 978 | goto out_error; |
| 979 | } |
| 980 | |
| 981 | fsinfo.fattr = fattr; |
Ricardo Labiaga | 85e174b | 2010-10-20 00:17:58 -0400 | [diff] [blame] | 982 | fsinfo.layouttype = 0; |
David Howells | 54ceac4 | 2006-08-22 20:06:13 -0400 | [diff] [blame] | 983 | error = clp->rpc_ops->fsinfo(server, mntfh, &fsinfo); |
| 984 | if (error < 0) |
| 985 | goto out_error; |
| 986 | |
Benny Halevy | 738fd0f3 | 2011-07-30 20:52:36 -0400 | [diff] [blame] | 987 | nfs_server_set_fsinfo(server, mntfh, &fsinfo); |
David Howells | 54ceac4 | 2006-08-22 20:06:13 -0400 | [diff] [blame] | 988 | |
| 989 | /* Get some general file system info */ |
| 990 | if (server->namelen == 0) { |
| 991 | struct nfs_pathconf pathinfo; |
| 992 | |
| 993 | pathinfo.fattr = fattr; |
| 994 | nfs_fattr_init(fattr); |
| 995 | |
| 996 | if (clp->rpc_ops->pathconf(server, mntfh, &pathinfo) >= 0) |
| 997 | server->namelen = pathinfo.max_namelen; |
| 998 | } |
| 999 | |
| 1000 | dprintk("<-- nfs_probe_fsinfo() = 0\n"); |
| 1001 | return 0; |
| 1002 | |
| 1003 | out_error: |
| 1004 | dprintk("nfs_probe_fsinfo: error = %d\n", -error); |
| 1005 | return error; |
| 1006 | } |
| 1007 | |
| 1008 | /* |
| 1009 | * Copy useful information when duplicating a server record |
| 1010 | */ |
Bryan Schumaker | fcf1039 | 2012-07-16 16:39:18 -0400 | [diff] [blame^] | 1011 | void nfs_server_copy_userdata(struct nfs_server *target, struct nfs_server *source) |
David Howells | 54ceac4 | 2006-08-22 20:06:13 -0400 | [diff] [blame] | 1012 | { |
| 1013 | target->flags = source->flags; |
Chuck Lever | 356e76b | 2010-04-22 15:35:56 -0400 | [diff] [blame] | 1014 | target->rsize = source->rsize; |
| 1015 | target->wsize = source->wsize; |
David Howells | 54ceac4 | 2006-08-22 20:06:13 -0400 | [diff] [blame] | 1016 | target->acregmin = source->acregmin; |
| 1017 | target->acregmax = source->acregmax; |
| 1018 | target->acdirmin = source->acdirmin; |
| 1019 | target->acdirmax = source->acdirmax; |
| 1020 | target->caps = source->caps; |
David Howells | 2df5480 | 2009-09-23 14:36:39 -0400 | [diff] [blame] | 1021 | target->options = source->options; |
David Howells | 54ceac4 | 2006-08-22 20:06:13 -0400 | [diff] [blame] | 1022 | } |
| 1023 | |
Bryan Schumaker | fcf1039 | 2012-07-16 16:39:18 -0400 | [diff] [blame^] | 1024 | void nfs_server_insert_lists(struct nfs_server *server) |
Chuck Lever | fca5238 | 2010-12-24 01:32:32 +0000 | [diff] [blame] | 1025 | { |
| 1026 | struct nfs_client *clp = server->nfs_client; |
Chuck Lever | 73ea666 | 2012-05-21 22:44:50 -0400 | [diff] [blame] | 1027 | struct nfs_net *nn = net_generic(clp->cl_net, nfs_net_id); |
Chuck Lever | fca5238 | 2010-12-24 01:32:32 +0000 | [diff] [blame] | 1028 | |
Stanislav Kinsbursky | dc03085 | 2012-01-23 17:26:31 +0000 | [diff] [blame] | 1029 | spin_lock(&nn->nfs_client_lock); |
Chuck Lever | fca5238 | 2010-12-24 01:32:32 +0000 | [diff] [blame] | 1030 | list_add_tail_rcu(&server->client_link, &clp->cl_superblocks); |
Stanislav Kinsbursky | c25d32b | 2012-01-23 17:26:14 +0000 | [diff] [blame] | 1031 | list_add_tail(&server->master_link, &nn->nfs_volume_list); |
Andy Adamson | d3b4c9d | 2011-03-01 01:34:10 +0000 | [diff] [blame] | 1032 | clear_bit(NFS_CS_STOP_RENEW, &clp->cl_res_state); |
Stanislav Kinsbursky | dc03085 | 2012-01-23 17:26:31 +0000 | [diff] [blame] | 1033 | spin_unlock(&nn->nfs_client_lock); |
Chuck Lever | fca5238 | 2010-12-24 01:32:32 +0000 | [diff] [blame] | 1034 | |
| 1035 | } |
| 1036 | |
| 1037 | static void nfs_server_remove_lists(struct nfs_server *server) |
| 1038 | { |
Andy Adamson | d3b4c9d | 2011-03-01 01:34:10 +0000 | [diff] [blame] | 1039 | struct nfs_client *clp = server->nfs_client; |
Trond Myklebust | 4c03ae4 | 2012-02-07 00:05:11 -0500 | [diff] [blame] | 1040 | struct nfs_net *nn; |
Andy Adamson | d3b4c9d | 2011-03-01 01:34:10 +0000 | [diff] [blame] | 1041 | |
Trond Myklebust | 4c03ae4 | 2012-02-07 00:05:11 -0500 | [diff] [blame] | 1042 | if (clp == NULL) |
| 1043 | return; |
Chuck Lever | 73ea666 | 2012-05-21 22:44:50 -0400 | [diff] [blame] | 1044 | nn = net_generic(clp->cl_net, nfs_net_id); |
Stanislav Kinsbursky | dc03085 | 2012-01-23 17:26:31 +0000 | [diff] [blame] | 1045 | spin_lock(&nn->nfs_client_lock); |
Chuck Lever | fca5238 | 2010-12-24 01:32:32 +0000 | [diff] [blame] | 1046 | list_del_rcu(&server->client_link); |
Trond Myklebust | 4c03ae4 | 2012-02-07 00:05:11 -0500 | [diff] [blame] | 1047 | if (list_empty(&clp->cl_superblocks)) |
Andy Adamson | d3b4c9d | 2011-03-01 01:34:10 +0000 | [diff] [blame] | 1048 | set_bit(NFS_CS_STOP_RENEW, &clp->cl_res_state); |
Chuck Lever | fca5238 | 2010-12-24 01:32:32 +0000 | [diff] [blame] | 1049 | list_del(&server->master_link); |
Stanislav Kinsbursky | dc03085 | 2012-01-23 17:26:31 +0000 | [diff] [blame] | 1050 | spin_unlock(&nn->nfs_client_lock); |
Chuck Lever | fca5238 | 2010-12-24 01:32:32 +0000 | [diff] [blame] | 1051 | |
| 1052 | synchronize_rcu(); |
| 1053 | } |
| 1054 | |
David Howells | 54ceac4 | 2006-08-22 20:06:13 -0400 | [diff] [blame] | 1055 | /* |
| 1056 | * Allocate and initialise a server record |
| 1057 | */ |
Bryan Schumaker | fcf1039 | 2012-07-16 16:39:18 -0400 | [diff] [blame^] | 1058 | struct nfs_server *nfs_alloc_server(void) |
David Howells | 54ceac4 | 2006-08-22 20:06:13 -0400 | [diff] [blame] | 1059 | { |
| 1060 | struct nfs_server *server; |
| 1061 | |
| 1062 | server = kzalloc(sizeof(struct nfs_server), GFP_KERNEL); |
| 1063 | if (!server) |
| 1064 | return NULL; |
| 1065 | |
| 1066 | server->client = server->client_acl = ERR_PTR(-EINVAL); |
| 1067 | |
| 1068 | /* Zero out the NFS state stuff */ |
| 1069 | INIT_LIST_HEAD(&server->client_link); |
| 1070 | INIT_LIST_HEAD(&server->master_link); |
Chuck Lever | d3978bb | 2010-12-24 01:33:04 +0000 | [diff] [blame] | 1071 | INIT_LIST_HEAD(&server->delegations); |
Weston Andros Adamson | 6382a44 | 2011-06-01 16:44:44 -0400 | [diff] [blame] | 1072 | INIT_LIST_HEAD(&server->layouts); |
Chuck Lever | 0aaaf5c | 2011-12-06 16:13:48 -0500 | [diff] [blame] | 1073 | INIT_LIST_HEAD(&server->state_owners_lru); |
David Howells | 54ceac4 | 2006-08-22 20:06:13 -0400 | [diff] [blame] | 1074 | |
Steve Dickson | ef818a2 | 2007-11-08 04:05:04 -0500 | [diff] [blame] | 1075 | atomic_set(&server->active, 0); |
| 1076 | |
David Howells | 54ceac4 | 2006-08-22 20:06:13 -0400 | [diff] [blame] | 1077 | server->io_stats = nfs_alloc_iostats(); |
| 1078 | if (!server->io_stats) { |
| 1079 | kfree(server); |
| 1080 | return NULL; |
| 1081 | } |
| 1082 | |
Jens Axboe | 48d0764 | 2009-09-21 09:59:39 +0200 | [diff] [blame] | 1083 | if (bdi_init(&server->backing_dev_info)) { |
| 1084 | nfs_free_iostats(server->io_stats); |
| 1085 | kfree(server); |
| 1086 | return NULL; |
| 1087 | } |
| 1088 | |
Trond Myklebust | 9157c31 | 2012-01-17 22:04:24 -0500 | [diff] [blame] | 1089 | ida_init(&server->openowner_id); |
Trond Myklebust | d2d7ce2 | 2012-01-17 22:04:25 -0500 | [diff] [blame] | 1090 | ida_init(&server->lockowner_id); |
Fred Isaman | f7e8917 | 2011-01-06 11:36:32 +0000 | [diff] [blame] | 1091 | pnfs_init_server(server); |
| 1092 | |
David Howells | 54ceac4 | 2006-08-22 20:06:13 -0400 | [diff] [blame] | 1093 | return server; |
| 1094 | } |
| 1095 | |
| 1096 | /* |
| 1097 | * Free up a server record |
| 1098 | */ |
| 1099 | void nfs_free_server(struct nfs_server *server) |
| 1100 | { |
| 1101 | dprintk("--> nfs_free_server()\n"); |
| 1102 | |
Chuck Lever | fca5238 | 2010-12-24 01:32:32 +0000 | [diff] [blame] | 1103 | nfs_server_remove_lists(server); |
David Howells | 54ceac4 | 2006-08-22 20:06:13 -0400 | [diff] [blame] | 1104 | |
| 1105 | if (server->destroy != NULL) |
| 1106 | server->destroy(server); |
Trond Myklebust | 5cef338 | 2007-12-11 22:01:56 -0500 | [diff] [blame] | 1107 | |
| 1108 | if (!IS_ERR(server->client_acl)) |
| 1109 | rpc_shutdown_client(server->client_acl); |
David Howells | 54ceac4 | 2006-08-22 20:06:13 -0400 | [diff] [blame] | 1110 | if (!IS_ERR(server->client)) |
| 1111 | rpc_shutdown_client(server->client); |
| 1112 | |
| 1113 | nfs_put_client(server->nfs_client); |
| 1114 | |
Trond Myklebust | d2d7ce2 | 2012-01-17 22:04:25 -0500 | [diff] [blame] | 1115 | ida_destroy(&server->lockowner_id); |
Trond Myklebust | 9157c31 | 2012-01-17 22:04:24 -0500 | [diff] [blame] | 1116 | ida_destroy(&server->openowner_id); |
David Howells | 54ceac4 | 2006-08-22 20:06:13 -0400 | [diff] [blame] | 1117 | nfs_free_iostats(server->io_stats); |
Peter Zijlstra | e0bf68d | 2007-10-16 23:25:46 -0700 | [diff] [blame] | 1118 | bdi_destroy(&server->backing_dev_info); |
David Howells | 54ceac4 | 2006-08-22 20:06:13 -0400 | [diff] [blame] | 1119 | kfree(server); |
| 1120 | nfs_release_automount_timer(); |
| 1121 | dprintk("<-- nfs_free_server()\n"); |
| 1122 | } |
| 1123 | |
| 1124 | /* |
| 1125 | * Create a version 2 or 3 volume record |
| 1126 | * - keyed on server and FSID |
| 1127 | */ |
\"Talpey, Thomas\ | 2283f8d | 2007-09-10 13:43:56 -0400 | [diff] [blame] | 1128 | struct nfs_server *nfs_create_server(const struct nfs_parsed_mount_data *data, |
David Howells | 54ceac4 | 2006-08-22 20:06:13 -0400 | [diff] [blame] | 1129 | struct nfs_fh *mntfh) |
| 1130 | { |
| 1131 | struct nfs_server *server; |
Trond Myklebust | fbca779 | 2010-04-16 16:22:46 -0400 | [diff] [blame] | 1132 | struct nfs_fattr *fattr; |
David Howells | 54ceac4 | 2006-08-22 20:06:13 -0400 | [diff] [blame] | 1133 | int error; |
| 1134 | |
| 1135 | server = nfs_alloc_server(); |
| 1136 | if (!server) |
| 1137 | return ERR_PTR(-ENOMEM); |
| 1138 | |
Trond Myklebust | fbca779 | 2010-04-16 16:22:46 -0400 | [diff] [blame] | 1139 | error = -ENOMEM; |
| 1140 | fattr = nfs_alloc_fattr(); |
| 1141 | if (fattr == NULL) |
| 1142 | goto error; |
| 1143 | |
David Howells | 54ceac4 | 2006-08-22 20:06:13 -0400 | [diff] [blame] | 1144 | /* Get a client representation */ |
| 1145 | error = nfs_init_server(server, data); |
| 1146 | if (error < 0) |
| 1147 | goto error; |
| 1148 | |
| 1149 | BUG_ON(!server->nfs_client); |
| 1150 | BUG_ON(!server->nfs_client->rpc_ops); |
| 1151 | BUG_ON(!server->nfs_client->rpc_ops->file_inode_ops); |
| 1152 | |
| 1153 | /* Probe the root fh to retrieve its FSID */ |
Trond Myklebust | fbca779 | 2010-04-16 16:22:46 -0400 | [diff] [blame] | 1154 | error = nfs_probe_fsinfo(server, mntfh, fattr); |
David Howells | 54ceac4 | 2006-08-22 20:06:13 -0400 | [diff] [blame] | 1155 | if (error < 0) |
| 1156 | goto error; |
Trond Myklebust | 54af3bb | 2007-09-28 12:27:41 -0400 | [diff] [blame] | 1157 | if (server->nfs_client->rpc_ops->version == 3) { |
| 1158 | if (server->namelen == 0 || server->namelen > NFS3_MAXNAMLEN) |
| 1159 | server->namelen = NFS3_MAXNAMLEN; |
| 1160 | if (!(data->flags & NFS_MOUNT_NORDIRPLUS)) |
| 1161 | server->caps |= NFS_CAP_READDIRPLUS; |
| 1162 | } else { |
| 1163 | if (server->namelen == 0 || server->namelen > NFS2_MAXNAMLEN) |
| 1164 | server->namelen = NFS2_MAXNAMLEN; |
| 1165 | } |
| 1166 | |
Trond Myklebust | fbca779 | 2010-04-16 16:22:46 -0400 | [diff] [blame] | 1167 | if (!(fattr->valid & NFS_ATTR_FATTR)) { |
| 1168 | error = server->nfs_client->rpc_ops->getattr(server, mntfh, fattr); |
David Howells | 54ceac4 | 2006-08-22 20:06:13 -0400 | [diff] [blame] | 1169 | if (error < 0) { |
| 1170 | dprintk("nfs_create_server: getattr error = %d\n", -error); |
| 1171 | goto error; |
| 1172 | } |
| 1173 | } |
Trond Myklebust | fbca779 | 2010-04-16 16:22:46 -0400 | [diff] [blame] | 1174 | memcpy(&server->fsid, &fattr->fsid, sizeof(server->fsid)); |
David Howells | 54ceac4 | 2006-08-22 20:06:13 -0400 | [diff] [blame] | 1175 | |
David Howells | 6daabf1 | 2006-08-24 15:44:16 -0400 | [diff] [blame] | 1176 | dprintk("Server FSID: %llx:%llx\n", |
| 1177 | (unsigned long long) server->fsid.major, |
| 1178 | (unsigned long long) server->fsid.minor); |
David Howells | 54ceac4 | 2006-08-22 20:06:13 -0400 | [diff] [blame] | 1179 | |
Chuck Lever | fca5238 | 2010-12-24 01:32:32 +0000 | [diff] [blame] | 1180 | nfs_server_insert_lists(server); |
David Howells | 54ceac4 | 2006-08-22 20:06:13 -0400 | [diff] [blame] | 1181 | server->mount_time = jiffies; |
Trond Myklebust | fbca779 | 2010-04-16 16:22:46 -0400 | [diff] [blame] | 1182 | nfs_free_fattr(fattr); |
David Howells | 54ceac4 | 2006-08-22 20:06:13 -0400 | [diff] [blame] | 1183 | return server; |
| 1184 | |
| 1185 | error: |
Trond Myklebust | fbca779 | 2010-04-16 16:22:46 -0400 | [diff] [blame] | 1186 | nfs_free_fattr(fattr); |
David Howells | 54ceac4 | 2006-08-22 20:06:13 -0400 | [diff] [blame] | 1187 | nfs_free_server(server); |
| 1188 | return ERR_PTR(error); |
| 1189 | } |
| 1190 | |
David Howells | 54ceac4 | 2006-08-22 20:06:13 -0400 | [diff] [blame] | 1191 | /* |
| 1192 | * Clone an NFS2, NFS3 or NFS4 server record |
| 1193 | */ |
| 1194 | struct nfs_server *nfs_clone_server(struct nfs_server *source, |
| 1195 | struct nfs_fh *fh, |
Bryan Schumaker | 7e6eb68 | 2012-04-27 13:27:42 -0400 | [diff] [blame] | 1196 | struct nfs_fattr *fattr, |
| 1197 | rpc_authflavor_t flavor) |
David Howells | 54ceac4 | 2006-08-22 20:06:13 -0400 | [diff] [blame] | 1198 | { |
| 1199 | struct nfs_server *server; |
Trond Myklebust | fbca779 | 2010-04-16 16:22:46 -0400 | [diff] [blame] | 1200 | struct nfs_fattr *fattr_fsinfo; |
David Howells | 54ceac4 | 2006-08-22 20:06:13 -0400 | [diff] [blame] | 1201 | int error; |
| 1202 | |
| 1203 | dprintk("--> nfs_clone_server(,%llx:%llx,)\n", |
David Howells | 6daabf1 | 2006-08-24 15:44:16 -0400 | [diff] [blame] | 1204 | (unsigned long long) fattr->fsid.major, |
| 1205 | (unsigned long long) fattr->fsid.minor); |
David Howells | 54ceac4 | 2006-08-22 20:06:13 -0400 | [diff] [blame] | 1206 | |
| 1207 | server = nfs_alloc_server(); |
| 1208 | if (!server) |
| 1209 | return ERR_PTR(-ENOMEM); |
| 1210 | |
Trond Myklebust | fbca779 | 2010-04-16 16:22:46 -0400 | [diff] [blame] | 1211 | error = -ENOMEM; |
| 1212 | fattr_fsinfo = nfs_alloc_fattr(); |
| 1213 | if (fattr_fsinfo == NULL) |
| 1214 | goto out_free_server; |
| 1215 | |
David Howells | 54ceac4 | 2006-08-22 20:06:13 -0400 | [diff] [blame] | 1216 | /* Copy data from the source */ |
| 1217 | server->nfs_client = source->nfs_client; |
Chuck Lever | 0aaaf5c | 2011-12-06 16:13:48 -0500 | [diff] [blame] | 1218 | server->destroy = source->destroy; |
David Howells | 54ceac4 | 2006-08-22 20:06:13 -0400 | [diff] [blame] | 1219 | atomic_inc(&server->nfs_client->cl_count); |
| 1220 | nfs_server_copy_userdata(server, source); |
| 1221 | |
| 1222 | server->fsid = fattr->fsid; |
| 1223 | |
Trond Myklebust | 3317023 | 2007-12-20 16:03:59 -0500 | [diff] [blame] | 1224 | error = nfs_init_server_rpcclient(server, |
| 1225 | source->client->cl_timeout, |
Bryan Schumaker | 7e6eb68 | 2012-04-27 13:27:42 -0400 | [diff] [blame] | 1226 | flavor); |
David Howells | 54ceac4 | 2006-08-22 20:06:13 -0400 | [diff] [blame] | 1227 | if (error < 0) |
| 1228 | goto out_free_server; |
| 1229 | if (!IS_ERR(source->client_acl)) |
| 1230 | nfs_init_server_aclclient(server); |
| 1231 | |
| 1232 | /* probe the filesystem info for this server filesystem */ |
Trond Myklebust | fbca779 | 2010-04-16 16:22:46 -0400 | [diff] [blame] | 1233 | error = nfs_probe_fsinfo(server, fh, fattr_fsinfo); |
David Howells | 54ceac4 | 2006-08-22 20:06:13 -0400 | [diff] [blame] | 1234 | if (error < 0) |
| 1235 | goto out_free_server; |
| 1236 | |
Trond Myklebust | 54af3bb | 2007-09-28 12:27:41 -0400 | [diff] [blame] | 1237 | if (server->namelen == 0 || server->namelen > NFS4_MAXNAMLEN) |
| 1238 | server->namelen = NFS4_MAXNAMLEN; |
| 1239 | |
David Howells | 54ceac4 | 2006-08-22 20:06:13 -0400 | [diff] [blame] | 1240 | dprintk("Cloned FSID: %llx:%llx\n", |
David Howells | 6daabf1 | 2006-08-24 15:44:16 -0400 | [diff] [blame] | 1241 | (unsigned long long) server->fsid.major, |
| 1242 | (unsigned long long) server->fsid.minor); |
David Howells | 54ceac4 | 2006-08-22 20:06:13 -0400 | [diff] [blame] | 1243 | |
| 1244 | error = nfs_start_lockd(server); |
| 1245 | if (error < 0) |
| 1246 | goto out_free_server; |
| 1247 | |
Chuck Lever | fca5238 | 2010-12-24 01:32:32 +0000 | [diff] [blame] | 1248 | nfs_server_insert_lists(server); |
David Howells | 54ceac4 | 2006-08-22 20:06:13 -0400 | [diff] [blame] | 1249 | server->mount_time = jiffies; |
| 1250 | |
Trond Myklebust | fbca779 | 2010-04-16 16:22:46 -0400 | [diff] [blame] | 1251 | nfs_free_fattr(fattr_fsinfo); |
David Howells | 54ceac4 | 2006-08-22 20:06:13 -0400 | [diff] [blame] | 1252 | dprintk("<-- nfs_clone_server() = %p\n", server); |
| 1253 | return server; |
| 1254 | |
| 1255 | out_free_server: |
Trond Myklebust | fbca779 | 2010-04-16 16:22:46 -0400 | [diff] [blame] | 1256 | nfs_free_fattr(fattr_fsinfo); |
David Howells | 54ceac4 | 2006-08-22 20:06:13 -0400 | [diff] [blame] | 1257 | nfs_free_server(server); |
| 1258 | dprintk("<-- nfs_clone_server() = error %d\n", error); |
| 1259 | return ERR_PTR(error); |
| 1260 | } |
David Howells | 6aaca56 | 2006-08-22 20:06:13 -0400 | [diff] [blame] | 1261 | |
Stanislav Kinsbursky | 6b13168 | 2012-01-23 17:26:05 +0000 | [diff] [blame] | 1262 | void nfs_clients_init(struct net *net) |
| 1263 | { |
| 1264 | struct nfs_net *nn = net_generic(net, nfs_net_id); |
| 1265 | |
| 1266 | INIT_LIST_HEAD(&nn->nfs_client_list); |
Stanislav Kinsbursky | c25d32b | 2012-01-23 17:26:14 +0000 | [diff] [blame] | 1267 | INIT_LIST_HEAD(&nn->nfs_volume_list); |
Stanislav Kinsbursky | 28cd1b3 | 2012-01-23 17:26:22 +0000 | [diff] [blame] | 1268 | #ifdef CONFIG_NFS_V4 |
| 1269 | idr_init(&nn->cb_ident_idr); |
| 1270 | #endif |
Trond Myklebust | 4c03ae4 | 2012-02-07 00:05:11 -0500 | [diff] [blame] | 1271 | spin_lock_init(&nn->nfs_client_lock); |
Chuck Lever | f092075 | 2012-05-21 22:45:41 -0400 | [diff] [blame] | 1272 | nn->boot_time = CURRENT_TIME; |
Stanislav Kinsbursky | 6b13168 | 2012-01-23 17:26:05 +0000 | [diff] [blame] | 1273 | } |
| 1274 | |
David Howells | 6aaca56 | 2006-08-22 20:06:13 -0400 | [diff] [blame] | 1275 | #ifdef CONFIG_PROC_FS |
| 1276 | static struct proc_dir_entry *proc_fs_nfs; |
| 1277 | |
| 1278 | static int nfs_server_list_open(struct inode *inode, struct file *file); |
| 1279 | static void *nfs_server_list_start(struct seq_file *p, loff_t *pos); |
| 1280 | static void *nfs_server_list_next(struct seq_file *p, void *v, loff_t *pos); |
| 1281 | static void nfs_server_list_stop(struct seq_file *p, void *v); |
| 1282 | static int nfs_server_list_show(struct seq_file *m, void *v); |
| 1283 | |
James Morris | 88e9d34 | 2009-09-22 16:43:43 -0700 | [diff] [blame] | 1284 | static const struct seq_operations nfs_server_list_ops = { |
David Howells | 6aaca56 | 2006-08-22 20:06:13 -0400 | [diff] [blame] | 1285 | .start = nfs_server_list_start, |
| 1286 | .next = nfs_server_list_next, |
| 1287 | .stop = nfs_server_list_stop, |
| 1288 | .show = nfs_server_list_show, |
| 1289 | }; |
| 1290 | |
Arjan van de Ven | 00977a5 | 2007-02-12 00:55:34 -0800 | [diff] [blame] | 1291 | static const struct file_operations nfs_server_list_fops = { |
David Howells | 6aaca56 | 2006-08-22 20:06:13 -0400 | [diff] [blame] | 1292 | .open = nfs_server_list_open, |
| 1293 | .read = seq_read, |
| 1294 | .llseek = seq_lseek, |
| 1295 | .release = seq_release, |
Denis V. Lunev | 34b3723 | 2008-04-29 01:02:07 -0700 | [diff] [blame] | 1296 | .owner = THIS_MODULE, |
David Howells | 6aaca56 | 2006-08-22 20:06:13 -0400 | [diff] [blame] | 1297 | }; |
| 1298 | |
| 1299 | static int nfs_volume_list_open(struct inode *inode, struct file *file); |
| 1300 | static void *nfs_volume_list_start(struct seq_file *p, loff_t *pos); |
| 1301 | static void *nfs_volume_list_next(struct seq_file *p, void *v, loff_t *pos); |
| 1302 | static void nfs_volume_list_stop(struct seq_file *p, void *v); |
| 1303 | static int nfs_volume_list_show(struct seq_file *m, void *v); |
| 1304 | |
James Morris | 88e9d34 | 2009-09-22 16:43:43 -0700 | [diff] [blame] | 1305 | static const struct seq_operations nfs_volume_list_ops = { |
David Howells | 6aaca56 | 2006-08-22 20:06:13 -0400 | [diff] [blame] | 1306 | .start = nfs_volume_list_start, |
| 1307 | .next = nfs_volume_list_next, |
| 1308 | .stop = nfs_volume_list_stop, |
| 1309 | .show = nfs_volume_list_show, |
| 1310 | }; |
| 1311 | |
Arjan van de Ven | 00977a5 | 2007-02-12 00:55:34 -0800 | [diff] [blame] | 1312 | static const struct file_operations nfs_volume_list_fops = { |
David Howells | 6aaca56 | 2006-08-22 20:06:13 -0400 | [diff] [blame] | 1313 | .open = nfs_volume_list_open, |
| 1314 | .read = seq_read, |
| 1315 | .llseek = seq_lseek, |
| 1316 | .release = seq_release, |
Denis V. Lunev | 34b3723 | 2008-04-29 01:02:07 -0700 | [diff] [blame] | 1317 | .owner = THIS_MODULE, |
David Howells | 6aaca56 | 2006-08-22 20:06:13 -0400 | [diff] [blame] | 1318 | }; |
| 1319 | |
| 1320 | /* |
| 1321 | * open "/proc/fs/nfsfs/servers" which provides a summary of servers with which |
| 1322 | * we're dealing |
| 1323 | */ |
| 1324 | static int nfs_server_list_open(struct inode *inode, struct file *file) |
| 1325 | { |
| 1326 | struct seq_file *m; |
| 1327 | int ret; |
Stanislav Kinsbursky | 6b13168 | 2012-01-23 17:26:05 +0000 | [diff] [blame] | 1328 | struct pid_namespace *pid_ns = file->f_dentry->d_sb->s_fs_info; |
| 1329 | struct net *net = pid_ns->child_reaper->nsproxy->net_ns; |
David Howells | 6aaca56 | 2006-08-22 20:06:13 -0400 | [diff] [blame] | 1330 | |
| 1331 | ret = seq_open(file, &nfs_server_list_ops); |
| 1332 | if (ret < 0) |
| 1333 | return ret; |
| 1334 | |
| 1335 | m = file->private_data; |
Stanislav Kinsbursky | 6b13168 | 2012-01-23 17:26:05 +0000 | [diff] [blame] | 1336 | m->private = net; |
David Howells | 6aaca56 | 2006-08-22 20:06:13 -0400 | [diff] [blame] | 1337 | |
| 1338 | return 0; |
| 1339 | } |
| 1340 | |
| 1341 | /* |
| 1342 | * set up the iterator to start reading from the server list and return the first item |
| 1343 | */ |
| 1344 | static void *nfs_server_list_start(struct seq_file *m, loff_t *_pos) |
| 1345 | { |
Stanislav Kinsbursky | 6b13168 | 2012-01-23 17:26:05 +0000 | [diff] [blame] | 1346 | struct nfs_net *nn = net_generic(m->private, nfs_net_id); |
| 1347 | |
David Howells | 6aaca56 | 2006-08-22 20:06:13 -0400 | [diff] [blame] | 1348 | /* lock the list against modification */ |
Stanislav Kinsbursky | dc03085 | 2012-01-23 17:26:31 +0000 | [diff] [blame] | 1349 | spin_lock(&nn->nfs_client_lock); |
Stanislav Kinsbursky | 6b13168 | 2012-01-23 17:26:05 +0000 | [diff] [blame] | 1350 | return seq_list_start_head(&nn->nfs_client_list, *_pos); |
David Howells | 6aaca56 | 2006-08-22 20:06:13 -0400 | [diff] [blame] | 1351 | } |
| 1352 | |
| 1353 | /* |
| 1354 | * move to next server |
| 1355 | */ |
| 1356 | static void *nfs_server_list_next(struct seq_file *p, void *v, loff_t *pos) |
| 1357 | { |
Stanislav Kinsbursky | 6b13168 | 2012-01-23 17:26:05 +0000 | [diff] [blame] | 1358 | struct nfs_net *nn = net_generic(p->private, nfs_net_id); |
| 1359 | |
| 1360 | return seq_list_next(v, &nn->nfs_client_list, pos); |
David Howells | 6aaca56 | 2006-08-22 20:06:13 -0400 | [diff] [blame] | 1361 | } |
| 1362 | |
| 1363 | /* |
| 1364 | * clean up after reading from the transports list |
| 1365 | */ |
| 1366 | static void nfs_server_list_stop(struct seq_file *p, void *v) |
| 1367 | { |
Stanislav Kinsbursky | dc03085 | 2012-01-23 17:26:31 +0000 | [diff] [blame] | 1368 | struct nfs_net *nn = net_generic(p->private, nfs_net_id); |
| 1369 | |
| 1370 | spin_unlock(&nn->nfs_client_lock); |
David Howells | 6aaca56 | 2006-08-22 20:06:13 -0400 | [diff] [blame] | 1371 | } |
| 1372 | |
| 1373 | /* |
| 1374 | * display a header line followed by a load of call lines |
| 1375 | */ |
| 1376 | static int nfs_server_list_show(struct seq_file *m, void *v) |
| 1377 | { |
| 1378 | struct nfs_client *clp; |
Stanislav Kinsbursky | 6b13168 | 2012-01-23 17:26:05 +0000 | [diff] [blame] | 1379 | struct nfs_net *nn = net_generic(m->private, nfs_net_id); |
David Howells | 6aaca56 | 2006-08-22 20:06:13 -0400 | [diff] [blame] | 1380 | |
| 1381 | /* display header on line 1 */ |
Stanislav Kinsbursky | 6b13168 | 2012-01-23 17:26:05 +0000 | [diff] [blame] | 1382 | if (v == &nn->nfs_client_list) { |
David Howells | 6aaca56 | 2006-08-22 20:06:13 -0400 | [diff] [blame] | 1383 | seq_puts(m, "NV SERVER PORT USE HOSTNAME\n"); |
| 1384 | return 0; |
| 1385 | } |
| 1386 | |
| 1387 | /* display one transport per line on subsequent lines */ |
| 1388 | clp = list_entry(v, struct nfs_client, cl_share_link); |
| 1389 | |
Malahal Naineni | 940aab4 | 2011-09-20 17:27:14 -0700 | [diff] [blame] | 1390 | /* Check if the client is initialized */ |
| 1391 | if (clp->cl_cons_state != NFS_CS_READY) |
| 1392 | return 0; |
| 1393 | |
Trond Myklebust | 2446ab6 | 2012-03-01 17:00:56 -0500 | [diff] [blame] | 1394 | rcu_read_lock(); |
Chuck Lever | 5d8515c | 2007-12-10 14:57:16 -0500 | [diff] [blame] | 1395 | seq_printf(m, "v%u %s %s %3d %s\n", |
Trond Myklebust | 40c55319 | 2007-12-14 14:56:07 -0500 | [diff] [blame] | 1396 | clp->rpc_ops->version, |
Chuck Lever | 5d8515c | 2007-12-10 14:57:16 -0500 | [diff] [blame] | 1397 | rpc_peeraddr2str(clp->cl_rpcclient, RPC_DISPLAY_HEX_ADDR), |
| 1398 | rpc_peeraddr2str(clp->cl_rpcclient, RPC_DISPLAY_HEX_PORT), |
David Howells | 6aaca56 | 2006-08-22 20:06:13 -0400 | [diff] [blame] | 1399 | atomic_read(&clp->cl_count), |
| 1400 | clp->cl_hostname); |
Trond Myklebust | 2446ab6 | 2012-03-01 17:00:56 -0500 | [diff] [blame] | 1401 | rcu_read_unlock(); |
David Howells | 6aaca56 | 2006-08-22 20:06:13 -0400 | [diff] [blame] | 1402 | |
| 1403 | return 0; |
| 1404 | } |
| 1405 | |
| 1406 | /* |
| 1407 | * open "/proc/fs/nfsfs/volumes" which provides a summary of extant volumes |
| 1408 | */ |
| 1409 | static int nfs_volume_list_open(struct inode *inode, struct file *file) |
| 1410 | { |
| 1411 | struct seq_file *m; |
| 1412 | int ret; |
Stanislav Kinsbursky | c25d32b | 2012-01-23 17:26:14 +0000 | [diff] [blame] | 1413 | struct pid_namespace *pid_ns = file->f_dentry->d_sb->s_fs_info; |
| 1414 | struct net *net = pid_ns->child_reaper->nsproxy->net_ns; |
David Howells | 6aaca56 | 2006-08-22 20:06:13 -0400 | [diff] [blame] | 1415 | |
| 1416 | ret = seq_open(file, &nfs_volume_list_ops); |
| 1417 | if (ret < 0) |
| 1418 | return ret; |
| 1419 | |
| 1420 | m = file->private_data; |
Stanislav Kinsbursky | c25d32b | 2012-01-23 17:26:14 +0000 | [diff] [blame] | 1421 | m->private = net; |
David Howells | 6aaca56 | 2006-08-22 20:06:13 -0400 | [diff] [blame] | 1422 | |
| 1423 | return 0; |
| 1424 | } |
| 1425 | |
| 1426 | /* |
| 1427 | * set up the iterator to start reading from the volume list and return the first item |
| 1428 | */ |
| 1429 | static void *nfs_volume_list_start(struct seq_file *m, loff_t *_pos) |
| 1430 | { |
Stanislav Kinsbursky | c25d32b | 2012-01-23 17:26:14 +0000 | [diff] [blame] | 1431 | struct nfs_net *nn = net_generic(m->private, nfs_net_id); |
| 1432 | |
David Howells | 6aaca56 | 2006-08-22 20:06:13 -0400 | [diff] [blame] | 1433 | /* lock the list against modification */ |
Stanislav Kinsbursky | dc03085 | 2012-01-23 17:26:31 +0000 | [diff] [blame] | 1434 | spin_lock(&nn->nfs_client_lock); |
Stanislav Kinsbursky | c25d32b | 2012-01-23 17:26:14 +0000 | [diff] [blame] | 1435 | return seq_list_start_head(&nn->nfs_volume_list, *_pos); |
David Howells | 6aaca56 | 2006-08-22 20:06:13 -0400 | [diff] [blame] | 1436 | } |
| 1437 | |
| 1438 | /* |
| 1439 | * move to next volume |
| 1440 | */ |
| 1441 | static void *nfs_volume_list_next(struct seq_file *p, void *v, loff_t *pos) |
| 1442 | { |
Stanislav Kinsbursky | c25d32b | 2012-01-23 17:26:14 +0000 | [diff] [blame] | 1443 | struct nfs_net *nn = net_generic(p->private, nfs_net_id); |
| 1444 | |
| 1445 | return seq_list_next(v, &nn->nfs_volume_list, pos); |
David Howells | 6aaca56 | 2006-08-22 20:06:13 -0400 | [diff] [blame] | 1446 | } |
| 1447 | |
| 1448 | /* |
| 1449 | * clean up after reading from the transports list |
| 1450 | */ |
| 1451 | static void nfs_volume_list_stop(struct seq_file *p, void *v) |
| 1452 | { |
Stanislav Kinsbursky | dc03085 | 2012-01-23 17:26:31 +0000 | [diff] [blame] | 1453 | struct nfs_net *nn = net_generic(p->private, nfs_net_id); |
| 1454 | |
| 1455 | spin_unlock(&nn->nfs_client_lock); |
David Howells | 6aaca56 | 2006-08-22 20:06:13 -0400 | [diff] [blame] | 1456 | } |
| 1457 | |
| 1458 | /* |
| 1459 | * display a header line followed by a load of call lines |
| 1460 | */ |
| 1461 | static int nfs_volume_list_show(struct seq_file *m, void *v) |
| 1462 | { |
| 1463 | struct nfs_server *server; |
| 1464 | struct nfs_client *clp; |
| 1465 | char dev[8], fsid[17]; |
Stanislav Kinsbursky | c25d32b | 2012-01-23 17:26:14 +0000 | [diff] [blame] | 1466 | struct nfs_net *nn = net_generic(m->private, nfs_net_id); |
David Howells | 6aaca56 | 2006-08-22 20:06:13 -0400 | [diff] [blame] | 1467 | |
| 1468 | /* display header on line 1 */ |
Stanislav Kinsbursky | c25d32b | 2012-01-23 17:26:14 +0000 | [diff] [blame] | 1469 | if (v == &nn->nfs_volume_list) { |
David Howells | 5d1acff | 2009-04-03 16:42:47 +0100 | [diff] [blame] | 1470 | seq_puts(m, "NV SERVER PORT DEV FSID FSC\n"); |
David Howells | 6aaca56 | 2006-08-22 20:06:13 -0400 | [diff] [blame] | 1471 | return 0; |
| 1472 | } |
| 1473 | /* display one transport per line on subsequent lines */ |
| 1474 | server = list_entry(v, struct nfs_server, master_link); |
| 1475 | clp = server->nfs_client; |
| 1476 | |
| 1477 | snprintf(dev, 8, "%u:%u", |
| 1478 | MAJOR(server->s_dev), MINOR(server->s_dev)); |
| 1479 | |
| 1480 | snprintf(fsid, 17, "%llx:%llx", |
David Howells | 6daabf1 | 2006-08-24 15:44:16 -0400 | [diff] [blame] | 1481 | (unsigned long long) server->fsid.major, |
| 1482 | (unsigned long long) server->fsid.minor); |
David Howells | 6aaca56 | 2006-08-22 20:06:13 -0400 | [diff] [blame] | 1483 | |
Trond Myklebust | 2446ab6 | 2012-03-01 17:00:56 -0500 | [diff] [blame] | 1484 | rcu_read_lock(); |
David Howells | 5d1acff | 2009-04-03 16:42:47 +0100 | [diff] [blame] | 1485 | seq_printf(m, "v%u %s %s %-7s %-17s %s\n", |
Trond Myklebust | 40c55319 | 2007-12-14 14:56:07 -0500 | [diff] [blame] | 1486 | clp->rpc_ops->version, |
Chuck Lever | 5d8515c | 2007-12-10 14:57:16 -0500 | [diff] [blame] | 1487 | rpc_peeraddr2str(clp->cl_rpcclient, RPC_DISPLAY_HEX_ADDR), |
| 1488 | rpc_peeraddr2str(clp->cl_rpcclient, RPC_DISPLAY_HEX_PORT), |
David Howells | 6aaca56 | 2006-08-22 20:06:13 -0400 | [diff] [blame] | 1489 | dev, |
David Howells | 5d1acff | 2009-04-03 16:42:47 +0100 | [diff] [blame] | 1490 | fsid, |
| 1491 | nfs_server_fscache_state(server)); |
Trond Myklebust | 2446ab6 | 2012-03-01 17:00:56 -0500 | [diff] [blame] | 1492 | rcu_read_unlock(); |
David Howells | 6aaca56 | 2006-08-22 20:06:13 -0400 | [diff] [blame] | 1493 | |
| 1494 | return 0; |
| 1495 | } |
| 1496 | |
| 1497 | /* |
| 1498 | * initialise the /proc/fs/nfsfs/ directory |
| 1499 | */ |
| 1500 | int __init nfs_fs_proc_init(void) |
| 1501 | { |
| 1502 | struct proc_dir_entry *p; |
| 1503 | |
Alexey Dobriyan | 36a5aeb | 2008-04-29 01:01:42 -0700 | [diff] [blame] | 1504 | proc_fs_nfs = proc_mkdir("fs/nfsfs", NULL); |
David Howells | 6aaca56 | 2006-08-22 20:06:13 -0400 | [diff] [blame] | 1505 | if (!proc_fs_nfs) |
| 1506 | goto error_0; |
| 1507 | |
David Howells | 6aaca56 | 2006-08-22 20:06:13 -0400 | [diff] [blame] | 1508 | /* a file of servers with which we're dealing */ |
Denis V. Lunev | 34b3723 | 2008-04-29 01:02:07 -0700 | [diff] [blame] | 1509 | p = proc_create("servers", S_IFREG|S_IRUGO, |
| 1510 | proc_fs_nfs, &nfs_server_list_fops); |
David Howells | 6aaca56 | 2006-08-22 20:06:13 -0400 | [diff] [blame] | 1511 | if (!p) |
| 1512 | goto error_1; |
| 1513 | |
David Howells | 6aaca56 | 2006-08-22 20:06:13 -0400 | [diff] [blame] | 1514 | /* a file of volumes that we have mounted */ |
Denis V. Lunev | 34b3723 | 2008-04-29 01:02:07 -0700 | [diff] [blame] | 1515 | p = proc_create("volumes", S_IFREG|S_IRUGO, |
| 1516 | proc_fs_nfs, &nfs_volume_list_fops); |
David Howells | 6aaca56 | 2006-08-22 20:06:13 -0400 | [diff] [blame] | 1517 | if (!p) |
| 1518 | goto error_2; |
David Howells | 6aaca56 | 2006-08-22 20:06:13 -0400 | [diff] [blame] | 1519 | return 0; |
| 1520 | |
| 1521 | error_2: |
| 1522 | remove_proc_entry("servers", proc_fs_nfs); |
| 1523 | error_1: |
Alexey Dobriyan | 36a5aeb | 2008-04-29 01:01:42 -0700 | [diff] [blame] | 1524 | remove_proc_entry("fs/nfsfs", NULL); |
David Howells | 6aaca56 | 2006-08-22 20:06:13 -0400 | [diff] [blame] | 1525 | error_0: |
| 1526 | return -ENOMEM; |
| 1527 | } |
| 1528 | |
| 1529 | /* |
| 1530 | * clean up the /proc/fs/nfsfs/ directory |
| 1531 | */ |
| 1532 | void nfs_fs_proc_exit(void) |
| 1533 | { |
| 1534 | remove_proc_entry("volumes", proc_fs_nfs); |
| 1535 | remove_proc_entry("servers", proc_fs_nfs); |
Alexey Dobriyan | 36a5aeb | 2008-04-29 01:01:42 -0700 | [diff] [blame] | 1536 | remove_proc_entry("fs/nfsfs", NULL); |
David Howells | 6aaca56 | 2006-08-22 20:06:13 -0400 | [diff] [blame] | 1537 | } |
| 1538 | |
| 1539 | #endif /* CONFIG_PROC_FS */ |