Commit Graph

102 Commits

Author SHA1 Message Date
John Baldwin
7aab9c14a4 iscsi: Handle unmapped I/O requests.
Don't assume that csio->data_ptr is pointer to a data buffer that can
be passed to icl_get_pdu_data and icl_append_data.  For unmapped I/O
requests, csio->data_ptr is instead a pointer to a struct bio as
indicated by CAM_DATA_BIO.  To support these requests, add
icl_pdu_append_bio and icl_pdu_get_bio methods which pass a pointer to
the bio and an offset and length relative to the bio's buffer.

Note that only backends supporting unmapped requests need to implement
these hooks.

Implement simple no-op hooks for the iser backend.

Reviewed by:	mav
Sponsored by:	Chelsio Communications
Differential Revision:	https://reviews.freebsd.org/D34382
2022-03-10 15:49:53 -08:00
John Baldwin
9c7a4875bc iscsi: Use ICL_NOCOPY for SCSI command immediate data and R2T.
The associated csio ccb will not be completed via xpt_done() until
after the associated PDUs are transmitted to the other side and either
the original PDU is acked with a SCSI response, or a response is
received for a subsequent abort CCB (which means the earlier PDU has
also been sent since it would have been sent before the abort PDU).

This does assume that once an I/O request has been aborted, no further
PDUs with data payload are queued for that I/O request.

Sponsored by:	Chelsio Communications
Differential Revision:	https://reviews.freebsd.org/D34405
2022-03-10 15:48:20 -08:00
Richard Scheffenegger
bd6bb49397 iscsi: per-session timeouts and rapid teardown of session on reconnect
Add per-Session configurable ping (SCSI NOP) and login timeouts.

Remove the torn down, old iSCSI session quickly, when performing a reconnect.

Reviewed By: trasz
Sponsored by:        NetApp, Inc.
Differential Revision: https://reviews.freebsd.org/D34198
2022-02-25 10:35:47 +01:00
Richard Scheffenegger
972a7d95eb iscsi: Use calloutng instead of ticks in iscsi initiator
callout *_sbt functions are used to reduce ping/timeout scheduling
overhead, while allowing later improvments in the functionality.
Keep similar 1000ms callouts while adding a 10 ms window, to allow
some kernel scheduling improvements.

Reviewed By: jhb
Sponsored by:        NetApp, Inc.
Differential Revision: https://reviews.freebsd.org/D34222
2022-02-15 17:36:22 +01:00
Ka Ho Ng
fa66950534 iscsi: Fix missing is_lock unlock after cam_simq_alloc() failed
Sponsored by:	The FreeBSD Foundation
MFC after:	3 days
2022-01-21 16:34:18 -05:00
John Baldwin
cdbc4a074b Further refine the ExpDataSN checks for SCSI Response PDUs.
According to 11.4.8 in RFC 7143, ExpDataSN MUST be 0 if the response
code is not Command Completed, but we were requiring it to always be
the count of DataIn PDUs regardless of the response code.

In addition, at least one target (OCI Oracle iSCSI block device)
returns an ExpDataSN of 0 when returning a valid completion with an
error status (Check Condition) in response to a SCSI Inquiry.  As a
workaround for this target, only warn without resetting the connection
for a 0 ExpDataSN for responses with a non-zero error status.

PR:		259152
Reported by:	dch
Reviewed by:	dch, mav, emaste
Fixes:		4f0f5bf995 iscsi: Validate DataSN values in Data-In PDUs in the initiator.
Sponsored by:	Chelsio Communications
Differential Revision:	https://reviews.freebsd.org/D32650
2021-10-26 14:50:05 -07:00
John Baldwin
4f0f5bf995 iscsi: Validate DataSN values in Data-In PDUs in the initiator.
As is done in the target, require that DataSN values are consecutive
and in-order.  If an out of order Data-In PDU is received, force a
session reconnect.  In addition, when a SCSI Response PDU is received,
verify that the ExpDataSN field matches the count of Data-In PDUs
received for this command.  If not, force a session reconnect.

