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