jcnelson / vdev

A device-file manager for *nix
GNU General Public License v3.0
101 stars 13 forks source link

/dev/snd/by-id #26

Closed fbt closed 9 years ago

fbt commented 9 years ago

Something vdevd doesn't do compared to (e)udev — links in snd/by-id. Without those jack and pulse both don't work.

jcnelson commented 9 years ago

Hi fbt,

Thank you for reporting this. I need to figure out which udev rules generate snd/by-id. On my system, it's only 60-persistent-alsa.rules, and it only generates symlinks for USB audio devices. Is this the case for you too?

Thanks!

fbt commented 9 years ago

I only have symlinks for USB audio devices, yes.

jcnelson commented 9 years ago

Can you try with a commit later than 6ce53f20d3093aeeac5a83d86dcb21481d3b4cc5? I added experimental code to generate /dev/snd/by-id. I don't have any USB audio devices, so I can't test it locally (hence "experimental").

Thanks for your patience!

fbt commented 9 years ago

Nope, doesn't create em. Here's the output of vdevd -1 -f -v2 /mnt/dev: http://sprunge.us/WfdR

jcnelson commented 9 years ago

Thanks for giving it a try, and thanks for sending me the trace!

I've noticed some odd behavior from the trace. A lot of helper scripts aren't getting run for some reason. It looks like only ifname.sh, usb-name.sh, and input.sh get invoked (sound.sh, which sets up /dev/snd, isn't getting run at all).

Here's an example of what I would expect from processing /dev/sda:

27347:-371292416: [        device.c:0757] vdev_device_add: DEBUG: ADD device: type 'block' at 'sda' ('sda' 8:0)
27347:-371292416: [        action.c:0507] vdev_action_run_sync: DEBUG: run command: 'exec "$VDEV_HELPERS/block.sh"'
27347:-371292416: [        action.c:0510] vdev_action_run_sync: DEBUG: command env: 'VDEV_MOUNTPOINT=/home/jude/Desktop/research/git/vdev/tmp'
27347:-371292416: [        action.c:0510] vdev_action_run_sync: DEBUG: command env: 'VDEV_ACTION=add'
27347:-371292416: [        action.c:0510] vdev_action_run_sync: DEBUG: command env: 'VDEV_PATH=sda'
27347:-371292416: [        action.c:0510] vdev_action_run_sync: DEBUG: command env: 'VDEV_METADATA=/home/jude/Desktop/research/git/vdev/tmp/metadata//sda'
27347:-371292416: [        action.c:0510] vdev_action_run_sync: DEBUG: command env: 'VDEV_MAJOR=8'
27347:-371292416: [        action.c:0510] vdev_action_run_sync: DEBUG: command env: 'VDEV_MINOR=0'
27347:-371292416: [        action.c:0510] vdev_action_run_sync: DEBUG: command env: 'VDEV_MODE=block'
27347:-371292416: [        action.c:0510] vdev_action_run_sync: DEBUG: command env: 'VDEV_HELPERS=//lib/vdev'
27347:-371292416: [        action.c:0510] vdev_action_run_sync: DEBUG: command env: 'VDEV_LOGFILE=/tmp/vdevd.log'
27347:-371292416: [        action.c:0510] vdev_action_run_sync: DEBUG: command env: 'VDEV_INSTANCE=O88L0729671M850O917P5474MLO8K5050K7K526797L446N1162L1LO0M47904KL'
27347:-371292416: [        action.c:0510] vdev_action_run_sync: DEBUG: command env: 'VDEV_FIRMWARE_DIR=//lib/firmware'
27347:-371292416: [        action.c:0510] vdev_action_run_sync: DEBUG: command env: 'VDEV_IFNAMES_PATH=//etc/vdev/ifnames.conf'
27347:-371292416: [        action.c:0510] vdev_action_run_sync: DEBUG: command env: 'VDEV_OS_DEVNAME=sda'
27347:-371292416: [        action.c:0510] vdev_action_run_sync: DEBUG: command env: 'VDEV_OS_DEVPATH=/devices/pci0000:00/0000:00:1f.2/ata1/host0/target0:0:0/0:0:0:0/block/sda'
27347:-371292416: [        action.c:0510] vdev_action_run_sync: DEBUG: command env: 'VDEV_OS_DEVTYPE=disk'
27347:-371292416: [        action.c:0510] vdev_action_run_sync: DEBUG: command env: 'VDEV_OS_SUBSYSTEM=block'
27347:-371292416: [        action.c:0510] vdev_action_run_sync: DEBUG: command env: 'VDEV_OS_SYSFS_MOUNTPOINT=/sys'
27347:-371292416: [        action.c:0515] vdev_action_run_sync: DEBUG: exit status 0
27347:-371292416: [        action.c:0507] vdev_action_run_sync: DEBUG: run command: 'exec "$VDEV_HELPERS/disk.sh"'
27347:-371292416: [        action.c:0510] vdev_action_run_sync: DEBUG: command env: 'VDEV_MOUNTPOINT=/home/jude/Desktop/research/git/vdev/tmp'
27347:-371292416: [        action.c:0510] vdev_action_run_sync: DEBUG: command env: 'VDEV_ACTION=add'
27347:-371292416: [        action.c:0510] vdev_action_run_sync: DEBUG: command env: 'VDEV_PATH=sda'
27347:-371292416: [        action.c:0510] vdev_action_run_sync: DEBUG: command env: 'VDEV_METADATA=/home/jude/Desktop/research/git/vdev/tmp/metadata//sda'
27347:-371292416: [        action.c:0510] vdev_action_run_sync: DEBUG: command env: 'VDEV_MAJOR=8'
27347:-371292416: [        action.c:0510] vdev_action_run_sync: DEBUG: command env: 'VDEV_MINOR=0'
27347:-371292416: [        action.c:0510] vdev_action_run_sync: DEBUG: command env: 'VDEV_MODE=block'
27347:-371292416: [        action.c:0510] vdev_action_run_sync: DEBUG: command env: 'VDEV_HELPERS=//lib/vdev'
27347:-371292416: [        action.c:0510] vdev_action_run_sync: DEBUG: command env: 'VDEV_LOGFILE=/tmp/vdevd.log'
27347:-371292416: [        action.c:0510] vdev_action_run_sync: DEBUG: command env: 'VDEV_INSTANCE=O88L0729671M850O917P5474MLO8K5050K7K526797L446N1162L1LO0M47904KL'
27347:-371292416: [        action.c:0510] vdev_action_run_sync: DEBUG: command env: 'VDEV_FIRMWARE_DIR=//lib/firmware'
27347:-371292416: [        action.c:0510] vdev_action_run_sync: DEBUG: command env: 'VDEV_IFNAMES_PATH=//etc/vdev/ifnames.conf'
27347:-371292416: [        action.c:0510] vdev_action_run_sync: DEBUG: command env: 'VDEV_OS_DEVNAME=sda'
27347:-371292416: [        action.c:0510] vdev_action_run_sync: DEBUG: command env: 'VDEV_OS_DEVPATH=/devices/pci0000:00/0000:00:1f.2/ata1/host0/target0:0:0/0:0:0:0/block/sda'
27347:-371292416: [        action.c:0510] vdev_action_run_sync: DEBUG: command env: 'VDEV_OS_DEVTYPE=disk'
27347:-371292416: [        action.c:0510] vdev_action_run_sync: DEBUG: command env: 'VDEV_OS_SUBSYSTEM=block'
27347:-371292416: [        action.c:0510] vdev_action_run_sync: DEBUG: command env: 'VDEV_OS_SYSFS_MOUNTPOINT=/sys'
27347:-371292416: [        action.c:0515] vdev_action_run_sync: DEBUG: exit status 0
27347:-371292416: [        action.c:0507] vdev_action_run_sync: DEBUG: run command: 'test -n "$(echo "$VDEV_OS_DEVNAME" | grep dm-[0-9]*)" && "$VDEV_HELPERS/dm-disk.sh" && exit $?; exit 0'
27347:-371292416: [        action.c:0510] vdev_action_run_sync: DEBUG: command env: 'VDEV_MOUNTPOINT=/home/jude/Desktop/research/git/vdev/tmp'
27347:-371292416: [        action.c:0510] vdev_action_run_sync: DEBUG: command env: 'VDEV_ACTION=add'
27347:-371292416: [        action.c:0510] vdev_action_run_sync: DEBUG: command env: 'VDEV_PATH=sda'
27347:-371292416: [        action.c:0510] vdev_action_run_sync: DEBUG: command env: 'VDEV_METADATA=/home/jude/Desktop/research/git/vdev/tmp/metadata//sda'
27347:-371292416: [        action.c:0510] vdev_action_run_sync: DEBUG: command env: 'VDEV_MAJOR=8'
27347:-371292416: [        action.c:0510] vdev_action_run_sync: DEBUG: command env: 'VDEV_MINOR=0'
27347:-371292416: [        action.c:0510] vdev_action_run_sync: DEBUG: command env: 'VDEV_MODE=block'
27347:-371292416: [        action.c:0510] vdev_action_run_sync: DEBUG: command env: 'VDEV_HELPERS=//lib/vdev'
27347:-371292416: [        action.c:0510] vdev_action_run_sync: DEBUG: command env: 'VDEV_LOGFILE=/tmp/vdevd.log'
27347:-371292416: [        action.c:0510] vdev_action_run_sync: DEBUG: command env: 'VDEV_INSTANCE=O88L0729671M850O917P5474MLO8K5050K7K526797L446N1162L1LO0M47904KL'
27347:-371292416: [        action.c:0510] vdev_action_run_sync: DEBUG: command env: 'VDEV_FIRMWARE_DIR=//lib/firmware'
27347:-371292416: [        action.c:0510] vdev_action_run_sync: DEBUG: command env: 'VDEV_IFNAMES_PATH=//etc/vdev/ifnames.conf'
27347:-371292416: [        action.c:0510] vdev_action_run_sync: DEBUG: command env: 'VDEV_OS_DEVNAME=sda'
27347:-371292416: [        action.c:0510] vdev_action_run_sync: DEBUG: command env: 'VDEV_OS_DEVPATH=/devices/pci0000:00/0000:00:1f.2/ata1/host0/target0:0:0/0:0:0:0/block/sda'
27347:-371292416: [        action.c:0510] vdev_action_run_sync: DEBUG: command env: 'VDEV_OS_DEVTYPE=disk'
27347:-371292416: [        action.c:0510] vdev_action_run_sync: DEBUG: command env: 'VDEV_OS_SUBSYSTEM=block'
27347:-371292416: [        action.c:0510] vdev_action_run_sync: DEBUG: command env: 'VDEV_OS_SYSFS_MOUNTPOINT=/sys'
27347:-371292416: [        action.c:0515] vdev_action_run_sync: DEBUG: exit status 0

In your trace, I see only:

04488:-1155684608: [        device.c:0757] vdev_device_add: DEBUG: ADD device: type 'block' at 'sda' ('sda' 8:0)

Can you confirm that:

Thanks!

fbt commented 9 years ago

I was testing snd specifically and didn't inspect /dev properly. Turns out I was a dummy and ran vdevd over an empty dir instead of devtmpfs. When I ran it properly, it did set up snd/by-id correctly. Here's a log of a proper run: http://sprunge.us/COcN

Now to helpers. I have looked at the log, and these pop out:

32687:1120143104: [        action.c:0879] vdev_action_run_commands: ERROR: vdev_action_run_sync('. "$VDEV_HELPERS/subr.sh"; vdev_permissions root.fuse 0777 "$VDEV_MOUNTPOINT/$VDEV_PATH"') rc = 1

Why root.fuse? The function feeds that directly into chown, and chown expects root:fuse:

> vdev_permissions root.fuse 0777 /mnt/dev/fuse 
/bin/chown: invalid user: ‘root.fuse’

As to your questions:

jcnelson commented 9 years ago

Thanks for trying it again! I'm glad to know that dev/snd/by-id got set up correctly.

Interestingly, the use of devtmpfs shouldn't make a difference in the output. It doesn't on my machine or my various Devuan VMs, for example. In fact, I disable devtmpfs when I use vdev to manage /dev. The fact that using devtmpfs makes a difference means there's a bug somewhere.

Your /usr/lib/vdev looks correct. Thank you for sending me the listing to verify.

You're right that the use of ":" is more appropriate than "." for chown's arguments, particularly because the ":" will report when a group does not exist. I will change this. I'm guessing you're seeing these errors in the first place because you don't have "fuse" or "dialout" groups defined? Admittedly, the helpers assume that Debian's default groups exist, but I'm open to changing this for portability--perhaps there can be a /lib/vdev/groups.sh shell library that defines shell variables for the distinct users and groups vdev needs, but whose values can be set on a per-distro basis.

The only non-POSIX shell feature I use in the scripts that I'm aware of (I need to go run checkbashisms at some point to be sure) is the "local" directive. I'm open to moving away from it, if needed--I'll can prefix function-local variables with "local" or something like that. I'm striving for both POSIX compliance and reliance on command-line utilities in /bin and /sbin only (not /usr), so if you notice any violations of these goals, they're bugs for me to fix :)

Unrelated, would you like to be included in the TESTERS file? If so, is there a particular username or alias you'd prefer? Feel free to email me if you'd prefer not to post it here :)

