Merge "libvirt: consider minimal I/O size when selecting cache type"
This commit is contained in:
commit
7d79f458d6
@ -2590,6 +2590,44 @@ class LibvirtConnTestCase(test.TestCase):
|
|||||||
self.assertEqual(len(interfaces), 2)
|
self.assertEqual(len(interfaces), 2)
|
||||||
self.assertEqual(interfaces[0].get('type'), 'bridge')
|
self.assertEqual(interfaces[0].get('type'), 'bridge')
|
||||||
|
|
||||||
|
def _behave_supports_direct_io(self, raise_open=False, raise_write=False,
|
||||||
|
exc=ValueError()):
|
||||||
|
open_behavior = os.open(os.path.join('.', '.directio.test'),
|
||||||
|
os.O_CREAT | os.O_WRONLY | os.O_DIRECT)
|
||||||
|
if raise_open:
|
||||||
|
open_behavior.AndRaise(exc)
|
||||||
|
else:
|
||||||
|
open_behavior.AndReturn(3)
|
||||||
|
write_bahavior = os.write(3, mox.IgnoreArg())
|
||||||
|
if raise_write:
|
||||||
|
write_bahavior.AndRaise(exc)
|
||||||
|
else:
|
||||||
|
os.close(3)
|
||||||
|
os.unlink(3)
|
||||||
|
|
||||||
|
def test_supports_direct_io(self):
|
||||||
|
einval = OSError()
|
||||||
|
einval.errno = errno.EINVAL
|
||||||
|
self.mox.StubOutWithMock(os, 'open')
|
||||||
|
self.mox.StubOutWithMock(os, 'write')
|
||||||
|
self.mox.StubOutWithMock(os, 'close')
|
||||||
|
self.mox.StubOutWithMock(os, 'unlink')
|
||||||
|
_supports_direct_io = libvirt_driver.LibvirtDriver._supports_direct_io
|
||||||
|
|
||||||
|
self._behave_supports_direct_io()
|
||||||
|
self._behave_supports_direct_io(raise_write=True)
|
||||||
|
self._behave_supports_direct_io(raise_open=True)
|
||||||
|
self._behave_supports_direct_io(raise_write=True, exc=einval)
|
||||||
|
self._behave_supports_direct_io(raise_open=True, exc=einval)
|
||||||
|
|
||||||
|
self.mox.ReplayAll()
|
||||||
|
self.assertTrue(_supports_direct_io('.'))
|
||||||
|
self.assertRaises(ValueError, _supports_direct_io, '.')
|
||||||
|
self.assertRaises(ValueError, _supports_direct_io, '.')
|
||||||
|
self.assertFalse(_supports_direct_io('.'))
|
||||||
|
self.assertFalse(_supports_direct_io('.'))
|
||||||
|
self.mox.VerifyAll()
|
||||||
|
|
||||||
def _check_xml_and_container(self, instance):
|
def _check_xml_and_container(self, instance):
|
||||||
user_context = context.RequestContext(self.user_id,
|
user_context = context.RequestContext(self.user_id,
|
||||||
self.project_id)
|
self.project_id)
|
||||||
|
@ -44,6 +44,7 @@ import errno
|
|||||||
import eventlet
|
import eventlet
|
||||||
import functools
|
import functools
|
||||||
import glob
|
import glob
|
||||||
|
import mmap
|
||||||
import os
|
import os
|
||||||
import shutil
|
import shutil
|
||||||
import socket
|
import socket
|
||||||
@ -2319,6 +2320,11 @@ class LibvirtDriver(driver.ComputeDriver):
|
|||||||
hasDirectIO = True
|
hasDirectIO = True
|
||||||
try:
|
try:
|
||||||
f = os.open(testfile, os.O_CREAT | os.O_WRONLY | os.O_DIRECT)
|
f = os.open(testfile, os.O_CREAT | os.O_WRONLY | os.O_DIRECT)
|
||||||
|
# Check is the write allowed with 512 byte alignment
|
||||||
|
align_size = 512
|
||||||
|
m = mmap.mmap(-1, align_size)
|
||||||
|
m.write(r"x" * align_size)
|
||||||
|
os.write(f, m)
|
||||||
os.close(f)
|
os.close(f)
|
||||||
LOG.debug(_("Path '%(path)s' supports direct I/O") %
|
LOG.debug(_("Path '%(path)s' supports direct I/O") %
|
||||||
{'path': dirpath})
|
{'path': dirpath})
|
||||||
|
Loading…
Reference in New Issue
Block a user