Hi, I'd like to discuss these rules with you and any comments are welcome. These are the prototypes of the rules we would like to use for device-mapper and its subsystems (LVM, multipath, etc.). We use a simple notification command "dmsetup udevnotify" that we have added. We send a notification when all the rules are completed, so we are sure that all the udev actions are complete. The "DM_COOKIE" value you can see in the rules is just a random numeric value we set for every action (ioctl) and return as env var in uevents. When we want to group these devices together, we just set the same cookie value for every device in a group. We can notify the waiting process directly this way. We use this method instead of comparing queued/processed udev event numbers (this way we are sure we don't waste time waiting for unrelated events). You can spot the use of the "last_rule", which seems to be controversial. The reason is that we require reliability and performance and we'd like to have more control over the rules that are applied for DM devices as well. Also, we would like to minimize any problems caused by some general rules creating wrong nodes or delaying the udev response for DM devices in any way (the process that fired the actions is waiting for the notification from udev rule!). And this is the part I'd like to discuss -- I know the usaage of "last_rule" is not perfect for the others, but we really need to satisfy the needs described above. There could be some system that requires the information about our devices, but we can resend the events for these systems if it is really necessary (for example the HAL). Simply, we need more control over this process. We also need a separate place to define permissions and also a separate place to register the subsystems. Therefore, the rules are separated into several files as you can see below. If you have any suggestions or critique, please, let me know. Thank you very much for any comments in advance... Peter These rules are supposed to be installed in /lib/udev/rules.d dir: ================================================================== 10-dm-getname.rules (set DM_NAME and DM_UUID env vars used in rules later) -------------------------------------------------------------------------- SUBSYSTEM!="block", GOTO="dm_end" KERNEL!="dm-[0-9]*", GOTO="dm_end" ACTION!="change", GOTO="dm_end" # "dm" sysfs subdirectory is available in kernels 2.6.29 and later. # We have to check for its existence and use dmsetup tool instead # to get the DM name and UUID if this subdirectory is not present. # We use DM_NAME and DM_UUID in rules later. TEST=="dm", ENV{DM_NAME}="$attr{dm/name}", ENV{DM_UUID}="$attr{dm/uuid}" TEST!="dm", IMPORT{program}="/sbin/dmsetup info -j %M -m %m -c --nameprefixes --noheadings --rows -o name,uuid" LABEL="dm_end" 12-dm.rules (create plain DM device nodes in /dev/mapper) --------------------------------------------------------- KERNEL=="device-mapper", NAME="exp_mapper/control" SUBSYSTEM!="block", GOTO="dm_end" KERNEL!="dm-[0-9]*", GOTO="dm_end" ACTION!="change|remove", GOTO="dm_end" ACTION=="change", NAME="mapper/$env{DM_NAME}" # If any DM subsystem is registered, we don't do any notificatons here. # It's the responsibility of the subsystem's rules to do this notification, # so the waiting process is notified after all the required actions are done. # We use the "last_rule" functionality, so we are sure that no other rule is # processed afterwards. ENV{DM_SUBSYS}=="?*", GOTO="dm_end" ENV{DM_COOKIE}=="?*", RUN+="/sbin/dmsetup udevnotify $env{DM_COOKIE}", OPTIONS+="last_rule" LABEL="dm_end" 13-lvm.rules (create symlinks for LVM -- /dev/VG_NAME/LV_NAME) -------------------------------------------------------------- SUBSYSTEM!="block", GOTO="lvm_end" KERNEL!="dm-[0-9]*", GOTO="lvm_end" ACTION!="change|remove", GOTO="lvm_end" ENV{DM_SUBSYS}!="LVM", GOTO="lvm_end" # Split DM name into its its VG/LV/LAYER LVM constituents ACTION=="change", IMPORT{program}="/sbin/dmsetup lvmsplit $env{DM_NAME} --nameprefixes --noheadings --rows" # Do not create symlinks for hidden subdevices. ENV{DM_LV_NAME}=="?*_mlog", GOTO="notify" ENV{DM_LV_NAME}=="?*_mimage_[0-9]*", GOTO="notify" # Create symlinks for top level devices only. ACTION=="change", ENV{DM_VG_NAME}=="?*", ENV{DM_LV_NAME}=="?*", ENV{DM_LV_LAYER}!="?*", SYMLINK+="$env{DM_VG_NAME}/$env{DM_LV_NAME}" LABEL="notify", ENV{DM_COOKIE}=="?*", RUN+="/sbin/dmsetup udevnotify $env{DM_COOKIE}", OPTIONS+="last_rule" LABEL="lvm_end" 95-dm-fallback.rules -------------------- SUBSYSTEM!="block", GOTO="dm_end" KERNEL!="dm-[0-9]*", GOTO="dm_end" ACTION!="change|remove", GOTO="dm_end" # Just in case there is any unsent notification. ENV{DM_COOKIE}=="?*", RUN+="/sbin/dmsetup udevnotify $env{DM_COOKIE}", OPTIONS+="last_rule" LABEL="dm_end" These rules are supposed to be installed in /etc/udev/rules.d dir: ================================================================== 11-dm-permissions.rules ----------------------- SUBSYSTEM!="block", GOTO="dm_end" KERNEL!="dm-[0-9]*", GOTO="dm_end" ACTION!="change", GOTO="dm_end" # You can define your own permissions for DM devices here. # There are two environment variables set for you which you # can use in your permission rules - DM_NAME and DM_UUID. ENV{DM_NAME}=="my_device", OWNER:="peter", GROUP:="peter", MODE:="644" # Default permissions for DM devices. KERNEL=="dm-[0-9]*", OWNER:="root", GROUP:="root", MODE:="0600" LABEL="dm_end" 11-dm-subsystem.rules --------------------- SUBSYSTEM!="block", GOTO="dm_end" KERNEL!="dm-[0-9]*", GOTO="dm_end" ACTION!="change", GOTO="dm_end" # Every DM subsystem registers its own prefixes here. # This is required so the notification is sent at right # time and after the subsystem's udev rules are processed. # We send the notification from the subsystem's rules then. # (if we forget to do so, there is still a fallback rule # that will send any residual notifications later) ENV{DM_UUID}=="LVM-?*", ENV{DM_SUBSYS}="LVM" ENV{DM_UUID}=="mpath-?*", ENV{DM_SUBSYS}="mpath" LABEL="dm_end" 40-multipath.rules ------------------ # multipath wants the devmaps presented as meaninglful device names # so name them after their devmap name SUBSYSTEM!="block", GOTO="end_mpath" RUN+="socket:/org/kernel/dm/multipath_event" KERNEL!="dm-[0-9]*", GOTO="end_mpath" ENV{DM_SUBSYS}!="mpath", GOTO="end_mpath" ACTION=="add", PROGRAM!="/sbin/mpath_wait %M %m", GOTO="end_mpath" ACTION=="add", RUN+="/sbin/dmsetup ls --target multipath --exec '/sbin/kpartx -a -p p' -j %M -m %m" LABEL="end_mpath" -- To unsubscribe from this list: send the line "unsubscribe linux-hotplug" in the body of a message to majordomo@xxxxxxxxxxxxxxx More majordomo info at http://vger.kernel.org/majordomo-info.html