Reviewed by:	mav
Sponsored by:	Chelsio Communications
Differential Revision:	https://reviews.freebsd.org/D31594
2021-08-24 14:58:34 -07:00
John Baldwin
f0594f52f6 iSCSI: Add support for segmentation offload for hardware offloads.
Similar to TSO, iSCSI segmentation offload permits the upper layers to
submit a "large" virtual PDU which is split up into multiple segments
(PDUs) on the wire.  Similar to how the TCP/IP headers are used as
templates for TSO, the BHS at the start of a large PDU is used as a
template to construct the specific BHS at the start of each PDU.  In
particular, the DataSN is incremented for each subsequent PDU, and the
'F' flag is only set on the last PDU.

struct icl_conn has a new 'ic_hw_isomax' field which defaults to 0,
but can be set to the largest virtual PDU a backend supports.  If this
value is non-zero, the iSCSI target and initiator use this size
instead of 'ic_max_send_data_segment_length' to determine the maximum
size for SCSI Data-In and SCSI Data-Out PDUs.  Note that since PDUs
can be constructed from multiple buffers before being dispatched, the
target and initiator must wait for the PDU to be fully constructed
before determining the number of DataSN values were consumed (and thus
updating the per-transfer DataSN value used for the start of the next
PDU).

The target generates large PDUs for SCSI Data-In PDUs in
cfiscsi_datamove_in().  The initiator generates large PDUs for SCSI
Data-Out PDUs generated in response to an R2T.

Reviewed by:	mav
Sponsored by:	Chelsio Communications
Differential Revision:	https://reviews.freebsd.org/D31222
2021-08-06 14:03:00 -07:00
Warner Losh
30f8afd027 cam: fix xpt_bus_register and xpt_bus_deregister return errno
xpt_bus_register and xpt_bus_deregister returns a hybrid error that's
neither a cam_status, nor an errno, but a mix of both.  Update
xpt_bus_register and xpt_bus_deregister to return an errno. The vast
majority of current users compare against zero, which can also be
spelled CAM_SUCCESS. Nobody uses CAM_FAILURE, so remove that symbol
to prevent comfusion (nothing returns it either).

Where the return value is saved, ensure that the variable 'error' is
used to store an errno and 'status' is used to store a cam_status where
it makes the code clearer (usually just in functions that already mix
and match). Where the return value isn't used at all, avoid storing it
at all.

Reviewed by:		scottl@, mav@ (earlier version)
Sponsored by:		Netflix
Differential Revision:	https://reviews.freebsd.org/D30860
2021-06-28 16:13:03 -06:00
John Baldwin
0cc7d64a2a iscsi: Move the maximum data segment limits into 'struct icl_conn'.
This fixes a few bugs in iSCSI backends where the backends were using
the limits they advertised initially during the login phase as the
final values instead of the values negotiated with the other end.

Reported by:	Jithesh Arakkan @ Chelsio
Reviewed by:	mav
Differential Revision:	https://reviews.freebsd.org/D30271
2021-05-20 09:59:11 -07:00
John Baldwin
89df484739 iscsi: Kick threads out of iscsi_ioctl() during unload.
iscsid can be sleeping in iscsi_ioctl() causing the destroy_dev() to
sleep forever if iscsi.ko is unloaded while iscsid is running.

Reported by:	Jithesh Arakkan @ Chelsio
Reviewed by:	mav
MFC after:	1 week
Sponsored by:	Chelsio Communications
Differential Revision:	https://reviews.freebsd.org/D29688
2021-04-12 13:58:21 -07:00
John Baldwin
47769bc557 iscsi: Mark iSCSI CAM sims as non-pollable.
Previously, iscsi_poll() just panicked.  This meant if you got a panic
on a box when using the iSCSI initiator, the attempt to shutdown would
trigger a nested panic and never write out a core.  Now, CCB's sent to
iSCSI devices (such as the sychronize-cache request in dashutdown())
just fail with a timeout during a panic shutdown.

