Stop needing any LVM2_PV_Info objects (#750582)

The LVM2_PV_Info cache had a pretend multi-object interface, yet all the
data is static.  An LVM2_PV_Info object doesn't contain any member
variables, yet was needed just to call the member functions.

Make all the member functions static removing the need to use any
LVM2_PV_Info objects.

Bug 750582 - Refactor the LVM2_PV_Info module object interface and
             internal cache representation
This commit is contained in:
Mike Fleetwood 2015-06-05 20:54:37 +01:00 committed by Curtis Gedak
parent 81f0b934bc
commit 2c5e7b0d90
6 changed files with 31 additions and 39 deletions

View File

@ -34,22 +34,22 @@ class LVM2_PV_Info
{ {
public: public:
static void load_cache(); static void load_cache();
bool is_lvm2_pv_supported() ; static bool is_lvm2_pv_supported();
Glib::ustring get_vg_name( const Glib::ustring & path ) ; static Glib::ustring get_vg_name( const Glib::ustring & path );
Byte_Value get_size_bytes( const Glib::ustring & path ) ; static Byte_Value get_size_bytes( const Glib::ustring & path );
Byte_Value get_free_bytes( const Glib::ustring & path ) ; static Byte_Value get_free_bytes( const Glib::ustring & path );
bool has_active_lvs( const Glib::ustring & path ) ; static bool has_active_lvs( const Glib::ustring & path );
bool is_vg_exported( const Glib::ustring & vgname ) ; static bool is_vg_exported( const Glib::ustring & vgname );
std::vector<Glib::ustring> get_vg_members( const Glib::ustring & vgname ) ; static std::vector<Glib::ustring> get_vg_members( const Glib::ustring & vgname );
std::vector<Glib::ustring> get_error_messages( const Glib::ustring & path ) ; static std::vector<Glib::ustring> get_error_messages( const Glib::ustring & path );
private: private:
void initialize_if_required() ; static void initialize_if_required();
static void set_command_found(); static void set_command_found();
static void load_lvm2_pv_info_cache(); static void load_lvm2_pv_info_cache();
Glib::ustring get_pv_attr_by_path( const Glib::ustring & path, unsigned int entry ) const ; static Glib::ustring get_pv_attr_by_path( const Glib::ustring & path, unsigned int entry );
Glib::ustring get_pv_attr_by_row( unsigned int row, unsigned int entry ) const ; static Glib::ustring get_pv_attr_by_row( unsigned int row, unsigned int entry );
Glib::ustring get_vg_attr_by_name( const Glib::ustring & vgname, unsigned int entry ) const ; static Glib::ustring get_vg_attr_by_name( const Glib::ustring & vgname, unsigned int entry );
Glib::ustring get_vg_attr_by_row( unsigned int row, unsigned int entry ) const ; static Glib::ustring get_vg_attr_by_row( unsigned int row, unsigned int entry );
static Glib::ustring get_attr_by_name( const std::vector<Glib::ustring> cache, static Glib::ustring get_attr_by_name( const std::vector<Glib::ustring> cache,
const Glib::ustring name, unsigned int entry ) ; const Glib::ustring name, unsigned int entry ) ;
static Glib::ustring get_attr_by_row( const std::vector<Glib::ustring> cache, static Glib::ustring get_attr_by_row( const std::vector<Glib::ustring> cache,

View File

@ -216,10 +216,9 @@ void Dialog_Partition_Info::Display_Info()
Sector ptn_sectors = partition .get_sector_length() ; Sector ptn_sectors = partition .get_sector_length() ;
LVM2_PV_Info lvm2_pv_info ;
Glib::ustring vgname = "" ; //Also used in partition status message Glib::ustring vgname = "" ; //Also used in partition status message
if ( partition .filesystem == FS_LVM2_PV ) if ( partition .filesystem == FS_LVM2_PV )
vgname = lvm2_pv_info .get_vg_name( partition .get_path() ) ; vgname = LVM2_PV_Info::get_vg_name( partition.get_path() );
//initialize table top and bottom row number attach trackers //initialize table top and bottom row number attach trackers
int top = 0 , bottom = 1 ; //Left field & value pairs int top = 0 , bottom = 1 ; //Left field & value pairs
@ -344,7 +343,7 @@ void Dialog_Partition_Info::Display_Info()
* the operating system. * the operating system.
*/ */
str_temp = _("Not active (Not a member of any volume group)") ; str_temp = _("Not active (Not a member of any volume group)") ;
else if ( lvm2_pv_info .is_vg_exported( vgname ) ) else if ( LVM2_PV_Info::is_vg_exported( vgname ) )
/* TO TRANSLATORS: Not active and exported /* TO TRANSLATORS: Not active and exported
* means that the partition is a member of an LVM volume group but * means that the partition is a member of an LVM volume group but
* the volume group is not active and not being used by the operating system. * the volume group is not active and not being used by the operating system.
@ -396,7 +395,7 @@ void Dialog_Partition_Info::Display_Info()
break ; break ;
case FS_LVM2_PV: case FS_LVM2_PV:
if ( ! vgname .empty() ) if ( ! vgname .empty() )
members = lvm2_pv_info .get_vg_members( vgname ) ; members = LVM2_PV_Info::get_vg_members( vgname );
break ; break ;
default: default:
break ; break ;

View File

@ -1689,7 +1689,6 @@ void GParted_Core::set_mountpoints( std::vector<Partition> & partitions )
#ifndef USE_LIBPARTED_DMRAID #ifndef USE_LIBPARTED_DMRAID
DMRaid dmraid ; //Use cache of dmraid device information DMRaid dmraid ; //Use cache of dmraid device information
#endif #endif
LVM2_PV_Info lvm2_pv_info ;
for ( unsigned int t = 0 ; t < partitions .size() ; t++ ) for ( unsigned int t = 0 ; t < partitions .size() ; t++ )
{ {
if ( ( partitions[ t ] .type == GParted::TYPE_PRIMARY || if ( ( partitions[ t ] .type == GParted::TYPE_PRIMARY ||
@ -1748,7 +1747,7 @@ void GParted_Core::set_mountpoints( std::vector<Partition> & partitions )
set_mountpoints( partitions[ t ] .logicals ) ; set_mountpoints( partitions[ t ] .logicals ) ;
else if ( partitions[ t ] .filesystem == GParted::FS_LVM2_PV ) else if ( partitions[ t ] .filesystem == GParted::FS_LVM2_PV )
{ {
Glib::ustring vgname = lvm2_pv_info. get_vg_name( partitions[t].get_path() ) ; Glib::ustring vgname = LVM2_PV_Info::get_vg_name( partitions[t].get_path() );
if ( ! vgname .empty() ) if ( ! vgname .empty() )
partitions[ t ] .add_mountpoint( vgname ) ; partitions[ t ] .add_mountpoint( vgname ) ;
} }
@ -3477,11 +3476,10 @@ bool GParted_Core::filesystem_resize_disallowed( const Partition & partition )
if ( partition .filesystem == FS_LVM2_PV ) if ( partition .filesystem == FS_LVM2_PV )
{ {
//The LVM2 PV can't be resized when it's a member of an export VG //The LVM2 PV can't be resized when it's a member of an export VG
LVM2_PV_Info lvm2_pv_info ; Glib::ustring vgname = LVM2_PV_Info::get_vg_name( partition.get_path() );
Glib::ustring vgname = lvm2_pv_info .get_vg_name( partition .get_path() ) ;
if ( vgname .empty() ) if ( vgname .empty() )
return false ; return false ;
return lvm2_pv_info .is_vg_exported( vgname ) ; return LVM2_PV_Info::is_vg_exported( vgname );
} }
return false ; return false ;
} }

View File

@ -274,22 +274,22 @@ void LVM2_PV_Info::load_lvm2_pv_info_cache()
} }
} }
Glib::ustring LVM2_PV_Info::get_pv_attr_by_path( const Glib::ustring & path, unsigned int entry ) const Glib::ustring LVM2_PV_Info::get_pv_attr_by_path( const Glib::ustring & path, unsigned int entry )
{ {
return get_attr_by_name( lvm2_pv_cache, path, entry ) ; return get_attr_by_name( lvm2_pv_cache, path, entry ) ;
} }
Glib::ustring LVM2_PV_Info::get_pv_attr_by_row( unsigned int row, unsigned int entry ) const Glib::ustring LVM2_PV_Info::get_pv_attr_by_row( unsigned int row, unsigned int entry )
{ {
return get_attr_by_row( lvm2_pv_cache, row, entry ) ; return get_attr_by_row( lvm2_pv_cache, row, entry ) ;
} }
Glib::ustring LVM2_PV_Info::get_vg_attr_by_name( const Glib::ustring & vgname, unsigned int entry ) const Glib::ustring LVM2_PV_Info::get_vg_attr_by_name( const Glib::ustring & vgname, unsigned int entry )
{ {
return get_attr_by_name( lvm2_vg_cache, vgname, entry ) ; return get_attr_by_name( lvm2_vg_cache, vgname, entry ) ;
} }
Glib::ustring LVM2_PV_Info::get_vg_attr_by_row( unsigned int row, unsigned int entry ) const Glib::ustring LVM2_PV_Info::get_vg_attr_by_row( unsigned int row, unsigned int entry )
{ {
return get_attr_by_row( lvm2_vg_cache, row, entry ) ; return get_attr_by_row( lvm2_vg_cache, row, entry ) ;
} }

View File

@ -2955,11 +2955,10 @@ bool Win_GParted::remove_non_empty_lvm2_pv_dialog( const OperationType optype )
tmp_msg += "\n\n" ; tmp_msg += "\n\n" ;
tmp_msg += _( "Do you want to continue to forcibly delete the Physical Volume?" ) ; tmp_msg += _( "Do you want to continue to forcibly delete the Physical Volume?" ) ;
LVM2_PV_Info lvm2_pv_info ; Glib::ustring vgname = LVM2_PV_Info::get_vg_name( selected_partition_ptr->get_path() );
Glib::ustring vgname = lvm2_pv_info.get_vg_name( selected_partition_ptr->get_path() );
std::vector<Glib::ustring> members ; std::vector<Glib::ustring> members ;
if ( ! vgname .empty() ) if ( ! vgname .empty() )
members = lvm2_pv_info .get_vg_members( vgname ) ; members = LVM2_PV_Info::get_vg_members( vgname );
//Single copy of each string for translation purposes //Single copy of each string for translation purposes
const Glib::ustring vgname_label = _( "Volume Group:" ) ; const Glib::ustring vgname_label = _( "Volume Group:" ) ;

View File

@ -49,8 +49,7 @@ FS lvm2_pv::get_filesystem_support()
FS fs ; FS fs ;
fs .filesystem = GParted::FS_LVM2_PV ; fs .filesystem = GParted::FS_LVM2_PV ;
LVM2_PV_Info lvm2_pv_info ; if ( LVM2_PV_Info::is_lvm2_pv_supported() )
if ( lvm2_pv_info .is_lvm2_pv_supported() )
{ {
fs .busy = FS::EXTERNAL ; fs .busy = FS::EXTERNAL ;
fs .read = FS::EXTERNAL ; fs .read = FS::EXTERNAL ;
@ -75,15 +74,13 @@ FS lvm2_pv::get_filesystem_support()
bool lvm2_pv::is_busy( const Glib::ustring & path ) bool lvm2_pv::is_busy( const Glib::ustring & path )
{ {
LVM2_PV_Info lvm2_pv_info ; return LVM2_PV_Info::has_active_lvs( path );
return lvm2_pv_info .has_active_lvs( path ) ;
} }
void lvm2_pv::set_used_sectors( Partition & partition ) void lvm2_pv::set_used_sectors( Partition & partition )
{ {
LVM2_PV_Info lvm2_pv_info ; T = (Sector) LVM2_PV_Info::get_size_bytes( partition.get_path() );
T = (Sector) lvm2_pv_info .get_size_bytes( partition .get_path() ) ; N = (Sector) LVM2_PV_Info::get_free_bytes( partition.get_path() );
N = (Sector) lvm2_pv_info .get_free_bytes( partition .get_path() ) ;
if ( T > -1 && N > -1 ) if ( T > -1 && N > -1 )
{ {
T = Utils::round( T / double(partition .sector_size) ) ; T = Utils::round( T / double(partition .sector_size) ) ;
@ -91,7 +88,7 @@ void lvm2_pv::set_used_sectors( Partition & partition )
partition .set_sector_usage( T, N ) ; partition .set_sector_usage( T, N ) ;
} }
std::vector<Glib::ustring> error_messages = lvm2_pv_info .get_error_messages( partition .get_path() ) ; std::vector<Glib::ustring> error_messages = LVM2_PV_Info::get_error_messages( partition.get_path() );
if ( ! error_messages .empty() ) if ( ! error_messages .empty() )
{ {
for ( unsigned int i = 0 ; i < error_messages .size() ; i ++ ) for ( unsigned int i = 0 ; i < error_messages .size() ; i ++ )
@ -121,8 +118,7 @@ bool lvm2_pv::check_repair( const Partition & partition, OperationDetail & opera
bool lvm2_pv::remove( const Partition & partition, OperationDetail & operationdetail ) bool lvm2_pv::remove( const Partition & partition, OperationDetail & operationdetail )
{ {
LVM2_PV_Info lvm2_pv_info ; Glib::ustring vgname = LVM2_PV_Info::get_vg_name( partition.get_path() );
Glib::ustring vgname = lvm2_pv_info .get_vg_name( partition .get_path() ) ;
Glib::ustring cmd ; Glib::ustring cmd ;
if ( vgname .empty() ) if ( vgname .empty() )
cmd = "lvm pvremove " + partition .get_path() ; cmd = "lvm pvremove " + partition .get_path() ;