Kaynağa Gözat

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

tags/v0.9.3
Michael Brown 17 yıl önce
ebeveyn
işleme
b22d4405c0
2 değiştirilmiş dosya ile 26 ekleme ve 0 silme
  1. 3
    0
      src/include/gpxe/aoe.h
  2. 23
    0
      src/net/aoe.c

+ 3
- 0
src/include/gpxe/aoe.h Dosyayı Görüntüle

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

+ 23
- 0
src/net/aoe.c Dosyayı Görüntüle

@@ -76,6 +76,12 @@ static int aoe_send_command ( struct aoe_session *aoe ) {
76 76
 	unsigned int count;
77 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 85
 	/* Calculate count and data_out_len for this subcommand */
80 86
 	count = command->cb.count.native;
81 87
 	if ( count > AOE_MAX_COUNT )
@@ -259,6 +265,19 @@ struct net_protocol aoe_protocol __net_protocol = {
259 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 282
  * Open AoE session
264 283
  *
@@ -269,6 +288,8 @@ void aoe_open ( struct aoe_session *aoe ) {
269 288
 		 sizeof ( aoe->target ) );
270 289
 	aoe->tag = AOE_TAG_MAGIC;
271 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 293
 	list_add ( &aoe->list, &aoe_sessions );
273 294
 }
274 295
 
@@ -278,6 +299,8 @@ void aoe_open ( struct aoe_session *aoe ) {
278 299
  * @v aoe		AoE session
279 300
  */
280 301
 void aoe_close ( struct aoe_session *aoe ) {
302
+	if ( aoe->netdev )
303
+		ref_del ( &aoe->netdev_ref );
281 304
 	list_del ( &aoe->list );
282 305
 }
283 306
 

Loading…
İptal
Kaydet