Browse Source

[retry] Hold reference while timer is running and during expiry callback

Guarantee that a retry timer cannot go out of scope while the timer is
running, and provide a guarantee to the expiry callback that the timer
will remain in scope during the entire callback (similar to the
guarantee provided to interface methods).

Signed-off-by: Michael Brown <mcb30@ipxe.org>
tags/v1.20.1
Michael Brown 14 years ago
parent
commit
28934eef81
10 changed files with 31 additions and 14 deletions
  1. 10
    1
      src/include/ipxe/retry.h
  2. 1
    1
      src/net/aoe.c
  3. 1
    1
      src/net/infiniband/ib_mi.c
  4. 1
    1
      src/net/ipv4.c
  5. 8
    2
      src/net/retry.c
  6. 2
    2
      src/net/tcp.c
  7. 2
    2
      src/net/udp/dhcp.c
  8. 1
    1
      src/net/udp/dns.c
  9. 4
    2
      src/net/udp/slam.c
  10. 1
    1
      src/net/udp/tftp.c

+ 10
- 1
src/include/ipxe/retry.h View File

@@ -49,6 +49,12 @@ struct retry_timer {
49 49
 	 * timeout has already exceeded @c MAX_TIMEOUT.
50 50
 	 */
51 51
 	void ( * expired ) ( struct retry_timer *timer, int over );
52
+	/** Reference counter
53
+	 *
54
+	 * If this interface is not part of a reference-counted
55
+	 * object, this field may be NULL.
56
+	 */
57
+	struct refcnt *refcnt;
52 58
 };
53 59
 
54 60
 /**
@@ -56,11 +62,14 @@ struct retry_timer {
56 62
  *
57 63
  * @v timer		Retry timer
58 64
  * @v expired		Timer expired callback
65
+ * @v refcnt		Reference counter, or NULL
59 66
  */
60 67
 static inline __attribute__ (( always_inline )) void
61 68
 timer_init ( struct retry_timer *timer,
62
-	     void ( * expired ) ( struct retry_timer *timer, int over ) ) {
69
+	     void ( * expired ) ( struct retry_timer *timer, int over ),
70
+	     struct refcnt *refcnt ) {
63 71
 	timer->expired = expired;
72
+	timer->refcnt = refcnt;
64 73
 }
65 74
 
66 75
 extern void start_timer ( struct retry_timer *timer );

+ 1
- 1
src/net/aoe.c View File

@@ -439,7 +439,7 @@ int aoe_attach ( struct ata_device *ata, struct net_device *netdev,
439 439
 	if ( ! aoe )
440 440
 		return -ENOMEM;
441 441
 	ref_init ( &aoe->refcnt, aoe_free );
442
-	timer_init ( &aoe->timer, aoe_timer_expired );
442
+	timer_init ( &aoe->timer, aoe_timer_expired, &aoe->refcnt );
443 443
 	aoe->netdev = netdev_get ( netdev );
444 444
 	memcpy ( aoe->target, netdev->ll_broadcast, sizeof ( aoe->target ) );
445 445
 	aoe->tag = AOE_TAG_MAGIC;

+ 1
- 1
src/net/infiniband/ib_mi.c View File

@@ -281,7 +281,7 @@ ib_create_madx ( struct ib_device *ibdev, struct ib_mad_interface *mi,
281 281
 	madx = zalloc ( sizeof ( *madx ) );
282 282
 	if ( ! madx )
283 283
 		return NULL;
284
-	timer_init ( &madx->timer, ib_mi_timer_expired );
284
+	timer_init ( &madx->timer, ib_mi_timer_expired, NULL );
285 285
 	madx->mi = mi;
286 286
 	madx->op = op;
287 287
 

+ 1
- 1
src/net/ipv4.c View File

@@ -222,7 +222,7 @@ static struct io_buffer * ipv4_reassemble ( struct io_buffer * iobuf ) {
222 222
 		free_iob ( iobuf );
223 223
 
224 224
 		/* Set the reassembly timer */
225
-		timer_init ( &fragbuf->frag_timer, ipv4_frag_expired );
225
+		timer_init ( &fragbuf->frag_timer, ipv4_frag_expired, NULL );
226 226
 		start_timer_fixed ( &fragbuf->frag_timer, IP_FRAG_TIMEOUT );
227 227
 
228 228
 		/* Add the fragment buffer to the list of fragment buffers */

+ 8
- 2
src/net/retry.c View File

@@ -57,8 +57,10 @@ static LIST_HEAD ( timers );
57 57
  * be stopped and the timer's callback function will be called.
58 58
  */
59 59
 void start_timer ( struct retry_timer *timer ) {
60
-	if ( ! timer->running )
60
+	if ( ! timer->running ) {
61 61
 		list_add ( &timer->list, &timers );
62
+		ref_get ( timer->refcnt );
63
+	}
62 64
 	timer->start = currticks();
63 65
 	timer->running = 1;
64 66
 
@@ -136,6 +138,8 @@ void stop_timer ( struct retry_timer *timer ) {
136 138
 			      timer, timer->timeout );
137 139
 		}
138 140
 	}
141
+
142
+	ref_put ( timer->refcnt );
139 143
 }
140 144
 
141 145
 /**
@@ -164,7 +168,9 @@ static void timer_expired ( struct retry_timer *timer ) {
164 168
 	      timer, timer->timeout );
165 169
 
166 170
 	/* Call expiry callback */
167
-	timer->expired ( timer, fail );	
171
+	timer->expired ( timer, fail );
172
+
173
+	ref_put ( timer->refcnt );
168 174
 }
