[gparted] Enable LVM2 VG activation / deactivation (#670171)



commit 619bda5d8bf9b9aeb393aa4c435735c4c2a8d228
Author: Mike Fleetwood <mike fleetwood googlemail com>
Date:   Mon Feb 13 12:44:45 2012 +0000

    Enable LVM2 VG activation / deactivation (#670171)
    
    In the Partition menu enable activation / deactivation of the LVM2
    Volume Group of which the Physical Volume is a member.
    
    Bug #670171 - Add LVM PV read-write support

 include/Utils.h       |    4 +-
 include/Win_GParted.h |    1 +
 include/lvm2_pv.h     |    1 +
 src/Win_GParted.cc    |   88 ++++++++++++++++++++++++++++++++++++++++++++-----
 src/lvm2_pv.cc        |   17 +++++++++
 5 files changed, 100 insertions(+), 11 deletions(-)
---
diff --git a/include/Utils.h b/include/Utils.h
index e56fb11..87dfd1a 100644
--- a/include/Utils.h
+++ b/include/Utils.h
@@ -97,8 +97,8 @@ enum SIZE_UNIT
 enum CUSTOM_TEXT
 {
 	CTEXT_NONE,
-	CTEXT_ACTIVATE_FILESYSTEM,		// Activate text ('Mount', 'Swapon', ...)
-	CTEXT_DEACTIVATE_FILESYSTEM,		// Deactivate text ('Unmount', 'Swapoff', ...)
+	CTEXT_ACTIVATE_FILESYSTEM,		// Activate text ('Mount', 'Swapon', VG 'Activate', ...)
+	CTEXT_DEACTIVATE_FILESYSTEM,		// Deactivate text ('Unmount', 'Swapoff', VG 'Deactivate', ...)
 	CTEXT_CHANGE_UUID_WARNING,		// Warning to print when changing UUIDs
 } ;
 
diff --git a/include/Win_GParted.h b/include/Win_GParted.h
index 6738347..81c15e1 100644
--- a/include/Win_GParted.h
+++ b/include/Win_GParted.h
@@ -130,6 +130,7 @@ private:
 	void thread_unmount_partition( bool * succes, Glib::ustring * error ) ;
 	void thread_mount_partition( Glib::ustring mountpoint, bool * succes, Glib::ustring * error ) ;
 	void thread_toggle_swap( bool * succes, Glib::ustring * error ) ;
+	void thread_toggle_lvm2_pv( bool * succes, Glib::ustring * error ) ;
 	void thread_guess_partition_table();
 		
 	//signal handlers
diff --git a/include/lvm2_pv.h b/include/lvm2_pv.h
index a6fca3b..1aff2a1 100644
--- a/include/lvm2_pv.h
+++ b/include/lvm2_pv.h
@@ -27,6 +27,7 @@ namespace GParted
 class lvm2_pv : public FileSystem
 {
 public:
+	const Glib::ustring get_custom_text( CUSTOM_TEXT ttype, int index = 0 ) ;
 	FS get_filesystem_support() ;
 	void set_used_sectors( Partition & partition ) ;
 	void read_label( Partition & partition ) ;
diff --git a/src/Win_GParted.cc b/src/Win_GParted.cc
index c7e71fd..09efdbb 100644
--- a/src/Win_GParted.cc
+++ b/src/Win_GParted.cc
@@ -954,7 +954,22 @@ void Win_GParted::set_valid_operations()
 	   )
 		allow_toggle_swap_mount_state( true ) ;
 
-	//only unmount/swapoff/... is allowed if busy
+	//Only permit VG deactivation if busy, or activation if not busy and a member of a VG.
+	//  For now specifically allow activation of an exported VG, which LVM will fail
+	//  with "Volume group "VGNAME" is exported", otherwise user won't know why the
+	//  inactive PV can't be activated.
+	if (    selected_partition .status == GParted::STAT_REAL
+	     && selected_partition .type != GParted::TYPE_EXTENDED
+	     && selected_partition .filesystem == GParted::FS_LVM2_PV
+	     && (    selected_partition .busy
+	          || (    ! selected_partition .busy
+                       && ! selected_partition .get_mountpoints() .empty()  //VGNAME from mount point
+	             )
+	        )
+	   )
+		allow_toggle_swap_mount_state( true ) ;
+
+	//only unmount/swapoff/VG deactivate/... is allowed if busy
 	if ( selected_partition .busy )
 		return ;
 
@@ -1997,6 +2012,23 @@ void Win_GParted::thread_toggle_swap( bool * succes, Glib::ustring * error )
 	pulse = false ;
 }
 
+void Win_GParted::thread_toggle_lvm2_pv( bool * success, Glib::ustring * error )
+{
+	Glib::ustring dummy ;
+
+	if ( selected_partition .busy )
+		//VGNAME from mount point
+		*success = ! Utils::execute_command( "lvm vgchange -a n " + selected_partition .get_mountpoint(),
+		                                     dummy,
+		                                     *error ) ;
+	else
+		*success = ! Utils::execute_command( "lvm vgchange -a y " + selected_partition .get_mountpoint(),
+		                                     dummy,
+		                                     *error ) ;
+
+	pulse = false ;
+}
+
 // Runs gpart in a thread
 void Win_GParted::thread_guess_partition_table()
 {
@@ -2010,11 +2042,12 @@ void Win_GParted::toggle_swap_mount_state()
 	int operation_count = partition_in_operation_queue_count( selected_partition ) ;
 	if ( operation_count > 0 )
 	{
-		//Note that this situation will only occur when trying to swapon a partition.
-		//  This is because GParted does not permit queueing operations on partitions
-		//  that are currently active (i.e., swap enabled, or mounted).  Hence this
-		//  situation will not occur for the swapoff or unmount actions that this
-		//  method handles.
+		//Note that this situation will only occur when trying to swapon a partition
+		//  or activate the Volume Group of a Physical Volume.  This is because
+		//  GParted does not permit queueing operations on partitions that are
+		//  currently active (i.e., swap enabled, mounted or active VG).  Hence
+		//  this situation will not occur for the swapoff, unmount or deactivate VG
+		//  actions that this method handles.
 
 		/*TO TRANSLATORS: Singular case looks like   1 operation is currently pending for partition /dev/sdd8. */
 		Glib::ustring tmp_msg =
@@ -2032,9 +2065,18 @@ void Win_GParted::toggle_swap_mount_state()
 		                         , Gtk::BUTTONS_OK
 		                         , true
 		                         ) ;
-		tmp_msg  = _( "The swapon action cannot be performed if an operation is pending for the partition." ) ;
-		tmp_msg += "\n" ;
-		tmp_msg += _( "Use the Edit menu to undo, clear, or apply operations before using swapon with this partition." ) ;
+		if ( selected_partition .filesystem == GParted::FS_LINUX_SWAP )
+		{
+			tmp_msg = _( "The swapon action cannot be performed if an operation is pending for the partition." ) ;
+			tmp_msg += "\n" ;
+			tmp_msg += _( "Use the Edit menu to undo, clear, or apply operations before using swapon with this partition." ) ;
+		}
+		else if ( selected_partition .filesystem == GParted::FS_LVM2_PV )
+		{
+			tmp_msg = _( "The activate Volume Group action cannot be performed if an operation is pending for the partition." ) ;
+			tmp_msg += "\n" ;
+			tmp_msg += _( "Use the Edit menu to undo, clear, or apply operations before using activate Volume Group with this partition." ) ;
+		}
 		dialog .set_secondary_text( tmp_msg ) ;
 		dialog .run() ;
 		return ;
@@ -2070,6 +2112,34 @@ void Win_GParted::toggle_swap_mount_state()
 			dialog.run() ;
 		}
 	}
