From 9b2fb1d4d2e27b76fd97446eb5fddfe346487b2b Mon Sep 17 00:00:00 2001 From: Steffen Maier Date: Tue, 25 Jul 2023 19:14:41 +0200 Subject: [PATCH] zdev: add helper to convert from dasd_mod.dasd to zdev config MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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 https://github.com/dracutdevs/dracut/pull/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") Github-ID: https://github.com/ibm-s390-linux/s390-tools/pull/158 Acked-by: Vineeth Vijayan Acked-by: Peter Oberparleiter Signed-off-by: Steffen Maier Signed-off-by: Jan Höppner --- zdev/src/Makefile | 3 +- zdev/src/zdev-from-dasd_mod.dasd | 87 ++++++++++++++++++++++++++++++++ 2 files changed, 89 insertions(+), 1 deletion(-) create mode 100644 zdev/src/zdev-from-dasd_mod.dasd diff --git a/zdev/src/Makefile b/zdev/src/Makefile index c43b6547..54785378 100644 --- a/zdev/src/Makefile +++ b/zdev/src/Makefile @@ -106,12 +106,13 @@ libs = $(rootdir)/libap/libap.a \ chzdev: $(chzdev_objects) $(libs) lszdev: $(lszdev_objects) $(libs) -install: chzdev zdev_id zdev-to-dasd_mod.dasd +install: chzdev zdev_id zdev-to-dasd_mod.dasd zdev-from-dasd_mod.dasd $(INSTALL) -d -m 755 $(DESTDIR)$(BINDIR) $(INSTALL) -c chzdev $(DESTDIR)$(BINDIR) $(INSTALL) -c lszdev $(DESTDIR)$(BINDIR) $(INSTALL) -c zdev_id $(DESTDIR)$(TOOLS_LIBDIR) $(INSTALL) -c zdev-to-dasd_mod.dasd $(DESTDIR)$(TOOLS_LIBDIR) + $(INSTALL) -c -m 644 zdev-from-dasd_mod.dasd $(DESTDIR)$(TOOLS_LIBDIR) ifeq ($(HAVE_DRACUT),1) $(INSTALL) -m 755 zdev-root-update.dracut \ $(DESTDIR)$(TOOLS_LIBDIR)/zdev-root-update diff --git a/zdev/src/zdev-from-dasd_mod.dasd b/zdev/src/zdev-from-dasd_mod.dasd new file mode 100644 index 00000000..d2df5ff7 --- /dev/null +++ b/zdev/src/zdev-from-dasd_mod.dasd @@ -0,0 +1,87 @@ +# +# Copyright IBM Corp. 2023 +# +# s390-tools is free software; you can redistribute it and/or modify +# it under the terms of the MIT license. See LICENSE for details. +# +# zdev-from-dasd_mod.dasd +# 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". +# +# shellcheck shell=sh + +# It would be possible to pass the collected rd.dasd options via +# modprobe.d. However, it is still required to parse the options to handle +# cio_ignore. That in turn ensures devices get sensed. Sensing is in turn +# required for automatically loading the device drivers via modalias and +# for the dasd device driver to find devices it can probe (set online). So +# go all the way and parse the rd.dasd options. For device bus-IDs, use +# chzdev, which not only handles cio_ignore transparently, but also +# generates persistent configuration that can be transferred from initrd to +# another root files system such as in a distro installer environment. + +zdev_dasd_base_args="--no-settle --yes --no-root-update --force" + +zdev_parse_dasd_list() { + sed 's/,/\n/g' | while read -r _zdev_dasditem; do + unset _zdev_dasd_range _zdev_dasd_features _zdev_dasd_attrs + case $_zdev_dasditem in + autodetect|probeonly|nopav|nofcx) + [ "$1" = "globals" ] || continue + # Autodetect can of course only enable devices that are not + # in the cio_ignore list. + # Intentionally do not dynamically configure now, but only + # generate a modprobe.d file, which configures the device + # later during kernel module load. + echo "rd.dasd ...,${_zdev_dasditem},... :" + # shellcheck disable=SC2086 + chzdev dasd --type "${_zdev_dasditem}=1" --persistent \ + $zdev_dasd_base_args + ;; + "") continue ;; # empty range + *) # currently no support for a device-spec "ipldev", only devbusid + [ "$1" = "ranges" ] || continue + SAVED_IFS="$IFS" + IFS='(' + read -r _zdev_dasd_range _zdev_dasd_features <