[openib-general] [PATCH] ib_agent: In agent_mad_send, destroy address handle on send completion rather than immediately

Hal Rosenstock halr at voltaire.com
Wed Oct 27 10:49:15 PDT 2004


ib_agent: In agent_mad_send, destroy address handle on send completion
rather than immediately

Index: ib_agent_priv.h
===================================================================
--- ib_agent_priv.h	(revision 1071)
+++ ib_agent_priv.h	(working copy)
@@ -32,6 +32,7 @@
 
 struct ib_agent_send_wr {
 	struct list_head send_list;
+	struct ib_ah *ah;
 	struct ib_mad *mad;
 	DECLARE_PCI_UNMAP_ADDR(mapping)
 };
Index: ib_agent.c
===================================================================
--- ib_agent.c	(revision 1077)
+++ ib_agent.c	(working copy)
@@ -350,7 +350,6 @@
 	struct ib_send_wr send_wr;
 	struct ib_send_wr *bad_send_wr;
 	struct ib_ah_attr ah_attr;
-	struct ib_ah *ah;
 	unsigned long flags;
 
 	/* Find matching MAD agent */
@@ -404,14 +403,14 @@
 		ah_attr.ah_flags = 0; /* No GRH */
 	}
 
-	ah = ib_create_ah(mad_agent->qp->pd, &ah_attr);
-	if (IS_ERR(ah)) {
+	agent_send_wr->ah = ib_create_ah(mad_agent->qp->pd, &ah_attr);
+	if (IS_ERR(agent_send_wr->ah)) {
 		printk(KERN_ERR SPFX "No memory for address handle\n");
 		kfree(mad);
 		return;
 	}
                                                                                 
-	send_wr.wr.ud.ah = ah;
+	send_wr.wr.ud.ah = agent_send_wr->ah;
 	if (mad->mad_hdr.mgmt_class == IB_MGMT_CLASS_PERF_MGMT) {
 		send_wr.wr.ud.pkey_index = mad_recv_wc->wc->pkey_index;
 		send_wr.wr.ud.remote_qkey = IB_QP1_QKEY;
@@ -427,16 +426,17 @@
 	/* Send */
 	spin_lock_irqsave(&port_priv->send_list_lock, flags);
 	if (ib_post_send_mad(mad_agent, &send_wr, &bad_send_wr)) {
+		spin_unlock_irqrestore(&port_priv->send_list_lock, flags);
 		pci_unmap_single(mad_agent->device->dma_device,
 				 pci_unmap_addr(agent_send_wr, mapping),
 				 sizeof(struct ib_mad),
 				 PCI_DMA_TODEVICE);
+		ib_destroy_ah(agent_send_wr->ah);
 	} else {
 		list_add_tail(&agent_send_wr->send_list,
 			      &port_priv->send_posted_list);
+		spin_unlock_irqrestore(&port_priv->send_list_lock, flags);
 	}
-	spin_unlock_irqrestore(&port_priv->send_list_lock, flags);
-	ib_destroy_ah(ah);
 }
 
 int smi_send_smp(struct ib_mad_agent *mad_agent,
@@ -590,6 +590,8 @@
 			 sizeof(struct ib_mad),
 			 PCI_DMA_TODEVICE);
 
+	ib_destroy_ah(agent_send_wr->ah);
+
 	/* Release allocated memory */
 	kfree(agent_send_wr->mad);
 }






More information about the general mailing list