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