History log of /freebsd-current/usr.sbin/ctld/kernel.c
Revision Date Author Comments
# 8f65dcd6 07-Nov-2023 Elyes Haouas <ehaouas@noos.fr>

ctld: Use nitems(foo) instead of sizeof(foo)/sizeof(foo[0])

Pull Request: https://github.com/freebsd/freebsd-src/pull/888
Signed-off-by: Elyes Haouas <ehaouas@noos.fr>


# 4d65a7c6 24-Nov-2023 Warner Losh <imp@FreeBSD.org>

usr.sbin: Automated cleanup of cdefs and other formatting

Apply the following automated changes to try to eliminate
no-longer-needed sys/cdefs.h includes as well as now-empty
blank lines in a row.

Remove /^#if.*\n#endif.*\n#include\s+<sys/cdefs.h>.*\n/
Remove /\n+#include\s+<sys/cdefs.h>.*\n+#if.*\n#endif.*\n+/
Remove /\n+#if.*\n#endif.*\n+/
Remove /^#if.*\n#endif.*\n/
Remove /\n+#include\s+<sys/cdefs.h>\n#include\s+<sys/types.h>/
Remove /\n+#include\s+<sys/cdefs.h>\n#include\s+<sys/param.h>/
Remove /\n+#include\s+<sys/cdefs.h>\n#include\s+<sys/capsicum.h>/

Sponsored by: Netflix


# 1d386b48 16-Aug-2023 Warner Losh <imp@FreeBSD.org>

Remove $FreeBSD$: one-line .c pattern

Remove /^[\s*]*__FBSDID\("\$FreeBSD\$"\);?\s*\n/


# 4d846d26 10-May-2023 Warner Losh <imp@FreeBSD.org>

spdx: The BSD-2-Clause-FreeBSD identifier is obsolete, drop -FreeBSD

The SPDX folks have obsoleted the BSD-2-Clause-FreeBSD identifier. Catch
up to that fact and revert to their recommended match of BSD-2-Clause.

Discussed with: pfg
MFC After: 3 days
Sponsored by: Netflix


# 7b02c1e8 18-Apr-2022 John Baldwin <jhb@FreeBSD.org>

iscsi: Fetch limits based on a socket rather than assuming global limits.

cxgbei needs the ability to return different limits based on the
connection (e.g. if the connection is over a T5 adapter or a T6
adapter as well as factoring in the MTU).

This change plumbs through the changes in the ioctls without changing
any of the backends. The limits callback passed to icl_register now
accepts a second socket argument which holds the integer file
descriptor. To support ABI compatiblity for old binaries, the
callback should return "global" values if the socket fd is zero.

The CTL_ISCSI_LIMITS argument used with CTL_ISCSI by ctld(8) now
accepts the socket fd in a field that was previously part of a
reserved spare field. Old binaries zero this request which results in
passing a socket fd of 0 to the limits callback.

The ISCSIDREQUEST ioctl no longer returns limits. Instead, iscsid(8)
invokes a new ISCSIDLIMITS ioctl after establishing the connection via
connect(2). For ABI compat, if the old ISCSIDREQUEST is invoked, the
global limits are still fetched (with a socket fd of 0) and returned.

Reviewed by: mav
Sponsored by: Chelsio Communications
Differential Revision: https://reviews.freebsd.org/D34928


# 63783933 22-Dec-2021 John Baldwin <jhb@FreeBSD.org>

Add an internal libiscsiutil library.

Move some of the code duplicated between ctld(8) and iscsid(8) into a
libiscsiutil library.

Sharing the low-level PDU code did require having a
'struct connection' base class with a method table to permit separate
initiator vs target behavior (e.g. in handling proxy PDUs).

Reviewed by: mav, emaste
Sponsored by: Chelsio Communications
Differential Revision: https://reviews.freebsd.org/D33544


# e3529571 01-Sep-2020 Edward Tomasz Napierala <trasz@FreeBSD.org>

Make sure not to pass NULL to strtoul(3). The values come
from the kernel, but let's try to be on the safe side.

Reviewed by: mav
MFC after: 2 weeks
Sponsored by: NetApp, Inc.
Sponsored by: Klara, Inc.
Differential Revision: https://reviews.freebsd.org/D26246


# 3b11655c 28-Jul-2020 Alexander Motin <mav@FreeBSD.org>

When modifying LUN pass "special" options too.

