]> git-server-git.apps.pok.os.sepia.ceph.com Git - ceph.git/commitdiff
ceph-disk: bluestore list
authorLoic Dachary <ldachary@redhat.com>
Thu, 28 Jan 2016 04:12:47 +0000 (11:12 +0700)
committerLoic Dachary <ldachary@redhat.com>
Thu, 4 Feb 2016 10:01:46 +0000 (17:01 +0700)
The objectstore journal and the bluestore block auxiliary device are
handled in the same way. Each occurrence of journal in the code is
replaced with a variable.

A few helpers are added to the Ptype class to factorize the most common
lookups but the code logic is unmodified with one exception: the
more_osd_info previously added a journal_uuid entry regarless. If there
was no journal_uuid file, it would be None. It is changed to only add
the {block,journal}_uuid entry if the corresponding file exist.

Signed-off-by: Loic Dachary <loic@dachary.org>
src/ceph-disk/ceph_disk/main.py
src/ceph-disk/tests/test_main.py

index bdc5f94c2ec749bdf582ee9a0404b74d6555f6de..5a5e6b8dcb2dec44ca52fedd2541dc9e03d0db1b 100755 (executable)
@@ -110,6 +110,44 @@ class Ptype(object):
     def get_ready_by_name(name):
         return [x[name]['ready'] for x in PTYPE.values()]
 
+    @staticmethod
+    def is_regular_space(ptype):
+        return Ptype.is_what_space('regular', ptype)
+
+    @staticmethod
+    def is_mpath_space(ptype):
+        return Ptype.is_what_space('mpath', ptype)
+
+    @staticmethod
+    def is_plain_space(ptype):
+        return Ptype.is_what_space('plain', ptype)
+
+    @staticmethod
+    def is_luks_space(ptype):
+        return Ptype.is_what_space('luks', ptype)
+
+    @staticmethod
+    def is_what_space(what, ptype):
+        for name in Space.NAMES:
+            if ptype == PTYPE[what][name]['ready']:
+                return True
+        return False
+
+    @staticmethod
+    def space_ptype_to_name(ptype):
+        for what in PTYPE.values():
+            for name in Space.NAMES:
+                if ptype == what[name]['ready']:
+                    return name
+        raise ValueError('ptype ' + ptype + ' not found')
+
+    @staticmethod
+    def is_dmcrypt_space(ptype):
+        for name in Space.NAMES:
+            if Ptype.is_dmcrypt(ptype, name):
+                return True
+        return False
+
     @staticmethod
     def is_dmcrypt(ptype, name):
         for what in ('plain', 'luks'):
@@ -1702,6 +1740,11 @@ class PrepareBluestore(Prepare):
         self.data.prepare(self.block)
 
 
+class Space(object):
+
+    NAMES = ('block', 'journal')
+
+
 class PrepareSpace(object):
 
     NONE = 0
@@ -3472,11 +3515,12 @@ def more_osd_info(path, uuid_map, desc):
     if desc['ceph_fsid']:
         desc['cluster'] = find_cluster_by_uuid(desc['ceph_fsid'])
     desc['whoami'] = get_oneliner(path, 'whoami')
-    desc['journal_uuid'] = get_oneliner(path, 'journal_uuid')
-    if desc['journal_uuid']:
-        desc['journal_uuid'] = desc['journal_uuid'].lower()
-        if desc['journal_uuid'] in uuid_map:
-            desc['journal_dev'] = uuid_map[desc['journal_uuid']]
+    for name in Space.NAMES:
+        uuid = get_oneliner(path, name + '_uuid')
+        if uuid:
+            desc[name + '_uuid'] = uuid.lower()
+            if desc[name + '_uuid'] in uuid_map:
+                desc[name + '_dev'] = uuid_map[desc[name + '_uuid']]
 
 
 def list_dev_osd(dev, uuid_map, desc):
@@ -3511,8 +3555,9 @@ def list_format_more_osd_info_plain(dev):
             desc.append('unknown cluster ' + dev['ceph_fsid'])
     if dev.get('whoami'):
         desc.append('osd.%s' % dev['whoami'])
-    if dev.get('journal_dev'):
-        desc.append('journal %s' % dev['journal_dev'])
+    for name in Space.NAMES:
+        if dev.get(name + '_dev'):
+            desc.append(name + ' %s' % dev[name + '_dev'])
     return desc
 
 
