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