[openib-general] [PATCH] ib_cancel_mad API

Sean Hefty mshefty at ichips.intel.com
Thu Sep 30 12:36:14 PDT 2004


On Thu, 30 Sep 2004 10:06:36 -0700
"Fab Tillier" <ftillier at infiniconsys.com> wrote:

> I find the "goto found" syntax ugly and confusing.  It seems unnatural to
> jump over the unlock like that.

Does this patch (version 3) seem more natural and less confusing to you?  :)

- Sean

Index: access/ib_mad.c
===================================================================
--- access/ib_mad.c	(revision 915)
+++ access/ib_mad.c	(working copy)
@@ -1026,6 +1026,65 @@
 	}
 }
 
+static struct ib_mad_send_wr_private*
+find_send_by_wr_id(struct ib_mad_agent_private *mad_agent_priv,
+		   u64 wr_id)
+{
+	struct ib_mad_send_wr_private *mad_send_wr;
+
+	list_for_each_entry(mad_send_wr, &mad_agent_priv->send_list,
+			    agent_send_list) {
+		if (mad_send_wr->wr_id == wr_id)
+			return mad_send_wr;
+	}
+	return NULL;
+}
+
+void ib_cancel_mad(struct ib_mad_agent *mad_agent,
+		  u64 wr_id)
+{
+	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 = container_of(mad_agent, struct ib_mad_agent_private,
+				      agent);
+	spin_lock_irqsave(&mad_agent_priv->send_list_lock, flags);
+	mad_send_wr = find_send_by_wr_id(mad_agent_priv, wr_id);
+	if (!mad_send_wr) {
+		spin_unlock_irqrestore(&mad_agent_priv->send_list_lock, flags);
+		return;
+	}
+
+	if (mad_send_wr->status == IB_WC_SUCCESS)
+		mad_send_wr->status = IB_WC_WR_FLUSH_ERR;
+
+	if (mad_send_wr->timeout_ms) {
+		mad_send_wr->timeout_ms = 0;
+		mad_send_wr->refcount--;
+	}
+
+	if (mad_send_wr->refcount != 0) {
+		spin_unlock_irqrestore(&mad_agent_priv->send_list_lock, flags);
+		return;
+	}
+
+	list_del(&mad_send_wr->agent_send_list);
+	spin_unlock_irqrestore(&mad_agent_priv->send_list_lock, flags);
+
+	mad_send_wc.status = IB_WC_WR_FLUSH_ERR;
+	mad_send_wc.vendor_err = 0;
+	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);
+}
+EXPORT_SYMBOL(ib_cancel_mad);
+
 /*
  * IB MAD thread
  */
Index: include/ib_mad.h
===================================================================
--- include/ib_mad.h	(revision 915)
+++ include/ib_mad.h	(working copy)
@@ -275,6 +275,17 @@
 void ib_free_recv_mad(struct ib_mad_recv_wc *mad_recv_wc);
 
 /**
+ * ib_cancel_mad - Cancels an outstanding send MAD operation.
+ * @mad_agent - Specifies the registration associated with sent MAD.
+ * @wr_id - Indicates the work request identifier of the MAD to cancel.
+ *
+ * MADs will be returned to the user through the corresponding 
+ * ib_mad_send_handler.
+ */
+void ib_cancel_mad(struct ib_mad_agent *mad_agent,
+		   u64 wr_id);
+
+/**
  * ib_redirect_mad_qp - Registers a QP for MAD services.
  * @qp - Reference to a QP that requires MAD services.
  * @rmpp_version - If set, indicates that the client will send



More information about the general mailing list