Skip to content

Commit

Permalink
Merge pull request #12 from almaslennikov/housekeeping
Browse files Browse the repository at this point in the history
Housekeeping
  • Loading branch information
adrianchiris authored Sep 6, 2023
2 parents a39ad54 + 6c1612f commit d8230af
Show file tree
Hide file tree
Showing 16 changed files with 190 additions and 43 deletions.
14 changes: 14 additions & 0 deletions .github/ISSUE_TEMPLATE/bug-report.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
---
name: Bug Report
about: Report a bug with rdmamap

---
<!-- Please use this template while reporting a bug and provide as much relevant info as possible. Doing so give us the best chance to find a prompt resolution to your issue -->

### What happened?

### What did you expect to happen?

### What are the minimal steps needed to reproduce the bug?

### Anything else we need to know?
11 changes: 11 additions & 0 deletions .github/ISSUE_TEMPLATE/enhancement.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
---
name: Enhancement / Feature Request
about: Suggest an enhancement or new feature for rdmamap

---
<!-- Please use this template to submit feature and enhancement requests -->


## What would you like to be added?

## What is the use case for this feature / enhancement?
12 changes: 12 additions & 0 deletions .github/ISSUE_TEMPLATE/other.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
---
name: Other Issues
about: For everything that isn't a bug report or a feature request

---
<!-- Please use this template to submit issues that are neither bugs reports nor feature requests -->

## What issue would you like to bring attention to?

## What is the impact of this issue?

## Do you have a proposed response or remediation for the issue?
59 changes: 59 additions & 0 deletions .github/workflows/buildtest.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
name: go-build-and-test-amd64
on:
push:
pull_request:
jobs:
build:
name: build
strategy:
matrix:
go-version: [1.20.x]
os: [ubuntu-22.04]
goos: [linux]
goarch: [amd64]
runs-on: ${{ matrix.os }}
steps:
- name: set up Go
uses: actions/setup-go@v3
with:
go-version: ${{ matrix.go-version }}
- name: check out code into the Go module directory
uses: actions/checkout@v2
- name: build test for ${{ matrix.goarch }}
env:
GOARCH: ${{ matrix.goarch }}
GOOS: ${{ matrix.goos }}
run: make build

test:
name: test
runs-on: ubuntu-22.04
needs: build
steps:
- name: set up Go
uses: actions/setup-go@v3
with:
go-version: 1.20.x
- name: check out code into the Go module directory
uses: actions/checkout@v3
- name: run unit-test
run: make test

coverage:
runs-on: ubuntu-22.04
needs: build
name: coverage
steps:
- name: Set up Go
uses: actions/setup-go@v3
with:
go-version: 1.20.x
- name: Check out code into the Go module directory
uses: actions/checkout@v2
- name: Go test with coverage
run: make test-coverage
- name: Coveralls
uses: coverallsapp/github-action@v2
with:
github-token: ${{ secrets.GITHUB_TOKEN }}
file: rdmamap.cover
39 changes: 39 additions & 0 deletions .github/workflows/codeql.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
name: "CodeQL"

on:
push:
branches: [ "master" ]
pull_request:
branches: [ "master" ]

jobs:
analyze:
name: Analyze
runs-on: ubuntu-latest
permissions:
actions: read
contents: read
security-events: write

strategy:
fail-fast: false
matrix:
language: [ go ]

steps:
- name: Checkout
uses: actions/checkout@v3

- name: Initialize CodeQL
uses: github/codeql-action/init@v2
with:
languages: ${{ matrix.language }}
queries: +security-and-quality

- name: Autobuild
uses: github/codeql-action/autobuild@v2

- name: Perform CodeQL Analysis
uses: github/codeql-action/analyze@v2
with:
category: "/language:${{ matrix.language }}"
15 changes: 15 additions & 0 deletions .github/workflows/static-scan.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
name: go-static-analysis
on: [push, pull_request]
jobs:
golangci:
name: Lint
runs-on: ubuntu-22.04
steps:
- name: set up Go
uses: actions/setup-go@v3
with:
go-version: 1.20.x
- name: checkout PR
uses: actions/checkout@v2
- name: run make lint
run: make lint
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
.gopath/
bin/
8 changes: 2 additions & 6 deletions .golangci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -55,19 +55,17 @@ linters:
disable-all: true
enable:
- bodyclose
- deadcode
- depguard
- dogsled
- dupl
- errcheck
- exportloopref
- funlen
- gochecknoinits
- goconst
- gocritic
- gocognit
- gofmt
- goimports
- golint
- gomnd
- goprintffuncname
- gosec
Expand All @@ -79,15 +77,13 @@ linters:
- nakedret
- prealloc
- rowserrcheck
- scopelint
- staticcheck
- structcheck
- stylecheck
- typecheck
- revive
- unconvert
- unparam
- unused
- varcheck
- whitespace

