]> review.fuel-infra Code Review - openstack-build/cinder-build.git/commitdiff
use O_DIRECT when copying from /dev/zero too
authorPádraig Brady <pbrady@redhat.com>
Fri, 23 Nov 2012 11:24:44 +0000 (11:24 +0000)
committerPádraig Brady <pbrady@redhat.com>
Fri, 23 Nov 2012 11:29:00 +0000 (11:29 +0000)
We need to avoid trying O_DIRECT with virtual
devices like /dev/zero and /dev/urandom etc.
as it's not supported there, which because of
our later check, would cause O_DIRECT to be
not applied to the output device either.

Related to bug 937694
Possibly related to bug 1023755
Change-Id: I034d8345c3d00689c1f1fffcc2c110735c49ee01

cinder/volume/driver.py

index 35af09935344a9d11eace7e0b134af70c2e1b1c1..0dacacfcd016250517d3a38697073674c4a9c3fa 100644 (file)
@@ -22,6 +22,7 @@ Drivers for volumes.
 
 import os
 import re
+import stat
 import time
 
 from cinder import exception
@@ -105,7 +106,15 @@ class VolumeDriver(object):
 
     def _copy_volume(self, srcstr, deststr, size_in_g):
         # Use O_DIRECT to avoid thrashing the system buffer cache
-        direct_flags = ('iflag=direct', 'oflag=direct')
+        direct_flags = ['oflag=direct']
+        try:
+            # Avoid trying O_DIRECT on virtual inputs like /dev/zero
+            # as it's not supported with such devices.
+            if not stat.S_ISCHR(os.stat(srcstr).st_mode):
+                direct_flags += ['iflag=direct']
+        except OSError:
+            # Deal with any access issues below
+            pass
 
         # Check whether O_DIRECT is supported
         try: