Commit Graph

312 Commits

Author SHA1 Message Date
Alexander Motin
ca734d8a13 Do not update "saved" mode page on every MODE SELECT.
We do not have non-volatile memory to really save those values, so we
neither report nor support this capability.  Also saved mode pages are
not replicated between HA peers now.

MFC after:	2 weeks
2016-12-27 22:38:44 +00:00
Alexander Motin
2e0a1f828e Fix/synchronize field types in struct ctl_modepage_header.
MFC after:	2 weeks
2016-12-27 22:31:06 +00:00
Alexander Motin
3722787c8a Add support for revert to defaults (RTD) bit in MODE SELECT.
MFC after:	2 weeks
2016-12-27 21:11:54 +00:00
Alexander Motin
ee5e44e076 Decouple limits on number of LUNs per port and LUs per CTL.
Those two values are not directly related, so make them independent.
This does not change any limits immediately, but makes number of LUNs
per port controllable via tunable/sysctl kern.cam.ctl.lun_map_size.
After this change increasing CTL_MAX_LUNS should be pretty cheap,
and even making it tunable should be easy.

MFC after:	2 weeks
2016-12-27 18:23:16 +00:00
Alexander Motin
92efdd4305 Fix improperly used nexus.targ_lun.
MFC after:	2 weeks
2016-12-26 08:47:35 +00:00
Alexander Motin
a16253002c Some random code cleaning.
- Reduce indentation.
 - Remove extra braces.
 - Add few missing savety checks.

MFC after:	2 weeks
2016-12-25 20:17:15 +00:00
Alexander Motin
4124315924 Remove CTL_MAX_LUNS from places where it is not required.
MFC after:	2 weeks
2016-12-25 13:34:02 +00:00
Alexander Motin
4fc0d1d757 Improve length handling when writing sense data.
- Allow maximal sense size limitation via Control Extension mode page.
 - When sense size limited, include descriptors atomically: whole or none.
 - Set new SDAT_OVFL bit if some descriptors don't fit the limit.
 - Report real written sense length instead of static maximal 252 bytes.

MFC after:	2 weeks
2016-12-24 17:42:34 +00:00
Alexander Motin
2be7cd9bdb Add support for REPD bit in RSTMF command.
We have no real timeout values to report there, but its better then error.

MFC after:	2 weeks
2016-12-22 12:18:40 +00:00
Alexander Motin
8202971892 Fix REPORT SUPPORTED OPERATION CODES for READ/WRITE BUFFER commands.
Specifications require MODE parameter of those commands to be treated
the same as SERVICE ACTION parameter of other commands.

MFC after:	2 weeks
2016-12-22 11:10:11 +00:00
Alexander Motin
20549bf66f Add support for REPORTING OPTIONS == 3 in REPORT SUPPORTED OPERATION CODES.
MFC after:	2 weeks
2016-12-21 20:19:12 +00:00
Alexander Motin
33e7ba9cf9 Add support for SITUA bit in Logical Block Provisioning mode page.
VMware tries to enable this bit to avoid multiple threshold notifications
in case of multiple initiators connected to the same LUN.  Unfortunately
their code sends MODE SELECT(6) request with parameter length hardcoded
for the page without any thresholds.  Since we have four threshold and our
page is bigger, this attempt fails, that is correct in my understanding.
So all we can do about this now is to report proper error code and hope
VMware fix their code one day.

MFC after:	2 weeks
2016-12-21 15:17:47 +00:00
Alexander Motin
f383d6efd5 Add support for locally assigned RFC 4122 UUID LUN identifiers.
MFC after:	2 weeks
2016-12-21 09:05:30 +00:00
Alexander Motin
171e4b68b3 Bump specifications support to SAM-6/SPC-5. 2016-12-20 21:58:43 +00:00
Alexander Motin
32920cbfa3 When reporting "Logical block address out of range" error, report the LBA
in sense data INFORMATION field.

MFC after:	2 weeks
2016-12-19 19:00:03 +00:00
Alexander Motin
f60639b79e Add new bits into Extended Inquiry VPD page.
MFC after:	2 weeks
2016-12-19 15:18:31 +00:00
Alexander Motin
7f900be181 Add support for NUAR bit in Control mode page.
MFC after:	2 weeks
2016-12-19 14:19:52 +00:00
Alexander Motin
1188787581 Add set of macros to simplify code access to mode pages fields.
MFC after:	2 weeks
2016-12-19 13:25:53 +00:00
Alexander Motin
f3ee47571e Following SPC-5, make REQUEST SENSE report "Logical unit not supported"
in returned parameter data for not accessible LUNs.

