Tizen 2.1 base
[external/device-mapper.git] / 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 # Device created, major and minor number assigned - "add" event generated.
34 # Table loaded - no event generated.
35 # Device resumed (or renamed) - "change" event generated.
36 # Device removed - "remove" event generated.
37 #
38 # The dm-X nodes are always created, even on "add" event, we can't suppress
39 # that (the node is created even earlier with devtmpfs). All the symlinks
40 # (e.g. /dev/mapper) are created in right time after a device has its table
41 # loaded and is properly resumed. For this reason, direct use of dm-X nodes
42 # is not recommended.
43 ACTION!="add|change", GOTO="dm_end"
44
45 # Rule out easy-to-detect inappropriate events first.
46 ENV{DISK_RO}=="1", GOTO="dm_disable"
47
48 # There is no cookie set nor any flags encoded in events not originating
49 # in libdevmapper so we need to detect this and try to behave correctly.
50 # For such spurious events, regenerate all flags from current udev database content
51 # (this information would normally be inaccessible for spurious ADD and CHANGE events).
52 ENV{DM_UDEV_PRIMARY_SOURCE_FLAG}=="1", GOTO="dm_flags_done"
53 IMPORT{db}="DM_UDEV_DISABLE_DM_RULES_FLAG"
54 IMPORT{db}="DM_UDEV_DISABLE_SUBSYSTEM_RULES_FLAG"
55 IMPORT{db}="DM_UDEV_DISABLE_DISK_RULES_FLAG"
56 IMPORT{db}="DM_UDEV_DISABLE_OTHER_RULES_FLAG"
57 IMPORT{db}="DM_UDEV_LOW_PRIORITY_FLAG"
58 IMPORT{db}="DM_UDEV_DISABLE_LIBRARY_FALLBACK_FLAG"
59 IMPORT{db}="DM_UDEV_PRIMARY_SOURCE_FLAG"
60 IMPORT{db}="DM_UDEV_FLAG7"
61 IMPORT{db}="DM_SUBSYSTEM_UDEV_FLAG0"
62 IMPORT{db}="DM_SUBSYSTEM_UDEV_FLAG1"
63 IMPORT{db}="DM_SUBSYSTEM_UDEV_FLAG2"
64 IMPORT{db}="DM_SUBSYSTEM_UDEV_FLAG3"
65 IMPORT{db}="DM_SUBSYSTEM_UDEV_FLAG4"
66 IMPORT{db}="DM_SUBSYSTEM_UDEV_FLAG5"
67 IMPORT{db}="DM_SUBSYSTEM_UDEV_FLAG6"
68 IMPORT{db}="DM_SUBSYSTEM_UDEV_FLAG7"
69 IMPORT{db}="DM_UDEV_RULES_VSN"
70 LABEL="dm_flags_done"
71
72 # Normally, we operate on "change" events. But when coldplugging, there's an
73 # "add" event present. We have to recognize this and do our actions in this
74 # particular situation, too. Also, we don't want the nodes to be created
75 # prematurely on "add" events while not coldplugging. We check
76 # DM_UDEV_PRIMARY_SOURCE_FLAG to see if the device was activated correctly
77 # before and if not, we ignore the "add" event totally. This way we can support
78 # udev triggers generating "add" events (e.g. "udevadm trigger --action=add" or
79 # "echo add > /sys/block/<dm_device>/uevent"). The trigger with "add" event is
80 # also used at boot to reevaluate udev rules for all existing devices activated
81 # before (e.g. in initrd). If udev is used in initrd, we require the udev init
82 # script to not remove the existing udev database so we can reuse the information
83 # stored at the time of device activation in the initrd.
84 ACTION=="add", ENV{DM_UDEV_RULES_VSN}!="1", ENV{DM_UDEV_PRIMARY_SOURCE_FLAG}!="1", GOTO="dm_disable"
85
86 # "dm" sysfs subdirectory is available in newer versions of DM
87 # only (kernels >= 2.6.29). We have to check for its existence
88 # and use dmsetup tool instead to get the DM name, uuid and 
89 # suspended state if the "dm" subdirectory is not present.
90 # The "suspended" item was added even later (kernels >= 2.6.31),
91 # so we also have to call dmsetup if the kernel version used
92 # is in between these releases.
93 TEST=="dm", ENV{DM_NAME}="$attr{dm/name}", ENV{DM_UUID}="$attr{dm/uuid}", ENV{DM_SUSPENDED}="$attr{dm/suspended}"
94 TEST!="dm", IMPORT{program}="$env{DM_SBIN_PATH}/dmsetup info -j %M -m %m -c --nameprefixes --noheadings --rows -o name,uuid,suspended"
95 ENV{DM_SUSPENDED}!="?*", IMPORT{program}="$env{DM_SBIN_PATH}/dmsetup info -j %M -m %m -c --nameprefixes --noheadings --rows -o suspended"
96
97 # dmsetup tool provides suspended state information in textual
98 # form with values "Suspended"/"Active". We translate it to
99 # 0/1 respectively to be consistent with sysfs values.
100 ENV{DM_SUSPENDED}=="Active", ENV{DM_SUSPENDED}="0"
101 ENV{DM_SUSPENDED}=="Suspended", ENV{DM_SUSPENDED}="1"
102
103 # This variable provides a reliable way to check that device-mapper
104 # rules were installed. It means that all needed variables are set
105 # by these rules directly so there's no need to acquire them again
106 # later. Other rules can alternate the functionality based on this
107 # fact (e.g. fallback to rules that behave correctly even without
108 # these rules installed). It also provides versioning for any
109 # possible future changes.
110 # VSN 1 - original rules
111 # VSN 2 - add support for synthesized events
112 ENV{DM_UDEV_RULES_VSN}="2"
113
114 ENV{DM_UDEV_DISABLE_DM_RULES_FLAG}!="1", ENV{DM_NAME}=="?*", SYMLINK+="(DM_DIR)/$env{DM_NAME}"
115
116 # We have to ignore further rule application for inappropriate events
117 # and devices. But still send the notification if cookie exists.
118 ENV{DM_UUID}=="mpath-?*", ENV{DM_ACTION}=="PATH_FAILED", GOTO="dm_disable"
119 ENV{DM_UUID}=="CRYPT-TEMP-?*", GOTO="dm_disable"
120 ENV{DM_UUID}!="?*", ENV{DM_NAME}=="temporary-cryptsetup-?*", GOTO="dm_disable"
121
122 GOTO="dm_end"
123
124 LABEL="dm_disable"
125 ENV{DM_UDEV_DISABLE_SUBSYSTEM_RULES_FLAG}="1"
126 ENV{DM_UDEV_DISABLE_DISK_RULES_FLAG}="1"
127 ENV{DM_UDEV_DISABLE_OTHER_RULES_FLAG}="1"
128 OPTIONS:="nowatch"
129
130 LABEL="dm_end"