[Bug 293076] ctld regression in FreeBSD 15: multiple physical ports per target rejected and ports not enabled automatically

[email protected] Mon, 13 Apr 2026 16:58:58 +0000
Newsgroups gmane.os.freebsd.devel.scsi
Message-ID <[email protected]/bugzilla/>
https://bugs.freebsd.org/bugzilla/show_bug.cgi?id=3D293076

--- Comment #17 from John Baldwin <[email protected]> ---
So I think your fix won't have the desired effect for reload.  I think if y=
ou
continue there, what will happen is that when re-parsing the configuration
during reload, the existing ports will not be added in the "new" config, so
conf::apply will end up removing the old ports (and thus disabling the phys=
ical
ports).  I think what we really want is to not have "linked" be a permanent
property of the pport.  Instead, inside of conf::add_pports we just want to
catch duplicate assignments.  I can actually use a local variable for this =
and
provide a better error as I can then report the name of the first target wh=
en a
port is claimed by multiple targets.

This patch aims to fix that, but it does build on top my other refactor, so=
 it
might be easiest to pull my branch and test it instead as it won't apply
directly to your tree:

diff --git a/usr.sbin/ctld/ctld.cc b/usr.sbin/ctld/ctld.cc
index b784c0e6f524..72001de6b5cb 100644
--- a/usr.sbin/ctld/ctld.cc
+++ b/usr.sbin/ctld/ctld.cc
@@ -1173,7 +1173,6 @@ conf::add_port(struct target *target, struct pport *p=
p)
                return (false);
        }

-       pp->link();
        return (true);
 }

@@ -2620,6 +2619,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;

@@ -2633,11 +2633,13 @@ conf::add_pports(struct kports &kports)
                         */
                        pp =3D kports.find_port(pport);
                        if (pp !=3D nullptr) {
-                               if (pp->linked()) {
+                               const auto &pair =3D linked_ports.try_empla=
ce(pp,
+                                   targ);
+                               if (!pair.second) {
                                        log_warnx("can't link port \"%s\" t=
o "
-                                           "%s, port already linked to som=
e "
-                                           "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 7eb86e6cc535..b4d71b141fb2 100644
--- a/usr.sbin/ctld/ctld.hh
+++ b/usr.sbin/ctld/ctld.hh
@@ -569,13 +569,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 =3D true; }
-
 private:
        std::string                     pp_name;
        uint32_t                        pp_ctl_port;
-       bool                            pp_linked =3D false;
 };

 struct kports {

--=20
You are receiving this mail because:
You are the assignee for the bug.=