Commit graph

675 commits

Author SHA1 Message Date
Alan Somers edbd489d09 ctladm: don't require the use of "-p" with "port -r"
When removing a port, the ioctl frontend requires the "-p" argument.
But other frontends, like cfiscsi, do not.  So don't require that
argument in the ctladm command.  The frontend driver will report an
error if any required argument is missing.

MFC after:	2 weeks
Sponsored by:	Axcient
Reviewed by:    mav
Pull Request:   https://github.com/freebsd/freebsd-src/pull/1279
2024-06-10 10:01:25 -06:00
Alan Somers afecc74cd7 ctladm: better documentation for adding and removing cfiscsi ports
MFC after:	2 weeks
Sponsored by:	Axcient
Reviewed by:    mav
Pull Request:   https://github.com/freebsd/freebsd-src/pull/1279
2024-06-10 10:01:25 -06:00
Gleb Smirnoff 0d37895849 ctl: use socket buffer mutexes in struct socket directly
A mechanical change performed with sed(1) script:

s/SOCKBUF_LOCK\(&so->so_rcv\)/SOCK_RECVBUF_LOCK(so)/
s/SOCKBUF_UNLOCK\(&so->so_rcv\)/SOCK_RECVBUF_UNLOCK(so)/
s/SOCKBUF_MTX\(&so->so_rcv\)/SOCK_RECVBUF_MTX(so)/
s/SOCKBUF_LOCK\(&so->so_snd\)/SOCK_SENDBUF_LOCK(so)/
s/SOCKBUF_UNLOCK\(&so->so_snd\)/SOCK_SENDBUF_UNLOCK(so)/
s/SOCKBUF_MTX\(&so->so_snd\)/SOCK_SENDBUF_MTX(so)/

Reviewed by:		mav
Differential Revision:	https://reviews.freebsd.org/D45190
2024-05-23 12:11:54 -07:00
John Baldwin 1f83483d73 ctl_backend_block: Correct value of NVME nsdata nuse field
Reported by:	Coverity Scan
CID:	 	1545043
Sponsored by:	Chelsio Communications
2024-05-10 09:13:40 -07:00
John Baldwin 25bad5a2da ctl: Add NVMF port type and ioctls
- Add CTL_PORT_NVMF as a new port type.

- Define a new CTL_NVMF ioctl for NVMF-specific operations similar to
  CTL_ISCSI.  This ioctl supports a command to handoff a single
  queue pair, a command to enumerate active associations, and a
  command to disconnect one or more active associations.

Reviewed by:	imp
Sponsored by:	Chelsio Communications
Differential Revision:	https://reviews.freebsd.org/D44724
2024-05-02 16:38:30 -07:00
John Baldwin 374f12c52f ctl_backend_block: Add support for NVMe
Reviewed by:	imp
Sponsored by:	Chelsio Communications
Differential Revision:	https://reviews.freebsd.org/D44723
2024-05-02 16:38:30 -07:00
John Baldwin 40a4359064 ctl_backend_block: Prepare for NVMe support
- Use wrapper routines for access to shared fields between SCSI and
  NVMe I/O requests.

- Use protocol-agnostic wrapper routines for I/O completion status.

Sponsored by:	Chelsio Communications
Differential Revision:	https://reviews.freebsd.org/D44851
2024-05-02 16:38:30 -07:00
John Baldwin d5c21c6883 ctl_backend_ramdisk: Add support for NVMe
One known caveat is that the support for WRITE_UNCORRECTABLE is not
quite correct as reads from LBAs after a WRITE_UNCORRECTABLE will
return zeroes rather than an error.  Fixing this would likely require
special handling for PG_ANCHOR for NVMe requests (or adding a new
PG_UNCORRECTABLE).

Reviewed by:	ken, imp
Sponsored by:	Chelsio Communications
Differential Revision:	https://reviews.freebsd.org/D44722
2024-05-02 16:38:30 -07:00
John Baldwin ccaaee4607 ctl_backend_ramdisk: Prepare for NVMe support
- Use wrapper routines for access to shared fields between SCSI and
  NVMe I/O requests.

