RHEL Engineering is moving the tracking of its product development work on RHEL 6 through RHEL 9 to Red Hat Jira (issues.redhat.com). If you're a Red Hat customer, please continue to file support cases via the Red Hat customer portal. If you're not, please head to the "RHEL project" in Red Hat Jira and file new tickets here. Individual Bugzilla bugs in the statuses "NEW", "ASSIGNED", and "POST" are being migrated throughout September 2023. Bugs of Red Hat partners with an assigned Engineering Partner Manager (EPM) are migrated in late September as per pre-agreed dates. Bugs against components "kernel", "kernel-rt", and "kpatch" are only migrated if still in "NEW" or "ASSIGNED". If you cannot log in to RH Jira, please consult article #7032570. That failing, please send an e-mail to the RH Jira admins at rh-issues@redhat.com to troubleshoot your issue as a user management inquiry. The email creates a ServiceNow ticket with Red Hat. Individual Bugzilla bugs that are migrated will be moved to status "CLOSED", resolution "MIGRATED", and set with "MigratedToJIRA" in "Keywords". The link to the successor Jira issue will be found under "Links", have a little "two-footprint" icon next to it, and direct you to the "RHEL project" in Red Hat Jira (issue links are of type "https://issues.redhat.com/browse/RHEL-XXXX", where "X" is a digit). This same link will be available in a blue banner at the top of the page informing you that that bug has been migrated.
Bug 1269533 - lvcreate with %FREE/%VG option should not fail when creating mirrors
Summary: lvcreate with %FREE/%VG option should not fail when creating mirrors
Keywords:
Status: CLOSED ERRATA
Alias: None
Product: Red Hat Enterprise Linux 7
Classification: Red Hat
Component: lvm2
Version: 7.2
Hardware: x86_64
OS: Linux
unspecified
low
Target Milestone: rc
: ---
Assignee: Heinz Mauelshagen
QA Contact: cluster-qe@redhat.com
URL:
Whiteboard:
Depends On:
Blocks: 1469559
TreeView+ depends on / blocked
 
Reported: 2015-10-07 14:01 UTC by Roman Bednář
Modified: 2021-09-03 12:37 UTC (History)
12 users (show)

Fixed In Version: lvm2-2.02.175-2.el7
Doc Type: If docs needed, set a value
Doc Text:
Clone Of:
Environment:
Last Closed: 2018-04-10 15:16:02 UTC
Target Upstream Version:
Embargoed:


Attachments (Terms of Use)
verbose lvcreate attempt (45.03 KB, text/plain)
2016-09-28 14:47 UTC, Corey Marthaler
no flags Details


Links
System ID Private Priority Status Summary Last Updated
Red Hat Product Errata RHEA-2018:0853 0 None None None 2018-04-10 15:17:48 UTC

Description Roman Bednář 2015-10-07 14:01:10 UTC
Description of problem:
When a user tries to create a mirrored LV where the number of needed PEs exceeds the limit of available PEs in a VG, and a number of legs is other than 3 or 4 the command fails.


Version-Release number of selected component (if applicable):
lvm2-2.02.130-2.el7.x86_64

How reproducible:
always

Steps to Reproduce:
1. vgcreate /dev/sda vg
2. lvcreate -n lv_test --type mirror -m 1 -l60%FREE vg

Actual results:
Error:
"Insufficient free space for log allocation for logical volume .
 Unable to allocate extents for mirror log."

Expected results:
the requested LV size should be treated as an approximate upper limit for the total number of physical extents
to be allocated (including extents used by any mirrors). Meaning it should be rounded down as needed
to "fit" into vg.


Example: 
lvcreate -n lv_test --type mirror -m 3 -l60%FREE vg
Succeeds.

Example:
lvcreate -n lv_test --type mirror -m 1 -l60%FREE vg
Should round the LV size to highest limit possible. Actual result would be ~50% for LV available to user.

Additional info:
The expected behaviour is already applied and working with 3 and 4 mirrors (-m 3/-m 4)

Comment 2 Heinz Mauelshagen 2016-05-17 13:28:25 UTC
Solved in upstream

Comment 7 Corey Marthaler 2016-09-28 14:47:00 UTC
Created attachment 1205500 [details]
verbose lvcreate attempt

