Commit Graph

92 Commits

Author SHA1 Message Date
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
Navdeep Parhar
c8b73c2cc7 Add comment to go with r291228.
Submitted by:	trasz@
2015-12-22 20:03:49 +00:00
Steven Hartland
c82d74037f Fix panic on shutdown due to iscsi event priority
iscsi's shutdown_pre_sync prio was SHUTDOWN_PRI_FIRST which caused it to
run before other high priority handlers such as filesystems e.g. ZFS.

This meant the iscsi sessions where removed before the ZFS geom consumer
was closed, resulting in a panic from g_access calls on debug kernels
due to negative acr.

Instead use the same as the old iscsi_initiator SHUTDOWN_PRI_DEFAULT-1
which allows it to run before dashutdown etc but after filesystems.

MFC after:	2 weeks
Sponsored by:	Multiplay
2015-12-07 02:56:08 +00:00
Navdeep Parhar
7ceec7e48d 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.
2015-11-24 01:12:17 +00:00
Navdeep Parhar
f5cadbc463 s/is->is_conn/ic to shorten things a bit. 2015-11-24 01:07:57 +00:00
Edward Tomasz Napierala
e553ca4994 Rework the way iSCSI initiator handles system shutdown. This fixes
hangs on shutdown with LUNs with mounted filesystems over a disconnected
iSCSI session.

MFC after:	1 month
Sponsored by:	The FreeBSD Foundation
Differential Revision:	https://reviews.freebsd.org/D3052
2015-08-03 11:57:11 +00:00
Edward Tomasz Napierala
7a03d007cf Extend ICL to add receive offload methods. For software ICL backend
they are no-ops.

MFC after:	1 month
Sponsored by:	The FreeBSD Foundation
2015-02-08 19:15:14 +00:00
Edward Tomasz Napierala
674074da06 Don't call callout_drain() with iscsi mutex held; this fixes a warning
that was introduced recently.  While here, don't try to access is_terminating
without lock.

MFC after:	1 month
Sponsored by:	The FreeBSD Foundation
2015-02-05 07:46:34 +00:00
Edward Tomasz Napierala
09f2b94bf4 Fix error handling.
MFC after:	1 month
Sponsored by:	The FreeBSD Foundation
2015-02-05 07:16:45 +00:00
Edward Tomasz Napierala
82babffba9 Make it possible to set (via iscsi.conf(5)) and query (via iscsictl -v)
initiator iSCSI offload.  Pass maximum data segment size supported by
chosen offload module to iscsid(8), and make iscsid(8) not try to negotiate
anything larger than that.

MFC after:	1 month
Sponsored by:	The FreeBSD Foundation
2015-02-05 06:37:59 +00:00
Edward Tomasz Napierala
321b17ec15 Add kobj interface between ICL and the rest of the iSCSI stack.
Review note - icl.c was moved to icl_soft.c.

MFC after:	1 month
Sponsored by:	The FreeBSD Foundation
2015-01-31 07:49:50 +00:00