First page Back Continue Last page Graphics
The solution (4) - cookies
A device-mapper cookie is a 32-bit integer generated by a userspace program that is going to need to wait for udev.
We pass the cookie into the kernel using the event number field which happens not to be used for input by the ioctls that need a cookie.
The cookie is passed to udev when uevents are generated and appears as the environment variable DM_COOKIE.
When LVM2 has several related events to wait for, it uses the same cookie for them all.
Our current implementation uses a semaphore for each cookie. To avoid races, we increment it prior to submitting the ioctls and wait for it to drop to 0. The last udev rule decrements it.