Initial import of binutils 2.22 on the new vendor branch
[dragonfly.git] / contrib / lvm2 / dist / udev / 10-dm.rules.in
1 # Copyright (C) 2009 Red Hat, Inc. All rights reserved.
2 #
3 # This file is part of LVM2.
4
5 # Udev rules for device-mapper devices.
6 #
7 # These rules create a DM control node in /dev/(DM_DIR) directory.
8 # The rules also create nodes named dm-x (x is a number) in /dev
9 # directory and symlinks to these nodes with names given by
10 # the actual DM names. Some udev environment variables are set
11 # for use in later rules:
12 #   DM_NAME - actual DM device's name
13 #   DM_UUID - UUID set for DM device (blank if not specified)
14 #   DM_SUSPENDED - suspended state of DM device (0 or 1)
15 #   DM_UDEV_RULES_VSN - DM udev rules version
16
17 KERNEL=="device-mapper", NAME="(DM_DIR)/control"
18
19 SUBSYSTEM!="block", GOTO="dm_end"
20 KERNEL!="dm-[0-9]*", GOTO="dm_end"
21
22 # Set proper sbin path, /sbin has higher priority than /usr/sbin.
23 ENV{DM_SBIN_PATH}="/sbin"
24 TEST!="$env{DM_SBIN_PATH}/dmsetup", ENV{DM_SBIN_PATH}="/usr/sbin"
25 TEST!="$env{DM_SBIN_PATH}/dmsetup", GOTO="dm_end"
26
27 # Decode udev control flags and set environment variables appropriately.
28 # These flags are encoded in DM_COOKIE variable that was introduced in
29 # kernel version 2.6.31. Therefore, we can use this feature with
30 # kernels >= 2.6.31 only.
31 ENV{DM_COOKIE}=="?*", IMPORT{program}="$env{DM_SBIN_PATH}/dmsetup udevflags $env{DM_COOKIE}"
32
33 # Normally, we would test for DM_UDEV_DISABLE_DM_RULES_FLAG here and skip
34 # the rules if set. However, we need to set DM_* environment variables
35 # for now to properly filter out inappropriate events. This dependency
36 # might be removed in the future.
37
38 ACTION!="add|change", GOTO="dm_end"
39
40 # Normally, we operate on "change" events only. But when
41 # coldplugging, there's an "add" event present. We have to
42 # recognize this and do our actions in this particular
43 # situation, too. Also, we don't want the nodes to be
44 # created prematurely on "add" events while not coldplugging.
45 ACTION=="add", ENV{STARTUP}!="1", NAME="", GOTO="dm_end"
46
47 # "dm" sysfs subdirectory is available in newer versions of DM
48 # only (kernels >= 2.6.29). We have to check for its existence
49 # and use dmsetup tool instead to get the DM name, uuid and 
50 # suspended state if the "dm" subdirectory is not present.
51 # The "suspended" item was added even later (kernels >= 2.6.31),
52 # so we also have to call dmsetup if the kernel version used
53 # is in between these releases.
54 TEST=="dm", ENV{DM_NAME}="$attr{dm/name}", ENV{DM_UUID}="$attr{dm/uuid}", ENV{DM_SUSPENDED}="$attr{dm/suspended}"
55 TEST!="dm", IMPORT{program}="$env{DM_SBIN_PATH}/dmsetup info -j %M -m %m -c --nameprefixes --noheadings --rows -o name,uuid,suspended"
56 ENV{DM_SUSPENDED}!="?*", IMPORT{program}="$env{DM_SBIN_PATH}/dmsetup info -j %M -m %m -c --nameprefixes --noheadings --rows -o suspended"
57
58 # dmsetup tool provides suspended state information in textual
59 # form with values "Suspended"/"Active". We translate it to
60 # 0/1 respectively to be consistent with sysfs values.
61 ENV{DM_SUSPENDED}=="Active", ENV{DM_SUSPENDED}="0"
62 ENV{DM_SUSPENDED}=="Suspended", ENV{DM_SUSPENDED}="1"
63
64 # This variable provides a reliable way to check that device-mapper
65 # rules were installed. It means that all needed variables are set
66 # by these rules directly so there's no need to acquire them again
67 # later. Other rules can alternate the functionality based on this
68 # fact (e.g. fallback to rules that behave correctly even without
69 # these rules installed). It also provides versioning for any
70 # possible future changes.
71 ENV{DM_UDEV_RULES_VSN}="1"
72
73 ENV{DM_UDEV_DISABLE_DM_RULES_FLAG}!="1", ENV{DM_NAME}=="?*", SYMLINK+="(DM_DIR)/$env{DM_NAME}"
74
75 # We have to ignore further rule application for inappropriate events
76 # and devices. But still send the notification if cookie exists.
77 ENV{DM_UUID}=="mpath-?*", ENV{DM_ACTION}=="PATH_FAILED", GOTO="dm_disable"
78 ENV{DM_UUID}=="CRYPT-TEMP-?*", GOTO="dm_disable"
79 ENV{DM_UUID}!="?*", ENV{DM_NAME}=="temporary-cryptsetup-?*", GOTO="dm_disable"
80
81 GOTO="dm_end"
82
83 LABEL="dm_disable"
84 ENV{DM_UDEV_DISABLE_SUBSYSTEM_RULES_FLAG}="1"
85 ENV{DM_UDEV_DISABLE_DISK_RULES_FLAG}="1"
86 ENV{DM_UDEV_DISABLE_OTHER_RULES_FLAG}="1"
87
88 LABEL="dm_end"