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 | */ |
Andy Adamson | 45a52a0 | 2011-03-01 01:34:08 +0000 | [diff] [blame] | 484 | static struct nfs_client * |
| 485 | nfs_get_client(const struct nfs_client_initdata *cl_init, |
| 486 | const struct rpc_timeout *timeparms, |
| 487 | const char *ip_addr, |
| 488 | rpc_authflavor_t authflavour, |
| 489 | int noresvport) |
David Howells | 24c8dbb | 2006-08-22 20:06:10 -0400 | [diff] [blame] | 490 | { |
| 491 | struct nfs_client *clp, *new = NULL; |
| 492 | int error; |
| 493 | |
Chuck Lever | d7422c4 | 2007-12-10 14:58:51 -0500 | [diff] [blame] | 494 | dprintk("--> nfs_get_client(%s,v%u)\n", |
| 495 | cl_init->hostname ?: "", cl_init->rpc_ops->version); |
David Howells | 24c8dbb | 2006-08-22 20:06:10 -0400 | [diff] [blame] | 496 | |
| 497 | /* see if the client already exists */ |
| 498 | do { |
| 499 | spin_lock(&nfs_client_lock); |
| 500 | |
Trond Myklebust | c81468a | 2007-12-14 14:56:05 -0500 | [diff] [blame] | 501 | clp = nfs_match_client(cl_init); |
David Howells | 24c8dbb | 2006-08-22 20:06:10 -0400 | [diff] [blame] | 502 | if (clp) |
| 503 | goto found_client; |
| 504 | if (new) |
| 505 | goto install_client; |
| 506 | |
| 507 | spin_unlock(&nfs_client_lock); |
| 508 | |
Trond Myklebust | 3a49802 | 2007-12-14 14:56:04 -0500 | [diff] [blame] | 509 | new = nfs_alloc_client(cl_init); |
Chuck Lever | a21bdd9 | 2009-06-17 18:02:10 -0700 | [diff] [blame] | 510 | } while (!IS_ERR(new)); |
David Howells | 24c8dbb | 2006-08-22 20:06:10 -0400 | [diff] [blame] | 511 | |
Chuck Lever | a21bdd9 | 2009-06-17 18:02:10 -0700 | [diff] [blame] | 512 | dprintk("--> nfs_get_client() = %ld [failed]\n", PTR_ERR(new)); |
| 513 | return new; |
David Howells | 24c8dbb | 2006-08-22 20:06:10 -0400 | [diff] [blame] | 514 | |
| 515 | /* install a new client and return with it unready */ |
| 516 | install_client: |
| 517 | clp = new; |
| 518 | list_add(&clp->cl_share_link, &nfs_client_list); |
| 519 | spin_unlock(&nfs_client_lock); |
Andy Adamson | 45a52a0 | 2011-03-01 01:34:08 +0000 | [diff] [blame] | 520 | |
| 521 | error = cl_init->rpc_ops->init_client(clp, timeparms, ip_addr, |
| 522 | authflavour, noresvport); |
| 523 | if (error < 0) { |
| 524 | nfs_put_client(clp); |
| 525 | return ERR_PTR(error); |
| 526 | } |
David Howells | 24c8dbb | 2006-08-22 20:06:10 -0400 | [diff] [blame] | 527 | dprintk("--> nfs_get_client() = %p [new]\n", clp); |
| 528 | return clp; |
| 529 | |
| 530 | /* found an existing client |
| 531 | * - make sure it's ready before returning |
| 532 | */ |
| 533 | found_client: |
| 534 | spin_unlock(&nfs_client_lock); |
| 535 | |
| 536 | if (new) |
| 537 | nfs_free_client(new); |
| 538 | |
Matthew Wilcox | 150030b | 2007-12-06 16:24:39 -0500 | [diff] [blame] | 539 | error = wait_event_killable(nfs_client_active_wq, |
Andy Adamson | 76db6d9 | 2009-04-01 09:22:38 -0400 | [diff] [blame] | 540 | clp->cl_cons_state < NFS_CS_INITING); |
Trond Myklebust | 0bae89e | 2006-10-08 14:33:24 -0400 | [diff] [blame] | 541 | if (error < 0) { |
| 542 | nfs_put_client(clp); |
| 543 | return ERR_PTR(-ERESTARTSYS); |
David Howells | 24c8dbb | 2006-08-22 20:06:10 -0400 | [diff] [blame] | 544 | } |
| 545 | |
| 546 | if (clp->cl_cons_state < NFS_CS_READY) { |
| 547 | error = clp->cl_cons_state; |
| 548 | nfs_put_client(clp); |
| 549 | return ERR_PTR(error); |
| 550 | } |
| 551 | |
David Howells | 54ceac4 | 2006-08-22 20:06:13 -0400 | [diff] [blame] | 552 | BUG_ON(clp->cl_cons_state != NFS_CS_READY); |
| 553 | |
David Howells | 24c8dbb | 2006-08-22 20:06:10 -0400 | [diff] [blame] | 554 | dprintk("--> nfs_get_client() = %p [share]\n", clp); |
| 555 | return clp; |
| 556 | } |
| 557 | |
| 558 | /* |
| 559 | * Mark a server as ready or failed |
| 560 | */ |
Andy Adamson | 76db6d9 | 2009-04-01 09:22:38 -0400 | [diff] [blame] | 561 | void nfs_mark_client_ready(struct nfs_client *clp, int state) |
David Howells | 24c8dbb | 2006-08-22 20:06:10 -0400 | [diff] [blame] | 562 | { |
| 563 | clp->cl_cons_state = state; |
| 564 | wake_up_all(&nfs_client_active_wq); |
| 565 | } |
David Howells | 5006a76 | 2006-08-22 20:06:12 -0400 | [diff] [blame] | 566 | |
| 567 | /* |
Benny Halevy | 008f55d | 2009-04-01 09:22:50 -0400 | [diff] [blame] | 568 | * With sessions, the client is not marked ready until after a |
| 569 | * successful EXCHANGE_ID and CREATE_SESSION. |
| 570 | * |
| 571 | * Map errors cl_cons_state errors to EPROTONOSUPPORT to indicate |
| 572 | * other versions of NFS can be tried. |
| 573 | */ |
| 574 | int nfs4_check_client_ready(struct nfs_client *clp) |
| 575 | { |
| 576 | if (!nfs4_has_session(clp)) |
| 577 | return 0; |
| 578 | if (clp->cl_cons_state < NFS_CS_READY) |
| 579 | return -EPROTONOSUPPORT; |
| 580 | return 0; |
| 581 | } |
| 582 | |
| 583 | /* |
David Howells | 5006a76 | 2006-08-22 20:06:12 -0400 | [diff] [blame] | 584 | * Initialise the timeout values for a connection |
| 585 | */ |
| 586 | static void nfs_init_timeout_values(struct rpc_timeout *to, int proto, |
| 587 | unsigned int timeo, unsigned int retrans) |
| 588 | { |
| 589 | to->to_initval = timeo * HZ / 10; |
| 590 | to->to_retries = retrans; |
David Howells | 5006a76 | 2006-08-22 20:06:12 -0400 | [diff] [blame] | 591 | |
| 592 | switch (proto) { |
\"Talpey, Thomas\ | 0896a72 | 2007-09-10 13:48:23 -0400 | [diff] [blame] | 593 | case XPRT_TRANSPORT_TCP: |
\"Talpey, Thomas\ | 2cf7ff7 | 2007-09-10 13:49:41 -0400 | [diff] [blame] | 594 | case XPRT_TRANSPORT_RDMA: |
Trond Myklebust | 259875e | 2008-07-02 14:43:47 -0400 | [diff] [blame] | 595 | if (to->to_retries == 0) |
| 596 | to->to_retries = NFS_DEF_TCP_RETRANS; |
Trond Myklebust | 7a3e3e1 | 2007-12-20 16:03:57 -0500 | [diff] [blame] | 597 | if (to->to_initval == 0) |
Trond Myklebust | 259875e | 2008-07-02 14:43:47 -0400 | [diff] [blame] | 598 | to->to_initval = NFS_DEF_TCP_TIMEO * HZ / 10; |
David Howells | 5006a76 | 2006-08-22 20:06:12 -0400 | [diff] [blame] | 599 | if (to->to_initval > NFS_MAX_TCP_TIMEOUT) |
| 600 | to->to_initval = NFS_MAX_TCP_TIMEOUT; |
| 601 | to->to_increment = to->to_initval; |
| 602 | to->to_maxval = to->to_initval + (to->to_increment * to->to_retries); |
Trond Myklebust | 7a3e3e1 | 2007-12-20 16:03:57 -0500 | [diff] [blame] | 603 | if (to->to_maxval > NFS_MAX_TCP_TIMEOUT) |
| 604 | to->to_maxval = NFS_MAX_TCP_TIMEOUT; |
| 605 | if (to->to_maxval < to->to_initval) |
| 606 | to->to_maxval = to->to_initval; |
David Howells | 5006a76 | 2006-08-22 20:06:12 -0400 | [diff] [blame] | 607 | to->to_exponential = 0; |
| 608 | break; |
\"Talpey, Thomas\ | 0896a72 | 2007-09-10 13:48:23 -0400 | [diff] [blame] | 609 | case XPRT_TRANSPORT_UDP: |
Trond Myklebust | 259875e | 2008-07-02 14:43:47 -0400 | [diff] [blame] | 610 | if (to->to_retries == 0) |
| 611 | to->to_retries = NFS_DEF_UDP_RETRANS; |
David Howells | 5006a76 | 2006-08-22 20:06:12 -0400 | [diff] [blame] | 612 | if (!to->to_initval) |
Trond Myklebust | 259875e | 2008-07-02 14:43:47 -0400 | [diff] [blame] | 613 | to->to_initval = NFS_DEF_UDP_TIMEO * HZ / 10; |
David Howells | 5006a76 | 2006-08-22 20:06:12 -0400 | [diff] [blame] | 614 | if (to->to_initval > NFS_MAX_UDP_TIMEOUT) |
| 615 | to->to_initval = NFS_MAX_UDP_TIMEOUT; |
| 616 | to->to_maxval = NFS_MAX_UDP_TIMEOUT; |
| 617 | to->to_exponential = 1; |
| 618 | break; |
Trond Myklebust | 259875e | 2008-07-02 14:43:47 -0400 | [diff] [blame] | 619 | default: |
| 620 | BUG(); |
David Howells | 5006a76 | 2006-08-22 20:06:12 -0400 | [diff] [blame] | 621 | } |
| 622 | } |
| 623 | |
| 624 | /* |
| 625 | * Create an RPC client handle |
| 626 | */ |
Trond Myklebust | 59dca3b | 2008-01-03 16:29:06 -0500 | [diff] [blame] | 627 | static int nfs_create_rpc_client(struct nfs_client *clp, |
Trond Myklebust | 3317023 | 2007-12-20 16:03:59 -0500 | [diff] [blame] | 628 | const struct rpc_timeout *timeparms, |
| 629 | rpc_authflavor_t flavor, |
Chuck Lever | 4a01b8a | 2008-12-23 15:21:35 -0500 | [diff] [blame] | 630 | int discrtry, int noresvport) |
David Howells | 5006a76 | 2006-08-22 20:06:12 -0400 | [diff] [blame] | 631 | { |
David Howells | 5006a76 | 2006-08-22 20:06:12 -0400 | [diff] [blame] | 632 | struct rpc_clnt *clnt = NULL; |
Chuck Lever | 41877d2 | 2006-08-22 20:06:20 -0400 | [diff] [blame] | 633 | struct rpc_create_args args = { |
Pavel Emelyanov | c653ce3 | 2010-09-29 16:04:45 +0400 | [diff] [blame] | 634 | .net = &init_net, |
Trond Myklebust | 59dca3b | 2008-01-03 16:29:06 -0500 | [diff] [blame] | 635 | .protocol = clp->cl_proto, |
Chuck Lever | 41877d2 | 2006-08-22 20:06:20 -0400 | [diff] [blame] | 636 | .address = (struct sockaddr *)&clp->cl_addr, |
Chuck Lever | 6e4cffd | 2007-12-10 14:58:15 -0500 | [diff] [blame] | 637 | .addrsize = clp->cl_addrlen, |
Trond Myklebust | 3317023 | 2007-12-20 16:03:59 -0500 | [diff] [blame] | 638 | .timeout = timeparms, |
Chuck Lever | 41877d2 | 2006-08-22 20:06:20 -0400 | [diff] [blame] | 639 | .servername = clp->cl_hostname, |
| 640 | .program = &nfs_program, |
| 641 | .version = clp->rpc_ops->version, |
| 642 | .authflavor = flavor, |
| 643 | }; |
David Howells | 5006a76 | 2006-08-22 20:06:12 -0400 | [diff] [blame] | 644 | |
Chuck Lever | 4a01b8a | 2008-12-23 15:21:35 -0500 | [diff] [blame] | 645 | if (discrtry) |
| 646 | args.flags |= RPC_CLNT_CREATE_DISCRTRY; |
| 647 | if (noresvport) |
| 648 | args.flags |= RPC_CLNT_CREATE_NONPRIVPORT; |
| 649 | |
David Howells | 5006a76 | 2006-08-22 20:06:12 -0400 | [diff] [blame] | 650 | if (!IS_ERR(clp->cl_rpcclient)) |
| 651 | return 0; |
| 652 | |
Chuck Lever | 41877d2 | 2006-08-22 20:06:20 -0400 | [diff] [blame] | 653 | clnt = rpc_create(&args); |
David Howells | 5006a76 | 2006-08-22 20:06:12 -0400 | [diff] [blame] | 654 | if (IS_ERR(clnt)) { |
| 655 | dprintk("%s: cannot create RPC client. Error = %ld\n", |
Harvey Harrison | 3110ff8 | 2008-05-02 13:42:44 -0700 | [diff] [blame] | 656 | __func__, PTR_ERR(clnt)); |
David Howells | 5006a76 | 2006-08-22 20:06:12 -0400 | [diff] [blame] | 657 | return PTR_ERR(clnt); |
| 658 | } |
| 659 | |
David Howells | 5006a76 | 2006-08-22 20:06:12 -0400 | [diff] [blame] | 660 | clp->cl_rpcclient = clnt; |
| 661 | return 0; |
| 662 | } |
David Howells | 54ceac4 | 2006-08-22 20:06:13 -0400 | [diff] [blame] | 663 | |
| 664 | /* |
| 665 | * Version 2 or 3 client destruction |
| 666 | */ |
| 667 | static void nfs_destroy_server(struct nfs_server *server) |
| 668 | { |
Suresh Jayaraman | 5eebde2 | 2010-09-23 08:55:58 -0400 | [diff] [blame] | 669 | if (!(server->flags & NFS_MOUNT_LOCAL_FLOCK) || |
| 670 | !(server->flags & NFS_MOUNT_LOCAL_FCNTL)) |
Chuck Lever | 9289e7f | 2008-01-11 17:09:52 -0500 | [diff] [blame] | 671 | nlmclnt_done(server->nlm_host); |
David Howells | 54ceac4 | 2006-08-22 20:06:13 -0400 | [diff] [blame] | 672 | } |
| 673 | |
| 674 | /* |
| 675 | * Version 2 or 3 lockd setup |
| 676 | */ |
| 677 | static int nfs_start_lockd(struct nfs_server *server) |
| 678 | { |
Chuck Lever | 9289e7f | 2008-01-11 17:09:52 -0500 | [diff] [blame] | 679 | struct nlm_host *host; |
| 680 | struct nfs_client *clp = server->nfs_client; |
Chuck Lever | 883bb16 | 2008-01-15 16:04:20 -0500 | [diff] [blame] | 681 | struct nlmclnt_initdata nlm_init = { |
| 682 | .hostname = clp->cl_hostname, |
| 683 | .address = (struct sockaddr *)&clp->cl_addr, |
| 684 | .addrlen = clp->cl_addrlen, |
Chuck Lever | 883bb16 | 2008-01-15 16:04:20 -0500 | [diff] [blame] | 685 | .nfs_version = clp->rpc_ops->version, |
Chuck Lever | 0cb2659 | 2008-12-23 15:21:38 -0500 | [diff] [blame] | 686 | .noresvport = server->flags & NFS_MOUNT_NORESVPORT ? |
| 687 | 1 : 0, |
Chuck Lever | 883bb16 | 2008-01-15 16:04:20 -0500 | [diff] [blame] | 688 | }; |
David Howells | 54ceac4 | 2006-08-22 20:06:13 -0400 | [diff] [blame] | 689 | |
Chuck Lever | 883bb16 | 2008-01-15 16:04:20 -0500 | [diff] [blame] | 690 | if (nlm_init.nfs_version > 3) |
Chuck Lever | 9289e7f | 2008-01-11 17:09:52 -0500 | [diff] [blame] | 691 | return 0; |
Suresh Jayaraman | 5eebde2 | 2010-09-23 08:55:58 -0400 | [diff] [blame] | 692 | if ((server->flags & NFS_MOUNT_LOCAL_FLOCK) && |
| 693 | (server->flags & NFS_MOUNT_LOCAL_FCNTL)) |
Chuck Lever | 9289e7f | 2008-01-11 17:09:52 -0500 | [diff] [blame] | 694 | return 0; |
| 695 | |
Trond Myklebust | 8a6e5de | 2009-09-23 14:36:37 -0400 | [diff] [blame] | 696 | switch (clp->cl_proto) { |
| 697 | default: |
| 698 | nlm_init.protocol = IPPROTO_TCP; |
| 699 | break; |
| 700 | case XPRT_TRANSPORT_UDP: |
| 701 | nlm_init.protocol = IPPROTO_UDP; |
| 702 | } |
| 703 | |
Chuck Lever | 883bb16 | 2008-01-15 16:04:20 -0500 | [diff] [blame] | 704 | host = nlmclnt_init(&nlm_init); |
Chuck Lever | 9289e7f | 2008-01-11 17:09:52 -0500 | [diff] [blame] | 705 | if (IS_ERR(host)) |
| 706 | return PTR_ERR(host); |
| 707 | |
| 708 | server->nlm_host = host; |
| 709 | server->destroy = nfs_destroy_server; |
| 710 | return 0; |
David Howells | 54ceac4 | 2006-08-22 20:06:13 -0400 | [diff] [blame] | 711 | } |
| 712 | |
| 713 | /* |
| 714 | * Initialise an NFSv3 ACL client connection |
| 715 | */ |
| 716 | #ifdef CONFIG_NFS_V3_ACL |
| 717 | static void nfs_init_server_aclclient(struct nfs_server *server) |
| 718 | { |
Trond Myklebust | 40c55319 | 2007-12-14 14:56:07 -0500 | [diff] [blame] | 719 | if (server->nfs_client->rpc_ops->version != 3) |
David Howells | 54ceac4 | 2006-08-22 20:06:13 -0400 | [diff] [blame] | 720 | goto out_noacl; |
| 721 | if (server->flags & NFS_MOUNT_NOACL) |
| 722 | goto out_noacl; |
| 723 | |
| 724 | server->client_acl = rpc_bind_new_program(server->client, &nfsacl_program, 3); |
| 725 | if (IS_ERR(server->client_acl)) |
| 726 | goto out_noacl; |
| 727 | |
| 728 | /* No errors! Assume that Sun nfsacls are supported */ |
| 729 | server->caps |= NFS_CAP_ACLS; |
| 730 | return; |
| 731 | |
| 732 | out_noacl: |
| 733 | server->caps &= ~NFS_CAP_ACLS; |
| 734 | } |
| 735 | #else |
| 736 | static inline void nfs_init_server_aclclient(struct nfs_server *server) |
| 737 | { |
| 738 | server->flags &= ~NFS_MOUNT_NOACL; |
| 739 | server->caps &= ~NFS_CAP_ACLS; |
| 740 | } |
| 741 | #endif |
| 742 | |
| 743 | /* |
| 744 | * Create a general RPC client |
| 745 | */ |
Trond Myklebust | 3317023 | 2007-12-20 16:03:59 -0500 | [diff] [blame] | 746 | static int nfs_init_server_rpcclient(struct nfs_server *server, |
| 747 | const struct rpc_timeout *timeo, |
| 748 | rpc_authflavor_t pseudoflavour) |
David Howells | 54ceac4 | 2006-08-22 20:06:13 -0400 | [diff] [blame] | 749 | { |
| 750 | struct nfs_client *clp = server->nfs_client; |
| 751 | |
| 752 | server->client = rpc_clone_client(clp->cl_rpcclient); |
| 753 | if (IS_ERR(server->client)) { |
Harvey Harrison | 3110ff8 | 2008-05-02 13:42:44 -0700 | [diff] [blame] | 754 | dprintk("%s: couldn't create rpc_client!\n", __func__); |
David Howells | 54ceac4 | 2006-08-22 20:06:13 -0400 | [diff] [blame] | 755 | return PTR_ERR(server->client); |
| 756 | } |
| 757 | |
Trond Myklebust | 3317023 | 2007-12-20 16:03:59 -0500 | [diff] [blame] | 758 | memcpy(&server->client->cl_timeout_default, |
| 759 | timeo, |
| 760 | sizeof(server->client->cl_timeout_default)); |
| 761 | server->client->cl_timeout = &server->client->cl_timeout_default; |
| 762 | |
David Howells | 54ceac4 | 2006-08-22 20:06:13 -0400 | [diff] [blame] | 763 | if (pseudoflavour != clp->cl_rpcclient->cl_auth->au_flavor) { |
| 764 | struct rpc_auth *auth; |
| 765 | |
| 766 | auth = rpcauth_create(pseudoflavour, server->client); |
| 767 | if (IS_ERR(auth)) { |
Harvey Harrison | 3110ff8 | 2008-05-02 13:42:44 -0700 | [diff] [blame] | 768 | dprintk("%s: couldn't create credcache!\n", __func__); |
David Howells | 54ceac4 | 2006-08-22 20:06:13 -0400 | [diff] [blame] | 769 | return PTR_ERR(auth); |
| 770 | } |
| 771 | } |
| 772 | server->client->cl_softrtry = 0; |
| 773 | if (server->flags & NFS_MOUNT_SOFT) |
| 774 | server->client->cl_softrtry = 1; |
| 775 | |
David Howells | 54ceac4 | 2006-08-22 20:06:13 -0400 | [diff] [blame] | 776 | return 0; |
| 777 | } |
| 778 | |
| 779 | /* |
| 780 | * Initialise an NFS2 or NFS3 client |
| 781 | */ |
Andy Adamson | 45a52a0 | 2011-03-01 01:34:08 +0000 | [diff] [blame] | 782 | int nfs_init_client(struct nfs_client *clp, const struct rpc_timeout *timeparms, |
| 783 | const char *ip_addr, rpc_authflavor_t authflavour, |
| 784 | int noresvport) |
David Howells | 54ceac4 | 2006-08-22 20:06:13 -0400 | [diff] [blame] | 785 | { |
David Howells | 54ceac4 | 2006-08-22 20:06:13 -0400 | [diff] [blame] | 786 | int error; |
| 787 | |
| 788 | if (clp->cl_cons_state == NFS_CS_READY) { |
| 789 | /* the client is already initialised */ |
| 790 | dprintk("<-- nfs_init_client() = 0 [already %p]\n", clp); |
| 791 | return 0; |
| 792 | } |
| 793 | |
David Howells | 54ceac4 | 2006-08-22 20:06:13 -0400 | [diff] [blame] | 794 | /* |
| 795 | * Create a client RPC handle for doing FSSTAT with UNIX auth only |
| 796 | * - RFC 2623, sec 2.3.2 |
| 797 | */ |
Chuck Lever | d740351 | 2008-12-23 15:21:37 -0500 | [diff] [blame] | 798 | error = nfs_create_rpc_client(clp, timeparms, RPC_AUTH_UNIX, |
Andy Adamson | 45a52a0 | 2011-03-01 01:34:08 +0000 | [diff] [blame] | 799 | 0, noresvport); |
David Howells | 54ceac4 | 2006-08-22 20:06:13 -0400 | [diff] [blame] | 800 | if (error < 0) |
| 801 | goto error; |
| 802 | nfs_mark_client_ready(clp, NFS_CS_READY); |
| 803 | return 0; |
| 804 | |
| 805 | error: |
| 806 | nfs_mark_client_ready(clp, error); |
| 807 | dprintk("<-- nfs_init_client() = xerror %d\n", error); |
| 808 | return error; |
| 809 | } |
| 810 | |
| 811 | /* |
| 812 | * Create a version 2 or 3 client |
| 813 | */ |
\"Talpey, Thomas\ | 2283f8d | 2007-09-10 13:43:56 -0400 | [diff] [blame] | 814 | static int nfs_init_server(struct nfs_server *server, |
| 815 | const struct nfs_parsed_mount_data *data) |
David Howells | 54ceac4 | 2006-08-22 20:06:13 -0400 | [diff] [blame] | 816 | { |
Trond Myklebust | 3a49802 | 2007-12-14 14:56:04 -0500 | [diff] [blame] | 817 | struct nfs_client_initdata cl_init = { |
| 818 | .hostname = data->nfs_server.hostname, |
Chuck Lever | d7422c4 | 2007-12-10 14:58:51 -0500 | [diff] [blame] | 819 | .addr = (const struct sockaddr *)&data->nfs_server.address, |
Chuck Lever | 4c56801 | 2007-12-10 14:59:28 -0500 | [diff] [blame] | 820 | .addrlen = data->nfs_server.addrlen, |
Trond Myklebust | 40c55319 | 2007-12-14 14:56:07 -0500 | [diff] [blame] | 821 | .rpc_ops = &nfs_v2_clientops, |
Trond Myklebust | 59dca3b | 2008-01-03 16:29:06 -0500 | [diff] [blame] | 822 | .proto = data->nfs_server.protocol, |
Trond Myklebust | 3a49802 | 2007-12-14 14:56:04 -0500 | [diff] [blame] | 823 | }; |
Trond Myklebust | 3317023 | 2007-12-20 16:03:59 -0500 | [diff] [blame] | 824 | struct rpc_timeout timeparms; |
David Howells | 54ceac4 | 2006-08-22 20:06:13 -0400 | [diff] [blame] | 825 | struct nfs_client *clp; |
Trond Myklebust | 3a49802 | 2007-12-14 14:56:04 -0500 | [diff] [blame] | 826 | int error; |
David Howells | 54ceac4 | 2006-08-22 20:06:13 -0400 | [diff] [blame] | 827 | |
| 828 | dprintk("--> nfs_init_server()\n"); |
| 829 | |
| 830 | #ifdef CONFIG_NFS_V3 |
Trond Myklebust | 8a6e5de | 2009-09-23 14:36:37 -0400 | [diff] [blame] | 831 | if (data->version == 3) |
Trond Myklebust | 40c55319 | 2007-12-14 14:56:07 -0500 | [diff] [blame] | 832 | cl_init.rpc_ops = &nfs_v3_clientops; |
David Howells | 54ceac4 | 2006-08-22 20:06:13 -0400 | [diff] [blame] | 833 | #endif |
| 834 | |
Andy Adamson | 45a52a0 | 2011-03-01 01:34:08 +0000 | [diff] [blame] | 835 | nfs_init_timeout_values(&timeparms, data->nfs_server.protocol, |
| 836 | data->timeo, data->retrans); |
| 837 | |
David Howells | 54ceac4 | 2006-08-22 20:06:13 -0400 | [diff] [blame] | 838 | /* Allocate or find a client reference we can use */ |
Andy Adamson | 45a52a0 | 2011-03-01 01:34:08 +0000 | [diff] [blame] | 839 | clp = nfs_get_client(&cl_init, &timeparms, NULL, RPC_AUTH_UNIX, |
| 840 | data->flags & NFS_MOUNT_NORESVPORT); |
David Howells | 54ceac4 | 2006-08-22 20:06:13 -0400 | [diff] [blame] | 841 | if (IS_ERR(clp)) { |
| 842 | dprintk("<-- nfs_init_server() = error %ld\n", PTR_ERR(clp)); |
| 843 | return PTR_ERR(clp); |
| 844 | } |
| 845 | |
David Howells | 54ceac4 | 2006-08-22 20:06:13 -0400 | [diff] [blame] | 846 | server->nfs_client = clp; |
| 847 | |
| 848 | /* Initialise the client representation from the mount data */ |
Trond Myklebust | ff3525a | 2008-08-15 16:59:14 -0400 | [diff] [blame] | 849 | server->flags = data->flags; |
David Howells | b797cac | 2009-04-03 16:42:48 +0100 | [diff] [blame] | 850 | server->options = data->options; |
Trond Myklebust | 62ab460c | 2009-08-09 15:06:19 -0400 | [diff] [blame] | 851 | server->caps |= NFS_CAP_HARDLINKS|NFS_CAP_SYMLINKS|NFS_CAP_FILEID| |
| 852 | NFS_CAP_MODE|NFS_CAP_NLINK|NFS_CAP_OWNER|NFS_CAP_OWNER_GROUP| |
| 853 | NFS_CAP_ATIME|NFS_CAP_CTIME|NFS_CAP_MTIME; |
David Howells | 54ceac4 | 2006-08-22 20:06:13 -0400 | [diff] [blame] | 854 | |
| 855 | if (data->rsize) |
| 856 | server->rsize = nfs_block_size(data->rsize, NULL); |
| 857 | if (data->wsize) |
| 858 | server->wsize = nfs_block_size(data->wsize, NULL); |
| 859 | |
| 860 | server->acregmin = data->acregmin * HZ; |
| 861 | server->acregmax = data->acregmax * HZ; |
| 862 | server->acdirmin = data->acdirmin * HZ; |
| 863 | server->acdirmax = data->acdirmax * HZ; |
| 864 | |
| 865 | /* Start lockd here, before we might error out */ |
| 866 | error = nfs_start_lockd(server); |
| 867 | if (error < 0) |
| 868 | goto error; |
| 869 | |
Chuck Lever | f22d6d7 | 2008-03-14 14:10:22 -0400 | [diff] [blame] | 870 | server->port = data->nfs_server.port; |
| 871 | |
Trond Myklebust | 3317023 | 2007-12-20 16:03:59 -0500 | [diff] [blame] | 872 | error = nfs_init_server_rpcclient(server, &timeparms, data->auth_flavors[0]); |
David Howells | 54ceac4 | 2006-08-22 20:06:13 -0400 | [diff] [blame] | 873 | if (error < 0) |
| 874 | goto error; |
| 875 | |
Chuck Lever | 3f8400d | 2008-03-14 14:10:30 -0400 | [diff] [blame] | 876 | /* Preserve the values of mount_server-related mount options */ |
| 877 | if (data->mount_server.addrlen) { |
| 878 | memcpy(&server->mountd_address, &data->mount_server.address, |
| 879 | data->mount_server.addrlen); |
| 880 | server->mountd_addrlen = data->mount_server.addrlen; |
| 881 | } |
| 882 | server->mountd_version = data->mount_server.version; |
| 883 | server->mountd_port = data->mount_server.port; |
| 884 | server->mountd_protocol = data->mount_server.protocol; |
| 885 | |
David Howells | 54ceac4 | 2006-08-22 20:06:13 -0400 | [diff] [blame] | 886 | server->namelen = data->namlen; |
| 887 | /* Create a client RPC handle for the NFSv3 ACL management interface */ |
| 888 | nfs_init_server_aclclient(server); |
David Howells | 54ceac4 | 2006-08-22 20:06:13 -0400 | [diff] [blame] | 889 | dprintk("<-- nfs_init_server() = 0 [new %p]\n", clp); |
| 890 | return 0; |
| 891 | |
| 892 | error: |
| 893 | server->nfs_client = NULL; |
| 894 | nfs_put_client(clp); |
| 895 | dprintk("<-- nfs_init_server() = xerror %d\n", error); |
| 896 | return error; |
| 897 | } |
| 898 | |
| 899 | /* |
| 900 | * Load up the server record from information gained in an fsinfo record |
| 901 | */ |
| 902 | static void nfs_server_set_fsinfo(struct nfs_server *server, struct nfs_fsinfo *fsinfo) |
| 903 | { |
| 904 | unsigned long max_rpc_payload; |
| 905 | |
| 906 | /* Work out a lot of parameters */ |
| 907 | if (server->rsize == 0) |
| 908 | server->rsize = nfs_block_size(fsinfo->rtpref, NULL); |
| 909 | if (server->wsize == 0) |
| 910 | server->wsize = nfs_block_size(fsinfo->wtpref, NULL); |
| 911 | |
| 912 | if (fsinfo->rtmax >= 512 && server->rsize > fsinfo->rtmax) |
| 913 | server->rsize = nfs_block_size(fsinfo->rtmax, NULL); |
| 914 | if (fsinfo->wtmax >= 512 && server->wsize > fsinfo->wtmax) |
| 915 | server->wsize = nfs_block_size(fsinfo->wtmax, NULL); |
| 916 | |
| 917 | max_rpc_payload = nfs_block_size(rpc_max_payload(server->client), NULL); |
| 918 | if (server->rsize > max_rpc_payload) |
| 919 | server->rsize = max_rpc_payload; |
| 920 | if (server->rsize > NFS_MAX_FILE_IO_SIZE) |
| 921 | server->rsize = NFS_MAX_FILE_IO_SIZE; |
| 922 | server->rpages = (server->rsize + PAGE_CACHE_SIZE - 1) >> PAGE_CACHE_SHIFT; |
Peter Zijlstra | e0bf68d | 2007-10-16 23:25:46 -0700 | [diff] [blame] | 923 | |
Jens Axboe | d993831 | 2009-06-12 14:45:52 +0200 | [diff] [blame] | 924 | server->backing_dev_info.name = "nfs"; |
David Howells | 54ceac4 | 2006-08-22 20:06:13 -0400 | [diff] [blame] | 925 | server->backing_dev_info.ra_pages = server->rpages * NFS_MAX_READAHEAD; |
| 926 | |
| 927 | if (server->wsize > max_rpc_payload) |
| 928 | server->wsize = max_rpc_payload; |
| 929 | if (server->wsize > NFS_MAX_FILE_IO_SIZE) |
| 930 | server->wsize = NFS_MAX_FILE_IO_SIZE; |
| 931 | server->wpages = (server->wsize + PAGE_CACHE_SIZE - 1) >> PAGE_CACHE_SHIFT; |
Ricardo Labiaga | 85e174b | 2010-10-20 00:17:58 -0400 | [diff] [blame] | 932 | set_pnfs_layoutdriver(server, fsinfo->layouttype); |
| 933 | |
David Howells | 54ceac4 | 2006-08-22 20:06:13 -0400 | [diff] [blame] | 934 | server->wtmult = nfs_block_bits(fsinfo->wtmult, NULL); |
| 935 | |
| 936 | server->dtsize = nfs_block_size(fsinfo->dtpref, NULL); |
Bryan Schumaker | 56e4ebf | 2010-10-20 15:44:37 -0400 | [diff] [blame] | 937 | if (server->dtsize > PAGE_CACHE_SIZE * NFS_MAX_READDIR_PAGES) |
| 938 | server->dtsize = PAGE_CACHE_SIZE * NFS_MAX_READDIR_PAGES; |
David Howells | 54ceac4 | 2006-08-22 20:06:13 -0400 | [diff] [blame] | 939 | if (server->dtsize > server->rsize) |
| 940 | server->dtsize = server->rsize; |
| 941 | |
| 942 | if (server->flags & NFS_MOUNT_NOAC) { |
| 943 | server->acregmin = server->acregmax = 0; |
| 944 | server->acdirmin = server->acdirmax = 0; |
| 945 | } |
| 946 | |
| 947 | server->maxfilesize = fsinfo->maxfilesize; |
| 948 | |
Ricardo Labiaga | 6b96724 | 2010-10-12 16:30:05 -0700 | [diff] [blame] | 949 | server->time_delta = fsinfo->time_delta; |
| 950 | |
David Howells | 54ceac4 | 2006-08-22 20:06:13 -0400 | [diff] [blame] | 951 | /* We're airborne Set socket buffersize */ |
| 952 | rpc_setbufsize(server->client, server->wsize + 100, server->rsize + 100); |
| 953 | } |
| 954 | |
| 955 | /* |
| 956 | * Probe filesystem information, including the FSID on v2/v3 |
| 957 | */ |
| 958 | static int nfs_probe_fsinfo(struct nfs_server *server, struct nfs_fh *mntfh, struct nfs_fattr *fattr) |
| 959 | { |
| 960 | struct nfs_fsinfo fsinfo; |
| 961 | struct nfs_client *clp = server->nfs_client; |
| 962 | int error; |
| 963 | |
| 964 | dprintk("--> nfs_probe_fsinfo()\n"); |
| 965 | |
| 966 | if (clp->rpc_ops->set_capabilities != NULL) { |
| 967 | error = clp->rpc_ops->set_capabilities(server, mntfh); |
| 968 | if (error < 0) |
| 969 | goto out_error; |
| 970 | } |
| 971 | |
| 972 | fsinfo.fattr = fattr; |
Ricardo Labiaga | 85e174b | 2010-10-20 00:17:58 -0400 | [diff] [blame] | 973 | fsinfo.layouttype = 0; |
David Howells | 54ceac4 | 2006-08-22 20:06:13 -0400 | [diff] [blame] | 974 | error = clp->rpc_ops->fsinfo(server, mntfh, &fsinfo); |
| 975 | if (error < 0) |
| 976 | goto out_error; |
| 977 | |
| 978 | nfs_server_set_fsinfo(server, &fsinfo); |
| 979 | |
| 980 | /* Get some general file system info */ |
| 981 | if (server->namelen == 0) { |
| 982 | struct nfs_pathconf pathinfo; |
| 983 | |
| 984 | pathinfo.fattr = fattr; |
| 985 | nfs_fattr_init(fattr); |
| 986 | |
| 987 | if (clp->rpc_ops->pathconf(server, mntfh, &pathinfo) >= 0) |
| 988 | server->namelen = pathinfo.max_namelen; |
| 989 | } |
| 990 | |
| 991 | dprintk("<-- nfs_probe_fsinfo() = 0\n"); |
| 992 | return 0; |
| 993 | |
| 994 | out_error: |
| 995 | dprintk("nfs_probe_fsinfo: error = %d\n", -error); |
| 996 | return error; |
| 997 | } |
| 998 | |
| 999 | /* |
| 1000 | * Copy useful information when duplicating a server record |
| 1001 | */ |
| 1002 | static void nfs_server_copy_userdata(struct nfs_server *target, struct nfs_server *source) |
| 1003 | { |
| 1004 | target->flags = source->flags; |
Chuck Lever | 356e76b | 2010-04-22 15:35:56 -0400 | [diff] [blame] | 1005 | target->rsize = source->rsize; |
| 1006 | target->wsize = source->wsize; |
David Howells | 54ceac4 | 2006-08-22 20:06:13 -0400 | [diff] [blame] | 1007 | target->acregmin = source->acregmin; |
| 1008 | target->acregmax = source->acregmax; |
| 1009 | target->acdirmin = source->acdirmin; |
| 1010 | target->acdirmax = source->acdirmax; |
| 1011 | target->caps = source->caps; |
David Howells | 2df5480 | 2009-09-23 14:36:39 -0400 | [diff] [blame] | 1012 | target->options = source->options; |
David Howells | 54ceac4 | 2006-08-22 20:06:13 -0400 | [diff] [blame] | 1013 | } |
| 1014 | |
Chuck Lever | fca5238 | 2010-12-24 01:32:32 +0000 | [diff] [blame] | 1015 | static void nfs_server_insert_lists(struct nfs_server *server) |
| 1016 | { |
| 1017 | struct nfs_client *clp = server->nfs_client; |
| 1018 | |
| 1019 | spin_lock(&nfs_client_lock); |
| 1020 | list_add_tail_rcu(&server->client_link, &clp->cl_superblocks); |
| 1021 | list_add_tail(&server->master_link, &nfs_volume_list); |
Andy Adamson | d3b4c9d | 2011-03-01 01:34:10 +0000 | [diff] [blame^] | 1022 | clear_bit(NFS_CS_STOP_RENEW, &clp->cl_res_state); |
Chuck Lever | fca5238 | 2010-12-24 01:32:32 +0000 | [diff] [blame] | 1023 | spin_unlock(&nfs_client_lock); |
| 1024 | |
| 1025 | } |
| 1026 | |
| 1027 | static void nfs_server_remove_lists(struct nfs_server *server) |
| 1028 | { |
Andy Adamson | d3b4c9d | 2011-03-01 01:34:10 +0000 | [diff] [blame^] | 1029 | struct nfs_client *clp = server->nfs_client; |
| 1030 | |
Chuck Lever | fca5238 | 2010-12-24 01:32:32 +0000 | [diff] [blame] | 1031 | spin_lock(&nfs_client_lock); |
| 1032 | list_del_rcu(&server->client_link); |
Andy Adamson | d3b4c9d | 2011-03-01 01:34:10 +0000 | [diff] [blame^] | 1033 | if (clp && list_empty(&clp->cl_superblocks)) |
| 1034 | set_bit(NFS_CS_STOP_RENEW, &clp->cl_res_state); |
Chuck Lever | fca5238 | 2010-12-24 01:32:32 +0000 | [diff] [blame] | 1035 | list_del(&server->master_link); |
| 1036 | spin_unlock(&nfs_client_lock); |
| 1037 | |
| 1038 | synchronize_rcu(); |
| 1039 | } |
| 1040 | |
David Howells | 54ceac4 | 2006-08-22 20:06:13 -0400 | [diff] [blame] | 1041 | /* |
| 1042 | * Allocate and initialise a server record |
| 1043 | */ |
| 1044 | static struct nfs_server *nfs_alloc_server(void) |
| 1045 | { |
| 1046 | struct nfs_server *server; |
| 1047 | |
| 1048 | server = kzalloc(sizeof(struct nfs_server), GFP_KERNEL); |
| 1049 | if (!server) |
| 1050 | return NULL; |
| 1051 | |
| 1052 | server->client = server->client_acl = ERR_PTR(-EINVAL); |
| 1053 | |
| 1054 | /* Zero out the NFS state stuff */ |
| 1055 | INIT_LIST_HEAD(&server->client_link); |
| 1056 | INIT_LIST_HEAD(&server->master_link); |
Chuck Lever | d3978bb | 2010-12-24 01:33:04 +0000 | [diff] [blame] | 1057 | INIT_LIST_HEAD(&server->delegations); |
David Howells | 54ceac4 | 2006-08-22 20:06:13 -0400 | [diff] [blame] | 1058 | |
Steve Dickson | ef818a2 | 2007-11-08 04:05:04 -0500 | [diff] [blame] | 1059 | atomic_set(&server->active, 0); |
| 1060 | |
David Howells | 54ceac4 | 2006-08-22 20:06:13 -0400 | [diff] [blame] | 1061 | server->io_stats = nfs_alloc_iostats(); |
| 1062 | if (!server->io_stats) { |
| 1063 | kfree(server); |
| 1064 | return NULL; |
| 1065 | } |
| 1066 | |
Jens Axboe | 48d0764 | 2009-09-21 09:59:39 +0200 | [diff] [blame] | 1067 | if (bdi_init(&server->backing_dev_info)) { |
| 1068 | nfs_free_iostats(server->io_stats); |
| 1069 | kfree(server); |
| 1070 | return NULL; |
| 1071 | } |
| 1072 | |
Fred Isaman | f7e8917 | 2011-01-06 11:36:32 +0000 | [diff] [blame] | 1073 | pnfs_init_server(server); |
| 1074 | |
David Howells | 54ceac4 | 2006-08-22 20:06:13 -0400 | [diff] [blame] | 1075 | return server; |
| 1076 | } |
| 1077 | |
| 1078 | /* |
| 1079 | * Free up a server record |
| 1080 | */ |
| 1081 | void nfs_free_server(struct nfs_server *server) |
| 1082 | { |
| 1083 | dprintk("--> nfs_free_server()\n"); |
| 1084 | |
Chuck Lever | fca5238 | 2010-12-24 01:32:32 +0000 | [diff] [blame] | 1085 | nfs_server_remove_lists(server); |
Ricardo Labiaga | 85e174b | 2010-10-20 00:17:58 -0400 | [diff] [blame] | 1086 | unset_pnfs_layoutdriver(server); |
David Howells | 54ceac4 | 2006-08-22 20:06:13 -0400 | [diff] [blame] | 1087 | |
| 1088 | if (server->destroy != NULL) |
| 1089 | server->destroy(server); |
Trond Myklebust | 5cef338 | 2007-12-11 22:01:56 -0500 | [diff] [blame] | 1090 | |
| 1091 | if (!IS_ERR(server->client_acl)) |
| 1092 | rpc_shutdown_client(server->client_acl); |
David Howells | 54ceac4 | 2006-08-22 20:06:13 -0400 | [diff] [blame] | 1093 | if (!IS_ERR(server->client)) |
| 1094 | rpc_shutdown_client(server->client); |
| 1095 | |
| 1096 | nfs_put_client(server->nfs_client); |
| 1097 | |
| 1098 | nfs_free_iostats(server->io_stats); |
Peter Zijlstra | e0bf68d | 2007-10-16 23:25:46 -0700 | [diff] [blame] | 1099 | bdi_destroy(&server->backing_dev_info); |
David Howells | 54ceac4 | 2006-08-22 20:06:13 -0400 | [diff] [blame] | 1100 | kfree(server); |
| 1101 | nfs_release_automount_timer(); |
| 1102 | dprintk("<-- nfs_free_server()\n"); |
| 1103 | } |
| 1104 | |
| 1105 | /* |
| 1106 | * Create a version 2 or 3 volume record |
| 1107 | * - keyed on server and FSID |
| 1108 | */ |
\"Talpey, Thomas\ | 2283f8d | 2007-09-10 13:43:56 -0400 | [diff] [blame] | 1109 | 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] | 1110 | struct nfs_fh *mntfh) |
| 1111 | { |
| 1112 | struct nfs_server *server; |
Trond Myklebust | fbca779 | 2010-04-16 16:22:46 -0400 | [diff] [blame] | 1113 | struct nfs_fattr *fattr; |
David Howells | 54ceac4 | 2006-08-22 20:06:13 -0400 | [diff] [blame] | 1114 | int error; |
| 1115 | |
| 1116 | server = nfs_alloc_server(); |
| 1117 | if (!server) |
| 1118 | return ERR_PTR(-ENOMEM); |
| 1119 | |
Trond Myklebust | fbca779 | 2010-04-16 16:22:46 -0400 | [diff] [blame] | 1120 | error = -ENOMEM; |
| 1121 | fattr = nfs_alloc_fattr(); |
| 1122 | if (fattr == NULL) |
| 1123 | goto error; |
| 1124 | |
David Howells | 54ceac4 | 2006-08-22 20:06:13 -0400 | [diff] [blame] | 1125 | /* Get a client representation */ |
| 1126 | error = nfs_init_server(server, data); |
| 1127 | if (error < 0) |
| 1128 | goto error; |
| 1129 | |
| 1130 | BUG_ON(!server->nfs_client); |
| 1131 | BUG_ON(!server->nfs_client->rpc_ops); |
| 1132 | BUG_ON(!server->nfs_client->rpc_ops->file_inode_ops); |
| 1133 | |
| 1134 | /* Probe the root fh to retrieve its FSID */ |
Trond Myklebust | fbca779 | 2010-04-16 16:22:46 -0400 | [diff] [blame] | 1135 | error = nfs_probe_fsinfo(server, mntfh, fattr); |
David Howells | 54ceac4 | 2006-08-22 20:06:13 -0400 | [diff] [blame] | 1136 | if (error < 0) |
| 1137 | goto error; |
Trond Myklebust | 54af3bb | 2007-09-28 12:27:41 -0400 | [diff] [blame] | 1138 | if (server->nfs_client->rpc_ops->version == 3) { |
| 1139 | if (server->namelen == 0 || server->namelen > NFS3_MAXNAMLEN) |
| 1140 | server->namelen = NFS3_MAXNAMLEN; |
| 1141 | if (!(data->flags & NFS_MOUNT_NORDIRPLUS)) |
| 1142 | server->caps |= NFS_CAP_READDIRPLUS; |
| 1143 | } else { |
| 1144 | if (server->namelen == 0 || server->namelen > NFS2_MAXNAMLEN) |
| 1145 | server->namelen = NFS2_MAXNAMLEN; |
| 1146 | } |
| 1147 | |
Trond Myklebust | fbca779 | 2010-04-16 16:22:46 -0400 | [diff] [blame] | 1148 | if (!(fattr->valid & NFS_ATTR_FATTR)) { |
| 1149 | error = server->nfs_client->rpc_ops->getattr(server, mntfh, fattr); |
David Howells | 54ceac4 | 2006-08-22 20:06:13 -0400 | [diff] [blame] | 1150 | if (error < 0) { |
| 1151 | dprintk("nfs_create_server: getattr error = %d\n", -error); |
| 1152 | goto error; |
| 1153 | } |
| 1154 | } |
Trond Myklebust | fbca779 | 2010-04-16 16:22:46 -0400 | [diff] [blame] | 1155 | memcpy(&server->fsid, &fattr->fsid, sizeof(server->fsid)); |
David Howells | 54ceac4 | 2006-08-22 20:06:13 -0400 | [diff] [blame] | 1156 | |
David Howells | 6daabf1 | 2006-08-24 15:44:16 -0400 | [diff] [blame] | 1157 | dprintk("Server FSID: %llx:%llx\n", |
| 1158 | (unsigned long long) server->fsid.major, |
| 1159 | (unsigned long long) server->fsid.minor); |
David Howells | 54ceac4 | 2006-08-22 20:06:13 -0400 | [diff] [blame] | 1160 | |
Chuck Lever | fca5238 | 2010-12-24 01:32:32 +0000 | [diff] [blame] | 1161 | nfs_server_insert_lists(server); |
David Howells | 54ceac4 | 2006-08-22 20:06:13 -0400 | [diff] [blame] | 1162 | server->mount_time = jiffies; |
Trond Myklebust | fbca779 | 2010-04-16 16:22:46 -0400 | [diff] [blame] | 1163 | nfs_free_fattr(fattr); |
David Howells | 54ceac4 | 2006-08-22 20:06:13 -0400 | [diff] [blame] | 1164 | return server; |
| 1165 | |
| 1166 | error: |
Trond Myklebust | fbca779 | 2010-04-16 16:22:46 -0400 | [diff] [blame] | 1167 | nfs_free_fattr(fattr); |
David Howells | 54ceac4 | 2006-08-22 20:06:13 -0400 | [diff] [blame] | 1168 | nfs_free_server(server); |
| 1169 | return ERR_PTR(error); |
| 1170 | } |
| 1171 | |
| 1172 | #ifdef CONFIG_NFS_V4 |
| 1173 | /* |
Andy Adamson | c36fca5 | 2011-01-06 02:04:32 +0000 | [diff] [blame] | 1174 | * NFSv4.0 callback thread helper |
| 1175 | * |
| 1176 | * Find a client by IP address, protocol version, and minorversion |
| 1177 | * |
| 1178 | * Called from the pg_authenticate method. The callback identifier |
| 1179 | * is not used as it has not been decoded. |
| 1180 | * |
| 1181 | * Returns NULL if no such client |
| 1182 | */ |
| 1183 | struct nfs_client * |
| 1184 | nfs4_find_client_no_ident(const struct sockaddr *addr) |
| 1185 | { |
| 1186 | struct nfs_client *clp; |
| 1187 | |
| 1188 | spin_lock(&nfs_client_lock); |
| 1189 | list_for_each_entry(clp, &nfs_client_list, cl_share_link) { |
| 1190 | if (nfs4_cb_match_client(addr, clp, 0) == false) |
| 1191 | continue; |
| 1192 | atomic_inc(&clp->cl_count); |
| 1193 | spin_unlock(&nfs_client_lock); |
| 1194 | return clp; |
| 1195 | } |
| 1196 | spin_unlock(&nfs_client_lock); |
| 1197 | return NULL; |
| 1198 | } |
| 1199 | |
| 1200 | /* |
| 1201 | * NFSv4.0 callback thread helper |
| 1202 | * |
| 1203 | * Find a client by callback identifier |
| 1204 | */ |
| 1205 | struct nfs_client * |
| 1206 | nfs4_find_client_ident(int cb_ident) |
| 1207 | { |
| 1208 | struct nfs_client *clp; |
| 1209 | |
| 1210 | spin_lock(&nfs_client_lock); |
| 1211 | clp = idr_find(&cb_ident_idr, cb_ident); |
| 1212 | if (clp) |
| 1213 | atomic_inc(&clp->cl_count); |
| 1214 | spin_unlock(&nfs_client_lock); |
| 1215 | return clp; |
| 1216 | } |
| 1217 | |
| 1218 | #if defined(CONFIG_NFS_V4_1) |
| 1219 | /* |
| 1220 | * NFSv4.1 callback thread helper |
| 1221 | * For CB_COMPOUND calls, find a client by IP address, protocol version, |
| 1222 | * minorversion, and sessionID |
| 1223 | * |
Andy Adamson | c36fca5 | 2011-01-06 02:04:32 +0000 | [diff] [blame] | 1224 | * Returns NULL if no such client |
| 1225 | */ |
| 1226 | struct nfs_client * |
| 1227 | nfs4_find_client_sessionid(const struct sockaddr *addr, |
Andy Adamson | 778be23 | 2011-01-25 15:38:01 +0000 | [diff] [blame] | 1228 | struct nfs4_sessionid *sid) |
Andy Adamson | c36fca5 | 2011-01-06 02:04:32 +0000 | [diff] [blame] | 1229 | { |
| 1230 | struct nfs_client *clp; |
| 1231 | |
| 1232 | spin_lock(&nfs_client_lock); |
| 1233 | list_for_each_entry(clp, &nfs_client_list, cl_share_link) { |
| 1234 | if (nfs4_cb_match_client(addr, clp, 1) == false) |
| 1235 | continue; |
| 1236 | |
| 1237 | if (!nfs4_has_session(clp)) |
| 1238 | continue; |
| 1239 | |
Andy Adamson | 778be23 | 2011-01-25 15:38:01 +0000 | [diff] [blame] | 1240 | /* Match sessionid*/ |
| 1241 | if (memcmp(clp->cl_session->sess_id.data, |
| 1242 | sid->data, NFS4_MAX_SESSIONID_LEN) != 0) |
Andy Adamson | c36fca5 | 2011-01-06 02:04:32 +0000 | [diff] [blame] | 1243 | continue; |
| 1244 | |
| 1245 | atomic_inc(&clp->cl_count); |
| 1246 | spin_unlock(&nfs_client_lock); |
| 1247 | return clp; |
| 1248 | } |
| 1249 | spin_unlock(&nfs_client_lock); |
| 1250 | return NULL; |
| 1251 | } |
| 1252 | |
| 1253 | #else /* CONFIG_NFS_V4_1 */ |
| 1254 | |
| 1255 | struct nfs_client * |
| 1256 | nfs4_find_client_sessionid(const struct sockaddr *addr, |
Andy Adamson | 778be23 | 2011-01-25 15:38:01 +0000 | [diff] [blame] | 1257 | struct nfs4_sessionid *sid) |
Andy Adamson | c36fca5 | 2011-01-06 02:04:32 +0000 | [diff] [blame] | 1258 | { |
| 1259 | return NULL; |
| 1260 | } |
| 1261 | #endif /* CONFIG_NFS_V4_1 */ |
| 1262 | |
| 1263 | /* |
Benny Halevy | 9bdaa86 | 2009-04-01 09:22:55 -0400 | [diff] [blame] | 1264 | * Initialize the NFS4 callback service |
| 1265 | */ |
| 1266 | static int nfs4_init_callback(struct nfs_client *clp) |
| 1267 | { |
| 1268 | int error; |
| 1269 | |
| 1270 | if (clp->rpc_ops->version == 4) { |
Andy Adamson | 0b5b7ae | 2009-04-01 09:23:15 -0400 | [diff] [blame] | 1271 | if (nfs4_has_session(clp)) { |
| 1272 | error = xprt_setup_backchannel( |
| 1273 | clp->cl_rpcclient->cl_xprt, |
| 1274 | NFS41_BC_MIN_CALLBACKS); |
| 1275 | if (error < 0) |
| 1276 | return error; |
| 1277 | } |
| 1278 | |
Trond Myklebust | 97dc135 | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 1279 | error = nfs_callback_up(clp->cl_mvops->minor_version, |
Benny Halevy | 7146851 | 2009-04-01 09:22:56 -0400 | [diff] [blame] | 1280 | clp->cl_rpcclient->cl_xprt); |
Benny Halevy | 9bdaa86 | 2009-04-01 09:22:55 -0400 | [diff] [blame] | 1281 | if (error < 0) { |
| 1282 | dprintk("%s: failed to start callback. Error = %d\n", |
| 1283 | __func__, error); |
| 1284 | return error; |
| 1285 | } |
| 1286 | __set_bit(NFS_CS_CALLBACK, &clp->cl_res_state); |
| 1287 | } |
| 1288 | return 0; |
| 1289 | } |
| 1290 | |
| 1291 | /* |
Andy Adamson | 557134a | 2009-04-01 09:21:53 -0400 | [diff] [blame] | 1292 | * Initialize the minor version specific parts of an NFS4 client record |
| 1293 | */ |
| 1294 | static int nfs4_init_client_minor_version(struct nfs_client *clp) |
| 1295 | { |
| 1296 | #if defined(CONFIG_NFS_V4_1) |
Trond Myklebust | 97dc135 | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 1297 | if (clp->cl_mvops->minor_version) { |
Andy Adamson | 557134a | 2009-04-01 09:21:53 -0400 | [diff] [blame] | 1298 | struct nfs4_session *session = NULL; |
| 1299 | /* |
| 1300 | * Create the session and mark it expired. |
| 1301 | * When a SEQUENCE operation encounters the expired session |
| 1302 | * it will do session recovery to initialize it. |
| 1303 | */ |
| 1304 | session = nfs4_alloc_session(clp); |
| 1305 | if (!session) |
| 1306 | return -ENOMEM; |
| 1307 | |
| 1308 | clp->cl_session = session; |
Trond Myklebust | fe74ba3 | 2010-06-16 09:52:27 -0400 | [diff] [blame] | 1309 | /* |
| 1310 | * The create session reply races with the server back |
| 1311 | * channel probe. Mark the client NFS_CS_SESSION_INITING |
| 1312 | * so that the client back channel can find the |
| 1313 | * nfs_client struct |
| 1314 | */ |
| 1315 | clp->cl_cons_state = NFS_CS_SESSION_INITING; |
Andy Adamson | 557134a | 2009-04-01 09:21:53 -0400 | [diff] [blame] | 1316 | } |
| 1317 | #endif /* CONFIG_NFS_V4_1 */ |
| 1318 | |
Benny Halevy | 7146851 | 2009-04-01 09:22:56 -0400 | [diff] [blame] | 1319 | return nfs4_init_callback(clp); |
Andy Adamson | 557134a | 2009-04-01 09:21:53 -0400 | [diff] [blame] | 1320 | } |
| 1321 | |
| 1322 | /* |
David Howells | 54ceac4 | 2006-08-22 20:06:13 -0400 | [diff] [blame] | 1323 | * Initialise an NFS4 client record |
| 1324 | */ |
Andy Adamson | 45a52a0 | 2011-03-01 01:34:08 +0000 | [diff] [blame] | 1325 | int nfs4_init_client(struct nfs_client *clp, |
| 1326 | const struct rpc_timeout *timeparms, |
| 1327 | const char *ip_addr, |
| 1328 | rpc_authflavor_t authflavour, |
| 1329 | int noresvport) |
David Howells | 54ceac4 | 2006-08-22 20:06:13 -0400 | [diff] [blame] | 1330 | { |
| 1331 | int error; |
| 1332 | |
| 1333 | if (clp->cl_cons_state == NFS_CS_READY) { |
| 1334 | /* the client is initialised already */ |
| 1335 | dprintk("<-- nfs4_init_client() = 0 [already %p]\n", clp); |
| 1336 | return 0; |
| 1337 | } |
| 1338 | |
| 1339 | /* Check NFS protocol revision and initialize RPC op vector */ |
| 1340 | clp->rpc_ops = &nfs_v4_clientops; |
| 1341 | |
Trond Myklebust | 59dca3b | 2008-01-03 16:29:06 -0500 | [diff] [blame] | 1342 | error = nfs_create_rpc_client(clp, timeparms, authflavour, |
Andy Adamson | 45a52a0 | 2011-03-01 01:34:08 +0000 | [diff] [blame] | 1343 | 1, noresvport); |
David Howells | 54ceac4 | 2006-08-22 20:06:13 -0400 | [diff] [blame] | 1344 | if (error < 0) |
| 1345 | goto error; |
Ben Hutchings | f4373bf | 2009-10-06 15:42:18 -0400 | [diff] [blame] | 1346 | strlcpy(clp->cl_ipaddr, ip_addr, sizeof(clp->cl_ipaddr)); |
David Howells | 54ceac4 | 2006-08-22 20:06:13 -0400 | [diff] [blame] | 1347 | |
| 1348 | error = nfs_idmap_new(clp); |
| 1349 | if (error < 0) { |
| 1350 | dprintk("%s: failed to create idmapper. Error = %d\n", |
Harvey Harrison | 3110ff8 | 2008-05-02 13:42:44 -0700 | [diff] [blame] | 1351 | __func__, error); |
David Howells | 54ceac4 | 2006-08-22 20:06:13 -0400 | [diff] [blame] | 1352 | goto error; |
| 1353 | } |
Trond Myklebust | 9c5bf38 | 2006-08-22 20:06:14 -0400 | [diff] [blame] | 1354 | __set_bit(NFS_CS_IDMAP, &clp->cl_res_state); |
David Howells | 54ceac4 | 2006-08-22 20:06:13 -0400 | [diff] [blame] | 1355 | |
Andy Adamson | 557134a | 2009-04-01 09:21:53 -0400 | [diff] [blame] | 1356 | error = nfs4_init_client_minor_version(clp); |
| 1357 | if (error < 0) |
| 1358 | goto error; |
| 1359 | |
Andy Adamson | 76db6d9 | 2009-04-01 09:22:38 -0400 | [diff] [blame] | 1360 | if (!nfs4_has_session(clp)) |
| 1361 | nfs_mark_client_ready(clp, NFS_CS_READY); |
David Howells | 54ceac4 | 2006-08-22 20:06:13 -0400 | [diff] [blame] | 1362 | return 0; |
| 1363 | |
| 1364 | error: |
| 1365 | nfs_mark_client_ready(clp, error); |
| 1366 | dprintk("<-- nfs4_init_client() = xerror %d\n", error); |
| 1367 | return error; |
| 1368 | } |
| 1369 | |
| 1370 | /* |
| 1371 | * Set up an NFS4 client |
| 1372 | */ |
| 1373 | static int nfs4_set_client(struct nfs_server *server, |
Chuck Lever | dcecae0 | 2007-12-10 14:58:59 -0500 | [diff] [blame] | 1374 | const char *hostname, |
| 1375 | const struct sockaddr *addr, |
| 1376 | const size_t addrlen, |
J. Bruce Fields | 7d9ac06 | 2006-10-19 23:28:39 -0700 | [diff] [blame] | 1377 | const char *ip_addr, |
David Howells | 54ceac4 | 2006-08-22 20:06:13 -0400 | [diff] [blame] | 1378 | rpc_authflavor_t authflavour, |
Benny Halevy | 94a417f | 2009-04-01 09:21:49 -0400 | [diff] [blame] | 1379 | int proto, const struct rpc_timeout *timeparms, |
| 1380 | u32 minorversion) |
David Howells | 54ceac4 | 2006-08-22 20:06:13 -0400 | [diff] [blame] | 1381 | { |
Trond Myklebust | 3a49802 | 2007-12-14 14:56:04 -0500 | [diff] [blame] | 1382 | struct nfs_client_initdata cl_init = { |
| 1383 | .hostname = hostname, |
Chuck Lever | dcecae0 | 2007-12-10 14:58:59 -0500 | [diff] [blame] | 1384 | .addr = addr, |
| 1385 | .addrlen = addrlen, |
Trond Myklebust | 40c55319 | 2007-12-14 14:56:07 -0500 | [diff] [blame] | 1386 | .rpc_ops = &nfs_v4_clientops, |
Trond Myklebust | 59dca3b | 2008-01-03 16:29:06 -0500 | [diff] [blame] | 1387 | .proto = proto, |
Benny Halevy | 5aae4a9 | 2009-04-01 09:21:50 -0400 | [diff] [blame] | 1388 | .minorversion = minorversion, |
Trond Myklebust | 3a49802 | 2007-12-14 14:56:04 -0500 | [diff] [blame] | 1389 | }; |
David Howells | 54ceac4 | 2006-08-22 20:06:13 -0400 | [diff] [blame] | 1390 | struct nfs_client *clp; |
| 1391 | int error; |
| 1392 | |
| 1393 | dprintk("--> nfs4_set_client()\n"); |
| 1394 | |
| 1395 | /* Allocate or find a client reference we can use */ |
Andy Adamson | 45a52a0 | 2011-03-01 01:34:08 +0000 | [diff] [blame] | 1396 | clp = nfs_get_client(&cl_init, timeparms, ip_addr, authflavour, |
| 1397 | server->flags & NFS_MOUNT_NORESVPORT); |
David Howells | 54ceac4 | 2006-08-22 20:06:13 -0400 | [diff] [blame] | 1398 | if (IS_ERR(clp)) { |
| 1399 | error = PTR_ERR(clp); |
| 1400 | goto error; |
| 1401 | } |
David Howells | 54ceac4 | 2006-08-22 20:06:13 -0400 | [diff] [blame] | 1402 | |
| 1403 | server->nfs_client = clp; |
| 1404 | dprintk("<-- nfs4_set_client() = 0 [new %p]\n", clp); |
| 1405 | return 0; |
David Howells | 54ceac4 | 2006-08-22 20:06:13 -0400 | [diff] [blame] | 1406 | error: |
| 1407 | dprintk("<-- nfs4_set_client() = xerror %d\n", error); |
| 1408 | return error; |
| 1409 | } |
| 1410 | |
Andy Adamson | 557134a | 2009-04-01 09:21:53 -0400 | [diff] [blame] | 1411 | |
| 1412 | /* |
Andy Adamson | 96b09e0 | 2009-04-01 09:22:33 -0400 | [diff] [blame] | 1413 | * Session has been established, and the client marked ready. |
| 1414 | * Set the mount rsize and wsize with negotiated fore channel |
| 1415 | * attributes which will be bound checked in nfs_server_set_fsinfo. |
| 1416 | */ |
| 1417 | static void nfs4_session_set_rwsize(struct nfs_server *server) |
| 1418 | { |
| 1419 | #ifdef CONFIG_NFS_V4_1 |
Alexandros Batsakis | 2449ea2 | 2009-12-05 13:36:55 -0500 | [diff] [blame] | 1420 | struct nfs4_session *sess; |
| 1421 | u32 server_resp_sz; |
| 1422 | u32 server_rqst_sz; |
| 1423 | |
Andy Adamson | 96b09e0 | 2009-04-01 09:22:33 -0400 | [diff] [blame] | 1424 | if (!nfs4_has_session(server->nfs_client)) |
| 1425 | return; |
Alexandros Batsakis | 2449ea2 | 2009-12-05 13:36:55 -0500 | [diff] [blame] | 1426 | sess = server->nfs_client->cl_session; |
| 1427 | server_resp_sz = sess->fc_attrs.max_resp_sz - nfs41_maxread_overhead; |
| 1428 | server_rqst_sz = sess->fc_attrs.max_rqst_sz - nfs41_maxwrite_overhead; |
| 1429 | |
| 1430 | if (server->rsize > server_resp_sz) |
| 1431 | server->rsize = server_resp_sz; |
| 1432 | if (server->wsize > server_rqst_sz) |
| 1433 | server->wsize = server_rqst_sz; |
Andy Adamson | 96b09e0 | 2009-04-01 09:22:33 -0400 | [diff] [blame] | 1434 | #endif /* CONFIG_NFS_V4_1 */ |
| 1435 | } |
| 1436 | |
Trond Myklebust | 44950b6 | 2010-06-17 11:45:12 -0400 | [diff] [blame] | 1437 | static int nfs4_server_common_setup(struct nfs_server *server, |
| 1438 | struct nfs_fh *mntfh) |
| 1439 | { |
| 1440 | struct nfs_fattr *fattr; |
| 1441 | int error; |
| 1442 | |
| 1443 | BUG_ON(!server->nfs_client); |
| 1444 | BUG_ON(!server->nfs_client->rpc_ops); |
| 1445 | BUG_ON(!server->nfs_client->rpc_ops->file_inode_ops); |
| 1446 | |
| 1447 | fattr = nfs_alloc_fattr(); |
| 1448 | if (fattr == NULL) |
| 1449 | return -ENOMEM; |
| 1450 | |
| 1451 | /* We must ensure the session is initialised first */ |
| 1452 | error = nfs4_init_session(server); |
| 1453 | if (error < 0) |
| 1454 | goto out; |
| 1455 | |
| 1456 | /* Probe the root fh to retrieve its FSID and filehandle */ |
| 1457 | error = nfs4_get_rootfh(server, mntfh); |
| 1458 | if (error < 0) |
| 1459 | goto out; |
| 1460 | |
| 1461 | dprintk("Server FSID: %llx:%llx\n", |
| 1462 | (unsigned long long) server->fsid.major, |
| 1463 | (unsigned long long) server->fsid.minor); |
| 1464 | dprintk("Mount FH: %d\n", mntfh->size); |
| 1465 | |
| 1466 | nfs4_session_set_rwsize(server); |
| 1467 | |
| 1468 | error = nfs_probe_fsinfo(server, mntfh, fattr); |
| 1469 | if (error < 0) |
| 1470 | goto out; |
| 1471 | |
| 1472 | if (server->namelen == 0 || server->namelen > NFS4_MAXNAMLEN) |
| 1473 | server->namelen = NFS4_MAXNAMLEN; |
| 1474 | |
Chuck Lever | fca5238 | 2010-12-24 01:32:32 +0000 | [diff] [blame] | 1475 | nfs_server_insert_lists(server); |
Trond Myklebust | 44950b6 | 2010-06-17 11:45:12 -0400 | [diff] [blame] | 1476 | server->mount_time = jiffies; |
| 1477 | out: |
| 1478 | nfs_free_fattr(fattr); |
| 1479 | return error; |
| 1480 | } |
| 1481 | |
Andy Adamson | 96b09e0 | 2009-04-01 09:22:33 -0400 | [diff] [blame] | 1482 | /* |
David Howells | 54ceac4 | 2006-08-22 20:06:13 -0400 | [diff] [blame] | 1483 | * Create a version 4 volume record |
| 1484 | */ |
| 1485 | static int nfs4_init_server(struct nfs_server *server, |
\"Talpey, Thomas\ | 91ea40b | 2007-09-10 13:44:33 -0400 | [diff] [blame] | 1486 | const struct nfs_parsed_mount_data *data) |
David Howells | 54ceac4 | 2006-08-22 20:06:13 -0400 | [diff] [blame] | 1487 | { |
Trond Myklebust | 3317023 | 2007-12-20 16:03:59 -0500 | [diff] [blame] | 1488 | struct rpc_timeout timeparms; |
David Howells | 54ceac4 | 2006-08-22 20:06:13 -0400 | [diff] [blame] | 1489 | int error; |
| 1490 | |
| 1491 | dprintk("--> nfs4_init_server()\n"); |
| 1492 | |
Trond Myklebust | 3317023 | 2007-12-20 16:03:59 -0500 | [diff] [blame] | 1493 | nfs_init_timeout_values(&timeparms, data->nfs_server.protocol, |
| 1494 | data->timeo, data->retrans); |
| 1495 | |
Chuck Lever | 542fcc3 | 2008-12-23 15:21:36 -0500 | [diff] [blame] | 1496 | /* Initialise the client representation from the mount data */ |
| 1497 | server->flags = data->flags; |
Bryan Schumaker | 82f2e54 | 2010-10-21 16:33:18 -0400 | [diff] [blame] | 1498 | server->caps |= NFS_CAP_ATOMIC_OPEN|NFS_CAP_CHANGE_ATTR|NFS_CAP_POSIX_LOCK; |
| 1499 | if (!(data->flags & NFS_MOUNT_NORDIRPLUS)) |
| 1500 | server->caps |= NFS_CAP_READDIRPLUS; |
David Howells | b797cac | 2009-04-03 16:42:48 +0100 | [diff] [blame] | 1501 | server->options = data->options; |
Chuck Lever | 542fcc3 | 2008-12-23 15:21:36 -0500 | [diff] [blame] | 1502 | |
Trond Myklebust | 3317023 | 2007-12-20 16:03:59 -0500 | [diff] [blame] | 1503 | /* Get a client record */ |
| 1504 | error = nfs4_set_client(server, |
| 1505 | data->nfs_server.hostname, |
| 1506 | (const struct sockaddr *)&data->nfs_server.address, |
| 1507 | data->nfs_server.addrlen, |
| 1508 | data->client_address, |
| 1509 | data->auth_flavors[0], |
| 1510 | data->nfs_server.protocol, |
Benny Halevy | 94a417f | 2009-04-01 09:21:49 -0400 | [diff] [blame] | 1511 | &timeparms, |
| 1512 | data->minorversion); |
Trond Myklebust | 3317023 | 2007-12-20 16:03:59 -0500 | [diff] [blame] | 1513 | if (error < 0) |
| 1514 | goto error; |
| 1515 | |
David Howells | 54ceac4 | 2006-08-22 20:06:13 -0400 | [diff] [blame] | 1516 | if (data->rsize) |
| 1517 | server->rsize = nfs_block_size(data->rsize, NULL); |
| 1518 | if (data->wsize) |
| 1519 | server->wsize = nfs_block_size(data->wsize, NULL); |
| 1520 | |
| 1521 | server->acregmin = data->acregmin * HZ; |
| 1522 | server->acregmax = data->acregmax * HZ; |
| 1523 | server->acdirmin = data->acdirmin * HZ; |
| 1524 | server->acdirmax = data->acdirmax * HZ; |
| 1525 | |
Chuck Lever | f22d6d7 | 2008-03-14 14:10:22 -0400 | [diff] [blame] | 1526 | server->port = data->nfs_server.port; |
| 1527 | |
Trond Myklebust | 3317023 | 2007-12-20 16:03:59 -0500 | [diff] [blame] | 1528 | error = nfs_init_server_rpcclient(server, &timeparms, data->auth_flavors[0]); |
David Howells | 54ceac4 | 2006-08-22 20:06:13 -0400 | [diff] [blame] | 1529 | |
Trond Myklebust | 3317023 | 2007-12-20 16:03:59 -0500 | [diff] [blame] | 1530 | error: |
David Howells | 54ceac4 | 2006-08-22 20:06:13 -0400 | [diff] [blame] | 1531 | /* Done */ |
| 1532 | dprintk("<-- nfs4_init_server() = %d\n", error); |
| 1533 | return error; |
| 1534 | } |
| 1535 | |
| 1536 | /* |
| 1537 | * Create a version 4 volume record |
| 1538 | * - keyed on server and FSID |
| 1539 | */ |
\"Talpey, Thomas\ | 91ea40b | 2007-09-10 13:44:33 -0400 | [diff] [blame] | 1540 | 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] | 1541 | struct nfs_fh *mntfh) |
| 1542 | { |
David Howells | 54ceac4 | 2006-08-22 20:06:13 -0400 | [diff] [blame] | 1543 | struct nfs_server *server; |
| 1544 | int error; |
| 1545 | |
| 1546 | dprintk("--> nfs4_create_server()\n"); |
| 1547 | |
| 1548 | server = nfs_alloc_server(); |
| 1549 | if (!server) |
| 1550 | return ERR_PTR(-ENOMEM); |
| 1551 | |
David Howells | 54ceac4 | 2006-08-22 20:06:13 -0400 | [diff] [blame] | 1552 | /* set up the general RPC client */ |
\"Talpey, Thomas\ | 91ea40b | 2007-09-10 13:44:33 -0400 | [diff] [blame] | 1553 | error = nfs4_init_server(server, data); |
David Howells | 54ceac4 | 2006-08-22 20:06:13 -0400 | [diff] [blame] | 1554 | if (error < 0) |
| 1555 | goto error; |
| 1556 | |
Trond Myklebust | 44950b6 | 2010-06-17 11:45:12 -0400 | [diff] [blame] | 1557 | error = nfs4_server_common_setup(server, mntfh); |
Trond Myklebust | fccba80 | 2009-07-21 16:48:07 -0400 | [diff] [blame] | 1558 | if (error < 0) |
| 1559 | goto error; |
Andy Adamson | 557134a | 2009-04-01 09:21:53 -0400 | [diff] [blame] | 1560 | |
David Howells | 54ceac4 | 2006-08-22 20:06:13 -0400 | [diff] [blame] | 1561 | dprintk("<-- nfs4_create_server() = %p\n", server); |
| 1562 | return server; |
| 1563 | |
| 1564 | error: |
| 1565 | nfs_free_server(server); |
| 1566 | dprintk("<-- nfs4_create_server() = error %d\n", error); |
| 1567 | return ERR_PTR(error); |
| 1568 | } |
| 1569 | |
| 1570 | /* |
| 1571 | * Create an NFS4 referral server record |
| 1572 | */ |
| 1573 | struct nfs_server *nfs4_create_referral_server(struct nfs_clone_mount *data, |
Trond Myklebust | f2d0d85 | 2007-02-02 14:46:09 -0800 | [diff] [blame] | 1574 | struct nfs_fh *mntfh) |
David Howells | 54ceac4 | 2006-08-22 20:06:13 -0400 | [diff] [blame] | 1575 | { |
| 1576 | struct nfs_client *parent_client; |
| 1577 | struct nfs_server *server, *parent_server; |
David Howells | 54ceac4 | 2006-08-22 20:06:13 -0400 | [diff] [blame] | 1578 | int error; |
| 1579 | |
| 1580 | dprintk("--> nfs4_create_referral_server()\n"); |
| 1581 | |
| 1582 | server = nfs_alloc_server(); |
| 1583 | if (!server) |
| 1584 | return ERR_PTR(-ENOMEM); |
| 1585 | |
| 1586 | parent_server = NFS_SB(data->sb); |
| 1587 | parent_client = parent_server->nfs_client; |
| 1588 | |
Chuck Lever | 542fcc3 | 2008-12-23 15:21:36 -0500 | [diff] [blame] | 1589 | /* Initialise the client representation from the parent server */ |
| 1590 | nfs_server_copy_userdata(server, parent_server); |
Trond Myklebust | 62ab460c | 2009-08-09 15:06:19 -0400 | [diff] [blame] | 1591 | server->caps |= NFS_CAP_ATOMIC_OPEN|NFS_CAP_CHANGE_ATTR; |
Chuck Lever | 542fcc3 | 2008-12-23 15:21:36 -0500 | [diff] [blame] | 1592 | |
David Howells | 54ceac4 | 2006-08-22 20:06:13 -0400 | [diff] [blame] | 1593 | /* Get a client representation. |
| 1594 | * Note: NFSv4 always uses TCP, */ |
Chuck Lever | dcecae0 | 2007-12-10 14:58:59 -0500 | [diff] [blame] | 1595 | error = nfs4_set_client(server, data->hostname, |
Chuck Lever | 6677d09 | 2007-12-10 14:59:06 -0500 | [diff] [blame] | 1596 | data->addr, |
| 1597 | data->addrlen, |
Chuck Lever | dcecae0 | 2007-12-10 14:58:59 -0500 | [diff] [blame] | 1598 | parent_client->cl_ipaddr, |
| 1599 | data->authflavor, |
| 1600 | parent_server->client->cl_xprt->prot, |
Benny Halevy | 94a417f | 2009-04-01 09:21:49 -0400 | [diff] [blame] | 1601 | parent_server->client->cl_timeout, |
Trond Myklebust | 97dc135 | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 1602 | parent_client->cl_mvops->minor_version); |
andros@citi.umich.edu | 297de4f | 2006-08-29 12:19:41 -0400 | [diff] [blame] | 1603 | if (error < 0) |
| 1604 | goto error; |
David Howells | 54ceac4 | 2006-08-22 20:06:13 -0400 | [diff] [blame] | 1605 | |
Trond Myklebust | 3317023 | 2007-12-20 16:03:59 -0500 | [diff] [blame] | 1606 | 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] | 1607 | if (error < 0) |
| 1608 | goto error; |
| 1609 | |
Trond Myklebust | 44950b6 | 2010-06-17 11:45:12 -0400 | [diff] [blame] | 1610 | error = nfs4_server_common_setup(server, mntfh); |
Trond Myklebust | f2d0d85 | 2007-02-02 14:46:09 -0800 | [diff] [blame] | 1611 | if (error < 0) |
| 1612 | goto error; |
| 1613 | |
David Howells | 54ceac4 | 2006-08-22 20:06:13 -0400 | [diff] [blame] | 1614 | dprintk("<-- nfs_create_referral_server() = %p\n", server); |
| 1615 | return server; |
| 1616 | |
| 1617 | error: |
| 1618 | nfs_free_server(server); |
| 1619 | dprintk("<-- nfs4_create_referral_server() = error %d\n", error); |
| 1620 | return ERR_PTR(error); |
| 1621 | } |
| 1622 | |
| 1623 | #endif /* CONFIG_NFS_V4 */ |
| 1624 | |
| 1625 | /* |
| 1626 | * Clone an NFS2, NFS3 or NFS4 server record |
| 1627 | */ |
| 1628 | struct nfs_server *nfs_clone_server(struct nfs_server *source, |
| 1629 | struct nfs_fh *fh, |
| 1630 | struct nfs_fattr *fattr) |
| 1631 | { |
| 1632 | struct nfs_server *server; |
Trond Myklebust | fbca779 | 2010-04-16 16:22:46 -0400 | [diff] [blame] | 1633 | struct nfs_fattr *fattr_fsinfo; |
David Howells | 54ceac4 | 2006-08-22 20:06:13 -0400 | [diff] [blame] | 1634 | int error; |
| 1635 | |
| 1636 | dprintk("--> nfs_clone_server(,%llx:%llx,)\n", |
David Howells | 6daabf1 | 2006-08-24 15:44:16 -0400 | [diff] [blame] | 1637 | (unsigned long long) fattr->fsid.major, |
| 1638 | (unsigned long long) fattr->fsid.minor); |
David Howells | 54ceac4 | 2006-08-22 20:06:13 -0400 | [diff] [blame] | 1639 | |
| 1640 | server = nfs_alloc_server(); |
| 1641 | if (!server) |
| 1642 | return ERR_PTR(-ENOMEM); |
| 1643 | |
Trond Myklebust | fbca779 | 2010-04-16 16:22:46 -0400 | [diff] [blame] | 1644 | error = -ENOMEM; |
| 1645 | fattr_fsinfo = nfs_alloc_fattr(); |
| 1646 | if (fattr_fsinfo == NULL) |
| 1647 | goto out_free_server; |
| 1648 | |
David Howells | 54ceac4 | 2006-08-22 20:06:13 -0400 | [diff] [blame] | 1649 | /* Copy data from the source */ |
| 1650 | server->nfs_client = source->nfs_client; |
| 1651 | atomic_inc(&server->nfs_client->cl_count); |
| 1652 | nfs_server_copy_userdata(server, source); |
| 1653 | |
| 1654 | server->fsid = fattr->fsid; |
| 1655 | |
Trond Myklebust | 3317023 | 2007-12-20 16:03:59 -0500 | [diff] [blame] | 1656 | error = nfs_init_server_rpcclient(server, |
| 1657 | source->client->cl_timeout, |
| 1658 | source->client->cl_auth->au_flavor); |
David Howells | 54ceac4 | 2006-08-22 20:06:13 -0400 | [diff] [blame] | 1659 | if (error < 0) |
| 1660 | goto out_free_server; |
| 1661 | if (!IS_ERR(source->client_acl)) |
| 1662 | nfs_init_server_aclclient(server); |
| 1663 | |
| 1664 | /* probe the filesystem info for this server filesystem */ |
Trond Myklebust | fbca779 | 2010-04-16 16:22:46 -0400 | [diff] [blame] | 1665 | error = nfs_probe_fsinfo(server, fh, fattr_fsinfo); |
David Howells | 54ceac4 | 2006-08-22 20:06:13 -0400 | [diff] [blame] | 1666 | if (error < 0) |
| 1667 | goto out_free_server; |
| 1668 | |
Trond Myklebust | 54af3bb | 2007-09-28 12:27:41 -0400 | [diff] [blame] | 1669 | if (server->namelen == 0 || server->namelen > NFS4_MAXNAMLEN) |
| 1670 | server->namelen = NFS4_MAXNAMLEN; |
| 1671 | |
David Howells | 54ceac4 | 2006-08-22 20:06:13 -0400 | [diff] [blame] | 1672 | dprintk("Cloned FSID: %llx:%llx\n", |
David Howells | 6daabf1 | 2006-08-24 15:44:16 -0400 | [diff] [blame] | 1673 | (unsigned long long) server->fsid.major, |
| 1674 | (unsigned long long) server->fsid.minor); |
David Howells | 54ceac4 | 2006-08-22 20:06:13 -0400 | [diff] [blame] | 1675 | |
| 1676 | error = nfs_start_lockd(server); |
| 1677 | if (error < 0) |
| 1678 | goto out_free_server; |
| 1679 | |
Chuck Lever | fca5238 | 2010-12-24 01:32:32 +0000 | [diff] [blame] | 1680 | nfs_server_insert_lists(server); |
David Howells | 54ceac4 | 2006-08-22 20:06:13 -0400 | [diff] [blame] | 1681 | server->mount_time = jiffies; |
| 1682 | |
Trond Myklebust | fbca779 | 2010-04-16 16:22:46 -0400 | [diff] [blame] | 1683 | nfs_free_fattr(fattr_fsinfo); |
David Howells | 54ceac4 | 2006-08-22 20:06:13 -0400 | [diff] [blame] | 1684 | dprintk("<-- nfs_clone_server() = %p\n", server); |
| 1685 | return server; |
| 1686 | |
| 1687 | out_free_server: |
Trond Myklebust | fbca779 | 2010-04-16 16:22:46 -0400 | [diff] [blame] | 1688 | nfs_free_fattr(fattr_fsinfo); |
David Howells | 54ceac4 | 2006-08-22 20:06:13 -0400 | [diff] [blame] | 1689 | nfs_free_server(server); |
| 1690 | dprintk("<-- nfs_clone_server() = error %d\n", error); |
| 1691 | return ERR_PTR(error); |
| 1692 | } |
David Howells | 6aaca56 | 2006-08-22 20:06:13 -0400 | [diff] [blame] | 1693 | |
| 1694 | #ifdef CONFIG_PROC_FS |
| 1695 | static struct proc_dir_entry *proc_fs_nfs; |
| 1696 | |
| 1697 | static int nfs_server_list_open(struct inode *inode, struct file *file); |
| 1698 | static void *nfs_server_list_start(struct seq_file *p, loff_t *pos); |
| 1699 | static void *nfs_server_list_next(struct seq_file *p, void *v, loff_t *pos); |
| 1700 | static void nfs_server_list_stop(struct seq_file *p, void *v); |
| 1701 | static int nfs_server_list_show(struct seq_file *m, void *v); |
| 1702 | |
James Morris | 88e9d34 | 2009-09-22 16:43:43 -0700 | [diff] [blame] | 1703 | static const struct seq_operations nfs_server_list_ops = { |
David Howells | 6aaca56 | 2006-08-22 20:06:13 -0400 | [diff] [blame] | 1704 | .start = nfs_server_list_start, |
| 1705 | .next = nfs_server_list_next, |
| 1706 | .stop = nfs_server_list_stop, |
| 1707 | .show = nfs_server_list_show, |
| 1708 | }; |
| 1709 | |
Arjan van de Ven | 00977a5 | 2007-02-12 00:55:34 -0800 | [diff] [blame] | 1710 | static const struct file_operations nfs_server_list_fops = { |
David Howells | 6aaca56 | 2006-08-22 20:06:13 -0400 | [diff] [blame] | 1711 | .open = nfs_server_list_open, |
| 1712 | .read = seq_read, |
| 1713 | .llseek = seq_lseek, |
| 1714 | .release = seq_release, |
Denis V. Lunev | 34b3723 | 2008-04-29 01:02:07 -0700 | [diff] [blame] | 1715 | .owner = THIS_MODULE, |
David Howells | 6aaca56 | 2006-08-22 20:06:13 -0400 | [diff] [blame] | 1716 | }; |
| 1717 | |
| 1718 | static int nfs_volume_list_open(struct inode *inode, struct file *file); |
| 1719 | static void *nfs_volume_list_start(struct seq_file *p, loff_t *pos); |
| 1720 | static void *nfs_volume_list_next(struct seq_file *p, void *v, loff_t *pos); |
| 1721 | static void nfs_volume_list_stop(struct seq_file *p, void *v); |
| 1722 | static int nfs_volume_list_show(struct seq_file *m, void *v); |
| 1723 | |
James Morris | 88e9d34 | 2009-09-22 16:43:43 -0700 | [diff] [blame] | 1724 | static const struct seq_operations nfs_volume_list_ops = { |
David Howells | 6aaca56 | 2006-08-22 20:06:13 -0400 | [diff] [blame] | 1725 | .start = nfs_volume_list_start, |
| 1726 | .next = nfs_volume_list_next, |
| 1727 | .stop = nfs_volume_list_stop, |
| 1728 | .show = nfs_volume_list_show, |
| 1729 | }; |
| 1730 | |
Arjan van de Ven | 00977a5 | 2007-02-12 00:55:34 -0800 | [diff] [blame] | 1731 | static const struct file_operations nfs_volume_list_fops = { |
David Howells | 6aaca56 | 2006-08-22 20:06:13 -0400 | [diff] [blame] | 1732 | .open = nfs_volume_list_open, |
| 1733 | .read = seq_read, |
| 1734 | .llseek = seq_lseek, |
| 1735 | .release = seq_release, |
Denis V. Lunev | 34b3723 | 2008-04-29 01:02:07 -0700 | [diff] [blame] | 1736 | .owner = THIS_MODULE, |
David Howells | 6aaca56 | 2006-08-22 20:06:13 -0400 | [diff] [blame] | 1737 | }; |
| 1738 | |
| 1739 | /* |
| 1740 | * open "/proc/fs/nfsfs/servers" which provides a summary of servers with which |
| 1741 | * we're dealing |
| 1742 | */ |
| 1743 | static int nfs_server_list_open(struct inode *inode, struct file *file) |
| 1744 | { |
| 1745 | struct seq_file *m; |
| 1746 | int ret; |
| 1747 | |
| 1748 | ret = seq_open(file, &nfs_server_list_ops); |
| 1749 | if (ret < 0) |
| 1750 | return ret; |
| 1751 | |
| 1752 | m = file->private_data; |
| 1753 | m->private = PDE(inode)->data; |
| 1754 | |
| 1755 | return 0; |
| 1756 | } |
| 1757 | |
| 1758 | /* |
| 1759 | * set up the iterator to start reading from the server list and return the first item |
| 1760 | */ |
| 1761 | static void *nfs_server_list_start(struct seq_file *m, loff_t *_pos) |
| 1762 | { |
David Howells | 6aaca56 | 2006-08-22 20:06:13 -0400 | [diff] [blame] | 1763 | /* lock the list against modification */ |
| 1764 | spin_lock(&nfs_client_lock); |
Pavel Emelianov | 259902e | 2007-07-15 23:39:56 -0700 | [diff] [blame] | 1765 | return seq_list_start_head(&nfs_client_list, *_pos); |
David Howells | 6aaca56 | 2006-08-22 20:06:13 -0400 | [diff] [blame] | 1766 | } |
| 1767 | |
| 1768 | /* |
| 1769 | * move to next server |
| 1770 | */ |
| 1771 | static void *nfs_server_list_next(struct seq_file *p, void *v, loff_t *pos) |
| 1772 | { |
Pavel Emelianov | 259902e | 2007-07-15 23:39:56 -0700 | [diff] [blame] | 1773 | return seq_list_next(v, &nfs_client_list, pos); |
David Howells | 6aaca56 | 2006-08-22 20:06:13 -0400 | [diff] [blame] | 1774 | } |
| 1775 | |
| 1776 | /* |
| 1777 | * clean up after reading from the transports list |
| 1778 | */ |
| 1779 | static void nfs_server_list_stop(struct seq_file *p, void *v) |
| 1780 | { |
| 1781 | spin_unlock(&nfs_client_lock); |
| 1782 | } |
| 1783 | |
| 1784 | /* |
| 1785 | * display a header line followed by a load of call lines |
| 1786 | */ |
| 1787 | static int nfs_server_list_show(struct seq_file *m, void *v) |
| 1788 | { |
| 1789 | struct nfs_client *clp; |
| 1790 | |
| 1791 | /* display header on line 1 */ |
Pavel Emelianov | 259902e | 2007-07-15 23:39:56 -0700 | [diff] [blame] | 1792 | if (v == &nfs_client_list) { |
David Howells | 6aaca56 | 2006-08-22 20:06:13 -0400 | [diff] [blame] | 1793 | seq_puts(m, "NV SERVER PORT USE HOSTNAME\n"); |
| 1794 | return 0; |
| 1795 | } |
| 1796 | |
| 1797 | /* display one transport per line on subsequent lines */ |
| 1798 | clp = list_entry(v, struct nfs_client, cl_share_link); |
| 1799 | |
Chuck Lever | 5d8515c | 2007-12-10 14:57:16 -0500 | [diff] [blame] | 1800 | seq_printf(m, "v%u %s %s %3d %s\n", |
Trond Myklebust | 40c55319 | 2007-12-14 14:56:07 -0500 | [diff] [blame] | 1801 | clp->rpc_ops->version, |
Chuck Lever | 5d8515c | 2007-12-10 14:57:16 -0500 | [diff] [blame] | 1802 | rpc_peeraddr2str(clp->cl_rpcclient, RPC_DISPLAY_HEX_ADDR), |
| 1803 | rpc_peeraddr2str(clp->cl_rpcclient, RPC_DISPLAY_HEX_PORT), |
David Howells | 6aaca56 | 2006-08-22 20:06:13 -0400 | [diff] [blame] | 1804 | atomic_read(&clp->cl_count), |
| 1805 | clp->cl_hostname); |
| 1806 | |
| 1807 | return 0; |
| 1808 | } |
| 1809 | |
| 1810 | /* |
| 1811 | * open "/proc/fs/nfsfs/volumes" which provides a summary of extant volumes |
| 1812 | */ |
| 1813 | static int nfs_volume_list_open(struct inode *inode, struct file *file) |
| 1814 | { |
| 1815 | struct seq_file *m; |
| 1816 | int ret; |
| 1817 | |
| 1818 | ret = seq_open(file, &nfs_volume_list_ops); |
| 1819 | if (ret < 0) |
| 1820 | return ret; |
| 1821 | |
| 1822 | m = file->private_data; |
| 1823 | m->private = PDE(inode)->data; |
| 1824 | |
| 1825 | return 0; |
| 1826 | } |
| 1827 | |
| 1828 | /* |
| 1829 | * set up the iterator to start reading from the volume list and return the first item |
| 1830 | */ |
| 1831 | static void *nfs_volume_list_start(struct seq_file *m, loff_t *_pos) |
| 1832 | { |
David Howells | 6aaca56 | 2006-08-22 20:06:13 -0400 | [diff] [blame] | 1833 | /* lock the list against modification */ |
| 1834 | spin_lock(&nfs_client_lock); |
Pavel Emelianov | 259902e | 2007-07-15 23:39:56 -0700 | [diff] [blame] | 1835 | return seq_list_start_head(&nfs_volume_list, *_pos); |
David Howells | 6aaca56 | 2006-08-22 20:06:13 -0400 | [diff] [blame] | 1836 | } |
| 1837 | |
| 1838 | /* |
| 1839 | * move to next volume |
| 1840 | */ |
| 1841 | static void *nfs_volume_list_next(struct seq_file *p, void *v, loff_t *pos) |
| 1842 | { |
Pavel Emelianov | 259902e | 2007-07-15 23:39:56 -0700 | [diff] [blame] | 1843 | return seq_list_next(v, &nfs_volume_list, pos); |
David Howells | 6aaca56 | 2006-08-22 20:06:13 -0400 | [diff] [blame] | 1844 | } |
| 1845 | |
| 1846 | /* |
| 1847 | * clean up after reading from the transports list |
| 1848 | */ |
| 1849 | static void nfs_volume_list_stop(struct seq_file *p, void *v) |
| 1850 | { |
| 1851 | spin_unlock(&nfs_client_lock); |
| 1852 | } |
| 1853 | |
| 1854 | /* |
| 1855 | * display a header line followed by a load of call lines |
| 1856 | */ |
| 1857 | static int nfs_volume_list_show(struct seq_file *m, void *v) |
| 1858 | { |
| 1859 | struct nfs_server *server; |
| 1860 | struct nfs_client *clp; |
| 1861 | char dev[8], fsid[17]; |
| 1862 | |
| 1863 | /* display header on line 1 */ |
Pavel Emelianov | 259902e | 2007-07-15 23:39:56 -0700 | [diff] [blame] | 1864 | if (v == &nfs_volume_list) { |
David Howells | 5d1acff | 2009-04-03 16:42:47 +0100 | [diff] [blame] | 1865 | seq_puts(m, "NV SERVER PORT DEV FSID FSC\n"); |
David Howells | 6aaca56 | 2006-08-22 20:06:13 -0400 | [diff] [blame] | 1866 | return 0; |
| 1867 | } |
| 1868 | /* display one transport per line on subsequent lines */ |
| 1869 | server = list_entry(v, struct nfs_server, master_link); |
| 1870 | clp = server->nfs_client; |
| 1871 | |
| 1872 | snprintf(dev, 8, "%u:%u", |
| 1873 | MAJOR(server->s_dev), MINOR(server->s_dev)); |
| 1874 | |
| 1875 | snprintf(fsid, 17, "%llx:%llx", |
David Howells | 6daabf1 | 2006-08-24 15:44:16 -0400 | [diff] [blame] | 1876 | (unsigned long long) server->fsid.major, |
| 1877 | (unsigned long long) server->fsid.minor); |
David Howells | 6aaca56 | 2006-08-22 20:06:13 -0400 | [diff] [blame] | 1878 | |
David Howells | 5d1acff | 2009-04-03 16:42:47 +0100 | [diff] [blame] | 1879 | seq_printf(m, "v%u %s %s %-7s %-17s %s\n", |
Trond Myklebust | 40c55319 | 2007-12-14 14:56:07 -0500 | [diff] [blame] | 1880 | clp->rpc_ops->version, |
Chuck Lever | 5d8515c | 2007-12-10 14:57:16 -0500 | [diff] [blame] | 1881 | rpc_peeraddr2str(clp->cl_rpcclient, RPC_DISPLAY_HEX_ADDR), |
| 1882 | rpc_peeraddr2str(clp->cl_rpcclient, RPC_DISPLAY_HEX_PORT), |
David Howells | 6aaca56 | 2006-08-22 20:06:13 -0400 | [diff] [blame] | 1883 | dev, |
David Howells | 5d1acff | 2009-04-03 16:42:47 +0100 | [diff] [blame] | 1884 | fsid, |
| 1885 | nfs_server_fscache_state(server)); |
David Howells | 6aaca56 | 2006-08-22 20:06:13 -0400 | [diff] [blame] | 1886 | |
| 1887 | return 0; |
| 1888 | } |
| 1889 | |
| 1890 | /* |
| 1891 | * initialise the /proc/fs/nfsfs/ directory |
| 1892 | */ |
| 1893 | int __init nfs_fs_proc_init(void) |
| 1894 | { |
| 1895 | struct proc_dir_entry *p; |
| 1896 | |
Alexey Dobriyan | 36a5aeb | 2008-04-29 01:01:42 -0700 | [diff] [blame] | 1897 | proc_fs_nfs = proc_mkdir("fs/nfsfs", NULL); |
David Howells | 6aaca56 | 2006-08-22 20:06:13 -0400 | [diff] [blame] | 1898 | if (!proc_fs_nfs) |
| 1899 | goto error_0; |
| 1900 | |
David Howells | 6aaca56 | 2006-08-22 20:06:13 -0400 | [diff] [blame] | 1901 | /* a file of servers with which we're dealing */ |
Denis V. Lunev | 34b3723 | 2008-04-29 01:02:07 -0700 | [diff] [blame] | 1902 | p = proc_create("servers", S_IFREG|S_IRUGO, |
| 1903 | proc_fs_nfs, &nfs_server_list_fops); |
David Howells | 6aaca56 | 2006-08-22 20:06:13 -0400 | [diff] [blame] | 1904 | if (!p) |
| 1905 | goto error_1; |
| 1906 | |
David Howells | 6aaca56 | 2006-08-22 20:06:13 -0400 | [diff] [blame] | 1907 | /* a file of volumes that we have mounted */ |
Denis V. Lunev | 34b3723 | 2008-04-29 01:02:07 -0700 | [diff] [blame] | 1908 | p = proc_create("volumes", S_IFREG|S_IRUGO, |
| 1909 | proc_fs_nfs, &nfs_volume_list_fops); |
David Howells | 6aaca56 | 2006-08-22 20:06:13 -0400 | [diff] [blame] | 1910 | if (!p) |
| 1911 | goto error_2; |
David Howells | 6aaca56 | 2006-08-22 20:06:13 -0400 | [diff] [blame] | 1912 | return 0; |
| 1913 | |
| 1914 | error_2: |
| 1915 | remove_proc_entry("servers", proc_fs_nfs); |
| 1916 | error_1: |
Alexey Dobriyan | 36a5aeb | 2008-04-29 01:01:42 -0700 | [diff] [blame] | 1917 | remove_proc_entry("fs/nfsfs", NULL); |
David Howells | 6aaca56 | 2006-08-22 20:06:13 -0400 | [diff] [blame] | 1918 | error_0: |
| 1919 | return -ENOMEM; |
| 1920 | } |
| 1921 | |
| 1922 | /* |
| 1923 | * clean up the /proc/fs/nfsfs/ directory |
| 1924 | */ |
| 1925 | void nfs_fs_proc_exit(void) |
| 1926 | { |
| 1927 | remove_proc_entry("volumes", proc_fs_nfs); |
| 1928 | remove_proc_entry("servers", proc_fs_nfs); |
Alexey Dobriyan | 36a5aeb | 2008-04-29 01:01:42 -0700 | [diff] [blame] | 1929 | remove_proc_entry("fs/nfsfs", NULL); |
David Howells | 6aaca56 | 2006-08-22 20:06:13 -0400 | [diff] [blame] | 1930 | } |
| 1931 | |
| 1932 | #endif /* CONFIG_PROC_FS */ |