@@ -3534,19 +3579,22 @@ def list_format_dev_plain(dev, prefix=''):
         else:
             desc = ['ceph data (dmcrypt %s)' % dmcrypt['type'],
                     'holders: ' + ','.join(dmcrypt['holders'])]
-    elif dev['ptype'] == PTYPE['regular']['journal']['ready']:
-        desc.append('ceph journal')
-        if dev.get('journal_for'):
-            desc.append('for %s' % dev['journal_for'])
-    elif Ptype.is_dmcrypt(dev['ptype'], 'journal'):
+    elif Ptype.is_regular_space(dev['ptype']):
+        name = Ptype.space_ptype_to_name(dev['ptype'])
+        desc.append('ceph ' + name)
+        if dev.get(name + '_for'):
+            desc.append('for %s' % dev[name + '_for'])
+    elif Ptype.is_dmcrypt_space(dev['ptype']):
+        name = Ptype.space_ptype_to_name(dev['ptype'])
         dmcrypt = dev['dmcrypt']
         if dmcrypt['holders'] and len(dmcrypt['holders']) == 1:
             holder = get_dev_path(dmcrypt['holders'][0])
-            desc = ['ceph journal (dmcrypt %s %s)' % (dmcrypt['type'], holder)]
+            desc = ['ceph ' + name + ' (dmcrypt %s %s)' %
+                    (dmcrypt['type'], holder)]
         else:
-            desc = ['ceph journal (dmcrypt %s)' % dmcrypt['type']]
-        if dev.get('journal_for'):
-            desc.append('for %s' % dev['journal_for'])
+            desc = ['ceph ' + name + ' (dmcrypt %s)' % dmcrypt['type']]
+        if dev.get(name + '_for'):
+            desc.append('for %s' % dev[name + '_for'])
     else:
         desc.append(dev['type'])
         if dev.get('fs_type'):
@@ -3572,7 +3620,7 @@ def list_format_plain(devices):
     return "\n".join(lines)
 
 
-def list_dev(dev, uuid_map, journal_map):
+def list_dev(dev, uuid_map, space_map):
     info = {
         'path': dev,
         'dmcrypt': {},
@@ -3606,27 +3654,29 @@ def list_dev(dev, uuid_map, journal_map):
         info['dmcrypt']['type'] = 'LUKS'
         if len(holders) == 1:
             list_dev_osd(get_dev_path(holders[0]), uuid_map, info)
-    elif ptype in (PTYPE['regular']['journal']['ready'],
-                   PTYPE['mpath']['journal']['ready']):
-        info['type'] = 'journal'
-        if ptype == PTYPE['mpath']['journal']['ready']:
+    elif Ptype.is_regular_space(ptype) or Ptype.is_mpath_space(ptype):
+        name = Ptype.space_ptype_to_name(ptype)
+        info['type'] = name
+        if ptype == PTYPE['mpath'][name]['ready']:
             info['multipath'] = True
-        if info.get('uuid') in journal_map:
-            info['journal_for'] = journal_map[info['uuid']]
-    elif ptype == PTYPE['plain']['journal']['ready']:
+        if info.get('uuid') in space_map:
+            info[name + '_for'] = space_map[info['uuid']]
+    elif Ptype.is_plain_space(ptype):
+        name = Ptype.space_ptype_to_name(ptype)
         holders = is_held(dev)
-        info['type'] = 'journal'
+        info['type'] = name
         info['dmcrypt']['type'] = 'plain'
         info['dmcrypt']['holders'] = holders
-        if info.get('uuid') in journal_map:
-            info['journal_for'] = journal_map[info['uuid']]
-    elif ptype == PTYPE['luks']['journal']['ready']:
+        if info.get('uuid') in space_map:
+            info[name + '_for'] = space_map[info['uuid']]
+    elif Ptype.is_luks_space(ptype):
+        name = Ptype.space_ptype_to_name(ptype)
         holders = is_held(dev)
-        info['type'] = 'journal'
+        info['type'] = name
         info['dmcrypt']['type'] = 'LUKS'
         info['dmcrypt']['holders'] = holders
-        if info.get('uuid') in journal_map:
-            info['journal_for'] = journal_map[info['uuid']]
+        if info.get('uuid') in space_map:
+            info[name + '_for'] = space_map[info['uuid']]
     else:
         path = is_mounted(dev)
         fs_type = get_dev_fs(dev)
@@ -3646,7 +3696,7 @@ def list_devices():
     partmap = list_all_partitions()
 
     uuid_map = {}
-    journal_map = {}
+    space_map = {}
     for base, parts in sorted(partmap.iteritems()):
         for p in parts:
             dev = get_dev_path(p)
@@ -3672,16 +3722,18 @@ def list_devices():
                         tpath = mount(dev=dev_to_mount,
                                       fstype=fs_type, options='')
                         try:
-                            journal_uuid = get_oneliner(tpath, 'journal_uuid')
-                            if journal_uuid:
-                                journal_map[journal_uuid.lower()] = dev
+                            for name in Space.NAMES:
+                                space_uuid = get_oneliner(tpath,
+                                                          name + '_uuid')
+                                if space_uuid:
+                                    space_map[space_uuid.lower()] = dev
                         finally:
                             unmount(tpath)
                     except MountError:
                         pass
 
     LOG.debug("main_list: " + str(partmap) + ", uuid_map = " +
-              str(uuid_map) + ", journal_map = " + str(journal_map))
+              str(uuid_map) + ", space_map = " + str(space_map))
 
     devices = []
     for base, parts in sorted(partmap.iteritems()):
