improve DASD parameters handling in normalize_dasd_arg (#824807)

This commit is contained in:
Dan Horák 2012-05-25 09:04:27 +02:00
parent 8c7c2bc4db
commit 0355cd14d3
2 changed files with 81 additions and 70 deletions

View File

@ -39,74 +39,82 @@ function canonicalize_devno()
} }
read DASD read DASD
for dasditem in $(echo $DASD |sed 's/,/ /g') # See if we've gotten a format like <dev>,feature or <dev>,<dev>,<dev>
do [[ "$DASD" =~ (\,*=[[:digit:]]) ]]
unset range features lo hi attrs devno lodevno hidevno devbusid sys case $? in
case $dasditem in # case of 0 is features, just turn the comma into a space
autodetect|probeonly|nopav|nofcx|"") continue ;; # these don't gen a config 0) echo $DASD |sed 's/,/ /g';;
*) *) # We've got no features, do things normally
IFS='(' for dasditem in $(echo $DASD |sed 's/,/ /g')
read range features <<< "$dasditem" do
unset IFS unset range features lo hi attrs devno lodevno hidevno devbusid sys
lo=${range%%-*} case $dasditem in
[[ "$lo" =~ (^[[:xdigit:]]+\.[0-3]\.[[:xdigit:]]{4}$)|(^[[:xdigit:]]{3,4}$) ]] autodetect|probeonly|nopav|nofcx|"") continue ;; # these don't gen a config
case $? in *)
0) # string matched the pattern IFS='('
lo=$(canonicalize_devno $lo) ;; read range features <<< "$dasditem"
1) # string did not match the pattern unset IFS
echo $"Incorrect format for lower bound of DASD range $range: $lo" lo=${range%%-*}
exit 1 [[ "$lo" =~ (^[[:xdigit:]]+\.[0-3]\.[[:xdigit:]]{4}$)|(^[[:xdigit:]]{3,4}$) ]]
;; case $? in
2) echo "l.$LINENO: syntax error in regex of match operator =~, code needs to be fixed" 1>&2 ;; 0) # string matched the pattern
*) echo "l.$LINENO: unexpected return code of regex match operator =~, code needs to be fixed" 1>&2 ;; lo=$(canonicalize_devno $lo) ;;
esac 1) # string did not match the pattern
if [ "${range//*-*/}" = "" ]; then echo $"Incorrect format for lower bound of DASD range $range: $lo" 1>&2
hi=${range##*-}
[[ "$hi" =~ (^[[:xdigit:]]+\.[0-3]\.[[:xdigit:]]{4}$)|(^[[:xdigit:]]{3,4}$) ]]
case $? in
0) # string matched the pattern
hi=$(canonicalize_devno $hi)
if [ "${lo%.*}" != "${hi%.*}" ]; then
echo $"Prefixes of DASD range $range do not match: ${lo%.*} != ${hi%.*}"
exit 1 exit 1
fi ;;
;; 2) echo "l.$LINENO: syntax error in regex of match operator =~, code needs to be fixed" 1>&2 ;;
1) # string did not match the pattern *) echo "l.$LINENO: unexpected return code of regex match operator =~, code needs to be fixed" 1>&2 ;;
echo $"Incorrect format for upper bound of DASD range $range: $hi"
exit 1
;;
2) echo "l.$LINENO: syntax error in regex of match operator =~, code needs to be fixed" 1>&2 ;;
*) echo "l.$LINENO: unexpected return code of regex match operator =~, code needs to be fixed" 1>&2 ;;
esac
fi
if [ "${features//*)/}" != "" ]; then
echo $"Missing closing parenthesis at features of DASD range $range: ($features"
exit 1
fi
if [ -n "$features" ]; then
attrs=""
features="${features%)}"
for feature in $(echo $features |sed 's/:/\n/g'); do
case $feature in
ro) attrs=$attrs" readonly" ;;
diag) attrs=$attrs" use_diag" ;;
erplog|failfast) attrs=$attrs" "$feature ;;
*) echo $"Unknown DASD feature for device range $range: $feature"
exit 1
;;
esac esac
done if [ "${range//*-*/}" = "" ]; then
fi hi=${range##*-}
[ -z "$hi" ] && hi=$lo [[ "$hi" =~ (^[[:xdigit:]]+\.[0-3]\.[[:xdigit:]]{4}$)|(^[[:xdigit:]]{3,4}$) ]]
lodevno=$((0x${lo##*.})) case $? in
hidevno=$((0x${hi##*.})) 0) # string matched the pattern
for ((devno=$lodevno; $devno <= $hidevno; ++devno)); do hi=$(canonicalize_devno $hi)
devbusid=$(printf "%s.%04x" ${lo%.*} $devno) if [ "${lo%.*}" != "${hi%.*}" ]; then
echo -n "$devbusid" echo $"Prefixes of DASD range $range do not match: ${lo%.*} != ${hi%.*}" 1>&2
for attr in $attrs; do exit 1
echo -n " $attr=1" fi
done ;;
echo 1) # string did not match the pattern
done echo $"Incorrect format for upper bound of DASD range $range: $hi" 1>&2
esac exit 1
done ;;
2) echo "l.$LINENO: syntax error in regex of match operator =~, code needs to be fixed" 1>&2 ;;
*) echo "l.$LINENO: unexpected return code of regex match operator =~, code needs to be fixed" 1>&2 ;;
esac
fi
if [ "${features//*)/}" != "" ]; then
echo $"Missing closing parenthesis at features of DASD range $range: ($features" 1>&2
exit 1
fi
if [ -n "$features" ]; then
attrs=""
features="${features%)}"
for feature in $(echo $features |sed 's/:/\n/g'); do
case $feature in
ro) attrs=$attrs" readonly" ;;
diag) attrs=$attrs" use_diag" ;;
erplog|failfast) attrs=$attrs" "$feature ;;
*) echo $"Unknown DASD feature for device range $range: $feature" 1>&2
exit 1
;;
esac
done
fi
[ -z "$hi" ] && hi=$lo
lodevno=$((0x${lo##*.}))
hidevno=$((0x${hi##*.}))
for ((devno=$lodevno; $devno <= $hidevno; ++devno)); do
devbusid=$(printf "%s.%04x" ${lo%.*} $devno)
echo -n "$devbusid"
for attr in $attrs; do
echo -n " $attr=1"
done
echo
done
esac
done
;;
esac

View File

@ -8,7 +8,7 @@ Name: s390utils
Summary: Utilities and daemons for IBM System/z Summary: Utilities and daemons for IBM System/z
Group: System Environment/Base Group: System Environment/Base
Version: 1.16.0 Version: 1.16.0
Release: 8%{?dist} Release: 9%{?dist}
Epoch: 2 Epoch: 2
License: GPLv2 and GPLv2+ and CPL License: GPLv2 and GPLv2+ and CPL
Buildroot: %{_tmppath}/%{name}-%{version}-%{release}-root-%(%{__id_u} -n) Buildroot: %{_tmppath}/%{name}-%{version}-%{release}-root-%(%{__id_u} -n)
@ -867,6 +867,9 @@ User-space development files for the s390/s390x architecture.
%changelog %changelog
* Fri May 25 2012 Dan Horák <dan[at]danny.cz> 2:1.16.0-9
- improve DASD parameters handling in normalize_dasd_arg (#824807)
* Wed May 23 2012 Dan Horák <dan[at]danny.cz> 2:1.16.0-8 * Wed May 23 2012 Dan Horák <dan[at]danny.cz> 2:1.16.0-8
- add normalize_dasd_arg script (#823078) - add normalize_dasd_arg script (#823078)