Use ctl_set_success() instead of direct inlining.

MFC after:	1 week

(cherry picked from commit 029391b08904011dd57ebd772aeb6b7c9620be5d)
(cherry picked from commit f29b391cf55b674019751bc211a8240a021286f2)
Replace home-grown CTL IO allocator with UMA.

Old allocator created significant lock congestion protecting its lists
of preallocated I/Os, while UMA provides much better SMP scalability.
The downside of UMA is lack of reliable preallocation, that could guarantee
successful allocation in non-sleepable environments.  But careful code
review shown, that only CAM target frontend really has that requirement.
Fix that making that frontend preallocate and statically bind CTL I/O for
every ATIO/INOT it preallocates any way.  That allows to avoid allocations
in hot I/O path.  Other frontends either may sleep in allocation context
or can properly handle allocation errors.

On 40-core server with 6 ZVOL-backed LUNs and 7 iSCSI client connections
this change increases peak performance from ~700K to >1M IOPS!  Yay! :)

MFC after:	1 month
Sponsored by:	iXsystems, Inc.

(cherry picked from commit 6c036a86ca2410c1186647bf2d76a30f953ffe92)

Conflicts:
	sys/cam/ctl/scsi_ctl.c

(cherry picked from commit 9d1a065cdd43659a56f3e459c2237eac1dcb740e)
Decouple datamove/done logic from CTL status set.

(cherry picked from commit 15164a21934a9630dff789459335bc2d18cceb10)

Conflicts:
	sys/cam/ctl/scsi_ctl.c

(cherry picked from commit 77e5b4788d1a4806594983507fe567b4bc1dc947)
Coalesce last data move and command status for read commands.

Make CTL core and block backend set success status before initiating last
data move for read commands.  Make CAM target and iSCSI frontends detect
such condition and send command status together with data.  New I/O flag
allows to skip duplicate status sending on later fe_done() call.

For Fibre Channel this change saves one of three interrupts per read command,
increasing performance from 126K to 160K IOPS.  For iSCSI this change saves
one of three PDUs per read command, increasing performance from 1M to 1.2M
IOPS.

MFC after:	1 month
Sponsored by:	iXsystems, Inc.

(cherry picked from commit 115d2f3c0bcc4cd75986c7f6ec8a1e9bd379df14)

Conflicts:
	sys/cam/ctl/ctl.c

(cherry picked from commit 592e5ae17a11035791d4d1ef3fcafd0e0c9b4094)
Removed unused variable and unify some names.

(cherry picked from commit 5fd40975d0bc93d30eeb8e699153a7c957b25a0e)
(cherry picked from commit 71c55df633bcf2ed59b9218016df67d4f0296554)
Reduce code duplication by creating ctl_set_res_ua() helper.

(cherry picked from commit 01c057650ce8b923893fa2c0e4b7a7e259883752)
(cherry picked from commit ffca1fb689e85c776bcba4607ecae19ec465e337)
Convert persis_offset from global variable to softc field.

(cherry picked from commit 23b376789b87f152bc5cb2e9647422f23bca9b61)
(cherry picked from commit d2f4741ceabaf2fe164c8d3812267a523227a8c4)
Do not pre-allocate reservation keys memory for every possible initiator.

In configurations with many ports, like iSCSI, each LUN is typically
accessed only by limited subset of ports.  Allocating that memory on
demand allows to reduce CTL memory usage from 5.3MB/LUN to 1.3MB/LUN.

MFC after:	1 month

(cherry picked from commit 826327d5dbd4663217586bd43ca25540e6effa4b)
(cherry picked from commit b785f40544c6c8852859ae6ab684027d9a09ef44)
Remove some unused code.

(cherry picked from commit 3167e2db4c943873e00c698889aa7aa92149f2c9)
(cherry picked from commit bf32df6d45f3d5197a48dfdaf73045d7d1643652)
Do not pre-allocate UNIT ATTENTIONs storage for every possible initiator.

Abusing ability of major UAs cover minor ones we may not account UAs for
inactive ports.  Allocate UAs storage for port and start accounting only
after some initiator from that port fetched its first POWER ON OCCURRED.

This reduces per-LUN CTL memory usage from >1MB to less then 100K.

MFC after:	1 month

(cherry picked from commit b087af8dc4d3cb722513deff2cf2495435a68e3a)
(cherry picked from commit c604ed384087d51252805eb8c11c95a402a13e5e)
Unify function names after r275458.

MFC after:	1 month

(cherry picked from commit 4c8c231b28bd5a8a0641516dae108054f908f65e)
(cherry picked from commit 63016681988fc186cbdfd12d532e598eab0e4da5)
Increase CTL ports limit from 128 to 256 and LUNs limit from 256 to 1024.

After recent optimizations this change is no longer blocked by CTL memory
consumption.  Those limits are still not free, but much cheaper now.

MFC after:	1 week
Relnotes:	yes
Sponsored by:	iXsystems, Inc.

(cherry picked from commit 0955bcdd21e020edd95513ac47f8b1f36da050d4)
(cherry picked from commit e0ec81c86d18942aa7332a4f9141ae98e4d3fa3f)
Add GET LBA STATUS command support to CTL.

It is implemented for LUNs backed by ZVOLs in "dev" mode and files.
GEOM has no such API, so for LUNs backed by raw devices all LBAs will
be reported as mapped/unknown.

MFC after:	2 weeks
Sponsored by:	iXsystems, Inc.

(cherry picked from commit 7884d9292abc7321b1da3091721ea068911a877f)
(cherry picked from commit 8fb9db418374b62842a79e6522e7538f93c70e8a)
Add to CTL support for threshold notifications for file-backed LUNs.

Previously it was supported only for ZVOL-backed LUNs, but now should work
for file-backed LUNs too.  Used value in this case is a space occupied by
the backing file, while available value is an available space on file
system.  Pool thresholds are still not implemented in this case.

MFC after:	2 weeks
Sponsored by:	iXsystems, Inc.

(cherry picked from commit 8f8bb7915235e95da464a872d6afc9737ac4fe8e)
(cherry picked from commit 4e9ad04f35af768e8e4d31c36304d36c961ec94f)
In addition to r275481 allow threshold notifications work without UNMAP.

While without UNMAP support there is not much initiator can do about it,
the administrator still better be notified about the storage overflow.

MFC after:	2 weeks
Sponsored by:	iXsystems, Inc.

(cherry picked from commit 04a19682d2176279276964dfe860b5e9e18ec299)
(cherry picked from commit ab48c58e60a6dce0557810b273fbcfbb37a3e2c9)
Do not count RCTD bit set as an error.

We can not really implement it, but specification tells that it "shall"
work, so it can be safely ignored.

MFC after:	1 week

(cherry picked from commit 22481bc2c20ca4fd2e3eb219fce7c3b16e226b98)
(cherry picked from commit 2504b4e03ca8853c86e361da4a74f3e76e5c86a3)