3.10.0-510.el7.x86_64
lvm2-2.02.165-4.el7    BUILT: Thu Sep 22 01:47:19 CDT 2016
lvm2-libs-2.02.165-4.el7    BUILT: Thu Sep 22 01:47:19 CDT 2016
lvm2-cluster-2.02.165-4.el7    BUILT: Thu Sep 22 01:47:19 CDT 2016
device-mapper-1.02.134-4.el7    BUILT: Thu Sep 22 01:47:19 CDT 2016
device-mapper-libs-1.02.134-4.el7    BUILT: Thu Sep 22 01:47:19 CDT 2016
device-mapper-event-1.02.134-4.el7    BUILT: Thu Sep 22 01:47:19 CDT 2016
device-mapper-event-libs-1.02.134-4.el7    BUILT: Thu Sep 22 01:47:19 CDT 2016
device-mapper-persistent-data-0.6.3-1.el7    BUILT: Fri Jul 22 05:29:13 CDT 2016



[root@host-116 ~]# pvscan
  PV /dev/sda1   VG vg              lvm2 [9.99 GiB / 9.99 GiB free]
  PV /dev/sdb1   VG vg              lvm2 [9.99 GiB / 9.99 GiB free]
  PV /dev/sdc1   VG vg              lvm2 [9.99 GiB / 9.99 GiB free]
  PV /dev/sdd1   VG vg              lvm2 [9.99 GiB / 9.99 GiB free]
  PV /dev/sde1   VG vg              lvm2 [9.99 GiB / 9.99 GiB free]
  PV /dev/sdf1   VG vg              lvm2 [9.99 GiB / 9.99 GiB free]
  PV /dev/sdg1   VG vg              lvm2 [9.99 GiB / 9.99 GiB free]
  PV /dev/sdh1   VG vg              lvm2 [9.99 GiB / 9.99 GiB free]

[root@host-116 ~]# vgs
  VG            #PV #LV #SN Attr   VSize  VFree 
  vg              8   0   0 wz--n- 79.94g 79.94g

[root@host-116 ~]# lvcreate --type raid1 -m 1 -l50%FREE vg
  Logical volume "lvol0" created.
[root@host-116 ~]# lvremove -y vg/lvol0
  Logical volume "lvol0" successfully removed
[root@host-116 ~]# lvcreate --type mirror -m 1 -l50%FREE vg
  Insufficient free space for log allocation for logical volume .
  Unable to allocate extents for mirror log.

[root@host-116 ~]# lvcreate --type mirror -m 3 -l60%FREE vg
  Insufficient free space for log allocation for logical volume .
  Unable to allocate extents for mirror log.

# This one actually worked for me
[root@host-116 ~]# lvcreate --type mirror -m 4 -l60%FREE vg
  Logical volume "lvol0" created.

[root@host-116 ~]# lvs -a -o +devices
 LV               VG  Attr       LSize Log          Cpy%Sync Devices
 lvol0            vg  mwi-a-m--- 9.99g [lvol0_mlog] 24.28    lvol0_mimage_0(0),lvol0_mimage_1(0),lvol0_mimage_2(0),lvol0_mimage_3(0),lvol0_mimage_4(0)
 [lvol0_mimage_0] vg  Iwi-aom--- 9.99g                       /dev/sda1(0)
 [lvol0_mimage_1] vg  Iwi-aom--- 9.99g                       /dev/sdb1(0)
 [lvol0_mimage_2] vg  Iwi-aom--- 9.99g                       /dev/sdc1(0)
 [lvol0_mimage_3] vg  Iwi-aom--- 9.99g                       /dev/sdd1(0)
 [lvol0_mimage_4] vg  Iwi-aom--- 9.99g                       /dev/sde1(0)
 [lvol0_mlog]     vg  lwi-aom--- 4.00m                       /dev/sdh1(0)

Comment 9 Alasdair Kergon 2016-09-28 15:11:42 UTC
So the problem is that it is allocating the log separately afterwards, and this only works if there was a remainder when the number of free extents was divided by the number of legs.

Fix is either to do the allocation all in one go, or to require the first allocation to leave a certain amount of space free.

Comment 11 Alasdair Kergon 2017-05-12 01:36:25 UTC
There are a few related problems in this code.
Cases that lead to Internal errors (if the percentage calculation leads to zero).
Mix-ups between physical extents and logical extents that already got fixed for lvresize but not for lvcreate.

