[PATCH] Use partially corrupt gpt disklabels.

Vratislav Podzimek vpodzime at redhat.com
Mon Jun 15 07:50:44 UTC 2015


On Fri, 2015-06-12 at 12:16 -0700, Brian C. Lane wrote:
> 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()
>  
Would be nice if pyparted also provided
'exn_handler(parted_exn_handler)' context manager, so this would look
like:
with parted.exn_handler(parted_exn_handler):
    ....

But that's more an agenda for master not as part of backporting stuff to
rhel7-branch.

-- 
Vratislav Podzimek

Anaconda Rider | Red Hat, Inc. | Brno - Czech Republic



More information about the anaconda-patches mailing list