From 566ebc1b8808c423def95e877f12ebbfb305c4b1 Mon Sep 17 00:00:00 2001 From: Mike Fleetwood Date: Sun, 15 Jan 2012 19:41:28 +0000 Subject: [PATCH] Add LVM2 PV resize, check and move operations (#670171) Copy operation for LVM2 Physical Volumes is deliberately not implemented because it doesn't fit with how LVM2 works and is not safe in the general case without an understanding of its internals. See comment in lvm2_pv::copy() for more details. Bug #670171 - Add LVM PV read-write support --- src/lvm2_pv.cc | 26 ++++++++++++++++++++++++-- 1 file changed, 24 insertions(+), 2 deletions(-) diff --git a/src/lvm2_pv.cc b/src/lvm2_pv.cc index 12bf3a41..b9dfeb6c 100644 --- a/src/lvm2_pv.cc +++ b/src/lvm2_pv.cc @@ -49,6 +49,10 @@ FS lvm2_pv::get_filesystem_support() { fs .read = FS::EXTERNAL ; fs .create = FS::EXTERNAL ; + fs .grow = FS::EXTERNAL ; + fs .shrink = FS::EXTERNAL ; + fs .move = FS::GPARTED ; + fs .check = FS::EXTERNAL ; } return fs ; @@ -100,7 +104,12 @@ bool lvm2_pv::create( const Partition & new_partition, OperationDetail & operati bool lvm2_pv::resize( const Partition & partition_new, OperationDetail & operationdetail, bool fill_partition ) { - return true ; + Glib::ustring size = "" ; + if ( ! fill_partition ) + size = " --setphysicalvolumesize " + + Utils::num_to_str( floor( Utils::sector_to_unit( + partition_new .get_sector_length(), partition_new .sector_size, UNIT_KIB ) ) ) + "K " ; + return ! execute_command( "lvm pvresize -v " + size + partition_new .get_path(), operationdetail ) ; } bool lvm2_pv::move( const Partition & partition_new @@ -115,12 +124,25 @@ bool lvm2_pv::copy( const Glib::ustring & src_part_path , const Glib::ustring & dest_part_path , OperationDetail & operationdetail ) { + //Copy not implemented. + // Metadata fully describing a Volume Group is stored at the start of + // each Physical Volume member. Internally LVM2 primarily uses UUIDs + // to uniquely identify all objects (PVs, VG and LVs) but the interface + // uses device names and VG and LV names. The general case of copying + // a PV could confuse LVM2 because it will result in duplicate objects, + // or even duplicate partial VGs and LVs if they span multiple PVs, so + // it is not safe and should be achieved using other LVM2 commands. A + // specific case of copying a PV is the right action when it is as part + // of the transfer of an exported VG to a remote machine via storage + // which will be detached from the local machine and attached to the + // remote machine, but would probably fit better at a VG manipulation + // layer. Thus copying of PVs is not implemented. return true ; } bool lvm2_pv::check_repair( const Partition & partition, OperationDetail & operationdetail ) { - return true ; + return ! execute_command( "lvm pvck -v " + partition .get_path(), operationdetail ) ; } } //GParted