Skip to content

Commit

Permalink
device: check for existing device PCI path before waiting
Browse files Browse the repository at this point in the history
If agent is up AFTER device is hotplugged, it will miss the window
of catching the device hotplug uevent and as a result it cannot fill
it in the device pci map.

We should check for such case before trying to wait otherwise the
waiting will always fail timeout.

Signed-off-by: Peng Tao <bergwolf@gmail.com>
  • Loading branch information
bergwolf committed Sep 7, 2018
1 parent 3441244 commit 7caf1c8
Showing 1 changed file with 13 additions and 1 deletion.
14 changes: 13 additions & 1 deletion device.go
Original file line number Diff line number Diff line change
Expand Up @@ -112,8 +112,8 @@ func getPCIDeviceName(s *sandbox, pciID string) (string, error) {

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

// Check if the PCI identifier is in PCI device map.
s.Lock()
// Check if the PCI identifier is in PCI device map.
for key, value := range s.pciDeviceMap {
if strings.Contains(key, pciAddr) {
devName = value
Expand All @@ -122,6 +122,15 @@ func getPCIDeviceName(s *sandbox, pciID string) (string, error) {
}
}

// Check if the PCI path is present before we setup the pci device map.
_, err = os.Stat(filepath.Join(rootBusPath, pciAddr))
if err == nil {
// Found pci path. It's there before we wait for the device map.
// We cannot find the name for it.
fieldLogger.Info("Device found on pci device path")
return "", nil
}

// If device is not found in the device map, hotplug event has not
// been received yet, create and add channel to the watchers map.
// The key of the watchers map is the device we are interested in.
Expand Down Expand Up @@ -160,6 +169,9 @@ func virtioBlkDeviceHandler(device pb.Device, spec *pb.Spec, s *sandbox) error {
if err != nil {
return err
}
if devPath == "" {
return fmt.Errorf("cannot find device name for virtio block device")
}
device.VmPath = devPath

return updateSpecDeviceList(device, spec)
Expand Down

0 comments on commit 7caf1c8

Please sign in to comment.