瀏覽代碼

[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 15 年之前
父節點
當前提交
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,12 +154,8 @@ static int netboot ( struct net_device *netdev ) {
154 154
 	ifstat ( netdev );
155 155
 
156 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 158
 		return rc;
161
-	}
162
-	printf ( " ok\n" );
163 159
 
164 160
 	/* Configure device via DHCP */
165 161
 	if ( ( rc = dhcp ( netdev ) ) != 0 )

+ 27
- 7
src/usr/ifmgmt.c 查看文件

@@ -103,25 +103,45 @@ void ifstat ( struct net_device *netdev ) {
103 103
 }
104 104
 
105 105
 /**
106
- * Wait for link-up
106
+ * Wait for link-up, with status indication
107 107
  *
108 108
  * @v netdev		Network device
109 109
  * @v max_wait_ms	Maximum time to wait, in ms
110 110
  */
111 111
 int iflinkwait ( struct net_device *netdev, unsigned int max_wait_ms ) {
112 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 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 129
 		step();
120 130
 		if ( iskey() ) {
121 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 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…
取消
儲存