Bug 1545627

Summary: On devices with a partition table --force option on pvcreate is not effective due to device filtering and the error message is not clear
Product: Red Hat Enterprise Linux 7 Reporter: Simone Tiraboschi <stirabos>
Component: lvm2Assignee: LVM and device-mapper development team <lvm-team>
lvm2 sub component: Command-line tools QA Contact: cluster-qe <cluster-qe>
Status: CLOSED NOTABUG Docs Contact:
Severity: high    
Priority: unspecified CC: agk, heinzm, jbrassow, khakimi, mcsontos, msnitzer, nsoffer, pbalogh, prajnoha, stirabos, talayan, teigland, thornber, zkabelac
Version: 7.5Keywords: AutomationBlocker
Target Milestone: rc   
Target Release: ---   
Hardware: Unspecified   
OS: Unspecified   
Whiteboard:
Fixed In Version: Doc Type: If docs needed, set a value
Doc Text:
Story Points: ---
Clone Of: Environment:
Last Closed: 2019-01-09 17:28:46 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: 1527077    

Description Simone Tiraboschi 2018-02-15 11:31:55 UTC
Description of problem:
If the selected device already contains a partition table the device is filtered out.
A pvcreate command, also if with --force, will fail due to device filtering.

The real issue ("Skipping: Partition table signature found") will appear only if with -vvv (-v or -vv are not enough). 

Reproducible with this:
DEVICE=/dev/vdc
(
echo o # Create a new empty DOS partition table
echo n # Add a new partition
echo p # Primary partition
echo 1 # Partition number
echo   # First sector (Accept default: 1)
echo   # Last sector (Accept default: last)
echo w # Write changes
) | sudo fdisk $DEVICE
partprobe
pvcreate $DEVICE
pvcreate -vvv $DEVICE 2>&1 | grep $DEVICE | grep "Partition table"
dd oflag=direct if=/dev/zero of=$DEVICE bs=1M count=1
pvcreate $DEVICE
echo $?

Which results in:
 [root@myhost ~]# DEVICE=/dev/vdb
 [root@myhost ~]# (
 > echo o # Create a new empty DOS partition table
 > echo n # Add a new partition
 > echo p # Primary partition
 > echo 1 # Partition number
 > echo   # First sector (Accept default: 1)
 > echo   # Last sector (Accept default: varies)
 > echo w # Write changes
 > ) | sudo fdisk $DEVICE
 Welcome to fdisk (util-linux 2.23.2).
 
 Changes will remain in memory only, until you decide to write them.
 Be careful before using the write command.
 
 Device does not contain a recognized partition table
 Building a new DOS disklabel with disk identifier 0xe95ff291.
 
 Command (m for help): Building a new DOS disklabel with disk identifier 0x71d3c804.
 
 Command (m for help): Partition type:
    p   primary (0 primary, 0 extended, 4 free)
    e   extended
 Select (default p): Partition number (1-4, default 1): First sector (2048-20971519, default 2048): Using default value 2048
 Last sector, +sectors or +size{K,M,G} (2048-20971519, default 20971519): Using default value 20971519
 Partition 1 of type Linux and of size 10 GiB is set
 
 Command (m for help): The partition table has been altered!
 
 Calling ioctl() to re-read partition table.
 Syncing disks.
 [root@myhost ~]# partprobe
 [root@myhost ~]# pvcreate $DEVICE
   Device /dev/vdb not found (or ignored by filtering).
 [root@myhost ~]# pvcreate -vvv $DEVICE 2>&1 | grep $DEVICE | grep "Partition table"
         /dev/vdb: Skipping: Partition table signature found
 [root@myhost ~]# dd oflag=direct if=/dev/zero of=$DEVICE bs=1M count=1
 1+0 records in
 1+0 records out
 1048576 bytes (1,0 MB) copied, 0,00252575 s, 415 MB/s
 [root@myhost ~]# pvcreate $DEVICE
   Physical volume "/dev/vdb" successfully created.
 [root@myhost ~]# echo $?
 0


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

How reproducible:
100%

Steps to Reproduce:
1. Test with the provided snippet 
2.
3.

Actual results:
pvcreate --force fails with:
  Device /dev/vdb not found (or ignored by filtering).
pvcreate --force -vvv shows also:
        /dev/vdb: Skipping: Partition table signature found
The user has to manually wipe out the first block with:
  dd oflag=direct if=/dev/zero of=/dev/vdb bs=1M count=1
Then pvcreate will work as expected (no --force is needed in that case)

Expected results:
pvcreate --force works also if the device already contains a partition table ignoring that specific filtering

Additional info:

Comment 2 Marian Csontos 2018-02-15 11:44:53 UTC
Why not using `wipefs` first to get rid of all metadata?

Anyway, it works with a FS, so should work the same with partition tables I guess.

