Bug 1035871 - lvm2 calculates snapshot space incorrectly
lvm2 calculates snapshot space incorrectly
Product: Red Hat Enterprise Linux 6
Classification: Red Hat
Component: lvm2 (Show other bugs)
All Linux
high Severity high
: rc
: ---
Assigned To: Zdenek Kabelac
Cluster QE
Depends On:
Blocks: 1066977
  Show dependency treegraph
Reported: 2013-11-28 12:11 EST by Mikuláš Patočka
Modified: 2014-10-14 04:24 EDT (History)
13 users (show)

See Also:
Fixed In Version: lvm2-2.02.107-1.el6
Doc Type: Bug Fix
Doc Text:
Cause: Incorrect assumption in formula for estimation of maximum size for snapshot's COW device size. Consequence: Estimated maximum size of snapshot volume could have been too small to hold all changed blocks from origin volume. Such snapshot is than automatically marked as invalidated and it is lost. Fix: Formula for size estimation has been fixed. Result: Maximum size of snapshot has correct size.
Story Points: ---
Clone Of:
: 1066977 (view as bug list)
Last Closed: 2014-10-14 04:24:55 EDT
Type: Bug
Regression: ---
Mount Type: ---
Documentation: ---
Verified Versions:
Category: ---
oVirt Team: ---
RHEL 7.3 requirements from Atomic Host:
Cloudforms Team: ---

Attachments (Terms of Use)

  None (edit)
Description Mikuláš Patočka 2013-11-28 12:11:49 EST
Description of problem:

In RHEL6, the lvm2 tool was modified so that it calculates maximum space that
a snapshot could use and restricts the user-supplied snapshot size so that it is
never larger than the maximum useable space. However, this calculation is
incorrect. Under certain circumstances lvm2 may allocate snapshot that is too
small. When this snapshot is filled up, it overflows and all data in the snapshot
is lost.

Version-Release number of selected component (if applicable):
2.02.100(2)-RHEL6 (2013-10-23)

How reproducible:

Steps to Reproduce:
Use this script. Set the variable VG to some real volume group. The volume
group must have extent size 4MiB or less (by default, extent size is 4MiB) and it
must have at least 4GiB free space.

lvremove -f $VG/origin
set -e
lvcreate -L 2143289344b -n origin $VG
lvcreate -n snap -c 8k -L 2304M -s $VG/origin
dd if=/dev/zero of=/dev/$VG/snap bs=1M oflag=direct

Actual results:
The snapshot overflows and all data in it is lost.

Expected results:
The snapshot should not overflow. The user specified sufficient size (2304MiB),
but lvm2 trimmed the size to a smaller value.

Additional info:
See the bug report at
Comment 2 Zdenek Kabelac 2014-02-26 08:58:42 EST
Upstreamed updated version of Mikulas' patch:

Comment 3 Zdenek Kabelac 2014-03-06 11:38:06 EST
Upstream test case:

Comment 6 Nenad Peric 2014-06-30 07:50:53 EDT
Ran 5 iteration of aforementioned test without issues:

Iteration 5 of 5 started at Mon Jun 30 13:43:47 CEST 2014
SCENARIO - [calc_maximum_usable_space]
Making origin volume
lvcreate -n origin -L 2143289344b snapper
Creating snap requiring LVM to recaluculate its total space
lvcreate -n calc_snap -c 8k -L 2304M -s /dev/snapper/origin

Attempting to fill snap
dd if=/dev/zero of=/dev/snapper/calc_snap bs=1M oflag=direct
dd: writing `/dev/snapper/calc_snap': No space left on device
2045+0 records in
2044+0 records out
2143289344 bytes (2.1 GB) copied, 33.7317 s, 63.5 MB/s

Read from snap
100+0 records in
100+0 records out
104857600 bytes (105 MB) copied, 1.22551 s, 85.6 MB/s

current snap attr: swi-a-s---
Removing volume snapper/calc_snap
Removing origin snapper/origin

Deleting VG snapper
Deleting PVs /dev/sdb1 /dev/sdc1

Marking VERIFIED with:

lvm2-2.02.107-1.el6    BUILT: Mon Jun 23 16:44:45 CEST 2014
lvm2-libs-2.02.107-1.el6    BUILT: Mon Jun 23 16:44:45 CEST 2014
lvm2-cluster-2.02.107-1.el6    BUILT: Mon Jun 23 16:44:45 CEST 2014
udev-147-2.55.el6    BUILT: Wed Jun 18 13:30:21 CEST 2014
device-mapper-1.02.86-1.el6    BUILT: Mon Jun 23 16:44:45 CEST 2014
device-mapper-libs-1.02.86-1.el6    BUILT: Mon Jun 23 16:44:45 CEST 2014
device-mapper-event-1.02.86-1.el6    BUILT: Mon Jun 23 16:44:45 CEST 2014
device-mapper-event-libs-1.02.86-1.el6    BUILT: Mon Jun 23 16:44:45 CEST 2014
device-mapper-persistent-data-0.3.2-1.el6    BUILT: Fri Apr  4 15:43:06 CEST 2014
cmirror-2.02.107-1.el6    BUILT: Mon Jun 23 16:44:45 CEST 2014
Comment 8 errata-xmlrpc 2014-10-14 04:24:55 EDT
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.


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