Skip to content
This repository was archived by the owner on May 12, 2021. It is now read-only.
Merged
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
46 changes: 13 additions & 33 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 All @@ -774,34 +774,14 @@ func (s *sandbox) listenToUdevEvents() {

fieldLogger.Infof("Got a wait channel for device %s", devAddress)

// blk driver case
if strings.HasPrefix(uEv.DevPath, filepath.Join(rootBusPath, devAddress)) {
goto OUT
}

// pmem/nvdimm case
if strings.Contains(uEv.DevPath, pfnDevPrefix) && strings.HasSuffix(uEv.DevPath, devAddress) {
goto OUT
}

// This is a pretty imperfect way of
// matching, but it's the same as we
// use in getDeviceName()
if strings.Contains(uEv.DevPath, devAddress) {
// scsi driver case
if strings.HasSuffix(devAddress, scsiBlockSuffix) {
goto OUT
}
// blk-ccw driver case
if strings.HasSuffix(devAddress, blkCCWSuffix) {
goto OUT
}
ch <- uEv.DevName
close(ch)
delete(s.deviceWatchers, devAddress)
}

continue

OUT:
ch <- uEv.DevName
close(ch)
delete(s.deviceWatchers, devAddress)

}

s.Unlock()
Expand Down Expand Up @@ -1548,7 +1528,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
4 changes: 0 additions & 4 deletions device_amd64.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,4 @@ const (
// 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"

// /dev/pmemX devices exported in the ACPI sysfs (/devices/LNXSYSTM) are
// in a subdirectory whose prefix is pfn (page frame number).
pfnDevPrefix = "/pfn"
)
4 changes: 0 additions & 4 deletions device_arm64.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,4 @@ const (
// 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"

// /dev/pmemX devices exported in the ACPI sysfs (/devices/LNXSYSTM) are
// in a subdirectory whose prefix is pfn (page frame number).
pfnDevPrefix = "/pfn"
)
4 changes: 0 additions & 4 deletions device_ppc64le.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,4 @@ const (
// 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"

// /dev/pmemX devices exported in the ACPI sysfs (/devices/LNXSYSTM) are
// in a subdirectory whose prefix is pfn (page frame number).
pfnDevPrefix = "/pfn"
)
4 changes: 0 additions & 4 deletions device_s390x.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,4 @@ const (
// 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"

// /dev/pmemX devices exported in the ACPI sysfs (/devices/LNXSYSTM) are
// in a subdirectory whose prefix is pfn (page frame number).
pfnDevPrefix = "/pfn"
)
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