From: Harald Hoyer Date: Thu, 7 Mar 2013 13:49:21 +0000 (+0100) Subject: split 95udev-rules/59-persistent-storage.rules to md and dm modules X-Git-Tag: 026~5 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=c46cda8260a53884182a9c8ad06f59e56729bdb4;p=thirdparty%2Fdracut.git split 95udev-rules/59-persistent-storage.rules to md and dm modules --- diff --git a/dracut-functions.sh b/dracut-functions.sh index 53ee9f75b..2a84d175f 100755 --- a/dracut-functions.sh +++ b/dracut-functions.sh @@ -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. diff --git a/modules.d/90dm/59-persistent-storage-dm.rules b/modules.d/90dm/59-persistent-storage-dm.rules new file mode 100644 index 000000000..73b093767 --- /dev/null +++ b/modules.d/90dm/59-persistent-storage-dm.rules @@ -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" diff --git a/modules.d/90dm/module-setup.sh b/modules.d/90dm/module-setup.sh index 6ec9af494..314c082fa 100755 --- a/modules.d/90dm/module-setup.sh +++ b/modules.d/90dm/module-setup.sh @@ -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" } diff --git a/modules.d/90mdraid/59-persistent-storage-md.rules b/modules.d/90mdraid/59-persistent-storage-md.rules new file mode 100644 index 000000000..bea932571 --- /dev/null +++ b/modules.d/90mdraid/59-persistent-storage-md.rules @@ -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" diff --git a/modules.d/90mdraid/module-setup.sh b/modules.d/90mdraid/module-setup.sh index 3824f406e..a2b9ac2a9 100755 --- a/modules.d/90mdraid/module-setup.sh +++ b/modules.d/90mdraid/module-setup.sh @@ -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" diff --git a/modules.d/95udev-rules/59-persistent-storage.rules b/modules.d/95udev-rules/59-persistent-storage.rules index c221cda5d..47ff6edd9 100644 --- a/modules.d/95udev-rules/59-persistent-storage.rules +++ b/modules.d/95udev-rules/59-persistent-storage.rules @@ -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" diff --git a/modules.d/95udev-rules/module-setup.sh b/modules.d/95udev-rules/module-setup.sh index f56f16624..1eb8642c9 100755 --- a/modules.d/95udev-rules/module-setup.sh +++ b/modules.d/95udev-rules/module-setup.sh @@ -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" } diff --git a/modules.d/95udev-rules/udev-rules-prepare.sh b/modules.d/95udev-rules/udev-rules-prepare.sh deleted file mode 100644 index 920485d93..000000000 --- a/modules.d/95udev-rules/udev-rules-prepare.sh +++ /dev/null @@ -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