From 15b3e3bb7efcbf7c29ab76e9ea7990c17df790e6 Mon Sep 17 00:00:00 2001 From: Alan Somers Date: Wed, 12 Oct 2022 16:44:09 -0600 Subject: [PATCH] ctld: if adding a target fails, retry it on the next reload If the admin creates more CTL ports than kern.cam.ctl.max_ports, then adding some will fail. If he then removes some ports and does "service ctld reload", he would expect that the new ports would get added in the newly-freed port space. But they don't, because ctld assigned them port numbers during their first creation attempts. Fix this bug by removing newly created ports from ctld's internal list if the kernel rejects them for any reason. That way, a subsequent config reload will attempt to add them again, possibly with new port numbers. MFC after: 2 weeks Sponsored by: Axcient Reviewed by: jhb, mav Differential Revision: https://reviews.freebsd.org/D36974 --- usr.sbin/ctld/ctld.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/usr.sbin/ctld/ctld.c b/usr.sbin/ctld/ctld.c index 3f4bca63251..7ee381de08a 100644 --- a/usr.sbin/ctld/ctld.c +++ b/usr.sbin/ctld/ctld.c @@ -2113,7 +2113,7 @@ conf_apply(struct conf *oldconf, struct conf *newconf) /* * Now add new ports or modify existing ones. */ - TAILQ_FOREACH(newport, &newconf->conf_ports, p_next) { + TAILQ_FOREACH_SAFE(newport, &newconf->conf_ports, p_next, tmpport) { if (port_is_dummy(newport)) continue; oldport = port_find(oldconf, newport->p_name); @@ -2130,6 +2130,8 @@ conf_apply(struct conf *oldconf, struct conf *newconf) log_warnx("failed to %s port %s", (oldport == NULL) ? "add" : "update", newport->p_name); + if (oldport == NULL || port_is_dummy(oldport)) + port_delete(newport); /* * XXX: Uncomment after fixing the root cause. *