git: d1a8fa2e0f41 - main - ctld: Only check physical port linking in a single configuration context
- Go to: [ bottom of page ] [ top of archives ] [ this month ]
Date: Wed, 27 May 2026 21:00:34 UTC
The branch main has been updated by jhb:
URL: https://cgit.FreeBSD.org/src/commit/?id=d1a8fa2e0f415f941e628f959fa0e70f23058fdb
commit d1a8fa2e0f415f941e628f959fa0e70f23058fdb
Author: John Baldwin <jhb@FreeBSD.org>
AuthorDate: 2026-05-27 20:57:38 +0000
Commit: John Baldwin <jhb@FreeBSD.org>
CommitDate: 2026-05-27 20:57:38 +0000
ctld: Only check physical port linking in a single configuration context
Commit 969876fcee57 moved struct pport from being per-configuration to
being a "global" object shared across multiple configurations. As a
result, the check for duplicate ports actually spanned across
configurations, such that reloading a configuration would now think
that existing physical ports were already linked.
The linking field in pport added in the C++-ification (commit
6acc7afa34aa) faithfully replicated this bug (albeit simpler as I had
noticed that the TAILQ links weren't used after the earlier commit).
To restore the desired behavior, remove the linking field from struct
pport entirely and use a local unordered_map in conf::add_pports which
tracks if a given pport is claimed by more than one target.
PR: 293076
Reported by: Ken J. Thomson <thomsonk@yandex.com>
Fixes: 969876fcee57 ("ctld: parse config file independently of getting kernel info")
Sponsored by: Chelsio Communications
Differential Revision: https://reviews.freebsd.org/D57093
---
usr.sbin/ctld/ctld.cc | 12 +++++++-----
usr.sbin/ctld/ctld.hh | 4 ----
2 files changed, 7 insertions(+), 9 deletions(-)
diff --git a/usr.sbin/ctld/ctld.cc b/usr.sbin/ctld/ctld.cc
index 8b99bde14911..834bef4ef363 100644
--- a/usr.sbin/ctld/ctld.cc
+++ b/usr.sbin/ctld/ctld.cc
@@ -1175,7 +1175,6 @@ conf::add_port(struct target *target, struct pport *pp)
return (false);
}
- pp->link();
return (true);
}
@@ -2641,6 +2640,7 @@ conf_new_from_file(const char *path, bool ucl)
bool
conf::add_pports(struct kports &kports)
{
+ std::unordered_map<struct pport *, struct target *> linked_ports;
struct pport *pp;
int ret, i_pp, i_vp;
@@ -2654,11 +2654,13 @@ conf::add_pports(struct kports &kports)
*/
pp = kports.find_port(pport);
if (pp != nullptr) {
- if (pp->linked()) {
+ const auto &pair = linked_ports.try_emplace(pp,
+ targ);
+ if (!pair.second) {
log_warnx("can't link port \"%s\" to "
- "%s, port already linked to some "
- "target", pport.c_str(),
- targ->label());
+ "%s, port already linked to %s",
+ pport.c_str(), targ->label(),
+ pair.first->second->label());
return (false);
}
diff --git a/usr.sbin/ctld/ctld.hh b/usr.sbin/ctld/ctld.hh
index 8d63de06dd80..3bc92449e372 100644
--- a/usr.sbin/ctld/ctld.hh
+++ b/usr.sbin/ctld/ctld.hh
@@ -567,13 +567,9 @@ struct pport {
const char *name() const { return pp_name.c_str(); }
uint32_t ctl_port() const { return pp_ctl_port; }
- bool linked() const { return pp_linked; }
- void link() { pp_linked = true; }
-
private:
std::string pp_name;
uint32_t pp_ctl_port;
- bool pp_linked = false;
};
struct kports {