Lines Matching refs:mp

98 #define	IS_CLIENT(mp)	(((mp)->epm_xprtflags & FMD_XPRT_ACCEPT) ? 0 : 1)
242 etm_check_hdr(fmd_hdl_t *hdl, etm_epmap_t *mp, void *buf)
248 ": 0x%x\n", mp->epm_ep_str, hp->hdr_delim);
258 if (hp->hdr_ver != mp->epm_ver) {
260 mp->epm_ep_str, hp->hdr_ver);
267 mp->epm_ep_str, hp->hdr_type);
298 etm_post_msg(fmd_hdl_t *hdl, etm_epmap_t *mp, void *buf, size_t buflen)
308 rv = etm_xport_post_filter(hdl, nvl, mp->epm_ep_str);
320 (void) pthread_mutex_lock(&mp->epm_lock);
324 if (mp->epm_qstat == Q_OPEN) {
325 fmd_xprt_post(hdl, mp->epm_xprthdl, nvl, 0);
327 } else if (mp->epm_qstat == Q_SUSPENDED) {
328 fmd_xprt_resume(hdl, mp->epm_xprthdl);
329 if (mp->epm_timer_in_use) {
330 fmd_timer_remove(hdl, mp->epm_timer_id);
331 mp->epm_timer_in_use = 0;
333 mp->epm_qstat = Q_OPEN;
335 mp->epm_ep_str);
336 fmd_xprt_post(hdl, mp->epm_xprthdl, nvl, 0);
340 mp->epm_qstat);
353 (void) pthread_mutex_unlock(&mp->epm_lock);
371 etm_handle_startup(fmd_hdl_t *hdl, etm_epmap_t *mp)
378 if ((mp->epm_oconn = etm_xport_open(hdl, mp->epm_tlhdl)) == NULL)
381 mp->epm_cstat = C_OPEN;
383 hdrlen = etm_create_hdr(hbuf, mp->epm_ver, ETM_HDR_C_HELLO, 0);
385 if ((etm_xport_write(hdl, mp->epm_oconn, Rw_timeout, hbuf,
388 mp->epm_ep_str);
392 mp->epm_qstat = Q_INIT_PENDING;
394 if ((etm_xport_read(hdl, mp->epm_oconn, Rw_timeout, hbuf,
397 mp->epm_ep_str);
401 hdrstat = etm_check_hdr(hdl, mp, hbuf);
405 "from %s", mp->epm_ep_str);
416 mp->epm_ep_str, hp->hdr_ver);
419 mp->epm_ver = hp->hdr_ver;
421 hdrlen = etm_create_hdr(hbuf, mp->epm_ver, ETM_HDR_ACK, 0);
423 if ((etm_xport_write(hdl, mp->epm_oconn, Rw_timeout, hbuf,
426 mp->epm_ep_str);
435 if ((mp->epm_xprthdl = fmd_xprt_open(hdl, mp->epm_xprtflags,
436 mp->epm_ep_nvl, NULL)) == NULL) {
438 mp->epm_ep_str);
440 fmd_xprt_setspecific(hdl, mp->epm_xprthdl, mp);
443 mp->epm_qstat = Q_OPEN;
444 fmd_hdl_debug(hdl, "queue open for %s", mp->epm_ep_str);
454 etm_send_shutdown(fmd_hdl_t *hdl, etm_epmap_t *mp)
459 if ((mp->epm_oconn = etm_xport_open(hdl, mp->epm_tlhdl)) == NULL)
462 hdrlen = etm_create_hdr(hbuf, mp->epm_ver, ETM_HDR_SHUTDOWN, 0);
464 (void) etm_xport_write(hdl, mp->epm_oconn, Rw_timeout, hbuf, hdrlen);
466 (void) etm_xport_close(hdl, mp->epm_oconn);
467 mp->epm_oconn = NULL;
475 etm_get_ep_nvl(fmd_hdl_t *hdl, etm_epmap_t *mp)
481 (void) nvlist_alloc(&mp->epm_ep_nvl, NV_UNIQUE_NAME, 0);
483 if (nvlist_add_string(mp->epm_ep_nvl, "domain-id", mp->epm_ep_str)) {
485 "for %s", mp->epm_ep_str);
486 nvlist_free(mp->epm_ep_nvl);
498 etm_free_ep_nvl(fmd_hdl_t *hdl, etm_epmap_t *mp)
500 nvlist_free(mp->epm_ep_nvl);
510 etm_epmap_t *mp;
512 for (mp = Epmap_head; mp != NULL; mp = mp->epm_next)
513 if (strcmp(epname, mp->epm_ep_str) == 0)
523 etm_reconnect(fmd_hdl_t *hdl, etm_epmap_t *mp)
525 if ((mp->epm_reconn_end > 0) && (mp->epm_cstat == C_UNINITIALIZED)) {
526 if (gethrtime() < mp->epm_reconn_end) {
527 if ((mp->epm_oconn = etm_xport_open(hdl,
528 mp->epm_tlhdl)) == NULL) {
530 mp->epm_ep_str);
531 mp->epm_timer_id = fmd_timer_install(hdl, mp,
533 mp->epm_timer_in_use = 1;
536 mp->epm_ep_str);
537 mp->epm_reconn_end = 0;
538 mp->epm_cstat = C_OPEN;
542 mp->epm_ep_str);
543 mp->epm_reconn_end = 0;
544 mp->epm_cstat = C_TIMED_OUT;
548 if (mp->epm_cstat == C_OPEN) {
549 fmd_xprt_resume(hdl, mp->epm_xprthdl);
550 mp->epm_qstat = Q_OPEN;
551 fmd_hdl_debug(hdl, "queue resumed for %s", mp->epm_ep_str);
560 etm_suspend_reconnect(fmd_hdl_t *hdl, etm_epmap_t *mp)
569 if (mp->epm_oconn != NULL) {
570 (void) etm_xport_close(hdl, mp->epm_oconn);
571 mp->epm_oconn = NULL;
574 mp->epm_reconn_end = gethrtime() + Reconn_timeout;
575 mp->epm_cstat = C_UNINITIALIZED;
577 if (mp->epm_xprthdl != NULL) {
578 fmd_xprt_suspend(hdl, mp->epm_xprthdl);
579 mp->epm_qstat = Q_SUSPENDED;
580 fmd_hdl_debug(hdl, "queue suspended for %s", mp->epm_ep_str);
582 if (mp->epm_timer_in_use == 0) {
583 mp->epm_timer_id = fmd_timer_install(hdl, mp, NULL,
585 mp->epm_timer_in_use = 1;
596 etm_reinit(fmd_hdl_t *hdl, etm_epmap_t *mp)
602 while (mp->epm_txbusy)
603 (void) pthread_cond_wait(&mp->epm_tx_cv, &mp->epm_lock);
605 if (mp->epm_xprthdl != NULL) {
606 fmd_xprt_close(hdl, mp->epm_xprthdl);
607 fmd_hdl_debug(hdl, "queue closed for %s", mp->epm_ep_str);
608 mp->epm_xprthdl = NULL;
609 /* mp->epm_ep_nvl is free'd in fmd_xprt_close */
610 mp->epm_ep_nvl = NULL;
613 if (mp->epm_timer_in_use) {
614 fmd_timer_remove(hdl, mp->epm_timer_id);
615 mp->epm_timer_in_use = 0;
618 if (mp->epm_oconn != NULL) {
619 (void) etm_xport_close(hdl, mp->epm_oconn);
620 mp->epm_oconn = NULL;
623 mp->epm_cstat = C_UNINITIALIZED;
624 mp->epm_qstat = Q_UNINITIALIZED;
633 etm_recv(fmd_hdl_t *hdl, etm_xport_conn_t conn, etm_epmap_t *mp)
644 mp->epm_ep_str);
649 hdrstat = etm_check_hdr(hdl, mp, hbuf);
653 (void) pthread_mutex_lock(&mp->epm_lock);
654 if (mp->epm_cstat == C_OPEN)
655 mp->epm_cstat = C_CLOSED;
656 (void) pthread_mutex_unlock(&mp->epm_lock);
664 hdrlen = etm_create_hdr(hbuf, mp->epm_ver, ETM_HDR_NAK, 0);
669 mp->epm_ep_str);
674 (void) pthread_mutex_lock(&mp->epm_lock);
675 mp->epm_cstat = C_LIMBO;
676 (void) pthread_mutex_unlock(&mp->epm_lock);
684 (void) pthread_mutex_lock(&mp->epm_lock);
685 etm_reinit(hdl, mp);
686 mp->epm_qstat = Q_INIT_PENDING;
687 (void) pthread_mutex_unlock(&mp->epm_lock);
689 hdrlen = etm_create_hdr(hbuf, mp->epm_ver, ETM_HDR_S_HELLO, 0);
694 mp->epm_ep_str);
703 (void) pthread_mutex_lock(&mp->epm_lock);
704 if (mp->epm_qstat == Q_INIT_PENDING) {
706 /* mp->epm_ep_nvl is free'd in fmd_xprt_close */
707 if (mp->epm_ep_nvl == NULL)
708 (void) etm_get_ep_nvl(hdl, mp);
715 if ((mp->epm_xprthdl = fmd_xprt_open(hdl,
716 mp->epm_xprtflags, mp->epm_ep_nvl, NULL)) == NULL) {
718 "for %s", mp->epm_ep_str);
720 fmd_xprt_setspecific(hdl, mp->epm_xprthdl, mp);
723 mp->epm_qstat = Q_OPEN;
724 (void) pthread_mutex_unlock(&mp->epm_lock);
726 mp->epm_ep_str);
728 (void) pthread_mutex_unlock(&mp->epm_lock);
730 "from %s\n", mp->epm_ep_str);
739 mp->epm_ep_str);
741 (void) pthread_mutex_lock(&mp->epm_lock);
743 etm_reinit(hdl, mp);
745 if (IS_CLIENT(mp)) {
750 mp->epm_timer_id = fmd_timer_install(hdl, mp, NULL,
753 mp->epm_timer_in_use = 1;
756 (void) pthread_mutex_unlock(&mp->epm_lock);
762 (void) pthread_mutex_lock(&mp->epm_lock);
763 if (mp->epm_qstat == Q_UNINITIALIZED) {
765 (void) pthread_mutex_unlock(&mp->epm_lock);
766 hdrlen = etm_create_hdr(hbuf, mp->epm_ver,
772 "to %s", mp->epm_ep_str);
779 (void) pthread_mutex_unlock(&mp->epm_lock);
787 mp->epm_ep_str);
798 if (etm_post_msg(hdl, mp, buf, buflen)) {
806 hdrlen = etm_create_hdr(hbuf, mp->epm_ver, ETM_HDR_ACK, 0);
811 mp->epm_ep_str);
823 (void) pthread_mutex_lock(&mp->epm_lock);
824 if (mp->epm_cstat == C_TIMED_OUT ||
825 mp->epm_cstat == C_LIMBO) {
826 if (mp->epm_oconn != NULL) {
827 (void) etm_xport_close(hdl, mp->epm_oconn);
828 mp->epm_oconn = NULL;
830 mp->epm_cstat = C_UNINITIALIZED;
831 fmd_xprt_resume(hdl, mp->epm_xprthdl);
832 if (mp->epm_timer_in_use) {
833 fmd_timer_remove(hdl, mp->epm_timer_id);
834 mp->epm_timer_in_use = 0;
836 mp->epm_qstat = Q_OPEN;
838 mp->epm_ep_str);
840 (void) pthread_mutex_unlock(&mp->epm_lock);
847 "from %s : %d", mp->epm_ep_str, hdrstat);
865 etm_epmap_t *mp = (etm_epmap_t *)arg;
877 rv = etm_recv(hdl, conn, mp);
880 (void) pthread_mutex_lock(&mp->epm_lock);
881 etm_reinit(hdl, mp);
882 etm_send_shutdown(hdl, mp);
883 (void) pthread_mutex_unlock(&mp->epm_lock);
1080 etm_free_epmap(fmd_hdl_t *hdl, etm_epmap_t *mp)
1085 (void) pthread_mutex_lock(&mp->epm_lock);
1092 while (mp->epm_txbusy)
1093 (void) pthread_cond_wait(&mp->epm_tx_cv, &mp->epm_lock);
1095 if (mp->epm_timer_in_use)
1096 fmd_timer_remove(hdl, mp->epm_timer_id);
1098 if (mp->epm_oconn != NULL) {
1099 hdrlen = etm_create_hdr(hbuf, mp->epm_ver,
1101 (void) etm_xport_write(hdl, mp->epm_oconn, Rw_timeout, hbuf,
1103 (void) etm_xport_close(hdl, mp->epm_oconn);
1104 mp->epm_oconn = NULL;
1107 if (mp->epm_xprthdl != NULL) {
1108 fmd_xprt_close(hdl, mp->epm_xprthdl);
1109 /* mp->epm_ep_nvl is free'd in fmd_xprt_close */
1110 mp->epm_ep_nvl = NULL;
1113 if (mp->epm_ep_nvl != NULL)
1114 etm_free_ep_nvl(hdl, mp);
1116 if (mp->epm_tlhdl != NULL)
1117 (void) etm_xport_fini(hdl, mp->epm_tlhdl);
1119 (void) pthread_mutex_unlock(&mp->epm_lock);
1120 (void) pthread_mutex_destroy(&mp->epm_lock);
1121 fmd_hdl_strfree(hdl, mp->epm_ep_str);
1122 fmd_hdl_free(hdl, mp, sizeof (etm_epmap_t));
1137 etm_epmap_t *mp;
1151 mp = fmd_xprt_getspecific(hdl, xprthdl);
1154 if (pthread_mutex_trylock(&mp->epm_lock) == 0) {
1174 mp->epm_txbusy++;
1176 if (mp->epm_qstat == Q_UNINITIALIZED) {
1177 mp->epm_txbusy--;
1178 (void) pthread_cond_broadcast(&mp->epm_tx_cv);
1179 (void) pthread_mutex_unlock(&mp->epm_lock);
1183 if (mp->epm_cstat == C_CLOSED) {
1184 etm_suspend_reconnect(hdl, mp);
1185 mp->epm_txbusy--;
1186 (void) pthread_cond_broadcast(&mp->epm_tx_cv);
1187 (void) pthread_mutex_unlock(&mp->epm_lock);
1191 if (mp->epm_cstat == C_LIMBO) {
1192 if (mp->epm_oconn != NULL) {
1193 (void) etm_xport_close(hdl, mp->epm_oconn);
1194 mp->epm_oconn = NULL;
1198 mp->epm_qstat = Q_SUSPENDED;
1199 mp->epm_txbusy--;
1200 (void) pthread_cond_broadcast(&mp->epm_tx_cv);
1201 (void) pthread_mutex_unlock(&mp->epm_lock);
1202 fmd_hdl_debug(hdl, "queue suspended for %s", mp->epm_ep_str);
1206 if (mp->epm_oconn == NULL) {
1207 if ((mp->epm_oconn = etm_xport_open(hdl, mp->epm_tlhdl))
1209 etm_suspend_reconnect(hdl, mp);
1210 mp->epm_txbusy--;
1211 (void) pthread_cond_broadcast(&mp->epm_tx_cv);
1212 (void) pthread_mutex_unlock(&mp->epm_lock);
1215 mp->epm_cstat = C_OPEN;
1224 mp->epm_txbusy--;
1225 (void) pthread_cond_broadcast(&mp->epm_tx_cv);
1226 (void) pthread_mutex_unlock(&mp->epm_lock);
1232 rv = etm_xport_send_filter(hdl, msgnvl, mp->epm_ep_str);
1234 mp->epm_txbusy--;
1235 (void) pthread_cond_broadcast(&mp->epm_tx_cv);
1236 (void) pthread_mutex_unlock(&mp->epm_lock);
1247 (void) pthread_mutex_unlock(&mp->epm_lock);
1258 (void) etm_create_hdr(buf, mp->epm_ver, ETM_HDR_MSG, nvsize);
1261 (void) pthread_mutex_lock(&mp->epm_lock);
1262 mp->epm_txbusy--;
1263 (void) pthread_cond_broadcast(&mp->epm_tx_cv);
1264 (void) pthread_mutex_unlock(&mp->epm_lock);
1273 if (etm_xport_write(hdl, mp->epm_oconn, Rw_timeout, buf,
1276 mp->epm_ep_str);
1277 (void) pthread_mutex_lock(&mp->epm_lock);
1278 etm_suspend_reconnect(hdl, mp);
1279 mp->epm_txbusy--;
1280 (void) pthread_cond_broadcast(&mp->epm_tx_cv);
1281 (void) pthread_mutex_unlock(&mp->epm_lock);
1292 if (etm_xport_read(hdl, mp->epm_oconn, Rw_timeout, buf,
1295 mp->epm_ep_str);
1296 (void) pthread_mutex_lock(&mp->epm_lock);
1297 etm_suspend_reconnect(hdl, mp);
1298 mp->epm_txbusy--;
1299 (void) pthread_cond_broadcast(&mp->epm_tx_cv);
1300 (void) pthread_mutex_unlock(&mp->epm_lock);
1306 hdrstat = etm_check_hdr(hdl, mp, buf);
1312 (void) pthread_mutex_lock(&mp->epm_lock);
1314 (void) etm_xport_close(hdl, mp->epm_oconn);
1315 mp->epm_oconn = NULL;
1319 if (mp->epm_xprthdl != NULL) {
1320 mp->epm_cstat = C_LIMBO;
1322 mp->epm_qstat = Q_SUSPENDED;
1324 "suspended for %s", mp->epm_ep_str);
1331 mp->epm_cstat = C_CLOSED;
1332 mp->epm_qstat = Q_UNINITIALIZED;
1334 mp->epm_ep_str);
1339 if (mp->epm_timer_in_use == 0) {
1340 mp->epm_timer_id = fmd_timer_install(
1341 hdl, mp, NULL, 0);
1342 mp->epm_timer_in_use = 1;
1353 mp->epm_cstat = C_CLOSED;
1354 fmd_hdl_debug(hdl, "bad ACK from %s", mp->epm_ep_str);
1359 mp->epm_txbusy--;
1361 (void) pthread_cond_broadcast(&mp->epm_tx_cv);
1362 (void) pthread_mutex_unlock(&mp->epm_lock);
1369 (void) pthread_mutex_lock(&mp->epm_lock);
1370 mp->epm_txbusy--;
1371 (void) pthread_cond_broadcast(&mp->epm_tx_cv);
1372 (void) pthread_mutex_unlock(&mp->epm_lock);
1384 etm_epmap_t *mp = (etm_epmap_t *)data;
1386 (void) pthread_mutex_lock(&mp->epm_lock);
1388 mp->epm_timer_in_use = 0;
1390 if (mp->epm_qstat == Q_UNINITIALIZED) {
1392 if (mp->epm_xprthdl != NULL) {
1393 fmd_xprt_close(hdl, mp->epm_xprthdl);
1395 mp->epm_ep_str);
1396 mp->epm_xprthdl = NULL;
1397 /* mp->epm_ep_nvl is free'd in fmd_xprt_close */
1398 mp->epm_ep_nvl = NULL;
1401 if (mp->epm_ep_nvl == NULL)
1402 (void) etm_get_ep_nvl(hdl, mp);
1404 if (etm_handle_startup(hdl, mp)) {
1405 if (mp->epm_oconn != NULL) {
1406 (void) etm_xport_close(hdl, mp->epm_oconn);
1407 mp->epm_oconn = NULL;
1409 mp->epm_cstat = C_UNINITIALIZED;
1410 mp->epm_qstat = Q_UNINITIALIZED;
1411 mp->epm_timer_id = fmd_timer_install(hdl, mp, NULL,
1413 mp->epm_timer_in_use = 1;
1416 etm_reconnect(hdl, mp);
1419 (void) pthread_mutex_unlock(&mp->epm_lock);
1490 etm_epmap_t *mp, *next;
1496 mp = Epmap_head;
1498 while (mp) {
1499 next = mp->epm_next;
1500 etm_free_epmap(hdl, mp);
1501 mp = next;