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