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 13 #include <linux/module.h> 14 #include <linux/init.h> 15 #include <linux/sched.h> 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/sunrpc/xprtsock.h> 27 #include <linux/sunrpc/xprtrdma.h> 28 #include <linux/nfs_fs.h> 29 #include <linux/nfs_mount.h> 30 #include <linux/nfs4_mount.h> 31 #include <linux/lockd/bind.h> 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/in6.h> 38 #include <linux/slab.h> 39 #include <linux/idr.h> 40 #include <net/ipv6.h> 41 #include <linux/nfs_xdr.h> 42 #include <linux/sunrpc/bc_xprt.h> 43 #include <linux/nsproxy.h> 44 #include <linux/pid_namespace.h> 45 46 #include <asm/system.h> 47 48 #include "nfs4_fs.h" 49 #include "callback.h" 50 #include "delegation.h" 51 #include "iostat.h" 52 #include "internal.h" 53 #include "fscache.h" 54 #include "pnfs.h" 55 #include "netns.h" 56 57 #define NFSDBG_FACILITY NFSDBG_CLIENT 58 59 static DECLARE_WAIT_QUEUE_HEAD(nfs_client_active_wq); 60 #ifdef CONFIG_NFS_V4 61 62 /* 63 * Get a unique NFSv4.0 callback identifier which will be used 64 * by the V4.0 callback service to lookup the nfs_client struct 65 */ 66 static int nfs_get_cb_ident_idr(struct nfs_client *clp, int minorversion) 67 { 68 int ret = 0; 69 struct nfs_net *nn = net_generic(clp->net, nfs_net_id); 70 71 if (clp->rpc_ops->version != 4 || minorversion != 0) 72 return ret; 73 retry: 74 if (!idr_pre_get(&nn->cb_ident_idr, GFP_KERNEL)) 75 return -ENOMEM; 76 spin_lock(&nn->nfs_client_lock); 77 ret = idr_get_new(&nn->cb_ident_idr, clp, &clp->cl_cb_ident); 78 spin_unlock(&nn->nfs_client_lock); 79 if (ret == -EAGAIN) 80 goto retry; 81 return ret; 82 } 83 #endif /* CONFIG_NFS_V4 */ 84 85 /* 86 * Turn off NFSv4 uid/gid mapping when using AUTH_SYS 87 */ 88 static bool nfs4_disable_idmapping = true; 89 90 /* 91 * RPC cruft for NFS 92 */ 93 static const struct rpc_version *nfs_version[5] = { 94 [2] = &nfs_version2, 95 #ifdef CONFIG_NFS_V3 96 [3] = &nfs_version3, 97 #endif 98 #ifdef CONFIG_NFS_V4 99 [4] = &nfs_version4, 100 #endif 101 }; 102 103 const struct rpc_program nfs_program = { 104 .name = "nfs", 105 .number = NFS_PROGRAM, 106 .nrvers = ARRAY_SIZE(nfs_version), 107 .version = nfs_version, 108 .stats = &nfs_rpcstat, 109 .pipe_dir_name = NFS_PIPE_DIRNAME, 110 }; 111 112 struct rpc_stat nfs_rpcstat = { 113 .program = &nfs_program 114 }; 115 116 117 #ifdef CONFIG_NFS_V3_ACL 118 static struct rpc_stat nfsacl_rpcstat = { &nfsacl_program }; 119 static const struct rpc_version *nfsacl_version[] = { 120 [3] = &nfsacl_version3, 121 }; 122 123 const struct rpc_program nfsacl_program = { 124 .name = "nfsacl", 125 .number = NFS_ACL_PROGRAM, 126 .nrvers = ARRAY_SIZE(nfsacl_version), 127 .version = nfsacl_version, 128 .stats = &nfsacl_rpcstat, 129 }; 130 #endif /* CONFIG_NFS_V3_ACL */ 131 132 struct nfs_client_initdata { 133 const char *hostname; 134 const struct sockaddr *addr; 135 size_t addrlen; 136 const struct nfs_rpc_ops *rpc_ops; 137 int proto; 138 u32 minorversion; 139 struct net *net; 140 }; 141 142 /* 143 * Allocate a shared client record 144 * 145 * Since these are allocated/deallocated very rarely, we don't 146 * bother putting them in a slab cache... 147 */ 148 static struct nfs_client *nfs_alloc_client(const struct nfs_client_initdata *cl_init) 149 { 150 struct nfs_client *clp; 151 struct rpc_cred *cred; 152 int err = -ENOMEM; 153 154 if ((clp = kzalloc(sizeof(*clp), GFP_KERNEL)) == NULL) 155 goto error_0; 156 157 clp->rpc_ops = cl_init->rpc_ops; 158 159 atomic_set(&clp->cl_count, 1); 160 clp->cl_cons_state = NFS_CS_INITING; 161 162 memcpy(&clp->cl_addr, cl_init->addr, cl_init->addrlen); 163 clp->cl_addrlen = cl_init->addrlen; 164 165 if (cl_init->hostname) { 166 err = -ENOMEM; 167 clp->cl_hostname = kstrdup(cl_init->hostname, GFP_KERNEL); 168 if (!clp->cl_hostname) 169 goto error_cleanup; 170 } 171 172 INIT_LIST_HEAD(&clp->cl_superblocks); 173 clp->cl_rpcclient = ERR_PTR(-EINVAL); 174 175 clp->cl_proto = cl_init->proto; 176 clp->net = get_net(cl_init->net); 177 178 #ifdef CONFIG_NFS_V4 179 err = nfs_get_cb_ident_idr(clp, cl_init->minorversion); 180 if (err) 181 goto error_cleanup; 182 183 spin_lock_init(&clp->cl_lock); 184 INIT_DELAYED_WORK(&clp->cl_renewd, nfs4_renew_state); 185 rpc_init_wait_queue(&clp->cl_rpcwaitq, "NFS client"); 186 clp->cl_boot_time = CURRENT_TIME; 187 clp->cl_state = 1 << NFS4CLNT_LEASE_EXPIRED; 188 clp->cl_minorversion = cl_init->minorversion; 189 clp->cl_mvops = nfs_v4_minor_ops[cl_init->minorversion]; 190 #endif 191 cred = rpc_lookup_machine_cred("*"); 192 if (!IS_ERR(cred)) 193 clp->cl_machine_cred = cred; 194 nfs_fscache_get_client_cookie(clp); 195 196 return clp; 197 198 error_cleanup: 199 kfree(clp); 200 error_0: 201 return ERR_PTR(err); 202 } 203 204 #ifdef CONFIG_NFS_V4 205 #ifdef CONFIG_NFS_V4_1 206 static void nfs4_shutdown_session(struct nfs_client *clp) 207 { 208 if (nfs4_has_session(clp)) { 209 nfs4_deviceid_purge_client(clp); 210 nfs4_destroy_session(clp->cl_session); 211 } 212 213 } 214 #else /* CONFIG_NFS_V4_1 */ 215 static void nfs4_shutdown_session(struct nfs_client *clp) 216 { 217 } 218 #endif /* CONFIG_NFS_V4_1 */ 219 220 /* 221 * Destroy the NFS4 callback service 222 */ 223 static void nfs4_destroy_callback(struct nfs_client *clp) 224 { 225 if (__test_and_clear_bit(NFS_CS_CALLBACK, &clp->cl_res_state)) 226 nfs_callback_down(clp->cl_mvops->minor_version); 227 } 228 229 static void nfs4_shutdown_client(struct nfs_client *clp) 230 { 231 if (__test_and_clear_bit(NFS_CS_RENEWD, &clp->cl_res_state)) 232 nfs4_kill_renewd(clp); 233 nfs4_shutdown_session(clp); 234 nfs4_destroy_callback(clp); 235 if (__test_and_clear_bit(NFS_CS_IDMAP, &clp->cl_res_state)) 236 nfs_idmap_delete(clp); 237 238 rpc_destroy_wait_queue(&clp->cl_rpcwaitq); 239 } 240 241 /* idr_remove_all is not needed as all id's are removed by nfs_put_client */ 242 void nfs_cleanup_cb_ident_idr(struct net *net) 243 { 244 struct nfs_net *nn = net_generic(net, nfs_net_id); 245 246 idr_destroy(&nn->cb_ident_idr); 247 } 248 249 /* nfs_client_lock held */ 250 static void nfs_cb_idr_remove_locked(struct nfs_client *clp) 251 { 252 struct nfs_net *nn = net_generic(clp->net, nfs_net_id); 253 254 if (clp->cl_cb_ident) 255 idr_remove(&nn->cb_ident_idr, clp->cl_cb_ident); 256 } 257 258 static void pnfs_init_server(struct nfs_server *server) 259 { 260 rpc_init_wait_queue(&server->roc_rpcwaitq, "pNFS ROC"); 261 } 262 263 static void nfs4_destroy_server(struct nfs_server *server) 264 { 265 nfs4_purge_state_owners(server); 266 } 267 268 #else 269 static void nfs4_shutdown_client(struct nfs_client *clp) 270 { 271 } 272 273 void nfs_cleanup_cb_ident_idr(struct net *net) 274 { 275 } 276 277 static void nfs_cb_idr_remove_locked(struct nfs_client *clp) 278 { 279 } 280 281 static void pnfs_init_server(struct nfs_server *server) 282 { 283 } 284 285 #endif /* CONFIG_NFS_V4 */ 286 287 /* 288 * Destroy a shared client record 289 */ 290 static void nfs_free_client(struct nfs_client *clp) 291 { 292 dprintk("--> nfs_free_client(%u)\n", clp->rpc_ops->version); 293 294 nfs4_shutdown_client(clp); 295 296 nfs_fscache_release_client_cookie(clp); 297 298 /* -EIO all pending I/O */ 299 if (!IS_ERR(clp->cl_rpcclient)) 300 rpc_shutdown_client(clp->cl_rpcclient); 301 302 if (clp->cl_machine_cred != NULL) 303 put_rpccred(clp->cl_machine_cred); 304 305 put_net(clp->net); 306 kfree(clp->cl_hostname); 307 kfree(clp->server_scope); 308 kfree(clp->impl_id); 309 kfree(clp); 310 311 dprintk("<-- nfs_free_client()\n"); 312 } 313 314 /* 315 * Release a reference to a shared client record 316 */ 317 void nfs_put_client(struct nfs_client *clp) 318 { 319 struct nfs_net *nn; 320 321 if (!clp) 322 return; 323 324 dprintk("--> nfs_put_client({%d})\n", atomic_read(&clp->cl_count)); 325 nn = net_generic(clp->net, nfs_net_id); 326 327 if (atomic_dec_and_lock(&clp->cl_count, &nn->nfs_client_lock)) { 328 list_del(&clp->cl_share_link); 329 nfs_cb_idr_remove_locked(clp); 330 spin_unlock(&nn->nfs_client_lock); 331 332 BUG_ON(!list_empty(&clp->cl_superblocks)); 333 334 nfs_free_client(clp); 335 } 336 } 337 EXPORT_SYMBOL_GPL(nfs_put_client); 338 339 #if defined(CONFIG_IPV6) || defined(CONFIG_IPV6_MODULE) 340 /* 341 * Test if two ip6 socket addresses refer to the same socket by 342 * comparing relevant fields. The padding bytes specifically, are not 343 * compared. sin6_flowinfo is not compared because it only affects QoS 344 * and sin6_scope_id is only compared if the address is "link local" 345 * because "link local" addresses need only be unique to a specific 346 * link. Conversely, ordinary unicast addresses might have different 347 * sin6_scope_id. 348 * 349 * The caller should ensure both socket addresses are AF_INET6. 350 */ 351 static int nfs_sockaddr_match_ipaddr6(const struct sockaddr *sa1, 352 const struct sockaddr *sa2) 353 { 354 const struct sockaddr_in6 *sin1 = (const struct sockaddr_in6 *)sa1; 355 const struct sockaddr_in6 *sin2 = (const struct sockaddr_in6 *)sa2; 356 357 if (!ipv6_addr_equal(&sin1->sin6_addr, &sin2->sin6_addr)) 358 return 0; 359 else if (ipv6_addr_type(&sin1->sin6_addr) & IPV6_ADDR_LINKLOCAL) 360 return sin1->sin6_scope_id == sin2->sin6_scope_id; 361 362 return 1; 363 } 364 #else /* !defined(CONFIG_IPV6) && !defined(CONFIG_IPV6_MODULE) */ 365 static int nfs_sockaddr_match_ipaddr6(const struct sockaddr *sa1, 366 const struct sockaddr *sa2) 367 { 368 return 0; 369 } 370 #endif 371 372 /* 373 * Test if two ip4 socket addresses refer to the same socket, by 374 * comparing relevant fields. The padding bytes specifically, are 375 * not compared. 376 * 377 * The caller should ensure both socket addresses are AF_INET. 378 */ 379 static int nfs_sockaddr_match_ipaddr4(const struct sockaddr *sa1, 380 const struct sockaddr *sa2) 381 { 382 const struct sockaddr_in *sin1 = (const struct sockaddr_in *)sa1; 383 const struct sockaddr_in *sin2 = (const struct sockaddr_in *)sa2; 384 385 return sin1->sin_addr.s_addr == sin2->sin_addr.s_addr; 386 } 387 388 static int nfs_sockaddr_cmp_ip6(const struct sockaddr *sa1, 389 const struct sockaddr *sa2) 390 { 391 const struct sockaddr_in6 *sin1 = (const struct sockaddr_in6 *)sa1; 392 const struct sockaddr_in6 *sin2 = (const struct sockaddr_in6 *)sa2; 393 394 return nfs_sockaddr_match_ipaddr6(sa1, sa2) && 395 (sin1->sin6_port == sin2->sin6_port); 396 } 397 398 static int nfs_sockaddr_cmp_ip4(const struct sockaddr *sa1, 399 const struct sockaddr *sa2) 400 { 401 const struct sockaddr_in *sin1 = (const struct sockaddr_in *)sa1; 402 const struct sockaddr_in *sin2 = (const struct sockaddr_in *)sa2; 403 404 return nfs_sockaddr_match_ipaddr4(sa1, sa2) && 405 (sin1->sin_port == sin2->sin_port); 406 } 407 408 #if defined(CONFIG_NFS_V4_1) 409 /* 410 * Test if two socket addresses represent the same actual socket, 411 * by comparing (only) relevant fields, excluding the port number. 412 */ 413 static int nfs_sockaddr_match_ipaddr(const struct sockaddr *sa1, 414 const struct sockaddr *sa2) 415 { 416 if (sa1->sa_family != sa2->sa_family) 417 return 0; 418 419 switch (sa1->sa_family) { 420 case AF_INET: 421 return nfs_sockaddr_match_ipaddr4(sa1, sa2); 422 case AF_INET6: 423 return nfs_sockaddr_match_ipaddr6(sa1, sa2); 424 } 425 return 0; 426 } 427 #endif /* CONFIG_NFS_V4_1 */ 428 429 /* 430 * Test if two socket addresses represent the same actual socket, 431 * by comparing (only) relevant fields, including the port number. 432 */ 433 static int nfs_sockaddr_cmp(const struct sockaddr *sa1, 434 const struct sockaddr *sa2) 435 { 436 if (sa1->sa_family != sa2->sa_family) 437 return 0; 438 439 switch (sa1->sa_family) { 440 case AF_INET: 441 return nfs_sockaddr_cmp_ip4(sa1, sa2); 442 case AF_INET6: 443 return nfs_sockaddr_cmp_ip6(sa1, sa2); 444 } 445 return 0; 446 } 447 448 #if defined(CONFIG_NFS_V4_1) 449 /* Common match routine for v4.0 and v4.1 callback services */ 450 static bool nfs4_cb_match_client(const struct sockaddr *addr, 451 struct nfs_client *clp, u32 minorversion) 452 { 453 struct sockaddr *clap = (struct sockaddr *)&clp->cl_addr; 454 455 /* Don't match clients that failed to initialise */ 456 if (!(clp->cl_cons_state == NFS_CS_READY || 457 clp->cl_cons_state == NFS_CS_SESSION_INITING)) 458 return false; 459 460 /* Match the version and minorversion */ 461 if (clp->rpc_ops->version != 4 || 462 clp->cl_minorversion != minorversion) 463 return false; 464 465 /* Match only the IP address, not the port number */ 466 if (!nfs_sockaddr_match_ipaddr(addr, clap)) 467 return false; 468 469 return true; 470 } 471 #endif /* CONFIG_NFS_V4_1 */ 472 473 /* 474 * Find an nfs_client on the list that matches the initialisation data 475 * that is supplied. 476 */ 477 static struct nfs_client *nfs_match_client(const struct nfs_client_initdata *data) 478 { 479 struct nfs_client *clp; 480 const struct sockaddr *sap = data->addr; 481 struct nfs_net *nn = net_generic(data->net, nfs_net_id); 482 483 list_for_each_entry(clp, &nn->nfs_client_list, cl_share_link) { 484 const struct sockaddr *clap = (struct sockaddr *)&clp->cl_addr; 485 /* Don't match clients that failed to initialise properly */ 486 if (clp->cl_cons_state < 0) 487 continue; 488 489 /* Different NFS versions cannot share the same nfs_client */ 490 if (clp->rpc_ops != data->rpc_ops) 491 continue; 492 493 if (clp->cl_proto != data->proto) 494 continue; 495 /* Match nfsv4 minorversion */ 496 if (clp->cl_minorversion != data->minorversion) 497 continue; 498 /* Match the full socket address */ 499 if (!nfs_sockaddr_cmp(sap, clap)) 500 continue; 501 502 atomic_inc(&clp->cl_count); 503 return clp; 504 } 505 return NULL; 506 } 507 508 /* 509 * Look up a client by IP address and protocol version 510 * - creates a new record if one doesn't yet exist 511 */ 512 static struct nfs_client * 513 nfs_get_client(const struct nfs_client_initdata *cl_init, 514 const struct rpc_timeout *timeparms, 515 const char *ip_addr, 516 rpc_authflavor_t authflavour, 517 int noresvport) 518 { 519 struct nfs_client *clp, *new = NULL; 520 int error; 521 struct nfs_net *nn = net_generic(cl_init->net, nfs_net_id); 522 523 dprintk("--> nfs_get_client(%s,v%u)\n", 524 cl_init->hostname ?: "", cl_init->rpc_ops->version); 525 526 /* see if the client already exists */ 527 do { 528 spin_lock(&nn->nfs_client_lock); 529 530 clp = nfs_match_client(cl_init); 531 if (clp) 532 goto found_client; 533 if (new) 534 goto install_client; 535 536 spin_unlock(&nn->nfs_client_lock); 537 538 new = nfs_alloc_client(cl_init); 539 } while (!IS_ERR(new)); 540 541 dprintk("--> nfs_get_client() = %ld [failed]\n", PTR_ERR(new)); 542 return new; 543 544 /* install a new client and return with it unready */ 545 install_client: 546 clp = new; 547 list_add(&clp->cl_share_link, &nn->nfs_client_list); 548 spin_unlock(&nn->nfs_client_lock); 549 550 error = cl_init->rpc_ops->init_client(clp, timeparms, ip_addr, 551 authflavour, noresvport); 552 if (error < 0) { 553 nfs_put_client(clp); 554 return ERR_PTR(error); 555 } 556 dprintk("--> nfs_get_client() = %p [new]\n", clp); 557 return clp; 558 559 /* found an existing client 560 * - make sure it's ready before returning 561 */ 562 found_client: 563 spin_unlock(&nn->nfs_client_lock); 564 565 if (new) 566 nfs_free_client(new); 567 568 error = wait_event_killable(nfs_client_active_wq, 569 clp->cl_cons_state < NFS_CS_INITING); 570 if (error < 0) { 571 nfs_put_client(clp); 572 return ERR_PTR(-ERESTARTSYS); 573 } 574 575 if (clp->cl_cons_state < NFS_CS_READY) { 576 error = clp->cl_cons_state; 577 nfs_put_client(clp); 578 return ERR_PTR(error); 579 } 580 581 BUG_ON(clp->cl_cons_state != NFS_CS_READY); 582 583 dprintk("--> nfs_get_client() = %p [share]\n", clp); 584 return clp; 585 } 586 587 /* 588 * Mark a server as ready or failed 589 */ 590 void nfs_mark_client_ready(struct nfs_client *clp, int state) 591 { 592 clp->cl_cons_state = state; 593 wake_up_all(&nfs_client_active_wq); 594 } 595 596 /* 597 * With sessions, the client is not marked ready until after a 598 * successful EXCHANGE_ID and CREATE_SESSION. 599 * 600 * Map errors cl_cons_state errors to EPROTONOSUPPORT to indicate 601 * other versions of NFS can be tried. 602 */ 603 int nfs4_check_client_ready(struct nfs_client *clp) 604 { 605 if (!nfs4_has_session(clp)) 606 return 0; 607 if (clp->cl_cons_state < NFS_CS_READY) 608 return -EPROTONOSUPPORT; 609 return 0; 610 } 611 612 /* 613 * Initialise the timeout values for a connection 614 */ 615 static void nfs_init_timeout_values(struct rpc_timeout *to, int proto, 616 unsigned int timeo, unsigned int retrans) 617 { 618 to->to_initval = timeo * HZ / 10; 619 to->to_retries = retrans; 620 621 switch (proto) { 622 case XPRT_TRANSPORT_TCP: 623 case XPRT_TRANSPORT_RDMA: 624 if (to->to_retries == 0) 625 to->to_retries = NFS_DEF_TCP_RETRANS; 626 if (to->to_initval == 0) 627 to->to_initval = NFS_DEF_TCP_TIMEO * HZ / 10; 628 if (to->to_initval > NFS_MAX_TCP_TIMEOUT) 629 to->to_initval = NFS_MAX_TCP_TIMEOUT; 630 to->to_increment = to->to_initval; 631 to->to_maxval = to->to_initval + (to->to_increment * to->to_retries); 632 if (to->to_maxval > NFS_MAX_TCP_TIMEOUT) 633 to->to_maxval = NFS_MAX_TCP_TIMEOUT; 634 if (to->to_maxval < to->to_initval) 635 to->to_maxval = to->to_initval; 636 to->to_exponential = 0; 637 break; 638 case XPRT_TRANSPORT_UDP: 639 if (to->to_retries == 0) 640 to->to_retries = NFS_DEF_UDP_RETRANS; 641 if (!to->to_initval) 642 to->to_initval = NFS_DEF_UDP_TIMEO * HZ / 10; 643 if (to->to_initval > NFS_MAX_UDP_TIMEOUT) 644 to->to_initval = NFS_MAX_UDP_TIMEOUT; 645 to->to_maxval = NFS_MAX_UDP_TIMEOUT; 646 to->to_exponential = 1; 647 break; 648 default: 649 BUG(); 650 } 651 } 652 653 /* 654 * Create an RPC client handle 655 */ 656 static int nfs_create_rpc_client(struct nfs_client *clp, 657 const struct rpc_timeout *timeparms, 658 rpc_authflavor_t flavor, 659 int discrtry, int noresvport) 660 { 661 struct rpc_clnt *clnt = NULL; 662 struct rpc_create_args args = { 663 .net = clp->net, 664 .protocol = clp->cl_proto, 665 .address = (struct sockaddr *)&clp->cl_addr, 666 .addrsize = clp->cl_addrlen, 667 .timeout = timeparms, 668 .servername = clp->cl_hostname, 669 .program = &nfs_program, 670 .version = clp->rpc_ops->version, 671 .authflavor = flavor, 672 }; 673 674 if (discrtry) 675 args.flags |= RPC_CLNT_CREATE_DISCRTRY; 676 if (noresvport) 677 args.flags |= RPC_CLNT_CREATE_NONPRIVPORT; 678 679 if (!IS_ERR(clp->cl_rpcclient)) 680 return 0; 681 682 clnt = rpc_create(&args); 683 if (IS_ERR(clnt)) { 684 dprintk("%s: cannot create RPC client. Error = %ld\n", 685 __func__, PTR_ERR(clnt)); 686 return PTR_ERR(clnt); 687 } 688 689 clp->cl_rpcclient = clnt; 690 return 0; 691 } 692 693 /* 694 * Version 2 or 3 client destruction 695 */ 696 static void nfs_destroy_server(struct nfs_server *server) 697 { 698 if (!(server->flags & NFS_MOUNT_LOCAL_FLOCK) || 699 !(server->flags & NFS_MOUNT_LOCAL_FCNTL)) 700 nlmclnt_done(server->nlm_host); 701 } 702 703 /* 704 * Version 2 or 3 lockd setup 705 */ 706 static int nfs_start_lockd(struct nfs_server *server) 707 { 708 struct nlm_host *host; 709 struct nfs_client *clp = server->nfs_client; 710 struct nlmclnt_initdata nlm_init = { 711 .hostname = clp->cl_hostname, 712 .address = (struct sockaddr *)&clp->cl_addr, 713 .addrlen = clp->cl_addrlen, 714 .nfs_version = clp->rpc_ops->version, 715 .noresvport = server->flags & NFS_MOUNT_NORESVPORT ? 716 1 : 0, 717 .net = clp->net, 718 }; 719 720 if (nlm_init.nfs_version > 3) 721 return 0; 722 if ((server->flags & NFS_MOUNT_LOCAL_FLOCK) && 723 (server->flags & NFS_MOUNT_LOCAL_FCNTL)) 724 return 0; 725 726 switch (clp->cl_proto) { 727 default: 728 nlm_init.protocol = IPPROTO_TCP; 729 break; 730 case XPRT_TRANSPORT_UDP: 731 nlm_init.protocol = IPPROTO_UDP; 732 } 733 734 host = nlmclnt_init(&nlm_init); 735 if (IS_ERR(host)) 736 return PTR_ERR(host); 737 738 server->nlm_host = host; 739 server->destroy = nfs_destroy_server; 740 return 0; 741 } 742 743 /* 744 * Initialise an NFSv3 ACL client connection 745 */ 746 #ifdef CONFIG_NFS_V3_ACL 747 static void nfs_init_server_aclclient(struct nfs_server *server) 748 { 749 if (server->nfs_client->rpc_ops->version != 3) 750 goto out_noacl; 751 if (server->flags & NFS_MOUNT_NOACL) 752 goto out_noacl; 753 754 server->client_acl = rpc_bind_new_program(server->client, &nfsacl_program, 3); 755 if (IS_ERR(server->client_acl)) 756 goto out_noacl; 757 758 /* No errors! Assume that Sun nfsacls are supported */ 759 server->caps |= NFS_CAP_ACLS; 760 return; 761 762 out_noacl: 763 server->caps &= ~NFS_CAP_ACLS; 764 } 765 #else 766 static inline void nfs_init_server_aclclient(struct nfs_server *server) 767 { 768 server->flags &= ~NFS_MOUNT_NOACL; 769 server->caps &= ~NFS_CAP_ACLS; 770 } 771 #endif 772 773 /* 774 * Create a general RPC client 775 */ 776 static int nfs_init_server_rpcclient(struct nfs_server *server, 777 const struct rpc_timeout *timeo, 778 rpc_authflavor_t pseudoflavour) 779 { 780 struct nfs_client *clp = server->nfs_client; 781 782 server->client = rpc_clone_client(clp->cl_rpcclient); 783 if (IS_ERR(server->client)) { 784 dprintk("%s: couldn't create rpc_client!\n", __func__); 785 return PTR_ERR(server->client); 786 } 787 788 memcpy(&server->client->cl_timeout_default, 789 timeo, 790 sizeof(server->client->cl_timeout_default)); 791 server->client->cl_timeout = &server->client->cl_timeout_default; 792 793 if (pseudoflavour != clp->cl_rpcclient->cl_auth->au_flavor) { 794 struct rpc_auth *auth; 795 796 auth = rpcauth_create(pseudoflavour, server->client); 797 if (IS_ERR(auth)) { 798 dprintk("%s: couldn't create credcache!\n", __func__); 799 return PTR_ERR(auth); 800 } 801 } 802 server->client->cl_softrtry = 0; 803 if (server->flags & NFS_MOUNT_SOFT) 804 server->client->cl_softrtry = 1; 805 806 return 0; 807 } 808 809 /* 810 * Initialise an NFS2 or NFS3 client 811 */ 812 int nfs_init_client(struct nfs_client *clp, const struct rpc_timeout *timeparms, 813 const char *ip_addr, rpc_authflavor_t authflavour, 814 int noresvport) 815 { 816 int error; 817 818 if (clp->cl_cons_state == NFS_CS_READY) { 819 /* the client is already initialised */ 820 dprintk("<-- nfs_init_client() = 0 [already %p]\n", clp); 821 return 0; 822 } 823 824 /* 825 * Create a client RPC handle for doing FSSTAT with UNIX auth only 826 * - RFC 2623, sec 2.3.2 827 */ 828 error = nfs_create_rpc_client(clp, timeparms, RPC_AUTH_UNIX, 829 0, noresvport); 830 if (error < 0) 831 goto error; 832 nfs_mark_client_ready(clp, NFS_CS_READY); 833 return 0; 834 835 error: 836 nfs_mark_client_ready(clp, error); 837 dprintk("<-- nfs_init_client() = xerror %d\n", error); 838 return error; 839 } 840 841 /* 842 * Create a version 2 or 3 client 843 */ 844 static int nfs_init_server(struct nfs_server *server, 845 const struct nfs_parsed_mount_data *data) 846 { 847 struct nfs_client_initdata cl_init = { 848 .hostname = data->nfs_server.hostname, 849 .addr = (const struct sockaddr *)&data->nfs_server.address, 850 .addrlen = data->nfs_server.addrlen, 851 .rpc_ops = &nfs_v2_clientops, 852 .proto = data->nfs_server.protocol, 853 .net = data->net, 854 }; 855 struct rpc_timeout timeparms; 856 struct nfs_client *clp; 857 int error; 858 859 dprintk("--> nfs_init_server()\n"); 860 861 #ifdef CONFIG_NFS_V3 862 if (data->version == 3) 863 cl_init.rpc_ops = &nfs_v3_clientops; 864 #endif 865 866 nfs_init_timeout_values(&timeparms, data->nfs_server.protocol, 867 data->timeo, data->retrans); 868 869 /* Allocate or find a client reference we can use */ 870 clp = nfs_get_client(&cl_init, &timeparms, NULL, RPC_AUTH_UNIX, 871 data->flags & NFS_MOUNT_NORESVPORT); 872 if (IS_ERR(clp)) { 873 dprintk("<-- nfs_init_server() = error %ld\n", PTR_ERR(clp)); 874 return PTR_ERR(clp); 875 } 876 877 server->nfs_client = clp; 878 879 /* Initialise the client representation from the mount data */ 880 server->flags = data->flags; 881 server->options = data->options; 882 server->caps |= NFS_CAP_HARDLINKS|NFS_CAP_SYMLINKS|NFS_CAP_FILEID| 883 NFS_CAP_MODE|NFS_CAP_NLINK|NFS_CAP_OWNER|NFS_CAP_OWNER_GROUP| 884 NFS_CAP_ATIME|NFS_CAP_CTIME|NFS_CAP_MTIME; 885 886 if (data->rsize) 887 server->rsize = nfs_block_size(data->rsize, NULL); 888 if (data->wsize) 889 server->wsize = nfs_block_size(data->wsize, NULL); 890 891 server->acregmin = data->acregmin * HZ; 892 server->acregmax = data->acregmax * HZ; 893 server->acdirmin = data->acdirmin * HZ; 894 server->acdirmax = data->acdirmax * HZ; 895 896 /* Start lockd here, before we might error out */ 897 error = nfs_start_lockd(server); 898 if (error < 0) 899 goto error; 900 901 server->port = data->nfs_server.port; 902 903 error = nfs_init_server_rpcclient(server, &timeparms, data->auth_flavors[0]); 904 if (error < 0) 905 goto error; 906 907 /* Preserve the values of mount_server-related mount options */ 908 if (data->mount_server.addrlen) { 909 memcpy(&server->mountd_address, &data->mount_server.address, 910 data->mount_server.addrlen); 911 server->mountd_addrlen = data->mount_server.addrlen; 912 } 913 server->mountd_version = data->mount_server.version; 914 server->mountd_port = data->mount_server.port; 915 server->mountd_protocol = data->mount_server.protocol; 916 917 server->namelen = data->namlen; 918 /* Create a client RPC handle for the NFSv3 ACL management interface */ 919 nfs_init_server_aclclient(server); 920 dprintk("<-- nfs_init_server() = 0 [new %p]\n", clp); 921 return 0; 922 923 error: 924 server->nfs_client = NULL; 925 nfs_put_client(clp); 926 dprintk("<-- nfs_init_server() = xerror %d\n", error); 927 return error; 928 } 929 930 /* 931 * Load up the server record from information gained in an fsinfo record 932 */ 933 static void nfs_server_set_fsinfo(struct nfs_server *server, 934 struct nfs_fh *mntfh, 935 struct nfs_fsinfo *fsinfo) 936 { 937 unsigned long max_rpc_payload; 938 939 /* Work out a lot of parameters */ 940 if (server->rsize == 0) 941 server->rsize = nfs_block_size(fsinfo->rtpref, NULL); 942 if (server->wsize == 0) 943 server->wsize = nfs_block_size(fsinfo->wtpref, NULL); 944 945 if (fsinfo->rtmax >= 512 && server->rsize > fsinfo->rtmax) 946 server->rsize = nfs_block_size(fsinfo->rtmax, NULL); 947 if (fsinfo->wtmax >= 512 && server->wsize > fsinfo->wtmax) 948 server->wsize = nfs_block_size(fsinfo->wtmax, NULL); 949 950 max_rpc_payload = nfs_block_size(rpc_max_payload(server->client), NULL); 951 if (server->rsize > max_rpc_payload) 952 server->rsize = max_rpc_payload; 953 if (server->rsize > NFS_MAX_FILE_IO_SIZE) 954 server->rsize = NFS_MAX_FILE_IO_SIZE; 955 server->rpages = (server->rsize + PAGE_CACHE_SIZE - 1) >> PAGE_CACHE_SHIFT; 956 957 server->backing_dev_info.name = "nfs"; 958 server->backing_dev_info.ra_pages = server->rpages * NFS_MAX_READAHEAD; 959 960 if (server->wsize > max_rpc_payload) 961 server->wsize = max_rpc_payload; 962 if (server->wsize > NFS_MAX_FILE_IO_SIZE) 963 server->wsize = NFS_MAX_FILE_IO_SIZE; 964 server->wpages = (server->wsize + PAGE_CACHE_SIZE - 1) >> PAGE_CACHE_SHIFT; 965 server->pnfs_blksize = fsinfo->blksize; 966 set_pnfs_layoutdriver(server, mntfh, fsinfo->layouttype); 967 968 server->wtmult = nfs_block_bits(fsinfo->wtmult, NULL); 969 970 server->dtsize = nfs_block_size(fsinfo->dtpref, NULL); 971 if (server->dtsize > PAGE_CACHE_SIZE * NFS_MAX_READDIR_PAGES) 972 server->dtsize = PAGE_CACHE_SIZE * NFS_MAX_READDIR_PAGES; 973 if (server->dtsize > server->rsize) 974 server->dtsize = server->rsize; 975 976 if (server->flags & NFS_MOUNT_NOAC) { 977 server->acregmin = server->acregmax = 0; 978 server->acdirmin = server->acdirmax = 0; 979 } 980 981 server->maxfilesize = fsinfo->maxfilesize; 982 983 server->time_delta = fsinfo->time_delta; 984 985 /* We're airborne Set socket buffersize */ 986 rpc_setbufsize(server->client, server->wsize + 100, server->rsize + 100); 987 } 988 989 /* 990 * Probe filesystem information, including the FSID on v2/v3 991 */ 992 static int nfs_probe_fsinfo(struct nfs_server *server, struct nfs_fh *mntfh, struct nfs_fattr *fattr) 993 { 994 struct nfs_fsinfo fsinfo; 995 struct nfs_client *clp = server->nfs_client; 996 int error; 997 998 dprintk("--> nfs_probe_fsinfo()\n"); 999 1000 if (clp->rpc_ops->set_capabilities != NULL) { 1001 error = clp->rpc_ops->set_capabilities(server, mntfh); 1002 if (error < 0) 1003 goto out_error; 1004 } 1005 1006 fsinfo.fattr = fattr; 1007 fsinfo.layouttype = 0; 1008 error = clp->rpc_ops->fsinfo(server, mntfh, &fsinfo); 1009 if (error < 0) 1010 goto out_error; 1011 1012 nfs_server_set_fsinfo(server, mntfh, &fsinfo); 1013 1014 /* Get some general file system info */ 1015 if (server->namelen == 0) { 1016 struct nfs_pathconf pathinfo; 1017 1018 pathinfo.fattr = fattr; 1019 nfs_fattr_init(fattr); 1020 1021 if (clp->rpc_ops->pathconf(server, mntfh, &pathinfo) >= 0) 1022 server->namelen = pathinfo.max_namelen; 1023 } 1024 1025 dprintk("<-- nfs_probe_fsinfo() = 0\n"); 1026 return 0; 1027 1028 out_error: 1029 dprintk("nfs_probe_fsinfo: error = %d\n", -error); 1030 return error; 1031 } 1032 1033 /* 1034 * Copy useful information when duplicating a server record 1035 */ 1036 static void nfs_server_copy_userdata(struct nfs_server *target, struct nfs_server *source) 1037 { 1038 target->flags = source->flags; 1039 target->rsize = source->rsize; 1040 target->wsize = source->wsize; 1041 target->acregmin = source->acregmin; 1042 target->acregmax = source->acregmax; 1043 target->acdirmin = source->acdirmin; 1044 target->acdirmax = source->acdirmax; 1045 target->caps = source->caps; 1046 target->options = source->options; 1047 } 1048 1049 static void nfs_server_insert_lists(struct nfs_server *server) 1050 { 1051 struct nfs_client *clp = server->nfs_client; 1052 struct nfs_net *nn = net_generic(clp->net, nfs_net_id); 1053 1054 spin_lock(&nn->nfs_client_lock); 1055 list_add_tail_rcu(&server->client_link, &clp->cl_superblocks); 1056 list_add_tail(&server->master_link, &nn->nfs_volume_list); 1057 clear_bit(NFS_CS_STOP_RENEW, &clp->cl_res_state); 1058 spin_unlock(&nn->nfs_client_lock); 1059 1060 } 1061 1062 static void nfs_server_remove_lists(struct nfs_server *server) 1063 { 1064 struct nfs_client *clp = server->nfs_client; 1065 struct nfs_net *nn; 1066 1067 if (clp == NULL) 1068 return; 1069 nn = net_generic(clp->net, nfs_net_id); 1070 spin_lock(&nn->nfs_client_lock); 1071 list_del_rcu(&server->client_link); 1072 if (list_empty(&clp->cl_superblocks)) 1073 set_bit(NFS_CS_STOP_RENEW, &clp->cl_res_state); 1074 list_del(&server->master_link); 1075 spin_unlock(&nn->nfs_client_lock); 1076 1077 synchronize_rcu(); 1078 } 1079 1080 /* 1081 * Allocate and initialise a server record 1082 */ 1083 static struct nfs_server *nfs_alloc_server(void) 1084 { 1085 struct nfs_server *server; 1086 1087 server = kzalloc(sizeof(struct nfs_server), GFP_KERNEL); 1088 if (!server) 1089 return NULL; 1090 1091 server->client = server->client_acl = ERR_PTR(-EINVAL); 1092 1093 /* Zero out the NFS state stuff */ 1094 INIT_LIST_HEAD(&server->client_link); 1095 INIT_LIST_HEAD(&server->master_link); 1096 INIT_LIST_HEAD(&server->delegations); 1097 INIT_LIST_HEAD(&server->layouts); 1098 INIT_LIST_HEAD(&server->state_owners_lru); 1099 1100 atomic_set(&server->active, 0); 1101 1102 server->io_stats = nfs_alloc_iostats(); 1103 if (!server->io_stats) { 1104 kfree(server); 1105 return NULL; 1106 } 1107 1108 if (bdi_init(&server->backing_dev_info)) { 1109 nfs_free_iostats(server->io_stats); 1110 kfree(server); 1111 return NULL; 1112 } 1113 1114 ida_init(&server->openowner_id); 1115 ida_init(&server->lockowner_id); 1116 pnfs_init_server(server); 1117 1118 return server; 1119 } 1120 1121 /* 1122 * Free up a server record 1123 */ 1124 void nfs_free_server(struct nfs_server *server) 1125 { 1126 dprintk("--> nfs_free_server()\n"); 1127 1128 nfs_server_remove_lists(server); 1129 unset_pnfs_layoutdriver(server); 1130 1131 if (server->destroy != NULL) 1132 server->destroy(server); 1133 1134 if (!IS_ERR(server->client_acl)) 1135 rpc_shutdown_client(server->client_acl); 1136 if (!IS_ERR(server->client)) 1137 rpc_shutdown_client(server->client); 1138 1139 nfs_put_client(server->nfs_client); 1140 1141 ida_destroy(&server->lockowner_id); 1142 ida_destroy(&server->openowner_id); 1143 nfs_free_iostats(server->io_stats); 1144 bdi_destroy(&server->backing_dev_info); 1145 kfree(server); 1146 nfs_release_automount_timer(); 1147 dprintk("<-- nfs_free_server()\n"); 1148 } 1149 1150 /* 1151 * Create a version 2 or 3 volume record 1152 * - keyed on server and FSID 1153 */ 1154 struct nfs_server *nfs_create_server(const struct nfs_parsed_mount_data *data, 1155 struct nfs_fh *mntfh) 1156 { 1157 struct nfs_server *server; 1158 struct nfs_fattr *fattr; 1159 int error; 1160 1161 server = nfs_alloc_server(); 1162 if (!server) 1163 return ERR_PTR(-ENOMEM); 1164 1165 error = -ENOMEM; 1166 fattr = nfs_alloc_fattr(); 1167 if (fattr == NULL) 1168 goto error; 1169 1170 /* Get a client representation */ 1171 error = nfs_init_server(server, data); 1172 if (error < 0) 1173 goto error; 1174 1175 BUG_ON(!server->nfs_client); 1176 BUG_ON(!server->nfs_client->rpc_ops); 1177 BUG_ON(!server->nfs_client->rpc_ops->file_inode_ops); 1178 1179 /* Probe the root fh to retrieve its FSID */ 1180 error = nfs_probe_fsinfo(server, mntfh, fattr); 1181 if (error < 0) 1182 goto error; 1183 if (server->nfs_client->rpc_ops->version == 3) { 1184 if (server->namelen == 0 || server->namelen > NFS3_MAXNAMLEN) 1185 server->namelen = NFS3_MAXNAMLEN; 1186 if (!(data->flags & NFS_MOUNT_NORDIRPLUS)) 1187 server->caps |= NFS_CAP_READDIRPLUS; 1188 } else { 1189 if (server->namelen == 0 || server->namelen > NFS2_MAXNAMLEN) 1190 server->namelen = NFS2_MAXNAMLEN; 1191 } 1192 1193 if (!(fattr->valid & NFS_ATTR_FATTR)) { 1194 error = server->nfs_client->rpc_ops->getattr(server, mntfh, fattr); 1195 if (error < 0) { 1196 dprintk("nfs_create_server: getattr error = %d\n", -error); 1197 goto error; 1198 } 1199 } 1200 memcpy(&server->fsid, &fattr->fsid, sizeof(server->fsid)); 1201 1202 dprintk("Server FSID: %llx:%llx\n", 1203 (unsigned long long) server->fsid.major, 1204 (unsigned long long) server->fsid.minor); 1205 1206 nfs_server_insert_lists(server); 1207 server->mount_time = jiffies; 1208 nfs_free_fattr(fattr); 1209 return server; 1210 1211 error: 1212 nfs_free_fattr(fattr); 1213 nfs_free_server(server); 1214 return ERR_PTR(error); 1215 } 1216 1217 #ifdef CONFIG_NFS_V4 1218 /* 1219 * NFSv4.0 callback thread helper 1220 * 1221 * Find a client by callback identifier 1222 */ 1223 struct nfs_client * 1224 nfs4_find_client_ident(struct net *net, int cb_ident) 1225 { 1226 struct nfs_client *clp; 1227 struct nfs_net *nn = net_generic(net, nfs_net_id); 1228 1229 spin_lock(&nn->nfs_client_lock); 1230 clp = idr_find(&nn->cb_ident_idr, cb_ident); 1231 if (clp) 1232 atomic_inc(&clp->cl_count); 1233 spin_unlock(&nn->nfs_client_lock); 1234 return clp; 1235 } 1236 1237 #if defined(CONFIG_NFS_V4_1) 1238 /* 1239 * NFSv4.1 callback thread helper 1240 * For CB_COMPOUND calls, find a client by IP address, protocol version, 1241 * minorversion, and sessionID 1242 * 1243 * Returns NULL if no such client 1244 */ 1245 struct nfs_client * 1246 nfs4_find_client_sessionid(struct net *net, const struct sockaddr *addr, 1247 struct nfs4_sessionid *sid) 1248 { 1249 struct nfs_client *clp; 1250 struct nfs_net *nn = net_generic(net, nfs_net_id); 1251 1252 spin_lock(&nn->nfs_client_lock); 1253 list_for_each_entry(clp, &nn->nfs_client_list, cl_share_link) { 1254 if (nfs4_cb_match_client(addr, clp, 1) == false) 1255 continue; 1256 1257 if (!nfs4_has_session(clp)) 1258 continue; 1259 1260 /* Match sessionid*/ 1261 if (memcmp(clp->cl_session->sess_id.data, 1262 sid->data, NFS4_MAX_SESSIONID_LEN) != 0) 1263 continue; 1264 1265 atomic_inc(&clp->cl_count); 1266 spin_unlock(&nn->nfs_client_lock); 1267 return clp; 1268 } 1269 spin_unlock(&nn->nfs_client_lock); 1270 return NULL; 1271 } 1272 1273 #else /* CONFIG_NFS_V4_1 */ 1274 1275 struct nfs_client * 1276 nfs4_find_client_sessionid(struct net *net, const struct sockaddr *addr, 1277 struct nfs4_sessionid *sid) 1278 { 1279 return NULL; 1280 } 1281 #endif /* CONFIG_NFS_V4_1 */ 1282 1283 /* 1284 * Initialize the NFS4 callback service 1285 */ 1286 static int nfs4_init_callback(struct nfs_client *clp) 1287 { 1288 int error; 1289 1290 if (clp->rpc_ops->version == 4) { 1291 struct rpc_xprt *xprt; 1292 1293 xprt = rcu_dereference_raw(clp->cl_rpcclient->cl_xprt); 1294 1295 if (nfs4_has_session(clp)) { 1296 error = xprt_setup_backchannel(xprt, 1297 NFS41_BC_MIN_CALLBACKS); 1298 if (error < 0) 1299 return error; 1300 } 1301 1302 error = nfs_callback_up(clp->cl_mvops->minor_version, xprt); 1303 if (error < 0) { 1304 dprintk("%s: failed to start callback. Error = %d\n", 1305 __func__, error); 1306 return error; 1307 } 1308 __set_bit(NFS_CS_CALLBACK, &clp->cl_res_state); 1309 } 1310 return 0; 1311 } 1312 1313 /* 1314 * Initialize the minor version specific parts of an NFS4 client record 1315 */ 1316 static int nfs4_init_client_minor_version(struct nfs_client *clp) 1317 { 1318 #if defined(CONFIG_NFS_V4_1) 1319 if (clp->cl_mvops->minor_version) { 1320 struct nfs4_session *session = NULL; 1321 /* 1322 * Create the session and mark it expired. 1323 * When a SEQUENCE operation encounters the expired session 1324 * it will do session recovery to initialize it. 1325 */ 1326 session = nfs4_alloc_session(clp); 1327 if (!session) 1328 return -ENOMEM; 1329 1330 clp->cl_session = session; 1331 /* 1332 * The create session reply races with the server back 1333 * channel probe. Mark the client NFS_CS_SESSION_INITING 1334 * so that the client back channel can find the 1335 * nfs_client struct 1336 */ 1337 clp->cl_cons_state = NFS_CS_SESSION_INITING; 1338 } 1339 #endif /* CONFIG_NFS_V4_1 */ 1340 1341 return nfs4_init_callback(clp); 1342 } 1343 1344 /* 1345 * Initialise an NFS4 client record 1346 */ 1347 int nfs4_init_client(struct nfs_client *clp, 1348 const struct rpc_timeout *timeparms, 1349 const char *ip_addr, 1350 rpc_authflavor_t authflavour, 1351 int noresvport) 1352 { 1353 char buf[INET6_ADDRSTRLEN + 1]; 1354 int error; 1355 1356 if (clp->cl_cons_state == NFS_CS_READY) { 1357 /* the client is initialised already */ 1358 dprintk("<-- nfs4_init_client() = 0 [already %p]\n", clp); 1359 return 0; 1360 } 1361 1362 /* Check NFS protocol revision and initialize RPC op vector */ 1363 clp->rpc_ops = &nfs_v4_clientops; 1364 1365 error = nfs_create_rpc_client(clp, timeparms, authflavour, 1366 1, noresvport); 1367 if (error < 0) 1368 goto error; 1369 1370 /* If no clientaddr= option was specified, find a usable cb address */ 1371 if (ip_addr == NULL) { 1372 struct sockaddr_storage cb_addr; 1373 struct sockaddr *sap = (struct sockaddr *)&cb_addr; 1374 1375 error = rpc_localaddr(clp->cl_rpcclient, sap, sizeof(cb_addr)); 1376 if (error < 0) 1377 goto error; 1378 error = rpc_ntop(sap, buf, sizeof(buf)); 1379 if (error < 0) 1380 goto error; 1381 ip_addr = (const char *)buf; 1382 } 1383 strlcpy(clp->cl_ipaddr, ip_addr, sizeof(clp->cl_ipaddr)); 1384 1385 error = nfs_idmap_new(clp); 1386 if (error < 0) { 1387 dprintk("%s: failed to create idmapper. Error = %d\n", 1388 __func__, error); 1389 goto error; 1390 } 1391 __set_bit(NFS_CS_IDMAP, &clp->cl_res_state); 1392 1393 error = nfs4_init_client_minor_version(clp); 1394 if (error < 0) 1395 goto error; 1396 1397 if (!nfs4_has_session(clp)) 1398 nfs_mark_client_ready(clp, NFS_CS_READY); 1399 return 0; 1400 1401 error: 1402 nfs_mark_client_ready(clp, error); 1403 dprintk("<-- nfs4_init_client() = xerror %d\n", error); 1404 return error; 1405 } 1406 1407 /* 1408 * Set up an NFS4 client 1409 */ 1410 static int nfs4_set_client(struct nfs_server *server, 1411 const char *hostname, 1412 const struct sockaddr *addr, 1413 const size_t addrlen, 1414 const char *ip_addr, 1415 rpc_authflavor_t authflavour, 1416 int proto, const struct rpc_timeout *timeparms, 1417 u32 minorversion, struct net *net) 1418 { 1419 struct nfs_client_initdata cl_init = { 1420 .hostname = hostname, 1421 .addr = addr, 1422 .addrlen = addrlen, 1423 .rpc_ops = &nfs_v4_clientops, 1424 .proto = proto, 1425 .minorversion = minorversion, 1426 .net = net, 1427 }; 1428 struct nfs_client *clp; 1429 int error; 1430 1431 dprintk("--> nfs4_set_client()\n"); 1432 1433 /* Allocate or find a client reference we can use */ 1434 clp = nfs_get_client(&cl_init, timeparms, ip_addr, authflavour, 1435 server->flags & NFS_MOUNT_NORESVPORT); 1436 if (IS_ERR(clp)) { 1437 error = PTR_ERR(clp); 1438 goto error; 1439 } 1440 1441 /* 1442 * Query for the lease time on clientid setup or renewal 1443 * 1444 * Note that this will be set on nfs_clients that were created 1445 * only for the DS role and did not set this bit, but now will 1446 * serve a dual role. 1447 */ 1448 set_bit(NFS_CS_CHECK_LEASE_TIME, &clp->cl_res_state); 1449 1450 server->nfs_client = clp; 1451 dprintk("<-- nfs4_set_client() = 0 [new %p]\n", clp); 1452 return 0; 1453 error: 1454 dprintk("<-- nfs4_set_client() = xerror %d\n", error); 1455 return error; 1456 } 1457 1458 /* 1459 * Set up a pNFS Data Server client. 1460 * 1461 * Return any existing nfs_client that matches server address,port,version 1462 * and minorversion. 1463 * 1464 * For a new nfs_client, use a soft mount (default), a low retrans and a 1465 * low timeout interval so that if a connection is lost, we retry through 1466 * the MDS. 1467 */ 1468 struct nfs_client *nfs4_set_ds_client(struct nfs_client* mds_clp, 1469 const struct sockaddr *ds_addr, 1470 int ds_addrlen, int ds_proto) 1471 { 1472 struct nfs_client_initdata cl_init = { 1473 .addr = ds_addr, 1474 .addrlen = ds_addrlen, 1475 .rpc_ops = &nfs_v4_clientops, 1476 .proto = ds_proto, 1477 .minorversion = mds_clp->cl_minorversion, 1478 .net = mds_clp->net, 1479 }; 1480 struct rpc_timeout ds_timeout = { 1481 .to_initval = 15 * HZ, 1482 .to_maxval = 15 * HZ, 1483 .to_retries = 1, 1484 .to_exponential = 1, 1485 }; 1486 struct nfs_client *clp; 1487 1488 /* 1489 * Set an authflavor equual to the MDS value. Use the MDS nfs_client 1490 * cl_ipaddr so as to use the same EXCHANGE_ID co_ownerid as the MDS 1491 * (section 13.1 RFC 5661). 1492 */ 1493 clp = nfs_get_client(&cl_init, &ds_timeout, mds_clp->cl_ipaddr, 1494 mds_clp->cl_rpcclient->cl_auth->au_flavor, 0); 1495 1496 dprintk("<-- %s %p\n", __func__, clp); 1497 return clp; 1498 } 1499 EXPORT_SYMBOL_GPL(nfs4_set_ds_client); 1500 1501 /* 1502 * Session has been established, and the client marked ready. 1503 * Set the mount rsize and wsize with negotiated fore channel 1504 * attributes which will be bound checked in nfs_server_set_fsinfo. 1505 */ 1506 static void nfs4_session_set_rwsize(struct nfs_server *server) 1507 { 1508 #ifdef CONFIG_NFS_V4_1 1509 struct nfs4_session *sess; 1510 u32 server_resp_sz; 1511 u32 server_rqst_sz; 1512 1513 if (!nfs4_has_session(server->nfs_client)) 1514 return; 1515 sess = server->nfs_client->cl_session; 1516 server_resp_sz = sess->fc_attrs.max_resp_sz - nfs41_maxread_overhead; 1517 server_rqst_sz = sess->fc_attrs.max_rqst_sz - nfs41_maxwrite_overhead; 1518 1519 if (server->rsize > server_resp_sz) 1520 server->rsize = server_resp_sz; 1521 if (server->wsize > server_rqst_sz) 1522 server->wsize = server_rqst_sz; 1523 #endif /* CONFIG_NFS_V4_1 */ 1524 } 1525 1526 static int nfs4_server_common_setup(struct nfs_server *server, 1527 struct nfs_fh *mntfh) 1528 { 1529 struct nfs_fattr *fattr; 1530 int error; 1531 1532 BUG_ON(!server->nfs_client); 1533 BUG_ON(!server->nfs_client->rpc_ops); 1534 BUG_ON(!server->nfs_client->rpc_ops->file_inode_ops); 1535 1536 /* data servers support only a subset of NFSv4.1 */ 1537 if (is_ds_only_client(server->nfs_client)) 1538 return -EPROTONOSUPPORT; 1539 1540 fattr = nfs_alloc_fattr(); 1541 if (fattr == NULL) 1542 return -ENOMEM; 1543 1544 /* We must ensure the session is initialised first */ 1545 error = nfs4_init_session(server); 1546 if (error < 0) 1547 goto out; 1548 1549 /* Probe the root fh to retrieve its FSID and filehandle */ 1550 error = nfs4_get_rootfh(server, mntfh); 1551 if (error < 0) 1552 goto out; 1553 1554 dprintk("Server FSID: %llx:%llx\n", 1555 (unsigned long long) server->fsid.major, 1556 (unsigned long long) server->fsid.minor); 1557 dprintk("Mount FH: %d\n", mntfh->size); 1558 1559 nfs4_session_set_rwsize(server); 1560 1561 error = nfs_probe_fsinfo(server, mntfh, fattr); 1562 if (error < 0) 1563 goto out; 1564 1565 if (server->namelen == 0 || server->namelen > NFS4_MAXNAMLEN) 1566 server->namelen = NFS4_MAXNAMLEN; 1567 1568 nfs_server_insert_lists(server); 1569 server->mount_time = jiffies; 1570 server->destroy = nfs4_destroy_server; 1571 out: 1572 nfs_free_fattr(fattr); 1573 return error; 1574 } 1575 1576 /* 1577 * Create a version 4 volume record 1578 */ 1579 static int nfs4_init_server(struct nfs_server *server, 1580 const struct nfs_parsed_mount_data *data) 1581 { 1582 struct rpc_timeout timeparms; 1583 int error; 1584 1585 dprintk("--> nfs4_init_server()\n"); 1586 1587 nfs_init_timeout_values(&timeparms, data->nfs_server.protocol, 1588 data->timeo, data->retrans); 1589 1590 /* Initialise the client representation from the mount data */ 1591 server->flags = data->flags; 1592 server->caps |= NFS_CAP_ATOMIC_OPEN|NFS_CAP_CHANGE_ATTR|NFS_CAP_POSIX_LOCK; 1593 if (!(data->flags & NFS_MOUNT_NORDIRPLUS)) 1594 server->caps |= NFS_CAP_READDIRPLUS; 1595 server->options = data->options; 1596 1597 /* Get a client record */ 1598 error = nfs4_set_client(server, 1599 data->nfs_server.hostname, 1600 (const struct sockaddr *)&data->nfs_server.address, 1601 data->nfs_server.addrlen, 1602 data->client_address, 1603 data->auth_flavors[0], 1604 data->nfs_server.protocol, 1605 &timeparms, 1606 data->minorversion, 1607 data->net); 1608 if (error < 0) 1609 goto error; 1610 1611 /* 1612 * Don't use NFS uid/gid mapping if we're using AUTH_SYS or lower 1613 * authentication. 1614 */ 1615 if (nfs4_disable_idmapping && data->auth_flavors[0] == RPC_AUTH_UNIX) 1616 server->caps |= NFS_CAP_UIDGID_NOMAP; 1617 1618 if (data->rsize) 1619 server->rsize = nfs_block_size(data->rsize, NULL); 1620 if (data->wsize) 1621 server->wsize = nfs_block_size(data->wsize, NULL); 1622 1623 server->acregmin = data->acregmin * HZ; 1624 server->acregmax = data->acregmax * HZ; 1625 server->acdirmin = data->acdirmin * HZ; 1626 server->acdirmax = data->acdirmax * HZ; 1627 1628 server->port = data->nfs_server.port; 1629 1630 error = nfs_init_server_rpcclient(server, &timeparms, data->auth_flavors[0]); 1631 1632 error: 1633 /* Done */ 1634 dprintk("<-- nfs4_init_server() = %d\n", error); 1635 return error; 1636 } 1637 1638 /* 1639 * Create a version 4 volume record 1640 * - keyed on server and FSID 1641 */ 1642 struct nfs_server *nfs4_create_server(const struct nfs_parsed_mount_data *data, 1643 struct nfs_fh *mntfh) 1644 { 1645 struct nfs_server *server; 1646 int error; 1647 1648 dprintk("--> nfs4_create_server()\n"); 1649 1650 server = nfs_alloc_server(); 1651 if (!server) 1652 return ERR_PTR(-ENOMEM); 1653 1654 /* set up the general RPC client */ 1655 error = nfs4_init_server(server, data); 1656 if (error < 0) 1657 goto error; 1658 1659 error = nfs4_server_common_setup(server, mntfh); 1660 if (error < 0) 1661 goto error; 1662 1663 dprintk("<-- nfs4_create_server() = %p\n", server); 1664 return server; 1665 1666 error: 1667 nfs_free_server(server); 1668 dprintk("<-- nfs4_create_server() = error %d\n", error); 1669 return ERR_PTR(error); 1670 } 1671 1672 /* 1673 * Create an NFS4 referral server record 1674 */ 1675 struct nfs_server *nfs4_create_referral_server(struct nfs_clone_mount *data, 1676 struct nfs_fh *mntfh) 1677 { 1678 struct nfs_client *parent_client; 1679 struct nfs_server *server, *parent_server; 1680 int error; 1681 1682 dprintk("--> nfs4_create_referral_server()\n"); 1683 1684 server = nfs_alloc_server(); 1685 if (!server) 1686 return ERR_PTR(-ENOMEM); 1687 1688 parent_server = NFS_SB(data->sb); 1689 parent_client = parent_server->nfs_client; 1690 1691 /* Initialise the client representation from the parent server */ 1692 nfs_server_copy_userdata(server, parent_server); 1693 server->caps |= NFS_CAP_ATOMIC_OPEN|NFS_CAP_CHANGE_ATTR; 1694 1695 /* Get a client representation. 1696 * Note: NFSv4 always uses TCP, */ 1697 error = nfs4_set_client(server, data->hostname, 1698 data->addr, 1699 data->addrlen, 1700 parent_client->cl_ipaddr, 1701 data->authflavor, 1702 rpc_protocol(parent_server->client), 1703 parent_server->client->cl_timeout, 1704 parent_client->cl_mvops->minor_version, 1705 parent_client->net); 1706 if (error < 0) 1707 goto error; 1708 1709 error = nfs_init_server_rpcclient(server, parent_server->client->cl_timeout, data->authflavor); 1710 if (error < 0) 1711 goto error; 1712 1713 error = nfs4_server_common_setup(server, mntfh); 1714 if (error < 0) 1715 goto error; 1716 1717 dprintk("<-- nfs_create_referral_server() = %p\n", server); 1718 return server; 1719 1720 error: 1721 nfs_free_server(server); 1722 dprintk("<-- nfs4_create_referral_server() = error %d\n", error); 1723 return ERR_PTR(error); 1724 } 1725 1726 #endif /* CONFIG_NFS_V4 */ 1727 1728 /* 1729 * Clone an NFS2, NFS3 or NFS4 server record 1730 */ 1731 struct nfs_server *nfs_clone_server(struct nfs_server *source, 1732 struct nfs_fh *fh, 1733 struct nfs_fattr *fattr) 1734 { 1735 struct nfs_server *server; 1736 struct nfs_fattr *fattr_fsinfo; 1737 int error; 1738 1739 dprintk("--> nfs_clone_server(,%llx:%llx,)\n", 1740 (unsigned long long) fattr->fsid.major, 1741 (unsigned long long) fattr->fsid.minor); 1742 1743 server = nfs_alloc_server(); 1744 if (!server) 1745 return ERR_PTR(-ENOMEM); 1746 1747 error = -ENOMEM; 1748 fattr_fsinfo = nfs_alloc_fattr(); 1749 if (fattr_fsinfo == NULL) 1750 goto out_free_server; 1751 1752 /* Copy data from the source */ 1753 server->nfs_client = source->nfs_client; 1754 server->destroy = source->destroy; 1755 atomic_inc(&server->nfs_client->cl_count); 1756 nfs_server_copy_userdata(server, source); 1757 1758 server->fsid = fattr->fsid; 1759 1760 error = nfs_init_server_rpcclient(server, 1761 source->client->cl_timeout, 1762 source->client->cl_auth->au_flavor); 1763 if (error < 0) 1764 goto out_free_server; 1765 if (!IS_ERR(source->client_acl)) 1766 nfs_init_server_aclclient(server); 1767 1768 /* probe the filesystem info for this server filesystem */ 1769 error = nfs_probe_fsinfo(server, fh, fattr_fsinfo); 1770 if (error < 0) 1771 goto out_free_server; 1772 1773 if (server->namelen == 0 || server->namelen > NFS4_MAXNAMLEN) 1774 server->namelen = NFS4_MAXNAMLEN; 1775 1776 dprintk("Cloned FSID: %llx:%llx\n", 1777 (unsigned long long) server->fsid.major, 1778 (unsigned long long) server->fsid.minor); 1779 1780 error = nfs_start_lockd(server); 1781 if (error < 0) 1782 goto out_free_server; 1783 1784 nfs_server_insert_lists(server); 1785 server->mount_time = jiffies; 1786 1787 nfs_free_fattr(fattr_fsinfo); 1788 dprintk("<-- nfs_clone_server() = %p\n", server); 1789 return server; 1790 1791 out_free_server: 1792 nfs_free_fattr(fattr_fsinfo); 1793 nfs_free_server(server); 1794 dprintk("<-- nfs_clone_server() = error %d\n", error); 1795 return ERR_PTR(error); 1796 } 1797 1798 void nfs_clients_init(struct net *net) 1799 { 1800 struct nfs_net *nn = net_generic(net, nfs_net_id); 1801 1802 INIT_LIST_HEAD(&nn->nfs_client_list); 1803 INIT_LIST_HEAD(&nn->nfs_volume_list); 1804 #ifdef CONFIG_NFS_V4 1805 idr_init(&nn->cb_ident_idr); 1806 #endif 1807 spin_lock_init(&nn->nfs_client_lock); 1808 } 1809 1810 #ifdef CONFIG_PROC_FS 1811 static struct proc_dir_entry *proc_fs_nfs; 1812 1813 static int nfs_server_list_open(struct inode *inode, struct file *file); 1814 static void *nfs_server_list_start(struct seq_file *p, loff_t *pos); 1815 static void *nfs_server_list_next(struct seq_file *p, void *v, loff_t *pos); 1816 static void nfs_server_list_stop(struct seq_file *p, void *v); 1817 static int nfs_server_list_show(struct seq_file *m, void *v); 1818 1819 static const struct seq_operations nfs_server_list_ops = { 1820 .start = nfs_server_list_start, 1821 .next = nfs_server_list_next, 1822 .stop = nfs_server_list_stop, 1823 .show = nfs_server_list_show, 1824 }; 1825 1826 static const struct file_operations nfs_server_list_fops = { 1827 .open = nfs_server_list_open, 1828 .read = seq_read, 1829 .llseek = seq_lseek, 1830 .release = seq_release, 1831 .owner = THIS_MODULE, 1832 }; 1833 1834 static int nfs_volume_list_open(struct inode *inode, struct file *file); 1835 static void *nfs_volume_list_start(struct seq_file *p, loff_t *pos); 1836 static void *nfs_volume_list_next(struct seq_file *p, void *v, loff_t *pos); 1837 static void nfs_volume_list_stop(struct seq_file *p, void *v); 1838 static int nfs_volume_list_show(struct seq_file *m, void *v); 1839 1840 static const struct seq_operations nfs_volume_list_ops = { 1841 .start = nfs_volume_list_start, 1842 .next = nfs_volume_list_next, 1843 .stop = nfs_volume_list_stop, 1844 .show = nfs_volume_list_show, 1845 }; 1846 1847 static const struct file_operations nfs_volume_list_fops = { 1848 .open = nfs_volume_list_open, 1849 .read = seq_read, 1850 .llseek = seq_lseek, 1851 .release = seq_release, 1852 .owner = THIS_MODULE, 1853 }; 1854 1855 /* 1856 * open "/proc/fs/nfsfs/servers" which provides a summary of servers with which 1857 * we're dealing 1858 */ 1859 static int nfs_server_list_open(struct inode *inode, struct file *file) 1860 { 1861 struct seq_file *m; 1862 int ret; 1863 struct pid_namespace *pid_ns = file->f_dentry->d_sb->s_fs_info; 1864 struct net *net = pid_ns->child_reaper->nsproxy->net_ns; 1865 1866 ret = seq_open(file, &nfs_server_list_ops); 1867 if (ret < 0) 1868 return ret; 1869 1870 m = file->private_data; 1871 m->private = net; 1872 1873 return 0; 1874 } 1875 1876 /* 1877 * set up the iterator to start reading from the server list and return the first item 1878 */ 1879 static void *nfs_server_list_start(struct seq_file *m, loff_t *_pos) 1880 { 1881 struct nfs_net *nn = net_generic(m->private, nfs_net_id); 1882 1883 /* lock the list against modification */ 1884 spin_lock(&nn->nfs_client_lock); 1885 return seq_list_start_head(&nn->nfs_client_list, *_pos); 1886 } 1887 1888 /* 1889 * move to next server 1890 */ 1891 static void *nfs_server_list_next(struct seq_file *p, void *v, loff_t *pos) 1892 { 1893 struct nfs_net *nn = net_generic(p->private, nfs_net_id); 1894 1895 return seq_list_next(v, &nn->nfs_client_list, pos); 1896 } 1897 1898 /* 1899 * clean up after reading from the transports list 1900 */ 1901 static void nfs_server_list_stop(struct seq_file *p, void *v) 1902 { 1903 struct nfs_net *nn = net_generic(p->private, nfs_net_id); 1904 1905 spin_unlock(&nn->nfs_client_lock); 1906 } 1907 1908 /* 1909 * display a header line followed by a load of call lines 1910 */ 1911 static int nfs_server_list_show(struct seq_file *m, void *v) 1912 { 1913 struct nfs_client *clp; 1914 struct nfs_net *nn = net_generic(m->private, nfs_net_id); 1915 1916 /* display header on line 1 */ 1917 if (v == &nn->nfs_client_list) { 1918 seq_puts(m, "NV SERVER PORT USE HOSTNAME\n"); 1919 return 0; 1920 } 1921 1922 /* display one transport per line on subsequent lines */ 1923 clp = list_entry(v, struct nfs_client, cl_share_link); 1924 1925 /* Check if the client is initialized */ 1926 if (clp->cl_cons_state != NFS_CS_READY) 1927 return 0; 1928 1929 rcu_read_lock(); 1930 seq_printf(m, "v%u %s %s %3d %s\n", 1931 clp->rpc_ops->version, 1932 rpc_peeraddr2str(clp->cl_rpcclient, RPC_DISPLAY_HEX_ADDR), 1933 rpc_peeraddr2str(clp->cl_rpcclient, RPC_DISPLAY_HEX_PORT), 1934 atomic_read(&clp->cl_count), 1935 clp->cl_hostname); 1936 rcu_read_unlock(); 1937 1938 return 0; 1939 } 1940 1941 /* 1942 * open "/proc/fs/nfsfs/volumes" which provides a summary of extant volumes 1943 */ 1944 static int nfs_volume_list_open(struct inode *inode, struct file *file) 1945 { 1946 struct seq_file *m; 1947 int ret; 1948 struct pid_namespace *pid_ns = file->f_dentry->d_sb->s_fs_info; 1949 struct net *net = pid_ns->child_reaper->nsproxy->net_ns; 1950 1951 ret = seq_open(file, &nfs_volume_list_ops); 1952 if (ret < 0) 1953 return ret; 1954 1955 m = file->private_data; 1956 m->private = net; 1957 1958 return 0; 1959 } 1960 1961 /* 1962 * set up the iterator to start reading from the volume list and return the first item 1963 */ 1964 static void *nfs_volume_list_start(struct seq_file *m, loff_t *_pos) 1965 { 1966 struct nfs_net *nn = net_generic(m->private, nfs_net_id); 1967 1968 /* lock the list against modification */ 1969 spin_lock(&nn->nfs_client_lock); 1970 return seq_list_start_head(&nn->nfs_volume_list, *_pos); 1971 } 1972 1973 /* 1974 * move to next volume 1975 */ 1976 static void *nfs_volume_list_next(struct seq_file *p, void *v, loff_t *pos) 1977 { 1978 struct nfs_net *nn = net_generic(p->private, nfs_net_id); 1979 1980 return seq_list_next(v, &nn->nfs_volume_list, pos); 1981 } 1982 1983 /* 1984 * clean up after reading from the transports list 1985 */ 1986 static void nfs_volume_list_stop(struct seq_file *p, void *v) 1987 { 1988 struct nfs_net *nn = net_generic(p->private, nfs_net_id); 1989 1990 spin_unlock(&nn->nfs_client_lock); 1991 } 1992 1993 /* 1994 * display a header line followed by a load of call lines 1995 */ 1996 static int nfs_volume_list_show(struct seq_file *m, void *v) 1997 { 1998 struct nfs_server *server; 1999 struct nfs_client *clp; 2000 char dev[8], fsid[17]; 2001 struct nfs_net *nn = net_generic(m->private, nfs_net_id); 2002 2003 /* display header on line 1 */ 2004 if (v == &nn->nfs_volume_list) { 2005 seq_puts(m, "NV SERVER PORT DEV FSID FSC\n"); 2006 return 0; 2007 } 2008 /* display one transport per line on subsequent lines */ 2009 server = list_entry(v, struct nfs_server, master_link); 2010 clp = server->nfs_client; 2011 2012 snprintf(dev, 8, "%u:%u", 2013 MAJOR(server->s_dev), MINOR(server->s_dev)); 2014 2015 snprintf(fsid, 17, "%llx:%llx", 2016 (unsigned long long) server->fsid.major, 2017 (unsigned long long) server->fsid.minor); 2018 2019 rcu_read_lock(); 2020 seq_printf(m, "v%u %s %s %-7s %-17s %s\n", 2021 clp->rpc_ops->version, 2022 rpc_peeraddr2str(clp->cl_rpcclient, RPC_DISPLAY_HEX_ADDR), 2023 rpc_peeraddr2str(clp->cl_rpcclient, RPC_DISPLAY_HEX_PORT), 2024 dev, 2025 fsid, 2026 nfs_server_fscache_state(server)); 2027 rcu_read_unlock(); 2028 2029 return 0; 2030 } 2031 2032 /* 2033 * initialise the /proc/fs/nfsfs/ directory 2034 */ 2035 int __init nfs_fs_proc_init(void) 2036 { 2037 struct proc_dir_entry *p; 2038 2039 proc_fs_nfs = proc_mkdir("fs/nfsfs", NULL); 2040 if (!proc_fs_nfs) 2041 goto error_0; 2042 2043 /* a file of servers with which we're dealing */ 2044 p = proc_create("servers", S_IFREG|S_IRUGO, 2045 proc_fs_nfs, &nfs_server_list_fops); 2046 if (!p) 2047 goto error_1; 2048 2049 /* a file of volumes that we have mounted */ 2050 p = proc_create("volumes", S_IFREG|S_IRUGO, 2051 proc_fs_nfs, &nfs_volume_list_fops); 2052 if (!p) 2053 goto error_2; 2054 return 0; 2055 2056 error_2: 2057 remove_proc_entry("servers", proc_fs_nfs); 2058 error_1: 2059 remove_proc_entry("fs/nfsfs", NULL); 2060 error_0: 2061 return -ENOMEM; 2062 } 2063 2064 /* 2065 * clean up the /proc/fs/nfsfs/ directory 2066 */ 2067 void nfs_fs_proc_exit(void) 2068 { 2069 remove_proc_entry("volumes", proc_fs_nfs); 2070 remove_proc_entry("servers", proc_fs_nfs); 2071 remove_proc_entry("fs/nfsfs", NULL); 2072 } 2073 2074 #endif /* CONFIG_PROC_FS */ 2075 2076 module_param(nfs4_disable_idmapping, bool, 0644); 2077 MODULE_PARM_DESC(nfs4_disable_idmapping, 2078 "Turn off NFSv4 idmapping when using 'sec=sys'"); 2079