xref: /dflybsd-src/contrib/lvm2/dist/test/t-lvextend-percent-extents.sh (revision 86d7f5d305c6adaa56ff4582ece9859d73106103)
186d7f5d3SJohn Marino#!/bin/sh
286d7f5d3SJohn Marino# Copyright (C) 2008 Red Hat, Inc. All rights reserved.
386d7f5d3SJohn Marino#
486d7f5d3SJohn Marino# This copyrighted material is made available to anyone wishing to use,
586d7f5d3SJohn Marino# modify, copy, or redistribute it subject to the terms and conditions
686d7f5d3SJohn Marino# of the GNU General Public License v.2.
786d7f5d3SJohn Marino#
886d7f5d3SJohn Marino# You should have received a copy of the GNU General Public License
986d7f5d3SJohn Marino# along with this program; if not, write to the Free Software Foundation,
1086d7f5d3SJohn Marino# Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
1186d7f5d3SJohn Marino
1286d7f5d3SJohn Marino# 'Check extents percentage arguments'
1386d7f5d3SJohn Marino
1486d7f5d3SJohn Marino. ./test-utils.sh
1586d7f5d3SJohn Marino
1686d7f5d3SJohn Marinoaux prepare_vg 2 128
1786d7f5d3SJohn Marino
1886d7f5d3SJohn Marinolvcreate -L 64m -n $lv $vg
1986d7f5d3SJohn Marino
2086d7f5d3SJohn Marino# 'lvextend rejects both size and extents without PVs'
2186d7f5d3SJohn Marinonot lvextend -l 10 -L 64m $vg/$lv 2>err
2286d7f5d3SJohn Marinogrep "^  Please specify either size or extents but not both.\$" err
2386d7f5d3SJohn Marino
2486d7f5d3SJohn Marino# 'lvextend rejects both size and extents with PVs'
2586d7f5d3SJohn Marinonot lvextend -l 10 -L 64m $vg/$lv $dev1 2>err
2686d7f5d3SJohn Marinogrep "^  Please specify either size or extents but not both.\$" err
2786d7f5d3SJohn Marino
2886d7f5d3SJohn Marino# 'lvextend accepts no size or extents but one PV - bz154691'
2986d7f5d3SJohn Marinolvextend $vg/$lv $dev1 >out
3086d7f5d3SJohn Marinogrep "^  Logical volume $lv successfully resized\$" out
3186d7f5d3SJohn Marinocheck_pv_field_ $dev1 pv_free "0"
3286d7f5d3SJohn Marino
3386d7f5d3SJohn Marinolvremove -f $vg/$lv
3486d7f5d3SJohn Marino
3586d7f5d3SJohn Marino# 'lvextend computes necessary free space correctly - bz213552'
3686d7f5d3SJohn Marinovgsize=$(vgs -o vg_extent_count --noheadings)
3786d7f5d3SJohn Marinolvcreate -l $vgsize  -n $lv $vg
3886d7f5d3SJohn Marinoyes | lvreduce -l $(( $vgsize / 2 )) $vg/$lv
3986d7f5d3SJohn Marinolvextend -l $vgsize $vg/$lv
4086d7f5d3SJohn Marino
4186d7f5d3SJohn Marino# 'Reset LV to original size'
4286d7f5d3SJohn Marinolvremove -f $vg/$lv
4386d7f5d3SJohn Marinolvcreate -L 64m -n $lv $vg
4486d7f5d3SJohn Marino
4586d7f5d3SJohn Marino# 'lvextend accepts no size but extents 100%PVS and two PVs - bz154691'
4686d7f5d3SJohn Marinolvextend -l +100%PVS $vg/$lv $dev1 $dev2 >out
4786d7f5d3SJohn Marinogrep "^  Logical volume $lv successfully resized\$" out
4886d7f5d3SJohn Marinocheck_pv_field_ $dev1 pv_free "0"
4986d7f5d3SJohn Marinocheck_pv_field_ $dev2 pv_free "0"
5086d7f5d3SJohn Marino
5186d7f5d3SJohn Marino# Exercise the range overlap code.  Allocate every 2 extents.
5286d7f5d3SJohn Marino#
5386d7f5d3SJohn Marino#      Physical Extents
5486d7f5d3SJohn Marino#          1         2
5586d7f5d3SJohn Marino#012345678901234567890123
5686d7f5d3SJohn Marino#
5786d7f5d3SJohn Marino#aaXXaaXXaaXXaaXXaaXXaaXX - (a)llocated
5886d7f5d3SJohn Marino#rrrXXXrrrXXXrrrXXXrrrXXX - (r)ange on cmdline
5986d7f5d3SJohn Marino#ooXXXXXXoXXXooXXXXXXoXXX - (o)verlap of range and allocated
6086d7f5d3SJohn Marino#
6186d7f5d3SJohn Marino# Key: a - allocated
6286d7f5d3SJohn Marino#      F - free
6386d7f5d3SJohn Marino#      r - part of a range on the cmdline
6486d7f5d3SJohn Marino#      N - not on cmdline
6586d7f5d3SJohn Marino#
6686d7f5d3SJohn Marino# Create the LV with 12 extents, allocated every other 2 extents.
6786d7f5d3SJohn Marino# Then extend it, with a range of PVs on the cmdline of every other 3 extents.
6886d7f5d3SJohn Marino# Total number of extents should be 12 + overlap = 12 + 6 = 18.
6986d7f5d3SJohn Marino# Thus, total size for the LV should be 18 * 4M = 72M
7086d7f5d3SJohn Marino#
7186d7f5d3SJohn Marino# 'Reset LV to 12 extents, allocate every other 2 extents'
7286d7f5d3SJohn Marinocreate_pvs=`for i in $(seq 0 4 20); do echo -n "\$dev1:$i-$(($i + 1)) "; done`
7386d7f5d3SJohn Marinolvremove -f $vg/$lv
7486d7f5d3SJohn Marinolvcreate -l 12 -n $lv $vg $create_pvs
7586d7f5d3SJohn Marinocheck_lv_field_ $vg/$lv lv_size "48.00m"
7686d7f5d3SJohn Marino
7786d7f5d3SJohn Marino# 'lvextend with partially allocated PVs and extents 100%PVS with PE ranges'
7886d7f5d3SJohn Marinoextend_pvs=`for i in $(seq 0 6 18); do echo -n "\$dev1:$i-$(($i + 2)) "; done`
7986d7f5d3SJohn Marinolvextend -l +100%PVS $vg/$lv $extend_pvs >out
8086d7f5d3SJohn Marinogrep "^  Logical volume $lv successfully resized\$" out
8186d7f5d3SJohn Marinocheck_lv_field_ $vg/$lv lv_size "72.00m"
8286d7f5d3SJohn Marino
8386d7f5d3SJohn Marino# Simple seg_count validation; initially create the LV with half the # of
8486d7f5d3SJohn Marino# extents (should be 1 lv segment), extend it (should go to 2 segments),
8586d7f5d3SJohn Marino# then reduce (should be back to 1)
8686d7f5d3SJohn Marino# FIXME: test other segment fields such as seg_size, pvseg_start, pvseg_size
8786d7f5d3SJohn Marinolvremove -f $vg/$lv
8886d7f5d3SJohn Marinope_count=$(pvs -o pv_pe_count --noheadings $dev1)
8986d7f5d3SJohn Marinope1=$(( $pe_count / 2 ))
9086d7f5d3SJohn Marinolvcreate -l $pe1 -n $lv $vg
9186d7f5d3SJohn Marinopesize=$(lvs -ovg_extent_size --units b --nosuffix --noheadings $vg/$lv)
9286d7f5d3SJohn Marinosegsize=$(( $pe1 * $pesize / 1024 / 1024 ))m
9386d7f5d3SJohn Marinocheck_lv_field_ $vg/$lv seg_count 1
9486d7f5d3SJohn Marinocheck_lv_field_ $vg/$lv seg_start 0
9586d7f5d3SJohn Marinocheck_lv_field_ $vg/$lv seg_start_pe 0
9686d7f5d3SJohn Marino#check_lv_field_ $vg/$lv seg_size $segsize
9786d7f5d3SJohn Marinolvextend -l +$(( $pe_count * 1 )) $vg/$lv
9886d7f5d3SJohn Marinocheck_lv_field_ $vg/$lv seg_count 2
9986d7f5d3SJohn Marinolvreduce -f -l -$(( $pe_count * 1 )) $vg/$lv
10086d7f5d3SJohn Marinocheck_lv_field_ $vg/$lv seg_count 1
10186d7f5d3SJohn Marino
102