Make CTL block backend return proper error code for operations unsupposed
by the underlying device.

MFC after:	2 weeks

(cherry picked from commit a6a173909d79f12a0c86dcc0d1be7164392c427f)
(cherry picked from commit e86cae40f6b30e3da5013b7410f7500bf10b8810)
Fix extremely slow operation with data digests enabled.  This was caused
by receive code waiting for data digest even when the data segment was
empty.  It didn't actually read it, but it waited until those four bytes
become available in the socket buffer, i.e. until any other PDU (such as NOP)
came in.

PR:		kern/185240
MFC after:	2 weeks
Sponsored by:	The FreeBSD Foundation

(cherry picked from commit 379b2b0f9aa593406dd96b85f183e2f1e49a9aab)
(cherry picked from commit ffd54b37c840e856325af2d3d6867d10e3d58bb9)
Fix a rare "truncated checksums" problem, which manifested like this:

WARNING: icl_pdu_check_data_digest: data digest check failed; got 0xf23b,
    should be 0xdb7f23b

Tested by:	Darcy Birkbeck
MFC after:	2 weeks
Sponsored by:	The FreeBSD Foundation

(cherry picked from commit d0cf88a92be080f09cbd053fbe48534485a2e377)
(cherry picked from commit afb6252962c10786b1fbcb686a9bd73ad43314a8)
Fail connection upon receiving too large data segment.

Approved by:	re (glebius)
Sponsored by:	FreeBSD Foundation

(cherry picked from commit a111dd548bde80502ea143ef148b2ebf06c8bbc8)
(cherry picked from commit bb0e265dbb2c4c1e60c85992d167c1b32f8713fe)
Fix hang on reboot with active iSCSI connections.

MFC after:	3 days
Sponsored by:	The FreeBSD Foundation

(cherry picked from commit 015cdc2535764e4ad04ba03731ed49daf21b0241)
(cherry picked from commit 60eccb64f722a5b697f0c7e22c17aff5ebf8b975)
Properly refuse handoff requests on already connected sessions.  Previously
this would result in dropping the session.

MFC after:	2 days
Sponsored by:	The FreeBSD Foundation

(cherry picked from commit 47cb60687b1d726069c7831a3ce3ca7cb091fc66)
(cherry picked from commit a3c6e83809a829a7e177699862848b3d66e6b976)
The log_whatever() routines don't accept NULL for format strings,
so mark them as __printflike instead of __printf0like.

Sponsored by:	The FreeBSD Foundation

(cherry picked from commit a2246187e5b593b6d37161db2df4ffaa082db84c)
(cherry picked from commit 06e6f576ecc0f670ccb752f00f4424ceaa4cdeca)
Empty data segment during Login Phase is rather unlikely, but it's not
a protocol error.

Sponsored by:	The FreeBSD Foundation

(cherry picked from commit 39c661e770208d4268cf375c3739c4fd8d42ba80)
(cherry picked from commit 3941c05154c808ab6d7730995601fe7cfe748add)
So, it turns out SIGCHLD is discarded by default, so we have to set up
a dummy handler to make it interrupt an ioctl(2) or select(2).

This makes those short-lived iscsid(8) zombies disappear.

Sponsored by:	The FreeBSD Foundation

(cherry picked from commit 14f5d801bfbeb0a4072d335619a59571ff034192)
(cherry picked from commit 926c03d24ad25c729301c9c034dcc4b5ae164fd3)
Fix typo.

Submitted by:	feld@
MFC after:	3 days
Sponsored by:	The FreeBSD Foundation

(cherry picked from commit c5a7ee096891dcbde23a8f4200233a467870a044)
(cherry picked from commit 023daadaf8a3d87abd56c1db5ef87fe9469c741d)
Fix typos.

MFC after:	3 days
Sponsored by:	The FreeBSD Foundation

(cherry picked from commit e3b2accfd9b121a0ba0ddff89daf3ff5d9690f15)
(cherry picked from commit acb476155c194baccfd52ccd0a74d438f0ede8e4)
Grammar fix.

MFC after:	3 days
Sponsored by:	The FreeBSD Foundation

(cherry picked from commit 6149217d805edb23d34c07d73a2e64763d37b788)
(cherry picked from commit 72350e8ecd11dcf9652b80ba29d3bc807f4495df)
Fix handling for empty auth-groups.  Without it, ctld child process
would either exit on assertion, or, if assertions are not enabled,
fail to authenticate the target.

MFC after:	2 days
Sponsored by:	The FreeBSD Foundation

(cherry picked from commit 9e76667e13878eb4ec51fdf820a831b0f7b9a6a0)
(cherry picked from commit 53b1287e126021144dbf21b50ab36f8aa553ca47)
Refactor.

Sponsored by:	The FreeBSD Foundation

(cherry picked from commit 942aab7c51325d88004aa825b2c9d8e315099a49)
(cherry picked from commit 698a708ddf00ec0dd2a270092588f0dfef168a7c)
Improve check for duplicated paths.  It shows the warning twice for
every path (once for each duplicate found), but it should do for now.

Sponsored by:	The FreeBSD Foundation

(cherry picked from commit f0306f793fa079fb2ba6a25d3df5ddc0a0d7524c)
(cherry picked from commit 8ae7f454f518bb79c5866d5eef0d370324cbf0dd)
The log_whatever() routines don't accept NULL for format strings,
so mark them as __printflike instead of__printf0like.

Sponsored by:	The FreeBSD Foundation

(cherry picked from commit 1d16ec7ceeb9b54c249c5ff3cb5472da7f3d9b45)
(cherry picked from commit a1dd1ab1fed214502e2271c655462caeda640222)
Empty data segment during Login Phase is rather unlikely, but it's
not, by itself, a protocol error.  This fixes interoperability with
OpenBSD initiator.

Sponsored by:	The FreeBSD Foundation

(cherry picked from commit e4b6e911a2dcde72418067d8c09105f8f8d1382f)
(cherry picked from commit 678cf130c8d472c67db64b9d05e9dc478dcef0e3)
Daemonize after applying configuration, not before, so that
any problems - including "daemon already running" - are visible
on the terminal and not just in logs.

Sponsored by:	The FreeBSD Foundation

(cherry picked from commit b84432b20cfa69f9c2d4d1bbe92ddf04e101e92d)
(cherry picked from commit 47a0273e369e626636449d73088630c2967de703)
Implement initiator-name and initiator-portal restrictions.

Sponsored by:	The FreeBSD Foundation

(cherry picked from commit fec3636fbdc2e427a2cc2fa123981ec14a638897)
(cherry picked from commit aaa8d94b5ae854c744c515c81f2f7a8d9c983ef0)
Make function ordering slightly more logical; no functional changes.

Sponsored by:	The FreeBSD Foundation

(cherry picked from commit 760495fbd7c1f574a762688313e2c5b116b7c79f)
(cherry picked from commit 64595afc09f3b6d71509bd47cdd30dbe7a3788be)