MFC after:	2 weeks
2016-12-19 11:44:41 +00:00
Alexander Motin
d9ba4eefdc Improve support for informational exceptions.
While CTL still has no real events to report in this way (like SMART),
it is possible to trigger false event by manually setting TEST bit in
Informational Exceptions Control mode page, that can be useful for
initiator testing.  This code supports all flavours of IE reporting:
UNIT ATTENTION, RECOVERED ERROR and NO SENSE sense keys, REQUEST SENSE
command and Informational Exceptions log page.

MFC after:	2 weeks
Sponsored by:	iXsystems, Inc.
2016-12-19 10:25:47 +00:00
Edward Tomasz Napierala
a851d1fbfd Check for lengths being <= 0. Note that this interface can only
be accessed by root.  It uses unsigned ints instead of size_t
to preserve the ABI.

PR:		207627
Submitted by:	ryan@ryanday.net (with slight tweaks)
MFC after:	1 month
2016-11-03 10:11:59 +00:00
Alexander Motin
4928a0c224 Add LU option to control reported provisioning type.
MFC after:	2 weeks
2016-10-15 14:40:34 +00:00
Alexander Motin
15fd2e2412 Add LUN options to limit UNMAP and WRITE SAME sizes.
CTL itself has no limits on on UNMAP and WRITE SAME sizes.  But depending
on backends large requests may take too much time.  To avoid that new
configuration options allow to hint initiator maximal sizes it should not
exceed.

MFC after:	2 weeks
2016-10-15 10:29:33 +00:00
Pedro F. Giffuni
1ffe58516c sys/cam: spelling fixes in comments.
No functional change.
2016-04-29 21:05:48 +00:00
Pedro F. Giffuni
167e63e394 cam: unsign some types to match their definitions and avoid overflows.
numpatterns is u_int.

ctl:
CTL_NUM_MODE_PAGES comes from sizeof().
In struct:ctl_scsiio, kern_sg_entries is uint32_t.

MFC after:	2 weeks
2016-04-27 15:35:05 +00:00
Sean Bruno
bbea316cc8 Plug memory leak in ctl(4) when ctl_copyin_args() is called with a non-
null terminated ASCII string.

PR:		207626
Submitted by:	cturt@hardenedbsd.org
MFC after:	2 days
2016-04-19 16:48:14 +00:00
Edward Tomasz Napierala
c5805a3deb Remove stray semicolons from the iSCSI code.
MFC after:	1 month
Sponsored by:	The FreeBSD Foundation
2016-02-10 17:55:39 +00:00
Konstantin Belousov
ee1988938c Convert sys/cam to use make_dev_s().
Reviewed by:	hps, jhb
Sponsored by:	The FreeBSD Foundation
MFC after:	3 weeks
Differential revision:	https://reviews.freebsd.org/D4746
2016-01-07 20:22:55 +00:00
Alexander Motin
1e6a6c096e Set DS flag, required for LPB log page by spec.
MFC after:	1 week
2015-12-15 21:19:32 +00:00
Alexander Motin
2d80af4f4a Fix panic when trying to sort unsupported command in OOA queue.
Handle unsupported commands as not conflicting/blocking.
2015-11-27 14:29:04 +00:00
Alexander Motin
9f72f0ee52 Add NULL check to make Coverity happy. 2015-11-14 14:56:01 +00:00
Alexander Motin
6bd364b523 Modify target port groups logic in CTL.
- Introduce "ha_shared" port option, which being set to "on" moves the
port into separate port group, shared between HA nodes.  This allows to
better handle cases when iSCSI portals are bound to CARP address that can
dynamically move between nodes.  Some initiators (at least VMware) don't
detect that after iSCSI reconnect they've attached to different SCSI port
from different port group, that totally breakes ALUA status parsing.
In theory, I believe, it should be enough to have different iSCSI portal
group tags on different nodes to make initiators detect this condition,
but it seems like VMware ignores those values, and even full LUN retaste
forced by UA does not help.
 - Make CTL report up to three port groups: 1 -- non-HA mode or ports
with "ha_shared" option set, 2 -- HA node 1, 3 -- HA node 2.
 - Report Transitioning state for all port groups when HA interlink is
