Bug 1035871

Summary: lvm2 calculates snapshot space incorrectly
Product: Red Hat Enterprise Linux 6 Reporter: Mikuláš Patočka <mpatocka>
Component: lvm2Assignee: Zdenek Kabelac <zkabelac>
Status: CLOSED ERRATA QA Contact: Cluster QE <mspqa-list>
Severity: high Docs Contact:
Priority: high    
Version: 6.5CC: agk, cmarthal, coughlan, dwysocha, heinzm, jbrassow, msnitzer, nperic, prajnoha, prockai, sauchter, thornber, zkabelac
Target Milestone: rc   
Target Release: ---   
Hardware: All   
OS: Linux   
Whiteboard:
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) Environment:
Last Closed: 2014-10-14 08:24:55 UTC Type: Bug
Regression: --- Mount Type: ---
Documentation: --- CRM:
Verified Versions: Category: ---
oVirt Team: --- RHEL 7.3 requirements from Atomic Host:
Cloudforms Team: --- Target Upstream Version:
Embargoed:
Bug Depends On:    
Bug Blocks: 1066977    

Description Mikuláš Patočka 2013-11-28 17:11:49 UTC
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:
Always

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.

#!/bin/sh
VG=vg1
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
http://www.redhat.com/archives/dm-devel/2013-November/msg00153.html

Comment 2 Zdenek Kabelac 2014-02-26 13:58:42 UTC
Upstreamed updated version of Mikulas' patch:

http://www.redhat.com/archives/lvm-devel/2014-February/msg00161.html

Comment 3 Zdenek Kabelac 2014-03-06 16:38:06 UTC
Upstream test case:

https://www.redhat.com/archives/lvm-devel/2014-March/msg00045.html

Comment 6 Nenad Peric 2014-06-30 11:50:53 UTC
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 08:24:55 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.

http://rhn.redhat.com/errata/RHBA-2014-1387.html