First patch:

https://www.redhat.com/archives/lvm-devel/2017-May/msg00042.html

https://sourceware.org/git/?p=lvm2.git;a=commitdiff;h=cf73f6cf61793e9d71391bb7a8f35162509898a4

commit cf73f6cf61793e9d71391bb7a8f35162509898a4
Author: Alasdair G Kergon <agk>
Date:   Fri May 12 02:04:05 2017 +0100

    lvcreate: Fix mirror percentage size calculations.
    
    Trap cases where the percentage calculation currently leads to an empty
    LV and the message:
    
      Internal error: Unable to create new logical volume with no extents
    
    Additionally convert the calculated number of extents from physical to
    logical when creating a mirror using a percentage that is based on
    Physical Extents.  Otherwise a command like 'lvcreate -m3 -l80%FREE'
    can never leave any free space.
    
    This brings the behaviour closer to that of lvresize.
    (A further patch is needed to cover all the raid types.)

Comment 12 Alasdair Kergon 2017-05-12 01:40:54 UTC
If the VG has no free space in it:

Old:

# lvcreate -l100%FREE vg0 -m4
  Internal error: Unable to create new logical volume with no extents.

New 

# lvcreate -l100%FREE vg0 -m4
  Calculated size of logical volume is 0 extents. Needs to be larger.

Comment 13 Alasdair Kergon 2017-05-12 01:42:24 UTC
lvcreate -l50%FREE with a mirror should now use up 50% of the free space (instead of using all of it), in the same way that lvresize -l+50%FREE does.

Comment 14 Heinz Mauelshagen 2017-05-12 14:49:39 UTC
Because "mirror" allocates the log on a seperate PV but RAID doesn't with its rmeta devices, we got the following correct but odd looking layout allocating -l50%FREE on even number (e.g.) 4 PVs:

# lvs -aoname,size,attr,segtype,segperanges p
  LV           LSize Attr       Type   PE Ranges                          
  r            8.00g Mwi-a-m--- mirror r_mimage_0:0-2046 r_mimage_1:0-2046
  [r_mimage_0] 8.00g iwi-aom--- linear /dev/sda:0-2046                    
  [r_mimage_1] 8.00g iwi-aom--- linear /dev/sdb:0-2046                    
  [r_mlog]     4.00m lwi-aom--- linear /dev/sdd:0-0

# lvs -aoname,size,attr,segtype,segperanges p
  LV           LSize Attr       Type   PE Ranges                          
  r            8.00g Rwi-a-r--- raid1  r_rimage_0:0-2046 r_rimage_1:0-2046
  [r_rimage_0] 8.00g iwi-aor--- linear /dev/sda:1-2046                    
  [r_rimage_0] 8.00g iwi-aor--- linear /dev/sdc:0-0                       
  [r_rimage_1] 8.00g iwi-aor--- linear /dev/sdb:1-2046                    
  [r_rimage_1] 8.00g iwi-aor--- linear /dev/sdd:0-0                       
  [r_rmeta_0]  4.00m ewi-aor--- linear /dev/sda:0-0                       
  [r_rmeta_1]  4.00m ewi-aor--- linear /dev/sdb:0-0

Comment 27 Roman Bednář 2017-10-23 11:47:10 UTC
Marking verified with latest rpms, this BZ seems to incorporate more fixes and behaviour changes. I'll try to summarize those (hopefully all of them) below.

1) creating a mirror when a vg has no free space left:

BEFORE FIX:
# lvcreate -l100%FREE vg -m4
  Internal error: Unable to create new logical volume with no extents.


AFTER FIX:
# lvcreate -l100%FREE vg -m4
  Calculated size of logical volume is 0 extents. Needs to be larger.


2) %FREE option now represents total allocation space (including possible mirrors)

BEFORE FIX:
# vgs vg -o vg_name,free
  VG VFree 
  vg 89.95g

# lvcreate -l50%FREE -m 2 vg
  Logical volume "lvol0" created.

# vgs vg -o vg_name,free
  VG VFree
  vg    0 


AFTER FIX:
# vgs vg -o vg_name,free
  VG VFree 
  vg 89.96g

