[gparted] Lazy initialize the cache from querying LVM2 PVs (#160787)
- From: Curtis Gedak <gedakc src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gparted] Lazy initialize the cache from querying LVM2 PVs (#160787)
- Date: Fri, 3 Feb 2012 19:04:54 +0000 (UTC)
commit ff8ad0412057dd6644cd290a8affc71786b5d89f
Author: Mike Fleetwood <mike fleetwood googlemail com>
Date: Sun Dec 11 23:17:52 2011 +0000
Lazy initialize the cache from querying LVM2 PVs (#160787)
Previously when GParted was started LVM2_PV_Info cache was loaded twice,
executing LVM2 PV querying commands twice. Firstly when
lvm2_pv::get_filesystem_support() was checking if LVM2 PV support was
available, and secondly when forced by a refresh in
GParted_Core::set_devices().
Implement lazy initialization. Only load the cache when forced by the
above mentioned refresh or having to return a value when the cache is
not yet loaded. Do not initialize the cache when just checking if LVM2
PV support is available.
Bug #160787 - lvm support
include/LVM2_PV_Info.h | 1 +
src/LVM2_PV_Info.cc | 33 ++++++++++++++++++---------------
2 files changed, 19 insertions(+), 15 deletions(-)
---
diff --git a/include/LVM2_PV_Info.h b/include/LVM2_PV_Info.h
index 9a03ddf..7ddb1a6 100644
--- a/include/LVM2_PV_Info.h
+++ b/include/LVM2_PV_Info.h
@@ -42,6 +42,7 @@ public:
Byte_Value get_free_bytes( const Glib::ustring & path ) ;
bool has_active_lvs( const Glib::ustring & path ) ;
private:
+ void initialize_if_required() ;
void set_commands_found() ;
void load_lvm2_pv_info_cache() ;
Glib::ustring get_pv_attr( const Glib::ustring & path, unsigned int entry ) ;
diff --git a/src/LVM2_PV_Info.cc b/src/LVM2_PV_Info.cc
index 28ef858..dc245f2 100644
--- a/src/LVM2_PV_Info.cc
+++ b/src/LVM2_PV_Info.cc
@@ -51,28 +51,16 @@ Glib::ustring LVM2_PV_Info::dmsetup_info_cache = "" ;
LVM2_PV_Info::LVM2_PV_Info()
{
- //Ensure that cache has been loaded at least once
- if ( ! lvm2_pv_info_cache_initialized )
- {
- lvm2_pv_info_cache_initialized = true ;
- set_commands_found() ;
- load_lvm2_pv_info_cache() ;
- }
}
LVM2_PV_Info::LVM2_PV_Info( bool do_refresh )
{
- //Ensure that cache has been loaded at least once
- if ( ! lvm2_pv_info_cache_initialized )
+ if ( do_refresh )
{
- lvm2_pv_info_cache_initialized = true ;
set_commands_found() ;
- if ( do_refresh == false )
- load_lvm2_pv_info_cache() ;
- }
-
- if ( do_refresh )
load_lvm2_pv_info_cache() ;
+ lvm2_pv_info_cache_initialized = true ;
+ }
}
LVM2_PV_Info::~LVM2_PV_Info()
@@ -81,17 +69,21 @@ LVM2_PV_Info::~LVM2_PV_Info()
bool LVM2_PV_Info::is_lvm2_pv_supported()
{
+ if ( ! lvm2_pv_info_cache_initialized )
+ set_commands_found() ;
return ( lvm_found && dmsetup_found ) ;
}
Glib::ustring LVM2_PV_Info::get_vg_name( const Glib::ustring & path )
{
+ initialize_if_required() ;
return get_pv_attr( path, PVATTR_VG_NAME ) ;
}
//Return number of free bytes in the PV, or -1 for error.
Byte_Value LVM2_PV_Info::get_free_bytes( const Glib::ustring & path )
{
+ initialize_if_required() ;
Byte_Value free_bytes = -1 ;
Glib::ustring fb_str = get_pv_attr( path, PVATTR_PV_FREE ) ;
if ( fb_str != "" )
@@ -108,6 +100,7 @@ Byte_Value LVM2_PV_Info::get_free_bytes( const Glib::ustring & path )
//Report if any LVs are active in the VG stored in the PV.
bool LVM2_PV_Info::has_active_lvs( const Glib::ustring & path )
{
+ initialize_if_required() ;
Glib::ustring vgname = get_pv_attr( path, PVATTR_VG_NAME ) ;
if ( vgname == "" )
//PV not yet included in any VG
@@ -120,6 +113,16 @@ bool LVM2_PV_Info::has_active_lvs( const Glib::ustring & path )
//Private methods
+void LVM2_PV_Info::initialize_if_required()
+{
+ if ( ! lvm2_pv_info_cache_initialized )
+ {
+ set_commands_found() ;
+ load_lvm2_pv_info_cache() ;
+ lvm2_pv_info_cache_initialized = true ;
+ }
+}
+
void LVM2_PV_Info::set_commands_found()
{
//Set status of commands found
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]