Lines Matching refs:cm
58 static int close_conn_mt_when_nouser(ns_conn_mt_t *cm);
62 static void close_conn_mt_by_procchg(ns_conn_mt_t *cm, int rc, char *errmsg);
94 #define NS_CONN_UNLOCK_AND_FREE(free, cm, cmg) \ argument
96 (void) mutex_unlock(&(cm)->lock); \
98 cmg = free_conn_mt((cm), 1); \
887 ns_conn_mt_t *cm; in init_conn_mt() local
890 cm = (ns_conn_mt_t *)calloc(1, sizeof (*cm)); in init_conn_mt()
891 if (cm == NULL) { in init_conn_mt()
908 (void) mutex_init(&cm->lock, USYNC_THREAD, NULL); in init_conn_mt()
909 cm->state = NS_CONN_MT_CONNECTING; in init_conn_mt()
910 cm->tid = thr_self(); in init_conn_mt()
911 cm->pid = getpid(); in init_conn_mt()
912 cm->next = NULL; in init_conn_mt()
913 cm->cu_head = NULL; in init_conn_mt()
914 cm->cu_tail = NULL; in init_conn_mt()
915 cm->conn = NULL; in init_conn_mt()
916 cm->conn_mgmt = cmg; in init_conn_mt()
918 return (cm); in init_conn_mt()
927 free_conn_mt(ns_conn_mt_t *cm, int unlock_cmg) in free_conn_mt() argument
931 if (cm == NULL) in free_conn_mt()
933 if (cm->ns_error != NULL) in free_conn_mt()
934 (void) __ns_ldap_freeError(&cm->ns_error); in free_conn_mt()
935 if (cm->conn != NULL) { in free_conn_mt()
936 if (cm->conn->ld != NULL) in free_conn_mt()
937 (void) ldap_unbind(cm->conn->ld); in free_conn_mt()
938 __s_api_freeConnection(cm->conn); in free_conn_mt()
940 cmg = cm->conn_mgmt; in free_conn_mt()
941 free(cm); in free_conn_mt()
947 add_cu2cm(ns_conn_user_t *cu, ns_conn_mt_t *cm) in add_cu2cm() argument
950 if (cm->cu_head == NULL) { in add_cu2cm()
951 cm->cu_head = cu; in add_cu2cm()
952 cm->cu_tail = cu; in add_cu2cm()
954 cm->cu_tail->next = cu; in add_cu2cm()
955 cm->cu_tail = cu; in add_cu2cm()
957 cm->cu_cnt++; in add_cu2cm()
962 add_cm2cmg(ns_conn_mt_t *cm, ns_conn_mgmt_t *cmg) in add_cm2cmg() argument
971 cmg->cm_head = cm; in add_cm2cmg()
972 cmg->cm_tail = cm; in add_cm2cmg()
974 if (cm->opened_for == NS_CONN_USER_WRITE) { in add_cm2cmg()
975 cm->next = cmg->cm_head; in add_cm2cmg()
976 cmg->cm_head = cm; in add_cm2cmg()
978 cmg->cm_tail->next = cm; in add_cm2cmg()
979 cmg->cm_tail = cm; in add_cm2cmg()
987 del_cu4cm(ns_conn_user_t *cu, ns_conn_mt_t *cm) in del_cu4cm() argument
991 if (cu == NULL || cm->cu_head == NULL || cm->cu_cnt == 0) in del_cu4cm()
995 if (cm->cu_head == cm->cu_tail) { in del_cu4cm()
996 if (cu == cm->cu_head) { in del_cu4cm()
997 cm->cu_head = cm->cu_tail = NULL; in del_cu4cm()
998 cm->cu_cnt = 0; in del_cu4cm()
1005 if (cu == cm->cu_head) { in del_cu4cm()
1006 cm->cu_head = cu->next; in del_cu4cm()
1007 cm->cu_cnt--; in del_cu4cm()
1012 pu = cm->cu_head; in del_cu4cm()
1013 for (u = cm->cu_head->next; u; u = u->next) { in del_cu4cm()
1018 if (pu != cm->cu_tail) { in del_cu4cm()
1021 cm->cu_tail = pu; in del_cu4cm()
1022 cm->cu_cnt--; in del_cu4cm()
1032 del_cm4cmg(ns_conn_mt_t *cm, ns_conn_mgmt_t *cmg) in del_cm4cmg() argument
1036 if (cm == NULL || cmg->cm_head == NULL || cmg->cm_cnt == 0) in del_cm4cmg()
1041 if (cm == cmg->cm_head) { in del_cm4cmg()
1044 cm->next = NULL; in del_cm4cmg()
1050 if (cm == cmg->cm_head) { in del_cm4cmg()
1051 cmg->cm_head = cm->next; in del_cm4cmg()
1053 cm->next = NULL; in del_cm4cmg()
1059 if (cm == m) in del_cm4cmg()
1064 pm->next = cm->next; in del_cm4cmg()
1068 cm->next = NULL; in del_cm4cmg()
1081 ns_conn_mt_t *cm) in is_server_cred_matched() argument
1083 Connection *cp = cm->conn; in is_server_cred_matched()
1106 wait_for_conn_mt(ns_conn_user_t *cu, ns_conn_mt_t *cm) in wait_for_conn_mt() argument
1110 add_cu2cm(cu, cm); in wait_for_conn_mt()
1111 cu->conn_mt = cm; in wait_for_conn_mt()
1113 (void) mutex_unlock(&cm->lock); in wait_for_conn_mt()
1118 (void) mutex_unlock(&(cm->conn_mgmt)->lock); in wait_for_conn_mt()
1120 (void) mutex_lock(&cm->lock); in wait_for_conn_mt()
1122 if (cm->state == NS_CONN_MT_CONNECTING) { in wait_for_conn_mt()
1123 (void) conn_wait(cm, cu); in wait_for_conn_mt()
1130 if (cm->state == NS_CONN_MT_CONNECTED) in wait_for_conn_mt()
1133 del_cu4cm(cu, cm); in wait_for_conn_mt()
1150 check_and_close_conn(ns_conn_mgmt_t *cmg, ns_conn_mt_t **cm, in check_and_close_conn() argument
1193 if (strcasecmp(cmg->pservers[j], (*cm)->conn->serverAddr) != 0) in check_and_close_conn()
1228 if ((*cm)->opened_for == NS_CONN_USER_WRITE || in check_and_close_conn()
1229 (*cm)->referral == B_TRUE) { in check_and_close_conn()
1233 free_cm = close_conn_mt_when_nouser(*cm); in check_and_close_conn()
1241 free_cm = close_conn_mt(*cm, LDAP_SERVER_DOWN, &ep, NULL); in check_and_close_conn()
1247 (void) mutex_unlock(&(*cm)->lock); in check_and_close_conn()
1249 (void) free_conn_mt(*cm, 0); in check_and_close_conn()
1250 *cm = NULL; in check_and_close_conn()
1274 ns_conn_mt_t *cm = *cmt; in match_conn_mt() local
1275 ns_conn_mgmt_t *cmg = cm->conn_mgmt; in match_conn_mt()
1277 if (cm->state != st || cm->close_when_nouser == B_TRUE || in match_conn_mt()
1278 cm->detached == B_TRUE || cm->pid != getpid() || in match_conn_mt()
1279 cm->referral != cu->referral) { in match_conn_mt()
1280 (void) mutex_unlock(&cm->lock); in match_conn_mt()
1295 if (cm->opened_for == NS_CONN_USER_WRITE && in match_conn_mt()
1296 cu->type != NS_CONN_USER_WRITE && cm->cu_cnt == 0 && in match_conn_mt()
1297 ((time(NULL) - cm->access_time) > 60)) { in match_conn_mt()
1302 free_cm = close_conn_mt(cm, NS_LDAP_INTERNAL, NULL, NULL); in match_conn_mt()
1303 (void) mutex_unlock(&cm->lock); in match_conn_mt()
1305 (void) free_conn_mt(cm, 0); in match_conn_mt()
1314 if (cm->opened_for == NS_CONN_USER_SEARCH || in match_conn_mt()
1315 cm->opened_for == NS_CONN_USER_GETENT) in match_conn_mt()
1320 if (cm->opened_for == NS_CONN_USER_WRITE) in match_conn_mt()
1330 is_server_cred_matched(server, cred, cm) == B_FALSE)) in match_conn_mt()
1342 if (cm->state == NS_CONN_MT_CONNECTED && in match_conn_mt()
1344 drop_conn = check_and_close_conn(cmg, &cm, cu); in match_conn_mt()
1346 if (cm == NULL) in match_conn_mt()
1353 if ((cm->state == NS_CONN_MT_CONNECTED && in match_conn_mt()
1354 cm->cu_max != NS_CONN_MT_USER_NO_MAX && in match_conn_mt()
1355 cm->cu_cnt >= cm->cu_max) || in match_conn_mt()
1356 (cm->state == NS_CONN_MT_CONNECTING && in match_conn_mt()
1357 cm->cu_max != NS_CONN_MT_USER_NO_MAX && in match_conn_mt()
1358 cm->waiter_cnt >= cm->cu_max - 1)) in match_conn_mt()
1363 (void) mutex_unlock(&cm->lock); in match_conn_mt()
1537 ns_conn_mt_t *cm = cu->conn_mt; in __s_api_conn_mt_add() local
1551 (void) mutex_lock(&cm->lock); in __s_api_conn_mt_add()
1552 cm->conn = con; in __s_api_conn_mt_add()
1553 cm->state = NS_CONN_MT_CONNECTED; in __s_api_conn_mt_add()
1554 cm->pid = getpid(); in __s_api_conn_mt_add()
1555 cm->create_time = time(NULL); in __s_api_conn_mt_add()
1556 cm->access_time = cm->create_time; in __s_api_conn_mt_add()
1557 cm->opened_for = cu->type; in __s_api_conn_mt_add()
1558 add_cu2cm(cu, cm); in __s_api_conn_mt_add()
1559 cu->conn_mt = cm; in __s_api_conn_mt_add()
1562 cm->cu_max = NS_CONN_MT_USER_MAX; in __s_api_conn_mt_add()
1564 cm->cu_max = 1; in __s_api_conn_mt_add()
1567 (void) conn_signal(cm); in __s_api_conn_mt_add()
1569 (void) mutex_unlock(&cm->lock); in __s_api_conn_mt_add()
1585 ns_conn_mt_t *cm; in __s_api_conn_mt_return() local
1590 cm = cu->conn_mt; in __s_api_conn_mt_return()
1591 if (cm == NULL) in __s_api_conn_mt_return()
1595 (void) mutex_lock(&cm->lock); in __s_api_conn_mt_return()
1596 del_cu4cm(cu, cm); in __s_api_conn_mt_return()
1606 if ((cm->close_when_nouser == B_TRUE || in __s_api_conn_mt_return()
1607 cm->state != NS_CONN_MT_CONNECTED) && cm->cu_cnt == 0) { in __s_api_conn_mt_return()
1608 (void) mutex_unlock(&cm->lock); in __s_api_conn_mt_return()
1610 (void) mutex_lock(&cm->lock); in __s_api_conn_mt_return()
1611 del_cm4cmg(cm, cmg); in __s_api_conn_mt_return()
1613 NS_CONN_UNLOCK_AND_FREE(ns_conn_free, cm, cmg); in __s_api_conn_mt_return()
1615 if (cm->state == NS_CONN_MT_CONNECTED && cm->cu_cnt == 0 && in __s_api_conn_mt_return()
1616 cm->conn != NULL && cm->conn->ld != NULL) { in __s_api_conn_mt_return()
1622 while (ldap_result(cm->conn->ld, LDAP_RES_ANY, in __s_api_conn_mt_return()
1628 (void) mutex_unlock(&cm->lock); in __s_api_conn_mt_return()
1634 err2cm(ns_conn_mt_t *cm, int rc, ns_ldap_error_t **errorp) { in err2cm() argument
1637 cm->ns_rc = rc; in err2cm()
1638 cm->ns_error = NULL; in err2cm()
1642 cm->ns_rc = NS_LDAP_MEMORY; in err2cm()
1644 cm->ns_error = ep; in err2cm()
1650 err_from_cm(ns_conn_user_t *cu, ns_conn_mt_t *cm) { in err_from_cm() argument
1653 cu->ns_rc = cm->ns_rc; in err_from_cm()
1657 if (cm->ns_rc != NS_LDAP_SUCCESS && cm->ns_error != NULL) { in err_from_cm()
1658 ep = __s_api_copy_error(cm->ns_error); in err_from_cm()
1694 ns_conn_mt_t *cm; in __s_api_conn_mt_remove() local
1699 if ((cm = cu->conn_mt) == NULL) in __s_api_conn_mt_remove()
1704 (void) mutex_lock(&cm->lock); in __s_api_conn_mt_remove()
1705 if (cm->state != NS_CONN_MT_CONNECT_ERROR) { in __s_api_conn_mt_remove()
1706 cm->state = NS_CONN_MT_CONNECT_ERROR; in __s_api_conn_mt_remove()
1707 cm->ns_rc = rc; in __s_api_conn_mt_remove()
1709 cm->ns_error = *errorp; in __s_api_conn_mt_remove()
1715 err_from_cm(cu, cm); in __s_api_conn_mt_remove()
1717 (void) conn_signal(cm); in __s_api_conn_mt_remove()
1719 del_cu4cm(cu, cm); in __s_api_conn_mt_remove()
1722 if (cm->cu_cnt == 0) { in __s_api_conn_mt_remove()
1723 del_cm4cmg(cm, cmg); in __s_api_conn_mt_remove()
1727 NS_CONN_UNLOCK_AND_FREE(free_cm, cm, cmg); in __s_api_conn_mt_remove()
1781 close_conn_mt(ns_conn_mt_t *cm, int rc, ns_ldap_error_t **errorp, in close_conn_mt() argument
1784 ns_conn_mgmt_t *cmg = cm->conn_mgmt; in close_conn_mt()
1788 if ((cm->state != NS_CONN_MT_CONNECTED && cm->state != in close_conn_mt()
1794 if (cm == m) in close_conn_mt()
1800 if (cm->state == NS_CONN_MT_CONNECTED) { /* first time in here */ in close_conn_mt()
1801 cm->state = NS_CONN_MT_CLOSING; in close_conn_mt()
1811 if ((cu != NULL && cm->cu_cnt > 1) || in close_conn_mt()
1812 (cu == NULL && cm->cu_cnt > 0)) { in close_conn_mt()
1813 err2cm(cm, rc, errorp); in close_conn_mt()
1815 (void) conn_signal(cm); in close_conn_mt()
1819 if (cm->cu_head != NULL) { in close_conn_mt()
1820 for (u = cm->cu_head; u; u = u->next) { in close_conn_mt()
1829 if ((cu != NULL && cm->cu_cnt == 1) || in close_conn_mt()
1830 (cu == NULL && cm->cu_cnt == 0)) { in close_conn_mt()
1831 del_cm4cmg(cm, cmg); in close_conn_mt()
1832 cm->detached = B_TRUE; in close_conn_mt()
1855 ns_conn_mt_t *cm; in __s_api_conn_mt_close() local
1861 if (cu->state != NS_CONN_USER_CONNECTED || (cm = cu->conn_mt) == NULL) in __s_api_conn_mt_close()
1866 (void) mutex_lock(&cm->lock); in __s_api_conn_mt_close()
1869 free_cm = close_conn_mt(cm, rc, errorp, cu); in __s_api_conn_mt_close()
1871 (void) mutex_unlock(&cm->lock); in __s_api_conn_mt_close()
1879 err_from_cm(cu, cm); in __s_api_conn_mt_close()
1883 del_cu4cm(cu, cm); in __s_api_conn_mt_close()
1888 NS_CONN_UNLOCK_AND_FREE(free_cm, cm, cmg); in __s_api_conn_mt_close()
1898 close_conn_mt_by_procchg(ns_conn_mt_t *cm, int rc, char *errmsg) in close_conn_mt_by_procchg() argument
1904 if (cm == NULL) in close_conn_mt_by_procchg()
1906 cmg = cm->conn_mgmt; in close_conn_mt_by_procchg()
1916 (void) mutex_lock(&cm->lock); in close_conn_mt_by_procchg()
1919 free_cm = close_conn_mt(cm, LDAP_SERVER_DOWN, &ep, NULL); in close_conn_mt_by_procchg()
1921 (void) mutex_unlock(&cm->lock); in close_conn_mt_by_procchg()
1927 NS_CONN_UNLOCK_AND_FREE(free_cm, cm, cmg); in close_conn_mt_by_procchg()
1938 close_conn_mt_when_nouser(ns_conn_mt_t *cm) in close_conn_mt_when_nouser() argument
1942 if (cm->cu_cnt == 0) { in close_conn_mt_when_nouser()
1943 del_cm4cmg(cm, cm->conn_mgmt); in close_conn_mt_when_nouser()
1946 cm->close_when_nouser = B_TRUE; in close_conn_mt_when_nouser()
1996 ns_conn_mt_t *cm; in proc_server_change() local
2030 for (cm = cmg->cm_head; cm; cm = cm->next) { in proc_server_change()
2031 (void) mutex_lock(&cm->lock); in proc_server_change()
2033 if (cm->state == NS_CONN_MT_CONNECTED && in proc_server_change()
2034 cm->conn != NULL && in proc_server_change()
2035 strcasecmp(cm->conn->serverAddr, s) == 0) { in proc_server_change()
2036 (void) mutex_unlock(&cm->lock); in proc_server_change()
2040 (void) mutex_unlock(&cm->lock); in proc_server_change()
2042 if (cm != NULL) { in proc_server_change()
2045 close_conn_mt_by_procchg(cm, LDAP_SERVER_DOWN, in proc_server_change()
2117 for (cm = cmg->cm_head; cm; cm = cm->next) { in proc_server_change()
2118 (void) mutex_lock(&cm->lock); in proc_server_change()
2125 if (cm->state == NS_CONN_MT_CONNECTED && in proc_server_change()
2126 cm->close_when_nouser == B_FALSE && in proc_server_change()
2127 cm->conn != NULL && cm->opened_for != in proc_server_change()
2129 cm->referral == B_FALSE) { in proc_server_change()
2141 cm->conn->serverAddr, in proc_server_change()
2157 cm); in proc_server_change()
2159 cm, cmg); in proc_server_change()
2172 (void) mutex_unlock(&cm->lock); in proc_server_change()
2175 if (cm == NULL) in proc_server_change()
2189 ns_conn_mt_t *cm; in shutdown_all_conn_mt() local
2201 for (cm = cmg->cm_head; cm; cm = cm->next) { in shutdown_all_conn_mt()
2202 (void) mutex_lock(&cm->lock); in shutdown_all_conn_mt()
2203 if (cm->next == NULL) in shutdown_all_conn_mt()
2206 free_cm = close_conn_mt(cm, LDAP_OTHER, &ep, NULL); in shutdown_all_conn_mt()
2207 (void) mutex_unlock(&cm->lock); in shutdown_all_conn_mt()
2209 (void) free_conn_mt(cm, 0); in shutdown_all_conn_mt()