Reviewed by:	scottl, mav
MFC after:	2 weeks
Sponsored by:	Chelsio
Differential Revision:	https://reviews.freebsd.org/D28455
2021-02-11 13:52:18 -08:00
Alexander Motin
3dd2a7a5ea Make DataSN counter of solicited Data-Out local.
DataSN for solicited Data-Out is per-R2T.  Since we handle whole R2T
in one go, we don't need to store it anywhere, especially in global
per-command structure.  This may allow us to handle multiple R2T per
command at once, if we decide, or may be relax locking.

Rename the second use of that field to io_referenced_task_tag.

MFC after:	1 month
2021-02-02 13:56:47 -05:00
Alexander Motin
9bee9a98ff Exclude reserved iSCSI Initiator Task Tag.
RFC 7143 (11.2.1.8):
   An ITT value of 0xffffffff is reserved and MUST NOT be assigned for a
   task by the initiator.  The only instance in which it may be seen on
   the wire is in a target-initiated NOP-In PDU (Section 11.19) and in
   the initiator response to that PDU, if necessary.

MFC after:	1 month
2021-01-24 14:23:04 -05:00
Konstantin Belousov
cd85379104 Make MAXPHYS tunable. Bump MAXPHYS to 1M.
Replace MAXPHYS by runtime variable maxphys. It is initialized from
MAXPHYS by default, but can be also adjusted with the tunable kern.maxphys.

Make b_pages[] array in struct buf flexible.  Size b_pages[] for buffer
cache buffers exactly to atop(maxbcachebuf) (currently it is sized to
atop(MAXPHYS)), and b_pages[] for pbufs is sized to atop(maxphys) + 1.
The +1 for pbufs allow several pbuf consumers, among them vmapbuf(),
to use unaligned buffers still sized to maxphys, esp. when such
buffers come from userspace (*).  Overall, we save significant amount
of otherwise wasted memory in b_pages[] for buffer cache buffers,
while bumping MAXPHYS to desired high value.

Eliminate all direct uses of the MAXPHYS constant in kernel and driver
sources, except a place which initialize maxphys.  Some random (and
arguably weird) uses of MAXPHYS, e.g. in linuxolator, are converted
straight.  Some drivers, which use MAXPHYS to size embeded structures,
get private MAXPHYS-like constant; their convertion is out of scope
for this work.

Changes to cam/, dev/ahci, dev/ata, dev/mpr, dev/mpt, dev/mvs,
dev/siis, where either submitted by, or based on changes by mav.

Suggested by: mav (*)
Reviewed by:	imp, mav, imp, mckusick, scottl (intermediate versions)
Tested by:	pho
Sponsored by:	The FreeBSD Foundation
Differential revision:	https://reviews.freebsd.org/D27225
2020-11-28 12:12:51 +00:00
Edward Tomasz Napierala
bce7ee9d41 Drop "All rights reserved" from all my stuff. This includes
Foundation copyrights, approved by emaste@.  It does not include
files which carry other people's copyrights; if you're one
of those people, feel free to make similar change.

Reviewed by:	emaste, imp, gbe (manpages)
Differential Revision:	https://reviews.freebsd.org/D26980
2020-10-28 13:46:11 +00:00
Alexander Motin
8836496815 Introduce support of SCSI Command Priority.
SAM-3 specification introduced concept of Task Priority, that was renamed
to Command Priority in SAM-4, and supported by all modern SCSI transports.
It provides 15 levels of relative priorities: 1 - highest, 15 - lowest and
0 - default.  SAT specification for SATA devices translates priorities 1-3
into NCQ high priority.

This change adds new "priority" field into empty spots of struct ccb_scsiio
and struct ccb_accept_tio of CAM and struct ctl_scsiio of CTL.  Respective
support is added into iscsi(4), isp(4), mpr(4), mps(4) and ocs_fc(4) drivers
for both initiator and where applicable target roles.  Minimal support was
added to CTL to receive the priority value from different frontends, pass it
between HA controllers and report in few places.