Before switching to nvlists CTL merged previous and new options, so
any options not passed just kept previous value. Now CTL completely
replaces them, so we must pass everything still relevant.

MFC after: 1 week
Sponsored by: iXsystems, Inc.


# 1489776d 30-Nov-2018 Mariusz Zaborski <oshogbo@FreeBSD.org>

iscsi: simplify the capsicumization

Approved by: trasz
Differential Revision: https://reviews.freebsd.org/D17962


# 8951f055 09-May-2018 Marcelo Araujo <araujo@FreeBSD.org>

Rework CTL frontend & backend options to use nv(3), allow creating multiple
ioctl frontend ports.

This revision introduces two changes to CTL:
- Changes the way options are passed to CTL_LUN_REQ and CTL_PORT_REQ ioctls.
Removes ctl_be_arg structure and associated logic and replaces it with
nv(3)-based logic for passing in and out arguments.
- Allows creating multiple ioctl frontend ports using either ctladm(8) or
ctld(8).
New frontend ports are represented by /dev/cam/ctl<pp>.<vp> nodes, eg /dev/cam/ctl5.3.
Those device nodes respond only to CTL_IO ioctl.

New command-line options for ctladm:
# creates new ioctl frontend port with using free pp and vp=0
ctladm port -c
# creates new ioctl frontend port with pp=10 and vp=0
ctladm port -c -O pp=10
# creates new ioctl frontend port with pp=11 and vp=12
ctladm port -c -O pp=11 -O vp=12
# removes port with number 4 (it's a "targ_port" number, not pp number)
ctladm port -r -p 4

New syntax for ctl.conf:
target ... {
port ioctl/<pp>
...
}

