Add creation of LVM2 PVs (#670171)

Add creation of Physical Volumes specifying LVM2 metatdata format:
    lvm pvcreate -M 2 /dev/DEVICE

Also set the partition type to identify its contents as LVM.  Note that
libparted treats every partition type as a file system except LVM which
it treats as a flag, hence GParted displaying "lvm" in the Manage Flags
dialog.  Never the less libparted set the partition types correctly.
For MBR partitioning the type is 8e "Linux LVM" and for GPT partitioning
the type is E6D6D379-F507-44C2-A23C-238F2A3DF928.  Setting the partition
type as LVM is not strictly required as LVM2 scans the contents of all
partitions looking for PVs, but it is best practice.

Bug #670171 - Add LVM PV read-write support
This commit is contained in:
Mike Fleetwood 2012-01-12 13:15:26 +00:00 committed by Curtis Gedak
parent 87625c2b0a
commit c3ab62591b
4 changed files with 31 additions and 11 deletions

View File

@ -49,8 +49,7 @@ void Dialog_Partition_New::Set_Data( const Partition & partition,
std::vector< FS >::iterator f ;
for ( f = this->FILESYSTEMS .begin(); f != this->FILESYSTEMS .end(); f++ )
{
if ( f ->filesystem == GParted::FS_UNKNOWN
|| f ->filesystem == GParted::FS_LVM2_PV
if ( f ->filesystem == GParted::FS_UNKNOWN
|| f ->filesystem == GParted::FS_LUKS
)
//Compensate for subsequent 'f++' ...

View File

@ -2766,11 +2766,14 @@ bool GParted_Core::set_partition_type( const Partition & partition, OperationDet
{
operationdetail .add_child( OperationDetail(
String::ucompose( _("set partition type on %1"), partition .get_path() ) ) ) ;
//Set partition type appropriately for the type of file system stored in the partition.
// Libparted treats every type as a file system, except LVM which it treats as a flag.
bool return_value = false ;
if ( open_device_and_disk( partition .device_path ) )
{
//Lookup libparted file system type using GParted's name, as most match
PedFileSystemType * fs_type =
ped_file_system_type_get( Utils::get_filesystem_string( partition .filesystem ) .c_str() ) ;
@ -2786,13 +2789,15 @@ bool GParted_Core::set_partition_type( const Partition & partition, OperationDet
if ( ! fs_type )
fs_type = ped_file_system_type_get( "ext2" ) ;
if ( fs_type )
if ( fs_type && partition .filesystem != FS_LVM2_PV )
{
lp_partition = ped_disk_get_partition_by_sector( lp_disk, partition .get_sector() ) ;
if ( lp_partition &&
ped_partition_set_system( lp_partition, fs_type ) &&
commit() )
//Also clear any libparted LVM flag so that it doesn't override the file system type
if ( lp_partition &&
ped_partition_set_flag( lp_partition, PED_PARTITION_LVM, 0 ) &&
ped_partition_set_system( lp_partition, fs_type ) &&
commit() )
{
operationdetail .get_last_child() .add_child(
OperationDetail( String::ucompose( _("new partition type: %1"),
@ -2803,6 +2808,22 @@ bool GParted_Core::set_partition_type( const Partition & partition, OperationDet
return_value = true ;
}
}
else if ( partition .filesystem == FS_LVM2_PV )
{
lp_partition = ped_disk_get_partition_by_sector( lp_disk, partition .get_sector() ) ;
if ( lp_partition &&
ped_partition_set_flag( lp_partition, PED_PARTITION_LVM, 1 ) &&
commit() )
{
operationdetail .get_last_child() .add_child(
OperationDetail( String::ucompose( _("new partition flag: %1"),
ped_partition_flag_get_name( PED_PARTITION_LVM ) ),
STATUS_NONE,
FONT_ITALIC ) ) ;
return_value = true ;
}
}
close_device_and_disk() ;
}

View File

@ -407,10 +407,9 @@ Gtk::Menu * Win_GParted::create_format_menu()
for ( unsigned int t =0; t < gparted_core .get_filesystems() .size() ; t++ )
{
//Skip luks, lvm2, and unknown because these are not file systems
//Skip luks and unknown because these are not file systems
if (
gparted_core .get_filesystems()[ t ] .filesystem == GParted::FS_LUKS ||
gparted_core .get_filesystems()[ t ] .filesystem == GParted::FS_LVM2_PV ||
gparted_core .get_filesystems()[ t ] .filesystem == GParted::FS_UNKNOWN
)
continue ;

View File

@ -30,7 +30,8 @@ FS lvm2_pv::get_filesystem_support()
LVM2_PV_Info lvm2_pv_info ;
if ( lvm2_pv_info .is_lvm2_pv_supported() )
{
fs .read = GParted::FS::EXTERNAL ;
fs .read = FS::EXTERNAL ;
fs .create = FS::EXTERNAL ;
}
return fs ;
@ -77,7 +78,7 @@ bool lvm2_pv::write_uuid( const Partition & partition, OperationDetail & operati
bool lvm2_pv::create( const Partition & new_partition, OperationDetail & operationdetail )
{
return true ;
return ! execute_command( "lvm pvcreate -M 2 " + new_partition .get_path(), operationdetail ) ;
}
bool lvm2_pv::resize( const Partition & partition_new, OperationDetail & operationdetail, bool fill_partition )