Преглед изворни кода

[ifmgmt] Move link-up status messages from autoboot() to iflinkwait()

With the addition of link status codes, we can now display a detailed
error indication if iflinkwait() fails.

Putting the error output in iflinkwait avoids code duplication, and
gains symmetry with the other interface management routines; ifopen()
already prints an error directly if it cannot open its interface.

Modified-by: Michael Brown <mcb30@etherboot.org>
Signed-off-by: Michael Brown <mcb30@etherboot.org>
tags/v0.9.8
Joshua Oreman пре 16 година
родитељ
комит
4125216a2f
2 измењених фајлова са 28 додато и 12 уклоњено
  1. 1
    5
      src/usr/autoboot.c
  2. 27
    7
      src/usr/ifmgmt.c

+ 1
- 5
src/usr/autoboot.c Прегледај датотеку

154
 	ifstat ( netdev );
154
 	ifstat ( netdev );
155
 
155
 
156
 	/* Wait for link-up */
156
 	/* Wait for link-up */
157
-	printf ( "Waiting for link-up on %s...", netdev->name );
158
-	if ( ( rc = iflinkwait ( netdev, LINK_WAIT_MS ) ) != 0 ) {
159
-		printf ( " no link detected\n" );
157
+	if ( ( rc = iflinkwait ( netdev, LINK_WAIT_MS ) ) != 0 )
160
 		return rc;
158
 		return rc;
161
-	}
162
-	printf ( " ok\n" );
163
 
159
 
164
 	/* Configure device via DHCP */
160
 	/* Configure device via DHCP */
165
 	if ( ( rc = dhcp ( netdev ) ) != 0 )
161
 	if ( ( rc = dhcp ( netdev ) ) != 0 )

+ 27
- 7
src/usr/ifmgmt.c Прегледај датотеку

103
 }
103
 }
104
 
104
 
105
 /**
105
 /**
106
- * Wait for link-up
106
+ * Wait for link-up, with status indication
107
  *
107
  *
108
  * @v netdev		Network device
108
  * @v netdev		Network device
109
  * @v max_wait_ms	Maximum time to wait, in ms
109
  * @v max_wait_ms	Maximum time to wait, in ms
110
  */
110
  */
111
 int iflinkwait ( struct net_device *netdev, unsigned int max_wait_ms ) {
111
 int iflinkwait ( struct net_device *netdev, unsigned int max_wait_ms ) {
112
 	int key;
112
 	int key;
113
+	int rc;
114
+
115
+	if ( netdev_link_ok ( netdev ) )
116
+		return 0;
117
+
118
+	printf ( "Waiting for link-up on %s...", netdev->name );
113
 
119
 
114
 	while ( 1 ) {
120
 	while ( 1 ) {
115
-		if ( netdev_link_ok ( netdev ) )
116
-			return 0;
117
-		if ( max_wait_ms-- == 0 )
118
-			return -ETIMEDOUT;
121
+		if ( netdev_link_ok ( netdev ) ) {
122
+			rc = 0;
123
+			break;
124
+		}
125
+		if ( max_wait_ms-- == 0 ) {
126
+			rc = netdev->link_rc;
127
+			break;
128
+		}
119
 		step();
129
 		step();
120
 		if ( iskey() ) {
130
 		if ( iskey() ) {
121
 			key = getchar();
131
 			key = getchar();
122
-			if ( key == CTRL_C )
123
-				return -ECANCELED;
132
+			if ( key == CTRL_C ) {
133
+				rc = -ECANCELED;
134
+				break;
135
+			}
124
 		}
136
 		}
125
 		mdelay ( 1 );
137
 		mdelay ( 1 );
126
 	}
138
 	}
139
+
140
+	if ( rc == 0 ) {
141
+		printf ( " ok\n" );
142
+	} else {
143
+		printf ( " failed: %s\n", strerror ( rc ) );
144
+	}
145
+
146
+	return rc;
127
 }
147
 }

Loading…
Откажи
Сачувај