[gparted] Enable failed partition change rollback for selected steps (#791875)



commit 0b5bf83b22a4184afeb7c6b3e08d281211ae6c8b
Author: Mike Fleetwood <mike fleetwood googlemail com>
Date:   Mon Dec 18 16:39:37 2017 +0000

    Enable failed partition change rollback for selected steps (#791875)
    
    The general rule is that:
    1) For a partition change step BEFORE a file system change step,
       rollback on failure;
    2) For a partition change step AFTER a file system change step, don't
       rollback on failure.
    
    Examining every case where resize_move_partition() is called and whether
    rollback on failure is wanted or not:
    
    * In resize_move()
        Resize / move extended partition.  No associated file system change.
      NO ROLLBACK
        Just to keep possibly applied operation.
    
    * #1 in move()
        Making all encompassing partition before moving file system.
      ROLLBACK
        To restore partition boundaries back to those of the file system.
    
    * #2 in move()
        Recreating original partition boundaries after file system move
        failed or was cancelled and has been rolled back.
      NO ROLLBACK
        To keep updated partition boundaries to match restored file system
        data.
    
    * #3 in move()
        Replacing all encompassing partition with final partition after
        successful file system move.
      NO ROLLBACK
        Keep new partition boundaries to match moved file system.
    
    * #1 in resize_encryption()
        Making the partition larger before growing closed LUKS encrypted
        data.
      ROLLBACK
        Restore partition boundaries back to those of the closed LUKS
        encrypted data.
    
    * #2 in resize_encryption()
        Shrinking the partition after open LUKS mapping has been shrunk, but
        before swap is re-created (smaller).
      NO ROLLBACK
        Difficult case because the partition shrink is in the middle of a
        LUKS shrink and a swap shrink (re-create).  If swap was actually
        shrunk like other types of file system, rather than re-created, then
        the operation sequence would be (1) shrink swap, (2) shrink LUKS
        encryption, (3) shrink partition.  In this hypothetical case and the
        actual case no rollback is preferred to try to keep the new
        partition boundaries match the shrunk open LUKS encryption mapping.
    
    * #3 in resize_encryption()
        Grow the partition before growing open LUKS mapping and re-creating
        swap larger.
      ROLLBACK
        Restore partition boundaries back to those of the smaller open LUKS
        encryption mapping.
    
    * #4 in resize_encryption()
        Shrink the partition after shrinking the file system and open LUKS
        encryption mapping.
      NO ROLLBACK
        Keep new smaller partition boundaries to match shrunk encrypted file
        system.
    
    * #5 in resize_encryption()
        Grow the partition before growing the open LUKS encryption mapping
        and file system.
      ROLLBACK
        Restore partition boundaries back to those of the not yet grown
        encrypted file system.
    
    * #1 in resize_plain()
        Resize partition before re-creating swap a different size.
      ROLLBACK
        Restore partition boundaries back to those of the not yet resized
        (re-created) swap space.
    
    * #2 in resize_plain()
        Shrink partition after shrinking the file system.
      NO ROLLBACK
        Keep new smaller partition boundaries to match shrunk file system.
    
    * #3 in resize_plain()
        Grow partition before growing the file system.
      ROLLBACK
        Restore partition boundaries back to those of the not yet grown
        file system.
    
    Removes the default value from the rollback_on_fail parameter so
    rollback or not has to be explicitly specified for every call of
    resize_move_partition().
    
    Bug 791875 - Rollback specific failed partition change steps

 include/GParted_Core.h |    2 +-
 src/GParted_Core.cc    |   26 +++++++++++++-------------
 2 files changed, 14 insertions(+), 14 deletions(-)
