2009-11-01 21:01:31 +03:00
# Copyright (C) 2009 Red Hat, Inc. All rights reserved.
#
# This file is part of LVM2.
2009-08-03 22:44:54 +04:00
# Udev rules for device-mapper devices.
#
# These rules create a DM control node in /dev/(DM_DIR) directory.
# The rules also create nodes named dm-x (x is a number) in /dev
# directory and symlinks to these nodes with names given by
# the actual DM names. Some udev environment variables are set
# for use in later rules:
# DM_NAME - actual DM device's name
# DM_UUID - UUID set for DM device (blank if not specified)
2009-09-11 20:05:20 +04:00
# DM_UDEV_RULES_VSN - DM udev rules version
2024-03-01 17:26:59 +03:00
# DM_UDEV_DISABLE_OTHER_RULES_FLAG - a flag that indicates that
# stacked layers shouldn't attempt to probe the device, and
# should try to import relevant properties from the udev db.
2016-04-26 13:51:06 +03:00
#
# These rules cover only basic device-mapper functionality in udev.
#
# Various DM subsystems may contain further subsystem-specific rules
# in 11-dm-<subsystem_name>.rules which should be installed together
# with the DM subsystem and which extend these basic rules.
# For example:
# 11-dm-lvm.rules for LVM subsystem
# 11-dm-mpath.rules for multipath subsystem (since version 0.6.0, recommended!)
#
2024-03-01 17:26:59 +03:00
# 11-dm<subsystem_name>.rules may use other DM related properties besides
# those listed above, like .DM_SUSPENDED. These properties are considered
# internal to device mapper, and subject to change without notice.
# Rules that are executed after 13-dm-disk.rules shouldn't use them.
#
2016-04-26 13:51:06 +03:00
# Even more specific rules may be required by subsystems so always
# check subsystem's upstream repository for recent set of rules.
# Also, keep in mind that recent rules may also require recent
# subsystem-specific binaries.
2009-08-03 22:44:54 +04:00
SUBSYSTEM!="block", GOTO="dm_end"
KERNEL!="dm-[0-9]*", GOTO="dm_end"
2012-06-22 13:50:02 +04:00
(DM_EXEC_RULE)
2009-09-11 20:05:20 +04:00
2010-06-23 21:00:32 +04:00
# Device created, major and minor number assigned - "add" event generated.
# Table loaded - no event generated.
# Device resumed (or renamed) - "change" event generated.
# Device removed - "remove" event generated.
#
# The dm-X nodes are always created, even on "add" event, we can't suppress
# that (the node is created even earlier with devtmpfs). All the symlinks
# (e.g. /dev/mapper) are created in right time after a device has its table
# loaded and is properly resumed. For this reason, direct use of dm-X nodes
# is not recommended.
2024-03-07 11:48:49 +03:00
ACTION=="remove", GOTO="dm_end"
2009-08-03 22:44:54 +04:00
2023-11-29 11:09:57 +03:00
# Persist device state on transition from the initrd. This means all udev device
# properties are kept in the udev database even when it is cleaned up on
# switch-root.
OPTIONS+="db_persist"
2011-08-11 21:55:29 +04:00
# Decode udev control flags and set environment variables appropriately.
# These flags are encoded in DM_COOKIE variable that was introduced in
# kernel version 2.6.31. Therefore, we can use this feature with
# kernels >= 2.6.31 only. Cookie is not decoded for remove event.
2024-03-01 14:43:36 +03:00
ENV{DM_COOKIE}!="?*", GOTO="dm_no_cookie"
IMPORT{program}="(DM_EXEC)/dmsetup udevflags $env{DM_COOKIE}"
# Store the original flag from the cookie as DM_COOKIE_DISABLE_OTHER_RULES_FLAG
# in the udev db. DM_UDEV_DISABLE_OTHER_RULES_FLAG will be or'd with other
# conditions for use by upper, non-dm layers.
ENV{DM_COOKIE_DISABLE_OTHER_RULES_FLAG}="$env{DM_UDEV_DISABLE_OTHER_RULES_FLAG}"
LABEL="dm_no_cookie"
2011-08-11 21:55:29 +04:00
2010-04-28 17:37:36 +04:00
# There is no cookie set nor any flags encoded in events not originating
# in libdevmapper so we need to detect this and try to behave correctly.
# For such spurious events, regenerate all flags from current udev database content
# (this information would normally be inaccessible for spurious ADD and CHANGE events).
2013-09-12 15:46:20 +04:00
ENV{DM_UDEV_PRIMARY_SOURCE_FLAG}=="1", ENV{DM_ACTIVATION}="1", GOTO="dm_flags_done"
2010-04-28 17:37:36 +04:00
IMPORT{db}="DM_UDEV_DISABLE_DM_RULES_FLAG"
IMPORT{db}="DM_UDEV_DISABLE_SUBSYSTEM_RULES_FLAG"
IMPORT{db}="DM_UDEV_DISABLE_DISK_RULES_FLAG"
2024-03-01 14:43:36 +03:00
IMPORT{db}="DM_COOKIE_DISABLE_OTHER_RULES_FLAG"
2010-04-28 17:37:36 +04:00
IMPORT{db}="DM_UDEV_LOW_PRIORITY_FLAG"
IMPORT{db}="DM_UDEV_DISABLE_LIBRARY_FALLBACK_FLAG"
2013-09-12 15:46:20 +04:00
IMPORT{db}="DM_UDEV_PRIMARY_SOURCE_FLAG"
2010-04-28 17:37:36 +04:00
IMPORT{db}="DM_UDEV_FLAG7"
2010-08-12 17:41:18 +04:00
IMPORT{db}="DM_UDEV_RULES_VSN"
2024-03-01 14:43:36 +03:00
ENV{DM_UDEV_DISABLE_OTHER_RULES_FLAG}="$env{DM_COOKIE_DISABLE_OTHER_RULES_FLAG}"
2010-04-28 17:37:36 +04:00
LABEL="dm_flags_done"
2024-03-05 14:22:40 +03:00
# If DISK_RO is set, it's an uevent that changes the ro attribute of the device.
# The event should be ignored as far as dm is concerned.
ENV{DISK_RO}=="0|1", GOTO="dm_disable"
2010-06-23 21:00:32 +04:00
# Normally, we operate on "change" events. But when coldplugging, there's an
# "add" event present. We have to recognize this and do our actions in this
# particular situation, too. Also, we don't want the nodes to be created
# prematurely on "add" events while not coldplugging. We check
# DM_UDEV_PRIMARY_SOURCE_FLAG to see if the device was activated correctly
# before and if not, we ignore the "add" event totally. This way we can support
# udev triggers generating "add" events (e.g. "udevadm trigger --action=add" or
# "echo add > /sys/block/<dm_device>/uevent"). The trigger with "add" event is
# also used at boot to reevaluate udev rules for all existing devices activated
# before (e.g. in initrd). If udev is used in initrd, we require the udev init
# script to not remove the existing udev database so we can reuse the information
# stored at the time of device activation in the initrd.
2013-09-12 15:46:20 +04:00
ACTION!="add", GOTO="dm_no_coldplug"
ENV{DM_UDEV_RULES_VSN}!="1", ENV{DM_UDEV_PRIMARY_SOURCE_FLAG}!="1", GOTO="dm_disable"
ENV{DM_ACTIVATION}="1"
LABEL="dm_no_coldplug"
2009-08-03 22:44:54 +04:00
2013-05-03 13:01:57 +04:00
# Putting it together, following table is used to recognize genuine and spurious events.
# N.B. Spurious events are generated based on use of the WATCH udev
# rule or by triggering an event manually by "udevadm trigger" call
# or by "echo <event_name> > /sys/block/dm-X/uevent".
#
2013-09-12 15:46:20 +04:00
# EVENT DM_UDEV_PRIMARY_SOURCE_FLAG DM_ACTIVATION
# ======================================================================
2013-05-03 13:01:57 +04:00
# add event (genuine) 0 0
# change event (genuine) 1 1
# add event (spurious)
# |_ dev still not active 0 0
2013-09-12 15:46:20 +04:00
# \_ dev already active 1 1
2013-05-03 13:01:57 +04:00
# change event (spurious)
# |_ dev still not active 0 0
2013-09-12 15:46:20 +04:00
# \_ dev already active 1 0
2013-05-03 13:01:57 +04:00
2009-08-03 22:44:54 +04:00
# "dm" sysfs subdirectory is available in newer versions of DM
# only (kernels >= 2.6.29). We have to check for its existence
# and use dmsetup tool instead to get the DM name, uuid and
# suspended state if the "dm" subdirectory is not present.
2009-08-04 12:05:06 +04:00
# The "suspended" item was added even later (kernels >= 2.6.31),
2009-08-03 22:44:54 +04:00
# so we also have to call dmsetup if the kernel version used
# is in between these releases.
2024-03-01 17:16:33 +03:00
TEST=="dm", ENV{DM_NAME}="$attr{dm/name}", ENV{DM_UUID}="$attr{dm/uuid}", ENV{.DM_SUSPENDED}="$attr{dm/suspended}"
2012-06-22 13:50:02 +04:00
TEST!="dm", IMPORT{program}="(DM_EXEC)/dmsetup info -j %M -m %m -c --nameprefixes --noheadings --rows -o name,uuid,suspended"
2009-08-03 22:44:54 +04:00
2024-03-01 17:16:33 +03:00
ENV{.DM_SUSPENDED}=="?*", GOTO="dm_suspended_set"
TEST=="dm", IMPORT{program}="(DM_EXEC)/dmsetup info -j %M -m %m -c --nameprefixes --noheadings --rows -o suspended"
2009-08-03 22:44:54 +04:00
# dmsetup tool provides suspended state information in textual
# form with values "Suspended"/"Active". We translate it to
# 0/1 respectively to be consistent with sysfs values.
2024-03-01 17:16:33 +03:00
ENV{DM_SUSPENDED}=="Active", ENV{.DM_SUSPENDED}="0"
ENV{DM_SUSPENDED}=="Suspended", ENV{.DM_SUSPENDED}="1"
ENV{DM_SUSPENDED}=""
LABEL="dm_suspended_set"
2009-08-03 22:44:54 +04:00
2009-09-11 20:05:20 +04:00
# This variable provides a reliable way to check that device-mapper
# rules were installed. It means that all needed variables are set
# by these rules directly so there's no need to acquire them again
# later. Other rules can alternate the functionality based on this
# fact (e.g. fallback to rules that behave correctly even without
# these rules installed). It also provides versioning for any
# possible future changes.
2010-08-12 17:41:18 +04:00
# VSN 1 - original rules
# VSN 2 - add support for synthesized events
2024-03-01 17:26:59 +03:00
# VSN 3 - use DM_UDEV_DISABLE_OTHER_RULES_FLAG as the only "API"
# to be consumed by non-dm rules.
ENV{DM_UDEV_RULES_VSN}="3"
2009-09-11 20:05:20 +04:00
2009-10-26 17:29:33 +03:00
ENV{DM_UDEV_DISABLE_DM_RULES_FLAG}!="1", ENV{DM_NAME}=="?*", SYMLINK+="(DM_DIR)/$env{DM_NAME}"
2009-08-03 22:44:54 +04:00
2011-01-28 14:41:51 +03:00
# Avoid processing and scanning a DM device in the other (foreign)
# rules if it is in suspended state. However, we still keep 'disk'
# and 'DM subsystem' related rules enabled in this case.
2024-03-01 17:16:33 +03:00
ENV{.DM_SUSPENDED}=="1", ENV{DM_UDEV_DISABLE_OTHER_RULES_FLAG}="1"
2011-01-28 14:41:51 +03:00
2009-09-11 20:05:20 +04:00
GOTO="dm_end"
2009-10-26 17:29:33 +03:00
LABEL="dm_disable"
ENV{DM_UDEV_DISABLE_SUBSYSTEM_RULES_FLAG}="1"
ENV{DM_UDEV_DISABLE_DISK_RULES_FLAG}="1"
ENV{DM_UDEV_DISABLE_OTHER_RULES_FLAG}="1"
2010-07-07 15:22:46 +04:00
OPTIONS:="nowatch"
2009-09-11 20:05:20 +04:00
2009-08-03 22:44:54 +04:00
LABEL="dm_end"