From 1a6235499594ffcced939b93bab937e928a0d6f3 Mon Sep 17 00:00:00 2001 From: Mike Fleetwood Date: Wed, 25 Jul 2012 21:45:02 +0100 Subject: [PATCH] Implement LVM2 PV remove() method (#670171) Implement remove() method so that the LVM2 metadata is updated to reflect the removal of the LVM2 Physical Volume as well as removing the signature from the PV before the partition is deleted or overwritten. lvm pvremove /dev/DEVICE Also specifically force the removal of the PV when it is a member of a Volume Group so that it will succeed. RATIONAL: If the PV was not removed before the partition was deleted or overwritten, LVM2 would be left in a broken state with metadata describing missing PVs for any partially deleted VGs. This leaves the user needing to perform recovery of a lost PV, which required in depth understanding of LVM2 and is beyond the scope of what GParted can currently provide. The alternative is to use the pvremove command to instruct LVM2 to remove the PV and update LVM2 metadata to reflect the removal of the PV. For PVs which are a member of a VG this includes forcing the removal. This has the impact of making recovery from accidental deletion of a partition containing a PV irrecoverable. GParted is not able to recover this situation anyway because Device -> Attempt Data Rescue, using the gpart command, is not able to detect the signature of an LVM2 PV. Choose to remove the PV, forcibly if required, rather than potentially leave LVM2 with missing PVs. Bug #670171 - Add LVM PV read-write support --- src/lvm2_pv.cc | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/src/lvm2_pv.cc b/src/lvm2_pv.cc index 18d1ea6c..c7cd1eee 100644 --- a/src/lvm2_pv.cc +++ b/src/lvm2_pv.cc @@ -53,6 +53,7 @@ FS lvm2_pv::get_filesystem_support() fs .shrink = FS::EXTERNAL ; fs .move = FS::GPARTED ; fs .check = FS::EXTERNAL ; + fs .remove = FS::EXTERNAL ; } return fs ; @@ -147,7 +148,15 @@ bool lvm2_pv::check_repair( const Partition & partition, OperationDetail & opera bool lvm2_pv::remove( const Partition & partition, OperationDetail & operationdetail ) { - return true ; + LVM2_PV_Info lvm2_pv_info ; + Glib::ustring vgname = lvm2_pv_info .get_vg_name( partition .get_path() ) ; + Glib::ustring cmd ; + if ( vgname .empty() ) + cmd = "lvm pvremove " + partition .get_path() ; + else + //Must force the removal of a PV which is a member of a VG + cmd = "echo y | lvm pvremove --force --force " + partition .get_path() ; + return ! execute_command( cmd, operationdetail ) ; } } //GParted