# lvcreate -l50%FREE -m 2 vg
  Logical volume "lvol0" created.

# vgs vg -o vg_name,free
  VG VFree  
  vg <44.98g

3) mirror log allocation:

BEFORE FIX:
# vgs vg -o vg_name,pv_count
  VG #PV
  vg   3
# lvcreate -l100%FREE --type mirror -m2 vg
  Insufficient free space for log allocation for logical volume .
  Unable to allocate extents for mirror log.

AFTER FIX:
# vgs vg -o vg_name,pv_count
  VG #PV
  vg   3
# lvcreate -l100%FREE --type mirror -m2 vg
  Logical volume "lvol0" created.


3.10.0-734.el7.x86_64

lvm2-2.02.175-2.el7    BUILT: Fri Oct 13 13:31:22 CEST 2017
lvm2-libs-2.02.175-2.el7    BUILT: Fri Oct 13 13:31:22 CEST 2017
lvm2-cluster-2.02.175-2.el7    BUILT: Fri Oct 13 13:31:22 CEST 2017
device-mapper-1.02.144-2.el7    BUILT: Fri Oct 13 13:31:22 CEST 2017
device-mapper-libs-1.02.144-2.el7    BUILT: Fri Oct 13 13:31:22 CEST 2017
device-mapper-event-1.02.144-2.el7    BUILT: Fri Oct 13 13:31:22 CEST 2017
device-mapper-event-libs-1.02.144-2.el7    BUILT: Fri Oct 13 13:31:22 CEST 2017
device-mapper-persistent-data-0.7.3-2.el7    BUILT: Tue Oct 10 11:00:07 CEST 2017
cmirror-2.02.175-2.el7    BUILT: Fri Oct 13 13:31:22 CEST 2017

Comment 31 Heinz Mauelshagen 2017-10-24 13:29:41 UTC
(In reply to Roman Bednář from comment #27)
> Marking verified with latest rpms, this BZ seems to incorporate more fixes
> and behaviour changes. I'll try to summarize those (hopefully all of them)
> below.
> 
> 1) creating a mirror when a vg has no free space left:
> 
> BEFORE FIX:
> # lvcreate -l100%FREE vg -m4
>   Internal error: Unable to create new logical volume with no extents.
> 

Previously, the 100% allocation failed allocating the log for the mirror
when consuming space of all PVs for the legs leading to this error.

The new behaviour preserves space for the mirror log to allow for
its allocation (see my remark below as well).


> 
> AFTER FIX:
> # lvcreate -l100%FREE vg -m4
>   Calculated size of logical volume is 0 extents. Needs to be larger.

You have a VG with 10 PVs. How did you cause this error?

Succeeds here:

[root@vm254 ~]# vgs nvm
  VG  #PV #LV #SN Attr   VSize  VFree 
  nvm  10   0   0 wz--n- 79.96g 79.96g

[root@vm254 ~]# lvcreate -l100%FREE --ty mirror -m4 nvm
  Logical volume "lvol0" created.


[root@vm254 ~]# lvs -aoname,size,attr,segtype,stripes,datastripes,regionsize,stripesize,syncpercent,reshapelen,origin,devices nvm
  LV               LSize  Attr       Type   #Str #DStr Region  Stripe Cpy%Sync RSize Origin Devices                                                                                  
  lvol0            15.99g mwi-a-m--- mirror    5     5 512.00k     0  0.39                  lvol0_mimage_0(0),lvol0_mimage_1(0),lvol0_mimage_2(0),lvol0_mimage_3(0),lvol0_mimage_4(0)
  [lvol0_mimage_0] 15.99g Iwi-aom--- linear    1     1      0      0                        /dev/sda(0)                                                                              
  [lvol0_mimage_0] 15.99g Iwi-aom--- linear    1     1      0      0                        /dev/sdf(0)                                                                              
  [lvol0_mimage_1] 15.99g Iwi-aom--- linear    1     1      0      0                        /dev/sdb(0)                                                                              
  [lvol0_mimage_1] 15.99g Iwi-aom--- linear    1     1      0      0                        /dev/sdg(0)                                                                              
  [lvol0_mimage_2] 15.99g Iwi-aom--- linear    1     1      0      0                        /dev/sdc(0)                                                                              
  [lvol0_mimage_2] 15.99g Iwi-aom--- linear    1     1      0      0                        /dev/sdh(0)                                                                              
  [lvol0_mimage_3] 15.99g Iwi-aom--- linear    1     1      0      0                        /dev/sdd(0)                                                                              
  [lvol0_mimage_3] 15.99g Iwi-aom--- linear    1     1      0      0                        /dev/sdi(0)                                                                              
  [lvol0_mimage_4] 15.99g Iwi-aom--- linear    1     1      0      0                        /dev/sde(0)                                                                              
  [lvol0_mimage_4] 15.99g Iwi-aom--- linear    1     1      0      0                        /dev/sdj(0)                                                                              
  [lvol0_mlog]      4.00m lwi-aom--- linear    1     1      0      0                        /dev/sdj(2046)