+	else if ( selected_partition .filesystem == GParted::FS_LVM2_PV )
+	{
+		thread = Glib::Thread::create( sigc::bind<bool *, Glib::ustring *>(
+			sigc::mem_fun( *this, &Win_GParted::thread_toggle_lvm2_pv ), &succes, &error ), true ) ;
+
+		show_pulsebar(
+			String::ucompose(
+				selected_partition .busy ? _("Deactivating Volume Group %1")
+				                         : _("Activating Volume Group %1"),
+				//VGNAME from mount point
+				selected_partition .get_mountpoint() ) ) ;
+
+		if ( ! succes )
+		{
+			Gtk::MessageDialog dialog(
+				*this,
+				selected_partition .busy ? _("Could not deactivate Volume Group")
+				                         : _("Could not activate Volume Group"),
+				false,
+				Gtk::MESSAGE_ERROR,
+				Gtk::BUTTONS_OK,
+				true ) ;
+
+			dialog .set_secondary_text( error ) ;
+
+			dialog.run() ;
+		}
+	}
 	else if ( selected_partition .busy )
 	{
 		thread = Glib::Thread::create( sigc::bind<bool *, Glib::ustring *>( 
diff --git a/src/lvm2_pv.cc b/src/lvm2_pv.cc
index 4d67aaa..12bf3a4 100644
--- a/src/lvm2_pv.cc
+++ b/src/lvm2_pv.cc
@@ -22,6 +22,23 @@
 namespace GParted
 {
 
+const Glib::ustring lvm2_pv::get_custom_text( CUSTOM_TEXT ttype, int index )
+{
+	/*TO TRANSLATORS: these labels will be used in the partition menu */
+	static const Glib::ustring activate_text = _( "Ac_tivate" ) ;
+	static const Glib::ustring deactivate_text = _( "Deac_tivate" ) ;
+
+	switch ( ttype )
+	{
+		case CTEXT_ACTIVATE_FILESYSTEM:
+			return index == 0 ? activate_text : "" ;
+		case CTEXT_DEACTIVATE_FILESYSTEM:
+			return index == 0 ? deactivate_text : "" ;
+		default:
+			return "" ;
+	}
+}
+
 FS lvm2_pv::get_filesystem_support()
 {
 	FS fs ;



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