]> git.apps.os.sepia.ceph.com Git - ceph.git/commitdiff
ceph-volume util.prepare add a helper to get block.db sizes from ceph.conf
authorAlfredo Deza <adeza@redhat.com>
Mon, 10 Sep 2018 16:09:50 +0000 (12:09 -0400)
committerAlfredo Deza <adeza@redhat.com>
Mon, 10 Sep 2018 16:09:50 +0000 (12:09 -0400)
Signed-off-by: Alfredo Deza <adeza@redhat.com>
src/ceph-volume/ceph_volume/util/prepare.py

index 964ca78f37856162d609a3f7415b264e56c372f4..1c1d45318627ecf093323189c5f50c7aa17861e9 100644 (file)
@@ -70,6 +70,36 @@ def get_journal_size(lv_format=True):
     return journal_size
 
 
+def get_block_db_size(lv_format=True):
+    """
+    Helper to retrieve the size (defined in megabytes in ceph.conf) to create
+    the block.db logical volume, it "translates" the string into a float value,
+    then converts that into gigabytes, and finally (optionally) it formats it
+    back as a string so that it can be used for creating the LV.
+
+    :param lv_format: Return a string to be used for ``lv_create``. A 5 GB size
+    would result in '5G', otherwise it will return a ``Size`` object.
+
+    .. note: Configuration values are in bytes, unlike journals which
+             are defined in gigabytes
+    """
+    conf_db_size = conf.ceph.get_safe('osd', 'bluestore_block_db_size', None)
+    if not conf_db_size:
+        logger.debug(
+            'block.db has no size configuration, will fallback to using as much as possible'
+        )
+        return None
+    logger.debug('bluestore_block_db_size set to %s' % conf_db_size)
+    db_size = disk.Size(b=str_to_int(conf_db_size))
+
+    if db_size < disk.Size(gb=2):
+        mlogger.error('Refusing to continue with configured size for block.db')
+        raise RuntimeError('block.db sizes must be larger than 2GB, detected: %s' % db_size)
+    if lv_format:
+        return '%sG' % db_size.gb.as_int()
+    return db_size
+
+
 def create_id(fsid, json_secrets, osd_id=None):
     """
     :param fsid: The osd fsid to create, always required