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 1366460 - When "pool-build --overwrite" a block device as a whole partition with filesystem=ext2/ext3/ext4/vfat, it will fail because libvirt call "mkfs" command without "-F/-I"(Force)
Summary: When "pool-build --overwrite" a block device as a whole partition with filesy...
Keywords:
Status: CLOSED ERRATA
Alias: None
Product: Red Hat Enterprise Linux 7
Classification: Red Hat
Component: libvirt
Version: 7.3
Hardware: x86_64
OS: Linux
medium
medium
Target Milestone: rc
: ---
Assignee: John Ferlan
QA Contact: Pei Zhang
URL:
Whiteboard:
Depends On:
Blocks:
TreeView+ depends on / blocked
 
Reported: 2016-08-12 03:59 UTC by yisun
Modified: 2017-08-01 23:53 UTC (History)
6 users (show)

Fixed In Version: libvirt-2.5.0-1.el7
Doc Type: No Doc Update
Doc Text:
undefined
Clone Of:
Environment:
Last Closed: 2017-08-01 17:11:42 UTC
Target Upstream Version:
Embargoed:


Attachments (Terms of Use)


Links
System ID Private Priority Status Summary Last Updated
Red Hat Product Errata RHEA-2017:1846 0 normal SHIPPED_LIVE libvirt bug fix and enhancement update 2017-08-01 18:02:50 UTC

Description yisun 2016-08-12 03:59:29 UTC
Description:
When "pool-build --overwrite" a block device as a whole partition with filesystem=ext2/ext3/ext4/vfat, it will fail because libvirt call "mkfs" command without "-F/-I"(Force)

Versions:
libvirt-2.0.0-5.el7.x86_64

How reproducible:
100%



Steps:
please note, the "Force" option for mkfs.vfat is "-I", for mkfs.ext2/3/4 is "-F" and for mkfs.xfs is "-f"
 
1. I used a usb disk in my test.
# lsscsi
[7:0:0:0]    disk    SanDisk  Cruzer Blade     1.26  /dev/sdg


2. mkfs the sdg as xfs file system.
# mkfs.xfs /dev/sdg -f

3. prepare a pool's xml as follow:
# cat fs.pool
<pool type='fs'>
  <name>fs</name>
  <uuid>5c7433cf-acf3-4c36-8300-65d5b2a18d01</uuid>
  <capacity unit='bytes'>0</capacity>
  <allocation unit='bytes'>0</allocation>
  <available unit='bytes'>0</available>
  <source>
    <device path='/dev/sdg'/>
    <format type='ext4'/>   <======= here can be ext4/ext3/ext2/vfat
  </source>
  <target>
    <path>/var/lib/libvirt/images/fs</path>
  </target>
</pool>

4. Define the pool
# virsh pool-define fs.pool
Pool fs defined from fs.pool

5. try to build the pool with --overwrite
# virsh pool-build fs --overwrite
error: Failed to build pool fs
error: Failed to make filesystem of type 'ext4' on device '/dev/sdg': Success


6. now, in libvirtd.log, we can see libvirt try to use "/usr/sbin/mkfs -t ext4 /dev/sdg"
#cat /var/log/libvirtd-debug.log
...
2016-08-11 11:15:16.932+0000: 3819: debug : virCommandRunAsync:2429 : About to run /usr/sbin/mkfs -t ext4 /dev/sdg
...

7. check the /dev/sdg
# parted /dev/sdg p
Model: SanDisk Cruzer Blade (scsi)
Disk /dev/sdg: 8004MB
Sector size (logical/physical): 512B/512B
Partition Table: loop
Disk Flags:

Number  Start  End     Size    File system  Flags
 1      0.00B  8004MB  8004MB  xfs <==== still xfs


Expected result:
with --overwrite option, pool-build should successfully mkfs the whole block device. As above step 6, if libvirt use "/usr/sbin/mkfs -t ext3 -F /dev/sdg" (a "-F" added"), the pool-build should be successful.

Actual result:
pool-build failed (and error message is strange with a "Success")


Additional info:
pool-build --overwrite a xfs pool is ok because the mkfs cmd has a "-f"
# tailf /var/log/libvirtd-debug.log  | grep xfs
2016-08-11 10:55:11.520+0000: 3819: debug : virStorageBackendMakeFileSystem:763 : source device: '/dev/sdg' format: 'xfs'
2016-08-11 10:55:11.520+0000: 3819: debug : virCommandRunAsync:2429 : About to run /usr/sbin/mkfs -t xfs -f /dev/sdg

Comment 1 John Ferlan 2016-11-15 20:40:13 UTC
Patch posted:

http://www.redhat.com/archives/libvir-list/2016-November/msg00782.html

Comment 2 John Ferlan 2016-11-16 12:09:46 UTC
Now pushed:

$ git show
commit 135e77d32fe9e7299f5c82757563e5a6d28e2f3c
Author: John Ferlan <jferlan>
Date:   Tue Nov 15 15:29:47 2016 -0500

    fs: Add proper switch to create filesystem with overwrite
...
    When using the --overwrite switch on a pool-build or pool-create, the
    The mkfs.ext{2|3|4} commands use mke2fs which requires using the '-F' switch
    in order to force overwriting the current filesystem on the whole disk.
    
    Likewise, the mkfs.vfat command uses mkfs.fat which requires using the '-I'
    switch in order to force overwriting the current filesystem on the whole disk.


$ git describe 135e77d32fe9e7299f5c82757563e5a6d28e2f3c
v2.4.0-154-g135e77d
$

Comment 4 Pei Zhang 2017-02-16 06:01:45 UTC
Version :
libvirt-3.0.0-2.el7.x86_64
qemu-kvm-rhev-2.8.0-4.el7.x86_64

Verified steps :

1. Prepare a disk 
# lsscsi
[15:0:0:0]   disk    LIO-ORG  target4          4.0   /dev/sdb 

2. make the sdb as xfs file system.
# mkfs.xfs /dev/sdb -f

3.Prepare a pool's xml with format type is ext4 :
# cat fspool.xml 
<pool type='fs'>
  <name>fs</name>
  <uuid>5c7433cf-acf3-4c36-8300-65d5b2a18d01</uuid>
  <capacity unit='bytes'>0</capacity>
  <allocation unit='bytes'>0</allocation>
  <available unit='bytes'>0</available>
  <source>
    <device path='/dev/sdb'/>
    <format type='ext4'/>   
  </source>
  <target>
    <path>/var/lib/libvirt/images/fs</path>
  </target>
</pool>

4. Define the pool
# virsh pool-define fspool.xml 
Pool fs defined from fspool.xml

5. Build the pool with --overwrite, build successfully
# virsh pool-build fs --overwrite
Pool fs built

6. Check the block device, the file system was changed tp ext4 successfully. 
# parted /dev/sdb p
......
Number  Start  End     Size    File system  Flags
 1      0.00B  32.2GB  32.2GB  ext4

7. using pool-edit gto change the format to ext3
# virsh pool-edit fs
Pool fs XML configuration edited.

8. build agian with --overwrite

# virsh pool-build fs --overwrite
Pool fs built

9. Check the block device, the file system was changed to ext3 successfully
# parted /dev/sdb p
......
Number  Start  End     Size    File system  Flags
 1      0.00B  32.2GB  32.2GB  ext3

10. Trying to change format to ext2/vfat. They also can be changed successfully.

As above, move this bug to verified.

Comment 5 errata-xmlrpc 2017-08-01 17:11:42 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-2017:1846

Comment 6 errata-xmlrpc 2017-08-01 23:53:19 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-2017:1846


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