summaryrefslogtreecommitdiffstats
path: root/tests/kpartx_4k_aligned/main.sh
blob: 530637a012ca9637ec15ca806c34fdb801811cbf (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
#!/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>

source ../include/ec.sh || exit 200

function gpt_partitioned_dev() {
    local dev=$1
    { for i in {1..4}; do
        echo -e "n\n\n\n+1M\n\n"
    done; echo w; echo y; } | gdisk $dev &> /dev/null
}

function extract_section_info_from_gdisk() {
    local dev=$1
    local node=$(basename $dev)
    gdisk -l $dev | awk -v dev=$node 'start==1{print dev $1,$2,$3};/Number/{start=1}'
}

function extract_section_info_from_kpartx() {
    local dev=$1
    kpartx -l $dev | awk '{ print $1, $NF, $NF+$4-1 }'
}

tlog "running $0"

rpm -q device-mapper-multipath || yum install -y device-mapper-multipath
rpm -q gdisk || yum install -y gdisk

# eliminate the possibility multipathd create device for new path
trun "service multipathd stop"

# create a device with 4k physical sector
trun "modprobe -r scsi_debug"
trun "modprobe scsi_debug sector_size=512 physblk_exp=3 &> /dev/null"

scsi_debug_dev=$(get_scsi_debug_devices)

trun "gpt_partitioned_dev $scsi_debug_dev"
sleep 3

trun "extract_section_info_from_gdisk $scsi_debug_dev"
result_of_gdisk=$tSTDOUT
trun "extract_section_info_from_kpartx $scsi_debug_dev"
result_of_kpartx=$tSTDOUT

tlog "result_of_kpartx=$result_of_kpartx"
tlog "result_of_gdisk=$result_of_gdisk"
tok '[[ "$result_of_kpartx" == "$result_of_gdisk" ]]'

sleep 3
trun "modprobe -r scsi_debug"

tend