Delay loading LVM2_PV_info cache until actually needed (#750582)

The lvm query commands were always run and the cache loaded even if
GParted, actually blkid, didn't identify any LVM2 PVs.  (GParted uses
libparted and blkid to identify partition content and the lvm commands
to provide the needed configuration details).

Now implement complete lazy initialization of the cache.  Never force
loading of the cache.  The cache is only loaded when the first value is
accessed from it.  When there are no LVM2 PVs, the cache is never
queried, so never loaded.  All the needed infrastructure for delayed
loading was previously added by this commit from 2011-12-11:
    ff8ad04120
    Lazy initialize the cache from querying LVM2 PVs (#160787)
Every public member function which access values from the cache already
calls initialize_if_required().  Just need to replace force loading of
the cache with a function which just clears the cache.

On my desktop, only when there are no LVM2 PVs, not loading the cache
and therefore not executing these external commands in
load_lvm2_pv_info_cache() saves 1.0 seconds of the 3.7 seconds it takes
to perform the a refresh in GParted:
    lvm vgscan
    lvm pvs ... -o pv_name,...
    lvm pvs ... -o vg_name,...

Bug 750582 - Refactor the LVM2_PV_Info module object interface and
             internal cache representation
This commit is contained in:
Mike Fleetwood 2015-06-07 21:42:08 +01:00 committed by Curtis Gedak
parent e6f7ea01f9
commit 9be8d37600
3 changed files with 9 additions and 9 deletions

View File

@ -49,8 +49,8 @@ struct LVM2_VG
class LVM2_PV_Info
{
public:
static void load_cache();
static bool is_lvm2_pv_supported();
static void clear_cache();
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 );

View File

@ -150,7 +150,7 @@ void GParted_Core::set_devices_thread( std::vector<Device> * pdevices )
Proc_Partitions_Info pp_info( true ) ; //Refresh cache of proc partition information
FS_Info fs_info( true ) ; //Refresh cache of file system information
DMRaid dmraid( true ) ; //Refresh cache of dmraid device information
LVM2_PV_Info::load_cache(); // Refresh cache of LVM2 PV information
LVM2_PV_Info::clear_cache(); // Cache automatically loaded if and when needed
btrfs::clear_cache() ;
init_maps() ;

View File

@ -70,19 +70,19 @@ std::vector<LVM2_PV> LVM2_PV_Info::lvm2_pv_cache;
std::vector<LVM2_VG> LVM2_PV_Info::lvm2_vg_cache;
std::vector<Glib::ustring> LVM2_PV_Info::error_messages ;
void LVM2_PV_Info::load_cache()
{
set_command_found();
load_lvm2_pv_info_cache();
lvm2_pv_info_cache_initialized = true;
}
bool LVM2_PV_Info::is_lvm2_pv_supported()
{
set_command_found() ;
return ( lvm_found ) ;
}
void LVM2_PV_Info::clear_cache()
{
lvm2_pv_cache.clear();
lvm2_vg_cache.clear();
lvm2_pv_info_cache_initialized = false;
}
Glib::ustring LVM2_PV_Info::get_vg_name( const Glib::ustring & path )
{
initialize_if_required() ;