fix(host): host-agent register skip upload vf nics

This commit is contained in:
wanyaoqi
2024-01-08 23:09:29 +08:00
parent 3b8549d8c7
commit abd0409f88
2 changed files with 20 additions and 4 deletions

View File

@@ -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 {

View File

@@ -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"))