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