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

Commit

Permalink
agent: Remove dev from pciDeviceMap when device is unplugged
Browse files Browse the repository at this point in the history
Delete `uEv.DevPath` from pciDeviceMap when recieving `remove` uevent.

Fixes #729
Signed-off-by: Li Yuxuan <liyuxuan04@baidu.com>
  • Loading branch information
darfux committed Feb 27, 2020
1 parent f8f6b67 commit 3f0d98e
Showing 1 changed file with 13 additions and 6 deletions.
19 changes: 13 additions & 6 deletions agent.go
Original file line number Diff line number Diff line change
Expand Up @@ -710,11 +710,6 @@ func (s *sandbox) listenToUdevEvents() {
continue
}

// We only care about add event
if uEv.Action != "add" {
continue
}

span, _ := trace(rootContext, "udev", "udev event")
span.setTag("udev-action", uEv.Action)
span.setTag("udev-name", uEv.DevName)
Expand All @@ -730,6 +725,18 @@ func (s *sandbox) listenToUdevEvents() {
"uevent-devname": uEv.DevName,
})

if uEv.Action == "remove" {
fieldLogger.Infof("Remove dev from pciDeviceMap")
s.Lock()
delete(s.pciDeviceMap, uEv.DevPath)
s.Unlock()
goto FINISH_SPAN
}

if uEv.Action != "add" {
goto FINISH_SPAN
}

fieldLogger.Infof("Received add uevent")

// Check if device hotplug event results in a device node being created.
Expand Down Expand Up @@ -782,7 +789,7 @@ func (s *sandbox) listenToUdevEvents() {
fieldLogger.WithError(err).Error("failed online device")
}
}

FINISH_SPAN:
span.finish()
}
}
Expand Down

0 comments on commit 3f0d98e

Please sign in to comment.