- Use protocol-agnostic wrapper routines for I/O completion status.

Sponsored by:	Chelsio Communications
Differential Revision:	https://reviews.freebsd.org/D44849
2024-05-02 16:38:30 -07:00
John Baldwin bef5da8ebf ctl: Add helper routines to populate NVMe namespace data IDs for a LUN
These will be used by the backends to populate the unique ID fields
like EUI64 in the NVMe namespace data (CNS == 0) and namespace
identification descriptor list (CNS == 3).

Reviewed by:	imp
Sponsored by:	Chelsio Communications
Differential Revision:	https://reviews.freebsd.org/D44721
2024-05-02 16:38:19 -07:00
John Baldwin 0c4ee619df ctl: Support for NVMe commands
- Add support for queueing and executing NVMe admin and NVM commands
  via ctl_run and ctl_queue.  This requires fixing a few places that
  were SCSI-specific to add NVME logic.

- NVMe has much simpler command ordering requirements than SCSI.  In
  particular, the HBA is not required to enforce any specific ordering
  for requests with overlapping LBAs.  The host is required to manage
  that ordering.  However, fused commands (currently only COMPARE and
  WRITE NVM commands can be fused) are required to be executed
  atomically.

  To support fused commands, make the second half of a fused command
  block on the first half, and have commands submitted after a fused
  command pair block on the second half.

- Add handlers and command tables for admin and NVM commands that
  operate on individual namespaces and will be passed down from an
  NVMe over Fabrics controller to a CTL LUN.

Reviewed by:	ken, imp
Sponsored by:	Chelsio Communications
Differential Revision:	https://reviews.freebsd.org/D44720
2024-05-02 16:32:09 -07:00
John Baldwin 105333f1d6 ctl: Add assertions in SCSI-only paths
Assert that only SCSI I/O requests are passed in various places
that assume a SCSI I/O request (that is, places that access fields
in io->scsiio directly).

Sponsored by:	Chelsio Communications
Differential Revision:	https://reviews.freebsd.org/D44847
2024-05-02 16:31:59 -07:00
John Baldwin ab4b83874a ctl: Update some core data paths to be protocol agnostic
- Add wrapper routines for invoking the be_move_done and io_continue
  callbacks in SCSI and NVMe I/O requests.

- Use wrapper routines for access to shared fields between SCSI and
  NVMe I/O requests.

- ctl_config_write_done is not fully updated since it resubmits SCSI
  commands via ctl_scsiio.  This will be completed in a subsequent
  commit when ctl_nvmeio is added.

Sponsored by:	Chelsio Communications
Differential Revision:	https://reviews.freebsd.org/D44846
2024-05-02 16:31:44 -07:00
John Baldwin 6f308bcf57 ctl: Support NVMe requests in debug trace functions
Reviewed by:	imp
Sponsored by:	Chelsio Communications
Differential Revision:	https://reviews.freebsd.org/D44719
2024-05-02 16:31:34 -07:00
John Baldwin 75577946b5 ctl: Add helper routines for setting NVMe completion status
Also includes a few protocol-agnostic wrappers for setting a generic
status (such as success) for a CTL I/O request whether it be SCSI or
NVMe.

Reviewed by:	imp
Sponsored by:	Chelsio Communications
Differential Revision:	https://reviews.freebsd.org/D44718
2024-05-02 16:31:20 -07:00
John Baldwin 59657816b9 ctl: Add structure and related constants for NVMe commands
This includes static inline functions to serve as getters/setters for
fields shared between SCSI and NVMe I/O requests to manage data
buffers.

Reviewed by:	ken, imp
Sponsored by:	Chelsio Communications
Differential Revision:	https://reviews.freebsd.org/D44717
2024-05-02 16:31:11 -07:00
John Baldwin ac7a514e20 ctl: Add CTL_IO_ASSERT wrapper macro
Currently, this pattern is commonly used to assert that a union ctl_io
is a SCSI request.  In the future it will be used to assert other
types.

