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

Commit

Permalink
device: Simplify uevent matching in listenToUdevEvents()
Browse files Browse the repository at this point in the history
This function watches for uvents that match addresses stored in
s.deviceWatchers() and if there's a matching entry signals the associated
channel.

"Matching" in this instance means soem sort of comparison between the
address we're watching for and the sysfs path in the uevent.  Currently we
match any of a bunch of different cases for different types of device.
Being very specific with how we match *sounds* like a good idea, but it's
complicated, tightly coupled to other parts of the code and, ultimately,
pointless.

The user of the data we're collecting here is getDeviceName().  Before
registering a watcher it checks s.sysToDevMap in case the uevent it's
interested in has already happened.

To have consistent behaviour regardless of when the uevent arrives,
the matching that getDeviceName() uses against s.sysToDevMap must be
the same as we use in listenToUdevEvents() and right now, it's not.
So, change the matching in listenToUdevEvents() to be the same as the
much simpler version in getDeviceName().

fixes #848

Signed-off-by: David Gibson <[email protected]>
  • Loading branch information
dgibson committed Sep 23, 2020
1 parent bd4dcc5 commit 0a4d443
Show file tree
Hide file tree
Showing 5 changed files with 6 additions and 42 deletions.
32 changes: 6 additions & 26 deletions agent.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
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"
)

0 comments on commit 0a4d443

Please sign in to comment.