]> review.fuel-infra Code Review - openstack-build/cinder-build.git/commitdiff
Handling Invalid argument iflag=direct in dd
authorSheel Rana <ranasheel2000@gmail.com>
Mon, 11 Jan 2016 20:06:46 +0000 (01:36 +0530)
committerSheel Rana <ranasheel2000@gmail.com>
Mon, 11 Jan 2016 20:08:33 +0000 (01:38 +0530)
During volume/snapshot create/delete operations,
dd command is used to clear contents of disk.

Before invoking dd, it is checked if iflag=direct
supports dd or not by executing dd command with
iflag=direct and if=/dev/zero combination.
But this always results in invalid argument
error.

Handling for this argument is done to eliminate
unnecessary call to dd command when it is used
with iflag=direct and if=/dev/zero combination
to check if this argument supports dd or not.

Closes-Bug: #1270362

Change-Id: Ic6dd029ca1a339076e491c38ef3c69315497f189

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

index d5158dbc2f9b183adba8f4ea203438350bbd4c62..f425ea7736131916df725a08b1e4dc993c5dc940 100644 (file)
@@ -445,6 +445,20 @@ class OdirectSupportTestCase(test.TestCase):
         mock_exec.assert_called_once_with('dd', 'count=0', 'if=/dev/abc',
                                           'of=/dev/def', 'iflag=direct',
                                           run_as_root=True)
+        mock_exec.reset_mock()
+
+        output = volume_utils.check_for_odirect_support('/dev/zero',
+                                                        '/dev/def',
+                                                        'iflag=direct')
+        self.assertFalse(output)
+        mock_exec.reset_mock()
+
+        output = volume_utils.check_for_odirect_support('/dev/zero',
+                                                        '/dev/def')
+        self.assertTrue(output)
+        mock_exec.assert_called_once_with('dd', 'count=0', 'if=/dev/zero',
+                                          'of=/dev/def', 'oflag=direct',
+                                          run_as_root=True)
 
     @mock.patch('cinder.utils.execute',
                 side_effect=processutils.ProcessExecutionError)
@@ -454,6 +468,13 @@ class OdirectSupportTestCase(test.TestCase):
         mock_exec.assert_called_once_with('dd', 'count=0', 'if=/dev/abc',
                                           'of=/dev/def', 'oflag=direct',
                                           run_as_root=True)
+        mock_exec.reset_mock()
+        output = volume_utils.check_for_odirect_support('/dev/zero',
+                                                        '/dev/def')
+        self.assertFalse(output)
+        mock_exec.assert_called_once_with('dd', 'count=0', 'if=/dev/zero',
+                                          'of=/dev/def', 'oflag=direct',
+                                          run_as_root=True)
 
 
 class ClearVolumeTestCase(test.TestCase):
index e875f5eee388e9ae0ad1ac48a025edd4c7483af3..f93c17c37ed7ec21656e8df0cd4d7d37e5107432 100644 (file)
@@ -299,9 +299,15 @@ def check_for_odirect_support(src, dest, flag='oflag=direct'):
 
     # Check whether O_DIRECT is supported
     try:
-        utils.execute('dd', 'count=0', 'if=%s' % src, 'of=%s' % dest,
-                      flag, run_as_root=True)
-        return True
+        # iflag=direct and if=/dev/zero combination does not work
+        # error: dd: failed to open '/dev/zero': Invalid argument
+        if (src == '/dev/zero' and flag == 'iflag=direct'):
+            return False
+        else:
+            utils.execute('dd', 'count=0', 'if=%s' % src,
+                          'of=%s' % dest,
+                          flag, run_as_root=True)
+            return True
     except processutils.ProcessExecutionError:
         return False