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

[PATCH 2/2] Remove newly added partition from disk if subsequent commit fails. (#559907)



If the commit fails because there's an md array active on the disk
we will try again to add the partition after stopping the array, but
if we don't remove the failed-to-add partition first, we end up with
a mess.
---
 storage/devices.py |    8 +++++++-
 1 files changed, 7 insertions(+), 1 deletions(-)

diff --git a/storage/devices.py b/storage/devices.py
index 1132df2..eee43e2 100644
--- a/storage/devices.py
+++ b/storage/devices.py
@@ -1253,7 +1253,13 @@ class PartitionDevice(StorageDevice):
             self.setupParents()
 
             self.disk.format.addPartition(self.partedPartition)
-            self.disk.format.commit()
+
+            try:
+                self.disk.format.commit()
+            except DiskLabelCommitError:
+                part = self.disk.format.partedDisk.getPartitionByPath(self.path)
+                self.disk.format.removePartition(part)
+                raise
 
             # Ensure old metadata which lived in freespace so did not get
             # explictly destroyed by a destroyformat action gets wiped
-- 
1.6.6


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