[openib-general] [RFC] [PATCH 2/2] local_sa: use new SA cursor routines to walk attributes in RMPP response

Sean Hefty sean.hefty at intel.com
Tue Aug 1 15:22:24 PDT 2006


Convert local SA to use the new SA cursor routines for walking a
list of attributes in an RMPP response returned by the SA.  This
replaces a local SA specific implementation.

Signed-off-by: Sean Hefty <sean.hefty at intel.com>
---
Index: core/local_sa.c
===================================================================
--- core/local_sa.c	(revision 8647)
+++ core/local_sa.c	(working copy)
@@ -194,60 +194,34 @@ static int insert_attr(struct index_root
 static void update_path_rec(struct sa_db_port *port,
 			    struct ib_mad_recv_wc *mad_recv_wc)
 {
-	struct ib_mad_recv_buf *recv_buf;
-	struct ib_sa_mad *mad = (void *) mad_recv_wc->recv_buf.mad;
+	struct ib_sa_attr_cursor *cursor;
 	struct ib_path_rec_info *path_info;
-	struct ib_path_rec ib_path, *path = NULL;
-	int i, attr_size, left, offset = 0;
 
-	attr_size = be16_to_cpu(mad->sa_hdr.attr_offset) * 8;
-	if (attr_size < sizeof ib_path)
+	cursor = ib_sa_create_cursor(mad_recv_wc);
+	if (IS_ERR(cursor))
 		return;
 
+	path_info = kmalloc(sizeof *path_info, GFP_KERNEL);
+	if (!path_info)
+		goto free_cursor;
+
 	down_write(&lock);
 	port->update++;
-	list_for_each_entry(recv_buf, &mad_recv_wc->rmpp_list, list) {
-		for (i = 0; i < IB_MGMT_SA_DATA;) {
-			mad = (struct ib_sa_mad *) recv_buf->mad;
-
-			left = IB_MGMT_SA_DATA - i;
-			if (left < sizeof ib_path) {
-				/* copy first piece of the attribute */
-				memcpy(&ib_path, &mad->data[i], left);
-				path = &ib_path;
-				offset = left;
-				break;
-			} else if (offset) {
-				/* copy the second piece of the attribute */
-				memcpy((void*) path + offset, &mad->data[i],
-				       sizeof ib_path - offset);
-				i += attr_size - offset;
-				offset = 0;
-			} else {
-				path = (void *) &mad->data[i];
-				i += attr_size;
-			}
-
-			if (!path->slid)
-				goto unlock;
-
-			path_info = kmalloc(sizeof *path_info, GFP_KERNEL);
-			if (!path_info)
-				goto unlock;
-
-			ib_sa_unpack_attr(&path_info->rec, path,
-					  IB_SA_ATTR_PATH_REC);
-
-			if (insert_attr(&port->index, port->update,
-					path_info->rec.dgid.raw,
-					&path_info->cursor)) {
-				kfree(path_info);
-				goto unlock;
-			}
-		}
+	while (ib_sa_get_next_attr(cursor, &path_info->rec)) {
+		if (insert_attr(&port->index, port->update,
+				path_info->rec.dgid.raw,
+				&path_info->cursor))
+			break;
+
+		path_info = kmalloc(sizeof *path_info, GFP_KERNEL);
+		if (!path_info)
+			break;
 	}
-unlock:
+
 	up_write(&lock);
+	kfree(path_info);
+free_cursor:
+	ib_sa_free_cursor(cursor);
 }
 
 static void recv_handler(struct ib_mad_agent *mad_agent,





More information about the general mailing list