Report space usage of LVM2 PVs (#160787)

Add minimal support for just reporting the space usage of LVM2 PVs.
Accept libparted / blkid detection of LVM2 PVs first, falling back on
GParted's specific detection code otherwise.  Maintain LVM not supported
warning message.

Bug #160787 - lvm support
This commit is contained in:
Mike Fleetwood 2011-11-28 12:33:51 +00:00 committed by Curtis Gedak
parent 391e5e12f9
commit abd0dd0426
6 changed files with 170 additions and 8 deletions

View file

@ -49,6 +49,7 @@ EXTRA_DIST = \
i18n.h \
jfs.h \
linux_swap.h \
lvm2_pv.h \
nilfs2.h \
ntfs.h \
reiser4.h \

50
include/lvm2_pv.h Normal file
View file

@ -0,0 +1,50 @@
/* Copyright (C) 2012 Mike Fleetwood
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Library General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*/
#ifndef LVM2_PV_H_
#define LVM2_PV_H_
#include "../include/FileSystem.h"
namespace GParted
{
class lvm2_pv : public FileSystem
{
public:
FS get_filesystem_support() ;
void set_used_sectors( Partition & partition ) ;
void read_label( Partition & partition ) ;
bool write_label( const Partition & partition, OperationDetail & operationdetail ) ;
void read_uuid( Partition & partition ) ;
bool write_uuid( const Partition & partition, OperationDetail & operationdetail ) ;
bool create( const Partition & new_partition, OperationDetail & operationdetail ) ;
bool resize( const Partition & partition_new, OperationDetail & operationdetail, bool fill_partition = false ) ;
bool move( const Partition & partition_new
, const Partition & partition_old
, OperationDetail & operationdetail
) ;
bool copy( const Glib::ustring & src_part_path
, const Glib::ustring & dest_part_path
, OperationDetail & operationdetail ) ;
bool check_repair( const Partition & partition, OperationDetail & operationdetail ) ;
};
} //GParted
#endif /*LVM2_PV_H_*/

View file

@ -39,6 +39,7 @@ src/hfs.cc
src/hfsplus.cc
src/jfs.cc
src/linux_swap.cc
src/lvm2_pv.cc
src/main.cc
src/ntfs.cc
src/nilfs2.cc

View file

@ -38,6 +38,7 @@
#include "../include/fat16.h"
#include "../include/fat32.h"
#include "../include/linux_swap.h"
#include "../include/lvm2_pv.h"
#include "../include/reiserfs.h"
#include "../include/nilfs2.h"
#include "../include/ntfs.h"
@ -127,6 +128,9 @@ void GParted_Core::find_supported_filesystems()
linux_swap fs_linux_swap;
FILESYSTEMS .push_back( fs_linux_swap .get_filesystem_support() ) ;
lvm2_pv fs_lvm2_pv;
FILESYSTEMS .push_back( fs_lvm2_pv .get_filesystem_support() ) ;
nilfs2 fs_nilfs2;
FILESYSTEMS .push_back( fs_nilfs2 .get_filesystem_support() ) ;
@ -145,10 +149,6 @@ void GParted_Core::find_supported_filesystems()
xfs fs_xfs;
FILESYSTEMS .push_back( fs_xfs .get_filesystem_support() ) ;
//lvm2 physical volume -- not a file system
fs_notsupp .filesystem = GParted::FS_LVM2_PV ;
FILESYSTEMS .push_back( fs_notsupp ) ;
//luks encryption-- not a file system
fs_notsupp .filesystem = GParted::FS_LUKS ;
FILESYSTEMS .push_back( fs_notsupp ) ;
@ -1102,6 +1102,9 @@ GParted::FILESYSTEM GParted_Core::get_filesystem()
fs_type = fs_info.get_fs_type( get_partition_path( lp_partition ) ) ;
}
Glib::ustring lvm_warning = _( "Logical Volume Management is not yet supported." ) ;
lvm_warning += "\n" ;
if ( ! fs_type .empty() )
{
if ( fs_type == "extended" )
@ -1124,6 +1127,11 @@ GParted::FILESYSTEM GParted_Core::get_filesystem()
fs_type == "linux-swap(old)" ||
fs_type == "swap" )
return GParted::FS_LINUX_SWAP ;
else if ( fs_type == "LVM2_member" )
{
partition_temp .messages .push_back( lvm_warning ) ;
return GParted::FS_LVM2_PV ;
}
else if ( fs_type == "fat16" )
return GParted::FS_FAT16 ;
else if ( fs_type == "fat32" )
@ -1194,9 +1202,7 @@ GParted::FILESYSTEM GParted_Core::get_filesystem()
if ( 0 == memcmp( magic1, "LABELONE", 8 )
&& 0 == memcmp( magic2, "LVM2", 4 ) )
{
temp = _( "Logical Volume Management is not yet supported." ) ;
temp += "\n" ;
partition_temp .messages .push_back( temp ) ;
partition_temp .messages .push_back( lvm_warning ) ;
return GParted::FS_LVM2_PV ;
}
}
@ -1412,7 +1418,6 @@ void GParted_Core::set_used_sectors( std::vector<Partition> & partitions )
{
if ( partitions[ t ] .filesystem != GParted::FS_LINUX_SWAP &&
partitions[ t ] .filesystem != GParted::FS_LUKS &&
partitions[ t ] .filesystem != GParted::FS_LVM2_PV &&
partitions[ t ] .filesystem != GParted::FS_UNKNOWN
)
{
@ -3007,6 +3012,7 @@ bool GParted_Core::set_proper_filesystem( const FILESYSTEM & filesystem )
case FS_EXT3 : p_filesystem = new ext3() ; break ;
case FS_EXT4 : p_filesystem = new ext4() ; break ;
case FS_LINUX_SWAP : p_filesystem = new linux_swap() ; break ;
case FS_LVM2_PV : p_filesystem = new lvm2_pv() ; break ;
case FS_FAT16 : p_filesystem = new fat16() ; break ;
case FS_FAT32 : p_filesystem = new fat32() ; break ;
case FS_NILFS2 : p_filesystem = new nilfs2() ; break ;

View file

@ -58,6 +58,7 @@ gpartedbin_SOURCES = \
hfsplus.cc \
jfs.cc \
linux_swap.cc \
lvm2_pv.cc \
main.cc \
nilfs2.cc \
ntfs.cc \

103
src/lvm2_pv.cc Normal file
View file

@ -0,0 +1,103 @@
/* Copyright (C) 2012 Mike Fleetwood
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Library General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*/
#include "../include/lvm2_pv.h"
namespace GParted
{
FS lvm2_pv::get_filesystem_support()
{
FS fs ;
fs .filesystem = GParted::FS_LVM2_PV ;
if ( ! Glib::find_program_in_path( "lvm" ) .empty() )
{
fs .read = GParted::FS::EXTERNAL ;
}
return fs ;
}
void lvm2_pv::set_used_sectors( Partition & partition )
{
if ( ! Utils::execute_command( "lvm pvs --units b --noheadings --nosuffix -o pv_free " + partition .get_path(), output, error, true ) )
{
gdouble free_bytes = g_ascii_strtod( output .c_str(), NULL ) ;
partition .Set_Unused( Utils::round( free_bytes / double(partition .sector_size) ) ) ;
}
else
{
if ( ! output .empty() )
partition .messages .push_back( output ) ;
if ( ! error .empty() )
partition .messages .push_back( error ) ;
}
}
void lvm2_pv::read_label( Partition & partition )
{
return ;
}
bool lvm2_pv::write_label( const Partition & partition, OperationDetail & operationdetail )
{
return true ;
}
void lvm2_pv::read_uuid( Partition & partition )
{
}
bool lvm2_pv::write_uuid( const Partition & partition, OperationDetail & operationdetail )
{
return true ;
}
bool lvm2_pv::create( const Partition & new_partition, OperationDetail & operationdetail )
{
return true ;
}
bool lvm2_pv::resize( const Partition & partition_new, OperationDetail & operationdetail, bool fill_partition )
{
return true ;
}
bool lvm2_pv::move( const Partition & partition_new
, const Partition & partition_old
, OperationDetail & operationdetail
)
{
return true ;
}
bool lvm2_pv::copy( const Glib::ustring & src_part_path
, const Glib::ustring & dest_part_path
, OperationDetail & operationdetail )
{
return true ;
}
bool lvm2_pv::check_repair( const Partition & partition, OperationDetail & operationdetail )
{
return true ;
}
} //GParted