Suggested by:	imp
Reviewed by:	imp
Sponsored by:	Chelsio Communications
Differential Revision:	https://reviews.freebsd.org/D44844
2024-05-02 16:30:44 -07:00
John Baldwin 352cf4a64a ctl: Avoid an upcast for calling ctl_scsi_path_string
Change the first argument of ctl_scsi_path_string to be the embedded
header structure instead of the union.  Currently union ctl_io and
struct ctl_scsiio have the same alignment, but this changes on i386 if
a new union member is added that contains a uint64_t member (such as
an embedded struct nvme_command for NVMeoF).  In that case, union
ctl_io requires stronger alignment, so the upcast from struct
ctl_scsiio to union ctl_io in ctl_scsi_sense_sbuf raises an increasing
alignment warning on i386.

Avoid the warning by passing struct ctl_io_hdr as the first argument
to ctl_scsi_path_string instead.

Reviewed by:	imp
Sponsored by:	Chelsio Communications
Differential Revision:	https://reviews.freebsd.org/D44716
2024-05-02 16:30:20 -07:00
HP van Braam 86fbb05da1 ctl: Fix CTL GET EVENT STATUS NOTIFICATION valid bits
Linux as an initiator periodically sends the following to SCSI cdrom
devices: 4a 01 00 00 10 00 00 00 08 00

According to the ctl_cmd_entry for this command this is invalid which
leads to a lot of failed SCSI commands.

The mask in this commit is based off of an early draft of the mmc
standard, https://www.t10.org/ftp/t10/document.97/97-108r0.pdf,
as well as subsequent standards (mmc2 through mmc6).

This solves the issue with Linux initiators.

Signed-off-by: HP van Braam <hp@tmm.cx>
Reviewed by: imp, mav
Pull Request: https://github.com/freebsd/freebsd-src/pull/1201
2024-04-29 08:37:30 -06:00
HP van Braam f0e59ecff8 CTL: READ(6) should be allowed on CD devices
DOS ASPI drivers use this, with this change applied it is possible to
load a DOS ASPI CDROM driver and run the Windows 98 installer.

Signed-off-by: HP van Braam <hp@tmm.cx>
Reviewed by: imp
Pull Request: https://github.com/freebsd/freebsd-src/pull/1202
2024-04-25 20:31:14 -06:00
Alexander Motin 7c667affb7 CTL: Drop Format Device and Rigid Disk Geometry mode pages
Those mode pages are obsolete since SBC-2 specification almost 20
years ago.  First I was trying to understand possible relations
between physical block and physical sector terms in different specs.
Then was thinking about possible relations to device CHS geometry
and compatibility issues.  Finally I just decided that none of it
worth the efforts and should rest in piece.

PR:	276524
2024-02-27 13:28:44 -05:00
John Baldwin 105eee97b0 ctl: Add missing comma after CTL_FLAG_ALREADY_DONE
Sponsored by:	Chelsio Communications
Differential Revision:	https://reviews.freebsd.org/D42930
2023-12-27 10:09:52 -08:00
John Baldwin dfbb6f2e59 ctl_frontend.h: Note that ctl_port.frontend is set by the FETD
Sponsored by:	Chelsio Communications
Differential Revision:	https://reviews.freebsd.org/D42931
2023-12-27 10:09:40 -08:00
John Baldwin e03e77ba4d ctl: Always return errno values from ctl_port_register
Return EBUSY instead of a bare 1 if a port number is already active.

Sponsored by:	Chelsio Communications
Differential Revision:	https://reviews.freebsd.org/D42929
2023-12-27 10:09:24 -08:00
Gleb Smirnoff cfb1e92912 sockets: don't malloc/free sockaddr memory on accept(2)
Let the accept functions provide stack memory for protocols to fill it in.
Generic code should provide sockaddr_storage, specialized code may provide
smaller structure.

While rewriting accept(2) make 'addrlen' a true in/out parameter, reporting
required length in case if provided length was insufficient.  Our manual
page accept(2) and POSIX don't explicitly require that, but one can read
the text as they do.  Linux also does that. Update tests accordingly.

Reviewed by:		rscheff, tuexen, zlei, dchagin
Differential Revision:	https://reviews.freebsd.org/D42635
2023-11-30 08:30:55 -08:00
Mitchell Horne 9d61fd0849 ctl_ha: don't shutdown threads if scheduler is stopped
In this case, just return.

