Bug 1977734

Summary: [RFE] Allow pvcreate -f to overwrite devices have GPT partition table.
Product: Red Hat Enterprise Linux 8 Reporter: Ranjith ML <rmadhuso>
Component: lvm2Assignee: David Teigland <teigland>
lvm2 sub component: Default / Unclassified QA Contact: cluster-qe <cluster-qe>
Status: ASSIGNED --- Docs Contact:
Severity: medium    
Priority: urgent CC: agk, bmr, cmarthal, heinzm, jbrassow, jmagrini, jpittman, mgandhi, msnitzer, nyewale, prajnoha, qguo, redhatbugzilla, rmadhuso, teigland, zkabelac
Version: 8.4Keywords: FutureFeature, RFE, Triaged
Target Milestone: betaFlags: rmadhuso: needinfo-
Target Release: ---   
Hardware: x86_64   
OS: Linux   
Whiteboard:
Fixed In Version: Doc Type: If docs needed, set a value
Doc Text:
Story Points: ---
Clone Of: Environment:
Last Closed: 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:

Comment 2 David Teigland 2021-06-30 15:36:25 UTC
It sounds like this is already fixed in 8.5 but I don't have nvme devices to test against to verify.  If you'd like to be sure it's fixed in 8.5 please try the most recent lvm build.

Comment 3 Rupesh Girase 2021-07-01 11:34:17 UTC
Hello,

Tried latest lvm2 build and it does not work.
reproducible with non nvme devices as well.

# parted /dev/mapper/mpathb mklabel gpt
Information: You may need to update /etc/fstab.

# pvcreate -y /dev/mapper/mpathb
  Cannot use /dev/mapper/mpathb: device is partitioned        <<<

# rpm -q lvm2
lvm2-2.03.12-2.el8.x86_64

# pvcreate --version
  LVM version:     2.03.12(2)-RHEL8 (2021-05-19)
  Library version: 1.02.177-RHEL8 (2021-05-19)
  Driver version:  4.43.0
  Configuration:   ./configure --build=x86_64-redhat-linux-gnu --host=x86_64-redhat-linux-gnu --program-prefix= --disable-dependency-tracking --prefix=/usr --exec-prefix=/usr --bindir=/usr/bin --sbindir=/usr/sbin --sysconfdir=/etc --datadir=/usr/share --includedir=/usr/include --libdir=/usr/lib64 --libexecdir=/usr/libexec --localstatedir=/var --sharedstatedir=/var/lib --mandir=/usr/share/man --infodir=/usr/share/info --with-default-dm-run-dir=/run --with-default-run-dir=/run/lvm --with-default-pid-dir=/run --with-default-locking-dir=/run/lock/lvm --with-usrlibdir=/usr/lib64 --enable-fsadm --enable-write_install --with-user= --with-group= --with-device-uid=0 --with-device-gid=6 --with-device-mode=0660 --enable-pkgconfig --enable-cmdlib --enable-dmeventd --enable-blkid_wiping --with-cluster=internal --enable-cmirrord --with-udevdir=/usr/lib/udev/rules.d --enable-udev_sync --with-thin=internal --with-cache=internal --enable-lvmpolld --enable-lvmlockd-dlm --enable-lvmlockd-dlmcontrol --enable-lvmlockd-sanlock --enable-dbus-service --enable-notify-dbus --enable-dmfilemapd --with-writecache=internal --with-vdo=internal --with-vdo-format=/usr/bin/vdoformat --with-integrity=internal --disable-silent-rules



Thanks,
Rupesh

Comment 14 David Teigland 2021-09-08 20:37:48 UTC
I've now learned what GPT labels/partitions are.

If a disk has any kind of partition header (GPT label alone, GPT label with partitions, or others), pvcreate will not overwrite that header, and reports:

# pvcreate /dev/sdc
  Cannot use /dev/sdc: device is partitioned

This seems correct to me, and it's consistent with how other tools handle the same device:

# blkid /dev/sdc
/dev/sdc: PTUUID="237eb497-c8b7-4e2b-b68f-c4ae47bad331" PTTYPE="gpt"

# mkfs.ext4 /dev/sdc
mke2fs 1.45.6 (20-Mar-2020)
Found a gpt partition table in /dev/sdc
Proceed anyway? (y,N)                 

# mkfs.xfs /dev/sdc
mkfs.xfs: /dev/sdc appears to contain a partition table (gpt).
mkfs.xfs: Use the -f option to force overwrite.


