]> git-server-git.apps.pok.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>
Wed, 13 Aug 2014 00:25:10 +0000 (17:25 -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>
src/ceph-disk

index 6c3775139dac438028a951d771d98ad599821c60..19e2696c44a1df1db77865a6cca562689133835b 100755 (executable)
@@ -2131,6 +2131,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(
         [
@@ -2146,7 +2165,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):
@@ -2191,7 +2216,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))
@@ -2212,7 +2237,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:
@@ -2245,7 +2270,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: