@staticmethod
def _supports_direct_io(dirpath):
    if (not hasattr(os, 'O_DIRECT')):
        LOG.debug('This python runtime does not support direct I/O')
        return False
    testfile = os.path.join(dirpath, '.directio.test')
    hasDirectIO = True
    try:
        f = os.open(testfile, ((os.O_CREAT | os.O_WRONLY) | os.O_DIRECT))
        align_size = 512
        m = mmap.mmap((- 1), align_size)
        m.write(('x' * align_size))
        os.write(f, m)
        os.close(f)
        LOG.debug("Path '%(path)s' supports direct I/O", {'path': dirpath})
    except OSError as e:
        if (e.errno == errno.EINVAL):
            LOG.debug("Path '%(path)s' does not support direct I/O: '%(ex)s'", {'path': dirpath, 'ex': str(e)})
            hasDirectIO = False
        else:
            with excutils.save_and_reraise_exception():
                LOG.error(_LE("Error on '%(path)s' while checking direct I/O: '%(ex)s'"), {'path': dirpath, 'ex': str(e)})
    except Exception as e:
        with excutils.save_and_reraise_exception():
            LOG.error(_LE("Error on '%(path)s' while checking direct I/O: '%(ex)s'"), {'path': dirpath, 'ex': str(e)})
    finally:
        try:
            os.unlink(testfile)
        except Exception:
            pass
    return hasDirectIO
@staticmethod
def _supports_direct_io(dirpath):
    if (not hasattr(os, 'O_DIRECT')):
        LOG.debug('This python runtime does not support direct I/O')
        return False
    testfile = os.path.join(dirpath, '.directio.test')
    hasDirectIO = True
    try:
        f = os.open(testfile, ((os.O_CREAT | os.O_WRONLY) | os.O_DIRECT))
        align_size = 512
        m = mmap.mmap((- 1), align_size)
        m.write(('x' * align_size))
        os.write(f, m)
        os.close(f)
        LOG.debug("Path '%(path)s' supports direct I/O", {'path': dirpath})
    except OSError as e:
        if (e.errno == errno.EINVAL):
            LOG.debug("Path '%(path)s' does not support direct I/O: '%(ex)s'", {'path': dirpath, 'ex': str(e)})
            hasDirectIO = False
        else:
            with excutils.save_and_reraise_exception():
                LOG.error(_LE("Error on '%(path)s' while checking direct I/O: '%(ex)s'"), {'path': dirpath, 'ex': str(e)})
    except Exception as e:
        with excutils.save_and_reraise_exception():
            LOG.error(_LE("Error on '%(path)s' while checking direct I/O: '%(ex)s'"), {'path': dirpath, 'ex': str(e)})
    finally:
        try:
            os.unlink(testfile)
        except Exception:
            pass
    return hasDirectIO