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