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