69-dm-lvm-metad.rules 5.7 KB

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