Mike Burns
2010-Mar-10 04:18 UTC
[Ovirt-devel] [PATCH node] Improve performance of multipath translations
Cleanup the translations of /dev/sdX to /dev/mapper and vice-versa. Signed-off-by: Mike Burns <mburns at redhat.com> --- scripts/ovirt-config-storage | 24 +++++++++++++++--------- scripts/ovirt-functions | 22 ++++++++++++++++++++++ 2 files changed, 37 insertions(+), 9 deletions(-) diff --git a/scripts/ovirt-config-storage b/scripts/ovirt-config-storage index aea73f8..cf73aa4 100755 --- a/scripts/ovirt-config-storage +++ b/scripts/ovirt-config-storage @@ -38,13 +38,12 @@ swap_min_size=5 get_sd_name() { local id=$1 local device_var=$2 - for device in $(ls /sys/block) - do - if [[ $id = $(cat /sys/block/$device/dev) ]]; then - eval $device_var=$device - return - fi - done + local device_sys=$(grep -H "^$id$" /sys/block/*/dev | cut -d: -f1) + + if [ -n "$device_sys" ]; then + eval $device_var=$(basename $(dirname $device_sys)) + return + fi eval $device_var=1 } @@ -83,10 +82,17 @@ translate_multipath_device() { local dev=$1 local mpath_var=$2 + if [[ $dev =~ "/dev/mapper" ]]; then + eval $mpath_var=$dev + return + fi + local basedev=$(basename $dev) - local mpath_device=$(multipath -ll $dev |grep -n . | \ - grep "^1:" |awk '{print $1}' | sed 's/^1:/\/dev\/mapper\//g') + local dm_dev=/dev/$(multipath -ll $dev | egrep dm-[0-9]+ | sed -r 's/^.& (dm-[0-9]+) .*$/\1/') + + local mpath_device+ get_dm_device $dm_dev $mpath_device if [ -z "$mpath_device" ]; then mpath_device=$dev diff --git a/scripts/ovirt-functions b/scripts/ovirt-functions index 6839614..5661bee 100644 --- a/scripts/ovirt-functions +++ b/scripts/ovirt-functions @@ -765,6 +765,28 @@ test_ntp_configuration () { } +get_dm_device () +{ + local device=$1 + local return_var=$2 + major=$(stat -c '%t' $(readlink -f $device)) + minor=$(stat -c '%T' $(readlink -f $device)) + local dm_device+ local rc=1 + for dm in /dev/mapper/*; do + if [ $major = $(stat -c '%t' $dm) -a \ + $minor = $(stat -c '%T' $dm) ]; then + local dm_device=$dm + rc=0 + break + fi + done + + eval $return_var=$dm_device + + return $rc +} + # execute a function if called as a script, e.g. # ovirt-functions ovirt_store_config /etc/hosts -- 1.6.6.1
Seemingly Similar Threads
- [PATCH][node REPOST] Improve performance of multipath translations
- [PATCH node] Handle space in storage wwid
- [PATCH node] First draft of replacing some of the ovirt-config-* scripts with python equivalents.
- [PATCH node] cleanup a couple small issues
- [PATCH node] cciss autoinstall fix