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
This commit is contained in:
Mike Fleetwood 2015-11-30 11:57:20 +00:00 committed by Curtis Gedak
parent 317114ffcb
commit 132091269c
3 changed files with 33 additions and 5 deletions

View file

@ -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

View file

@ -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() ;

View file

@ -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