55-dm.rules 7.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151
  1. # Copyright (C) 2009 Red Hat, Inc. All rights reserved.
  2. #
  3. # This file is part of LVM2.
  4. # Udev rules for device-mapper devices.
  5. #
  6. # These rules create a DM control node in /dev/mapper directory.
  7. # The rules also create nodes named dm-x (x is a number) in /dev
  8. # directory and symlinks to these nodes with names given by
  9. # the actual DM names. Some udev environment variables are set
  10. # for use in later rules:
  11. # DM_NAME - actual DM device's name
  12. # DM_UUID - UUID set for DM device (blank if not specified)
  13. # DM_SUSPENDED - suspended state of DM device (0 or 1)
  14. # DM_UDEV_RULES_VSN - DM udev rules version
  15. #
  16. # These rules cover only basic device-mapper functionality in udev.
  17. #
  18. # Various DM subsystems may contain further subsystem-specific rules
  19. # in 11-dm-<subsystem_name>.rules which should be installed together
  20. # with the DM subsystem and which extend these basic rules.
  21. # For example:
  22. # 11-dm-lvm.rules for LVM subsystem
  23. # 11-dm-mpath.rules for multipath subsystem (since version 0.6.0, recommended!)
  24. #
  25. # Even more specific rules may be required by subsystems so always
  26. # check subsystem's upstream repository for recent set of rules.
  27. # Also, keep in mind that recent rules may also require recent
  28. # subsystem-specific binaries.
  29. KERNEL=="device-mapper", NAME="mapper/control"
  30. SUBSYSTEM!="block", GOTO="dm_end"
  31. KERNEL!="dm-[0-9]*", GOTO="dm_end"
  32. # Device created, major and minor number assigned - "add" event generated.
  33. # Table loaded - no event generated.
  34. # Device resumed (or renamed) - "change" event generated.
  35. # Device removed - "remove" event generated.
  36. #
  37. # The dm-X nodes are always created, even on "add" event, we can't suppress
  38. # that (the node is created even earlier with devtmpfs). All the symlinks
  39. # (e.g. /dev/mapper) are created in right time after a device has its table
  40. # loaded and is properly resumed. For this reason, direct use of dm-X nodes
  41. # is not recommended.
  42. ACTION!="add|change", GOTO="dm_end"
  43. # Decode udev control flags and set environment variables appropriately.
  44. # These flags are encoded in DM_COOKIE variable that was introduced in
  45. # kernel version 2.6.31. Therefore, we can use this feature with
  46. # kernels >= 2.6.31 only. Cookie is not decoded for remove event.
  47. ENV{DM_COOKIE}=="?*", IMPORT{program}="/sbin/dmsetup udevflags $env{DM_COOKIE}"
  48. # Rule out easy-to-detect inappropriate events first.
  49. ENV{DISK_RO}=="1", GOTO="dm_disable"
  50. # There is no cookie set nor any flags encoded in events not originating
  51. # in libdevmapper so we need to detect this and try to behave correctly.
  52. # For such spurious events, regenerate all flags from current udev database content
  53. # (this information would normally be inaccessible for spurious ADD and CHANGE events).
  54. ENV{DM_UDEV_PRIMARY_SOURCE_FLAG}=="1", ENV{DM_ACTIVATION}="1", GOTO="dm_flags_done"
  55. IMPORT{db}="DM_UDEV_DISABLE_DM_RULES_FLAG"
  56. IMPORT{db}="DM_UDEV_DISABLE_SUBSYSTEM_RULES_FLAG"
  57. IMPORT{db}="DM_UDEV_DISABLE_DISK_RULES_FLAG"
  58. IMPORT{db}="DM_UDEV_DISABLE_OTHER_RULES_FLAG"
  59. IMPORT{db}="DM_UDEV_LOW_PRIORITY_FLAG"
  60. IMPORT{db}="DM_UDEV_DISABLE_LIBRARY_FALLBACK_FLAG"
  61. IMPORT{db}="DM_UDEV_PRIMARY_SOURCE_FLAG"
  62. IMPORT{db}="DM_UDEV_FLAG7"
  63. IMPORT{db}="DM_UDEV_RULES"
  64. IMPORT{db}="DM_UDEV_RULES_VSN"
  65. LABEL="dm_flags_done"
  66. # Normally, we operate on "change" events. But when coldplugging, there's an
  67. # "add" event present. We have to recognize this and do our actions in this
  68. # particular situation, too. Also, we don't want the nodes to be created
  69. # prematurely on "add" events while not coldplugging. We check
  70. # DM_UDEV_PRIMARY_SOURCE_FLAG to see if the device was activated correctly
  71. # before and if not, we ignore the "add" event totally. This way we can support
  72. # udev triggers generating "add" events (e.g. "udevadm trigger --action=add" or
  73. # "echo add > /sys/block/<dm_device>/uevent"). The trigger with "add" event is
  74. # also used at boot to reevaluate udev rules for all existing devices activated
  75. # before (e.g. in initrd). If udev is used in initrd, we require the udev init
  76. # script to not remove the existing udev database so we can reuse the information
  77. # stored at the time of device activation in the initrd.
  78. ACTION!="add", GOTO="dm_no_coldplug"
  79. ENV{DM_UDEV_PRIMARY_SOURCE_FLAG}!="1", GOTO="dm_disable"
  80. ENV{DM_ACTIVATION}="1"
  81. LABEL="dm_no_coldplug"
  82. # Putting it together, following table is used to recognize genuine and spurious events.
  83. # N.B. Spurious events are generated based on use of the WATCH udev
  84. # rule or by triggering an event manually by "udevadm trigger" call
  85. # or by "echo <event_name> > /sys/block/dm-X/uevent".
  86. #
  87. # EVENT DM_UDEV_PRIMARY_SOURCE_FLAG DM_ACTIVATION
  88. # ======================================================================
  89. # add event (genuine) 0 0
  90. # change event (genuine) 1 1
  91. # add event (spurious)
  92. # |_ dev still not active 0 0
  93. # \_ dev already active 1 1
  94. # change event (spurious)
  95. # |_ dev still not active 0 0
  96. # \_ dev already active 1 0
  97. # "dm" sysfs subdirectory is available in newer versions of DM
  98. # only (kernels >= 2.6.29). We have to check for its existence
  99. # and use dmsetup tool instead to get the DM name, uuid and
  100. # suspended state if the "dm" subdirectory is not present.
  101. # The "suspended" item was added even later (kernels >= 2.6.31),
  102. # so we also have to call dmsetup if the kernel version used
  103. # is in between these releases.
  104. TEST=="dm", ENV{DM_NAME}="$attr{dm/name}", ENV{DM_UUID}="$attr{dm/uuid}", ENV{DM_SUSPENDED}="$attr{dm/suspended}"
  105. TEST!="dm", IMPORT{program}="/sbin/dmsetup info -j %M -m %m -c --nameprefixes --noheadings --rows -o name,uuid,suspended"
  106. ENV{DM_SUSPENDED}!="?*", IMPORT{program}="/sbin/dmsetup info -j %M -m %m -c --nameprefixes --noheadings --rows -o suspended"
  107. # dmsetup tool provides suspended state information in textual
  108. # form with values "Suspended"/"Active". We translate it to
  109. # 0/1 respectively to be consistent with sysfs values.
  110. ENV{DM_SUSPENDED}=="Active", ENV{DM_SUSPENDED}="0"
  111. ENV{DM_SUSPENDED}=="Suspended", ENV{DM_SUSPENDED}="1"
  112. # This variable provides a reliable way to check that device-mapper
  113. # rules were installed. It means that all needed variables are set
  114. # by these rules directly so there's no need to acquire them again
  115. # later. Other rules can alternate the functionality based on this
  116. # fact (e.g. fallback to rules that behave correctly even without
  117. # these rules installed). It also provides versioning for any
  118. # possible future changes.
  119. # VSN 1 - original rules
  120. # VSN 2 - add support for synthesized events
  121. ENV{DM_UDEV_RULES}="1"
  122. ENV{DM_UDEV_RULES_VSN}="2"
  123. ENV{DM_UDEV_DISABLE_DM_RULES_FLAG}!="1", ENV{DM_NAME}=="?*", SYMLINK+="mapper/$env{DM_NAME}"
  124. # Avoid processing and scanning a DM device in the other (foreign)
  125. # rules if it is in suspended state. However, we still keep 'disk'
  126. # and 'DM subsystem' related rules enabled in this case.
  127. ENV{DM_SUSPENDED}=="1", ENV{DM_UDEV_DISABLE_OTHER_RULES_FLAG}="1"
  128. GOTO="dm_end"
  129. LABEL="dm_disable"
  130. ENV{DM_UDEV_DISABLE_SUBSYSTEM_RULES_FLAG}="1"
  131. ENV{DM_UDEV_DISABLE_DISK_RULES_FLAG}="1"
  132. ENV{DM_UDEV_DISABLE_OTHER_RULES_FLAG}="1"
  133. OPTIONS:="nowatch"
  134. LABEL="dm_end"