1#!/bin/sh
2# Copyright (C) 2008 Red Hat, Inc. All rights reserved.
3#
4# This copyrighted material is made available to anyone wishing to use,
5# modify, copy, or redistribute it subject to the terms and conditions
6# of the GNU General Public License v.2.
7#
8# You should have received a copy of the GNU General Public License
9# along with this program; if not, write to the Free Software Foundation,
10# Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
11
12test_description='Test pvcreate option values'
13PAGESIZE=$(getconf PAGESIZE)
14
15. ./test-utils.sh
16
17aux prepare_devs 4
18
19#COMM 'pvcreate rejects negative setphysicalvolumesize'
20not pvcreate --setphysicalvolumesize -1024 $dev1
21
22#COMM 'pvcreate rejects negative metadatasize'
23not pvcreate --metadatasize -1024 $dev1
24
25# x. metadatasize 0, defaults to 255
26# FIXME: unable to check default value, not in reporting cmds
27# should default to 255 according to code
28#   check_pv_field_ pv_mda_size 255
29#COMM 'pvcreate accepts metadatasize 0'
30pvcreate --metadatasize 0 $dev1
31pvremove $dev1
32
33#Verify vg_mda_size is smaller pv_mda_size
34pvcreate --metadatasize 512k $dev1
35pvcreate --metadatasize 96k $dev2
36vgcreate $vg $dev1 $dev2
37compare_two_fields_ vgs $vg vg_mda_size pvs $dev2 pv_mda_size
38vgremove -ff $vg
39
40# x. metadatasize too large
41# For some reason we allow this, even though there's no room for data?
42##COMM  'pvcreate rejects metadatasize too large'
43#not pvcreate --metadatasize 100000000000000 $dev1
44
45#COMM 'pvcreate rejects metadatacopies < 0'
46not pvcreate --metadatacopies -1 $dev1
47
48#COMM 'pvcreate accepts metadatacopies = 0, 1, 2'
49for j in metadatacopies pvmetadatacopies
50do
51pvcreate --$j 0 $dev1
52pvcreate --$j 1 $dev2
53pvcreate --$j 2 $dev3
54check_pv_field_ $dev1 pv_mda_count 0
55check_pv_field_ $dev2 pv_mda_count 1
56check_pv_field_ $dev3 pv_mda_count 2
57pvremove $dev1
58pvremove $dev2
59pvremove $dev3
60done
61
62#COMM 'pvcreate rejects metadatacopies > 2'
63not pvcreate --metadatacopies 3 $dev1
64
65#COMM 'pvcreate rejects invalid device'
66not pvcreate $dev1bogus
67
68#COMM 'pvcreate rejects labelsector < 0'
69not pvcreate --labelsector -1 $dev1
70
71#COMM 'pvcreate rejects labelsector > 1000000000000'
72not pvcreate --labelsector 1000000000000 $dev1
73
74# other possibilites based on code inspection (not sure how hard)
75# x. device too small (min of 512 * 1024 KB)
76# x. device filtered out
77# x. unable to open /dev/urandom RDONLY
78# x. device too large (pe_count > UINT32_MAX)
79# x. device read-only
80# x. unable to open device readonly
81# x. BLKGETSIZE64 fails
82# x. set size to value inconsistent with device / PE size
83
84#COMM 'pvcreate basic dataalignment sanity checks'
85not pvcreate --dataalignment -1 $dev1
86not pvcreate -M 1 --dataalignment 1 $dev1
87not pvcreate --dataalignment 1e $dev1
88
89#COMM 'pvcreate always rounded up to page size for start of device'
90#pvcreate --metadatacopies 0 --dataalignment 1 $dev1
91# amuse shell experts
92#check_pv_field_ $dev1 pe_start $(($(getconf PAGESIZE)/1024))".00k"
93
94#COMM 'pvcreate sets data offset directly'
95pvcreate --dataalignment 512k $dev1
96check_pv_field_ $dev1 pe_start 512.00k
97
98#COMM 'vgcreate/vgremove do not modify data offset of existing PV'
99vgcreate $vg $dev1  --config 'devices { data_alignment = 1024 }'
100check_pv_field_ $dev1 pe_start 512.00k
101vgremove $vg --config 'devices { data_alignment = 1024 }'
102check_pv_field_ $dev1 pe_start 512.00k
103
104#COMM 'pvcreate sets data offset next to mda area'
105pvcreate --metadatasize 100k --dataalignment 100k $dev1
106check_pv_field_ $dev1 pe_start 200.00k
107
108# metadata area start is aligned according to pagesize
109# pagesize should be 64k or 4k ...
110if [ $PAGESIZE -eq 65536 ] ; then
111	pv_align="192.50k"
112else
113	pv_align="133.00k"
114fi
115
116pvcreate --metadatasize 128k --dataalignment 3.5k $dev1
117check_pv_field_ $dev1 pe_start $pv_align
118
119pvcreate --metadatasize 128k --metadatacopies 2 --dataalignment 3.5k $dev1
120check_pv_field_ $dev1 pe_start $pv_align
121
122# data area is aligned to 64k by default,
123# data area start is shifted by the specified alignment_offset
124pv_align="195.50k"
125pvcreate --metadatasize 128k --dataalignmentoffset 7s $dev1
126check_pv_field_ $dev1 pe_start $pv_align
127
128# 2nd metadata area is created without problems when
129# data area start is shifted by the specified alignment_offset
130pvcreate --metadatasize 128k --metadatacopies 2 --dataalignmentoffset 7s $dev1
131check_pv_field_ $dev1 pv_mda_count 2
132# FIXME: compare start of 2nd mda with and without --dataalignmentoffset
133
134#COMM 'pv with LVM1 compatible data alignment can be convereted'
135#compatible == LVM1_PE_ALIGN == 64k
136pvcreate --dataalignment 256k $dev1
137vgcreate -s 1m $vg $dev1
138vgconvert -M1 $vg
139vgconvert -M2 $vg
140check_pv_field_ $dev1 pe_start 256.00k
141vgremove $vg
142
143#COMM 'pv with LVM1 incompatible data alignment cannot be convereted'
144pvcreate --dataalignment 10k $dev1
145vgcreate -s 1m $vg $dev1
146not vgconvert -M1 $vg
147vgremove $vg
148
149#COMM 'vgcfgrestore allows pe_start=0'
150#basically it produces nonsense, but it tests vgcfgrestore,
151#not that final cfg is usable...
152pvcreate --metadatacopies 0 $dev1
153pvcreate $dev2
154vgcreate $vg $dev1 $dev2
155vgcfgbackup -f "$(pwd)/backup.$$" $vg
156sed 's/pe_start = [0-9]*/pe_start = 0/' "$(pwd)/backup.$$" > "$(pwd)/backup.$$1"
157vgcfgrestore -f "$(pwd)/backup.$$1" $vg
158check_pv_field_ $dev1 pe_start 0
159check_pv_field_ $dev2 pe_start 0
160vgremove $vg
161