connected, but neither of nodes is primary for the LUN.

MFC after:	2 weeks
2015-11-11 13:18:38 +00:00
Alexander Motin
5b9676b17b Add two more KASSERTs. 2015-11-06 17:29:21 +00:00
Alexander Motin
10643dd70e Don't try to replicate mode pages not present on this device.
MFC after:	3 days
2015-10-26 14:14:56 +00:00
Alexander Motin
59f063d549 Give CTL support for PIM_EXTLUNS when talking to CAM.
CTL itself still lives in flat LUN space, but it can generate extended
numbers if CAM SIM reports such capability.
2015-10-24 17:24:19 +00:00
Alexander Motin
5124012aae Make some panic strings mode informative. 2015-10-21 15:31:26 +00:00
Alexander Motin
f24b1dc90c Implement SPC-3 exceptions to SPC-2 RESERVE and RELEASE behavior. 2015-10-01 12:57:37 +00:00
Alexander Motin
f53270c858 Unify PR variable names to reduce confusion. 2015-10-01 12:15:36 +00:00
Alexander Motin
f5a2bbe6d6 Use proper STAILQ_* macros where possible. 2015-09-30 20:38:35 +00:00
Alexander Motin
66b6967686 Really implement PREVENT ALLOW MEDIUM REMOVAL command. 2015-09-29 15:12:40 +00:00
Alexander Motin
6908da41fa Report that we can read all flavours of DVD. Why not? 2015-09-29 10:44:37 +00:00
Alexander Motin
d6e7f6e741 Add CD/DVD Capabilities and Mechanical Status Page.
This page is obsolete since MMC-4, but still used by some software.
2015-09-29 09:09:37 +00:00
Alexander Motin
648dfc1a29 Umplement media load/eject support for removable devices.
In case of block backend eject really closes the backing store, while
load tries to open it back.  Failed store open is reported as no media.
2015-09-28 20:54:18 +00:00
Alexander Motin
91be33dc78 Add to CTL initial support for CDROMs and removable devices.
Relnotes:	yes
2015-09-27 13:47:28 +00:00
Alexander Motin
0b33261bbe Remove concept of control device. 2015-09-26 12:53:55 +00:00
Alexander Motin
d3ab449cfa Remove few more unused variables. 2015-09-26 11:39:54 +00:00
Alexander Motin
9c887a4f86 Remove some duplicate, legacy, dead and questionable code. 2015-09-26 11:28:45 +00:00
Alexander Motin
86b7954b92 Properly lock LUN in ctl_failover_lun(). 2015-09-25 22:45:23 +00:00
Alexander Motin
5d4dfee032 Constify ctl_serialize_table. 2015-09-25 18:49:25 +00:00
Alexander Motin
c30a4c1871 Remove some dead code found by Clang analyzer. 2015-09-25 18:15:34 +00:00
Alexander Motin
e675024a02 Switch I/O time accounting from system time to uptime.
While there, make num_dmas accounted independently of CTL_TIME_IO.
2015-09-25 10:14:39 +00:00
Alexander Motin
6c068d4bf3 Collect DMA statistics on secondary HA node. 2015-09-25 09:55:51 +00:00
Alexander Motin
116c5818ec Make HA handle datamove and done in a universal way, using port methods.
Now from primary node point of view requests transferred from secondary
node should look almost normal and always have valid port.
2015-09-25 09:14:29 +00:00
Alexander Motin
21d963e528 Remove some control_softc references. 2015-09-25 07:27:23 +00:00
Alexander Motin
6c2acea564 Allow WRITE SAME with NDOB bit set but without UNMAP.
This combination was originally forbidden, but allowed at spc4r3.
2015-09-24 15:59:08 +00:00
Alexander Motin
4ef0129a46 Add new report types to REPORT LUNS command.
This is only for completeness, since we have nothing new to report there.
2015-09-24 12:22:47 +00:00
Alexander Motin
a6daea64fd Update WRITE ATOMIC(16) support to sbc4r8 draft.
This is only a cosmetic change.  We still don't support atomic boundary
field in the CDB, but at least now we do it formally.
2015-09-24 08:04:47 +00:00
Alexander Motin
de988746be Add support for READ BUFFER(16) command. 2015-09-24 07:16:34 +00:00
Alexander Motin
ca85b7c4e9 Synchronize mode pages between HA peers.
We allow to modify only few fields in mode pages now, but still it is
not good if they unexpectedly change during failover.  Also this fixes
reporting of "Mode parameters changed" UAs on secondary node.
2015-09-23 18:33:00 +00:00
Alexander Motin
a85700a912 Make HA peers announce their parameters on connect.
HA protocol requires strict version, parameters and configuration match.
Differences there may cause full set of problems up to kernel panic.
To avoid that, validate peer parameters on connect, and abort connection
immediately if some mismatch detected.
2015-09-23 15:49:27 +00:00
Alexander Motin
c53993057b Add support for Control extension mode page. 2015-09-22 14:55:46 +00:00
Alexander Motin
921af50782 Always execute REPORT LUNS and REQUEST SENSE commands locally.
REPORT LUNS command is more related to target rather then specific LUN.
This node may be primary for LUNs for some reason unknown to another,
and command forwarded to another node won't be able to report them.

