How do I assign an iscsi target to a specific local device?

From: G. Paul Ziemba <pz-freebsd-scsi_at_ziemba.us>
Date: Tue, 20 Dec 2022 20:43:34 UTC
FreeBSD 13.1-STABLE (stable branch as of 2022-May-01)

On a freebsd iscsi initiator, I'd like to map remote devices (accesed
via iscsi) to specific device names on the initiator.

In my case, the remote devices happen to be tape library changers and
tape drives, which show up as ch and sa devices on the initiator.

Here is partial output of "camcontrol devlist -v" showing relevant
dynamically-assigned entries:

    scbus12 on iscsi4 bus 0:
    <DELL PV-122T K17r>        at scbus12 target 0 lun 0 (pass10,ch2)
    <IBM ULTRIUM-TD2 3AYD>     at scbus12 target 0 lun 1 (pass11,sa2)
    <>                         at scbus12 target -1 lun ffffffff ()


I'm familiar with "wiring" mappings as described in cam(4) via
/boot/device.hints. However, I believe that in the case of the iscsi
initiator, the controller instance "iscsi4" depends on past history,
so I can't expect consistency via a device.hints entry such as:

    hint.scbus.0.at="iscsi4"

"iscsictl -L -v" output indicates:

    Session ID:               4
    [...]
    Device nodes:             ch2 sa2 

And /usr/src/sys/dev/iscsi_initiator/iscsi.c has:

    static int
    i_create_session(struct cdev *dev, int *ndev)
    {
	 [...]
	 int                error, n;
	 [...]
	 if((n = alloc_unr(sc->unit)) < 0) {
	      [...]
	      xdebug("too many sessions!");
	      return EPERM;
	 }

I'm guessing that "4" in "iscsi4" comes from the iscsi session ID
and, based on the session ID assignment code, there is no current
way to assign fixed session IDs to specific targets. I'm hoping
someone can dispute this claim.

In theory I could hack something up that parsed the "iscsictl -L -v"
output and symlinked the devices to fixed names, but that's ugly and
asynchronous. Is there a better approach?

Many thanks!
-- 
G. Paul Ziemba
FreeBSD unix:
12:41PM  up 8 days, 22:19, 29 users, load averages: 0.29, 0.17, 0.15