From 15384bcedb8002440e1327e97cd9c139af8a32dd Mon Sep 17 00:00:00 2001 From: Harald Hoyer Date: Mon, 15 Jan 2018 15:44:46 +0100 Subject: [PATCH] dracut-functions.sh:check_vol_slaves() speedup LV -> VG name Instead of trying all /dev/mapper/* devices to match the maj:min, and get the VG name with "lvm lvs", use the dm/name from /sys and dmsetup splitname. This should speedup execution with lots of LVs. Cherry-picked from: 9ed6eb741 Resolves: #1531503 --- dracut-functions.sh | 62 +++++++++++++++++++++------------------------ 1 file changed, 29 insertions(+), 33 deletions(-) diff --git a/dracut-functions.sh b/dracut-functions.sh index ca54bd7f..53289ca0 100755 --- a/dracut-functions.sh +++ b/dracut-functions.sh @@ -687,43 +687,39 @@ for_each_host_dev_and_slaves() # but you cannot create the logical volume without the volume group. # And the volume group might be bigger than the devices the LV needs. check_vol_slaves() { - local _lv _vg _pv - for i in /dev/mapper/*; do - [[ $i == /dev/mapper/control ]] && continue - _lv=$(get_maj_min $i) - if [[ $_lv = $2 ]]; then - _vg=$(lvm lvs --noheadings -o vg_name $i 2>/dev/null) - # strip space - _vg="${_vg//[[:space:]]/}" - if [[ $_vg ]]; then - for _pv in $(lvm vgs --noheadings -o pv_name "$_vg" 2>/dev/null) - do - check_block_and_slaves $1 $(get_maj_min $_pv) && return 0 - done - fi - fi - done + local _lv _vg _pv _dm _majmin + _majmin="$2" + _lv="/dev/block/$_majmin" + _dm=/sys/dev/block/$_majmin/dm + [[ -f $_dm/uuid && $(<$_dm/uuid) =~ LVM-* ]] || return 1 + _vg=$(dmsetup splitname --noheadings -o vg_name $(<"$_dm/name") ) + # strip space + _vg="${_vg//[[:space:]]/}" + if [[ $_vg ]]; then + for _pv in $(lvm vgs --noheadings -o pv_name "$_vg" 2>/dev/null) + do + check_block_and_slaves $1 $(get_maj_min $_pv) && return 0 + done + fi return 1 } check_vol_slaves_all() { - local _lv _vg _pv - for i in /dev/mapper/*; do - [[ $i == /dev/mapper/control ]] && continue - _lv=$(get_maj_min $i) - if [[ $_lv = $2 ]]; then - _vg=$(lvm lvs --noheadings -o vg_name $i 2>/dev/null) - # strip space - _vg="${_vg//[[:space:]]/}" - if [[ $_vg ]]; then - for _pv in $(lvm vgs --noheadings -o pv_name "$_vg" 2>/dev/null) - do - check_block_and_slaves_all $1 $(get_maj_min $_pv) - done - return 0 - fi - fi - done + local _lv _vg _pv _majmin + _majmin="$2" + _lv="/dev/block/$_majmin" + _dm="/sys/dev/block/$_majmin/dm" + [[ -f $_dm/uuid && $(<$_dm/uuid) =~ LVM-* ]] || return 1 + _vg=$(dmsetup splitname --noheadings -o vg_name $(<"$_dm/name") ) + # strip space + _vg="${_vg//[[:space:]]/}" + if [[ $_vg ]]; then + for _pv in $(lvm vgs --noheadings -o pv_name "$_vg" 2>/dev/null) + do + check_block_and_slaves_all $1 $(get_maj_min $_pv) + done + return 0 + fi return 1 }