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
This commit is contained in:
Kyle Evans
2026-04-28 15:51:50 -05:00
parent fe9d81d7c6
commit d9c0594191
3 changed files with 21 additions and 0 deletions
+15
View File
@@ -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)
{
+2
View File
@@ -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;
+4
View File
@@ -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)) {