From owner-svn-src-all@FreeBSD.ORG Wed Mar 23 11:09:04 2011 Return-Path: Delivered-To: svn-src-all@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id CC8D1106564A; Wed, 23 Mar 2011 11:09:04 +0000 (UTC) (envelope-from pjd@FreeBSD.org) Received: from svn.freebsd.org (svn.freebsd.org [IPv6:2001:4f8:fff6::2c]) by mx1.freebsd.org (Postfix) with ESMTP id BD7F68FC1A; Wed, 23 Mar 2011 11:09:04 +0000 (UTC) Received: from svn.freebsd.org (localhost [127.0.0.1]) by svn.freebsd.org (8.14.3/8.14.3) with ESMTP id p2NB94cu091634; Wed, 23 Mar 2011 11:09:04 GMT (envelope-from pjd@svn.freebsd.org) Received: (from pjd@localhost) by svn.freebsd.org (8.14.3/8.14.3/Submit) id p2NB94ek091631; Wed, 23 Mar 2011 11:09:04 GMT (envelope-from pjd@svn.freebsd.org) Message-Id: <201103231109.p2NB94ek091631@svn.freebsd.org> From: Pawel Jakub Dawidek Date: Wed, 23 Mar 2011 11:09:04 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org X-SVN-Group: head MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Cc: Subject: svn commit: r219900 - head/sbin/hastd X-BeenThere: svn-src-all@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: "SVN commit messages for the entire src tree \(except for " user" and " projects" \)" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Wed, 23 Mar 2011 11:09:04 -0000 Author: pjd Date: Wed Mar 23 11:09:04 2011 New Revision: 219900 URL: http://svn.freebsd.org/changeset/base/219900 Log: Don't create socketpair for connection forwarding between parent and secondary. Secondary doesn't need to connect anywhere. MFC after: 1 week Modified: head/sbin/hastd/hastd.c head/sbin/hastd/secondary.c Modified: head/sbin/hastd/hastd.c ============================================================================== --- head/sbin/hastd/hastd.c Wed Mar 23 08:33:12 2011 (r219899) +++ head/sbin/hastd/hastd.c Wed Mar 23 11:09:04 2011 (r219900) @@ -224,7 +224,8 @@ descriptors_assert(const struct hast_res fd, dtype2str(mode), dtype2str(S_IFSOCK)); 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) { (void)snprintf(msg, sizeof(msg), "Descriptor %d (conn) is closed, but should be open.", @@ -238,6 +239,15 @@ descriptors_assert(const struct hast_res 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 && fd == proto_descriptor(res->hr_remotein)) { if (!isopen) { (void)snprintf(msg, sizeof(msg), @@ -851,6 +861,8 @@ connection_migrate(struct hast_resource 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) { pjdlog_errno(LOG_WARNING, "Unable to receive connection command"); @@ -951,17 +963,19 @@ main_loop(void) TAILQ_FOREACH(res, &cfg->hc_resources, hr_next) { if (res->hr_event == NULL) continue; - PJDLOG_ASSERT(res->hr_conn != NULL); fd = proto_descriptor(res->hr_event); PJDLOG_ASSERT(fd >= 0); FD_SET(fd, &rfds); maxfd = fd > maxfd ? fd : maxfd; if (res->hr_role == HAST_ROLE_PRIMARY) { /* Only primary workers asks for connections. */ + PJDLOG_ASSERT(res->hr_conn != NULL); fd = proto_descriptor(res->hr_conn); PJDLOG_ASSERT(fd >= 0); FD_SET(fd, &rfds); 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) { if (res->hr_event == NULL) continue; - PJDLOG_ASSERT(res->hr_conn != NULL); if (FD_ISSET(proto_descriptor(res->hr_event), &rfds)) { if (event_recv(res) == 0) continue; /* The worker process exited? */ proto_close(res->hr_event); res->hr_event = NULL; - proto_close(res->hr_conn); - res->hr_conn = NULL; + if (res->hr_conn != NULL) { + proto_close(res->hr_conn); + res->hr_conn = NULL; + } continue; } - if (res->hr_role == HAST_ROLE_PRIMARY && - FD_ISSET(proto_descriptor(res->hr_conn), &rfds)) { - connection_migrate(res); + if (res->hr_role == HAST_ROLE_PRIMARY) { + PJDLOG_ASSERT(res->hr_conn != NULL); + if (FD_ISSET(proto_descriptor(res->hr_conn), + &rfds)) { + connection_migrate(res); + } + } else { + PJDLOG_ASSERT(res->hr_conn == NULL); } } } Modified: head/sbin/hastd/secondary.c ============================================================================== --- head/sbin/hastd/secondary.c Wed Mar 23 08:33:12 2011 (r219899) +++ head/sbin/hastd/secondary.c Wed Mar 23 11:09:04 2011 (r219900) @@ -378,16 +378,6 @@ hastd_secondary(struct hast_resource *re pjdlog_exit(EX_OSERR, "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(); if (pid < 0) { @@ -405,7 +395,6 @@ hastd_secondary(struct hast_resource *re proto_recv(res->hr_event, NULL, 0); /* Declare that we are sender. */ proto_send(res->hr_ctrl, NULL, 0); - proto_send(res->hr_conn, NULL, 0); res->hr_workerpid = pid; return; } @@ -418,7 +407,6 @@ hastd_secondary(struct hast_resource *re proto_send(res->hr_event, NULL, 0); /* Declare that we are receiver. */ proto_recv(res->hr_ctrl, NULL, 0); - proto_recv(res->hr_conn, NULL, 0); descriptors_cleanup(res); descriptors_assert(res, mode);