Comment 3 Simone Tiraboschi 2018-02-15 17:26:16 UTC
(In reply to Marian Csontos from comment #2)
> Why not using `wipefs` first to get rid of all metadata?

'wipefs'by default is not enough, you need 'wipefs -a'

> Anyway, it works with a FS, so should work the same with partition tables I
> guess.

Yes, I think so.

Comment 4 Jonathan Earl Brassow 2018-03-14 14:46:58 UTC
(In reply to Simone Tiraboschi from comment #3)
> (In reply to Marian Csontos from comment #2)
> > Why not using `wipefs` first to get rid of all metadata?
> 
> 'wipefs'by default is not enough, you need 'wipefs -a'
> 
> > Anyway, it works with a FS, so should work the same with partition tables I
> > guess.
> 
> Yes, I think so.

I don't understand this discussion... are you saying that you have a solution and we can close this bug, or something else?

Comment 5 Simone Tiraboschi 2018-03-14 15:32:30 UTC
(In reply to Jonathan Earl Brassow from comment #4)
> (In reply to Simone Tiraboschi from comment #3)
> > (In reply to Marian Csontos from comment #2)
> > > Why not using `wipefs` first to get rid of all metadata?
> > 
> > 'wipefs'by default is not enough, you need 'wipefs -a'
> > 
> > > Anyway, it works with a FS, so should work the same with partition tables I
> > > guess.
> > 
> > Yes, I think so.
> 
> I don't understand this discussion... are you saying that you have a
> solution and we can close this bug, or something else?

No, I'm just saying that I agree that if --force works when the device contains a  FS, I'd expect the same behavior if the device contains a partition table.

The issue is that all the devices containing a partition table get filtered out before applying --force option.

Comment 6 Zdenek Kabelac 2018-03-14 15:43:30 UTC
(In reply to Simone Tiraboschi from comment #5)
> (In reply to Jonathan Earl Brassow from comment #4)
> > (In reply to Simone Tiraboschi from comment #3)
> > > (In reply to Marian Csontos from comment #2)
> > > > Why not using `wipefs` first to get rid of all metadata?
> > > 
> > > 'wipefs'by default is not enough, you need 'wipefs -a'
> > > 
> > > > Anyway, it works with a FS, so should work the same with partition tables I
> > > > guess.
> > > 
> > > Yes, I think so.
> > 
> > I don't understand this discussion... are you saying that you have a
> > solution and we can close this bug, or something else?
> 
> No, I'm just saying that I agree that if --force works when the device
> contains a  FS, I'd expect the same behavior if the device contains a
> partition table.
> 
> The issue is that all the devices containing a partition table get filtered
> out before applying --force option.

This is correct logic for lvm2.

Lvm2 doesn't check all partitions when it's manipulating with a single device.

In other words - this is 'rather' huge change for lvm2 internals to introduce some 'bypass' for elimination of partition tables skipping for --force option.

You can think of lvm2 being a 'consumer' of 'device list' where 'partitioned' devices are ignored - the option '--force' is not meant to bypass core logic of device scanning ATM.

Lvm2 would need to be enhanced first to detect it's safe to drop partition table.

Comment 7 Jonathan Earl Brassow 2018-04-11 13:38:02 UTC
I see 2 options here:
1) decrease the necessary verbose setting to see the "partition" message below -vvv, but at least requiring -v
2) close WONTFIX

Comment 9 Nir Soffer 2018-04-12 09:26:34 UTC
Kobi, why this blocks automation? why don't you wipe the first 1MiB of a LUN before
adding it?

Comment 10 Kobi Hakimi 2018-04-12 09:33:47 UTC
added AutomationBlocker because in any case, we had to do force clean of hosted engine environment
(force clean - reprovision the host without correct cleanup) 
we failed in the next deploy even with the force key OVEHOSTED_ENGINE/forceCreateVG
in the answer file.

Comment 11 Marian Csontos 2018-04-12 10:11:10 UTC
Our policy is: It is safer to err on side of caution and ask user if data loss is possible.

There is a difference between wiping single FS and all partitions - when wiping all partitions we would need to go through all partitions and check their content. What if there are other PVs on those partitions? What if ...?

This does not look like a job for LVM but for a management tool.

If you want to clean a system, use `wipefs -a $DISK` but LVM is not a universal tool for managing ALL block devices including partitions.

If you still wish to go down that road, use pvcreate --force with --yes which should work, but it is always dangerous combination to use in scripts.

The only thing WE will do is improve the warning.

Comment 12 Kobi Hakimi 2018-04-30 10:47:11 UTC
additional info:
The user get the following error when trying to deploy HE on FC SD manually and its not clean:

[ INFO  ] TASK [Add Fibre Channel storage domain]
[ ERROR ] TypeError: 'NoneType' object is not iterable
[ ERROR ] fatal: [localhost]: FAILED! => {"changed": false, "msg": "'NoneType' object is not iterable"}
          Please specify the storage you would like to use (glusterfs, iscsi, fc, nfs)[nfs]:

Comment 13 Sandro Bonazzola 2019-01-09 09:17:20 UTC
Can we plan this to be fixed in upcoming releases?

Comment 14 David Teigland 2019-01-09 17:28:46 UTC
I agree with Zdenek and Marian, clearing partitions with pvcreate -f doesn't look right; wipefs -a or dd work fine for this.