From: Alfredo Deza Date: Thu, 22 May 2014 21:04:28 +0000 (-0400) Subject: better error reporting on incompatible device requirements X-Git-Tag: v0.80.6~64 X-Git-Url: http://git-server-git.apps.pok.os.sepia.ceph.com/?a=commitdiff_plain;h=c9847ef059f182ad15ef027c8bdfae6c99d91867;p=ceph.git better error reporting on incompatible device requirements Signed-off-by: Alfredo Deza (cherry picked from commit 1ac3a503a15ddf7f7c1a33310a468fac10a1b7b6) --- diff --git a/src/ceph-disk b/src/ceph-disk index 7a9ef5f53532..8ca5f3b17c85 100755 --- a/src/ceph-disk +++ b/src/ceph-disk @@ -360,6 +360,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) @@ -367,6 +368,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 @@ -973,6 +997,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(