From 0a4d443c81f25f04453aac5be9db616a0e0de391 Mon Sep 17 00:00:00 2001 From: David Gibson Date: Tue, 22 Sep 2020 15:31:28 +1000 Subject: [PATCH] device: Simplify uevent matching in listenToUdevEvents() 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 --- agent.go | 32 ++++++-------------------------- device_amd64.go | 4 ---- device_arm64.go | 4 ---- device_ppc64le.go | 4 ---- device_s390x.go | 4 ---- 5 files changed, 6 insertions(+), 42 deletions(-) diff --git a/agent.go b/agent.go index 031600296..4c0ff340b 100644 --- a/agent.go +++ b/agent.go @@ -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() diff --git a/device_amd64.go b/device_amd64.go index 66bc0522a..fe9f8b785 100644 --- a/device_amd64.go +++ b/device_amd64.go @@ -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" ) diff --git a/device_arm64.go b/device_arm64.go index b73b582d4..11c4e70d8 100644 --- a/device_arm64.go +++ b/device_arm64.go @@ -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" ) diff --git a/device_ppc64le.go b/device_ppc64le.go index 66bc0522a..fe9f8b785 100644 --- a/device_ppc64le.go +++ b/device_ppc64le.go @@ -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" ) diff --git a/device_s390x.go b/device_s390x.go index dd8cecab5..e28074c44 100644 --- a/device_s390x.go +++ b/device_s390x.go @@ -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" )