Discussion:
[PATCH] mdev: Follow symbolic links in /sys
Add Reply
Marius Adaskevicius
2018-11-16 06:08:31 UTC
Reply
Permalink
The current code does not follow symbolic links when iterating over /sys
entries
for block devices when run with -s flag. As a result, mdev rules are never
executed, for example, for USB flash drive partitions.

On i.MX6 board with 4.9.11 kernel:

/sys/block/sda ->
/sys/devices/soc0/soc/2100000.aips-bus/2184200.usb/ci_hdrc.1/usb1/1-1/1-1.2/1-1.2:1.0/host0/target0:0:0/0:0:0:0/block/sda
/sys/block/sda/sda1 ->
/sys/devices/soc0/soc/2100000.aips-bus/2184200.usb/ci_hdrc.1/usb1/1-1/1-1.2/1-1.2:1.0/host0/target0:0:0/0:0:0:0/block/sda/sda1

As a workaround, USB flash drive has to be reinserted so that mdev rules are
executed in response to kernel hotplug events. The issue can be fixed by
adding a flag to follow symbolic links so that partition entries could be
processed as well.

---
 toys/pending/mdev.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/toys/pending/mdev.c b/toys/pending/mdev.c
index 0493f1a..b80efea 100644
--- a/toys/pending/mdev.c
+++ b/toys/pending/mdev.c
@@ -280,7 +280,7 @@ static int callback(struct dirtree *node)
   // Circa 2.6.25 the entries more than 2 deep are all either redundant
   // (mouse#, event#) or unnamed (every usb_* entry is called "device").

-  return (node->parent && node->parent->parent) ? 0 : DIRTREE_RECURSE;
+  return (node->parent && node->parent->parent) ? 0 : (DIRTREE_RECURSE
| DIRTREE_SYMFOLLOW);
 }

 void mdev_main(void)
--
2.7.4
Rob Landley
2018-11-16 23:21:10 UTC
Reply
Permalink
The current code does not follow symbolic links when iterating over /sys entries
for block devices when run with -s flag. As a result, mdev rules are never
executed, for example, for USB flash drive partitions.
I'd assumed that devtmpfs had removed most of the call for mdev, but apparently
not. I should study what busybox added over the past 5 years, finish this
command, and promote it.

Alas I'd hit 40 hours at $DAYJOB sometime yesterday, and probably have to come
in saturday too.
/sys/block/sda ->
/sys/devices/soc0/soc/2100000.aips-bus/2184200.usb/ci_hdrc.1/usb1/1-1/1-1.2/1-1.2:1.0/host0/target0:0:0/0:0:0:0/block/sda
/sys/block/sda/sda1 ->
/sys/devices/soc0/soc/2100000.aips-bus/2184200.usb/ci_hdrc.1/usb1/1-1/1-1.2/1-1.2:1.0/host0/target0:0:0/0:0:0:0/block/sda/sda1
As a workaround, USB flash drive has to be reinserted so that mdev rules are
executed in response to kernel hotplug events. The issue can be fixed by
adding a flag to follow symbolic links so that partition entries could be
processed as well.
The problem with following symlinks is you can easily wind up in endless loops.
What it should be looking at is /sys/class/*/*/dev and then the first * being
block means mknod 'b' instead of 'c'.

(Greg KH and Kay Sievers keep changing what's under sysfs and breaking code
attempting to parse it. It's really annoying. I wrestled with them for _years_
about it...)

Rob
Marius Adaskevicius
2018-11-19 06:05:56 UTC
Reply
Permalink
Post by Rob Landley
The problem with following symlinks is you can easily wind up in endless loops.
What it should be looking at is /sys/class/*/*/dev and then the first * being
block means mknod 'b' instead of 'c'.
(Greg KH and Kay Sievers keep changing what's under sysfs and breaking code
attempting to parse it. It's really annoying. I wrestled with them for _years_
about it...)
I agree, although currently dirtree callback skips entries that are more
than
two levels deep so endless loops should not be a problem.
Rob Landley
2018-11-30 01:37:45 UTC
Reply
Permalink
Post by Rob Landley
The problem with following symlinks is you can easily wind up in endless loops.
What it should be looking at is /sys/class/*/*/dev and then the first * being
block means mknod 'b' instead of 'c'.
(Greg KH and Kay Sievers keep changing what's under sysfs and breaking code
attempting to parse it. It's really annoying. I wrestled with them for _years_
about it...)
I agree, although currently dirtree callback skips entries that are more than
two levels deep so endless loops should not be a problem.
Sorry for the delay. Fixed.

Rob

Loading...