From 5e363eb194e3d33e9a71b7f2f900e5c6dc13a0b1 Mon Sep 17 00:00:00 2001 From: Sheel Rana Date: Tue, 12 Jan 2016 01:36:46 +0530 Subject: [PATCH] Handling Invalid argument iflag=direct in dd 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 | 21 +++++++++++++++++++++ cinder/volume/utils.py | 12 +++++++++--- 2 files changed, 30 insertions(+), 3 deletions(-) diff --git a/cinder/tests/unit/test_volume_utils.py b/cinder/tests/unit/test_volume_utils.py index d5158dbc2..f425ea773 100644 --- a/cinder/tests/unit/test_volume_utils.py +++ b/cinder/tests/unit/test_volume_utils.py @@ -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): diff --git a/cinder/volume/utils.py b/cinder/volume/utils.py index e875f5eee..f93c17c37 100644 --- a/cinder/volume/utils.py +++ b/cinder/volume/utils.py @@ -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 -- 2.45.2