[openib-general] [PATCH v2 2/2] local_sa: use SA iterator routines to walk attributes in RMPP response

Sean Hefty sean.hefty at intel.com
Thu Aug 3 10:39:43 PDT 2006


Convert local SA to use the new SA iterator 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)
@@ -107,16 +107,6 @@ struct sa_db_device {
 	struct sa_db_port port[0];
 };
 
-/* Define path record format to enable needed checks against MAD data. */
-struct ib_path_rec {
-	u8	reserved[8];
-	u8	dgid[16];
-	u8	sgid[16];
-	__be16	dlid;
-	__be16	slid;
-	u8	reserved2[20];
-};
-
 struct ib_sa_cursor {
 	struct ib_sa_cursor	*next;
 };
@@ -194,60 +184,27 @@ 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_iter *iter;
 	struct ib_path_rec_info *path_info;
-	struct ib_path_rec ib_path, *path = NULL;
-	int i, attr_size, left, offset = 0;
+	void *attr;
 
-	attr_size = be16_to_cpu(mad->sa_hdr.attr_offset) * 8;
-	if (attr_size < sizeof ib_path)
+	iter = ib_sa_iter_create(mad_recv_wc);
+	if (IS_ERR(iter))
 		return;
 
 	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 ((attr = ib_sa_iter_next(iter)) &&
+	       (path_info = kmalloc(sizeof *path_info, GFP_KERNEL))) {
+
+		ib_sa_unpack_attr(&path_info->rec, attr, IB_SA_ATTR_PATH_REC);
+		if (insert_attr(&port->index, port->update,
+				path_info->rec.dgid.raw,
+				&path_info->cursor))
+			break;
 	}
-unlock:
 	up_write(&lock);
+	ib_sa_iter_free(iter);
 }
 
 static void recv_handler(struct ib_mad_agent *mad_agent,





More information about the general mailing list