[Toybox] [PATCH] mdev: implement basic hotplug support (and probe for partitions).

Isaac Dunham ibid.ag at gmail.com
Sat Apr 18 18:30:31 PDT 2015


Hello Rob,
Today I decided to see if I could implement hotplug support cleanly.
Here's a patch that adds support for hotplug (including device removal),
as well as making mdev probe for partitions. It costs about 30 lines of
new code; most of the "deletions" are just reindented.

I think it would be possible to implement this more concisely by doing
roughly this in the hotplug section:
    char *temp, *devpath = getenv("DEVPATH");

    if (!devpath) show_usage();
    temp = xmprintf("/sys%s/dev", devpath);
    make_device(devpath);
    free(devpath);

and in make_device(), if optflags is 0 then use the getenv("SUBSYSTEM")
path to determine if it's a block device.
This would still require checking for ACTION=remove.

But this feels "wrong", since MAJOR/MINOR/DEVNAME are there.

In case anyone thinks this is about to replace busybox mdev, here's what's
not supported from busybox:
* spawning helpers (FEATURE_MDEV_EXECUTE: @|$|*)
* serializing events via $SEQNUM and /dev/mdev.seq
* environment rules ($MODALIAS=.*)
  - this implies that module autoloading doesn't work; apparently the
    kernel does *not* autoload modules in most cases, although there
    seem to be a few places where it does. Some people object to
    autoloading modules, FWIW.
* move device (=dir/ | >dir/), regex-based rename
* username/group lookup
...in other words, most of the features people use mdev for.

If you want module autoloading without a rewrite of the config file stuff,
it would be trivial to implement it via something like this (in the hotplug
part of mdev_main):
    char alias = getenv("MODALIAS");
    if (alias) xexec((char *[]){"modprobe", "-abq", alias, NULL});
But I don't see how to make that configureable.


While I've worked on busybox mdev recently (within the past month),
I have found the way it's structured to be cumbersome and hideous.
Even if it were license compatible (which it isn't), I wouldn't want
to copy it.

Thanks,
Isaac Dunham
-------------- next part --------------
A non-text attachment was scrubbed...
Name: 0001-mdev-implement-hotplug-support.patch
Type: text/x-diff
Size: 3362 bytes
Desc: not available
URL: <http://lists.landley.net/pipermail/toybox-landley.net/attachments/20150419/e13e3a5c/attachment-0004.patch>


More information about the Toybox mailing list