issues:
Expand Down
12 changes: 0 additions & 12 deletions .travis.yml

This file was deleted.

2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ GOLANGCI_LINT = $(GOBIN)/golangci-lint
# golangci-lint version should be updated periodically
# we keep it fixed to avoid it from unexpectedly failing on the project
# in case of a version bump
GOLANGCI_LINT_VER = v1.23.8
GOLANGCI_LINT_VER = v1.53.3
TIMEOUT = 15
Q = $(if $(filter 1,$V),,@)

Expand Down
Binary file added bin/golangci-lint
Binary file not shown.
6 changes: 4 additions & 2 deletions go.mod
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
module github.com/Mellanox/rdmamap

go 1.13
go 1.20

require (
github.com/vishvananda/netlink v1.1.0
github.com/vishvananda/netns v0.0.0-20191106174202-0a2b9b5464df
github.com/vishvananda/netns v0.0.4
)

require golang.org/x/sys v0.10.0 // indirect
6 changes: 4 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
github.com/vishvananda/netlink v1.1.0 h1:1iyaYNBLmP6L0220aDnYQpo1QEV4t4hJ+xEEhhJH8j0=
github.com/vishvananda/netlink v1.1.0/go.mod h1:cTgwzPIzzgDAYoQrMm0EdrjRUBkTqKYppBueQtXaqoE=
github.com/vishvananda/netns v0.0.0-20191106174202-0a2b9b5464df h1:OviZH7qLw/7ZovXvuNyL3XQl8UFofeikI1NW1Gypu7k=
github.com/vishvananda/netns v0.0.0-20191106174202-0a2b9b5464df/go.mod h1:JP3t17pCcGlemwknint6hfoeCVQrEMVwxRLRjXpq+BU=
golang.org/x/sys v0.0.0-20190606203320-7fc4e5ec1444 h1:/d2cWp6PSamH4jDPFLyO150psQdqvtoNX8Zjg3AQ31g=
github.com/vishvananda/netns v0.0.4 h1:Oeaw1EM2JMxD51g9uhtC0D7erkIjgmj8+JZc26m1YX8=
github.com/vishvananda/netns v0.0.4/go.mod h1:SpkAiCQRtJ6TvvxPnOSyH3BMl6unz3xZlaprSwhNNJM=
golang.org/x/sys v0.0.0-20190606203320-7fc4e5ec1444/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.10.0 h1:SqMFp9UcQJZa+pmYuAKjd9xq1f0j5rLcDIk0mj4qAsA=
golang.org/x/sys v0.10.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
33 changes: 18 additions & 15 deletions rdma_map.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,12 @@ import (
"bytes"
"fmt"
"io"
"io/ioutil"
"os"
"path/filepath"
"strconv"
"strings"

"github.com/vishvananda/netlink"
netlink "github.com/vishvananda/netlink"
)