> 
> 
> 2) %FREE option now represents total allocation space (including possible
> mirrors)
> 
> BEFORE FIX:
> # vgs vg -o vg_name,free
>   VG VFree 
>   vg 89.95g
> 
> # lvcreate -l50%FREE -m 2 vg
>   Logical volume "lvol0" created.
> 
> # vgs vg -o vg_name,free
>   VG VFree
>   vg    0 
> 
> 
> AFTER FIX:
> # vgs vg -o vg_name,free
>   VG VFree 
>   vg 89.96g

This results from the coallocation of the mirror log on a PV with a mirror log,
hence reducing the soze of all legs cusing (a little) more free space.

> 
> # lvcreate -l50%FREE -m 2 vg
>   Logical volume "lvol0" created.
> 
> # vgs vg -o vg_name,free
>   VG VFree  
>   vg <44.98g
> 
> 3) mirror log allocation:
> 
> BEFORE FIX:
> # vgs vg -o vg_name,pv_count
>   VG #PV
>   vg   3
> # lvcreate -l100%FREE --type mirror -m2 vg
>   Insufficient free space for log allocation for logical volume .
>   Unable to allocate extents for mirror log.
> 
> AFTER FIX:
> # vgs vg -o vg_name,pv_count
>   VG #PV
>   vg   3
> # lvcreate -l100%FREE --type mirror -m2 vg
>   Logical volume "lvol0" created.
> 
> 
> 3.10.0-734.el7.x86_64
> 
> lvm2-2.02.175-2.el7    BUILT: Fri Oct 13 13:31:22 CEST 2017
> lvm2-libs-2.02.175-2.el7    BUILT: Fri Oct 13 13:31:22 CEST 2017
> lvm2-cluster-2.02.175-2.el7    BUILT: Fri Oct 13 13:31:22 CEST 2017
> device-mapper-1.02.144-2.el7    BUILT: Fri Oct 13 13:31:22 CEST 2017
> device-mapper-libs-1.02.144-2.el7    BUILT: Fri Oct 13 13:31:22 CEST 2017
> device-mapper-event-1.02.144-2.el7    BUILT: Fri Oct 13 13:31:22 CEST 2017
> device-mapper-event-libs-1.02.144-2.el7    BUILT: Fri Oct 13 13:31:22 CEST
> 2017
> device-mapper-persistent-data-0.7.3-2.el7    BUILT: Tue Oct 10 11:00:07 CEST
> 2017
> cmirror-2.02.175-2.el7    BUILT: Fri Oct 13 13:31:22 CEST 2017

Comment 32 Roman Bednář 2017-10-24 15:06:42 UTC
> > AFTER FIX:
> > # lvcreate -l100%FREE vg -m4
> >   Calculated size of logical volume is 0 extents. Needs to be larger.
> 
> You have a VG with 10 PVs. How did you cause this error?

It happens when vg has no free space left, as I wrote. I should have pasted all commands for clarity. So it's: 


# vgs
  VG            #PV #LV #SN Attr   VSize   VFree  
  rhel_virt-362   1   2   0 wz--n-  <7.00g      0 
  vg             10   0   0 wz--n- 299.88g 299.88g

# lvcreate -l100%FREE vg
  Logical volume "lvol0" created.

# lvcreate -l100%FREE vg -m4
  Calculated size of logical volume is 0 extents. Needs to be larger.

