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\ | 0896a72 | 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; |
Stanislav Kinsbursky | 28cd1b3 | 2012-01-23 17:26:22 +0000 | [diff] [blame] | 68 | struct nfs_net *nn = net_generic(clp->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 | /* |
Trond Myklebust | b064eca2 | 2011-02-22 15:44:32 -0800 | [diff] [blame] | 85 | * Turn off NFSv4 uid/gid mapping when using AUTH_SYS |
| 86 | */ |
Rusty Russell | 90ab5ee | 2012-01-13 09:32:20 +1030 | [diff] [blame] | 87 | static bool nfs4_disable_idmapping = true; |
Trond Myklebust | b064eca2 | 2011-02-22 15:44:32 -0800 | [diff] [blame] | 88 | |
| 89 | /* |
David Howells | 5006a76 | 2006-08-22 20:06:12 -0400 | [diff] [blame] | 90 | * RPC cruft for NFS |
| 91 | */ |
Trond Myklebust | a613fa1 | 2012-01-20 13:53:56 -0500 | [diff] [blame] | 92 | static const struct rpc_version *nfs_version[5] = { |
David Howells | 5006a76 | 2006-08-22 20:06:12 -0400 | [diff] [blame] | 93 | [2] = &nfs_version2, |
| 94 | #ifdef CONFIG_NFS_V3 |
| 95 | [3] = &nfs_version3, |
| 96 | #endif |
| 97 | #ifdef CONFIG_NFS_V4 |
| 98 | [4] = &nfs_version4, |
| 99 | #endif |
| 100 | }; |
| 101 | |
Trond Myklebust | a613fa1 | 2012-01-20 13:53:56 -0500 | [diff] [blame] | 102 | const struct rpc_program nfs_program = { |
David Howells | 5006a76 | 2006-08-22 20:06:12 -0400 | [diff] [blame] | 103 | .name = "nfs", |
| 104 | .number = NFS_PROGRAM, |
| 105 | .nrvers = ARRAY_SIZE(nfs_version), |
| 106 | .version = nfs_version, |
| 107 | .stats = &nfs_rpcstat, |
Jim Rees | fe0a9b7 | 2011-07-30 20:52:42 -0400 | [diff] [blame] | 108 | .pipe_dir_name = NFS_PIPE_DIRNAME, |
David Howells | 5006a76 | 2006-08-22 20:06:12 -0400 | [diff] [blame] | 109 | }; |
| 110 | |
| 111 | struct rpc_stat nfs_rpcstat = { |
| 112 | .program = &nfs_program |
| 113 | }; |
| 114 | |
| 115 | |
| 116 | #ifdef CONFIG_NFS_V3_ACL |
| 117 | static struct rpc_stat nfsacl_rpcstat = { &nfsacl_program }; |
Trond Myklebust | a613fa1 | 2012-01-20 13:53:56 -0500 | [diff] [blame] | 118 | static const struct rpc_version *nfsacl_version[] = { |
David Howells | 5006a76 | 2006-08-22 20:06:12 -0400 | [diff] [blame] | 119 | [3] = &nfsacl_version3, |
| 120 | }; |
| 121 | |
Trond Myklebust | a613fa1 | 2012-01-20 13:53:56 -0500 | [diff] [blame] | 122 | const struct rpc_program nfsacl_program = { |
David Howells | 5006a76 | 2006-08-22 20:06:12 -0400 | [diff] [blame] | 123 | .name = "nfsacl", |
| 124 | .number = NFS_ACL_PROGRAM, |
| 125 | .nrvers = ARRAY_SIZE(nfsacl_version), |
| 126 | .version = nfsacl_version, |
| 127 | .stats = &nfsacl_rpcstat, |
| 128 | }; |
| 129 | #endif /* CONFIG_NFS_V3_ACL */ |
| 130 | |
Trond Myklebust | 3a49802 | 2007-12-14 14:56:04 -0500 | [diff] [blame] | 131 | struct nfs_client_initdata { |
| 132 | const char *hostname; |
Chuck Lever | d7422c4 | 2007-12-10 14:58:51 -0500 | [diff] [blame] | 133 | const struct sockaddr *addr; |
Chuck Lever | 6e4cffd | 2007-12-10 14:58:15 -0500 | [diff] [blame] | 134 | size_t addrlen; |
Trond Myklebust | 40c55319 | 2007-12-14 14:56:07 -0500 | [diff] [blame] | 135 | const struct nfs_rpc_ops *rpc_ops; |
Trond Myklebust | 59dca3b | 2008-01-03 16:29:06 -0500 | [diff] [blame] | 136 | int proto; |
Benny Halevy | 5aae4a9 | 2009-04-01 09:21:50 -0400 | [diff] [blame] | 137 | u32 minorversion; |
Stanislav Kinsbursky | e50a7a1 | 2012-01-10 16:12:46 +0400 | [diff] [blame] | 138 | struct net *net; |
Trond Myklebust | 3a49802 | 2007-12-14 14:56:04 -0500 | [diff] [blame] | 139 | }; |
| 140 | |
David Howells | 5006a76 | 2006-08-22 20:06:12 -0400 | [diff] [blame] | 141 | /* |
David Howells | 24c8dbb | 2006-08-22 20:06:10 -0400 | [diff] [blame] | 142 | * Allocate a shared client record |
| 143 | * |
| 144 | * Since these are allocated/deallocated very rarely, we don't |
| 145 | * bother putting them in a slab cache... |
| 146 | */ |
Trond Myklebust | 3a49802 | 2007-12-14 14:56:04 -0500 | [diff] [blame] | 147 | static 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] | 148 | { |
| 149 | struct nfs_client *clp; |
Trond Myklebust | 7c67db3 | 2008-04-07 20:50:11 -0400 | [diff] [blame] | 150 | struct rpc_cred *cred; |
Chuck Lever | a21bdd9 | 2009-06-17 18:02:10 -0700 | [diff] [blame] | 151 | int err = -ENOMEM; |
David Howells | 24c8dbb | 2006-08-22 20:06:10 -0400 | [diff] [blame] | 152 | |
| 153 | if ((clp = kzalloc(sizeof(*clp), GFP_KERNEL)) == NULL) |
| 154 | goto error_0; |
| 155 | |
Trond Myklebust | 40c55319 | 2007-12-14 14:56:07 -0500 | [diff] [blame] | 156 | clp->rpc_ops = cl_init->rpc_ops; |
| 157 | |
David Howells | 24c8dbb | 2006-08-22 20:06:10 -0400 | [diff] [blame] | 158 | atomic_set(&clp->cl_count, 1); |
| 159 | clp->cl_cons_state = NFS_CS_INITING; |
| 160 | |
Chuck Lever | 6e4cffd | 2007-12-10 14:58:15 -0500 | [diff] [blame] | 161 | memcpy(&clp->cl_addr, cl_init->addr, cl_init->addrlen); |
| 162 | clp->cl_addrlen = cl_init->addrlen; |
David Howells | 24c8dbb | 2006-08-22 20:06:10 -0400 | [diff] [blame] | 163 | |
Trond Myklebust | 3a49802 | 2007-12-14 14:56:04 -0500 | [diff] [blame] | 164 | if (cl_init->hostname) { |
Chuck Lever | a21bdd9 | 2009-06-17 18:02:10 -0700 | [diff] [blame] | 165 | err = -ENOMEM; |
Trond Myklebust | 3a49802 | 2007-12-14 14:56:04 -0500 | [diff] [blame] | 166 | clp->cl_hostname = kstrdup(cl_init->hostname, GFP_KERNEL); |
David Howells | 24c8dbb | 2006-08-22 20:06:10 -0400 | [diff] [blame] | 167 | if (!clp->cl_hostname) |
Benny Halevy | 7146851 | 2009-04-01 09:22:56 -0400 | [diff] [blame] | 168 | goto error_cleanup; |
David Howells | 24c8dbb | 2006-08-22 20:06:10 -0400 | [diff] [blame] | 169 | } |
| 170 | |
| 171 | INIT_LIST_HEAD(&clp->cl_superblocks); |
| 172 | clp->cl_rpcclient = ERR_PTR(-EINVAL); |
| 173 | |
Trond Myklebust | 59dca3b | 2008-01-03 16:29:06 -0500 | [diff] [blame] | 174 | clp->cl_proto = cl_init->proto; |
Trond Myklebust | abd9669 | 2012-02-19 08:46:49 +0100 | [diff] [blame] | 175 | clp->net = get_net(cl_init->net); |
Trond Myklebust | 59dca3b | 2008-01-03 16:29:06 -0500 | [diff] [blame] | 176 | |
David Howells | 24c8dbb | 2006-08-22 20:06:10 -0400 | [diff] [blame] | 177 | #ifdef CONFIG_NFS_V4 |
Andy Adamson | f4eecd5 | 2011-01-06 02:04:30 +0000 | [diff] [blame] | 178 | err = nfs_get_cb_ident_idr(clp, cl_init->minorversion); |
| 179 | if (err) |
| 180 | goto error_cleanup; |
| 181 | |
David Howells | 24c8dbb | 2006-08-22 20:06:10 -0400 | [diff] [blame] | 182 | spin_lock_init(&clp->cl_lock); |
David Howells | 65f27f3 | 2006-11-22 14:55:48 +0000 | [diff] [blame] | 183 | INIT_DELAYED_WORK(&clp->cl_renewd, nfs4_renew_state); |
David Howells | 24c8dbb | 2006-08-22 20:06:10 -0400 | [diff] [blame] | 184 | rpc_init_wait_queue(&clp->cl_rpcwaitq, "NFS client"); |
| 185 | clp->cl_boot_time = CURRENT_TIME; |
| 186 | clp->cl_state = 1 << NFS4CLNT_LEASE_EXPIRED; |
Benny Halevy | 5aae4a9 | 2009-04-01 09:21:50 -0400 | [diff] [blame] | 187 | clp->cl_minorversion = cl_init->minorversion; |
Trond Myklebust | 97dc135 | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 188 | clp->cl_mvops = nfs_v4_minor_ops[cl_init->minorversion]; |
David Howells | 24c8dbb | 2006-08-22 20:06:10 -0400 | [diff] [blame] | 189 | #endif |
Trond Myklebust | 68c9715 | 2012-01-03 13:22:46 -0500 | [diff] [blame] | 190 | cred = rpc_lookup_machine_cred("*"); |
Trond Myklebust | 7c67db3 | 2008-04-07 20:50:11 -0400 | [diff] [blame] | 191 | if (!IS_ERR(cred)) |
| 192 | clp->cl_machine_cred = cred; |
David Howells | 1472728 | 2009-04-03 16:42:42 +0100 | [diff] [blame] | 193 | nfs_fscache_get_client_cookie(clp); |
| 194 | |
David Howells | 24c8dbb | 2006-08-22 20:06:10 -0400 | [diff] [blame] | 195 | return clp; |
| 196 | |
Benny Halevy | 7146851 | 2009-04-01 09:22:56 -0400 | [diff] [blame] | 197 | error_cleanup: |
David Howells | 24c8dbb | 2006-08-22 20:06:10 -0400 | [diff] [blame] | 198 | kfree(clp); |
| 199 | error_0: |
Chuck Lever | a21bdd9 | 2009-06-17 18:02:10 -0700 | [diff] [blame] | 200 | return ERR_PTR(err); |
David Howells | 24c8dbb | 2006-08-22 20:06:10 -0400 | [diff] [blame] | 201 | } |
| 202 | |
Trond Myklebust | 5dd3177 | 2006-08-24 01:03:05 -0400 | [diff] [blame] | 203 | #ifdef CONFIG_NFS_V4 |
Andy Adamson | 557134a | 2009-04-01 09:21:53 -0400 | [diff] [blame] | 204 | #ifdef CONFIG_NFS_V4_1 |
Andy Adamson | ea00528 | 2011-01-06 02:04:29 +0000 | [diff] [blame] | 205 | static void nfs4_shutdown_session(struct nfs_client *clp) |
| 206 | { |
Trond Myklebust | 7df529a | 2012-02-26 17:34:22 -0500 | [diff] [blame] | 207 | if (nfs4_has_session(clp)) { |
| 208 | nfs4_deviceid_purge_client(clp); |
Andy Adamson | 557134a | 2009-04-01 09:21:53 -0400 | [diff] [blame] | 209 | nfs4_destroy_session(clp->cl_session); |
Trond Myklebust | 7df529a | 2012-02-26 17:34:22 -0500 | [diff] [blame] | 210 | } |
| 211 | |
Andy Adamson | 557134a | 2009-04-01 09:21:53 -0400 | [diff] [blame] | 212 | } |
Andy Adamson | ea00528 | 2011-01-06 02:04:29 +0000 | [diff] [blame] | 213 | #else /* CONFIG_NFS_V4_1 */ |
| 214 | static void nfs4_shutdown_session(struct nfs_client *clp) |
| 215 | { |
| 216 | } |
| 217 | #endif /* CONFIG_NFS_V4_1 */ |
Andy Adamson | 557134a | 2009-04-01 09:21:53 -0400 | [diff] [blame] | 218 | |
| 219 | /* |
Alexandros Batsakis | 888ef2e | 2010-02-05 03:45:03 -0800 | [diff] [blame] | 220 | * Destroy the NFS4 callback service |
| 221 | */ |
| 222 | static void nfs4_destroy_callback(struct nfs_client *clp) |
| 223 | { |
| 224 | if (__test_and_clear_bit(NFS_CS_CALLBACK, &clp->cl_res_state)) |
Trond Myklebust | 97dc135 | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 225 | nfs_callback_down(clp->cl_mvops->minor_version); |
Alexandros Batsakis | 888ef2e | 2010-02-05 03:45:03 -0800 | [diff] [blame] | 226 | } |
| 227 | |
| 228 | static void nfs4_shutdown_client(struct nfs_client *clp) |
| 229 | { |
| 230 | if (__test_and_clear_bit(NFS_CS_RENEWD, &clp->cl_res_state)) |
| 231 | nfs4_kill_renewd(clp); |
Andy Adamson | ea00528 | 2011-01-06 02:04:29 +0000 | [diff] [blame] | 232 | nfs4_shutdown_session(clp); |
Alexandros Batsakis | 888ef2e | 2010-02-05 03:45:03 -0800 | [diff] [blame] | 233 | nfs4_destroy_callback(clp); |
| 234 | if (__test_and_clear_bit(NFS_CS_IDMAP, &clp->cl_res_state)) |
| 235 | nfs_idmap_delete(clp); |
| 236 | |
| 237 | rpc_destroy_wait_queue(&clp->cl_rpcwaitq); |
| 238 | } |
Andy Adamson | f4eecd5 | 2011-01-06 02:04:30 +0000 | [diff] [blame] | 239 | |
| 240 | /* 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] | 241 | void nfs_cleanup_cb_ident_idr(struct net *net) |
Andy Adamson | f4eecd5 | 2011-01-06 02:04:30 +0000 | [diff] [blame] | 242 | { |
Stanislav Kinsbursky | 28cd1b3 | 2012-01-23 17:26:22 +0000 | [diff] [blame] | 243 | struct nfs_net *nn = net_generic(net, nfs_net_id); |
| 244 | |
| 245 | idr_destroy(&nn->cb_ident_idr); |
Andy Adamson | f4eecd5 | 2011-01-06 02:04:30 +0000 | [diff] [blame] | 246 | } |
| 247 | |
| 248 | /* nfs_client_lock held */ |
| 249 | static void nfs_cb_idr_remove_locked(struct nfs_client *clp) |
| 250 | { |
Stanislav Kinsbursky | 28cd1b3 | 2012-01-23 17:26:22 +0000 | [diff] [blame] | 251 | struct nfs_net *nn = net_generic(clp->net, nfs_net_id); |
| 252 | |
Andy Adamson | f4eecd5 | 2011-01-06 02:04:30 +0000 | [diff] [blame] | 253 | if (clp->cl_cb_ident) |
Stanislav Kinsbursky | 28cd1b3 | 2012-01-23 17:26:22 +0000 | [diff] [blame] | 254 | idr_remove(&nn->cb_ident_idr, clp->cl_cb_ident); |
Andy Adamson | f4eecd5 | 2011-01-06 02:04:30 +0000 | [diff] [blame] | 255 | } |
| 256 | |
Fred Isaman | f7e8917 | 2011-01-06 11:36:32 +0000 | [diff] [blame] | 257 | static void pnfs_init_server(struct nfs_server *server) |
| 258 | { |
| 259 | rpc_init_wait_queue(&server->roc_rpcwaitq, "pNFS ROC"); |
| 260 | } |
| 261 | |
Chuck Lever | 0aaaf5c | 2011-12-06 16:13:48 -0500 | [diff] [blame] | 262 | static void nfs4_destroy_server(struct nfs_server *server) |
| 263 | { |
| 264 | nfs4_purge_state_owners(server); |
| 265 | } |
| 266 | |
Alexandros Batsakis | 888ef2e | 2010-02-05 03:45:03 -0800 | [diff] [blame] | 267 | #else |
| 268 | static void nfs4_shutdown_client(struct nfs_client *clp) |
| 269 | { |
| 270 | } |
Andy Adamson | f4eecd5 | 2011-01-06 02:04:30 +0000 | [diff] [blame] | 271 | |
Stanislav Kinsbursky | 28cd1b3 | 2012-01-23 17:26:22 +0000 | [diff] [blame] | 272 | void nfs_cleanup_cb_ident_idr(struct net *net) |
Andy Adamson | f4eecd5 | 2011-01-06 02:04:30 +0000 | [diff] [blame] | 273 | { |
| 274 | } |
| 275 | |
| 276 | static void nfs_cb_idr_remove_locked(struct nfs_client *clp) |
| 277 | { |
| 278 | } |
Fred Isaman | f7e8917 | 2011-01-06 11:36:32 +0000 | [diff] [blame] | 279 | |
| 280 | static void pnfs_init_server(struct nfs_server *server) |
| 281 | { |
| 282 | } |
| 283 | |
Alexandros Batsakis | 888ef2e | 2010-02-05 03:45:03 -0800 | [diff] [blame] | 284 | #endif /* CONFIG_NFS_V4 */ |
| 285 | |
| 286 | /* |
David Howells | 24c8dbb | 2006-08-22 20:06:10 -0400 | [diff] [blame] | 287 | * Destroy a shared client record |
| 288 | */ |
| 289 | static void nfs_free_client(struct nfs_client *clp) |
| 290 | { |
Trond Myklebust | 40c55319 | 2007-12-14 14:56:07 -0500 | [diff] [blame] | 291 | dprintk("--> nfs_free_client(%u)\n", clp->rpc_ops->version); |
David Howells | 24c8dbb | 2006-08-22 20:06:10 -0400 | [diff] [blame] | 292 | |
Trond Myklebust | 5dd3177 | 2006-08-24 01:03:05 -0400 | [diff] [blame] | 293 | nfs4_shutdown_client(clp); |
David Howells | 24c8dbb | 2006-08-22 20:06:10 -0400 | [diff] [blame] | 294 | |
David Howells | 1472728 | 2009-04-03 16:42:42 +0100 | [diff] [blame] | 295 | nfs_fscache_release_client_cookie(clp); |
| 296 | |
David Howells | 24c8dbb | 2006-08-22 20:06:10 -0400 | [diff] [blame] | 297 | /* -EIO all pending I/O */ |
| 298 | if (!IS_ERR(clp->cl_rpcclient)) |
| 299 | rpc_shutdown_client(clp->cl_rpcclient); |
| 300 | |
Trond Myklebust | 7c67db3 | 2008-04-07 20:50:11 -0400 | [diff] [blame] | 301 | if (clp->cl_machine_cred != NULL) |
| 302 | put_rpccred(clp->cl_machine_cred); |
| 303 | |
Trond Myklebust | abd9669 | 2012-02-19 08:46:49 +0100 | [diff] [blame] | 304 | put_net(clp->net); |
David Howells | 24c8dbb | 2006-08-22 20:06:10 -0400 | [diff] [blame] | 305 | kfree(clp->cl_hostname); |
Weston Andros Adamson | 78fe0f4 | 2011-05-31 19:05:47 -0400 | [diff] [blame] | 306 | kfree(clp->server_scope); |
Weston Andros Adamson | 7d2ed9a | 2012-02-17 15:20:26 -0500 | [diff] [blame] | 307 | kfree(clp->impl_id); |
David Howells | 24c8dbb | 2006-08-22 20:06:10 -0400 | [diff] [blame] | 308 | kfree(clp); |
| 309 | |
| 310 | dprintk("<-- nfs_free_client()\n"); |
| 311 | } |
| 312 | |
| 313 | /* |
| 314 | * Release a reference to a shared client record |
| 315 | */ |
| 316 | void nfs_put_client(struct nfs_client *clp) |
| 317 | { |
Stanislav Kinsbursky | dc03085 | 2012-01-23 17:26:31 +0000 | [diff] [blame] | 318 | struct nfs_net *nn; |
| 319 | |
David Howells | 27ba851 | 2006-07-30 14:40:56 -0400 | [diff] [blame] | 320 | if (!clp) |
| 321 | return; |
| 322 | |
David Howells | 24c8dbb | 2006-08-22 20:06:10 -0400 | [diff] [blame] | 323 | dprintk("--> nfs_put_client({%d})\n", atomic_read(&clp->cl_count)); |
Stanislav Kinsbursky | dc03085 | 2012-01-23 17:26:31 +0000 | [diff] [blame] | 324 | nn = net_generic(clp->net, nfs_net_id); |
David Howells | 24c8dbb | 2006-08-22 20:06:10 -0400 | [diff] [blame] | 325 | |
Stanislav Kinsbursky | dc03085 | 2012-01-23 17:26:31 +0000 | [diff] [blame] | 326 | if (atomic_dec_and_lock(&clp->cl_count, &nn->nfs_client_lock)) { |
David Howells | 24c8dbb | 2006-08-22 20:06:10 -0400 | [diff] [blame] | 327 | list_del(&clp->cl_share_link); |
Andy Adamson | f4eecd5 | 2011-01-06 02:04:30 +0000 | [diff] [blame] | 328 | nfs_cb_idr_remove_locked(clp); |
Stanislav Kinsbursky | dc03085 | 2012-01-23 17:26:31 +0000 | [diff] [blame] | 329 | spin_unlock(&nn->nfs_client_lock); |
David Howells | 24c8dbb | 2006-08-22 20:06:10 -0400 | [diff] [blame] | 330 | |
| 331 | BUG_ON(!list_empty(&clp->cl_superblocks)); |
| 332 | |
| 333 | nfs_free_client(clp); |
| 334 | } |
| 335 | } |
Andy Adamson | 16b374c | 2010-10-20 00:18:04 -0400 | [diff] [blame] | 336 | EXPORT_SYMBOL_GPL(nfs_put_client); |
David Howells | 24c8dbb | 2006-08-22 20:06:10 -0400 | [diff] [blame] | 337 | |
Trond Myklebust | 9082a5c | 2008-12-23 15:21:53 -0500 | [diff] [blame] | 338 | #if defined(CONFIG_IPV6) || defined(CONFIG_IPV6_MODULE) |
Trond Myklebust | 9f4c899 | 2009-03-12 14:51:32 -0400 | [diff] [blame] | 339 | /* |
| 340 | * Test if two ip6 socket addresses refer to the same socket by |
| 341 | * comparing relevant fields. The padding bytes specifically, are not |
| 342 | * compared. sin6_flowinfo is not compared because it only affects QoS |
| 343 | * and sin6_scope_id is only compared if the address is "link local" |
| 344 | * because "link local" addresses need only be unique to a specific |
| 345 | * link. Conversely, ordinary unicast addresses might have different |
| 346 | * sin6_scope_id. |
| 347 | * |
| 348 | * The caller should ensure both socket addresses are AF_INET6. |
| 349 | */ |
Chuck Lever | 3c8c45d | 2009-03-18 20:48:14 -0400 | [diff] [blame] | 350 | static int nfs_sockaddr_match_ipaddr6(const struct sockaddr *sa1, |
| 351 | const struct sockaddr *sa2) |
Trond Myklebust | 9f4c899 | 2009-03-12 14:51:32 -0400 | [diff] [blame] | 352 | { |
Chuck Lever | 3c8c45d | 2009-03-18 20:48:14 -0400 | [diff] [blame] | 353 | const struct sockaddr_in6 *sin1 = (const struct sockaddr_in6 *)sa1; |
| 354 | const struct sockaddr_in6 *sin2 = (const struct sockaddr_in6 *)sa2; |
Trond Myklebust | 9f4c899 | 2009-03-12 14:51:32 -0400 | [diff] [blame] | 355 | |
Mi Jinlong | b9dd3ab | 2011-10-12 15:09:34 +0800 | [diff] [blame] | 356 | if (!ipv6_addr_equal(&sin1->sin6_addr, &sin2->sin6_addr)) |
Trond Myklebust | 9f4c899 | 2009-03-12 14:51:32 -0400 | [diff] [blame] | 357 | return 0; |
Mi Jinlong | b9dd3ab | 2011-10-12 15:09:34 +0800 | [diff] [blame] | 358 | else if (ipv6_addr_type(&sin1->sin6_addr) & IPV6_ADDR_LINKLOCAL) |
| 359 | return sin1->sin6_scope_id == sin2->sin6_scope_id; |
Trond Myklebust | 3b0d3f9 | 2008-01-03 13:28:58 -0500 | [diff] [blame] | 360 | |
Mi Jinlong | b9dd3ab | 2011-10-12 15:09:34 +0800 | [diff] [blame] | 361 | return 1; |
Trond Myklebust | 3b0d3f9 | 2008-01-03 13:28:58 -0500 | [diff] [blame] | 362 | } |
Chuck Lever | 3c8c45d | 2009-03-18 20:48:14 -0400 | [diff] [blame] | 363 | #else /* !defined(CONFIG_IPV6) && !defined(CONFIG_IPV6_MODULE) */ |
| 364 | static int nfs_sockaddr_match_ipaddr6(const struct sockaddr *sa1, |
| 365 | const struct sockaddr *sa2) |
Trond Myklebust | 9f4c899 | 2009-03-12 14:51:32 -0400 | [diff] [blame] | 366 | { |
| 367 | return 0; |
| 368 | } |
Trond Myklebust | 9082a5c | 2008-12-23 15:21:53 -0500 | [diff] [blame] | 369 | #endif |
Trond Myklebust | 3b0d3f9 | 2008-01-03 13:28:58 -0500 | [diff] [blame] | 370 | |
David Howells | 24c8dbb | 2006-08-22 20:06:10 -0400 | [diff] [blame] | 371 | /* |
Ian Dall | d7371c4 | 2009-03-10 20:33:22 -0400 | [diff] [blame] | 372 | * Test if two ip4 socket addresses refer to the same socket, by |
| 373 | * comparing relevant fields. The padding bytes specifically, are |
| 374 | * not compared. |
| 375 | * |
| 376 | * The caller should ensure both socket addresses are AF_INET. |
| 377 | */ |
Chuck Lever | 3c8c45d | 2009-03-18 20:48:14 -0400 | [diff] [blame] | 378 | static int nfs_sockaddr_match_ipaddr4(const struct sockaddr *sa1, |
| 379 | const struct sockaddr *sa2) |
| 380 | { |
| 381 | const struct sockaddr_in *sin1 = (const struct sockaddr_in *)sa1; |
| 382 | const struct sockaddr_in *sin2 = (const struct sockaddr_in *)sa2; |
| 383 | |
| 384 | return sin1->sin_addr.s_addr == sin2->sin_addr.s_addr; |
| 385 | } |
| 386 | |
| 387 | static int nfs_sockaddr_cmp_ip6(const struct sockaddr *sa1, |
| 388 | const struct sockaddr *sa2) |
| 389 | { |
| 390 | const struct sockaddr_in6 *sin1 = (const struct sockaddr_in6 *)sa1; |
| 391 | const struct sockaddr_in6 *sin2 = (const struct sockaddr_in6 *)sa2; |
| 392 | |
| 393 | return nfs_sockaddr_match_ipaddr6(sa1, sa2) && |
| 394 | (sin1->sin6_port == sin2->sin6_port); |
| 395 | } |
| 396 | |
Trond Myklebust | 9f4c899 | 2009-03-12 14:51:32 -0400 | [diff] [blame] | 397 | static int nfs_sockaddr_cmp_ip4(const struct sockaddr *sa1, |
| 398 | const struct sockaddr *sa2) |
Ian Dall | d7371c4 | 2009-03-10 20:33:22 -0400 | [diff] [blame] | 399 | { |
Chuck Lever | 3c8c45d | 2009-03-18 20:48:14 -0400 | [diff] [blame] | 400 | const struct sockaddr_in *sin1 = (const struct sockaddr_in *)sa1; |
| 401 | const struct sockaddr_in *sin2 = (const struct sockaddr_in *)sa2; |
Trond Myklebust | 9f4c899 | 2009-03-12 14:51:32 -0400 | [diff] [blame] | 402 | |
Chuck Lever | 3c8c45d | 2009-03-18 20:48:14 -0400 | [diff] [blame] | 403 | return nfs_sockaddr_match_ipaddr4(sa1, sa2) && |
| 404 | (sin1->sin_port == sin2->sin_port); |
Ian Dall | d7371c4 | 2009-03-10 20:33:22 -0400 | [diff] [blame] | 405 | } |
| 406 | |
Bryan Schumaker | 4b7c8dd | 2012-03-12 11:28:24 -0400 | [diff] [blame] | 407 | #if defined(CONFIG_NFS_V4_1) |
Ian Dall | d7371c4 | 2009-03-10 20:33:22 -0400 | [diff] [blame] | 408 | /* |
Ian Dall | d7371c4 | 2009-03-10 20:33:22 -0400 | [diff] [blame] | 409 | * Test if two socket addresses represent the same actual socket, |
Chuck Lever | 3c8c45d | 2009-03-18 20:48:14 -0400 | [diff] [blame] | 410 | * by comparing (only) relevant fields, excluding the port number. |
| 411 | */ |
| 412 | static int nfs_sockaddr_match_ipaddr(const struct sockaddr *sa1, |
| 413 | const struct sockaddr *sa2) |
| 414 | { |
| 415 | if (sa1->sa_family != sa2->sa_family) |
| 416 | return 0; |
| 417 | |
| 418 | switch (sa1->sa_family) { |
| 419 | case AF_INET: |
| 420 | return nfs_sockaddr_match_ipaddr4(sa1, sa2); |
| 421 | case AF_INET6: |
| 422 | return nfs_sockaddr_match_ipaddr6(sa1, sa2); |
| 423 | } |
| 424 | return 0; |
| 425 | } |
Bryan Schumaker | 4b7c8dd | 2012-03-12 11:28:24 -0400 | [diff] [blame] | 426 | #endif /* CONFIG_NFS_V4_1 */ |
Chuck Lever | 3c8c45d | 2009-03-18 20:48:14 -0400 | [diff] [blame] | 427 | |
| 428 | /* |
| 429 | * Test if two socket addresses represent the same actual socket, |
| 430 | * by comparing (only) relevant fields, including the port number. |
Ian Dall | d7371c4 | 2009-03-10 20:33:22 -0400 | [diff] [blame] | 431 | */ |
| 432 | static int nfs_sockaddr_cmp(const struct sockaddr *sa1, |
| 433 | const struct sockaddr *sa2) |
| 434 | { |
| 435 | if (sa1->sa_family != sa2->sa_family) |
| 436 | return 0; |
| 437 | |
| 438 | switch (sa1->sa_family) { |
| 439 | case AF_INET: |
Trond Myklebust | 9f4c899 | 2009-03-12 14:51:32 -0400 | [diff] [blame] | 440 | return nfs_sockaddr_cmp_ip4(sa1, sa2); |
Ian Dall | d7371c4 | 2009-03-10 20:33:22 -0400 | [diff] [blame] | 441 | case AF_INET6: |
Trond Myklebust | 9f4c899 | 2009-03-12 14:51:32 -0400 | [diff] [blame] | 442 | return nfs_sockaddr_cmp_ip6(sa1, sa2); |
Ian Dall | d7371c4 | 2009-03-10 20:33:22 -0400 | [diff] [blame] | 443 | } |
| 444 | return 0; |
| 445 | } |
| 446 | |
Bryan Schumaker | 4b7c8dd | 2012-03-12 11:28:24 -0400 | [diff] [blame] | 447 | #if defined(CONFIG_NFS_V4_1) |
Andy Adamson | c36fca5 | 2011-01-06 02:04:32 +0000 | [diff] [blame] | 448 | /* Common match routine for v4.0 and v4.1 callback services */ |
Trond Myklebust | 1728017 | 2012-03-11 13:11:00 -0400 | [diff] [blame] | 449 | static bool nfs4_cb_match_client(const struct sockaddr *addr, |
| 450 | struct nfs_client *clp, u32 minorversion) |
Trond Myklebust | c81468a | 2007-12-14 14:56:05 -0500 | [diff] [blame] | 451 | { |
Andy Adamson | c36fca5 | 2011-01-06 02:04:32 +0000 | [diff] [blame] | 452 | struct sockaddr *clap = (struct sockaddr *)&clp->cl_addr; |
Trond Myklebust | c81468a | 2007-12-14 14:56:05 -0500 | [diff] [blame] | 453 | |
Andy Adamson | c36fca5 | 2011-01-06 02:04:32 +0000 | [diff] [blame] | 454 | /* Don't match clients that failed to initialise */ |
| 455 | if (!(clp->cl_cons_state == NFS_CS_READY || |
| 456 | clp->cl_cons_state == NFS_CS_SESSION_INITING)) |
| 457 | return false; |
Trond Myklebust | 3b0d3f9 | 2008-01-03 13:28:58 -0500 | [diff] [blame] | 458 | |
Andy Adamson | c36fca5 | 2011-01-06 02:04:32 +0000 | [diff] [blame] | 459 | /* Match the version and minorversion */ |
| 460 | if (clp->rpc_ops->version != 4 || |
| 461 | clp->cl_minorversion != minorversion) |
| 462 | return false; |
Trond Myklebust | c81468a | 2007-12-14 14:56:05 -0500 | [diff] [blame] | 463 | |
Andy Adamson | c36fca5 | 2011-01-06 02:04:32 +0000 | [diff] [blame] | 464 | /* Match only the IP address, not the port number */ |
| 465 | if (!nfs_sockaddr_match_ipaddr(addr, clap)) |
| 466 | return false; |
Trond Myklebust | c81468a | 2007-12-14 14:56:05 -0500 | [diff] [blame] | 467 | |
Andy Adamson | c36fca5 | 2011-01-06 02:04:32 +0000 | [diff] [blame] | 468 | return true; |
Trond Myklebust | 3fbd67a | 2008-01-26 01:06:40 -0500 | [diff] [blame] | 469 | } |
Bryan Schumaker | 4b7c8dd | 2012-03-12 11:28:24 -0400 | [diff] [blame] | 470 | #endif /* CONFIG_NFS_V4_1 */ |
Trond Myklebust | 3fbd67a | 2008-01-26 01:06:40 -0500 | [diff] [blame] | 471 | |
| 472 | /* |
Trond Myklebust | c81468a | 2007-12-14 14:56:05 -0500 | [diff] [blame] | 473 | * Find an nfs_client on the list that matches the initialisation data |
| 474 | * that is supplied. |
| 475 | */ |
| 476 | 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] | 477 | { |
| 478 | struct nfs_client *clp; |
Ian Dall | d7371c4 | 2009-03-10 20:33:22 -0400 | [diff] [blame] | 479 | const struct sockaddr *sap = data->addr; |
Stanislav Kinsbursky | 6b13168 | 2012-01-23 17:26:05 +0000 | [diff] [blame] | 480 | struct nfs_net *nn = net_generic(data->net, nfs_net_id); |
David Howells | 24c8dbb | 2006-08-22 20:06:10 -0400 | [diff] [blame] | 481 | |
Stanislav Kinsbursky | 6b13168 | 2012-01-23 17:26:05 +0000 | [diff] [blame] | 482 | list_for_each_entry(clp, &nn->nfs_client_list, cl_share_link) { |
Ian Dall | d7371c4 | 2009-03-10 20:33:22 -0400 | [diff] [blame] | 483 | const struct sockaddr *clap = (struct sockaddr *)&clp->cl_addr; |
Trond Myklebust | 13bbc06 | 2006-10-19 23:28:40 -0700 | [diff] [blame] | 484 | /* Don't match clients that failed to initialise properly */ |
| 485 | if (clp->cl_cons_state < 0) |
| 486 | continue; |
| 487 | |
David Howells | 24c8dbb | 2006-08-22 20:06:10 -0400 | [diff] [blame] | 488 | /* Different NFS versions cannot share the same nfs_client */ |
Trond Myklebust | 40c55319 | 2007-12-14 14:56:07 -0500 | [diff] [blame] | 489 | if (clp->rpc_ops != data->rpc_ops) |
David Howells | 24c8dbb | 2006-08-22 20:06:10 -0400 | [diff] [blame] | 490 | continue; |
| 491 | |
Trond Myklebust | 59dca3b | 2008-01-03 16:29:06 -0500 | [diff] [blame] | 492 | if (clp->cl_proto != data->proto) |
| 493 | continue; |
Benny Halevy | 5aae4a9 | 2009-04-01 09:21:50 -0400 | [diff] [blame] | 494 | /* Match nfsv4 minorversion */ |
| 495 | if (clp->cl_minorversion != data->minorversion) |
| 496 | continue; |
Trond Myklebust | c81468a | 2007-12-14 14:56:05 -0500 | [diff] [blame] | 497 | /* Match the full socket address */ |
Ian Dall | d7371c4 | 2009-03-10 20:33:22 -0400 | [diff] [blame] | 498 | if (!nfs_sockaddr_cmp(sap, clap)) |
David Howells | 24c8dbb | 2006-08-22 20:06:10 -0400 | [diff] [blame] | 499 | continue; |
| 500 | |
Trond Myklebust | c81468a | 2007-12-14 14:56:05 -0500 | [diff] [blame] | 501 | atomic_inc(&clp->cl_count); |
| 502 | return clp; |
David Howells | 24c8dbb | 2006-08-22 20:06:10 -0400 | [diff] [blame] | 503 | } |
David Howells | 24c8dbb | 2006-08-22 20:06:10 -0400 | [diff] [blame] | 504 | return NULL; |
David Howells | 24c8dbb | 2006-08-22 20:06:10 -0400 | [diff] [blame] | 505 | } |
| 506 | |
| 507 | /* |
| 508 | * Look up a client by IP address and protocol version |
| 509 | * - creates a new record if one doesn't yet exist |
| 510 | */ |
Andy Adamson | 45a52a0 | 2011-03-01 01:34:08 +0000 | [diff] [blame] | 511 | static struct nfs_client * |
| 512 | nfs_get_client(const struct nfs_client_initdata *cl_init, |
| 513 | const struct rpc_timeout *timeparms, |
| 514 | const char *ip_addr, |
| 515 | rpc_authflavor_t authflavour, |
| 516 | int noresvport) |
David Howells | 24c8dbb | 2006-08-22 20:06:10 -0400 | [diff] [blame] | 517 | { |
| 518 | struct nfs_client *clp, *new = NULL; |
| 519 | int error; |
Stanislav Kinsbursky | 6b13168 | 2012-01-23 17:26:05 +0000 | [diff] [blame] | 520 | struct nfs_net *nn = net_generic(cl_init->net, nfs_net_id); |
David Howells | 24c8dbb | 2006-08-22 20:06:10 -0400 | [diff] [blame] | 521 | |
Chuck Lever | d7422c4 | 2007-12-10 14:58:51 -0500 | [diff] [blame] | 522 | dprintk("--> nfs_get_client(%s,v%u)\n", |
| 523 | cl_init->hostname ?: "", cl_init->rpc_ops->version); |
David Howells | 24c8dbb | 2006-08-22 20:06:10 -0400 | [diff] [blame] | 524 | |
| 525 | /* see if the client already exists */ |
| 526 | do { |
Stanislav Kinsbursky | dc03085 | 2012-01-23 17:26:31 +0000 | [diff] [blame] | 527 | spin_lock(&nn->nfs_client_lock); |
David Howells | 24c8dbb | 2006-08-22 20:06:10 -0400 | [diff] [blame] | 528 | |
Trond Myklebust | c81468a | 2007-12-14 14:56:05 -0500 | [diff] [blame] | 529 | clp = nfs_match_client(cl_init); |
David Howells | 24c8dbb | 2006-08-22 20:06:10 -0400 | [diff] [blame] | 530 | if (clp) |
| 531 | goto found_client; |
| 532 | if (new) |
| 533 | goto install_client; |
| 534 | |
Stanislav Kinsbursky | dc03085 | 2012-01-23 17:26:31 +0000 | [diff] [blame] | 535 | spin_unlock(&nn->nfs_client_lock); |
David Howells | 24c8dbb | 2006-08-22 20:06:10 -0400 | [diff] [blame] | 536 | |
Trond Myklebust | 3a49802 | 2007-12-14 14:56:04 -0500 | [diff] [blame] | 537 | new = nfs_alloc_client(cl_init); |
Chuck Lever | a21bdd9 | 2009-06-17 18:02:10 -0700 | [diff] [blame] | 538 | } while (!IS_ERR(new)); |
David Howells | 24c8dbb | 2006-08-22 20:06:10 -0400 | [diff] [blame] | 539 | |
Chuck Lever | a21bdd9 | 2009-06-17 18:02:10 -0700 | [diff] [blame] | 540 | dprintk("--> nfs_get_client() = %ld [failed]\n", PTR_ERR(new)); |
| 541 | return new; |
David Howells | 24c8dbb | 2006-08-22 20:06:10 -0400 | [diff] [blame] | 542 | |
| 543 | /* install a new client and return with it unready */ |
| 544 | install_client: |
| 545 | clp = new; |
Stanislav Kinsbursky | 6b13168 | 2012-01-23 17:26:05 +0000 | [diff] [blame] | 546 | list_add(&clp->cl_share_link, &nn->nfs_client_list); |
Stanislav Kinsbursky | dc03085 | 2012-01-23 17:26:31 +0000 | [diff] [blame] | 547 | spin_unlock(&nn->nfs_client_lock); |
Andy Adamson | 45a52a0 | 2011-03-01 01:34:08 +0000 | [diff] [blame] | 548 | |
| 549 | error = cl_init->rpc_ops->init_client(clp, timeparms, ip_addr, |
| 550 | authflavour, noresvport); |
| 551 | if (error < 0) { |
| 552 | nfs_put_client(clp); |
| 553 | return ERR_PTR(error); |
| 554 | } |
David Howells | 24c8dbb | 2006-08-22 20:06:10 -0400 | [diff] [blame] | 555 | dprintk("--> nfs_get_client() = %p [new]\n", clp); |
| 556 | return clp; |
| 557 | |
| 558 | /* found an existing client |
| 559 | * - make sure it's ready before returning |
| 560 | */ |
| 561 | found_client: |
Stanislav Kinsbursky | dc03085 | 2012-01-23 17:26:31 +0000 | [diff] [blame] | 562 | spin_unlock(&nn->nfs_client_lock); |
David Howells | 24c8dbb | 2006-08-22 20:06:10 -0400 | [diff] [blame] | 563 | |
| 564 | if (new) |
| 565 | nfs_free_client(new); |
| 566 | |
Matthew Wilcox | 150030b | 2007-12-06 16:24:39 -0500 | [diff] [blame] | 567 | error = wait_event_killable(nfs_client_active_wq, |
Andy Adamson | 76db6d9 | 2009-04-01 09:22:38 -0400 | [diff] [blame] | 568 | clp->cl_cons_state < NFS_CS_INITING); |
Trond Myklebust | 0bae89e | 2006-10-08 14:33:24 -0400 | [diff] [blame] | 569 | if (error < 0) { |
| 570 | nfs_put_client(clp); |
| 571 | return ERR_PTR(-ERESTARTSYS); |
David Howells | 24c8dbb | 2006-08-22 20:06:10 -0400 | [diff] [blame] | 572 | } |
| 573 | |
| 574 | if (clp->cl_cons_state < NFS_CS_READY) { |
| 575 | error = clp->cl_cons_state; |
| 576 | nfs_put_client(clp); |
| 577 | return ERR_PTR(error); |
| 578 | } |
| 579 | |
David Howells | 54ceac4 | 2006-08-22 20:06:13 -0400 | [diff] [blame] | 580 | BUG_ON(clp->cl_cons_state != NFS_CS_READY); |
| 581 | |
David Howells | 24c8dbb | 2006-08-22 20:06:10 -0400 | [diff] [blame] | 582 | dprintk("--> nfs_get_client() = %p [share]\n", clp); |
| 583 | return clp; |
| 584 | } |
| 585 | |
| 586 | /* |
| 587 | * Mark a server as ready or failed |
| 588 | */ |
Andy Adamson | 76db6d9 | 2009-04-01 09:22:38 -0400 | [diff] [blame] | 589 | void nfs_mark_client_ready(struct nfs_client *clp, int state) |
David Howells | 24c8dbb | 2006-08-22 20:06:10 -0400 | [diff] [blame] | 590 | { |
| 591 | clp->cl_cons_state = state; |
| 592 | wake_up_all(&nfs_client_active_wq); |
| 593 | } |
David Howells | 5006a76 | 2006-08-22 20:06:12 -0400 | [diff] [blame] | 594 | |
| 595 | /* |
Benny Halevy | 008f55d | 2009-04-01 09:22:50 -0400 | [diff] [blame] | 596 | * With sessions, the client is not marked ready until after a |
| 597 | * successful EXCHANGE_ID and CREATE_SESSION. |
| 598 | * |
| 599 | * Map errors cl_cons_state errors to EPROTONOSUPPORT to indicate |
| 600 | * other versions of NFS can be tried. |
| 601 | */ |
| 602 | int nfs4_check_client_ready(struct nfs_client *clp) |
| 603 | { |
| 604 | if (!nfs4_has_session(clp)) |
| 605 | return 0; |
| 606 | if (clp->cl_cons_state < NFS_CS_READY) |
| 607 | return -EPROTONOSUPPORT; |
| 608 | return 0; |
| 609 | } |
| 610 | |
| 611 | /* |
David Howells | 5006a76 | 2006-08-22 20:06:12 -0400 | [diff] [blame] | 612 | * Initialise the timeout values for a connection |
| 613 | */ |
| 614 | static void nfs_init_timeout_values(struct rpc_timeout *to, int proto, |
| 615 | unsigned int timeo, unsigned int retrans) |
| 616 | { |
| 617 | to->to_initval = timeo * HZ / 10; |
| 618 | to->to_retries = retrans; |
David Howells | 5006a76 | 2006-08-22 20:06:12 -0400 | [diff] [blame] | 619 | |
| 620 | switch (proto) { |
\"Talpey, Thomas\ | 0896a72 | 2007-09-10 13:48:23 -0400 | [diff] [blame] | 621 | case XPRT_TRANSPORT_TCP: |
\"Talpey, Thomas\ | 2cf7ff7 | 2007-09-10 13:49:41 -0400 | [diff] [blame] | 622 | case XPRT_TRANSPORT_RDMA: |
Trond Myklebust | 259875e | 2008-07-02 14:43:47 -0400 | [diff] [blame] | 623 | if (to->to_retries == 0) |
| 624 | to->to_retries = NFS_DEF_TCP_RETRANS; |
Trond Myklebust | 7a3e3e1 | 2007-12-20 16:03:57 -0500 | [diff] [blame] | 625 | if (to->to_initval == 0) |
Trond Myklebust | 259875e | 2008-07-02 14:43:47 -0400 | [diff] [blame] | 626 | to->to_initval = NFS_DEF_TCP_TIMEO * HZ / 10; |
David Howells | 5006a76 | 2006-08-22 20:06:12 -0400 | [diff] [blame] | 627 | if (to->to_initval > NFS_MAX_TCP_TIMEOUT) |
| 628 | to->to_initval = NFS_MAX_TCP_TIMEOUT; |
| 629 | to->to_increment = to->to_initval; |
| 630 | to->to_maxval = to->to_initval + (to->to_increment * to->to_retries); |
Trond Myklebust | 7a3e3e1 | 2007-12-20 16:03:57 -0500 | [diff] [blame] | 631 | if (to->to_maxval > NFS_MAX_TCP_TIMEOUT) |
| 632 | to->to_maxval = NFS_MAX_TCP_TIMEOUT; |
| 633 | if (to->to_maxval < to->to_initval) |
| 634 | to->to_maxval = to->to_initval; |
David Howells | 5006a76 | 2006-08-22 20:06:12 -0400 | [diff] [blame] | 635 | to->to_exponential = 0; |
| 636 | break; |
\"Talpey, Thomas\ | 0896a72 | 2007-09-10 13:48:23 -0400 | [diff] [blame] | 637 | case XPRT_TRANSPORT_UDP: |
Trond Myklebust | 259875e | 2008-07-02 14:43:47 -0400 | [diff] [blame] | 638 | if (to->to_retries == 0) |
| 639 | to->to_retries = NFS_DEF_UDP_RETRANS; |
David Howells | 5006a76 | 2006-08-22 20:06:12 -0400 | [diff] [blame] | 640 | if (!to->to_initval) |
Trond Myklebust | 259875e | 2008-07-02 14:43:47 -0400 | [diff] [blame] | 641 | to->to_initval = NFS_DEF_UDP_TIMEO * HZ / 10; |
David Howells | 5006a76 | 2006-08-22 20:06:12 -0400 | [diff] [blame] | 642 | if (to->to_initval > NFS_MAX_UDP_TIMEOUT) |
| 643 | to->to_initval = NFS_MAX_UDP_TIMEOUT; |
| 644 | to->to_maxval = NFS_MAX_UDP_TIMEOUT; |
| 645 | to->to_exponential = 1; |
| 646 | break; |
Trond Myklebust | 259875e | 2008-07-02 14:43:47 -0400 | [diff] [blame] | 647 | default: |
| 648 | BUG(); |
David Howells | 5006a76 | 2006-08-22 20:06:12 -0400 | [diff] [blame] | 649 | } |
| 650 | } |
| 651 | |
| 652 | /* |
| 653 | * Create an RPC client handle |
| 654 | */ |
Trond Myklebust | 59dca3b | 2008-01-03 16:29:06 -0500 | [diff] [blame] | 655 | static int nfs_create_rpc_client(struct nfs_client *clp, |
Trond Myklebust | 3317023 | 2007-12-20 16:03:59 -0500 | [diff] [blame] | 656 | const struct rpc_timeout *timeparms, |
| 657 | rpc_authflavor_t flavor, |
Chuck Lever | 4a01b8a | 2008-12-23 15:21:35 -0500 | [diff] [blame] | 658 | int discrtry, int noresvport) |
David Howells | 5006a76 | 2006-08-22 20:06:12 -0400 | [diff] [blame] | 659 | { |
David Howells | 5006a76 | 2006-08-22 20:06:12 -0400 | [diff] [blame] | 660 | struct rpc_clnt *clnt = NULL; |
Chuck Lever | 41877d2 | 2006-08-22 20:06:20 -0400 | [diff] [blame] | 661 | struct rpc_create_args args = { |
Stanislav Kinsbursky | 6d59b8d | 2012-01-10 16:12:54 +0400 | [diff] [blame] | 662 | .net = clp->net, |
Trond Myklebust | 59dca3b | 2008-01-03 16:29:06 -0500 | [diff] [blame] | 663 | .protocol = clp->cl_proto, |
Chuck Lever | 41877d2 | 2006-08-22 20:06:20 -0400 | [diff] [blame] | 664 | .address = (struct sockaddr *)&clp->cl_addr, |
Chuck Lever | 6e4cffd | 2007-12-10 14:58:15 -0500 | [diff] [blame] | 665 | .addrsize = clp->cl_addrlen, |
Trond Myklebust | 3317023 | 2007-12-20 16:03:59 -0500 | [diff] [blame] | 666 | .timeout = timeparms, |
Chuck Lever | 41877d2 | 2006-08-22 20:06:20 -0400 | [diff] [blame] | 667 | .servername = clp->cl_hostname, |
| 668 | .program = &nfs_program, |
| 669 | .version = clp->rpc_ops->version, |
| 670 | .authflavor = flavor, |
| 671 | }; |
David Howells | 5006a76 | 2006-08-22 20:06:12 -0400 | [diff] [blame] | 672 | |
Chuck Lever | 4a01b8a | 2008-12-23 15:21:35 -0500 | [diff] [blame] | 673 | if (discrtry) |
| 674 | args.flags |= RPC_CLNT_CREATE_DISCRTRY; |
| 675 | if (noresvport) |
| 676 | args.flags |= RPC_CLNT_CREATE_NONPRIVPORT; |
| 677 | |
David Howells | 5006a76 | 2006-08-22 20:06:12 -0400 | [diff] [blame] | 678 | if (!IS_ERR(clp->cl_rpcclient)) |
| 679 | return 0; |
| 680 | |
Chuck Lever | 41877d2 | 2006-08-22 20:06:20 -0400 | [diff] [blame] | 681 | clnt = rpc_create(&args); |
David Howells | 5006a76 | 2006-08-22 20:06:12 -0400 | [diff] [blame] | 682 | if (IS_ERR(clnt)) { |
| 683 | dprintk("%s: cannot create RPC client. Error = %ld\n", |
Harvey Harrison | 3110ff8 | 2008-05-02 13:42:44 -0700 | [diff] [blame] | 684 | __func__, PTR_ERR(clnt)); |
David Howells | 5006a76 | 2006-08-22 20:06:12 -0400 | [diff] [blame] | 685 | return PTR_ERR(clnt); |
| 686 | } |
| 687 | |
David Howells | 5006a76 | 2006-08-22 20:06:12 -0400 | [diff] [blame] | 688 | clp->cl_rpcclient = clnt; |
| 689 | return 0; |
| 690 | } |
David Howells | 54ceac4 | 2006-08-22 20:06:13 -0400 | [diff] [blame] | 691 | |
| 692 | /* |
| 693 | * Version 2 or 3 client destruction |
| 694 | */ |
| 695 | static void nfs_destroy_server(struct nfs_server *server) |
| 696 | { |
Suresh Jayaraman | 5eebde2 | 2010-09-23 08:55:58 -0400 | [diff] [blame] | 697 | if (!(server->flags & NFS_MOUNT_LOCAL_FLOCK) || |
| 698 | !(server->flags & NFS_MOUNT_LOCAL_FCNTL)) |
Chuck Lever | 9289e7f | 2008-01-11 17:09:52 -0500 | [diff] [blame] | 699 | nlmclnt_done(server->nlm_host); |
David Howells | 54ceac4 | 2006-08-22 20:06:13 -0400 | [diff] [blame] | 700 | } |
| 701 | |
| 702 | /* |
| 703 | * Version 2 or 3 lockd setup |
| 704 | */ |
| 705 | static int nfs_start_lockd(struct nfs_server *server) |
| 706 | { |
Chuck Lever | 9289e7f | 2008-01-11 17:09:52 -0500 | [diff] [blame] | 707 | struct nlm_host *host; |
| 708 | struct nfs_client *clp = server->nfs_client; |
Chuck Lever | 883bb16 | 2008-01-15 16:04:20 -0500 | [diff] [blame] | 709 | struct nlmclnt_initdata nlm_init = { |
| 710 | .hostname = clp->cl_hostname, |
| 711 | .address = (struct sockaddr *)&clp->cl_addr, |
| 712 | .addrlen = clp->cl_addrlen, |
Chuck Lever | 883bb16 | 2008-01-15 16:04:20 -0500 | [diff] [blame] | 713 | .nfs_version = clp->rpc_ops->version, |
Chuck Lever | 0cb2659 | 2008-12-23 15:21:38 -0500 | [diff] [blame] | 714 | .noresvport = server->flags & NFS_MOUNT_NORESVPORT ? |
| 715 | 1 : 0, |
Stanislav Kinsbursky | 66697bf | 2012-01-31 15:08:13 +0400 | [diff] [blame] | 716 | .net = clp->net, |
Chuck Lever | 883bb16 | 2008-01-15 16:04:20 -0500 | [diff] [blame] | 717 | }; |
David Howells | 54ceac4 | 2006-08-22 20:06:13 -0400 | [diff] [blame] | 718 | |
Chuck Lever | 883bb16 | 2008-01-15 16:04:20 -0500 | [diff] [blame] | 719 | if (nlm_init.nfs_version > 3) |
Chuck Lever | 9289e7f | 2008-01-11 17:09:52 -0500 | [diff] [blame] | 720 | return 0; |
Suresh Jayaraman | 5eebde2 | 2010-09-23 08:55:58 -0400 | [diff] [blame] | 721 | if ((server->flags & NFS_MOUNT_LOCAL_FLOCK) && |
| 722 | (server->flags & NFS_MOUNT_LOCAL_FCNTL)) |
Chuck Lever | 9289e7f | 2008-01-11 17:09:52 -0500 | [diff] [blame] | 723 | return 0; |
| 724 | |
Trond Myklebust | 8a6e5de | 2009-09-23 14:36:37 -0400 | [diff] [blame] | 725 | switch (clp->cl_proto) { |
| 726 | default: |
| 727 | nlm_init.protocol = IPPROTO_TCP; |
| 728 | break; |
| 729 | case XPRT_TRANSPORT_UDP: |
| 730 | nlm_init.protocol = IPPROTO_UDP; |
| 731 | } |
| 732 | |
Chuck Lever | 883bb16 | 2008-01-15 16:04:20 -0500 | [diff] [blame] | 733 | host = nlmclnt_init(&nlm_init); |
Chuck Lever | 9289e7f | 2008-01-11 17:09:52 -0500 | [diff] [blame] | 734 | if (IS_ERR(host)) |
| 735 | return PTR_ERR(host); |
| 736 | |
| 737 | server->nlm_host = host; |
| 738 | server->destroy = nfs_destroy_server; |
| 739 | return 0; |
David Howells | 54ceac4 | 2006-08-22 20:06:13 -0400 | [diff] [blame] | 740 | } |
| 741 | |
| 742 | /* |
| 743 | * Initialise an NFSv3 ACL client connection |
| 744 | */ |
| 745 | #ifdef CONFIG_NFS_V3_ACL |
| 746 | static void nfs_init_server_aclclient(struct nfs_server *server) |
| 747 | { |
Trond Myklebust | 40c55319 | 2007-12-14 14:56:07 -0500 | [diff] [blame] | 748 | if (server->nfs_client->rpc_ops->version != 3) |
David Howells | 54ceac4 | 2006-08-22 20:06:13 -0400 | [diff] [blame] | 749 | goto out_noacl; |
| 750 | if (server->flags & NFS_MOUNT_NOACL) |
| 751 | goto out_noacl; |
| 752 | |
| 753 | server->client_acl = rpc_bind_new_program(server->client, &nfsacl_program, 3); |
| 754 | if (IS_ERR(server->client_acl)) |
| 755 | goto out_noacl; |
| 756 | |
| 757 | /* No errors! Assume that Sun nfsacls are supported */ |
| 758 | server->caps |= NFS_CAP_ACLS; |
| 759 | return; |
| 760 | |
| 761 | out_noacl: |
| 762 | server->caps &= ~NFS_CAP_ACLS; |
| 763 | } |
| 764 | #else |
| 765 | static inline void nfs_init_server_aclclient(struct nfs_server *server) |
| 766 | { |
| 767 | server->flags &= ~NFS_MOUNT_NOACL; |
| 768 | server->caps &= ~NFS_CAP_ACLS; |
| 769 | } |
| 770 | #endif |
| 771 | |
| 772 | /* |
| 773 | * Create a general RPC client |
| 774 | */ |
Trond Myklebust | 3317023 | 2007-12-20 16:03:59 -0500 | [diff] [blame] | 775 | static int nfs_init_server_rpcclient(struct nfs_server *server, |
| 776 | const struct rpc_timeout *timeo, |
| 777 | rpc_authflavor_t pseudoflavour) |
David Howells | 54ceac4 | 2006-08-22 20:06:13 -0400 | [diff] [blame] | 778 | { |
| 779 | struct nfs_client *clp = server->nfs_client; |
| 780 | |
| 781 | server->client = rpc_clone_client(clp->cl_rpcclient); |
| 782 | if (IS_ERR(server->client)) { |
Harvey Harrison | 3110ff8 | 2008-05-02 13:42:44 -0700 | [diff] [blame] | 783 | dprintk("%s: couldn't create rpc_client!\n", __func__); |
David Howells | 54ceac4 | 2006-08-22 20:06:13 -0400 | [diff] [blame] | 784 | return PTR_ERR(server->client); |
| 785 | } |
| 786 | |
Trond Myklebust | 3317023 | 2007-12-20 16:03:59 -0500 | [diff] [blame] | 787 | memcpy(&server->client->cl_timeout_default, |
| 788 | timeo, |
| 789 | sizeof(server->client->cl_timeout_default)); |
| 790 | server->client->cl_timeout = &server->client->cl_timeout_default; |
| 791 | |
David Howells | 54ceac4 | 2006-08-22 20:06:13 -0400 | [diff] [blame] | 792 | if (pseudoflavour != clp->cl_rpcclient->cl_auth->au_flavor) { |
| 793 | struct rpc_auth *auth; |
| 794 | |
| 795 | auth = rpcauth_create(pseudoflavour, server->client); |
| 796 | if (IS_ERR(auth)) { |
Harvey Harrison | 3110ff8 | 2008-05-02 13:42:44 -0700 | [diff] [blame] | 797 | dprintk("%s: couldn't create credcache!\n", __func__); |
David Howells | 54ceac4 | 2006-08-22 20:06:13 -0400 | [diff] [blame] | 798 | return PTR_ERR(auth); |
| 799 | } |
| 800 | } |
| 801 | server->client->cl_softrtry = 0; |
| 802 | if (server->flags & NFS_MOUNT_SOFT) |
| 803 | server->client->cl_softrtry = 1; |
| 804 | |
David Howells | 54ceac4 | 2006-08-22 20:06:13 -0400 | [diff] [blame] | 805 | return 0; |
| 806 | } |
| 807 | |
| 808 | /* |
| 809 | * Initialise an NFS2 or NFS3 client |
| 810 | */ |
Andy Adamson | 45a52a0 | 2011-03-01 01:34:08 +0000 | [diff] [blame] | 811 | int nfs_init_client(struct nfs_client *clp, const struct rpc_timeout *timeparms, |
| 812 | const char *ip_addr, rpc_authflavor_t authflavour, |
| 813 | int noresvport) |
David Howells | 54ceac4 | 2006-08-22 20:06:13 -0400 | [diff] [blame] | 814 | { |
David Howells | 54ceac4 | 2006-08-22 20:06:13 -0400 | [diff] [blame] | 815 | int error; |
| 816 | |
| 817 | if (clp->cl_cons_state == NFS_CS_READY) { |
| 818 | /* the client is already initialised */ |
| 819 | dprintk("<-- nfs_init_client() = 0 [already %p]\n", clp); |
| 820 | return 0; |
| 821 | } |
| 822 | |
David Howells | 54ceac4 | 2006-08-22 20:06:13 -0400 | [diff] [blame] | 823 | /* |
| 824 | * Create a client RPC handle for doing FSSTAT with UNIX auth only |
| 825 | * - RFC 2623, sec 2.3.2 |
| 826 | */ |
Chuck Lever | d740351 | 2008-12-23 15:21:37 -0500 | [diff] [blame] | 827 | error = nfs_create_rpc_client(clp, timeparms, RPC_AUTH_UNIX, |
Andy Adamson | 45a52a0 | 2011-03-01 01:34:08 +0000 | [diff] [blame] | 828 | 0, noresvport); |
David Howells | 54ceac4 | 2006-08-22 20:06:13 -0400 | [diff] [blame] | 829 | if (error < 0) |
| 830 | goto error; |
| 831 | nfs_mark_client_ready(clp, NFS_CS_READY); |
| 832 | return 0; |
| 833 | |
| 834 | error: |
| 835 | nfs_mark_client_ready(clp, error); |
| 836 | dprintk("<-- nfs_init_client() = xerror %d\n", error); |
| 837 | return error; |
| 838 | } |
| 839 | |
| 840 | /* |
| 841 | * Create a version 2 or 3 client |
| 842 | */ |
\"Talpey, Thomas\ | 2283f8d | 2007-09-10 13:43:56 -0400 | [diff] [blame] | 843 | static int nfs_init_server(struct nfs_server *server, |
| 844 | const struct nfs_parsed_mount_data *data) |
David Howells | 54ceac4 | 2006-08-22 20:06:13 -0400 | [diff] [blame] | 845 | { |
Trond Myklebust | 3a49802 | 2007-12-14 14:56:04 -0500 | [diff] [blame] | 846 | struct nfs_client_initdata cl_init = { |
| 847 | .hostname = data->nfs_server.hostname, |
Chuck Lever | d7422c4 | 2007-12-10 14:58:51 -0500 | [diff] [blame] | 848 | .addr = (const struct sockaddr *)&data->nfs_server.address, |
Chuck Lever | 4c56801 | 2007-12-10 14:59:28 -0500 | [diff] [blame] | 849 | .addrlen = data->nfs_server.addrlen, |
Trond Myklebust | 40c55319 | 2007-12-14 14:56:07 -0500 | [diff] [blame] | 850 | .rpc_ops = &nfs_v2_clientops, |
Trond Myklebust | 59dca3b | 2008-01-03 16:29:06 -0500 | [diff] [blame] | 851 | .proto = data->nfs_server.protocol, |
Stanislav Kinsbursky | e50a7a1 | 2012-01-10 16:12:46 +0400 | [diff] [blame] | 852 | .net = data->net, |
Trond Myklebust | 3a49802 | 2007-12-14 14:56:04 -0500 | [diff] [blame] | 853 | }; |
Trond Myklebust | 3317023 | 2007-12-20 16:03:59 -0500 | [diff] [blame] | 854 | struct rpc_timeout timeparms; |
David Howells | 54ceac4 | 2006-08-22 20:06:13 -0400 | [diff] [blame] | 855 | struct nfs_client *clp; |
Trond Myklebust | 3a49802 | 2007-12-14 14:56:04 -0500 | [diff] [blame] | 856 | int error; |
David Howells | 54ceac4 | 2006-08-22 20:06:13 -0400 | [diff] [blame] | 857 | |
| 858 | dprintk("--> nfs_init_server()\n"); |
| 859 | |
| 860 | #ifdef CONFIG_NFS_V3 |
Trond Myklebust | 8a6e5de | 2009-09-23 14:36:37 -0400 | [diff] [blame] | 861 | if (data->version == 3) |
Trond Myklebust | 40c55319 | 2007-12-14 14:56:07 -0500 | [diff] [blame] | 862 | cl_init.rpc_ops = &nfs_v3_clientops; |
David Howells | 54ceac4 | 2006-08-22 20:06:13 -0400 | [diff] [blame] | 863 | #endif |
| 864 | |
Andy Adamson | 45a52a0 | 2011-03-01 01:34:08 +0000 | [diff] [blame] | 865 | nfs_init_timeout_values(&timeparms, data->nfs_server.protocol, |
| 866 | data->timeo, data->retrans); |
| 867 | |
David Howells | 54ceac4 | 2006-08-22 20:06:13 -0400 | [diff] [blame] | 868 | /* Allocate or find a client reference we can use */ |
Andy Adamson | 45a52a0 | 2011-03-01 01:34:08 +0000 | [diff] [blame] | 869 | clp = nfs_get_client(&cl_init, &timeparms, NULL, RPC_AUTH_UNIX, |
| 870 | data->flags & NFS_MOUNT_NORESVPORT); |
David Howells | 54ceac4 | 2006-08-22 20:06:13 -0400 | [diff] [blame] | 871 | if (IS_ERR(clp)) { |
| 872 | dprintk("<-- nfs_init_server() = error %ld\n", PTR_ERR(clp)); |
| 873 | return PTR_ERR(clp); |
| 874 | } |
| 875 | |
David Howells | 54ceac4 | 2006-08-22 20:06:13 -0400 | [diff] [blame] | 876 | server->nfs_client = clp; |
| 877 | |
| 878 | /* Initialise the client representation from the mount data */ |
Trond Myklebust | ff3525a | 2008-08-15 16:59:14 -0400 | [diff] [blame] | 879 | server->flags = data->flags; |
David Howells | b797cac | 2009-04-03 16:42:48 +0100 | [diff] [blame] | 880 | server->options = data->options; |
Trond Myklebust | 62ab460c | 2009-08-09 15:06:19 -0400 | [diff] [blame] | 881 | server->caps |= NFS_CAP_HARDLINKS|NFS_CAP_SYMLINKS|NFS_CAP_FILEID| |
| 882 | NFS_CAP_MODE|NFS_CAP_NLINK|NFS_CAP_OWNER|NFS_CAP_OWNER_GROUP| |
| 883 | NFS_CAP_ATIME|NFS_CAP_CTIME|NFS_CAP_MTIME; |
David Howells | 54ceac4 | 2006-08-22 20:06:13 -0400 | [diff] [blame] | 884 | |
| 885 | if (data->rsize) |
| 886 | server->rsize = nfs_block_size(data->rsize, NULL); |
| 887 | if (data->wsize) |
| 888 | server->wsize = nfs_block_size(data->wsize, NULL); |
| 889 | |
| 890 | server->acregmin = data->acregmin * HZ; |
| 891 | server->acregmax = data->acregmax * HZ; |
| 892 | server->acdirmin = data->acdirmin * HZ; |
| 893 | server->acdirmax = data->acdirmax * HZ; |
| 894 | |
| 895 | /* Start lockd here, before we might error out */ |
| 896 | error = nfs_start_lockd(server); |
| 897 | if (error < 0) |
| 898 | goto error; |
| 899 | |
Chuck Lever | f22d6d7 | 2008-03-14 14:10:22 -0400 | [diff] [blame] | 900 | server->port = data->nfs_server.port; |
| 901 | |
Trond Myklebust | 3317023 | 2007-12-20 16:03:59 -0500 | [diff] [blame] | 902 | error = nfs_init_server_rpcclient(server, &timeparms, data->auth_flavors[0]); |
David Howells | 54ceac4 | 2006-08-22 20:06:13 -0400 | [diff] [blame] | 903 | if (error < 0) |
| 904 | goto error; |
| 905 | |
Chuck Lever | 3f8400d | 2008-03-14 14:10:30 -0400 | [diff] [blame] | 906 | /* Preserve the values of mount_server-related mount options */ |
| 907 | if (data->mount_server.addrlen) { |
| 908 | memcpy(&server->mountd_address, &data->mount_server.address, |
| 909 | data->mount_server.addrlen); |
| 910 | server->mountd_addrlen = data->mount_server.addrlen; |
| 911 | } |
| 912 | server->mountd_version = data->mount_server.version; |
| 913 | server->mountd_port = data->mount_server.port; |
| 914 | server->mountd_protocol = data->mount_server.protocol; |
| 915 | |
David Howells | 54ceac4 | 2006-08-22 20:06:13 -0400 | [diff] [blame] | 916 | server->namelen = data->namlen; |
| 917 | /* Create a client RPC handle for the NFSv3 ACL management interface */ |
| 918 | nfs_init_server_aclclient(server); |
David Howells | 54ceac4 | 2006-08-22 20:06:13 -0400 | [diff] [blame] | 919 | dprintk("<-- nfs_init_server() = 0 [new %p]\n", clp); |
| 920 | return 0; |
| 921 | |
| 922 | error: |
| 923 | server->nfs_client = NULL; |
| 924 | nfs_put_client(clp); |
| 925 | dprintk("<-- nfs_init_server() = xerror %d\n", error); |
| 926 | return error; |
| 927 | } |
| 928 | |
| 929 | /* |
| 930 | * Load up the server record from information gained in an fsinfo record |
| 931 | */ |
Benny Halevy | 738fd0f3 | 2011-07-30 20:52:36 -0400 | [diff] [blame] | 932 | static void nfs_server_set_fsinfo(struct nfs_server *server, |
| 933 | struct nfs_fh *mntfh, |
| 934 | struct nfs_fsinfo *fsinfo) |
David Howells | 54ceac4 | 2006-08-22 20:06:13 -0400 | [diff] [blame] | 935 | { |
| 936 | unsigned long max_rpc_payload; |
| 937 | |
| 938 | /* Work out a lot of parameters */ |
| 939 | if (server->rsize == 0) |
| 940 | server->rsize = nfs_block_size(fsinfo->rtpref, NULL); |
| 941 | if (server->wsize == 0) |
| 942 | server->wsize = nfs_block_size(fsinfo->wtpref, NULL); |
| 943 | |
| 944 | if (fsinfo->rtmax >= 512 && server->rsize > fsinfo->rtmax) |
| 945 | server->rsize = nfs_block_size(fsinfo->rtmax, NULL); |
| 946 | if (fsinfo->wtmax >= 512 && server->wsize > fsinfo->wtmax) |
| 947 | server->wsize = nfs_block_size(fsinfo->wtmax, NULL); |
| 948 | |
| 949 | max_rpc_payload = nfs_block_size(rpc_max_payload(server->client), NULL); |
| 950 | if (server->rsize > max_rpc_payload) |
| 951 | server->rsize = max_rpc_payload; |
| 952 | if (server->rsize > NFS_MAX_FILE_IO_SIZE) |
| 953 | server->rsize = NFS_MAX_FILE_IO_SIZE; |
| 954 | server->rpages = (server->rsize + PAGE_CACHE_SIZE - 1) >> PAGE_CACHE_SHIFT; |
Peter Zijlstra | e0bf68d | 2007-10-16 23:25:46 -0700 | [diff] [blame] | 955 | |
Jens Axboe | d993831 | 2009-06-12 14:45:52 +0200 | [diff] [blame] | 956 | server->backing_dev_info.name = "nfs"; |
David Howells | 54ceac4 | 2006-08-22 20:06:13 -0400 | [diff] [blame] | 957 | server->backing_dev_info.ra_pages = server->rpages * NFS_MAX_READAHEAD; |
| 958 | |
| 959 | if (server->wsize > max_rpc_payload) |
| 960 | server->wsize = max_rpc_payload; |
| 961 | if (server->wsize > NFS_MAX_FILE_IO_SIZE) |
| 962 | server->wsize = NFS_MAX_FILE_IO_SIZE; |
| 963 | server->wpages = (server->wsize + PAGE_CACHE_SIZE - 1) >> PAGE_CACHE_SHIFT; |
Fred Isaman | dae100c | 2011-07-30 20:52:37 -0400 | [diff] [blame] | 964 | server->pnfs_blksize = fsinfo->blksize; |
Benny Halevy | 738fd0f3 | 2011-07-30 20:52:36 -0400 | [diff] [blame] | 965 | set_pnfs_layoutdriver(server, mntfh, fsinfo->layouttype); |
Ricardo Labiaga | 85e174b | 2010-10-20 00:17:58 -0400 | [diff] [blame] | 966 | |
David Howells | 54ceac4 | 2006-08-22 20:06:13 -0400 | [diff] [blame] | 967 | server->wtmult = nfs_block_bits(fsinfo->wtmult, NULL); |
| 968 | |
| 969 | server->dtsize = nfs_block_size(fsinfo->dtpref, NULL); |
Bryan Schumaker | 56e4ebf | 2010-10-20 15:44:37 -0400 | [diff] [blame] | 970 | if (server->dtsize > PAGE_CACHE_SIZE * NFS_MAX_READDIR_PAGES) |
| 971 | server->dtsize = PAGE_CACHE_SIZE * NFS_MAX_READDIR_PAGES; |
David Howells | 54ceac4 | 2006-08-22 20:06:13 -0400 | [diff] [blame] | 972 | if (server->dtsize > server->rsize) |
| 973 | server->dtsize = server->rsize; |
| 974 | |
| 975 | if (server->flags & NFS_MOUNT_NOAC) { |
| 976 | server->acregmin = server->acregmax = 0; |
| 977 | server->acdirmin = server->acdirmax = 0; |
| 978 | } |
| 979 | |
| 980 | server->maxfilesize = fsinfo->maxfilesize; |
| 981 | |
Ricardo Labiaga | 6b96724 | 2010-10-12 16:30:05 -0700 | [diff] [blame] | 982 | server->time_delta = fsinfo->time_delta; |
| 983 | |
David Howells | 54ceac4 | 2006-08-22 20:06:13 -0400 | [diff] [blame] | 984 | /* We're airborne Set socket buffersize */ |
| 985 | rpc_setbufsize(server->client, server->wsize + 100, server->rsize + 100); |
| 986 | } |
| 987 | |
| 988 | /* |
| 989 | * Probe filesystem information, including the FSID on v2/v3 |
| 990 | */ |
| 991 | static int nfs_probe_fsinfo(struct nfs_server *server, struct nfs_fh *mntfh, struct nfs_fattr *fattr) |
| 992 | { |
| 993 | struct nfs_fsinfo fsinfo; |
| 994 | struct nfs_client *clp = server->nfs_client; |
| 995 | int error; |
| 996 | |
| 997 | dprintk("--> nfs_probe_fsinfo()\n"); |
| 998 | |
| 999 | if (clp->rpc_ops->set_capabilities != NULL) { |
| 1000 | error = clp->rpc_ops->set_capabilities(server, mntfh); |
| 1001 | if (error < 0) |
| 1002 | goto out_error; |
| 1003 | } |
| 1004 | |
| 1005 | fsinfo.fattr = fattr; |
Ricardo Labiaga | 85e174b | 2010-10-20 00:17:58 -0400 | [diff] [blame] | 1006 | fsinfo.layouttype = 0; |
David Howells | 54ceac4 | 2006-08-22 20:06:13 -0400 | [diff] [blame] | 1007 | error = clp->rpc_ops->fsinfo(server, mntfh, &fsinfo); |
| 1008 | if (error < 0) |
| 1009 | goto out_error; |
| 1010 | |
Benny Halevy | 738fd0f3 | 2011-07-30 20:52:36 -0400 | [diff] [blame] | 1011 | nfs_server_set_fsinfo(server, mntfh, &fsinfo); |
David Howells | 54ceac4 | 2006-08-22 20:06:13 -0400 | [diff] [blame] | 1012 | |
| 1013 | /* Get some general file system info */ |
| 1014 | if (server->namelen == 0) { |
| 1015 | struct nfs_pathconf pathinfo; |
| 1016 | |
| 1017 | pathinfo.fattr = fattr; |
| 1018 | nfs_fattr_init(fattr); |
| 1019 | |
| 1020 | if (clp->rpc_ops->pathconf(server, mntfh, &pathinfo) >= 0) |
| 1021 | server->namelen = pathinfo.max_namelen; |
| 1022 | } |
| 1023 | |
| 1024 | dprintk("<-- nfs_probe_fsinfo() = 0\n"); |
| 1025 | return 0; |
| 1026 | |
| 1027 | out_error: |
| 1028 | dprintk("nfs_probe_fsinfo: error = %d\n", -error); |
| 1029 | return error; |
| 1030 | } |
| 1031 | |
| 1032 | /* |
| 1033 | * Copy useful information when duplicating a server record |
| 1034 | */ |
| 1035 | static void nfs_server_copy_userdata(struct nfs_server *target, struct nfs_server *source) |
| 1036 | { |
| 1037 | target->flags = source->flags; |
Chuck Lever | 356e76b | 2010-04-22 15:35:56 -0400 | [diff] [blame] | 1038 | target->rsize = source->rsize; |
| 1039 | target->wsize = source->wsize; |
David Howells | 54ceac4 | 2006-08-22 20:06:13 -0400 | [diff] [blame] | 1040 | target->acregmin = source->acregmin; |
| 1041 | target->acregmax = source->acregmax; |
| 1042 | target->acdirmin = source->acdirmin; |
| 1043 | target->acdirmax = source->acdirmax; |
| 1044 | target->caps = source->caps; |
David Howells | 2df5480 | 2009-09-23 14:36:39 -0400 | [diff] [blame] | 1045 | target->options = source->options; |
David Howells | 54ceac4 | 2006-08-22 20:06:13 -0400 | [diff] [blame] | 1046 | } |
| 1047 | |
Chuck Lever | fca5238 | 2010-12-24 01:32:32 +0000 | [diff] [blame] | 1048 | static void nfs_server_insert_lists(struct nfs_server *server) |
| 1049 | { |
| 1050 | struct nfs_client *clp = server->nfs_client; |
Stanislav Kinsbursky | c25d32b | 2012-01-23 17:26:14 +0000 | [diff] [blame] | 1051 | struct nfs_net *nn = net_generic(clp->net, nfs_net_id); |
Chuck Lever | fca5238 | 2010-12-24 01:32:32 +0000 | [diff] [blame] | 1052 | |
Stanislav Kinsbursky | dc03085 | 2012-01-23 17:26:31 +0000 | [diff] [blame] | 1053 | spin_lock(&nn->nfs_client_lock); |
Chuck Lever | fca5238 | 2010-12-24 01:32:32 +0000 | [diff] [blame] | 1054 | list_add_tail_rcu(&server->client_link, &clp->cl_superblocks); |
Stanislav Kinsbursky | c25d32b | 2012-01-23 17:26:14 +0000 | [diff] [blame] | 1055 | list_add_tail(&server->master_link, &nn->nfs_volume_list); |
Andy Adamson | d3b4c9d | 2011-03-01 01:34:10 +0000 | [diff] [blame] | 1056 | clear_bit(NFS_CS_STOP_RENEW, &clp->cl_res_state); |
Stanislav Kinsbursky | dc03085 | 2012-01-23 17:26:31 +0000 | [diff] [blame] | 1057 | spin_unlock(&nn->nfs_client_lock); |
Chuck Lever | fca5238 | 2010-12-24 01:32:32 +0000 | [diff] [blame] | 1058 | |
| 1059 | } |
| 1060 | |
| 1061 | static void nfs_server_remove_lists(struct nfs_server *server) |
| 1062 | { |
Andy Adamson | d3b4c9d | 2011-03-01 01:34:10 +0000 | [diff] [blame] | 1063 | struct nfs_client *clp = server->nfs_client; |
Trond Myklebust | 4c03ae4 | 2012-02-07 00:05:11 -0500 | [diff] [blame] | 1064 | struct nfs_net *nn; |
Andy Adamson | d3b4c9d | 2011-03-01 01:34:10 +0000 | [diff] [blame] | 1065 | |
Trond Myklebust | 4c03ae4 | 2012-02-07 00:05:11 -0500 | [diff] [blame] | 1066 | if (clp == NULL) |
| 1067 | return; |
| 1068 | nn = net_generic(clp->net, nfs_net_id); |
Stanislav Kinsbursky | dc03085 | 2012-01-23 17:26:31 +0000 | [diff] [blame] | 1069 | spin_lock(&nn->nfs_client_lock); |
Chuck Lever | fca5238 | 2010-12-24 01:32:32 +0000 | [diff] [blame] | 1070 | list_del_rcu(&server->client_link); |
Trond Myklebust | 4c03ae4 | 2012-02-07 00:05:11 -0500 | [diff] [blame] | 1071 | if (list_empty(&clp->cl_superblocks)) |
Andy Adamson | d3b4c9d | 2011-03-01 01:34:10 +0000 | [diff] [blame] | 1072 | set_bit(NFS_CS_STOP_RENEW, &clp->cl_res_state); |
Chuck Lever | fca5238 | 2010-12-24 01:32:32 +0000 | [diff] [blame] | 1073 | list_del(&server->master_link); |
Stanislav Kinsbursky | dc03085 | 2012-01-23 17:26:31 +0000 | [diff] [blame] | 1074 | spin_unlock(&nn->nfs_client_lock); |
Chuck Lever | fca5238 | 2010-12-24 01:32:32 +0000 | [diff] [blame] | 1075 | |
| 1076 | synchronize_rcu(); |
| 1077 | } |
| 1078 | |
David Howells | 54ceac4 | 2006-08-22 20:06:13 -0400 | [diff] [blame] | 1079 | /* |
| 1080 | * Allocate and initialise a server record |
| 1081 | */ |
| 1082 | static struct nfs_server *nfs_alloc_server(void) |
| 1083 | { |
| 1084 | struct nfs_server *server; |
| 1085 | |
| 1086 | server = kzalloc(sizeof(struct nfs_server), GFP_KERNEL); |
| 1087 | if (!server) |
| 1088 | return NULL; |
| 1089 | |
| 1090 | server->client = server->client_acl = ERR_PTR(-EINVAL); |
| 1091 | |
| 1092 | /* Zero out the NFS state stuff */ |
| 1093 | INIT_LIST_HEAD(&server->client_link); |
| 1094 | INIT_LIST_HEAD(&server->master_link); |
Chuck Lever | d3978bb | 2010-12-24 01:33:04 +0000 | [diff] [blame] | 1095 | INIT_LIST_HEAD(&server->delegations); |
Weston Andros Adamson | 6382a44 | 2011-06-01 16:44:44 -0400 | [diff] [blame] | 1096 | INIT_LIST_HEAD(&server->layouts); |
Chuck Lever | 0aaaf5c | 2011-12-06 16:13:48 -0500 | [diff] [blame] | 1097 | INIT_LIST_HEAD(&server->state_owners_lru); |
David Howells | 54ceac4 | 2006-08-22 20:06:13 -0400 | [diff] [blame] | 1098 | |
Steve Dickson | ef818a2 | 2007-11-08 04:05:04 -0500 | [diff] [blame] | 1099 | atomic_set(&server->active, 0); |
| 1100 | |
David Howells | 54ceac4 | 2006-08-22 20:06:13 -0400 | [diff] [blame] | 1101 | server->io_stats = nfs_alloc_iostats(); |
| 1102 | if (!server->io_stats) { |
| 1103 | kfree(server); |
| 1104 | return NULL; |
| 1105 | } |
| 1106 | |
Jens Axboe | 48d0764 | 2009-09-21 09:59:39 +0200 | [diff] [blame] | 1107 | if (bdi_init(&server->backing_dev_info)) { |
| 1108 | nfs_free_iostats(server->io_stats); |
| 1109 | kfree(server); |
| 1110 | return NULL; |
| 1111 | } |
| 1112 | |
Trond Myklebust | 9157c31 | 2012-01-17 22:04:24 -0500 | [diff] [blame] | 1113 | ida_init(&server->openowner_id); |
Trond Myklebust | d2d7ce2 | 2012-01-17 22:04:25 -0500 | [diff] [blame] | 1114 | ida_init(&server->lockowner_id); |
Fred Isaman | f7e8917 | 2011-01-06 11:36:32 +0000 | [diff] [blame] | 1115 | pnfs_init_server(server); |
| 1116 | |
David Howells | 54ceac4 | 2006-08-22 20:06:13 -0400 | [diff] [blame] | 1117 | return server; |
| 1118 | } |
| 1119 | |
| 1120 | /* |
| 1121 | * Free up a server record |
| 1122 | */ |
| 1123 | void nfs_free_server(struct nfs_server *server) |
| 1124 | { |
| 1125 | dprintk("--> nfs_free_server()\n"); |
| 1126 | |
Chuck Lever | fca5238 | 2010-12-24 01:32:32 +0000 | [diff] [blame] | 1127 | nfs_server_remove_lists(server); |
Ricardo Labiaga | 85e174b | 2010-10-20 00:17:58 -0400 | [diff] [blame] | 1128 | unset_pnfs_layoutdriver(server); |
David Howells | 54ceac4 | 2006-08-22 20:06:13 -0400 | [diff] [blame] | 1129 | |
| 1130 | if (server->destroy != NULL) |
| 1131 | server->destroy(server); |
Trond Myklebust | 5cef338 | 2007-12-11 22:01:56 -0500 | [diff] [blame] | 1132 | |
| 1133 | if (!IS_ERR(server->client_acl)) |
| 1134 | rpc_shutdown_client(server->client_acl); |
David Howells | 54ceac4 | 2006-08-22 20:06:13 -0400 | [diff] [blame] | 1135 | if (!IS_ERR(server->client)) |
| 1136 | rpc_shutdown_client(server->client); |
| 1137 | |
| 1138 | nfs_put_client(server->nfs_client); |
| 1139 | |
Trond Myklebust | d2d7ce2 | 2012-01-17 22:04:25 -0500 | [diff] [blame] | 1140 | ida_destroy(&server->lockowner_id); |
Trond Myklebust | 9157c31 | 2012-01-17 22:04:24 -0500 | [diff] [blame] | 1141 | ida_destroy(&server->openowner_id); |
David Howells | 54ceac4 | 2006-08-22 20:06:13 -0400 | [diff] [blame] | 1142 | nfs_free_iostats(server->io_stats); |
Peter Zijlstra | e0bf68d | 2007-10-16 23:25:46 -0700 | [diff] [blame] | 1143 | bdi_destroy(&server->backing_dev_info); |
David Howells | 54ceac4 | 2006-08-22 20:06:13 -0400 | [diff] [blame] | 1144 | kfree(server); |
| 1145 | nfs_release_automount_timer(); |
| 1146 | dprintk("<-- nfs_free_server()\n"); |
| 1147 | } |
| 1148 | |
| 1149 | /* |
| 1150 | * Create a version 2 or 3 volume record |
| 1151 | * - keyed on server and FSID |
| 1152 | */ |
\"Talpey, Thomas\ | 2283f8d | 2007-09-10 13:43:56 -0400 | [diff] [blame] | 1153 | 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] | 1154 | struct nfs_fh *mntfh) |
| 1155 | { |
| 1156 | struct nfs_server *server; |
Trond Myklebust | fbca779 | 2010-04-16 16:22:46 -0400 | [diff] [blame] | 1157 | struct nfs_fattr *fattr; |
David Howells | 54ceac4 | 2006-08-22 20:06:13 -0400 | [diff] [blame] | 1158 | int error; |
| 1159 | |
| 1160 | server = nfs_alloc_server(); |
| 1161 | if (!server) |
| 1162 | return ERR_PTR(-ENOMEM); |
| 1163 | |
Trond Myklebust | fbca779 | 2010-04-16 16:22:46 -0400 | [diff] [blame] | 1164 | error = -ENOMEM; |
| 1165 | fattr = nfs_alloc_fattr(); |
| 1166 | if (fattr == NULL) |
| 1167 | goto error; |
| 1168 | |
David Howells | 54ceac4 | 2006-08-22 20:06:13 -0400 | [diff] [blame] | 1169 | /* Get a client representation */ |
| 1170 | error = nfs_init_server(server, data); |
| 1171 | if (error < 0) |
| 1172 | goto error; |
| 1173 | |
| 1174 | BUG_ON(!server->nfs_client); |
| 1175 | BUG_ON(!server->nfs_client->rpc_ops); |
| 1176 | BUG_ON(!server->nfs_client->rpc_ops->file_inode_ops); |
| 1177 | |
| 1178 | /* Probe the root fh to retrieve its FSID */ |
Trond Myklebust | fbca779 | 2010-04-16 16:22:46 -0400 | [diff] [blame] | 1179 | error = nfs_probe_fsinfo(server, mntfh, fattr); |
David Howells | 54ceac4 | 2006-08-22 20:06:13 -0400 | [diff] [blame] | 1180 | if (error < 0) |
| 1181 | goto error; |
Trond Myklebust | 54af3bb | 2007-09-28 12:27:41 -0400 | [diff] [blame] | 1182 | if (server->nfs_client->rpc_ops->version == 3) { |
| 1183 | if (server->namelen == 0 || server->namelen > NFS3_MAXNAMLEN) |
| 1184 | server->namelen = NFS3_MAXNAMLEN; |
| 1185 | if (!(data->flags & NFS_MOUNT_NORDIRPLUS)) |
| 1186 | server->caps |= NFS_CAP_READDIRPLUS; |
| 1187 | } else { |
| 1188 | if (server->namelen == 0 || server->namelen > NFS2_MAXNAMLEN) |
| 1189 | server->namelen = NFS2_MAXNAMLEN; |
| 1190 | } |
| 1191 | |
Trond Myklebust | fbca779 | 2010-04-16 16:22:46 -0400 | [diff] [blame] | 1192 | if (!(fattr->valid & NFS_ATTR_FATTR)) { |
| 1193 | error = server->nfs_client->rpc_ops->getattr(server, mntfh, fattr); |
David Howells | 54ceac4 | 2006-08-22 20:06:13 -0400 | [diff] [blame] | 1194 | if (error < 0) { |
| 1195 | dprintk("nfs_create_server: getattr error = %d\n", -error); |
| 1196 | goto error; |
| 1197 | } |
| 1198 | } |
Trond Myklebust | fbca779 | 2010-04-16 16:22:46 -0400 | [diff] [blame] | 1199 | memcpy(&server->fsid, &fattr->fsid, sizeof(server->fsid)); |
David Howells | 54ceac4 | 2006-08-22 20:06:13 -0400 | [diff] [blame] | 1200 | |
David Howells | 6daabf1 | 2006-08-24 15:44:16 -0400 | [diff] [blame] | 1201 | dprintk("Server FSID: %llx:%llx\n", |
| 1202 | (unsigned long long) server->fsid.major, |
| 1203 | (unsigned long long) server->fsid.minor); |
David Howells | 54ceac4 | 2006-08-22 20:06:13 -0400 | [diff] [blame] | 1204 | |
Chuck Lever | fca5238 | 2010-12-24 01:32:32 +0000 | [diff] [blame] | 1205 | nfs_server_insert_lists(server); |
David Howells | 54ceac4 | 2006-08-22 20:06:13 -0400 | [diff] [blame] | 1206 | server->mount_time = jiffies; |
Trond Myklebust | fbca779 | 2010-04-16 16:22:46 -0400 | [diff] [blame] | 1207 | nfs_free_fattr(fattr); |
David Howells | 54ceac4 | 2006-08-22 20:06:13 -0400 | [diff] [blame] | 1208 | return server; |
| 1209 | |
| 1210 | error: |
Trond Myklebust | fbca779 | 2010-04-16 16:22:46 -0400 | [diff] [blame] | 1211 | nfs_free_fattr(fattr); |
David Howells | 54ceac4 | 2006-08-22 20:06:13 -0400 | [diff] [blame] | 1212 | nfs_free_server(server); |
| 1213 | return ERR_PTR(error); |
| 1214 | } |
| 1215 | |
| 1216 | #ifdef CONFIG_NFS_V4 |
| 1217 | /* |
Andy Adamson | c36fca5 | 2011-01-06 02:04:32 +0000 | [diff] [blame] | 1218 | * NFSv4.0 callback thread helper |
| 1219 | * |
Andy Adamson | c36fca5 | 2011-01-06 02:04:32 +0000 | [diff] [blame] | 1220 | * Find a client by callback identifier |
| 1221 | */ |
| 1222 | struct nfs_client * |
Stanislav Kinsbursky | 28cd1b3 | 2012-01-23 17:26:22 +0000 | [diff] [blame] | 1223 | nfs4_find_client_ident(struct net *net, int cb_ident) |
Andy Adamson | c36fca5 | 2011-01-06 02:04:32 +0000 | [diff] [blame] | 1224 | { |
| 1225 | struct nfs_client *clp; |
Stanislav Kinsbursky | 28cd1b3 | 2012-01-23 17:26:22 +0000 | [diff] [blame] | 1226 | struct nfs_net *nn = net_generic(net, nfs_net_id); |
Andy Adamson | c36fca5 | 2011-01-06 02:04:32 +0000 | [diff] [blame] | 1227 | |
Stanislav Kinsbursky | dc03085 | 2012-01-23 17:26:31 +0000 | [diff] [blame] | 1228 | spin_lock(&nn->nfs_client_lock); |
Stanislav Kinsbursky | 28cd1b3 | 2012-01-23 17:26:22 +0000 | [diff] [blame] | 1229 | clp = idr_find(&nn->cb_ident_idr, cb_ident); |
Andy Adamson | c36fca5 | 2011-01-06 02:04:32 +0000 | [diff] [blame] | 1230 | if (clp) |
| 1231 | atomic_inc(&clp->cl_count); |
Stanislav Kinsbursky | dc03085 | 2012-01-23 17:26:31 +0000 | [diff] [blame] | 1232 | spin_unlock(&nn->nfs_client_lock); |
Andy Adamson | c36fca5 | 2011-01-06 02:04:32 +0000 | [diff] [blame] | 1233 | return clp; |
| 1234 | } |
| 1235 | |
| 1236 | #if defined(CONFIG_NFS_V4_1) |
| 1237 | /* |
| 1238 | * NFSv4.1 callback thread helper |
| 1239 | * For CB_COMPOUND calls, find a client by IP address, protocol version, |
| 1240 | * minorversion, and sessionID |
| 1241 | * |
Andy Adamson | c36fca5 | 2011-01-06 02:04:32 +0000 | [diff] [blame] | 1242 | * Returns NULL if no such client |
| 1243 | */ |
| 1244 | struct nfs_client * |
Stanislav Kinsbursky | c7add9a | 2012-01-26 15:11:49 +0400 | [diff] [blame] | 1245 | nfs4_find_client_sessionid(struct net *net, const struct sockaddr *addr, |
Andy Adamson | 778be23 | 2011-01-25 15:38:01 +0000 | [diff] [blame] | 1246 | struct nfs4_sessionid *sid) |
Andy Adamson | c36fca5 | 2011-01-06 02:04:32 +0000 | [diff] [blame] | 1247 | { |
| 1248 | struct nfs_client *clp; |
Stanislav Kinsbursky | c7add9a | 2012-01-26 15:11:49 +0400 | [diff] [blame] | 1249 | struct nfs_net *nn = net_generic(net, nfs_net_id); |
Andy Adamson | c36fca5 | 2011-01-06 02:04:32 +0000 | [diff] [blame] | 1250 | |
Stanislav Kinsbursky | dc03085 | 2012-01-23 17:26:31 +0000 | [diff] [blame] | 1251 | spin_lock(&nn->nfs_client_lock); |
Stanislav Kinsbursky | 6b13168 | 2012-01-23 17:26:05 +0000 | [diff] [blame] | 1252 | list_for_each_entry(clp, &nn->nfs_client_list, cl_share_link) { |
Andy Adamson | c36fca5 | 2011-01-06 02:04:32 +0000 | [diff] [blame] | 1253 | if (nfs4_cb_match_client(addr, clp, 1) == false) |
| 1254 | continue; |
| 1255 | |
| 1256 | if (!nfs4_has_session(clp)) |
| 1257 | continue; |
| 1258 | |
Andy Adamson | 778be23 | 2011-01-25 15:38:01 +0000 | [diff] [blame] | 1259 | /* Match sessionid*/ |
| 1260 | if (memcmp(clp->cl_session->sess_id.data, |
| 1261 | sid->data, NFS4_MAX_SESSIONID_LEN) != 0) |
Andy Adamson | c36fca5 | 2011-01-06 02:04:32 +0000 | [diff] [blame] | 1262 | continue; |
| 1263 | |
| 1264 | atomic_inc(&clp->cl_count); |
Stanislav Kinsbursky | dc03085 | 2012-01-23 17:26:31 +0000 | [diff] [blame] | 1265 | spin_unlock(&nn->nfs_client_lock); |
Andy Adamson | c36fca5 | 2011-01-06 02:04:32 +0000 | [diff] [blame] | 1266 | return clp; |
| 1267 | } |
Stanislav Kinsbursky | dc03085 | 2012-01-23 17:26:31 +0000 | [diff] [blame] | 1268 | spin_unlock(&nn->nfs_client_lock); |
Andy Adamson | c36fca5 | 2011-01-06 02:04:32 +0000 | [diff] [blame] | 1269 | return NULL; |
| 1270 | } |
| 1271 | |
| 1272 | #else /* CONFIG_NFS_V4_1 */ |
| 1273 | |
| 1274 | struct nfs_client * |
Stanislav Kinsbursky | b6d1e83 | 2012-02-07 19:53:19 +0400 | [diff] [blame] | 1275 | nfs4_find_client_sessionid(struct net *net, const struct sockaddr *addr, |
Andy Adamson | 778be23 | 2011-01-25 15:38:01 +0000 | [diff] [blame] | 1276 | struct nfs4_sessionid *sid) |
Andy Adamson | c36fca5 | 2011-01-06 02:04:32 +0000 | [diff] [blame] | 1277 | { |
| 1278 | return NULL; |
| 1279 | } |
| 1280 | #endif /* CONFIG_NFS_V4_1 */ |
| 1281 | |
| 1282 | /* |
Benny Halevy | 9bdaa86 | 2009-04-01 09:22:55 -0400 | [diff] [blame] | 1283 | * Initialize the NFS4 callback service |
| 1284 | */ |
| 1285 | static int nfs4_init_callback(struct nfs_client *clp) |
| 1286 | { |
| 1287 | int error; |
| 1288 | |
| 1289 | if (clp->rpc_ops->version == 4) { |
Trond Myklebust | 2446ab6 | 2012-03-01 17:00:56 -0500 | [diff] [blame] | 1290 | struct rpc_xprt *xprt; |
| 1291 | |
| 1292 | xprt = rcu_dereference_raw(clp->cl_rpcclient->cl_xprt); |
| 1293 | |
Andy Adamson | 0b5b7ae | 2009-04-01 09:23:15 -0400 | [diff] [blame] | 1294 | if (nfs4_has_session(clp)) { |
Trond Myklebust | 2446ab6 | 2012-03-01 17:00:56 -0500 | [diff] [blame] | 1295 | error = xprt_setup_backchannel(xprt, |
Andy Adamson | 0b5b7ae | 2009-04-01 09:23:15 -0400 | [diff] [blame] | 1296 | NFS41_BC_MIN_CALLBACKS); |
| 1297 | if (error < 0) |
| 1298 | return error; |
| 1299 | } |
| 1300 | |
Trond Myklebust | 2446ab6 | 2012-03-01 17:00:56 -0500 | [diff] [blame] | 1301 | error = nfs_callback_up(clp->cl_mvops->minor_version, xprt); |
Benny Halevy | 9bdaa86 | 2009-04-01 09:22:55 -0400 | [diff] [blame] | 1302 | if (error < 0) { |
| 1303 | dprintk("%s: failed to start callback. Error = %d\n", |
| 1304 | __func__, error); |
| 1305 | return error; |
| 1306 | } |
| 1307 | __set_bit(NFS_CS_CALLBACK, &clp->cl_res_state); |
| 1308 | } |
| 1309 | return 0; |
| 1310 | } |
| 1311 | |
| 1312 | /* |
Andy Adamson | 557134a | 2009-04-01 09:21:53 -0400 | [diff] [blame] | 1313 | * Initialize the minor version specific parts of an NFS4 client record |
| 1314 | */ |
| 1315 | static int nfs4_init_client_minor_version(struct nfs_client *clp) |
| 1316 | { |
| 1317 | #if defined(CONFIG_NFS_V4_1) |
Trond Myklebust | 97dc135 | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 1318 | if (clp->cl_mvops->minor_version) { |
Andy Adamson | 557134a | 2009-04-01 09:21:53 -0400 | [diff] [blame] | 1319 | struct nfs4_session *session = NULL; |
| 1320 | /* |
| 1321 | * Create the session and mark it expired. |
| 1322 | * When a SEQUENCE operation encounters the expired session |
| 1323 | * it will do session recovery to initialize it. |
| 1324 | */ |
| 1325 | session = nfs4_alloc_session(clp); |
| 1326 | if (!session) |
| 1327 | return -ENOMEM; |
| 1328 | |
| 1329 | clp->cl_session = session; |
Trond Myklebust | fe74ba3 | 2010-06-16 09:52:27 -0400 | [diff] [blame] | 1330 | /* |
| 1331 | * The create session reply races with the server back |
| 1332 | * channel probe. Mark the client NFS_CS_SESSION_INITING |
| 1333 | * so that the client back channel can find the |
| 1334 | * nfs_client struct |
| 1335 | */ |
| 1336 | clp->cl_cons_state = NFS_CS_SESSION_INITING; |
Andy Adamson | 557134a | 2009-04-01 09:21:53 -0400 | [diff] [blame] | 1337 | } |
| 1338 | #endif /* CONFIG_NFS_V4_1 */ |
| 1339 | |
Benny Halevy | 7146851 | 2009-04-01 09:22:56 -0400 | [diff] [blame] | 1340 | return nfs4_init_callback(clp); |
Andy Adamson | 557134a | 2009-04-01 09:21:53 -0400 | [diff] [blame] | 1341 | } |
| 1342 | |
| 1343 | /* |
David Howells | 54ceac4 | 2006-08-22 20:06:13 -0400 | [diff] [blame] | 1344 | * Initialise an NFS4 client record |
| 1345 | */ |
Andy Adamson | 45a52a0 | 2011-03-01 01:34:08 +0000 | [diff] [blame] | 1346 | int nfs4_init_client(struct nfs_client *clp, |
| 1347 | const struct rpc_timeout *timeparms, |
| 1348 | const char *ip_addr, |
| 1349 | rpc_authflavor_t authflavour, |
| 1350 | int noresvport) |
David Howells | 54ceac4 | 2006-08-22 20:06:13 -0400 | [diff] [blame] | 1351 | { |
Chuck Lever | 31b8e2a | 2012-03-01 17:01:23 -0500 | [diff] [blame] | 1352 | char buf[INET6_ADDRSTRLEN + 1]; |
David Howells | 54ceac4 | 2006-08-22 20:06:13 -0400 | [diff] [blame] | 1353 | int error; |
| 1354 | |
| 1355 | if (clp->cl_cons_state == NFS_CS_READY) { |
| 1356 | /* the client is initialised already */ |
| 1357 | dprintk("<-- nfs4_init_client() = 0 [already %p]\n", clp); |
| 1358 | return 0; |
| 1359 | } |
| 1360 | |
| 1361 | /* Check NFS protocol revision and initialize RPC op vector */ |
| 1362 | clp->rpc_ops = &nfs_v4_clientops; |
| 1363 | |
Trond Myklebust | 59dca3b | 2008-01-03 16:29:06 -0500 | [diff] [blame] | 1364 | error = nfs_create_rpc_client(clp, timeparms, authflavour, |
Andy Adamson | 45a52a0 | 2011-03-01 01:34:08 +0000 | [diff] [blame] | 1365 | 1, noresvport); |
David Howells | 54ceac4 | 2006-08-22 20:06:13 -0400 | [diff] [blame] | 1366 | if (error < 0) |
| 1367 | goto error; |
Chuck Lever | 31b8e2a | 2012-03-01 17:01:23 -0500 | [diff] [blame] | 1368 | |
| 1369 | /* If no clientaddr= option was specified, find a usable cb address */ |
| 1370 | if (ip_addr == NULL) { |
| 1371 | struct sockaddr_storage cb_addr; |
| 1372 | struct sockaddr *sap = (struct sockaddr *)&cb_addr; |
| 1373 | |
| 1374 | error = rpc_localaddr(clp->cl_rpcclient, sap, sizeof(cb_addr)); |
| 1375 | if (error < 0) |
| 1376 | goto error; |
| 1377 | error = rpc_ntop(sap, buf, sizeof(buf)); |
| 1378 | if (error < 0) |
| 1379 | goto error; |
| 1380 | ip_addr = (const char *)buf; |
| 1381 | } |
Ben Hutchings | f4373bf | 2009-10-06 15:42:18 -0400 | [diff] [blame] | 1382 | strlcpy(clp->cl_ipaddr, ip_addr, sizeof(clp->cl_ipaddr)); |
David Howells | 54ceac4 | 2006-08-22 20:06:13 -0400 | [diff] [blame] | 1383 | |
| 1384 | error = nfs_idmap_new(clp); |
| 1385 | if (error < 0) { |
| 1386 | dprintk("%s: failed to create idmapper. Error = %d\n", |
Harvey Harrison | 3110ff8 | 2008-05-02 13:42:44 -0700 | [diff] [blame] | 1387 | __func__, error); |
David Howells | 54ceac4 | 2006-08-22 20:06:13 -0400 | [diff] [blame] | 1388 | goto error; |
| 1389 | } |
Trond Myklebust | 9c5bf38 | 2006-08-22 20:06:14 -0400 | [diff] [blame] | 1390 | __set_bit(NFS_CS_IDMAP, &clp->cl_res_state); |
David Howells | 54ceac4 | 2006-08-22 20:06:13 -0400 | [diff] [blame] | 1391 | |
Andy Adamson | 557134a | 2009-04-01 09:21:53 -0400 | [diff] [blame] | 1392 | error = nfs4_init_client_minor_version(clp); |
| 1393 | if (error < 0) |
| 1394 | goto error; |
| 1395 | |
Andy Adamson | 76db6d9 | 2009-04-01 09:22:38 -0400 | [diff] [blame] | 1396 | if (!nfs4_has_session(clp)) |
| 1397 | nfs_mark_client_ready(clp, NFS_CS_READY); |
David Howells | 54ceac4 | 2006-08-22 20:06:13 -0400 | [diff] [blame] | 1398 | return 0; |
| 1399 | |
| 1400 | error: |
| 1401 | nfs_mark_client_ready(clp, error); |
| 1402 | dprintk("<-- nfs4_init_client() = xerror %d\n", error); |
| 1403 | return error; |
| 1404 | } |
| 1405 | |
| 1406 | /* |
| 1407 | * Set up an NFS4 client |
| 1408 | */ |
| 1409 | static int nfs4_set_client(struct nfs_server *server, |
Chuck Lever | dcecae0 | 2007-12-10 14:58:59 -0500 | [diff] [blame] | 1410 | const char *hostname, |
| 1411 | const struct sockaddr *addr, |
| 1412 | const size_t addrlen, |
J. Bruce Fields | 7d9ac06 | 2006-10-19 23:28:39 -0700 | [diff] [blame] | 1413 | const char *ip_addr, |
David Howells | 54ceac4 | 2006-08-22 20:06:13 -0400 | [diff] [blame] | 1414 | rpc_authflavor_t authflavour, |
Benny Halevy | 94a417f | 2009-04-01 09:21:49 -0400 | [diff] [blame] | 1415 | int proto, const struct rpc_timeout *timeparms, |
Stanislav Kinsbursky | e50a7a1 | 2012-01-10 16:12:46 +0400 | [diff] [blame] | 1416 | u32 minorversion, struct net *net) |
David Howells | 54ceac4 | 2006-08-22 20:06:13 -0400 | [diff] [blame] | 1417 | { |
Trond Myklebust | 3a49802 | 2007-12-14 14:56:04 -0500 | [diff] [blame] | 1418 | struct nfs_client_initdata cl_init = { |
| 1419 | .hostname = hostname, |
Chuck Lever | dcecae0 | 2007-12-10 14:58:59 -0500 | [diff] [blame] | 1420 | .addr = addr, |
| 1421 | .addrlen = addrlen, |
Trond Myklebust | 40c55319 | 2007-12-14 14:56:07 -0500 | [diff] [blame] | 1422 | .rpc_ops = &nfs_v4_clientops, |
Trond Myklebust | 59dca3b | 2008-01-03 16:29:06 -0500 | [diff] [blame] | 1423 | .proto = proto, |
Benny Halevy | 5aae4a9 | 2009-04-01 09:21:50 -0400 | [diff] [blame] | 1424 | .minorversion = minorversion, |
Stanislav Kinsbursky | e50a7a1 | 2012-01-10 16:12:46 +0400 | [diff] [blame] | 1425 | .net = net, |
Trond Myklebust | 3a49802 | 2007-12-14 14:56:04 -0500 | [diff] [blame] | 1426 | }; |
David Howells | 54ceac4 | 2006-08-22 20:06:13 -0400 | [diff] [blame] | 1427 | struct nfs_client *clp; |
| 1428 | int error; |
| 1429 | |
| 1430 | dprintk("--> nfs4_set_client()\n"); |
| 1431 | |
| 1432 | /* Allocate or find a client reference we can use */ |
Andy Adamson | 45a52a0 | 2011-03-01 01:34:08 +0000 | [diff] [blame] | 1433 | clp = nfs_get_client(&cl_init, timeparms, ip_addr, authflavour, |
| 1434 | server->flags & NFS_MOUNT_NORESVPORT); |
David Howells | 54ceac4 | 2006-08-22 20:06:13 -0400 | [diff] [blame] | 1435 | if (IS_ERR(clp)) { |
| 1436 | error = PTR_ERR(clp); |
| 1437 | goto error; |
| 1438 | } |
David Howells | 54ceac4 | 2006-08-22 20:06:13 -0400 | [diff] [blame] | 1439 | |
Andy Adamson | d6fb79d | 2011-03-01 01:34:11 +0000 | [diff] [blame] | 1440 | /* |
| 1441 | * Query for the lease time on clientid setup or renewal |
| 1442 | * |
| 1443 | * Note that this will be set on nfs_clients that were created |
| 1444 | * only for the DS role and did not set this bit, but now will |
| 1445 | * serve a dual role. |
| 1446 | */ |
| 1447 | set_bit(NFS_CS_CHECK_LEASE_TIME, &clp->cl_res_state); |
| 1448 | |
David Howells | 54ceac4 | 2006-08-22 20:06:13 -0400 | [diff] [blame] | 1449 | server->nfs_client = clp; |
| 1450 | dprintk("<-- nfs4_set_client() = 0 [new %p]\n", clp); |
| 1451 | return 0; |
David Howells | 54ceac4 | 2006-08-22 20:06:13 -0400 | [diff] [blame] | 1452 | error: |
| 1453 | dprintk("<-- nfs4_set_client() = xerror %d\n", error); |
| 1454 | return error; |
| 1455 | } |
| 1456 | |
Andy Adamson | d83217c | 2011-03-01 01:34:17 +0000 | [diff] [blame] | 1457 | /* |
| 1458 | * Set up a pNFS Data Server client. |
| 1459 | * |
| 1460 | * Return any existing nfs_client that matches server address,port,version |
| 1461 | * and minorversion. |
| 1462 | * |
| 1463 | * For a new nfs_client, use a soft mount (default), a low retrans and a |
| 1464 | * low timeout interval so that if a connection is lost, we retry through |
| 1465 | * the MDS. |
| 1466 | */ |
| 1467 | struct nfs_client *nfs4_set_ds_client(struct nfs_client* mds_clp, |
| 1468 | const struct sockaddr *ds_addr, |
| 1469 | int ds_addrlen, int ds_proto) |
| 1470 | { |
| 1471 | struct nfs_client_initdata cl_init = { |
| 1472 | .addr = ds_addr, |
| 1473 | .addrlen = ds_addrlen, |
| 1474 | .rpc_ops = &nfs_v4_clientops, |
| 1475 | .proto = ds_proto, |
| 1476 | .minorversion = mds_clp->cl_minorversion, |
Stanislav Kinsbursky | e50a7a1 | 2012-01-10 16:12:46 +0400 | [diff] [blame] | 1477 | .net = mds_clp->net, |
Andy Adamson | d83217c | 2011-03-01 01:34:17 +0000 | [diff] [blame] | 1478 | }; |
| 1479 | struct rpc_timeout ds_timeout = { |
| 1480 | .to_initval = 15 * HZ, |
| 1481 | .to_maxval = 15 * HZ, |
| 1482 | .to_retries = 1, |
| 1483 | .to_exponential = 1, |
| 1484 | }; |
| 1485 | struct nfs_client *clp; |
| 1486 | |
| 1487 | /* |
| 1488 | * Set an authflavor equual to the MDS value. Use the MDS nfs_client |
| 1489 | * cl_ipaddr so as to use the same EXCHANGE_ID co_ownerid as the MDS |
| 1490 | * (section 13.1 RFC 5661). |
| 1491 | */ |
| 1492 | clp = nfs_get_client(&cl_init, &ds_timeout, mds_clp->cl_ipaddr, |
| 1493 | mds_clp->cl_rpcclient->cl_auth->au_flavor, 0); |
| 1494 | |
| 1495 | dprintk("<-- %s %p\n", __func__, clp); |
| 1496 | return clp; |
| 1497 | } |
Trond Myklebust | 94b134a | 2011-07-13 19:26:49 -0400 | [diff] [blame] | 1498 | EXPORT_SYMBOL_GPL(nfs4_set_ds_client); |
Andy Adamson | 557134a | 2009-04-01 09:21:53 -0400 | [diff] [blame] | 1499 | |
| 1500 | /* |
Andy Adamson | 96b09e0 | 2009-04-01 09:22:33 -0400 | [diff] [blame] | 1501 | * Session has been established, and the client marked ready. |
| 1502 | * Set the mount rsize and wsize with negotiated fore channel |
| 1503 | * attributes which will be bound checked in nfs_server_set_fsinfo. |
| 1504 | */ |
| 1505 | static void nfs4_session_set_rwsize(struct nfs_server *server) |
| 1506 | { |
| 1507 | #ifdef CONFIG_NFS_V4_1 |
Alexandros Batsakis | 2449ea2 | 2009-12-05 13:36:55 -0500 | [diff] [blame] | 1508 | struct nfs4_session *sess; |
| 1509 | u32 server_resp_sz; |
| 1510 | u32 server_rqst_sz; |
| 1511 | |
Andy Adamson | 96b09e0 | 2009-04-01 09:22:33 -0400 | [diff] [blame] | 1512 | if (!nfs4_has_session(server->nfs_client)) |
| 1513 | return; |
Alexandros Batsakis | 2449ea2 | 2009-12-05 13:36:55 -0500 | [diff] [blame] | 1514 | sess = server->nfs_client->cl_session; |
| 1515 | server_resp_sz = sess->fc_attrs.max_resp_sz - nfs41_maxread_overhead; |
| 1516 | server_rqst_sz = sess->fc_attrs.max_rqst_sz - nfs41_maxwrite_overhead; |
| 1517 | |
| 1518 | if (server->rsize > server_resp_sz) |
| 1519 | server->rsize = server_resp_sz; |
| 1520 | if (server->wsize > server_rqst_sz) |
| 1521 | server->wsize = server_rqst_sz; |
Andy Adamson | 96b09e0 | 2009-04-01 09:22:33 -0400 | [diff] [blame] | 1522 | #endif /* CONFIG_NFS_V4_1 */ |
| 1523 | } |
| 1524 | |
Trond Myklebust | 44950b6 | 2010-06-17 11:45:12 -0400 | [diff] [blame] | 1525 | static int nfs4_server_common_setup(struct nfs_server *server, |
| 1526 | struct nfs_fh *mntfh) |
| 1527 | { |
| 1528 | struct nfs_fattr *fattr; |
| 1529 | int error; |
| 1530 | |
| 1531 | BUG_ON(!server->nfs_client); |
| 1532 | BUG_ON(!server->nfs_client->rpc_ops); |
| 1533 | BUG_ON(!server->nfs_client->rpc_ops->file_inode_ops); |
| 1534 | |
Andy Adamson | 94de8b2 | 2011-03-01 01:34:12 +0000 | [diff] [blame] | 1535 | /* data servers support only a subset of NFSv4.1 */ |
| 1536 | if (is_ds_only_client(server->nfs_client)) |
| 1537 | return -EPROTONOSUPPORT; |
| 1538 | |
Trond Myklebust | 44950b6 | 2010-06-17 11:45:12 -0400 | [diff] [blame] | 1539 | fattr = nfs_alloc_fattr(); |
| 1540 | if (fattr == NULL) |
| 1541 | return -ENOMEM; |
| 1542 | |
| 1543 | /* We must ensure the session is initialised first */ |
| 1544 | error = nfs4_init_session(server); |
| 1545 | if (error < 0) |
| 1546 | goto out; |
| 1547 | |
| 1548 | /* Probe the root fh to retrieve its FSID and filehandle */ |
| 1549 | error = nfs4_get_rootfh(server, mntfh); |
| 1550 | if (error < 0) |
| 1551 | goto out; |
| 1552 | |
| 1553 | dprintk("Server FSID: %llx:%llx\n", |
| 1554 | (unsigned long long) server->fsid.major, |
| 1555 | (unsigned long long) server->fsid.minor); |
| 1556 | dprintk("Mount FH: %d\n", mntfh->size); |
| 1557 | |
| 1558 | nfs4_session_set_rwsize(server); |
| 1559 | |
| 1560 | error = nfs_probe_fsinfo(server, mntfh, fattr); |
| 1561 | if (error < 0) |
| 1562 | goto out; |
| 1563 | |
| 1564 | if (server->namelen == 0 || server->namelen > NFS4_MAXNAMLEN) |
| 1565 | server->namelen = NFS4_MAXNAMLEN; |
| 1566 | |
Chuck Lever | fca5238 | 2010-12-24 01:32:32 +0000 | [diff] [blame] | 1567 | nfs_server_insert_lists(server); |
Trond Myklebust | 44950b6 | 2010-06-17 11:45:12 -0400 | [diff] [blame] | 1568 | server->mount_time = jiffies; |
Chuck Lever | 0aaaf5c | 2011-12-06 16:13:48 -0500 | [diff] [blame] | 1569 | server->destroy = nfs4_destroy_server; |
Trond Myklebust | 44950b6 | 2010-06-17 11:45:12 -0400 | [diff] [blame] | 1570 | out: |
| 1571 | nfs_free_fattr(fattr); |
| 1572 | return error; |
| 1573 | } |
| 1574 | |
Andy Adamson | 96b09e0 | 2009-04-01 09:22:33 -0400 | [diff] [blame] | 1575 | /* |
David Howells | 54ceac4 | 2006-08-22 20:06:13 -0400 | [diff] [blame] | 1576 | * Create a version 4 volume record |
| 1577 | */ |
| 1578 | static int nfs4_init_server(struct nfs_server *server, |
\"Talpey, Thomas\ | 91ea40b | 2007-09-10 13:44:33 -0400 | [diff] [blame] | 1579 | const struct nfs_parsed_mount_data *data) |
David Howells | 54ceac4 | 2006-08-22 20:06:13 -0400 | [diff] [blame] | 1580 | { |
Trond Myklebust | 3317023 | 2007-12-20 16:03:59 -0500 | [diff] [blame] | 1581 | struct rpc_timeout timeparms; |
David Howells | 54ceac4 | 2006-08-22 20:06:13 -0400 | [diff] [blame] | 1582 | int error; |
| 1583 | |
| 1584 | dprintk("--> nfs4_init_server()\n"); |
| 1585 | |
Trond Myklebust | 3317023 | 2007-12-20 16:03:59 -0500 | [diff] [blame] | 1586 | nfs_init_timeout_values(&timeparms, data->nfs_server.protocol, |
| 1587 | data->timeo, data->retrans); |
| 1588 | |
Chuck Lever | 542fcc3 | 2008-12-23 15:21:36 -0500 | [diff] [blame] | 1589 | /* Initialise the client representation from the mount data */ |
| 1590 | server->flags = data->flags; |
Bryan Schumaker | 82f2e54 | 2010-10-21 16:33:18 -0400 | [diff] [blame] | 1591 | server->caps |= NFS_CAP_ATOMIC_OPEN|NFS_CAP_CHANGE_ATTR|NFS_CAP_POSIX_LOCK; |
| 1592 | if (!(data->flags & NFS_MOUNT_NORDIRPLUS)) |
| 1593 | server->caps |= NFS_CAP_READDIRPLUS; |
David Howells | b797cac | 2009-04-03 16:42:48 +0100 | [diff] [blame] | 1594 | server->options = data->options; |
Chuck Lever | 542fcc3 | 2008-12-23 15:21:36 -0500 | [diff] [blame] | 1595 | |
Trond Myklebust | 3317023 | 2007-12-20 16:03:59 -0500 | [diff] [blame] | 1596 | /* Get a client record */ |
| 1597 | error = nfs4_set_client(server, |
| 1598 | data->nfs_server.hostname, |
| 1599 | (const struct sockaddr *)&data->nfs_server.address, |
| 1600 | data->nfs_server.addrlen, |
| 1601 | data->client_address, |
| 1602 | data->auth_flavors[0], |
| 1603 | data->nfs_server.protocol, |
Benny Halevy | 94a417f | 2009-04-01 09:21:49 -0400 | [diff] [blame] | 1604 | &timeparms, |
Stanislav Kinsbursky | e50a7a1 | 2012-01-10 16:12:46 +0400 | [diff] [blame] | 1605 | data->minorversion, |
| 1606 | data->net); |
Trond Myklebust | 3317023 | 2007-12-20 16:03:59 -0500 | [diff] [blame] | 1607 | if (error < 0) |
| 1608 | goto error; |
| 1609 | |
Trond Myklebust | b064eca2 | 2011-02-22 15:44:32 -0800 | [diff] [blame] | 1610 | /* |
| 1611 | * Don't use NFS uid/gid mapping if we're using AUTH_SYS or lower |
| 1612 | * authentication. |
| 1613 | */ |
| 1614 | if (nfs4_disable_idmapping && data->auth_flavors[0] == RPC_AUTH_UNIX) |
| 1615 | server->caps |= NFS_CAP_UIDGID_NOMAP; |
| 1616 | |
David Howells | 54ceac4 | 2006-08-22 20:06:13 -0400 | [diff] [blame] | 1617 | if (data->rsize) |
| 1618 | server->rsize = nfs_block_size(data->rsize, NULL); |
| 1619 | if (data->wsize) |
| 1620 | server->wsize = nfs_block_size(data->wsize, NULL); |
| 1621 | |
| 1622 | server->acregmin = data->acregmin * HZ; |
| 1623 | server->acregmax = data->acregmax * HZ; |
| 1624 | server->acdirmin = data->acdirmin * HZ; |
| 1625 | server->acdirmax = data->acdirmax * HZ; |
| 1626 | |
Chuck Lever | f22d6d7 | 2008-03-14 14:10:22 -0400 | [diff] [blame] | 1627 | server->port = data->nfs_server.port; |
| 1628 | |
Trond Myklebust | 3317023 | 2007-12-20 16:03:59 -0500 | [diff] [blame] | 1629 | error = nfs_init_server_rpcclient(server, &timeparms, data->auth_flavors[0]); |
David Howells | 54ceac4 | 2006-08-22 20:06:13 -0400 | [diff] [blame] | 1630 | |
Trond Myklebust | 3317023 | 2007-12-20 16:03:59 -0500 | [diff] [blame] | 1631 | error: |
David Howells | 54ceac4 | 2006-08-22 20:06:13 -0400 | [diff] [blame] | 1632 | /* Done */ |
| 1633 | dprintk("<-- nfs4_init_server() = %d\n", error); |
| 1634 | return error; |
| 1635 | } |
| 1636 | |
| 1637 | /* |
| 1638 | * Create a version 4 volume record |
| 1639 | * - keyed on server and FSID |
| 1640 | */ |
\"Talpey, Thomas\ | 91ea40b | 2007-09-10 13:44:33 -0400 | [diff] [blame] | 1641 | struct nfs_server *nfs4_create_server(const struct nfs_parsed_mount_data *data, |
David Howells | 54ceac4 | 2006-08-22 20:06:13 -0400 | [diff] [blame] | 1642 | struct nfs_fh *mntfh) |
| 1643 | { |
David Howells | 54ceac4 | 2006-08-22 20:06:13 -0400 | [diff] [blame] | 1644 | struct nfs_server *server; |
| 1645 | int error; |
| 1646 | |
| 1647 | dprintk("--> nfs4_create_server()\n"); |
| 1648 | |
| 1649 | server = nfs_alloc_server(); |
| 1650 | if (!server) |
| 1651 | return ERR_PTR(-ENOMEM); |
| 1652 | |
David Howells | 54ceac4 | 2006-08-22 20:06:13 -0400 | [diff] [blame] | 1653 | /* set up the general RPC client */ |
\"Talpey, Thomas\ | 91ea40b | 2007-09-10 13:44:33 -0400 | [diff] [blame] | 1654 | error = nfs4_init_server(server, data); |
David Howells | 54ceac4 | 2006-08-22 20:06:13 -0400 | [diff] [blame] | 1655 | if (error < 0) |
| 1656 | goto error; |
| 1657 | |
Trond Myklebust | 44950b6 | 2010-06-17 11:45:12 -0400 | [diff] [blame] | 1658 | error = nfs4_server_common_setup(server, mntfh); |
Trond Myklebust | fccba80 | 2009-07-21 16:48:07 -0400 | [diff] [blame] | 1659 | if (error < 0) |
| 1660 | goto error; |
Andy Adamson | 557134a | 2009-04-01 09:21:53 -0400 | [diff] [blame] | 1661 | |
David Howells | 54ceac4 | 2006-08-22 20:06:13 -0400 | [diff] [blame] | 1662 | dprintk("<-- nfs4_create_server() = %p\n", server); |
| 1663 | return server; |
| 1664 | |
| 1665 | error: |
| 1666 | nfs_free_server(server); |
| 1667 | dprintk("<-- nfs4_create_server() = error %d\n", error); |
| 1668 | return ERR_PTR(error); |
| 1669 | } |
| 1670 | |
| 1671 | /* |
| 1672 | * Create an NFS4 referral server record |
| 1673 | */ |
| 1674 | struct nfs_server *nfs4_create_referral_server(struct nfs_clone_mount *data, |
Trond Myklebust | f2d0d85 | 2007-02-02 14:46:09 -0800 | [diff] [blame] | 1675 | struct nfs_fh *mntfh) |
David Howells | 54ceac4 | 2006-08-22 20:06:13 -0400 | [diff] [blame] | 1676 | { |
| 1677 | struct nfs_client *parent_client; |
| 1678 | struct nfs_server *server, *parent_server; |
David Howells | 54ceac4 | 2006-08-22 20:06:13 -0400 | [diff] [blame] | 1679 | int error; |
| 1680 | |
| 1681 | dprintk("--> nfs4_create_referral_server()\n"); |
| 1682 | |
| 1683 | server = nfs_alloc_server(); |
| 1684 | if (!server) |
| 1685 | return ERR_PTR(-ENOMEM); |
| 1686 | |
| 1687 | parent_server = NFS_SB(data->sb); |
| 1688 | parent_client = parent_server->nfs_client; |
| 1689 | |
Chuck Lever | 542fcc3 | 2008-12-23 15:21:36 -0500 | [diff] [blame] | 1690 | /* Initialise the client representation from the parent server */ |
| 1691 | nfs_server_copy_userdata(server, parent_server); |
Trond Myklebust | 62ab460c | 2009-08-09 15:06:19 -0400 | [diff] [blame] | 1692 | server->caps |= NFS_CAP_ATOMIC_OPEN|NFS_CAP_CHANGE_ATTR; |
Chuck Lever | 542fcc3 | 2008-12-23 15:21:36 -0500 | [diff] [blame] | 1693 | |
David Howells | 54ceac4 | 2006-08-22 20:06:13 -0400 | [diff] [blame] | 1694 | /* Get a client representation. |
| 1695 | * Note: NFSv4 always uses TCP, */ |
Chuck Lever | dcecae0 | 2007-12-10 14:58:59 -0500 | [diff] [blame] | 1696 | error = nfs4_set_client(server, data->hostname, |
Chuck Lever | 6677d09 | 2007-12-10 14:59:06 -0500 | [diff] [blame] | 1697 | data->addr, |
| 1698 | data->addrlen, |
Chuck Lever | dcecae0 | 2007-12-10 14:58:59 -0500 | [diff] [blame] | 1699 | parent_client->cl_ipaddr, |
| 1700 | data->authflavor, |
Trond Myklebust | 2446ab6 | 2012-03-01 17:00:56 -0500 | [diff] [blame] | 1701 | rpc_protocol(parent_server->client), |
Benny Halevy | 94a417f | 2009-04-01 09:21:49 -0400 | [diff] [blame] | 1702 | parent_server->client->cl_timeout, |
Stanislav Kinsbursky | e50a7a1 | 2012-01-10 16:12:46 +0400 | [diff] [blame] | 1703 | parent_client->cl_mvops->minor_version, |
| 1704 | parent_client->net); |
andros@citi.umich.edu | 297de4f | 2006-08-29 12:19:41 -0400 | [diff] [blame] | 1705 | if (error < 0) |
| 1706 | goto error; |
David Howells | 54ceac4 | 2006-08-22 20:06:13 -0400 | [diff] [blame] | 1707 | |
Trond Myklebust | 3317023 | 2007-12-20 16:03:59 -0500 | [diff] [blame] | 1708 | error = nfs_init_server_rpcclient(server, parent_server->client->cl_timeout, data->authflavor); |
David Howells | 54ceac4 | 2006-08-22 20:06:13 -0400 | [diff] [blame] | 1709 | if (error < 0) |
| 1710 | goto error; |
| 1711 | |
Trond Myklebust | 44950b6 | 2010-06-17 11:45:12 -0400 | [diff] [blame] | 1712 | error = nfs4_server_common_setup(server, mntfh); |
Trond Myklebust | f2d0d85 | 2007-02-02 14:46:09 -0800 | [diff] [blame] | 1713 | if (error < 0) |
| 1714 | goto error; |
| 1715 | |
David Howells | 54ceac4 | 2006-08-22 20:06:13 -0400 | [diff] [blame] | 1716 | dprintk("<-- nfs_create_referral_server() = %p\n", server); |
| 1717 | return server; |
| 1718 | |
| 1719 | error: |
| 1720 | nfs_free_server(server); |
| 1721 | dprintk("<-- nfs4_create_referral_server() = error %d\n", error); |
| 1722 | return ERR_PTR(error); |
| 1723 | } |
| 1724 | |
| 1725 | #endif /* CONFIG_NFS_V4 */ |
| 1726 | |
| 1727 | /* |
| 1728 | * Clone an NFS2, NFS3 or NFS4 server record |
| 1729 | */ |
| 1730 | struct nfs_server *nfs_clone_server(struct nfs_server *source, |
| 1731 | struct nfs_fh *fh, |
Bryan Schumaker | 7e6eb68 | 2012-04-27 13:27:42 -0400 | [diff] [blame] | 1732 | struct nfs_fattr *fattr, |
| 1733 | rpc_authflavor_t flavor) |
David Howells | 54ceac4 | 2006-08-22 20:06:13 -0400 | [diff] [blame] | 1734 | { |
| 1735 | struct nfs_server *server; |
Trond Myklebust | fbca779 | 2010-04-16 16:22:46 -0400 | [diff] [blame] | 1736 | struct nfs_fattr *fattr_fsinfo; |
David Howells | 54ceac4 | 2006-08-22 20:06:13 -0400 | [diff] [blame] | 1737 | int error; |
| 1738 | |
| 1739 | dprintk("--> nfs_clone_server(,%llx:%llx,)\n", |
David Howells | 6daabf1 | 2006-08-24 15:44:16 -0400 | [diff] [blame] | 1740 | (unsigned long long) fattr->fsid.major, |
| 1741 | (unsigned long long) fattr->fsid.minor); |
David Howells | 54ceac4 | 2006-08-22 20:06:13 -0400 | [diff] [blame] | 1742 | |
| 1743 | server = nfs_alloc_server(); |
| 1744 | if (!server) |
| 1745 | return ERR_PTR(-ENOMEM); |
| 1746 | |
Trond Myklebust | fbca779 | 2010-04-16 16:22:46 -0400 | [diff] [blame] | 1747 | error = -ENOMEM; |
| 1748 | fattr_fsinfo = nfs_alloc_fattr(); |
| 1749 | if (fattr_fsinfo == NULL) |
| 1750 | goto out_free_server; |
| 1751 | |
David Howells | 54ceac4 | 2006-08-22 20:06:13 -0400 | [diff] [blame] | 1752 | /* Copy data from the source */ |
| 1753 | server->nfs_client = source->nfs_client; |
Chuck Lever | 0aaaf5c | 2011-12-06 16:13:48 -0500 | [diff] [blame] | 1754 | server->destroy = source->destroy; |
David Howells | 54ceac4 | 2006-08-22 20:06:13 -0400 | [diff] [blame] | 1755 | atomic_inc(&server->nfs_client->cl_count); |
| 1756 | nfs_server_copy_userdata(server, source); |
| 1757 | |
| 1758 | server->fsid = fattr->fsid; |
| 1759 | |
Trond Myklebust | 3317023 | 2007-12-20 16:03:59 -0500 | [diff] [blame] | 1760 | error = nfs_init_server_rpcclient(server, |
| 1761 | source->client->cl_timeout, |
Bryan Schumaker | 7e6eb68 | 2012-04-27 13:27:42 -0400 | [diff] [blame] | 1762 | flavor); |
David Howells | 54ceac4 | 2006-08-22 20:06:13 -0400 | [diff] [blame] | 1763 | if (error < 0) |
| 1764 | goto out_free_server; |
| 1765 | if (!IS_ERR(source->client_acl)) |
| 1766 | nfs_init_server_aclclient(server); |
| 1767 | |
| 1768 | /* probe the filesystem info for this server filesystem */ |
Trond Myklebust | fbca779 | 2010-04-16 16:22:46 -0400 | [diff] [blame] | 1769 | error = nfs_probe_fsinfo(server, fh, fattr_fsinfo); |
David Howells | 54ceac4 | 2006-08-22 20:06:13 -0400 | [diff] [blame] | 1770 | if (error < 0) |
| 1771 | goto out_free_server; |
| 1772 | |
Trond Myklebust | 54af3bb | 2007-09-28 12:27:41 -0400 | [diff] [blame] | 1773 | if (server->namelen == 0 || server->namelen > NFS4_MAXNAMLEN) |
| 1774 | server->namelen = NFS4_MAXNAMLEN; |
| 1775 | |
David Howells | 54ceac4 | 2006-08-22 20:06:13 -0400 | [diff] [blame] | 1776 | dprintk("Cloned FSID: %llx:%llx\n", |
David Howells | 6daabf1 | 2006-08-24 15:44:16 -0400 | [diff] [blame] | 1777 | (unsigned long long) server->fsid.major, |
| 1778 | (unsigned long long) server->fsid.minor); |
David Howells | 54ceac4 | 2006-08-22 20:06:13 -0400 | [diff] [blame] | 1779 | |
| 1780 | error = nfs_start_lockd(server); |
| 1781 | if (error < 0) |
| 1782 | goto out_free_server; |
| 1783 | |
Chuck Lever | fca5238 | 2010-12-24 01:32:32 +0000 | [diff] [blame] | 1784 | nfs_server_insert_lists(server); |
David Howells | 54ceac4 | 2006-08-22 20:06:13 -0400 | [diff] [blame] | 1785 | server->mount_time = jiffies; |
| 1786 | |
Trond Myklebust | fbca779 | 2010-04-16 16:22:46 -0400 | [diff] [blame] | 1787 | nfs_free_fattr(fattr_fsinfo); |
David Howells | 54ceac4 | 2006-08-22 20:06:13 -0400 | [diff] [blame] | 1788 | dprintk("<-- nfs_clone_server() = %p\n", server); |
| 1789 | return server; |
| 1790 | |
| 1791 | out_free_server: |
Trond Myklebust | fbca779 | 2010-04-16 16:22:46 -0400 | [diff] [blame] | 1792 | nfs_free_fattr(fattr_fsinfo); |
David Howells | 54ceac4 | 2006-08-22 20:06:13 -0400 | [diff] [blame] | 1793 | nfs_free_server(server); |
| 1794 | dprintk("<-- nfs_clone_server() = error %d\n", error); |
| 1795 | return ERR_PTR(error); |
| 1796 | } |
David Howells | 6aaca56 | 2006-08-22 20:06:13 -0400 | [diff] [blame] | 1797 | |
Stanislav Kinsbursky | 6b13168 | 2012-01-23 17:26:05 +0000 | [diff] [blame] | 1798 | void nfs_clients_init(struct net *net) |
| 1799 | { |
| 1800 | struct nfs_net *nn = net_generic(net, nfs_net_id); |
| 1801 | |
| 1802 | INIT_LIST_HEAD(&nn->nfs_client_list); |
Stanislav Kinsbursky | c25d32b | 2012-01-23 17:26:14 +0000 | [diff] [blame] | 1803 | INIT_LIST_HEAD(&nn->nfs_volume_list); |
Stanislav Kinsbursky | 28cd1b3 | 2012-01-23 17:26:22 +0000 | [diff] [blame] | 1804 | #ifdef CONFIG_NFS_V4 |
| 1805 | idr_init(&nn->cb_ident_idr); |
| 1806 | #endif |
Trond Myklebust | 4c03ae4 | 2012-02-07 00:05:11 -0500 | [diff] [blame] | 1807 | spin_lock_init(&nn->nfs_client_lock); |
Stanislav Kinsbursky | 6b13168 | 2012-01-23 17:26:05 +0000 | [diff] [blame] | 1808 | } |
| 1809 | |
David Howells | 6aaca56 | 2006-08-22 20:06:13 -0400 | [diff] [blame] | 1810 | #ifdef CONFIG_PROC_FS |
| 1811 | static struct proc_dir_entry *proc_fs_nfs; |
| 1812 | |
| 1813 | static int nfs_server_list_open(struct inode *inode, struct file *file); |
| 1814 | static void *nfs_server_list_start(struct seq_file *p, loff_t *pos); |
| 1815 | static void *nfs_server_list_next(struct seq_file *p, void *v, loff_t *pos); |
| 1816 | static void nfs_server_list_stop(struct seq_file *p, void *v); |
| 1817 | static int nfs_server_list_show(struct seq_file *m, void *v); |
| 1818 | |
James Morris | 88e9d34 | 2009-09-22 16:43:43 -0700 | [diff] [blame] | 1819 | static const struct seq_operations nfs_server_list_ops = { |
David Howells | 6aaca56 | 2006-08-22 20:06:13 -0400 | [diff] [blame] | 1820 | .start = nfs_server_list_start, |
| 1821 | .next = nfs_server_list_next, |
| 1822 | .stop = nfs_server_list_stop, |
| 1823 | .show = nfs_server_list_show, |
| 1824 | }; |
| 1825 | |
Arjan van de Ven | 00977a5 | 2007-02-12 00:55:34 -0800 | [diff] [blame] | 1826 | static const struct file_operations nfs_server_list_fops = { |
David Howells | 6aaca56 | 2006-08-22 20:06:13 -0400 | [diff] [blame] | 1827 | .open = nfs_server_list_open, |
| 1828 | .read = seq_read, |
| 1829 | .llseek = seq_lseek, |
| 1830 | .release = seq_release, |
Denis V. Lunev | 34b3723 | 2008-04-29 01:02:07 -0700 | [diff] [blame] | 1831 | .owner = THIS_MODULE, |
David Howells | 6aaca56 | 2006-08-22 20:06:13 -0400 | [diff] [blame] | 1832 | }; |
| 1833 | |
| 1834 | static int nfs_volume_list_open(struct inode *inode, struct file *file); |
| 1835 | static void *nfs_volume_list_start(struct seq_file *p, loff_t *pos); |
| 1836 | static void *nfs_volume_list_next(struct seq_file *p, void *v, loff_t *pos); |
| 1837 | static void nfs_volume_list_stop(struct seq_file *p, void *v); |
| 1838 | static int nfs_volume_list_show(struct seq_file *m, void *v); |
| 1839 | |
James Morris | 88e9d34 | 2009-09-22 16:43:43 -0700 | [diff] [blame] | 1840 | static const struct seq_operations nfs_volume_list_ops = { |
David Howells | 6aaca56 | 2006-08-22 20:06:13 -0400 | [diff] [blame] | 1841 | .start = nfs_volume_list_start, |
| 1842 | .next = nfs_volume_list_next, |
| 1843 | .stop = nfs_volume_list_stop, |
| 1844 | .show = nfs_volume_list_show, |
| 1845 | }; |
| 1846 | |
Arjan van de Ven | 00977a5 | 2007-02-12 00:55:34 -0800 | [diff] [blame] | 1847 | static const struct file_operations nfs_volume_list_fops = { |
David Howells | 6aaca56 | 2006-08-22 20:06:13 -0400 | [diff] [blame] | 1848 | .open = nfs_volume_list_open, |
| 1849 | .read = seq_read, |
| 1850 | .llseek = seq_lseek, |
| 1851 | .release = seq_release, |
Denis V. Lunev | 34b3723 | 2008-04-29 01:02:07 -0700 | [diff] [blame] | 1852 | .owner = THIS_MODULE, |
David Howells | 6aaca56 | 2006-08-22 20:06:13 -0400 | [diff] [blame] | 1853 | }; |
| 1854 | |
| 1855 | /* |
| 1856 | * open "/proc/fs/nfsfs/servers" which provides a summary of servers with which |
| 1857 | * we're dealing |
| 1858 | */ |
| 1859 | static int nfs_server_list_open(struct inode *inode, struct file *file) |
| 1860 | { |
| 1861 | struct seq_file *m; |
| 1862 | int ret; |
Stanislav Kinsbursky | 6b13168 | 2012-01-23 17:26:05 +0000 | [diff] [blame] | 1863 | struct pid_namespace *pid_ns = file->f_dentry->d_sb->s_fs_info; |
| 1864 | struct net *net = pid_ns->child_reaper->nsproxy->net_ns; |
David Howells | 6aaca56 | 2006-08-22 20:06:13 -0400 | [diff] [blame] | 1865 | |
| 1866 | ret = seq_open(file, &nfs_server_list_ops); |
| 1867 | if (ret < 0) |
| 1868 | return ret; |
| 1869 | |
| 1870 | m = file->private_data; |
Stanislav Kinsbursky | 6b13168 | 2012-01-23 17:26:05 +0000 | [diff] [blame] | 1871 | m->private = net; |
David Howells | 6aaca56 | 2006-08-22 20:06:13 -0400 | [diff] [blame] | 1872 | |
| 1873 | return 0; |
| 1874 | } |
| 1875 | |
| 1876 | /* |
| 1877 | * set up the iterator to start reading from the server list and return the first item |
| 1878 | */ |
| 1879 | static void *nfs_server_list_start(struct seq_file *m, loff_t *_pos) |
| 1880 | { |
Stanislav Kinsbursky | 6b13168 | 2012-01-23 17:26:05 +0000 | [diff] [blame] | 1881 | struct nfs_net *nn = net_generic(m->private, nfs_net_id); |
| 1882 | |
David Howells | 6aaca56 | 2006-08-22 20:06:13 -0400 | [diff] [blame] | 1883 | /* lock the list against modification */ |
Stanislav Kinsbursky | dc03085 | 2012-01-23 17:26:31 +0000 | [diff] [blame] | 1884 | spin_lock(&nn->nfs_client_lock); |
Stanislav Kinsbursky | 6b13168 | 2012-01-23 17:26:05 +0000 | [diff] [blame] | 1885 | return seq_list_start_head(&nn->nfs_client_list, *_pos); |
David Howells | 6aaca56 | 2006-08-22 20:06:13 -0400 | [diff] [blame] | 1886 | } |
| 1887 | |
| 1888 | /* |
| 1889 | * move to next server |
| 1890 | */ |
| 1891 | static void *nfs_server_list_next(struct seq_file *p, void *v, loff_t *pos) |
| 1892 | { |
Stanislav Kinsbursky | 6b13168 | 2012-01-23 17:26:05 +0000 | [diff] [blame] | 1893 | struct nfs_net *nn = net_generic(p->private, nfs_net_id); |
| 1894 | |
| 1895 | return seq_list_next(v, &nn->nfs_client_list, pos); |
David Howells | 6aaca56 | 2006-08-22 20:06:13 -0400 | [diff] [blame] | 1896 | } |
| 1897 | |
| 1898 | /* |
| 1899 | * clean up after reading from the transports list |
| 1900 | */ |
| 1901 | static void nfs_server_list_stop(struct seq_file *p, void *v) |
| 1902 | { |
Stanislav Kinsbursky | dc03085 | 2012-01-23 17:26:31 +0000 | [diff] [blame] | 1903 | struct nfs_net *nn = net_generic(p->private, nfs_net_id); |
| 1904 | |
| 1905 | spin_unlock(&nn->nfs_client_lock); |
David Howells | 6aaca56 | 2006-08-22 20:06:13 -0400 | [diff] [blame] | 1906 | } |
| 1907 | |
| 1908 | /* |
| 1909 | * display a header line followed by a load of call lines |
| 1910 | */ |
| 1911 | static int nfs_server_list_show(struct seq_file *m, void *v) |
| 1912 | { |
| 1913 | struct nfs_client *clp; |
Stanislav Kinsbursky | 6b13168 | 2012-01-23 17:26:05 +0000 | [diff] [blame] | 1914 | struct nfs_net *nn = net_generic(m->private, nfs_net_id); |
David Howells | 6aaca56 | 2006-08-22 20:06:13 -0400 | [diff] [blame] | 1915 | |
| 1916 | /* display header on line 1 */ |
Stanislav Kinsbursky | 6b13168 | 2012-01-23 17:26:05 +0000 | [diff] [blame] | 1917 | if (v == &nn->nfs_client_list) { |
David Howells | 6aaca56 | 2006-08-22 20:06:13 -0400 | [diff] [blame] | 1918 | seq_puts(m, "NV SERVER PORT USE HOSTNAME\n"); |
| 1919 | return 0; |
| 1920 | } |
| 1921 | |
| 1922 | /* display one transport per line on subsequent lines */ |
| 1923 | clp = list_entry(v, struct nfs_client, cl_share_link); |
| 1924 | |
Malahal Naineni | 940aab4 | 2011-09-20 17:27:14 -0700 | [diff] [blame] | 1925 | /* Check if the client is initialized */ |
| 1926 | if (clp->cl_cons_state != NFS_CS_READY) |
| 1927 | return 0; |
| 1928 | |
Trond Myklebust | 2446ab6 | 2012-03-01 17:00:56 -0500 | [diff] [blame] | 1929 | rcu_read_lock(); |
Chuck Lever | 5d8515c | 2007-12-10 14:57:16 -0500 | [diff] [blame] | 1930 | seq_printf(m, "v%u %s %s %3d %s\n", |
Trond Myklebust | 40c55319 | 2007-12-14 14:56:07 -0500 | [diff] [blame] | 1931 | clp->rpc_ops->version, |
Chuck Lever | 5d8515c | 2007-12-10 14:57:16 -0500 | [diff] [blame] | 1932 | rpc_peeraddr2str(clp->cl_rpcclient, RPC_DISPLAY_HEX_ADDR), |
| 1933 | rpc_peeraddr2str(clp->cl_rpcclient, RPC_DISPLAY_HEX_PORT), |
David Howells | 6aaca56 | 2006-08-22 20:06:13 -0400 | [diff] [blame] | 1934 | atomic_read(&clp->cl_count), |
| 1935 | clp->cl_hostname); |
Trond Myklebust | 2446ab6 | 2012-03-01 17:00:56 -0500 | [diff] [blame] | 1936 | rcu_read_unlock(); |
David Howells | 6aaca56 | 2006-08-22 20:06:13 -0400 | [diff] [blame] | 1937 | |
| 1938 | return 0; |
| 1939 | } |
| 1940 | |
| 1941 | /* |
| 1942 | * open "/proc/fs/nfsfs/volumes" which provides a summary of extant volumes |
| 1943 | */ |
| 1944 | static int nfs_volume_list_open(struct inode *inode, struct file *file) |
| 1945 | { |
| 1946 | struct seq_file *m; |
| 1947 | int ret; |
Stanislav Kinsbursky | c25d32b | 2012-01-23 17:26:14 +0000 | [diff] [blame] | 1948 | struct pid_namespace *pid_ns = file->f_dentry->d_sb->s_fs_info; |
| 1949 | struct net *net = pid_ns->child_reaper->nsproxy->net_ns; |
David Howells | 6aaca56 | 2006-08-22 20:06:13 -0400 | [diff] [blame] | 1950 | |
| 1951 | ret = seq_open(file, &nfs_volume_list_ops); |
| 1952 | if (ret < 0) |
| 1953 | return ret; |
| 1954 | |
| 1955 | m = file->private_data; |
Stanislav Kinsbursky | c25d32b | 2012-01-23 17:26:14 +0000 | [diff] [blame] | 1956 | m->private = net; |
David Howells | 6aaca56 | 2006-08-22 20:06:13 -0400 | [diff] [blame] | 1957 | |
| 1958 | return 0; |
| 1959 | } |
| 1960 | |
| 1961 | /* |
| 1962 | * set up the iterator to start reading from the volume list and return the first item |
| 1963 | */ |
| 1964 | static void *nfs_volume_list_start(struct seq_file *m, loff_t *_pos) |
| 1965 | { |
Stanislav Kinsbursky | c25d32b | 2012-01-23 17:26:14 +0000 | [diff] [blame] | 1966 | struct nfs_net *nn = net_generic(m->private, nfs_net_id); |
| 1967 | |
David Howells | 6aaca56 | 2006-08-22 20:06:13 -0400 | [diff] [blame] | 1968 | /* lock the list against modification */ |
Stanislav Kinsbursky | dc03085 | 2012-01-23 17:26:31 +0000 | [diff] [blame] | 1969 | spin_lock(&nn->nfs_client_lock); |
Stanislav Kinsbursky | c25d32b | 2012-01-23 17:26:14 +0000 | [diff] [blame] | 1970 | return seq_list_start_head(&nn->nfs_volume_list, *_pos); |
David Howells | 6aaca56 | 2006-08-22 20:06:13 -0400 | [diff] [blame] | 1971 | } |
| 1972 | |
| 1973 | /* |
| 1974 | * move to next volume |
| 1975 | */ |
| 1976 | static void *nfs_volume_list_next(struct seq_file *p, void *v, loff_t *pos) |
| 1977 | { |
Stanislav Kinsbursky | c25d32b | 2012-01-23 17:26:14 +0000 | [diff] [blame] | 1978 | struct nfs_net *nn = net_generic(p->private, nfs_net_id); |
| 1979 | |
| 1980 | return seq_list_next(v, &nn->nfs_volume_list, pos); |
David Howells | 6aaca56 | 2006-08-22 20:06:13 -0400 | [diff] [blame] | 1981 | } |
| 1982 | |
| 1983 | /* |
| 1984 | * clean up after reading from the transports list |
| 1985 | */ |
| 1986 | static void nfs_volume_list_stop(struct seq_file *p, void *v) |
| 1987 | { |
Stanislav Kinsbursky | dc03085 | 2012-01-23 17:26:31 +0000 | [diff] [blame] | 1988 | struct nfs_net *nn = net_generic(p->private, nfs_net_id); |
| 1989 | |
| 1990 | spin_unlock(&nn->nfs_client_lock); |
David Howells | 6aaca56 | 2006-08-22 20:06:13 -0400 | [diff] [blame] | 1991 | } |
| 1992 | |
| 1993 | /* |
| 1994 | * display a header line followed by a load of call lines |
| 1995 | */ |
| 1996 | static int nfs_volume_list_show(struct seq_file *m, void *v) |
| 1997 | { |
| 1998 | struct nfs_server *server; |
| 1999 | struct nfs_client *clp; |
| 2000 | char dev[8], fsid[17]; |
Stanislav Kinsbursky | c25d32b | 2012-01-23 17:26:14 +0000 | [diff] [blame] | 2001 | struct nfs_net *nn = net_generic(m->private, nfs_net_id); |
David Howells | 6aaca56 | 2006-08-22 20:06:13 -0400 | [diff] [blame] | 2002 | |
| 2003 | /* display header on line 1 */ |
Stanislav Kinsbursky | c25d32b | 2012-01-23 17:26:14 +0000 | [diff] [blame] | 2004 | if (v == &nn->nfs_volume_list) { |
David Howells | 5d1acff | 2009-04-03 16:42:47 +0100 | [diff] [blame] | 2005 | seq_puts(m, "NV SERVER PORT DEV FSID FSC\n"); |
David Howells | 6aaca56 | 2006-08-22 20:06:13 -0400 | [diff] [blame] | 2006 | return 0; |
| 2007 | } |
| 2008 | /* display one transport per line on subsequent lines */ |
| 2009 | server = list_entry(v, struct nfs_server, master_link); |
| 2010 | clp = server->nfs_client; |
| 2011 | |
| 2012 | snprintf(dev, 8, "%u:%u", |
| 2013 | MAJOR(server->s_dev), MINOR(server->s_dev)); |
| 2014 | |
| 2015 | snprintf(fsid, 17, "%llx:%llx", |
David Howells | 6daabf1 | 2006-08-24 15:44:16 -0400 | [diff] [blame] | 2016 | (unsigned long long) server->fsid.major, |
| 2017 | (unsigned long long) server->fsid.minor); |
David Howells | 6aaca56 | 2006-08-22 20:06:13 -0400 | [diff] [blame] | 2018 | |
Trond Myklebust | 2446ab6 | 2012-03-01 17:00:56 -0500 | [diff] [blame] | 2019 | rcu_read_lock(); |
David Howells | 5d1acff | 2009-04-03 16:42:47 +0100 | [diff] [blame] | 2020 | seq_printf(m, "v%u %s %s %-7s %-17s %s\n", |
Trond Myklebust | 40c55319 | 2007-12-14 14:56:07 -0500 | [diff] [blame] | 2021 | clp->rpc_ops->version, |
Chuck Lever | 5d8515c | 2007-12-10 14:57:16 -0500 | [diff] [blame] | 2022 | rpc_peeraddr2str(clp->cl_rpcclient, RPC_DISPLAY_HEX_ADDR), |
| 2023 | rpc_peeraddr2str(clp->cl_rpcclient, RPC_DISPLAY_HEX_PORT), |
David Howells | 6aaca56 | 2006-08-22 20:06:13 -0400 | [diff] [blame] | 2024 | dev, |
David Howells | 5d1acff | 2009-04-03 16:42:47 +0100 | [diff] [blame] | 2025 | fsid, |
| 2026 | nfs_server_fscache_state(server)); |
Trond Myklebust | 2446ab6 | 2012-03-01 17:00:56 -0500 | [diff] [blame] | 2027 | rcu_read_unlock(); |
David Howells | 6aaca56 | 2006-08-22 20:06:13 -0400 | [diff] [blame] | 2028 | |
| 2029 | return 0; |
| 2030 | } |
| 2031 | |
| 2032 | /* |
| 2033 | * initialise the /proc/fs/nfsfs/ directory |
| 2034 | */ |
| 2035 | int __init nfs_fs_proc_init(void) |
| 2036 | { |
| 2037 | struct proc_dir_entry *p; |
| 2038 | |
Alexey Dobriyan | 36a5aeb | 2008-04-29 01:01:42 -0700 | [diff] [blame] | 2039 | proc_fs_nfs = proc_mkdir("fs/nfsfs", NULL); |
David Howells | 6aaca56 | 2006-08-22 20:06:13 -0400 | [diff] [blame] | 2040 | if (!proc_fs_nfs) |
| 2041 | goto error_0; |
| 2042 | |
David Howells | 6aaca56 | 2006-08-22 20:06:13 -0400 | [diff] [blame] | 2043 | /* a file of servers with which we're dealing */ |
Denis V. Lunev | 34b3723 | 2008-04-29 01:02:07 -0700 | [diff] [blame] | 2044 | p = proc_create("servers", S_IFREG|S_IRUGO, |
| 2045 | proc_fs_nfs, &nfs_server_list_fops); |
David Howells | 6aaca56 | 2006-08-22 20:06:13 -0400 | [diff] [blame] | 2046 | if (!p) |
| 2047 | goto error_1; |
| 2048 | |
David Howells | 6aaca56 | 2006-08-22 20:06:13 -0400 | [diff] [blame] | 2049 | /* a file of volumes that we have mounted */ |
Denis V. Lunev | 34b3723 | 2008-04-29 01:02:07 -0700 | [diff] [blame] | 2050 | p = proc_create("volumes", S_IFREG|S_IRUGO, |
| 2051 | proc_fs_nfs, &nfs_volume_list_fops); |
David Howells | 6aaca56 | 2006-08-22 20:06:13 -0400 | [diff] [blame] | 2052 | if (!p) |
| 2053 | goto error_2; |
David Howells | 6aaca56 | 2006-08-22 20:06:13 -0400 | [diff] [blame] | 2054 | return 0; |
| 2055 | |
| 2056 | error_2: |
| 2057 | remove_proc_entry("servers", proc_fs_nfs); |
| 2058 | error_1: |
Alexey Dobriyan | 36a5aeb | 2008-04-29 01:01:42 -0700 | [diff] [blame] | 2059 | remove_proc_entry("fs/nfsfs", NULL); |
David Howells | 6aaca56 | 2006-08-22 20:06:13 -0400 | [diff] [blame] | 2060 | error_0: |
| 2061 | return -ENOMEM; |
| 2062 | } |
| 2063 | |
| 2064 | /* |
| 2065 | * clean up the /proc/fs/nfsfs/ directory |
| 2066 | */ |
| 2067 | void nfs_fs_proc_exit(void) |
| 2068 | { |
| 2069 | remove_proc_entry("volumes", proc_fs_nfs); |
| 2070 | remove_proc_entry("servers", proc_fs_nfs); |
Alexey Dobriyan | 36a5aeb | 2008-04-29 01:01:42 -0700 | [diff] [blame] | 2071 | remove_proc_entry("fs/nfsfs", NULL); |
David Howells | 6aaca56 | 2006-08-22 20:06:13 -0400 | [diff] [blame] | 2072 | } |
| 2073 | |
| 2074 | #endif /* CONFIG_PROC_FS */ |
Trond Myklebust | b064eca2 | 2011-02-22 15:44:32 -0800 | [diff] [blame] | 2075 | |
| 2076 | module_param(nfs4_disable_idmapping, bool, 0644); |
| 2077 | MODULE_PARM_DESC(nfs4_disable_idmapping, |
| 2078 | "Turn off NFSv4 idmapping when using 'sec=sys'"); |