commit:     fe4f505dab7c4c1420c54d493d638445d95dc742
Author:     Thomas Deutschmann <whissi <AT> gentoo <DOT> org>
AuthorDate: Thu Jul 23 20:59:33 2020 +0000
Commit:     Thomas Deutschmann <whissi <AT> gentoo <DOT> org>
CommitDate: Thu Jul 23 22:56:48 2020 +0000
URL:        https://gitweb.gentoo.org/proj/genkernel.git/commit/?id=fe4f505d

multipath: Switch to UDEV usage

Signed-off-by: Thomas Deutschmann <whissi <AT> gentoo.org>

 defaults/initrd.scripts | 46 ++++++++++------------------------------------
 gen_initramfs.sh        | 31 ++++++++++++++++++++++++++++---
 gkbuilds/lvm.gkbuild    |  5 +++--
 3 files changed, 41 insertions(+), 41 deletions(-)

diff --git a/defaults/initrd.scripts b/defaults/initrd.scripts
index 8e7d109..7d852ee 100644
--- a/defaults/initrd.scripts
+++ b/defaults/initrd.scripts
@@ -1527,48 +1527,22 @@ start_volumes() {
 
        if [ "${USE_MULTIPATH_NORMAL}" = '1' ]
        then
-               for multipath_path in /sbin/multipath /bin/multipath MISSING
-               do
-                       [ -x "${multipath_path}" ] && break
-               done
-
-               for dmsetup_path in /usr/sbin/dmsetup /sbin/dmsetup 
/bin/dmsetup MISSING
-               do
-                       [ -x "${dmsetup_path}" ] && break
-               done
-
-               for kpartx_path in /sbin/kpartx /bin/kpartx MISSING
-               do
-                       [ -x "${kpartx_path}" ] && break
-               done
-
-               fail=0
-               [ "${multipath_path}" = "MISSING" ] && fail=1 && bad_msg 
"domultipath called, but multipath binary missing! Skipping multipath"
-               [ "${dmsetup_path}" = "MISSING" ] && fail=1 && bad_msg 
"domultipath called, but dmsetup binary missing! Skipping multipath"
-               [ "${kpartx_path}" = "MISSING" ] && fail=1 && bad_msg 
"domultipath called, but kpartx binary missing! Skipping multipath"
-
-               if [ ${fail} -eq 0 ]
+               if ! hash multipath >/dev/null 2>&1
                then
+                       bad_msg "domultipath called, but multipath binary 
missing! Skipping multipath"
+               else
                        good_msg "Scanning for multipath devices"
-                       good_msg ":: Populating scsi_id info for libudev 
queries"
-                       run mkdir -p /run/udev/data
 
-                       local ech
-                       for ech in /sys/block/*
-                       do
-                               local tgtfile=b$(cat ${ech}/dev)
-                               run /lib/udev/scsi_id -g -x /dev/${ech##*/} | 
sed -e 's/^/E:/' >/run/udev/data/${tgtfile}
-                       done
-
-                       local multipath_cmd="run ${multipath_path} -v 0 2>&1"
+                       local multipath_cmd="run multipath -v 0 2>&1"
                        is_log_enabled && multipath_cmd="${multipath_cmd} | tee 
-a '${GK_INIT_LOG}'"
-                       eval "${multipath_cmd}"
-                       sleep 2
 
-                       good_msg "Activating multipath devices ..."
-                       multipath_cmd="run ${dmsetup_path} ls --target 
multipath --exec '${kpartx_path} -a -v' 2>&1"
-                       is_log_enabled && multipath_cmd="${multipath_cmd} | tee 
-a '${GK_INIT_LOG}'"
                        eval "${multipath_cmd}"
+                       if [ $? -ne 0 ]
+                       then
+                               bad_msg "Scanning for multipath devices failed!"
+                       else
+                               udevsettle
+                       fi
                fi
        fi
 

diff --git a/gen_initramfs.sh b/gen_initramfs.sh
index af0ff44..1b8c829 100755
--- a/gen_initramfs.sh
+++ b/gen_initramfs.sh
@@ -701,15 +701,40 @@ append_multipath() {
 
        mkdir -p "${TDIR}"/etc || gen_die "Failed to create '${TDIR}/etc'!"
 
+       mkdir -p "${TDIR}"/usr/lib/udev/rules.d || gen_die "Failed to create 
'${TDIR}/usr/lib/udev/rules.d'!"
+
        local libdir=$(get_chost_libdir)
+       if [[ "${libdir}" =~ ^/usr ]]
+       then
+               libdir=${libdir/\/usr/}
+       fi
 
        copy_binaries \
-               "${TDIR}"\
+               "${TDIR}" \
                /sbin/multipath \
                /sbin/kpartx \
                /sbin/mpathpersist \
-               ${libdir}/multipath/lib*.so \
-               /lib/udev/scsi_id
+               ${libdir}/multipath/lib*.so
+
+       local udevdir=$(get_udevdir)
+       local udevdir_initramfs="/usr/lib/udev"
+       local udev_files=( $(qlist -e sys-fs/multipath-tools:0 \
+               | xargs --no-run-if-empty realpath \
+               | grep -E -- "^${udevdir}")
+       )
+
+       if [ ${#udev_files[@]} -eq 0 ]
+       then
+               gen_die "Something went wrong: Did not found any udev-related 
files for sys-fs/multipath-tools!"
+       fi
+
+       local udev_files
+       for udev_file in "${udev_files[@]}"
+       do
+               local 
dest_file="${TDIR%/}${udev_file/${udevdir}/${udevdir_initramfs}}"
+               cp -aL "${udev_file}" "${dest_file}" \
+                       || gen_die "Failed to copy '${udev_file}' to 
'${dest_file}'"
+       done
 
        cd "${TDIR}" || gen_die "Failed to chdir to '${TDIR}'!"
 

diff --git a/gkbuilds/lvm.gkbuild b/gkbuilds/lvm.gkbuild
index 1346cb0..3006381 100644
--- a/gkbuilds/lvm.gkbuild
+++ b/gkbuilds/lvm.gkbuild
@@ -63,11 +63,12 @@ src_install() {
        ln -s dmsetup "${D}"/usr/sbin/dmstats \
                || die "Failed to create symlink '${D}/usr/sbin/dmstats' to 
'${D}/usr/sbin/dmsetup'!"
 
-       # For backward compatibility
+       # For backward compatibility (packages like multipath-tools are
+       # expecting /sbin/dmsetup in udev rules).
        mkdir "${D}"/sbin || die "Failed to create '${D}/sbin'!"
 
        ln -s ../usr/sbin/dmsetup "${D}"/sbin/dmsetup \
-               || die "Failed to create symlink '${D}/sbin/dmstats' to 
'${D}/usr/sbin/dmstats'!"
+               || die "Failed to create symlink '${D}/sbin/dmsetup' to 
'${D}/usr/sbin/dmsetup'!"
 
        ln -s ../usr/sbin/dmstats "${D}"/sbin/dmstats \
                || die "Failed to create symlink '${D}/sbin/dmstats' to 
'${D}/usr/sbin/dmstats'!"

Reply via email to