Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

NFS: Refactor nfs_get_client(): add nfs_found_client()

Clean up: Code that takes and releases nfs_client_lock remains in
nfs_get_client(). Logic that handles a pre-existing nfs_client is
moved to a separate function.

No behavior change is expected.

Signed-off-by: Chuck Lever <chuck.lever@oracle.com>
Signed-off-by: Trond Myklebust <Trond.Myklebust@netapp.com>

authored by

Chuck Lever and committed by
Trond Myklebust
f411703a f092075d

+37 -30
+37 -30
fs/nfs/client.c
··· 506 506 } 507 507 508 508 /* 509 + * Found an existing client. Make sure it's ready before returning. 510 + */ 511 + static struct nfs_client * 512 + nfs_found_client(const struct nfs_client_initdata *cl_init, 513 + struct nfs_client *clp) 514 + { 515 + int error; 516 + 517 + error = wait_event_killable(nfs_client_active_wq, 518 + clp->cl_cons_state < NFS_CS_INITING); 519 + if (error < 0) { 520 + nfs_put_client(clp); 521 + return ERR_PTR(-ERESTARTSYS); 522 + } 523 + 524 + if (clp->cl_cons_state < NFS_CS_READY) { 525 + error = clp->cl_cons_state; 526 + nfs_put_client(clp); 527 + return ERR_PTR(error); 528 + } 529 + 530 + BUG_ON(clp->cl_cons_state != NFS_CS_READY); 531 + 532 + dprintk("<-- %s found nfs_client %p for %s\n", 533 + __func__, clp, cl_init->hostname ?: ""); 534 + return clp; 535 + } 536 + 537 + /* 509 538 * Look up a client by IP address and protocol version 510 539 * - creates a new record if one doesn't yet exist 511 540 */ ··· 557 528 spin_lock(&nn->nfs_client_lock); 558 529 559 530 clp = nfs_match_client(cl_init); 560 - if (clp) 561 - goto found_client; 531 + if (clp) { 532 + spin_unlock(&nn->nfs_client_lock); 533 + if (new) 534 + nfs_free_client(new); 535 + return nfs_found_client(cl_init, clp); 536 + } 562 537 if (new) 563 538 goto install_client; 564 539 ··· 571 538 new = nfs_alloc_client(cl_init); 572 539 } while (!IS_ERR(new)); 573 540 574 - dprintk("--> nfs_get_client() = %ld [failed]\n", PTR_ERR(new)); 541 + dprintk("<-- nfs_get_client() Failed to find %s (%ld)\n", 542 + cl_init->hostname ?: "", PTR_ERR(new)); 575 543 return new; 576 544 577 545 /* install a new client and return with it unready */ ··· 588 554 return ERR_PTR(error); 589 555 } 590 556 dprintk("--> nfs_get_client() = %p [new]\n", clp); 591 - return clp; 592 - 593 - /* found an existing client 594 - * - make sure it's ready before returning 595 - */ 596 - found_client: 597 - spin_unlock(&nn->nfs_client_lock); 598 - 599 - if (new) 600 - nfs_free_client(new); 601 - 602 - error = wait_event_killable(nfs_client_active_wq, 603 - clp->cl_cons_state < NFS_CS_INITING); 604 - if (error < 0) { 605 - nfs_put_client(clp); 606 - return ERR_PTR(-ERESTARTSYS); 607 - } 608 - 609 - if (clp->cl_cons_state < NFS_CS_READY) { 610 - error = clp->cl_cons_state; 611 - nfs_put_client(clp); 612 - return ERR_PTR(error); 613 - } 614 - 615 - BUG_ON(clp->cl_cons_state != NFS_CS_READY); 616 - 617 - dprintk("--> nfs_get_client() = %p [share]\n", clp); 618 557 return clp; 619 558 } 620 559