From 4125216a2f88c1e4c9fd33931d1249b8afc2f923 Mon Sep 17 00:00:00 2001 From: Joshua Oreman Date: Fri, 19 Jun 2009 02:08:21 -0700 Subject: [PATCH] [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 Signed-off-by: Michael Brown --- src/usr/autoboot.c | 6 +----- src/usr/ifmgmt.c | 34 +++++++++++++++++++++++++++------- 2 files changed, 28 insertions(+), 12 deletions(-) diff --git a/src/usr/autoboot.c b/src/usr/autoboot.c index a99d12b1..41b6d3f4 100644 --- a/src/usr/autoboot.c +++ b/src/usr/autoboot.c @@ -154,12 +154,8 @@ static int netboot ( struct net_device *netdev ) { ifstat ( netdev ); /* Wait for link-up */ - printf ( "Waiting for link-up on %s...", netdev->name ); - if ( ( rc = iflinkwait ( netdev, LINK_WAIT_MS ) ) != 0 ) { - printf ( " no link detected\n" ); + if ( ( rc = iflinkwait ( netdev, LINK_WAIT_MS ) ) != 0 ) return rc; - } - printf ( " ok\n" ); /* Configure device via DHCP */ if ( ( rc = dhcp ( netdev ) ) != 0 ) diff --git a/src/usr/ifmgmt.c b/src/usr/ifmgmt.c index 2c4b3d24..97cde4a0 100644 --- a/src/usr/ifmgmt.c +++ b/src/usr/ifmgmt.c @@ -103,25 +103,45 @@ void ifstat ( struct net_device *netdev ) { } /** - * Wait for link-up + * Wait for link-up, with status indication * * @v netdev Network device * @v max_wait_ms Maximum time to wait, in ms */ int iflinkwait ( struct net_device *netdev, unsigned int max_wait_ms ) { int key; + int rc; + + if ( netdev_link_ok ( netdev ) ) + return 0; + + printf ( "Waiting for link-up on %s...", netdev->name ); while ( 1 ) { - if ( netdev_link_ok ( netdev ) ) - return 0; - if ( max_wait_ms-- == 0 ) - return -ETIMEDOUT; + if ( netdev_link_ok ( netdev ) ) { + rc = 0; + break; + } + if ( max_wait_ms-- == 0 ) { + rc = netdev->link_rc; + break; + } step(); if ( iskey() ) { key = getchar(); - if ( key == CTRL_C ) - return -ECANCELED; + if ( key == CTRL_C ) { + rc = -ECANCELED; + break; + } } mdelay ( 1 ); } + + if ( rc == 0 ) { + printf ( " ok\n" ); + } else { + printf ( " failed: %s\n", strerror ( rc ) ); + } + + return rc; }