Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

:resize action on physical volume doesn't work on unallocated pvs #39

Open
klarna-marcus-nilsson opened this issue Oct 17, 2014 · 3 comments

Comments

@klarna-marcus-nilsson
Copy link

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.

@tas50 tas50 added the Type: Bug label Jan 4, 2017
@rolffujino
Copy link

rolffujino commented Oct 2, 2018

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

@rolffujino
Copy link

rolffujino commented Mar 1, 2019

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

@rolffujino
Copy link

rolffujino commented Oct 19, 2019

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants