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

device: Do not rescan PCI bus #782

Closed
Closed
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
1 change: 0 additions & 1 deletion agent_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@ const (
testExecID = "testExecID"
testContainerID = "testContainerID"
testFileMode = os.FileMode(0640)
testDirMode = os.FileMode(0750)
)

func createFileWithPerms(file, contents string, perms os.FileMode) error {
Expand Down
17 changes: 0 additions & 17 deletions device.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,13 +37,8 @@ const (
vmRootfs = "/"
)

const (
pciBusMode = 0220
)

var (
sysBusPrefix = sysfsDir + "/bus/pci/devices"
pciBusRescanFile = sysfsDir + "/bus/pci/rescan"
pciBusPathFormat = "%s/%s/pci_bus/"
systemDevPath = "/dev"
getSCSIDevPath = getSCSIDevPathImpl
Expand Down Expand Up @@ -81,10 +76,6 @@ var deviceHandlerList = map[string]deviceHandler{
driverNvdimmType: nvdimmDeviceHandler,
}

func rescanPciBus() error {
return ioutil.WriteFile(pciBusRescanFile, []byte{'1'}, pciBusMode)
}

// getDevicePCIAddress fetches the complete PCI address in sysfs, based on the PCI
// identifier provided. This should be in the format: "bridgeAddr/deviceAddr".
// Here, bridgeAddr is the address at which the brige is attached on the root bus,
Expand Down Expand Up @@ -179,14 +170,6 @@ func getPCIDeviceNameImpl(s *sandbox, pciID string) (string, error) {
return "", err
}

fieldLogger := agentLog.WithField("pciAddr", pciAddr)

// Rescan pci bus if we need to wait for a new pci device
if err = rescanPciBus(); err != nil {
fieldLogger.WithError(err).Error("Failed to scan pci bus")
return "", err
}

return getDeviceName(s, pciAddr)
}

Expand Down
46 changes: 0 additions & 46 deletions device_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -504,45 +504,6 @@ func TestUpdateSpecDeviceList(t *testing.T) {
assert.NoError(err)
}

func TestRescanPciBus(t *testing.T) {
skipUnlessRoot(t)

assert := assert.New(t)

err := rescanPciBus()
assert.Nil(err)

}

func TestRescanPciBusSubverted(t *testing.T) {
assert := assert.New(t)

dir, err := ioutil.TempDir("", "")
assert.NoError(err)
defer os.RemoveAll(dir)

rescanDir := filepath.Join(dir, "rescan-dir")

err = os.MkdirAll(rescanDir, testDirMode)
assert.NoError(err)

rescan := filepath.Join(rescanDir, "rescan")

savedFile := pciBusRescanFile
defer func() {
pciBusRescanFile = savedFile
}()

pciBusRescanFile = rescan

err = rescanPciBus()
assert.NoError(err)

os.RemoveAll(rescanDir)
err = rescanPciBus()
assert.Error(err)
}

func TestVirtioMmioBlkDeviceHandler(t *testing.T) {
assert := assert.New(t)

Expand Down Expand Up @@ -635,13 +596,6 @@ func TestGetPCIDeviceName(t *testing.T) {

_, err = getPCIDeviceNameImpl(&sb, "")
assert.Error(err)

rescanDir := filepath.Dir(pciBusRescanFile)
err = os.MkdirAll(rescanDir, testDirMode)
assert.NoError(err)

_, err = getPCIDeviceNameImpl(&sb, "")
assert.Error(err)
}

func TestGetSCSIDevPath(t *testing.T) {
Expand Down
6 changes: 0 additions & 6 deletions grpc.go
Original file line number Diff line number Diff line change
Expand Up @@ -618,12 +618,6 @@ func (a *agentGRPC) CreateContainer(ctx context.Context, req *pb.CreateContainer
return emptyResp, err
}

// re-scan PCI bus
// looking for hidden devices
if err = rescanPciBus(); err != nil {
agentLog.WithError(err).Warn("Could not rescan PCI bus")
}

// Some devices need some extra processing (the ones invoked with
// --device for instance), and that's what this call is doing. It
// updates the devices listed in the OCI spec, so that they actually
Expand Down