Browse Source

An AoE session holds a persistent reference to a net device.

tags/v0.9.3
Michael Brown 18 years ago
parent
commit
b22d4405c0
2 changed files with 26 additions and 0 deletions
  1. 3
    0
      src/include/gpxe/aoe.h
  2. 23
    0
      src/net/aoe.c

+ 3
- 0
src/include/gpxe/aoe.h View File

86
 
86
 
87
 	/** Network device */
87
 	/** Network device */
88
 	struct net_device *netdev;
88
 	struct net_device *netdev;
89
+	/** Reference to network device */
90
+	struct reference netdev_ref;
91
+
89
 	/** Major number */
92
 	/** Major number */
90
 	uint16_t major;
93
 	uint16_t major;
91
 	/** Minor number */
94
 	/** Minor number */

+ 23
- 0
src/net/aoe.c View File

76
 	unsigned int count;
76
 	unsigned int count;
77
 	unsigned int data_out_len;
77
 	unsigned int data_out_len;
78
 
78
 
79
+	/* Fail immediately if we have no netdev to send on */
80
+	if ( ! aoe->netdev ) {
81
+		aoe_done ( aoe, -ENETUNREACH );
82
+		return -ENETUNREACH;
83
+	}
84
+
79
 	/* Calculate count and data_out_len for this subcommand */
85
 	/* Calculate count and data_out_len for this subcommand */
80
 	count = command->cb.count.native;
86
 	count = command->cb.count.native;
81
 	if ( count > AOE_MAX_COUNT )
87
 	if ( count > AOE_MAX_COUNT )
259
 	.rx = aoe_rx,
265
 	.rx = aoe_rx,
260
 };
266
 };
261
 
267
 
268
+/**
269
+ * Forget reference to net_device
270
+ *
271
+ * @v ref		Persistent reference
272
+ */
273
+static void aoe_forget_netdev ( struct reference *ref ) {
274
+	struct aoe_session *aoe
275
+		= container_of ( ref, struct aoe_session, netdev_ref );
276
+
277
+	aoe->netdev = NULL;
278
+	ref_del ( &aoe->netdev_ref );
279
+}
280
+
262
 /**
281
 /**
263
  * Open AoE session
282
  * Open AoE session
264
  *
283
  *
269
 		 sizeof ( aoe->target ) );
288
 		 sizeof ( aoe->target ) );
270
 	aoe->tag = AOE_TAG_MAGIC;
289
 	aoe->tag = AOE_TAG_MAGIC;
271
 	aoe->timer.expired = aoe_timer_expired;
290
 	aoe->timer.expired = aoe_timer_expired;
291
+	aoe->netdev_ref.forget = aoe_forget_netdev;
292
+	ref_add ( &aoe->netdev_ref, &aoe->netdev->references );
272
 	list_add ( &aoe->list, &aoe_sessions );
293
 	list_add ( &aoe->list, &aoe_sessions );
273
 }
294
 }
274
 
295
 
278
  * @v aoe		AoE session
299
  * @v aoe		AoE session
279
  */
300
  */
280
 void aoe_close ( struct aoe_session *aoe ) {
301
 void aoe_close ( struct aoe_session *aoe ) {
302
+	if ( aoe->netdev )
303
+		ref_del ( &aoe->netdev_ref );
281
 	list_del ( &aoe->list );
304
 	list_del ( &aoe->list );
282
 }
305
 }
283
 
306
 

Loading…
Cancel
Save