REQUEST SENSE is related to LUN, but in our implementation it reports
only UAs and CAs, that are stored locally rather then on primary node.
2015-09-19 19:30:55 +00:00
Alexander Motin
efbf6139a4 Split two command flags with different meaning.
This is only a cosmetical change.
2015-09-19 19:11:59 +00:00
Alexander Motin
6861045bda Fix memory corruption when >128K transferred through HA link.
While there, do some cleaning.
2015-09-19 13:12:09 +00:00
Alexander Motin
bc8749e2ff Mark I/Os with DMA flag while moving data through the HA link. 2015-09-18 20:11:10 +00:00
Alexander Motin
75a3108e13 Relax serseq option operation for reads.
Previously, with serseq enabled, next command was unblocked only after
previous completed.  With this change, for read operations, next command
is unblocked as soon as last media read completed.  This is important
for frontends that actually wait for data move completion (like camtgt),
or when data are moved through the HA link, or especially when both.
2015-09-18 19:43:14 +00:00
Alexander Motin
59bb97a934 Kill HA link and shutdown the threads on shutdown. 2015-09-18 12:08:00 +00:00
Alexander Motin
0c05f0dc16 Replicate initiators WWPNs and names between HA peers. 2015-09-17 21:51:11 +00:00
Alexander Motin
54713bce25 Replicate port->init_devid to HA peer. 2015-09-17 20:36:34 +00:00
Alexander Motin
6213882769 When reporting TPT UA, report which of thresholds was reached. 2015-09-17 17:00:36 +00:00
Alexander Motin
7f7bb97a0f Report proper medium error code for VERIFY commands. 2015-09-17 12:52:18 +00:00
Alexander Motin
923863546a Close potential race between datamove and HA failover. 2015-09-15 09:36:46 +00:00
Alexander Motin
d0f25804a7 Implement data/status aggregation for secondary HA node.
For short read requests this reduces latency by 30%, reporting command
completion after two interlink roundtrips instead of full three.
2015-09-14 15:21:23 +00:00
Alexander Motin
7b6660c9aa Remove CTL_PRIV_LBA_LEN from HA messages.
Previously it was used for statistics, but now just a 16 extra bytes.
2015-09-14 09:56:01 +00:00
Alexander Motin
ceff31dc0c Implement QUERY TASK, QUERY TASK SET and QUERY ASYNC EVENT.
Now we support most of SAM-5 task management.
2015-09-14 08:01:05 +00:00
Alexander Motin
6187d4722a Improve read-only support. 2015-09-13 16:49:41 +00:00
Alexander Motin
6b56dd0cfa Reannounce port to HA peer if LUN map changed after online. 2015-09-13 15:31:55 +00:00
Alexander Motin
cfa0987386 Report INQUIRY DATA HAS CHANGED for related LUNs on port on-/offline. 2015-09-13 14:52:31 +00:00
Alexander Motin
eebde34629 Report CTL_UA_LUN_CHANGE on LUN map change. 2015-09-13 14:04:42 +00:00
Alexander Motin
844c2a3a94 Make TARGET RESET respect LUN mapping. 2015-09-13 13:00:20 +00:00
Alexander Motin
051481a24e Add HA support for CTL_TASK_I_T_NEXUS_RESET. 2015-09-12 20:06:22 +00:00
Alexander Motin
0a4c638188 Fix false CTL_UA_RES_RELEASE on secondary HA node. 2015-09-12 18:29:05 +00:00
Alexander Motin
e184d2576a Some HA polishing. 2015-09-12 12:46:04 +00:00
Alexander Motin
572846e089 Make ctld restart on primary HA node less invasive for secondary. 2015-09-11 14:47:35 +00:00
Alexander Motin
7ac58230ea Reimplement CTL High Availability.
CTL HA functionality was originally implemented by Copan many years ago,
but large part of the sources was never published.  This change includes
clean room implementation of the missing code and fixes for many bugs.

