798 sip->next = NULL;
799 sip->prev = NULL;
800
801 rw_init(&sip->oldstate_lock, NULL, RW_DEFAULT, NULL);
802 /*
803 * This initial dummy entry is required to setup for insque/remque.
804 * It must be skipped over whenever the list is traversed.
805 */
806 oldstate = kmem_alloc(sizeof (rfs4_oldstate_t), KM_SLEEP);
807 /* insque/remque require initial list entry to be self-terminated */
808 oldstate->next = oldstate;
809 oldstate->prev = oldstate;
810 sip->oldstate = oldstate;
811
812
813 sip->dss_npaths = dss_npaths;
814 sip->dss_paths = kmem_alloc(dss_npaths *
815 sizeof (rfs4_dss_path_t *), KM_SLEEP);
816
817 for (i = 0; i < dss_npaths; i++) {
818 /* CSTYLED */
819 sip->dss_paths[i] = rfs4_dss_newpath(nsrv4, sip, dss_paths[i], i);
820 }
821
822 mutex_enter(&nsrv4->servinst_lock);
823 if (nsrv4->nfs4_cur_servinst != NULL) {
824 /* add to linked list */
825 sip->prev = nsrv4->nfs4_cur_servinst;
826 nsrv4->nfs4_cur_servinst->next = sip;
827 }
828 if (start_grace)
829 rfs4_grace_start(sip);
830 /* make the new instance "current" */
831 nsrv4->nfs4_cur_servinst = sip;
832
833 mutex_exit(&nsrv4->servinst_lock);
834 }
835
836 /*
837 * In future, we might add a rfs4_servinst_destroy(sip) but, for now, destroy
838 * all instances directly.
839 */
840 void
841 rfs4_servinst_destroy_all(nfs4_srv_t *nsrv4)
842 {
843 rfs4_servinst_t *sip, *prev, *current;
844 #ifdef DEBUG
845 int n = 0;
846 #endif
847
848 mutex_enter(&nsrv4->servinst_lock);
849 ASSERT(nsrv4->nfs4_cur_servinst != NULL);
850 current = nsrv4->nfs4_cur_servinst;
851 nsrv4->nfs4_cur_servinst = NULL;
852 for (sip = current; sip != NULL; sip = prev) {
853 prev = sip->prev;
854 rw_destroy(&sip->rwlock);
855 if (sip->oldstate)
856 kmem_free(sip->oldstate, sizeof (rfs4_oldstate_t));
857 if (sip->dss_paths)
858 kmem_free(sip->dss_paths,
859 sip->dss_npaths * sizeof (rfs4_dss_path_t *));
860 kmem_free(sip, sizeof (rfs4_servinst_t));
861 #ifdef DEBUG
862 n++;
863 #endif
864 }
865 mutex_exit(&nsrv4->servinst_lock);
866 }
867
868 /*
869 * Assign the current server instance to a client_t.
870 * Should be called with cp->rc_dbe held.
871 */
872 void
873 rfs4_servinst_assign(nfs4_srv_t *nsrv4, rfs4_client_t *cp,
874 rfs4_servinst_t *sip)
875 {
876 ASSERT(rfs4_dbe_refcnt(cp->rc_dbe) > 0);
877
878 /*
879 * The lock ensures that if the current instance is in the process
|
798 sip->next = NULL;
799 sip->prev = NULL;
800
801 rw_init(&sip->oldstate_lock, NULL, RW_DEFAULT, NULL);
802 /*
803 * This initial dummy entry is required to setup for insque/remque.
804 * It must be skipped over whenever the list is traversed.
805 */
806 oldstate = kmem_alloc(sizeof (rfs4_oldstate_t), KM_SLEEP);
807 /* insque/remque require initial list entry to be self-terminated */
808 oldstate->next = oldstate;
809 oldstate->prev = oldstate;
810 sip->oldstate = oldstate;
811
812
813 sip->dss_npaths = dss_npaths;
814 sip->dss_paths = kmem_alloc(dss_npaths *
815 sizeof (rfs4_dss_path_t *), KM_SLEEP);
816
817 for (i = 0; i < dss_npaths; i++) {
818 sip->dss_paths[i] =
819 rfs4_dss_newpath(nsrv4, sip, dss_paths[i], i);
820 }
821
822 mutex_enter(&nsrv4->servinst_lock);
823 if (nsrv4->nfs4_cur_servinst != NULL) {
824 /* add to linked list */
825 sip->prev = nsrv4->nfs4_cur_servinst;
826 nsrv4->nfs4_cur_servinst->next = sip;
827 }
828 if (start_grace)
829 rfs4_grace_start(sip);
830 /* make the new instance "current" */
831 nsrv4->nfs4_cur_servinst = sip;
832
833 mutex_exit(&nsrv4->servinst_lock);
834 }
835
836 /*
837 * In future, we might add a rfs4_servinst_destroy(sip) but, for now, destroy
838 * all instances directly.
839 */
840 void
841 rfs4_servinst_destroy_all(nfs4_srv_t *nsrv4)
842 {
843 rfs4_servinst_t *sip, *prev, *current;
844 #ifdef DEBUG
845 int n = 0;
846 #endif
847
848 mutex_enter(&nsrv4->servinst_lock);
849 ASSERT(nsrv4->nfs4_cur_servinst != NULL);
850 current = nsrv4->nfs4_cur_servinst;
851 nsrv4->nfs4_cur_servinst = NULL;
852 for (sip = current; sip != NULL; sip = prev) {
853 prev = sip->prev;
854 rw_destroy(&sip->rwlock);
855 if (sip->oldstate)
856 kmem_free(sip->oldstate, sizeof (rfs4_oldstate_t));
857 if (sip->dss_paths) {
858 int i = sip->dss_npaths;
859
860 while (i > 0) {
861 i--;
862 if (sip->dss_paths[i] != NULL) {
863 char *path = sip->dss_paths[i]->path;
864
865 if (path != NULL) {
866 kmem_free(path,
867 strlen(path) + 1);
868 }
869 kmem_free(sip->dss_paths[i],
870 sizeof (rfs4_dss_path_t));
871 }
872 }
873 kmem_free(sip->dss_paths,
874 sip->dss_npaths * sizeof (rfs4_dss_path_t *));
875 }
876 kmem_free(sip, sizeof (rfs4_servinst_t));
877 #ifdef DEBUG
878 n++;
879 #endif
880 }
881 mutex_exit(&nsrv4->servinst_lock);
882 }
883
884 /*
885 * Assign the current server instance to a client_t.
886 * Should be called with cp->rc_dbe held.
887 */
888 void
889 rfs4_servinst_assign(nfs4_srv_t *nsrv4, rfs4_client_t *cp,
890 rfs4_servinst_t *sip)
891 {
892 ASSERT(rfs4_dbe_refcnt(cp->rc_dbe) > 0);
893
894 /*
895 * The lock ensures that if the current instance is in the process
|