Commit Graph

289 Commits

Author SHA1 Message Date
Edward Tomasz Napierala
6e4f347cd6 Make it possible to interrupt login when running in proxy mode.
Sponsored by:	The FreeBSD Foundation
2014-04-16 10:37:26 +00:00
Edward Tomasz Napierala
8cab2ed4cd 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
2014-04-16 10:29:34 +00:00
Edward Tomasz Napierala
2ebde326cb Add some stuff to make it easier to figure out for the system administrator
whether the ICL_KERNEL_PROXY stuff got compiled in correctly.

Sponsored by:	The FreeBSD Foundation
2014-04-16 10:18:44 +00:00
Edward Tomasz Napierala
ba3a2d31c8 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
2014-04-16 10:06:37 +00:00
Alexander Motin
2dfdd4ae19 Join CTL worker threads into one process for convenience.
Report their idle state as "-".
2014-04-13 11:10:36 +00:00
Alexander Motin
7081bb15b0 Fix three refcounter leaks and lock recursion they covered.
MFC after:	1 week
2014-04-09 19:16:40 +00:00
Alexander Motin
004008d6e6 Introduce new serialization type CTL_SERIDX_UNMAP.
Unfortunately we can't check range collisions for UNMAP commands alike
to writes, because they include multiple ranges, which are also passed
in data block, not in CDB.  As result, UNMAP commands have to be treated
as colliding with any other command accessing the media.