Comment 33 Heinz Mauelshagen 2017-10-24 16:39:55 UTC
(In reply to Roman Bednář from comment #32)

<SNIP>

> # lvcreate -l100%FREE vg
>   Logical volume "lvol0" created.
> 
> # lvcreate -l100%FREE vg -m4
>   Calculated size of logical volume is 0 extents. Needs to be larger.

Ok, when given percent size on a zero free VG, the message tells as much being calculated for the mirror LV which is correct.

Comment 36 Corey Marthaler 2018-01-16 17:59:14 UTC
Marking verified in the latest rpms. The %FREE/%VG mirror cmds no longer fail.

The remaining free space will always be dependent on the number of PVs in the VG and how many images were requested. For -m1, -m2, -m3, etc, there will always be scenarios we can construct where we'll have remaining space even when using 100%FREE   


# 4 leg mirror -m3 (but 4 PVs in VG) = no free space
[root@host-082 ~]# vgcreate mirror_sanity /dev/sd[abcd]
  Volume group "mirror_sanity" successfully created
[root@host-082 ~]# lvcreate -l100%VG -n mirror_3 --type mirror -m3 mirror_sanity
  Logical volume "mirror_3" created.
[root@host-082 ~]# vgs -o vg_size,vg_free mirror_sanity
  VSize    VFree 
  <119.97g 12.00m

# 2 leg mirror -m1 (but 3 PVs in VG) = free space equal to ~1 PVs
[root@host-082 ~]# vgcreate mirror_sanity /dev/sd[abc]
  Volume group "mirror_sanity" successfully created
[root@host-082 ~]# lvcreate -l100%VG -n mirror_1 --type mirror -m1 mirror_sanity
  Logical volume "mirror_1" created.
[root@host-082 ~]# vgs -o vg_size,vg_free mirror_sanity
  VSize   VFree  
  <89.98g <29.99g

# 3 leg mirror -m2 (but 5 PVs in VG) = free space equal to ~2 PVs 
[root@host-082 ~]# vgcreate mirror_sanity /dev/sd[abcde]
  Volume group "mirror_sanity" successfully created
[root@host-082 ~]# lvcreate -l100%VG -n mirror_2 --type mirror -m2 mirror_sanity
  Logical volume "mirror_2" created.
[root@host-082 ~]# vgs -o vg_size,vg_free mirror_sanity
  VSize   VFree 
  149.96g 59.98g


3.10.0-830.el7.x86_64
lvm2-2.02.176-5.el7    BUILT: Wed Dec  6 11:13:07 CET 2017
lvm2-libs-2.02.176-5.el7    BUILT: Wed Dec  6 11:13:07 CET 2017
lvm2-cluster-2.02.176-5.el7    BUILT: Wed Dec  6 11:13:07 CET 2017
lvm2-lockd-2.02.176-5.el7    BUILT: Wed Dec  6 11:13:07 CET 2017
lvm2-python-boom-0.8.1-5.el7    BUILT: Wed Dec  6 11:15:40 CET 2017
cmirror-2.02.176-5.el7    BUILT: Wed Dec  6 11:13:07 CET 2017
device-mapper-1.02.145-5.el7    BUILT: Wed Dec  6 11:13:07 CET 2017
device-mapper-libs-1.02.145-5.el7    BUILT: Wed Dec  6 11:13:07 CET 2017
device-mapper-event-1.02.145-5.el7    BUILT: Wed Dec  6 11:13:07 CET 2017
device-mapper-event-libs-1.02.145-5.el7    BUILT: Wed Dec  6 11:13:07 CET 2017
device-mapper-persistent-data-0.7.0-0.1.rc6.el7    BUILT: Mon Mar 27 17:15:46 CEST 2017
sanlock-3.5.0-1.el7    BUILT: Wed Apr 26 16:37:30 CEST 2017
sanlock-lib-3.5.0-1.el7    BUILT: Wed Apr 26 16:37:30 CEST 2017

Comment 39 errata-xmlrpc 2018-04-10 15:16:02 UTC
Since the problem described in this bug report should be
resolved in a recent advisory, it has been closed with a
resolution of ERRATA.

For information on the advisory, and where to find the updated
files, follow the link below.

If the solution does not work for you, open a new bug report.

https://access.redhat.com/errata/RHEA-2018:0853


Note You need to log in before you can comment on or make changes to this bug.