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