ib_srp: Enlarge block layer timeout

Enlarge the block layer timeout for disks such that it is above
the InfiniBand transport layer timeout. This is necessary to avoid
that an SRP response is received after the SCSI layer has already
killed the associated SCSI command.

Signed-off-by: Bart Van Assche <bvanassche@acm.org>
Cc: David Dillow <dillowda@ornl.gov>
Cc: Roland Dreier <roland@purestorage.com>
ib_srp: Introduce srp_handle_qp_err()

Move the IB completion handler error handling code into the new
function srp_handle_qp_err(). Convert srp_target_port.qp_in_error
from int to bool. Move the initialization of that variable into
srp_connect_target(). Help the CPU branch predictor by making it
clear that IB_WC_SUCCESS is the most likely case.

Signed-off-by: Bart Van Assche <bvanassche@acm.org>
Cc: David Dillow <dillowda@ornl.gov>
Cc: Roland Dreier <roland@purestorage.com>
ib_srp: Micro-optimize srp_queuecommand()

Block the SCSI host while reconnecting instead of representing
this as a distinct SRP target state.

Signed-off-by: Bart Van Assche <bvanassche@acm.org>
Cc: David Dillow <dillowda@ornl.gov>
Cc: Roland Dreier <roland@purestorage.com>
ib_srp: Suppress superfluous error messages

Keep track of the connection state. Don't send any data over the
QP after it has been disconnected. Only report QP errors while
connected. Only invoke ib_send_cm_dreq() when connected such that
invoking srp_disconnect_target() after having received a DREQ
does not cause an error message to be printed.

Signed-off-by: Bart Van Assche <bvanassche@acm.org>
Cc: David Dillow <dillowda@ornl.gov>
Cc: Roland Dreier <roland@purestorage.com>
ib_srp: Avoid that SCSI error handling triggers a crash

Sending any data over a queue pair associated with a closed
connection is wrong. The HCA will send the data anyway and such
data may be sent to another system to a queue pair that is in use.
The data will get processed and a response will be sent back. That
can result in ib_srp complaining about "Null scmnd for RSP ..."
followed by a kernel oops.

Signed-off-by: Bart Van Assche <bvanassche@acm.org>
Cc: David Dillow <dillowda@ornl.gov>
Cc: Roland Dreier <roland@purestorage.com>
ib_srp: Introduce the helper function srp_remove_target()

Signed-off-by: Bart Van Assche <bvanassche@acm.org>
Cc: David Dillow <dillowda@ornl.gov>
Cc: Roland Dreier <roland@purestorage.com>
ib_srp: Eliminate state SRP_TARGET_DEAD

Only queue removal work after having changed the target state
into SRP_TARGET_REMOVED and not if that state was already equal
to SRP_TARGET_REMOVED. That allows to remove the state
SRP_TARGET_DEAD. Add a call to srp_disconnect_target() in
srp_remove_target() - due to previous changes it is now safe to
invoke that last function even if the IB connection has already
been disconnected. This change allows to replace the target
removal code in srp_remove_one() by a call to srp_remove_target().
Rename srp_target_port.work into srp_target_port.remove_work to
reflect its usage. Move function srp_change_state() to just
before srp_change_state_to_removed() to avoid having to
introduce a forward declaration.

Signed-off-by: Bart Van Assche <bvanassche@acm.org>
Cc: David Dillow <dillowda@ornl.gov>
Cc: Roland Dreier <roland@purestorage.com>
ib_srp: Make srp_disconnect_target() wait for IB completions

Modify srp_disconnect_target() such that it waits until it is
sure that no new IB completions will be received.

Signed-off-by: Bart Van Assche <bvanassche@acm.org>
Cc: David Dillow <dillowda@ornl.gov>
Cc: Roland Dreier <roland@purestorage.com>
srp_transport: Fix atttribute registration

Register transport attributes after the attribute array has been
set up instead of before. The current code can trigger a race
condition because the code reading the attribute array can run
on another thread than the code that initialized that array.
Make sure that any code reading the attribute array will see all
values written into that array.

Signed-off-by: Bart Van Assche <bvanassche@acm.org>
Cc: FUJITA Tomonori <fujita.tomonori@lab.ntt.co.jp>
Cc: Brian King <brking@linux.vnet.ibm.com>
Cc: David Dillow <dillowda@ornl.gov>
Cc: Roland Dreier <roland@purestorage.com>
Cc: <stable@kernel.org>
srp_transport: Simplify attribute initialization code