Reviewed by:	markj
MFC after:	1 week
Sponsored by:	The FreeBSD Foundation
Differential Revision:	https://reviews.freebsd.org/D42341
2023-11-23 12:07:42 -04:00
Alexander Motin 519b24f029 CAM: Replace random sbuf_printf() with cheaper cat/putc. 2023-11-22 18:04:05 -05:00
Warner Losh 2ffd30f7ee cam: Remove left-over sys/cdefs.h in sys/cam
These weren't removed when $FreeBSD$ was removed. They aren't needed and
now are a style(9) nonconformity.

Sponsored by:		Netflix
2023-11-06 12:20:23 -07:00
John Baldwin e846a3e016 ctl: Use ctl_io_sbuf in ctl_process_done
This reduces a second copy of (mostly) the same code.

Reviewed by:	ken, imp
Sponsored by:	Chelsio Communications
Differential Revision:	https://reviews.freebsd.org/D42210
2023-10-16 15:47:09 -07:00
John Baldwin fc8cf0a8de ctl: Make ctl_private.h more self-contained
Include <sys/sysctl.h> for sysctl context types.

Reviewed by:	ken, imp
Sponsored by:	Chelsio Communications
Differential Revision:	https://reviews.freebsd.org/D42209
2023-10-16 15:46:43 -07:00
John Baldwin 10b1a66934 ctl: Make ctl_ha.h more self-contained
Include <sys/queue.h> for queue macros

Reviewed by:	ken, imp
Sponsored by:	Chelsio Communications
Differential Revision:	https://reviews.freebsd.org/D42208
2023-10-16 15:46:11 -07:00
John Baldwin 4efebb3de3 ctl: Make ctl_io.h more self-contained
Include <cam/scsi/scsi_all.h> for struct scsi_sense_data.
Include <sys/queue.h> for queue macros.

Reviewed by:	ken, imp
Sponsored by:	Chelsio Communications
Differential Revision:	https://reviews.freebsd.org/D42207
2023-10-16 15:45:43 -07:00
John Baldwin 55231cd180 ctl: Make ctl.h more self-contained
Make MALLOC_DECLARE conditional on <sys/malloc.h> and forward declare
several types.

Reviewed by:	ken, imp
Sponsored by:	Chelsio Communications
Differential Revision:	https://reviews.freebsd.org/D42206
2023-10-16 15:45:15 -07:00
Warner Losh 685dc743dc sys: Remove $FreeBSD$: one-line .c pattern
Remove /^[\s*]*__FBSDID\("\$FreeBSD\$"\);?\s*\n/
2023-08-16 11:54:36 -06:00
Warner Losh 71625ec9ad sys: Remove $FreeBSD$: one-line .c comment pattern
Remove /^/[*/]\s*\$FreeBSD\$.*\n/
2023-08-16 11:54:24 -06:00
Warner Losh 2ff63af9b8 sys: Remove $FreeBSD$: one-line .h pattern
Remove /^\s*\*+\s*\$FreeBSD\$.*$\n/
2023-08-16 11:54:18 -06:00
Warner Losh 95ee2897e9 sys: Remove $FreeBSD$: two-line .h pattern
Remove /^\s*\*\n \*\s+\$FreeBSD\$$\n/
2023-08-16 11:54:11 -06:00
Warner Losh a74530d9e2 cam/ctl: Migrate to modern uintXX_t from u_intXX_t
As per https://lists.freebsd.org/archives/freebsd-scsi/2023-July/000257.html
move to the modern uintXX_t.

MFC After:	3 days
Sponsored by:	Netflix
2023-07-24 21:32:56 -06:00
Warner Losh 4d846d260e 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
2023-05-12 10:44:03 -06:00
Alexander Motin 7467a69536 CTL: Allow userland supply tags via ioctl frontend.
Before this ioctl frontend always replaced tags with sequential ones.
It was done for ctladm, that can not keep track of global tag list.
But in case of virtio-scsi in bhyve we can pass provided tags as-is.
It should be on virtio-scsi initiator to provide us valid tags.  It
should allow proper task management, error reporting, etc.  In case
of several virtio-scsi devices, they should use different CTL ports
or initiator IDs to avoid conflicts, but this is expected by design.

