2017-07-02 22:38:32 +03:00
#!/usr/bin/env bash
2008-10-06 20:47:07 +04:00
# Copyright (C) 2008 Red Hat, Inc. All rights reserved.
2008-07-17 01:32:38 +04:00
#
# This copyrighted material is made available to anyone wishing to use,
# modify, copy, or redistribute it subject to the terms and conditions
# of the GNU General Public License v.2.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software Foundation,
2016-01-21 13:49:46 +03:00
# Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
2008-07-17 01:32:38 +04:00
test_description = 'Test pvcreate option values'
2018-05-24 17:49:48 +03:00
2015-10-27 17:10:06 +03:00
SKIP_WITH_LVMPOLLD = 1
2009-06-06 20:40:39 +04:00
PAGESIZE = $( getconf PAGESIZE)
2015-10-30 12:02:00 +03:00
# MDA_SIZE_MIN defined in lib/format_text/layout.h
2017-07-06 20:27:04 +03:00
MDA_SIZE_MIN = $(( 8 * PAGESIZE ))
2008-07-17 01:32:38 +04:00
2014-06-06 19:40:04 +04:00
. lib/inittest
2008-07-17 01:32:38 +04:00
2008-10-06 20:47:07 +04:00
aux prepare_devs 4
2008-07-17 01:32:38 +04:00
2008-10-06 20:47:07 +04:00
#COMM 'pvcreate rejects negative setphysicalvolumesize'
2012-03-16 17:00:05 +04:00
not pvcreate --setphysicalvolumesize -1024 " $dev1 "
2008-07-17 01:32:38 +04:00
2008-10-06 20:47:07 +04:00
#COMM 'pvcreate rejects negative metadatasize'
2012-03-16 17:00:05 +04:00
not pvcreate --metadatasize -1024 " $dev1 "
2008-07-17 01:32:38 +04:00
2015-10-30 12:02:00 +03:00
#COMM 'pvcreate rejects metadatasize that is less than minimum size'
2017-07-06 20:27:04 +03:00
not pvcreate --dataalignment $(( MDA_SIZE_MIN / 2 )) b --metadatasize $(( MDA_SIZE_MIN / 2 )) b " $dev1 " 2>err
2015-10-30 12:02:00 +03:00
grep "Metadata area size too small" err
#COMM 'pvcreate accepts metadatasize that is at least the minimum size'
pvcreate --dataalignment ${ MDA_SIZE_MIN } b --metadatasize ${ MDA_SIZE_MIN } b " $dev1 "
2009-05-08 10:10:45 +04:00
#Verify vg_mda_size is smaller pv_mda_size
2012-03-16 17:00:05 +04:00
pvcreate --metadatasize 512k " $dev1 "
pvcreate --metadatasize 96k " $dev2 "
2018-05-24 17:49:48 +03:00
vgcreate $SHARED $vg " $dev1 " " $dev2 "
2013-11-18 00:04:07 +04:00
pvs -o +pv_mda_size
2012-03-16 17:00:05 +04:00
check compare_fields vgs $vg vg_mda_size pvs " $dev2 " pv_mda_size
vgremove $vg
2009-05-08 10:10:45 +04:00
2008-07-17 01:32:38 +04:00
# x. metadatasize too large
# For some reason we allow this, even though there's no room for data?
2008-10-06 20:47:07 +04:00
##COMM 'pvcreate rejects metadatasize too large'
2012-03-16 17:00:05 +04:00
#not pvcreate --metadatasize 100000000000000 "$dev1"
2008-07-17 01:32:38 +04:00
2008-10-06 20:47:07 +04:00
#COMM 'pvcreate rejects metadatacopies < 0'
2012-03-16 17:00:05 +04:00
not pvcreate --metadatacopies -1 " $dev1 "
2008-07-17 01:32:38 +04:00
2008-10-06 20:47:07 +04:00
#COMM 'pvcreate accepts metadatacopies = 0, 1, 2'
2009-10-06 00:55:56 +04:00
for j in metadatacopies pvmetadatacopies
do
2012-03-16 17:00:05 +04:00
pvcreate --$j 0 " $dev1 "
pvcreate --$j 1 " $dev2 "
pvcreate --$j 2 " $dev3 "
check pv_field " $dev1 " pv_mda_count 0
check pv_field " $dev2 " pv_mda_count 1
check pv_field " $dev3 " pv_mda_count 2
pvremove " $dev1 " " $dev2 " " $dev3 "
2009-10-06 00:55:56 +04:00
done
2008-07-17 01:32:38 +04:00
2008-10-06 20:47:07 +04:00
#COMM 'pvcreate rejects metadatacopies > 2'
2012-03-16 17:00:05 +04:00
not pvcreate --metadatacopies 3 " $dev1 "
2008-07-17 01:32:38 +04:00
2008-10-06 20:47:07 +04:00
#COMM 'pvcreate rejects invalid device'
2012-03-16 17:00:05 +04:00
not pvcreate " $dev1 " bogus
2008-07-17 01:32:38 +04:00
2008-10-06 20:47:07 +04:00
#COMM 'pvcreate rejects labelsector < 0'
2012-03-16 17:00:05 +04:00
not pvcreate --labelsector -1 " $dev1 "
2008-07-17 01:32:38 +04:00
2008-10-06 20:47:07 +04:00
#COMM 'pvcreate rejects labelsector > 1000000000000'
2012-03-16 17:00:05 +04:00
not pvcreate --labelsector 1000000000000 " $dev1 "
2008-07-17 01:32:38 +04:00
2024-08-30 13:10:35 +03:00
# other possibilities based on code inspection (not sure how hard)
2008-07-17 01:32:38 +04:00
# x. device too small (min of 512 * 1024 KB)
# x. device filtered out
# x. unable to open /dev/urandom RDONLY
# x. device too large (pe_count > UINT32_MAX)
# x. device read-only
# x. unable to open device readonly
# x. BLKGETSIZE64 fails
# x. set size to value inconsistent with device / PE size
2009-02-22 22:00:26 +03:00
#COMM 'pvcreate basic dataalignment sanity checks'
2012-03-16 17:00:05 +04:00
not pvcreate --dataalignment -1 " $dev1 "
not pvcreate --dataalignment 1e " $dev1 "
2009-02-22 22:00:26 +03:00
#COMM 'pvcreate always rounded up to page size for start of device'
2012-03-16 17:00:05 +04:00
#pvcreate --metadatacopies 0 --dataalignment 1 "$dev1"
2009-02-22 22:00:26 +03:00
# amuse shell experts
2012-03-16 17:00:05 +04:00
#check pv_field "$dev1" pe_start $(($(getconf PAGESIZE)/1024))".00k"
2009-02-22 22:00:26 +03:00
Place the first PE at 1 MiB for all defaults
. When using default settings, this commit should change
nothing. The first PE continues to be placed at 1 MiB
resulting in a metadata area size of 1020 KiB (for
4K page sizes; slightly smaller for larger page sizes.)
. When default_data_alignment is disabled in lvm.conf,
align pe_start at 1 MiB, based on a default metadata area
size that adapts to the page size. Previously, disabling
this option would result in mda_size that was too small
for common use, and produced a 64 KiB aligned pe_start.
. Customized pe_start and mda_size values continue to be
set as before in lvm.conf and command line.
. Remove the configure option for setting default_data_alignment
at build time.
. Improve alignment related option descriptions.
. Add section about alignment to pvcreate man page.
Previously, DEFAULT_PVMETADATASIZE was 255 sectors.
However, the fact that the config setting named
"default_data_alignment" has a default value of 1 (MiB)
meant that DEFAULT_PVMETADATASIZE was having no effect.
The metadata area size is the space between the start of
the metadata area (page size offset from the start of the
device) and the first PE (1 MiB by default due to
default_data_alignment 1.) The result is a 1020 KiB metadata
area on machines with 4KiB page size (1024 KiB - 4 KiB),
and smaller on machines with larger page size.
If default_data_alignment was set to 0 (disabled), then
DEFAULT_PVMETADATASIZE 255 would take effect, and produce a
metadata area that was 188 KiB and pe_start of 192 KiB.
This was too small for common use.
This is fixed by making the default metadata area size a
computed value that matches the value produced by
default_data_alignment.
2018-11-14 00:00:11 +03:00
#COMM 'pvcreate sets data alignment directly'
pvcreate --dataalignment 512K --config 'metadata {pvmetadatasize=255}' " $dev1 "
2012-03-16 17:00:05 +04:00
check pv_field " $dev1 " pe_start "512.00k"
2009-02-22 22:00:26 +03:00
Place the first PE at 1 MiB for all defaults
. When using default settings, this commit should change
nothing. The first PE continues to be placed at 1 MiB
resulting in a metadata area size of 1020 KiB (for
4K page sizes; slightly smaller for larger page sizes.)
. When default_data_alignment is disabled in lvm.conf,
align pe_start at 1 MiB, based on a default metadata area
size that adapts to the page size. Previously, disabling
this option would result in mda_size that was too small
for common use, and produced a 64 KiB aligned pe_start.
. Customized pe_start and mda_size values continue to be
set as before in lvm.conf and command line.
. Remove the configure option for setting default_data_alignment
at build time.
. Improve alignment related option descriptions.
. Add section about alignment to pvcreate man page.
Previously, DEFAULT_PVMETADATASIZE was 255 sectors.
However, the fact that the config setting named
"default_data_alignment" has a default value of 1 (MiB)
meant that DEFAULT_PVMETADATASIZE was having no effect.
The metadata area size is the space between the start of
the metadata area (page size offset from the start of the
device) and the first PE (1 MiB by default due to
default_data_alignment 1.) The result is a 1020 KiB metadata
area on machines with 4KiB page size (1024 KiB - 4 KiB),
and smaller on machines with larger page size.
If default_data_alignment was set to 0 (disabled), then
DEFAULT_PVMETADATASIZE 255 would take effect, and produce a
metadata area that was 188 KiB and pe_start of 192 KiB.
This was too small for common use.
This is fixed by making the default metadata area size a
computed value that matches the value produced by
default_data_alignment.
2018-11-14 00:00:11 +03:00
#COMM 'vgcreate/vgremove do not modify data offset of existing PV'
2018-05-24 17:49:48 +03:00
vgcreate $SHARED $vg " $dev1 " --config 'devices { data_alignment = 1024 }'
2012-03-16 17:00:05 +04:00
check pv_field " $dev1 " pe_start "512.00k"
2009-02-22 22:00:26 +03:00
vgremove $vg --config 'devices { data_alignment = 1024 }'
2012-03-16 17:00:05 +04:00
check pv_field " $dev1 " pe_start "512.00k"
2009-02-22 22:00:26 +03:00
#COMM 'pvcreate sets data offset next to mda area'
2012-03-16 17:00:05 +04:00
pvcreate --metadatasize 100k --dataalignment 100k " $dev1 "
check pv_field " $dev1 " pe_start "200.00k"
2009-02-22 22:00:26 +03:00
2009-06-06 20:40:39 +04:00
# metadata area start is aligned according to pagesize
2012-03-16 17:00:05 +04:00
case " $PAGESIZE " in
65536) pv_align = "192.50k" ; ;
8192) pv_align = "136.50k" ; ;
*) pv_align = "133.00k" ; ;
esac
2009-06-06 20:40:39 +04:00
Place the first PE at 1 MiB for all defaults
. When using default settings, this commit should change
nothing. The first PE continues to be placed at 1 MiB
resulting in a metadata area size of 1020 KiB (for
4K page sizes; slightly smaller for larger page sizes.)
. When default_data_alignment is disabled in lvm.conf,
align pe_start at 1 MiB, based on a default metadata area
size that adapts to the page size. Previously, disabling
this option would result in mda_size that was too small
for common use, and produced a 64 KiB aligned pe_start.
. Customized pe_start and mda_size values continue to be
set as before in lvm.conf and command line.
. Remove the configure option for setting default_data_alignment
at build time.
. Improve alignment related option descriptions.
. Add section about alignment to pvcreate man page.
Previously, DEFAULT_PVMETADATASIZE was 255 sectors.
However, the fact that the config setting named
"default_data_alignment" has a default value of 1 (MiB)
meant that DEFAULT_PVMETADATASIZE was having no effect.
The metadata area size is the space between the start of
the metadata area (page size offset from the start of the
device) and the first PE (1 MiB by default due to
default_data_alignment 1.) The result is a 1020 KiB metadata
area on machines with 4KiB page size (1024 KiB - 4 KiB),
and smaller on machines with larger page size.
If default_data_alignment was set to 0 (disabled), then
DEFAULT_PVMETADATASIZE 255 would take effect, and produce a
metadata area that was 188 KiB and pe_start of 192 KiB.
This was too small for common use.
This is fixed by making the default metadata area size a
computed value that matches the value produced by
default_data_alignment.
2018-11-14 00:00:11 +03:00
# pe_start is a multiple of dataalignment, leaving enough
# space between mda_start and pe_end for the specified
# metadata size.
#
# With page size 4k, mda_start is rounded up start at 4k.
# The chosen multiple of data alignment (3.5k) is 38:
# 3.5k * 38 = 133k for pe_start
# Space available for metadata between mda_start and pe_end is:
# 133k - 4k = 129k mda size, which is large enough for the
# specified mda size of 128k.
#
# With page size 8k, mda_start is rouned up to start at 8k.
# The chosen multiple of data alignment (3.5k) is 39:
# 3.5k * 39 = 136.5k for pe_start
# Space available for metadata between mda_start and pe_end is:
# 136.5k - 8k = 128.5k mda size, which is large enough for the
# specified mda size of 128k.
#
# With page size 64k, mda_start is rouned up to start at 64k.
# The chosen multiple of data alignment (3.5k) is 55:
# 3.5k * 55 = 192.5k for pe_start
# Space available for metadata between mda_start and pe_end is:
# 192.5k - 64k = 128.5k mda size, which is large enough for the
# specified mda size of 128k.
2012-03-16 17:00:05 +04:00
pvcreate --metadatasize 128k --dataalignment 3.5k " $dev1 "
check pv_field " $dev1 " pe_start $pv_align
2009-05-07 16:11:50 +04:00
2012-03-16 17:00:05 +04:00
pvcreate --metadatasize 128k --metadatacopies 2 --dataalignment 3.5k " $dev1 "
check pv_field " $dev1 " pe_start $pv_align
2009-05-07 16:11:50 +04:00
2010-08-12 08:11:48 +04:00
# data area is aligned to 1M by default,
2009-08-04 20:02:39 +04:00
# data area start is shifted by the specified alignment_offset
2012-03-16 17:00:05 +04:00
pv_align = 1052160B # 1048576 + (7*512)
pvcreate --metadatasize 128k --dataalignmentoffset 7s " $dev1 "
check pv_field " $dev1 " pe_start $pv_align --units b
2009-08-04 20:02:39 +04:00
# 2nd metadata area is created without problems when
# data area start is shifted by the specified alignment_offset
2012-03-16 17:00:05 +04:00
pvcreate --metadatasize 128k --metadatacopies 2 --dataalignmentoffset 7s " $dev1 "
check pv_field " $dev1 " pv_mda_count 2
2009-08-04 20:02:39 +04:00
# FIXME: compare start of 2nd mda with and without --dataalignmentoffset
2009-02-22 22:00:26 +03:00
#COMM 'vgcfgrestore allows pe_start=0'
#basically it produces nonsense, but it tests vgcfgrestore,
#not that final cfg is usable...
2012-03-16 17:00:05 +04:00
pvcreate --metadatacopies 0 " $dev1 "
pvcreate " $dev2 "
2018-05-24 17:49:48 +03:00
vgcreate $SHARED $vg " $dev1 " " $dev2 "
2012-03-16 17:00:05 +04:00
vgcfgbackup -f backup.$$ $vg
sed 's/pe_start = [0-9]*/pe_start = 0/' backup.$$ > backup.$$ 1
vgcfgrestore -f backup.$$ 1 $vg
check pv_field " $dev1 " pe_start "0"
check pv_field " $dev2 " pe_start "0"
2009-02-22 22:00:26 +03:00
vgremove $vg
2010-06-30 16:17:55 +04:00
2012-03-16 17:00:05 +04:00
echo "test pvcreate --metadataignore"
2010-06-30 16:17:55 +04:00
for pv_in_vg in 1 0; do
for mdacp in 1 2; do
for ignore in y n; do
2012-03-16 17:00:05 +04:00
echo "pvcreate --metadataignore has proper mda_count and mda_used_count"
pvcreate --metadatacopies $mdacp --metadataignore $ignore " $dev1 " " $dev2 "
check pv_field " $dev1 " pv_mda_count " $mdacp "
check pv_field " $dev2 " pv_mda_count " $mdacp "
2010-06-30 16:17:55 +04:00
if [ $ignore = y ] ; then
2012-03-16 17:00:05 +04:00
check pv_field " $dev1 " pv_mda_used_count "0"
check pv_field " $dev2 " pv_mda_used_count "0"
2010-06-30 16:17:55 +04:00
else
2012-03-16 17:00:05 +04:00
check pv_field " $dev1 " pv_mda_used_count " $mdacp "
check pv_field " $dev2 " pv_mda_used_count " $mdacp "
2010-06-30 16:17:55 +04:00
fi
2018-05-24 17:49:48 +03:00
echo " vgcreate $SHARED has proper vg_mda_count and vg_mda_used_count "
2010-06-30 16:17:55 +04:00
if [ $pv_in_vg = 1 ] ; then
2018-05-24 17:49:48 +03:00
vgcreate $SHARED $vg " $dev1 " " $dev2 "
2017-07-06 20:27:04 +03:00
check vg_field $vg vg_mda_count $(( mdacp * 2 ))
2010-06-30 16:17:55 +04:00
if [ $ignore = y ] ; then
2012-03-16 17:00:05 +04:00
check vg_field $vg vg_mda_used_count "1"
2010-06-30 16:17:55 +04:00
else
2017-07-06 20:27:04 +03:00
check vg_field $vg vg_mda_used_count " $(( mdacp * 2 )) "
2010-06-30 16:17:55 +04:00
fi
2012-03-16 17:00:05 +04:00
check vg_field $vg vg_mda_copies "unmanaged"
2010-06-30 16:17:55 +04:00
vgremove $vg
fi
done
done
done