split 95udev-rules/59-persistent-storage.rules to md and dm modules

master
Harald Hoyer 2013-03-07 14:49:21 +01:00
parent 34bd2be23f
commit c46cda8260
8 changed files with 80 additions and 74 deletions

View File

@ -978,6 +978,33 @@ inst_rules() {
done
}

prepare_udev_rules() {
[ -z "$UDEVVERSION" ] && export UDEVVERSION=$(udevadm --version)

for f in "$@"; do
f="${initdir}/etc/udev/rules.d/$f"
[ -e "$f" ] || continue
while read line; do
if [ "${line%%IMPORT PATH_ID}" != "$line" ]; then
if [ $UDEVVERSION -ge 174 ]; then
printf '%sIMPORT{builtin}="path_id"\n' "${line%%IMPORT PATH_ID}"
else
printf '%sIMPORT{program}="path_id %%p"\n' "${line%%IMPORT PATH_ID}"
fi
elif [ "${line%%IMPORT BLKID}" != "$line" ]; then
if [ $UDEVVERSION -ge 176 ]; then
printf '%sIMPORT{builtin}="blkid"\n' "${line%%IMPORT BLKID}"
else
printf '%sIMPORT{program}="/sbin/blkid -o udev -p $tempnode"\n' "${line%%IMPORT BLKID}"
fi
else
echo "$line"
fi
done < "${f}" > "${f}.new"
mv "${f}.new" "$f"
done
}

# install function specialized for hooks
# $1 = type of hook, $2 = hook priority (lower runs first), $3 = hook
# All hooks should be POSIX/SuS compliant, they will be sourced by init.

View File

@ -0,0 +1,15 @@
SUBSYSTEM!="block", GOTO="dm_end"
ACTION!="add|change", GOTO="dm_end"
# Also don't process disks that are slated to be a multipath device
ENV{DM_MULTIPATH_DEVICE_PATH}=="?*", GOTO="dm_end"

KERNEL!="dm-[0-9]*", GOTO="dm_end"
ACTION=="add", GOTO="dm_end"
IMPORT{program}="/sbin/dmsetup info -c --nameprefixes --unquoted --rows --noheadings -o name,uuid,suspended,readonly,major,minor,open,tables_loaded,names_using_dev -j%M -m%m"
ENV{DM_NAME}!="?*", GOTO="dm_end"
ENV{DM_UDEV_DISABLE_OTHER_RULES_FLAG}=="1", GOTO="dm_end"
ENV{DM_UUID}=="CRYPT-TEMP-?*", GOTO="dm_end"
ENV{DM_UUID}!="?*", ENV{DM_NAME}=="temporary-cryptsetup-?*", GOTO="dm_end"
IMPORT BLKID

LABEL="dm_end"

View File

@ -32,6 +32,9 @@ install() {

inst_rules "$moddir/11-dm.rules"

inst_rules "$moddir/59-persistent-storage-dm.rules"
prepare_udev_rules 59-persistent-storage-dm.rules

inst_hook shutdown 30 "$moddir/dm-shutdown.sh"
}


View File

@ -0,0 +1,23 @@
SUBSYSTEM!="block", GOTO="md_end"
ACTION!="add|change", GOTO="md_end"
# Also don't process disks that are slated to be a multipath device
ENV{DM_MULTIPATH_DEVICE_PATH}=="?*", GOTO="md_end"

KERNEL!="md[0-9]*|md_d[0-9]*|md/*", KERNEL!="md*", GOTO="md_end"

# partitions have no md/{array_state,metadata_version}
ENV{DEVTYPE}=="partition", GOTO="md_ignore_state"

# container devices have a metadata version of e.g. 'external:ddf' and
# never leave state 'inactive'
ATTR{md/metadata_version}=="external:[A-Za-z]*", ATTR{md/array_state}=="inactive", GOTO="md_ignore_state"
TEST!="md/array_state", GOTO="md_end"
ATTR{md/array_state}=="|clear|inactive", GOTO="md_end"

LABEL="md_ignore_state"

IMPORT{program}="/sbin/mdadm --detail --export $tempnode"
IMPORT BLKID
OPTIONS+="link_priority=100"
OPTIONS+="watch"
LABEL="md_end"

View File

@ -48,23 +48,18 @@ install() {
inst $(command -v partx) /sbin/partx
inst $(command -v mdadm) /sbin/mdadm

# XXX: mdmon really needs to run as non-root?
# If so, write only the user it needs in the initrd's /etc/passwd (and maybe /etc/group)
# in a similar fashion to modules.d/95nfs. Do not copy /etc/passwd and /etc/group from
# the system into the initrd.
# dledford has hardware to test this, so he should be able to clean this up.
# inst /etc/passwd
# inst /etc/group

inst_rules 64-md-raid.rules
# remove incremental assembly from stock rules, so they don't shadow
# 65-md-inc*.rules and its fine-grained controls, or cause other problems
# when we explicitly don't want certain components to be incrementally
# assembled
sed -i -r -e '/RUN\+?="[[:alpha:]/]*mdadm[[:blank:]]+(--incremental|-I)[[:blank:]]+(\$env\{DEVNAME\}|\$tempnode)"/d' "${initdir}${udevdir}/rules.d/64-md-raid.rules"
inst_rules 64-md-raid.rules
# remove incremental assembly from stock rules, so they don't shadow
# 65-md-inc*.rules and its fine-grained controls, or cause other problems
# when we explicitly don't want certain components to be incrementally
# assembled
sed -i -r -e '/RUN\+?="[[:alpha:]/]*mdadm[[:blank:]]+(--incremental|-I)[[:blank:]]+(\$env\{DEVNAME\}|\$tempnode)"/d' "${initdir}${udevdir}/rules.d/64-md-raid.rules"

inst_rules "$moddir/65-md-incremental-imsm.rules"

inst_rules "$moddir/59-persistent-storage-md.rules"
prepare_udev_rules 59-persistent-storage-md.rules

# guard against pre-3.0 mdadm versions, that can't handle containers
if ! mdadm -Q -e imsm /dev/null >/dev/null 2>&1; then
inst_hook pre-trigger 30 "$moddir/md-noimsm.sh"

View File

@ -6,35 +6,4 @@ ENV{DM_MULTIPATH_DEVICE_PATH}=="?*", GOTO="ps_end"
KERNEL=="cciss[0-9]*", IMPORT BLKID
KERNEL=="nbd[0-9]*", IMPORT BLKID


KERNEL!="md[0-9]*|md_d[0-9]*|md/*", KERNEL!="md*", GOTO="md_end"

# partitions have no md/{array_state,metadata_version}
ENV{DEVTYPE}=="partition", GOTO="md_ignore_state"

# container devices have a metadata version of e.g. 'external:ddf' and
# never leave state 'inactive'
ATTR{md/metadata_version}=="external:[A-Za-z]*", ATTR{md/array_state}=="inactive", GOTO="md_ignore_state"
TEST!="md/array_state", GOTO="md_end"
ATTR{md/array_state}=="|clear|inactive", GOTO="md_end"

LABEL="md_ignore_state"

IMPORT{program}="/sbin/mdadm --detail --export $tempnode"
IMPORT BLKID
OPTIONS+="link_priority=100"
OPTIONS+="watch"
LABEL="md_end"


KERNEL!="dm-[0-9]*", GOTO="ps_end"
ACTION=="add", GOTO="ps_end"
IMPORT{program}="/sbin/dmsetup info -c --nameprefixes --unquoted --rows --noheadings -o name,uuid,suspended,readonly,major,minor,open,tables_loaded,names_using_dev -j%M -m%m"
ENV{DM_NAME}!="?*", GOTO="ps_end"
ENV{DM_UDEV_DISABLE_OTHER_RULES_FLAG}=="1", GOTO="ps_end"
ENV{DM_UUID}=="CRYPT-TEMP-?*", GOTO="ps_end"
ENV{DM_UUID}!="?*", ENV{DM_NAME}=="temporary-cryptsetup-?*", GOTO="ps_end"
IMPORT BLKID


LABEL="ps_end"

View File

@ -34,6 +34,8 @@ install() {
"$moddir/59-persistent-storage.rules" \
"$moddir/61-persistent-storage.rules"

prepare_udev_rules 59-persistent-storage.rules 61-persistent-storage.rules

inst_dir /run/udev
inst_dir /run/udev/rules.d

@ -41,7 +43,7 @@ install() {
for i in cdrom tape dialout floppy; do
if ! egrep -q "^$i:" "$initdir/etc/group" 2>/dev/null; then
if ! egrep "^$i:" /etc/group 2>/dev/null; then
case $i in
case $i in
cdrom) echo "$i:x:11:";;
dialout) echo "$i:x:18:";;
floppy) echo "$i:x:19:";;
@ -75,6 +77,5 @@ install() {

inst_libdir_file "libnss_files*"

. "$moddir/udev-rules-prepare.sh"
}


View File

@ -1,27 +0,0 @@
#!/bin/sh
# -*- mode: shell-script; indent-tabs-mode: nil; sh-basic-offset: 4; -*-
# ex: ts=8 sw=4 sts=4 et filetype=sh

[ -z "$UDEVVERSION" ] && export UDEVVERSION=$(udevadm --version)

for f in ${initdir}/etc/udev/rules.d/*-persistent-storage.rules; do
[ -e "$f" ] || continue
while read line; do
if [ "${line%%IMPORT PATH_ID}" != "$line" ]; then
if [ $UDEVVERSION -ge 174 ]; then
printf '%sIMPORT{builtin}="path_id"\n' "${line%%IMPORT PATH_ID}"
else
printf '%sIMPORT{program}="path_id %%p"\n' "${line%%IMPORT PATH_ID}"
fi
elif [ "${line%%IMPORT BLKID}" != "$line" ]; then
if [ $UDEVVERSION -ge 176 ]; then
printf '%sIMPORT{builtin}="blkid"\n' "${line%%IMPORT BLKID}"
else
printf '%sIMPORT{program}="/sbin/blkid -o udev -p $tempnode"\n' "${line%%IMPORT BLKID}"
fi
else
echo "$line"
fi
done < "${f}" > "${f}.new"
mv "${f}.new" "$f"
done