From 1ac3a503a15ddf7f7c1a33310a468fac10a1b7b6 Mon Sep 17 00:00:00 2001 From: Alfredo Deza Date: Thu, 22 May 2014 17:04:28 -0400 Subject: [PATCH] better error reporting on incompatible device requirements Signed-off-by: Alfredo Deza --- src/ceph-disk | 35 +++++++++++++++++++++++++++++++++++ 1 file changed, 35 insertions(+) diff --git a/src/ceph-disk b/src/ceph-disk index 7b358397f47bc..9ec1f5f9fe316 100755 --- a/src/ceph-disk +++ b/src/ceph-disk @@ -359,6 +359,7 @@ def get_dev_path(name): """ return '/dev/' + name.replace('!', '/') + def get_dev_relpath(name): """ get a relative path to /dev from a name (cciss!c0d1) @@ -366,6 +367,29 @@ def get_dev_relpath(name): return name.replace('!', '/') +def get_dev_size(dev, size='megabytes'): + """ + Attempt to get the size of a device so that we can prevent errors + from actions to devices that are smaller, and improve error reporting. + + Because we want to avoid breakage in case this approach is not robust, we + will issue a warning if we failed to get the size. + + :param size: bytes or megabytes + :param dev: the device to calculate the size + """ + fd = os.open(dev, os.O_RDONLY) + dividers = {'bytes': 1, 'megabytes': 1024*1024} + try: + device_size = os.lseek(fd, 0, os.SEEK_END) + divider = dividers.get(size, 1024*1024) # default to megabytes + return device_size/divider + except Exception as error: + LOG.warning('failed to get size of %s: %s' % (dev, str(error))) + finally: + os.close(fd) + + def get_partition_dev(dev, pnum): """ get the device name for a partition @@ -972,6 +996,17 @@ def prepare_journal_dev( ) LOG.warning('OSD will not be hot-swappable if journal is not the same device as the osd data') + dev_size = get_dev_size(journal) + + if journal_size > dev_size: + LOG.error('refusing to create journal on %s' % journal) + LOG.error('journal size (%sM) is bigger than device (%sM)' % (journal_size, dev_size)) + raise Error('%s device size (%sM) is not big enough for journal' % ( + journal, + dev_size) + ) + + try: LOG.debug('Creating journal partition num %d size %d on %s', num, journal_size, journal) command_check_call( -- 2.39.5