10-dm.rules 6.7 KB

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