PR:	267539
2022-12-03 12:05:05 -05:00
Alexander Motin 0acc026dda CTL: Increase maximum SCSI tag size from 32 to 64 bits.
SAM-5 specification states maximum size of command identifier (tag),
defined by specific transports, should not be larger than 64 bits.
While most of supported transports use 32 bits or less, it was
reported that virtio-scsi uses 64 bits.  Truncation to 32 bits in
bhyve code caused false tag conflict errors reported and possibly
other issues.

This changes CTL ABI and HA protocol, so CTL_HA_VERSION is bumped.

While we make HA protocol incompatible, increase default maximum
number of ports in CTL from 256 to 1024, matching number of LUNs.
There are many reports from people who need many iSCSI targets with
only one LUN each.  Increased memory consumption should be less of
a problem these days.

PR:	267539
2022-12-03 10:23:29 -05:00
Alexander Motin 0586be48a9 CTL: Validate IOCTL parameters.
It was possible to cause kernel panic by passing too large args_len
or non-NULL result_nvl.

Though since the /dev/cam/ctl device is accessible only by root and
used only by limited number of tools it was not a big problem.

PR:	266115
PR:	266136
Reported by:	Robert Morris <rtm@lcs.mit.edu>
MFC after:	1 week
2022-09-06 21:58:27 -04:00
Alexander Motin 3b0e3e8d2a CTL: Fix double command completions on HA failover.
I've found couple cases when CTL_FLAG_SENT_2OTHER_SC flags were not
cleared on commands return from active node or the send failure.  It
created races when ctl_failover_lun() call before ctl_process_done()
could cause second ctl_done() and ctl_process_done() calls, causing
all sorts of problems.

MFC after:	2 weeks
Sponsored by:	iXsystems, Inc.
2022-06-14 00:24:39 -04:00
John Baldwin 7b02c1e8c6 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
2022-04-18 12:53:28 -07:00
Mateusz Guzik bb92cd7bcd vfs: NDFREE(&nd, NDF_ONLY_PNBUF) -> NDFREE_PNBUF(&nd) 2022-03-24 10:20:51 +00:00
Alexander Motin f00ced06da CTL: Rework 05c3e8e871 using %zu format.
MFC after:	2 days
2022-02-25 11:53:53 -05:00
Alexander Motin 05c3e8e871 Fix 32-bit build after 530d274c15.
MFC after:	3 days
2022-02-24 18:11:36 -05:00
Alexander Motin 530d274c15 CTL: Add length validation for incoming HA messages.
This should fix uninitialized memory reads when working with broken
HA peer, like one fixed in 1a8d8a3a90.  Instead print error message
and kill the HA link.

MFC after:	3 days
Sponsored by:	iXsystems, Inc.
2022-02-24 16:24:43 -05:00
John Baldwin bd6e8729d6 ctl ramdisk: Free compare buffer after a compare I/O request.
For a compare request, the ramdisk backend allocates a temporary
buffer to hold the I/O data and then compares it against the LUN's
pages in ctl_backend_ramdisk_cmp after the data has been filled.
However, the tempory buffer was leaked when after the comparison was
complete.  Fix this by freeing the buffer after the comparison.

Reviewed by:	mav
Sponsored by:	Chelsio Communications
Differential Revision:	https://reviews.freebsd.org/D34316
2022-02-18 15:20:14 -08:00
John Baldwin a3d71fffa7 cfiscsi_done: Free the dummy PDU earlier.
The dummy PDU needs to be freed before marking task abortion complete
as otherwise cfiscsi_session_terminate_tasks can return and destroy
the session in another thread before the PDU is freed.

Fixes:		2e8d1a5525 iscsi: Allocate a dummy PDU for the internal nexus reset task.
Sponsored by:	Chelsio Communications
Differential Revision:	https://reviews.freebsd.org/D34176
2022-02-07 12:55:08 -08:00