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