From: Sage Weil Date: Wed, 13 Aug 2014 00:25:10 +0000 (-0700) Subject: ceph-disk: use partition type UUIDs, and blkid X-Git-Tag: v0.80.6~60 X-Git-Url: http://git-server-git.apps.pok.os.sepia.ceph.com/?a=commitdiff_plain;h=6775f46e4a5862ddbf81bef11016bc036222fda9;p=ceph.git ceph-disk: use partition type UUIDs, and blkid 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 (cherry picked from commit 6c77f5f2f994c881232d76ce9c69af80d10772bd) --- diff --git a/src/ceph-disk b/src/ceph-disk index a8a9f8adffa4..79bfcc330c04 100755 --- a/src/ceph-disk +++ b/src/ceph-disk @@ -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: