Bug 1247987

Summary: volume info has incorrect allocation value for extended partition.
Product: Red Hat Enterprise Linux 7 Reporter: yisun
Component: libvirtAssignee: John Ferlan <jferlan>
Status: CLOSED ERRATA QA Contact: Virtualization Bugs <virt-bugs>
Severity: low Docs Contact:
Priority: low    
Version: 7.2CC: dyuan, jferlan, rbalakri, xuzhang, yanyang
Target Milestone: rc   
Target Release: ---   
Hardware: x86_64   
OS: Linux   
Whiteboard:
Fixed In Version: libvirt-1.3.1-1.el7 Doc Type: Bug Fix
Doc Text:
Story Points: ---
Clone Of: Environment:
Last Closed: 2016-11-03 18:21:33 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:

Description yisun 2015-07-29 11:55:27 UTC
Description of problem:
volume info has incorrect allocation value for extended partition. 

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


How reproducible:
100%

Steps to Reproduce:
1. prepare a disk pool
# virsh pool-dumpxml sdb
<pool type='disk'>
  <name>sdb</name>
  <uuid>0d5e0da6-db87-4a93-975e-4d3467a64d4a</uuid>
  <capacity unit='bytes'>8003197440</capacity>
  <allocation unit='bytes'>1048576</allocation>
  <available unit='bytes'>8002084352</available>
  <source>
    <device path='/dev/sdb'>
      <freeExtent start='32256' end='1048576'/>
      <freeExtent start='2129408' end='5370806272'/>
      <freeExtent start='5370806272' end='8003197440'/>
    </device>
    <format type='dos'/>
  </source>
  <target>
    <path>/dev</path>
    <permissions>
      <mode>0700</mode>
      <owner>0</owner>
      <group>0</group>
    </permissions>
  </target>
</pool>


2. create a extended partition from disk sdb
#fdisk /dev/sdb
Command (m for help): n
Partition type:
   p   primary (1 primary, 0 extended, 3 free)
   e   extended
Select (default p): e
Partition number (2-4, default 2): 
First sector (4096-15633407, default 4096): 
Using default value 4096
Last sector, +sectors or +size{K,M,G} (4096-15633407, default 15633407): +5G
Partition 2 of type Extended and of size 5 GiB is set

Command (m for help): w
The partition table has been altered!

Calling ioctl() to re-read partition table.
Syncing disks.


3. check the vol's info in this disk pool
# virsh vol-list sdb --details
 Name  Path       Type   Capacity  Allocation
----------------------------------------------
 sdb1  /dev/sdb1  block  1.00 MiB    1.00 MiB
 sdb2  /dev/sdb2  block  5.00 GiB    5.00 GiB  <== extended partitoin should not take up space until logical partition created. 


5. check the vol-info 
# virsh vol-info sdb2 sdb
Name:           sdb2
Type:           block
Capacity:       5.00 GiB
Allocation:     5.00 GiB <=== this is not correct. 


4. check the pool info
# virsh pool-info sdb
Name:           sdb
UUID:           0d5e0da6-db87-4a93-975e-4d3467a64d4a
State:          running
Persistent:     yes
Autostart:      no
Capacity:       7.45 GiB
Allocation:     1.00 MiB   <=== correct according to bz 1206521#c8
Available:      7.45 GiB



Actual results:
in step 3, the extended partition volume sdb2 has allocation=5GiB 

Expected results:
extended partition doesn't take up any space until logical partition generated. According to 1206521#c8, we may do not show up the extended partition volume. Or we can use correct extended partition allocation value, which is the sum of all logical volumes generated from that extended partition.

Comment 1 John Ferlan 2015-10-02 13:48:05 UTC
Patch posted upstream:

http://www.redhat.com/archives/libvir-list/2015-October/msg00084.html

Comment 2 John Ferlan 2015-10-06 11:43:29 UTC
Patch pushed upstream as commit id '1895b42114c932495c2242d6847e47c054955998'

git describe 1895b42114c932495c2242d6847e47c054955998
v1.2.20-28-g1895b42

Comment 5 yisun 2016-04-01 08:44:29 UTC
Verified on : libvirt-1.3.2-1.el7.x86_64

1. prepare a pool xml
# cat pool.usb 
<pool type='disk'>
  <name>sdb</name>
  <source>
    <device path='/dev/sdb'>
    </device>
    <format type='dos'/>
  </source>
  <target>
    <path>/dev</path>
    <permissions>
      <mode>0700</mode>
      <owner>0</owner>
      <group>0</group>
    </permissions>
  </target>
</pool>

2. define the pool
# virsh pool-define pool.usb 
Pool sdb defined from pool.usb

3. build the pool
# virsh pool-build sdb --overwrite
Pool sdb built

4. start the pool
# virsh pool-start sdb
Pool sdb started

5. make a extended partition on sdb
# parted /dev/sdb
GNU Parted 3.1
Using /dev/sdb
Welcome to GNU Parted! Type 'help' to view a list of commands.
(parted) mkpart 
Partition type?  primary/extended? extended                               
Start? 0                                                                  
End? 4G                                                                   
Warning: The resulting partition is not properly aligned for best performance.
Ignore/Cancel? Ignore                                                     
(parted) quit 
Information: You may need to update /etc/fstab.

6. refresh the pool
# virsh pool-refresh sdb                                
Pool sdb refreshed

7. check the vol-list with --details. make sure extended partition has 0B allocation before make any logical partitions. 
# virsh vol-list --details sdb
 Name  Path       Type   Capacity  Allocation
----------------------------------------------
 sdb1  /dev/sdb1  block  3.73 GiB      0.00 B


8. check the extended partition's vol info, allocation should be 0B at now
# virsh vol-info sdb1 sdb
Name:           sdb1
Type:           block
Capacity:       3.73 GiB
Allocation:     0.00 B

9. check the pool info, allocation should be 0B at now
# virsh pool-info sdb
Name:           sdb
UUID:           b426d1b4-a35b-4da9-be84-6315b7c5907b
State:          running
Persistent:     yes
Autostart:      no
Capacity:       7.45 GiB
Allocation:     0.00 B
Available:      7.45 GiB

10. create a logical parition
# parted /dev/sdb mkpart
Partition type?  primary/logical? logical                                 
File system type?  [ext2]?                                                
Start?                                                                    
Start? 1                                                                  
End? 100M                                                                 
Information: You may need to update /etc/fstab.

11. refresh the pool
# virsh pool-refresh sdb
Pool sdb refreshed


12. The extended partition should have allocation equals to 100M right now
# virsh vol-list --details sdb
 Name  Path       Type    Capacity  Allocation
-----------------------------------------------
 sdb1  /dev/sdb1  block   3.73 GiB   94.00 MiB
 sdb5  /dev/sdb5  block  94.00 MiB   94.00 MiB



13. check the pool info, the allocation should be around 100M right now
# virsh pool-info sdb
Name:           sdb
UUID:           7962ba02-9dd2-40e8-b7d5-1d8d5417126f
State:          running
Persistent:     yes
Autostart:      no
Capacity:       7.45 GiB
Allocation:     94.00 MiB
Available:      7.36 GiB


14. check the extended partition and the logical partition, their allocation should be correct, both equals to 100M 
# virsh vol-info sdb1 sdb
Name:           sdb1
Type:           block
Capacity:       3.73 GiB
Allocation:     94.00 MiB

# virsh vol-info sdb5 sdb
Name:           sdb5
Type:           block
Capacity:       94.00 MiB
Allocation:     94.00 MiB

Comment 7 errata-xmlrpc 2016-11-03 18:21:33 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://rhn.redhat.com/errata/RHSA-2016-2577.html