]> git.apps.os.sepia.ceph.com Git - ceph.git/commitdiff
better error reporting on incompatible device requirements 1874/head
authorAlfredo Deza <alfredo@deza.pe>
Thu, 22 May 2014 21:04:28 +0000 (17:04 -0400)
committerAlfredo Deza <alfredo@deza.pe>
Tue, 27 May 2014 16:54:49 +0000 (12:54 -0400)
Signed-off-by: Alfredo Deza <alfredo@deza.pe>
src/ceph-disk

index 7b358397f47bcf72c0f46c82dfeae7103ee38a54..9ec1f5f9fe316265743b37bb333ba804a9e2509d 100755 (executable)
@@ -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(