fbt commented 9 years ago

Oh. You're right, there is no fuse group on Arch. It's assumed that fuse is 777. But it's a matter of configuration, really. I should and will provide distro-specific configuration.

If you actually use 'local', then, by all means, keep it and the shebang. I see no problems with depending on a particular shell.

If you are going to add me anywhere, I go by fbt or Jack L. Frost with my main email being fbt@fleshless.org.

fbt commented 9 years ago

I've done a few clean tests with vdevd to make sure it did, in fact, create snd/by-id, and it doesn't. I thought it did because devtmpfs is actually persistent till you reboot. You can mount it elsewhere and it's the same fs. So I had snd/by-id created by eudev that I ran and forgot that I did it.

Booting with vdevd and testing it on a “clean” devtmpfs, as well as an empty tmpfs, results in no snd/by-id. Here's a clean run: http://sprunge.us/jeMF

I've added some debug code into sound.sh and this is what I've found: The part with the links doesn't run at all, because vdev_subsystems is being fed the wrong path: /devices/pci0000:00/0000:00:14.0/usb1/1-3/1-3:1.0/sound/card1/controlC1 instead of /sys/devices/pci0000:00/0000:00:14.0/usb1/1-3/1-3:1.0/sound/card1/controlC1

But then it does nothing anyway, because VDEV_USB_SERIAL is not set.

