Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Manually update to the latest sdk-sriov version #123

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ require (
github.com/kelseyhightower/envconfig v1.4.0
github.com/networkservicemesh/api v0.0.0-20210202152048-ec956057eb3a
github.com/networkservicemesh/sdk v0.0.0-20210216095211-a36209b21c4b
github.com/networkservicemesh/sdk-sriov v0.0.0-20210216100057-84463e4b82ce
github.com/networkservicemesh/sdk-sriov v0.0.0-20210217064121-69fae3fcd42e
github.com/pkg/errors v0.9.1
github.com/sirupsen/logrus v1.7.0
github.com/spiffe/go-spiffe/v2 v2.0.0-alpha.5
Expand Down
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -296,8 +296,8 @@ github.com/networkservicemesh/sdk v0.0.0-20210216095211-a36209b21c4b h1:6M4ZAQwA
github.com/networkservicemesh/sdk v0.0.0-20210216095211-a36209b21c4b/go.mod h1:7Y9JsBKKjgvOT2faCXy/aM76bWsA//xvdVfbdLe0WXk=
github.com/networkservicemesh/sdk-kernel v0.0.0-20210216095528-c177e58a0d03 h1:ooGOUOXve7Dwdt25oyDrKINenrfG86UoxfEIXsQSorE=
github.com/networkservicemesh/sdk-kernel v0.0.0-20210216095528-c177e58a0d03/go.mod h1:fYNkQR64twi8v9ATVTXDfMRbfKktUHA49nxI/kqwvDE=
github.com/networkservicemesh/sdk-sriov v0.0.0-20210216100057-84463e4b82ce h1:ig+1CO9xtH7ZhNymp30bAnyMCcc+yZewIoTvOVVMXhM=
github.com/networkservicemesh/sdk-sriov v0.0.0-20210216100057-84463e4b82ce/go.mod h1:SAfJDaAfFQ7z+2hRlddcqP4MVdMY6LEl6v2ApU2HkQQ=
github.com/networkservicemesh/sdk-sriov v0.0.0-20210217064121-69fae3fcd42e h1:dsbp9wJc4ZB8P8gOt6+lXMUhBTyM7eyc0OmvBNjTvdA=
github.com/networkservicemesh/sdk-sriov v0.0.0-20210217064121-69fae3fcd42e/go.mod h1:SAfJDaAfFQ7z+2hRlddcqP4MVdMY6LEl6v2ApU2HkQQ=
github.com/niemeyer/pretty v0.0.0-20200227124842-a10e7caefd8e h1:fD57ERR4JtEqsWbfPhv4DMiApHyliiK5xCTNVSPiaAs=
github.com/niemeyer/pretty v0.0.0-20200227124842-a10e7caefd8e/go.mod h1:zD1mROLANZcx1PVRCS0qkT7pwLkGfwJo4zjcN/Tysno=
github.com/nishanths/exhaustive v0.0.0-20200811152831-6cf413ae40e0/go.mod h1:wBEpHwM2OdmeNpdCvRPUlkEbBuaFmcK4Wv8Q7FuGW3c=
Expand Down
34 changes: 1 addition & 33 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,13 +20,9 @@
package main

import (
"bufio"
"context"
"fmt"
"os"
"path/filepath"
"regexp"
"strings"

nested "github.com/antonfisher/nested-logrus-formatter"
"github.com/edwarnicke/grpcfd"
Expand Down Expand Up @@ -230,13 +226,7 @@ func RunClient(
}
clients = append(clients, kernel.NewClient(kernel.WithInterfaceName(iface)))
case vfiomech.MECHANISM:
var cgroupDir string
cgroupDir, err = cgroupDirPath()
if err != nil {
log.FromContext(ctx).Errorf("failed to get devices cgroup: %v", err.Error())
continue
}
clients = append(clients, vfio.NewClient("/dev/vfio", cgroupDir))
clients = append(clients, vfio.NewClient())
}
nsmClient := nsmClientFactory(clients...)

Expand Down Expand Up @@ -271,25 +261,3 @@ func RunClient(
}
return cleanup, nil
}

var devicesCgroup = regexp.MustCompile("^[1-9][0-9]*?:devices:(.*)$")

func cgroupDirPath() (string, error) {
cgroupInfo, err := os.OpenFile("/proc/self/cgroup", os.O_RDONLY, 0)
if err != nil {
return "", errors.Wrap(err, "error opening cgroup info file")
}
for scanner := bufio.NewScanner(cgroupInfo); scanner.Scan(); {
line := scanner.Text()
if devicesCgroup.MatchString(line) {
return podCgroupDirPath(devicesCgroup.FindStringSubmatch(line)[1]), nil
}
}
return "", errors.New("can't find out cgroup directory")
}

func podCgroupDirPath(containerCgroupDirPath string) string {
split := strings.Split(containerCgroupDirPath, string(filepath.Separator))
split[len(split)-1] = "*" // any container match
return filepath.Join(split...)
}