[gparted] Display any errors from querying LVM2 PVs to the user (#160787)



commit c24170927d545d9f3cde4ed2d98dfc122505920d
Author: Mike Fleetwood <mike fleetwood googlemail com>
Date:   Thu Feb 9 20:58:55 2012 +0000

    Display any errors from querying LVM2 PVs to the user (#160787)
    
    Previously any errors which occurred when running LVM commands used to
    load the LVM2_PV_Info cache were simply ignored and the cache wasn't
    loaded.  This lead to missing information about LVM2 PVs, but the user
    had no indication as to why.
    
    Now when any errors occur the command ran and all output is captured.
    This is displayed to the user, along with a suitable warning message, in
    the Partition Information dialog.
    
    Bug #160787 - lvm support

 include/LVM2_PV_Info.h |    2 ++
 src/LVM2_PV_Info.cc    |   28 +++++++++++++++++++++++++++-
 src/lvm2_pv.cc         |    7 +++++++
 3 files changed, 36 insertions(+), 1 deletions(-)
---
diff --git a/include/LVM2_PV_Info.h b/include/LVM2_PV_Info.h
index c936103..c0039bb 100644
--- a/include/LVM2_PV_Info.h
+++ b/include/LVM2_PV_Info.h
@@ -41,6 +41,7 @@ public:
 	Glib::ustring get_vg_name( const Glib::ustring & path ) ;
 	Byte_Value get_free_bytes( const Glib::ustring & path ) ;
 	bool has_active_lvs( const Glib::ustring & path ) ;
+	std::vector<Glib::ustring> get_error_messages() ;
 private:
 	void initialize_if_required() ;
 	void set_command_found() ;
@@ -49,6 +50,7 @@ private:
 	static bool lvm2_pv_info_cache_initialized ;
 	static bool lvm_found ;
 	static std::vector<Glib::ustring> lvm2_pv_cache ;
+	static std::vector<Glib::ustring> error_messages ;
 };
 
 }//GParted
diff --git a/src/LVM2_PV_Info.cc b/src/LVM2_PV_Info.cc
index 9397de9..6497ad4 100644
--- a/src/LVM2_PV_Info.cc
+++ b/src/LVM2_PV_Info.cc
@@ -46,12 +46,14 @@ enum PV_ATTRIBUTE
 //                         "/dev/sda13,830472192,GParted_VG3,lvol0,-wi-a-",
 //                         "/dev/sda13,830472192,GParted_VG3,lvol1,-wi-a-",
 //                         "/dev/sda13,830472192,GParted_VG3,,"]
+//  error_messages      - String vector storing error messsages.
 
 
 //Initialize static data elements
 bool LVM2_PV_Info::lvm2_pv_info_cache_initialized = false ;
 bool LVM2_PV_Info::lvm_found = false ;
 std::vector<Glib::ustring> LVM2_PV_Info::lvm2_pv_cache ;
+std::vector<Glib::ustring> LVM2_PV_Info::error_messages ;
 
 LVM2_PV_Info::LVM2_PV_Info()
 {
@@ -128,6 +130,12 @@ bool LVM2_PV_Info::has_active_lvs( const Glib::ustring & path )
 	return false ;
 }
 
+std::vector<Glib::ustring> LVM2_PV_Info::get_error_messages()
+{
+	initialize_if_required() ;
+	return error_messages ;
+}
+
 //Private methods
 
 void LVM2_PV_Info::initialize_if_required()
@@ -151,6 +159,7 @@ void LVM2_PV_Info::load_lvm2_pv_info_cache()
 	Glib::ustring output, error ;
 
 	lvm2_pv_cache .clear() ;
+	error_messages .clear() ;
 	if ( lvm_found )
 	{
 		//The OS is expected to fully enable LVM, this scan does
@@ -160,11 +169,28 @@ void LVM2_PV_Info::load_lvm2_pv_info_cache()
 
 		//Load LVM2 PV attribute cache.  Output PV attributes in
 		//  PV_ATTRIBUTE order
-		if ( ! Utils::execute_command( "lvm pvs --config \"log{command_names=0}\" --nosuffix --noheadings --separator , --units b -o pv_name,pv_free,vg_name,lv_name,lv_attr", output, error, true ) )
+		Glib::ustring cmd = "lvm pvs --config \"log{command_names=0}\" --nosuffix --noheadings --separator , --units b -o pv_name,pv_free,vg_name,lv_name,lv_attr" ;
+		if ( ! Utils::execute_command( cmd, output, error, true ) )
 		{
 			if ( output != "" )
 				Utils::tokenize( output, lvm2_pv_cache, " \n" ) ;
 		}
+		else
+		{
+			error_messages .push_back( cmd ) ;
+			if ( ! output .empty() )
+				error_messages .push_back ( output ) ;
+			if ( ! error .empty() )
+				error_messages .push_back ( error ) ;
+			Glib::ustring temp ;
+			temp = _("An error occurred reading LVM2 configuration!") ;
+			temp += "\n" ;
+			temp += _("Some or all of the details may be missing or incorrect.") ;
+			temp += "\n" ;
+			temp += _("You should NOT modify any LVM2 PV partitions.") ;
+			temp += "\n" ;
+			error_messages .push_back( temp ) ;
+		}
 	}
 }
 
diff --git a/src/lvm2_pv.cc b/src/lvm2_pv.cc
index 8bd2d84..f168497 100644
--- a/src/lvm2_pv.cc
+++ b/src/lvm2_pv.cc
@@ -42,6 +42,13 @@ void lvm2_pv::set_used_sectors( Partition & partition )
 	Byte_Value free_bytes = lvm2_pv_info .get_free_bytes( partition .get_path() ) ;
 	if ( free_bytes >= 0 )
 		partition .Set_Unused( Utils::round( double(free_bytes) / double(partition .sector_size) ) ) ;
+
+	std::vector<Glib::ustring> error_messages = lvm2_pv_info .get_error_messages() ;
+	if ( ! error_messages .empty() )
+	{
+		for ( unsigned int i = 0 ; i < error_messages .size() ; i ++ )
+			partition .messages .push_back( error_messages [ i ] ) ;
+	}
 }
 
 void lvm2_pv::read_label( Partition & partition )



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