From 03e7e8beec7574af6ad521b0a5f677c7c292926a Mon Sep 17 00:00:00 2001
From: David Lehman <dlehman@redhat.com>
Date: Fri, 7 Nov 2014 15:48:42 -0600
Subject: [PATCH 17/26] Store disklabel and partition UUIDs when available.

---
 blivet/devices/partition.py |  5 +++--
 blivet/devicetree.py        | 13 ++++++-------
 blivet/formats/disklabel.py |  1 +
 blivet/udev.py              |  6 ++++++
 4 files changed, 16 insertions(+), 9 deletions(-)

diff --git a/blivet/devices/partition.py b/blivet/devices/partition.py
index 0bac6b6..dc8d98c 100644
--- a/blivet/devices/partition.py
+++ b/blivet/devices/partition.py
@@ -61,7 +61,7 @@ class PartitionDevice(StorageDevice):
     _resizable = True
     defaultSize = DEFAULT_PART_SIZE
 
-    def __init__(self, name, fmt=None,
+    def __init__(self, name, fmt=None, uuid=None,
                  size=None, grow=False, maxsize=None, start=None, end=None,
                  major=None, minor=None, bootable=None,
                  sysfsPath='', parents=None, exists=False,
@@ -80,6 +80,7 @@ class PartitionDevice(StorageDevice):
 
             For existing partitions only:
 
+            :keyword str uuid: partition UUID (not filesystem UUID)
             :keyword major: the device major
             :type major: long
             :keyword minor: the device minor
@@ -125,7 +126,7 @@ class PartitionDevice(StorageDevice):
 
         self._bootable = False
 
-        StorageDevice.__init__(self, name, fmt=fmt, size=size,
+        StorageDevice.__init__(self, name, fmt=fmt, uuid=uuid, size=size,
                                major=major, minor=minor, exists=exists,
                                sysfsPath=sysfsPath, parents=parents)
 
diff --git a/blivet/devicetree.py b/blivet/devicetree.py
index c0d84d9..3704560 100644
--- a/blivet/devicetree.py
+++ b/blivet/devicetree.py
@@ -51,7 +51,6 @@ from .devicelibs import loop
 from .devicelibs import edd
 from . import udev
 from . import util
-from .platform import platform
 from . import tsort
 from .flags import flags
 from .storage_log import log_exception_info, log_method_call, log_method_return
@@ -875,7 +874,8 @@ class DeviceTree(object):
 
     def addUdevPartitionDevice(self, info, disk=None):
         name = udev.device_get_name(info)
-        log_method_call(self, name=name)
+        uuid = udev.device_get_partition_uuid(info)
+        log_method_call(self, name=name, uuid=uuid)
         sysfs_path = udev.device_get_sysfs_path(info)
 
         if name.startswith("md"):
@@ -935,6 +935,7 @@ class DeviceTree(object):
         device = None
         try:
             device = PartitionDevice(name, sysfsPath=sysfs_path,
+                                     uuid=uuid,
                                      major=udev.device_get_major(info),
                                      minor=udev.device_get_minor(info),
                                      exists=True, parents=[disk])
@@ -1232,6 +1233,7 @@ class DeviceTree(object):
 
     def handleUdevDiskLabelFormat(self, info, device):
         disklabel_type = udev.device_get_disklabel_type(info)
+        disklabel_uuid = udev.device_get_disklabel_uuid(info)
         log_method_call(self, device=device.name, label_type=disklabel_type)
         # if there is no disklabel on the device
         # blkid doesn't understand dasd disklabels, so bypass for dasd
@@ -1262,12 +1264,9 @@ class DeviceTree(object):
                 device.format = fmt
             return
 
-        # we're going to pass the "best" disklabel type into the DiskLabel
-        # constructor, but it only has meaning for non-existent disklabels.
-        labelType = platform.bestDiskLabelType(device)
-
         try:
-            fmt = getFormat("disklabel", device=device.path, labelType=labelType, exists=True)
+            fmt = getFormat("disklabel", uuid=disklabel_uuid,
+                            device=device.path, exists=True)
         except InvalidDiskLabelError as e:
             log.info("no usable disklabel on %s", device.name)
             if disklabel_type == "gpt":
diff --git a/blivet/formats/disklabel.py b/blivet/formats/disklabel.py
index a3867a1..0b6359d 100644
--- a/blivet/formats/disklabel.py
+++ b/blivet/formats/disklabel.py
@@ -48,6 +48,7 @@ class DiskLabel(DeviceFormat):
         """
             :keyword device: full path to the block device node
             :type device: str
+            :keyword str uuid: disklabel UUID
             :keyword labelType: type of disklabel to create
             :type labelType: str
             :keyword exists: whether the formatting exists
diff --git a/blivet/udev.py b/blivet/udev.py
index ea37bef..079b4aa 100644
--- a/blivet/udev.py
+++ b/blivet/udev.py
@@ -545,6 +545,12 @@ def device_get_disklabel_type(info):
 
     return info.get("ID_PART_TABLE_TYPE")
 
+def device_get_disklabel_uuid(info):
+    return info.get("ID_PART_TABLE_UUID")
+
+def device_get_partition_uuid(info):
+    return info.get("ID_PART_ENTRY_UUID")
+
 # iscsi disks' ID_PATH form depends on the driver:
 # for software iscsi:
 # ip-${iscsi_address}:${iscsi_port}-iscsi-${iscsi_tgtname}-lun-${lun}
-- 
1.9.3

