[systemd-devel] Trying to come up with udev rule for USB geographic naming

Andrei Borzenkov arvidjaar at gmail.com
Tue Jul 11 03:54:19 UTC 2017


11.07.2017 05:33, Paul D. DeRocco пишет:
> That is, I want a rule for creating a symlink that describes the USB port
> something is plugged into, rather than the specific device plugged into
> it. Linux USB has a way of representing the location of each physical
> jack, even when hubs are involved. For devices like USB serial and USB
> MIDI, I'd like apps to be able to refer to devices by where they're
> plugged in.
> 
> I used udevadm to generate the info for a USB MIDI converter. The first
> three levels look like this:
> 
> looking at device
> '/devices/platform/soc/3f980000.usb/usb1/1-1/1-1.2/1-1.2:1.0/sound/card1/m
> idiC1D0':
>   KERNEL=="midiC1D0"
>   SUBSYSTEM=="sound"
>   DRIVER==""
> 
> looking at parent device
> '/devices/platform/soc/3f980000.usb/usb1/1-1/1-1.2/1-1.2:1.0/sound/card1':
>   KERNELS=="card1"
>   SUBSYSTEMS=="sound"
>   DRIVERS==""
>   ATTRS{id}=="XMidi1X1"
>   ATTRS{number}=="1"
> 
> looking at parent device
> '/devices/platform/soc/3f980000.usb/usb1/1-1/1-1.2/1-1.2:1.0':
>   KERNELS=="1-1.2:1.0"
>   SUBSYSTEMS=="usb"
>   DRIVERS=="snd-usb-audio"
>   ATTRS{authorized}=="1"
>   ATTRS{bAlternateSetting}==" 0"
>   ATTRS{bInterfaceClass}=="01"
>   ATTRS{bInterfaceNumber}=="00"
>   ATTRS{bInterfaceProtocol}=="00"
>   ATTRS{bInterfaceSubClass}=="01"
>   ATTRS{bNumEndpoints}=="00"
>   ATTRS{supports_autosuspend}=="1"
> 
> (There may be spurious line breaks in there, due to email.)
> 
> I'd like an alias for this device to be "/dev/midi1-1.2:1.0". I tried the
> following:
> 
> KERNEL=="midiC*", DRIVERS=="snd-usb-audio", SYMLINK+="midi%k"
> 

You probably want %b instead of %k here which should refer to device
name matched by DRIVERS.

> It did bupkis. The man page seems to imply that, while a single rule can't
> match items from different parents, it's okay to match something in the
> device and then something else in a parent. So I would expect the KERNEL
> key would match the device itself, DRIVERS would match a parent, but what
> then does %k refer to, the kernel name in the device or the kernel name in
> the parent?
> 
> But it not only didn't create a "midi1-1.2:1.0", it didn't create a
> "midimidiC1D0" either, so it doesn't look like the rule matched at all.
> 

It could be race condition between driver loading and follow-up
processing. Or there is some rule that stops further processing. Start
with "udevadm test" to verify.

> There is already a symlink
> "/dev/snd/by-path/platform-3f980000.usb-usb-0:1.2:1.0", but it refers to
> the useless "controlC1" interface. It also doesn't appear to be generated
> by an explicit rule anywhere that might show me what to do.
> 

It is created by 60-persistent-alsa.rules that explicitly restricts
processing to controlC*.

> What am I doing wrong? Do I need a rule that just matches the MIDI device,
> and then runs a script that searches for the parent name?
> 



More information about the systemd-devel mailing list