RE: [openib-general] Re: [PATCH][26/26] IB: MAD cancel callbacks fromthread

From: Sean Hefty
Date: Thu Mar 03 2005 - 19:48:30 EST


>Roland Dreier wrote:
>> +void cancel_sends(void *data)
>> +{
>> + struct ib_mad_agent_private *mad_agent_priv;
>> + struct ib_mad_send_wr_private *mad_send_wr;
>> + struct ib_mad_send_wc mad_send_wc;
>> + unsigned long flags;
>> +
>> + mad_agent_priv = (struct ib_mad_agent_private *)data;
>
>don't add casts to a void pointer, that's silly.

This is my bad.

>> + mad_send_wc.status = IB_WC_WR_FLUSH_ERR;
>> + mad_send_wc.vendor_err = 0;
>> +
>> + spin_lock_irqsave(&mad_agent_priv->lock, flags);
>> + while (!list_empty(&mad_agent_priv->canceled_list)) {
>> + mad_send_wr = list_entry(mad_agent_priv->canceled_list.next,
>> + struct ib_mad_send_wr_private,
>> + agent_list);
>> +
>> + list_del(&mad_send_wr->agent_list);
>> + spin_unlock_irqrestore(&mad_agent_priv->lock, flags);
>> +
>> + mad_send_wc.wr_id = mad_send_wr->wr_id;
>> + mad_agent_priv->agent.send_handler(&mad_agent_priv->agent,
>> + &mad_send_wc);
>> +
>> + kfree(mad_send_wr);
>> + if (atomic_dec_and_test(&mad_agent_priv->refcount))
>> + wake_up(&mad_agent_priv->wait);
>> + spin_lock_irqsave(&mad_agent_priv->lock, flags);
>> + }
>> + spin_unlock_irqrestore(&mad_agent_priv->lock, flags);
>
>dumb question... why is the lock dropped? is it just for the
>send_handler(), or also for wr_id assigned, kfree, and wake_up() ?

The lock is dropped to avoid calling the user back with it held. The if
statement / wake_up call near the bottom of the loop can be replaced with a
simple atomic_dec. The test should always fail. The lock is to protect
access to the canceled_list.

(Sorry about the mailer...)

- Sean

-
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/