169 175
 
170 176
 /**

+ 2
- 2
src/net/tcp.c View File

@@ -265,8 +265,8 @@ static int tcp_open ( struct interface *xfer, struct sockaddr *peer,
265 265
 	DBGC ( tcp, "TCP %p allocated\n", tcp );
266 266
 	ref_init ( &tcp->refcnt, NULL );
267 267
 	intf_init ( &tcp->xfer, &tcp_xfer_desc, &tcp->refcnt );
268
-	timer_init ( &tcp->timer, tcp_expired );
269
-	timer_init ( &tcp->wait, tcp_wait_expired );
268
+	timer_init ( &tcp->timer, tcp_expired, &tcp->refcnt );
269
+	timer_init ( &tcp->wait, tcp_wait_expired, &tcp->refcnt );
270 270
 	tcp->prev_tcp_state = TCP_CLOSED;
271 271
 	tcp->tcp_state = TCP_STATE_SENT ( TCP_SYN );
272 272
 	tcp_dump_state ( tcp );

+ 2
- 2
src/net/udp/dhcp.c View File

@@ -1425,7 +1425,7 @@ int start_dhcp ( struct interface *job, struct net_device *netdev ) {
1425 1425
 	ref_init ( &dhcp->refcnt, dhcp_free );
1426 1426
 	intf_init ( &dhcp->job, &dhcp_job_desc, &dhcp->refcnt );
1427 1427
 	intf_init ( &dhcp->xfer, &dhcp_xfer_desc, &dhcp->refcnt );
1428
-	timer_init ( &dhcp->timer, dhcp_timer_expired );
1428
+	timer_init ( &dhcp->timer, dhcp_timer_expired, &dhcp->refcnt );
1429 1429
 	dhcp->netdev = netdev_get ( netdev );
1430 1430
 	dhcp->local.sin_family = AF_INET;
1431 1431
 	dhcp->local.sin_port = htons ( BOOTPC_PORT );
@@ -1528,7 +1528,7 @@ int start_pxebs ( struct interface *job, struct net_device *netdev,
1528 1528
 	ref_init ( &dhcp->refcnt, dhcp_free );
1529 1529
 	intf_init ( &dhcp->job, &dhcp_job_desc, &dhcp->refcnt );
1530 1530
 	intf_init ( &dhcp->xfer, &dhcp_xfer_desc, &dhcp->refcnt );
1531
-	timer_init ( &dhcp->timer, dhcp_timer_expired );
1531
+	timer_init ( &dhcp->timer, dhcp_timer_expired, &dhcp->refcnt );
1532 1532
 	dhcp->netdev = netdev_get ( netdev );
1533 1533
 	dhcp->local.sin_family = AF_INET;
1534 1534
 	fetch_ipv4_setting ( netdev_settings ( netdev ), &ip_setting,

+ 1
- 1
src/net/udp/dns.c View File

@@ -527,7 +527,7 @@ static int dns_resolv ( struct interface *resolv,
527 527
 	ref_init ( &dns->refcnt, NULL );
528 528
 	intf_init ( &dns->resolv, &dns_resolv_desc, &dns->refcnt );
529 529
 	intf_init ( &dns->socket, &dns_socket_desc, &dns->refcnt );
530
-	timer_init ( &dns->timer, dns_timer_expired );
530
+	timer_init ( &dns->timer, dns_timer_expired, &dns->refcnt );
531 531
 	memcpy ( &dns->sa, sa, sizeof ( dns->sa ) );
532 532
 
533 533
 	/* Create query */

+ 4
- 2
src/net/udp/slam.c View File

@@ -695,8 +695,10 @@ static int slam_open ( struct interface *xfer, struct uri *uri ) {
695 695
 	intf_init ( &slam->xfer, &slam_xfer_desc, &slam->refcnt );
696 696
 	intf_init ( &slam->socket, &slam_socket_desc, &slam->refcnt );
697 697
 	intf_init ( &slam->mc_socket, &slam_mc_socket_desc, &slam->refcnt );
698
-	timer_init ( &slam->master_timer, slam_master_timer_expired );
699
-	timer_init ( &slam->slave_timer, slam_slave_timer_expired );
698
+	timer_init ( &slam->master_timer, slam_master_timer_expired,
699
+		     &slam->refcnt );
700
+	timer_init ( &slam->slave_timer, slam_slave_timer_expired,
701
+		     &slam->refcnt );
700 702
 	/* Fake an invalid cached header of { 0x00, ... } */
701 703
 	slam->header_len = 1;
702 704
 	/* Fake parameters for initial NACK */

+ 1
- 1
src/net/udp/tftp.c View File

@@ -1097,7 +1097,7 @@ static int tftp_core_open ( struct interface *xfer, struct uri *uri,
1097 1097
 	intf_init ( &tftp->xfer, &tftp_xfer_desc, &tftp->refcnt );
1098 1098
 	intf_init ( &tftp->socket, &tftp_socket_desc, &tftp->refcnt );
1099 1099
 	intf_init ( &tftp->mc_socket, &tftp_mc_socket_desc, &tftp->refcnt );
1100
-	timer_init ( &tftp->timer, tftp_timer_expired );
1100
+	timer_init ( &tftp->timer, tftp_timer_expired, &tftp->refcnt );
1101 1101
 	tftp->uri = uri_get ( uri );
1102 1102
 	tftp->blksize = TFTP_DEFAULT_BLKSIZE;
1103 1103
 	tftp->flags = flags;

Loading…
Cancel
Save