const (
Expand All @@ -26,11 +25,11 @@ const (
RdmaUverbsDir = "/sys/class/infiniband_verbs"
RdmaUverbsFilxPrefix = "uverbs"

RdmaGidAttrDir = "gid_attrs" //nolint:stylecheck,golint
RdmaGidAttrNdevDir = "ndevs" //nolint:stylecheck,golint
RdmaGidAttrDir = "gid_attrs" //nolint:stylecheck,revive
RdmaGidAttrNdevDir = "ndevs" //nolint:stylecheck,revive
RdmaPortsdir = "ports"

RdmaNodeGuidFile = "node_guid" //nolint:stylecheck,golint
RdmaNodeGuidFile = "node_guid" //nolint:stylecheck,revive
RdmaUcmDevice = "/dev/infiniband/rdma_cm"
RdmaDeviceDir = "/dev/infiniband"

Expand All @@ -44,9 +43,12 @@ const (
prevDir = ".."
nibbleBitSize = 4
loopBackIfName = "lo"

ReadOnlyPermissions = 0444
)

// Returns a list of rdma device names
// GetRdmaDeviceList Returns a list of rdma device names
//
//nolint:prealloc
func GetRdmaDeviceList() []string {
var rdmaDevices []string
Expand All @@ -73,7 +75,7 @@ func GetRdmaDeviceList() []string {
func isDirForRdmaDevice(rdmaDeviceName, dirName string) bool {
fileName := filepath.Join(dirName, "ibdev")

fd, err := os.OpenFile(fileName, os.O_RDONLY, 0444)
fd, err := os.OpenFile(fileName, os.O_RDONLY, ReadOnlyPermissions)
if err != nil {
return false
}
Expand All @@ -83,11 +85,11 @@ func isDirForRdmaDevice(rdmaDeviceName, dirName string) bool {
return false
}

data, err := ioutil.ReadAll(fd)
data, err := io.ReadAll(fd)
if err != nil {
return false
}
return (strings.Compare(strings.Trim(string(data), "\n"), rdmaDeviceName) == 0)
return strings.Trim(string(data), "\n") == rdmaDeviceName
}

func getCharDevice(rdmaDeviceName, classDir, charDevPrefix string) (string, error) {
Expand All @@ -112,7 +114,7 @@ func getCharDevice(rdmaDeviceName, classDir, charDevPrefix string) (string, erro
if !isDirForRdmaDevice(rdmaDeviceName, dirName) {
continue
}
deviceFile := filepath.Join("/dev/infiniband", fileInfos[i].Name())
deviceFile := filepath.Join("/dev/infiniband", fileInfos[i].Name()) //nolint:gocritic
return deviceFile, nil
}
return "", fmt.Errorf("no ucm device found")
Expand Down Expand Up @@ -185,6 +187,7 @@ func GetRdmaCharDevices(rdmaDeviceName string) []string {
}

// Gets a list of ports for a specified device
//
//nolint:prealloc
func GetPorts(rdmaDeviceName string) []string {
var ports []string
Expand Down Expand Up @@ -241,7 +244,7 @@ func isNetdevForRdma(rdmaDeviceName, port, index, netdevName string) bool {
fileName := filepath.Join(RdmaClassDir, rdmaDeviceName, RdmaPortsdir, port,
RdmaGidAttrDir, RdmaGidAttrNdevDir, index)

fd, err := os.OpenFile(fileName, os.O_RDONLY, 0444)
fd, err := os.OpenFile(fileName, os.O_RDONLY, ReadOnlyPermissions)
if err != nil {
return false
}
Expand All @@ -251,7 +254,7 @@ func isNetdevForRdma(rdmaDeviceName, port, index, netdevName string) bool {
return false
}

data, err := ioutil.ReadAll(fd)
data, err := io.ReadAll(fd)
if err != nil {
return false
}
Expand Down Expand Up @@ -284,7 +287,7 @@ func getNodeGUID(rdmaDeviceName string) ([]byte, error) {

fileName := filepath.Join(RdmaClassDir, rdmaDeviceName, RdmaNodeGuidFile)

fd, err := os.OpenFile(fileName, os.O_RDONLY, 0444)
fd, err := os.OpenFile(fileName, os.O_RDONLY, ReadOnlyPermissions)
if err != nil {
return nil, err
}
Expand All @@ -293,7 +296,7 @@ func getNodeGUID(rdmaDeviceName string) ([]byte, error) {
if _, err = fd.Seek(0, io.SeekStart); err != nil {
return nil, err
}
data, err := ioutil.ReadAll(fd)
data, err := io.ReadAll(fd)
if err != nil {
return nil, err
}
Expand Down Expand Up @@ -361,7 +364,7 @@ func IsRDmaDeviceForNetdevice(netdevName string) bool {
func getRdmaDevicesFromDir(dirName string) []string {
var rdmadevs []string

entries, err := ioutil.ReadDir(dirName)
entries, err := os.ReadDir(dirName)
if err != nil {
return rdmadevs
}
Expand Down
Loading

0 comments on commit d8230af

Please sign in to comment.