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