Print this page
5045 use atomic_{inc,dec}_* instead of atomic_add_*


 656 
 657         ASSERT(lop);
 658         ASSERT(lop->lo_flags & NFS4_LOCK_SEQID_INUSE);
 659 
 660         mutex_enter(&lop->lo_lock);
 661         lop->lock_stateid = stateid;
 662         mutex_exit(&lop->lo_lock);
 663 }
 664 
 665 /*
 666  * Sequence number used when a new open owner is needed.
 667  * This is used so as to not confuse the server.  Since a open owner
 668  * is based off of cred, a cred could be re-used quickly, and the server
 669  * may not release all state for a cred.
 670  */
 671 static uint64_t open_owner_seq_num = 0;
 672 
 673 uint64_t
 674 nfs4_get_new_oo_name(void)
 675 {
 676         return (atomic_add_64_nv(&open_owner_seq_num, 1));
 677 }
 678 
 679 /*
 680  * Create a new open owner and add it to the open owner hash table.
 681  */
 682 nfs4_open_owner_t *
 683 create_open_owner(cred_t *cr, mntinfo4_t *mi)
 684 {
 685         nfs4_open_owner_t       *oop;
 686         nfs4_oo_hash_bucket_t   *bucketp;
 687 
 688         oop = kmem_alloc(sizeof (nfs4_open_owner_t), KM_SLEEP);
 689         /*
 690          * Make sure the cred doesn't go away when we put this open owner
 691          * on the free list, as well as make crcmp() a valid check.
 692          */
 693         crhold(cr);
 694         oop->oo_cred = cr;
 695         mutex_init(&oop->oo_lock, NULL, MUTEX_DEFAULT, NULL);
 696         oop->oo_ref_count = 1;


 819         NFS4_DEBUG(nfs4_client_state_debug, (CE_NOTE,
 820             "create_lock_owner: pid %x", pid));
 821 
 822         ASSERT(mutex_owned(&rp->r_statev4_lock));
 823 
 824         lop = kmem_alloc(sizeof (nfs4_lock_owner_t), KM_SLEEP);
 825         lop->lo_ref_count = 2;
 826         lop->lo_valid = 1;
 827         bzero(&lop->lock_stateid, sizeof (stateid4));
 828         lop->lo_pid = pid;
 829         lop->lock_seqid = 0;
 830         lop->lo_pending_rqsts = 0;
 831         lop->lo_just_created = NFS4_JUST_CREATED;
 832         lop->lo_flags = 0;
 833         lop->lo_seqid_holder = NULL;
 834 
 835         /*
 836          * A Solaris lock_owner is <seq_num><pid>
 837          */
 838         lop->lock_owner_name.ln_seq_num =
 839             atomic_add_64_nv(&lock_owner_seq_num, 1);
 840         lop->lock_owner_name.ln_pid = pid;
 841 
 842         cv_init(&lop->lo_cv_seqid_sync, NULL, CV_DEFAULT, NULL);
 843         mutex_init(&lop->lo_lock, NULL, MUTEX_DEFAULT, NULL);
 844 
 845         mutex_enter(&lop->lo_lock);
 846 
 847         /* now add the lock owner to rp */
 848         lop->lo_prev_rnode = &rp->r_lo_head;
 849         lop->lo_next_rnode = rp->r_lo_head.lo_next_rnode;
 850         rp->r_lo_head.lo_next_rnode->lo_prev_rnode = lop;
 851         rp->r_lo_head.lo_next_rnode = lop;
 852 
 853         return (lop);
 854 
 855 }
 856 
 857 /*
 858  * This sets the lock seqid of a lock owner.
 859  */


 866         ASSERT(lop != NULL);
 867         ASSERT(lop->lo_flags & NFS4_LOCK_SEQID_INUSE);
 868 
 869         lop->lock_seqid = seqid;
 870 }
 871 
 872 static void
 873 nfs4_set_new_lock_owner_args(lock_owner4 *owner, pid_t pid)
 874 {
 875         nfs4_lo_name_t *cast_namep;
 876 
 877         NFS4_DEBUG(nfs4_client_state_debug, (CE_NOTE,
 878             "nfs4_set_new_lock_owner_args"));
 879 
 880         owner->owner_len = sizeof (*cast_namep);
 881         owner->owner_val = kmem_alloc(owner->owner_len, KM_SLEEP);
 882         /*
 883          * A Solaris lock_owner is <seq_num><pid>
 884          */
 885         cast_namep = (nfs4_lo_name_t *)owner->owner_val;
 886         cast_namep->ln_seq_num = atomic_add_64_nv(&lock_owner_seq_num, 1);
 887         cast_namep->ln_pid = pid;
 888 }
 889 
 890 /*
 891  * Fill in the lock owner args.
 892  */
 893 void
 894 nfs4_setlockowner_args(lock_owner4 *owner, rnode4_t *rp, pid_t pid)
 895 {
 896         nfs4_lock_owner_t *lop;
 897 
 898         NFS4_DEBUG(nfs4_client_state_debug, (CE_NOTE,
 899             "nfs4_setlockowner_args"));
 900 
 901         /* This increments lop's ref count */
 902         lop = find_lock_owner(rp, pid, LOWN_VALID_STATEID);
 903 
 904         if (!lop)
 905                 goto make_up_args;
 906 




 656 
 657         ASSERT(lop);
 658         ASSERT(lop->lo_flags & NFS4_LOCK_SEQID_INUSE);
 659 
 660         mutex_enter(&lop->lo_lock);
 661         lop->lock_stateid = stateid;
 662         mutex_exit(&lop->lo_lock);
 663 }
 664 
 665 /*
 666  * Sequence number used when a new open owner is needed.
 667  * This is used so as to not confuse the server.  Since a open owner
 668  * is based off of cred, a cred could be re-used quickly, and the server
 669  * may not release all state for a cred.
 670  */
 671 static uint64_t open_owner_seq_num = 0;
 672 
 673 uint64_t
 674 nfs4_get_new_oo_name(void)
 675 {
 676         return (atomic_inc_64_nv(&open_owner_seq_num));
 677 }
 678 
 679 /*
 680  * Create a new open owner and add it to the open owner hash table.
 681  */
 682 nfs4_open_owner_t *
 683 create_open_owner(cred_t *cr, mntinfo4_t *mi)
 684 {
 685         nfs4_open_owner_t       *oop;
 686         nfs4_oo_hash_bucket_t   *bucketp;
 687 
 688         oop = kmem_alloc(sizeof (nfs4_open_owner_t), KM_SLEEP);
 689         /*
 690          * Make sure the cred doesn't go away when we put this open owner
 691          * on the free list, as well as make crcmp() a valid check.
 692          */
 693         crhold(cr);
 694         oop->oo_cred = cr;
 695         mutex_init(&oop->oo_lock, NULL, MUTEX_DEFAULT, NULL);
 696         oop->oo_ref_count = 1;


 819         NFS4_DEBUG(nfs4_client_state_debug, (CE_NOTE,
 820             "create_lock_owner: pid %x", pid));
 821 
 822         ASSERT(mutex_owned(&rp->r_statev4_lock));
 823 
 824         lop = kmem_alloc(sizeof (nfs4_lock_owner_t), KM_SLEEP);
 825         lop->lo_ref_count = 2;
 826         lop->lo_valid = 1;
 827         bzero(&lop->lock_stateid, sizeof (stateid4));
 828         lop->lo_pid = pid;
 829         lop->lock_seqid = 0;
 830         lop->lo_pending_rqsts = 0;
 831         lop->lo_just_created = NFS4_JUST_CREATED;
 832         lop->lo_flags = 0;
 833         lop->lo_seqid_holder = NULL;
 834 
 835         /*
 836          * A Solaris lock_owner is <seq_num><pid>
 837          */
 838         lop->lock_owner_name.ln_seq_num =
 839             atomic_inc_64_nv(&lock_owner_seq_num);
 840         lop->lock_owner_name.ln_pid = pid;
 841 
 842         cv_init(&lop->lo_cv_seqid_sync, NULL, CV_DEFAULT, NULL);
 843         mutex_init(&lop->lo_lock, NULL, MUTEX_DEFAULT, NULL);
 844 
 845         mutex_enter(&lop->lo_lock);
 846 
 847         /* now add the lock owner to rp */
 848         lop->lo_prev_rnode = &rp->r_lo_head;
 849         lop->lo_next_rnode = rp->r_lo_head.lo_next_rnode;
 850         rp->r_lo_head.lo_next_rnode->lo_prev_rnode = lop;
 851         rp->r_lo_head.lo_next_rnode = lop;
 852 
 853         return (lop);
 854 
 855 }
 856 
 857 /*
 858  * This sets the lock seqid of a lock owner.
 859  */


 866         ASSERT(lop != NULL);
 867         ASSERT(lop->lo_flags & NFS4_LOCK_SEQID_INUSE);
 868 
 869         lop->lock_seqid = seqid;
 870 }
 871 
 872 static void
 873 nfs4_set_new_lock_owner_args(lock_owner4 *owner, pid_t pid)
 874 {
 875         nfs4_lo_name_t *cast_namep;
 876 
 877         NFS4_DEBUG(nfs4_client_state_debug, (CE_NOTE,
 878             "nfs4_set_new_lock_owner_args"));
 879 
 880         owner->owner_len = sizeof (*cast_namep);
 881         owner->owner_val = kmem_alloc(owner->owner_len, KM_SLEEP);
 882         /*
 883          * A Solaris lock_owner is <seq_num><pid>
 884          */
 885         cast_namep = (nfs4_lo_name_t *)owner->owner_val;
 886         cast_namep->ln_seq_num = atomic_inc_64_nv(&lock_owner_seq_num);
 887         cast_namep->ln_pid = pid;
 888 }
 889 
 890 /*
 891  * Fill in the lock owner args.
 892  */
 893 void
 894 nfs4_setlockowner_args(lock_owner4 *owner, rnode4_t *rp, pid_t pid)
 895 {
 896         nfs4_lock_owner_t *lop;
 897 
 898         NFS4_DEBUG(nfs4_client_state_debug, (CE_NOTE,
 899             "nfs4_setlockowner_args"));
 900 
 901         /* This increments lop's ref count */
 902         lop = find_lock_owner(rp, pid, LOWN_VALID_STATEID);
 903 
 904         if (!lop)
 905                 goto make_up_args;
 906