A different question is whether the pvcreate -f option or -ff option will allow a user to overwrite any partition header.  In the current version, pvcreate -f or -ff do not allow overwriting it.  This looks like a bug (and seems to be unrelated to either NVME or GPT.)

Comment 15 David Teigland 2021-09-08 21:39:49 UTC
Here's a dev branch patch that allows pvcreate -f to overwrite partitions:
https://sourceware.org/git/?p=lvm2.git;a=shortlog;h=refs/heads/dev-dct-pvcreate-f

I was trying to track down a commit for this regression but haven't found that yet (got back to late 2019), to see if that reveals any other cases for -f that also need to be fixed.

Comment 16 David Teigland 2021-09-09 14:52:16 UTC
I have gone back and tested 8.2, 8.1 and 8.0, and none of these versions allow pvcreate -f to overwrite a partition header.  

The stable-2.02 branch (basis for RHEL7 versions) also does not allow pvcreate -f to overwrite a partition header.

So, overwriting partitions with pvcreate -f sounds more like a feature request than a bug fix.

I suspect that the results shown above, where "pvcreate -f /dev/nvme0n1" overwrites a partition header, may in fact be a different issue (not recognizing nvme devices/partitions).  This patch for bug 1859659 fixed recognizing nvme devices/partitions:


commit bee9f4efdd8195f383f026290b741314cdc42439
Author: David Teigland <teigland>
Date:   Thu Dec 3 10:48:21 2020 -0600

    filter-mpath: work with nvme devices
    
    Recognize when a device is nvme, and apply filter-mpath to
    nvme devices in addition to scsi devices.

Comment 20 David Teigland 2021-09-13 14:57:00 UTC
The debug trace shows that lvm does not see partitions on /dev/nvme0n1, so it is not excluded by filter-partitioned, which is meant to reject devices with partition tables.  This allows the device to be formatted, which includes calling the wiping code (which does find partitions to wipe and produces the messages.)

So, the problem is with the old code failing to see partition info on the device.  If partition detection was fixed in the old version, then the old version would disallow overwriting the partition tables.

Perhaps it makes the most sense to use this bz as an RFE to allow pvcreate -f to overwrite partition tables.

Comment 21 Ranjith ML 2021-10-19 07:47:31 UTC
Changing this as RFE request.

Description of problem:

pvcreate -y should allows to wipe gpt partition label and initialize device as PV.

Actual results:

$ sudo parted /dev/nvme1n1 mklabel GPT
Information: You may need to update /etc/fstab.

$ sudo pvcreate -y /dev/nvme1n1             
  Cannot use /dev/nvme1n1: device is partitioned

Expected results:

pvcreate should wipe gpt label from disk as the device doesn't has any actual partition on it.

Comment 22 David Teigland 2022-01-14 20:27:31 UTC
change is here:
https://sourceware.org/git/?p=lvm2.git;a=commit;h=d5a950ca67c106403054ecb847e226e8b5a7c30e

# grep sdc /proc/partitions
   8       32  976236544 sdc
   8       33    2097152 sdc1
   8       34  974138368 sdc2

# ls -l /dev/sdc*
brw-rw----. 1 root disk 8, 32 Jan 13 13:33 /dev/sdc
brw-rw----. 1 root disk 8, 33 Jan 13 13:33 /dev/sdc1
brw-rw----. 1 root disk 8, 34 Jan 13 13:33 /dev/sdc2

# pvcreate /dev/sdc
  Cannot use /dev/sdc: device is partitioned

# pvcreate -f /dev/sdc
  Wiping dos signature on /dev/sdc.
  Physical volume "/dev/sdc" successfully created.

# grep sdc /proc/partitions
   8       32  976236544 sdc

# ls -l /dev/sdc*
brw-rw----. 1 root disk 8, 32 Jan 13 13:34 /dev/sdc

# pvs /dev/sdc
  PV         VG Fmt  Attr PSize   PFree  
  /dev/sdc      lvm2 ---  931.01g 931.01g

Comment 23 David Teigland 2022-01-14 20:45:49 UTC
> change is here:
> https://sourceware.org/git/?p=lvm2.git;a=commit;
> h=d5a950ca67c106403054ecb847e226e8b5a7c30e

That was the commit in the main branch, the commit in the stable branch for rhel8 is:
https://sourceware.org/git/?p=lvm2.git;a=commit;h=a5c37afdca97d6565ea02bc4bc7d52f360823cd3

Comment 32 David Teigland 2023-03-08 18:13:22 UTC
*** Bug 2138459 has been marked as a duplicate of this bug. ***