From 896bd39c889be7bc40f76eb681a25152f170f6b7 Mon Sep 17 00:00:00 2001 From: Willy Tarreau Date: Tue, 6 Jul 2010 09:03:36 +0200 Subject: vrrp_if: don't probe all the 32 MII regs all the time We only need to probe them the first time to ensure this is properly supported. After that this is not needed anymore, as we only need the BMSR register. Doing this saves 31 ioctl on the interface, some of which are often expensive. --- keepalived/include/vrrp_if.h | 2 +- keepalived/vrrp/vrrp_if.c | 12 ++++++------ 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/keepalived/include/vrrp_if.h b/keepalived/include/vrrp_if.h index 2f9ef4e..182edd3 100644 --- a/keepalived/include/vrrp_if.h +++ b/keepalived/include/vrrp_if.h @@ -107,7 +107,7 @@ typedef struct _tracked_if { extern interface *if_get_by_ifindex(const int ifindex); extern interface *if_get_by_ifname(const char *ifname); extern int if_linkbeat(const interface *ifp); -extern int if_mii_probe(const char *ifname); +extern int if_mii_probe(const char *ifname, int full_check); extern int if_ethtool_probe(const char *ifname); extern void if_add_queue(interface * ifp); extern int if_monitor_thread(thread * thread_obj); diff --git a/keepalived/vrrp/vrrp_if.c b/keepalived/vrrp/vrrp_if.c index 76065d3..00865d5 100644 --- a/keepalived/vrrp/vrrp_if.c +++ b/keepalived/vrrp/vrrp_if.c @@ -129,7 +129,7 @@ static void if_mii_dump(const uint16_t mii_regs[32], unsigned phy_id) /* return -1 in case of failure */ static int -if_mii_status(const int fd) +if_mii_status(const int fd, int full_check) { uint16_t *data = (uint16_t *) (&ifr.ifr_data); unsigned phy_id = data[0]; @@ -140,7 +140,7 @@ if_mii_status(const int fd) /* Reset MII registers */ memset(mii_regs, 0, sizeof (mii_regs)); - for (mii_reg = 0; mii_reg < 32; mii_reg++) { + for (mii_reg = (full_check ? 0 : 1); mii_reg < (full_check ? 32 : 2); mii_reg++) { int ret = if_mii_read(fd, phy_id, mii_reg); if (ret < 0) { log_message(LOG_ERR, "No MII transceiver present for %s !!!", @@ -172,7 +172,7 @@ if_mii_status(const int fd) } int -if_mii_probe(const char *ifname) +if_mii_probe(const char *ifname, int full_check) { uint16_t *data = (uint16_t *) (&ifr.ifr_data); int phy_id; @@ -189,7 +189,7 @@ if_mii_probe(const char *ifname) } /* Dump the MII transceiver */ - status = if_mii_status(fd); + status = if_mii_status(fd, full_check); close(fd); return status; } @@ -317,7 +317,7 @@ if_linkbeat_refresh_thread(thread * thread_obj) interface *ifp = THREAD_ARG(thread_obj); if (IF_MII_SUPPORTED(ifp)) - ifp->linkbeat = (if_mii_probe(ifp->ifname)) ? 1 : 0; + ifp->linkbeat = (if_mii_probe(ifp->ifname, 0)) ? 1 : 0; else if (IF_ETHTOOL_SUPPORTED(ifp)) ifp->linkbeat = (if_ethtool_probe(ifp->ifname)) ? 1 : 0; else @@ -344,7 +344,7 @@ init_if_linkbeat(void) for (e = LIST_HEAD(if_queue); e; ELEMENT_NEXT(e)) { ifp = ELEMENT_DATA(e); ifp->lb_type = LB_IOCTL; - status = if_mii_probe(ifp->ifname); + status = if_mii_probe(ifp->ifname, 1); if (status >= 0) { ifp->lb_type = LB_MII; ifp->linkbeat = (status) ? 1 : 0; -- 1.6.0.4