ctld: Use freebsd::fd_up to manage the lifecycle of accepted sockets

Explicitly hand off ownership of accepted sockets to the
portal::handle_connection method.

Reviewed by:	asomers
Sponsored by:	Chelsio Communications
Differential Revision:	https://reviews.freebsd.org/D51729
This commit is contained in:
John Baldwin
2025-08-06 15:57:27 -04:00
parent 7e844dcad2
commit 40484d3117
5 changed files with 14 additions and 15 deletions
+3 -5
View File
@@ -2166,7 +2166,7 @@ wait_for_children(bool block)
}
static void
handle_connection(struct portal *portal, int fd,
handle_connection(struct portal *portal, freebsd::fd_up fd,
const struct sockaddr *client_sa, bool dont_fork)
{
struct portal_group *pg;
@@ -2197,10 +2197,8 @@ handle_connection(struct portal *portal, int fd,
pid = fork();
if (pid < 0)
log_err(1, "fork");
if (pid > 0) {
close(fd);
if (pid > 0)
return;
}
conf->close_pidfile();
}
@@ -2214,7 +2212,7 @@ handle_connection(struct portal *portal, int fd,
log_set_peer_addr(host);
setproctitle("%s", host);
portal->handle_connection(fd, host, client_sa);
portal->handle_connection(std::move(fd), host, client_sa);
log_debugx("nothing more to do; exiting");
exit(0);
}
+1 -1
View File
@@ -144,7 +144,7 @@ struct portal {
bool reuse_socket(portal &oldp);
bool init_socket();
virtual bool init_socket_options(int s __unused) { return true; }
virtual void handle_connection(int fd, const char *host,
virtual void handle_connection(freebsd::fd_up fd, const char *host,
const struct sockaddr *client_sa) = 0;
portal_group *portal_group() { return p_portal_group; }
+6 -6
View File
@@ -61,7 +61,7 @@ struct iscsi_portal final : public portal {
portal(pg, listen, protocol, std::move(ai)) {}
bool init_socket_options(int s) override;
void handle_connection(int fd, const char *host,
void handle_connection(freebsd::fd_up fd, const char *host,
const struct sockaddr *client_sa) override;
};
@@ -410,13 +410,13 @@ pdu_fail(const struct connection *conn __unused, const char *reason __unused)
{
}
iscsi_connection::iscsi_connection(struct portal *portal, int fd,
iscsi_connection::iscsi_connection(struct portal *portal, freebsd::fd_up fd,
const char *host, const struct sockaddr *client_sa) :
conn_portal(portal), conn_initiator_addr(host),
conn_portal(portal), conn_fd(std::move(fd)), conn_initiator_addr(host),
conn_initiator_sa(client_sa)
{
connection_init(&conn, &conn_ops, proxy_mode);
conn.conn_socket = fd;
conn.conn_socket = conn_fd;
}
iscsi_connection::~iscsi_connection()
@@ -496,12 +496,12 @@ iscsi_connection::handle()
}
void
iscsi_portal::handle_connection(int fd, const char *host,
iscsi_portal::handle_connection(freebsd::fd_up fd, const char *host,
const struct sockaddr *client_sa)
{
struct conf *conf = portal_group()->conf();
iscsi_connection conn(this, fd, host, client_sa);
iscsi_connection conn(this, std::move(fd), host, client_sa);
start_timer(conf->timeout(), true);
kernel_capsicate();
conn.handle();
+3 -2
View File
@@ -36,8 +36,8 @@
#define CONN_SESSION_TYPE_NORMAL 2
struct iscsi_connection {
iscsi_connection(struct portal *portal, int fd, const char *host,
const struct sockaddr *client_sa);
iscsi_connection(struct portal *portal, freebsd::fd_up fd,
const char *host, const struct sockaddr *client_sa);
~iscsi_connection();
void handle();
@@ -61,6 +61,7 @@ private:
struct portal *conn_portal = nullptr;
const struct port *conn_port = nullptr;
struct target *conn_target = nullptr;
freebsd::fd_up conn_fd;
int conn_session_type = CONN_SESSION_TYPE_NONE;
std::string conn_initiator_name;
std::string conn_initiator_addr;
+1 -1
View File
@@ -752,7 +752,7 @@ iscsi_connection::login_negotiate(struct pdu *request)
conn_max_burst_limit = (1 << 24) - 1;
conn_first_burst_limit = (1 << 24) - 1;
kernel_limits(pg->offload(),
conn.conn_socket,
conn_fd,
&conn_max_recv_data_segment_limit,
&conn_max_send_data_segment_limit,
&conn_max_burst_limit,