@@ -3691,11 +3743,11 @@ def list_devices():
             for p in sorted(parts):
                 partitions.append(list_dev(get_dev_path(p),
                                            uuid_map,
-                                           journal_map))
+                                           space_map))
             disk['partitions'] = partitions
             devices.append(disk)
         else:
-            device = list_dev(get_dev_path(base), uuid_map, journal_map)
+            device = list_dev(get_dev_path(base), uuid_map, space_map)
             device['path'] = get_dev_path(base)
             devices.append(device)
     LOG.debug("list_devices: " + str(devices))
index f6355fcc71ce57f3300d0c4d9b4880b5fc853573..fe85eb720de88534006ee0c4387a03153b2f7fe4 100644 (file)
@@ -426,36 +426,46 @@ class TestCephDisk(object):
                        }]}]
             assert expect == main.list_devices()
 
-    def test_list_dmcrypt(self):
+    def test_list_default(self):
         self.list(main.PTYPE['plain']['osd']['ready'],
                   main.PTYPE['plain']['journal']['ready'])
         self.list(main.PTYPE['luks']['osd']['ready'],
                   main.PTYPE['luks']['journal']['ready'])
-
-    def test_list_normal(self):
         self.list(main.PTYPE['regular']['osd']['ready'],
                   main.PTYPE['regular']['journal']['ready'])
 
-    def list(self, data_ptype, journal_ptype):
+    def test_list_bluestore(self):
+        self.list(main.PTYPE['plain']['osd']['ready'],
+                  main.PTYPE['plain']['block']['ready'])
+        self.list(main.PTYPE['luks']['osd']['ready'],
+                  main.PTYPE['luks']['block']['ready'])
+        self.list(main.PTYPE['regular']['osd']['ready'],
+                  main.PTYPE['regular']['block']['ready'])
+
+    def list(self, data_ptype, space_ptype):
         #
         # a single disk has a data partition and a journal
         # partition and the osd is active
         #
+        name = main.Ptype.space_ptype_to_name(space_ptype)
         data_uuid = "56244cf5-83ef-4984-888a-2d8b8e0e04b2"
         disk = "Xda"
         data = "Xda1"
         data_holder = "dm-0"
-        journal = "Xda2"
-        journal_holder = "dm-0"
+        space = "Xda2"
+        space_holder = "dm-0"
         mount_path = '/mount/path'
         fs_type = 'ext4'
-        journal_uuid = "7ad5e65a-0ca5-40e4-a896-62a74ca61c55"
+        space_uuid = "7ad5e65a-0ca5-40e4-a896-62a74ca61c55"
         ceph_fsid = "60a2ef70-d99b-4b9b-a83c-8a86e5e60091"
         osd_id = '1234'
 
         def get_oneliner(path, what):
