From 32725f904828b0b05e28b91b9cbf6eca382ed4a3 Mon Sep 17 00:00:00 2001 From: Bart Van Assche Date: Sat, 4 Jun 2011 12:36:03 +0000 Subject: [PATCH] ib_srpt: Introduce the function srpt_set_ch_state_to_draining() git-svn-id: http://svn.code.sf.net/p/scst/svn/trunk@3527 d57e44dd-8a1f-0410-8b47-8ef2f437770f --- srpt/src/ib_srpt.c | 28 ++++++++++++++++++++++------ 1 file changed, 22 insertions(+), 6 deletions(-) diff --git a/srpt/src/ib_srpt.c b/srpt/src/ib_srpt.c index 6c38cb4dd..e213d2397 100644 --- a/srpt/src/ib_srpt.c +++ b/srpt/src/ib_srpt.c @@ -186,6 +186,27 @@ srpt_set_ch_state(struct srpt_rdma_ch *ch, enum rdma_ch_state new_state) return prev; } +static bool srpt_set_ch_state_to_draining(struct srpt_rdma_ch *ch) +{ + unsigned long flags; + bool changed_state = false; + + spin_lock_irqsave(&ch->spinlock, flags); + switch (ch->state) { + case CH_CONNECTING: + case CH_LIVE: + case CH_DISCONNECTING: + ch->state = CH_DRAINING; + changed_state = true; + break; + default: + break; + } + spin_unlock_irqrestore(&ch->spinlock, flags); + + return changed_state; +} + /** * srpt_test_and_set_ch_state() - Test and set the channel state. * @@ -2092,12 +2113,7 @@ static void srpt_drain_channel(struct ib_cm_id *cm_id) spin_lock_irq(&sdev->spinlock); list_for_each_entry(ch, &sdev->rch_list, list) { if (ch->cm_id == cm_id) { - do_reset = srpt_test_and_set_ch_state(ch, - CH_CONNECTING, CH_DRAINING) || - srpt_test_and_set_ch_state(ch, - CH_LIVE, CH_DRAINING) || - srpt_test_and_set_ch_state(ch, - CH_DISCONNECTING, CH_DRAINING); + do_reset = srpt_set_ch_state_to_draining(ch); break; } }