git: d9c0594191f5 - main - ctld: kernel-sourced portal groups are not dummies
- Go to: [ bottom of page ] [ top of archives ] [ this month ]
Date: Tue, 28 Apr 2026 20:52:17 UTC
The branch main has been updated by kevans:
URL: https://cgit.FreeBSD.org/src/commit/?id=d9c0594191f5c45d7f3c737350321ee59bfce9bf
commit d9c0594191f5c45d7f3c737350321ee59bfce9bf
Author: Kyle Evans <kevans@FreeBSD.org>
AuthorDate: 2026-04-28 20:51:50 +0000
Commit: Kyle Evans <kevans@FreeBSD.org>
CommitDate: 2026-04-28 20:51:50 +0000
ctld: kernel-sourced portal groups are not dummies
The current and historical versions of ctld would flag our initial set
of kernel ports as dummies, because their portal groups were empty since
portals come from the configuration on-disk.
As a result, we would never try to remove a kernel port at startup that
didn't exist in the configuration (possibly a feature if you wanted
concurrent ctld(8)), and we would always try to port->kernel_add() on
ports in the configuration (even if they actually did have an existing
kernel port).
Flag these portal groups as kernel groups so that we avoid trying to add
ports that already exist. It may be the case that the kernel_remove()
loop in conf::apply() needs to do something other than the current
`oldport->is_dummy()` to avoid removing ports that it isn't supposed to
be managing, but that wuld also seem to apply to LUNs that would be
removed today.
Reviewed by: jhb
Differential Revision: https://reviews.freebsd.org/D51782
---
usr.sbin/ctld/ctld.cc | 15 +++++++++++++++
usr.sbin/ctld/ctld.hh | 2 ++
usr.sbin/ctld/kernel.cc | 4 ++++
3 files changed, 21 insertions(+)
diff --git a/usr.sbin/ctld/ctld.cc b/usr.sbin/ctld/ctld.cc
index cf1dde93b86d..8aaec41e8487 100644
--- a/usr.sbin/ctld/ctld.cc
+++ b/usr.sbin/ctld/ctld.cc
@@ -578,9 +578,18 @@ conf::find_transport_group(std::string_view name)
return (it->second.get());
}
+/*
+ * Foreign portal groups (which only redirect to other targets), and portal
+ * groups without any active portals are considered dummies and ports belonging
+ * to such groups are ignored. However, portal groups that exist in the kernel
+ * prior to ctld starting will contain real ports but no portals, so these are
+ * never considered dummies.
+ */
bool
portal_group::is_dummy() const
{
+ if (pg_kernel)
+ return (false);
if (pg_foreign)
return (true);
if (pg_portals.empty())
@@ -697,6 +706,12 @@ portal_group::set_foreign()
pg_foreign = true;
}
+void
+portal_group::set_kernel()
+{
+ pg_kernel = true;
+}
+
bool
portal_group::set_offload(const char *offload)
{
diff --git a/usr.sbin/ctld/ctld.hh b/usr.sbin/ctld/ctld.hh
index 61213119f911..45590ada4111 100644
--- a/usr.sbin/ctld/ctld.hh
+++ b/usr.sbin/ctld/ctld.hh
@@ -220,6 +220,7 @@ struct portal_group {
bool set_dscp(u_int dscp);
virtual bool set_filter(const char *str) = 0;
void set_foreign();
+ void set_kernel();
bool set_offload(const char *offload);
bool set_pcp(u_int pcp);
bool set_redirection(const char *addr);
@@ -248,6 +249,7 @@ protected:
enum discovery_filter pg_discovery_filter =
discovery_filter::UNKNOWN;
bool pg_foreign = false;
+ bool pg_kernel = false;
bool pg_assigned = false;
std::list<portal_up> pg_portals;
std::unordered_map<std::string, port *> pg_ports;
diff --git a/usr.sbin/ctld/kernel.cc b/usr.sbin/ctld/kernel.cc
index 6b17ce60ac69..a6b0a79850ec 100644
--- a/usr.sbin/ctld/kernel.cc
+++ b/usr.sbin/ctld/kernel.cc
@@ -483,6 +483,8 @@ add_iscsi_port(struct kports &kports, struct conf *conf,
log_warnx("Failed to add portal-group \"%s\"", pg_name);
return;
}
+
+ pg->set_kernel();
}
pg->set_tag(port.cfiscsi_portal_group_tag);
if (!conf->add_port(targ, pg, port.port_id)) {
@@ -520,6 +522,8 @@ add_nvmf_port(struct conf *conf, const struct cctl_port &port,
tg_name);
return;
}
+
+ pg->set_kernel();
}
pg->set_tag(port.portid);
if (!conf->add_port(targ, pg, port.port_id)) {