Skip to content
This repository has been archived by the owner on May 12, 2021. It is now read-only.

Commit

Permalink
Merge pull request #860 from jongwu/rootbus
Browse files Browse the repository at this point in the history
rootBusPath: create rootBusPath dynamically.
  • Loading branch information
Julio Montes authored Nov 26, 2020
2 parents 8c85bb5 + d66fcb8 commit 25d7471
Show file tree
Hide file tree
Showing 8 changed files with 71 additions and 8 deletions.
5 changes: 5 additions & 0 deletions agent.go
Original file line number Diff line number Diff line change
Expand Up @@ -709,6 +709,11 @@ func (s *sandbox) waitForStopServer() {

func (s *sandbox) listenToUdevEvents() {
fieldLogger := agentLog.WithField("subsystem", "udevlistener")
rootBusPath, err := createRootBusPath()
if err != nil {
fieldLogger.Warnf("Error creating root bus path")
return
}

uEvHandler, err := uevent.NewHandler()
if err != nil {
Expand Down
4 changes: 4 additions & 0 deletions device.go
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,10 @@ func rescanPciBus() error {
func pciPathToSysfsImpl(pciPath PciPath) (string, error) {
var relPath string
bus := "0000:00"
rootBusPath, err := createRootBusPath()
if err != nil {
return "", err
}

tokens := strings.Split(pciPath.path, "/")

Expand Down
6 changes: 4 additions & 2 deletions device_amd64.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,14 @@
package main

const (
rootBusPath = "/devices/pci0000:00"

// From https://www.kernel.org/doc/Documentation/acpi/namespace.txt
// The Linux kernel's core ACPI subsystem creates struct acpi_device
// objects for ACPI namespace objects representing devices, power resources
// processors, thermal zones. Those objects are exported to user space via
// sysfs as directories in the subtree under /sys/devices/LNXSYSTM:00
acpiDevPath = "/devices/LNXSYSTM"
)

func createRootBusPath() (string, error) {
return "/devices/pci0000:00", nil
}
28 changes: 26 additions & 2 deletions device_arm64.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,37 @@

package main

const (
rootBusPath = "/devices/platform/4010000000.pcie/pci0000:00"
import (
"fmt"
"io/ioutil"
"path/filepath"
"strings"
)

const (
// From https://www.kernel.org/doc/Documentation/acpi/namespace.txt
// The Linux kernel's core ACPI subsystem creates struct acpi_device
// objects for ACPI namespace objects representing devices, power resources
// processors, thermal zones. Those objects are exported to user space via
// sysfs as directories in the subtree under /sys/devices/LNXSYSTM:00
acpiDevPath = "/devices/LNXSYSTM"
)

func createRootBusPath() (string, error) {
startRootBusPath := "/devices/platform"
endRootBusPath := "/pci0000:00"
sysStartRootBusPath := filepath.Join(sysfsDir, startRootBusPath)
files, err := ioutil.ReadDir(sysStartRootBusPath)
if err != nil {
return "", fmt.Errorf("Error reading %s: %s", sysStartRootBusPath, err)
}

// find out the directory end with ".pcie"
for _, file := range files {
if strings.HasSuffix(file.Name(), ".pcie") && file.IsDir() {
return filepath.Join(startRootBusPath, file.Name(), endRootBusPath), nil
}
}

return "", fmt.Errorf("no pcie bus found under %s", sysStartRootBusPath)
}
6 changes: 4 additions & 2 deletions device_ppc64le.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,14 @@
package main

const (
rootBusPath = "/devices/pci0000:00"

// From https://www.kernel.org/doc/Documentation/acpi/namespace.txt
// The Linux kernel's core ACPI subsystem creates struct acpi_device
// objects for ACPI namespace objects representing devices, power resources
// processors, thermal zones. Those objects are exported to user space via
// sysfs as directories in the subtree under /sys/devices/LNXSYSTM:00
acpiDevPath = "/devices/LNXSYSTM"
)

func createRootBusPath() (string, error) {
return "/devices/pci0000:00", nil
}
6 changes: 4 additions & 2 deletions device_s390x.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,14 @@
package main

const (
rootBusPath = "/devices/css0"

// From https://www.kernel.org/doc/Documentation/acpi/namespace.txt
// The Linux kernel's core ACPI subsystem creates struct acpi_device
// objects for ACPI namespace objects representing devices, power resources
// processors, thermal zones. Those objects are exported to user space via
// sysfs as directories in the subtree under /sys/devices/LNXSYSTM:00
acpiDevPath = "/devices/LNXSYSTM"
)

func createRootBusPath() (string, error) {
return "/devices/css0", nil
}
12 changes: 12 additions & 0 deletions device_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import (
"os"
"path"
"path/filepath"
"runtime"
"strings"
"testing"

Expand Down Expand Up @@ -93,6 +94,17 @@ func TestVirtioBlkDeviceHandlerEmptyLinuxDevicesSpecFailure(t *testing.T) {
}

func TestPciPathToSysfs(t *testing.T) {
var rootBusPath string
var err error

if runtime.GOARCH == "arm64" {
rootBusPath = "/devices/platform/4010000000.pcie/pci0000:00"
} else {
rootBusPath, err = createRootBusPath()
if err != nil {
t.Fatal(t, err)
}
}
testDir, err := ioutil.TempDir("", "kata-agent-tmp-")
if err != nil {
t.Fatal(t, err)
Expand Down
12 changes: 12 additions & 0 deletions mount_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import (
"io/ioutil"
"os"
"path/filepath"
"runtime"
"syscall"
"testing"

Expand Down Expand Up @@ -210,6 +211,17 @@ func TestVirtioBlkStorageDeviceFailure(t *testing.T) {

func TestVirtioBlkStorageHandlerSuccessful(t *testing.T) {
skipUnlessRoot(t)
var rootBusPath string
var err error

if runtime.GOARCH == "arm64" {
rootBusPath = "/devices/platform/4010000000.pcie/pci0000:00"
} else {
rootBusPath, err = createRootBusPath()
if err != nil {
t.Fatal(t, err)
}
}

testDir, err := ioutil.TempDir("", "kata-agent-tmp-")
if err != nil {
Expand Down

0 comments on commit 25d7471

Please sign in to comment.