UPD: you can check grep's exit code instead of testing the output:

if vdev_subsystems "/sys/$VDEV_OS_DEVPATH" | /bin/grep 'usb' &>/dev/null; then
    ...
fi
jcnelson commented 9 years ago

Hey, thanks for trying again on a clean install. Part of my motivation to design vdevd to not need devtmpfs is to avoid having to deal with its weird behavior :) Especially in the context of application containers.

The part with the links doesn't run at all, because vdev_subsystems is being fed the wrong path:

Good catch!

But then it does nothing anyway, because VDEV_USB_SERIAL is not set.

I made this mistake more than once, it seems. The stat_usb binary a couple lines down (the one in the 'eval' statement) is getting fed the wrong path too. The stat_usb binary takes a /sys/devices/... path and generates a list of environment variable declarations (including one for VDEV_USB_SERIAL), which get imported into the script through the eval.

I just pushed a possible fix for this (b20bf81dd51cc219f172c4972418e229ba008239). Can you see if it works? Thanks again for your patience--I realize this must be tedious, since I can't test it locally.

Also, prior to this commit, I switched all the vdev_permissions calls to using ":" instead of ".", so you should be seeing the more informative "group does not exist" errors instead of the "user does not exist" errors. I can get a list of all the users and groups vdev's helper scripts expect to exist, and start a "PACKAGING" document that describes potential pitfalls like this. Thanks for keeping me informed!

fbt commented 9 years ago

Yup, works on my two desktops, snd/by-id is being created properly. chown now spews out a more informative “invalid group”.

I'll get to distro-specific configs on the weekend probably.

Keep up the good work :)