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