我的属性太骚了,怎么办?
My attributes are way too racy, what should I do?
在 linux 设备驱动程序中,在 probe
中创建 sysfs 属性太过活泼了——具体而言,it experiences a race condition with userspace. The recommended workaround is to add your attributes to various default attribute groups so they can be automatically created before probe. For a device driver, struct device_driver
contains const struct attribute_group **groups
为此目的。
然而,struct attribute_group
only got a field for binary attributes in Linux 3.11。对于较旧的内核(特别是 3.4),设备驱动程序应该如何在探测之前创建 sysfs 二进制属性?
作为 3.11 开发周期的一部分引用(强调我的)Greg Kroah-Hartman from his comment to a merge request (that was merged by Linus:
Here are some driver core patches for 3.11-rc2. They aren't really
bugfixes, but a bunch of new helper macros for drivers to properly
create attribute groups, which drivers and subsystems need to fix up a
ton of race issues with incorrectly creating sysfs files (binary and
normal) after userspace has been told that the device is present.
Also here is the ability to create binary files as attribute groups, to solve that race condition, which was impossible to do before this, so that's my fault the drivers were broken.
所以看起来在旧内核上确实没有办法解决这个问题。
在 linux 设备驱动程序中,在 probe
中创建 sysfs 属性太过活泼了——具体而言,it experiences a race condition with userspace. The recommended workaround is to add your attributes to various default attribute groups so they can be automatically created before probe. For a device driver, struct device_driver
contains const struct attribute_group **groups
为此目的。
然而,struct attribute_group
only got a field for binary attributes in Linux 3.11。对于较旧的内核(特别是 3.4),设备驱动程序应该如何在探测之前创建 sysfs 二进制属性?
作为 3.11 开发周期的一部分引用(强调我的)Greg Kroah-Hartman from his comment to a merge request (that was merged by Linus:
Here are some driver core patches for 3.11-rc2. They aren't really bugfixes, but a bunch of new helper macros for drivers to properly create attribute groups, which drivers and subsystems need to fix up a ton of race issues with incorrectly creating sysfs files (binary and normal) after userspace has been told that the device is present.
Also here is the ability to create binary files as attribute groups, to solve that race condition, which was impossible to do before this, so that's my fault the drivers were broken.
所以看起来在旧内核上确实没有办法解决这个问题。