[gparted] Stop needing any LVM2_PV_Info objects (#750582)



commit 2c5e7b0d90d089858b063632d9b2eafcc17b6cbd
Author: Mike Fleetwood <mike fleetwood googlemail com>
Date:   Fri Jun 5 20:54:37 2015 +0100

    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

 include/LVM2_PV_Info.h       |   26 +++++++++++++-------------
 src/Dialog_Partition_Info.cc |    7 +++----
 src/GParted_Core.cc          |    8 +++-----
 src/LVM2_PV_Info.cc          |    8 ++++----
 src/Win_GParted.cc           |    5 ++---
 src/lvm2_pv.cc               |   16 ++++++----------
 6 files changed, 31 insertions(+), 39 deletions(-)
---
diff --git a/include/LVM2_PV_Info.h b/include/LVM2_PV_Info.h
index ac48913..b474bd6 100644
--- a/include/LVM2_PV_Info.h
+++ b/include/LVM2_PV_Info.h
@@ -34,22 +34,22 @@ class LVM2_PV_Info
 {
 public:
        static void load_cache();
-       bool is_lvm2_pv_supported() ;
-       Glib::ustring get_vg_name( const Glib::ustring & path ) ;
-       Byte_Value get_size_bytes( const Glib::ustring & path ) ;
-       Byte_Value get_free_bytes( const Glib::ustring & path ) ;
-       bool has_active_lvs( const Glib::ustring & path ) ;
-       bool is_vg_exported( const Glib::ustring & vgname ) ;
-       std::vector<Glib::ustring> get_vg_members( const Glib::ustring & vgname ) ;
-       std::vector<Glib::ustring> get_error_messages( const Glib::ustring & path ) ;
+       static bool is_lvm2_pv_supported();
+       static Glib::ustring get_vg_name( const Glib::ustring & path );
+       static Byte_Value get_size_bytes( const Glib::ustring & path );
+       static Byte_Value get_free_bytes( const Glib::ustring & path );
+       static bool has_active_lvs( const Glib::ustring & path );
+       static bool is_vg_exported( const Glib::ustring & vgname );
+       static std::vector<Glib::ustring> get_vg_members( const Glib::ustring & vgname );
+       static std::vector<Glib::ustring> get_error_messages( const Glib::ustring & path );
 private:
-       void initialize_if_required() ;
+       static void initialize_if_required();
        static void set_command_found();
        static void load_lvm2_pv_info_cache();
-       Glib::ustring get_pv_attr_by_path( const Glib::ustring & path, unsigned int entry ) const ;
-       Glib::ustring get_pv_attr_by_row( unsigned int row, unsigned int entry ) const ;
-       Glib::ustring get_vg_attr_by_name( const Glib::ustring & vgname, unsigned int entry ) const ;
-       Glib::ustring get_vg_attr_by_row( unsigned int row, unsigned int entry ) const ;
+       static Glib::ustring get_pv_attr_by_path( const Glib::ustring & path, unsigned int entry );
+       static Glib::ustring get_pv_attr_by_row( unsigned int row, unsigned int entry );
+       static Glib::ustring get_vg_attr_by_name( const Glib::ustring & vgname, unsigned int entry );
+       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,
                                               const Glib::ustring name, unsigned int entry ) ;
        static Glib::ustring get_attr_by_row( const std::vector<Glib::ustring> cache,
diff --git a/src/Dialog_Partition_Info.cc b/src/Dialog_Partition_Info.cc
index adeb21d..4f5e167 100644
--- a/src/Dialog_Partition_Info.cc
+++ b/src/Dialog_Partition_Info.cc
@@ -216,10 +216,9 @@ void Dialog_Partition_Info::Display_Info()
 
        Sector ptn_sectors = partition .get_sector_length() ;
 
-       LVM2_PV_Info lvm2_pv_info ;
        Glib::ustring vgname = "" ;  //Also used in partition status message
        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
        int top = 0     , bottom = 1 ;      //Left field & value pairs
@@ -344,7 +343,7 @@ void Dialog_Partition_Info::Display_Info()
                                 * the operating system.
                                 */
                                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
                                 * 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.
@@ -396,7 +395,7 @@ void Dialog_Partition_Info::Display_Info()
                                break ;
                        case FS_LVM2_PV:
                                if ( ! vgname .empty() )
-                                       members = lvm2_pv_info .get_vg_members( vgname ) ;
+                                       members = LVM2_PV_Info::get_vg_members( vgname );
                                break ;
                        default:
                                break ;
diff --git a/src/GParted_Core.cc b/src/GParted_Core.cc
index cb6d2be..84738ca 100644
--- a/src/GParted_Core.cc
+++ b/src/GParted_Core.cc
@@ -1689,7 +1689,6 @@ void GParted_Core::set_mountpoints( std::vector<Partition> & partitions )
 #ifndef USE_LIBPARTED_DMRAID
        DMRaid dmraid ; //Use cache of dmraid device information
 #endif
-       LVM2_PV_Info lvm2_pv_info ;
        for ( unsigned int t = 0 ; t < partitions .size() ; t++ )
        {
                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 ) ;
                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() )
                                partitions[ t ] .add_mountpoint( vgname ) ;
                }
@@ -3477,11 +3476,10 @@ bool GParted_Core::filesystem_resize_disallowed( const Partition & partition )
        if ( partition .filesystem == FS_LVM2_PV )
        {
                //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() )
                        return false ;
-               return lvm2_pv_info .is_vg_exported( vgname ) ;
+               return LVM2_PV_Info::is_vg_exported( vgname );
        }
        return false ;
 }
diff --git a/src/LVM2_PV_Info.cc b/src/LVM2_PV_Info.cc
index f43a258..ee16d34 100644
--- a/src/LVM2_PV_Info.cc
+++ b/src/LVM2_PV_Info.cc
@@ -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 ) ;
 }
 
-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 ) ;
 }
 
-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 ) ;
 }
 
-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 ) ;
 }
diff --git a/src/Win_GParted.cc b/src/Win_GParted.cc
index cdb08e3..5d3b9e4 100644
--- a/src/Win_GParted.cc
+++ b/src/Win_GParted.cc
@@ -2955,11 +2955,10 @@ bool Win_GParted::remove_non_empty_lvm2_pv_dialog( const OperationType optype )
        tmp_msg += "\n\n" ;
        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 ;
        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
        const Glib::ustring vgname_label  = _( "Volume Group:" ) ;
diff --git a/src/lvm2_pv.cc b/src/lvm2_pv.cc
index e94d4f8..21b412a 100644
--- a/src/lvm2_pv.cc
+++ b/src/lvm2_pv.cc
@@ -49,8 +49,7 @@ FS lvm2_pv::get_filesystem_support()
        FS fs ;
        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 .read   = FS::EXTERNAL ;
@@ -75,15 +74,13 @@ FS lvm2_pv::get_filesystem_support()
 
 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 )
 {
-       LVM2_PV_Info lvm2_pv_info ;
-       T = (Sector) lvm2_pv_info .get_size_bytes( partition .get_path() ) ;
-       N = (Sector) lvm2_pv_info .get_free_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() );
        if ( T > -1 && N > -1 )
        {
                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 ) ;
        }
 
-       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() )
        {
                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 )
 {
-       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 ;
        if ( vgname .empty() )
                cmd = "lvm pvremove " + partition .get_path() ;


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]