Commit Graph

69 Commits

Author SHA1 Message Date
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