This patch does not add consumers of this functionality, so nothing should
really change yet, since the field is still set to 0 (default) on initiator
and not actively used on target.  Those are to be implemented separately.

I've confirmed priority working on WD Red SATA disks connected via mpr(4)
and properly transferred to CTL target via iscsi(4), isp(4) and ocs_fc(4).

While there, added missing tag_action support to ocs_fc(4) initiator role.

MFC after:	1 month
Relnotes:	yes
Sponsored by:	iXsystems, Inc.
2020-10-25 19:34:02 +00:00
Alexander Motin
7dbbd1aeae Negotiate iSCSIProtocolLevel of 2 (RFC 7144) in initiator.
It does not change anything immediately, but allows further support of
Command Priority, Status Qualifier and new task management functions.

MFC after:	1 month
Sponsored by:	iXsystems, Inc.
2020-10-22 20:26:27 +00:00
Edward Tomasz Napierala
186bcdaac7 If the SIM freezes the queue at exactly the wrong moment, after
another thread has started to send in a CCB and already checked
the queue wasn't frozen, we would end up with iscsi_action()
being called despite the queue is now frozen.

Add a check to make sure this doesn't happen . Perhaps this should
be fixed at the CAM level instead, but given how the send queue and
SIM are governed by two separate mutexes, it is somewhat hard to do.

Reviewed by:	imp, mav
MFC after:	2 weeks
Sponsored by:	NetApp, Inc.
Sponsored by:	Klara, Inc.
Differential Revision:	https://reviews.freebsd.org/D26750
2020-10-18 16:30:49 +00:00
Mateusz Guzik
2140d5b64f iscsi: clean up empty lines in .c and .h files 2020-09-01 21:30:22 +00:00
Pawel Biernacki
e0d69c5a88 Mark more nodes as CTLFLAG_MPSAFE or CTLFLAG_NEEDGIANT (1 of many)
r357614 added CTLFLAG_NEEDGIANT to make it easier to find nodes that are
still not MPSAFE (or already are but aren’t properly marked). Use it in
preparation for a general review of all nodes.
This is non-functional change that adds annotations to SYSCTL_NODE and
SYSCTL_PROC nodes using one of the soon-to-be-required flags.

Reviewed by:	kib, trasz
Approved by:	kib (mentor)
Differential Revision:	https://reviews.freebsd.org/D23640
2020-02-15 18:48:38 +00:00
Mateusz Guzik
879e0604ee Add KERNEL_PANICKED macro for use in place of direct panicstr tests 2020-01-12 06:07:54 +00:00
Edward Tomasz Napierala
6960c4e135 Fix typo in a warning message.
MFC after:	2 weeks
2018-03-14 18:27:06 +00:00
Edward Tomasz Napierala
8ff2372a2c Check for duplicates when modifying an iSCSI session. Previously we did
this check on open, but "iscsictl -M", or an iSCSI redirect received by
iscsid(8) could end up with two sessions with the same target name and
portal.

MFC after:	2 weeks
2018-03-10 14:21:37 +00:00
Pedro F. Giffuni
718cf2ccb9 sys/dev: further 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.
2017-11-27 14:52:40 +00:00
Hans Petter Selasky
9ac7c5a64c Make sure the iSCSI I/O limits are set properly so that the ISCSIDSEND IOCTL
can be used prior to the ISCSIDHANDOFF IOCTL which set the negotiated values.
Else the login PDU will fail when passing the "-r" option to "iscsictl" which
means iSCSI over RDMA instead of TCP/IP.

Discussed with:	np@ and trasz@
Sponsored by:	Mellanox Technologies
MFC after:	1 week
2017-11-23 13:57:44 +00:00
Andriy Gapon
e54fb4ff8c iscsi_shutdown_post: do nothing if panic-ing
There is nothing that that routine should or could really do in that
context.