---
diff --git a/include/GParted_Core.h b/include/GParted_Core.h
index 6a46647..89b59bb 100644
--- a/include/GParted_Core.h
+++ b/include/GParted_Core.h
@@ -146,7 +146,7 @@ private:
        bool resize_move_partition( const Partition & partition_old,
                                    const Partition & partition_new,
                                    OperationDetail & operationdetail,
-                                   bool rollback_on_fail = false );
+                                   bool rollback_on_fail );
        bool resize_move_partition_implement( const Partition & partition_old,
                                              const Partition & partition_new,
                                              Sector & new_start,
diff --git a/src/GParted_Core.cc b/src/GParted_Core.cc
index 27f178a..008dd87 100644
--- a/src/GParted_Core.cc
+++ b/src/GParted_Core.cc
@@ -2244,7 +2244,7 @@ bool GParted_Core::resize_move( const Partition & partition_old,
           )
        {
                if ( partition_old .type == TYPE_EXTENDED )
-                       return resize_move_partition( partition_old, partition_new, operationdetail ) ;
+                       return resize_move_partition( partition_old, partition_new, operationdetail, false );
 
                if ( partition_new .sector_start == partition_old .sector_start )
                        return resize( partition_old, partition_new, operationdetail ) ;
@@ -2320,7 +2320,7 @@ bool GParted_Core::move( const Partition & partition_old,
        // Make old partition all encompassing and if move file system fails then return
        // partition table to original state
        bool success = false;
-       if ( resize_move_partition( partition_old, *partition_all_space, operationdetail ) )
+       if ( resize_move_partition( partition_old, *partition_all_space, operationdetail, true ) )
        {
                // Note move of file system is from old values to new values, not from the
                // all encompassing values.
@@ -2331,8 +2331,8 @@ bool GParted_Core::move( const Partition & partition_old,
 
                        Partition * partition_restore = partition_old.clone();
                        partition_restore->alignment = ALIGN_STRICT;  // Ensure that old partition boundaries 
are not modified
-                       if ( resize_move_partition( *partition_all_space,
-                                                   *partition_restore, operationdetail.get_last_child() ) )
+                       if ( resize_move_partition( *partition_all_space, *partition_restore,
+                                                   operationdetail.get_last_child(), false ) )
                        {
                                operationdetail.get_last_child().set_success_and_capture_errors( true );
                                check_repair_filesystem( partition_old, operationdetail );
@@ -2354,7 +2354,7 @@ bool GParted_Core::move( const Partition & partition_old,
        // Make new partition from all encompassing partition
        if ( success )
        {
-               success =    resize_move_partition( *partition_all_space, partition_new, operationdetail )
+               success =    resize_move_partition( *partition_all_space, partition_new, operationdetail, 
false )
                          && update_bootsector( partition_new, operationdetail );
        }
 
@@ -2561,7 +2561,7 @@ bool GParted_Core::resize_encryption( const Partition & partition_old,
                // grow closed LUKS.
                // maximize_encryption() is only called to display no action needed
                // operation message generated in luks::resize() for this case.
-               return    resize_move_partition( partition_old, partition_new, operationdetail )
+               return    resize_move_partition( partition_old, partition_new, operationdetail, true )
                       && maximize_encryption( partition_new, operationdetail );
        }
 
@@ -2573,12 +2573,12 @@ bool GParted_Core::resize_encryption( const Partition & partition_old,
                if ( delta < 0LL )  // shrink
                {
                        return    shrink_encryption( partition_old, partition_new, operationdetail )
-                              && resize_move_partition( partition_old, partition_new, operationdetail )
+                              && resize_move_partition( partition_old, partition_new, operationdetail, false 
)
                               && recreate_linux_swap_filesystem( filesystem_ptn_new, operationdetail );
                }
                else if ( delta > 0LL ) // grow
                {
-                       return    resize_move_partition( partition_old, partition_new, operationdetail )
+                       return    resize_move_partition( partition_old, partition_new, operationdetail, true )
                               && maximize_encryption( partition_new, operationdetail )
                               && recreate_linux_swap_filesystem( filesystem_ptn_new, operationdetail );
                }
@@ -2590,12 +2590,12 @@ bool GParted_Core::resize_encryption( const Partition & partition_old,
                return    check_repair_filesystem( filesystem_ptn_old, operationdetail )
                       && shrink_filesystem( filesystem_ptn_old, filesystem_ptn_new, operationdetail )
                       && shrink_encryption( partition_old, partition_new, operationdetail )
-                      && resize_move_partition( partition_old, partition_new, operationdetail );
+                      && resize_move_partition( partition_old, partition_new, operationdetail, false );
        }
        else if ( delta > 0LL )  // grow
        {
                return    check_repair_filesystem( filesystem_ptn_old, operationdetail )
-                      && resize_move_partition( partition_old, partition_new, operationdetail )
+                      && resize_move_partition( partition_old, partition_new, operationdetail, true )
                       && maximize_encryption( partition_new, operationdetail )
                       && maximize_filesystem( filesystem_ptn_new, operationdetail );
        }
@@ -2618,7 +2618,7 @@ bool GParted_Core::resize_plain( const Partition & partition_old,
        if ( partition_new.filesystem == FS_LINUX_SWAP )
        {
                // linux-swap is recreated, not resized
-               return    resize_move_partition( partition_old, partition_new, operationdetail )
+               return    resize_move_partition( partition_old, partition_new, operationdetail, true )
                       && recreate_linux_swap_filesystem( partition_new, operationdetail );
        }
 
@@ -2627,12 +2627,12 @@ bool GParted_Core::resize_plain( const Partition & partition_old,
        {
                return    check_repair_filesystem( partition_new, operationdetail )
                       && shrink_filesystem( partition_old, partition_new, operationdetail )
-                      && resize_move_partition( partition_old, partition_new, operationdetail );
+                      && resize_move_partition( partition_old, partition_new, operationdetail, false );
        }
        else if ( delta > 0LL )  // grow
        {
                return    check_repair_filesystem( partition_new, operationdetail )
-                      && resize_move_partition( partition_old, partition_new, operationdetail )
+                      && resize_move_partition( partition_old, partition_new, operationdetail, true )
                       && maximize_filesystem( partition_new, operationdetail );
        }
 


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