From b9510e0425a1d00e91ea051ec24d9ab8b65b4f75 Mon Sep 17 00:00:00 2001 From: Alfredo Deza Date: Mon, 10 Sep 2018 12:09:50 -0400 Subject: [PATCH] ceph-volume util.prepare add a helper to get block.db sizes from ceph.conf Signed-off-by: Alfredo Deza (cherry picked from commit 860068ec5daca6d7087cf1ce0594a2fe36e91193) --- src/ceph-volume/ceph_volume/util/prepare.py | 30 +++++++++++++++++++++ 1 file changed, 30 insertions(+) diff --git a/src/ceph-volume/ceph_volume/util/prepare.py b/src/ceph-volume/ceph_volume/util/prepare.py index 687a5892bda9c..aaeced84222eb 100644 --- a/src/ceph-volume/ceph_volume/util/prepare.py +++ b/src/ceph-volume/ceph_volume/util/prepare.py @@ -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 -- 2.39.5