lvm
lvm copied to clipboard
:resize action on physical volume doesn't work on unallocated pvs
Reproduce:
lvm_physical_volume "/dev/sdb" do action [:create, :resize] end
pe_count becomes 0, because the PE Size is zero until it is allocated.
This is what is breaking the code:
pe_size = pv_size / pv[0].pe_count
On a completely new/clean physical volume, the pe_count
is equal to '0'.
[root@default-centos-74 ~]# pvs /dev/sdb -o pv_all
Fmt PV UUID DevSize PV Maj Min PMdaFree PMdaSize PExtVsn 1st PE PSize PFree Used Attr Allocatable Exported Missing PE Alloc PV Tags #PMda #PMdaUse BA Start BA Size PInUse Duplicate
lvm2 zKdkF1-BEug-fikS-ucbM-5pUh-4E10-QfpYyO 2.00g /dev/sdb 8 16 0 1020.00k 2 1.00m 2.00g 2.00g 0 --- 0 0 1 1 0 0
[root@default-centos-74 ~]# pvdisplay /dev/sdb
"/dev/sdb" is a new physical volume of "2.00 GiB"
--- NEW Physical volume ---
PV Name /dev/sdb
VG Name
PV Size 2.00 GiB
Allocatable NO
PE Size 0
Total PE 0
Free PE 0
Allocated PE 0
PV UUID zKdkF1-BEug-fikS-ucbM-5pUh-4E10-QfpYyO
I would submit a fix but I am not 100% sure what this block of code is trying to achieve:
# get the size the OS says the block device is
block_device_raw_size = pv[0].dev_size.to_i
# get the size LVM thinks the PV is
pv_size = pv[0].size.to_i
pe_size = pv_size / pv[0].pe_count
# get the amount of space that cannot be allocated
non_allocatable_space = block_device_raw_size % pe_size
# if it's an exact amount LVM appears to just take 1 full extent
non_allocatable_space = pe_size if non_allocatable_space == 0
block_device_allocatable_size = block_device_raw_size - non_allocatable_space
# only resize if they are not same
if pv_size != block_device_allocatable_size
I might be missing something, but couldn't this entire section be replaced by:
dev_size = pv[0].dev_size.to_i
pv_size = pv[0].size.to_i
if pv_size != dev_size
For those curious this is my workaround:
lvm_physical_volume '/dev/sdb' do
if `pvs /dev/sdb -o pv_pe_count --noheadings | sed 's/ //g\` != 0
action :resize
else
action :create
end
end
With the version 13+ of the chef-client you should make sure to use full paths in my workaround, otherwise it won't work because it can't find the commands.
lvm_physical_volume '/dev/sdb' do
if `/usr/sbin/pvs /dev/sdb -o pv_pe_count --noheadings | sed 's/ //g\` != 0
action :resize
else
action :create
end
end
Please see this issue for more details: #167