target ... {
port ioctl/<pp>/<vp>
...

Note: Most of this work was made by jceel@, thank you.

Submitted by: jceel
Reworked by: myself
Reviewed by: mav (earlier versions and recently during the rework)
Obtained from: FreeNAS and TrueOS
Relnotes: Yes
Sponsored by: iXsystems Inc.
Differential Revision: https://reviews.freebsd.org/D9299


# 1de7b4b8 27-Nov-2017 Pedro F. Giffuni <pfg@FreeBSD.org>

various: general adoption of SPDX licensing ID tags.

Mainly focus on files that use BSD 2-Clause license, however the tool I
was using misidentified many licenses so this was mostly a manual - error
prone - task.

The Software Package Data Exchange (SPDX) group provides a specification
to make it easier for automated tools to detect and summarize well known
opensource licenses. We are gradually adopting the specification, noting
that the tags are considered only advisory and do not, in any way,
superceed or replace the license texts.

No functional change intended.


# 653e7d63 29-Mar-2017 Enji Cooper <ngie@FreeBSD.org>

Split iscsi(4) ctl frontend off of ctl(4) as cfiscsi(4)

The goal of this work is to remove the explicit dependency for ctl(4)
on iscsi(4), so end-users without iscsi(4) support in the kernel can
use ctl(4) for its other functions.

This allows those without iscsi(4) support built into the kernel to use
ctl(4) as a test mechanism. As a sidenote, this was possible around the
10.0-RELEASE period, but made impossible for end-users without iscsi(4)
between 10.0-RELEASE and 11.0-RELEASE.

Automatically load cfiscsi(4) from ctladm(8) and ctld(8) for backwards
compatibility with previously releases. The automatic loading feature is
compiled into the beforementioned tools if MK_ISCSI == yes when building
world.

Add a manpage for cfiscsi(4) and refer to it in ctl(4).

Differential Revision: D10099
MFC after: 2 months
Relnotes: yes
Reviewed by: mav, trasz
Sponsored by: Dell EMC Isilon


# 9118b1b0 27-Mar-2017 Enji Cooper <ngie@FreeBSD.org>

ctld: sort #includes per style(9)

- Only include sys/types.h or sys/param.h, not both.
- Sort alphabetically.

MFC after: 3 days
Sponsored by: Dell EMC Isilon


# 51167250 10-Mar-2017 Marcelo Araujo <araujo@FreeBSD.org>

Use nitems() from sys/param.h.

Reviewed by: np
MFC after: 3 weeks.
Differential Revision: https://reviews.freebsd.org/D9945


# 97b84d34 24-Aug-2016 Navdeep Parhar <np@FreeBSD.org>

Make the iSCSI parameter negotiation more flexible.

Decouple the send and receive limits on the amount of data in a single
iSCSI PDU. MaxRecvDataSegmentLength is declarative, not negotiated, and
is direction-specific so there is no reason for both ends to limit
themselves to the same min(initiator, target) value in both directions.

Allow iSCSI drivers to report their send, receive, first burst, and max
burst limits explicitly instead of using hardcoded values or trying to
derive all of them from the receive limit (which was the only limit
reported by the drivers prior to this change).

Display the send and receive limits separately in the userspace iSCSI
utilities.

Reviewed by: jpaetzel@ (earlier version), trasz@
Sponsored by: Chelsio Communications
Differential Revision: https://reviews.freebsd.org/D7279


# 4e5408f1 05-Jun-2016 Edward Tomasz Napierala <trasz@FreeBSD.org>

Report negotiated MaxBurstLength and FirstBurstLength in "iscsictl -v"
and "ctladm islist -v" outputs.

MFC after: 1 month


# 05c3dfee 14-Nov-2015 Edward Tomasz Napierala <trasz@FreeBSD.org>

Add missing error checks.

MFC after: 1 month
Sponsored by: The FreeBSD Foundation


# c2ef20fd 14-Nov-2015 Edward Tomasz Napierala <trasz@FreeBSD.org>

Don't try to avoid calling free(3) with NULL argument.

MFC after: 1 month
Sponsored by: The FreeBSD Foundation


# 398290f2 09-Nov-2015 Alexander Motin <mav@FreeBSD.org>

Introduce portal group options in ctl.conf.

While CTL has concept of port options, used at least for iSCSI ports now,
before this change it was impossible to set them manually. There still
no user-configurable port options now, but I am planning to change that.


# 91be33dc 27-Sep-2015 Alexander Motin <mav@FreeBSD.org>

Add to CTL initial support for CDROMs and removable devices.

Relnotes: yes


# 9c887a4f 26-Sep-2015 Alexander Motin <mav@FreeBSD.org>

Remove some duplicate, legacy, dead and questionable code.


# e543b3a8 21-Sep-2015 Alexander Motin <mav@FreeBSD.org>

Make cltd ignore HA ports.


# 3933f7b1 15-Sep-2015 Alexander Motin <mav@FreeBSD.org>

Add ctl-lun config option for consistency in HA setups.


# 828524c1 13-Sep-2015 Alexander Motin <mav@FreeBSD.org>

When updating port, apply only change of LUN map, not whole.


# a3977bea 06-Sep-2015 Alexander Motin <mav@FreeBSD.org>

Allow LUN options modification via CTL_LUNREQ_MODIFY.

Not all changes take effect, but that is a different question.


# c01a5fa9 04-Sep-2015 Alexander Motin <mav@FreeBSD.org>

Another addition to r287455.


# 2f444d15 15-Aug-2015 Alexander Motin <mav@FreeBSD.org>

Drop "internal" CTL frontend.

Its idea was to be a simple initiator and execute several commands from
kernel level, but FreeBSD never had consumer for that functionality,
while its implementation polluted many unrelated places..


# 0bb4b989 26-Jun-2015 Alexander Motin <mav@FreeBSD.org>

Plug minor memory leak at r284765.

Reported by: Coverity
CID: 1308401
MFC after: 3 days


# d83595b2 24-Jun-2015 Alexander Motin <mav@FreeBSD.org>

Teach ctld about CTL's physical_port and virtual_port fields.

This allows ctld to work with isp(4) virtual ports, specifying them as
isp0/1, isp0/2, etc. There are still problems on isp(4) layer with
disabling those ports after enabling, but hopefully they can be fixed.

MFC after: 3 days
Sponsored by: iXsystems, Inc.


# aadf439b 04-Mar-2015 Alexander Motin <mav@FreeBSD.org>

If target name starts with "naa.", set it as WWNN for CTL port.

MFC after: 1 week
Sponsored by: iXsystems, Inc.


# a9d78210 27-Feb-2015 Edward Tomasz Napierala <trasz@FreeBSD.org>

Move the "offload" clause from the target section to portal-group
section; it makes more sense there.

MFC after: 1 month
Sponsored by: The FreeBSD Foundation


# 16fa2809 25-Feb-2015 Alexander Motin <mav@FreeBSD.org>

Add checks for malloc() failures.

Submitted by: Dmitry Luhtionov <dmitryluhtionov@gmail.com>
MFC after: 3 days


# 057abcb0 07-Feb-2015 Alexander Motin <mav@FreeBSD.org>

Teach ctld(8) to control non-iSCSI CTL ports.

This change introduces new target option "port", that assigns current target
to specified CTL port. On config application ctld(8) will apply LUN mapping
according to target configuration to specified port and bring the port up.
On shutdown cltd(8) will remove the mapping and put the port down.

This change allows to configure both iSCSI and FibreChannel targets in the
same configuration file in alike way.

Kernel side support was added earlier at r278037.

MFC after: 2 weeks
Relnotes: yes
Sponsored by: iXsystems, Inc.


# 07b49a3e 06-Feb-2015 Edward Tomasz Napierala <trasz@FreeBSD.org>

Make it possible to set (via ctl.conf(5)) and query (via ctladm islist -v)
target iSCSI offload. Add mechanism to query maximum receive data segment
size supported by chosen hardware offload module, and use it in ctld(8)
to determine the value to advertise to the other side.

MFC after: 1 month
Sponsored by: The FreeBSD Foundation


# 92847ee1 06-Feb-2015 Alexander Motin <mav@FreeBSD.org>

Add support for multiple portal groups per target.

This change allows multiple "portal-group" options to be specified per
target. Each of them may include new optional auth-group name parameter
to override per-target auth parameters for specific portal group.

Kernel side support was added earlier at r278161.

MFC after: 2 weeks
Sponsored by: iXsystems, Inc.


# 6b31e130 03-Feb-2015 Alexander Motin <mav@FreeBSD.org>

Bring some more order into iSCSI portal group tags support.

While ctld(8) still does not allow multiple portal groups per target
to be configured, kernel should now be able to handle it.

MFC after: 2 weeks
Sponsored by: iXsystems, Inc.


# 920c6cba 01-Feb-2015 Alexander Motin <mav@FreeBSD.org>

CTL LUN mapping rewrite.

Replace iSCSI-specific LUN mapping mechanism with new one, working for any
ports. By default all ports are created without LUN mapping, exposing all
CTL LUNs as before. But, if needed, LUN mapping can be manually set on
per-port basis via ctladm. For its iSCSI ports ctld does it via ioctl(2).
The next step will be to teach ctld to work with FibreChannel ports also.

Respecting additional flexibility of the new mechanism, ctl.conf now allows
alternative syntax for LUN definition. LUNs can now be defined in global
context, and then referenced from targets by unique name, as needed. It
allows same LUN to be exposed several times via multiple targets.

While there, increase limit for LUNs per target in ctld from 256 to 1024.
Some initiators do not support LUNs above 255, but that is not our problem.

Discussed with: trasz
MFC after: 2 weeks
Relnotes: yes
Sponsored by: iXsystems, Inc.


# 2bd28269 22-Oct-2014 Edward Tomasz Napierala <trasz@FreeBSD.org>

Whitespace fixes.

MFC after: 1 month
Sponsored by: The FreeBSD Foundation


# 19720f41 10-Oct-2014 Alexander Motin <mav@FreeBSD.org>

Make ctld start even if some LUNs are unable to open backing storage.

Such LUNs will be visible to initiators, but return "not ready" status
on media access commands. If backing storage become available later,
`ctladm modify ...` or `service ctld reload` can trigger its reopen.


# b7a65e39 21-Aug-2014 Edward Tomasz Napierala <trasz@FreeBSD.org>

Make the iSCSI stack use __FBSDID() properly.

MFC after: 2 weeks
Sponsored by: The FreeBSD Foundation


# a6f6f7a6 17-Jul-2014 Alexander Motin <mav@FreeBSD.org>

Fix ctld crash on startup if target alias is not set.

MFC after: 3 days


# 1380b77c 06-Jul-2014 Alexander Motin <mav@FreeBSD.org>

Close race in r268291 between port destruction, delayed by sessions
teardown, and new port creation during `service ctld restart`.

Close it by returning iSCSI port internal state, that allows to identify
dying ports, which should not be counted as existing, from really alive.


# 6d81c129 05-Jul-2014 Alexander Motin <mav@FreeBSD.org>

Pass through iSCSI session ISID from LOGIN request to the CTL frontend.

ISID is an important part of initiator transport ID for iSCSI. It is not
used now, but should be to properly implement persistent reservation.


# 027e5269 05-Jul-2014 Alexander Motin <mav@FreeBSD.org>

Burry devid port method, which was a gross hack.

Instead make ports provide wanted port and target IDs, and LUNs provide
wanted LUN IDs. After that core Device ID VPD code only had to link all
of them together and add relative port and port group numbers.

LUN ID for iSCSI LUNs no longer created by CTL, but by ctld, and passed
to CTL as "scsiname" LUN option. This makes LUNs to report the same set
of IDs, independently from the port through which it is accessed, as
required by SCSI specifications.


# 917d38fb 05-Jul-2014 Alexander Motin <mav@FreeBSD.org>

Create separate CTL port for every iSCSI target (and maybe portal group).

Having single port for all iSCSI connections makes problematic implementing
some more advanced SCSI functionality in CTL, that require proper ports
enumeration and identification.

This change extends CTL iSCSI API, making ctld daemon to control list of
iSCSI ports in CTL. When new target is defined in config fine, ctld will
create respective port in CTL. When target is removed -- port will be
also removed after all active commands through that port properly aborted.
This change require ctld to be rebuilt to match the kernel.

As a minor side effect, this allows to have iSCSI targets without LUNs.
While that may look odd and not very useful, that is not incorrect.


# 8ea4f2ef 19-Jun-2014 Alexander Motin <mav@FreeBSD.org>

serial_num and device_id fields are not necessarily null-terminated.

Before this it was impossible to use all 16 bytes of serial number, and
client always got serial number NULL-terminated, that is not required.

MFC after: 2 weeks


# 8eab95d6 16-Apr-2014 Edward Tomasz Napierala <trasz@FreeBSD.org>

Properly pass the initiator address when running in proxy mode.

Sponsored by: The FreeBSD Foundation


# 8cab2ed4 16-Apr-2014 Edward Tomasz Napierala <trasz@FreeBSD.org>

Properly identify target portal when running in proxy mode. While here,
remove CTL_ISCSI_CLOSE, it wasn't used or implemented anyway.

Sponsored by: The FreeBSD Foundation


# ba3a2d31 16-Apr-2014 Edward Tomasz Napierala <trasz@FreeBSD.org>

Make it possible for the iSCSI target side to operate in both normal
and ICL_KERNEL_PROXY mode, and fix some bit rot so the latter actually
works again.

Sponsored by: The FreeBSD Foundation


# b881b8be 16-Mar-2014 Robert Watson <rwatson@FreeBSD.org>

Update most userspace consumers of capability.h to use capsicum.h instead.

auditdistd is not updated as I will make the change upstream and then do a
vendor import sometime in the next week or two.

MFC after: 3 weeks


# b3361aab 11-Feb-2014 Edward Tomasz Napierala <trasz@FreeBSD.org>

Improve error reporting.

Sponsored by: The FreeBSD Foundation


# f7ae5bf8 11-Feb-2014 Edward Tomasz Napierala <trasz@FreeBSD.org>

Rename a variable, no functional changes.

Sponsored by: The FreeBSD Foundation


# 1af40365 08-Oct-2013 Edward Tomasz Napierala <trasz@FreeBSD.org>

Fix off-by-one.

Coverity CID: 1011375
Approved by: re (glebius)
Sponsored by: FreeBSD Foundation


# 7843bd03 18-Sep-2013 Edward Tomasz Napierala <trasz@FreeBSD.org>

Fix several problems in the new iSCSI stack; this includes interoperability
fix for LIO (Linux target), removing possibility for the target to avoid mutual
CHAP by choosing to skip authentication altogether, and fixing truncated error
messages in iscsictl(8) output. This also fixes several of the problems found
with Coverity.

Note that this change requires world rebuild.

Coverity CID: 1088038, 1087998, 1087990, 1088004, 1088044, 1088041, 1088040
Approved by: re (blanket)
Sponsored by: FreeBSD Foundation


# c76e8a9a 18-Sep-2013 Edward Tomasz Napierala <trasz@FreeBSD.org>

Make iscsictl(8) automatically try to load the iscsi module. While here,
improve module loading in iscsid(8) and ctld(8).

Approved by: re (delphij)


# 009ea47e 14-Sep-2013 Edward Tomasz Napierala <trasz@FreeBSD.org>

Bring in the new iSCSI target and initiator.

Reviewed by: ken (parts)
Approved by: re (delphij)
Sponsored by: FreeBSD Foundation