Skip to content

Commit c55e82d

Browse files
committed
zdev: add helper to convert from dasd_mod.dasd to zdev config
Shell library, which can be sourced by other POSIX compatible shell scripts. Provide helper function parsing its stdin based on the syntax of kernel device driver parameter dasd_mod.dasd= and invoking chzdev to produce corresponding persistent device configurations. The helper function takes one argument, which is either "globals" or "ranges". For a complete configuration, call the function twice, first with "globals" and then with "ranges". The new script library file should be packaged in a core (sub)package of s390-tools so the script is available for initrd environments. Users with examples: Subsequent commit ("zdev/dracut: add rd.dasd parsing") introduces zdev/dracut/95zdev/parse-dasd.sh performing: zdev_parse_rd_dasd | zdev_parse_dasd_list globals 2>&1 | zdev_vinfo zdev_parse_rd_dasd | zdev_parse_dasd_list ranges 2>&1 | zdev_vinfo dracutdevs/dracut#2534 updates modules.d/80cms/cmssetup.sh performing: echo "$DASD" | zdev_parse_dasd_list globals 2>&1 | vinfo echo "$DASD" | zdev_parse_dasd_list ranges 2>&1 | vinfo The parsing code for rd.dasd using the same syntax as dasd_mod.dasd= is inspired by the own implementation that used to be in linuxrc.s390 of https://github.com/rhinstaller/anaconda. https://web.archive.org/web/20190721154444/https://www.redhat.com/archives/anaconda-devel-list/2009-February/msg00392.html https://www.spinics.net/linux/fedora/anaconda-devel/msg08316.html ("Re: Improved linuxrc.s390 (third try)") => 9249e40f42ff ("IBM improvements to linuxrc.s390 (#475350)") https://web.archive.org/web/20190721150254/https://www.redhat.com/archives/anaconda-devel-list/2009-July/msg00310.html => 5f0fcf6688d0 ("Update linuxrc.s390 and friends to reflect review comments.") https://web.archive.org/web/20190721125255/https://www.redhat.com/archives/anaconda-devel-list/2009-August/msg00158.html => 523095c86876 ("Handle activation of DASDs in linuxrc.s390 since loader no longer works") Signed-off-by: Steffen Maier <[email protected]>
1 parent b66396d commit c55e82d

File tree

2 files changed

+89
-1
lines changed

2 files changed

+89
-1
lines changed

zdev/src/Makefile

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -106,12 +106,13 @@ libs = $(rootdir)/libap/libap.a \
106106
chzdev: $(chzdev_objects) $(libs)
107107
lszdev: $(lszdev_objects) $(libs)
108108

109-
install: chzdev zdev_id zdev-to-dasd_mod.dasd
109+
install: chzdev zdev_id zdev-to-dasd_mod.dasd zdev-from-dasd_mod.dasd
110110
$(INSTALL) -d -m 755 $(DESTDIR)$(BINDIR)
111111
$(INSTALL) -c chzdev $(DESTDIR)$(BINDIR)
112112
$(INSTALL) -c lszdev $(DESTDIR)$(BINDIR)
113113
$(INSTALL) -c zdev_id $(DESTDIR)$(TOOLS_LIBDIR)
114114
$(INSTALL) -c zdev-to-dasd_mod.dasd $(DESTDIR)$(TOOLS_LIBDIR)
115+
$(INSTALL) -c -m 644 zdev-from-dasd_mod.dasd $(DESTDIR)$(TOOLS_LIBDIR)
115116
ifeq ($(HAVE_DRACUT),1)
116117
$(INSTALL) -m 755 zdev-root-update.dracut \
117118
$(DESTDIR)$(TOOLS_LIBDIR)/zdev-root-update

zdev/src/zdev-from-dasd_mod.dasd

