ctld: Only check physical port linking in a single configuration context

Commit 969876fcee 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
6acc7afa34) 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:		969876fcee ("ctld: parse config file independently of getting kernel info")
Sponsored by:	Chelsio Communications
Differential Revision:	https://reviews.freebsd.org/D57093
This commit is contained in:
John Baldwin
2026-05-27 16:57:38 -04:00
parent caef3c50ac
commit d1a8fa2e0f
2 changed files with 7 additions and 9 deletions
+7 -5
View File
@@ -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);
}
-4
View File
@@ -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 {