dmsetup and udev have the functionality needed to do this in a race-free
manner, but it's necessarily complicated and takes a while to get your head
around it. You'll need to use the dmsetup commands/options for udev cookies
described in the man page.
Alasdair