]> git.apps.os.sepia.ceph.com Git - ceph.git/commitdiff
ceph-disk: use partition type UUIDs, and blkid
authorSage Weil <sage@redhat.com>
Wed, 13 Aug 2014 00:25:10 +0000 (17:25 -0700)
committerSage Weil <sage@redhat.com>
Sat, 16 Aug 2014 00:15:37 +0000 (17:15 -0700)
Use blkid to give us the GPT partition type.  This lets us distinguish
between dmcrypt and non-dmcrypt partitions.  Fake it if blkid doesn't
give us what we want and try with sgdisk.  This isn't perfect (it can't
tell between dmcrypt and not dmcrypt), but such is life, and we are better
off than before.

Signed-off-by: Sage Weil <sage@redhat.com>
(cherry picked from commit 6c77f5f2f994c881232d76ce9c69af80d10772bd)

src/ceph-disk

index a8a9f8adffa454962c63ee4bb216c30f276fa972..79bfcc330c04670f0e27581cd8d5dd68737691c1 100755 (executable)
@@ -2133,6 +2133,25 @@ def get_dev_fs(dev):
         return None
 
 def get_partition_type(part):
+    """
+    Get the GPT partition type UUID.  If we have an old blkid and can't
+    get it that way, use sgdisk and use the description instead (and hope
+    dmcrypt isn't being used).
+    """
+    blkid, _ = command(
+        [
+            'blkid',
+            '-p',
+            '-o', 'udev',
+            part,
+        ]
+    )
+    for line in blkid.splitlines():
+        (key, value) = line.split('=')
+        if key == 'ID_PART_ENTRY_TYPE':
+            return value
+
+    # bah, fall back to sgdisk.
     (base, partnum) = re.match('(\D+)(\d+)', part).group(1, 2)
     sgdisk, _ = command(
         [
@@ -2148,7 +2167,13 @@ def get_partition_type(part):
             num = m.group(1)
             if num != partnum:
                 continue
-            return m.group(2)
+            desc = m.group(2)
+            # assume unencrypted ... blkid has failed us :(
+            if desc == 'ceph data':
+                return OSD_UUID
+            if desc == 'ceph journal':
+                return JOURNAL_UUID
+
     return None
 
 def get_partition_uuid(dev):
@@ -2193,7 +2218,7 @@ def list_dev(dev, uuid_map, journal_map):
     path = is_mounted(dev)
 
     desc = []
-    if ptype == 'ceph data':
+    if ptype == OSD_UUID:
         if path:
             desc.append('active')
             desc.extend(more_osd_info(path, uuid_map))
@@ -2214,7 +2239,7 @@ def list_dev(dev, uuid_map, journal_map):
             desc = ['ceph data'] + desc
         else:
             desc = ['ceph data', 'unprepared']
-    elif ptype == 'ceph journal':
+    elif ptype == JOURNAL_UUID:
         desc.append('ceph journal')
         part_uuid = get_partition_uuid(dev)
         if part_uuid and part_uuid in journal_map:
@@ -2247,7 +2272,7 @@ def main_list(args):
             if part_uuid:
                 uuid_map[part_uuid] = dev
             ptype = get_partition_type(dev)
-            if ptype == 'ceph data':
+            if ptype == OSD_UUID:
                 fs_type = get_dev_fs(dev)
                 if fs_type is not None:
                     try: