[gparted] Display VG export status with an LVM2 PVs busy status (#160787)



commit 6d665d669db14c1fce8db7e924bb903e1fd79b4f
Author: Mike Fleetwood <mike fleetwood googlemail com>
Date:   Sun Feb 12 13:41:41 2012 +0000

    Display VG export status with an LVM2 PVs busy status (#160787)
    
    Also update to use LVM terminology, such that a Physical Volume is
    referred to as a member of a Volume Group.  Status of an LVM2 PV is now
    displayed using one of the following messages:
        Not active (Not a member of any volume group)
        VGNAME not active
        VGNAME not active and exported
        VGNAME active
    
    Bug #160787 - lvm support

 include/LVM2_PV_Info.h       |    1 +
 src/Dialog_Partition_Info.cc |   20 ++++++++++++----
 src/LVM2_PV_Info.cc          |   53 +++++++++++++++++++++++++++++++----------
 3 files changed, 56 insertions(+), 18 deletions(-)
---
diff --git a/include/LVM2_PV_Info.h b/include/LVM2_PV_Info.h
index 45315da..f3edb23 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 ) ;
+	bool is_vg_exported( const Glib::ustring & vgname ) ;
 	std::vector<Glib::ustring> get_error_messages() ;
 private:
 	void initialize_if_required() ;
diff --git a/src/Dialog_Partition_Info.cc b/src/Dialog_Partition_Info.cc
index a1ab995..820bcf3 100644
--- a/src/Dialog_Partition_Info.cc
+++ b/src/Dialog_Partition_Info.cc
@@ -17,6 +17,7 @@
  */
  
 #include "../include/Dialog_Partition_Info.h"
+#include "../include/LVM2_PV_Info.h"
 
 namespace GParted
 {
@@ -269,7 +270,7 @@ void Dialog_Partition_Info::Display_Info()
 			else if ( partition .filesystem == FS_LVM2_PV )
 			{
 				/* TO TRANSLATORS:  myvgname active
-				 * means that the partition is part of an LVM volume group and that
+				 * means that the partition is a member of an LVM volume group and the
 				 * volume group is active and being used by the operating system.
 				 */
 				str_temp = String::ucompose( _("%1 active"), partition .get_mountpoint() ) ;
@@ -300,17 +301,26 @@ void Dialog_Partition_Info::Display_Info()
 		}
 		else if ( partition .filesystem == FS_LVM2_PV )
 		{
+			LVM2_PV_Info lvm2_pv_info ;
 			Glib::ustring mount_point = partition .get_mountpoint() ;
 			if ( mount_point .empty() )
-				/* TO TRANSLATORS:  Not active (Not part of any volume group)
-				 * means that the partition is not yet part of an LVM volume
+				/* TO TRANSLATORS:  Not active (Not a member of any volume group)
+				 * means that the partition is not yet a member of an LVM volume
 				 * group and therefore is not active and can not yet be used by
 				 * the operating system.
 				 */
-				str_temp = _("Not active (Not part of any volume group)") ;
+				str_temp = _("Not active (Not a member of any volume group)") ;
+			else if ( lvm2_pv_info .is_vg_exported( mount_point ) )
+				/* TO TRANSLATORS:  myvgname not active and exported
+				 * means that the partition is a member of an LVM volume group but
+				 * the volume group is not active and not being used by the operating system.
+				 * The volume group has also been exported making the LVM physical volumes
+				 * ready for moving to a different computer system.
+				 */
+				str_temp = String::ucompose( _("%1 not active and exported"), mount_point ) ;
 			else
 				/* TO TRANSLATORS:  myvgname not active
-				 * means that the partition is part of an LVM volume group but
+				 * means that the partition is a member of an LVM volume group but
 				 * the volume group is not active and not being used by the operating system.
 				 */
 				str_temp = String::ucompose( _("%1 not active"), mount_point ) ;
diff --git a/src/LVM2_PV_Info.cc b/src/LVM2_PV_Info.cc
index 91e5cc7..a882fb5 100644
--- a/src/LVM2_PV_Info.cc
+++ b/src/LVM2_PV_Info.cc
@@ -25,8 +25,9 @@ enum PV_ATTRIBUTE
 	PVATTR_PV_NAME = 0,
 	PVATTR_PV_FREE = 1,
 	PVATTR_VG_NAME = 2,
-	PVATTR_LV_NAME = 3,
-	PVATTR_LV_BITS = 4
+	PVATTR_VG_BITS = 3,
+	PVATTR_LV_NAME = 4,
+	PVATTR_LV_BITS = 5
 } ;
 
 //Data model:
@@ -35,17 +36,20 @@ enum PV_ATTRIBUTE
 //  lvm_found           - Is the "lvm" command available?
 //  lvm2_pv_cache       - String vector storing attributes of a PV.
 //                        Attributes are: pv_name,pv_free,vg_name,
-//                        lv_name,lv_attr.  Pv_free is the number of
-//                        free bytes, see lvs(8) for details of
-//                        lv_attrs.
+//                        vg_attr,lv_name,lv_attr.  Pv_free is the
+//                        number of free bytes, see vgs(8) and lvs(8)
+//                        for details of vg_attr and lv_attr
+//                        respectively.
 //                        E.g.
-//                        ["/dev/sda10,2147483648,,,",
-//                         "/dev/sda11,2143289344,GParted-VG1,,",
-//                         "/dev/sda12,1619001344,GParted-VG2,lvol0,-wi---",
-//                         "/dev/sda12,1619001344,GParted-VG2,,",
-//                         "/dev/sda13,830472192,GParted_VG3,lvol0,-wi-a-",
-//                         "/dev/sda13,830472192,GParted_VG3,lvol1,-wi-a-",
-//                         "/dev/sda13,830472192,GParted_VG3,,"]
+//                        ["/dev/sda10,2147483648,,r-----,,",
+//                         "/dev/sda11,2143289344,GParted-VG1,wz--n-,,",
+//                         "/dev/sda12,1619001344,GParted-VG2,wz--n-,lvol0,-wi---",
+//                         "/dev/sda12,1619001344,GParted-VG2,wz--n-,,",
+//                         "/dev/sda13,830472192,GParted_VG3,wz--n-,lvol0,-wi-a-",
+//                         "/dev/sda13,830472192,GParted_VG3,wz--n-,lvol1,-wi-a-",
+//                         "/dev/sda13,830472192,GParted_VG3,wz--n-,,",
+//                         "/dev/sda14,1828716544,GParted-VG4,wzx-n-,lvol0,-wi---",
+//                         "/dev/sda14,1828716544,GParted-VG4,wzx-n-,,"]
 //  error_messages      - String vector storing error messsages.
 
 
@@ -130,6 +134,29 @@ bool LVM2_PV_Info::has_active_lvs( const Glib::ustring & path )
 	return false ;
 }
 
+//Report if the VG is exported.
+bool LVM2_PV_Info::is_vg_exported( const Glib::ustring & vgname )
+{
+	initialize_if_required() ;
+
+	for ( unsigned int i = 0 ; i < lvm2_pv_cache .size() ; i ++ )
+	{
+		std::vector<Glib::ustring> pv_attrs ;
+		Utils::split( lvm2_pv_cache [i], pv_attrs, "," ) ;
+		if ( vgname == get_pv_attr_by_row( i, PVATTR_VG_NAME ) )
+		{
+			Glib::ustring vg_bits = get_pv_attr_by_row( i, PVATTR_VG_BITS ) ;
+			//3rd "bit" is export status.  E.g.
+			//  "wz--n-" imported, "wzx-n-" exported.
+			//  Treat any non-hyphen character as exported.
+			if ( vg_bits .length() >= 3 && vg_bits [2] != '-' )
+				//VG is exported
+				return true ;
+		}
+	}
+	return false ;
+}
+
 std::vector<Glib::ustring> LVM2_PV_Info::get_error_messages()
 {
 	initialize_if_required() ;
@@ -169,7 +196,7 @@ void LVM2_PV_Info::load_lvm2_pv_info_cache()
 
 		//Load LVM2 PV attribute cache.  Output PV attributes in
 		//  PV_ATTRIBUTE order
-		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" ;
+		Glib::ustring cmd = "lvm pvs --config \"log{command_names=0}\" --nosuffix --noheadings --separator , --units b -o pv_name,pv_free,vg_name,vg_attr,lv_name,lv_attr" ;
 		if ( ! Utils::execute_command( cmd, output, error, true ) )
 		{
 			if ( output != "" )



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