From bd4dcc565c93dc5de629deba915fb17a04f9b199 Mon Sep 17 00:00:00 2001 From: David Gibson Date: Tue, 15 Sep 2020 13:55:15 +1000 Subject: [PATCH] device: Rename pciDeviceMap in sandbox struct 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 --- agent.go | 14 +++++++------- device.go | 4 ++-- device_test.go | 8 ++++---- mount_test.go | 10 +++++----- 4 files changed, 18 insertions(+), 18 deletions(-) diff --git a/agent.go b/agent.go index 33ee869f2..031600296 100644 --- a/agent.go +++ b/agent.go @@ -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 @@ -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 } @@ -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. @@ -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{}), diff --git a/device.go b/device.go index 28d98a063..3c8b83c24 100644 --- a/device.go +++ b/device.go @@ -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 } } diff --git a/device_test.go b/device_test.go index 51b9df04f..e9d928b59 100644 --- a/device_test.go +++ b/device_test.go @@ -872,12 +872,12 @@ 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) @@ -885,7 +885,7 @@ func TestGetDeviceName(t *testing.T) { assert.Nil(err) assert.Equal(name, path.Join(devRootPath, devName)) - delete(sb.pciDeviceMap, devPath) + delete(sb.sysToDevMap, devPath) go func() { for { diff --git a/mount_test.go b/mount_test.go index 823472ac6..913098a9e 100644 --- a/mount_test.go +++ b/mount_test.go @@ -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" @@ -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 { @@ -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"