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