Skip to content

Commit

Permalink
Use netlink in GetNetDevLinkStatus()
Browse files Browse the repository at this point in the history
Signed-off-by: Vasilis Remmas <vremmas@nvidia.com>
  • Loading branch information
vasrem committed Jan 17, 2024
1 parent 4a9bd4b commit d18aae1
Showing 1 changed file with 10 additions and 7 deletions.
17 changes: 10 additions & 7 deletions pkg/host/network.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import (
"time"

"github.com/cenkalti/backoff"
"github.com/vishvananda/netlink"
"sigs.k8s.io/controller-runtime/pkg/log"

dputils "github.com/k8snetworkplumbingwg/sriov-network-device-plugin/pkg/utils"
Expand Down Expand Up @@ -231,12 +232,14 @@ func (n *network) GetNetDevLinkSpeed(ifaceName string) string {

func (n *network) GetNetDevLinkStatus(ifaceName string) string {
log.Log.V(2).Info("GetNetDevLinkStatus(): get LinkStatus", "device", ifaceName)
statusFilePath := filepath.Join(vars.FilesystemRoot, consts.SysClassNet, ifaceName, "operstate")
data, err := os.ReadFile(statusFilePath)
if err != nil {
log.Log.Error(err, "GetNetDevLinkStatus(): fail to read Link Status file", "path", statusFilePath)
return ""
if len(ifaceName) > 0 {
link, err := netlink.LinkByName(ifaceName)
if err != nil {
log.Log.Error(err, "GetNetDevLinkStatus(): failed to get link", "device", ifaceName)
return ""
}
linkStatus := link.Attrs().OperState
return linkStatus.String()
}

return strings.TrimSpace(string(data))
return ""
}

0 comments on commit d18aae1

Please sign in to comment.