Don't create socketpair for connection forwarding between parent and secondary.
Secondary doesn't need to connect anywhere. MFC after: 1 week
This commit is contained in:
parent
9775d5ebdf
commit
640b7ee623
Notes:
svn2git
2020-12-20 02:59:44 +00:00
svn path=/head/; revision=219900
@ -224,7 +224,8 @@ descriptors_assert(const struct hast_resource *res, int pjdlogmode)
|
|||||||
fd, dtype2str(mode), dtype2str(S_IFSOCK));
|
fd, dtype2str(mode), dtype2str(S_IFSOCK));
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
} else if (fd == proto_descriptor(res->hr_conn)) {
|
} else if (res->hr_role == HAST_ROLE_PRIMARY &&
|
||||||
|
fd == proto_descriptor(res->hr_conn)) {
|
||||||
if (!isopen) {
|
if (!isopen) {
|
||||||
(void)snprintf(msg, sizeof(msg),
|
(void)snprintf(msg, sizeof(msg),
|
||||||
"Descriptor %d (conn) is closed, but should be open.",
|
"Descriptor %d (conn) is closed, but should be open.",
|
||||||
@ -237,6 +238,15 @@ descriptors_assert(const struct hast_resource *res, int pjdlogmode)
|
|||||||
fd, dtype2str(mode), dtype2str(S_IFSOCK));
|
fd, dtype2str(mode), dtype2str(S_IFSOCK));
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
} else if (res->hr_role == HAST_ROLE_SECONDARY &&
|
||||||
|
res->hr_conn != NULL &&
|
||||||
|
fd == proto_descriptor(res->hr_conn)) {
|
||||||
|
if (isopen) {
|
||||||
|
(void)snprintf(msg, sizeof(msg),
|
||||||
|
"Descriptor %d (conn) is open, but should be closed.",
|
||||||
|
fd);
|
||||||
|
break;
|
||||||
|
}
|
||||||
} else if (res->hr_role == HAST_ROLE_SECONDARY &&
|
} else if (res->hr_role == HAST_ROLE_SECONDARY &&
|
||||||
fd == proto_descriptor(res->hr_remotein)) {
|
fd == proto_descriptor(res->hr_remotein)) {
|
||||||
if (!isopen) {
|
if (!isopen) {
|
||||||
@ -851,6 +861,8 @@ connection_migrate(struct hast_resource *res)
|
|||||||
|
|
||||||
pjdlog_prefix_set("[%s] (%s) ", res->hr_name, role2str(res->hr_role));
|
pjdlog_prefix_set("[%s] (%s) ", res->hr_name, role2str(res->hr_role));
|
||||||
|
|
||||||
|
PJDLOG_ASSERT(res->hr_role == HAST_ROLE_PRIMARY);
|
||||||
|
|
||||||
if (proto_recv(res->hr_conn, &val, sizeof(val)) < 0) {
|
if (proto_recv(res->hr_conn, &val, sizeof(val)) < 0) {
|
||||||
pjdlog_errno(LOG_WARNING,
|
pjdlog_errno(LOG_WARNING,
|
||||||
"Unable to receive connection command");
|
"Unable to receive connection command");
|
||||||
@ -951,17 +963,19 @@ main_loop(void)
|
|||||||
TAILQ_FOREACH(res, &cfg->hc_resources, hr_next) {
|
TAILQ_FOREACH(res, &cfg->hc_resources, hr_next) {
|
||||||
if (res->hr_event == NULL)
|
if (res->hr_event == NULL)
|
||||||
continue;
|
continue;
|
||||||
PJDLOG_ASSERT(res->hr_conn != NULL);
|
|
||||||
fd = proto_descriptor(res->hr_event);
|
fd = proto_descriptor(res->hr_event);
|
||||||
PJDLOG_ASSERT(fd >= 0);
|
PJDLOG_ASSERT(fd >= 0);
|
||||||
FD_SET(fd, &rfds);
|
FD_SET(fd, &rfds);
|
||||||
maxfd = fd > maxfd ? fd : maxfd;
|
maxfd = fd > maxfd ? fd : maxfd;
|
||||||
if (res->hr_role == HAST_ROLE_PRIMARY) {
|
if (res->hr_role == HAST_ROLE_PRIMARY) {
|
||||||
/* Only primary workers asks for connections. */
|
/* Only primary workers asks for connections. */
|
||||||
|
PJDLOG_ASSERT(res->hr_conn != NULL);
|
||||||
fd = proto_descriptor(res->hr_conn);
|
fd = proto_descriptor(res->hr_conn);
|
||||||
PJDLOG_ASSERT(fd >= 0);
|
PJDLOG_ASSERT(fd >= 0);
|
||||||
FD_SET(fd, &rfds);
|
FD_SET(fd, &rfds);
|
||||||
maxfd = fd > maxfd ? fd : maxfd;
|
maxfd = fd > maxfd ? fd : maxfd;
|
||||||
|
} else {
|
||||||
|
PJDLOG_ASSERT(res->hr_conn == NULL);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -998,20 +1012,26 @@ main_loop(void)
|
|||||||
TAILQ_FOREACH(res, &cfg->hc_resources, hr_next) {
|
TAILQ_FOREACH(res, &cfg->hc_resources, hr_next) {
|
||||||
if (res->hr_event == NULL)
|
if (res->hr_event == NULL)
|
||||||
continue;
|
continue;
|
||||||
PJDLOG_ASSERT(res->hr_conn != NULL);
|
|
||||||
if (FD_ISSET(proto_descriptor(res->hr_event), &rfds)) {
|
if (FD_ISSET(proto_descriptor(res->hr_event), &rfds)) {
|
||||||
if (event_recv(res) == 0)
|
if (event_recv(res) == 0)
|
||||||
continue;
|
continue;
|
||||||
/* The worker process exited? */
|
/* The worker process exited? */
|
||||||
proto_close(res->hr_event);
|
proto_close(res->hr_event);
|
||||||
res->hr_event = NULL;
|
res->hr_event = NULL;
|
||||||
proto_close(res->hr_conn);
|
if (res->hr_conn != NULL) {
|
||||||
res->hr_conn = NULL;
|
proto_close(res->hr_conn);
|
||||||
|
res->hr_conn = NULL;
|
||||||
|
}
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
if (res->hr_role == HAST_ROLE_PRIMARY &&
|
if (res->hr_role == HAST_ROLE_PRIMARY) {
|
||||||
FD_ISSET(proto_descriptor(res->hr_conn), &rfds)) {
|
PJDLOG_ASSERT(res->hr_conn != NULL);
|
||||||
connection_migrate(res);
|
if (FD_ISSET(proto_descriptor(res->hr_conn),
|
||||||
|
&rfds)) {
|
||||||
|
connection_migrate(res);
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
PJDLOG_ASSERT(res->hr_conn == NULL);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -378,16 +378,6 @@ hastd_secondary(struct hast_resource *res, struct nv *nvin)
|
|||||||
pjdlog_exit(EX_OSERR,
|
pjdlog_exit(EX_OSERR,
|
||||||
"Unable to create event sockets between child and parent");
|
"Unable to create event sockets between child and parent");
|
||||||
}
|
}
|
||||||
/*
|
|
||||||
* Create communication channel for sending connection requests from
|
|
||||||
* parent to child.
|
|
||||||
*/
|
|
||||||
if (proto_client(NULL, "socketpair://", &res->hr_conn) < 0) {
|
|
||||||
/* TODO: There's no need for this to be fatal error. */
|
|
||||||
KEEP_ERRNO((void)pidfile_remove(pfh));
|
|
||||||
pjdlog_exit(EX_OSERR,
|
|
||||||
"Unable to create connection sockets between parent and child");
|
|
||||||
}
|
|
||||||
|
|
||||||
pid = fork();
|
pid = fork();
|
||||||
if (pid < 0) {
|
if (pid < 0) {
|
||||||
@ -405,7 +395,6 @@ hastd_secondary(struct hast_resource *res, struct nv *nvin)
|
|||||||
proto_recv(res->hr_event, NULL, 0);
|
proto_recv(res->hr_event, NULL, 0);
|
||||||
/* Declare that we are sender. */
|
/* Declare that we are sender. */
|
||||||
proto_send(res->hr_ctrl, NULL, 0);
|
proto_send(res->hr_ctrl, NULL, 0);
|
||||||
proto_send(res->hr_conn, NULL, 0);
|
|
||||||
res->hr_workerpid = pid;
|
res->hr_workerpid = pid;
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@ -418,7 +407,6 @@ hastd_secondary(struct hast_resource *res, struct nv *nvin)
|
|||||||
proto_send(res->hr_event, NULL, 0);
|
proto_send(res->hr_event, NULL, 0);
|
||||||
/* Declare that we are receiver. */
|
/* Declare that we are receiver. */
|
||||||
proto_recv(res->hr_ctrl, NULL, 0);
|
proto_recv(res->hr_ctrl, NULL, 0);
|
||||||
proto_recv(res->hr_conn, NULL, 0);
|
|
||||||
descriptors_cleanup(res);
|
descriptors_cleanup(res);
|
||||||
|
|
||||||
descriptors_assert(res, mode);
|
descriptors_assert(res, mode);
|
||||||
|
Loading…
Reference in New Issue
Block a user