partitionedfs: do not use blkid for PARTUUID
authorArtem Bityutskiy <artem.bityutskiy@intel.com>
Tue, 29 Jan 2013 12:19:32 +0000 (14:19 +0200)
committerGui Chen <gui.chen@intel.com>
Tue, 29 Jan 2013 05:50:26 +0000 (13:50 +0800)
Now, as we have our own GPT partition table parser, lets use it. This patch
teaches partitionedfs.py to add the 'partuuid' key to partitions dictionary.
This value is later used in 'raw.py' when generating the extlinux.conf file.

Change-Id: I1af9e59742171797842f3fafd5c74be78e1414bc
Signed-off-by: Artem Bityutskiy <artem.bityutskiy@intel.com>
Conflicts:
mic/imager/raw.py

mic/imager/raw.py
mic/utils/partitionedfs.py

index d516ae3..462a7ea 100644 (file)
@@ -225,10 +225,7 @@ class RawImageCreator(BaseImageCreator):
         for p in self.__instloop.partitions:
             if p['mountpoint'] == "/":
                 rootdev = "/dev/%s%-d" % (p['disk_name'], p['num'])
-                try:
-                    root_part_uuid = self.__instloop.get_partuuid(p['device'])
-                except:
-                    pass
+                root_part_uuid = p['partuuid']
 
         return (rootdev, root_part_uuid)
 
index d63c0e7..8f4b302 100644 (file)
@@ -24,6 +24,7 @@ from mic import msger
 from mic.utils import runner
 from mic.utils.errors import MountError
 from mic.utils.fs_related import *
+from mic.utils.gpt_parser import GptParser
 
 # Overhead of the MBR partitioning scheme (just one sector)
 MBR_OVERHEAD = 1
@@ -45,7 +46,6 @@ class PartitionedMount(Mount):
         self.parted = find_binary_path("parted")
         self.kpartx = find_binary_path("kpartx")
         self.mkswap = find_binary_path("mkswap")
-        self.blkid = find_binary_path("blkid")
         self.btrfscmd=None
         self.mountcmd = find_binary_path("mount")
         self.umountcmd = find_binary_path("umount")
@@ -148,7 +148,8 @@ class PartitionedMount(Mount):
                      'mount': None, # Mount object
                      'num': None, # Partition number
                      'boot': boot, # Bootable flag
-                     'align': align } # Partition alignment
+                     'align': align, # Partition alignment
+                     'partuuid': None } # Partition UUID (GPT-only)
 
             self.__add_partition(part)
 
@@ -333,6 +334,29 @@ class PartitionedMount(Mount):
                 self.__run_parted(["-s", d['disk'].device, "set",
                                    "%d" % p['num'], flag_name, "on"])
 
+        # If the partition table format is "gpt", find out PARTUUIDs for all
+        # the partitions
+        for disk_name, disk in self.disks.items():
+            if disk['ptable_format'] != 'gpt':
+                continue
+
+            pnum = 0
+            gpt_parser = GptParser(d['disk'].device, SECTOR_SIZE)
+            # Iterate over all GPT partitions on this disk
+            for entry in gpt_parser.get_partitions():
+                pnum += 1
+                # Find the matching partition in the 'self.partitions' list
+                for n in d['partitions']:
+                    p = self.partitions[n]
+                    if p['num'] == pnum:
+                        # Found, assign PARTUUID
+                        p['partuuid'] = entry[1]
+                        msger.debug("PARTUUID for partition %d of disk '%s' " \
+                                    "(mount point '%s') is '%s'" % (pnum, \
+                                    disk_name, p['mountpoint'], p['partuuid']))
+
+            del gpt_parser
+
     def __map_partitions(self):
         """Load it if dm_snapshot isn't loaded. """
         load_module("dm_snapshot")
@@ -414,26 +438,6 @@ class PartitionedMount(Mount):
 
             d['mapped'] = False
 
-    def get_partuuid(self, device):
-        """ Find UUID of a partition corresponding to a device node
-        'device'. """
-
-        args = [ self.blkid, '-c', '/dev/null', '-p', '-i', device ]
-        msger.debug("Running 'blkid': " + str(args))
-        rc, output = runner.runtool(args)
-        if rc != 0:
-            raise MountError("blkid failed: %s" % output)
-
-        # Parse blkid output and search for the PART_ENTRY_UUID value
-        partuuid = None
-        for line in output.splitlines():
-            var, value = line.partition("=")[::2]
-            if var.strip() == "PART_ENTRY_UUID":
-                partuuid = value.strip()
-
-        return partuuid
-
-
     def __calculate_mountorder(self):
         msger.debug("Calculating mount order")
         for p in self.partitions: