xref: /dflybsd-src/contrib/lvm2/dist/udev/10-dm.rules.in (revision 86d7f5d305c6adaa56ff4582ece9859d73106103)
186d7f5d3SJohn Marino# Copyright (C) 2009 Red Hat, Inc. All rights reserved.
286d7f5d3SJohn Marino#
386d7f5d3SJohn Marino# This file is part of LVM2.
486d7f5d3SJohn Marino
586d7f5d3SJohn Marino# Udev rules for device-mapper devices.
686d7f5d3SJohn Marino#
786d7f5d3SJohn Marino# These rules create a DM control node in /dev/(DM_DIR) directory.
886d7f5d3SJohn Marino# The rules also create nodes named dm-x (x is a number) in /dev
986d7f5d3SJohn Marino# directory and symlinks to these nodes with names given by
1086d7f5d3SJohn Marino# the actual DM names. Some udev environment variables are set
1186d7f5d3SJohn Marino# for use in later rules:
1286d7f5d3SJohn Marino#   DM_NAME - actual DM device's name
1386d7f5d3SJohn Marino#   DM_UUID - UUID set for DM device (blank if not specified)
1486d7f5d3SJohn Marino#   DM_SUSPENDED - suspended state of DM device (0 or 1)
1586d7f5d3SJohn Marino#   DM_UDEV_RULES_VSN - DM udev rules version
1686d7f5d3SJohn Marino
1786d7f5d3SJohn MarinoKERNEL=="device-mapper", NAME="(DM_DIR)/control"
1886d7f5d3SJohn Marino
1986d7f5d3SJohn MarinoSUBSYSTEM!="block", GOTO="dm_end"
2086d7f5d3SJohn MarinoKERNEL!="dm-[0-9]*", GOTO="dm_end"
2186d7f5d3SJohn Marino
2286d7f5d3SJohn Marino# Set proper sbin path, /sbin has higher priority than /usr/sbin.
2386d7f5d3SJohn MarinoENV{DM_SBIN_PATH}="/sbin"
2486d7f5d3SJohn MarinoTEST!="$env{DM_SBIN_PATH}/dmsetup", ENV{DM_SBIN_PATH}="/usr/sbin"
2586d7f5d3SJohn MarinoTEST!="$env{DM_SBIN_PATH}/dmsetup", GOTO="dm_end"
2686d7f5d3SJohn Marino
2786d7f5d3SJohn Marino# Decode udev control flags and set environment variables appropriately.
2886d7f5d3SJohn Marino# These flags are encoded in DM_COOKIE variable that was introduced in
2986d7f5d3SJohn Marino# kernel version 2.6.31. Therefore, we can use this feature with
3086d7f5d3SJohn Marino# kernels >= 2.6.31 only.
3186d7f5d3SJohn MarinoENV{DM_COOKIE}=="?*", IMPORT{program}="$env{DM_SBIN_PATH}/dmsetup udevflags $env{DM_COOKIE}"
3286d7f5d3SJohn Marino
3386d7f5d3SJohn Marino# Normally, we would test for DM_UDEV_DISABLE_DM_RULES_FLAG here and skip
3486d7f5d3SJohn Marino# the rules if set. However, we need to set DM_* environment variables
3586d7f5d3SJohn Marino# for now to properly filter out inappropriate events. This dependency
3686d7f5d3SJohn Marino# might be removed in the future.
3786d7f5d3SJohn Marino
3886d7f5d3SJohn MarinoACTION!="add|change", GOTO="dm_end"
3986d7f5d3SJohn Marino
4086d7f5d3SJohn Marino# Normally, we operate on "change" events only. But when
4186d7f5d3SJohn Marino# coldplugging, there's an "add" event present. We have to
4286d7f5d3SJohn Marino# recognize this and do our actions in this particular
4386d7f5d3SJohn Marino# situation, too. Also, we don't want the nodes to be
4486d7f5d3SJohn Marino# created prematurely on "add" events while not coldplugging.
4586d7f5d3SJohn MarinoACTION=="add", ENV{STARTUP}!="1", NAME="", GOTO="dm_end"
4686d7f5d3SJohn Marino
4786d7f5d3SJohn Marino# "dm" sysfs subdirectory is available in newer versions of DM
4886d7f5d3SJohn Marino# only (kernels >= 2.6.29). We have to check for its existence
4986d7f5d3SJohn Marino# and use dmsetup tool instead to get the DM name, uuid and
5086d7f5d3SJohn Marino# suspended state if the "dm" subdirectory is not present.
5186d7f5d3SJohn Marino# The "suspended" item was added even later (kernels >= 2.6.31),
5286d7f5d3SJohn Marino# so we also have to call dmsetup if the kernel version used
5386d7f5d3SJohn Marino# is in between these releases.
5486d7f5d3SJohn MarinoTEST=="dm", ENV{DM_NAME}="$attr{dm/name}", ENV{DM_UUID}="$attr{dm/uuid}", ENV{DM_SUSPENDED}="$attr{dm/suspended}"
5586d7f5d3SJohn MarinoTEST!="dm", IMPORT{program}="$env{DM_SBIN_PATH}/dmsetup info -j %M -m %m -c --nameprefixes --noheadings --rows -o name,uuid,suspended"
5686d7f5d3SJohn MarinoENV{DM_SUSPENDED}!="?*", IMPORT{program}="$env{DM_SBIN_PATH}/dmsetup info -j %M -m %m -c --nameprefixes --noheadings --rows -o suspended"
5786d7f5d3SJohn Marino
5886d7f5d3SJohn Marino# dmsetup tool provides suspended state information in textual
5986d7f5d3SJohn Marino# form with values "Suspended"/"Active". We translate it to
6086d7f5d3SJohn Marino# 0/1 respectively to be consistent with sysfs values.
6186d7f5d3SJohn MarinoENV{DM_SUSPENDED}=="Active", ENV{DM_SUSPENDED}="0"
6286d7f5d3SJohn MarinoENV{DM_SUSPENDED}=="Suspended", ENV{DM_SUSPENDED}="1"
6386d7f5d3SJohn Marino
6486d7f5d3SJohn Marino# This variable provides a reliable way to check that device-mapper
6586d7f5d3SJohn Marino# rules were installed. It means that all needed variables are set
6686d7f5d3SJohn Marino# by these rules directly so there's no need to acquire them again
6786d7f5d3SJohn Marino# later. Other rules can alternate the functionality based on this
6886d7f5d3SJohn Marino# fact (e.g. fallback to rules that behave correctly even without
6986d7f5d3SJohn Marino# these rules installed). It also provides versioning for any
7086d7f5d3SJohn Marino# possible future changes.
7186d7f5d3SJohn MarinoENV{DM_UDEV_RULES_VSN}="1"
7286d7f5d3SJohn Marino
7386d7f5d3SJohn MarinoENV{DM_UDEV_DISABLE_DM_RULES_FLAG}!="1", ENV{DM_NAME}=="?*", SYMLINK+="(DM_DIR)/$env{DM_NAME}"
7486d7f5d3SJohn Marino
7586d7f5d3SJohn Marino# We have to ignore further rule application for inappropriate events
7686d7f5d3SJohn Marino# and devices. But still send the notification if cookie exists.
7786d7f5d3SJohn MarinoENV{DM_UUID}=="mpath-?*", ENV{DM_ACTION}=="PATH_FAILED", GOTO="dm_disable"
7886d7f5d3SJohn MarinoENV{DM_UUID}=="CRYPT-TEMP-?*", GOTO="dm_disable"
7986d7f5d3SJohn MarinoENV{DM_UUID}!="?*", ENV{DM_NAME}=="temporary-cryptsetup-?*", GOTO="dm_disable"
8086d7f5d3SJohn Marino
8186d7f5d3SJohn MarinoGOTO="dm_end"
8286d7f5d3SJohn Marino
8386d7f5d3SJohn MarinoLABEL="dm_disable"
8486d7f5d3SJohn MarinoENV{DM_UDEV_DISABLE_SUBSYSTEM_RULES_FLAG}="1"
8586d7f5d3SJohn MarinoENV{DM_UDEV_DISABLE_DISK_RULES_FLAG}="1"
8686d7f5d3SJohn MarinoENV{DM_UDEV_DISABLE_OTHER_RULES_FLAG}="1"
8786d7f5d3SJohn Marino
8886d7f5d3SJohn MarinoLABEL="dm_end"
89