Browse Source

[fc] Hold reference to peers and ULPs while calling fc_link_examine()

Allow link examination methods to safely assume that their
self-reference remains valid for the duration of the method call.

Signed-off-by: Michael Brown <mcb30@ipxe.org>
tags/v1.20.1
Michael Brown 13 years ago
parent
commit
c09f87e3b7
1 changed files with 16 additions and 4 deletions
  1. 16
    4
      src/net/fc.c

+ 16
- 4
src/net/fc.c View File

@@ -982,8 +982,11 @@ int fc_port_login ( struct fc_port *port, struct fc_port_id *port_id,
982 982
 	fc_link_up ( &port->link );
983 983
 
984 984
 	/* Notify peers of link state change */
985
-	list_for_each_entry_safe ( peer, tmp, &fc_peers, list )
985
+	list_for_each_entry_safe ( peer, tmp, &fc_peers, list ) {
986
+		fc_peer_get ( peer );
986 987
 		fc_link_examine ( &peer->link );
988
+		fc_peer_put ( peer );
989
+	}
987 990
 
988 991
 	return 0;
989 992
 }
@@ -1008,8 +1011,11 @@ void fc_port_logout ( struct fc_port *port, int rc ) {
1008 1011
 	fc_link_err ( &port->link, rc );
1009 1012
 
1010 1013
 	/* Notify peers of link state change */
1011
-	list_for_each_entry_safe ( peer, tmp, &fc_peers, list )
1014
+	list_for_each_entry_safe ( peer, tmp, &fc_peers, list ) {
1015
+		fc_peer_get ( peer );
1012 1016
 		fc_link_examine ( &peer->link );
1017
+		fc_peer_put ( peer );
1018
+	}
1013 1019
 }
1014 1020
 
1015 1021
 /**
@@ -1274,8 +1280,11 @@ int fc_peer_login ( struct fc_peer *peer, struct fc_port *port,
1274 1280
 	fc_link_up ( &peer->link );
1275 1281
 
1276 1282
 	/* Notify ULPs of link state change */
1277
-	list_for_each_entry_safe ( ulp, tmp, &peer->ulps, list )
1283
+	list_for_each_entry_safe ( ulp, tmp, &peer->ulps, list ) {
1284
+		fc_ulp_get ( ulp );
1278 1285
 		fc_link_examine ( &ulp->link );
1286
+		fc_ulp_put ( ulp );
1287
+	}
1279 1288
 
1280 1289
 	return 0;
1281 1290
 }
@@ -1305,8 +1314,11 @@ void fc_peer_logout ( struct fc_peer *peer, int rc ) {
1305 1314
 	fc_link_err ( &peer->link, rc );
1306 1315
 
1307 1316
 	/* Notify ULPs of link state change */
1308
-	list_for_each_entry_safe ( ulp, tmp, &peer->ulps, list )
1317
+	list_for_each_entry_safe ( ulp, tmp, &peer->ulps, list ) {
1318
+		fc_ulp_get ( ulp );
1309 1319
 		fc_link_examine ( &ulp->link );
1320
+		fc_ulp_put ( ulp );
1321
+	}
1310 1322
 
1311 1323
 	/* Close peer if there are no active users */
1312 1324
 	if ( peer->usage == 0 )

Loading…
Cancel
Save