69-dm-lvm-metad.rules 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  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. # If the PV label got lost, inform lvmetad immediately.
  18. # Detect the lost PV label by comparing previous ID_FS_TYPE value with current one.
  19. ENV{.ID_FS_TYPE_NEW}="$env{ID_FS_TYPE}"
  20. IMPORT{db}="ID_FS_TYPE"
  21. ENV{ID_FS_TYPE}=="LVM2_member|LVM1_member", ENV{.ID_FS_TYPE_NEW}!="LVM2_member|LVM1_member", ENV{LVM_PV_GONE}="1"
  22. ENV{ID_FS_TYPE}="$env{.ID_FS_TYPE_NEW}"
  23. ENV{LVM_PV_GONE}=="1", GOTO="lvm_scan"
  24. # Only process devices already marked as a PV - this requires blkid to be called before.
  25. ENV{ID_FS_TYPE}!="LVM2_member|LVM1_member", GOTO="lvm_end"
  26. ENV{DM_MULTIPATH_DEVICE_PATH}=="1", GOTO="lvm_end"
  27. # Inform lvmetad about any PV that is gone.
  28. ACTION=="remove", GOTO="lvm_scan"
  29. # Create /dev/disk/by-id/lvm-pv-uuid-<PV_UUID> symlink for each PV
  30. ENV{ID_FS_UUID_ENC}=="?*", SYMLINK+="disk/by-id/lvm-pv-uuid-$env{ID_FS_UUID_ENC}"
  31. # If the PV is a special device listed below, scan only if the device is
  32. # properly activated. These devices are not usable after an ADD event,
  33. # but they require an extra setup and they are ready after a CHANGE event.
  34. # Also support coldplugging with ADD event but only if the device is already
  35. # properly activated.
  36. # This logic should be eventually moved to rules where those particular
  37. # devices are processed primarily (MD and loop).
  38. # DM device:
  39. KERNEL!="dm-[0-9]*", GOTO="next"
  40. ENV{DM_UDEV_PRIMARY_SOURCE_FLAG}=="1", ENV{DM_ACTIVATION}=="1", GOTO="lvm_scan"
  41. GOTO="lvm_end"
  42. # MD device:
  43. LABEL="next"
  44. KERNEL!="md[0-9]*", GOTO="next"
  45. IMPORT{db}="LVM_MD_PV_ACTIVATED"
  46. ACTION=="add", ENV{LVM_MD_PV_ACTIVATED}=="1", GOTO="lvm_scan"
  47. ACTION=="change", ENV{LVM_MD_PV_ACTIVATED}!="1", TEST=="md/array_state", ENV{LVM_MD_PV_ACTIVATED}="1", GOTO="lvm_scan"
  48. ACTION=="add", KERNEL=="md[0-9]*p[0-9]*", GOTO="lvm_scan"
  49. ENV{LVM_MD_PV_ACTIVATED}!="1", ENV{SYSTEMD_READY}="0"
  50. GOTO="lvm_end"
  51. # Loop device:
  52. LABEL="next"
  53. KERNEL!="loop[0-9]*", GOTO="next"
  54. ACTION=="add", ENV{LVM_LOOP_PV_ACTIVATED}=="1", GOTO="lvm_scan"
  55. ACTION=="change", ENV{LVM_LOOP_PV_ACTIVATED}!="1", TEST=="loop/backing_file", ENV{LVM_LOOP_PV_ACTIVATED}="1", GOTO="lvm_scan"
  56. ENV{LVM_LOOP_PV_ACTIVATED}!="1", ENV{SYSTEMD_READY}="0"
  57. GOTO="lvm_end"
  58. # If the PV is not a special device listed above, scan only after device addition (ADD event)
  59. LABEL="next"
  60. ACTION!="add", GOTO="lvm_end"
  61. LABEL="lvm_scan"
  62. # The table below summarises the situations in which we reach the LABEL="lvm_scan".
  63. # Marked by X, X* means only if the special dev is properly set up.
  64. # The artificial ADD is supported for coldplugging. We avoid running the pvscan
  65. # on artificial CHANGE so there's no unexpected autoactivation when WATCH rule fires.
  66. # N.B. MD and loop never actually reaches lvm_scan on REMOVE as the PV label is gone
  67. # within a CHANGE event (these are caught by the "LVM_PV_GONE" rule at the beginning).
  68. #
  69. # | real ADD | real CHANGE | artificial ADD | artificial CHANGE | REMOVE
  70. # =============================================================================
  71. # DM | | X | X* | | X
  72. # MD | | X | X* | |
  73. # loop | | X | X* | |
  74. # other | X | | X | | X
  75. ENV{SYSTEMD_READY}="1"
  76. RUN+="/usr/bin/lvm pvscan --background --cache --activate ay --major $major --minor $minor", ENV{LVM_SCANNED}="1"
  77. LABEL="lvm_end"