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