From abd0409f8832cf1f47d2f4d58a7175cfe2d5d90b Mon Sep 17 00:00:00 2001 From: wanyaoqi Date: Mon, 8 Jan 2024 23:09:29 +0800 Subject: [PATCH] fix(host): host-agent register skip upload vf nics --- pkg/hostman/hostinfo/hostinfo.go | 12 +++++++++++- pkg/util/sysutils/nics.go | 12 +++++++++--- 2 files changed, 20 insertions(+), 4 deletions(-) diff --git a/pkg/hostman/hostinfo/hostinfo.go b/pkg/hostman/hostinfo/hostinfo.go index 9d170e3e81..db6803dcd7 100644 --- a/pkg/hostman/hostinfo/hostinfo.go +++ b/pkg/hostman/hostinfo/hostinfo.go @@ -1638,7 +1638,17 @@ func (h *SHostInfo) ensureNicsHostwires(hostInfo *api.HostDetails) error { } func (h *SHostInfo) isVirtualFunction(nic string) bool { - return fileutils2.Exists(path.Join("/sys/class/net", nic, "device", "physfn")) + physPortName, err := fileutils2.FileGetContents(path.Join("/sys/class/net", nic, "phys_port_name")) + if err != nil { + log.Warningf("failed get nic %s phys_port_name: %s", nic, err) + return false + } + if strings.Contains(physPortName, "vf") { + log.Infof("nic %s is virtual function", nic) + return true + } + log.Infof("nic %s is not virtual function", nic) + return false } func (h *SHostInfo) uploadNetworkInfo() error { diff --git a/pkg/util/sysutils/nics.go b/pkg/util/sysutils/nics.go index 8930af9ac1..7abf0dd09f 100644 --- a/pkg/util/sysutils/nics.go +++ b/pkg/util/sysutils/nics.go @@ -21,6 +21,7 @@ import ( "path" "path/filepath" "strconv" + "strings" "yunion.io/x/log" "yunion.io/x/pkg/errors" @@ -50,9 +51,14 @@ func Nics() ([]*types.SNicDevInfo, error) { } /*else if (fi.Mode() & os.ModeSymlink) == 0 { continue }*/ - if fileutils2.Exists(path.Join(netPath, "device", "infiniband")) { - // skip infiniband nic - continue + nicType, err := fileutils2.FileGetContents(path.Join(netPath, "type")) + if err != nil { + return nil, errors.Wrap(err, "failed get nic type") + } + if strings.TrimSpace(nicType) == "32" { + // include/uapi/linux/if_arp.h + // #define ARPHRD_INFINIBAND 32 /* InfiniBand */ + continue // skip infiniband nic } speedStr := GetSysConfigQuiet(filepath.Join(netPath, "speed"))