Reported by:	Ben RUBSON <ben.rubson@gmail.com>
MFC after:	1 week
2017-10-24 14:59:31 +00:00
Andriy Gapon
ad10496cf4 never retry oustanding requests when terminating iscsi session
CAM_REQ_ABORTED sounds natural for aborting outstanding requests when
tearing down a session, but that status actually causes eligible
requests to be tried again.  That's completely useless, so let's use
CAM_DEV_NOT_THERE instead.  Perhaps there is a better status, but this
should be good enough.  The change should affect only the session
termination.

Tested by:	Ben RUBSON <ben.rubson@gmail.com>
Reviewed by:	mav, trasz
MFC after:	2 weeks
Differential Revision: https://reviews.freebsd.org/D12653
2017-10-17 16:03:59 +00:00
Andriy Gapon
20e9cab5fa iscsi: do not hold the global lock while tearing down a session
It should be sufficient to hold the lock just for removing the session
from the session list.  Everything else should be covered by the session
specific lock.

On top of that, at present we can get a deadlock caused by waiting on
the CAM SIM reference count while holding the global lock.  A specific
scenario involving ZFS is this:
- concurrent termination of two sessions, S1 and S2
- session S1 completed all I/Os and sleeps in CAM waiting for device
  close by ZFS;
- session S2 is also dead now, but can not forcefully complete
  outstanding requests by calling iscsi_session_cleanup() from
  iscsi_maintenance_thread_terminate(), since it can't get the same
  global sc_lock;
- as soon as there are unfinished requests, ZFS can not do
  spa_config_enter() as writer, and so can not close the device for
  session S1;
- deadlock.

Reported by:	Ben RUBSON <ben.rubson@gmail.com>
Tested by:	Ben RUBSON <ben.rubson@gmail.com>
Reviewed by:	mav, trasz
MFC after:	2 weeks
Differential Revision: https://reviews.freebsd.org/D12652
2017-10-17 15:39:38 +00:00
Alexander Motin
4c9ea0ced9 Freeze CAM SIM when request is postponed due to MaxCmdSN.
This allows to avoid resource allocation (especially offload) for requests
that can not be executed at this time any way.

MFC after:	2 weeks
2017-02-17 04:34:17 +00:00
Alexander Motin
5b338bc073 Fix tight loop spinning on postponed requests.
MFC after:	2 weeks
2017-02-17 04:29:23 +00:00
Navdeep Parhar
48214203c4 Fix send/recv limit mixup. 2016-09-05 23:12:24 +00:00
Navdeep Parhar
97b84d344d 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
2016-08-25 05:22:53 +00:00
Edward Tomasz Napierala
4e5408f10c Report negotiated MaxBurstLength and FirstBurstLength in "iscsictl -v"
and "ctladm islist -v" outputs.

MFC after:	1 month
2016-06-05 08:48:37 +00:00
Edward Tomasz Napierala
ba165a31b3 Add "iscsictl -e". Among other things, it makes it possible to perform
discovery without attaching to the targets ("iscsictl -Ad ... -e off"),
and then attach to selected ones ("iscsictl -Mi ... -e on").

PR:		204129
MFC after:	1 month
Relnotes:	yes
Sponsored by:	The FreeBSD Foundation
Differential Revision:	https://reviews.freebsd.org/D6633
2016-05-31 11:32:07 +00:00
Edward Tomasz Napierala
bcec64bc61 Add a special case for iSER data tranfers.
Obtained from:	Mellanox Technologies
MFC after:	1 month
Sponsored by:	The FreeBSD Foundation
2016-05-26 12:43:15 +00:00
Edward Tomasz Napierala
b891159418 Add mechanism for choosing iSER-capable ICL modules.
MFC after:	1 month
Sponsored by:	The FreeBSD Foundation
2016-05-24 08:44:45 +00:00
Edward Tomasz Napierala
a3fd63f223 Properly reset session state when using proxy and fail_on_disconnection=1.
Without it the reconnection would fail due to mismatched sequence numbers.

