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