]> review.fuel-infra Code Review - openstack-build/cinder-build.git/commitdiff
Check whether O_DIRECT is supported to iflag and oflag separately
authorvitas.yuzhou <vitas.yuzhou@huawei.com>
Mon, 12 May 2014 18:57:48 +0000 (02:57 +0800)
committervitas.yuzhou <vitas.yuzhou@huawei.com>
Tue, 20 May 2014 08:54:50 +0000 (16:54 +0800)
The problem is when this is used for volume clear and the clear method
specifies use of the 'zero' option (/dev/zero) setting iflag direct is
not a valid option for that input file, but oflag direct is a valid
option for output file, so we should check iflag and oflag separately.

Change-Id: I4b627e95b68d56e3011cddc577c62fad0c384dba
Close-Bug: 1318748

cinder/tests/test_volume_utils.py
cinder/volume/utils.py

index fd120013c18966dc134abb7a815404aee141d53a..358a5e66a6839638bb32cf5ac0da615dff32f5bb 100644 (file)
@@ -25,6 +25,7 @@ from cinder import db
 from cinder import exception
 from cinder.openstack.common import importutils
 from cinder.openstack.common import log as logging
+from cinder.openstack.common import processutils
 from cinder import test
 from cinder.tests import fake_notifier
 from cinder import utils
@@ -200,3 +201,19 @@ class ClearVolumeTestCase(test.TestCase):
 
         self.stubs.Set(volume_utils, 'copy_volume', fake_copy_volume)
         volume_utils.clear_volume(123, vol_path)
+
+
+class CopyVolumeTestCase(test.TestCase):
+
+    def test_copy_volume_dd_iflag_and_oflag(self):
+        def fake_utils_execute(*cmd, **kwargs):
+            if 'if=/dev/zero' in cmd and 'iflag=direct' in cmd:
+                raise processutils.ProcessExecutionError()
+            if 'of=/dev/null' in cmd and 'oflag=direct' in cmd:
+                raise processutils.ProcessExecutionError()
+            if 'iflag=direct' in cmd and 'oflag=direct' in cmd:
+                raise exception.InvalidInput(message='iflag/oflag error')
+
+        volume_utils.copy_volume('/dev/zero', '/dev/null', 1024,
+                                 CONF.volume_dd_blocksize, sync=True,
+                                 ionice=None, execute=fake_utils_execute)
index 967bcee53baa62f322c74aa35b5240491a8f65f0..0ca7b68b577599590a13255ca73a6e8782bd3b12 100644 (file)
@@ -131,14 +131,15 @@ def _calculate_count(size_in_m, blocksize):
 def copy_volume(srcstr, deststr, size_in_m, blocksize, sync=False,
                 execute=utils.execute, ionice=None):
     # Use O_DIRECT to avoid thrashing the system buffer cache
-    extra_flags = ['iflag=direct', 'oflag=direct']
-
-    # Check whether O_DIRECT is supported
-    try:
-        execute('dd', 'count=0', 'if=%s' % srcstr, 'of=%s' % deststr,
-                *extra_flags, run_as_root=True)
-    except processutils.ProcessExecutionError:
-        extra_flags = []
+    extra_flags = []
+    # Check whether O_DIRECT is supported to iflag and oflag separately
+    for flag in ['iflag=direct', 'oflag=direct']:
+        try:
+            execute('dd', 'count=0', 'if=%s' % srcstr, 'of=%s' % deststr,
+                    flag, run_as_root=True)
+            extra_flags.append(flag)
+        except processutils.ProcessExecutionError:
+            pass
 
     # If the volume is being unprovisioned then
     # request the data is persisted before returning,