[PATCH] Use partially corrupt gpt disklabels.

Brian C. Lane bcl at redhat.com
Fri Jun 12 19:16:41 UTC 2015


Tell pyparted to answer "yes" when libparted asks if we want to proceed
using the secondary gpt disklabel in the event of a corrupt primary (or
use the primary in spite of a corrupt secondary label). We only do this
while populating the devicetree.

We only do this if udev/blkid has identified the disk as containing a
disklabel. This means we are going with the system's consensus as to
which formatting to acknowledge in the event there are multiple
signatures on the disk.

Based on commit e8b5e4b0058946b77ac472b466087196f4c6810b

Resolves: rhbz#1188163
---
 blivet/devicetree.py | 15 +++++++++++++++
 1 file changed, 15 insertions(+)

diff --git a/blivet/devicetree.py b/blivet/devicetree.py
index ebdb44e..dd2fc59 100644
--- a/blivet/devicetree.py
+++ b/blivet/devicetree.py
@@ -26,6 +26,7 @@ import re
 import shutil
 import pprint
 import copy
+import parted
 
 from .errors import CryptoError, DeviceError, DeviceTreeError, DiskLabelCommitError, DMError, FSError, InvalidDiskLabelError, LUKSError, MDRaidError, StorageError, UnusableConfigurationError
 from .devices import BTRFSDevice, BTRFSSubVolumeDevice, BTRFSVolumeDevice, BTRFSSnapShotDevice
@@ -61,6 +62,18 @@ log = logging.getLogger("blivet")
 
 _LVM_DEVICE_CLASSES = (LVMLogicalVolumeDevice, LVMVolumeGroupDevice)
 
+def parted_exn_handler(exn_type, exn_options, exn_msg):
+    """ Answer any of parted's yes/no questions in the affirmative.
+
+        This allows us to proceed with partially corrupt gpt disklabels.
+    """
+    log.info("parted exception: %s", exn_msg)
+    ret = parted.EXCEPTION_RESOLVE_UNHANDLED
+    if exn_type == parted.EXCEPTION_TYPE_ERROR and \
+       exn_options == parted.EXCEPTION_OPT_YES_NO:
+        ret = parted.EXCEPTION_RESOLVE_YES
+    return ret
+
 class DeviceTree(object):
     """ A quasi-tree that represents the devices in the system.
 
@@ -2139,11 +2152,13 @@ class DeviceTree(object):
         if cleanupOnly:
             self._cleanup = True
 
+        parted.register_exn_handler(parted_exn_handler)
         try:
             self._populate()
         except Exception:
             raise
         finally:
+            parted.clear_exn_handler()
             self._hideIgnoredDisks()
             self.restoreConfigs()
 
-- 
2.4.0



More information about the anaconda-patches mailing list