[openib-general] [PATCH] ib_mad: Version/Class/Method table locking

Hal Rosenstock halr at voltaire.com
Sun Sep 12 05:04:34 PDT 2004


ib_mad: Version/Class/Method table locking

Index: ib_mad.c
===================================================================
--- ib_mad.c	(revision 789)
+++ ib_mad.c	(working copy)
@@ -168,24 +168,6 @@
 		goto error1;
 	}
 
-	/* 
-	 * Make sure MAD registration (if supplied)
-	 * is non overlapping with any existing ones
-	 */
-	if (mad_reg_req) {
-		class = priv->version[mad_reg_req->mgmt_class_version];
-		if (class) {
-			mgmt_class = convert_mgmt_class(mad_reg_req);
-			method = class->method_table[mgmt_class];
-			if (method) {
-				if (is_method_in_use(&method, mad_reg_req)) {
-					ret = ERR_PTR(-EINVAL);
-					goto error1;
-				}
-			}
-		}
-	}
-
 	/* Allocate structures */
 	mad_agent = kmalloc(sizeof *mad_agent, GFP_KERNEL);
 	mad_agent_priv = kmalloc(sizeof *mad_agent_priv, GFP_KERNEL);
@@ -204,6 +186,27 @@
 		memcpy(reg_req, mad_reg_req, sizeof *reg_req);
 	} 
 
+	spin_lock_irqsave(&priv->reg_lock, flags);
+
+	/*
+	 * Make sure MAD registration (if supplied)
+	 * is non overlapping with any existing ones
+	 */
+	if (mad_reg_req) {
+		class = priv->version[mad_reg_req->mgmt_class_version];
+		if (class) {
+			mgmt_class = convert_mgmt_class(mad_reg_req);
+			method = class->method_table[mgmt_class];
+			if (method) {
+				if (is_method_in_use(&method, mad_reg_req)) {
+					spin_unlock_irqrestore(&priv->reg_lock, flags);
+					ret = ERR_PTR(-EINVAL);
+					goto error2;
+				}
+			}
+		}
+	}
+
 	/* Now, fill in the various structures */
 	memset(mad_agent_priv, 0, sizeof *mad_agent_priv);
 	mad_agent_priv->agent = mad_agent;
@@ -223,6 +226,7 @@
 	spin_unlock_irqrestore(&ib_mad_agent_list_lock, flags);
 
 	ret2 = add_mad_reg_req(mad_reg_req, mad_agent_priv);
+	spin_unlock_irqrestore(&priv->reg_lock, flags);
 	if (ret2) {
 		ret = ERR_PTR(ret2);	
 		goto error3;	
@@ -1123,6 +1127,7 @@
 	device->mad = priv;
 	priv->device = device;
 	priv->port = port;
+	spin_lock_init(&priv->reg_lock);
 	for (i = 0; i < MAX_MGMT_VERSION; i++) {
 		priv->version[i] = NULL;
 	}
Index: ib_mad_priv.h
===================================================================
--- ib_mad_priv.h	(revision 788)
+++ ib_mad_priv.h	(working copy)
@@ -125,12 +125,14 @@
 	struct ib_mad_port_private *next;
 	struct ib_device *device;
 	int port;
-	struct ib_mad_mgmt_class_table *version[MAX_MGMT_VERSION];
 	struct ib_qp *qp[IB_MAD_QPS_SUPPORTED];
 	struct ib_cq *cq;
 	struct ib_pd *pd;
 	struct ib_mr *mr;
 
+	spinlock_t reg_lock;
+	struct ib_mad_mgmt_class_table *version[MAX_MGMT_VERSION];
+
 	spinlock_t send_list_lock;
 	struct list_head send_posted_mad_list;
 	int send_posted_mad_count;
Index: TODO
===================================================================
--- TODO	(revision 790)
+++ TODO	(working copy)
@@ -4,7 +4,6 @@
 
 Short Term
 Fix list handling
-Version/Class/Method table locking
 Client ID table
 Use wait queue and wait_event rather than signals and semaphores
 Finish receive path coding





More information about the general mailing list