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