-            if what == 'journal_uuid':
-                return journal_uuid
+            if '_uuid' in what:
+                if what == name + '_uuid':
+                    return space_uuid
+                else:
+                    return None
             elif what == 'ceph_fsid':
                 return ceph_fsid
             elif what == 'whoami':
@@ -466,8 +476,8 @@ class TestCephDisk(object):
         def get_partition_uuid(dev):
             if dev == '/dev/' + data:
                 return data_uuid
-            elif dev == '/dev/' + journal:
-                return journal_uuid
+            elif dev == '/dev/' + space:
+                return space_uuid
             else:
                 raise Exception('unknown ' + dev)
 
@@ -475,9 +485,9 @@ class TestCephDisk(object):
             if (dev == '/dev/' + data or
                     dev == '/dev/' + data_holder):
                 return data_ptype
-            elif (dev == '/dev/' + journal or
-                    dev == '/dev/' + journal_holder):
-                return journal_ptype
+            elif (dev == '/dev/' + space or
+                    dev == '/dev/' + space_holder):
+                return space_ptype
             else:
                 raise Exception('unknown ' + dev)
         cluster = 'ceph'
@@ -496,27 +506,27 @@ class TestCephDisk(object):
         else:
             raise Exception('unknown ' + data_ptype)
 
-        if journal_ptype == main.PTYPE['regular']['journal']['ready']:
-            journal_dmcrypt = {}
-        elif journal_ptype == main.PTYPE['plain']['journal']['ready']:
-            journal_dmcrypt = {
+        if space_ptype == main.PTYPE['regular'][name]['ready']:
+            space_dmcrypt = {}
+        elif space_ptype == main.PTYPE['plain'][name]['ready']:
+            space_dmcrypt = {
                 'type': 'plain',
-                'holders': [journal_holder],
+                'holders': [space_holder],
             }
-        elif journal_ptype == main.PTYPE['luks']['journal']['ready']:
-            journal_dmcrypt = {
+        elif space_ptype == main.PTYPE['luks'][name]['ready']:
+            space_dmcrypt = {
                 'type': 'LUKS',
-                'holders': [journal_holder],
+                'holders': [space_holder],
             }
         else:
-            raise Exception('unknown ' + journal_ptype)
+            raise Exception('unknown ' + space_ptype)
 
         if data_dmcrypt:
             def is_held(dev):
                 if dev == '/dev/' + data:
                     return [data_holder]
-                elif dev == '/dev/' + journal:
-                    return [journal_holder]
+                elif dev == '/dev/' + space:
+                    return [space_holder]
                 else:
                     raise Exception('unknown ' + dev)
         else:
@@ -525,7 +535,7 @@ class TestCephDisk(object):
 
         with patch.multiple(
                 main,
-                list_all_partitions=lambda: {disk: [data, journal]},
+                list_all_partitions=lambda: {disk: [data, space]},
                 get_dev_fs=lambda dev: fs_type,
                 is_mounted=lambda dev: mount_path,
                 get_partition_uuid=get_partition_uuid,
@@ -544,8 +554,8 @@ class TestCephDisk(object):
                            'dmcrypt': data_dmcrypt,
                            'fs_type': fs_type,
                            'is_partition': True,
-                           'journal_dev': '/dev/' + journal,
-                           'journal_uuid': journal_uuid,
+                           name + '_dev': '/dev/' + space,
+                           name + '_uuid': space_uuid,
                            'mount': mount_path,
                            'path': '/dev/' + data,
                            'ptype': data_ptype,
@@ -554,13 +564,13 @@ class TestCephDisk(object):
                            'whoami': osd_id,
                            'uuid': data_uuid,
                        }, {
-                           'dmcrypt': journal_dmcrypt,
+                           'dmcrypt': space_dmcrypt,
                            'is_partition': True,
-                           'journal_for': '/dev/' + data,
-                           'path': '/dev/' + journal,
-                           'ptype': journal_ptype,
-                           'type': 'journal',
-                           'uuid': journal_uuid,
+                           name + '_for': '/dev/' + data,
+                           'path': '/dev/' + space,
+                           'ptype': space_ptype,
+                           'type': name,
+                           'uuid': space_uuid,
                        }]}]
             assert expect == main.list_devices()