From b1c242ffc5762fea6c15fe880e352008a5c34c43 Mon Sep 17 00:00:00 2001 From: Michael Prokop Date: Tue, 8 Jun 2010 03:02:08 +0200 Subject: hook-functions: make device name handling for /proc/mdstat more flexible for MODULES=dep We can't assume it's always [hs]dX# in /proc/mdstat. It can be e.g. also [hs]dX (raw device) or dm-## as well. So don't statically calculate the string based on string length but instead try to be as smart as possible. Also add support for handling additional arguments in the /proc/mdstat output like "(auto-read-only)". This affects MODULES=dep only. [Closes: #584520] + [Closes: #514756] Reported-by: Simon Richter Reported-by: Martin Michlmayr Signed-off-by: Michael Prokop --- hook-functions | 30 +++++++++++++++++++++++------- 1 file changed, 23 insertions(+), 7 deletions(-) (limited to 'hook-functions') diff --git a/hook-functions b/hook-functions index 86dc905..8bebdea 100644 --- a/hook-functions +++ b/hook-functions @@ -259,8 +259,9 @@ dep_add_modules() done # lvm on md or luks on md if [ "${block#md}" != "${block}" ]; then - block=$(awk "/^${block}/{print substr(\$5, 1, 4); exit}" \ - /proc/mdstat) + block=$(grep "^${block}" /proc/mdstat | \ + awk "{gsub(/^${block} : .* (multipath|linear|raid[[:digit:]]+)\ /,\"\")};1") + block="${block%%\[*}" fi # luks or lvm on cciss or ida if [ "${block#cciss}" != "${block}" ] \ @@ -272,13 +273,28 @@ dep_add_modules() # md root new naming scheme /dev/md/X elif [ "${root#/dev/md/}" != "${root}" ]; then root=${root#/dev/md/} - block=$(awk "/^md${root}/{print substr(\$5, 1, 3); exit}" \ - /proc/mdstat) + block=$(grep "^md${root}" /proc/mdstat | \ + awk "{gsub(/^md${root} : .* (multipath|linear|raid[[:digit:]]+)\ /,\"\")};1") + block="${block%%\[*}" + # drop the partition number only for sdX and hdX devices + # and keep it for other devices like loop#, dm-# devices + case "$block" in + sd*) block=${block%%[0-9]*};; + hd*) block=${block%%[0-9]*};; + esac # md root /dev/mdX elif [ "${root#/dev/md}" != "${root}" ]; then - root=${root#/dev/} - block=$(awk "/^${root}/{print substr(\$5, 1, 3); exit}" \ - /proc/mdstat) + root=${root#/dev/md} + block=$(grep "^md${root}" /proc/mdstat | \ + awk "{gsub(/^md${root} : .* (multipath|linear|raid[[:digit:]]+)\ /,\"\")};1") + block="${block%%\[*}" + # drop the partition number only for sdX and hdX devices + # and keep it for other devices like loop#, dm-# devices + case "$block" in + sd*) block=${block%%[0-9]*};; + hd*) block=${block%%[0-9]*};; + esac + # cciss device elif [ "${root#/dev/cciss/}" != "${root}" ]; then block=${root#/dev/cciss/*} -- cgit v1.2.3