917 /*
918 * Get an auth handle.
919 */
920 error = authget(svp, cp->ch_client, cr);
921 if (error || cp->ch_client->cl_auth == NULL) {
922 CLNT_DESTROY(cp->ch_client);
923 kmem_cache_free(chtab4_cache, cp);
924 return ((error != 0) ? error : EINTR);
925 }
926 ch->ch_timesused++;
927 *newcl = cp->ch_client;
928 *chp = cp;
929 return (0);
930 }
931
932 /*
933 * There weren't any free client handles which fit, so allocate
934 * a new one and use that.
935 */
936 #ifdef DEBUG
937 atomic_add_64(&nfscl->nfscl_stat.clalloc.value.ui64, 1);
938 #endif
939 mutex_exit(&nfscl->nfscl_chtable4_lock);
940
941 nfscl->nfscl_stat.cltoomany.value.ui64++;
942 if (newch != NULL) {
943 kmem_free(newch->ch_protofmly, strlen(newch->ch_protofmly) + 1);
944 kmem_free(newch, sizeof (*newch));
945 }
946
947 cp = kmem_cache_alloc(chtab4_cache, KM_SLEEP);
948 cp->ch_head = ch;
949
950 sigintr(&smask, (int)ci->cl_flags & MI4_INT);
951 error = clnt_tli_kcreate(svp->sv_knconf, &svp->sv_addr, ci->cl_prog,
952 ci->cl_vers, ci->cl_readsize, ci->cl_retrans, cr, &cp->ch_client);
953 sigunintr(&smask);
954
955 if (error != 0) {
956 kmem_cache_free(chtab4_cache, cp);
957 #ifdef DEBUG
958 atomic_add_64(&nfscl->nfscl_stat.clalloc.value.ui64, -1);
959 #endif
960 /*
961 * Warning is unnecessary if error is EINTR.
962 */
963 if (error != EINTR) {
964 nfs_cmn_err(error, CE_WARN,
965 "clget: couldn't create handle: %m\n");
966 }
967 return (error);
968 }
969 (void) CLNT_CONTROL(cp->ch_client, CLSET_PROGRESS, NULL);
970 auth_destroy(cp->ch_client->cl_auth);
971
972 /*
973 * Get an auth handle.
974 */
975 error = authget(svp, cp->ch_client, cr);
976 if (error || cp->ch_client->cl_auth == NULL) {
977 CLNT_DESTROY(cp->ch_client);
978 kmem_cache_free(chtab4_cache, cp);
979 #ifdef DEBUG
980 atomic_add_64(&nfscl->nfscl_stat.clalloc.value.ui64, -1);
981 #endif
982 return ((error != 0) ? error : EINTR);
983 }
984 ch->ch_timesused++;
985 *newcl = cp->ch_client;
986 ASSERT(cp->ch_client->cl_nosignal == FALSE);
987 *chp = cp;
988 return (0);
989 }
990
991 static int
992 nfs_clget4(mntinfo4_t *mi, servinfo4_t *svp, cred_t *cr, CLIENT **newcl,
993 struct chtab **chp, struct nfs4_clnt *nfscl)
994 {
995 clinfo_t ci;
996 bool_t is_recov;
997 int firstcall, error = 0;
998
999 /*
1000 * Set read buffer size to rsize
2629
2630 if (rdip != NULL) {
2631 rc = &rdip->rc;
2632 rc->data = (void *)rdip;
2633 rc->nfs4_cookie = 0;
2634 rc->nfs4_ncookie = 0;
2635 rc->entries = NULL;
2636 rc->eof = 0;
2637 rc->entlen = 0;
2638 rc->buflen = 0;
2639 rc->actlen = 0;
2640 /*
2641 * A readdir is required so set the flag.
2642 */
2643 rc->flags = RDDIRREQ;
2644 cv_init(&rc->cv, NULL, CV_DEFAULT, NULL);
2645 rc->error = 0;
2646 mutex_init(&rdip->lock, NULL, MUTEX_DEFAULT, NULL);
2647 rdip->count = 1;
2648 #ifdef DEBUG
2649 atomic_add_64(&clstat4_debug.dirent.value.ui64, 1);
2650 #endif
2651 }
2652 return (rc);
2653 }
2654
2655 /*
2656 * Increment the reference count to this cache element.
2657 */
2658 static void
2659 rddir4_cache_hold(rddir4_cache *rc)
2660 {
2661 rddir4_cache_impl *rdip = (rddir4_cache_impl *)rc->data;
2662
2663 mutex_enter(&rdip->lock);
2664 rdip->count++;
2665 mutex_exit(&rdip->lock);
2666 }
2667
2668 /*
2669 * Release a reference to this cache element. If the count is zero then
2686 }
2687
2688 mutex_enter(&rdip->lock);
2689 ASSERT(rdip->count > 0);
2690 if (--rdip->count == 0) {
2691 mutex_exit(&rdip->lock);
2692 rddir4_cache_free(rdip);
2693 } else
2694 mutex_exit(&rdip->lock);
2695 }
2696
2697 /*
2698 * Free a cache element.
2699 */
2700 static void
2701 rddir4_cache_free(rddir4_cache_impl *rdip)
2702 {
2703 rddir4_cache *rc = &rdip->rc;
2704
2705 #ifdef DEBUG
2706 atomic_add_64(&clstat4_debug.dirent.value.ui64, -1);
2707 #endif
2708 if (rc->entries != NULL)
2709 kmem_free(rc->entries, rc->buflen);
2710 cv_destroy(&rc->cv);
2711 mutex_destroy(&rdip->lock);
2712 kmem_free(rdip, sizeof (*rdip));
2713 }
2714
2715 /*
2716 * Snapshot callback for nfs:0:nfs4_client as registered with the kstat
2717 * framework.
2718 */
2719 static int
2720 cl4_snapshot(kstat_t *ksp, void *buf, int rw)
2721 {
2722 ksp->ks_snaptime = gethrtime();
2723 if (rw == KSTAT_WRITE) {
2724 bcopy(buf, ksp->ks_private, sizeof (clstat4_tmpl));
2725 #ifdef DEBUG
2726 /*
|
917 /*
918 * Get an auth handle.
919 */
920 error = authget(svp, cp->ch_client, cr);
921 if (error || cp->ch_client->cl_auth == NULL) {
922 CLNT_DESTROY(cp->ch_client);
923 kmem_cache_free(chtab4_cache, cp);
924 return ((error != 0) ? error : EINTR);
925 }
926 ch->ch_timesused++;
927 *newcl = cp->ch_client;
928 *chp = cp;
929 return (0);
930 }
931
932 /*
933 * There weren't any free client handles which fit, so allocate
934 * a new one and use that.
935 */
936 #ifdef DEBUG
937 atomic_inc_64(&nfscl->nfscl_stat.clalloc.value.ui64);
938 #endif
939 mutex_exit(&nfscl->nfscl_chtable4_lock);
940
941 nfscl->nfscl_stat.cltoomany.value.ui64++;
942 if (newch != NULL) {
943 kmem_free(newch->ch_protofmly, strlen(newch->ch_protofmly) + 1);
944 kmem_free(newch, sizeof (*newch));
945 }
946
947 cp = kmem_cache_alloc(chtab4_cache, KM_SLEEP);
948 cp->ch_head = ch;
949
950 sigintr(&smask, (int)ci->cl_flags & MI4_INT);
951 error = clnt_tli_kcreate(svp->sv_knconf, &svp->sv_addr, ci->cl_prog,
952 ci->cl_vers, ci->cl_readsize, ci->cl_retrans, cr, &cp->ch_client);
953 sigunintr(&smask);
954
955 if (error != 0) {
956 kmem_cache_free(chtab4_cache, cp);
957 #ifdef DEBUG
958 atomic_dec_64(&nfscl->nfscl_stat.clalloc.value.ui64);
959 #endif
960 /*
961 * Warning is unnecessary if error is EINTR.
962 */
963 if (error != EINTR) {
964 nfs_cmn_err(error, CE_WARN,
965 "clget: couldn't create handle: %m\n");
966 }
967 return (error);
968 }
969 (void) CLNT_CONTROL(cp->ch_client, CLSET_PROGRESS, NULL);
970 auth_destroy(cp->ch_client->cl_auth);
971
972 /*
973 * Get an auth handle.
974 */
975 error = authget(svp, cp->ch_client, cr);
976 if (error || cp->ch_client->cl_auth == NULL) {
977 CLNT_DESTROY(cp->ch_client);
978 kmem_cache_free(chtab4_cache, cp);
979 #ifdef DEBUG
980 atomic_dec_64(&nfscl->nfscl_stat.clalloc.value.ui64);
981 #endif
982 return ((error != 0) ? error : EINTR);
983 }
984 ch->ch_timesused++;
985 *newcl = cp->ch_client;
986 ASSERT(cp->ch_client->cl_nosignal == FALSE);
987 *chp = cp;
988 return (0);
989 }
990
991 static int
992 nfs_clget4(mntinfo4_t *mi, servinfo4_t *svp, cred_t *cr, CLIENT **newcl,
993 struct chtab **chp, struct nfs4_clnt *nfscl)
994 {
995 clinfo_t ci;
996 bool_t is_recov;
997 int firstcall, error = 0;
998
999 /*
1000 * Set read buffer size to rsize
2629
2630 if (rdip != NULL) {
2631 rc = &rdip->rc;
2632 rc->data = (void *)rdip;
2633 rc->nfs4_cookie = 0;
2634 rc->nfs4_ncookie = 0;
2635 rc->entries = NULL;
2636 rc->eof = 0;
2637 rc->entlen = 0;
2638 rc->buflen = 0;
2639 rc->actlen = 0;
2640 /*
2641 * A readdir is required so set the flag.
2642 */
2643 rc->flags = RDDIRREQ;
2644 cv_init(&rc->cv, NULL, CV_DEFAULT, NULL);
2645 rc->error = 0;
2646 mutex_init(&rdip->lock, NULL, MUTEX_DEFAULT, NULL);
2647 rdip->count = 1;
2648 #ifdef DEBUG
2649 atomic_inc_64(&clstat4_debug.dirent.value.ui64);
2650 #endif
2651 }
2652 return (rc);
2653 }
2654
2655 /*
2656 * Increment the reference count to this cache element.
2657 */
2658 static void
2659 rddir4_cache_hold(rddir4_cache *rc)
2660 {
2661 rddir4_cache_impl *rdip = (rddir4_cache_impl *)rc->data;
2662
2663 mutex_enter(&rdip->lock);
2664 rdip->count++;
2665 mutex_exit(&rdip->lock);
2666 }
2667
2668 /*
2669 * Release a reference to this cache element. If the count is zero then
2686 }
2687
2688 mutex_enter(&rdip->lock);
2689 ASSERT(rdip->count > 0);
2690 if (--rdip->count == 0) {
2691 mutex_exit(&rdip->lock);
2692 rddir4_cache_free(rdip);
2693 } else
2694 mutex_exit(&rdip->lock);
2695 }
2696
2697 /*
2698 * Free a cache element.
2699 */
2700 static void
2701 rddir4_cache_free(rddir4_cache_impl *rdip)
2702 {
2703 rddir4_cache *rc = &rdip->rc;
2704
2705 #ifdef DEBUG
2706 atomic_dec_64(&clstat4_debug.dirent.value.ui64);
2707 #endif
2708 if (rc->entries != NULL)
2709 kmem_free(rc->entries, rc->buflen);
2710 cv_destroy(&rc->cv);
2711 mutex_destroy(&rdip->lock);
2712 kmem_free(rdip, sizeof (*rdip));
2713 }
2714
2715 /*
2716 * Snapshot callback for nfs:0:nfs4_client as registered with the kstat
2717 * framework.
2718 */
2719 static int
2720 cl4_snapshot(kstat_t *ksp, void *buf, int rw)
2721 {
2722 ksp->ks_snaptime = gethrtime();
2723 if (rw == KSTAT_WRITE) {
2724 bcopy(buf, ksp->ks_private, sizeof (clstat4_tmpl));
2725 #ifdef DEBUG
2726 /*
|