IB/srp: consolidate state change code
Signed-off-by: Bart Van Assche <bvanassche@acm.org> [ broken out and small cleanups by David Dillow ] Signed-off-by: David Dillow <dillowda@ornl.gov>
This commit is contained in:
parent
f8b6e31e4e
commit
9709f0e05b
1 changed files with 24 additions and 21 deletions
|
@ -441,18 +441,28 @@ static void srp_disconnect_target(struct srp_target_port *target)
|
||||||
wait_for_completion(&target->done);
|
wait_for_completion(&target->done);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static bool srp_change_state(struct srp_target_port *target,
|
||||||
|
enum srp_target_state old,
|
||||||
|
enum srp_target_state new)
|
||||||
|
{
|
||||||
|
bool changed = false;
|
||||||
|
|
||||||
|
spin_lock_irq(target->scsi_host->host_lock);
|
||||||
|
if (target->state == old) {
|
||||||
|
target->state = new;
|
||||||
|
changed = true;
|
||||||
|
}
|
||||||
|
spin_unlock_irq(target->scsi_host->host_lock);
|
||||||
|
return changed;
|
||||||
|
}
|
||||||
|
|
||||||
static void srp_remove_work(struct work_struct *work)
|
static void srp_remove_work(struct work_struct *work)
|
||||||
{
|
{
|
||||||
struct srp_target_port *target =
|
struct srp_target_port *target =
|
||||||
container_of(work, struct srp_target_port, work);
|
container_of(work, struct srp_target_port, work);
|
||||||
|
|
||||||
spin_lock_irq(target->scsi_host->host_lock);
|
if (!srp_change_state(target, SRP_TARGET_DEAD, SRP_TARGET_REMOVED))
|
||||||
if (target->state != SRP_TARGET_DEAD) {
|
|
||||||
spin_unlock_irq(target->scsi_host->host_lock);
|
|
||||||
return;
|
return;
|
||||||
}
|
|
||||||
target->state = SRP_TARGET_REMOVED;
|
|
||||||
spin_unlock_irq(target->scsi_host->host_lock);
|
|
||||||
|
|
||||||
spin_lock(&target->srp_host->target_lock);
|
spin_lock(&target->srp_host->target_lock);
|
||||||
list_del(&target->list);
|
list_del(&target->list);
|
||||||
|
@ -560,13 +570,8 @@ static int srp_reconnect_target(struct srp_target_port *target)
|
||||||
struct ib_wc wc;
|
struct ib_wc wc;
|
||||||
int ret;
|
int ret;
|
||||||
|
|
||||||
spin_lock_irq(target->scsi_host->host_lock);
|
if (!srp_change_state(target, SRP_TARGET_LIVE, SRP_TARGET_CONNECTING))
|
||||||
if (target->state != SRP_TARGET_LIVE) {
|
|
||||||
spin_unlock_irq(target->scsi_host->host_lock);
|
|
||||||
return -EAGAIN;
|
return -EAGAIN;
|
||||||
}
|
|
||||||
target->state = SRP_TARGET_CONNECTING;
|
|
||||||
spin_unlock_irq(target->scsi_host->host_lock);
|
|
||||||
|
|
||||||
srp_disconnect_target(target);
|
srp_disconnect_target(target);
|
||||||
/*
|
/*
|
||||||
|
@ -605,13 +610,8 @@ static int srp_reconnect_target(struct srp_target_port *target)
|
||||||
if (ret)
|
if (ret)
|
||||||
goto err;
|
goto err;
|
||||||
|
|
||||||
spin_lock_irq(target->scsi_host->host_lock);
|
if (!srp_change_state(target, SRP_TARGET_CONNECTING, SRP_TARGET_LIVE))
|
||||||
if (target->state == SRP_TARGET_CONNECTING) {
|
|
||||||
ret = 0;
|
|
||||||
target->state = SRP_TARGET_LIVE;
|
|
||||||
} else
|
|
||||||
ret = -EAGAIN;
|
ret = -EAGAIN;
|
||||||
spin_unlock_irq(target->scsi_host->host_lock);
|
|
||||||
|
|
||||||
return ret;
|
return ret;
|
||||||
|
|
||||||
|
@ -621,9 +621,12 @@ static int srp_reconnect_target(struct srp_target_port *target)
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* We couldn't reconnect, so kill our target port off.
|
* We couldn't reconnect, so kill our target port off.
|
||||||
* However, we have to defer the real removal because we might
|
* However, we have to defer the real removal because we
|
||||||
* be in the context of the SCSI error handler now, which
|
* are in the context of the SCSI error handler now, which
|
||||||
* would deadlock if we call scsi_remove_host().
|
* will deadlock if we call scsi_remove_host().
|
||||||
|
*
|
||||||
|
* Schedule our work inside the lock to avoid a race with
|
||||||
|
* the flush_scheduled_work() in srp_remove_one().
|
||||||
*/
|
*/
|
||||||
spin_lock_irq(target->scsi_host->host_lock);
|
spin_lock_irq(target->scsi_host->host_lock);
|
||||||
if (target->state == SRP_TARGET_CONNECTING) {
|
if (target->state == SRP_TARGET_CONNECTING) {
|
||||||
|
|
Loading…
Reference in a new issue