MFC after:	1 month
Sponsored by:	The FreeBSD Foundation
2016-05-21 11:26:03 +00:00
Edward Tomasz Napierala
7deb68ab2c Provide a way for ICL modules to declare they support PIM_UNMAPPED.
MFC after:	1 month
Sponsored by:	The FreeBSD Foundation
2016-05-21 11:10:48 +00:00
Edward Tomasz Napierala
b218ca6fdd Pass maxtags value to the ICL module. iSER needs it.
MFC after:	1 month
Sponsored by:	The FreeBSD Foundation
2016-05-21 10:59:36 +00:00
Edward Tomasz Napierala
906a424b26 Call the ICL module's handoff method even when using ICL proxy.
The upcoming iSER code uses this.

MFC after:	1 month
Sponsored by:	The FreeBSD Foundation
2016-05-20 17:38:51 +00:00
Edward Tomasz Napierala
d66a906bc2 Make ICL proxy use kernel code for handling iSCSI sequence numbers
for PDUs to/from iscsid(8).  This fixes StatSN for Logout PDUs sent
by iscsi_session_logout().

MFC after:	1 month
Sponsored by:	The FreeBSD Foundation
2016-05-19 14:57:37 +00:00
Edward Tomasz Napierala
2f0586b2ce Make it possible to interrupt proxy-mode iscsid receive.
MFC after:	1 month
Sponsored by:	The FreeBSD Foundation
2016-05-19 14:37:24 +00:00
Edward Tomasz Napierala
0fbbc37da3 Make iscsi_ioctl_daemon_send() actually work by adding missing locking.
MFC after:	1 month
Sponsored by:	The FreeBSD Foundation
2016-05-17 11:59:38 +00:00
Edward Tomasz Napierala
f41492b00f Add icl_conn_connect() ICL method, required for iSER.
Obtained from:	Mellanox Technologies (earlier version)
MFC after:	1 month
Sponsored by:	The FreeBSD Foundation
2016-05-17 11:10:44 +00:00
Edward Tomasz Napierala
604c023f94 Extend the ICL interface to include the PDU pointer in the task_setup
method.  This is required for upcoming iSER support.

Obtained from:	Mellanox Technologies (earlier version)
MFC after:	1 month
Sponsored by:	The FreeBSD Foundation
2016-05-17 08:55:21 +00:00
Edward Tomasz Napierala
938bcb04fc Fix iSCSI initiator crash that could happen with out-of-memory
conditions with in-flight IO and subsequent reconnection.

PR:		199117
MFC after:	1 month
Sponsored by:	The FreeBSD Foundation
Differential Revision:	https://reviews.freebsd.org/D5673
2016-03-25 16:01:40 +00:00
Edward Tomasz Napierala
e204e2cd93 Add lock assertion.
MFC after:	1 month
Sponsored by:	The FreeBSD Foundation
2016-03-18 13:26:16 +00:00
Steven Hartland
481b36c66a Close iSCSI sessions on shutdown
Ensure that all iSCSI sessions are correctly terminated during shutdown.

* Enhances the changes done by r286226 (D3052).
* Add shutdown post sync event to run after filesystem shutdown
  (SHUTDOWN_PRI_FIRST) but before CAM shutdown (SHUTDOWN_PRI_DEFAULT).
* Changes iscsi_maintenance_thread to processes terminate in preference to
  reconnect.

Reviewed by:	trasz
MFC after:	2 weeks
Sponsored by:	Multiplay
Differential Revision:	https://reviews.freebsd.org/D4429
2016-01-11 10:24:30 +00:00
Navdeep Parhar
1e86840331 MFP r291227, r291228, and r292618.
r291227:
s/is->is_conn/ic to shorten things a bit.

r291228:
Do not generate PDUs with payload greater than max_data_segment_length.

It is perhaps preferable to have a separate limit for send instead of
reusing the receive limit.  I'll discuss with trasz@ and mav@ before
pulling this into head.

r292618:
Add comment to go with r291228.
2015-12-24 02:35:59 +00:00