Lines Matching refs:softc

103 ctl_ha_conn_wake(struct ha_softc *softc)
106 mtx_lock(&softc->ha_lock);
107 softc->ha_wakeup = 1;
108 mtx_unlock(&softc->ha_lock);
109 wakeup(&softc->ha_wakeup);
115 struct ha_softc *softc = arg;
117 ctl_ha_conn_wake(softc);
124 struct ha_softc *softc = arg;
126 wakeup(&softc->ha_receiving);
133 struct ha_softc *softc = arg;
135 ctl_ha_conn_wake(softc);
140 ctl_ha_evt(struct ha_softc *softc, ctl_ha_channel ch, ctl_ha_event evt,
146 if (softc->ha_handler[ch])
147 softc->ha_handler[ch](ch, evt, param);
151 if (softc->ha_handler[i])
152 softc->ha_handler[i](i, evt, param);
157 ctl_ha_close(struct ha_softc *softc)
159 struct socket *so = softc->ha_so;
162 if (softc->ha_connected || softc->ha_disconnect) {
163 softc->ha_connected = 0;
164 mbufq_drain(&softc->ha_sendq);
165 m_freem(softc->ha_sending);
166 softc->ha_sending = NULL;
172 while (softc->ha_receiving) {
173 wakeup(&softc->ha_receiving);
174 msleep(&softc->ha_receiving, SOCKBUF_MTX(&so->so_rcv),
181 softc->ha_so = NULL;
182 if (softc->ha_connect)
187 ctl_ha_evt(softc, CTL_HA_CHAN_MAX, CTL_HA_EVT_LINK_CHANGE,
188 (softc->ha_connect || softc->ha_listen) ?
194 ctl_ha_lclose(struct ha_softc *softc)
197 if (softc->ha_lso) {
198 if (SOLISTENING(softc->ha_lso)) {
199 SOLISTEN_LOCK(softc->ha_lso);
200 solisten_upcall_set(softc->ha_lso, NULL, NULL);
201 SOLISTEN_UNLOCK(softc->ha_lso);
203 soclose(softc->ha_lso);
204 softc->ha_lso = NULL;
211 struct ha_softc *softc = arg;
212 struct socket *so = softc->ha_so;
225 while (sbavail(&so->so_rcv) < next || softc->ha_disconnect) {
226 if (softc->ha_connected == 0 || softc->ha_disconnect ||
232 msleep(&softc->ha_receiving, SOCKBUF_MTX(&so->so_rcv),
247 error = soreceive(softc->ha_so, NULL, &uio, NULL,
256 ctl_ha_evt(softc, wire_hdr.channel,
263 softc->ha_receiving = 0;
264 wakeup(&softc->ha_receiving);
266 ctl_ha_conn_wake(softc);
271 ctl_ha_send(struct ha_softc *softc)
273 struct socket *so = softc->ha_so;
277 if (softc->ha_sending == NULL) {
278 mtx_lock(&softc->ha_lock);
279 softc->ha_sending = mbufq_dequeue(&softc->ha_sendq);
280 mtx_unlock(&softc->ha_lock);
281 if (softc->ha_sending == NULL) {
287 if (sbspace(&so->so_snd) < softc->ha_sending->m_pkthdr.len) {
288 so->so_snd.sb_lowat = softc->ha_sending->m_pkthdr.len;
293 error = sosend(softc->ha_so, NULL, NULL, softc->ha_sending,
295 softc->ha_sending = NULL;
304 ctl_ha_sock_setup(struct ha_softc *softc)
307 struct socket *so = softc->ha_so;
317 soupcall_set(so, SO_RCV, ctl_ha_rupcall, softc);
321 soupcall_set(so, SO_SND, ctl_ha_supcall, softc);
368 ctl_ha_connect(struct ha_softc *softc)
382 softc->ha_so = so;
383 ctl_ha_sock_setup(softc);
385 memcpy(&sa, &softc->ha_peer_in, sizeof(sa));
395 ctl_ha_close(softc);
400 ctl_ha_accept(struct ha_softc *softc)
406 lso = softc->ha_lso;
426 softc->ha_so = so;
427 ctl_ha_sock_setup(softc);
431 ctl_ha_lclose(softc);
436 ctl_ha_listen(struct ha_softc *softc)
444 if (softc->ha_lso == NULL) {
445 error = socreate(PF_INET, &softc->ha_lso, SOCK_STREAM,
458 error = sosetopt(softc->ha_lso, &opt);
470 error = sosetopt(softc->ha_lso, &opt);
477 memcpy(&sa, &softc->ha_peer_in, sizeof(sa));
478 error = sobind(softc->ha_lso, (struct sockaddr *)&sa, td);
483 error = solisten(softc->ha_lso, 1, td);
488 SOLISTEN_LOCK(softc->ha_lso);
489 softc->ha_lso->so_state |= SS_NBIO;
490 solisten_upcall_set(softc->ha_lso, ctl_ha_lupcall, softc);
491 SOLISTEN_UNLOCK(softc->ha_lso);
495 ctl_ha_lclose(softc);
502 struct ha_softc *softc = arg;
506 if (softc->ha_disconnect || softc->ha_shutdown) {
507 ctl_ha_close(softc);
508 if (softc->ha_disconnect == 2 || softc->ha_shutdown)
509 ctl_ha_lclose(softc);
510 softc->ha_disconnect = 0;
511 if (softc->ha_shutdown)
513 } else if (softc->ha_so != NULL &&
514 (softc->ha_so->so_error ||
515 softc->ha_so->so_rcv.sb_state & SBS_CANTRCVMORE))
516 ctl_ha_close(softc);
517 if (softc->ha_so == NULL) {
518 if (softc->ha_lso != NULL)
519 ctl_ha_accept(softc);
520 else if (softc->ha_listen)
521 ctl_ha_listen(softc);
522 else if (softc->ha_connect)
523 ctl_ha_connect(softc);
525 if (softc->ha_so != NULL) {
526 if (softc->ha_connected == 0 &&
527 softc->ha_so->so_error == 0 &&
528 (softc->ha_so->so_state & SS_ISCONNECTING) == 0) {
529 softc->ha_connected = 1;
530 ctl_ha_evt(softc, CTL_HA_CHAN_MAX,
533 softc->ha_receiving = 1;
535 softc, &softc->ha_ctl_softc->ctl_proc,
539 softc->ha_receiving = 0;
540 softc->ha_disconnect = 1;
543 ctl_ha_send(softc);
545 mtx_lock(&softc->ha_lock);
546 if (softc->ha_so != NULL &&
547 (softc->ha_so->so_error ||
548 softc->ha_so->so_rcv.sb_state & SBS_CANTRCVMORE))
550 else if (!softc->ha_wakeup)
551 msleep(&softc->ha_wakeup, &softc->ha_lock, 0, "-", hz);
552 softc->ha_wakeup = 0;
553 mtx_unlock(&softc->ha_lock);
555 mtx_lock(&softc->ha_lock);
556 softc->ha_shutdown = 2;
557 wakeup(&softc->ha_wakeup);
558 mtx_unlock(&softc->ha_lock);
565 struct ha_softc *softc = (struct ha_softc *)arg1;
570 strlcpy(buf, softc->ha_peer, sizeof(buf));
573 strncmp(buf, softc->ha_peer, sizeof(buf)) == 0)
576 sa = &softc->ha_peer_in;
577 mtx_lock(&softc->ha_lock);
580 softc->ha_connect = 1;
581 softc->ha_listen = 0;
584 softc->ha_connect = 0;
585 softc->ha_listen = 1;
587 softc->ha_connect = 0;
588 softc->ha_listen = 0;
594 strlcpy(softc->ha_peer, buf, sizeof(softc->ha_peer));
595 if (softc->ha_connect || softc->ha_listen) {
603 softc->ha_disconnect = 2;
604 softc->ha_wakeup = 1;
605 mtx_unlock(&softc->ha_lock);
606 wakeup(&softc->ha_wakeup);
613 struct ha_softc *softc = &ha_softc;
617 softc->ha_handler[channel] = handler;
624 struct ha_softc *softc = &ha_softc;
628 softc->ha_handler[channel] = NULL;
639 struct ha_softc *softc = &ha_softc;
644 if (!softc->ha_connected)
656 error = soreceive(softc->ha_so, NULL, &uio, NULL, NULL, &flags);
661 mtx_lock(&softc->ha_lock);
662 if (softc->ha_connected) {
663 softc->ha_disconnect = 1;
664 softc->ha_wakeup = 1;
665 wakeup(&softc->ha_wakeup);
667 mtx_unlock(&softc->ha_lock);
678 struct ha_softc *softc = &ha_softc;
683 if (!softc->ha_connected)
690 mtx_lock(&softc->ha_lock);
691 if (softc->ha_connected) {
692 softc->ha_disconnect = 1;
693 softc->ha_wakeup = 1;
694 wakeup(&softc->ha_wakeup);
696 mtx_unlock(&softc->ha_lock);
727 mtx_lock(&softc->ha_lock);
728 if (!softc->ha_connected) {
729 mtx_unlock(&softc->ha_lock);
733 mbufq_enqueue(&softc->ha_sendq, newmb);
734 softc->ha_wakeup = 1;
735 mtx_unlock(&softc->ha_lock);
736 wakeup(&softc->ha_wakeup);
751 struct ha_softc *softc = &ha_softc;
753 mtx_lock(&softc->ha_lock);
754 softc->ha_disconnect = 1;
755 softc->ha_wakeup = 1;
756 mtx_unlock(&softc->ha_lock);
757 wakeup(&softc->ha_wakeup);
787 struct ha_softc *softc = &ha_softc;
796 mtx_lock(&softc->ha_lock);
797 TAILQ_INSERT_TAIL(&softc->ha_dts, req, links);
798 mtx_unlock(&softc->ha_lock);
816 struct ha_softc *softc = &ha_softc;
845 mtx_lock(&softc->ha_lock);
846 TAILQ_FOREACH(req, &softc->ha_dts, links) {
848 TAILQ_REMOVE(&softc->ha_dts, req, links);
852 mtx_unlock(&softc->ha_lock);
862 mtx_lock(&softc->ha_lock);
863 while ((req = TAILQ_FIRST(&softc->ha_dts)) != NULL) {
864 TAILQ_REMOVE(&softc->ha_dts, req, links);
865 mtx_unlock(&softc->ha_lock);
868 mtx_lock(&softc->ha_lock);
870 mtx_unlock(&softc->ha_lock);
880 struct ha_softc *softc = &ha_softc;
883 softc->ha_ctl_softc = ctl_softc;
884 mtx_init(&softc->ha_lock, "CTL HA mutex", NULL, MTX_DEF);
885 mbufq_init(&softc->ha_sendq, INT_MAX);
886 TAILQ_INIT(&softc->ha_dts);
887 error = kproc_kthread_add(ctl_ha_conn_thread, softc,
891 mtx_destroy(&softc->ha_lock);
894 softc->ha_shutdown_eh = EVENTHANDLER_REGISTER(shutdown_pre_sync,
900 softc, 0, ctl_ha_peer_sysctl, "A", "HA peer connection method");
913 struct ha_softc *softc = &ha_softc;
916 mtx_lock(&softc->ha_lock);
917 if (softc->ha_shutdown < 2) {
918 softc->ha_shutdown = 1;
919 softc->ha_wakeup = 1;
920 wakeup(&softc->ha_wakeup);
921 while (softc->ha_shutdown < 2 && !SCHEDULER_STOPPED()) {
922 msleep(&softc->ha_wakeup, &softc->ha_lock, 0,
926 mtx_unlock(&softc->ha_lock);
932 struct ha_softc *softc = &ha_softc;
934 if (softc->ha_shutdown_eh != NULL) {
936 softc->ha_shutdown_eh);
937 softc->ha_shutdown_eh = NULL;
945 mtx_destroy(&softc->ha_lock);