Lines changed: 87 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,87 @@
1+
#
2+
# Copyright IBM Corp. 2023
3+
#
4+
# s390-tools is free software; you can redistribute it and/or modify
5+
# it under the terms of the MIT license. See LICENSE for details.
6+
#
7+
# zdev-from-dasd_mod.dasd
8+
# Shell library, which can be sourced by other POSIX compatible shell scripts.
9+
# Provide helper function parsing its stdin based on the syntax of kernel
10+
# device driver parameter dasd_mod.dasd= and invoking chzdev to produce
11+
# corresponding persistent device configurations. The helper function
12+
# takes one argument, which is either "globals" or "ranges". For a
13+
# complete configuration, call the function twice, first with "globals"
14+
# and then with "ranges".
15+
#
16+
# shellcheck shell=sh
17+
18+
# It would be possible to pass the collected rd.dasd options via
19+
# modprobe.d. However, it is still required to parse the options to handle
20+
# cio_ignore. That in turn ensures devices get sensed. Sensing is in turn
21+
# required for automatically loading the device drivers via modalias and
22+
# for the dasd device driver to find devices it can probe (set online). So
23+
# go all the way and parse the rd.dasd options. For device bus-IDs, use
24+
# chzdev, which not only handles cio_ignore transparently, but also
25+
# generates persistent configuration that can be transferred from initrd to
26+
# another root files system such as in a distro installer environment.
27+
28+
zdev_dasd_base_args="--no-settle --yes --no-root-update --force"
29+
30+
zdev_parse_dasd_list() {
31+
sed 's/,/\n/g' | while read -r _zdev_dasditem; do
32+
unset _zdev_dasd_range _zdev_dasd_features _zdev_dasd_attrs
33+
case $_zdev_dasditem in
34+
autodetect|probeonly|nopav|nofcx)
35+
[ "$1" = "globals" ] || continue
36+
# Autodetect can of course only enable devices that are not
37+
# in the cio_ignore list.
38+
# Intentionally do not dynamically configure now, but only
39+
# generate a modprobe.d file, which configures the device
40+
# later during kernel module load.
41+
echo "rd.dasd ...,${_zdev_dasditem},... :"
42+
# shellcheck disable=SC2086
43+
chzdev dasd --type "${_zdev_dasditem}=1" --persistent \
44+
$zdev_dasd_base_args
45+
;;
46+
"") continue ;; # empty range
47+
*) # currently no support for a device-spec "ipldev", only devbusid
48+
[ "$1" = "ranges" ] || continue
49+
SAVED_IFS="$IFS"
50+
IFS='('
51+
read -r _zdev_dasd_range _zdev_dasd_features <<EOF
52+
$_zdev_dasditem
53+
EOF
54+
IFS="$SAVED_IFS"
55+
if [ "${_zdev_dasd_features%%*)}" != "" ]; then
56+
warn "rd.dasd: Missing closing parenthesis at features of DASD range $_zdev_dasd_range: ($_zdev_dasd_features"
57+
fi
58+
if [ -n "$_zdev_dasd_features" ]; then
59+
_zdev_dasd_features="${_zdev_dasd_features%)}"
60+
_zdev_dasd_features=$(echo "$_zdev_dasd_features" | sed 's/:/\n/g')
61+
while read -r _zdev_dasd_feature; do
62+
case $_zdev_dasd_feature in
63+
ro) _zdev_dasd_attrs="$_zdev_dasd_attrs readonly=1" ;;
64+
diag) _zdev_dasd_attrs="$_zdev_dasd_attrs use_diag=1" ;;
65+
raw) _zdev_dasd_attrs="$_zdev_dasd_attrs raw_track_access=1" ;;
66+
erplog|failfast) _zdev_dasd_attrs="$_zdev_dasd_attrs ${_zdev_dasd_feature}=1" ;;
67+
*)
68+
warn "rd.dasd: Unknown DASD feature for device range $_zdev_dasd_range: $_zdev_dasd_feature"
69+
;;
70+
esac
71+
done <<EOF
72+
$_zdev_dasd_features
73+
EOF
74+
fi
75+
# Without dynamic (active) config zdev cannot infer
76+
# the actual dasd type (eckd, fba) so configure for both.
77+
echo "rd.dasd ...,${_zdev_dasditem},... :"
78+
# shellcheck disable=SC2086
79+
chzdev dasd-eckd --enable --persistent "$_zdev_dasd_range" $_zdev_dasd_attrs \
80+
$zdev_dasd_base_args
81+
# shellcheck disable=SC2086
82+
chzdev dasd-fba --enable --persistent "$_zdev_dasd_range" $_zdev_dasd_attrs \
83+
$zdev_dasd_base_args
84+
;;
85+
esac
86+
done # input redir w/ process substitution causes syntax error in dracut env
87+
}

0 commit comments

Comments
 (0)