[gparted] Implement demand loading of LUKS_Info cache (#760080)



commit 132091269cc1f8a492377e37e0e688816d2a0e07
Author: Mike Fleetwood <mike fleetwood googlemail com>
Date:   Mon Nov 30 11:57:20 2015 +0000

    Implement demand loading of LUKS_Info cache (#760080)
    
    Only load the LUKS_Info cache of active dm-crypt mappings when the first
    LUKS partition is encountered.  Not needed from a performance point of
    view as the longest that I have ever seen "dmsetup table --target crypt"
    take to run is 0.05 seconds.  Just means that the dmsetup command is
    only run when there are LUKS partitions and the information is needed.
    
    Bug 760080 - Implement read-only LUKS support

 include/LUKS_Info.h |    7 ++++++-
 src/GParted_Core.cc |    2 +-
 src/LUKS_Info.cc    |   29 ++++++++++++++++++++++++++---
 3 files changed, 33 insertions(+), 5 deletions(-)
---
diff --git a/include/LUKS_Info.h b/include/LUKS_Info.h
index b7e287f..8b3fe20 100644
--- a/include/LUKS_Info.h
+++ b/include/LUKS_Info.h
@@ -46,11 +46,16 @@ struct LUKS_Mapping
 class LUKS_Info
 {
 public:
-       static void load_cache();
+       static void clear_cache();
        static const LUKS_Mapping & get_cache_entry( const Glib::ustring & path );
 
 private:
+       static void initialise_if_required();
+       static void load_cache();
+       static const LUKS_Mapping & get_cache_entry_internal( const Glib::ustring & path );
+
        static std::vector<LUKS_Mapping> luks_mapping_cache;
+       static bool cache_initialised;
 };
 
 }//GParted
diff --git a/src/GParted_Core.cc b/src/GParted_Core.cc
index 96f7513..ca6c01f 100644
--- a/src/GParted_Core.cc
+++ b/src/GParted_Core.cc
@@ -163,7 +163,7 @@ void GParted_Core::set_devices_thread( std::vector<Device> * pdevices )
        LVM2_PV_Info::clear_cache();            // Cache automatically loaded if and when needed
        btrfs::clear_cache();                   // Cache incrementally loaded if and when needed
        SWRaid_Info::load_cache();
-       LUKS_Info::load_cache();
+       LUKS_Info::clear_cache();               // Cache automatically loaded if and when needed
 
        init_maps() ;
        
diff --git a/src/LUKS_Info.cc b/src/LUKS_Info.cc
index c3b6f11..8337295 100644
--- a/src/LUKS_Info.cc
+++ b/src/LUKS_Info.cc
@@ -31,6 +31,31 @@ namespace GParted
 //     {name="sdb6_crypt", major=8, minor=22, path="/dev/sdb6", offset=2097152, length=534773760}
 std::vector<LUKS_Mapping> LUKS_Info::luks_mapping_cache;
 
+bool LUKS_Info::cache_initialised = false;
+
+void LUKS_Info::clear_cache()
+{
+       luks_mapping_cache.clear();
+       cache_initialised = false;
+}
+
+const LUKS_Mapping & LUKS_Info::get_cache_entry( const Glib::ustring & path )
+{
+       initialise_if_required();
+       return get_cache_entry_internal( path );
+}
+
+//Private methods
+
+void LUKS_Info::initialise_if_required()
+{
+       if ( ! cache_initialised )
+       {
+               load_cache();
+               cache_initialised = true;
+       }
+}
+
 void LUKS_Info::load_cache()
 {
        luks_mapping_cache.clear();
@@ -108,7 +133,7 @@ void LUKS_Info::load_cache()
 
 // Return LUKS cache entry for the named underlying block device path,
 // or not found substitute when no entry exists.
-const LUKS_Mapping & LUKS_Info::get_cache_entry( const Glib::ustring & path )
+const LUKS_Mapping & LUKS_Info::get_cache_entry_internal( const Glib::ustring & path )
 {
        // First scan the cache looking for an underlying block device path match.
        // (Totally in memory)
@@ -142,6 +167,4 @@ const LUKS_Mapping & LUKS_Info::get_cache_entry( const Glib::ustring & path )
        return not_found;
 }
 
-//Private methods
-
 }//GParted


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