Changeset View
Changeset View
Standalone View
Standalone View
sys/cam/ctl/ctl_ha.c
Show First 20 Lines • Show All 452 Lines • ▼ Show 20 Lines | |||||
out: | out: | ||||
ctl_ha_close(softc); | ctl_ha_close(softc); | ||||
return (error); | return (error); | ||||
} | } | ||||
static int | static int | ||||
ctl_ha_accept(struct ha_softc *softc) | ctl_ha_accept(struct ha_softc *softc) | ||||
{ | { | ||||
struct socket *so; | struct socket *lso, *so; | ||||
struct sockaddr *sap; | struct sockaddr *sap; | ||||
int error; | int error; | ||||
ACCEPT_LOCK(); | lso = softc->ha_lso; | ||||
if (softc->ha_lso->so_rcv.sb_state & SBS_CANTRCVMORE) | SOLISTEN_LOCK(lso); | ||||
softc->ha_lso->so_error = ECONNABORTED; | error = solisten_dequeue(lso, &so, 0); | ||||
if (softc->ha_lso->so_error) { | if (error == EWOULDBLOCK) | ||||
error = softc->ha_lso->so_error; | return (error); | ||||
softc->ha_lso->so_error = 0; | if (error) { | ||||
ACCEPT_UNLOCK(); | |||||
printf("%s: socket error %d\n", __func__, error); | printf("%s: socket error %d\n", __func__, error); | ||||
goto out; | goto out; | ||||
} | } | ||||
so = TAILQ_FIRST(&softc->ha_lso->so_comp); | |||||
if (so == NULL) { | |||||
ACCEPT_UNLOCK(); | |||||
return (EWOULDBLOCK); | |||||
} | |||||
KASSERT(!(so->so_qstate & SQ_INCOMP), ("accept1: so SQ_INCOMP")); | |||||
KASSERT(so->so_qstate & SQ_COMP, ("accept1: so not SQ_COMP")); | |||||
/* | |||||
* Before changing the flags on the socket, we have to bump the | |||||
* reference count. Otherwise, if the protocol calls sofree(), | |||||
* the socket will be released due to a zero refcount. | |||||
*/ | |||||
SOCK_LOCK(so); /* soref() and so_state update */ | |||||
soref(so); /* file descriptor reference */ | |||||
TAILQ_REMOVE(&softc->ha_lso->so_comp, so, so_list); | |||||
softc->ha_lso->so_qlen--; | |||||
so->so_state |= SS_NBIO; | |||||
so->so_qstate &= ~SQ_COMP; | |||||
so->so_head = NULL; | |||||
SOCK_UNLOCK(so); | |||||
ACCEPT_UNLOCK(); | |||||
sap = NULL; | sap = NULL; | ||||
error = soaccept(so, &sap); | error = soaccept(so, &sap); | ||||
if (error != 0) { | if (error != 0) { | ||||
printf("%s: soaccept() error %d\n", __func__, error); | printf("%s: soaccept() error %d\n", __func__, error); | ||||
if (sap != NULL) | if (sap != NULL) | ||||
free(sap, M_SONAME); | free(sap, M_SONAME); | ||||
goto out; | goto out; | ||||
} | } | ||||
▲ Show 20 Lines • Show All 43 Lines • ▼ Show 20 Lines | if (softc->ha_lso == NULL) { | ||||
opt.sopt_val = &val; | opt.sopt_val = &val; | ||||
opt.sopt_valsize = sizeof(val); | opt.sopt_valsize = sizeof(val); | ||||
val = 1; | val = 1; | ||||
error = sosetopt(softc->ha_lso, &opt); | error = sosetopt(softc->ha_lso, &opt); | ||||
if (error) { | if (error) { | ||||
printf("%s: REUSEPORT setting failed %d\n", | printf("%s: REUSEPORT setting failed %d\n", | ||||
__func__, error); | __func__, error); | ||||
} | } | ||||
SOCKBUF_LOCK(&softc->ha_lso->so_rcv); | |||||
soupcall_set(softc->ha_lso, SO_RCV, ctl_ha_lupcall, softc); | |||||
SOCKBUF_UNLOCK(&softc->ha_lso->so_rcv); | |||||
} | } | ||||
memcpy(&sa, &softc->ha_peer_in, sizeof(sa)); | memcpy(&sa, &softc->ha_peer_in, sizeof(sa)); | ||||
error = sobind(softc->ha_lso, (struct sockaddr *)&sa, td); | error = sobind(softc->ha_lso, (struct sockaddr *)&sa, td); | ||||
if (error != 0) { | if (error != 0) { | ||||
printf("%s: sobind() error %d\n", __func__, error); | printf("%s: sobind() error %d\n", __func__, error); | ||||
goto out; | goto out; | ||||
} | } | ||||
error = solisten(softc->ha_lso, 1, td); | error = solisten(softc->ha_lso, 1, td); | ||||
if (error != 0) { | if (error != 0) { | ||||
printf("%s: solisten() error %d\n", __func__, error); | printf("%s: solisten() error %d\n", __func__, error); | ||||
goto out; | goto out; | ||||
} | } | ||||
SOLISTEN_LOCK(softc->ha_lso); | |||||
softc->ha_lso->so_state |= SS_NBIO; | |||||
solisten_upcall_set(softc->ha_lso, ctl_ha_lupcall, softc); | |||||
SOLISTEN_UNLOCK(softc->ha_lso); | |||||
return (0); | return (0); | ||||
out: | out: | ||||
ctl_ha_lclose(softc); | ctl_ha_lclose(softc); | ||||
return (error); | return (error); | ||||
} | } | ||||
static void | static void | ||||
▲ Show 20 Lines • Show All 448 Lines • Show Last 20 Lines |