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

Commit

Permalink
device: Rename pciDeviceMap in sandbox struct
Browse files Browse the repository at this point in the history
pciDeviceMap is essentially just a map from sysfs paths to corresponding
device nodes.  The only thing PCI related is that the sysfs paths we're
usually looking up in it usually involve PCI addresses.  There's no reason
that has to be the case, however, and I have future uses which will not
be PCI.

Therefore, rename it (and change some surrounding comments) to reflect
its more general nature.  While we're there, fix a typo in a related
comment.

Signed-off-by: David Gibson <[email protected]>
  • Loading branch information
dgibson committed Sep 23, 2020
1 parent cfff0bb commit bd4dcc5
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 18 deletions.
14 changes: 7 additions & 7 deletions agent.go
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@ type sandbox struct {
mounts []string
subreaper reaper
server *grpc.Server
pciDeviceMap map[string]string
sysToDevMap map[string]string
deviceWatchers map[string](chan string)
sharedUTSNs namespace
sharedIPCNs namespace
Expand Down Expand Up @@ -742,9 +742,9 @@ func (s *sandbox) listenToUdevEvents() {
})

if uEv.Action == "remove" {
fieldLogger.Infof("Remove dev from pciDeviceMap")
fieldLogger.Infof("Remove dev from sysToDevMap")
s.Lock()
delete(s.pciDeviceMap, uEv.DevPath)
delete(s.sysToDevMap, uEv.DevPath)
s.Unlock()
goto FINISH_SPAN
}
Expand All @@ -758,12 +758,12 @@ func (s *sandbox) listenToUdevEvents() {
// Check if device hotplug event results in a device node being created.
if uEv.DevName != "" &&
(strings.HasPrefix(uEv.DevPath, rootBusPath) || strings.HasPrefix(uEv.DevPath, acpiDevPath)) {
// Lock is needed to safey read and modify the pciDeviceMap and deviceWatchers.
// Lock is needed to safely read and modify the sysToDevMap and deviceWatchers.
// This makes sure that watchers do not access the map while it is being updated.
s.Lock()

// Add the device node name to the pci device map.
s.pciDeviceMap[uEv.DevPath] = uEv.DevName
// Add the device node name to the device map.
s.sysToDevMap[uEv.DevPath] = uEv.DevName

// Notify watchers that are interested in the udev event.
// Close the channel after watcher has been notified.
Expand Down Expand Up @@ -1548,7 +1548,7 @@ func realMain() error {
// Documentation/filesystem/ramfs-rootfs-initramfs.txt
noPivotRoot: (fsType == typeRootfs),
subreaper: r,
pciDeviceMap: make(map[string]string),
sysToDevMap: make(map[string]string),
deviceWatchers: make(map[string](chan string)),
storages: make(map[string]*sandboxStorage),
stopServer: make(chan struct{}),
Expand Down
4 changes: 2 additions & 2 deletions device.go
Original file line number Diff line number Diff line change
Expand Up @@ -144,10 +144,10 @@ func getDeviceName(s *sandbox, devID string) (string, error) {

// Check if the dev identifier is in PCI device map.
s.Lock()
for key, value := range s.pciDeviceMap {
for key, value := range s.sysToDevMap {
if strings.Contains(key, devID) {
devName = value
fieldLogger.Infof("Device: %s found in pci device map", devID)
fieldLogger.Infof("Device: %s found in device map", devID)
break
}
}
Expand Down
8 changes: 4 additions & 4 deletions device_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -872,20 +872,20 @@ func TestGetDeviceName(t *testing.T) {
busID := "0.0.0005"
devPath := path.Join("/devices/css0/0.0.0004", busID, "virtio4/block", devName)

pcidevicemap := make(map[string]string)
pcidevicemap[devPath] = devName
systodevmap := make(map[string]string)
systodevmap[devPath] = devName

sb := sandbox{
deviceWatchers: make(map[string](chan string)),
pciDeviceMap: pcidevicemap,
sysToDevMap: systodevmap,
}

name, err := getDeviceName(&sb, busID)

assert.Nil(err)
assert.Equal(name, path.Join(devRootPath, devName))

delete(sb.pciDeviceMap, devPath)
delete(sb.sysToDevMap, devPath)

go func() {
for {
Expand Down
10 changes: 5 additions & 5 deletions mount_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -248,11 +248,11 @@ func TestVirtioBlkStorageHandlerSuccessful(t *testing.T) {
defer syscall.Unmount(storage.MountPoint, 0)

s := &sandbox{
pciDeviceMap: make(map[string]string),
sysToDevMap: make(map[string]string),
}

s.Lock()
s.pciDeviceMap[completePCIAddr] = devPath
s.sysToDevMap[completePCIAddr] = devPath
s.Unlock()

storage.Fstype = "bind"
Expand All @@ -268,7 +268,7 @@ func TestVirtioBlkStorageHandlerSuccessful(t *testing.T) {
func TestNvdimmStorageHandlerSuccessful(t *testing.T) {
skipUnlessRoot(t)

completePCIAddr := "/devices/LNXSYSTM/LNXSYBUS/ACPI/ndbus0/region1/pfn1.1/block/pmem0"
sysfsPath := "/devices/LNXSYSTM/LNXSYBUS/ACPI/ndbus0/region1/pfn1.1/block/pmem0"
pmemDev := "/dev/pmem0"
devPath, err := createFakeDevicePath()
if err != nil {
Expand All @@ -289,11 +289,11 @@ func TestNvdimmStorageHandlerSuccessful(t *testing.T) {
defer syscall.Unmount(storage.MountPoint, 0)

s := &sandbox{
pciDeviceMap: make(map[string]string),
sysToDevMap: make(map[string]string),
}

s.Lock()
s.pciDeviceMap[completePCIAddr] = devPath
s.sysToDevMap[sysfsPath] = devPath
s.Unlock()

storage.Fstype = "bind"
Expand Down

0 comments on commit bd4dcc5

Please sign in to comment.