From the other side all UNMAPs are equal (we don't support ANCHOR flag),
so we can execute several UNMAPs same time.
2014-04-09 10:58:52 +00:00
Alexander Motin
8f5a226a3c When splitting huge unmap requests, do it on sector boundary. 2014-04-09 10:44:09 +00:00
Alexander Motin
7e0be0226f Another fix for r264274. Last moment cosmetic changes are evil! 2014-04-08 22:36:39 +00:00
Alexander Motin
f7ad1c4625 Oops! Few quick fixes for r264274. 2014-04-08 21:30:10 +00:00
Alexander Motin
ee7f31c068 Add support for SCSI UNMAP commands to CTL.
This patch adds support for three new SCSI commands: UNMAP, WRITE SAME(10)
and WRITE SAME(16).  WRITE SAME commands support both normal write mode
and UNMAP flag.  To properly report UNMAP capabilities this patch also adds
support for reporting two new VPD pages: Block limits and Logical Block
Provisioning.

UNMAP support can be enabled per-LUN by adding "-o unmap=on" to `ctladm
create` command line or "option unmap on" to lun sections of /etc/ctl.conf.

At this moment UNMAP supported for ramdisks and device-backed block LUNs.
It was tested to work great with ZFS ZVOLs.  For file-backed LUNs UNMAP
support is unfortunately missing due to absence of respective VFS KPI.

Reviewed by:	ken
MFC after:	1 month
Sponsored by:	iXsystems, Inc
2014-04-08 20:50:48 +00:00
Alexander Motin
1fa3ca3ca7 Wakeup only one thread of added in r263978i at a time.
This slightly reduces lock congestion between threads.

Submitted by:	trasz
2014-04-08 18:22:03 +00:00
Alexander Motin
f601272298 Report stripe size and offset of the backing device in READ CAPACITY (16)
as physical sector size and offset.

MFC after:	2 weeks
2014-04-06 10:13:14 +00:00
Edward Tomasz Napierala
605a34b065 All the iSCSI sysctls are also tunables; advertise that.
Sponsored by:	The FreeBSD Foundation
2014-04-04 08:48:55 +00:00
Edward Tomasz Napierala
01a111f447 Use atomic ops instead of mutexes where appropriate.
Submitted by:	mav@
Sponsored by:	The FreeBSD Foundation
2014-04-01 21:54:20 +00:00
Edward Tomasz Napierala
ecba49ddfc Instead of "icltx" and "iclrx", use thread names with prefix from upper
layer, so that one can see which side of the stack the threads are for.

Sponsored by:	The FreeBSD Foundation
2014-04-01 21:47:22 +00:00
Edward Tomasz Napierala
6ed8f5d236 Get rid of ICL lock; use upper-layer (initiator or target) lock instead.
This avoids extra locking in icl_pdu_queue(); the upper layer needs to call
it while holding its own lock anyway, to avoid sending PDUs out of order.

Sponsored by:	The FreeBSD Foundation
2014-04-01 21:40:46 +00:00
Edward Tomasz Napierala
a0e36aee93 Remove the homegrown ctl_be_block_io allocator, replacing it with UMA.
There is no performance difference.

Reviewed by:	mav@
Sponsored by:	The FreeBSD Foundation
2014-04-01 21:13:05 +00:00
Edward Tomasz Napierala
ac030c53c0 Hide CTL messages about SCSI error responses. Too many users take
them for actual target errors.  They can be enabled back by setting
kern.cam.ctl.verbose=1, or booting with bootverbose.

Sponsored by:	The FreeBSD Foundation
2014-03-31 21:04:15 +00:00
Edward Tomasz Napierala
9328f8a939 Make it possible to have multiple CTL worker threads. Leave the default
of 1 for now.

Sponsored by:	The FreeBSD Foundation
2014-03-31 20:49:33 +00:00
Edward Tomasz Napierala
0f26fd2c61 Remove ctl_mem_pool.{c,h}.
Sponsored by:	The FreeBSD Foundation
2014-03-27 11:10:13 +00:00
Edward Tomasz Napierala
6d9d321647 Rework cfiscsi_datamove_in() to obey expected data transfer length
received from the initiator.

Sponsored by:	The FreeBSD Foundation
2014-03-27 10:15:35 +00:00
Edward Tomasz Napierala
ea86ccce9b Target Transfer Tag is opaque; no need to htonl(3) it.
Sponsored by:	The FreeBSD Foundation
2014-03-25 19:28:40 +00:00
Edward Tomasz Napierala
b1277ad1f7 Use a less unusual syntax in debug printfs.
Sponsored by:	The FreeBSD Foundation
2014-03-25 18:30:57 +00:00
Robert Watson
4a14441044 Update kernel inclusions of capability.h to use capsicum.h instead; some
further refinement is required as some device drivers intended to be
portable over FreeBSD versions rely on __FreeBSD_version to decide whether
to include capability.h.

MFC after:	3 weeks
2014-03-16 10:55:57 +00:00
Edward Tomasz Napierala
2cb15089bb Make reset handling in iSCSI target RFC-compliant. This fixes some rare
hangs with Open-iSCSI (Linux).

MFC after:	1 month
Sponsored by:	The FreeBSD Foundation
2014-03-06 10:45:53 +00:00
Edward Tomasz Napierala
561a971a76 Fix missing unlock in persistent reservations code, which resulted in panics
with Hyper-V Failover Cluster.

Reviewed by:	ken@
MFC after:	2 weeks
Sponsored by:	The FreeBSD Foundation
2014-03-05 12:02:29 +00:00
Alexander Motin
e0c2f97550 Make CTL block backend return proper error code for operations unsupposed
by the underlying device.

MFC after:	2 weeks
2014-02-06 03:54:58 +00:00
Edward Tomasz Napierala
025a2301f8 Properly report an error instead of panicing when user tries to create
LUN backed by non-disk device, e.g. /dev/null.

Reviewed by:	ken (earlier version)
MFC after:	3 days
Sponsored by:	The FreeBSD Foundation
2013-12-03 18:04:14 +00:00
Andriy Gapon
d9fae5ab88 dtrace sdt: remove the ugly sname parameter of SDT_PROBE_DEFINE
In its stead use the Solaris / illumos approach of emulating '-' (dash)
in probe names with '__' (two consecutive underscores).

Reviewed by:	markj
MFC after:	3 weeks
2013-11-26 08:46:27 +00:00
Attilio Rao
54366c0bd7 - For kernel compiled only with KDTRACE_HOOKS and not any lock debugging
option, unbreak the lock tracing release semantic by embedding
  calls to LOCKSTAT_PROFILE_RELEASE_LOCK() direclty in the inlined
  version of the releasing functions for mutex, rwlock and sxlock.
  Failing to do so skips the lockstat_probe_func invokation for
  unlocking.
- As part of the LOCKSTAT support is inlined in mutex operation, for
  kernel compiled without lock debugging options, potentially every
  consumer must be compiled including opt_kdtrace.h.
  Fix this by moving KDTRACE_HOOKS into opt_global.h and remove the
  dependency by opt_kdtrace.h for all files, as now only KDTRACE_FRAMES
  is linked there and it is only used as a compile-time stub [0].

[0] immediately shows some new bug as DTRACE-derived support for debug
in sfxge is broken and it was never really tested.  As it was not
including correctly opt_kdtrace.h before it was never enabled so it
was kept broken for a while.  Fix this by using a protection stub,
leaving sfxge driver authors the responsibility for fixing it
appropriately [1].

Sponsored by:	EMC / Isilon storage division
Discussed with:	rstone
[0] Reported by:	rstone
[1] Discussed with:	philip
2013-11-25 07:38:45 +00:00
Alexander Motin
8c6d5f8282 Introduce seperate mutex lock to protect protect CTL I/O pools, slightly
reducing global CTL lock scope and congestion.

While there, simplify CTL I/O pools KPI, hiding implementation details.
2013-11-11 08:27:20 +00:00
Alexander Motin
eeb9405409 Remove 128KB bzero() call done for every block I/O data buffer.
On my tests this improves performance of the new iSCSI target backed by
GEOM STRIPE of SSDs from 75K to 110K IOPS.

Reviewed by:	ken
2013-10-23 17:55:35 +00:00
Alexander Motin
227d67aa54 Merge CAM locking changes from the projects/camlock branch to radically
reduce lock congestion and improve SMP scalability of the SCSI/ATA stack,
preparing the ground for the coming next GEOM direct dispatch support.

Replace big per-SIM locks with bunch of smaller ones:
 - per-LUN locks to protect device and peripheral drivers state;
 - per-target locks to protect list of LUNs on target;
 - per-bus locks to protect reference counting;
 - per-send queue locks to protect queue of CCBs to be sent;
 - per-done queue locks to protect queue of completed CCBs;
 - remaining per-SIM locks now protect only HBA driver internals.

While holding LUN lock it is allowed (while not recommended for performance
reasons) to take SIM lock.  The opposite acquisition order is forbidden.
All the other locks are leaf locks, that can be taken anywhere, but should
not be cascaded.  Many functions, such as: xpt_action(), xpt_done(),
xpt_async(), xpt_create_path(), etc. are no longer require (but allow) SIM
lock to be held.

To keep compatibility and solve cases where SIM lock can't be dropped, all
xpt_async() calls in addition to xpt_done() calls are queued to completion
threads for async processing in clean environment without SIM lock held.

Instead of single CAM SWI thread, used for commands completion processing
before, use multiple (depending on number of CPUs) threads.  Load balanced
between them using "hash" of the device B:T:L address.

HBA drivers that can drop SIM lock during completion processing and have
sufficient number of completion threads to efficiently scale to multiple
CPUs can use new function xpt_done_direct() to avoid extra context switch.
Make ahci(4) driver to use this mechanism depending on hardware setup.

Sponsored by:	iXsystems, Inc.
MFC after:	2 months
2013-10-21 12:00:26 +00:00
Edward Tomasz Napierala
c48f182bb1 Remove no longer useful debugging output and a stale comment.
Approved by:	re (gjb)
Sponsored by:	FreeBSD Foundation
2013-10-09 17:34:45 +00:00
Edward Tomasz Napierala
02147e9cd0 Make the error handling more consistant. Shouldn't make any functional
difference.

Approved by:	re (gjb)
Sponsored by:	FreeBSD Foundation
2013-10-09 17:06:03 +00:00
Edward Tomasz Napierala
8ba0396077 Tidy up, cache return value of a function, and add an assertion;
shouldn't make any functional difference.

Approved by:	re (gjb)
Sponsored by:	FreeBSD Foundation
2013-10-09 16:55:52 +00:00
Edward Tomasz Napierala
1008ac5eb7 Fix NOP-In/NOP-Out payload handling. Previous way didn't work at all; fortunately
nothing seems to actually use this feature, but it's required by standard.

Approved by:	re (glebius)
Sponsored by:	FreeBSD Foundation
2013-10-09 12:03:04 +00:00
Edward Tomasz Napierala
a9c80a534a Properly fix out of memory handling in the iSCSI target.
Approved by:	re (glebius)
Sponsored by:	FreeBSD Foundation
2013-10-08 19:18:02 +00:00
Edward Tomasz Napierala
0f30c5d3c0 Split cfiscsi_datamove() in two; no functional changes.
Approved by:	re (glebius)
Sponsored by:	FreeBSD Foundation
2013-10-05 16:22:33 +00:00
Edward Tomasz Napierala
c28c09c1f0 Don't leak memory when removing an unconnected session, and remove useless
UMA_ZONE_NOFREE that caused another leak when unloading the module.

Approved by:	re (glebius)
Sponsored by:	FreeBSD Foundation
2013-10-04 19:31:41 +00:00
Edward Tomasz Napierala
9606f568fe Properly ignore PDUs with CmdSN outside of allowed range.
Approved by:	re (glebius)
Sponsored by:	FreeBSD Foundation
2013-09-24 13:46:13 +00:00
Edward Tomasz Napierala
69aa56bef2 Fix a few instances of M_WAITOK in threads marked as prohibited from sleep,
missed in r255824.

Approved by:	re (kib)
Sponsored by:	FreeBSD Foundation
2013-09-24 09:33:31 +00:00
Edward Tomasz Napierala
46aaea8995 Don't use M_WAITOK when running from context where sleeping is prohibited,
such as callout or a geom thread.

Approved by:	re (marius)
Sponsored by:	FreeBSD Foundation
2013-09-23 19:54:44 +00:00
Edward Tomasz Napierala
ac873bb350 Add some spare fields to structs used by the new iSCSI stack - some just
in case, some for future MC/S support.

This requires kernel and world rebuild.

Approved by:	re (blanket)
Sponsored by:	FreeBSD Foundation
2013-09-20 21:26:51 +00:00
Edward Tomasz Napierala
009ea47eb2 Bring in the new iSCSI target and initiator.
Reviewed by:	ken (parts)
Approved by:	re (delphij)
Sponsored by:	FreeBSD Foundation
2013-09-14 15:29:06 +00:00
Alexander Motin
27492bea85 Fix the build with CTLFEDEBUG, broken by unmapped I/O support changes. 2013-09-01 10:11:00 +00:00
Edward Tomasz Napierala
81a2151d5c CTL changes required for iSCSI target, most notably LUN remapping
and a mechanism to allow CTL frontends for retrieving LUN options.

Reviewed by:	ken (earlier version)
2013-08-24 01:50:31 +00:00
Edward Tomasz Napierala
da4757e06b Turn comments about locking into actual lock assertions.
Reviewed by:	ken
Tested by:	ken
MFC after:	1 month
2013-08-15 20:00:32 +00:00
Edward Tomasz Napierala
ea7c84e46f Remove dead code. 2013-08-06 10:42:18 +00:00
Alexander Motin
ce300fbfb7 Fix NULL-deference kernel panic on attempt of destroying non-existing
ramdisk-backed CTL LUN.
2013-07-03 14:58:11 +00:00
Eitan Adler
7a2b450ff8 Fxi a bunch of typos.
PR:	misc/174625
Submitted by:	Jeremy Chadwick <jdc@koitsu.org>
2013-05-10 16:41:26 +00:00
Eitan Adler
578acad37e Correct a few sizeof()s
Submitted by:	swildner@DragonFlyBSD.org
Reviewed by:	alfred
2013-05-01 04:37:34 +00:00
Alexander Motin
e5dfa058da MFprojects/camlock r248982:
Stop abusing xpt_periph in random plases that really have no periph related
to CCB, for example, bus scanning.  NULL value is fine in such cases and it
is correctly logged in debug messages as "noperiph".  If at some point we
need some real XPT periphs (alike to pmpX now), quite likely they will be
per-bus, and not a single global instance as xpt_periph now.
2013-04-14 09:55:48 +00:00
Alexander Motin
cccf422080 MFprojects/camlock r248890, r248897, r248898, r248900, r248903, r248905,
r248917, r248918, r248978, r249001, r249014, r249030:

Remove multilevel freezing mechanism, implemented to handle specifics of
the ATA/SATA error recovery, when post-reset recovery commands should be
allocated when queues are already full of payload requests.  Instead of
removing frozen CCBs with specified range of priorities from the queue
to provide free openings, use simple hack, allowing explicit CCBs over-
allocation for requests with priority higher (numerically lower) then
CAM_PRIORITY_OOB threshold.

Simplify CCB allocation logic by removing SIM-level allocation queue.
After that SIM-level queue manages only CCBs execution, while allocation
logic is localized within each single device.

Suggested by:	gibbs
2013-04-14 09:28:14 +00:00
Edward Tomasz Napierala
8ed9860914 Remove ctl(4) from GENERIC. Also remove 'options CTL_DISABLE'
and kern.cam.ctl.disable tunable; those were introduced as a workaround
to make it possible to boot GENERIC on low memory machines.

With ctl(4) being built as a module and automatically loaded by ctladm(8),
this makes CTL work out of the box.

Reviewed by:	ken
Sponsored by:	FreeBSD Foundation
2013-04-12 16:25:03 +00:00
Kenneth D. Merry
1fe2e04bb6 Fix a memory leak that showed up when we delete LUNs. The memory used for
the LUN was never freed.

ctl.c:		Adjust ctl_alloc_lun() to make sure we don't clear the
		CTL_LUN_MALLOCED flag.

Reported by:	Sreenivasa Honnur <shonnur@chelsio.com>
Sponsored by:	Spectra Logic
MFC after:	3 days
2013-04-08 15:36:26 +00:00
Edward Tomasz Napierala
d2a0972d46 Make SYNCHRONIZE CACHE work with LUNs backed by device files (as opposed
to regular files, which already worked fine).  With this change, it's no
longer neccessary to use "ctladm realsync off" workaround.
2013-04-06 10:34:02 +00:00
Edward Tomasz Napierala
7aba111672 Since the CTL version in FreeBSD does not support High Availability,
ctl_is_single should always be set to 1.  Make it so.  Previously
it was always 0, because ctl_isc_start() never got to run.

Suggested by:	ken
2013-04-04 18:00:18 +00:00
Edward Tomasz Napierala
b93f389f48 Fix locking problem in ctl_maintenance_in() - one cannot use M_WAITOK or call
ctl_done() with mutex held.

Reviewed by:	ken
Sponsored by:	FreeBSD Foundation
2013-04-03 20:26:52 +00:00
Kenneth D. Merry
3e49efa8b3 Fix sending virtual scatter/gather lists from the CTL CAM frontend
peripheral.

Sponsored by:	Spectra Logic
2013-04-02 17:29:17 +00:00
Edward Tomasz Napierala
9eef3375ce Don't directly dereference userland pointer; instead use kernel pointer
copied in from userspace.  This fixes instant panic when creating CTL LUN
on sparc64.  Not a security problem, since the API is root-only.

Reviewed by:	ken
Sponsored by:	FreeBSD Foundation
2013-04-02 16:50:50 +00:00
Edward Tomasz Napierala
d732e85ce2 Fix comment formatting. 2013-04-02 12:22:44 +00:00
Edward Tomasz Napierala
26d664f914 Remove unused code.
Reviewed by:	ken
2013-04-02 09:45:34 +00:00
Edward Tomasz Napierala
325621458d Make it possible to build CTL as a module.
Reviewed by:	ken
Sponsored by:	FreeBSD Foundation
2013-04-02 09:42:42 +00:00
Kenneth D. Merry
3a45b4781a Re-enable CTL in GENERIC on i386 and amd64, but turn on the CTL disable
tunable by default.

This will allow GENERIC configurations to boot on small memory boxes, but
not require end users who want to use CTL to recompile their kernel.  They
can simply set kern.cam.ctl.disable=0 in loader.conf.

The eventual solution to the memory usage problem is to change the way
CTL allocates memory to be more configurable, but this should fix things
for small memory situations in the mean time.

UPDATING:		Explain the change in the CTL configuration, and
			how users can enable CTL if they would like to use
			it.

sys/conf/options:	Add a new option, CTL_DISABLE, that prevents CTL
			from initializing.

ctl.c:			If CTL_DISABLE is turned on, don't initialize.

i386/conf/GENERIC,
amd64/conf/GENERIC:	Re-enable device ctl, and add the CTL_DISABLE
			option.
2013-03-04 21:18:45 +00:00
Konstantin Belousov
dd0b4fb6d5 Reform the busdma API so that new types may be added without modifying
every architecture's busdma_machdep.c.  It is done by unifying the
bus_dmamap_load_buffer() routines so that they may be called from MI
code.  The MD busdma is then given a chance to do any final processing
in the complete() callback.

The cam changes unify the bus_dmamap_load* handling in cam drivers.

The arm and mips implementations are updated to track virtual
addresses for sync().  Previously this was done in a type specific
way.  Now it is done in a generic way by recording the list of
virtuals in the map.

Submitted by:	jeff (sponsored by EMC/Isilon)
Reviewed by:	kan (previous version), scottl,
	mjacob (isp(4), no objections for target mode changes)
Discussed with:	     ian (arm changes)
Tested by:	marius (sparc64), mips (jmallet), isci(4) on x86 (jharris),
	amd64 (Fabian Keil <freebsd-listen@fabiankeil.de>)
2013-02-12 16:57:20 +00:00
Kenneth D. Merry
744c26b250 Make CTL work a little better with loading and unloading drivers.
Previously CTL would leave individual LUNs enabled in the target
driver, whether or not the port as a whole was enabled.  It would
also leave the wildcard LUN enabled indefinitely.

This change means that CTL will enable and disable any active LUNs,
as well as the wildcard LUN, when enabling and disabling a port.

Also, fix a bug that could crop up due to an uninitialized CCB
type.

ctl.c:		Before calling ctl_frontend_online(), run through
		the LUN list and enable all active LUNs.

		After calling ctl_frontend_offline(), run through
		the LUN list and disble all active LUNs.

scsi_ctl.c:	Before bringing a port online, allocate the
		wildcard peripheral for that bus.  And after taking
		a port offline, invalidate the wildcard peripheral
		for that bus.

		Make sure that we hold the SIM lock around all
		calls to xpt_action() and other transport layer
		interfaces that require it.

		Use CAM_SIM_{LOCK|UNLOCK} consistently to acquire
		and release the SIM lock.

		Update a number of outdated comments.  Some of
		these should have been fixed long ago.

		Actually do LUN disbables now.  The newer drivers
		in the tree work correctly for this as far as I
		know.

		Initialize the CCB type to CTLFE_CCB_DEFAULT to
		avoid a panic due to uninitialized memory.

Submitted by:	Chuck Tuffli (partially)
MFC after:	1 week
2013-01-09 17:02:08 +00:00
Kenneth D. Merry
54f90e7783 Fix a couple of CTL locking issues and clean up some duplicated code.
ctl_frontend_cam_sim.c:	Coalesce cfcs_online() and cfcs_offline()
			into a single function since these were
			identical except for one line.

			Make sure we hold the SIM lock around path
			creation, and calling xpt_rescan().

scsi_ctl.c:		In ctlfe_onoffline(), make sure we hold the
			SIM lock around path creation and free
			calls, as well as xpt_action().

			In ctlfe_lun_enable(), hold the SIM lock
			around path and peripheral operations that
			require it.

Sponsored by:	Spectra Logic Corporation
MFC after:	1 week
2012-12-09 19:53:21 +00:00
Kenneth D. Merry
a6495a9d22 Make sure we hold the SIM lock when calling xpt_free_path().
Sponsored by:	Spectra Logic Corporation
MFC after:	1 week
2012-12-08 04:55:06 +00:00
Kenneth D. Merry
c67e754951 Fix the CTL OOA queue dumping code so that it does not hold a mutex
while doing a copyout.  That can cause a panic, because copyout
can trigger VM faults, and we can't handle VM faults while holding
a mutex.

The solution here is to malloc a separate buffer to hold the OOA
queue entries, so that we don't risk a VM fault while filling up
the buffer and we don't have to drop the lock.  The other solution
would be to wire the user's memory while filling their buffer with
copyout, but that would have been a little more complex.

Also fix a debugging parenthesis issue in ctl_abort_task() pointed
out by Chuck Tuffli.

Sponsored by:	Spectra Logic Corporation
MFC after:	1 week
2012-12-08 04:16:07 +00:00
Edward Tomasz Napierala
a492b68b27 Use M_ZERO instead of explicit memsets and bzeros. 2012-10-30 12:52:41 +00:00
Alexander Motin
15a2601b29 Remove several uses of numeric priorities from immediate CCB setups. 2012-10-27 09:40:29 +00:00
Konstantin Belousov
5050aa86cf Remove the support for using non-mpsafe filesystem modules.
In particular, do not lock Giant conditionally when calling into the
filesystem module, remove the VFS_LOCK_GIANT() and related
macros. Stop handling buffers belonging to non-mpsafe filesystems.

The VFS_VERSION is bumped to indicate the interface change which does
not result in the interface signatures changes.

Conducted and reviewed by:	attilio
Tested by:	pho
2012-10-22 17:50:54 +00:00
Eitan Adler
db702c59cf remove duplicate semicolons where possible.
Approved by:	cperciva
MFC after:	1 week
2012-10-22 03:00:37 +00:00
Alexander Motin
e6ce97d1b5 Extend SIM lock coverage during the bus registration process. 2012-10-13 17:55:06 +00:00
Edward Tomasz Napierala
a0a6ff825b Remove useless NULL checks after M_WAITOK allocations. 2012-09-27 10:51:38 +00:00
Edward Tomasz Napierala
43f3d8e372 Fix panic in CTL caused by trying to free invalid pointers passed
by the userland process via the IOCTL interface.

Reviewed by:	ken@
2012-09-26 07:09:15 +00:00
Matt Jacob
3388f7a926 Handle a case where we had an SRR that pushed back the
data pointer. This is a temp fix that resubmits the
command, adjusted, so that the backend can fetch the
data again.

Sponsored by: Spectralogic
MFC after:	1 month
2012-07-28 20:08:14 +00:00
Kenneth D. Merry
beedaee94a Add a loader tunable, kern.cam.ctl.disable, that will disable
loading CTL.  This may be useful in very low memory installations.

MFC after:	3 days
2012-06-28 19:39:30 +00:00
Kenneth D. Merry
b79dc8a8da Fix an issue that caused the kernel to panic inside CTL when trying
to attach to target capable HBAs that implement the old immediate
notify (XPT_IMMED_NOTIFY) and notify acknowledge (XPT_NOTIFY_ACK)
CCBs.  The new API has been in place since SVN change 196008 in
2009.

The solution is two-fold:  fix CTL to handle the responses from the
HBAs, and convert the HBA drivers in question to use the new API.

These drivers have not been tested with CTL, so how well they will
interoperate with CTL is unknown.

scsi_target.c:	Update the userland target example code to use the
		new immediate notify API.

scsi_ctl.c:	Detect when an immediate notify CCB is returned
		with CAM_REQ_INVALID or CAM_PROVIDE_FAIL status,
		and just free it.

		Fix a duplicate assignment.

aic79xx.c,
aic79xx_osm.c:	Update the aic79xx driver to use the new API.
		Target mode is not enabled on for this driver, so
		the changes will have no practical effect.

aic7xxx.c,
aic7xxx_osm.c:	Update the aic7xxx driver to use the new API.

sbp_targ.c:	Update the firewire target code to work with the
		new API.

mpt_cam.c:	Update the mpt(4) driver to work with the new API.
		Target mode is only enabled for Fibre Channel
		mpt(4) devices.

MFC after:	3 days
2012-06-26 14:51:35 +00:00
Matt Jacob
5a1ae35dd1 Print FC PortID as a hex number. This makes it easy to
figure out domain, etc..

Zero ATIO and INOTify allocations. It makes for much
less guesswork when looking at the structure and
seeing 'deadc0de' present.

Reviewed by:	kdm
MFC after:	2 weeks
Sponsored by:	Spectralogic
2012-06-01 23:24:56 +00:00
Kenneth D. Merry
bf8f8f340e Change the SCSI INQUIRY peripheral qualifier that CTL reports for LUNs
that don't exist.

Anecdotal evidence indicates that it is better to return 011b (bad LUN)
than 001b (LUN offline).  However, this change also gives the user a
sysctl/tunable, kern.cam.ctl.inquiry_pq_no_lun, to override the change
and return to the previous behavior.  (The previous behavior was to
return 001b, or LUN offline.)

ctl.c:		Change the default inquiry peripheral qualifier to 011b,
		and add a sysctl and tunable to allow the user to change
		it back to 001b if needed.

		Don't insert a Copan copyright statement in the inquiry
		data.  The copyright statements on the files are
		sufficient.

ctl_private.h:	Add sysctl variable context to the CTL softc.

ctl_cmd_table.c,
ctl_frontend_internal.c,
ctl_frontend.c,
ctl_backend.c,
ctl_error.c:	Include sys/sysctl.h.

MFC after:	3 days
2012-04-06 22:23:13 +00:00
Edward Tomasz Napierala
811772950f Add LUN resizing to CTL. Also make it possible to explicitly set
size when creating file-backed or device-backed LUN.

Reviewed by:	ken (earlier version)
Sponsored by:	The FreeBSD Foundation
2012-03-06 13:43:57 +00:00
Dimitry Andric
c995195062 Use a better way to silence unneeded internal declaration warnings in
several sys/cam/ctl files.

Suggested by:	ed
Reviewed by:	ken
MFC after:	1 week
2012-02-23 21:34:14 +00:00
Ed Maste
f0e3e0350a Avoid panic from unlocking a not locked mutex (in some error cases).
Reviewed by:	ken@
2012-02-06 18:11:00 +00:00
Kenneth D. Merry
2a2443d833 Quiet some clang warnings when compiling CTL.
ctl_error.c,
ctl_error.h:	Take out the ctl_sense_format enumeration, and use
		scsi_sense_data_type instead.

		Remove ctl_get_sense_format() and switch ctl_build_ua()
		over to using scsi_sense_data_type.

ctl_backend_ramdisk.c,
ctl_backend_block.c:
		Use C99 structure initializers instead of GNU initializers.

ctl.c:		Switch over to using the SCSI sense format enumeration
		instead of the CTL-specific enumeration.

Submitted by:	dim (partially)
MFC after:	1 month
2012-01-19 18:42:03 +00:00
Kenneth D. Merry
b87c6ae04b Silence some unnecessary verbosity.
Reported by:	mav
MFC after:	1 month
2012-01-12 22:08:33 +00:00
Kenneth D. Merry
130f4520cb Add the CAM Target Layer (CTL).
CTL is a disk and processor device emulation subsystem originally written
for Copan Systems under Linux starting in 2003.  It has been shipping in
Copan (now SGI) products since 2005.

It was ported to FreeBSD in 2008, and thanks to an agreement between SGI
(who acquired Copan's assets in 2010) and Spectra Logic in 2010, CTL is
available under a BSD-style license.  The intent behind the agreement was
that Spectra would work to get CTL into the FreeBSD tree.

Some CTL features:

 - Disk and processor device emulation.
 - Tagged queueing
 - SCSI task attribute support (ordered, head of queue, simple tags)
 - SCSI implicit command ordering support.  (e.g. if a read follows a mode
   select, the read will be blocked until the mode select completes.)
 - Full task management support (abort, LUN reset, target reset, etc.)
 - Support for multiple ports
 - Support for multiple simultaneous initiators
 - Support for multiple simultaneous backing stores
 - Persistent reservation support
 - Mode sense/select support
 - Error injection support
 - High Availability support (1)
 - All I/O handled in-kernel, no userland context switch overhead.

(1) HA Support is just an API stub, and needs much more to be fully
    functional.

ctl.c:			The core of CTL.  Command handlers and processing,
			character driver, and HA support are here.

ctl.h:			Basic function declarations and data structures.

ctl_backend.c,
ctl_backend.h:		The basic CTL backend API.

ctl_backend_block.c,
ctl_backend_block.h:	The block and file backend.  This allows for using
			a disk or a file as the backing store for a LUN.
			Multiple threads are started to do I/O to the
			backing device, primarily because the VFS API
			requires that to get any concurrency.

ctl_backend_ramdisk.c:	A "fake" ramdisk backend.  It only allocates a
			small amount of memory to act as a source and sink
			for reads and writes from an initiator.  Therefore
			it cannot be used for any real data, but it can be
			used to test for throughput.  It can also be used
			to test initiators' support for extremely large LUNs.

ctl_cmd_table.c:	This is a table with all 256 possible SCSI opcodes,
			and command handler functions defined for supported
			opcodes.

ctl_debug.h:		Debugging support.

ctl_error.c,
ctl_error.h:		CTL-specific wrappers around the CAM sense building
			functions.

ctl_frontend.c,
ctl_frontend.h:		These files define the basic CTL frontend port API.

ctl_frontend_cam_sim.c:	This is a CTL frontend port that is also a CAM SIM.
			This frontend allows for using CTL without any
			target-capable hardware.  So any LUNs you create in
			CTL are visible in CAM via this port.

ctl_frontend_internal.c,
ctl_frontend_internal.h:
			This is a frontend port written for Copan to do
			some system-specific tasks that required sending
			commands into CTL from inside the kernel.  This
			isn't entirely relevant to FreeBSD in general,
			but can perhaps be repurposed.

ctl_ha.h:		This is a stubbed-out High Availability API.  Much
			more is needed for full HA support.  See the
			comments in the header and the description of what
			is needed in the README.ctl.txt file for more
			details.

ctl_io.h:		This defines most of the core CTL I/O structures.
			union ctl_io is conceptually very similar to CAM's
			union ccb.

ctl_ioctl.h:		This defines all ioctls available through the CTL
			character device, and the data structures needed
			for those ioctls.

ctl_mem_pool.c,
ctl_mem_pool.h:		Generic memory pool implementation used by the
			internal frontend.

ctl_private.h:		Private data structres (e.g. CTL softc) and
			function prototypes.  This also includes the SCSI
			vendor and product names used by CTL.

ctl_scsi_all.c,
ctl_scsi_all.h:		CTL wrappers around CAM sense printing functions.

ctl_ser_table.c:	Command serialization table.  This defines what
			happens when one type of command is followed by
			another type of command.

ctl_util.c,
ctl_util.h:		CTL utility functions, primarily designed to be
			used from userland.  See ctladm for the primary
			consumer of these functions.  These include CDB
			building functions.

scsi_ctl.c:		CAM target peripheral driver and CTL frontend port.
			This is the path into CTL for commands from
			target-capable hardware/SIMs.

README.ctl.txt:		CTL code features, roadmap, to-do list.

usr.sbin/Makefile:	Add ctladm.

ctladm/Makefile,
ctladm/ctladm.8,
ctladm/ctladm.c,
ctladm/ctladm.h,
ctladm/util.c:		ctladm(8) is the CTL management utility.
			It fills a role similar to camcontrol(8).
			It allow configuring LUNs, issuing commands,
			injecting errors and various other control
			functions.

usr.bin/Makefile:	Add ctlstat.

ctlstat/Makefile
ctlstat/ctlstat.8,
ctlstat/ctlstat.c:	ctlstat(8) fills a role similar to iostat(8).
			It reports I/O statistics for CTL.

sys/conf/files:		Add CTL files.

sys/conf/NOTES:		Add device ctl.

sys/cam/scsi_all.h:	To conform to more recent specs, the inquiry CDB
			length field is now 2 bytes long.

			Add several mode page definitions for CTL.

sys/cam/scsi_all.c:	Handle the new 2 byte inquiry length.

sys/dev/ciss/ciss.c,
sys/dev/ata/atapi-cam.c,
sys/cam/scsi/scsi_targ_bh.c,
scsi_target/scsi_cmds.c,
mlxcontrol/interface.c:	Update for 2 byte inquiry length field.

scsi_da.h:		Add versions of the format and rigid disk pages
			that are in a more reasonable format for CTL.

amd64/conf/GENERIC,
i386/conf/GENERIC,
ia64/conf/GENERIC,
sparc64/conf/GENERIC:	Add device ctl.

i386/conf/PAE:		The CTL frontend SIM at least does not compile
			cleanly on PAE.

Sponsored by:	Copan Systems, SGI and Spectra Logic
MFC after:	1 month
2012-01-12 00:34:33 +00:00