Skip to content

Tolerate new udev actions "bind" and "unbind" #6

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

navaati
Copy link

@navaati navaati commented Jan 29, 2022

Recent kernel and udev versions have added new actions that are triggered on top of the usual add and remove actions. This causes the script to exit 1 every time, which appears as a warning in udev logs. While not a big deal, this is ugly. This patch fixes that and protects us against future new events as well.

Recent kernel and udev versions have added new actions that are triggered on top of the usual add and remove actions. This causes the script to `exit 1` every time, which appears as a warning in udev logs. Why not a big deal, this is ugly, this patch fixes that and protects us against future new events as well.
@Geekdude
Copy link

@navaati I'm new to udev scripts. Is the bind action in addition to the add action, or does it replace it? I had to modify the script like #7 for it to work as expected on Ubuntu 20.04.4 LTS.

@navaati
Copy link
Author

navaati commented Aug 18, 2022

It’s in addition, which means that your change in #7 will try to attach twice, which is probably harmless but still not great.

@Geekdude
Copy link

@navaati I tried the navaati:patch-1 branch, and the USB device did not attach to the VM as expected. The virsh attach-device command failed with unable to execute QEMU command 'device_add': failed to find host USB device

image

When I use my branch Geekdude:master, it does indeed run the script twice; on the add action it fails with the same error, then on the bind action, it succeeds.

image

@navaati
Copy link
Author

navaati commented Aug 21, 2022

Oh ok that’s much curious, thanks for the testing. Let me see my current file… Ahah ! Interesting, I have an additionnal "sleep 1" at the end (in between line 100 and 101). So maybe the "add" action is too early and the "bind" action is the right one, and we can kind of combine both our patches to arrive at the right result…

We need to check the udev doc regarding the lifecycle and timing of events.

@navaati
Copy link
Author

navaati commented Aug 21, 2022

Most extensive documentation seems to be this LWN article (bless jcorbet): https://lwn.net/Articles/837033/.

@navaati
Copy link
Author

navaati commented Aug 21, 2022

Ok so reading that, definitely "bind" is the later event and the one we want to use. I’ll rework my branch later today to use it (and ignore other events, in particular add) and remove the sleep, then I’ll test-drive that for a week. It makes the change more impactful, though, because it makes the script not work on systemd versions older than 247 (I think CentOS7 uses systemd 219), that’ll be a decision to be taken by the maintainers.

@Geekdude
Copy link

I was thinking along the same lines as well. If bind is the event we want, is it better to break backward capability by only responding to bind events or to maintain backward capability, but to have the add action fail? The proper approach is probably to have conditionals that check the version systemd/kernel and respond according.

Also, according to this line, "For drivers that support the new mechanism, a BIND event for a device will follow the ADD event once the device is ready to operate." We might still want to respond to both event types since, depending on the drivers, there might only be an ADD event. I don't think there is any issue with trying to attach a USB device twice with virsh, but that might be something we should test. So we really want bind events, but if there will not be a bind event, then the script should respond to the add event.

argorain added a commit to argorain/usb-libvirt-hotplug that referenced this pull request Feb 29, 2024
As suggested in discussion under PR
olavmrk#6 which is also
absorbed, further changes were needed but they never materialised.

This change is not compatible with systemd older than 247.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants