From c88eb13036f2f1ca21cfc17d0612c4d06cc4a3ab Mon Sep 17 00:00:00 2001 From: kuralamudhan ramakrishnan Date: Mon, 20 Feb 2017 17:28:30 +0000 Subject: [PATCH] checking operation not supported for phys port id file --- sriov/sriov.go | 28 +++++++++++++++++++--------- 1 file changed, 19 insertions(+), 9 deletions(-) diff --git a/sriov/sriov.go b/sriov/sriov.go index 3a64ad796..adb93032d 100644 --- a/sriov/sriov.go +++ b/sriov/sriov.go @@ -23,6 +23,12 @@ import ( const defaultCNIDir = "/var/lib/cni/sriov" +const ( + NOTSUP = iota - 1 + FALSE = iota - 1 + TRUE = iota - 1 +) + type dpdkConf struct { PCIaddr string `json:"pci_addr"` Ifname string `json:"ifname"` @@ -221,17 +227,21 @@ func getphyPortID(ifName string) (string, error) { } -func compareportID(ifName string, portId string) (bool, error) { +func compareportID(ifName string, portId string) (int, error) { physportId, err := getphyPortID(ifName) if err != nil { - return false, err + return FALSE, err } - if strings.Compare(physportId, portId) != 0 { - return false, nil + + if len(physportId) == 0 && err == nil { + return NOTSUP, nil } - return true, nil + if strings.Compare(physportId, portId) != 0 { + return FALSE, nil + } + return TRUE, nil } func getsriovNumfs(ifName string) (int, error) { @@ -313,11 +323,11 @@ func setupVF(conf *NetConf, ifName string, podifName string, cid string, netns n // if sriov vf has more than one interface if len(infos) <= 2 { - var portId bool var err error vfIdx = vf - for i := 1; i <= len(infos) && portId != true; i++ { + portId := FALSE + for i := 1; i <= len(infos) && portId == FALSE; i++ { vfDevName = infos[i-1].Name() if len(physportId) != 0 { @@ -331,11 +341,11 @@ func setupVF(conf *NetConf, ifName string, podifName string, cid string, netns n } //return error, if no VF is available for the NIC support port ID - if !portId && len(physportId) != 0 && (vf == (vfTotal - 1)) { + if portId == FALSE && len(physportId) != 0 && (vf == (vfTotal - 1)) { return fmt.Errorf("no Virtual function exist in directory %s, last vf is virtfn%d", vfDir, vf) } - if !portId && len(physportId) != 0 { + if portId == FALSE && len(physportId) != 0 { continue }