Eliminate the private_rport_attrs[] array and the SETUP_*() macros
used to set up that array since the information in that array
duplicates the information in the static device attributes. Also,
verify whether SRP_RPORT_ATTRS is large enough since it is easy
to forget to update that macro when adding new attributes.

Signed-off-by: Bart Van Assche <bvanassche@acm.org>
Cc: FUJITA Tomonori <fujita.tomonori@lab.ntt.co.jp>
Cc: Brian King <brking@linux.vnet.ibm.com>
Cc: David Dillow <dillowda@ornl.gov>
Cc: Roland Dreier <roland@purestorage.com>
srp_transport: Document sysfs attributes

Signed-off-by: Bart Van Assche <bvanassche@acm.org>
Cc: FUJITA Tomonori <fujita.tomonori@lab.ntt.co.jp>
Cc: Brian King <brking@linux.vnet.ibm.com>
Cc: David Dillow <dillowda@ornl.gov>
Cc: Roland Dreier <roland@purestorage.com>
ib_srp: Document sysfs attributes

Document the sysfs attributes of the SRP initiator (ib_srp) according
to the rules specified in Documentation/ABI/README.

Signed-off-by: Bart Van Assche <bvanassche@acm.org>
Cc: David Dillow <dillowda@ornl.gov>
Cc: Roland Dreier <roland@purestorage.com>
ib_srp: Allow SRP disconnect through sysfs

Make it possible to disconnect the IB RC connection used by the
SRP protocol to communicate with a target.

Let the SRP transport layer create a sysfs "delete" attribute for
initiator drivers that support this functionality.

Signed-off-by: Bart Van Assche <bvanassche@acm.org>
Cc: David Dillow <dillowda@ornl.gov>
Cc: Roland Dreier <roland@purestorage.com>
Cc: FUJITA Tomonori <fujita.tomonori@lab.ntt.co.jp>
Cc: Brian King <brking@linux.vnet.ibm.com>
ib_srp: Introduce a temporary variable in srp_remove_target()

Signed-off-by: Bart Van Assche <bvanassche@acm.org>
Cc: David Dillow <dillowda@ornl.gov>
Cc: Roland Dreier <roland@purestorage.com>
ib_srp: Maintain a single connection per I_T nexus

The sysfs attribute 'add_target' may be used to relogin to a
target. An SRP target that receives a second login request from
an initiator will disconnect the previous connection. So before
trying to reconnect, check whether another connection to the
same SRP target identifier already exists. If so, remove the
target port.  Add a target to the target list before connecting
instead of after such that this algorithm has a chance to work.

Signed-off-by: Bart Van Assche <bvanassche@acm.org>
Cc: David Dillow <dillowda@ornl.gov>
Cc: Roland Dreier <roland@purestorage.com>
ib_srp: Avoid that reconnecting triggers a kernel warning

Avoid that the following kernel warning is triggered by a failed
relogin:

WARNING: at fs/sysfs/file.c:498 sysfs_attr_ns+0x99/0xa0()

Call Trace:
 [<ffffffff81037e9f>] warn_slowpath_common+0x7f/0xc0
 [<ffffffff81037f96>] warn_slowpath_fmt+0x46/0x50
 [<ffffffff81089e9d>] ? trace_hardirqs_off+0xd/0x10
 [<ffffffff811b8ab9>] sysfs_attr_ns+0x99/0xa0
 [<ffffffff811b8ae4>] sysfs_remove_file+0x24/0x50
 [<ffffffff812b2247>] device_remove_file+0x17/0x20
 [<ffffffffa04ca040>] srp_remove_target+0x60/0xe0 [ib_srp]
 [<ffffffffa04ca2a4>] srp_remove_work+0x64/0x90 [ib_srp]
 [<ffffffffa04cbfde>] srp_create_target+0x3ae/0xfe0 [ib_srp]
 [<ffffffff812b14f0>] dev_attr_store+0x20/0x30
 [<ffffffff811b82d6>] sysfs_write_file+0xe6/0x170
 [<ffffffff8114d36e>] vfs_write+0xce/0x170
 [<ffffffff8114d674>] sys_write+0x54/0xa0
 [<ffffffff81407012>] system_call_fastpath+0x16/0x1b

This change is necessary due to commit
ce597919361dcec97341151690e780eade2a9cf4.

Signed-off-by: Bart Van Assche <bvanassche@acm.org>
ib_srp: Keep processing commands while scsi_remove_host() is in progress
ib_srp: Make it safe to invoke srp_abort() before the transport layer timeout elapsed
ib_srp: Stop queueing if QP in error