This code supports dual-node HA with ALUA in four modes:
 - Active/Unavailable without interlink between nodes;
 - Active/Standby with second node handling only basic LUN discovery and
reservation, synchronizing with the first node through the interlink;
 - Active/Active with both nodes processing commands and accessing the
backing storage, synchronizing with the first node through the interlink;
 - Active/Active with second node working as proxy, transfering all
commands to the first node for execution through the interlink.

Unlike original Copan's implementation, depending on specific hardware,
this code uses simple custom TCP-based protocol for interlink.  It has
no authentication, so it should never be enabled on public interfaces.

The code may still need some polishing, but generally it is functional.

Relnotes:	yes
Sponsored by:	iXsystems, Inc.
2015-09-10 12:40:31 +00:00
Alexander Motin
fb606ebabc Remove unused target and initiator IDs. 2015-09-10 10:46:21 +00:00
Alexander Motin
3f326305fc Disable CTL_IO_DELAY feature.
It is too developer-oriented to be enabled by default.
2015-09-10 09:27:22 +00:00
Alexander Motin
0bcd4ab6ba Move setting of media parameters inside open routines.
This is preparation for possibility to open/close media several times
per LUN life cycle.  While there, rename variables to reduce confusion.
As additional bonus this allows to open read-only media, such as ZFS
snapshots.
2015-09-06 09:54:56 +00:00
Alexander Motin
420abfcecd Small UA cleanup. 2015-09-03 12:56:57 +00:00
Alexander Motin
8be6a2df51 Fix copy-paste bug introduced in r275458.
MFC after:	3 days
2015-09-03 12:15:14 +00:00
Alexander Motin
1b7849d0f2 Make most of port methods optional and remove bunch of dummies. 2015-09-01 16:28:06 +00:00
Alexander Motin
67ceb24bca Move "ioctl" CAM frontend into separate file.
It has nothing to share with too huge ctl.c other then device descriptor,
but even that may be counted as design error that may be fixed later.
At some point we may even want to have several ioctl ports.
2015-08-15 15:42:21 +00:00
Alexander Motin
2f444d157b 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..
2015-08-15 13:34:38 +00:00
Alexander Motin
4ddb055594 Remove verbose CTL messages.
Reporting SCSI errors to console is often useless, pollutes logs and may
affect performance.  For debugging there is kern.cam.ctl.debug sysctl

MFC after:	1 week
2015-08-09 09:54:29 +00:00
Alexander Motin
3301406331 Add more ifdefs to fix build with GCC after r286406. 2015-08-07 14:12:51 +00:00
Marcelo Araujo
8b3ae99560 Wrap some unused functions with notyet, it is necessary to be able to
build the modules/ctl directly.
Remove a dead MALLOC_DEFINE.

Differential Revision:	D3329
Reviewed by:		mav
Sponsored by:		gandi.net
2015-08-07 08:30:43 +00:00
Alexander Motin
7d0d4342e3 Pass SYNCHRONIZE CACHE command parameters to backends.
At this point IMMED flag is translated to MNT_NOWAIT flag of VOP_FSYNC(),
hoping that file system implements that (ZFS seems doesn't).

MFC after:	2 weeks
Sponsored by:	iXsystems, Inc.
2015-08-05 22:24:49 +00:00
Alexander Motin
1ec1012dd2 Fix REPORT LUNS command output for the case when same LUN mapped to same
port several times.  While it is unusual configuration, it is not illegal.

MFC after:	1 week
2015-06-20 13:02:57 +00:00
Alexander Motin
7834ea8891 Bring per-port LUN enable/disable code up to date:
- remove last remnants of never implemented multiple targets support;
 - implement missing support for LUN mapping in this area.

Due to existing locking constraints LUN mapping code is practically
unlocked at this point.  Hopefully it is not racy enough to live until
somebody get idea how to call sleeping fronend methods under lock also
taken by the same frontend in non-sleepable context. :(
2015-06-20 12:43:54 +00:00
Alexander Motin
754e493530 Remove some dead and duplicate LUN enabling code. 2015-06-20 07:33:06 +00:00