69-lvm-metad.rules 6.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142
  1. # Copyright (C) 2012 Red Hat, Inc. All rights reserved.
  2. #
  3. # This file is part of LVM2.
  4. # Udev rules for LVM.
  5. #
  6. # Scan all block devices having a PV label for LVM metadata.
  7. # Store this information in LVMetaD (the LVM metadata daemon) and maintain LVM
  8. # metadata state for improved performance by avoiding further scans while
  9. # running subsequent LVM commands or while using lvm2app library.
  10. # Also, notify LVMetaD about any relevant block device removal.
  11. #
  12. # This rule is essential for having the information in LVMetaD up-to-date.
  13. # It also requires blkid to be called on block devices before so only devices
  14. # used as LVM PVs are processed (ID_FS_TYPE="LVM2_member" or "LVM1_member").
  15. SUBSYSTEM!="block", GOTO="lvm_end"
  16. ENV{DM_UDEV_DISABLE_OTHER_RULES_FLAG}=="1", GOTO="lvm_end"
  17. # XXX: Properly call blkid on md devices. Workaround for #793631
  18. KERNEL!="md[0-9]*", GOTO="next"
  19. IMPORT{builtin}="blkid"
  20. LABEL="next"
  21. # If the PV label got lost, inform lvmetad immediately.
  22. # Detect the lost PV label by comparing previous ID_FS_TYPE value with current one.
  23. ENV{.ID_FS_TYPE_NEW}="$env{ID_FS_TYPE}"
  24. IMPORT{db}="ID_FS_TYPE"
  25. ENV{ID_FS_TYPE}=="LVM2_member|LVM1_member", ENV{.ID_FS_TYPE_NEW}!="LVM2_member|LVM1_member", ENV{LVM_PV_GONE}="1"
  26. ENV{ID_FS_TYPE}="$env{.ID_FS_TYPE_NEW}"
  27. ENV{LVM_PV_GONE}=="1", GOTO="lvm_scan"
  28. # Only process devices already marked as a PV - this requires blkid to be called before.
  29. ENV{ID_FS_TYPE}!="LVM2_member|LVM1_member", GOTO="lvm_end"
  30. ENV{DM_MULTIPATH_DEVICE_PATH}=="1", GOTO="lvm_end"
  31. # Inform lvmetad about any PV that is gone.
  32. ACTION=="remove", GOTO="lvm_scan"
  33. # Create /dev/disk/by-id/lvm-pv-uuid-<PV_UUID> symlink for each PV
  34. ENV{ID_FS_UUID_ENC}=="?*", SYMLINK+="disk/by-id/lvm-pv-uuid-$env{ID_FS_UUID_ENC}"
  35. # If the PV is a special device listed below, scan only if the device is
  36. # properly activated. These devices are not usable after an ADD event,
  37. # but they require an extra setup and they are ready after a CHANGE event.
  38. # Also support coldplugging with ADD event but only if the device is already
  39. # properly activated.
  40. # This logic should be eventually moved to rules where those particular
  41. # devices are processed primarily (MD and loop).
  42. # DM device:
  43. KERNEL!="dm-[0-9]*", GOTO="next"
  44. ENV{DM_UDEV_PRIMARY_SOURCE_FLAG}=="1", ENV{DM_ACTIVATION}=="1", GOTO="lvm_scan"
  45. GOTO="lvm_end"
  46. # MD device:
  47. LABEL="next"
  48. KERNEL!="md[0-9]*", GOTO="next"
  49. IMPORT{db}="LVM_MD_PV_ACTIVATED"
  50. ACTION=="add", ENV{LVM_MD_PV_ACTIVATED}=="1", GOTO="lvm_scan"
  51. ACTION=="change", ENV{LVM_MD_PV_ACTIVATED}!="1", ENV{LVM_MD_PV_ACTIVATED}="1", GOTO="lvm_scan"
  52. ACTION=="add", KERNEL=="md[0-9]*p[0-9]*", GOTO="lvm_scan"
  53. ENV{LVM_MD_PV_ACTIVATED}!="1", ENV{SYSTEMD_READY}="0"
  54. GOTO="lvm_end"
  55. # Loop device:
  56. LABEL="next"
  57. KERNEL!="loop[0-9]*", GOTO="next"
  58. ACTION=="add", ENV{LVM_LOOP_PV_ACTIVATED}=="1", GOTO="lvm_scan"
  59. ACTION=="change", ENV{LVM_LOOP_PV_ACTIVATED}!="1", ENV{LVM_LOOP_PV_ACTIVATED}="1", GOTO="lvm_scan"
  60. ENV{LVM_LOOP_PV_ACTIVATED}!="1", ENV{SYSTEMD_READY}="0"
  61. GOTO="lvm_end"
  62. # If the PV is not a special device listed above, scan only if necessary.
  63. # For "direct_pvscan" mode (see below), this means run rules only an ADD events.
  64. # For "systemd_background" mode, systemd takes care of this by activating
  65. # the lvm2-pvscan@.service only once.
  66. LABEL="next"
  67. TEST!="/run/systemd/system", ACTION!="add", GOTO="lvm_end"
  68. TEST=="/run/systemd/system", ACTION!="add|change", GOTO="lvm_end"
  69. LABEL="lvm_scan"
  70. ENV{SYSTEMD_READY}="1"
  71. # The method for invoking pvscan is selected at build time with the option
  72. # --(enable|disable)-udev-systemd-background-jobs to "configure".
  73. # On modern distributions with recent systemd, it's "systemd_background";
  74. # on others, "direct_pvscan".
  75. TEST!="/run/systemd/system", GOTO="direct_pvscan"
  76. TEST=="/run/systemd/system", GOTO="systemd_background"
  77. LABEL="systemd_background"
  78. # The table below summarises the situations in which we reach the LABEL="lvm_scan"
  79. # in the "systemd_background" case.
  80. # Marked by X, X* means only if the special dev is properly set up.
  81. # The artificial ADD is supported for coldplugging. We avoid running the pvscan
  82. # on artificial CHANGE so there's no unexpected autoactivation when WATCH rule fires.
  83. # N.B. MD and loop never actually reaches lvm_scan on REMOVE as the PV label is gone
  84. # within a CHANGE event (these are caught by the "LVM_PV_GONE" rule at the beginning).
  85. #
  86. # In this case, we simply set up the dependency between the device and the pvscan
  87. # job using SYSTEMD_ALIAS (which sets up a simplified device identifier that
  88. # allows using "BindsTo" in the sytemd unit file) and SYSTEMD_WANTS (which tells
  89. # systemd to start the pvscan job once the device is ready).
  90. # We need to set these variables for both "add" and "change" events, otherwise
  91. # systemd may loose information about the device/unit dependencies.
  92. #
  93. # | real ADD | real CHANGE | artificial ADD | artificial CHANGE | REMOVE
  94. # =============================================================================
  95. # DM | | X | X* | | X
  96. # MD | | X | X* | |
  97. # loop | | X | X* | |
  98. # other | X | X | X | | X
  99. ACTION!="remove", ENV{LVM_PV_GONE}=="1", RUN+="/usr/bin/systemd-run /sbin/lvm pvscan --cache $major:$minor", GOTO="lvm_end"
  100. ENV{SYSTEMD_ALIAS}="/dev/block/$major:$minor"
  101. ENV{SYSTEMD_WANTS}+="lvm2-pvscan@$major:$minor.service"
  102. GOTO="lvm_end"
  103. LABEL="direct_pvscan"
  104. # The table below summarises the situations in which we reach the LABEL="lvm_scan"
  105. # for the "direct_pvscan" case.
  106. # Marked by X, X* means only if the special dev is properly set up.
  107. # The artificial ADD is supported for coldplugging. We avoid running the pvscan
  108. # on artificial CHANGE so there's no unexpected autoactivation when WATCH rule fires.
  109. #
  110. # In this case, we need to make sure that pvscan is not invoked spuriously, therefore
  111. # we invoke it only for "add" events for "other" devices.
  112. #
  113. # | real ADD | real CHANGE | artificial ADD | artificial CHANGE | REMOVE
  114. # =============================================================================
  115. # DM | | X | X* | | X
  116. # MD | | X | X* | |
  117. # loop | | X | X* | |
  118. # other | X | | X | | X
  119. RUN+="/sbin/lvm pvscan --cache --activate ay --major $major --minor $minor", ENV{LVM_SCANNED}="1"
  120. LABEL="lvm_end"