summaryrefslogtreecommitdiffstats
path: root/tests/include/mpath.sh
blob: 22a68f94bed3ed16484d0fd42fdefc07f50d158c (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
#!/bin/bash

# Copyright (c) 2016 Red Hat, Inc.
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program.  If not, see <http://www.gnu.org/licenses/>.

# Author: Lin Li   <lilin@redhat.com>


# filename: loop.sh

# USAGE

test x$LXT_MPATH = x || return
LXT_MPATH=1

#source /mnt/tests/kernel/storage/include/bash_modules/lxt/tc.sh

# make sure multipathd is running
get_mpath_disks()
{
    multipathd_running || texit "multipathd is not running" 
    multipathd -k'show maps' 2>/dev/null | grep '^mpath' | awk '{print
"/dev/mapper/" $1}'
    return 0
}

# make sure multipathd is running
get_wwid_of_disk()
{
# we should not use scsi_id or /dev/disk/by-id to get the wwid
# since multipath could replace the white spaces of wwid if 
# having white spaces. we should use 
# multipathd show paths format %w %d 
# to get the wwid

    for dev in `ls /dev/disk/by-id/*`
    do
        if readlink $dev | grep -qw "$disk$" 
        then
            wwid=$(basename $dev | sed 's/^[^-]*-//g')
            break
        fi
    done
    if test X$wwid = X
    then
        wwid=$(/lib/udev/scsi_id --page=0x83 --whitelisted --device=/dev/$disk)
    fi
    echo $wwid

#    multipathd_running || texit "multipathd is not running" 
#    local disk=$1
#    local wwid=$(multipathd show paths format %d,%w | grep "^$disk\s*," | \
#        awk -F, '{ print $2 }' | sed 's/\s//g')
#    echo $wwid
}


# make sure multipathd is running
get_mpath_disk_by_scsi_device()
{
#    multipathd_running || texit "multipathd is not running" 
    local disk=$1
    wwid=$(get_wwid_of_disk $disk)
    local mpath=$(multipathd show maps format %w,%n | grep "^$wwid\s*," \
        | awk -F, '{ print $2 }' | sed 's/\s//g')
    echo $mpath
}

# make sure multipathd is running
get_major_minor_by_scsi_device()
{
    multipathd_running || texit "multipathd is not running" 
    local disk=$1
    local mm=$(multipathd show paths format %d,%D | grep "^$disk\s*," | \
        awk -F, '{ print $2 }' | sed 's/\s//g')
    echo $mm
}

# make sure multipathd is running
get_hcil_by_scsi_device()
{
    multipathd_running || texit "multipathd is not running" 
    local disk=$1
    local hcil=$(multipathd show paths format %d,%i | grep "^$disk\s*," | \
        awk -F, '{ print $2 }' | sed 's/\s//g')
    echo $hcil
}

# make sure multipathd is running
is_mpath()
{
    multipathd_running || texit "multipathd is not running" 
    local mpath=$1
    multipathd show maps format %n | grep -w "^$mpath" &> /dev/null
}

multipathd_running()
{
    pidof multipathd &> /dev/null && return 0
    return 1
}

# will set find_multipaths no and start multipathd
setup_multipath()
{
    trun "rpm -q device-mapper-multipath || yum install -y device-mapper-multipath" || texit "fail to install multipath"
    test -f /etc/multipath.conf && cp /etc/multipath.conf /etc/multipath.conf.storage_qe 
    trun "mpathconf --enable --find_multipaths n --with_multipathd y" 
    trun "multipath -r"
}

get_unused_mpath()
{
    multipathd_running &>/dev/null || texit "multipathd is not running" 
    rootdisk=$(get_root_disk)
    rootmpath=$(get_mpath_disk_by_scsi_device $rootdisk)
    if is_null $rootmpath; then
        $maps=$(multipathd show maps format "%n" | grep -v name)
    else 
        $maps=$(multipathd show maps format "%n" | grep -v name | grep -v $rootmpath)
    fi
    
    echo $maps
}