From nobody Tue Jun 23 16:28:32 2026 X-Original-To: dev-commits-src-branches@mlmmj.nyi.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mlmmj.nyi.freebsd.org (Postfix) with ESMTP id 4gl9VT0N62z6hhcq for ; Tue, 23 Jun 2026 16:28:33 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from mxrelay.nyi.freebsd.org (mxrelay.nyi.freebsd.org [IPv6:2610:1c1:1:606c::19:3]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256 client-signature RSA-PSS (4096 bits) client-digest SHA256) (Client CN "mxrelay.nyi.freebsd.org", Issuer "YR1" (not verified)) by mx1.freebsd.org (Postfix) with ESMTPS id 4gl9VS4Mxpz3NJb for ; Tue, 23 Jun 2026 16:28:32 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1782232112; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=iORRsqzWnFNysglD6GqddQCy9SqHbaHpNxZNK7yj62U=; b=fo5hj8zNoGiIw+qJktXgRwcU0EFbtqc7SjMgtGyBDpgVmQIgojBtfsNmbmzXkCyMdlZaYE rCp9Jo7vDHy/F9JFjsAVVVi4Bn4trOAb9TAb42Xl6PuoKv1OStO/7nHgdxJoFSr9Yt+NTD WkdjktLFwcC8hOX/WcHTNIJxpPWyH5WH+mCDOQhW9QDSOpqRh5klrUirohknucJ+Fx9LwH nd6eAAssdvpeRQm5bWCEMK38J8v/d0lnFeb+K++t97tJqRH4OOPhcNohSqMz231woAs+gN Nic2kXLvT5zbnccCUoJEwr+roz+4cAuQAEPOp02lUuiBg1fKl6EHb78SGfEalw== ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1782232112; a=rsa-sha256; cv=none; b=Bp/gsUaY4l1H+Xari7geD89wxSNkqcWdvIj+43IV+p6XQlrZaQlTWvrecceV8gtWZnsNeX fUvsOQngLnjQ0Rkjqa3i/jxBnSKEuOntpshvauucxCppAZK4DHaqR0WYUuU3SlyA83LAGk anj5C6OEF/fJRPOecAEeXlkd7A9Xqjdp16TMp0JQtnGsGxIQdrJdjK32NktXoJAD1cyh2Y 5z5Rt2NHsnHbITQc0bIkZWqRaFcSes8HTmf6thlydFzW4IV/V7eZvXvh8nnjdbmuLlFP1U 4KTe4cpKt8LGYX/4XNiDk2ChxVej7ZXhKrIjdkrC6yzv2DygUrr6lL795/HVWA== ARC-Authentication-Results: i=1; mx1.freebsd.org; none ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1782232112; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=iORRsqzWnFNysglD6GqddQCy9SqHbaHpNxZNK7yj62U=; b=FHIZKUQVQuPt6miQag1rDpf4SZ/LfgHQ0R/sqLjxBsYojJpSiZvDdU62WHEAhElNMytp4Q A4sdq9AlZmV0rOL6H0bZDdi3DCq92d/Bnlxe/+900Z0iDTpfWDH+JjzHbPfYMUKgY5zBNM xRR/FZNHatzZu05LoCfG8t/lYZLdrkHNsU9JreZq7LTGbaB1R8IP3le1tgd9sukWn6p8v3 NapXHgACzJpIzPvnSTGwBnw4I6rtROSBECoDYq3iqw7V6uyjd+6wcpgovJfeGEUOMQyNNU UiKlMQWsYGZStVsjwmnqrA0lPg+vvS7vL6xK6f0QAKeaoiaS1zWnjKOK6Kk3CA== Received: from gitrepo.freebsd.org (gitrepo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:5]) by mxrelay.nyi.freebsd.org (Postfix) with ESMTP id 4gl9VS2Zhlzhm9 for ; Tue, 23 Jun 2026 16:28:32 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from git (uid 1279) (envelope-from git@FreeBSD.org) id 26ccf by gitrepo.freebsd.org (DragonFly Mail Agent v0.13+ on gitrepo.freebsd.org); Tue, 23 Jun 2026 16:28:32 +0000 To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-branches@FreeBSD.org From: John Baldwin Subject: git: c1a05ddfdcbc - stable/15 - ctld: Add a dedicated conf method for shutting down List-Id: Commits to the stable branches of the FreeBSD src repository List-Archive: https://lists.freebsd.org/archives/dev-commits-src-branches List-Help: List-Post: List-Subscribe: List-Unsubscribe: X-BeenThere: dev-commits-src-branches@freebsd.org Sender: owner-dev-commits-src-branches@FreeBSD.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit X-Git-Committer: jhb X-Git-Repository: src X-Git-Refname: refs/heads/stable/15 X-Git-Reftype: branch X-Git-Commit: c1a05ddfdcbc7af62d63a8d8a14511187729e21e Auto-Submitted: auto-generated Date: Tue, 23 Jun 2026 16:28:32 +0000 Message-Id: <6a3ab430.26ccf.60cae983@gitrepo.freebsd.org> The branch stable/15 has been updated by jhb: URL: https://cgit.FreeBSD.org/src/commit/?id=c1a05ddfdcbc7af62d63a8d8a14511187729e21e commit c1a05ddfdcbc7af62d63a8d8a14511187729e21e Author: John Baldwin AuthorDate: 2026-05-18 19:48:09 +0000 Commit: John Baldwin CommitDate: 2026-06-23 16:17:31 +0000 ctld: Add a dedicated conf method for shutting down Currently the main loop creates an empty config and applies it to force a shutdown of all of the existing configuration. While this is functional and does avoid duplicating some code, it is also a bit clunky and requires a special hack in the pidfile path handling in the conf::apply method. Instead, use a dedicated conf::shutdown method which tears down the CTL ports and LUNs and closes the sockets. Sponsored by: Chelsio Communications Differential Revision: https://reviews.freebsd.org/D56532 (cherry picked from commit f1c5de5fab9d5cada11935418db11e19ebff7e34) --- usr.sbin/ctld/ctld.cc | 56 ++++++++++++++++++++++++++++++++++++--------------- usr.sbin/ctld/ctld.hh | 1 + 2 files changed, 41 insertions(+), 16 deletions(-) diff --git a/usr.sbin/ctld/ctld.cc b/usr.sbin/ctld/ctld.cc index 627ecf8bba93..24b02a936670 100644 --- a/usr.sbin/ctld/ctld.cc +++ b/usr.sbin/ctld/ctld.cc @@ -1976,11 +1976,9 @@ conf::apply(struct conf *oldconf) /* * Rename the pidfile if the pathname changes. On startup, * oldconf created via conf_new_from_kernel will not contain a - * valid pidfile_path. On shutdown, the temporary newconf - * will not contain a valid pidfile_path. + * valid pidfile_path. */ - if (!oldconf->conf_pidfile_path.empty() && - !conf_pidfile_path.empty()) { + if (!oldconf->conf_pidfile_path.empty()) { if (oldconf->conf_pidfile_path != conf_pidfile_path) { /* pidfile has changed. rename it */ log_debugx("moving pidfile to %s", @@ -2210,6 +2208,41 @@ conf::apply(struct conf *oldconf) return (cumulated_error); } +void +conf::shutdown() +{ + /* Deregister from iSNS servers. */ + for (auto &kv : conf_isns) + isns_deregister_targets(&kv.second); + + /* Remove all ports. */ + for (const auto &kv : conf_ports) { + const std::string &name = kv.first; + port *port = kv.second.get(); + + if (port->is_dummy()) + continue; + log_debugx("removing port \"%s\"", name.c_str()); + if (!port->kernel_remove()) + log_warnx("failed to remove port %s", name.c_str()); + } + + /* Remove all LUNs. */ + for (const auto &kv : conf_luns) { + struct lun *lun = kv.second.get(); + + if (!lun->kernel_remove()) + log_warnx("failed to remove lun \"%s\", CTL lun %d", + lun->name(), lun->ctl_lun()); + } + + /* Close sockets on all portal groups. */ + for (auto &kv : conf_portal_groups) + kv.second->close_sockets(); + for (auto &kv : conf_transport_groups) + kv.second->close_sockets(); +} + bool timed_out(void) { @@ -2767,21 +2800,12 @@ main(int argc, char **argv) oldconf.reset(); } } else if (sigterm_received) { - log_debugx("exiting on signal; " - "reloading empty configuration"); + log_debugx("exiting on signal"); - log_debugx("removing CTL iSCSI ports " + log_debugx("removing CTL iSCSI and NVMeoF ports " "and terminating all connections"); - oldconf = std::move(newconf); - newconf = std::make_unique(); - if (debug > 0) - newconf->set_debug(debug); - error = newconf->apply(oldconf.get()); - if (error != 0) - log_warnx("failed to apply configuration"); - oldconf.reset(); - + newconf->shutdown(); log_warnx("exiting on signal"); return (0); } else { diff --git a/usr.sbin/ctld/ctld.hh b/usr.sbin/ctld/ctld.hh index d3b08dc12603..7ae033804157 100644 --- a/usr.sbin/ctld/ctld.hh +++ b/usr.sbin/ctld/ctld.hh @@ -513,6 +513,7 @@ struct conf { int apply(struct conf *oldconf); void delete_target_luns(struct lun *lun); bool reuse_portal_group_socket(struct portal &newp); + void shutdown(); bool verify(); private: